frontend-quality-gates / merge / static checks (pull_request) Successful in 1m15s
frontend-quality-gates / merge / tests (pull_request) Successful in 13m20s
frontend-quality-gates / merge / browser tests (pull_request) Successful in 5m16s
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Skipped
frontend-quality-gates / external-provenance-provider (pull_request) Skipped
frontend-quality-gates / main / self-tests and removal drills (pull_request) Skipped
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Skipped
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Skipped
frontend-quality-gates / external-vulnerability-provider (pull_request) Skipped
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Skipped
frontend-quality-gates / deploy-promoted-release (pull_request) Skipped
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Skipped
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Skipped
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Skipped
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Skipped
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Skipped
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Skipped
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Skipped
스크립트 22곳이 argv[1]로 직접 실행을 판정해서, checkout 경로에 공백·한글이 있거나 symlink 절대 경로로 부르면 18곳이 검사 없이 rc=0으로 끝날 수 있다. merge 게이트 명령 셋이 여기 걸린다. isEntryModule(import.meta) 하나로 바꾸고, process.argv 둘째 값 읽기와 helper 밖 판정은 시험으로 막는다. 맨 import.meta.main은 그 값이 없는 Node에서 같은 거짓 통과가 나서 버렸다. realpath 비교는 같은 판정의 사본 22개가 남고, argv 값의 쓰임을 따라가는 시험은 return·대입으로 피할 수 있어 버렸다. 위험·한계: 건너뛰던 검사가 실패하기 시작할 수 있고, 실행 판정이 아닌 process.argv[1] 읽기도 실패한다. import.meta.main이 없는 Node에서 직접 실행하거나 import하면 실패한다. verify-extreme-scale도 그 Node에서는 rc=2보다 먼저 rc=1로 끝나고, 이전 기록(passed일 수 있다)이 그대로 남아 종료 code로 본다. 코드로 읽은 것이고 그 Node로 돌려 보지 않았다. 막는 시험은 process·argv 별칭과 계산한 index를 따라가지 않는다. 검증(노트북, main으로 옮기기 전 트리 a806088b): 새 시험 고치기 전 실패, 고친 뒤 통과. test:unit 3707개, types, lint, check:ci, verify:documentation rc=0. desktop merge 단계는 따로 확인한다. Refs: REV-FE-0040
263 lines
11 KiB
TypeScript
263 lines
11 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { randomBytes } from "node:crypto";
|
|
import { constants } from "node:fs";
|
|
import { access, readFile } from "node:fs/promises";
|
|
|
|
import { isEntryModule } from "./lib/entry-module.ts";
|
|
import {
|
|
formatProviderPrerequisiteUnitName,
|
|
MINIMUM_PROVIDER_SYSTEMD_VERSION,
|
|
systemdRunPrerequisiteProbeArguments,
|
|
USER_MANAGER_VERSION_ARGUMENTS,
|
|
} from "./lib/provider-cgroup.ts";
|
|
import { PROVIDER_SANDBOX_NAMESPACE_ARGUMENTS } from "./lib/provider-sandbox-namespaces.ts";
|
|
|
|
/** What the check reads from the host; a test passes a fake. */
|
|
export type SystemTestHost = Readonly<{
|
|
/** Resolves when `target` is executable, rejects otherwise. */
|
|
access(target: string): Promise<void>;
|
|
readFile(target: string): Promise<string>;
|
|
spawn(
|
|
command: string,
|
|
args: readonly string[],
|
|
timeoutMs: number,
|
|
): Readonly<{ status: number | null; stdout?: string; stderr: string; error?: Error | undefined }>;
|
|
/** Names the provider-shaped scope the probe starts; a test passes a fixed one. */
|
|
probeUnitName?: () => string;
|
|
}>;
|
|
|
|
export const nodeSystemTestHost: SystemTestHost = Object.freeze({
|
|
access: async (target: string) => access(target, constants.X_OK),
|
|
readFile: async (target: string) => readFile(target, "utf8"),
|
|
spawn: (command: string, args: readonly string[], timeoutMs: number) => {
|
|
const result = spawnSync(command, [...args], { encoding: "utf8", timeout: timeoutMs });
|
|
return { status: result.status, stdout: result.stdout ?? "", stderr: result.stderr ?? "", error: result.error };
|
|
},
|
|
probeUnitName: defaultProbeUnitName,
|
|
});
|
|
|
|
function defaultProbeUnitName(): string {
|
|
return formatProviderPrerequisiteUnitName(process.pid, randomBytes(12).toString("hex"));
|
|
}
|
|
|
|
const BWRAP = "/usr/bin/bwrap";
|
|
const SYSTEMCTL = "/usr/bin/systemctl";
|
|
const SYSTEMD_RUN = "/usr/bin/systemd-run";
|
|
|
|
/**
|
|
* 1105/12-01. The provider sandbox's own namespace options on /bin/true. The
|
|
* check used to see only that /usr/bin/bwrap was executable, so a host that
|
|
* refuses unprivileged user namespaces passed it and then failed 18 provider
|
|
* tests with `bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted`.
|
|
*/
|
|
export const NAMESPACE_PROBE_ARGUMENTS: readonly string[] = Object.freeze([
|
|
...PROVIDER_SANDBOX_NAMESPACE_ARGUMENTS,
|
|
"--ro-bind", "/", "/",
|
|
"--", "/bin/true",
|
|
]);
|
|
|
|
/** Host settings that decide whether an unprivileged process may create user namespaces. */
|
|
const USER_NAMESPACE_SETTINGS = Object.freeze([
|
|
["kernel.apparmor_restrict_unprivileged_userns", "/proc/sys/kernel/apparmor_restrict_unprivileged_userns"],
|
|
["kernel.unprivileged_userns_clone", "/proc/sys/kernel/unprivileged_userns_clone"],
|
|
["user.max_user_namespaces", "/proc/sys/user/max_user_namespaces"],
|
|
] as const);
|
|
|
|
const PROBE_TIMEOUT_MS = 5_000;
|
|
const SCOPE_PROBE_TIMEOUT_MS = 15_000;
|
|
const MAX_REPORTED_STDERR_LINES = 4;
|
|
|
|
export async function findSystemTestPrerequisiteFailures(
|
|
host: SystemTestHost = nodeSystemTestHost,
|
|
): Promise<string[]> {
|
|
const failures: string[] = [];
|
|
const executable = new Map<string, boolean>();
|
|
for (const [target, label] of [
|
|
[BWRAP, "bubblewrap"],
|
|
["/usr/bin/prlimit", "prlimit"],
|
|
[SYSTEMD_RUN, "systemd-run"],
|
|
[SYSTEMCTL, "systemctl"],
|
|
["/usr/bin/tar", "tar"],
|
|
] as const) {
|
|
try {
|
|
await host.access(target);
|
|
executable.set(target, true);
|
|
} catch {
|
|
executable.set(target, false);
|
|
failures.push(`${label} is required at ${target}`);
|
|
}
|
|
}
|
|
|
|
let cgroupV2 = false;
|
|
try {
|
|
const controllers = await host.readFile("/sys/fs/cgroup/cgroup.controllers");
|
|
if (controllers.trim().length === 0) {
|
|
failures.push("cgroup v2 controllers are unavailable");
|
|
} else {
|
|
cgroupV2 = true;
|
|
}
|
|
} catch {
|
|
failures.push("cgroup v2 is required at /sys/fs/cgroup/cgroup.controllers");
|
|
}
|
|
|
|
// 1112/08-03. The provider asks the user manager (not the system manager)
|
|
// for its version and then starts its sandbox in a `systemd-run --user
|
|
// --scope` (scripts/run-and-validate-provider.ts). The check makes the same
|
|
// calls, so a host without a user bus, with an old manager, or without
|
|
// delegated controllers fails here by name instead of in each provider test.
|
|
if (executable.get(SYSTEMCTL)) {
|
|
const userManager = findUserManagerFailure(host);
|
|
if (userManager !== undefined) {
|
|
failures.push(userManager);
|
|
} else if (executable.get(SYSTEMD_RUN)) {
|
|
const scope = findProviderScopeFailure(host);
|
|
if (scope !== undefined) failures.push(scope);
|
|
}
|
|
}
|
|
|
|
// The user manager's cgroup path below is a cgroup v2 path; without v2 it would name the wrong cause.
|
|
const controllerFailure = cgroupV2 ? await findProviderScopeControllerFailure(host) : undefined;
|
|
if (controllerFailure !== undefined) failures.push(controllerFailure);
|
|
|
|
if (executable.get(BWRAP)) {
|
|
const failure = await findProviderSandboxNamespaceFailure(host);
|
|
if (failure !== undefined) failures.push(failure);
|
|
}
|
|
return failures;
|
|
}
|
|
|
|
function findUserManagerFailure(host: SystemTestHost): string | undefined {
|
|
const probe = host.spawn(SYSTEMCTL, USER_MANAGER_VERSION_ARGUMENTS, 3_000);
|
|
const command = `${SYSTEMCTL} ${USER_MANAGER_VERSION_ARGUMENTS.join(" ")}`;
|
|
if (probe.error || probe.status !== 0) {
|
|
return [
|
|
`a reachable systemd user manager is required (${command} ${outcomeOf(probe)}).`,
|
|
...stderrLines(probe.stderr, "systemctl"),
|
|
" The provider runs in a `systemd-run --user --scope`; give the runner user a user",
|
|
" manager (for example `loginctl enable-linger <user>`) and a user bus in XDG_RUNTIME_DIR.",
|
|
].join("\n");
|
|
}
|
|
const reported = (probe.stdout ?? "").trim();
|
|
const match = /^([0-9]+)/u.exec(reported);
|
|
const version = match ? Number(match[1]) : Number.NaN;
|
|
if (!Number.isSafeInteger(version) || version < MINIMUM_PROVIDER_SYSTEMD_VERSION) {
|
|
return `systemd user manager ${MINIMUM_PROVIDER_SYSTEMD_VERSION} or newer is required (${command} reported ${JSON.stringify(reported)})`;
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
function findProviderScopeFailure(host: SystemTestHost): string | undefined {
|
|
const args = systemdRunPrerequisiteProbeArguments((host.probeUnitName ?? defaultProbeUnitName)());
|
|
const probe = host.spawn(SYSTEMD_RUN, args, SCOPE_PROBE_TIMEOUT_MS);
|
|
if (!probe.error && probe.status === 0) return undefined;
|
|
return [
|
|
"systemd-run could not start the provider's cgroup scope around /bin/true " +
|
|
`(${SYSTEMD_RUN} --user --scope ... ${outcomeOf(probe)}).`,
|
|
...stderrLines(probe.stderr, "systemd-run"),
|
|
" The scope needs the memory, pids and cpu controllers delegated to the user manager",
|
|
" (Delegate= in user@.service) and cgroup v2. Runner requirements: docs/operations/ci-quality-gates.md.",
|
|
].join("\n");
|
|
}
|
|
|
|
function outcomeOf(probe: ReturnType<SystemTestHost["spawn"]>): string {
|
|
return probe.error ? `did not finish: ${probe.error.message}` : `exited ${String(probe.status)}`;
|
|
}
|
|
|
|
function stderrLines(stderr: string, label: string): string[] {
|
|
const lines = stderr
|
|
.split("\n")
|
|
.map((line) => line.trim())
|
|
.filter((line) => line.length > 0)
|
|
.slice(0, MAX_REPORTED_STDERR_LINES);
|
|
return lines.length > 0 ? lines.map((line) => ` ${label} stderr: ${line}`) : [` ${label} stderr: (empty)`];
|
|
}
|
|
|
|
/**
|
|
* 1101/13-03. Whether this host lets the provider sandbox create its
|
|
* namespaces, and if not, why and what to do. The release provider jobs run
|
|
* it before the provider (scripts/run-and-validate-provider.ts).
|
|
*/
|
|
export async function findProviderSandboxNamespaceFailure(
|
|
host: SystemTestHost = nodeSystemTestHost,
|
|
): Promise<string | undefined> {
|
|
const probe = host.spawn(BWRAP, NAMESPACE_PROBE_ARGUMENTS, PROBE_TIMEOUT_MS);
|
|
return probe.error || probe.status !== 0 ? namespaceFailure(host, probe) : undefined;
|
|
}
|
|
|
|
async function namespaceFailure(
|
|
host: SystemTestHost,
|
|
probe: ReturnType<SystemTestHost["spawn"]>,
|
|
): Promise<string> {
|
|
const settings: string[] = [];
|
|
for (const [name, file] of USER_NAMESPACE_SETTINGS) {
|
|
try {
|
|
settings.push(`${name} = ${(await host.readFile(file)).trim()}`);
|
|
} catch {
|
|
// Absent on this kernel; the others still say what the host allows.
|
|
}
|
|
}
|
|
return [
|
|
"this host does not allow unprivileged user and network namespaces, which the provider " +
|
|
`sandbox needs (bwrap ${PROVIDER_SANDBOX_NAMESPACE_ARGUMENTS.join(" ")}).`,
|
|
` probe: ${BWRAP} ${NAMESPACE_PROBE_ARGUMENTS.join(" ")} ${outcomeOf(probe)}`,
|
|
...stderrLines(probe.stderr, "bwrap"),
|
|
...(settings.length > 0 ? [` host settings: ${settings.join(", ")}`] : []),
|
|
" To fix, do one of these:",
|
|
" - give /usr/bin/bwrap an AppArmor profile that allows `userns` (Ubuntu 23.10 and later),",
|
|
" - on a host you own, set sysctl kernel.apparmor_restrict_unprivileged_userns=0",
|
|
" (or kernel.unprivileged_userns_clone=1 where that setting exists),",
|
|
" - run FE-GATE-013 on another runner that allows them.",
|
|
" Runner requirements: docs/operations/ci-quality-gates.md.",
|
|
].join("\n");
|
|
}
|
|
|
|
/** The controllers every provider scope is limited by (scripts/lib/provider-cgroup.ts). */
|
|
const PROVIDER_SCOPE_CONTROLLERS = Object.freeze(["cpu", "memory", "pids"] as const);
|
|
|
|
/**
|
|
* Whether the systemd user manager that provider scopes run under was handed
|
|
* the cgroup controllers their limits need. A manager without them passed
|
|
* every check above, and then each provider stopped with `provider cgroup
|
|
* enforcement failed: cannot read memory.max` (2026-11-14: a `docker exec`
|
|
* sat in the system container's root cgroup while systemd started, so systemd
|
|
* delegated nothing).
|
|
*/
|
|
async function findProviderScopeControllerFailure(host: SystemTestHost): Promise<string | undefined> {
|
|
const status = await host.readFile("/proc/self/status").catch(() => "");
|
|
const uid = /^Uid:\s+(\d+)\s/mu.exec(status)?.[1];
|
|
if (uid === undefined) return "this process's uid is unreadable at /proc/self/status";
|
|
const manager = `/sys/fs/cgroup/user.slice/user-${uid}.slice/user@${uid}.service`;
|
|
let delegated: string[];
|
|
try {
|
|
delegated = (await host.readFile(`${manager}/cgroup.controllers`)).trim().split(/\s+/u);
|
|
} catch {
|
|
return `a systemd user manager is required at ${manager}`;
|
|
}
|
|
const missing = PROVIDER_SCOPE_CONTROLLERS.filter((controller) => !delegated.includes(controller));
|
|
return missing.length === 0
|
|
? undefined
|
|
: `the systemd user manager at ${manager} has no ${missing.join(", ")} cgroup controller ` +
|
|
`for provider scopes (it has: ${delegated.join(" ") || "none"})`;
|
|
}
|
|
|
|
export function formatSystemTestPrerequisiteReport(failures: readonly string[]): string {
|
|
return [
|
|
"System/CI-runner test prerequisites are unavailable:",
|
|
...failures.map((failure) => ` - ${failure}`),
|
|
"",
|
|
"Run test:unit/test:contract/test:component/test:integration for the",
|
|
"developer loop. test:system is intentionally reserved for a compatible",
|
|
"Linux CI-runner host.",
|
|
"",
|
|
].join("\n");
|
|
}
|
|
|
|
if (isEntryModule(import.meta)) {
|
|
const failures = await findSystemTestPrerequisiteFailures();
|
|
if (failures.length > 0) {
|
|
process.stderr.write(formatSystemTestPrerequisiteReport(failures));
|
|
process.exit(1);
|
|
}
|
|
process.stdout.write("System test prerequisites: PASS\n");
|
|
}
|