Files
reverse-engineering-anything/scripts/lint/rules/provider-failure-classifier.mjs
T
morluto 1f7884b5b9 refactor(process): classify owned command outcomes through one owner (#10628)
* fix(pcap): report a refused tool launch as an unavailable tool

When a capture read's tool launch was refused with EPERM, pcap reported it
as unreadable tool output (AnalysisProtocolError) instead of an unavailable
tool. Pcap also never told "not executable" apart from "missing".

Add classifyLaunchFailure in src/process as the one owner of which spawn
errnos mean missing (ENOENT, ENOTDIR) and which mean present but not
executable (EACCES, EPERM, ENOEXEC, EISDIR). Pcap, apktool and gdb used three
different errno lists; all three now use it.

* refactor(process): classify owned command outcomes through one owner

Add ProviderOutcome, read once from the supervisor's facts, and classifyProviderOutcome, the one mapping from an outcome to a typed error. Migrate pcap and the shared artifact producer command failure (TShark, sigrok). Add the rea/provider-failure-classifier lint rule with a shrink-only baseline of per-site (cause: unknown) => AnalysisError functions.

* refactor(process): classify Java and adb launch refusals with the shared owner (#10598)

The Ghidra and JADX Java probes and adb's version probe now take
missing-versus-not-executable from classifyLaunchFailure instead of their
own errno checks. ELOOP and ENAMETOOLONG join the owner's missing set, so
adb keeps its existing classification and both Java probes now treat a
non-directory path component as a missing runtime.

* fix(pcap): preserve command launch attribution

* test(pcap): expect an unknown failing stage when a limited capture tool exits unsuccessfully

* refactor(process): classify owned command outcomes through one owner

Add ProviderOutcome, read once from the supervisor's facts, and classifyProviderOutcome, the one mapping from an outcome to a typed error. Migrate pcap and the shared artifact producer command failure (TShark, sigrok). Add the rea/provider-failure-classifier lint rule with a shrink-only baseline of per-site (cause: unknown) => AnalysisError functions.

* test(lint): cover baselined files in the provider-failure classifier rule

* fix(pcap): attribute a limited capture's exit through the prlimit wrapper

* fix(process): identify the refused executable for every launcher shape

Name the executable on errnos Node throws synchronously from spawn
(ENOEXEC, ENOTDIR, ...) and read the Windows native launcher's
executable-launch constraint, so pcap attributes those refusals to the
selected tool or limiter instead of an unknown stage.

* test(pcap): prove synchronous launch naming with ENOTDIR on every POSIX host

* refactor(process): build classified cancellations with cancelledBy and the carried caller reason

* chore(lint): count runOwned's close-failure mapper from main in the classifier baseline
2026-11-15 13:45:46 +08:00

92 lines
2.9 KiB
JavaScript

import { readFileSync } from "node:fs";
import { relative } from "node:path";
import { fileURLToPath } from "node:url";
const root = fileURLToPath(new URL("../../../", import.meta.url));
/**
* Files that predate the rule, with their count of per-site classifier
* functions. A count may only shrink: the rule reports a file above or below
* its entry.
*/
const baseline = JSON.parse(
readFileSync(
new URL("./provider-failure-classifier-baseline.json", import.meta.url),
"utf8",
),
);
const isUnknownParameter = (parameter) => {
const target =
parameter.type === "AssignmentPattern"
? parameter.left
: parameter.type === "TSParameterProperty"
? parameter.parameter
: parameter;
return target?.typeAnnotation?.typeAnnotation?.type === "TSUnknownKeyword";
};
const namesAnalysisError = (type) => {
if (type === undefined || type === null) return false;
if (type.type === "TSUnionType") return type.types.some(namesAnalysisError);
return (
type.type === "TSTypeReference" &&
type.typeName.type === "Identifier" &&
type.typeName.name === "AnalysisError"
);
};
/**
* A per-site classifier takes an unexamined `unknown` failure and returns an
* `AnalysisError`, re-deriving what kind of failure it was.
*/
const isClassifier = (node) =>
node.params.some(isUnknownParameter) &&
namesAnalysisError(node.returnType?.typeAnnotation);
export default {
meta: {
type: "problem",
docs: {
description:
"Classify raw provider failures through the shared ProviderOutcome classifier, not a new per-site function.",
},
schema: [],
messages: {
classifier:
"Do not add a per-site `(cause: unknown) => AnalysisError` classifier. Read the supervisor's facts with providerOutcomeOf(cause) and classify them with classifyProviderOutcome(...), putting provider-specific refusals in its dialect.",
stale:
"provider-failure-classifier-baseline.json allows {{allowed}} per-site classifiers in this file but {{actual}} remain; lower the entry to {{actual}}.",
},
},
create(context) {
const filename = relative(
root,
context.physicalFilename ?? context.filename,
).replaceAll("\\", "/");
const classifiers = [];
const visit = (node) => {
if (isClassifier(node)) classifiers.push(node);
};
return {
ArrowFunctionExpression: visit,
FunctionDeclaration: visit,
FunctionExpression: visit,
"Program:exit"(program) {
const allowed = baseline[filename] ?? 0;
if (classifiers.length > allowed)
for (const node of classifiers)
context.report({ node, messageId: "classifier" });
else if (classifiers.length < allowed)
context.report({
node: program,
messageId: "stale",
data: {
allowed: String(allowed),
actual: String(classifiers.length),
},
});
},
};
},
};