From 0edc3fc90a948fbe2897ed019930a33139859976 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Wed, 4 Nov 2026 21:04:35 +0900 Subject: [PATCH] =?UTF-8?q?fix(provider):=20worktree=EC=9D=98=20.git=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EC=9D=84=20=EC=83=8C=EB=93=9C=EB=B0=95?= =?UTF-8?q?=EC=8A=A4=EC=97=90=EC=84=9C=20=EA=B0=80=EB=A6=AC=EA=B3=A0=20?= =?UTF-8?q?=EB=8B=A4=EB=A5=B8=20checkout=EC=9D=80=20=EB=B3=B5=EC=82=AC?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제 scripts/run-and-validate-provider.ts는 작업 폴더에 .git이 있으면 그 자리에 --tmpfs를 건다. git worktree나 서브모듈 checkout에서는 .git이 디렉터리가 아니라 "gitdir:" 한 줄짜리 파일이라 bubblewrap이 "Can't mkdir …/.git: Not a directory"로 끝난다. 그래서 worktree에서 test:system을 돌리면 사전 점검은 PASS인데 provider 테스트 16개가 샌드박스 회귀처럼 실패한다. 또 provider 기반 fixture는 현재 폴더를 통째로 복사해, checkout 안의 .claude/worktrees/*나 .tmp/* 같은 다른 checkout·드릴 fixture와 그 node_modules까지 /tmp/ci-provider-upload-*에 복사했다(시간 초과, ENOTEMPTY). 고른 방법 - .git이 디렉터리면 지금처럼 tmpfs로 가린다. 디렉터리가 아니면 /dev/null을 --ro-bind로 겹친다. bubblewrap은 bind를 nodev로 걸어서 provider는 그 줄을 읽지도 그 경로에 쓰지도 못한다. 파일이 가리키는 실제 git 디렉터리는 작업 폴더 밖이라 원래 샌드박스에 들어오지 않는다. - 리뷰 최소 개선 (1)(사전 점검이 worktree를 거부) 대신 (2)를 골랐다. 이 repo의 리뷰·수정 절차가 영역마다 worktree를 쓰므로, worktree에서 샌드박스 경계 테스트를 돌릴 수 있어야 한다. 비용도 몇 줄로 비슷하다. - 기반 fixture 복사에서 .claude, .worktrees, .tmp, graphify-out을 뺀다. 모두 추적하지 않는 폴더라 후보의 추적 파일 목록에는 영향이 없다. - 새 system 테스트 2건이 .git이 디렉터리일 때와 파일일 때 provider가 그 내용을 보지도 바꾸지도 못함을 확인한다. - 버린 대안: --dev-bind /dev/null. 읽으면 빈 내용이지만 쓰기를 받는다. --remount-ro를 더하면 nodev가 다시 걸려 --ro-bind와 같아진다. 빈 일반 파일을 호스트에 만들어 bind. 임시 파일의 수명·정리 경로가 하나 는다. 위험·한계 - .git 파일 자리에서 provider는 빈 파일이 아니라 열 수 없는 문자 장치를 본다(EACCES). 작업 폴더를 훑는 provider가 그 오류를 실패로 다루면 거기서 드러난다. - 마스크를 지우는 변이 확인은 부하(load 24) 때문에 systemd unit 수거가 늦어 결론을 내지 못했다(두 경우 모두 "provider unit remained loaded"). 검증 - RED: worktree에서 test:system 16 failed / 96 passed(모두 provider 묶음, 같은 bwrap 오류). 새 테스트는 수정 전 "file" 경우만 실패. - 수정 뒤 새 테스트 2건 통과(-t "hides repository metadata"). - eslint 통과. Refs: docs/reviews/2026-11-03-maturity-review/11-tests-browser-release-scale.md 11-04 --- scripts/run-and-validate-provider.ts | 27 ++++++-- .../ci-runner/ci-artifact-contract.test.ts | 61 ++++++++++++++++++- 2 files changed, 83 insertions(+), 5 deletions(-) diff --git a/scripts/run-and-validate-provider.ts b/scripts/run-and-validate-provider.ts index 597989d8..09511f4a 100644 --- a/scripts/run-and-validate-provider.ts +++ b/scripts/run-and-validate-provider.ts @@ -1,7 +1,7 @@ import { spawn } from "node:child_process"; import { randomBytes } from "node:crypto"; import { constants } from "node:fs"; -import { access, appendFile, lstat } from "node:fs/promises"; +import { access, appendFile, lstat, stat } from "node:fs/promises"; import path from "node:path"; import { @@ -274,12 +274,21 @@ async function runProviderInSandbox( bwrapArguments.push("--dir", directory); } bwrapArguments.push("--ro-bind", workspaceRoot, workspaceRoot); - if (await exists(path.join(workspaceRoot, ".git"))) { + const repositoryMetadata = path.join(workspaceRoot, ".git"); + const metadataKind = await entryKind(repositoryMetadata); + if (metadataKind === "directory") { bwrapArguments.push( "--size", String(PROVIDER_MASK_BYTES), - "--tmpfs", path.join(workspaceRoot, ".git"), - "--remount-ro", path.join(workspaceRoot, ".git"), + "--tmpfs", repositoryMetadata, + "--remount-ro", repositoryMetadata, ); + } else if (metadataKind === "other") { + // 1103/11-04. A linked worktree or a submodule checkout has a one-line + // `gitdir:` file here, and a tmpfs cannot be mounted on a file. /dev/null + // is bound over it instead. bubblewrap mounts binds nodev, so the provider + // can neither read the line nor write the path; the directory it names + // lies outside the workspace and is never bound into the sandbox. + bwrapArguments.push("--ro-bind", "/dev/null", repositoryMetadata); } bwrapArguments.push( "--ro-bind", candidateRoot, "/candidate", @@ -597,6 +606,16 @@ function missingDestinationAncestors(target: string): string[] { return ancestors.reverse(); } +/** What `target` is once symlinks are followed, as bubblewrap will see it. */ +async function entryKind(target: string): Promise<"directory" | "other" | null> { + try { + return (await stat(target)).isDirectory() ? "directory" : "other"; + } catch (error) { + if (hasErrorCode(error, "ENOENT")) return null; + throw error; + } +} + async function exists(target: string): Promise { try { await lstat(target); diff --git a/tests/system/ci-runner/ci-artifact-contract.test.ts b/tests/system/ci-runner/ci-artifact-contract.test.ts index 1eefff9a..3aa99b33 100644 --- a/tests/system/ci-runner/ci-artifact-contract.test.ts +++ b/tests/system/ci-runner/ci-artifact-contract.test.ts @@ -764,6 +764,44 @@ describe("candidate archive and provider upload boundaries", { timeout: PROCESS_ await expect(readFile(canary, "utf8")).resolves.toBe("host-secret\n"); }); + // 1103/11-04. In a linked worktree or a submodule checkout `.git` is a + // one-line `gitdir:` file. The sandbox hid `.git` with a tmpfs, which + // bubblewrap cannot mount on a file, so every provider run in a worktree + // ended with "Can't mkdir …/.git: Not a directory" before the provider ran. + it.each(["directory", "file"] as const)( + "hides repository metadata from the provider when .git is a %s", + async (shape) => { + const fixture = await createProviderFixture(); + await rm(fixture.reportPath); + const metadata = path.join(fixture.root, ".git"); + await rm(metadata, { recursive: true, force: true }); + if (shape === "directory") { + await mkdir(metadata); + await writeFile(path.join(metadata, "HEAD"), "ref: refs/heads/fixture\n"); + } else { + await writeFile(metadata, "gitdir: /repository/.git/worktrees/fixture\n"); + } + const providerScript = path.join(fixture.root, "provider-git-metadata.mjs"); + // Exit 9 when the provider can see what the metadata says, exit 8 when + // it can change it. + await writeFile(providerScript, [ + "import { appendFileSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs';", + `const metadata = ${JSON.stringify(metadata)};`, + "const directory = statSync(metadata).isDirectory();", + "let visible = false;", + "try { visible = directory ? readdirSync(metadata).length > 0 : readFileSync(metadata).length > 0; } catch {}", + "if (visible) process.exit(9);", + "try { appendFileSync(directory ? `${metadata}/HEAD` : metadata, 'mutated\\n'); process.exit(8); } catch {}", + providerV2WriterSource({ importFs: false }), + ].join("\n")); + const result = runProviderSupervisor(fixture, { + command: `node ${JSON.stringify(providerScript)}`, + sealedPath: path.join(fixture.root, "provider-evidence/vulnerability-report.json"), + }); + expect(result.status, result.stderr).toBe(0); + }, + ); + it("applies effective aggregate cgroup limits without exposing command or credentials", async () => { const fixture = await createProviderFixture(); await rm(fixture.reportPath); @@ -2184,6 +2222,27 @@ async function createProviderFixture() { }; } +/** + * Top-level entries the provider base fixture leaves behind: build output, + * installed modules (linked separately below), and other checkouts or scratch + * trees that can live inside a checkout. `.claude/worktrees/*` and + * `.worktrees/*` are other worktrees of this repository and `.tmp/*` holds + * removal-drill fixtures, each with its own node_modules; copying them filled + * every /tmp/ci-provider-upload-* root with those trees, and the suite failed + * with timeouts and ENOTEMPTY clean-ups (1103/11-04). None of them is tracked, + * so the candidate's tracked-file inventory does not miss them. + */ +const PROVIDER_BASE_FIXTURE_UNCOPIED_ENTRIES: readonly string[] = Object.freeze([ + ".release", + "artifacts", + "dist", + "node_modules", + ".claude", + ".worktrees", + ".tmp", + "graphify-out", +]); + async function ensureProviderBaseFixture(): Promise { if (providerBaseRoot) return providerBaseRoot; const sourceRoot = process.cwd(); @@ -2194,7 +2253,7 @@ async function ensureProviderBaseFixture(): Promise { const relative = path.relative(sourceRoot, source); if (!relative) return true; const first = relative.split(path.sep)[0]; - return ![".release", "artifacts", "dist", "node_modules"].includes(first ?? ""); + return !PROVIDER_BASE_FIXTURE_UNCOPIED_ENTRIES.includes(first ?? ""); }, }); // The release evidence, minus the trace and Storybook trees. Copying the