Repository navigation
Commit 5b2ec82
feat(spec)!: strict defineStack judges a packages[] stack's namespace prefixes per body and its top level by the residual rule (#33122)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoWK5rFW1SUGSkDw9iatZE4f)_
Fixes #33069
Clause-②: yes (narrowing) — one face widens and one narrows. Widened: a
stack carrying `packages[]` whose top level repeats objects that package
bodies of different namespaces declare (an additive artifact, such as
`resolveArtifactCollections` output) is accepted by strict
`defineStack`, where it was refused. Narrowed: a `packages[]` body whose
object its own body's namespace does not prefix is refused, where it was
accepted when the stack's top level held no copy of it or a copy the
manifest's namespace prefixes.
Metadata-protocol: narrowed
Skills-docs: none — the taught rule (every `object.name` carries its own
package's `namespace` prefix) is unchanged, and no skill or docs page
teaches handing a `packages[]` stack to `defineStack`; what moves is
which namespace strict `defineStack` judges each object of such a stack
against.
## 维护者速读
- 改了什么:严格模式 `defineStack` 判带 `packages[]`
的栈的命名空间前缀时,按加载路径的登记方式判:每个包体的对象对照该包体自己的命名空间;没有包体声明的顶层对象(残余)才对照栈 manifest
的命名空间。判残余用的是 #33074 已有的同一份 `isResidualTopLevelItem`,没有第二份实现。
- 为什么改:原来把顶层合并后的所有对象都拿去比 manifest
的一个命名空间,多包、多命名空间的组合制品(`resolveArtifactCollections` 的输出)交回 `defineStack`
会被 `STACK_NAMESPACE_PREFIX_INVALID` 误拒;而包体里前缀写错的对象反而没人判。
- 风险与回滚:一放一收(`Clause-②: yes (narrowing)`)。收的一面只影响手搭的或 `strict: false`
构建的包体(经严格 `defineStack` 产出的包体早已按自己的命名空间判过)。实测本仓与 HotCRM 没有产品代码把带
`packages[]` 的栈交给严格 `defineStack`。不带 `packages[]` 的栈判法与报错原文逐字不变。回滚即
revert。
- 先看:`packages/spec/src/stack.zod.ts` 的
`namespacePrefixErrors`(新函数,`validateNamespacePrefix`
改为调用它);`packages/spec/src/stack.test.ts` 新
describe;`packages/runtime/src/artifact-collections.public-reader.test.ts`
新 describe。
- 两分钟验证:`pnpm --filter @objectstack/spec exec vitest run
src/stack.test.ts -t "namespace prefixes are judged per body"`,预期 4
条全绿,其中一条是「两个命名空间的组合制品被接受」,一条是「残余对象前缀不对被拒(422
`STACK_NAMESPACE_PREFIX_INVALID`)」。
- 需要你做的:无,席位落地。
## What changes
**`validateNamespacePrefix`** (the strict `defineStack` pass,
`packages/spec/src/stack.zod.ts`) now reads its prefix findings from a
new `namespacePrefixErrors`, which judges each object against the
namespace of the package the load path registers it under:
- **No `packages[]`:** unchanged. Every top-level object is judged
against `manifest.namespace`, and the finding is
`validateObjectNamespacePrefix`'s own sentence, byte for byte.
- **`packages[]`** (ADR-0130 D4): each body's objects are judged against
that body's own `namespace`, the finding prefixed `Package 'ID'
(packages[J].manifest.objects[I]): `. A top-level object that no body
declares is the residual, registered under `manifest.id` by the boot's
residual rule (`unclaimedTopLevel`, `@objectstack/metadata`), and is
judged against `manifest.namespace`, prefixed `Top-level objects[I],
which no package body declares, is registered under package 'ID': `. A
top-level object a body declares is a copy of that body's object and is
judged with the body only.
- **Shared reading, not a second one:** which top-level object is
residual is `isResidualTopLevelItem(bodies)`, the mirror of
`unclaimedTopLevel` that the owner-stamp gate and the single-app judge
(#33074) already read. `packages/metadata` is read, not changed.
- A package with no `namespace` is not judged (the rule's legacy skip);
the namespace/object-name clash half of `validateNamespacePrefix`
(ADR-0150 D6) is untouched.
Example finding (the residual pin): "Top-level objects[2], which no
package body declares, is registered under package 'com.example.svc':
Object 'zzz_orphan' is missing the package namespace prefix. Rename it
to 'svc_zzz_orphan' (namespace = 'svc')."
**ADR-0087.** New semantic entry
`define-stack-packages-body-namespace-prefix-refused`
(`packages/spec/src/migrations/entries/semantic/18.define-stack-packages-body-namespace-prefix-refused.ts`),
no D2 conversion (an object's name is its table and API name, only the
author renames it). The changeset registers it.
**Changeset.** `.changeset/33069-define-stack-packages-namespace.md`,
`@objectstack/spec` minor, both declaration lines, BREAKING banner with
Before / Now / Unchanged / Fix.
**No error code added**: the refusal is the existing
`STACK_NAMESPACE_PREFIX_INVALID` (422).
## Tests
New top-level describe in `packages/spec/src/stack.test.ts`
("defineStack — a packages[] stack's namespace prefixes are judged per
body, and its top level by the residual rule"), two packages of
namespaces `crm` and `svc` composed under `manifest: 'preserve'`:
1. accepts the additive artifact (the reader's shape: both bodies'
objects on the top level) under the `svc` manifest, with anti-vacuity
(`crm_account` at the top level);
2. refuses a residual top-level object no body's namespace and not the
manifest's prefixes: `code` `STACK_NAMESPACE_PREFIX_INVALID`, `status`
422, `issues` exactly the located finding; a residual the manifest's
namespace prefixes is accepted;
3. refuses a body object its own body's namespace does not prefix
(though another body's and the manifest's would), located at the body;
4. CONTROL: a stack without `packages[]` gives the exact finding and the
exact message (header, line, hint) it gave on `main`.
New top-level describe in
`packages/runtime/src/artifact-collections.public-reader.test.ts`:
`defineStack(resolveArtifactCollections(composeStacks([crm app, svc
module], { manifest: 'preserve' })))` passes, with anti-vacuity (both
objects at the top level, manifest namespace `svc`).
Measured on `origin/main` `2c98485d` (which carries #33074; the order's
`64551047` is its parent and lacks the shared residual reading) before
the fix, with a probe through the real reader: the round trip was
refused `STACK_NAMESPACE_PREFIX_INVALID` (`Object 'crm_account' is
missing the package namespace prefix … (namespace = 'svc')`);
`unclaimedTopLevel` of the same artifact answered an empty residual
(every top-level object is claimed by a body, so none is registered from
the top level); a body object `crm_stray` in the `svc` body with no
top-level copy was accepted.
<details><summary>Ablations (fix committed first at `1dbbe63d`, mutated
through `scripts/ablation-replace.mjs`, restored to the HEAD
blob)</summary>
Each mutation landed (anchor 1 → 0, blob `bf975a2fe1a7` → a new blob)
and each restore read `blob == HEAD (bf975a2) and git diff HEAD is
empty`.
| # | Mutation in `stack.zod.ts` | Expected | Observed |
|:--|:--|:--|:--|
| 1 | the residual filter dropped (every top-level object judged against
the manifest, the old reading) | additive pin red, runtime round-trip
pin red | spec: 2 failed (additive, and residual, which now also reports
`crm_account`); runtime: 1 failed (round trip) |
| 2 | body objects not judged | body pin red | 1 failed (body) |
| 3 | residual judged never | residual pin red | 1 failed (residual) |
| main | `stack.zod.ts` restored to `origin/main` `2c98485d` (blob
`f5dc7819`, checked against `git rev-parse origin/main:…`), tests
unchanged | additive, residual, body pins red; CONTROL green | spec: 3
failed, control passed (the no-`packages[]` finding and message are
byte-identical to `main`); runtime: round trip failed |
Both suites resolve `@objectstack/spec` to `src/` (`stack.test.ts`
imports `./stack.zod`; `packages/runtime/vitest.config.ts` aliases the
package to `src`), so no dist rebuild was owed per leg.
</details>
## Acceptance notes
- Delta, measured (order step 1). Newly accepted: a `packages[]` stack
whose top-level objects are copies of body objects prefixed by their own
bodies' namespaces but not by the manifest's (the reader round trip of a
multi-namespace suite). Newly refused: a `packages[]` body object its
own body's namespace does not prefix, when the stack's top level holds
no copy of it, holds a copy the manifest's namespace prefixes, or the
manifest declares no namespace. Unchanged: every stack without
`packages[]`; a residual top-level object is judged against the
manifest's namespace exactly as before, now with a locator in front of
the same sentence. A copy of a body object that the manifest's namespace
does NOT prefix but its own body's does now passes; a mis-prefixed body
object that used to be caught through its top-level copy is still
refused, located at the body instead of the top level.
- Producers: no first-party production code hands a `packages[]` stack
to strict `defineStack`. HotCRM (`4f0ffd8`, read-only) builds each
package with strict `defineStack` (all five declare `namespace: 'crm'`)
and reads the composed suite through `resolveArtifactCollections` in
`test/helpers/composed-stack.ts` without re-judging it. The consumer
suites below are the empirical half.
- The `defineStack` hint after the findings still reads "Every
object.name must be `${manifest.namespace}_${shortName}`"; on a
`packages[]` stack the namespace is the body's, which each located
finding names. Left as is so the no-`packages[]` message stays
byte-identical.
- Ruling-surface grep (`ruling|Ruling-ref|maintainer|⛔`): `stack.zod.ts`
68 hits file-wide, none inside the edited region
(`validateNamespacePrefix` and the new `namespacePrefixErrors`,
~:2540–2670); `stack.test.ts` 2 hits (~:1846, :1855, the retired `type:
page` block), untouched; `artifact-collections.public-reader.test.ts`
none. No ruling sits on the edited lines.
- ADR-0019 (governed, not edited). Its Status line's "Landed in spec"
list is its enforcement log; after this lands it could name that strict
`defineStack` judges a `packages[]` suite's namespace prefixes per
package body (D4: an app owns a set of namespaces), so a suite whose
packages declare different namespaces round-trips through
`resolveArtifactCollections`, with this PR and its merge sha. That is
the landing seat's card to file, not this PR's.
- Serial: no open PR edits `stack.zod.ts` (search of open PRs naming it:
0; the two open spec-touching PRs, #32895 and #33110, list no
`stack.zod.ts` in their files).
- Contract-review nits (record 6858193093, PASS at `da607a7f`), noted
and not pushed for:
- N1 · the declaration line lists two before-states of the newly refused
body object; a third is missing (the stack manifest declares no
namespace). The changeset's Before bullet and the delta note above cover
it.
- N2 · "its own body's namespace does not prefix" names one arm:
`validateObjectNamespacePrefix` also refuses the legacy `__` form, so a
body object such as `crm_a__b` is newly refused too. Same rule, code and
status.
- N3 · pin gaps: N1's third state, N2's arm, a namespace-less body's
copy, `packages: []`, and a multi-namespace suite with apps through the
reader are not pinned. Pin 2's "refuses" half does not discriminate by
verdict (the old rule refuses that stack too).
- N4 · `namespacePrefixErrors` re-spells the two-line `entry.manifest`
walk the clash half repeats, and labels packages through
`singleAppPackageLabel`, a helper named for the other rule.
- N5 · on a body finding the hint still reads "Every object.name must be
`${manifest.namespace}_${shortName}`" while the body's namespace is the
one judged; left so the no-`packages[]` message stays byte-identical
(the hint note above).
## Verification
Readings at head `da607a7f` (after merging `origin/main` `e997113c`:
#33110, #33080, #33078, none on this diff's files) unless named, after
`pnpm install --frozen-lockfile` and `pnpm --workspace-concurrency=2
--filter '@objectstack/dogfood^...' --filter @objectstack/cli build`,
every heavy command under `scripts/pm/os-verify-lock.sh` (VERDICT
command-exit 0 on each unless named), exit codes captured before any
pipe:
- `pnpm --filter @objectstack/spec check:generated`: all 14 generated
artefacts up to date. (At `1dbbe63d` it named one
`test-typecheck-debt.json` arrival, a TS2488 on the new body pin's
spread; fixed in `6112dbb9`, not ledgered.)
- `pnpm --filter @objectstack/spec test`: Test Files 840 passed (840),
Tests 26832 passed, 1 todo. `typecheck` (at `6112dbb9`): exit 0.
- Consumers of the changed schema door (run by hand; `dispatch-gates`
does not derive them), at `6112dbb9`, the merge touching none of their
sources:
- `@objectstack/metadata` test (the `unclaimedTopLevel` load path): Test
Files 76 passed (76), Tests 2204 passed.
- `@objectstack/metadata-protocol` test: Test Files 337 passed, 7
skipped (344); Tests 22799 passed, 36 skipped.
- `@objectstack/core` test: Test Files 146 passed (146), Tests 3369
passed.
- `@objectstack/cli` unit (`vitest run --project unit`): Test Files 414
passed of 416; the other two (`published-subpath-console.pin`,
`published-subpath-hook-body.pin`) refused for an unbuilt
`packages/cli/dist` (PREREQUISITE, the pins' own guard), and after
building the cli they passed at `da607a7f` (2 files, 29 tests). The
integration layer is CI's (no spawn entry or integration file in the
diff).
- `@objectstack/runtime` `artifact-collections.test.ts` +
`artifact-collections.public-reader.test.ts`: Test Files 2 passed (2),
Tests 26 passed; runtime `typecheck`: exit 0.
- Full dogfood battery (`Clause-②` carries a `(narrowing)` arm): `pnpm
--filter @objectstack/dogfood test` at `da607a7f`, lock VERDICT
command-exit 0, Test Files 460 passed, 3 skipped (463); Tests 3874
passed, 42 skipped (3916); no failure (finished after this PR opened;
also in the os-dev report, comment 6857790505).
- Derived gates: `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` → 91 families (same list at `6112dbb9` and
`da607a7f`), each run with stdin from /dev/null. 85 exited 0 on the
first pass; six read built output while a closure build was rewriting it
(`check:api-surface`, `check:dual-source-exports`,
`check:entry-nameability`, `check:exported-any` exit 3 PREREQUISITE;
`check:dts-closure` exit 1 naming two packages mid-build;
`check:dual-build-cjs-loads` exit 3) and all six exited 0 when rerun
after the build settled. `node scripts/check-plugin-teardown-shape.mjs
--self-test` exit 0 after `git fetch origin
621a487 --depth=1`. Reconciliation
`--ran` with exit codes: `91 derived famil(ies) accounted for — 91 run,
0 NOT-MEASURED (a DERIVED zero — all 91 recorded an exit code and none
of them is 3)`.
- CI: not yet run at opening; the contract review (6858193093) read 52
success, 11 skipped, 3 Test Core shards in progress, no failure at
15:59Z.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibxbMr8S6rSezDVowtd)_
<!-- signed: domain:spec#2 · os-tesla · session_01L9qibxbMr8S6rSezDVowtd
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 5c005e0 commit 5b2ec82
5 files changed
Lines changed: 224 additions & 10 deletions
File tree
- .changeset
- packages
- runtime/src
- spec/src
- migrations/entries/semantic
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1813 | 1813 | | |
1814 | 1814 | | |
1815 | 1815 | | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
1816 | 1893 | | |
1817 | 1894 | | |
1818 | 1895 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2541 | 2541 | | |
2542 | 2542 | | |
2543 | 2543 | | |
| 2544 | + | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
2544 | 2550 | | |
2545 | 2551 | | |
2546 | 2552 | | |
| |||
2556 | 2562 | | |
2557 | 2563 | | |
2558 | 2564 | | |
2559 | | - | |
2560 | | - | |
2561 | | - | |
2562 | | - | |
2563 | | - | |
2564 | | - | |
2565 | | - | |
2566 | | - | |
2567 | | - | |
2568 | | - | |
| 2565 | + | |
2569 | 2566 | | |
2570 | 2567 | | |
2571 | 2568 | | |
| |||
2599 | 2596 | | |
2600 | 2597 | | |
2601 | 2598 | | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
| 2625 | + | |
| 2626 | + | |
| 2627 | + | |
| 2628 | + | |
| 2629 | + | |
| 2630 | + | |
| 2631 | + | |
| 2632 | + | |
| 2633 | + | |
| 2634 | + | |
| 2635 | + | |
| 2636 | + | |
| 2637 | + | |
| 2638 | + | |
| 2639 | + | |
| 2640 | + | |
| 2641 | + | |
| 2642 | + | |
| 2643 | + | |
| 2644 | + | |
| 2645 | + | |
| 2646 | + | |
| 2647 | + | |
| 2648 | + | |
| 2649 | + | |
| 2650 | + | |
| 2651 | + | |
| 2652 | + | |
| 2653 | + | |
| 2654 | + | |
| 2655 | + | |
| 2656 | + | |
| 2657 | + | |
| 2658 | + | |
2602 | 2659 | | |
2603 | 2660 | | |
2604 | 2661 | | |
| |||
0 commit comments