From da7aebafeca5c3d64e568c5b34f1d27f5bb3613d Mon Sep 17 00:00:00 2001 From: ndycode <405533+ndycode@users.noreply.github.com> Date: Sun, 22 Mar 2026 13:11:56 +0800 Subject: [PATCH 1/3] test: cover runtime benchmark script --- test/benchmark-runtime-path-script.test.ts | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 test/benchmark-runtime-path-script.test.ts diff --git a/test/benchmark-runtime-path-script.test.ts b/test/benchmark-runtime-path-script.test.ts new file mode 100644 index 00000000..5e215139 --- /dev/null +++ b/test/benchmark-runtime-path-script.test.ts @@ -0,0 +1,94 @@ +import { spawnSync } from "node:child_process"; +import { + copyFileSync, + mkdirSync, + mkdtempSync, + readFileSync, + rmSync, + writeFileSync, +} from "node:fs"; +import { tmpdir } from "node:os"; +import { dirname, join } from "node:path"; +import { afterEach, describe, expect, it } from "vitest"; + +const tempRoots: string[] = []; +const scriptPath = "scripts/benchmark-runtime-path.mjs"; + +afterEach(() => { + while (tempRoots.length > 0) { + const root = tempRoots.pop(); + if (root) rmSync(root, { recursive: true, force: true }); + } +}); + +function createRuntimeBenchmarkFixture(): { + fixtureRoot: string; + scriptCopy: string; +} { + const fixtureRoot = mkdtempSync(join(tmpdir(), "runtime-bench-fixture-")); + tempRoots.push(fixtureRoot); + + const scriptsDir = join(fixtureRoot, "scripts"); + const distRequestDir = join(fixtureRoot, "dist", "lib", "request"); + const distHelpersDir = join(distRequestDir, "helpers"); + const distLibDir = join(fixtureRoot, "dist", "lib"); + + mkdirSync(scriptsDir, { recursive: true }); + mkdirSync(distHelpersDir, { recursive: true }); + mkdirSync(distLibDir, { recursive: true }); + + const scriptCopy = join(scriptsDir, "benchmark-runtime-path.mjs"); + copyFileSync(join(process.cwd(), scriptPath), scriptCopy); + + writeFileSync( + join(distRequestDir, "request-transformer.js"), + "export function filterInput(input) { return Array.isArray(input) ? input : []; }\n", + "utf8", + ); + writeFileSync( + join(distHelpersDir, "tool-utils.js"), + "export function cleanupToolDefinitions(tools) { return Array.isArray(tools) ? tools : []; }\n", + "utf8", + ); + writeFileSync( + join(distLibDir, "accounts.js"), + [ + "export class AccountManager {", + " constructor(_, storage) { this.storage = storage; }", + " getCurrentOrNextForFamilyHybrid() { return this.storage.accounts[0] ?? null; }", + "}", + ].join("\n"), + "utf8", + ); + + return { fixtureRoot, scriptCopy }; +} + +describe("benchmark runtime path script", () => { + it("writes a benchmark payload with the expected result entries", () => { + const { fixtureRoot, scriptCopy } = createRuntimeBenchmarkFixture(); + const outputPath = join(fixtureRoot, "runtime-benchmark.json"); + + const result = spawnSync( + process.execPath, + [scriptCopy, "--iterations=1", `--output=${outputPath}`], + { encoding: "utf8" }, + ); + + expect(result.status).toBe(0); + expect(result.stdout).toContain("Runtime benchmark written:"); + + const payload = JSON.parse(readFileSync(outputPath, "utf8")) as { + iterations: number; + results: Array<{ name: string }>; + }; + expect(payload.iterations).toBe(1); + expect(payload.results.map((entry) => entry.name)).toEqual([ + "filterInput_small", + "filterInput_large", + "cleanupToolDefinitions_medium", + "cleanupToolDefinitions_large", + "accountHybridSelection_200", + ]); + }); +}); From f3b55a284fa28c36dcf914fad7906e7a669dab8c Mon Sep 17 00:00:00 2001 From: ndycode <405533+ndycode@users.noreply.github.com> Date: Sun, 22 Mar 2026 13:53:33 +0800 Subject: [PATCH 2/3] Use retry-safe cleanup in benchmark path test --- test/benchmark-runtime-path-script.test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/benchmark-runtime-path-script.test.ts b/test/benchmark-runtime-path-script.test.ts index 5e215139..6e727f22 100644 --- a/test/benchmark-runtime-path-script.test.ts +++ b/test/benchmark-runtime-path-script.test.ts @@ -4,20 +4,22 @@ import { mkdirSync, mkdtempSync, readFileSync, - rmSync, writeFileSync, } from "node:fs"; import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; import { afterEach, describe, expect, it } from "vitest"; +import { removeWithRetry } from "./helpers/remove-with-retry.js"; const tempRoots: string[] = []; const scriptPath = "scripts/benchmark-runtime-path.mjs"; -afterEach(() => { +afterEach(async () => { while (tempRoots.length > 0) { const root = tempRoots.pop(); - if (root) rmSync(root, { recursive: true, force: true }); + if (root) { + await removeWithRetry(root, { recursive: true, force: true }); + } } }); From 37a9f2fcb1a7a1a03b29b05dea1ff79b27b146b7 Mon Sep 17 00:00:00 2001 From: ndycode <405533+ndycode@users.noreply.github.com> Date: Sun, 22 Mar 2026 13:59:15 +0800 Subject: [PATCH 3/3] Drop unused benchmark path import --- test/benchmark-runtime-path-script.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/benchmark-runtime-path-script.test.ts b/test/benchmark-runtime-path-script.test.ts index 6e727f22..90f6d28b 100644 --- a/test/benchmark-runtime-path-script.test.ts +++ b/test/benchmark-runtime-path-script.test.ts @@ -7,7 +7,7 @@ import { writeFileSync, } from "node:fs"; import { tmpdir } from "node:os"; -import { dirname, join } from "node:path"; +import { join } from "node:path"; import { afterEach, describe, expect, it } from "vitest"; import { removeWithRetry } from "./helpers/remove-with-retry.js";