Skip to content

Commit 2c98485

Browse files
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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@objectstack/spec': minor
3+
---
4+
5+
feat(spec)!: strict `defineStack` judges a stack that carries `packages[]` per package body, and counts against its manifest id only the top-level apps no body declares, the reading `composeStacks` and the load path use (ADR-0019 D3 as amended)
6+
7+
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, 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.
8+
Metadata-protocol: narrowed
9+
10+
<!-- adr-0087: registered define-stack-packages-residual-second-app-refused -->
11+
12+
**BREAKING** accept-set narrowing in strict `defineStack` (`@objectstack/spec`, the root export), for a stack that carries `packages[]` and a manifest of type `app` or `module`.
13+
14+
- **Before.** Strict `defineStack` counted every top-level app of such a stack against the stack's own manifest. The load path registers each package body under its own id, and only the top-level apps that no body declares under the manifest id (the residual rule, `unclaimedTopLevel` in `@objectstack/metadata`). So `defineStack` accepted a hand-built stack whose undeclared top-level app the boot then registered beside the manifest-id body's own app (two apps under one package), and refused an additive artifact whose top level only repeats the apps its bodies declare.
15+
- **Now.** `defineStack` reads such a stack through the judge `composeStacks` uses for its result: each body by its own type, id and apps, and the manifest id with the apps of its own body plus every top-level app no body declares. Two or more there are refused with `STACK_SINGLE_APP_VIOLATION` (422), header `defineStack single-app validation failed`, one finding naming the package, each app with where it sits, and the remedy. A top-level app a body declares counts against that body only, so the additive artifact is accepted (`resolveArtifactCollections(composeStacks(stacks, { manifest: 'preserve' }))` handed back to `defineStack` passes the single-app rule).
16+
- **Unchanged.** A stack without `packages[]` (every authored package): every app it carries still counts against its own manifest. Package types other than `app` and `module`, and `defineStack(…, { strict: false })`, are not judged.
17+
- **Fix.** Declare each top-level app inside the package body it belongs to, or give it a `type: 'module'` package of its own and compose with `composeStacks(stacks, { manifest: 'preserve' })`.

‎packages/runtime/src/artifact-collections.public-reader.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,38 @@ describe('resolveArtifactCollections — the public reader of a composed suite (
110110
expect(read.apps.map((a) => a.name).sort()).toEqual(['sales_app', 'service_app', 'suite_app']);
111111
});
112112
});
113+
114+
describe('resolveArtifactCollections — its output handed back to strict defineStack passes the single-app rule (ADR-0019 D3 as amended)', () => {
115+
// The reader's output is an additive artifact: every body's apps merged
116+
// onto the top level beside `packages[]`. Each of those apps is declared by
117+
// a body, so the load path registers it under that body's id, and strict
118+
// `defineStack` counts it there too, not against the artifact's manifest.
119+
// The packages share one namespace so that no other `defineStack` rule
120+
// (the namespace prefix of the merged objects) is what answers.
121+
const strictPackage = (id: string, type: 'app' | 'module', slug: string) =>
122+
defineStack({
123+
manifest: { id, name: slug, version: '1.0.0', type, namespace: 'crm' },
124+
objects: [{ name: `crm_${slug}`, label: slug, fields: { title: { type: 'text', label: 'Title' } } }],
125+
apps: [{
126+
name: `crm_${slug}_app`,
127+
label: `${slug} app`,
128+
navigation: [{ id: `nav_${slug}`, type: 'object', label: slug, objectName: `crm_${slug}` }],
129+
}],
130+
} as never);
131+
132+
it('accepts the reader\'s output of a preserve suite with one app per package', () => {
133+
const preserved = composeStacks(
134+
[strictPackage('com.example.crm', 'app', 'sales'), strictPackage('com.example.crm.service', 'module', 'service')],
135+
{ manifest: 'preserve' },
136+
);
137+
const read = resolveArtifactCollections(preserved) as Raw & { manifest?: { type?: string } };
138+
139+
// Anti-vacuity: two apps at the top level, under a `module` manifest
140+
// the single-app rule judges.
141+
expect(((read.apps as Array<{ name: string }>) ?? []).map((a) => a.name)).toEqual(['crm_sales_app', 'crm_service_app']);
142+
expect(read.manifest?.type).toBe('module');
143+
expect(Array.isArray(read.packages)).toBe(true);
144+
145+
expect(() => defineStack(read as never)).not.toThrow();
146+
});
147+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
import type { SemanticMigration } from '../../types.js';
4+
5+
// An accept-set narrowing of strict defineStack on a stack that carries
6+
// packages[]: its top level is judged the way the load path registers it, so
7+
// a top-level app no body declares counts against the manifest id beside that
8+
// id's own body's app (ADR-0019 D3 as amended). No D2 conversion: which
9+
// package an app belongs to is the author's call.
10+
export const entry: SemanticMigration = {
11+
id: 'define-stack-packages-residual-second-app-refused',
12+
surface:
13+
'defineStack(stack) (strict, the default) on a stack that carries packages[] and a manifest of type '
14+
+ '\'app\' or \'module\', whose top level holds an app that no package body declares while the package body '
15+
+ 'with the manifest\'s id already defines one, or two or more such apps, e.g. a composeStacks(stacks, '
16+
+ '{ manifest: \'preserve\' }) result handed back to defineStack with an extra app added at its top level',
17+
replacement:
18+
'Declare the app inside the package body it belongs to, or give it a \'module\' package of its own and '
19+
+ 'compose with composeStacks(stacks, { manifest: \'preserve\' }), which registers each package body under its '
20+
+ 'own id. A top-level app that a package body declares (an additive artifact\'s merged copy, such as the '
21+
+ 'output of resolveArtifactCollections from @objectstack/runtime) counts against that body only and is now '
22+
+ 'accepted. A stack without packages[] is judged as before.',
23+
reason:
24+
'The load path registers each packages[] body under its own id, and a top-level app that no body declares '
25+
+ 'under the stack\'s manifest id (the residual rule, unclaimedTopLevel in @objectstack/metadata). Strict '
26+
+ 'defineStack counted every top-level app against the manifest instead, so it accepted a hand-built stack '
27+
+ 'whose undeclared app the boot then registered as a second app of one app or module package, the shape '
28+
+ 'ADR-0019 (app-as-consumer-unit) D3 as amended removes, and it refused an additive artifact whose top level '
29+
+ 'only repeats apps its bodies declare. defineStack now reads a packages[] stack through the judge '
30+
+ 'composeStacks uses for its result and refuses the first shape with STACK_SINGLE_APP_VIOLATION (422). Not '
31+
+ 'convertible: which package an app belongs to is a fact only the author holds.',
32+
acceptanceCriteria:
33+
'os validate and os build, and every config or test helper that calls defineStack on a packages[] stack, run '
34+
+ 'without a STACK_SINGLE_APP_VIOLATION finding. Then boot the artifact and confirm each app opens from the '
35+
+ 'Console under its own package id.',
36+
};

‎packages/spec/src/stack.test.ts‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,96 @@ describe('composeStacks — at most one App per package, judged on what the comp
17231723
});
17241724
});
17251725

1726+
describe('defineStack — a packages[] stack is judged per body, and its top level by the residual rule composeStacks reads (ADR-0019 D3 as amended)', () => {
1727+
// The load path registers each body under its own id, and a top-level app
1728+
// that no body declares under the stack's manifest id (`unclaimedTopLevel`,
1729+
// `@objectstack/metadata`). Strict `defineStack` reads a `packages[]` stack
1730+
// the same way, through the judge `composeStacks` uses for its result.
1731+
const objectOf = (name: string) => ({ name, label: name, fields: { title: { type: 'text' as const } } });
1732+
const appOf = (name: string, objectName: string) => ({
1733+
name,
1734+
label: name,
1735+
navigation: [{ id: `nav_${objectName}`, type: 'object' as const, label: objectName, objectName }],
1736+
});
1737+
const pkg = (id: string, type: 'app' | 'module') => ({ id, version: '1.0.0', type, name: id, namespace: 'crm' });
1738+
const sales = () => defineStack({
1739+
manifest: pkg('com.example.crm', 'app'),
1740+
objects: [objectOf('crm_account')],
1741+
apps: [appOf('crm_sales', 'crm_account')],
1742+
});
1743+
const service = () => defineStack({
1744+
manifest: pkg('com.example.crm.service', 'module'),
1745+
objects: [objectOf('crm_case')],
1746+
apps: [appOf('crm_service', 'crm_case')],
1747+
});
1748+
/** A suite artifact: two bodies with one app each, under the service package's manifest. */
1749+
const suite = () => composeStacks([sales(), service()], { manifest: 'preserve' });
1750+
1751+
type Refusal = { code?: string; status?: number; issues?: readonly string[]; message: string };
1752+
const refusalOf = (stack: unknown): Refusal | null => {
1753+
try {
1754+
defineStack(stack as never);
1755+
return null;
1756+
} catch (e) {
1757+
return e as Refusal;
1758+
}
1759+
};
1760+
1761+
it('accepts an additive artifact whose top level repeats the apps two different bodies declare: each registers under its own body\'s id', () => {
1762+
const artifact = suite();
1763+
// The shape `resolveArtifactCollections` (`@objectstack/runtime`) returns:
1764+
// every body's collections merged onto the top level beside `packages[]`.
1765+
const additive = {
1766+
...artifact,
1767+
objects: [objectOf('crm_account'), objectOf('crm_case')],
1768+
apps: [appOf('crm_sales', 'crm_account'), appOf('crm_service', 'crm_case')],
1769+
};
1770+
expect(additive.manifest?.type).toBe('module');
1771+
expect(refusalOf(additive)).toBeNull();
1772+
});
1773+
1774+
it('refuses a hand-built stack whose top-level app no body declares, which the load path registers under the manifest id beside that id\'s own body\'s app', () => {
1775+
const handBuilt = { ...suite(), apps: [appOf('crm_field_service', 'crm_case')] };
1776+
const r = refusalOf(handBuilt);
1777+
expect(r, 'refused').not.toBeNull();
1778+
expect(r!.code).toBe('STACK_SINGLE_APP_VIOLATION');
1779+
expect(r!.status).toBe(422);
1780+
expect(r!.issues).toHaveLength(1);
1781+
expect(r!.message.startsWith('defineStack single-app validation failed (1 issue):')).toBe(true);
1782+
const finding = r!.issues![0];
1783+
expect(finding).toMatch(/^A 'module' package must define at most one app/);
1784+
expect(finding).toContain("package 'com.example.crm.service' 2");
1785+
expect(finding).toContain("'crm_service' from its package body (packages[1])");
1786+
expect(finding).toContain("'crm_field_service' at its top level (apps[0]), which no package body declares");
1787+
expect(finding).not.toContain("'crm_sales'");
1788+
});
1789+
1790+
it('accepts one residual app when the manifest id\'s own body declares none, and refuses two', () => {
1791+
const revenue = defineStack({ manifest: pkg('com.example.crm.revenue', 'module'), objects: [objectOf('crm_quote')] });
1792+
const artifact = composeStacks([sales(), revenue], { manifest: 'preserve' });
1793+
expect(refusalOf({ ...artifact, apps: [appOf('crm_quotes', 'crm_quote')] })).toBeNull();
1794+
const r = refusalOf({ ...artifact, apps: [appOf('crm_quotes', 'crm_quote'), appOf('crm_pricing', 'crm_quote')] });
1795+
expect(r?.code).toBe('STACK_SINGLE_APP_VIOLATION');
1796+
expect(r?.status).toBe(422);
1797+
expect(r?.issues?.[0]).toContain("package 'com.example.crm.revenue' 2");
1798+
});
1799+
1800+
it('control: a stack without packages[] counts every app against its own package, unchanged', () => {
1801+
const flat = {
1802+
manifest: pkg('com.example.crm.service', 'module'),
1803+
objects: [objectOf('crm_case')],
1804+
apps: [appOf('crm_service', 'crm_case'), appOf('crm_field_service', 'crm_case')],
1805+
};
1806+
const r = refusalOf(flat);
1807+
expect(r?.code).toBe('STACK_SINGLE_APP_VIOLATION');
1808+
expect(r?.status).toBe(422);
1809+
expect(r?.issues).toEqual([
1810+
expect.stringContaining("package 'com.example.crm.service' defines 2 ('crm_service', 'crm_field_service')"),
1811+
]);
1812+
expect(refusalOf({ ...flat, apps: [appOf('crm_service', 'crm_case')] })).toBeNull();
1813+
});
1814+
});
1815+
17261816
// ── ADR-0087 D2 conversion notices reach the author ─────────────────────────
17271817
//
17281818
// Moved to `stack-conversion-notices.test.ts` with #23543 F5-http: the block

0 commit comments

Comments
 (0)