






















@@ -142,6 +142,23 @@ describe("memory cli", () => {
142142);
143143}
144144145+const ansiPattern = /\u001B\[[0-?]*[ -/]*[@-~]/g;
146+147+function loggedOutput(spy: ReturnType<typeof vi.spyOn>) {
148+return spy.mock.calls
149+.map((call: unknown[]) => (typeof call[0] === "string" ? call[0] : ""))
150+.join("\n")
151+.replace(ansiPattern, "");
152+}
153+154+function expectLogged(spy: ReturnType<typeof vi.spyOn>, expected: string) {
155+expect(loggedOutput(spy)).toContain(expected);
156+}
157+158+function expectNotLogged(spy: ReturnType<typeof vi.spyOn>, expected: string) {
159+expect(loggedOutput(spy)).not.toContain(expected);
160+}
161+145162async function runMemoryCli(args: string[]) {
146163const program = new Command();
147164program.name("test");
@@ -241,14 +258,12 @@ describe("memory cli", () => {
241258await runMemoryCli(["status"]);
242259243260expect(probeVectorAvailability).not.toHaveBeenCalled();
244-expect(log).toHaveBeenCalledWith(expect.stringContaining("Vector store: ready"));
245-expect(log).toHaveBeenCalledWith(expect.stringContaining("Semantic vectors: ready"));
246-expect(log).toHaveBeenCalledWith(expect.stringContaining("Vector dims: 1024"));
247-expect(log).toHaveBeenCalledWith(expect.stringContaining("Vector path: /opt/sqlite-vec.dylib"));
248-expect(log).toHaveBeenCalledWith(expect.stringContaining("FTS: ready"));
249-expect(log).toHaveBeenCalledWith(
250-expect.stringContaining("Embedding cache: enabled (123 entries)"),
251-);
261+expectLogged(log, "Vector store: ready");
262+expectLogged(log, "Semantic vectors: ready");
263+expectLogged(log, "Vector dims: 1024");
264+expectLogged(log, "Vector path: /opt/sqlite-vec.dylib");
265+expectLogged(log, "FTS: ready");
266+expectLogged(log, "Embedding cache: enabled (123 entries)");
252267expect(close).toHaveBeenCalled();
253268});
254269@@ -277,8 +292,8 @@ describe("memory cli", () => {
277292278293expect(probeVectorAvailability).not.toHaveBeenCalled();
279294expect(probeEmbeddingAvailability).not.toHaveBeenCalled();
280-expect(log).toHaveBeenCalledWith(expect.stringContaining("Provider: auto"));
281-expect(log).toHaveBeenCalledWith(expect.stringContaining("Vector store: unknown"));
295+expectLogged(log, "Provider: auto");
296+expectLogged(log, "Vector store: unknown");
282297expect(close).toHaveBeenCalled();
283298});
284299@@ -366,9 +381,9 @@ describe("memory cli", () => {
366381const log = spyRuntimeLogs(defaultRuntime);
367382await runMemoryCli(["status", "--agent", "main"]);
368383369-expect(log).toHaveBeenCalledWith(expect.stringContaining("Vector store: unavailable"));
370-expect(log).toHaveBeenCalledWith(expect.stringContaining("Semantic vectors: unavailable"));
371-expect(log).toHaveBeenCalledWith(expect.stringContaining("Vector error: load failed"));
384+expectLogged(log, "Vector store: unavailable");
385+expectLogged(log, "Semantic vectors: unavailable");
386+expectLogged(log, "Vector error: load failed");
372387expect(close).toHaveBeenCalled();
373388});
374389@@ -391,7 +406,7 @@ describe("memory cli", () => {
391406expect(probeVectorStoreAvailability).toHaveBeenCalled();
392407expect(probeVectorAvailability).toHaveBeenCalled();
393408expect(probeEmbeddingAvailability).toHaveBeenCalled();
394-expect(log).toHaveBeenCalledWith(expect.stringContaining("Embeddings: ready"));
409+expectLogged(log, "Embeddings: ready");
395410expect(close).toHaveBeenCalled();
396411});
397412@@ -427,12 +442,10 @@ describe("memory cli", () => {
427442expect(probeVectorStoreAvailability).toHaveBeenCalled();
428443expect(probeEmbeddingAvailability).toHaveBeenCalled();
429444expect(probeVectorAvailability).toHaveBeenCalled();
430-expect(log).toHaveBeenCalledWith(expect.stringContaining("Vector store: ready"));
431-expect(log).toHaveBeenCalledWith(expect.stringContaining("Semantic vectors: unavailable"));
432-expect(log).toHaveBeenCalledWith(expect.stringContaining("Embeddings: unavailable"));
433-expect(log).toHaveBeenCalledWith(
434-expect.stringContaining("Embeddings error: No embedding provider available"),
435-);
445+expectLogged(log, "Vector store: ready");
446+expectLogged(log, "Semantic vectors: unavailable");
447+expectLogged(log, "Embeddings: unavailable");
448+expectLogged(log, "Embeddings error: No embedding provider available");
436449expect(close).toHaveBeenCalled();
437450});
438451@@ -466,8 +479,8 @@ describe("memory cli", () => {
466479expect(probeVectorStoreAvailability).not.toHaveBeenCalled();
467480expect(probeVectorAvailability).toHaveBeenCalled();
468481expect(probeEmbeddingAvailability).toHaveBeenCalled();
469-expect(log).toHaveBeenCalledWith(expect.stringContaining("Vector: ready"));
470-expect(log).not.toHaveBeenCalledWith(expect.stringContaining("Vector store:"));
482+expectLogged(log, "Vector: ready");
483+expectNotLogged(log, "Vector store:");
471484expect(close).toHaveBeenCalled();
472485});
473486@@ -498,8 +511,8 @@ describe("memory cli", () => {
498511const log = spyRuntimeLogs(defaultRuntime);
499512await runMemoryCli(["status"]);
500513501-expect(log).toHaveBeenCalledWith(expect.stringContaining("Recall store: 1 entries"));
502-expect(log).toHaveBeenCalledWith(expect.stringContaining("Dreaming: off"));
514+expectLogged(log, "Recall store: 1 entries");
515+expectLogged(log, "Dreaming: off");
503516expect(close).toHaveBeenCalled();
504517});
505518});
@@ -553,7 +566,7 @@ describe("memory cli", () => {
553566const log = spyRuntimeLogs(defaultRuntime);
554567await runMemoryCli(["status", "--fix"]);
555568556-expect(log).toHaveBeenCalledWith(expect.stringContaining("Repair: rewrote store"));
569+expectLogged(log, "Repair: rewrote store");
557570await expect(fs.stat(lockPath)).rejects.toThrow();
558571const repaired = JSON.parse(await fs.readFile(storePath, "utf-8")) as {
559572entries: Record<string, { conceptTags?: string[] }>;
@@ -577,9 +590,7 @@ describe("memory cli", () => {
577590578591const log = spyRuntimeLogs(defaultRuntime);
579592await runMemoryCli(["status"]);
580-expect(log).toHaveBeenCalledWith(
581-expect.stringContaining("Fix: openclaw memory status --fix --agent main"),
582-);
593+expectLogged(log, "Fix: openclaw memory status --fix --agent main");
583594584595log.mockClear();
585596mockManager({
@@ -588,9 +599,7 @@ describe("memory cli", () => {
588599 close,
589600});
590601await runMemoryCli(["status", "--fix"]);
591-expect(log).not.toHaveBeenCalledWith(
592-expect.stringContaining("Fix: openclaw memory status --fix --agent main"),
593-);
602+expectNotLogged(log, "Fix: openclaw memory status --fix --agent main");
594603});
595604});
596605@@ -623,10 +632,8 @@ describe("memory cli", () => {
623632const log = spyRuntimeLogs(defaultRuntime);
624633await runMemoryCli(["status", "--fix"]);
625634626-expect(log).toHaveBeenCalledWith(
627-expect.stringContaining("Dream repair: archived session corpus"),
628-);
629-expect(log).toHaveBeenCalledWith(expect.stringContaining("Dream archive:"));
635+expectLogged(log, "Dream repair: archived session corpus");
636+expectLogged(log, "Dream archive:");
630637await expect(fs.access(sessionCorpusDir)).rejects.toMatchObject({ code: "ENOENT" });
631638await expect(
632639fs.access(path.join(workspaceDir, "memory", ".dreams", "session-ingestion.json")),
@@ -746,7 +753,7 @@ describe("memory cli", () => {
746753await runMemoryCli(["index"]);
747754748755expectCliSync(sync);
749-expect(log).toHaveBeenCalledWith(expect.stringContaining("QMD index: "));
756+expectLogged(log, "QMD index: ");
750757expect(log).toHaveBeenCalledWith("Memory index updated (main).");
751758expect(close).toHaveBeenCalled();
752759});
@@ -776,8 +783,8 @@ describe("memory cli", () => {
776783const log = spyRuntimeLogs(defaultRuntime);
777784await runMemoryCli(["status"]);
778785779-expect(log).toHaveBeenCalledWith(expect.stringContaining("QMD audit:"));
780-expect(log).toHaveBeenCalledWith(expect.stringContaining("2 collections"));
786+expectLogged(log, "QMD audit:");
787+expectLogged(log, "2 collections");
781788expect(close).toHaveBeenCalled();
782789});
783790});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。