





















@@ -84,6 +84,19 @@ function findGatewayHandler(
8484return registerGatewayMethod.mock.calls.find((call) => call[0] === method)?.[1];
8585}
868687+function readRespondPayload(respond: { mock: { calls: Array<Array<unknown>> } }): unknown {
88+const call = respond.mock.calls[0];
89+expect(call?.[0]).toBe(true);
90+return call?.[1];
91+}
92+93+function readRespondError(respond: { mock: { calls: Array<Array<unknown>> } }): unknown {
94+const call = respond.mock.calls[0];
95+expect(call?.[0]).toBe(false);
96+expect(call?.[1]).toBeUndefined();
97+return call?.[2];
98+}
99+87100describe("memory-wiki gateway methods", () => {
88101beforeEach(() => {
89102vi.clearAllMocks();
@@ -161,13 +174,10 @@ describe("memory-wiki gateway methods", () => {
161174expect(resolveMemoryWikiStatus).toHaveBeenCalledWith(config, {
162175appConfig: undefined,
163176});
164-expect(respond).toHaveBeenCalledWith(
165-true,
166-expect.objectContaining({
167-vaultMode: "isolated",
168-vaultExists: true,
169-}),
170-);
177+expect(readRespondPayload(respond)).toEqual({
178+vaultMode: "isolated",
179+vaultExists: true,
180+});
171181});
172182173183it("returns recent import runs over the gateway", async () => {
@@ -210,13 +220,27 @@ describe("memory-wiki gateway methods", () => {
210220});
211221212222expect(listMemoryWikiImportRuns).toHaveBeenCalledWith(config, { limit: 5 });
213-expect(respond).toHaveBeenCalledWith(
214-true,
215-expect.objectContaining({
216-totalRuns: 1,
217-activeRuns: 1,
218-}),
219-);
223+expect(readRespondPayload(respond)).toEqual({
224+runs: [
225+{
226+runId: "chatgpt-abc123",
227+importType: "chatgpt",
228+appliedAt: "2026-04-10T10:00:00.000Z",
229+exportPath: "/tmp/chatgpt",
230+sourcePath: "/tmp/chatgpt/conversations.json",
231+conversationCount: 12,
232+createdCount: 4,
233+updatedCount: 2,
234+skippedCount: 6,
235+status: "applied",
236+pagePaths: ["sources/chatgpt-2026-04-10-alpha.md"],
237+samplePaths: ["sources/chatgpt-2026-04-10-alpha.md"],
238+},
239+],
240+totalRuns: 1,
241+activeRuns: 1,
242+rolledBackRuns: 0,
243+});
220244});
221245222246it("returns import insights over the gateway", async () => {
@@ -267,14 +291,36 @@ describe("memory-wiki gateway methods", () => {
267291268292expect(syncMemoryWikiImportedSources).toHaveBeenCalledWith({ config, appConfig: undefined });
269293expect(listMemoryWikiImportInsights).toHaveBeenCalledWith(config);
270-expect(respond).toHaveBeenCalledWith(
271-true,
272-expect.objectContaining({
273-sourceType: "chatgpt",
274-totalItems: 2,
275-totalClusters: 1,
276-}),
277-);
294+expect(readRespondPayload(respond)).toEqual({
295+sourceType: "chatgpt",
296+totalItems: 2,
297+totalClusters: 1,
298+clusters: [
299+{
300+key: "topic/travel",
301+label: "Travel",
302+itemCount: 2,
303+highRiskCount: 1,
304+withheldCount: 1,
305+preferenceSignalCount: 0,
306+updatedAt: "2026-04-10T10:00:00.000Z",
307+items: [
308+{
309+pagePath: "sources/chatgpt-2026-04-10-alpha.md",
310+title: "BA flight receipts process",
311+riskLevel: "low",
312+labels: ["domain/personal", "area/travel", "topic/travel"],
313+topicKey: "topic/travel",
314+topicLabel: "Travel",
315+digestStatus: "available",
316+firstUserLine: "how do i get receipts?",
317+lastUserLine: "that option does not exist",
318+preferenceSignals: [],
319+},
320+],
321+},
322+],
323+});
278324});
279325280326it("returns memory palace overview over the gateway", async () => {
@@ -324,13 +370,35 @@ describe("memory-wiki gateway methods", () => {
324370325371expect(syncMemoryWikiImportedSources).toHaveBeenCalledWith({ config, appConfig: undefined });
326372expect(listMemoryWikiPalace).toHaveBeenCalledWith(config);
327-expect(respond).toHaveBeenCalledWith(
328-true,
329-expect.objectContaining({
330-totalItems: 3,
331-totalClaims: 4,
332-}),
333-);
373+expect(readRespondPayload(respond)).toEqual({
374+totalItems: 3,
375+totalClaims: 4,
376+totalQuestions: 1,
377+totalContradictions: 1,
378+clusters: [
379+{
380+key: "synthesis",
381+label: "Syntheses",
382+itemCount: 1,
383+claimCount: 2,
384+questionCount: 1,
385+contradictionCount: 0,
386+items: [
387+{
388+pagePath: "syntheses/travel-system.md",
389+title: "Travel system",
390+kind: "synthesis",
391+claimCount: 2,
392+questionCount: 1,
393+contradictionCount: 0,
394+claims: ["prefers direct receipts"],
395+questions: ["should this become a playbook?"],
396+contradictions: [],
397+},
398+],
399+},
400+],
401+});
334402});
335403336404it("validates required query params for wiki.search", async () => {
@@ -350,11 +418,10 @@ describe("memory-wiki gateway methods", () => {
350418});
351419352420expect(searchMemoryWiki).not.toHaveBeenCalled();
353-expect(respond).toHaveBeenCalledWith(
354-false,
355-undefined,
356-expect.objectContaining({ message: "query is required." }),
357-);
421+expect(readRespondError(respond)).toEqual({
422+code: "internal_error",
423+message: "query is required.",
424+});
358425});
359426360427it("forwards wiki.search mode and corpus options over the gateway", async () => {
@@ -379,18 +446,19 @@ describe("memory-wiki gateway methods", () => {
379446 respond,
380447});
381448382-expect(searchMemoryWiki).toHaveBeenCalledWith(
383-expect.objectContaining({
384- config,
385-appConfig: undefined,
386-query: "Teams Azure",
387-maxResults: 3,
388-searchBackend: "local",
389-searchCorpus: "wiki",
390-mode: "route-question",
391-}),
392-);
393-expect(respond).toHaveBeenCalledWith(true, expect.anything());
449+expect(searchMemoryWiki).toHaveBeenCalledWith({
450+ config,
451+appConfig: undefined,
452+query: "Teams Azure",
453+maxResults: 3,
454+searchBackend: "local",
455+searchCorpus: "wiki",
456+mode: "route-question",
457+});
458+expect(readRespondPayload(respond)).toEqual({
459+items: [],
460+total: 0,
461+});
394462});
395463396464it("forwards ingest requests over the gateway", async () => {
@@ -417,12 +485,9 @@ describe("memory-wiki gateway methods", () => {
417485inputPath: "/tmp/alpha-notes.txt",
418486title: "Alpha",
419487});
420-expect(respond).toHaveBeenCalledWith(
421-true,
422-expect.objectContaining({
423-pagePath: "sources/alpha-notes.md",
424-}),
425-);
488+expect(readRespondPayload(respond)).toEqual({
489+pagePath: "sources/alpha-notes.md",
490+});
426491});
427492428493it("applies wiki mutations over the gateway", async () => {
@@ -450,17 +515,16 @@ describe("memory-wiki gateway methods", () => {
450515expect(normalizeMemoryWikiMutationInput).toHaveBeenCalledWith(params);
451516expect(applyMemoryWikiMutation).toHaveBeenCalledWith({
452517 config,
453-mutation: expect.objectContaining({
518+mutation: {
454519op: "create_synthesis",
455520title: "Gateway Alpha",
456-}),
521+body: "Gateway summary.",
522+sourceIds: ["source.alpha"],
523+},
524+});
525+expect(readRespondPayload(respond)).toEqual({
526+operation: "create_synthesis",
527+pagePath: "syntheses/gateway-alpha.md",
457528});
458-expect(respond).toHaveBeenCalledWith(
459-true,
460-expect.objectContaining({
461-operation: "create_synthesis",
462-pagePath: "syntheses/gateway-alpha.md",
463-}),
464-);
465529});
466530});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。