|
1 | 1 | import { test } from 'vitest'; |
2 | 2 | import assert from 'node:assert/strict'; |
3 | 3 | import { AppError } from '@agent-device/kernel/errors'; |
4 | | -import { discoverReplayTestEntries } from '../session-test-discovery.ts'; |
| 4 | +import { |
| 5 | + buildReplayTestInvocationId, |
| 6 | + buildReplayTestSessionName, |
| 7 | + discoverReplayTestEntries, |
| 8 | +} from '../session-test-discovery.ts'; |
| 9 | +import { buildReplayTestArtifactSlug, trimEdgeDashes } from '../session-test-artifacts.ts'; |
5 | 10 | import type { ReplayTestManifest, ReplayTestSource } from '../session-test-types.ts'; |
6 | 11 |
|
7 | 12 | // Scheduler-owned discovery policy (#1478 P3b): which sources a --platform filter runs, which |
@@ -75,3 +80,27 @@ test('a suite that matched nothing after filtering is rejected', () => { |
75 | 80 | (error: unknown) => error instanceof AppError && /No replay tests matched/.test(error.message), |
76 | 81 | ); |
77 | 82 | }); |
| 83 | + |
| 84 | +test('edge-dash trimming stays linear on an interior dash run (CodeQL js/polynomial-redos)', () => { |
| 85 | + // The slug pipeline collapses character runs before trimming, so only a |
| 86 | + // direct call can carry a long interior run — which is exactly the shape |
| 87 | + // the retired /^-+|-+$/g form re-scans quadratically (each interior dash |
| 88 | + // restarts a -+$ attempt that fails at the trailing x). 100k dashes take |
| 89 | + // seconds there and must stay well under a second here, with the input |
| 90 | + // returned byte-identical since nothing sits at the edges. |
| 91 | + const interiorRun = `x${'-'.repeat(100_000)}x`; |
| 92 | + const startedAt = performance.now(); |
| 93 | + const trimmed = trimEdgeDashes(interiorRun); |
| 94 | + assert.ok(performance.now() - startedAt < 1000); |
| 95 | + assert.equal(trimmed, interiorRun); |
| 96 | +}); |
| 97 | + |
| 98 | +test('all-dash inputs land on the documented fallbacks instead of empty identifiers', () => { |
| 99 | + assert.equal(buildReplayTestArtifactSlug('/tmp/####', '/tmp'), 'test'); |
| 100 | + assert.equal(buildReplayTestInvocationId('----'), 'suite'); |
| 101 | + // A session-name slug that trims to nothing is omitted entirely — no dangling separator. |
| 102 | + assert.equal( |
| 103 | + buildReplayTestSessionName('s', 'suite1', '/tmp/----.ad', 0), |
| 104 | + 's:test:suite1:1:attempt-1', |
| 105 | + ); |
| 106 | +}); |
0 commit comments