Skip to content

Commit e63cef1

Browse files
committed
tooling(cutover): check:test-source-alias asks the vitest-alias half of non-ui/ members only (decision F, objectstack#25803)
Decision F (17f): adopt the function-body half for the objectui tests (warm module-scope imports, card F) and scope the vitest-alias half of the gate to members outside ui/. objectui's tests resolve their workspace deps through the built dist/ by design; at the import 42 ui/ members read as unaliased with no registry entry. inAliasHalf() keeps those members out of the measured registry population and out of the 'tests import ... no source alias' verdict. The scan still measures their specifiers, so the clocked-window rule reads ui/ exactly as before; the ENOTDIR alias-table rules and config readability are unchanged. A registry entry naming a ui/ member is refused as unneeded. The OK line names how many scanned packages were not asked the alias half. Self-test: fixture (1c) and four baseline assertions; dropping the scope reds three of them. Before: exit 1 (42 alias-half + 57 clocked-window findings on the verify tree). After: self-test 0; scan exit 1 on the 57 clocked-window findings only, the accepted class that #25781 and card F clear. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CUXv64KLMfYv3ia2sWi6te
1 parent 9a9379a commit e63cef1

1 file changed

Lines changed: 57 additions & 2 deletions

File tree

‎scripts/check-test-source-alias.mjs‎

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,24 @@ const WORKSPACE_BARE_MEMBER_MANIFESTS = ['ui/package.json'];
655655
/** The parent directories those globs enumerate — each glob minus its leaf. */
656656
const WORKSPACE_PARENT_DIRS = WORKSPACE_PARENT_GLOBS.map((glob) => glob.replace(/\/\*$/, ''));
657657

658+
/**
659+
* Where the VITEST-ALIAS half stops (decision F, objectstack#25752 item 17f).
660+
* That half -- a workspace dep resolved through `dist/` with no source alias,
661+
* and the KNOWN_UNALIASED_TEST_IMPORTS registry that mirrors it -- is asked of
662+
* members outside the objectui tree only: objectui's tests resolve their
663+
* workspace deps through the built `dist/` by design (its Test UI matrix builds
664+
* first), 42 members at the import, and the ruling keeps that. Every other rule
665+
* still reads ui/: the clocked-window rule (the function-body half F adopted,
666+
* over the same measured specifiers), both ENOTDIR alias-table rules, and the
667+
* readability of every config.
668+
*/
669+
const ALIAS_HALF_EXCLUDED_DIR = 'ui';
670+
671+
/** Is the package at `rel` asked the vitest-alias half? */
672+
function inAliasHalf(rel) {
673+
return rel !== ALIAS_HALF_EXCLUDED_DIR && !rel.startsWith(`${ALIAS_HALF_EXCLUDED_DIR}/`);
674+
}
675+
658676
const SKIP_DIRS = new Set(['node_modules', 'dist', 'build', 'coverage', '.turbo', '.next', '.cache']);
659677
const TEST_FILE = /\.(test|spec)\.[cm]?[jt]sx?$/;
660678
const SOURCE_FILE = /\.[cm]?[jt]sx?$/;
@@ -2120,7 +2138,11 @@ function check(root, registry) {
21202138
'scanner found NO package publishing a subpath export — the `exports` read is broken, not the repo',
21212139
);
21222140

2123-
const measured = new Map(packages.filter((p) => p.unaliased.length > 0).map((p) => [p.name, p.unaliased]));
2141+
// The vitest-alias half, scoped by decision F (`inAliasHalf`). Measured for
2142+
// every package still -- the clocked-window rule reads the same specifiers.
2143+
const measured = new Map(
2144+
packages.filter((p) => p.unaliased.length > 0 && inAliasHalf(p.rel)).map((p) => [p.name, p.unaliased]),
2145+
);
21242146

21252147
for (const pkg of packages) {
21262148
if (pkg.unreadable) {
@@ -2317,6 +2339,18 @@ function buildFixtureTree() {
23172339
'export default log + nested + ghost;\n',
23182340
});
23192341

2342+
// (1c) THE OBJECTUI SCOPE (decision F). The violator's shape under ui/, plus a
2343+
// load inside a test body: the vitest-alias half must not ask it, the
2344+
// clocked-window rule still must.
2345+
fixture(root, 'ui/packages/ui-violator', {
2346+
'package.json': ARTIFACT_MANIFEST('@fx/ui-violator'),
2347+
'src/thing.test.ts':
2348+
"import { it } from 'vitest';\n" +
2349+
"it('y', async () => {\n" +
2350+
" await import('@fx/core');\n" +
2351+
'});\n',
2352+
});
2353+
23202354
// (2) compliant: anchored array-form alias to source.
23212355
fixture(root, 'packages/compliant', {
23222356
'package.json': ARTIFACT_MANIFEST('@fx/compliant'),
@@ -2927,6 +2961,23 @@ function selfTest() {
29272961
expect(!has(bare.failures, 'packages/unreachable'), 'an import no test can reach was treated as a hazard');
29282962
expect(has(bare.failures, 'ENOTDIR'), 'the prefix/ENOTDIR alias trap was not detected');
29292963
expect(has(bare.failures, 'cannot be read statically'), 'a config with spread aliases was read as aliasing nothing');
2964+
// Decision F: the ui/ member is out of the vitest-alias half and in the clocked-window rule.
2965+
expect(
2966+
!bare.failures.some((f) => f.startsWith('ui/packages/ui-violator') && f.includes('no source alias')),
2967+
'a ui/ member was asked the vitest-alias half that decision F scopes to non-ui/ members',
2968+
);
2969+
expect(
2970+
!bare.measured.has('@fx/ui-violator'),
2971+
'a ui/ member entered the measured registry population that decision F scopes out',
2972+
);
2973+
expect(
2974+
bare.failures.some((f) => f.startsWith('ui/packages/ui-violator/src/thing.test.ts:3') && f.includes('a CLOCKED window')),
2975+
'scoping the vitest-alias half also silenced the clocked-window rule for a ui/ member',
2976+
);
2977+
expect(
2978+
has(check(root, { '@fx/ui-violator': ['@fx/core'] }).failures, '@fx/ui-violator: registry entry is no longer needed'),
2979+
'a registry entry for a ui/ member was not refused as unneeded',
2980+
);
29302981

29312982
// ── the payload boundary ─────────────────────────────────────────────
29322983
// A test under a dir the package's own tsconfig excludes is payload (the
@@ -3641,9 +3692,13 @@ if (argv.includes('--self-test')) {
36413692
);
36423693
process.exit(1);
36433694
}
3695+
const outOfAliasHalf = packages.filter((p) => !inAliasHalf(p.rel)).length;
36443696
console.log(
36453697
`check-test-source-alias OK — ${packages.length} packages with tests scanned; ` +
36463698
`${measured.size} registered as still resolving a workspace dep through \`dist/\`; ` +
3647-
`${publishedCount} published subpath(s) resolved through every alias table.`,
3699+
`${publishedCount} published subpath(s) resolved through every alias table.` +
3700+
(outOfAliasHalf === 0
3701+
? ''
3702+
: ` ${outOfAliasHalf} of them under ${ALIAS_HALF_EXCLUDED_DIR}/ were not asked the vitest-alias half (decision F).`),
36483703
);
36493704
}

0 commit comments

Comments
 (0)