Files
clean-architecture-frontend…/tests/unit/system-test-prerequisites.test.ts
DongHyeonka 9ebd0856a1
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Canceled after 0s
frontend-quality-gates / main / self-tests and removal drills (pull_request) Canceled after 0s
frontend-quality-gates / merge / static checks (pull_request) Canceled after 0s
frontend-quality-gates / merge / tests (pull_request) Canceled after 0s
frontend-quality-gates / merge / browser tests (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Canceled after 0s
frontend-quality-gates / external-vulnerability-provider (pull_request) Canceled after 0s
frontend-quality-gates / external-provenance-provider (pull_request) Canceled after 0s
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Canceled after 0s
frontend-quality-gates / deploy-promoted-release (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Canceled after 0s
fix(ci): provider job에 sandbox runner 요구를 적고 시작 때 namespace를 점검한다
문제: release의 provider job 둘(vulnerability·provenance)은 FE-GATE-013과
같은 provider sandbox(systemd-run scope, bwrap --unshare-pid/ipc/uts/net)를
돈다. 그런데 생성 workflow의 runner 요구 주석은 게이트의
hostRequirements에서 나와 merge_test에만 붙고, provider job에는 없다.
provider 감독 스크립트의 시작 점검도 실행 파일이 있는지만 봐서, 비특권
user namespace를 막는 runner에서는 나중에 bwrap 원문 오류로 끝난다.

고른 방법:
- 계약 job에 선택 칸 `hostRequirements`를 두고 provider job 둘에
  FE-GATE-013과 같은 요구를 적는다. 계약이 provider job의 요구가
  FE-GATE-013과 같은지 보고(갈라지면 거절), provider 밖 job은 이 칸을 못
  쓴다. 생성기가 그 job의 runs-on 옆에 주석을 쓴다.
- `check-system-test-prerequisites.ts`에서 namespace 점검만 함수로 내보내고
  (`findProviderSandboxNamespaceFailure`), `run-and-validate-provider.ts`가
  provider를 띄우기 전에 부른다. 실패하면 test:system 사전 점검과 같은
  문구(제한 이름, bwrap stderr, host 설정, 고치는 법)로 멈춘다.
- 버린 대안: 생성기가 hostEnvironment 게이트의 요구를 provider job에
  저절로 붙이기. 연결이 계약에 보이지 않는다.

위험·한계: provider job은 release 단계라 PR run에서 돌지 않는다. 새
점검은 desktop FE-GATE-013의 provider 시스템 시험(감독 스크립트를 실제로
띄움)으로 본다. 「provider 없이 배포할 때」 문서 절은 소유자 결정이라
이 커밋에 없다.

검증(desktop): 구현을 main으로 되돌리고 새 시험만 둔 상태에서 4개 실패
(RED), 고친 뒤 system-test-prerequisites·ci-workflow-generation 445개 통과,
generate:ci-workflow·스냅샷 갱신, check:ci·check:types·eslint rc=0,
verify:documentation PASS_SCOPED. desktop `scripts/verify.sh gate FE-GATE-013`
rc=0 226초(시스템 컨테이너, system 시험 115개 통과 — provider 감독
스크립트를 실제로 띄워 새 점검을 거친다). 로그 /tmp/claude-gates/w2fe2-prov1/,
w2fe2-prov013/.

Refs: 1101/13-03
2026-11-13 05:02:16 +09:00

159 lines
6.8 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";
/** 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) => {
if (target === "/sys/fs/cgroup/cgroup.controllers") return "cpuset cpu io memory pids\n";
const content = 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"]);
});
});
// 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({"));
});
});