Skip to content

Commit 39fafc0

Browse files
fix(spec)!: a book audience names one gate, and a gated book claims its pages by name (#37870)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuKG2Z9TG76Xqkusa81b3qqz)_ Fixes #37613 Clause-②: yes (narrowing) Metadata-protocol: narrowed Skills-docs: none — no `skills/` page teaches the book audience forms; `content/docs/ui/doc-pages.mdx` documents both refusals in this change DELIBERATE CORRECTION: `.changeset/36029-book-audience-system-permission.md` (pending, from #37591). Its sentence "an object that also carries `permissionSet` still parses as the older, non-strict `{ permissionSet }` arm with the other key dropped, as before." is false after this PR and now reads "and an object that also carries `permissionSet` is refused too: an audience names one gate." `Check Changeset` is red on this by design until the seat's record confirms it. ## 维护者速读 - 手册(book)的可见范围以后只能写一种门槛:同时写了「某个权限集」和「某项系统权限」会被直接拒绝,并告诉作者留哪一个。以前这种写法会悄悄只按权限集放行,作者以为是按系统权限。 - 设了可见范围的手册,如果用 `include: '*'` 把所有文档都揽进来,`os validate` / `os build` / `os lint` 和 Studio、REST、MCP 保存时都会报错,因为它会把不属于任何包的文档也藏起来。 - Setup 和 Studio 两个包各加了一个测试:它们注册的每篇文档都必须被自己的手册认领;文档名换了前缀、或手册改回 `'*'`,测试就会变红。 - 这是收严(narrowing),走 Tier H。存量数据不改写、开机也不拒;只有下次保存这类手册时才报错。仓库和 hotcrm 里没有一处这样写。 ## What changes - **`@objectstack/spec` — an audience names one gate.** `BookAudienceSchema`'s `{ permissionSet }` arm now declares `systemPermission` only to refuse it (`z.never`, message `BOOK_AUDIENCE_ONE_GATE`), and the `{ systemPermission }` arm moves from `.strict()` to `strictObject` with a `guidance` entry for `permissionSet`, so the union's chosen branch prints the same prescription. Rendered by `defineStack`: ```text ✗ books.0.audience: Unrecognized key(s) on this book audience: `permissionSet`. • A book audience names ONE gate, and this one names two: `permissionSet` and `systemPermission`. Keep `systemPermission` when the readers are everyone who holds a capability through any permission set (…); keep `permissionSet` when the readers are the holders of that one set. Delete the other key. … ``` Only the second gate key is refused: `{ permissionSet, label }` still parses to `{ permissionSet }` exactly as before, and `{ systemPermission, label }` is still refused as before. Regenerated: `content/docs/references/system/book.mdx`. New upgrade-guide entry `book-audience-two-gates-and-catch-all-claim-refused` (ADR-0087 D3, notice only). - **`@objectstack/lint` — `book-gated-catch-all-include` (error).** `validateBookAudienceClaims` refuses a book whose `audience` is `{ permissionSet }` or `{ systemPermission }` with a group whose `include` is the catch-all (a glob of `*` alone: `'*'`, `'**'`). Namespace globs, tag includes and pinned `pages` pass; `'org'` / `'public'` / no audience are out of scope. Registered `gating` on all three commands and on the runtime publish gate for `book` writes. - **`@objectstack/setup`, `@objectstack/studio` — N4.** Each package gets `src/manual-claims-docs.test.ts`: it calls the plugin's own `start()` with a capturing manifest service, so it reads the docs and the book the package really registers, and resolves them with the spec's `resolveDocAudiences`. Every registered doc must carry exactly the manual's audience, and a control doc bound to no package must stay `org`. Wiring that came with it: a `test` script, `**/*.test.ts` dropped from `tsconfig.json`'s `exclude` so `typecheck` reads the tests (`check:type-check-coverage`), and a `vitest.config.ts` aliasing `@objectstack/spec/system` and `@objectstack/platform-objects/apps` to source (`check:test-source-alias`). - **`packages/spec/liveness/book.json` — N5.** `name` goes back to `2026-09-27` (its evidence did not change in #37591); `audience` moves to `2026-11-27`, re-closed here against both refusals. - **Docs.** `content/docs/ui/doc-pages.mdx` names both refusals where it already teaches the forms. Decided in the thread (small, listed per the standing rule): - **Route for item 1: the schema, not a lint rule.** Measured: `defineStack` parses a book at definition time, and `{ permissionSet: 'xy_admin', systemPermission: 'setup.access' }` comes out as `{ permissionSet: 'xy_admin' }` (probe against the built `dist` of `main` @ `adb65d16`). So for a TS config, the documented authoring path, every authoring rule receives the value with the key already gone, whatever its input tier (`authoring-rules.ts` § "What `normalized` does NOT buy" says the same). Only the runtime save door hands the rules the authored body. A lint rule would therefore miss the main path; the parse refusal reaches `defineStack`, `os validate` and the `/meta` save alike. - **Narrow refusal, not a strict `{ permissionSet }` arm.** A strict arm refuses every stray key, and a stored book row is kept verbatim (`protocol-save.ts`: "Every other type keeps its body verbatim"), so nothing proves no stored `{ permissionSet }` audience carries some other stray key. The narrow form refuses only the pair the card names. The pair cannot have been meaningful in any stable release: `{ systemPermission }` first shipped in `19.0.0-next.0` (2026-11-26T19:13Z, after #37591 merged at 18:15Z); `latest` is `18.6.0`. A repo and hotcrm grep finds no audience with both keys (hotcrm's one gated book is `{ permissionSet }` claiming `crm_admin_*`). - **What a stored two-gate row does after this lands** (source read, not measured): the docs gate lists stored books without re-parsing them, and `audienceAllows` reads `permissionSet` first, so such a row keeps the set gate it has today. The read-time diagnostics pass (`metadata-diagnostics.ts`) parses with the same schema, so Studio shows it as invalid; its next save is refused with the fix named. - The catch-all rule is `gating` (error) and also runs at the runtime publish door, because a Studio, REST or MCP author of a book has no other door. - The refusing key appears in the generated JSON schema as `"systemPermission": { "not": {} }` on the set arm, the same shape every `retiredKey` tombstone already emits (this schema's own `groups[].translations` among them). ## Why Card #37613, three review follow-ups of #37591 / #37663: an audience written with both keys was accepted and silently gated on the set alone (an admin manual opening to a different group than its author meant); the authoring rule "a gated book never claims by `include: '*'`" was taught by the ADR-0046 §6.7 amendment and enforced nowhere; and nothing held the Setup and Studio docs to their manuals' name prefix. ## Tests Local runs on head `8143254075`. The two later heads are docs only: the `book-gated-catch-all-include` row in `validating-metadata.mdx`, and the author-time rule count `83` → `84` in the four CLI transcripts (`check:docs-transcript-drift` green locally). CI on head `b9998850`: every check green except **Check Changeset**, the DELIBERATE CORRECTION declared above. Test Core (4/10) failed once on a driver-sql timeout outside this diff (PR comment 7213999688) and passed on re-run. - `packages/spec` `src/system src/migrations src/shared src/kernel`: 191 files, 5601 passed. `book.test.ts` 52/52 (2 new: the two-gate refusal in both key orders with the prescription text; every shape accepted before still accepted, `{ permissionSet, label }` still stripped). - `packages/lint` full suite: 241 files, 9749 passed. `validate-book-audience-claims.test.ts` 9/9: positive and negative pin per gated form, `'**'`, ungated audiences, map-shaped `books`, the three commands, and the runtime gate refusing a catch-all book write while passing a named claim. `authoring-rule-wiring.test.ts` green with the new entry. - `packages/apps/setup`, `packages/apps/studio`: 2/2 each; `typecheck` green in both and in `packages/lint`. - `check:generated` (spec): all 14 current after `--fix` regenerated `book.mdx` only. `check:liveness`, `check:strictness-ledger` green inside it. `check:adr-0087-registration` green (registered). `check:test-source-alias`, `check:type-check-coverage`, `check:doc-authoring`, `check:changeset-fixed`, console-intercept disarm: green. eslint on every touched TS file: clean. - Not run here: `rest`, `runtime`, dogfood and `ui/` suites (CI carries them; the only cross-package fixtures naming a catch-all are REST's catch-all control book, which is served through a stub, not a lint run). <details><summary>Ablations (each restored, tree clean after)</summary> - Spec: the refusing `systemPermission` field removed → `book.test.ts` 1 red (the two-gate refusal), 51 pass. - Lint: the catch-all test disabled → 6 of 9 red. - Setup: `include: 'setup_*'` → `'*'` → the control-doc pin red ("the manual claims a doc bound to no package"). - Setup: `setup_overview` renamed `admin_overview` → the claim pin red ("admin_overview is not claimed by setup_manual"). </details> ## Acceptance notes - File surface vs the claim: the claim listed `packages/lint`, the pins, `liveness/book.json`, and `book.zod.ts` "only if the lint route cannot reach the authored value" — it cannot (above). Also touched: `packages/apps/{setup,studio}` (the N4 pins, their wiring), `packages/spec/src/migrations/entries/semantic/` (the ADR-0087 entry this narrowing owes), `content/docs/ui/doc-pages.mdx`, the rule row in `content/docs/deployment/validating-metadata.mdx`, the rule count in four CLI transcripts, the regenerated `book.mdx`, and the pending `36029` changeset (DELIBERATE CORRECTION above). The claim's declarations were `Clause-②: no` / `Metadata-protocol: none`; this PR declares `yes (narrowing)` / `narrowed`. - A security item found while reading this surface is with the owner seat. - The prescription arrives under the union's "Unrecognized key(s) on this book audience: `permissionSet`" line, because branch ranking prefers an unknown-key branch (`union-branch-policy.ts`); the bullet under it carries the whole fix. ## Verification Read first: `packages/spec/src/system/book.zod.ts` (`BOOK_AUDIENCE_ONE_GATE`, `BookAudienceSchema`), then `packages/lint/src/validate-book-audience-claims.ts`, then `packages/apps/setup/src/manual-claims-docs.test.ts`. Two-minute check: `pnpm --filter @objectstack/lint exec vitest run src/validate-book-audience-claims.test.ts` (9 passed) and `pnpm --filter @objectstack/setup test` (2 passed). Tier H: `Clause-②: yes (narrowing)` on `packages/spec/src`. Contract review at CONTRACT_REVIEW_TIER owed by the seat; not self-reviewed here. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes (eslint on every touched file). - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgTbkZmKG1Moic2iU5K --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgTbkZmKG1Moic2iU5K)_ <!-- signed: repo:objectstack#2 · os-sales · session_01L6bhgTbkZmKG1Moic2iU5K --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a3c229e commit 39fafc0

24 files changed

Lines changed: 548 additions & 16 deletions

‎.changeset/36029-book-audience-system-permission.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Skills-docs: none — no `skills/` page teaches the book audience forms; `conten
1717

1818
A book's `audience` (ADR-0046 §6.7) takes a fourth form, `{ systemPermission: 'TOKEN' }`: the book's pages are read by a signed-in caller who holds that capability through any permission set, the same caller an app with `requiredPermissions: ['TOKEN']` opens for. `{ permissionSet }` names one set, so it could not gate a manual on a capability several sets grant (`setup.access` comes with `organization_admin`, `admin_full_access` and any delegated-admin set an application authors).
1919

20-
- **`@objectstack/spec`.** `BookAudienceSchema` and `BookAudience` gain the arm. It is strict, so `{ systemPermission, label }` is refused at parse; an object that also carries `permissionSet` still parses as the older, non-strict `{ permissionSet }` arm with the other key dropped, as before. `BookAudience` is a wider union now: TypeScript code that reads `.permissionSet` after a bare `typeof audience === 'object'` check narrows by key instead (`'permissionSet' in audience`). `AudienceCaller` gains `systemPermissions`, and `audienceAllows` admits the arm only when that list holds the token; an absent list denies (fail closed). Every other form answers as before.
20+
- **`@objectstack/spec`.** `BookAudienceSchema` and `BookAudience` gain the arm. It is strict, so `{ systemPermission, label }` is refused at parse, and an object that also carries `permissionSet` is refused too: an audience names one gate. `BookAudience` is a wider union now: TypeScript code that reads `.permissionSet` after a bare `typeof audience === 'object'` check narrows by key instead (`'permissionSet' in audience`). `AudienceCaller` gains `systemPermissions`, and `audienceAllows` admits the arm only when that list holds the token; an absent list denies (fail closed). Every other form answers as before.
2121
- **`@objectstack/rest`.** The docs audience reads the caller's own `systemPermissions` (the list every `requiredPermissions` arm of the `/meta` read gate reads) when some book carries the new form, on `GET /meta/doc` (with and without `?include=content`), `GET /meta/doc/:name`, `GET /meta/book`, `GET /meta/book/:name/tree` and the app-nav `doc` entries. New: `anySystemPermissionAudience`, and the optional `resolveAudienceSystemPermissions` port on `MetaReadGateAudienceSources` for a transport whose audience reads someone else's holdings.
2222
- **`@objectstack/runtime`.** The MCP docs tools (`search_package_docs`, `read_package_doc`) gate on the same form; on an OAuth grant they read the delegating person's own capabilities, never the token's ceiling.
2323
- **`@objectstack/setup`, `@objectstack/studio`.** Each package now ships a manual (`setup_manual`, `studio_manual`) claiming its package's doc namespace (`setup_*`, `studio_*`), gated on `setup.access` / `studio.access`. Before, those docs were claimed by no book, so they fell back to `org`: listed to administrators only by the Console's docs index, but readable at their address, and through `?include=content`, by every signed-in member. Now a member who cannot open Setup gets `setup_overview` in neither list and a `403 PERMISSION_DENIED` on its read; an administrator reads it as before. The docs' Console address now names the manual (`/apps/com.objectstack.setup/docs/setup/setup_overview`) in place of the package's implicit one; the flat `/docs/setup_overview` permalink still finds it.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/lint': minor
4+
---
5+
6+
fix(spec)!: a book audience names one gate, and a gated book claims its pages by name
7+
8+
Clause-②: yes (narrowing)
9+
Metadata-protocol: narrowed
10+
Skills-docs: none — no `skills/` page teaches the book audience forms; `content/docs/ui/doc-pages.mdx` documents both refusals in this change
11+
12+
<!-- adr-0087: registered book-audience-two-gates-and-catch-all-claim-refused -->
13+
14+
**BREAKING** for two book shapes (ADR-0046 §6.7) that were accepted and meant less than they said. Stored books are not rewritten or refused at boot; the next save or publish of such a book is refused with the fix named.
15+
16+
- **`@objectstack/spec`.** `BookAudienceSchema` refuses an `audience` naming both `permissionSet` and `systemPermission`. The older `{ permissionSet }` arm is a plain object, so the pair used to parse as the set form with the capability stripped: the author believed the book was gated on a capability, and it was gated on one set. `defineStack`, `os validate` and the `/meta` save now refuse it, and the message says which key to keep. Only the second gate key is refused: every other shape that parsed before still parses the same way.
17+
- **`@objectstack/lint`.** New error `book-gated-catch-all-include` (`validateBookAudienceClaims`): a book whose `audience` is `{ permissionSet }` or `{ systemPermission }` with a group claiming docs by `include: '*'`. A package scope leaves out only a doc stamped with another package, so a stored doc bound to no package is in every scope, and the catch-all claimed it too and hid it from every reader outside the audience. It runs on `os validate`, `os build` and `os lint`, and at the runtime publish gate on a book write (Studio, REST `/meta`, MCP).
18+
19+
## FROM → TO
20+
21+
- `audience: { permissionSet: 'crm_admin', systemPermission: 'setup.access' }` → `audience: { systemPermission: 'setup.access' }` (everyone holding the capability through any set) or `audience: { permissionSet: 'crm_admin' }` (the holders of that one set).
22+
- `audience: { systemPermission: 'crm.runbook' }` with `groups: [{ key: 'all', label: 'All', include: '*' }]` → `include: 'crm_runbook_*'` (the package's doc namespace), a tag include `{ tag: 'runbook' }`, or pinned `pages`.

‎content/docs/deployment/cli.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ os compile --json # JSON output for CI pipelines
937937
→ Normalizing stack definition...
938938
→ Lowering inline handlers...
939939
→ Validating protocol compliance...
940-
→ Running author-time rules (85)...
940+
→ Running author-time rules (86)...
941941
→ Checking that every required capability has a provider installable in this edition...
942942
→ Collecting package docs (ADR-0046)... 0 collected
943943
→ Writing artifact...

‎content/docs/deployment/validating-metadata.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ orthogonal to both, and no cell here can carry it; it is written out in
549549
| Advisory: credential literals in a flow — an `http` node's headers or url query, a node's `connectorConfig.input` (`flow-credential-literal`, #20698) | ✓ | ✓ | ✓ | ✓ᶠ |
550550
| Advisory: credential literals in a connector — its header and environment maps, and a stdio MCP credential route (`connector-credential-literal`, #29424) | ✓ | ✓ | ✓ | ✓ᶜ |
551551
| `views[]` and page-component conditional-visibility predicates — CEL syntax, parse budget, bare identifiers, binding-root layer; schema path refs on `views[]` only (ADR-0089 D3b, #7010; page components at the save door #24491); an app navigation entry's `visible` at the save door (#28663) | ✓ | ✓ | ✓ | ✓ᵛᵖᵃ |
552+
| Gated book claims — a book whose `audience` is `{ permissionSet }` or `{ systemPermission }` claiming docs by `include: '*'`, which also takes every doc bound to no package away from readers outside the audience (`book-gated-catch-all-include`, ADR-0046 §6.7) | ✓ | ✓ | ✓ | ✓ᵇ |
552553
| Advisory: record titles, semantic field pointers (ADR-0085), action placement, seed replay/state safety, capability references | ✓ | ✓ | ✓ | — |
553554
| Advisory: form-section layout | ✓ | ✓ | ✓ | ✓ᵛ |
554555
| Advisory: liveness | ✓ | ✓ | ✓ | ✓ᵉᵐᵈˢ |
@@ -869,7 +870,7 @@ A clean run walks the registry and reports timing:
869870
Config: /path/to/support-desk/objectstack.config.ts
870871
Load time: 21ms
871872
→ Validating against ObjectStack Protocol...
872-
→ Running author-time rules (85)...
873+
→ Running author-time rules (86)...
873874
→ Checking that every required capability has a provider installable in this edition...
874875
→ Checking package docs (ADR-0046)...
875876

‎content/docs/getting-started/build-with-claude-code.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ visible: 'status != "resolved"'
318318
◆ Validate
319319
────────────────────────────────────────
320320
→ Validating against ObjectStack Protocol...
321-
→ Running author-time rules (85)...
321+
→ Running author-time rules (86)...
322322
323323
✗ Author-time rules failed (1 issue)
324324
• stack · action 'resolve_ticket' visible: bare reference `status` — a

‎content/docs/references/system/book.mdx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ const result = BookSchema.parse(data);
6363
| **_lockDocsUrl** | `string` | optional | Optional documentation link surfaced next to _lockReason. |
6464
| **overrides** | `{ package: string; basedOn: string }` | optional | Override declaration (ADR-0146 D2): `{ package, basedOn }` — this item of "`<base>`.custom" replaces the base package's same-named item whole. `basedOn` is recorded and never gates; a base's upgrade plan reads it only as advice. |
6565

66+
### Nested Shape: `Book.audience[option 3]`
67+
68+
| Property | Type | Required | Description |
69+
| :--- | :--- | :--- | :--- |
70+
| **permissionSet** | `string` | ✅ | |
71+
| **systemPermission** | `never` | optional | Not accepted beside `permissionSet`: an audience names one gate |
72+
6673
### Nested Shape: `Book.groups[number]`
6774

6875
| Property | Type | Required | Description |
@@ -110,6 +117,7 @@ Type: `'public'`
110117
| Property | Type | Required | Description |
111118
| :--- | :--- | :--- | :--- |
112119
| **permissionSet** | `string` | ✅ | |
120+
| **systemPermission** | `never` | optional | Not accepted beside `permissionSet`: an audience names one gate |
113121

114122
---
115123

‎content/docs/ui/doc-pages.mdx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,16 @@ capability through any permission set — the same caller an app with
252252
`requiredPermissions: ['crm.read_runbook']` opens for. Use the capability form for the
253253
manual of an app gated on a capability several sets grant: naming one of those sets would
254254
shut out the holders of every other one. A caller whose holdings cannot be resolved is
255-
denied — the gate fails closed.
255+
denied — the gate fails closed. An audience names one gate: an object carrying both
256+
`permissionSet` and `systemPermission` is refused when the book is parsed, and the message
257+
says which key to keep.
256258

257259
Claim a gated book's pages by name (a namespace glob such as `include: 'crm_runbook_*'`, or
258260
pinned `pages`), not with `include: '*'`. A package scope leaves out only a doc stamped with
259261
*another* package, so a stored doc bound to no package is in every scope: a catch-all gated
260262
book would claim it as well and take it away from every reader outside the audience.
263+
`os validate`, `os build` and `os lint` refuse such a group (`book-gated-catch-all-include`),
264+
and so does saving the book through Studio, REST `/meta` or MCP.
261265

262266
<Callout type="info">
263267
The gate is a **capability** reference, never a distribution one: packages own permission

‎content/docs/ui/react-pages.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ objectstack validate
404404
────────────────────────────────────────
405405
→ Loading configuration...
406406
→ Validating against ObjectStack Protocol...
407-
→ Running author-time rules (85)...
407+
→ Running author-time rules (86)...
408408
→ Checking that every required capability has a provider installable in this edition...
409409
→ Checking package docs (ADR-0046)...
410410

‎packages/apps/setup/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
},
2222
"scripts": {
2323
"build": "tsup && node ../../../scripts/check-dts-emitted.mjs",
24+
"test": "vitest run",
2425
"typecheck": "tsc --noEmit"
2526
},
2627
"dependencies": {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [ADR-0046 §6.7] Every doc this package registers is claimed by its manual,
5+
* and gated as the manual is.
6+
*
7+
* The Setup manual claims its pages by the package's doc namespace
8+
* (`include: 'setup_*'`), and nothing else holds the package's docs to that
9+
* prefix: `docs/namespace-prefix` runs in `os build`, and this package is built
10+
* by tsup. So this pin reads what the plugin really registers, the shipped
11+
* constants and nothing copied, and resolves the audiences the docs doors
12+
* resolve. A doc named outside the prefix is claimed by no book and falls back
13+
* to `org`; the constant put back to `'*'` also claims the control doc bound to
14+
* no package. Either turns this red.
15+
*/
16+
17+
import { describe, expect, it } from 'vitest';
18+
import { resolveDocAudiences, type AudienceBook, type ResolverDoc } from '@objectstack/spec/system';
19+
import { createSetupAppPlugin, SETUP_APP_PACKAGE_ID, SETUP_MANUAL_BOOK } from './index.js';
20+
21+
interface Registered {
22+
id: string;
23+
docs: Array<{ name: string; label?: string }>;
24+
books: AudienceBook[];
25+
}
26+
27+
async function registeredManifest(): Promise<Registered> {
28+
const registered: Registered[] = [];
29+
const manifest = { register: (m: Registered) => registered.push(m) };
30+
await createSetupAppPlugin().start({ getService: (name: string) => (name === 'manifest' ? manifest : undefined) });
31+
expect(registered, 'start() registers one manifest').toHaveLength(1);
32+
return registered[0]!;
33+
}
34+
35+
describe('setup_manual claims every doc @objectstack/setup registers', () => {
36+
it('registers the manual beside its docs', async () => {
37+
const m = await registeredManifest();
38+
expect(m.id).toBe(SETUP_APP_PACKAGE_ID);
39+
expect(m.books).toEqual([SETUP_MANUAL_BOOK]);
40+
expect(m.docs.length, 'a package with no docs pins nothing').toBeGreaterThan(0);
41+
});
42+
43+
it('gives every registered doc the manual\'s audience, and leaves a doc bound to no package alone', async () => {
44+
const m = await registeredManifest();
45+
// The metadata layer stamps each registered item with its package.
46+
const books: AudienceBook[] = m.books.map((b) => ({ ...b, packageId: m.id }));
47+
const docs: ResolverDoc[] = [
48+
...m.docs.map((d) => ({ name: d.name, label: d.label, packageId: m.id })),
49+
// Control: a stored doc bound to no package is in every package scope.
50+
{ name: 'unbound_page', label: 'Unbound' },
51+
];
52+
const audiences = resolveDocAudiences(books, docs);
53+
for (const doc of m.docs) {
54+
expect(audiences.get(doc.name), `${doc.name} is not claimed by setup_manual`).toEqual([SETUP_MANUAL_BOOK.audience]);
55+
}
56+
expect(audiences.get('unbound_page'), 'the manual claims a doc bound to no package').toEqual(['org']);
57+
});
58+
});

0 commit comments

Comments
 (0)