refactor(verify): exclude negated .ok checks from the abort-reclassification guard

The completed-abort-reclassification pattern matched any `.ok && …aborted`,
including `!outcome.ok && signal?.aborted`, which attaches a secondary
cancellation to an already failed primary and reclassifies nothing. Move
the pattern to completed-abort-guard.mjs, where the receiver chain
(member, optional, private, element and call segments) must start the
check, and cover positive and negated forms in tests.
DesktopApplicationState and FridaInstrumentationService leave the
baseline.

Fixes #11920

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
gensokyo-devandgensokyo-dev authored and Ysopwnable committed 2026-11-21 19:07:31 +01:00
1 parent b95bd814a7
commit a80dc68318
5 files changed
+65 -3

No files matched your search

+2 -1
View File
@@ -11,6 +11,7 @@ import { localCompletenessEnumCount } from "./completeness-enum-guard.mjs";
import { countKeyedFirstMatches } from "./keyed-first-match.mjs";
import { budgetArithmeticCount } from "./budget-arithmetic-guard.mjs";
import { localLimitErrorClassCount } from "./limit-class-guard.mjs";
import { completedAbortReclassificationCount } from "./completed-abort-guard.mjs";
import { countDefaultValidationClients } from "./mcp-client-validation.mjs";
import {
isComparisonOrCountFile,
@@ -635,7 +636,7 @@ checkCounted(
"completed result reclassified by a hand-read abort signal (finalize through runOwned in src/providers/runOwned)",
"completed-abort-reclassification",
files,
/\.ok\s*&&\s*(?:isAborted\(|[\w.?]*signal\??\.aborted)/gu,
completedAbortReclassificationCount,
["src/providers/runOwned.ts"],
);
@@ -1,8 +1,6 @@
{
"src/application/EvidenceInputResolver.ts": 1,
"src/application/binary/BinarySession.ts": 1,
"src/application/desktop/DesktopApplicationState.ts": 1,
"src/application/frida/FridaInstrumentationService.ts": 1,
"src/browser/CdpBrowserProvider.ts": 1,
"src/browser/CdpElectronProvider.ts": 1,
"src/browser/PlaywrightBrowserScenarioProvider.ts": 1,
@@ -0,0 +1 @@
export function completedAbortReclassificationCount(content: string): number;
+18
View File
@@ -0,0 +1,18 @@
// Counts completed results reclassified by a hand-read abort signal:
// `<receiver>.ok && isAborted(…)` or `<receiver>.ok && …signal.aborted`.
// The receiver chain must start the check, so a negated `!outcome.ok && …`,
// which attaches a secondary cancellation to a failed primary, is not
// counted. Receivers may use member, optional, private, element and call
// segments, or start with one parenthesized expression, and each part may
// carry a TypeScript non-null assertion (`result!.ok`). Parentheses may nest
// one level, as in `(await settle()).ok`; element brackets cannot nest.
const parenthesized = String.raw`\((?:[^()]|\([^()]*\))*\)`;
const segment = String.raw`(?:(?:\??\.#?[A-Za-z_$][\w$]*|(?:\?\.)?\[[^[\]]*\]|(?:\?\.)?${parenthesized})!?)`;
const completedAbortReclassification = new RegExp(
String.raw`(?<![\w$#.?\])]|!\s*)(?:[A-Za-z_$][\w$]*|${parenthesized})!?${segment}*\??\.ok\s*&&\s*(?:isAborted\(|[\w.?]*signal\??\.aborted)`,
"gu",
);
/** @param {string} content */
export const completedAbortReclassificationCount = (content) =>
content.match(completedAbortReclassification)?.length ?? 0;