Skip to content

Commit 3572122

Browse files
authored
Merge branch 'main' into fix-cache-stable-user-turn-serialization
2 parents 008429d + 5936595 commit 3572122

10 files changed

Lines changed: 415 additions & 95 deletions

‎scripts/bench-cli-startup.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Sample = {
2323
maxRssMb: number | null;
2424
exitCode: number | null;
2525
signal: string | null;
26+
timedOut?: boolean;
2627
stdoutTail?: string;
2728
stderrTail?: string;
2829
};
@@ -644,6 +645,7 @@ async function runSample(params: {
644645
let stdout = "";
645646
let stderr = "";
646647
let settled = false;
648+
let timedOut = false;
647649
const maxOutputLength = 32 * 1024 * 1024;
648650

649651
try {
@@ -674,6 +676,7 @@ async function runSample(params: {
674676
ms,
675677
firstOutputMs,
676678
maxRssMb: parseMaxRssMb(stderr),
679+
...(timedOut ? { timedOut } : {}),
677680
...sample,
678681
});
679682
};
@@ -685,6 +688,7 @@ async function runSample(params: {
685688
};
686689

687690
const timeout = setTimeout(() => {
691+
timedOut = true;
688692
try {
689693
proc.kill("SIGTERM");
690694
} catch {
@@ -828,7 +832,9 @@ export function collectFailedSamples(result: SuiteResult): string[] {
828832
for (const [sampleIndex, sample] of commandCase.samples.entries()) {
829833
const label = `${result.entry} ${commandCase.id} sample ${sampleIndex + 1}`;
830834
const expectedExitCodes = new Set(commandCase.expectedExitCodes ?? [0]);
831-
if (sample.signal !== null) {
835+
if (sample.timedOut === true) {
836+
failures.push(`${label}: timed out`);
837+
} else if (sample.signal !== null) {
832838
failures.push(`${label}: exited via signal ${sample.signal}`);
833839
} else if (!expectedExitCodes.has(sample.exitCode ?? -1)) {
834840
failures.push(`${label}: exited with code ${String(sample.exitCode)}`);

‎scripts/bench-test-changed.mjs‎

Lines changed: 84 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Benchmarks `pnpm test:changed` planning/runtime behavior across repeated runs.
22
import { spawnSync } from "node:child_process";
33
import path from "node:path";
4+
import { pathToFileURL } from "node:url";
45
import { parseFlagArgs, stringFlag } from "./lib/arg-utils.mjs";
56
import { formatMs } from "./lib/vitest-report-cli-utils.mjs";
67

@@ -35,7 +36,7 @@ function positiveIntegerFlag(flag, key) {
3536
};
3637
}
3738

38-
function parseArgs(argv) {
39+
export function parseArgs(argv) {
3940
const args = parseFlagArgs(
4041
argv,
4142
{
@@ -103,16 +104,16 @@ function listChangedPaths(opts) {
103104
return runGitList(["diff", "--name-only", `${opts.ref}...HEAD`], opts.cwd);
104105
}
105106

106-
function parseMaxRssKb(output) {
107+
export function parseMaxRssBytes(output) {
107108
const match = output.match(/(\d+)\s+maximum resident set size/u);
108109
return match ? Number.parseInt(match[1], 10) : null;
109110
}
110111

111-
function formatRss(valueKb) {
112-
if (valueKb === null) {
112+
export function formatRss(valueBytes) {
113+
if (valueBytes === null) {
113114
return "n/a";
114115
}
115-
return `${(valueKb / 1024).toFixed(1)}MB`;
116+
return `${(valueBytes / 1024 / 1024).toFixed(1)}MB`;
116117
}
117118

118119
function runBenchCommand(params) {
@@ -136,7 +137,7 @@ function runBenchCommand(params) {
136137
const output = `${result.stdout ?? ""}${result.stderr ?? ""}`;
137138
return {
138139
elapsedMs,
139-
maxRssKb: params.rss ? parseMaxRssKb(output) : null,
140+
maxRssBytes: params.rss ? parseMaxRssBytes(output) : null,
140141
status: result.status ?? 1,
141142
output,
142143
};
@@ -145,81 +146,92 @@ function runBenchCommand(params) {
145146
function printRunSummary(label, result) {
146147
console.log(
147148
`${label.padEnd(8, " ")} wall=${formatMs(result.elapsedMs).padStart(9, " ")} rss=${formatRss(
148-
result.maxRssKb,
149+
result.maxRssBytes,
149150
).padStart(9, " ")}`,
150151
);
151152
}
152153

153-
let opts;
154-
try {
155-
opts = parseArgs(process.argv.slice(2));
156-
} catch (error) {
157-
console.error(error instanceof Error ? error.message : String(error));
158-
process.exit(1);
159-
}
160-
const changedPaths = listChangedPaths(opts);
161-
if (changedPaths.length === 0) {
154+
function main() {
155+
let opts;
156+
try {
157+
opts = parseArgs(process.argv.slice(2));
158+
} catch (error) {
159+
console.error(error instanceof Error ? error.message : String(error));
160+
process.exit(1);
161+
}
162+
const changedPaths = listChangedPaths(opts);
163+
if (changedPaths.length === 0) {
164+
console.log(
165+
opts.mode === "worktree"
166+
? "[bench-test-changed] no changed paths in worktree"
167+
: `[bench-test-changed] no changed paths for ${opts.ref}...HEAD`,
168+
);
169+
process.exit(0);
170+
}
171+
162172
console.log(
163173
opts.mode === "worktree"
164-
? "[bench-test-changed] no changed paths in worktree"
165-
: `[bench-test-changed] no changed paths for ${opts.ref}...HEAD`,
174+
? "[bench-test-changed] mode=worktree"
175+
: `[bench-test-changed] ref=${opts.ref}`,
166176
);
167-
process.exit(0);
168-
}
177+
console.log("[bench-test-changed] changed paths:");
178+
for (const changedPath of changedPaths) {
179+
console.log(`- ${changedPath}`);
180+
}
169181

170-
console.log(
171-
opts.mode === "worktree"
172-
? "[bench-test-changed] mode=worktree"
173-
: `[bench-test-changed] ref=${opts.ref}`,
174-
);
175-
console.log("[bench-test-changed] changed paths:");
176-
for (const changedPath of changedPaths) {
177-
console.log(`- ${changedPath}`);
178-
}
182+
const routedCommand =
183+
opts.mode === "worktree"
184+
? [process.execPath, "scripts/test-projects.mjs", ...changedPaths]
185+
: [process.execPath, "scripts/test-projects.mjs", "--changed", opts.ref];
186+
const rootCommand = [
187+
process.execPath,
188+
"scripts/run-vitest.mjs",
189+
"run",
190+
"--config",
191+
"vitest.config.ts",
192+
...changedPaths,
193+
];
194+
195+
console.log(`[bench-test-changed] routed: ${routedCommand.map(quoteArg).join(" ")}`);
196+
const routed = runBenchCommand({
197+
command: routedCommand,
198+
cwd: opts.cwd,
199+
rss: opts.rss,
200+
...(typeof opts.maxWorkers === "number" ? { maxWorkers: opts.maxWorkers } : {}),
201+
});
202+
if (routed.status !== 0) {
203+
process.stderr.write(routed.output);
204+
process.exit(routed.status);
205+
}
179206

180-
const routedCommand =
181-
opts.mode === "worktree"
182-
? [process.execPath, "scripts/test-projects.mjs", ...changedPaths]
183-
: [process.execPath, "scripts/test-projects.mjs", "--changed", opts.ref];
184-
const rootCommand = [
185-
process.execPath,
186-
"scripts/run-vitest.mjs",
187-
"run",
188-
"--config",
189-
"vitest.config.ts",
190-
...changedPaths,
191-
];
192-
193-
console.log(`[bench-test-changed] routed: ${routedCommand.map(quoteArg).join(" ")}`);
194-
const routed = runBenchCommand({
195-
command: routedCommand,
196-
cwd: opts.cwd,
197-
rss: opts.rss,
198-
...(typeof opts.maxWorkers === "number" ? { maxWorkers: opts.maxWorkers } : {}),
199-
});
200-
if (routed.status !== 0) {
201-
process.stderr.write(routed.output);
202-
process.exit(routed.status);
203-
}
207+
console.log(`[bench-test-changed] root: ${rootCommand.map(quoteArg).join(" ")}`);
208+
const root = runBenchCommand({
209+
command: rootCommand,
210+
cwd: opts.cwd,
211+
rss: opts.rss,
212+
...(typeof opts.maxWorkers === "number" ? { maxWorkers: opts.maxWorkers } : {}),
213+
});
214+
if (root.status !== 0) {
215+
process.stderr.write(root.output);
216+
process.exit(root.status);
217+
}
204218

205-
console.log(`[bench-test-changed] root: ${rootCommand.map(quoteArg).join(" ")}`);
206-
const root = runBenchCommand({
207-
command: rootCommand,
208-
cwd: opts.cwd,
209-
rss: opts.rss,
210-
...(typeof opts.maxWorkers === "number" ? { maxWorkers: opts.maxWorkers } : {}),
211-
});
212-
if (root.status !== 0) {
213-
process.stderr.write(root.output);
214-
process.exit(root.status);
219+
printRunSummary("routed", routed);
220+
printRunSummary("root", root);
221+
console.log(
222+
`[bench-test-changed] delta wall=${formatMs(root.elapsedMs - routed.elapsedMs)} rss=${
223+
routed.maxRssBytes !== null && root.maxRssBytes !== null
224+
? formatRss(root.maxRssBytes - routed.maxRssBytes)
225+
: "n/a"
226+
}`,
227+
);
215228
}
216229

217-
printRunSummary("routed", routed);
218-
printRunSummary("root", root);
219-
console.log(
220-
`[bench-test-changed] delta wall=${formatMs(root.elapsedMs - routed.elapsedMs)} rss=${
221-
routed.maxRssKb !== null && root.maxRssKb !== null
222-
? formatRss(root.maxRssKb - routed.maxRssKb)
223-
: "n/a"
224-
}`,
225-
);
230+
const isMain =
231+
typeof process.argv[1] === "string" &&
232+
process.argv[1].length > 0 &&
233+
import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href;
234+
235+
if (isMain) {
236+
main();
237+
}

‎scripts/check-cli-startup-memory.mjs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { spawnSync as defaultSpawnSync } from "node:child_process";
55
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
66
import os from "node:os";
77
import path from "node:path";
8-
import { pathToFileURL } from "node:url";
8+
import { fileURLToPath, pathToFileURL } from "node:url";
99

10-
const repoRoot = process.cwd();
10+
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
1111
const tmpDir = process.env.TMPDIR || process.env.TEMP || process.env.TMP || os.tmpdir();
1212
const MAX_RSS_MARKER = "__OPENCLAW_MAX_RSS_KB__=";
1313
const DEFAULT_COMMAND_TIMEOUT_MS = 60_000;
@@ -367,6 +367,7 @@ export const testing = {
367367
parseArgs,
368368
readPositiveIntEnv,
369369
readPositiveNumberEnv,
370+
repoRoot,
370371
resolveDefaultLimitsMb,
371372
runCase,
372373
runStartupMemoryCheck,

‎scripts/package-mac-app.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ if [[ "$BUNDLE_ID" == *.debug ]]; then
4242
fi
4343

4444
sparkle_canonical_build_from_version() {
45-
node --import tsx "$ROOT_DIR/scripts/sparkle-build.ts" canonical-build "$1"
45+
(cd "$ROOT_DIR" && node --import tsx "$ROOT_DIR/scripts/sparkle-build.ts" canonical-build "$1")
4646
}
4747

4848
build_path_for_arch() {

0 commit comments

Comments
 (0)