diff --git a/deploy/README.md b/deploy/README.md index 277528bd8..dfae54b31 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -186,7 +186,7 @@ The gate's validation runs as two jobs at once on the `xiaoxin` runner: `validat | `jyotisha-pip` | pip download cache | kept | | `jyotisha-npm` | npm download cache mounted into the `npm ci` container | kept | -The web image build also uses BuildKit cache mounts (`jyotisha-web-npm`, `jyotisha-web-next`); they live in the BuildKit store and are pruned by `deploy/reclaim-runner-disk.sh` only when the runner is short on disk. Deleting any of these only makes the next run slower. +The web image build also uses BuildKit cache mounts (`jyotisha-web-npm`, `jyotisha-web-next-v2`); they live in the BuildKit store and are pruned by `deploy/reclaim-runner-disk.sh` only when the runner is short on disk. Deleting any of these only makes the next run slower. Right after `next build` the image build runs `frontend/scripts/check-built-css.mjs`: if a class from `globals.css` is missing from the built style sheets (the Next cache served an old sheet, BUG-2069) the build fails; change the version suffix of the `jyotisha-web-next-v2` cache id to start from an empty cache. Every Web image build must pass that same full 40-character commit as the Docker build argument `NEXT_DEPLOYMENT_ID`. Next.js embeds it during `next build`, adds diff --git a/deploy/railway-web.Dockerfile b/deploy/railway-web.Dockerfile index 7f37d5efd..b58e33366 100644 --- a/deploy/railway-web.Dockerfile +++ b/deploy/railway-web.Dockerfile @@ -34,7 +34,11 @@ COPY skills /app/skills # Next.js build cache (webpack/SWC) across builds on the runner; it only # speeds up compilation and never lands in the image. -RUN --mount=type=cache,id=jyotisha-web-next,target=/app/frontend/.next/cache npm run build +# The cache id carries a version: BUG-2069 shipped the previous build's +# globals.css out of the old cache, so that cache is left behind. +RUN --mount=type=cache,id=jyotisha-web-next-v2,target=/app/frontend/.next/cache npm run build +# A build that reused old CSS fails here instead of reaching a server. +RUN node scripts/check-built-css.mjs # File tracing pulls skills/ into the standalone bundle with symlinks resolved into # real directories, which then collides with the explicit COPY in the final stage. diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index 2a5b95445..b3a5c35b6 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -27736,3 +27736,17 @@ - `chart-choice-pause-20261115` 的「只有无范围的人才有范围一行」改为所有人都有(注明原值/新值/原因)。 - 关联记录:BUG-1649、BUG-2062、BUG-2063。 - 修复版本:`claude/rect-wording`。 + + +## BUG-2069 | 测试环境上线的新版本带着上一版的 globals.css:新页面的结构是新的,样式没有 + +- 状态:fixed-pending-verify(修复已备好,未推送;要等下一次测试环境构建后在真机上确认)。 +- 首次发现 / 最近更新:2026-11-20 / 2026-11-20。 +- 触发与现象:`e4b25c26` 上线后打开设置里的「账户与点数」,余额、页签、兑换码、「兑换过的码」全部是没有样式的裸文字(页签两个字连在一起,列表没有行距和对齐)。页面结构和接口是新版本的,功能能用。 +- 触发条件:这一次测试环境构建;所有用到 BUG-2059 新类名的页面(设置弹窗的行、头像上传与裁剪、账户与点数三页)。年运等页面单独的样式表是新的,不受影响。 +- 根因:线上全站样式表(文件名带 `dpl=e4b25c26`)里有 53 个源文件里的类名一条规则都没有(`settings-row`、`avatar-crop`、`billing-tabs` 等),却还留着 BUG-2059 / BUG-2056 已经从源文件删掉的 `.billing-summary`、`.membership-payment-error`;它的类名集合和上一个上线版本 `c7e9b6c5` 的 `globals.css` 完全一致。同一份源文件在本机过同一个 Tailwind 步骤,产出里新类名齐全、旧类名没有。所以是镜像构建复用了上一次构建的全站样式表;镜像构建给 `.next/cache` 挂了跨次构建的缓存(`jyotisha-web-next`)。缓存里具体哪一层没有察觉 `globals.css` 改了,没有查到;2026-11-02 本机构建出过同样的现象(删 `.next/cache` 后正常)。 +- 修复:镜像构建换一个新的缓存名(`jyotisha-web-next-v2`),旧缓存不再使用;`next build` 之后加一步 `frontend/scripts/check-built-css.mjs`,`globals.css` 里任何一个开头的类名在构建出的样式表里找不到,镜像构建就失败,不会再把旧样式发到服务器。 +- 验证与防复发:`frontend/tests/built-css-check-2069.test.ts`(类名读取、齐全时通过、旧样式表时列出缺的类名);`frontend/tests/staging-backend-workflows.test.ts` 断言 Dockerfile 里有这一步和新的缓存名。用线上这份旧样式表跑检查脚本:报缺 53 个类名;换成本机新产出的全站样式表:通过。真实镜像构建里这一步还没有跑过。 +- 已知留待处理:检查只看全站样式表(每个页面都加载,一定在构建产物里);各页面单独的样式表没有纳入。 +- 关联记录:BUG-2059(这批新类名)、BUG-215 / BUG-248(样式没有编译进去的旧问题,原因不同)。 +- 修复版本:`claude/stale-css-2069`。 diff --git a/frontend/scripts/check-built-css.mjs b/frontend/scripts/check-built-css.mjs new file mode 100644 index 000000000..5dd796b75 --- /dev/null +++ b/frontend/scripts/check-built-css.mjs @@ -0,0 +1,49 @@ +// The web image must carry the style rules of the source it was built from. +// On 2026-11-20 a staging image shipped new pages with the previous build's +// globals.css (BUG-2069): the markup was new, its class names had no rules. +// This runs right after `next build` and fails the image build when a class +// that starts a rule in globals.css is absent from every built sheet. +import { readdirSync, readFileSync, statSync } from "node:fs"; +import { join } from "node:path"; +import { pathToFileURL } from "node:url"; + +function cssFiles(dir) { + const found = []; + for (const name of readdirSync(dir)) { + const path = join(dir, name); + if (statSync(path).isDirectory()) found.push(...cssFiles(path)); + else if (name.endsWith(".css") && !name.endsWith(".module.css")) found.push(path); + } + return found; +} + +/** Class names that open a rule at the start of a line in a source style sheet. */ +export function sourceClassNames(css) { + const names = new Set(); + for (const match of css.replace(/\/\*[\s\S]*?\*\//g, "").matchAll(/^[ \t]*\.([A-Za-z_][\w-]*)/gm)) names.add(match[1]); + return names; +} + +export function missingClassNames(sourceFiles, builtDir) { + const built = cssFiles(builtDir).map((path) => readFileSync(path, "utf8")).join("\n"); + const builtNames = new Set([...built.matchAll(/\.([A-Za-z_][\w-]*)/g)].map((match) => match[1])); + const missing = []; + for (const path of sourceFiles) { + for (const name of sourceClassNames(readFileSync(path, "utf8"))) { + if (!builtNames.has(name)) missing.push(`${path}: .${name}`); + } + } + return missing; +} + +if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) { + // globals.css is loaded by every page, so its rules are always in the build. + const [sourceFile = "src/app/globals.css", builtDir = ".next/static"] = process.argv.slice(2); + const missing = missingClassNames([sourceFile], builtDir); + if (missing.length > 0) { + console.error(`built style sheets are missing ${missing.length} class(es) from the source; the build reused old CSS:`); + for (const line of missing.slice(0, 20)) console.error(` ${line}`); + process.exit(1); + } + console.log("built style sheets carry every source class"); +} diff --git a/frontend/tests/built-css-check-2069.test.ts b/frontend/tests/built-css-check-2069.test.ts new file mode 100644 index 000000000..76d91350b --- /dev/null +++ b/frontend/tests/built-css-check-2069.test.ts @@ -0,0 +1,37 @@ +import assert from "node:assert/strict"; +import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import test from "node:test"; + +import { missingClassNames, sourceClassNames } from "../scripts/check-built-css.mjs"; + +function fixture(source: string, built: Record) { + const root = mkdtempSync(join(tmpdir(), "built-css-")); + const sourceFile = join(root, "globals.css"); + writeFileSync(sourceFile, source); + const builtDir = join(root, "static", "chunks"); + mkdirSync(builtDir, { recursive: true }); + for (const [name, css] of Object.entries(built)) writeFileSync(join(builtDir, name), css); + return { sourceFile, builtDir: join(root, "static") }; +} + +test("BUG-2069: class names are read from rule starts, not from comments", () => { + const names = sourceClassNames("/* .gone-rule was here */\n.billing-tabs { display: flex; }\n .billing-tab.is-active, .other { color: red; }\n@media (max-width: 600px) {\n .billing-row { gap: 0; }\n}\n"); + assert.deepEqual([...names].sort(), ["billing-row", "billing-tab", "billing-tabs"]); +}); + +test("BUG-2069: a build that carries every source class passes", () => { + const { sourceFile, builtDir } = fixture(".billing-tabs { display: flex; }\n.settings-row { gap: 4px; }\n", { + "a.css": ".billing-tabs{display:flex}", + "b.css": "@layer base{.settings-row{gap:4px}}", + }); + assert.deepEqual(missingClassNames([sourceFile], builtDir), []); +}); + +test("BUG-2069: a build with the previous version's sheet names the missing classes", () => { + const { sourceFile, builtDir } = fixture(".billing-tabs { display: flex; }\n.settings-row { gap: 4px; }\n", { + "a.css": ".billing-summary{margin:0}.settings-row-old{gap:4px}", + }); + assert.deepEqual(missingClassNames([sourceFile], builtDir), [`${sourceFile}: .billing-tabs`, `${sourceFile}: .settings-row`]); +}); diff --git a/frontend/tests/staging-backend-workflows.test.ts b/frontend/tests/staging-backend-workflows.test.ts index 18315d0cd..6bf50966b 100644 --- a/frontend/tests/staging-backend-workflows.test.ts +++ b/frontend/tests/staging-backend-workflows.test.ts @@ -173,9 +173,10 @@ test("railway web image uses Next standalone runtime output", () => { assert.match( dockerfile, // 原值 RUN npm run build;新值带 BuildKit 缓存挂载(只加速编译,不进镜像)。 - /ENV NEXT_DEPLOYMENT_ID=\$\{NEXT_DEPLOYMENT_ID\}[\s\S]*RUN --mount=type=cache,id=jyotisha-web-next,target=\/app\/frontend\/\.next\/cache npm run build/, + /ENV NEXT_DEPLOYMENT_ID=\$\{NEXT_DEPLOYMENT_ID\}[\s\S]*RUN --mount=type=cache,id=jyotisha-web-next-v2,target=\/app\/frontend\/\.next\/cache npm run build/, ); - assert.match(dockerfile, /RUN --mount=type=cache,id=jyotisha-web-next,target=\/app\/frontend\/\.next\/cache npm run build\n/); // 原值 RUN npm run build\n;CI 提速加 Next 构建缓存 + assert.match(dockerfile, /RUN --mount=type=cache,id=jyotisha-web-next-v2,target=\/app\/frontend\/\.next\/cache npm run build\n/); // 原值 RUN npm run build\n;CI 提速加 Next 构建缓存;BUG-2069 换了缓存名 + assert.match(dockerfile, /npm run build\n# [^\n]+\nRUN node scripts\/check-built-css\.mjs\n/); // BUG-2069: old CSS fails the image build // BUG-1503: the image's own npm ci uses the same mirror as the gate install; registry.npmjs.org timed out twice. // 原值 RUN npm ci;新值带 npm 下载缓存挂载与 --prefer-offline(锁文件仍决定版本与完整性)。 assert.match(dockerfile, /ARG NPM_CONFIG_REGISTRY=https:\/\/registry\.npmmirror\.com\n(?:#[^\n]*\n)*RUN --mount=type=cache,id=jyotisha-web-npm,target=\/root\/\.npm npm ci --prefer-offline\n/);