Extract benchmark follow-up pass parsing into perf config
Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
1 parent
142ce0fdcf
commit
2afff24bae
3 files changed
+62
-12
No files matched your search
@@ -4,7 +4,7 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { BrowserWindow, contentTracing, type WebContents } from "electron";
|
||||
import { shouldRunTerminalPerfInteractions } from "./perfConfig";
|
||||
import { resolveBenchmarkFollowUpPassCount, shouldRunTerminalPerfInteractions } from "./perfConfig";
|
||||
|
||||
const PERF_AUTOMATION_ENABLED = process.env.T3CODE_DESKTOP_PERF_AUTOMATION === "1";
|
||||
const PERF_TRACE_OUT_PATH = process.env.T3CODE_DESKTOP_PERF_TRACE_OUT?.trim() ?? "";
|
||||
@@ -14,16 +14,11 @@ const RUN_TERMINAL_INTERACTIONS = shouldRunTerminalPerfInteractions({
|
||||
T3CODE_DESKTOP_PERF_RUN_TERMINAL: process.env.T3CODE_DESKTOP_PERF_RUN_TERMINAL,
|
||||
CI: process.env.CI,
|
||||
});
|
||||
const BENCHMARK_FOLLOW_UP_PASS_COUNT = (() => {
|
||||
const raw = process.env.T3CODE_DESKTOP_PERF_BENCHMARK_FOLLOW_UP_PASSES?.trim();
|
||||
if (raw && raw.length > 0) {
|
||||
const parsed = Number.parseInt(raw, 10);
|
||||
if (Number.isFinite(parsed) && parsed >= 0) {
|
||||
return parsed;
|
||||
}
|
||||
}
|
||||
return process.env.CI === "true" ? 0 : 1;
|
||||
})();
|
||||
const BENCHMARK_FOLLOW_UP_PASS_COUNT = resolveBenchmarkFollowUpPassCount({
|
||||
T3CODE_DESKTOP_PERF_BENCHMARK_FOLLOW_UP_PASSES:
|
||||
process.env.T3CODE_DESKTOP_PERF_BENCHMARK_FOLLOW_UP_PASSES,
|
||||
CI: process.env.CI,
|
||||
});
|
||||
|
||||
function delay(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { shouldRunTerminalPerfInteractions } from "./perfConfig";
|
||||
import { resolveBenchmarkFollowUpPassCount, shouldRunTerminalPerfInteractions } from "./perfConfig";
|
||||
|
||||
describe("shouldRunTerminalPerfInteractions", () => {
|
||||
it("defaults to enabled outside CI when env is unset", () => {
|
||||
@@ -130,3 +130,45 @@ describe("shouldRunTerminalPerfInteractions", () => {
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveBenchmarkFollowUpPassCount", () => {
|
||||
it("defaults to 1 outside CI", () => {
|
||||
expect(resolveBenchmarkFollowUpPassCount({ CI: "false" })).toBe(1);
|
||||
expect(resolveBenchmarkFollowUpPassCount({ CI: "0" })).toBe(1);
|
||||
});
|
||||
|
||||
it("defaults to 0 in CI", () => {
|
||||
expect(resolveBenchmarkFollowUpPassCount({ CI: "true" })).toBe(0);
|
||||
expect(resolveBenchmarkFollowUpPassCount({ CI: "on" })).toBe(0);
|
||||
});
|
||||
|
||||
it("accepts explicit non-negative integer overrides", () => {
|
||||
expect(
|
||||
resolveBenchmarkFollowUpPassCount({
|
||||
T3CODE_DESKTOP_PERF_BENCHMARK_FOLLOW_UP_PASSES: "2",
|
||||
CI: "true",
|
||||
}),
|
||||
).toBe(2);
|
||||
expect(
|
||||
resolveBenchmarkFollowUpPassCount({
|
||||
T3CODE_DESKTOP_PERF_BENCHMARK_FOLLOW_UP_PASSES: " 0 ",
|
||||
CI: "false",
|
||||
}),
|
||||
).toBe(0);
|
||||
});
|
||||
|
||||
it("ignores malformed overrides and falls back to CI default", () => {
|
||||
expect(
|
||||
resolveBenchmarkFollowUpPassCount({
|
||||
T3CODE_DESKTOP_PERF_BENCHMARK_FOLLOW_UP_PASSES: "1abc",
|
||||
CI: "true",
|
||||
}),
|
||||
).toBe(0);
|
||||
expect(
|
||||
resolveBenchmarkFollowUpPassCount({
|
||||
T3CODE_DESKTOP_PERF_BENCHMARK_FOLLOW_UP_PASSES: "-1",
|
||||
CI: "false",
|
||||
}),
|
||||
).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -3,6 +3,11 @@ type PerfToggleEnv = {
|
||||
CI?: string | undefined;
|
||||
};
|
||||
|
||||
type PerfBenchmarkEnv = {
|
||||
T3CODE_DESKTOP_PERF_BENCHMARK_FOLLOW_UP_PASSES?: string | undefined;
|
||||
CI?: string | undefined;
|
||||
};
|
||||
|
||||
const TRUE_VALUES = new Set(["1", "true", "yes", "on"]);
|
||||
const FALSE_VALUES = new Set(["0", "false", "no", "off"]);
|
||||
|
||||
@@ -34,3 +39,11 @@ export function shouldRunTerminalPerfInteractions(env: PerfToggleEnv): boolean {
|
||||
if (toggleOverride !== null) return toggleOverride;
|
||||
return !isCiEnvironment(env.CI);
|
||||
}
|
||||
|
||||
export function resolveBenchmarkFollowUpPassCount(env: PerfBenchmarkEnv): number {
|
||||
const raw = env.T3CODE_DESKTOP_PERF_BENCHMARK_FOLLOW_UP_PASSES?.trim();
|
||||
if (raw && /^\d+$/.test(raw)) {
|
||||
return Number.parseInt(raw, 10);
|
||||
}
|
||||
return isCiEnvironment(env.CI) ? 0 : 1;
|
||||
}
|
||||
Reference in new issue
Block a user