fix(qa): reject loose code-mode live task limits

This commit is contained in:
Vincent Koc
2026-06-16 21:11:16 +02:00
parent 319e41d0c5
commit fd166a5318
4 changed files with 60 additions and 12 deletions
+29 -12
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env -S node --import tsx
// Code Mode Namespace Live script supports OpenClaw repository automation.
import { performance } from "node:perf_hooks";
import { pathToFileURL } from "node:url";
import { Type } from "typebox";
import type { Model } from "../../packages/agent-core/src/llm.js";
import type { AgentEvent, AgentTool } from "../../packages/agent-core/src/types.js";
@@ -80,6 +81,7 @@ type RunMetrics = {
};
const PLUGIN_ID = "fictions-live";
const POSITIVE_INTEGER_PATTERN = /^[1-9]\d*$/u;
function cloneState(): FictionServiceState {
return {
@@ -598,19 +600,32 @@ function readArg(name: string): string | undefined {
return match?.slice(prefix.length);
}
async function main() {
export function parseTaskLimit(raw: string | undefined, label: string): number {
const text = raw?.trim() ?? "3";
if (!POSITIVE_INTEGER_PATTERN.test(text)) {
throw new Error(`${label} must be a positive integer`);
}
const parsed = Number(text);
if (!Number.isSafeInteger(parsed)) {
throw new Error(`${label} must be a safe positive integer`);
}
return parsed;
}
export async function main() {
const model = readArg("model") ?? process.env.OPENCLAW_CODE_MODE_LIVE_MODEL ?? "gpt-5.4-mini";
const modeArg = readArg("modes");
const modes = (modeArg ? modeArg.split(",") : ["regular", "code-namespace"]) as Mode[];
const taskArg = readArg("tasks");
const taskLimit = parseTaskLimit(
taskArg ?? process.env.OPENCLAW_CODE_MODE_LIVE_TASKS,
taskArg === undefined ? "OPENCLAW_CODE_MODE_LIVE_TASKS" : "--tasks",
);
const apiKey = process.env.OPENAI_API_KEY?.trim();
if (!apiKey) {
throw new Error("OPENAI_API_KEY is required");
}
const model = readArg("model") ?? process.env.OPENCLAW_CODE_MODE_LIVE_MODEL ?? "gpt-5.4-mini";
const modeArg = readArg("modes");
const modes = (modeArg ? modeArg.split(",") : ["regular", "code-namespace"]) as Mode[];
const taskLimit = Number(readArg("tasks") ?? process.env.OPENCLAW_CODE_MODE_LIVE_TASKS ?? "3");
const selectedTasks = tasks.slice(
0,
Number.isFinite(taskLimit) && taskLimit > 0 ? taskLimit : tasks.length,
);
const selectedTasks = tasks.slice(0, taskLimit);
const results: RunMetrics[] = [];
for (const task of selectedTasks) {
for (const mode of modes) {
@@ -640,6 +655,8 @@ async function main() {
}
}
await main().finally(() => {
clearCodeModeNamespacesForPlugin(PLUGIN_ID);
});
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
await main().finally(() => {
clearCodeModeNamespacesForPlugin(PLUGIN_ID);
});
}
+1
View File
@@ -589,6 +589,7 @@ const TOOLING_SOURCE_TEST_TARGETS = new Map([
["scripts/tsdown-build.mjs", ["test/scripts/tsdown-build.test.ts"]],
["scripts/verify.mjs", ["test/scripts/verify.test.ts"]],
["scripts/zai-fallback-repro.ts", ["test/scripts/zai-fallback-repro.test.ts"]],
["scripts/repro/code-mode-namespace-live.ts", ["test/scripts/code-mode-namespace-live.test.ts"]],
["scripts/lib/extension-test-plan.mjs", ["test/scripts/test-extension.test.ts"]],
["scripts/lib/vitest-batch-runner.mjs", ["test/scripts/test-extension.test.ts"]],
["scripts/lib/ci-node-test-plan.mjs", ["test/scripts/ci-node-test-plan.test.ts"]],
@@ -0,0 +1,23 @@
// Code Mode Namespace Live tests cover live repro argument parsing.
import { describe, expect, it } from "vitest";
import { parseTaskLimit } from "../../scripts/repro/code-mode-namespace-live.ts";
describe("code-mode namespace live repro", () => {
it("parses task limits as strict positive integers", () => {
expect(parseTaskLimit(undefined, "--tasks")).toBe(3);
expect(parseTaskLimit(" 2 ", "--tasks")).toBe(2);
expect(() => parseTaskLimit("0", "--tasks")).toThrow("--tasks must be a positive integer");
expect(() => parseTaskLimit("1e3", "--tasks")).toThrow("--tasks must be a positive integer");
expect(() => parseTaskLimit("2.5", "--tasks")).toThrow("--tasks must be a positive integer");
expect(() => parseTaskLimit("3 tasks", "--tasks")).toThrow(
"--tasks must be a positive integer",
);
});
it("reports the environment variable name for inherited task limits", () => {
expect(() => parseTaskLimit("1e3", "OPENCLAW_CODE_MODE_LIVE_TASKS")).toThrow(
"OPENCLAW_CODE_MODE_LIVE_TASKS must be a positive integer",
);
});
});
+7
View File
@@ -335,6 +335,13 @@ describe("scripts/test-projects changed-target routing", () => {
});
});
it("routes code-mode namespace live repro changes through its regression test", () => {
expect(resolveChangedTestTargetPlan(["scripts/repro/code-mode-namespace-live.ts"])).toEqual({
mode: "targets",
targets: ["test/scripts/code-mode-namespace-live.test.ts"],
});
});
it("routes group visible reply config changes through channel delivery regressions", () => {
expect(
resolveChangedTestTargetPlan([