Handle fork PR desktop perf runs and harden trace shutdown

- Run desktop perf tests on forked pull requests without posting PR summaries
- Restrict PR summary posting to same-repo pull requests
- Add timeout-wrapped trace stop logic and guarded cleanup to avoid hangs
This commit is contained in:
Julius Marminge committed 2026-02-16 08:41:15 -08:00
1 parent 7fb2051e67
commit af40c4aa5a
2 files changed
+46 -6

No files matched your search

+5 -1
View File
@@ -57,8 +57,12 @@ jobs:
if: github.event_name != 'pull_request'
run: xvfb-run -a bun run test:desktop-perf
- name: Desktop perf trace test (fork PR)
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
run: xvfb-run -a bun run test:desktop-perf
- name: Desktop perf trace test and PR summary
if: github.event_name == 'pull_request'
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
env:
GH_TOKEN: ${{ github.token }}
run: xvfb-run -a bun run test:desktop-perf:post
+41 -5
View File
@@ -11,6 +11,26 @@ function delay(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function withTimeout<T>(promise: Promise<T>, timeoutMs: number, label: string): Promise<T> {
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new Error(`Timed out waiting for ${label} (${timeoutMs}ms).`));
}, timeoutMs);
timeout.unref();
promise.then(
(value) => {
clearTimeout(timeout);
resolve(value);
},
(error: unknown) => {
clearTimeout(timeout);
reject(error);
},
);
});
}
function waitForDidFinishLoad(
webContents: WebContents,
options?: { timeoutMs?: number; label?: string },
@@ -348,6 +368,7 @@ export async function runDesktopPerfAutomation(window: BrowserWindow): Promise<v
};
let tracePath = PERF_TRACE_OUT_PATH;
let isTraceRecording = false;
const startedAt = Date.now();
try {
console.log("[desktop-perf] waiting for initial load");
@@ -368,11 +389,17 @@ export async function runDesktopPerfAutomation(window: BrowserWindow): Promise<v
fs.mkdirSync(path.dirname(PERF_TRACE_OUT_PATH), { recursive: true });
console.log("[desktop-perf] starting trace recording");
await contentTracing.startRecording(traceConfig);
isTraceRecording = true;
console.log("[desktop-perf] running scripted interactions");
const interactions = await runRendererPerfInteractions(window);
await delay(300);
console.log("[desktop-perf] stopping trace recording");
tracePath = await contentTracing.stopRecording(PERF_TRACE_OUT_PATH);
tracePath = await withTimeout(
contentTracing.stopRecording(PERF_TRACE_OUT_PATH),
15_000,
"trace recording to stop",
);
isTraceRecording = false;
const completedAt = Date.now();
console.log(`[desktop-perf] trace recorded at ${tracePath}`);
@@ -395,10 +422,19 @@ export async function runDesktopPerfAutomation(window: BrowserWindow): Promise<v
);
}
} catch (error) {
try {
tracePath = await contentTracing.stopRecording(PERF_TRACE_OUT_PATH);
} catch {
// Ignore errors while attempting to stop a recording that may not have started.
if (isTraceRecording) {
try {
tracePath = await withTimeout(
contentTracing.stopRecording(PERF_TRACE_OUT_PATH),
15_000,
"trace recording to stop after failure",
);
} catch (stopError) {
const stopMessage = stopError instanceof Error ? stopError.message : String(stopError);
console.error("[desktop-perf] failed to stop trace recording:", stopMessage);
} finally {
isTraceRecording = false;
}
}
const message = error instanceof Error ? error.message : String(error);
console.error("[desktop-perf] automation failed:", message);