mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-05 21:52:56 +00:00
fix(memory-core): centralize cli integer parsing
This commit is contained in:
@@ -1108,10 +1108,10 @@ describe("memory cli", () => {
|
||||
mockManager({ search, close });
|
||||
|
||||
const log = spyRuntimeLogs(defaultRuntime);
|
||||
await runMemoryCli(["search", "hello"]);
|
||||
await runMemoryCli(["search", "hello", "--max-results", "+02"]);
|
||||
|
||||
expect(search).toHaveBeenCalledWith("hello", {
|
||||
maxResults: undefined,
|
||||
maxResults: 2,
|
||||
minScore: undefined,
|
||||
sessionKey: "agent:main:cli:direct:memory-search",
|
||||
});
|
||||
@@ -1235,12 +1235,14 @@ describe("memory cli", () => {
|
||||
await runMemoryCli([
|
||||
"promote",
|
||||
"--json",
|
||||
"--limit",
|
||||
"+01",
|
||||
"--min-score",
|
||||
"0",
|
||||
"--min-recall-count",
|
||||
"0",
|
||||
"+0",
|
||||
"--min-unique-queries",
|
||||
"0",
|
||||
"00",
|
||||
]);
|
||||
|
||||
const payload = firstWrittenJsonArg<{ candidates: unknown[] }>(writeJson);
|
||||
|
||||
@@ -4,6 +4,10 @@ import {
|
||||
formatHelpExamples,
|
||||
theme,
|
||||
} from "openclaw/plugin-sdk/memory-core-host-runtime-cli";
|
||||
import {
|
||||
parseStrictNonNegativeInteger,
|
||||
parseStrictPositiveInteger,
|
||||
} from "openclaw/plugin-sdk/number-runtime";
|
||||
import type {
|
||||
MemoryCommandOptions,
|
||||
MemoryPromoteCommandOptions,
|
||||
@@ -28,7 +32,6 @@ async function loadMemoryCliRuntime(): Promise<MemoryCliRuntime> {
|
||||
}
|
||||
|
||||
const DECIMAL_NUMBER_RE = /^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/;
|
||||
const DECIMAL_INTEGER_RE = /^\d+$/;
|
||||
|
||||
export async function runMemoryStatus(opts: MemoryCommandOptions) {
|
||||
const runtime = await loadMemoryCliRuntime();
|
||||
@@ -87,18 +90,16 @@ function parseMemoryCliNumberOption(value: string, flag: string): number {
|
||||
}
|
||||
|
||||
function parseMemoryCliPositiveIntegerOption(value: string, flag: string): number {
|
||||
const trimmed = value.trim();
|
||||
const parsed = DECIMAL_INTEGER_RE.test(trimmed) ? Number(trimmed) : Number.NaN;
|
||||
if (!Number.isSafeInteger(parsed) || parsed < 1) {
|
||||
const parsed = parseStrictPositiveInteger(value);
|
||||
if (parsed === undefined) {
|
||||
throw invalidCliArgument(`${flag} must be a positive integer.`);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function parseMemoryCliNonNegativeIntegerOption(value: string, flag: string): number {
|
||||
const trimmed = value.trim();
|
||||
const parsed = DECIMAL_INTEGER_RE.test(trimmed) ? Number(trimmed) : Number.NaN;
|
||||
if (!Number.isSafeInteger(parsed) || parsed < 0) {
|
||||
const parsed = parseStrictNonNegativeInteger(value);
|
||||
if (parsed === undefined) {
|
||||
throw invalidCliArgument(`${flag} must be a non-negative integer.`);
|
||||
}
|
||||
return parsed;
|
||||
|
||||
Reference in New Issue
Block a user