fix(cli-node): forward --no-infer flag to add (#5267)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
098a599579
commit
88934304c6
@@ -46,7 +46,7 @@ export async function cmdAdd(
|
|||||||
file?: string;
|
file?: string;
|
||||||
metadata?: string;
|
metadata?: string;
|
||||||
immutable: boolean;
|
immutable: boolean;
|
||||||
noInfer: boolean;
|
infer?: boolean;
|
||||||
expires?: string;
|
expires?: string;
|
||||||
categories?: string;
|
categories?: string;
|
||||||
output: string;
|
output: string;
|
||||||
@@ -136,7 +136,7 @@ export async function cmdAdd(
|
|||||||
runId: opts.runId,
|
runId: opts.runId,
|
||||||
metadata: meta,
|
metadata: meta,
|
||||||
immutable: opts.immutable,
|
immutable: opts.immutable,
|
||||||
infer: !opts.noInfer,
|
infer: opts.infer !== false,
|
||||||
expires: opts.expires,
|
expires: opts.expires,
|
||||||
categories: cats,
|
categories: cats,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||||
|
import { Command } from "commander";
|
||||||
import { createMockBackend } from "./setup.js";
|
import { createMockBackend } from "./setup.js";
|
||||||
import type { Backend } from "../src/backend/base.js";
|
import type { Backend } from "../src/backend/base.js";
|
||||||
import { setAgentMode } from "../src/state.js";
|
import { setAgentMode } from "../src/state.js";
|
||||||
@@ -41,8 +42,6 @@ describe("cmdAdd", () => {
|
|||||||
await cmdAdd(mockBackend, "I prefer dark mode", {
|
await cmdAdd(mockBackend, "I prefer dark mode", {
|
||||||
userId: "alice",
|
userId: "alice",
|
||||||
immutable: false,
|
immutable: false,
|
||||||
noInfer: false,
|
|
||||||
|
|
||||||
output: "text",
|
output: "text",
|
||||||
});
|
});
|
||||||
expect(mockBackend.add).toHaveBeenCalledOnce();
|
expect(mockBackend.add).toHaveBeenCalledOnce();
|
||||||
@@ -54,8 +53,6 @@ describe("cmdAdd", () => {
|
|||||||
userId: "alice",
|
userId: "alice",
|
||||||
messages: JSON.stringify([{ role: "user", content: "I love Python" }]),
|
messages: JSON.stringify([{ role: "user", content: "I love Python" }]),
|
||||||
immutable: false,
|
immutable: false,
|
||||||
noInfer: false,
|
|
||||||
|
|
||||||
output: "text",
|
output: "text",
|
||||||
});
|
});
|
||||||
expect(mockBackend.add).toHaveBeenCalledOnce();
|
expect(mockBackend.add).toHaveBeenCalledOnce();
|
||||||
@@ -66,8 +63,6 @@ describe("cmdAdd", () => {
|
|||||||
await cmdAdd(mockBackend, "test", {
|
await cmdAdd(mockBackend, "test", {
|
||||||
userId: "alice",
|
userId: "alice",
|
||||||
immutable: false,
|
immutable: false,
|
||||||
noInfer: false,
|
|
||||||
|
|
||||||
output: "json",
|
output: "json",
|
||||||
});
|
});
|
||||||
expect(output).toContain("results");
|
expect(output).toContain("results");
|
||||||
@@ -78,14 +73,59 @@ describe("cmdAdd", () => {
|
|||||||
await cmdAdd(mockBackend, "test", {
|
await cmdAdd(mockBackend, "test", {
|
||||||
userId: "alice",
|
userId: "alice",
|
||||||
immutable: false,
|
immutable: false,
|
||||||
noInfer: false,
|
|
||||||
|
|
||||||
output: "quiet",
|
output: "quiet",
|
||||||
});
|
});
|
||||||
expect(output).not.toContain("dark mode");
|
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", () => {
|
describe("cmdAdd deduplicates PENDING", () => {
|
||||||
const DUPLICATE_PENDING = {
|
const DUPLICATE_PENDING = {
|
||||||
results: [
|
results: [
|
||||||
@@ -100,8 +140,6 @@ describe("cmdAdd deduplicates PENDING", () => {
|
|||||||
await cmdAdd(mockBackend, "test", {
|
await cmdAdd(mockBackend, "test", {
|
||||||
userId: "alice",
|
userId: "alice",
|
||||||
immutable: false,
|
immutable: false,
|
||||||
noInfer: false,
|
|
||||||
|
|
||||||
output: "text",
|
output: "text",
|
||||||
});
|
});
|
||||||
expect(output.match(/Queued/g)?.length).toBe(1);
|
expect(output.match(/Queued/g)?.length).toBe(1);
|
||||||
@@ -113,8 +151,6 @@ describe("cmdAdd deduplicates PENDING", () => {
|
|||||||
await cmdAdd(mockBackend, "test", {
|
await cmdAdd(mockBackend, "test", {
|
||||||
userId: "alice",
|
userId: "alice",
|
||||||
immutable: false,
|
immutable: false,
|
||||||
noInfer: false,
|
|
||||||
|
|
||||||
output: "json",
|
output: "json",
|
||||||
});
|
});
|
||||||
const data = JSON.parse(output);
|
const data = JSON.parse(output);
|
||||||
@@ -129,8 +165,6 @@ describe("cmdAdd deduplicates PENDING", () => {
|
|||||||
await cmdAdd(mockBackend, "test", {
|
await cmdAdd(mockBackend, "test", {
|
||||||
userId: "alice",
|
userId: "alice",
|
||||||
immutable: false,
|
immutable: false,
|
||||||
noInfer: false,
|
|
||||||
|
|
||||||
output: "agent",
|
output: "agent",
|
||||||
});
|
});
|
||||||
const data = JSON.parse(output);
|
const data = JSON.parse(output);
|
||||||
@@ -315,8 +349,6 @@ describe("agent mode", () => {
|
|||||||
await cmdAdd(mockBackend, "test preference", {
|
await cmdAdd(mockBackend, "test preference", {
|
||||||
userId: "alice",
|
userId: "alice",
|
||||||
immutable: false,
|
immutable: false,
|
||||||
noInfer: false,
|
|
||||||
|
|
||||||
output: "agent",
|
output: "agent",
|
||||||
});
|
});
|
||||||
const parsed = JSON.parse(output.trim());
|
const parsed = JSON.parse(output.trim());
|
||||||
|
|||||||
Reference in New Issue
Block a user