Skip to content

Commit 7d5d46f

Browse files
committed
fix(windows): normalize inventory skip grouping
Strip only balanced parentheses that enclose a complete skip expression before applying the Windows-false ternary exemption. Generated-by: Maka
1 parent 8508b9b commit 7d5d46f

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

scripts/windows-test-inventory.mjs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function classifySkip(path, title, expression) {
223223
}
224224

225225
export function excludesWindows(expression) {
226-
const compact = expression.replaceAll(/\s+/gu, ' ');
226+
const compact = stripBalancedOuterParentheses(expression.replaceAll(/\s+/gu, ' ').trim());
227227
// A Windows-only regression commonly uses `false` on Windows and a skip
228228
// reason elsewhere. Exempt only when that ternary is the complete skip
229229
// expression: a surrounding boolean expression may still skip on Windows.
@@ -240,6 +240,39 @@ export function excludesWindows(expression) {
240240
);
241241
}
242242

243+
function stripBalancedOuterParentheses(expression) {
244+
let compact = expression;
245+
while (hasCompleteOuterParentheses(compact)) compact = compact.slice(1, -1).trim();
246+
return compact;
247+
}
248+
249+
function hasCompleteOuterParentheses(expression) {
250+
if (!expression.startsWith('(') || !expression.endsWith(')')) return false;
251+
let depth = 0;
252+
let quote;
253+
let escaped = false;
254+
for (let index = 0; index < expression.length; index += 1) {
255+
const char = expression[index];
256+
if (quote) {
257+
if (escaped) escaped = false;
258+
else if (char === '\\') escaped = true;
259+
else if (char === quote) quote = undefined;
260+
continue;
261+
}
262+
if (char === "'" || char === '"' || char === '`') {
263+
quote = char;
264+
continue;
265+
}
266+
if (char === '(') depth += 1;
267+
else if (char === ')') {
268+
depth -= 1;
269+
if (depth === 0) return index === expression.length - 1;
270+
if (depth < 0) return false;
271+
}
272+
}
273+
return false;
274+
}
275+
243276
function nearbyTestTitle(lines, skipIndex) {
244277
const context = lines.slice(Math.max(0, skipIndex - 12), skipIndex + 1).join('\n');
245278
const matches = [...context.matchAll(/\b(?:test|it|describe)\s*\(\s*(['"`])([\s\S]+?)\1/gu)];

scripts/windows-test-inventory.test.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ test('exempts a complete Windows-false ternary from the skip inventory', () => {
77
excludesWindows("process.platform === 'win32' ? false : 'Windows-only regression'"),
88
false,
99
);
10+
assert.equal(
11+
excludesWindows("((process.platform === 'win32' ? false : 'Windows-only regression'))"),
12+
false,
13+
);
1014
});
1115

1216
test('keeps a composite expression that can still skip on Windows', () => {
@@ -16,6 +20,12 @@ test('keeps a composite expression that can still skip on Windows', () => {
1620
),
1721
true,
1822
);
23+
assert.equal(
24+
excludesWindows(
25+
"(process.platform === 'win32' ? false : 'Unix-only') || (process.env.CI === '1')",
26+
),
27+
true,
28+
);
1929
});
2030

2131
test('keeps a direct Windows exclusion in the skip inventory', () => {

0 commit comments

Comments
 (0)