diff --git a/cli/node/src/commands/memory.ts b/cli/node/src/commands/memory.ts index dd3a08211..3b7b67b4f 100644 --- a/cli/node/src/commands/memory.ts +++ b/cli/node/src/commands/memory.ts @@ -46,7 +46,7 @@ export async function cmdAdd( file?: string; metadata?: string; immutable: boolean; - noInfer: boolean; + infer?: boolean; expires?: string; categories?: string; output: string; @@ -136,7 +136,7 @@ export async function cmdAdd( runId: opts.runId, metadata: meta, immutable: opts.immutable, - infer: !opts.noInfer, + infer: opts.infer !== false, expires: opts.expires, categories: cats, }); diff --git a/cli/node/tests/commands.test.ts b/cli/node/tests/commands.test.ts index 0d67a03af..4cd43d1be 100644 --- a/cli/node/tests/commands.test.ts +++ b/cli/node/tests/commands.test.ts @@ -3,6 +3,7 @@ */ import { describe, it, expect, vi, beforeEach } from "vitest"; +import { Command } from "commander"; import { createMockBackend } from "./setup.js"; import type { Backend } from "../src/backend/base.js"; import { setAgentMode } from "../src/state.js"; @@ -41,8 +42,6 @@ describe("cmdAdd", () => { await cmdAdd(mockBackend, "I prefer dark mode", { userId: "alice", immutable: false, - noInfer: false, - output: "text", }); expect(mockBackend.add).toHaveBeenCalledOnce(); @@ -54,8 +53,6 @@ describe("cmdAdd", () => { userId: "alice", messages: JSON.stringify([{ role: "user", content: "I love Python" }]), immutable: false, - noInfer: false, - output: "text", }); expect(mockBackend.add).toHaveBeenCalledOnce(); @@ -66,8 +63,6 @@ describe("cmdAdd", () => { await cmdAdd(mockBackend, "test", { userId: "alice", immutable: false, - noInfer: false, - output: "json", }); expect(output).toContain("results"); @@ -78,14 +73,59 @@ describe("cmdAdd", () => { await cmdAdd(mockBackend, "test", { userId: "alice", immutable: false, - noInfer: false, - output: "quiet", }); expect(output).not.toContain("dark mode"); }); }); +describe("cmdAdd forwards --no-infer (regression for #5261)", () => { + it("forwards infer: false when --no-infer is set", async () => { + const { cmdAdd } = await import("../src/commands/memory.js"); + // `infer: false` is the shape Commander produces for `--no-infer`. + await cmdAdd(mockBackend, "store me verbatim", { + userId: "alice", + immutable: false, + infer: false, + output: "text", + }); + expect(mockBackend.add).toHaveBeenCalledWith( + "store me verbatim", + undefined, + expect.objectContaining({ infer: false }), + ); + }); + + it("forwards infer: true by default (flag absent)", async () => { + const { cmdAdd } = await import("../src/commands/memory.js"); + await cmdAdd(mockBackend, "infer me", { + userId: "alice", + immutable: false, + output: "text", + }); + expect(mockBackend.add).toHaveBeenCalledWith( + "infer me", + undefined, + expect.objectContaining({ infer: true }), + ); + }); + + it("Commander stores --no-infer as opts.infer, not opts.noInfer", () => { + // Pins the assumption the fix relies on: Commander's `--no-X` option + // populates the positive camelCase key (`infer`), never `noInfer`. + const withFlag = new Command(); + withFlag.option("--no-infer", "Skip inference, store raw.").action(() => {}); + withFlag.parse(["--no-infer"], { from: "user" }); + expect(withFlag.opts().infer).toBe(false); + expect(withFlag.opts().noInfer).toBeUndefined(); + + const withoutFlag = new Command(); + withoutFlag.option("--no-infer", "Skip inference, store raw.").action(() => {}); + withoutFlag.parse([], { from: "user" }); + expect(withoutFlag.opts().infer).toBe(true); + }); +}); + describe("cmdAdd deduplicates PENDING", () => { const DUPLICATE_PENDING = { results: [ @@ -100,8 +140,6 @@ describe("cmdAdd deduplicates PENDING", () => { await cmdAdd(mockBackend, "test", { userId: "alice", immutable: false, - noInfer: false, - output: "text", }); expect(output.match(/Queued/g)?.length).toBe(1); @@ -113,8 +151,6 @@ describe("cmdAdd deduplicates PENDING", () => { await cmdAdd(mockBackend, "test", { userId: "alice", immutable: false, - noInfer: false, - output: "json", }); const data = JSON.parse(output); @@ -129,8 +165,6 @@ describe("cmdAdd deduplicates PENDING", () => { await cmdAdd(mockBackend, "test", { userId: "alice", immutable: false, - noInfer: false, - output: "agent", }); const data = JSON.parse(output); @@ -315,8 +349,6 @@ describe("agent mode", () => { await cmdAdd(mockBackend, "test preference", { userId: "alice", immutable: false, - noInfer: false, - output: "agent", }); const parsed = JSON.parse(output.trim());