- Persist and remove the seeded run parent directory after perf runs - Add regression coverage for seed cleanup, percentile clamping, and RAF reset
Showing the changes to scripts (1 of 10 files). Show all
Unified · Split
| @@ -1,6 +1,6 @@ | |||
| 1 | import { spawn, type ChildProcess } from "node:child_process"; | 1 | import { spawn, type ChildProcess } from "node:child_process"; |
| 2 | import { once } from "node:events"; | 2 | import { once } from "node:events"; |
| 3 | import { access } from "node:fs/promises"; | 3 | import { access, rm } from "node:fs/promises"; |
| 4 | import { createServer } from "node:net"; | 4 | import { createServer } from "node:net"; |
| 5 | import { resolve } from "node:path"; | 5 | import { resolve } from "node:path"; |
| 6 | import { fileURLToPath } from "node:url"; | 6 | import { fileURLToPath } from "node:url"; |
| @@ -27,6 +27,7 @@ interface PerfSeedThreadSummary { · 20 unmodified lines | |||
| 27 | 27 | ||
| 28 | interface PerfSeededState { | 28 | interface PerfSeededState { |
| 29 | readonly scenarioId: PerfSeedScenarioId; | 29 | readonly scenarioId: PerfSeedScenarioId; |
| 30 | readonly runParentDir: string; | ||
| 30 | readonly baseDir: string; | 31 | readonly baseDir: string; |
| 31 | readonly workspaceRoot: string; | 32 | readonly workspaceRoot: string; |
| 32 | readonly projectTitle: string | null; | 33 | readonly projectTitle: string | null; |
| @@ -252,6 +253,10 @@ async function stopChildProcess(process: ChildProcess): Promise<void> { · 219 unmodified lines | |||
| 252 | } | 253 | } |
| 253 | } | 254 | } |
| 254 | 255 | ||
| 256 | async function cleanupPerfRunDir(runParentDir: string): Promise<void> { | ||
| 257 | await rm(runParentDir, { recursive: true, force: true }); | ||
| 258 | } | ||
| 259 | |||
| 255 | function openUrl(url: string): void { | 260 | function openUrl(url: string): void { |
| 256 | const command: [string, ...string[]] = | 261 | const command: [string, ...string[]] = |
| 257 | process.platform === "darwin" | 262 | process.platform === "darwin" |
| @@ -339,6 +344,7 @@ async function main(): Promise<void> { · 81 unmodified lines | |||
| 339 | shuttingDown = true; | 344 | shuttingDown = true; |
| 340 | process.stdout.write(`\nReceived ${signal}. Stopping perf app...\n`); | 345 | process.stdout.write(`\nReceived ${signal}. Stopping perf app...\n`); |
| 341 | await stopChildProcess(serverProcess); | 346 | await stopChildProcess(serverProcess); |
| 347 | await cleanupPerfRunDir(seededState.runParentDir); | ||
| 342 | process.exit(0); | 348 | process.exit(0); |
| 343 | }; | 349 | }; |
| 344 | 350 | ||
| @@ -349,17 +355,24 @@ async function main(): Promise<void> { · 4 unmodified lines | |||
| 349 | void shutdown("SIGTERM"); | 355 | void shutdown("SIGTERM"); |
| 350 | }); | 356 | }); |
| 351 | 357 | ||
| 352 | const url = `http://${options.host}:${port.toString()}`; | 358 | try { |
| 353 | await waitForServerReady(url, serverProcess); | 359 | const url = `http://${options.host}:${port.toString()}`; |
| 354 | printSeedSummary(seededState, url, options.providerScenarioId); | 360 | await waitForServerReady(url, serverProcess); |
| 361 | printSeedSummary(seededState, url, options.providerScenarioId); | ||
| 355 | 362 | ||
| 356 | if (options.openBrowser) { | 363 | if (options.openBrowser) { |
| 357 | openUrl(url); | 364 | openUrl(url); |
| 358 | } | 365 | } |
| 359 | 366 | ||
| 360 | const [exitCode] = (await once(serverProcess, "exit")) as [number | null]; | 367 | const [exitCode] = (await once(serverProcess, "exit")) as [number | null]; |
| 361 | if (!shuttingDown) { | 368 | if (!shuttingDown) { |
| 362 | process.exit(exitCode ?? 0); | 369 | await cleanupPerfRunDir(seededState.runParentDir); |
| 370 | process.exit(exitCode ?? 0); | ||
| 371 | } | ||
| 372 | } catch (error) { | ||
| 373 | await stopChildProcess(serverProcess); | ||
| 374 | await cleanupPerfRunDir(seededState.runParentDir); | ||
| 375 | throw error; | ||
| 363 | } | 376 | } |
| 364 | } | 377 | } |
| 365 | 378 | ||