fix(ci): isolate Linux Hopper process fixture inventory
This commit is contained in:
committed by
Kaoru0822
parent
ad16d250e3
commit
c0018ca403
@@ -1,3 +1,4 @@
|
|||||||
export function assertCleanLinuxHopperRuntime(
|
export function assertCleanLinuxHopperRuntime(
|
||||||
launcherPaths?: readonly string[],
|
launcherPaths?: readonly string[],
|
||||||
|
procRoot?: string,
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export const assertCleanLinuxHopperRuntime = async (
|
|||||||
? []
|
? []
|
||||||
: [process.env.HOPPER_LAUNCHER_PATH]),
|
: [process.env.HOPPER_LAUNCHER_PATH]),
|
||||||
],
|
],
|
||||||
|
procRoot = "/proc",
|
||||||
) => {
|
) => {
|
||||||
const { stdout } = await execFileAsync("ps", ["-ax", "-o", "command="]);
|
const { stdout } = await execFileAsync("ps", ["-ax", "-o", "command="]);
|
||||||
if (/\/opt\/hopper\/bin\/Hopper|\bXvfb\b|hopper-demo-x11\.py/u.test(stdout))
|
if (/\/opt\/hopper\/bin\/Hopper|\bXvfb\b|hopper-demo-x11\.py/u.test(stdout))
|
||||||
@@ -32,17 +33,17 @@ export const assertCleanLinuxHopperRuntime = async (
|
|||||||
// /proc exposes the executed file even when argv[0] names a removed symlink.
|
// /proc exposes the executed file even when argv[0] names a removed symlink.
|
||||||
// Compare file identity, not a display path or a process name.
|
// Compare file identity, not a display path or a process name.
|
||||||
let inspectionError;
|
let inspectionError;
|
||||||
for (const entry of await readdir("/proc", { withFileTypes: true })) {
|
for (const entry of await readdir(procRoot, { withFileTypes: true })) {
|
||||||
if (!entry.isDirectory() || !/^\d+$/u.test(entry.name)) continue;
|
if (!entry.isDirectory() || !/^\d+$/u.test(entry.name)) continue;
|
||||||
let executable;
|
let executable;
|
||||||
try {
|
try {
|
||||||
executable = await stat(`/proc/${entry.name}/exe`, { bigint: true });
|
executable = await stat(`${procRoot}/${entry.name}/exe`, { bigint: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error?.code === "ENOENT" || error?.code === "ESRCH") continue;
|
if (error?.code === "ENOENT" || error?.code === "ESRCH") continue;
|
||||||
// Other users' executables may be unreadable. The setup lane launches
|
// Other users' executables may be unreadable. The setup lane launches
|
||||||
// providers as the caller; unreadable caller-owned processes fail closed.
|
// providers as the caller; unreadable caller-owned processes fail closed.
|
||||||
if (error?.code === "EACCES") {
|
if (error?.code === "EACCES") {
|
||||||
const owner = await stat(`/proc/${entry.name}`).catch((cause) => {
|
const owner = await stat(`${procRoot}/${entry.name}`).catch((cause) => {
|
||||||
if (cause?.code === "ENOENT") return undefined;
|
if (cause?.code === "ENOENT") return undefined;
|
||||||
throw cause;
|
throw cause;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
import { execFile } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
import { randomUUID } from "node:crypto";
|
import { randomUUID } from "node:crypto";
|
||||||
import { chmod, copyFile, readFile, symlink, unlink } from "node:fs/promises";
|
import {
|
||||||
|
chmod,
|
||||||
|
copyFile,
|
||||||
|
mkdir,
|
||||||
|
readFile,
|
||||||
|
symlink,
|
||||||
|
unlink,
|
||||||
|
} from "node:fs/promises";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { promisify } from "node:util";
|
import { promisify } from "node:util";
|
||||||
|
|
||||||
@@ -24,12 +31,20 @@ it
|
|||||||
const directory = await createTestTempDirectory("rea-clean-runtime-test-");
|
const directory = await createTestTempDirectory("rea-clean-runtime-test-");
|
||||||
const launcher = join(directory, "Hopper");
|
const launcher = join(directory, "Hopper");
|
||||||
const alternate = join(directory, "Hopper-alternate");
|
const alternate = join(directory, "Hopper-alternate");
|
||||||
|
const procRoot = join(directory, "proc");
|
||||||
|
await mkdir(procRoot);
|
||||||
const alternateMode = mode === "alternate launcher";
|
const alternateMode = mode === "alternate launcher";
|
||||||
if (alternateMode) {
|
if (alternateMode) {
|
||||||
await copyFile("/usr/bin/sleep", launcher);
|
await copyFile("/usr/bin/sleep", launcher);
|
||||||
await chmod(launcher, 0o700);
|
await chmod(launcher, 0o700);
|
||||||
await symlink(launcher, alternate);
|
await symlink(launcher, alternate);
|
||||||
}
|
}
|
||||||
|
// A rejection must come from the fixture we are about to launch. An
|
||||||
|
// existing Xvfb would otherwise mask a broken executable-identity check.
|
||||||
|
await assertCleanLinuxHopperRuntime(
|
||||||
|
alternateMode ? [launcher] : [],
|
||||||
|
procRoot,
|
||||||
|
);
|
||||||
const command = alternateMode ? alternate : process.execPath;
|
const command = alternateMode ? alternate : process.execPath;
|
||||||
const arguments_ = alternateMode ? ["30"] : ["-e", childCode];
|
const arguments_ = alternateMode ? ["30"] : ["-e", childCode];
|
||||||
const parentCode = `
|
const parentCode = `
|
||||||
@@ -56,6 +71,11 @@ it
|
|||||||
const { stdout } = await parent;
|
const { stdout } = await parent;
|
||||||
const { pid } = JSON.parse(stdout) as { pid: number };
|
const { pid } = JSON.parse(stdout) as { pid: number };
|
||||||
orphanPid = pid;
|
orphanPid = pid;
|
||||||
|
if (alternateMode) {
|
||||||
|
const processEntry = join(procRoot, String(pid));
|
||||||
|
await mkdir(processEntry);
|
||||||
|
await symlink(`/proc/${String(pid)}/exe`, join(processEntry, "exe"));
|
||||||
|
}
|
||||||
const { stdout: coordinates } = await execFileAsync("ps", [
|
const { stdout: coordinates } = await execFileAsync("ps", [
|
||||||
"-p",
|
"-p",
|
||||||
String(pid),
|
String(pid),
|
||||||
@@ -89,7 +109,10 @@ it
|
|||||||
await unlink(alternate);
|
await unlink(alternate);
|
||||||
}
|
}
|
||||||
await expect(
|
await expect(
|
||||||
assertCleanLinuxHopperRuntime(alternateMode ? [launcher] : []),
|
assertCleanLinuxHopperRuntime(
|
||||||
|
alternateMode ? [launcher] : [],
|
||||||
|
procRoot,
|
||||||
|
),
|
||||||
).rejects.toThrow("Clean Linux runner retained a Hopper demo process");
|
).rejects.toThrow("Clean Linux runner retained a Hopper demo process");
|
||||||
// Observation must not terminate the fixture, even though it resembles Xvfb.
|
// Observation must not terminate the fixture, even though it resembles Xvfb.
|
||||||
const { stdout: alive } = await execFileAsync("ps", [
|
const { stdout: alive } = await execFileAsync("ps", [
|
||||||
|
|||||||
Reference in New Issue
Block a user