Skip to content

Commit 68441ea

Browse files
committed
test(onboard): keep legacy gateway fixtures linear
Signed-off-by: Prekshi Vyas <prekshiv@nvidia.com>
1 parent 40d9907 commit 68441ea

3 files changed

Lines changed: 85 additions & 69 deletions

File tree

src/lib/actions/uninstall/run-plan-gateway-segregation.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,15 @@ describe("uninstall gateway-port segregation (#3053)", () => {
142142
rmSync: fs.rmSync,
143143
run: (command, args) => {
144144
calls.push({ args, command });
145-
if (command === "systemctl" && args.includes("--property=MainPID")) {
146-
return ok(`${String(externalPid)}\n`);
147-
}
148-
if (command === "ps" && args.includes("uid=")) {
149-
return ok(`${String(process.getuid?.() ?? -1)}\n`);
150-
}
151-
return ok();
145+
return (
146+
(command === "systemctl" &&
147+
args.includes("--property=MainPID") &&
148+
ok(`${String(externalPid)}\n`)) ||
149+
(command === "ps" &&
150+
args.includes("uid=") &&
151+
ok(`${String(process.getuid?.() ?? -1)}\n`)) ||
152+
ok()
153+
);
152154
},
153155
runDocker: (args) => {
154156
dockerCalls.push(args);

src/lib/actions/uninstall/run-plan-gateway-service.test.ts

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,17 @@ function uninstall(
143143
commandExists: (command) => command === "openshell" || commandExists(command),
144144
run: (command, args, options) => {
145145
const delegated = run(command, args, options);
146-
if (command === "openshell" && args[0] === "gateway" && args[1] === "list") {
147-
return ok(JSON.stringify(gateways));
148-
}
149-
if (
150-
command === "systemctl" &&
151-
args.includes("--property=MainPID") &&
152-
delegated.stdout === ""
153-
) {
154-
return ok("0\n");
155-
}
156-
return delegated;
146+
return (
147+
(command === "openshell" &&
148+
args[0] === "gateway" &&
149+
args[1] === "list" &&
150+
ok(JSON.stringify(gateways))) ||
151+
(command === "systemctl" &&
152+
args.includes("--property=MainPID") &&
153+
delegated.stdout === "" &&
154+
ok("0\n")) ||
155+
delegated
156+
);
157157
},
158158
},
159159
);
@@ -321,13 +321,13 @@ describe("uninstall OpenShell gateway user service", () => {
321321
}),
322322
run: (command, args) => {
323323
calls.push([command, ...args]);
324-
if (command === "systemctl" && args.includes("--property=MainPID")) {
325-
return ok(`${String(pid)}\n`);
326-
}
327-
if (command === "ps" && args.includes("uid=")) {
328-
return ok(`${String(process.getuid?.() ?? -1)}\n`);
329-
}
330-
return ok();
324+
return (
325+
(command === "systemctl" &&
326+
args.includes("--property=MainPID") &&
327+
ok(`${String(pid)}\n`)) ||
328+
(command === "ps" && args.includes("uid=") && ok(`${String(process.getuid?.() ?? -1)}\n`)) ||
329+
ok()
330+
);
331331
},
332332
},
333333
[{ name: "nemoclaw" }, { name: "sibling" }],
@@ -410,30 +410,39 @@ describe("uninstall OpenShell gateway user service", () => {
410410
const calls: string[][] = [];
411411
const errors: string[] = [];
412412

413+
const externalAuthority = externallySupervised
414+
? {
415+
resolveGatewayTeardownAuthority: ({
416+
gatewayName,
417+
gatewayPort,
418+
}: {
419+
gatewayName: string;
420+
gatewayPort: number;
421+
}) => ({
422+
gatewayName,
423+
gatewayPort,
424+
mode: "externally-supervised" as const,
425+
source: "declared" as const,
426+
endpoint: `http://127.0.0.1:${String(gatewayPort)}`,
427+
stateDir: path.dirname(configPath),
428+
supervisor: {
429+
kind: "systemd-user" as const,
430+
serviceName: "external-openshell.service",
431+
execPath: "/usr/local/bin/openshell-gateway",
432+
},
433+
requiredCapabilities: [],
434+
}),
435+
}
436+
: {};
413437
const deps: Partial<UninstallRunDeps> = {
414438
commandExists: (command) => command === "systemctl",
415439
run: (command, args) => {
416440
calls.push([command, ...args]);
417441
return ok();
418442
},
419443
error: (message) => errors.push(message),
444+
...externalAuthority,
420445
};
421-
if (externallySupervised) {
422-
deps.resolveGatewayTeardownAuthority = ({ gatewayName, gatewayPort }) => ({
423-
gatewayName,
424-
gatewayPort,
425-
mode: "externally-supervised",
426-
source: "declared",
427-
endpoint: `http://127.0.0.1:${String(gatewayPort)}`,
428-
stateDir: path.dirname(configPath),
429-
supervisor: {
430-
kind: "systemd-user",
431-
serviceName: "external-openshell.service",
432-
execPath: "/usr/local/bin/openshell-gateway",
433-
},
434-
requiredCapabilities: [],
435-
});
436-
}
437446

438447
const result = uninstall(test, keepOpenShell, deps, [
439448
{ name: "nemoclaw" },

src/lib/onboard/docker-driver-gateway-config-toml.test.ts

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ function writePreScopedGatewayConfig(
3737
driver: "docker" | "podman" = "docker",
3838
): { configPath: string; env: Record<string, string>; gatewayId: string } {
3939
const env = baseGatewayEnv(stateDir);
40-
if (driver === "podman") {
41-
env.OPENSHELL_DRIVERS = "podman";
42-
env.OPENSHELL_PODMAN_SOCKET = path.join(stateDir, "podman.sock");
43-
}
40+
Object.assign(
41+
env,
42+
driver === "podman"
43+
? {
44+
OPENSHELL_DRIVERS: "podman",
45+
OPENSHELL_PODMAN_SOCKET: path.join(stateDir, "podman.sock"),
46+
}
47+
: {},
48+
);
4449
const gatewayId = legacyGatewayIdForStateDir(stateDir);
4550
const jwtBundle = ensureDockerDriverGatewayJwtBundle(stateDir);
4651
let toml = buildDockerDriverGatewayConfigToml(
@@ -271,40 +276,40 @@ describe("docker-driver-gateway config TOML", () => {
271276
let stderr = "";
272277
let proofTimer: NodeJS.Timeout | undefined;
273278
const startupTimer = setTimeout(() => {
274-
if (settled) return;
275-
settled = true;
276-
spawned.kill("SIGKILL");
277-
reject(new Error("child did not finish importing the gateway config module"));
279+
settled ||
280+
((settled = true),
281+
spawned.kill("SIGKILL"),
282+
reject(new Error("child did not finish importing the gateway config module")));
278283
}, 15_000);
279284
spawned.stderr.on("data", (chunk: Buffer) => {
280285
stderr += chunk.toString("utf-8");
281286
});
282287
spawned.stdout.on("data", (chunk: Buffer) => {
283288
stdout += chunk.toString("utf-8");
284-
if (ready || !stdout.includes("ready\n")) return;
285-
ready = true;
286-
clearTimeout(startupTimer);
287-
proofTimer = setTimeout(() => {
288-
if (settled) return;
289-
settled = true;
290-
spawned.kill("SIGKILL");
291-
reject(new Error("scoped cleanup proof blocked while opening a FIFO config"));
292-
}, 2_000);
293-
spawned.stdin.write("run\n");
289+
(ready || !stdout.includes("ready\n")) ||
290+
((ready = true),
291+
clearTimeout(startupTimer),
292+
(proofTimer = setTimeout(() => {
293+
settled ||
294+
((settled = true),
295+
spawned.kill("SIGKILL"),
296+
reject(new Error("scoped cleanup proof blocked while opening a FIFO config")));
297+
}, 2_000)),
298+
spawned.stdin.write("run\n"));
294299
});
295300
spawned.once("error", (error) => {
296-
if (settled) return;
297-
settled = true;
298-
clearTimeout(startupTimer);
299-
if (proofTimer) clearTimeout(proofTimer);
300-
reject(error);
301+
settled ||
302+
((settled = true),
303+
clearTimeout(startupTimer),
304+
proofTimer && clearTimeout(proofTimer),
305+
reject(error));
301306
});
302307
spawned.once("exit", (code) => {
303-
if (settled) return;
304-
settled = true;
305-
clearTimeout(startupTimer);
306-
if (proofTimer) clearTimeout(proofTimer);
307-
resolve({ code, stderr });
308+
settled ||
309+
((settled = true),
310+
clearTimeout(startupTimer),
311+
proofTimer && clearTimeout(proofTimer),
312+
resolve({ code, stderr }));
308313
});
309314
},
310315
);

0 commit comments

Comments
 (0)