Skip to content

Commit 5d7eabc

Browse files
huangyiireneclaude
andauthored
test(service-settings): alias the remaining three workspace deps to source, emptying its check-test-source-alias entry (#8104) (#8190)
#8063 aliased two workspace deps to source in this package's first `vitest.config.ts`. The other three — `@objectstack/spec`, `@objectstack/platform-objects`, `@objectstack/types` — stayed on their `KNOWN_UNALIASED_TEST_IMPORTS` entry and kept resolving through `exports` to `dist/`. They are now aliased to source and the registry entry is deleted. 17 of this package's 20 test files were really reading the artifact: with the three `dist/` trees removed and the pre-#8104 config in place, 17 files fail to load and only 58 of 413 cases run. With the aliases, the same tree with no `spec`/`platform-objects`/`types` build output passes 413/413. The subpath entry points were the actual work. This package imports no bare `@objectstack/spec` and no bare `@objectstack/platform-objects` at run time — every reachable specifier for those two is a subpath (`spec/api`, `spec/contracts`, `spec/data`, `spec/system`, `platform-objects/system`, plus `spec/security` reached transitively through `types`). The object alias form would swallow them into `…/index.ts/<sub>` (`ENOTDIR`, #7778); the anchored bare form #8063 established does not swallow them but does not cover them either, so copying that shape would have left every one of them on `dist` with the registry entry undeletable. So `spec` takes the one-rule-for-all-namespaces capture form, its export map being uniform, while `platform-objects` takes an explicit `/system` entry because its map is not (`./plugin` is `src/plugin.ts`, a file, so a `([a-z-]+)` rule would invent `src/plugin/index.ts`). `plugin-audit` writes its `platform-objects/audit` entry the same way. The registry deletion is half the change: the entry is audited for set equality in both directions, so aliases-complete-with-entry-present and entry-deleted-with-aliases-incomplete each fail the gate. It reads OK at 61 registered packages, down from 62. 413 passed / 20 files, unchanged from baseline. No change under `src/`. Claude-Session: https://claude.ai/code/session_01SMN7p2W62YzA3bY7BaFv3r Co-authored-by: Claude <noreply@anthropic.com>
1 parent 43f37e1 commit 5d7eabc

3 files changed

Lines changed: 112 additions & 9 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
"@objectstack/service-settings": patch
3+
---
4+
5+
test(service-settings): resolve the remaining three workspace deps from source, emptying this package's `check-test-source-alias` registry entry (#8104)
6+
7+
#8063 gave this package its first `vitest.config.ts` and aliased two workspace
8+
deps to source (`@objectstack/objectql`, `@objectstack/core`) — the two that
9+
gate named when the package's first real-engine test landed. The other three,
10+
`@objectstack/spec`, `@objectstack/platform-objects` and `@objectstack/types`,
11+
stayed on their registered entry in `KNOWN_UNALIASED_TEST_IMPORTS` and kept
12+
resolving through `exports` to **`dist/`**. They are now aliased to source and
13+
the entry is deleted.
14+
15+
**How much of the suite was actually reading the artifact: 17 of 20 files.**
16+
Measured, not inferred — with the three `dist/` trees removed from the checkout
17+
and the pre-#8104 config in place, 17 test files fail to load at all
18+
(`Cannot find package '@objectstack/spec/system'`) and only 58 of 413 cases run.
19+
With the aliases below, the same tree with no `spec`, `platform-objects` or
20+
`types` build output anywhere passes 413/413. The build artifact is off the
21+
resolution path rather than merely shadowed by a fresh copy of it.
22+
23+
**The subpath entry points were the whole job, and the obvious shape does not
24+
do it.** This package imports **no bare** `@objectstack/spec` and **no bare**
25+
`@objectstack/platform-objects` at run time. Every specifier its tests can reach
26+
for those two is a subpath — `spec/api`, `spec/contracts`, `spec/data`,
27+
`spec/system`, `platform-objects/system` — joined by `spec/security`, reached
28+
transitively through `@objectstack/types` ([ADR-0105 D1] tenancy posture) once
29+
types itself resolves to source. So the two shapes that suggest themselves both
30+
fail, in opposite directions:
31+
32+
- the **object** form matches by **prefix**, so a bare key whose replacement is
33+
a file swallows the subpaths into `…/index.ts/system``ENOTDIR` at run time
34+
in a config that reads as correct (#7778);
35+
- the **anchored bare** form (`/^@objectstack\/spec$/`, the shape #8063 left
36+
behind) does not swallow them but does not **cover** them either — all six
37+
specifiers stay on `dist` and the registry entry cannot come off.
38+
39+
What covers them is a subpath rule. `spec` takes the one-rule-for-all-namespaces
40+
form `/^@objectstack\/spec\/([a-z-]+)$/` with the capture group inside the path,
41+
because its export map is uniform (`src/<ns>/index.ts` throughout) — so a new
42+
namespace import cannot make it stale. `platform-objects` gets an **explicit**
43+
`platform-objects/system` entry instead, because its map is *not* uniform:
44+
`./plugin` is `src/plugin.ts`, a file, so a `([a-z-]+)` rule would send
45+
`platform-objects/plugin` to `src/plugin/index.ts`, a path nobody wrote, failing
46+
on whoever next adds that import. `plugin-audit` writes its
47+
`platform-objects/audit` entry the same way for the same reason.
48+
49+
**The registry deletion is half the change, not its cleanup.**
50+
`KNOWN_UNALIASED_TEST_IMPORTS` is audited for set equality in both directions,
51+
so the two halves constrain each other and neither is green alone: with the
52+
aliases complete and the entry still present the gate fails *"registry entry is
53+
no longer needed … Delete the entry"*; with the entry deleted and any one alias
54+
missing it fails *"tests import 1 workspace package(s) that resolve to `dist/`
55+
with no source alias"*. The gate goes from 62 registered packages to 61.
56+
57+
No test turned red and no assertion moved: 413 passed / 20 files before and
58+
after, and **no change under `src/`**. That is the expected reading for a
59+
checkout whose `dist` was built from the same commit — dist and source agree
60+
here, which is exactly the condition under which the old setup looked fine. What
61+
changes is that the suite no longer has an opinion about build state at all.

packages/services/service-settings/vitest.config.ts

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,23 @@
1515
// adapter), which pulls `resolveAuthzContext` from core — so core became
1616
// newly reachable from the package's tests and the gate named it.
1717
//
18-
// Only those two are aliased, deliberately. The package's other workspace
19-
// imports (`@objectstack/platform-objects`, `@objectstack/spec`,
20-
// `@objectstack/types`) are its registered set in that gate's
21-
// `KNOWN_UNALIASED_TEST_IMPORTS`; the registry is audited for set EQUALITY in
22-
// both directions, so aliasing them here is a separate, deliberate shrink and
23-
// not a rider on a P0 security fix.
18+
// #8104 finished the job for the remaining three — `@objectstack/spec`,
19+
// `@objectstack/platform-objects` and `@objectstack/types` — and with them this
20+
// package's entry in `KNOWN_UNALIASED_TEST_IMPORTS` came off. That registry is
21+
// audited for set EQUALITY in both directions, so deleting the entry is half of
22+
// that change rather than its cleanup: the aliases below and the absence of the
23+
// entry each fail the gate without the other.
24+
//
25+
// ⚠️ What the shrink actually required, measured rather than assumed: this
26+
// package imports NO bare `@objectstack/spec` and NO bare
27+
// `@objectstack/platform-objects` at run time. Every specifier its tests can
28+
// reach for those two is a SUBPATH — `spec/api`, `spec/contracts`, `spec/data`,
29+
// `spec/system`, `platform-objects/system` — joined by `spec/security`, reached
30+
// transitively through `@objectstack/types` ([ADR-0105 D1] tenancy posture)
31+
// once types itself resolves to source. An anchored BARE pattern
32+
// (`/^@objectstack\/spec$/`) matches none of them, so copying #8063's
33+
// two-entry shape would have left all of them on `dist` with the registry entry
34+
// undeletable. The subpath rules below are the load-bearing half.
2435
import { defineConfig } from 'vitest/config';
2536
import path from 'path';
2637

@@ -43,6 +54,40 @@ export default defineConfig({
4354
find: /^@objectstack\/core$/,
4455
replacement: path.resolve(__dirname, '../../core/src/index.ts'),
4556
},
57+
// `platform-objects` gets an EXPLICIT subpath entry rather than the
58+
// one-rule-for-all-namespaces capture below, because its export map is
59+
// not uniform: `./plugin` is `src/plugin.ts`, a FILE, while every other
60+
// namespace is `src/<ns>/index.ts`. A `([a-z-]+)` rule would send
61+
// `platform-objects/plugin` to `src/plugin/index.ts`, which does not
62+
// exist — a path nobody wrote, failing on whoever adds that import.
63+
// `plugin-audit` writes its `platform-objects/audit` entry the same way
64+
// and for the same reason.
65+
{
66+
find: /^@objectstack\/platform-objects\/system$/,
67+
replacement: path.resolve(__dirname, '../../platform-objects/src/system/index.ts'),
68+
},
69+
{
70+
find: /^@objectstack\/platform-objects$/,
71+
replacement: path.resolve(__dirname, '../../platform-objects/src/index.ts'),
72+
},
73+
// `spec`, by contrast, IS uniform — every namespace in its export map is
74+
// `src/<ns>/index.ts` — so one rule covers all of them and cannot go
75+
// stale when a new namespace import arrives. The capture group has to sit
76+
// INSIDE the path, which is what forces the template literal here (the
77+
// shape `service-knowledge` and `plugin-audit` already use, and the one
78+
// the gate's canary fixture pins so a reader cannot misread it — #8020).
79+
{
80+
find: /^@objectstack\/spec\/([a-z-]+)$/,
81+
replacement: `${path.resolve(__dirname, '../../spec/src')}/$1/index.ts`,
82+
},
83+
{
84+
find: /^@objectstack\/spec$/,
85+
replacement: path.resolve(__dirname, '../../spec/src/index.ts'),
86+
},
87+
{
88+
find: /^@objectstack\/types$/,
89+
replacement: path.resolve(__dirname, '../../types/src/index.ts'),
90+
},
4691
],
4792
},
4893
});

scripts/check-test-source-alias.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,6 @@ const KNOWN_UNALIASED_TEST_IMPORTS = {
302302
'@objectstack/service-package': ['@objectstack/metadata-core'],
303303
'@objectstack/service-queue': ['@objectstack/objectql', '@objectstack/platform-objects'],
304304
'@objectstack/service-realtime': ['@objectstack/spec'],
305-
'@objectstack/service-settings': [
306-
'@objectstack/platform-objects', '@objectstack/spec', '@objectstack/types',
307-
],
308305
'@objectstack/service-sms': ['@objectstack/plugin-auth', '@objectstack/service-settings'],
309306
'@objectstack/service-storage': [
310307
'@objectstack/objectql', '@objectstack/observability', '@objectstack/platform-objects',

0 commit comments

Comments
 (0)