An open source design system that's fully customizable and agent ready
TypeScript
ci: the RTL D7 regression step skips, visibly, a head that predates the D7 test (#8811)
Cindy Zhang62dd62c98b7e
diff --git a/.github/scripts/ci-rtl-d7.test.mjs b/.github/scripts/ci-rtl-d7.test.mjsnew file mode 100644index 0000000000..09a88fef21--- /dev/null+++ b/.github/scripts/ci-rtl-d7.test.mjs@@ -0,0 +1,101 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file Contract for the RTL audit's D7 regression step in ci.yml.+ *+ * The step runs `.github/scripts/rtl-audit-coarse-hit.browser.test.mjs` from+ * the pull request's head. A head cut before that test existed has no D7+ * native-size enforcement for it to check: the step logs that it skipped and+ * passes. A head that has the file always runs it, and its failure fails the+ * step. The path must name a real file, or a move would skip silently.+ */++import {spawnSync} from 'node:child_process';+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';++import {describe, expect, it} from 'vitest';+import yaml from 'yaml';++const root = path.resolve(import.meta.dirname, '../..');+const ci = yaml.parse(+ fs.readFileSync(path.join(root, '.github/workflows/ci.yml'), 'utf8'),+);+const D7_TEST = '.github/scripts/rtl-audit-coarse-hit.browser.test.mjs';++function d7Step() {+ for (const job of Object.values(ci.jobs)) {+ const step = (job.steps ?? []).find(+ candidate => candidate.name === 'Verify D7 native target regression',+ );+ if (step != null) {+ return step;+ }+ }+ throw new Error('no "Verify D7 native target regression" step in ci.yml');+}++/**+ * Runs the step's script as Actions does (bash -e) in a scratch checkout,+ * with a stub `pnpm` first on PATH that records its arguments and exits+ * `pnpmExit`.+ */+function run({hasTest, pnpmExit}) {+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ci-rtl-d7-'));+ const bin = path.join(dir, 'bin');+ fs.mkdirSync(bin);+ const calls = path.join(dir, 'pnpm-calls.txt');+ fs.writeFileSync(+ path.join(bin, 'pnpm'),+ `#!/usr/bin/env bash\necho "$*" >> ${JSON.stringify(calls)}\nexit ${pnpmExit}\n`,+ {mode: 0o755},+ );+ if (hasTest) {+ fs.mkdirSync(path.join(dir, path.dirname(D7_TEST)), {recursive: true});+ fs.writeFileSync(path.join(dir, D7_TEST), '');+ }+ const result = spawnSync('bash', ['-e', '-c', d7Step().run], {+ cwd: dir,+ encoding: 'utf8',+ env: {...process.env, PATH: `${bin}:${process.env.PATH}`},+ });+ const pnpm = fs.existsSync(calls) ? fs.readFileSync(calls, 'utf8') : '';+ fs.rmSync(dir, {recursive: true, force: true});+ return {status: result.status, stdout: result.stdout, pnpm};+}++describe('ci.yml RTL D7 regression step', () => {+ it('names a D7 test that exists, so moving it cannot skip the step silently', () => {+ expect(fs.existsSync(path.join(root, D7_TEST))).toBe(true);+ expect(d7Step().run).toContain(D7_TEST);+ });++ it('runs only for the first core RTL shard, in the browser mode', () => {+ const step = d7Step();+ expect(step.if).toBe("matrix.package == 'core' && matrix.part == 1");+ expect(step.env).toEqual({ASTRYX_RTL_BROWSER: '1'});+ });++ it('skips with a visible log when the head predates the D7 test', () => {+ const result = run({hasTest: false, pnpmExit: 1});+ expect(result.status).toBe(0);+ expect(result.stdout).toContain(+ 'skipped: head predates D7 native-size enforcement',+ );+ expect(result.pnpm).toBe('');+ });++ it('runs the D7 test when the head has it, and passes when it passes', () => {+ const result = run({hasTest: true, pnpmExit: 0});+ expect(result.status).toBe(0);+ expect(result.pnpm).toContain(`vitest run --project node ${D7_TEST}`);+ expect(result.stdout).not.toContain('skipped');+ });++ it('fails closed when the head has the D7 test and it fails', () => {+ const result = run({hasTest: true, pnpmExit: 1});+ expect(result.status).not.toBe(0);+ expect(result.pnpm).toContain(D7_TEST);+ });+});diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 4226b1cb20..b33d7d5898 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -2461,11 +2461,22 @@ jobs:- name: Install Playwrightrun: pnpm install --frozen-lockfile && npx playwright install chromium+ # The D7 native-size regression test lives on the PR head. A head cut+ # before it has no native-size enforcement for the test to check (its+ # audit still checks D7's centering and hit-testing), so the step says+ # so and passes; a head that has the file always runs it, and a failure+ # fails. ci-rtl-d7.test.mjs keeps the path pointing at a real file.- name: Verify D7 native target regressionif: matrix.package == 'core' && matrix.part == 1env:ASTRYX_RTL_BROWSER: '1'- run: pnpm exec vitest run --project node .github/scripts/rtl-audit-coarse-hit.browser.test.mjs --maxWorkers=1+ run: |+ D7_TEST=.github/scripts/rtl-audit-coarse-hit.browser.test.mjs+ if [ ! -f "$D7_TEST" ]; then+ echo '::notice title=D7 regression skipped::skipped: head predates D7 native-size enforcement; its D7 results cover centering and hit-testing only'+ exit 0+ fi+ pnpm exec vitest run --project node "$D7_TEST" --maxWorkers=1# A registry/classifier mutation runs the full audit from the PR checkout,# while eligibility itself came from trusted base policy. Scope resolution