fix(tooling): accept pnpm separator in web fetch benchmark

Accept the documented package-manager separator for the web fetch benchmark CLI and add a process-level regression test. Verified with rebased Testbox check:changed, prior targeted Testbox benchmark/test smokes, and AWS macOS install/build/gateway probes.
This commit is contained in:
Vincent Koc
2026-07-04 13:47:14 -07:00
committed by GitHub
parent 0427fa35fb
commit 260c9c4589
2 changed files with 61 additions and 6 deletions
+8 -6
View File
@@ -7,6 +7,7 @@ import { createWebFetchTool } from "../src/agents/tools/web-fetch.js";
import type { OpenClawConfig } from "../src/config/types.openclaw.js";
import type { LookupFn } from "../src/infra/net/ssrf.js";
import { extractReadableContent } from "../src/web-fetch/content-extractors.runtime.js";
import { stripLeadingPackageManagerSeparator } from "./lib/arg-utils.mjs";
type BenchmarkCaseId =
| "tool-create"
@@ -204,13 +205,14 @@ function parseFlagValue(flag: string, args: string[]): string | undefined {
}
function parseOptions(args = process.argv.slice(2)): Options {
validateArgs(args);
const normalizedArgs = stripLeadingPackageManagerSeparator(args);
validateArgs(normalizedArgs);
return {
cases: parseCases(args),
json: args.includes("--json"),
output: parseFlagValue("--output", args),
runs: parsePositiveInteger("--runs", 20, args),
warmup: parseNonNegativeInteger("--warmup", 3, args),
cases: parseCases(normalizedArgs),
json: normalizedArgs.includes("--json"),
output: parseFlagValue("--output", normalizedArgs),
runs: parsePositiveInteger("--runs", 20, normalizedArgs),
warmup: parseNonNegativeInteger("--warmup", 3, normalizedArgs),
};
}
+53
View File
@@ -0,0 +1,53 @@
// Bench Web Fetch tests cover the offline benchmark CLI contract.
import { spawnSync } from "node:child_process";
import { describe, expect, it } from "vitest";
const SCRIPT_PATH = "scripts/bench-web-fetch.ts";
function runBenchWebFetch(...args: string[]) {
return spawnSync(process.execPath, ["--import", "tsx", SCRIPT_PATH, ...args], {
cwd: process.cwd(),
encoding: "utf8",
env: {
...process.env,
FIRECRAWL_API_KEY: "test-firecrawl-key-that-should-be-ignored",
NODE_NO_WARNINGS: "1",
},
});
}
describe("web fetch benchmark script", () => {
it("accepts the package-manager separator documented for pnpm scripts", () => {
const result = runBenchWebFetch(
"--",
"--case",
"tool-create",
"--runs",
"1",
"--warmup",
"0",
"--json",
);
expect(result.status).toBe(0);
expect(result.stderr).toBe("");
const report = JSON.parse(result.stdout) as {
cases: Array<{ id: string; samplesMs: number[] }>;
};
expect(report.cases).toHaveLength(1);
expect(report.cases[0]).toMatchObject({
id: "tool-create",
samplesMs: expect.any(Array),
});
expect(report.cases[0]?.samplesMs).toHaveLength(1);
});
it("rejects duplicate singular flags without a stack trace", () => {
const result = runBenchWebFetch("--runs", "1", "--runs", "2");
expect(result.status).toBe(2);
expect(result.stdout).toBe("");
expect(result.stderr.trim()).toBe("--runs was provided more than once");
expect(result.stderr).not.toContain("\n at ");
});
});