Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
38dd811
fix(ci): select both browser suites for shared fixture changes
Nov 28, 2026
3f62281
fix(ci): enforce lint gate and run full unit suite on Windows
Nov 28, 2026
f05ed90
fix(ci): run Lighthouse budgets on a schedule
Nov 28, 2026
757d925
fix(test): surface explicit skips in subpath build test
Nov 28, 2026
7ec6046
fix(test): remove dead visual regression spec and guard style exclusions
Nov 28, 2026
28db80c
fix(a11y): require a single visible page h1 across scanned pages
Nov 28, 2026
7fcbdc3
fix(resolve): match nested barrels on win32 path separators
Nov 28, 2026
8aa9820
fix(ci): verify preview port ownership and keep single page h1
Nov 28, 2026
06cca2d
fix(pages): define bodyHasH1 helper on permalink route
Nov 28, 2026
9b922c2
Merge remote-tracking branch 'origin/main' into r2/ci
Nov 28, 2026
4cd55b4
chore(ci): format integration sources merged from main
Nov 28, 2026
7a1c42a
test(site): cover body-heading fixture in archive and category views
Nov 28, 2026
ff88461
fix(a11y): demote post body h1 headings instead of demoting the title
Nov 28, 2026
60a0100
test(site): fix Windows file URLs and decrypted TOC numbering after h…
Nov 28, 2026
d31b3a6
Merge remote-tracking branch 'origin/main' into r2/ci
Nov 28, 2026
33480c5
chore(ci): merge main and resolve biome lint findings from merged sou…
Nov 28, 2026
9359d3e
fix(a11y): shift the whole post outline down one level instead of onl…
Nov 28, 2026
2de7dab
fix(a11y): demote only body h1 headings and pin the resulting TOC tier
Nov 28, 2026
07aebb9
style(biome): wrap demoteBodyH1Headings signature to satisfy biome fo…
Nov 28, 2026
28c21f8
test(site): warm dev routes before asserting the static pager
Nov 28, 2026
4238301
fix(a11y): scope body h1 demotion to the posts collection and cover M…
Nov 28, 2026
9a26980
fix(ci): pin the e2e dev server port and stop leftover background ser…
Nov 28, 2026
f7c17af
docs(ci): describe the e2e port policy the config actually enforces
Nov 28, 2026
a788941
Merge origin/main into r2/ci
Nov 28, 2026
6f680e7
fix(ci): run Node test files one at a time
Nov 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ jobs:
run: pnpm install --frozen-lockfile

- name: Run Biome
continue-on-error: true
run: pnpm exec biome ci ./src --reporter=github

checks:
Expand Down Expand Up @@ -132,13 +131,17 @@ jobs:
- name: Validate package runtime manifest
run: pnpm check:package-manifest

# `tests/content/*.test.mjs` mutate the tracked config-overlay module
# (src/user/user-config.ts) through scripts/content/config-overlay.mjs,
# so concurrent test files see each other's residual overlay. One file
# at a time keeps the suite deterministic (~2.5 min).
- name: Run unit tests
run: node --test "tests/**/*.test.mjs"
run: node --test --test-concurrency=1 "tests/**/*.test.mjs"

windows-paths:
name: Windows path regressions
name: Windows unit tests
runs-on: windows-latest
timeout-minutes: 20
timeout-minutes: 30
env:
CI: true

Expand All @@ -161,8 +164,12 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Run Windows path regressions
run: node --test tests/paths.test.mjs tests/overlay.test.mjs tests/pagefind.test.mjs tests/cli-package-init.test.mjs
- name: Run unit tests
# Every unit test runs on Windows too: several suites branch on
# process.platform, so a hand-picked subset hides win32 regressions.
# --test-concurrency=1: see the note in the Diagnostics job — the
# content-overlay suites share src/user/user-config.ts.
run: node --test --test-concurrency=1 "tests/**/*.test.mjs"

build:
name: Build (Node.js ${{ matrix.node }})
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Lighthouse budgets

# F-39: the thresholds in lighthouserc.cjs (CLS, a11y/SEO scores) are real
# budgets but no workflow executed them. This scheduled/dispatch job runs the
# production build, serves dist/, and fails when lhci assert reports an error.
on:
schedule:
- cron: "0 3 * * 1"
workflow_dispatch:

permissions:
contents: read

jobs:
lighthouse:
name: Lighthouse budgets
runs-on: ubuntu-24.04
timeout-minutes: 30
env:
CI: true

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Set up pnpm
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
with:
# Omit the version so the action reads `packageManager` from package.json.
run_install: false

- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 26.13.0
cache: pnpm
cache-dependency-path: pnpm-lock.yaml

- name: Install dependencies
run: pnpm install --frozen-lockfile

# scripts/lighthouse/run.mjs builds, serves dist/ on 127.0.0.1:4321 and
# runs `lhci autorun` (collect + assert against lighthouserc.cjs).
- name: Build and audit production site
run: pnpm lighthouse
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ research/
# playwright
.playwright-cli/
test-results/
playwright-report/
tests/site/visual.spec.ts-snapshots/

# Lighthouse local reports
artifacts/lighthouse/*
Expand Down
8 changes: 4 additions & 4 deletions docs/ci-and-node-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ is needed.

The main `ci.yml` runs quality checks, diagnostics, Node unit tests, a Node 26.13.0 production build, and the cross-repository package-mode validation for every PR and push. Only the Playwright browser suites are path-gated.

`pnpm test` discovers browser specs under `tests/site/`. Run `node --test "tests/**/*.test.mjs"` for the separate Node suite.
`pnpm test` discovers browser specs under `tests/site/`. Run `node --test --test-concurrency=1 "tests/**/*.test.mjs"` for the separate Node suite. Keep `--test-concurrency=1`: several suites under `tests/content/` drive `scripts/content/config-overlay.mjs` against the tracked `src/user/user-config.ts`, so running test files concurrently lets one file read another's residual overlay (13 spurious failures on an 8-core machine, green when serialized).

- For a PR, changed paths are computed from the base SHA to the PR merge commit; for a push, from the event's `before` SHA to the current commit. Manual dispatches and new-branch pushes select both browser suites. The Shirones package-mode job is unconditional and runs on every workflow trigger.
- `tests/fixtures/**` selects the comment suite. Source, dependencies, runtime/build config, scripts, public assets, and workflow changes select both browser suites. Fast paths are limited to explicit documentation/Markdown patterns and the Node-test globs (`tests/*.test.mjs`, `tests/*/*.test.mjs`). Bash `*` can match `/`, so the second pattern also matches deeper paths such as `tests/plugins/markdown/katex-version.test.mjs`; these globs are not limited to one directory level. Unrecognized paths fail closed and select both browser suites; mixed changes take the most conservative selection.
- Unknown paths select both browser suites; a failed diff or invalid output must fail the stable regression checks rather than silently skip browser tests. The classifier reads NUL-delimited Git paths, so spaces, Unicode, and newlines are not split or quoted incorrectly.
- The workflow calls `scripts/ci/detect-browser-suites.sh`, which runs `scripts/ci/classifier-change-guard.sh` and `scripts/ci/classify-browser-suites.sh` into separate temporary output files. If the classifier or orchestrator changed, the guard's `comments=true` and `styles=true` values are authoritative; only the selected result is appended to `GITHUB_OUTPUT`, so a later classifier result cannot overwrite the guard. `git diff --quiet` status 1 means a protected script changed; statuses greater than 1 are Git errors and fail closed. `tests/ci-path-filter.test.mjs` runs the detector on temporary Git histories, including a classifier that reports false after changing, and asserts the final outputs; it also tests changed classifier, changed orchestrator, unchanged, and invalid-base guard cases.
- The classifier integration tests run Bash on POSIX hosts when it is available. Native Windows is skipped because the tests pass POSIX paths and temporary Git paths to Bash without Windows path translation; use WSL/Linux to run them locally. CI runs them on Ubuntu.

The `Diagnostics and tests` job runs the package runtime manifest check (`pnpm check:package-manifest`) on every CI run, and the expensive cross-repository tarball validation also runs on every CI run. The Biome step in `ci.yml` currently has `continue-on-error: true`; a green required check does not itself make Biome blocking. Run `pnpm exec biome ci ./src` locally for source changes and review formatter edits rather than assuming CI status enforces them.
The `Diagnostics and tests` job runs the package runtime manifest check (`pnpm check:package-manifest`) on every CI run, and the expensive cross-repository tarball validation also runs on every CI run. The Biome step in `ci.yml` no longer carries `continue-on-error`, so a lint or format violation fails the `Code quality` job instead of only annotating it. Run `pnpm exec biome ci ./src` locally for source changes and review formatter edits rather than assuming CI status enforces them.

The Node 26.13.0 production build exercises source mode. The 30-minute Style regressions check is a stable aggregate over four parallel Playwright shards. `scripts/ci/list-style-regression-specs.mjs` selects every top-level `tests/site/*.spec.ts` except `comments.spec.ts` and `waline.spec.ts` (kept in the separate disabled/Waline/Twikoo mode matrix) and `visual.spec.ts` (its golden screenshots are ignored and local-only). `tests/style-regression-specs.test.mjs` checks this selection against the filesystem and the four-shard workflow matrix. The prior 14-spec focused suite took about 21.5 minutes in the 2-GiB local review sandbox (147 passed, 2 intentionally skipped); the expanded all-applicable suite is now divided across four shards. The cross-repository Shirones job now builds and validates the npm tarball, including its CLI lifecycle and Astro build/dev smoke checks. Changes under `src/integration/` or other package-mode wiring should still follow [npm package mode](./npm-package-mode.md) and the [packaging contract](./packaging-contract.md); source-mode checks alone are not package-mode evidence.
The Node 26.13.0 production build exercises source mode. The 30-minute Style regressions check is a stable aggregate over four parallel Playwright shards. `scripts/ci/list-style-regression-specs.mjs` selects every top-level `tests/site/*.spec.ts` except `comments.spec.ts` and `waline.spec.ts` (kept in the separate disabled/Waline/Twikoo mode matrix); `visual.spec.ts` was removed with F-71 because its golden screenshots are gitignored and never compared in CI. `tests/style-regression-specs.test.mjs` checks this selection against the filesystem and the four-shard workflow matrix, and fails if any excluded spec is not named in `ci.yml`, so a spec cannot go silently dead again. The prior 14-spec focused suite took about 21.5 minutes in the 2-GiB local review sandbox (147 passed, 2 intentionally skipped); the expanded all-applicable suite is now divided across four shards. The shard runner `scripts/ci/run-style-regressions.sh` exports `E2E_PORT` and runs `astro dev stop` before Playwright, and `playwright.config.ts` derives both the dev command port and `baseURL`/`webServer.url` from that value with `reuseExistingServer: !process.env.CI`, so `astro dev` can no longer fall back to a random port while the specs keep addressing the pinned one. The cross-repository Shirones job now builds and validates the npm tarball, including its CLI lifecycle and Astro build/dev smoke checks. Changes under `src/integration/` or other package-mode wiring should still follow [npm package mode](./npm-package-mode.md) and the [packaging contract](./packaging-contract.md); source-mode checks alone are not package-mode evidence.

## Local validation order

Expand All @@ -62,7 +62,7 @@ After changing Markdown processing, i18n modules, or test loading paths, run:
pnpm.cmd exec biome ci ./src
npx.cmd astro check
pnpm.cmd check:manifest
node --test "tests/**/*.test.mjs"
node --test --test-concurrency=1 "tests/**/*.test.mjs"
git diff --check
```

Expand Down
6 changes: 3 additions & 3 deletions docs/m3e-standard.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,19 +352,19 @@ variables.styl --mc-* → 语义令牌(--primary、--surface-container-low…

### 9.1 当前状态(2026-08)

- **site 级测试保留**(`tests/site/`,真实页面):视觉回归(4 页面 × light/dark)、axe 双模式、TOC、文章页(copy-link)、SSR 图标渲染、reduced-motion。
- **site 级测试保留**(`tests/site/`,真实页面):axe 双模式、TOC、文章页(copy-link)、SSR 图标渲染、reduced-motion(视觉回归的 golden 截图只在本地产出、CI 从不比对,相关 spec 已在 round 2 移除)。
- **atoms 级测试已移除**:原子测试页(`src/pages/atoms-*-test.astro`)、演示页(`src/components/atoms/*Demo.svelte`)、`tests/atoms/`(spec + helpers)已删除;**组件文件全部保留**(含 Tier B/C 库存原子)。历史测试记录在 git 中可追溯,未来组件落地/复用时按本节约定重建。
- 组件质量仍以官方 Material Web(`research/material-web/tokens/versions/v0_192`)为基准。

### 9.2 运行

```bash
pnpm test # 全量(等价 npx playwright test,site 级)
npx playwright test tests/site/visual.spec.ts # 单个文件
npx playwright test tests/site/a11y.spec.ts # 单个文件
npx playwright test -g "TOC" # 按标题过滤
```

- 配置:`playwright.config.ts`,testDir `./tests`,单 worker,`webServer` 自动拉起 Astro dev(http://localhost:4321)。
- 配置:`playwright.config.ts`,testDir `./tests`,单 worker,`webServer` 自动拉起 Astro dev(端口由 `E2E_PORT` 指定,默认 http://localhost:4321)。
- 断言要点(重建 atoms 级测试时沿用):
- 主题引擎写入 `--mc-*` 后组件颜色带 transition,断言前必须等过渡收敛(`--m3e-duration-short` 150ms),否则会拿到中间帧的 `rgba` 混合值。
- 交互类断言同样要等动画结束;菜单项选中后容器加 `.closed` 隐藏(项保留在 DOM,应断言容器而非计数)。
Expand Down
25 changes: 20 additions & 5 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@ import { defineConfig } from "@playwright/test";
* 组件质量专项 — Playwright 配置
* 说明:测试针对 Astro 开发服务器上的 atoms-*-test 页面(组件库验证页)。
* 复用系统 Chrome(channel: chrome),避免额外下载浏览器。
*
* 端口由 E2E_PORT 集中指定(默认 4321):`astro dev` 遇到端口被占会退到随机端口,
* 而用例仍按 baseURL 访问固定端口,就会打到别的仓库或别的流的服务器上(表现为与
* 代码无关的断言失败)。CI 跑用例前先停掉残留的后台服务器,并且不复用外部服务器;
* 需要并行跑多路 Playwright(例如同时开两个 worktree)时用 E2E_PORT 隔离。
*/
const e2ePort = Number(process.env.E2E_PORT ?? 4321);
if (!Number.isInteger(e2ePort) || e2ePort < 1024 || e2ePort > 65535) {
throw new Error(
`E2E_PORT must be a TCP port above 1023, got ${process.env.E2E_PORT}`,
);
}
const e2eOrigin = `http://localhost:${e2ePort}`;

export default defineConfig({
testDir: "./tests/site",
timeout: 30_000,
Expand All @@ -17,18 +30,20 @@ export default defineConfig({
retries: 0,
reporter: [["list"]],
use: {
baseURL: "http://localhost:4321",
baseURL: e2eOrigin,
channel: "chrome",
viewport: { width: 1280, height: 900 },
trace: "retain-on-failure",
},
webServer: {
command:
process.platform === "win32"
? "pnpm.cmd astro dev --port 4321 --host"
: "pnpm astro dev --port 4321 --host",
url: "http://localhost:4321",
reuseExistingServer: true,
? `pnpm.cmd astro dev --port ${e2ePort} --host`
: `pnpm astro dev --port ${e2ePort} --host`,
url: e2eOrigin,
// CI 下绝不复用已有服务器:端口被别的过程占用时要立刻报错,
// 而不是静默地对别的构建做测试。
reuseExistingServer: !process.env.CI,
timeout: 120_000,
env: {
ASTRO_DEV_BACKGROUND: "false",
Expand Down
5 changes: 3 additions & 2 deletions scripts/ci/classify-browser-suites.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ select_both_suites() {

while IFS= read -r -d '' path; do
case "$path" in
# Comment suites also consume fixtures outside tests/site/; keep this before docs/config patterns.
# Shared fixtures feed the comment suites and the unit tests that import
# them directly, so fixture edits select both browser regression suites.
tests/fixtures/*)
comments=true
select_both_suites
;;
# Source, dependency, runtime/build config, scripts, assets and workflow
# changes select both browser regression suites.
Expand Down
1 change: 0 additions & 1 deletion scripts/ci/list-style-regression-specs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { fileURLToPath } from "node:url";
export const EXCLUDED_STYLE_SPECS = new Set([
"comments.spec.ts",
"waline.spec.ts",
"visual.spec.ts",
]);

const ROOT = dirname(dirname(dirname(fileURLToPath(import.meta.url))));
Expand Down
12 changes: 11 additions & 1 deletion scripts/ci/run-style-regressions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ if (( shard_index > shard_total )); then
exit 2
fi

# `astro dev` 在端口被占时会退到随机端口,而 Playwright 仍按 baseURL 访问固定端口,
# 用例于是可能打到别的过程(例如某一步用 `astro dev --background` 留下的服务器)上,
# 表现为与代码无关的偶发失败。这里先停掉本项目残留的后台服务器,确保端口空闲,
# 并把端口显式交给 playwright.config.ts(CI 下 reuseExistingServer=false,端口被占
# 会直接报错而不是静默换端口)。分片端口保持同一个值:feed/post/share 等用例的断言
# 里写死了 dev 源(http://localhost:4321),换端口会让它们失败。
export E2E_PORT="${E2E_PORT:-4321}"
pnpm exec astro dev stop >/dev/null 2>&1 || true

mapfile -t specs < <(node scripts/ci/list-style-regression-specs.mjs)
if [[ "${#specs[@]}" -eq 0 ]]; then
echo "::error::No style regression specs were discovered."
exit 1
fi

printf 'Running %s site specs in Playwright shard %s.\n' "${#specs[@]}" "$shard"
printf 'Running %s site specs in Playwright shard %s on dev port %s.\n' \
"${#specs[@]}" "$shard" "$E2E_PORT"
pnpm exec playwright test "${specs[@]}" "--shard=$shard"
55 changes: 53 additions & 2 deletions scripts/lighthouse/run.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { spawn, execSync } from "node:child_process";
import { execSync, spawn } from "node:child_process";
import { readFileSync } from "node:fs";

const deviceArg = process.argv.find((arg) => arg.startsWith("--device="));
const device = deviceArg?.split("=")[1] === "mobile" ? "mobile" : "desktop";
Expand Down Expand Up @@ -49,13 +50,62 @@ async function waitForServer(url, timeoutMs = 20000) {
throw new Error(`Server failed to respond at ${url} within ${timeoutMs}ms`);
}

async function isPortServing(url) {
try {
await fetch(url, { signal: AbortSignal.timeout(2000) });
return true;
} catch {
return false;
}
}

function titleOf(html) {
return /<title[^>]*>([^<]*)<\/title>/i.exec(html)?.[1]?.trim() ?? "";
}

/** Title of the freshly built site, used to confirm the served page is ours. */
function distTitle() {
const html = readFileSync(
new URL("../../dist/index.html", import.meta.url),
"utf8",
);
return titleOf(html);
}

async function servedTitle(url) {
const res = await fetch(url, { signal: AbortSignal.timeout(5000) });
return titleOf(await res.text());
}

let server;
try {
console.log("Building site for Lighthouse audit...");
await run(["build"]);
killPort4321();
await run(["astro", "preview", "stop"]).catch(() => undefined);
await run(["astro", "preview", "--host", "127.0.0.1", "--port", "4321"]);
// Another project's server on 4321 would otherwise be audited in our name.
if (await isPortServing("http://127.0.0.1:4321/")) {
throw new Error(
"Port 4321 is already serving another server; stop it and retry.",
);
}
// Start the preview server without awaiting it: the server never exits on
// its own, so awaiting it here would hang the whole audit forever.
server = spawn(
Comment thread
markd3ng marked this conversation as resolved.
Resolved
command,
["astro", "preview", "--host", "127.0.0.1", "--port", "4321"],
{ stdio: "inherit", shell: process.platform === "win32" },
);
server.on("error", () => undefined);
await waitForServer("http://127.0.0.1:4321/");
// Confirm the port really serves the dist we just built, not a stranger.
const expectedTitle = distTitle();
const actualTitle = await servedTitle("http://127.0.0.1:4321/");
if (expectedTitle && actualTitle !== expectedTitle) {
throw new Error(
`Port 4321 serves unexpected content (title "${actualTitle}", expected "${expectedTitle}"); another server may own the port.`,
);
}
console.log(
`Preview server is running at http://127.0.0.1:4321/. Running Lighthouse CI (${device})...`,
);
Expand All @@ -66,6 +116,7 @@ try {
console.error(error instanceof Error ? error.message : error);
process.exitCode = 1;
} finally {
server?.kill();
await run(["astro", "preview", "stop"]).catch(() => undefined);
killPort4321();
}
2 changes: 1 addition & 1 deletion src/components/organisms/AlbumSection.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script lang="ts">
import Chips from "@components/atoms/action/Chips.svelte";
import Card from "@components/atoms/display/Card.svelte";
import Icon from "@components/atoms/display/Icon.svelte";
import LoadingIndicator from "@components/atoms/feedback/LoadingIndicator.svelte";
import TextField from "@components/atoms/input/TextField.svelte";
import AlbumCard from "@components/molecules/AlbumCard.svelte";
import PageHeader from "@components/molecules/PageHeader.svelte";
import I18nKey from "@i18n/i18nKey";
import { i18n } from "@i18n/translation";
import Icon from "@components/atoms/display/Icon.svelte";
import { onMount } from "svelte";
import type { AlbumIndexItem } from "@/types/album";

Expand Down
Loading
Loading