Skip to content

Commit ba2620a

Browse files
committed
fix(memory-lancedb): centralize cli integer parsing
1 parent 182d605 commit ba2620a

2 files changed

Lines changed: 71 additions & 2 deletions

File tree

extensions/memory-lancedb/index.test.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import { Buffer } from "node:buffer";
1212
import fs from "node:fs/promises";
1313
import path from "node:path";
14+
import { Command } from "commander";
1415
import {
1516
clearMemoryPluginState,
1617
getMemoryCapabilityRegistration,
@@ -708,6 +709,73 @@ describe("memory plugin e2e", () => {
708709
});
709710
});
710711

712+
test("normalizes signed decimal CLI limits through the shared parser", async () => {
713+
const ensureGlobalUndiciEnvProxyDispatcher = vi.fn();
714+
const toArray = vi.fn(async () => []);
715+
const limit = vi.fn(() => ({ toArray }));
716+
const select = vi.fn(() => ({ limit, toArray }));
717+
const query = vi.fn(() => ({ select }));
718+
const loadLanceDbModule = vi.fn(async () => ({
719+
connect: vi.fn(async () => ({
720+
tableNames: vi.fn(async () => ["memories"]),
721+
openTable: vi.fn(async () => ({
722+
query,
723+
countRows: vi.fn(async () => 0),
724+
add: vi.fn(async () => undefined),
725+
delete: vi.fn(async () => undefined),
726+
})),
727+
})),
728+
}));
729+
730+
await withMockedOpenAiMemoryPlugin({
731+
ensureGlobalUndiciEnvProxyDispatcher,
732+
loadLanceDbModule,
733+
run: async (dynamicMemoryPlugin) => {
734+
const registerCli = vi.fn();
735+
const mockApi = {
736+
id: "memory-lancedb",
737+
name: "Memory (LanceDB)",
738+
source: "test",
739+
config: {},
740+
pluginConfig: {
741+
embedding: {
742+
apiKey: OPENAI_API_KEY,
743+
model: "text-embedding-3-small",
744+
},
745+
dbPath: getDbPath(),
746+
autoCapture: false,
747+
autoRecall: false,
748+
},
749+
runtime: {},
750+
logger: {
751+
info: vi.fn(),
752+
warn: vi.fn(),
753+
error: vi.fn(),
754+
debug: vi.fn(),
755+
},
756+
registerTool: vi.fn(),
757+
registerCli,
758+
registerService: vi.fn(),
759+
on: vi.fn(),
760+
resolvePath: (filePath: string) => filePath,
761+
};
762+
const log = vi.spyOn(console, "log").mockImplementation(() => undefined);
763+
try {
764+
dynamicMemoryPlugin.register(mockApi as any);
765+
const registrar = firstMockArg(registerCli as unknown as MockCallSource, "cli registrar");
766+
const program = new Command();
767+
(registrar as (params: { program: Command }) => void)({ program });
768+
769+
await program.parseAsync(["node", "openclaw", "ltm", "list", "--limit", "+03"]);
770+
771+
expect(limit).toHaveBeenCalledWith(3);
772+
} finally {
773+
log.mockRestore();
774+
}
775+
},
776+
});
777+
});
778+
711779
test("keeps before_prompt_build registered but inert when auto-recall is disabled", async () => {
712780
const on = vi.fn();
713781
const mockApi = {

extensions/memory-lancedb/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from "openclaw/plugin-sdk/channel-actions";
1616
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
1717
import type { MemoryEmbeddingProvider } from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
18+
import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";
1819
import { readFiniteNumberParam, readPositiveIntegerParam } from "openclaw/plugin-sdk/param-readers";
1920
import { resolveLivePluginConfigObject } from "openclaw/plugin-sdk/plugin-config-runtime";
2021
import { ensureGlobalUndiciEnvProxyDispatcher } from "openclaw/plugin-sdk/runtime-env";
@@ -196,8 +197,8 @@ function parsePositiveIntegerOption(value: string | undefined, flag: string): nu
196197
if (value === undefined) {
197198
return undefined;
198199
}
199-
const parsed = Number(value);
200-
if (!Number.isInteger(parsed) || parsed < 1) {
200+
const parsed = parseStrictPositiveInteger(value);
201+
if (parsed === undefined) {
201202
throw new Error(`${flag} must be a positive integer`);
202203
}
203204
return parsed;

0 commit comments

Comments
 (0)