Repository navigation
Commit f923bc1
ci(test-ui): select a cross-package test when a package it reads is affected, not on every run (#31540)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9Ubb77KgkSa7rZ7QmbAP6hZdVB)_
Part-of #31520 (slice 1 of 3 planned; the card closes only when the
empty-diff count is under 200 and the three-PR shard reading is on it)
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:Test UI 的选测脚本不再把「跨包引用」的测试当作每次必跑;它们只在所引用的包被改动时才跑。空改动下的必跑集从 691
个文件降到 579 个。
- 为什么改:一个只改一行的 UI PR 也要跑完这 691 个必跑文件;其中 112 个只是引用了别的包,包图本可以定位它们。
- 风险与回滚:风险是某个测试在它读的包变了时没被选中;已用 34
个单包改动逐一比对旧新两版,没有一个测试丢掉它该有的选中。回滚即还原这一个脚本。
- 先看:`ui/scripts/select-affected-tests.mjs` 里 `attributed`
那段(依据所触及的包选中),然后是测试文件里新增的 `attributed test files` 一组。
- 两分钟验证:`cd ui && node scripts/select-affected-tests.mjs --base
origin/main --explain`,预期 `always-on test files ...: 579`。
- 需要你做的:无,席位落地。
## What changes
`ui/scripts/select-affected-tests.mjs` had four always-on reasons. Two
of them, "reaches PKG outside OWNER" and "imports NAME, which OWNER does
not depend on", named a workspace package the selector could already
place. Those tests now get **input packages**: their own package, every
package their relative import closure has a file in, and every workspace
package that closure imports by name. A test is selected, as a file
filter, whenever one of its input packages is affected. Because the
affected set already includes dependents, a change to a package that a
reached package depends on selects the test too.
What stays always-on is unchanged: tests outside every package, tests
whose closure reads the disk or spawns a process, and tests that reach a
file outside every package (`scripts/`, the tree root). `--explain`
prints the attributed files and the packages that selected each one. The
header (new item 2a) says why the edge is attributed rather than
declared. Declaring it in `package.json` would make the test's whole
package a dependent of the target. On this tree, three of the five
undeclared edges would also be cycles: `core`↔`plugin-map`,
`core`↔`i18n`, `react`↔`plugin-grid`.
Empty-diff count, `cd ui && node scripts/select-affected-tests.mjs
--base origin/main --explain`:
| head | always-on | selected of tracked |
|---|---:|---:|
| `f4b1f9ee` (branch base) | 691 | 691 of 6,658 |
| `a3ac7fb3` (`origin/main` merged in, main's selector) | 691 | 691 of
6,658 |
| `1f0dd719` (this PR, after merging `a3ac7fb3`) | 579 | 579 of 6,658 |
## Why
Slice 1 of the plan the `domain:ui#3` seat approved on #31520: class (a)
of the card's classification, the 112 always-on tests whose only edges
past their package go into other packages. Slices 2 (disk readers whose
reads resolve inside named packages) and 3 (`scripts/` and
`eslint-rules/` as owner directories) follow as separate PRs.
## Tests
In `ui/scripts/__tests__/select-affected-tests.test.ts`, the fixture
gains `packages/c/src/reach.test.ts`, which imports a file of `@fx/b`,
which in turn depends on `@fx/a`. The existing `undeclared.test.ts`
imports `@fx/a` by name without declaring it.
- Positive controls: a change in `@fx/a` selects `undeclared.test.ts`
(through `@fx/a`). A change in `@fx/b` selects `reach.test.ts` (through
`@fx/b`). A change in `@fx/a` also selects `reach.test.ts` (through
`@fx/a` and `@fx/b`), which is the case the seat asked for: a package
the reached package depends on.
- Negative controls: a docs-only change leaves both out of the always-on
set and out of the filters. A change in an unrelated package
(`@fx/registry`) selects neither. A change in their own package selects
them through the package directory, not as attributed files.
`escapes.test.ts`, which reaches `scripts/`, stays always-on.
- The old pin that `undeclared.test.ts` is always-on is replaced by the
attribution pins above.
<details><summary>Ablation: the selector at the base, the new controls
red</summary>
With the fix committed (`80935d1b`), the selector was restored to
`f4b1f9ee` on disk (`grep -c attributed` gave 0 on disk against 7 at
HEAD). The test file at HEAD was then run: 6 failed, 38 passed. The
failures were the six new cases: "does not keep a test whose only edges
past its package are into other packages", the three "selects a test
when ..." cases, "does not select either ...", and "a change to its own
package ...". The selector was then restored from `HEAD`, and `git
hash-object` matched the HEAD blob `6b5a98a0`. `git diff HEAD` was
empty.
</details>
<details><summary>Exactness sweep: no test loses a selection it
needs</summary>
For each workspace package with a tracked `src/` file (38 packages;
core, i18n, test-support and types are full-run triggers under both
versions), the base selector and this one were each run on a one-file
change in that package. Across the 34 affected-mode runs, 1,891
test-file selections were dropped and 0 were added. For every dropped
one, an independent check of the test's relative closure confirmed it
has no file in an affected package's directory, imports no affected
package by name, reads no disk, and reaches no non-package file.
</details>
## Acceptance notes
- **The card's second acceptance line will read 16 shards on every UI
PR, whatever the always-on count.** `node scripts/ci-shard-matrix.mjs`
reads `test-ui 16 literal`; Test Core's matrix is `planned`. On PR run
42478811805 (a console-only fix), the 16 Test UI shards took 3,368
runner-seconds, 59% of it in the test step. This PR shrinks only that
step. The seat has taken the matrix question to the maintainer. It would
be a `ci.yml` change, which is out of scope here.
- The step-1 classification of all 691 files is in the card thread's
project files (`issue-31520/classification.md`). On that measurement,
slices 1 to 3 reach about 393, and under 200 needs a further decision
recorded on the card.
## Verification
Derived with `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` at `80935d1b`: 20 families. All 20 were run
locally on that head and reconciled with `--ran`, which reported "20
run, 0 NOT-MEASURED (a DERIVED zero)". `node
scripts/check-sdui-manifest.mjs` was also run, as the ui seat requires
on every card.
<details><summary>Gate exit codes at 80935d1</summary>
```text
node scripts/check-closing-keyword-parity.mjs :: exit 0
node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0
node scripts/check-comment-mask-corpus.mjs :: exit 0
pnpm check:cross-package-test-inputs :: exit 0
pnpm check:driver-memory-census :: exit 0
pnpm check:engine-double-contract :: exit 0
pnpm check:gitlink-declared :: exit 0
pnpm check:nul-bytes :: exit 0
pnpm check:published-files :: exit 0
pnpm check:query-options-erasure :: exit 0
pnpm check:refd-timer-probe :: exit 0
pnpm check:registry-log-declared :: exit 0
pnpm check:rest-log-spy-declared :: exit 0
pnpm check:tier-file-adoption :: exit 0
pnpm check:type-check-coverage :: exit 0
pnpm check:type-check-debt :: exit 0
pnpm check:undeclared-dep-imports :: exit 0
pnpm check:watch-hint-literal :: exit 0
pnpm check:where-matcher :: exit 0
node scripts/check-sdui-manifest.mjs :: exit 0
pnpm --dir ui exec vitest run scripts/ :: exit 0
```
</details>
- `pnpm --dir ui exec vitest run scripts/` (under the verify lock): 170
test files passed and 2 were skipped, the skips being existing
conditional skips. 5,002 tests passed.
- On `1f0dd719`, after merging `a3ac7fb3`: the selector's own two suites
passed again (2 files, 54 tests), and `--explain` printed 579. The merge
brought in no `ui/scripts/` change.
- No changeset: `ui/` is the private `object-ui-monorepo` root, and
`ui/scripts/` ships in no package, so this PR carries `skip-changeset`.
- CI runs the rest: the PR's required check-runs.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QsR2jREy1UXbgGdQRBvZji)_
Co-authored-by: Claude <noreply@anthropic.com>1 parent dabef0f commit f923bc1
2 files changed
Lines changed: 86 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
164 | 165 | | |
165 | 166 | | |
166 | 167 | | |
167 | | - | |
168 | | - | |
| 168 | + | |
| 169 | + | |
169 | 170 | | |
170 | 171 | | |
171 | | - | |
172 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
173 | 177 | | |
174 | 178 | | |
175 | 179 | | |
| |||
178 | 182 | | |
179 | 183 | | |
180 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
181 | 223 | | |
182 | 224 | | |
183 | 225 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
58 | 69 | | |
59 | 70 | | |
60 | 71 | | |
| |||
597 | 608 | | |
598 | 609 | | |
599 | 610 | | |
600 | | - | |
| 611 | + | |
601 | 612 | | |
602 | 613 | | |
603 | 614 | | |
| |||
704 | 715 | | |
705 | 716 | | |
706 | 717 | | |
| 718 | + | |
707 | 719 | | |
| 720 | + | |
| 721 | + | |
708 | 722 | | |
709 | 723 | | |
710 | 724 | | |
| |||
717 | 731 | | |
718 | 732 | | |
719 | 733 | | |
720 | | - | |
721 | | - | |
722 | | - | |
| 734 | + | |
| 735 | + | |
723 | 736 | | |
724 | 737 | | |
| 738 | + | |
| 739 | + | |
725 | 740 | | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
730 | 746 | | |
731 | 747 | | |
732 | 748 | | |
733 | 749 | | |
734 | 750 | | |
735 | 751 | | |
736 | | - | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
737 | 758 | | |
738 | 759 | | |
739 | 760 | | |
| |||
742 | 763 | | |
743 | 764 | | |
744 | 765 | | |
| 766 | + | |
745 | 767 | | |
746 | 768 | | |
747 | 769 | | |
| |||
797 | 819 | | |
798 | 820 | | |
799 | 821 | | |
| 822 | + | |
| 823 | + | |
800 | 824 | | |
801 | 825 | | |
802 | 826 | | |
| |||
0 commit comments