mirror of
https://github.com/nightly-labs/openbot.git
synced 2026-12-04 01:54:48 +08:00
* Send the iPhone notification when the phone has no Live Activity The host keeps the Live Activity registration of a phone in memory. While the host thinks that the Live Activity shows a reply, it sends the reply to the Live Activity and skips the normal notification. When the phone told the host that it has no Live Activity (liveActivityStartedAt null in the push registration), the host used its own start time instead. So after the Live Activity ended on the phone, or Live Activities were turned off, each reply went to a Live Activity that was gone for up to 8 hours. No banner showed and no sound played until the host restarted. The phone sends liveActivityStartedAt in each push registration since the field came with iPhone notifications (#1971), and it sends null only when it has no Live Activity token for that server. The host now lets the Live Activity replace a notification only when the phone gives its start time. If the phone sends null while a Live Activity shows, the user gets a normal notification too, not no alert. The E2E scripts that call showsEvent now pass the start time that a real phone sends. Fixes #17607 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Add the iPhone release notes for the Live Activity notification fix Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
316 lines
11 KiB
TypeScript
316 lines
11 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { createHash, randomBytes } from "node:crypto";
|
|
import { EventEmitter } from "node:events";
|
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
import { join, resolve } from "node:path";
|
|
import { type AgentEvent, type AgentRuntimeSnapshot, isAgentRuntimeSnapshot } from "@openbot/contracts/ipc";
|
|
import { LIVE_ACTIVITY_SEALED_LIMIT, type LiveActivityRelayPush } from "@openbot/contracts/live-activity-relay";
|
|
import { isDynamicRecord } from "@openbot/contracts/runtime-values";
|
|
import type { AgentLiveActivityProps } from "@openbot/team-client/live-activity-props";
|
|
import {
|
|
encodeLiveActivityBytes,
|
|
LIVE_ACTIVITY_SECRET_BYTES,
|
|
liveActivityKeys,
|
|
} from "@openbot/team-client/live-activity-seal";
|
|
import { Effect } from "effect";
|
|
import { openSealedLiveActivity } from "../apps/mobile/src/features/live-activity/model/live-activity-open";
|
|
import { LiveActivityPushService } from "../src/main/live-activity-push";
|
|
|
|
const ROOT = resolve(import.meta.dirname, "..");
|
|
const DEADLINE_MS = 10_000;
|
|
const EMOJI = "\u{1F600}";
|
|
const CASES = [
|
|
{
|
|
name: "emoji-code-span-cut",
|
|
input: `Run \`${"a".repeat(149)}${EMOJI.repeat(40)}\` now.`,
|
|
expected: `Run \`${"a".repeat(149)}${EMOJI.repeat(26)}\`…`,
|
|
},
|
|
{
|
|
name: "emoji-code-span-cut-odd",
|
|
input: `Run \`${"a".repeat(150)}${EMOJI.repeat(39)}\` now.`,
|
|
expected: `Run \`${"a".repeat(150)}${EMOJI.repeat(25)}\`…`,
|
|
},
|
|
{ name: "short-emoji-code-span", input: `Run \`ab${EMOJI}cd\` now.`, expected: `Run \`ab${EMOJI}cd\` now.` },
|
|
{ name: "ascii-code-span-cut", input: `Run \`${"a".repeat(200)}\` now.`, expected: `Run \`${"a".repeat(175)}\`…` },
|
|
{
|
|
name: "emoji-text-cut",
|
|
input: `${"a".repeat(170)}${EMOJI.repeat(30)}`,
|
|
expected: `${"a".repeat(170)}${EMOJI.repeat(9)}…`,
|
|
},
|
|
];
|
|
const SOURCES = [
|
|
"scripts/live-activity-code-span-e2e.ts",
|
|
"src/main/live-activity-push.ts",
|
|
"packages/team-client/src/dynamic-island-coordinator.ts",
|
|
"packages/team-client/src/dynamic-island-presentation.ts",
|
|
"packages/team-client/src/agent-message-text.ts",
|
|
"packages/team-client/src/live-activity-props.ts",
|
|
"packages/team-client/src/live-activity-text.ts",
|
|
"packages/team-client/src/message-summary.ts",
|
|
"packages/team-client/src/live-activity-seal.ts",
|
|
"apps/mobile/src/features/live-activity/model/live-activity-open.ts",
|
|
];
|
|
|
|
interface CaseResult {
|
|
name: string;
|
|
input: string;
|
|
expected: string;
|
|
observedDetail: string | null;
|
|
stage: string;
|
|
passed: boolean;
|
|
relayPushes: number;
|
|
snapshotReads: number;
|
|
readStateReads: number;
|
|
relay: { event: string; sealedLength: number; priority: number } | null;
|
|
cleanup: {
|
|
disposeCompleted: boolean;
|
|
registrationRemoved: boolean;
|
|
listenersRemaining: number;
|
|
listenerAdds: number;
|
|
listenerRemoves: number;
|
|
deadlineCleared: boolean;
|
|
};
|
|
}
|
|
|
|
interface Report {
|
|
phase: string;
|
|
surface: string;
|
|
transport: string;
|
|
sourceHashes: Record<string, string>;
|
|
cases: CaseResult[];
|
|
passed: boolean;
|
|
status: string;
|
|
}
|
|
|
|
type DisplayedProps = Pick<AgentLiveActivityProps, "mode" | "title" | "compact" | "detailMarkdown" | "detail">;
|
|
|
|
function decodeDisplayedProps(value: unknown): DisplayedProps {
|
|
assert.ok(isDynamicRecord(value), "The opened content must be a props object.");
|
|
assert.ok(value.mode === "message");
|
|
assert.ok(typeof value.title === "string");
|
|
assert.ok(typeof value.compact === "string");
|
|
assert.ok(typeof value.detailMarkdown === "boolean");
|
|
assert.ok(typeof value.detail === "string");
|
|
return {
|
|
mode: value.mode,
|
|
title: value.title,
|
|
compact: value.compact,
|
|
detailMarkdown: value.detailMarkdown,
|
|
detail: value.detail,
|
|
};
|
|
}
|
|
|
|
function snapshot(text: string): AgentRuntimeSnapshot {
|
|
return {
|
|
agents: [
|
|
{
|
|
id: "fixture-agent",
|
|
name: "Fixture agent",
|
|
notifications: true,
|
|
preview: text,
|
|
updatedAt: "2026-10-17T00:00:00.000Z",
|
|
avatarSeed: "fixture-agent",
|
|
avatarHue: null,
|
|
avatarUrl: null,
|
|
},
|
|
],
|
|
activeTurns: [],
|
|
work: [],
|
|
latestMessages: [{ agentId: "fixture-agent", id: "fixture-message", text, createdAt: "2026-10-17T00:00:00.000Z" }],
|
|
attentionComplete: true,
|
|
pendingPrompts: [],
|
|
pendingApprovals: [],
|
|
pendingBrowserTakeovers: [],
|
|
failedTurns: [],
|
|
};
|
|
}
|
|
|
|
async function runCase(fixture: (typeof CASES)[number]): Promise<CaseResult> {
|
|
const result: CaseResult = {
|
|
...fixture,
|
|
observedDetail: null,
|
|
stage: "setup",
|
|
passed: false,
|
|
relayPushes: 0,
|
|
snapshotReads: 0,
|
|
readStateReads: 0,
|
|
relay: null,
|
|
cleanup: {
|
|
disposeCompleted: false,
|
|
registrationRemoved: false,
|
|
listenersRemaining: 0,
|
|
listenerAdds: 0,
|
|
listenerRemoves: 0,
|
|
deadlineCleared: false,
|
|
},
|
|
};
|
|
const events = new EventEmitter<{ event: [AgentEvent] }>();
|
|
const secret = randomBytes(LIVE_ACTIVITY_SECRET_BYTES);
|
|
const keys = liveActivityKeys(secret);
|
|
let deadline: ReturnType<typeof setTimeout> | undefined;
|
|
let service: LiveActivityPushService | undefined;
|
|
try {
|
|
const runtime = snapshot(fixture.input);
|
|
assert.ok(isAgentRuntimeSnapshot(runtime), "The fixture must be a valid runtime snapshot.");
|
|
let receive: (push: LiveActivityRelayPush) => void = () => {};
|
|
const received = new Promise<LiveActivityRelayPush>((resolvePush, reject) => {
|
|
receive = resolvePush;
|
|
deadline = setTimeout(() => reject(new Error("No local relay push before the deadline.")), DEADLINE_MS);
|
|
});
|
|
service = new LiveActivityPushService({
|
|
agents: {
|
|
on: (event, listener) => {
|
|
result.cleanup.listenerAdds += 1;
|
|
events.on(event, listener);
|
|
},
|
|
off: (event, listener) => {
|
|
result.cleanup.listenerRemoves += 1;
|
|
events.off(event, listener);
|
|
},
|
|
listAgents: () => [],
|
|
getRuntimeSnapshot: () => {
|
|
result.snapshotReads += 1;
|
|
return runtime;
|
|
},
|
|
listConversationReads: () => {
|
|
result.readStateReads += 1;
|
|
return {
|
|
"fixture-agent": { unreadCount: 1, firstUnreadMessageId: "fixture-message", throughMessageId: null },
|
|
};
|
|
},
|
|
},
|
|
send: (push) =>
|
|
Effect.sync(() => {
|
|
result.relayPushes += 1;
|
|
receive(push);
|
|
return "sent" as const;
|
|
}),
|
|
memberActive: (memberId) => memberId === "fixture-member",
|
|
randomBytes,
|
|
});
|
|
service.register(
|
|
"fixture-session",
|
|
{
|
|
memberId: "fixture-member",
|
|
hiddenAgentIds: () => new Set<string>(),
|
|
readOptions: {
|
|
excludeRoutineEvents: true,
|
|
excludeRoutineRunEvents: true,
|
|
excludeHostedSiteEvents: true,
|
|
excludeRoutineQuietAnswers: true,
|
|
},
|
|
},
|
|
{
|
|
serverId: "fixture-server",
|
|
token: "ab".repeat(32),
|
|
environment: "development",
|
|
secret: encodeLiveActivityBytes(secret),
|
|
locale: "en",
|
|
away: false,
|
|
photos: [],
|
|
},
|
|
);
|
|
assert.equal(result.relayPushes, 0);
|
|
assert.equal(events.listenerCount("event"), 1);
|
|
service.disconnected("fixture-session");
|
|
assert.equal(
|
|
service.showsEvent("fixture-session", { agentId: "fixture-agent", kind: "reply" }, null, Date.now()),
|
|
true,
|
|
);
|
|
result.stage = "relay";
|
|
const push = await received;
|
|
result.relay = { event: push.event, sealedLength: push.sealed?.length ?? 0, priority: push.priority };
|
|
assert.equal(push.event, "update");
|
|
assert.equal(push.environment, "development");
|
|
assert.ok(push.sealed && push.sealed.length <= LIVE_ACTIVITY_SEALED_LIMIT);
|
|
assert.ok(result.snapshotReads > 0 && result.readStateReads > 0);
|
|
result.stage = "decrypt";
|
|
const opened = openSealedLiveActivity(
|
|
push.sealed,
|
|
encodeLiveActivityBytes(keys.seal),
|
|
encodeLiveActivityBytes(keys.tag),
|
|
);
|
|
assert.ok(opened, "The widget must open the real service seal.");
|
|
const props = decodeDisplayedProps(JSON.parse(opened));
|
|
assert.equal(props.mode, "message");
|
|
assert.equal(props.title, "Fixture agent");
|
|
assert.equal(props.compact, "1");
|
|
assert.equal(props.detailMarkdown, true);
|
|
result.observedDetail = props.detail;
|
|
result.stage = "displayed-detail";
|
|
assert.ok(!/[\uD800-\uDFFF]/u.test(props.detail), "The decrypted display detail must have no lone surrogate.");
|
|
assert.ok(!props.detail.includes("\uFFFD"), "The decrypted display detail must have no replacement character.");
|
|
assert.equal(props.detail, fixture.expected, "The decrypted display detail must keep the expected text.");
|
|
result.stage = "complete";
|
|
result.passed = true;
|
|
} catch {
|
|
result.passed = false;
|
|
} finally {
|
|
if (deadline !== undefined) clearTimeout(deadline);
|
|
result.cleanup.deadlineCleared = true;
|
|
try {
|
|
if (service) {
|
|
await Effect.runPromise(service.dispose());
|
|
result.cleanup.disposeCompleted = true;
|
|
result.cleanup.registrationRemoved = !service.showsEvent(
|
|
"fixture-session",
|
|
{ agentId: "fixture-agent", kind: "reply" },
|
|
null,
|
|
Date.now(),
|
|
);
|
|
}
|
|
} catch {
|
|
result.passed = false;
|
|
result.stage = "cleanup";
|
|
}
|
|
result.cleanup.listenersRemaining = events.listenerCount("event");
|
|
if (
|
|
!result.cleanup.disposeCompleted ||
|
|
!result.cleanup.registrationRemoved ||
|
|
result.cleanup.listenersRemaining !== 0 ||
|
|
result.cleanup.listenerAdds !== 1 ||
|
|
result.cleanup.listenerRemoves !== 1
|
|
) {
|
|
result.passed = false;
|
|
result.stage = "cleanup";
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
const phaseArgument = process.argv.slice(2);
|
|
const phase = phaseArgument[0]?.replace(/^--phase=/u, "") ?? "before";
|
|
const validArguments =
|
|
phaseArgument.length <= 1 &&
|
|
(phaseArgument.length === 0 || phaseArgument[0]?.startsWith("--phase=")) &&
|
|
/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/u.test(phase);
|
|
const output = join(ROOT, ".openbot-build/live-activity-code-span-e2e", validArguments ? phase : "invalid-arguments");
|
|
const report: Report = {
|
|
phase: validArguments ? phase : "invalid-arguments",
|
|
surface:
|
|
"LiveActivityPushService -> DynamicIslandCoordinator -> liveActivityView -> seal -> local relay -> widget open",
|
|
transport: "injected local send adapter; no account, APNs, provider, or model",
|
|
sourceHashes: {},
|
|
cases: [],
|
|
passed: false,
|
|
status: "setup",
|
|
};
|
|
try {
|
|
assert.ok(validArguments, "Use one --phase=<folder-name> argument.");
|
|
for (const file of SOURCES) {
|
|
report.sourceHashes[file] = createHash("sha256")
|
|
.update(readFileSync(join(ROOT, file)))
|
|
.digest("hex");
|
|
}
|
|
for (const fixture of CASES) report.cases.push(await runCase(fixture));
|
|
report.passed = report.cases.length === CASES.length && report.cases.every((result) => result.passed);
|
|
report.status = report.passed ? "pass" : "fail";
|
|
} catch {
|
|
report.status = validArguments ? "setup-failure" : "invalid-arguments";
|
|
} finally {
|
|
mkdirSync(output, { recursive: true });
|
|
writeFileSync(join(output, "report.json"), `${JSON.stringify(report, null, 2)}\n`);
|
|
}
|
|
process.stdout.write(`${report.passed ? "PASS" : "FAIL"}: ${join(output, "report.json")}\n`);
|
|
if (!report.passed) process.exitCode = 1;
|