fix(native): preserve definitive failures alongside operational diagnostics
This commit is contained in:
@@ -4,7 +4,7 @@ import type { NativeCommandCapture } from "./CommandRunner.js";
|
||||
/** Strip the diagnostic's echoed pathname for classification, keeping the raw line elsewhere. */
|
||||
export const codesignReason = (line: string, path: string): string => {
|
||||
if (line.startsWith(`${path}: `)) return line.slice(path.length + 2);
|
||||
if (line.startsWith("/")) {
|
||||
if (line.startsWith("/") || line.startsWith(`${path}/`)) {
|
||||
const delimiter = line.lastIndexOf(": ");
|
||||
return delimiter >= 0 ? line.slice(delimiter + 2) : "";
|
||||
}
|
||||
@@ -26,26 +26,28 @@ export const codesignReasons = (
|
||||
};
|
||||
|
||||
/** Classify only explicit diagnostic reasons; nonzero exit alone proves no invalidity. */
|
||||
const operationalReason = (reason: string): boolean =>
|
||||
/^(?:permission denied|operation not permitted|EACCES\b|EPERM\b|I\/O error|input\/output error)/iu.test(
|
||||
reason,
|
||||
);
|
||||
|
||||
/** Operational diagnostics can coexist with an independently proven invalid component. */
|
||||
export const codesignOperationalFailure = (
|
||||
capture: NativeCommandCapture,
|
||||
path: string,
|
||||
): boolean => codesignReasons(capture, path).some(operationalReason);
|
||||
|
||||
const verificationStatus = (
|
||||
capture: NativeCommandCapture,
|
||||
reasons: readonly string[],
|
||||
unsigned: boolean,
|
||||
): NonNullable<InspectSignature["verification"]>["status"] => {
|
||||
if (capture.exitCode === 0) return "valid";
|
||||
if (
|
||||
reasons.some((reason) =>
|
||||
/^(?:permission denied|operation not permitted|EACCES\b|EPERM\b|I\/O error|input\/output error)/iu.test(
|
||||
reason,
|
||||
),
|
||||
)
|
||||
)
|
||||
return "unknown";
|
||||
const unsignedReason = reasons.some((reason) =>
|
||||
/^(?:code object is not signed at all|code object is not signed|not signed at all)/iu.test(
|
||||
reason,
|
||||
),
|
||||
);
|
||||
if (unsignedReason) return unsigned ? "unsigned" : "invalid";
|
||||
if (
|
||||
reasons.some((reason) =>
|
||||
/^(?:a sealed resource is missing or invalid|code or signature modified|invalid signature|invalid or unsupported format|resource envelope is obsolete|signature is invalid|unsealed contents present|file modified:|file added:|a resource envelope is obsolete)/iu.test(
|
||||
@@ -54,6 +56,9 @@ const verificationStatus = (
|
||||
)
|
||||
)
|
||||
return "invalid";
|
||||
if (unsignedReason && !unsigned) return "invalid";
|
||||
if (reasons.some(operationalReason)) return "unknown";
|
||||
if (unsignedReason) return "unsigned";
|
||||
return "unknown";
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user