Skip to content

Commit e2cdd52

Browse files
committed
fix: warn on replay video finalization failure
1 parent 76203ee commit e2cdd52

5 files changed

Lines changed: 45 additions & 6 deletions

File tree

‎src/cli-test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ function renderDefaultTestResult(result: ReplaySuiteTestResult): void {
6363
process.stdout.write(
6464
`PASS ${replayTestDisplayName(result)}${formatReplayTestDurationSuffix(result)}\n`,
6565
);
66+
for (const line of replayTestWarningLines(result)) {
67+
process.stdout.write(` ${line}\n`);
68+
}
6669
}
6770

6871
function renderVerboseTestResult(result: ReplaySuiteTestResult): void {
@@ -78,6 +81,9 @@ function renderVerboseTestResult(result: ReplaySuiteTestResult): void {
7881
if (result.status === 'skipped') {
7982
process.stdout.write(` ${result.message ?? 'skipped'}\n`);
8083
}
84+
for (const line of replayTestWarningLines(result)) {
85+
process.stdout.write(` ${line}\n`);
86+
}
8187
for (const line of replayTestStepLines(result)) {
8288
process.stdout.write(` ${line}\n`);
8389
}
@@ -447,6 +453,9 @@ function appendReplaySystemOutMetadata(lines: string[], test: ReplaySuiteTestRes
447453
appendOptionalLine(lines, 'session' in test ? `session: ${test.session}` : undefined);
448454
appendOptionalLine(lines, 'replayed' in test ? `replayed: ${test.replayed}` : undefined);
449455
appendOptionalLine(lines, 'healed' in test ? `healed: ${test.healed}` : undefined);
456+
for (const warning of replayTestWarningLines(test)) {
457+
lines.push(warning);
458+
}
450459
appendOptionalLine(
451460
lines,
452461
'artifactsDir' in test && test.artifactsDir ? `artifactsDir: ${test.artifactsDir}` : undefined,
@@ -513,6 +522,11 @@ function appendOptionalLine(lines: string[], line: string | undefined): void {
513522
if (line) lines.push(line);
514523
}
515524

525+
function replayTestWarningLines(result: ReplaySuiteTestResult): string[] {
526+
if (result.status !== 'passed') return [];
527+
return (result.warnings ?? []).map((warning) => `warning: ${warning}`);
528+
}
529+
516530
function formatJUnitSeconds(durationMs: number): string {
517531
return (Math.max(0, durationMs) / 1000).toFixed(3);
518532
}

‎src/daemon/handlers/__tests__/session-test-runtime.test.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ test('runReplayTestAttempt keeps cancellation active until a timed-out replay se
6767
});
6868
});
6969

70-
test('runReplayTestAttempt reports finalization failure after a passing replay', async () => {
70+
test('runReplayTestAttempt keeps a passing replay passed when finalization fails', async () => {
7171
const cleanupSession = vi.fn(async () => {});
7272

7373
const result = await runReplayTestAttempt({
@@ -82,9 +82,10 @@ test('runReplayTestAttempt reports finalization failure after a passing replay',
8282
cleanupSession,
8383
});
8484

85-
expect(result.ok).toBe(false);
86-
if (!result.ok) {
87-
expect(result.error.message).toBe('failed to stop recording');
88-
}
85+
expect(result.ok).toBe(true);
86+
if (!result.ok) throw new Error(result.error.message);
87+
expect(result.data?.warnings).toEqual([
88+
'Replay test finalization failed: failed to stop recording',
89+
]);
8990
expect(cleanupSession).toHaveBeenCalledWith('default:test:pass');
9091
});

‎src/daemon/handlers/session-test-runtime.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ export async function runReplayTestAttempt(
137137
tracePath,
138138
});
139139
if (response?.ok && finalizedResponse && !finalizedResponse.ok) {
140-
response = finalizedResponse;
140+
appendReplayTestWarning(
141+
response,
142+
`Replay test finalization failed: ${finalizedResponse.error.message}`,
143+
);
141144
}
142145
const cleanupStartedAt = Date.now();
143146
try {
@@ -281,6 +284,17 @@ function markReplayTimeoutCleanupPending(response: DaemonResponse | undefined):
281284
};
282285
}
283286

287+
function appendReplayTestWarning(
288+
response: Extract<DaemonResponse, { ok: true }>,
289+
warning: string,
290+
): void {
291+
const data = (response.data ??= {});
292+
const warnings = Array.isArray(data.warnings)
293+
? data.warnings.filter((entry): entry is string => typeof entry === 'string')
294+
: [];
295+
data.warnings = [...warnings, warning];
296+
}
297+
284298
function prepareReplayTestTimingTrace(params: {
285299
artifactsDir?: string;
286300
artifactPaths: Set<string>;

‎src/daemon/handlers/session-test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ async function runReplayTestCase(
480480
artifactsDir: testArtifactsDir,
481481
replayed: typeof finalResponse.data?.replayed === 'number' ? finalResponse.data.replayed : 0,
482482
healed: typeof finalResponse.data?.healed === 'number' ? finalResponse.data.healed : 0,
483+
...replayTestWarningsResultMetadata(finalResponse.data?.warnings),
483484
...replayTestShardResultMetadata(shard),
484485
...(attemptFailures.length > 0 ? { attemptFailures } : {}),
485486
};
@@ -517,6 +518,14 @@ async function runReplayTestCase(
517518
};
518519
}
519520

521+
function replayTestWarningsResultMetadata(
522+
warnings: unknown,
523+
): Pick<Extract<ReplaySuiteTestResult, { status: 'passed' }>, 'warnings'> {
524+
if (!Array.isArray(warnings)) return {};
525+
const filtered = warnings.filter((entry): entry is string => typeof entry === 'string');
526+
return filtered.length > 0 ? { warnings: filtered } : {};
527+
}
528+
520529
function replayTestShardResultMetadata(
521530
shard: ReplayTestShardContext | undefined,
522531
): Pick<ReplaySuiteTestFailed, 'shardIndex' | 'shardCount' | 'deviceId'> {

‎src/daemon/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export type ReplaySuiteTestPassed = {
5656
artifactsDir?: string;
5757
replayed: number;
5858
healed: number;
59+
warnings?: string[];
5960
attemptFailures?: ReplaySuiteAttemptFailure[];
6061
shardIndex?: number;
6162
shardCount?: number;

0 commit comments

Comments
 (0)