- Change once(seedProcess, 'exit') to once(seedProcess, 'close') in appHarness.ts and open-perf-app.ts to ensure piped stdio buffers are fully drained before parsing stdout. - Extract buildPerfServerEnv into @t3tools/shared/perf/serverEnv to eliminate identical copies in serverPerfHarness.ts and web serverEnv.ts. Both consumers now import from the shared module.
Unified · Split
| @@ -33,13 +33,11 @@ import type { · 32 unmodified lines | |||
| 33 | PerfProviderScenarioId, | 33 | PerfProviderScenarioId, |
| 34 | PerfSeedScenarioId, | 34 | PerfSeedScenarioId, |
| 35 | } from "@t3tools/shared/perf/scenarioCatalog"; | 35 | } from "@t3tools/shared/perf/scenarioCatalog"; |
| 36 | import { buildPerfServerEnv } from "@t3tools/shared/perf/serverEnv"; | ||
| 36 | import { seedPerfState, type PerfSeededState } from "./seedPerfState.ts"; | 37 | import { seedPerfState, type PerfSeededState } from "./seedPerfState.ts"; |
| 37 | 38 | ||
| 38 | const repoRoot = fileURLToPath(new URL("../../../../", import.meta.url)); | 39 | const repoRoot = fileURLToPath(new URL("../../../../", import.meta.url)); |
| 39 | const PERF_ARTIFACT_DIR_ENV = "T3CODE_PERF_ARTIFACT_DIR"; | 40 | const PERF_ARTIFACT_DIR_ENV = "T3CODE_PERF_ARTIFACT_DIR"; |
| 40 | const PERF_PROVIDER_ENV = "T3CODE_PERF_PROVIDER"; | ||
| 41 | const PERF_SCENARIO_ENV = "T3CODE_PERF_SCENARIO"; | ||
| 42 | const AUTO_BOOTSTRAP_PROJECT_ENV = "T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD"; | ||
| 43 | 41 | ||
| 44 | const makeWsRpcClient = RpcClient.make(WsRpcGroup); | 42 | const makeWsRpcClient = RpcClient.make(WsRpcGroup); |
| 45 | type WsRpcClient = | 43 | type WsRpcClient = |
| @@ -184,28 +182,6 @@ async function writeServerLogs( · 138 unmodified lines | |||
| 184 | ]); | 182 | ]); |
| 185 | } | 183 | } |
| 186 | 184 | ||
| 187 | function buildPerfServerEnv( | ||
| 188 | baseEnv: NodeJS.ProcessEnv, | ||
| 189 | providerScenarioId?: PerfProviderScenarioId, | ||
| 190 | ): NodeJS.ProcessEnv { | ||
| 191 | const env: NodeJS.ProcessEnv = { | ||
| 192 | ...baseEnv, | ||
| 193 | [AUTO_BOOTSTRAP_PROJECT_ENV]: "false", | ||
| 194 | }; | ||
| 195 | |||
| 196 | if (!providerScenarioId) { | ||
| 197 | delete env[PERF_PROVIDER_ENV]; | ||
| 198 | delete env[PERF_SCENARIO_ENV]; | ||
| 199 | return env; | ||
| 200 | } | ||
| 201 | |||
| 202 | return { | ||
| 203 | ...env, | ||
| 204 | [PERF_PROVIDER_ENV]: "1", | ||
| 205 | [PERF_SCENARIO_ENV]: providerScenarioId, | ||
| 206 | }; | ||
| 207 | } | ||
| 208 | |||
| 209 | export class PerfWsRpcClient { | 185 | export class PerfWsRpcClient { |
| 210 | private readonly runtime: ManagedRuntime.ManagedRuntime<RpcClient.Protocol, never>; | 186 | private readonly runtime: ManagedRuntime.ManagedRuntime<RpcClient.Protocol, never>; |
| 211 | private readonly clientScope: Scope.Closeable; | 187 | private readonly clientScope: Scope.Closeable; |
| @@ -266,7 +266,7 @@ export async function startPerfAppHarness( · 265 unmodified lines | |||
| 266 | seedProcess.stderr?.on("data", (chunk) => { | 266 | seedProcess.stderr?.on("data", (chunk) => { |
| 267 | stderr += chunk.toString(); | 267 | stderr += chunk.toString(); |
| 268 | }); | 268 | }); |
| 269 | const [exitCode] = (await once(seedProcess, "exit")) as [number | null]; | 269 | const [exitCode] = (await once(seedProcess, "close")) as [number | null]; |
| 270 | if (exitCode !== 0) { | 270 | if (exitCode !== 0) { |
| 271 | throw new Error(`Perf seed command failed with code ${exitCode ?? "unknown"}.\n${stderr}`); | 271 | throw new Error(`Perf seed command failed with code ${exitCode ?? "unknown"}.\n${stderr}`); |
| 272 | } | 272 | } |
| @@ -1,27 +1,5 @@ | |||
| 1 | import type { PerfProviderScenarioId } from "@t3tools/shared/perf/scenarioCatalog"; | 1 | export { |
| 2 | 2 | buildPerfServerEnv, | |
| 3 | export const PERF_PROVIDER_ENV = "T3CODE_PERF_PROVIDER"; | 3 | PERF_PROVIDER_ENV, |
| 4 | export const PERF_SCENARIO_ENV = "T3CODE_PERF_SCENARIO"; | 4 | PERF_SCENARIO_ENV, |
| 5 | const AUTO_BOOTSTRAP_PROJECT_ENV = "T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD"; | 5 | } from "@t3tools/shared/perf/serverEnv"; |
| 6 | |||
| 7 | export function buildPerfServerEnv( | ||
| 8 | baseEnv: NodeJS.ProcessEnv, | ||
| 9 | providerScenarioId?: PerfProviderScenarioId, | ||
| 10 | ): NodeJS.ProcessEnv { | ||
| 11 | const env: NodeJS.ProcessEnv = { | ||
| 12 | ...baseEnv, | ||
| 13 | [AUTO_BOOTSTRAP_PROJECT_ENV]: "false", | ||
| 14 | }; | ||
| 15 | |||
| 16 | if (!providerScenarioId) { | ||
| 17 | delete env[PERF_PROVIDER_ENV]; | ||
| 18 | delete env[PERF_SCENARIO_ENV]; | ||
| 19 | return env; | ||
| 20 | } | ||
| 21 | |||
| 22 | return { | ||
| 23 | ...env, | ||
| 24 | [PERF_PROVIDER_ENV]: "1", | ||
| 25 | [PERF_SCENARIO_ENV]: providerScenarioId, | ||
| 26 | }; | ||
| 27 | } | ||
| @@ -51,6 +51,10 @@ · 50 unmodified lines | |||
| 51 | "./perf/artifact": { | 51 | "./perf/artifact": { |
| 52 | "types": "./src/perf/artifact.ts", | 52 | "types": "./src/perf/artifact.ts", |
| 53 | "import": "./src/perf/artifact.ts" | 53 | "import": "./src/perf/artifact.ts" |
| 54 | }, | ||
| 55 | "./perf/serverEnv": { | ||
| 56 | "types": "./src/perf/serverEnv.ts", | ||
| 57 | "import": "./src/perf/serverEnv.ts" | ||
| 54 | } | 58 | } |
| 55 | }, | 59 | }, |
| 56 | "scripts": { | 60 | "scripts": { |
| @@ -0,0 +1,27 @@ | |||
| 1 | import type { PerfProviderScenarioId } from "./scenarioCatalog.ts"; | ||
| 2 | |||
| 3 | export const PERF_PROVIDER_ENV = "T3CODE_PERF_PROVIDER"; | ||
| 4 | export const PERF_SCENARIO_ENV = "T3CODE_PERF_SCENARIO"; | ||
| 5 | const AUTO_BOOTSTRAP_PROJECT_ENV = "T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD"; | ||
| 6 | |||
| 7 | export function buildPerfServerEnv( | ||
| 8 | baseEnv: NodeJS.ProcessEnv, | ||
| 9 | providerScenarioId?: PerfProviderScenarioId, | ||
| 10 | ): NodeJS.ProcessEnv { | ||
| 11 | const env: NodeJS.ProcessEnv = { | ||
| 12 | ...baseEnv, | ||
| 13 | [AUTO_BOOTSTRAP_PROJECT_ENV]: "false", | ||
| 14 | }; | ||
| 15 | |||
| 16 | if (!providerScenarioId) { | ||
| 17 | delete env[PERF_PROVIDER_ENV]; | ||
| 18 | delete env[PERF_SCENARIO_ENV]; | ||
| 19 | return env; | ||
| 20 | } | ||
| 21 | |||
| 22 | return { | ||
| 23 | ...env, | ||
| 24 | [PERF_PROVIDER_ENV]: "1", | ||
| 25 | [PERF_SCENARIO_ENV]: providerScenarioId, | ||
| 26 | }; | ||
| 27 | } | ||
| @@ -208,7 +208,7 @@ async function seedPerfState(scenarioId: PerfSeedScenarioId): Promise<PerfSeeded · 207 unmodified lines | |||
| 208 | stderr += chunk.toString(); | 208 | stderr += chunk.toString(); |
| 209 | }); | 209 | }); |
| 210 | 210 | ||
| 211 | const [exitCode] = (await once(seedProcess, "exit")) as [number | null]; | 211 | const [exitCode] = (await once(seedProcess, "close")) as [number | null]; |
| 212 | if (exitCode !== 0) { | 212 | if (exitCode !== 0) { |
| 213 | throw new Error(`Perf seed command failed with code ${exitCode ?? "unknown"}.\n${stderr}`); | 213 | throw new Error(`Perf seed command failed with code ${exitCode ?? "unknown"}.\n${stderr}`); |
| 214 | } | 214 | } |