fix(ci): 테스트가 만드는 로컬 빌드는 CI=true에서도 release 빌드로 검사되지 않는다
문제
workflow는 모든 job에 CI=true와 CI 빌드 식별값을 준다. 메인 세션이 깨끗한
clone에서 그 env 그대로(CI=true 포함) merge 단계 14개를 돌리자 FE-GATE-005·
008·020이 실패했다.
- vitest 안의 fixture 빌드(tests/e2e/support/fixture-builds.ts →
build-frontend.ts)가 CI=true를 물려받아 release 빌드처럼 검사된다.
af312de가 vitest에서 VITE_COMMIT_SHA를 지워 "missing required CI build
environment: VITE_COMMIT_SHA"로 멈춘다(service-worker-build-output 7건이
돌지 않음, 제거 드릴 안에서도 같다).
- 시각 골든 build(9bddfa5)가 VITE_COMMIT_SHA="local"을 받는데 CI=true가
40·64자리 hex를 요구해 webServer가 뜨지 않는다.
내 X4가 CI=true 없이 돌아 놓쳤다. 1103/11-07과 같은 원인이다.
고른 방법
- scripts/lib/build-environment.ts에 둘을 둔다.
- localBuildEnvironment(env): spawn하는 로컬 빌드용. CI와 CI 빌드 식별값을
뺀 사본. fixture-builds.ts, service-worker-builds.ts가 쓴다.
- LOCAL_BUILD_IDENTITY: Playwright web server용. Playwright가 env를
process.env 위에 합치므로 CI를 지우지 않고 ""로 덮는다(검사는
CI === "true"일 때만). visual·capabilities·dev 설정이 쓴다.
- assertCiBuildEnvironment의 CI=true 검사는 그대로다. job 자신의 release
빌드(build:release-candidate 등)는 계속 검사된다.
- 버린 대안: 로컬 빌드에 유효한 가짜 커밋 id(0×40)를 주기. CI=true 검사의
다른 칸(CI_RUNNER_IMAGE, SOURCE_DATE_EPOCH)도 함께 맞춰야 하고, 로컬
빌드가 release 빌드인 척한다.
위험·한계
- 로컬 빌드 안에서 CI를 읽어 동작을 바꾸는 코드가 있으면 그 빌드는 이제
CI가 아닌 쪽으로 돈다(지금은 build-environment 검사뿐이다).
검증
- tests/unit/local-build-environment.test.ts 3건: 구현 전 2건 실패(RED),
CI job 자체 검사는 유지.
- CI=true·VITE_COMMIT_SHA·VITE_BUILD_ID=gitea-41-1·RELEASE_ID·
CI_RUNNER_IMAGE·SOURCE_DATE_EPOCH로: service-worker-build-output 7건,
test:visual 6/6, test:unit 2,883, test:component 270, test:integration 189
통과. 수정 전 service-worker-build-output은 7건 미실행.
- check:types, lint 통과.
Refs: docs/reviews/2026-11-03-maturity-review/README.md 13절 11-08
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { defineConfig, devices } from "@playwright/test";
|
||||
|
||||
import { LOCAL_BUILD_IDENTITY } from "./scripts/lib/build-environment.ts";
|
||||
|
||||
export default defineConfig({
|
||||
testDir: "./tests/browser-capabilities",
|
||||
forbidOnly: true,
|
||||
@@ -30,7 +32,7 @@ export default defineConfig({
|
||||
// BUILD_ID is local-build. CI sets VITE_BUILD_ID for the whole workflow;
|
||||
// built into the dev bundle it makes every page a rolling-release mismatch
|
||||
// that reloads once and then fails closed (CONFIG_BUILD_MISMATCH).
|
||||
env: { VITE_BUILD_ID: "local-build", VITE_COMMIT_SHA: "local" },
|
||||
env: { ...LOCAL_BUILD_IDENTITY },
|
||||
command:
|
||||
"corepack pnpm dev --host 127.0.0.1 --port 4174",
|
||||
url: "http://127.0.0.1:4174",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { defineConfig } from "@playwright/test";
|
||||
|
||||
import releaseConfig from "./playwright.config.ts";
|
||||
import { LOCAL_BUILD_IDENTITY } from "./scripts/lib/build-environment.ts";
|
||||
|
||||
export default defineConfig({
|
||||
...releaseConfig,
|
||||
@@ -13,7 +14,7 @@ export default defineConfig({
|
||||
// BUILD_ID is local-build. CI sets VITE_BUILD_ID for the whole workflow;
|
||||
// built into the dev bundle it makes every page a rolling-release mismatch
|
||||
// that reloads once and then fails closed (CONFIG_BUILD_MISMATCH).
|
||||
env: { VITE_BUILD_ID: "local-build", VITE_COMMIT_SHA: "local" },
|
||||
env: { ...LOCAL_BUILD_IDENTITY },
|
||||
command: "corepack pnpm dev --host 127.0.0.1",
|
||||
url: "http://127.0.0.1:5173",
|
||||
reuseExistingServer: true,
|
||||
|
||||
@@ -2,6 +2,8 @@ import { fileURLToPath } from "node:url";
|
||||
|
||||
import { defineConfig, devices } from "@playwright/test";
|
||||
|
||||
import { LOCAL_BUILD_IDENTITY } from "./scripts/lib/build-environment.ts";
|
||||
|
||||
export default defineConfig({
|
||||
testDir: "./tests/visual",
|
||||
forbidOnly: true,
|
||||
@@ -51,11 +53,8 @@ export default defineConfig({
|
||||
// whole workflow, so its build drew other text than the goldens and every
|
||||
// CI run failed here. The goldens are the template's shape, captured with
|
||||
// the local identity.
|
||||
env: {
|
||||
VITE_BUILD_ID: "local-build",
|
||||
VITE_COMMIT_SHA: "local",
|
||||
RELEASE_ID: "local-release",
|
||||
},
|
||||
// 1103/11-08: CI too, or the build is checked as a release build.
|
||||
env: { ...LOCAL_BUILD_IDENTITY },
|
||||
command:
|
||||
"corepack pnpm build && corepack pnpm preview --host 127.0.0.1 --port 4174",
|
||||
url: "http://127.0.0.1:4174",
|
||||
|
||||
@@ -40,6 +40,32 @@ export function ciBuildEnvironmentFailures(
|
||||
return failures;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1103/11-08. The workflow sets CI=true and the CI build identity for every
|
||||
* job. A build a test makes of a copy (a fixture build, the visual goldens'
|
||||
* build, a dev server) is a local build, never the job's release build, so it
|
||||
* starts without them. The job's own release build keeps the check above.
|
||||
*
|
||||
* `localBuildEnvironment` is for a process this code spawns: the caller's
|
||||
* environment without CI and the CI identity. `LOCAL_BUILD_IDENTITY` is for a
|
||||
* Playwright web server, whose env Playwright merges over process.env, so CI
|
||||
* is overridden there instead of removed.
|
||||
*/
|
||||
export const LOCAL_BUILD_IDENTITY = Object.freeze({
|
||||
CI: "",
|
||||
VITE_BUILD_ID: "local-build",
|
||||
VITE_COMMIT_SHA: "local",
|
||||
RELEASE_ID: "local-release",
|
||||
});
|
||||
|
||||
export function localBuildEnvironment(
|
||||
environment: Readonly<Record<string, string | undefined>> = process.env,
|
||||
): Record<string, string | undefined> {
|
||||
const local: Record<string, string | undefined> = { ...environment };
|
||||
for (const name of ["CI", ...CI_BUILD_ENVIRONMENT_VARIABLES]) delete local[name];
|
||||
return local;
|
||||
}
|
||||
|
||||
export function assertCiBuildEnvironment(
|
||||
environment: Readonly<Record<string, string | undefined>>,
|
||||
) {
|
||||
|
||||
@@ -3,6 +3,7 @@ import { cp, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { localBuildEnvironment } from "../../../scripts/lib/build-environment.ts";
|
||||
import { linkFixtureNodeModules } from "../../../scripts/lib/fixture-node-modules.ts";
|
||||
|
||||
/**
|
||||
@@ -60,7 +61,8 @@ function run(
|
||||
const result = spawnSync("node", [script], {
|
||||
cwd,
|
||||
encoding: "utf8",
|
||||
env: { ...process.env, ...env, VITE_BUILD_ID: buildId, RELEASE_ID: buildId },
|
||||
// 1103/11-08. A local build, not the CI job's release build.
|
||||
env: { ...localBuildEnvironment(), ...env, VITE_BUILD_ID: buildId, RELEASE_ID: buildId },
|
||||
});
|
||||
if (result.status !== 0) {
|
||||
throw new Error(
|
||||
|
||||
@@ -16,6 +16,7 @@ import { pathToFileURL } from "node:url";
|
||||
import { gzipSync } from "node:zlib";
|
||||
|
||||
import { SERVICE_WORKER_ASSETS_OUTPUT } from "../../../scripts/generate-service-worker-assets.ts";
|
||||
import { localBuildEnvironment } from "../../../scripts/lib/build-environment.ts";
|
||||
import { linkFixtureNodeModules } from "../../../scripts/lib/fixture-node-modules.ts";
|
||||
import type { StaticAssetManifestV1 } from "../../../src/contracts/service-worker.ts";
|
||||
|
||||
@@ -174,7 +175,8 @@ function run(cwd: string, script: string, buildId: string): void {
|
||||
const result = spawnSync("node", [script], {
|
||||
cwd,
|
||||
encoding: "utf8",
|
||||
env: { ...process.env, VITE_BUILD_ID: buildId, RELEASE_ID: buildId },
|
||||
// 1103/11-08. A local build, not the CI job's release build.
|
||||
env: { ...localBuildEnvironment(), VITE_BUILD_ID: buildId, RELEASE_ID: buildId },
|
||||
});
|
||||
if (result.status !== 0) {
|
||||
throw new Error(
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
ciBuildEnvironmentFailures,
|
||||
LOCAL_BUILD_IDENTITY,
|
||||
localBuildEnvironment,
|
||||
} from "../../scripts/lib/build-environment.ts";
|
||||
import visualConfig from "../../playwright.visual.config.ts";
|
||||
|
||||
/**
|
||||
* 1103/11-08. The workflow sets CI=true and the CI build identity for every
|
||||
* job. A build a test makes of a copy is a local build: it used to inherit
|
||||
* CI=true and be checked as a release build. Inside vitest, whose config
|
||||
* drops VITE_COMMIT_SHA (11-07), that failed with "missing required CI build
|
||||
* environment: VITE_COMMIT_SHA"; the visual goldens' build failed on its
|
||||
* local commit id "local".
|
||||
*/
|
||||
const CI_JOB = Object.freeze({
|
||||
CI: "true",
|
||||
VITE_BUILD_ID: "gitea-41-1",
|
||||
RELEASE_ID: "refs/heads/fix/example-41-1",
|
||||
CI_RUNNER_IMAGE: `local/runner@sha256:${"a".repeat(64)}`,
|
||||
SOURCE_DATE_EPOCH: "1793700000",
|
||||
PATH: "/usr/bin",
|
||||
});
|
||||
|
||||
describe("local build environment (1103/11-08)", () => {
|
||||
it("is not checked as a CI build, whatever CI identity the job has", () => {
|
||||
const local = localBuildEnvironment(CI_JOB);
|
||||
|
||||
expect(ciBuildEnvironmentFailures(local)).toEqual([]);
|
||||
expect(local).not.toHaveProperty("CI");
|
||||
expect(local).not.toHaveProperty("VITE_BUILD_ID");
|
||||
expect(local["PATH"]).toBe("/usr/bin");
|
||||
});
|
||||
|
||||
it("keeps a CI job's own release build checked", () => {
|
||||
expect(ciBuildEnvironmentFailures(CI_JOB)).toContain(
|
||||
"missing required CI build environment: VITE_COMMIT_SHA",
|
||||
);
|
||||
});
|
||||
|
||||
it("starts the visual goldens' build as a local build inside a CI job", () => {
|
||||
const webServer = visualConfig.webServer;
|
||||
const env = Array.isArray(webServer) ? undefined : webServer?.env;
|
||||
|
||||
// Playwright merges a web server's env over the runner's process.env.
|
||||
expect(ciBuildEnvironmentFailures({ ...CI_JOB, ...env })).toEqual([]);
|
||||
expect(env).toMatchObject(LOCAL_BUILD_IDENTITY);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user