fix(windows): preserve transient runtime admission failures (#2467)
Fixes #2257. Thanks to @chqcjq for the native self-test retry diagnosis in #2266. Preserve retry disposition through analysis workflows. Native warm admission requires exact sharing/lock codes and affirmative pre-allocation evidence; cleanup ownership takes precedence. No automatic retry or new analysis cache. Verified with real Windows 11 CLI, same-connection SDK MCP normal/conflict/recovery, the Windows native verifier, 99 focused tests and static/docs gates. Official npm 11.16.0 launcher sources were the application input. No IDA or Ghidra engine was used for this change. Win32 5 was not reproduced; no resolution claim for #1701/#2196. Performance measurements and limits are recorded in experiments/analysis-efficiency/windows-runtime-retry.md.
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import { beforeEach, expect, it, vi } from "vitest";
|
||||
import { WindowsPrivateRuntime } from "../../src/windows/WindowsPrivateRuntime.js";
|
||||
import { PrivateRuntimeRootUnavailableError } from "../../src/process/PrivateRuntimeRootUnavailableError.js";
|
||||
|
||||
const { nativeCall } = vi.hoisted(() => ({ nativeCall: vi.fn() }));
|
||||
vi.mock("../../src/windows/WindowsNativeLoader.js", async (original) => ({
|
||||
...(await original<
|
||||
typeof import("../../src/windows/WindowsNativeLoader.js")
|
||||
>()),
|
||||
requireWindowsNativeAuthority: () => ({ call: nativeCall }),
|
||||
}));
|
||||
beforeEach(() => {
|
||||
nativeCall.mockReset();
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
label: "sharing conflict before allocation",
|
||||
win32Code: 32,
|
||||
runtimeAllocation: "not-started",
|
||||
retryable: true,
|
||||
},
|
||||
{
|
||||
label: "lock conflict before allocation",
|
||||
win32Code: 33,
|
||||
runtimeAllocation: "not-started",
|
||||
retryable: true,
|
||||
},
|
||||
{ label: "unknown allocation", win32Code: 32, retryable: false },
|
||||
{
|
||||
label: "possible allocation",
|
||||
win32Code: 32,
|
||||
runtimeAllocation: "started",
|
||||
retryable: false,
|
||||
},
|
||||
{
|
||||
label: "permission failure",
|
||||
win32Code: 5,
|
||||
runtimeAllocation: "not-started",
|
||||
retryable: false,
|
||||
},
|
||||
{
|
||||
label: "string code",
|
||||
win32Code: "32",
|
||||
runtimeAllocation: "not-started",
|
||||
retryable: false,
|
||||
},
|
||||
{
|
||||
label: "inconsistent error code",
|
||||
win32Code: 32,
|
||||
code: "EACCES",
|
||||
runtimeAllocation: "not-started",
|
||||
retryable: false,
|
||||
},
|
||||
])(
|
||||
"retains $label without guessing runtime ownership",
|
||||
({ retryable, label: _label, ...facts }) => {
|
||||
const cause = Object.assign(new Error("Selected native diagnostic"), {
|
||||
code: "ERR_REA_WINDOWS_NATIVE",
|
||||
...facts,
|
||||
});
|
||||
nativeCall.mockImplementation(() => {
|
||||
throw cause;
|
||||
});
|
||||
let observed: unknown;
|
||||
try {
|
||||
WindowsPrivateRuntime.create("D:/selected parent", "selected-prefix-");
|
||||
} catch (failure: unknown) {
|
||||
observed = failure;
|
||||
}
|
||||
expect(nativeCall).toHaveBeenCalledTimes(1);
|
||||
expect(nativeCall).toHaveBeenCalledWith("runtime_create", [
|
||||
"D:/selected parent",
|
||||
"selected-prefix-",
|
||||
]);
|
||||
if (retryable) {
|
||||
expect(observed).toBeInstanceOf(PrivateRuntimeRootUnavailableError);
|
||||
expect(observed).toMatchObject({
|
||||
message: cause.message,
|
||||
cause,
|
||||
retryable: true,
|
||||
});
|
||||
} else expect(observed).toBe(cause);
|
||||
},
|
||||
);
|
||||
|
||||
it("does not infer a transient status from a human-readable diagnostic", () => {
|
||||
const cause = new Error("Open Windows path component failed (Win32 32)");
|
||||
nativeCall.mockImplementation(() => {
|
||||
throw cause;
|
||||
});
|
||||
let observed: unknown;
|
||||
try {
|
||||
WindowsPrivateRuntime.create("D:/selected parent", "selected-prefix-");
|
||||
} catch (failure: unknown) {
|
||||
observed = failure;
|
||||
}
|
||||
expect(observed).toBe(cause);
|
||||
});
|
||||
Reference in New Issue
Block a user