fix(android): clean Windows workspaces after owner termination (#2440)
* fix(android): clean Windows workspaces after owner termination * fix(android): retain Windows workspace guardian on cleanup failure * fix(android): preserve released guardian pipe state on cleanup retry * fix(android): normalize extended local guardian parent paths --------- Co-authored-by: LcokHcak <268763621+LcokHcak@users.noreply.github.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
co-authored by
LcokHcak
morluto
parent
c45d912c91
commit
c938f97fb2
@@ -0,0 +1,60 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { readFile } from "node:fs/promises";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
it.skipIf(process.platform !== "win32")(
|
||||
"retains guardian cleanup ownership through more than 100 transient failures",
|
||||
async () => {
|
||||
const guardian = await readFile(
|
||||
new URL(
|
||||
"../../../scripts/rea-android-workspace-guardian.mjs",
|
||||
import.meta.url,
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
const withoutTimer = guardian
|
||||
.replace(/^#!.*\r?\n/u, "")
|
||||
.replace(
|
||||
'import { setTimeout as delay } from "node:timers/promises";',
|
||||
"const delay = async () => {};",
|
||||
);
|
||||
const injected = withoutTimer.replace(
|
||||
'import { WindowsPrivateRuntime } from "../dist/windows/WindowsPrivateRuntime.js";',
|
||||
`let attempts = 0;
|
||||
const WindowsPrivateRuntime = {
|
||||
create: () => ({
|
||||
observation: { path: "synthetic-root", volumeSerial: "0", fileId: "0", privateDacl: true },
|
||||
close: async () => { if (++attempts <= 101) throw new Error("transient cleanup failure"); },
|
||||
}),
|
||||
};`,
|
||||
);
|
||||
expect(withoutTimer).not.toBe(guardian);
|
||||
expect(injected).not.toBe(withoutTimer);
|
||||
const child = spawn(
|
||||
process.execPath,
|
||||
[
|
||||
"--input-type=module",
|
||||
"-e",
|
||||
'process.argv.splice(1, 0, "guardian.mjs");\n' + injected,
|
||||
"synthetic-parent",
|
||||
],
|
||||
{ signal: AbortSignal.timeout(3000) },
|
||||
);
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
child.stdout.on("data", (chunk: Buffer) => {
|
||||
stdout += chunk.toString();
|
||||
});
|
||||
child.stderr.on("data", (chunk: Buffer) => {
|
||||
stderr += chunk.toString();
|
||||
});
|
||||
child.stdin.end();
|
||||
const code = await new Promise<number | null>((resolve, reject) => {
|
||||
child.once("close", resolve);
|
||||
child.once("error", reject);
|
||||
});
|
||||
expect(code, stderr).toBe(0);
|
||||
expect(JSON.parse(stdout.trim())).toMatchObject({ path: "synthetic-root" });
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user