Files
clean-architecture-frontend…/tests/unit/dependency-cache-root.test.ts
DongHyeonka f21ea48911
frontend-quality-gates / merge / static checks (pull_request) Successful in 1m56s
frontend-quality-gates / merge / tests (pull_request) Successful in 15m58s
frontend-quality-gates / merge / browser tests (pull_request) Successful in 6m15s
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 / 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
ci(gates): 의존성 캐시를 checkout과 같은 파일시스템의 폴더에 둔다
문제: #41의 merge job 캐시는 hit해도 설치가 빨라지지 않았다. PR run
230에서 세 job 모두 복원했지만(222MB, 4.8초) pnpm 설치는 16.9·26.4·22.4초로
캐시 없는 run(13.8~22.8초)과 같았다. `reused 404, downloaded 0` 뒤 node_modules에
넣는 데만 15초 넘게 걸렸다. desktop 재현: 같은 파일시스템 2.1초, tar 왕복 뒤
7.6초, store가 다른 파일시스템이면 58.8초(하드링크 대신 복사). store가 job의
`/tmp`에 있어 checkout과 다른 파일시스템일 가능성이 크다.

고친 것(권하는 안으로 정함, 총괄): merge job의 첫 캐시 단계가
`scripts/ci/dependency-cache-root.sh "$RUNNER_TEMP" "$(dirname "$GITHUB_WORKSPACE")"`
를 돈다. 후보 중 checkout과 `stat -c %d`가 같고 checkout 밖인 첫 폴더를 고르고,
없으면 첫 후보를 쓴다. 고른 폴더, 견준 장치 번호, job 시작 때의 부하를 한
줄로 로그에 남기고, `COREPACK_HOME`·`PNPM_CONFIG_STORE_DIR`·
`PNPM_CONFIG_CACHE_DIR`를 `$GITHUB_ENV`로 넘긴다(job env 고정값을 뺌). 캐시
경로는 그 단계 출력을 쓴다. checkout 안은 후보가 아니다(`git status`, repo
배치 검사, 산출물에 잡히지 않게).

버린 대안: checkout 안 `.tmp` 아래(배치 검사·산출물에 걸림), workspace 부모를
고정 경로로(파일시스템이 같은지 runner마다 다를 수 있다).

위험·한계: 고른 폴더가 run마다 다르면 캐시 항목의 경로가 달라 hit하지 않는다
(같은 runner에서는 같다). 같은 파일시스템이 없으면 지금과 같다. runner에서의
효과는 main 저장 → 다음 PR 복원으로 잰다.

검증(desktop): 새 시험 `tests/unit/dependency-cache-root.test.ts`(가짜
`stat`으로 같은 파일시스템 고르기·checkout 안 제외·대체 경로) 통과, 최대
47ms. 생성 시험은 바꾸기 전 생성기에서 실패(RED), 고친 뒤
ci-workflow-generation·test-timeout-declarations·repository-layout 등 460개
통과. check:ci·check:types·eslint·verify:documentation rc=0.
2026-11-13 14:05:46 +09:00

102 lines
4.3 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { chmod, mkdir, mkdtemp, readFile, realpath, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { DEPENDENCY_CACHE } from "../../scripts/contracts/ci-gates.ts";
import { childProcessTimeout } from "../helpers/child-process-timeout.ts";
/**
* scripts/ci/dependency-cache-root.sh picks the merge job's dependency cache
* folder: the first candidate on the checkout's filesystem and outside it
* (run 230: with the store in the job's /tmp, pnpm copied node_modules across
* filesystems and a warm install was no faster than a cold one). A fake
* `stat` stands in for the devices, so the cases do not depend on how this
* host mounts its folders: a path under FAKE_SAME is device 11, any other 22.
*/
const roots: string[] = [];
afterEach(async () => {
await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
});
async function layout() {
const root = await realpath(await mkdtemp(path.join(tmpdir(), "dependency-cache-root-")));
roots.push(root);
const bin = path.join(root, "bin");
await mkdir(bin);
await writeFile(
path.join(bin, "stat"),
['#!/usr/bin/env bash', 'target=${@: -1}', 'case "$target/" in "$FAKE_SAME"/*) echo 11 ;; *) echo 22 ;; esac', ""].join("\n"),
);
await chmod(path.join(bin, "stat"), 0o755);
const folders = {
same: path.join(root, "same"),
checkout: path.join(root, "same", "checkout"),
insideCheckout: path.join(root, "same", "checkout", "tmp"),
sameTemp: path.join(root, "same", "runner-temp"),
other: path.join(root, "other"),
otherTemp: path.join(root, "other", "runner-temp"),
missing: path.join(root, "missing"),
};
for (const folder of [folders.insideCheckout, folders.sameTemp, folders.otherTemp]) {
await mkdir(folder, { recursive: true });
}
const environmentFile = path.join(root, "github-env");
const outputFile = path.join(root, "github-output");
const run = (...candidates: string[]) =>
spawnSync("bash", [DEPENDENCY_CACHE.rootScript, ...candidates], {
encoding: "utf8",
env: {
PATH: `${bin}:${process.env.PATH ?? ""}`,
FAKE_SAME: folders.same,
GITHUB_WORKSPACE: folders.checkout,
GITHUB_ENV: environmentFile,
GITHUB_OUTPUT: outputFile,
},
});
const written = async () => ({
environment: (await readFile(environmentFile, "utf8")).trim().split("\n"),
output: (await readFile(outputFile, "utf8")).trim(),
});
return { folders, run, written };
}
const variables = (root: string) => [
`COREPACK_HOME=${root}/corepack`,
`PNPM_CONFIG_STORE_DIR=${root}/pnpm-store`,
`PNPM_CONFIG_CACHE_DIR=${root}/pnpm-cache`,
];
describe("the merge job's dependency cache folder", { timeout: childProcessTimeout(47) }, () => {
it("is the first candidate on the checkout's filesystem, never one inside the checkout", async () => {
const { folders, run, written } = await layout();
const result = run(folders.otherTemp, folders.insideCheckout, folders.sameTemp);
expect(result.status, result.stderr).toBe(0);
const root = `${folders.sameTemp}/fe-dependency-cache`;
expect(await written()).toEqual({ environment: variables(root), output: `root=${root}` });
expect(result.stdout).toMatch(
new RegExp(
String.raw`^dependency cache: ${root} \(on the checkout's filesystem: yes; devices: checkout=11 ${folders.otherTemp}=22 ${folders.sameTemp}=11; load average at job start: [0-9.]+ [0-9.]+ [0-9.]+\)\n$`,
"u",
),
);
expect(DEPENDENCY_CACHE.environmentNames).toEqual(variables(root).map((line) => line.split("=")[0]));
});
it("falls back to the first usable candidate when none shares the checkout's filesystem", async () => {
const { folders, run, written } = await layout();
const result = run(folders.missing, "", folders.otherTemp, folders.other);
expect(result.status, result.stderr).toBe(0);
const root = `${folders.otherTemp}/fe-dependency-cache`;
expect(await written()).toEqual({ environment: variables(root), output: `root=${root}` });
expect(result.stdout).toContain(`dependency cache: ${root} (on the checkout's filesystem: no; devices: checkout=11 ${folders.otherTemp}=22 ${folders.other}=22;`);
});
});