






























@@ -148,6 +148,44 @@ function firstCallParam(calls: readonly unknown[][], label: string) {
148148return call[0];
149149}
150150151+type MockSessionEntry = {
152+sessionId?: string;
153+updatedAt?: number;
154+[key: string]: unknown;
155+};
156+157+function createMockSessionRuntime(sessionStore: Record<string, unknown>) {
158+return {
159+resolveStorePath: vi.fn(() => "/tmp/sessions.json"),
160+loadSessionStore: vi.fn(() => sessionStore),
161+saveSessionStore: vi.fn(async () => {}),
162+updateSessionStore: vi.fn(async (_storePath, mutator: (store: never) => unknown) =>
163+mutator(sessionStore as never),
164+),
165+getSessionEntry: vi.fn(
166+({ sessionKey }: { sessionKey: string }) => sessionStore[sessionKey] as MockSessionEntry,
167+),
168+patchSessionEntry: vi.fn(
169+async ({
170+ sessionKey,
171+ fallbackEntry,
172+ update,
173+}: {
174+sessionKey: string;
175+fallbackEntry: MockSessionEntry;
176+update: (entry: MockSessionEntry) => Promise<MockSessionEntry> | MockSessionEntry;
177+}) => {
178+const current = (sessionStore[sessionKey] as MockSessionEntry | undefined) ?? fallbackEntry;
179+const patch = await update(current);
180+const next = { ...current, ...patch };
181+sessionStore[sessionKey] = next;
182+return next;
183+},
184+),
185+resolveSessionFilePath: vi.fn(() => "/tmp/session.json"),
186+};
187+}
188+151189function requireRecord(value: unknown, label: string): Record<string, unknown> {
152190if (value === null || typeof value !== "object" || Array.isArray(value)) {
153191throw new Error(`expected ${label} to be a record`);
@@ -364,13 +402,7 @@ describe("createVoiceCallRuntime lifecycle", () => {
364402resolveThinkingDefault: vi.fn(() => "high"),
365403resolveAgentTimeoutMs: vi.fn(() => 30_000),
366404ensureAgentWorkspace: vi.fn(async () => {}),
367-session: {
368-resolveStorePath: vi.fn(() => "/tmp/sessions.json"),
369-loadSessionStore: vi.fn(() => sessionStore),
370-saveSessionStore: vi.fn(async () => {}),
371-updateSessionStore: vi.fn(async (_storePath, mutator) => mutator(sessionStore as never)),
372-resolveSessionFilePath: vi.fn(() => "/tmp/session.json"),
373-},
405+session: createMockSessionRuntime(sessionStore),
374406 runEmbeddedPiAgent,
375407};
376408mocks.managerGetCall.mockReturnValue({
@@ -450,13 +482,7 @@ describe("createVoiceCallRuntime lifecycle", () => {
450482resolveThinkingDefault: vi.fn(() => "high"),
451483resolveAgentTimeoutMs: vi.fn(() => 30_000),
452484ensureAgentWorkspace: vi.fn(async () => {}),
453-session: {
454-resolveStorePath: vi.fn(() => "/tmp/sessions.json"),
455-loadSessionStore: vi.fn(() => sessionStore),
456-saveSessionStore: vi.fn(async () => {}),
457-updateSessionStore: vi.fn(async (_storePath, mutator) => mutator(sessionStore as never)),
458-resolveSessionFilePath: vi.fn(() => "/tmp/session.json"),
459-},
485+session: createMockSessionRuntime(sessionStore),
460486 runEmbeddedPiAgent,
461487};
462488mocks.managerGetCall.mockReturnValue({
@@ -508,13 +534,7 @@ describe("createVoiceCallRuntime lifecycle", () => {
508534resolveThinkingDefault: vi.fn(() => "high"),
509535resolveAgentTimeoutMs: vi.fn(() => 30_000),
510536ensureAgentWorkspace: vi.fn(async () => {}),
511-session: {
512-resolveStorePath: vi.fn(() => "/tmp/sessions.json"),
513-loadSessionStore: vi.fn(() => sessionStore),
514-saveSessionStore: vi.fn(async () => {}),
515-updateSessionStore: vi.fn(async (_storePath, mutator) => mutator(sessionStore as never)),
516-resolveSessionFilePath: vi.fn(() => "/tmp/session.json"),
517-},
537+session: createMockSessionRuntime(sessionStore),
518538 runEmbeddedPiAgent,
519539};
520540mocks.managerGetCall.mockReturnValue({
@@ -582,13 +602,7 @@ describe("createVoiceCallRuntime lifecycle", () => {
582602resolveThinkingDefault: vi.fn(() => "high"),
583603resolveAgentTimeoutMs: vi.fn(() => 30_000),
584604ensureAgentWorkspace: vi.fn(async () => {}),
585-session: {
586-resolveStorePath: vi.fn(() => "/tmp/sessions.json"),
587-loadSessionStore: vi.fn(() => sessionStore),
588-saveSessionStore: vi.fn(async () => {}),
589-updateSessionStore: vi.fn(async (_storePath, mutator) => mutator(sessionStore)),
590-resolveSessionFilePath: vi.fn(() => "/tmp/session.json"),
591-},
605+session: createMockSessionRuntime(sessionStore),
592606 runEmbeddedPiAgent,
593607};
594608mocks.managerGetCall.mockReturnValue({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。