fix(windows): retain failed native inspection ownership (#1826)

This commit is contained in:
Ysopwnable
2026-10-11 21:33:25 +08:00
committed by GitHub
parent 6ac5c36503
commit 0b4ce83618
11 changed files with 240 additions and 19 deletions
+7 -6
View File
@@ -169,17 +169,18 @@ describe("packaged Windows native admission", () => {
}),
).toMatchObject({
available: false,
retryable: true,
reason: expect.stringContaining("private DACL: access denied"),
});
});
it("requires every inspected native fact", () => {
const value = fixture();
expect(
loadWindowsNativeAuthority({
...value.host,
loadArtifact: () => ({ call: () => ({ privateDacl: true }) }),
}).available,
).toBe(false);
const loaded = loadWindowsNativeAuthority({
...value.host,
loadArtifact: () => ({ call: () => ({ privateDacl: true }) }),
});
expect(loaded.available).toBe(false);
expect(loaded).not.toHaveProperty("retryable");
});
});
+20 -3
View File
@@ -67,7 +67,12 @@ export interface WindowsNativeAuthority {
/** Availability of the bundled native implementation, including load failures. */
export type WindowsNativeLoadResult =
| { readonly available: true; readonly authority: WindowsNativeAuthority }
| { readonly available: false; readonly reason: string };
| {
readonly available: false;
readonly reason: string;
/** Only a failed native invocation can recover on a later query. */
readonly retryable?: true;
};
/** Trusted package reads and module loading, replaceable in loader tests. */
export interface WindowsNativeLoadHost {
@@ -106,7 +111,17 @@ export const loadWindowsNativeAuthority = (
);
assertWindowsX64Artifact(artifact);
const binding = bindingSchema.parse(host.loadArtifact());
const inspection = inspectionSchema.parse(binding.call("inspect", []));
let observed: unknown;
try {
observed = binding.call("inspect", []);
} catch (cause: unknown) {
return {
available: false,
retryable: true,
reason: `REA Windows native self-test failed: ${cause instanceof Error ? cause.message : String(cause)}`,
};
}
const inspection = inspectionSchema.parse(observed);
return { available: true, authority: { call: binding.call, inspection } };
} catch (cause: unknown) {
return {
@@ -131,8 +146,10 @@ const assertWindowsX64Artifact = (bytes: Buffer): void => {
let cached: WindowsNativeLoadResult | undefined;
/** Load only the package-owned artifact, lazily and once per process. */
/** Cache stable admission; let a later query retry failed owned inspection. */
export const systemWindowsNativeAuthority = (): WindowsNativeLoadResult => {
if (cached?.available === false && cached.retryable === true)
cached = undefined;
cached ??= loadWindowsNativeAuthority({
platform: process.platform,
architecture: process.arch,