




















@@ -22,6 +22,7 @@ function createState(): { state: DreamingState; request: ReturnType<typeof vi.fn
2222 request,
2323} as unknown as DreamingState["client"],
2424connected: true,
25+hello: null,
2526configSnapshot: { hash: "hash-1" },
2627applySessionKey: "main",
2728dreamingStatusLoading: false,
@@ -227,6 +228,11 @@ describe("dreaming controller", () => {
227228228229it("loads and normalizes wiki import insights", async () => {
229230const { state, request } = createState();
231+state.hello = {
232+type: "hello-ok",
233+protocol: 3,
234+features: { methods: ["wiki.importInsights"] },
235+};
230236state.configSnapshot = {
231237hash: "hash-1",
232238config: {
@@ -297,6 +303,40 @@ describe("dreaming controller", () => {
297303expect(state.wikiImportInsightsLoading).toBe(false);
298304});
299305306+it("falls back to config gating for wiki import insights when methods are not advertised", async () => {
307+const { state, request } = createState();
308+state.configSnapshot = {
309+hash: "hash-1",
310+config: {
311+plugins: {
312+entries: {
313+"memory-wiki": {
314+enabled: true,
315+},
316+},
317+},
318+},
319+};
320+request.mockResolvedValue({
321+sourceType: "chatgpt",
322+totalItems: 1,
323+totalClusters: 1,
324+clusters: [],
325+});
326+327+await loadWikiImportInsights(state);
328+329+expect(request).toHaveBeenCalledWith("wiki.importInsights", {});
330+expect(state.wikiImportInsights).toEqual(
331+expect.objectContaining({
332+totalItems: 1,
333+totalClusters: 1,
334+}),
335+);
336+expect(state.wikiImportInsightsError).toBeNull();
337+expect(state.wikiImportInsightsLoading).toBe(false);
338+});
339+300340it("skips wiki import insights when memory-wiki is not enabled", async () => {
301341const { state, request } = createState();
302342state.configSnapshot = {
@@ -321,8 +361,48 @@ describe("dreaming controller", () => {
321361expect(state.wikiImportInsightsLoading).toBe(false);
322362});
323363364+it("skips wiki import insights when the gateway does not advertise the method", async () => {
365+const { state, request } = createState();
366+state.hello = {
367+type: "hello-ok",
368+protocol: 3,
369+features: { methods: ["doctor.memory.status"] },
370+};
371+state.configSnapshot = {
372+hash: "hash-1",
373+config: {
374+plugins: {
375+entries: {
376+"memory-wiki": {
377+enabled: true,
378+},
379+},
380+},
381+},
382+};
383+state.wikiImportInsights = {
384+sourceType: "chatgpt",
385+totalItems: 1,
386+totalClusters: 1,
387+clusters: [],
388+};
389+state.wikiImportInsightsError = "unknown method: wiki.importInsights";
390+391+await loadWikiImportInsights(state);
392+393+expect(request).not.toHaveBeenCalled();
394+expect(state.wikiImportInsights).toBeNull();
395+expect(state.wikiImportInsightsError).toBeNull();
396+expect(state.wikiImportInsightsLoading).toBe(false);
397+});
398+324399it("loads and normalizes the wiki memory palace", async () => {
325400const { state, request } = createState();
401+state.hello = {
402+type: "hello-ok",
403+protocol: 3,
404+features: { methods: ["wiki.palace"] },
405+};
326406state.configSnapshot = {
327407hash: "hash-1",
328408config: {
@@ -391,6 +471,41 @@ describe("dreaming controller", () => {
391471expect(state.wikiMemoryPalaceLoading).toBe(false);
392472});
393473474+it("falls back to config gating for wiki memory palace when methods are not advertised", async () => {
475+const { state, request } = createState();
476+state.configSnapshot = {
477+hash: "hash-1",
478+config: {
479+plugins: {
480+entries: {
481+"memory-wiki": {
482+enabled: true,
483+},
484+},
485+},
486+},
487+};
488+request.mockResolvedValue({
489+totalItems: 1,
490+totalClaims: 2,
491+totalQuestions: 0,
492+totalContradictions: 0,
493+clusters: [],
494+});
495+496+await loadWikiMemoryPalace(state);
497+498+expect(request).toHaveBeenCalledWith("wiki.palace", {});
499+expect(state.wikiMemoryPalace).toEqual(
500+expect.objectContaining({
501+totalItems: 1,
502+totalClaims: 2,
503+}),
504+);
505+expect(state.wikiMemoryPalaceError).toBeNull();
506+expect(state.wikiMemoryPalaceLoading).toBe(false);
507+});
508+394509it("skips wiki memory palace when memory-wiki is not enabled", async () => {
395510const { state, request } = createState();
396511state.configSnapshot = {
@@ -416,6 +531,42 @@ describe("dreaming controller", () => {
416531expect(state.wikiMemoryPalaceLoading).toBe(false);
417532});
418533534+it("skips wiki memory palace when the gateway does not advertise the method", async () => {
535+const { state, request } = createState();
536+state.hello = {
537+type: "hello-ok",
538+protocol: 3,
539+features: { methods: ["doctor.memory.status"] },
540+};
541+state.configSnapshot = {
542+hash: "hash-1",
543+config: {
544+plugins: {
545+entries: {
546+"memory-wiki": {
547+enabled: true,
548+},
549+},
550+},
551+},
552+};
553+state.wikiMemoryPalace = {
554+totalItems: 1,
555+totalClaims: 1,
556+totalQuestions: 0,
557+totalContradictions: 0,
558+clusters: [],
559+};
560+state.wikiMemoryPalaceError = "unknown method: wiki.palace";
561+562+await loadWikiMemoryPalace(state);
563+564+expect(request).not.toHaveBeenCalled();
565+expect(state.wikiMemoryPalace).toBeNull();
566+expect(state.wikiMemoryPalaceError).toBeNull();
567+expect(state.wikiMemoryPalaceLoading).toBe(false);
568+});
569+419570it("patches config to update global dreaming enablement", async () => {
420571const { state, request } = createState();
421572state.configSnapshot = {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。