From 11836700be3b1a49d4cb5caaa450b26ae1ebd49f Mon Sep 17 00:00:00 2001 From: Priya Raman Date: Fri, 4 Sep 2026 01:55:58 +0000 Subject: [PATCH] fix(runner): treat await as a regex-literal prefix in the wait guard The scanner did not list await as a keyword that expects an expression next, so it read the / in an await-prefixed regex literal as division. A closing brace inside that regex then closed template interpolation tracking early and hid a real vi.waitFor( call from the guard. Add await to the keyword set and add a regression test for this exact form. Co-authored-by: Paperclip --- .../scripts/check-bare-real-process-waits.test.mjs | 12 ++++++++++++ .../scripts/lib/bare-real-process-wait.mjs | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/paperclip-runner/scripts/check-bare-real-process-waits.test.mjs b/packages/paperclip-runner/scripts/check-bare-real-process-waits.test.mjs index b16c74de80f..24eaf6f0c6a 100644 --- a/packages/paperclip-runner/scripts/check-bare-real-process-waits.test.mjs +++ b/packages/paperclip-runner/scripts/check-bare-real-process-waits.test.mjs @@ -194,6 +194,18 @@ test("rejects a vi.waitFor( that follows a regex literal with a quantifier's ope ]); }); +test("rejects a vi.waitFor( that follows an await-prefixed regex literal with a closing brace inside a template literal interpolation", () => { + const source = [ + "async function example() {", + " const message = `status: ${await /}/.test(x) ? await vi.waitFor(() => expect(x).toBe(1)) : false}`;", + "}", + ].join("\n"); + + assert.deepEqual(findBareRealProcessWaits(source), [ + { line: 2, pattern: "vi.waitFor(" }, + ]); +}); + test("ignores a vi.waitFor( written inside a regex literal's own text, inside a template literal interpolation", () => { const source = [ "async function example() {", diff --git a/packages/paperclip-runner/scripts/lib/bare-real-process-wait.mjs b/packages/paperclip-runner/scripts/lib/bare-real-process-wait.mjs index 62ecf21ce93..f76d8e15346 100644 --- a/packages/paperclip-runner/scripts/lib/bare-real-process-wait.mjs +++ b/packages/paperclip-runner/scripts/lib/bare-real-process-wait.mjs @@ -59,7 +59,7 @@ async function collectSourceFiles(target) { // state; this heuristic only needs to hold for the code this guard scans. const REGEX_PRECEDING_KEYWORDS = new Set([ "return", "typeof", "instanceof", "in", "of", "new", "delete", "void", - "yield", "case", "throw", "do", "else", + "yield", "case", "throw", "do", "else", "await", ]); function isRegexLiteralStart(source, index) {