fix: clear the last polynomial-redos instance in swift-cache - #1549
Conversation
sanitizeCacheName used /^-+|-+$/g to trim edge dashes, the same js/polynomial-redos pattern PR #1546 retired everywhere else. Replace it with the linear-time trim used there, and add a counterfactual regression test that fails against the old regex on a long interior dash run.
Size Report
Startup median (7 runs, lower is better):
Top changed chunks:
|
|
Reviewed exact head |
…h compileSwiftSourceText Addresses PR #1549 reviewer feedback: sanitizeCacheName was exported solely so the regression test could import it, which docs/agents/testing.md's test-interface rule forbids. Reverted the export and rewrote the test to exercise the sanitizer through compileSwiftSourceText, an existing production seam that already calls it. - Timing pin: a cache name with a 100k-char interior dash run still resolves in sub-second time (the call may reject once it reaches disk I/O due to the OS path-component length limit, but that happens only after the now-fast sanitize step, so timing the settle either way still proves no catastrophic backtracking). - Fallback pin: a cache name that sanitizes to nothing (e.g. '---') still produces the 'swift-helper' fallback, observed via the returned executable path. Counterfactuals (see PR comment for full output): - Restoring the retired `/^-+|-+$/g` regex trim made the timing pin fail: 3428ms >= 1000ms. - Removing the `|| 'swift-helper'` fallback made the fallback pin fail: basename did not start with 'swift-helper-'.
|
Addressed the P2: reverted Test changes (
Counterfactual evidence:
Validation: Pushed to Generated by Claude Code |
|
Summary
sanitizeCacheNameinsrc/utils/swift-cache.tsused.replaceAll(/^-+|-+$/g, ''), the exactjs/polynomial-redospattern class fix: clear the polynomial-redos class across main #1546 retired everywhere else in the repo — this instance was missed.packages/replay-test/src/internal/session-test-artifacts.ts(trimEdgeDashes), kept local to this file since it has a single call site.Test plan
'x' + '-'.repeat(100_000) + 'x') completes in <1s and returns the input unchanged. Verified it fails against the retired regex (~3.2s, well over the 1s budget).pnpm typecheckpnpm lintpnpm format:checkvitest run src/utils/__tests__/swift-cache.test.ts