Files
clean-architecture-frontend…/tests/unit/system-test-prerequisites.test.ts
DongHyeonka 411c9338c6
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Skipped
frontend-quality-gates / main / self-tests and removal drills (pull_request) Skipped
frontend-quality-gates / merge / static checks (pull_request) Successful in 1m9s
frontend-quality-gates / merge / tests (pull_request) Successful in 10m55s
frontend-quality-gates / merge / browser tests (pull_request) Successful in 5m11s
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 / FE-GATE-015 / immutable-release-candidate (pull_request) Skipped
frontend-quality-gates / external-vulnerability-provider (pull_request) Skipped
frontend-quality-gates / external-provenance-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
revert: 그룹 C 검사기 PR(#55)을 되돌려 main 제거 드릴을 살린다
This reverts commit b489589403, reversing
changes made to 9e1cfd5975.

문제: main run 376(b4895894)의 `main / self-tests and removal drills`
job에서 FE-GATE-030이 실패한다. browser-file-storage 제거 드릴 사본에서
tests/unit/test-evidence-source-rules.test.ts 6건이 모두 같은 이유로
떨어진다. scripts/check-test-evidence.ts의 missingForbidOnly가
playwright.capabilities.config.ts를 읽다 ENOENT로 죽는다. #55가
forbidOnly 검사를 전체 검사에서 fixture 모드까지 모든 모드로 옮겼다.
드릴은 그 설정 파일을 지우지만 config/repository-layout.json의
playwright-configs 목록에는 그대로 남는다. 이 job은 main 단계에만 있어
PR run에서는 돌지 않았다.

고른 방법: CI 매뉴얼 9.3대로 main을 먼저 초록으로 돌리려고 #55 병합
커밋을 통째로 되돌린다(git revert -m 1 b4895894). 되돌린 트리는
9e1cfd59 트리(9b3237dd)와 같다.
버린 대안: 그 자리에서 고치기(없는 설정을 건너뛰거나, 드릴이 목록에서도
빼기)는 어느 쪽이 맞는지 판단과 검증이 필요해 main 빨강이 길어진다.
고침은 #55를 다시 올리는 PR에서 한다.

위험·한계: #55의 고침 12커밋(검사기 진단과 시험 빈틈)이 main에서
빠진다. 다시 올릴 때 이 드릴(FE-GATE-030, main 단계)을 PR 쪽에서 따로
돌리지 않으면 같은 일이 다시 난다.

검증: desktop 공유 잠금 아래 test:browser-file-storage-removal.
b4895894 트리(7536337a) 3회 모두 rc=1(64·69·53초). 3회차 로그에서 6건 실패,
6건 모두 run 376과 같은 ENOENT(playwright.capabilities.config.ts).
9e1cfd59 트리(9b3237dd, 이 커밋의 트리) 1회 rc=0(92초). 로그 desktop
/tmp/claude-gates/fe-run376-b489-removal/, fe-run376-9e1c-removal/.
2026-11-19 13:20:00 +09:00

204 lines
8.9 KiB
TypeScript

import { readFile } from "node:fs/promises";
import { describe, expect, it } from "vitest";
import {
findProviderSandboxNamespaceFailure,
findSystemTestPrerequisiteFailures,
formatSystemTestPrerequisiteReport,
NAMESPACE_PROBE_ARGUMENTS,
type SystemTestHost,
} from "../../scripts/check-system-test-prerequisites.ts";
import { PROVIDER_SANDBOX_NAMESPACE_ARGUMENTS } from "../../scripts/lib/provider-sandbox-namespaces.ts";
type SpawnCall = Readonly<{ command: string; args: readonly string[] }>;
type SpawnResult = ReturnType<SystemTestHost["spawn"]>;
const RTM_NEWADDR = "bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted";
const USER_MANAGER_CONTROLLERS = "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/cgroup.controllers";
/** A host that has every prerequisite, except what `bwrap` and `files` say. */
function fakeHost(
bwrap: SpawnResult,
files: Readonly<Record<string, string>> = {},
): { host: SystemTestHost; calls: SpawnCall[] } {
const calls: SpawnCall[] = [];
const host: SystemTestHost = {
access: async () => undefined,
readFile: async (target) => {
const content = {
"/sys/fs/cgroup/cgroup.controllers": "cpuset cpu io memory pids\n",
"/proc/self/status": "Name:\tnode\nUid:\t1000\t1000\t1000\t1000\n",
[USER_MANAGER_CONTROLLERS]: "cpu memory pids\n",
...files,
}[target];
if (content === undefined) throw new Error(`ENOENT: ${target}`);
return content;
},
spawn: (command, args) => {
calls.push({ command, args });
if (command === "/usr/bin/systemctl") return { status: 0, stderr: "" };
if (command === "/usr/bin/bwrap") return bwrap;
throw new Error(`unexpected spawn: ${command}`);
},
};
return { host, calls };
}
// 1105/12-01. The check looked only for the bwrap executable, so a host that
// refuses unprivileged user namespaces printed PASS and then failed 18
// provider tests with bwrap's raw netlink error.
describe("system test prerequisites (1105/12-01)", () => {
it("passes when bubblewrap creates the provider sandbox's namespaces", async () => {
const { host, calls } = fakeHost({ status: 0, stderr: "" });
expect(await findSystemTestPrerequisiteFailures(host)).toEqual([]);
const probes = calls.filter(({ command }) => command === "/usr/bin/bwrap");
expect(probes).toHaveLength(1);
expect(probes[0]?.args).toEqual(NAMESPACE_PROBE_ARGUMENTS);
expect(probes[0]?.args.at(-1)).toBe("/bin/true");
});
it("probes with exactly the namespace options the provider sandbox uses", async () => {
expect(PROVIDER_SANDBOX_NAMESPACE_ARGUMENTS).toEqual([
"--unshare-pid",
"--unshare-ipc",
"--unshare-uts",
"--unshare-net",
]);
expect(NAMESPACE_PROBE_ARGUMENTS.slice(0, PROVIDER_SANDBOX_NAMESPACE_ARGUMENTS.length)).toEqual(
PROVIDER_SANDBOX_NAMESPACE_ARGUMENTS,
);
// The provider takes the list from the same module instead of its own copy.
const provider = await readFile("scripts/run-and-validate-provider.ts", "utf8");
expect(provider).toContain("...PROVIDER_SANDBOX_NAMESPACE_ARGUMENTS,");
expect(provider).not.toMatch(/"--unshare-/u);
});
it("fails with the namespace restriction, bwrap's stderr and what to do when bwrap cannot set up loopback", async () => {
const { host } = fakeHost(
{ status: 1, stderr: `${RTM_NEWADDR}\n` },
{ "/proc/sys/kernel/apparmor_restrict_unprivileged_userns": "1\n" },
);
const failures = await findSystemTestPrerequisiteFailures(host);
expect(failures).toHaveLength(1);
const failure = failures[0] ?? "";
expect(failure).toMatch(/^this host does not allow unprivileged user and network namespaces/u);
expect(failure).toContain("--unshare-net");
expect(failure).toContain(`bwrap stderr: ${RTM_NEWADDR}`);
expect(failure).toContain("kernel.apparmor_restrict_unprivileged_userns = 1");
expect(failure).toMatch(/AppArmor profile/u);
expect(failure).toMatch(/sysctl kernel\.apparmor_restrict_unprivileged_userns=0/u);
expect(failure).toMatch(/another runner/u);
expect(formatSystemTestPrerequisiteReport(failures)).toContain(
" - this host does not allow unprivileged user and network namespaces",
);
});
it("fails the same way when the probe cannot run to the end", async () => {
const { host } = fakeHost({ status: null, stderr: "", error: new Error("spawnSync /usr/bin/bwrap ETIMEDOUT") });
const failures = await findSystemTestPrerequisiteFailures(host);
expect(failures).toHaveLength(1);
expect(failures[0]).toMatch(/^this host does not allow unprivileged user and network namespaces/u);
expect(failures[0]).toContain("did not finish: spawnSync /usr/bin/bwrap ETIMEDOUT");
});
it("keeps the executable, cgroup v2 and systemd bus checks, and probes bwrap only when it is there", async () => {
const calls: SpawnCall[] = [];
const host: SystemTestHost = {
access: async (target) => {
if (target === "/usr/bin/bwrap") throw new Error(`EACCES: ${target}`);
},
readFile: async () => "\n",
spawn: (command, args) => {
calls.push({ command, args });
return { status: 1, stderr: "Failed to connect to bus" };
},
};
expect(await findSystemTestPrerequisiteFailures(host)).toEqual([
"bubblewrap is required at /usr/bin/bwrap",
"cgroup v2 controllers are unavailable",
"a reachable systemd manager bus is required",
]);
expect(calls.map(({ command }) => command)).toEqual(["/usr/bin/systemctl"]);
});
});
// 2026-11-14. In one system container in four, systemd delegated no cgroup
// controller to the root user manager; this check printed PASS and then every
// provider stopped with `provider cgroup enforcement failed: cannot read
// memory.max`.
describe("system test prerequisites: provider scope controllers", () => {
it.each([
["none", "\n", "cpu, memory, pids", "none"],
["memory", "cpu pids\n", "memory", "cpu pids"],
])("names the controllers the user manager lacks (%s missing)", async (_label, delegated, missing, has) => {
const { host } = fakeHost({ status: 0, stderr: "" }, { [USER_MANAGER_CONTROLLERS]: delegated });
expect(await findSystemTestPrerequisiteFailures(host)).toEqual([
"the systemd user manager at /sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service " +
`has no ${missing} cgroup controller for provider scopes (it has: ${has})`,
]);
});
it("reads the user manager only where cgroup v2 is there", async () => {
const { host } = fakeHost({ status: 0, stderr: "" }, { "/sys/fs/cgroup/cgroup.controllers": "\n", [USER_MANAGER_CONTROLLERS]: "\n" });
expect(await findSystemTestPrerequisiteFailures(host)).toEqual(["cgroup v2 controllers are unavailable"]);
});
it("names an unreadable uid", async () => {
const { host } = fakeHost({ status: 0, stderr: "" }, { "/proc/self/status": "Name:\tnode\n" });
expect(await findSystemTestPrerequisiteFailures(host)).toEqual([
"this process's uid is unreadable at /proc/self/status",
]);
});
it("requires a user manager for this process's own uid", async () => {
const { host } = fakeHost({ status: 0, stderr: "" }, { "/proc/self/status": "Uid:\t0\t0\t0\t0\n" });
expect(await findSystemTestPrerequisiteFailures(host)).toEqual([
"a systemd user manager is required at /sys/fs/cgroup/user.slice/user-0.slice/user@0.service",
]);
});
});
// 1101/13-03. The release provider jobs run the same sandbox on whatever
// runner picks them up. The supervisor checked only that the executables
// exist, so a host that refuses the namespaces failed later with bwrap's raw
// error and without the host settings.
describe("provider sandbox namespace check (1101/13-03)", () => {
it("passes on a host that creates the namespaces and probes only with bwrap", async () => {
const { host, calls } = fakeHost({ status: 0, stderr: "" });
expect(await findProviderSandboxNamespaceFailure(host)).toBeUndefined();
expect(calls).toEqual([{ command: "/usr/bin/bwrap", args: NAMESPACE_PROBE_ARGUMENTS }]);
});
it("names the restriction, bwrap's stderr and the host settings on a host that refuses them", async () => {
const { host } = fakeHost(
{ status: 1, stderr: `${RTM_NEWADDR}\n` },
{ "/proc/sys/kernel/apparmor_restrict_unprivileged_userns": "1\n" },
);
const failure = (await findProviderSandboxNamespaceFailure(host)) ?? "";
expect(failure).toMatch(/^this host does not allow unprivileged user and network namespaces/u);
expect(failure).toContain(`bwrap stderr: ${RTM_NEWADDR}`);
expect(failure).toContain("kernel.apparmor_restrict_unprivileged_userns = 1");
});
it("runs before the provider supervisor launches anything", async () => {
const provider = await readFile("scripts/run-and-validate-provider.ts", "utf8");
const check = provider.indexOf("await findProviderSandboxNamespaceFailure()");
expect(check).toBeGreaterThan(0);
expect(check).toBeLessThan(provider.indexOf("superviseProviderEvidence({"));
});
});