Repository navigation
Commit 2c98485
feat(spec)!: strict defineStack judges a packages[] stack per body and counts only the top-level apps no body declares against its manifest (#33074)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoWK5rFW1SUGSkDw9iatZE4f)_
Fixes #32978
Clause-②: yes (narrowing) — one face narrows and one widens. Narrowed: a
stack carrying `packages[]` whose top level holds an app that no package
body declares, beside an app of the package body with the manifest's id
(or two such apps), is refused by strict `defineStack`, where it was
accepted. Widened: a stack carrying `packages[]` whose top level repeats
apps that different package bodies declare (an additive artifact, such
as `resolveArtifactCollections` output) is accepted, where it was
refused.
Metadata-protocol: narrowed
Skills-docs: none — the taught rule (at most one app per package;
compose a suite with `composeStacks(stacks, { manifest: 'preserve' })`)
is unchanged, and no skill or docs page teaches handing a `packages[]`
stack to `defineStack`; what moves is which top-level apps strict
`defineStack` counts on such a stack. The single-app teaching follow-up
of #32898 is #32977.
## 维护者速读
- 改了什么:严格模式 `defineStack` 判带 `packages[]` 的栈时,改用 `composeStacks`
已有的同一个判法(同一份实现,两道门共用):每个包体按自己的类型和应用判;只有「没有包体声明的顶层应用」才和 manifest id
那个包体自己的应用一起算到栈的 manifest 下,与加载路径的残余规则一致。
- 为什么改:#32898 让 `composeStacks` 按加载路径的读法判,`defineStack` 还是把全部顶层应用都算到栈自己的
manifest 下,两道门对同一形状判法不同:把 `resolveArtifactCollections` 的输出交回
`defineStack` 会被误拒;手搭一个多出一个未声明顶层应用的栈却会通过,启动时变成一个包两个应用。
- 风险与回滚:一收一放(`Clause-②: yes (narrowing)`)。实测本仓与 HotCRM 没有任何产品代码把带
`packages[]` 的栈交给严格 `defineStack`(HotCRM 是每包 `defineStack` 后
`composeStacks` preserve)。不带 `packages[]` 的栈判法不变。回滚即 revert。
- 先看:`packages/spec/src/stack.zod.ts` 的 `validateSingleApp`(新分支)与
`residualSingleAppFinding`(抽成两门共用、按门传入残余应用的来源与改法);`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 "judged per body"`,预期 4 条全绿,其中一条是「手搭栈的未声明顶层应用与
manifest id 包体的应用一起被拒(422 `STACK_SINGLE_APP_VIOLATION`)」。
- 需要你做的:无,席位落地。
## What changes
**One judge for both doors.** `residualSingleAppFinding`
(`packages/spec/src/stack.zod.ts`), added by #32898 for `composeStacks`,
is now shared. It reads a `packages[]` stack the way the load path
registers it: the apps of the body whose id is the manifest's, plus
every top-level app no body declares (the residual rule,
`unclaimedTopLevel` in `@objectstack/metadata`, mirrored by the existing
`isResidualTopLevelItem`; `packages/metadata` is read, not changed). Two
or more of them, at least one residual, are refused. A
`ResidualSingleAppDoor` argument carries only what differs per door: the
finding's subject, where each residual app came from, and the remedy.
The `composeStacks` finding is byte-identical to before (its pins are
unchanged and green).
**`validateSingleApp`** (the strict `defineStack` pass):
- **No `packages[]`:** unchanged. Every app counts against the stack's
own package.
- **`packages[]`** with an `app` or `module` manifest: the top level
goes through the shared judge, the residual apps named as `'NAME' at its
top level (apps[i]), which no package body declares`; every body is
still judged by `collectPackageBodySingleAppErrors` as before.
Example finding: "A 'module' package must define at most one app, but
the stack gives package 'com.example.crm.service' 2 ('crm_service' from
its package body (packages[1]), 'crm_field_service' at its top level
(apps[0]), which no package body declares): an app that no package body
declares is registered under the artifact's manifest id, beside the apps
of that package's own body. Keep one app per package: declare each such
app inside the package body it belongs to, or give it a 'module' package
of its own and compose with composeStacks(stacks, { manifest: 'preserve'
}), which registers each package body under its own id — ADR-0019
(app-as-consumer-unit) D3 as amended (a suite may surface several apps,
one per package)."
**Docblocks.** `validateSingleApp`'s docblock no longer says
`composeStacks` judges by "the same rule" loosely: it states the two
readings (no `packages[]` / `packages[]`) and that `composeStacks`
shares the residual judge. `StackSingleAppViolationError`'s
`defineStack` raise-site line and `collectComposedSingleAppErrors`'s
docblock say the same.
**ADR-0087.** New semantic entry
`define-stack-packages-residual-second-app-refused`
(`packages/spec/src/migrations/entries/semantic/18.define-stack-packages-residual-second-app-refused.ts`),
no D2 conversion (which package an app belongs to is the author's call).
The changeset registers it.
**Changeset.** `.changeset/32978-define-stack-packages-single-app.md`,
`@objectstack/spec` minor, both declaration lines, BREAKING banner with
Before / Now / Unchanged / Fix.
**No error code added**: the refusal is the existing
`STACK_SINGLE_APP_VIOLATION` (422).
## Tests
New top-level describe in `packages/spec/src/stack.test.ts`
("defineStack — a packages[] stack is judged per body, and its top level
by the residual rule composeStacks reads"):
1. accepts an additive artifact whose top level repeats the apps two
bodies declare (the reader's shape), under a `module` manifest;
2. refuses a hand-built stack (a preserve artifact plus one undeclared
top-level app): `code` `STACK_SINGLE_APP_VIOLATION`, `status` 422, the
`defineStack` header, the package, both apps with where each sits;
3. one residual app is accepted when the manifest id's body declares
none, two are refused;
4. CONTROL: a stack without `packages[]` is judged unchanged (two apps
refused naming the package, one accepted).
New top-level describe in
`packages/runtime/src/artifact-collections.public-reader.test.ts` (file
surface amended by the seat, comment 6846967975):
`defineStack(resolveArtifactCollections(composeStacks([app, module], {
manifest: 'preserve' })))` passes, with anti-vacuity (two top-level apps
under a `module` manifest). The packages share one namespace so the
namespace-prefix rule is not what answers (see #33069).
Both arms were reproduced on `origin/main` `157051ce` before the fix
with a built probe: the reader round trip was refused
`STACK_SINGLE_APP_VIOLATION` 422, and the hand-built stack was accepted.
<details><summary>Ablations (each committed first, mutated through
`scripts/ablation-replace.mjs`, restored to the HEAD blob)</summary>
Taken at `f649a494` (pre-merge head; the merge of `origin/main` touched
no line these mutate). Each mutation landed (anchor 1 → 0, blob changed)
and each restore read `blob == HEAD (6d75946) and git diff HEAD is
empty`.
| # | Mutation in `stack.zod.ts` | Expected | Observed |
|:--|:--|:--|:--|
| 1 | `validateSingleApp` back to the old reading (`const own = true
\|\| !Array.isArray(config.packages)`) | additive, hand-built and
one/two-residual pins red; control green | 3 failed, control passed |
| 2 | residual predicate ignored in the `defineStack` door (every
top-level app residual) | additive pin red | 1 failed (additive) |
| 3 | shared judge stops counting the manifest-id body's apps |
hand-built pin red | 1 failed (hand-built) |
| 4 | the no-`packages[]` branch judges nothing | control red | 1 failed
(control) |
| 5 | as 1, read by the runtime round-trip pin
(`artifact-collections.public-reader.test.ts`) | round-trip red | 1
failed, 2 passed |
The runtime suite resolves `@objectstack/spec` to `src/`
(`packages/runtime/vitest.config.ts` alias), and so does `stack.test.ts`
(`./stack.zod`), so no dist rebuild was owed per leg.
</details>
## Acceptance notes
- Measurement (order step 1): no first-party production code hands a
`packages[]` stack to strict `defineStack`. In-repo `defineStack(` call
sites on a stack value are tests (all `strict: false` or per-package
inputs) and authored configs without `packages[]`; HotCRM (`0009f58`,
read-only) builds each package with `defineStack` and composes with
`composeStacks(packageStacks, { manifest: 'preserve' })`, never
re-judging the artifact. The consumer suites below are the empirical
half.
- Out of scope, filed by the seat as #33069: with packages of different
namespaces (the usual case), the same reader round trip is refused
earlier by `STACK_NAMESPACE_PREFIX_INVALID`, because
`validateNamespacePrefix` judges the merged top-level copies of body
objects against the stack manifest's namespace. Not touched here.
- Ruling-surface grep (`ruling|Ruling-ref|maintainer|⛔`) over
`stack.zod.ts`: 68 hits file-wide, one inside the edited regions (the
`validateUnmanagedInstallMode` docblock, untouched). No ruling sits on
the edited lines.
- Contract-review nits (record 6848214183), noted and not pushed for:
- N1 · the "(or two such apps)" clause of the declaration line and the
entry `surface`'s "or two or more such apps" name no newly refused
shape: two undeclared top-level apps were already refused before this
change, with the same code and status. Over-inclusive, in the safe
direction.
- N2 · a `packages[]` stack that was already refused (two undeclared
top-level apps, or `packages: []` with two apps) now reads the residual
sentence instead of "package 'X' defines N …", and on that path an `app`
manifest loses the "fold them into one app" remedy. Code, status and
header are unchanged; the changeset does not mention the rewording.
- N3 · the "refuses two" half of the one/two-residual pin does not
discriminate by verdict (the old rule refuses it too; only its wording
assertion turns red). No pin covers copies of other bodies' apps beside
one residual app, or a manifest-id body of an unjudged type.
- N4 · the changeset's Widened line names `resolveArtifactCollections`
output as accepted without the #33069 limit (differently-namespaced
packages are still refused earlier, by the namespace-prefix rule). This
body states the limit.
- N5 · `residualSingleAppFinding`'s docblock says `door` "only names"
the residual apps, but `door.residual` also enumerates them, so the
count comes from the door. The two doors agree today; a third could
differ.
- Serial: PR #33008 (`renamedFrom`) edits another region of
`stack.zod.ts`; this PR touches `validateSingleApp` (~:2690–2760), the
`StackSingleAppViolationError` docblock (~:3825) and
`collectComposedSingleAppErrors` / `residualSingleAppFinding`
(~:8836–8990).
## Verification
Readings at head `0d2b8278` (after merging `origin/main` `12b14462`,
which brought #33008), after `pnpm install --frozen-lockfile` and `pnpm
turbo run build --concurrency=2 --filter='./packages/**'
--filter='@objectstack/dogfood^...'` (81/81 tasks), every heavy command
under `scripts/pm/os-verify-lock.sh` (VERDICT command-exit 0 on each),
exit codes captured before any pipe:
- `pnpm --filter @objectstack/spec check:generated`: all 14 generated
artefacts up to date; tree clean.
- `pnpm --filter @objectstack/spec test`: Test Files 840 passed (840),
Tests 26827 passed, 1 todo. `typecheck`: exit 0.
- Consumers of the changed schema door (run by hand; `dispatch-gates`
does not derive them):
- `@objectstack/runtime` test: Test Files 596 passed (596), Tests 10562
passed, 19 skipped; `typecheck` exit 0.
- `@objectstack/metadata` test (the `unclaimedTopLevel` load path): Test
Files 76 passed (76), Tests 2178 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 3368
passed.
- `@objectstack/lint` test: Test Files 202 passed (202), Tests 8610
passed.
- `@objectstack/cli` unit (`vitest run --project unit`): Test Files 416
passed (416), Tests 5933 passed. The integration layer is CI's (no spawn
entry or integration file in the diff).
- Full dogfood battery (`Clause-②` carries a `(narrowing)` arm): `pnpm
--filter @objectstack/dogfood test` at `0d2b8278`, lock VERDICT
command-exit 0, Test Files 458 passed, 3 skipped (461); Tests 3844
passed, 42 skipped; no failure.
- Derived gates: `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` → 91 families, each run with `</dev/null`.
90 exited 0 on the first pass; `node
scripts/check-plugin-teardown-shape.mjs --self-test` exited 3
(PREREQUISITE: its pinned fixture commit `621a4876` was outside the
shallow clone), and after `git fetch origin
621a487 --depth=1` it exited 0 (48
cases). Reconciliation `--ran`: `91 derived famil(ies) accounted for —
91 run, 0 NOT-MEASURED`.
- CI at `0d2b8278`: 67 check-runs, all `success` or `skipped`, none
failed or pending (the eleven required contexts that ran on the PR: Lint
& Repo Gates, TypeScript Type Check, Test Core, Build Core, Governed
Surface Queue Guard, Test UI, Build & E2E UI, Type Check UI, Live E2E
UI, Dogfood Regression Gate success; Lint UI skipped by its path
filter). Check Changeset success.
- Contract review: record 6848214183, `CONTRACT_REVIEW_TIER`, head
`0d2b8278`, **PASS**, no must-fix or should-fix.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibyebbesu5rXZGhyF6z)_
<!-- signed: domain:spec#2 · os-tesla · session_01L9qibyebbesu5rXZGhyF6z
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent 6455104 commit 2c98485
5 files changed
Lines changed: 270 additions & 40 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 | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 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 | + | |
| 36 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1723 | 1723 | | |
1724 | 1724 | | |
1725 | 1725 | | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
1726 | 1816 | | |
1727 | 1817 | | |
1728 | 1818 | | |
| |||
0 commit comments