Skip to content

Commit 2487242

Browse files
objectstack-fleet[bot]claudeos-support-ai
authored
fix(objectql,metadata-protocol,console): a list view column on a field a disabled package adds no longer fails the whole list (#34979)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBLW6dHPW6sSheA32XPKZzPV)_ Fixes #34901 repo:objectstack#3 · os-support-ai · session_01WGufzg2evNa1V3zxrQq3KX Clause-②: yes (widening: the view save door accepts withheld names; one spec read-decoration member; one locale key; one optional security-service member, add-only) Metadata-protocol: none ## 维护者速读 - 改了什么:一个包给别的包的对象加了字段,这个包被停用后,对象的读取接口会在 `_withheldFields` 里说明哪些字段被暂时收起、由哪个包添加;保存视图时按“含停用包字段”的存储对象来校验,所以视图能照常保存;列表和表格在所有查询里都不再带这些字段,列不显示,并在列表上方用一行说明原因。 - 为什么改:之前只要视图引用了停用包的字段,整个列表就报 400 打不开,重命名、置顶或在 Studio 里改视图也会被 422 拒绝;HotCRM 的费用、订单到收款等视图都会碰到,HotCRM 下个版本在等这张卡。 - 风险与回滚:无权读取被收起字段的用户在 `_withheldFields` 里看不到它(按存储定义逐人判断,判断不了就整项不给);不改视图数据,也不写用户的列表偏好;重新启用包后列、排序、分组自动回来。保存校验只对视图放宽,拼错的字段仍会被拒绝,页面、流程等其他写入不受影响。回滚即还原本 PR。 - 先看:`packages/metadata-protocol/src/protocol-authoring-gate.ts`(只对视图写入使用存储对象校验的那一处);`ui/packages/plugin-list/src/ListView.tsx`(各查询参数去掉被收起字段、列的推导、持久化排序保留它);`packages/objectql/src/registry-object-registration.ts`(`includeDisabledExtensions` 与读取被收起字段的方法)。 - 两分钟验证:`pnpm --filter @objectstack/objectql exec vitest run src/protocol-withheld-extension-fields.test.ts`,应看到 4 个用例通过:停用包后对象读取带 `_withheldFields`、视图能保存进定制包、拼错的列仍被拒绝、页面写入仍被拒绝。 - 需要你做的:无,席位落地。 ## What changes A package can add fields to another package's object (`objectExtensions`). While that package is disabled, the platform leaves those fields out of the served object, and the data door refuses any request that names one. The owner's views keep naming the field on purpose, so the column, sort and grouping come back when the package is re-enabled. Until now, those references failed the whole list (`400 INVALID_FIELD`, or `400 INVALID_SORT` for a sort), and re-saving the view failed with `422`. **Server (`@objectstack/objectql`, `@objectstack/metadata-protocol`)** - `SchemaRegistry.getWithheldExtensionFields(name)` returns `{ [field]: { packageId } }` for each field that a disabled package's `extend` contribution adds and that no kept contributor also declares. It reads the same `withholdDisabledExtensions` computation as the served fold. It is registered as a `read` in `SCHEMA_REGISTRY_METHOD_KINDS`, because the registry revision ledger fails to compile without that row. - `ObjectExtensionFoldOptions.includeDisabledExtensions` folds every disabled package's extension in, which gives the storage view of the object. It changes no state. - **Served marker:** the served face of an object read stamps `_withheldFields` on `getMetaItem` and on the effective-layer list read. The execution face, the draft read and the layered editor read never carry it. It is added to `METADATA_READ_DECORATIONS` in `@objectstack/spec`, so `stripReadDecorations` removes it at the save door and before re-parses, and the diagnostics verdict ignores it. - **View save door:** `judgeRuntimeAuthoringRules` judges a `view` write against the objects with disabled extensions folded in (`withDisabledExtensionsFolded`). It applies to the registered and the stored halves of the merged universe. A withheld name resolves as the stored field it is. A misspelled name is still refused. Every other written type keeps the served objects. **Console (`@object-ui/core`, `@object-ui/plugin-list`, `@object-ui/plugin-grid`, `@object-ui/i18n`)** - `@object-ui/core` `withheld-fields.ts` is the one reader: `readWithheldFieldNames(objectDef)`, `refersToWithheldField`, and `withheldFieldNamesOfFieldMap`, for a hook that holds only the field map. - `ListView` merges the withheld set with the draft-only set (`queryDropFields`) on every request leg: `$select`, `$filter` (all three `buildEffectiveFilter` callers), `$orderby` (`serverSort`), `$searchFields`, the export, and the grouping levels it queries with. - It hides a withheld column by derivation in `effectiveFields`. Nothing is written to `hiddenFields`, the view or the user's list preferences. - One line above the rows names every withheld field the view refers to: `list.withheldFieldsLeftOut`, `data-testid="list-withheld-fields-notice"`. - `emitSortChange` keeps a withheld entry in the sort it persists. The projection has no entry for that field only while the package is off. Other refused entries are still dropped. - **Grid:** the row load drops withheld names from `$select`, the declared `$orderby` and `$searchFields`. The grouping decisions refuse a withheld `groupBy` key, the same way they refuse a draft-only key. The column generator does not draw a withheld authored column. PIN 4 (`projectionFls-6898`) is unedited and green. - **Locale:** one key, `list.withheldFieldsLeftOut`, in the 11 eager packs (zh-Hant regenerated by `gen:zh-hant`) and in `ListView`'s default dictionary. The `list.*` keys live in the eager packs, and no lazy namespace covers them. ## Tests <details><summary>New pins (each named against the card's required pins)</summary> - `packages/objectql/src/protocol-withheld-extension-fields.test.ts`: the real protocol over the real `ObjectQL` engine and an in-memory driver, with P extending Q's object and Q's view naming the field as a column and as its sort. - The served object read and the list read carry `_withheldFields`, and the execution face does not. Re-enabling P clears it (pin 6). - The view saves into `Q.custom` while P is off and keeps the withheld column and sort, and is served that way once P is back (pin 1). - A misspelled column is refused with exactly one issue on its own path (pin 1). - A page sorting by the withheld field is still refused (`page-field-unknown`) while P is off, with controls for P on and for a served field (pin 2). - `packages/objectql/src/registry-disabled-package-extensions.test.ts`: the reader names the withheld field and its package, leaves out a name a kept contributor also declares, and clears on re-enable. `includeDisabledExtensions` folds every disabled extension in without moving the served fold or the disable state. - `packages/metadata-protocol/src/protocol.read-decorations.test.ts`: `stripReadDecorations` removes `_withheldFields`. GET, then edit, then PUT of the served object stores none of it and is byte-identical apart from the edit. The layered read does not carry it, and nothing withheld means no marker (pin 3). The existing drift guard now also covers the new member. - `ui/packages/plugin-list/src/__tests__/ListView.withheldFields-34901.test.tsx`: the data source refuses any request naming the field, as the door does. - No request names it on `$select`, `$filter`, `$orderby` or `$searchFields`, each with positive controls. The grid is handed no column, sort or grouping on it, and the notice names it (pin 5). - A withheld grouping level is left out and the grid groups by the level left. The grid that runs its own grouped query gets no filter or searchable field on it (pin 5). - The sort builder's write and the grid's header seam both persist the withheld entry, and a refused non-withheld entry is still dropped (pin 4). - A definition without the marker draws and requests the column again, with `onSortChange` never called (pin 6). - `ui/packages/plugin-grid/src/__tests__/withheldFields-34901.test.tsx`: a standalone grid never sends the field in `$select`, `$orderby` or `groupBy`, and draws no column for it. Controls cover P on, and enabling in place without a reload (pin 5, pin 6). - `ui/packages/core/src/utils/__tests__/withheld-fields.test.ts`: the reader, the declared-name guard and the field-map lookup. </details> <details><summary>Suites and typecheck (head b76b858 for the ui reruns; f4ea4f9 for the rest, the only later change being the regenerated zh-Hant.ts line)</summary> - `pnpm --filter @objectstack/objectql run test`: Tests 13670 passed (13670) - `pnpm --filter @objectstack/metadata-protocol run test`: Tests 23124 passed, 45 skipped (23169) - `pnpm --filter @objectstack/spec exec vitest run src/kernel`: Tests 1493 passed (1493) - `pnpm --dir ui exec vitest run packages/core/`: Tests 4450 passed, 27 skipped - `pnpm --dir ui exec vitest run packages/plugin-grid/`: Tests 2480 passed (2480), `projectionFls-6898` included - `pnpm --dir ui exec vitest run packages/plugin-list/`: Tests 1880 passed (1880) - `pnpm --dir ui exec vitest run packages/i18n/` plus the new pins and PIN 4, rerun on b76b858: Test Files 107 passed, Tests 1927 passed, 13 skipped. The first run went red on `zh-hant-generated.test.ts` until `gen:zh-hant` regenerated the zh-Hant line. - Typecheck: `@objectstack/objectql` `typecheck` exit 0 (after the revision-ledger row), `@objectstack/metadata-protocol` exit 0, `@objectstack/spec` exit 0; `turbo run type-check` over `@object-ui/core`, `@object-ui/i18n`, `@object-ui/plugin-grid`, `@object-ui/plugin-list`: 58 successful of 58 tasks. - `pnpm --filter @objectstack/spec run check:generated`: all 14 generated artifacts up to date; nothing to regenerate. </details> <details><summary>Ablations (commit first, mutate through ablation-replace, rebuild and preflight where the suite reads dist)</summary> 1. **Gate fold** (`protocol-authoring-gate.ts`): the `objects:` line was replaced so every type keeps the served objects. Anchor 1 to 0, blob `5d6ef7cd64e9` to `c29895708e3a`. `metadata-protocol` was rebuilt, and the preflight found the marker in 2 dist files. - Mutated run: 2 failed, 2 passed. The save came back `422 INVALID_METADATA` with `sort-field-unknown` and `list-view-field-unknown` on the withheld column and sort, which is the bug. The typo case listed 3 issues instead of 1. - Restore: blob back to HEAD and `git diff HEAD` empty; rebuilt, preflight `--absent` across 24 files, 4 passed. 2. **Console drop** (`ListView.tsx` `queryDropFields`): the merge with the withheld set was short-circuited (blob `73271f53f396` to `d8d554821983`, source-aliased, no build). Mutated run: 3 failed, 1 passed, with `$filter` naming `crm_project` and `Unknown field 'crm_project'` from the data source. Restored to HEAD. 3. **Persist boundary** (`emitSortChange`): the withheld arm of the keep filter was disabled. Mutated run: 1 failed (`expected [] to deeply equal [ [ 'crm_project', 'asc' ] ]`). Restored to HEAD. </details> ## Acceptance notes - **Deviations:** the seat accepted deviations 1, 2 and 4 from the round-3 report. The Clause-② locale-key count is corrected per the seat: one locale key, in the changeset and in this body. - **Out of scope, by the claim:** - Embedded `listViews` on an object write. An object is extended, never replaced (ADR-0146 D10), and an object write keeps the served judgement. - Dashboards and reports that name a withheld field. Only `view` writes get the storage fold, and this PR adds no console leg for those surfaces. - **Pin 4, a correction to my round-2 wording:** a column-header click cannot persist a withheld sort entry. `data-table`'s manual-sorting `handleSort` replaces the whole sort with the clicked column ("A header click REPLACES the order"), so the click itself carries no earlier entry. The pin covers the two places a write crosses: the sort builder's edit, and `ListView`'s header seam (`handleHeaderSort` then `emitSortChange`), fed a list that holds the withheld entry. `ObjectGrid`'s own `manualOnSortChange` filters a multi-entry emission through the sortability projection before that seam. That file is outside this claim, and `data-table` never emits more than one entry. - **Grid grouping note:** the standalone grid drops a withheld `groupBy` key without a note of its own. The note would render in `ObjectGrid.tsx`, which is outside the claim. Inside a list view, the list's own line names the field. As a result the claim's second locale key is not minted, and the PR adds one key, as the Clause-② line states. - **How the grouping decisions find the names:** `useObjectGridGroupingDecisions` receives only `objectSchema.fields` from `ObjectGrid.tsx`. The row load reads `_withheldFields` off the definition it fetched before handing the definition on. `withheldFieldNamesOfFieldMap` answers from a module `WeakMap` keyed on that payload field map, not on a memo identity, which follows ui AGENTS.md #10. The alternative is to pass the names from `ObjectGrid.tsx` as one more argument, which needs that file. - **Standalone grid `$filter`:** an authored block filter naming a withheld field is not dropped on a standalone grid. Without a note, dropping it would silently widen the rows the author filtered. The list view does drop it from its own filter and names it in the notice. - **Files:** - `registry-revision.ts` gains one row. The registry's method-kind ledger fails to compile without it once the public reader exists. - `protocol-object-extender-fold.ts` and the stored-collection fold are unedited. The stored half is folded at the gate, over the merged universe. - **Not covered:** kanban, calendar, gallery, timeline, gantt and map bindings, which name a field per visualization, are not touched by this card. - **Eager closure (the merged tree, `origin/main` = BASE `fff0ad0c180`):** "Console eager closure is 1898.8 KB gzipped across 104 of 2538 chunks (budget: 2431.6 KB, headroom: 532.8 KB)". `i18n-locale-en` is 60.5 KB against a 78.7 KB ceiling, headroom 18.2 KB. No ceiling was edited. - **Governed:** `node scripts/pm/check-governed-merges.mjs --branch claude/issue-34901-disabled-package-view-column` gives "0 of 32 path(s) hit the register — NOT governed", with size 1295 changed lines, under the 3000 threshold. The PR is DRAFT either way. - **Overlap:** `node scripts/pm/overlap-check.mjs` gives VERDICT clean exit 0. It merges cleanly with `origin/main`, #34925 (shares `ListView.tsx` and the locale packs) and #34950 (shares the locale packs). ## Verification All local readings are on head `b76b8580b59`, the head this PR opens with. CI runs every family named here again on the PR. Its check-runs are still `in_progress` at report time, and this list is the local subset. Head `d639b903f34` adds one prose-only commit on top: the changeset's Clause-② line now counts one locale key. On that head `node scripts/check-empty-changeset.mjs --base origin/main`, `node scripts/check-changeset-no-major.mjs --base origin/main` and `pnpm check:nul-bytes` (scan of 26061 files plus `--self-test`) each exit 0, and `node scripts/pm/overlap-check.mjs` gives VERDICT clean exit 0 against `origin/main` `0465f4aa401`. The code readings below are unchanged, because no code changed. <details><summary>dispatch-gates union and reconciliation</summary> - `node scripts/pm/dispatch-gates.mjs --commands` derived 101 commands (74 pnpm, 27 direct node) from 32 paths against merge base `fff0ad0c1`. All 101 ran on `b76b8580b59`, three at a time, each exit captured before any pipe. - `node scripts/pm/dispatch-gates.mjs --ran` with a `COMMAND :: exit N` record: "101 derived famil(ies) accounted for — 100 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3)". - 100 exit 0. That count includes `pnpm --dir ui exec vitest run scripts/`. Two of its tests (`check-vi-mock-specifiers`, `dollar-dialect-alias-census`) timed out at 15 s in a first run on `f4ea4f9b7ee` that shared the box with the full test suites, and passed in this run. - `pnpm check:dts-closure` exits 0 ("289/289 declared declaration file(s) present") after `pnpm --dir ui/apps/console run build:plugin` wrote `ui/apps/console/plugin.d.ts`. Its first exit 1 named only that missing local artifact. - NOT MEASURED: `pnpm check:dual-build-cjs-loads`, exit 3, PREREQUISITE NOT MET. It reads every package's `dist/`, and this worktree built only the closures this card touches. CI's Build Core measures it. - `pnpm --filter @objectstack/spec run check:generated`: all 14 generated artifacts up to date. - `ui` `check:eager-closure`: green, readings under Acceptance notes. - `check-platform-checklist --changed-from`: not owed. No exported symbol is renamed or deleted; the reader and the helper functions are additions. - Full dogfood: not owed. The title carries no `!`, and the Clause-② line has no `(narrowing)` arm. </details> ## Fix round (L2 6963280774) Head `2a4d8e5a852` (two commits on `da04396946`, no merge: 7 first-parent commits on `main` since the merge base, under 15). Dev-effort: high. **M1 (must-fix): measured red on `da04396946`, not fixed in this round. It needs a seat decision first; the dev report on this PR carries the options.** - A real `SecurityPlugin` (its `getMetadataReadableFields`, ADR-0106 D7) answers `["id","name","amount"]` for all three callers: denied `crm_project` by a permission set's `readable: false`, denied by the field's `requiredPermissions`, and allowed. The served schema no longer carries the field, so the readable set has no entry for it in either direction, and the projection cannot tell a denied caller from an allowed one. - With that service behind each door, a `project`-posture caller is served `_withheldFields: {"crm_project":{"packageId":"com.acme.projects"}}` on REST `GET /meta/object/:name` (cached and uncached), REST `GET /meta/object`, and the runtime `/metadata/object/:name` and `/metadata/object` reads: 10 of 10 denied-caller pins red (both denial kinds, every door). The cached read's ETag is `"shared"` for the denied and the allowed caller alike (no D3 fingerprint for the entry). - Judging an entry against the stored field needs the caller's permission-set entry and capability fold for a field the live registry does not hold. The dispatch layer has no security-service question that answers that today, so the fix needs a contract choice (a new optional security-service member, or a wider answer from the existing one) that the ruling does not settle, and it would add an item to the Clause-② line. The measurement tests were scratch and are not committed. **S1 (should-fix): fixed.** A served view's `_diagnostics` (the item read and the `?layers=true` editor read) now judges names against the same disabled-package fold as the save door (`viewLintObjectLookup` over `withDisabledExtensionsFolded`, which moved from `protocol-authoring-gate.ts` into `metadata-diagnostics.ts` beside the lint passes; the gate imports it from there). Pins in `packages/objectql/src/protocol-withheld-extension-fields.test.ts`: - A view the door accepts while P is off (column, sort, filter, grouping level, searchable field on `crm_project`) reads back with no warning naming it, on both reads. - A code-registered view with a typo'd column still warns, once. - A form section on the withheld field reads back with no `form-field-unknown`. - Ablation: `viewLintObjectLookup` returning the served object (marker in `metadata-protocol/dist`, 2 files) turned the 2 read pins red with the four warnings the live reading saw (`columns.2`, `grouping.fields.0`, `filter.0`, `sections.0.fields.1`). Restored: blob equals HEAD, `git diff HEAD` empty, rebuilt, marker absent from all 24 dist files, 10/10 green. **N5: done.** Save-door pins for a filter, a grouping level and a searchable field on the withheld name, each with a typo control that is refused at its own path. A form section's unknown field is advisory at the door (`form-field-unknown` never refuses), so its pin reads the save's `advisories`: none for the withheld name, one for a typo. The fold docblocks (`metadata-diagnostics.ts`, `registry-top-level.ts`) now name every position instead of "a column or sort". **N3: done.** The comment in `packages/runtime/src/domains/packages.ts` names all three read decorations. Comment only, so no changeset entry for `@objectstack/runtime`. **Files this round adds to the claimed surface:** `packages/metadata-protocol/src/metadata-diagnostics.ts`, `packages/metadata-protocol/src/protocol-meta-item-reads.ts`, `packages/metadata-protocol/src/protocol-meta-layered-reads.ts`, `packages/runtime/src/domains/packages.ts` (comment). Also edited, already claimed: `protocol-authoring-gate.ts`, `registry-top-level.ts` (docblock), the objectql pin file, the changeset (one sentence on the diagnostics fold). No public export moves. **Suites on `2a4d8e5a852`:** metadata-protocol 23124 passed, 45 skipped (360 files); objectql 13731 passed (611 files); typecheck exit 0 on both. `dispatch-gates --commands`: 103 derived, 101 exit 0; NOT MEASURED: `check:dual-build-cjs-loads` (exit 3, no dist for untouched packages here) and `pnpm --dir ui exec vitest run scripts/` (exit 1 on a module-resolution prerequisite, `@objectstack/client` has no dist in this worktree; no `ui/` file changed this round). `check-platform-checklist --changed-from origin/main`: OK, 0 anchors lost. Clause-② and Metadata-protocol lines unchanged. ## M1 round (route A) Head `610ee495e41`. Seat ruling route A (claim amendment 6964496069). Dev-effort: high. The round restarted after the container was restarted: the previous dev's local WIP commit was reviewed, finished, squashed into the commits below, and pushed as a fast-forward of `2a4d8e5a852`. Merged `origin/main` (`eb7b09d4d2`) because main was 27 first-parent commits past the merge base (the bar is 15). **What changes** - `@objectstack/spec`: `ISecurityService` gains an OPTIONAL member, `getMetadataReadableWithheldFields(object, context)`, add-only. It answers which fields a disabled package withholds may be named to the caller. The docblock says that absence, `undefined` and a throw all mean "name none". - `@objectstack/plugin-security`: implements it in a new file, `security-plugin-withheld-field-readers.ts`. It reads the withheld names (`getWithheldExtensionFields`) and the storage definition (`getStorageObject`), and judges each name with the same evaluator the readable projection uses: the permission-set field entry, the stored field's own `requiredPermissions`, the D7 fallback set for a caller who resolves no set, the on-behalf-of delegator's intersection (with the organization refusal), and the computed-field fold. It is narrower than the readable projection in two places, and both fail closed: a computed withheld field that reads through a reference is not admitted, and a masking rule does not admit a field its capability fold denies. A system context is told every name. The member is registered on the `security` service, and the registered-members pin declares it. - `@objectstack/metadata-core`: for a `project`-posture caller, `applyObjectSchemaMask` keeps a `_withheldFields` entry only when the member admits it. It removes the decoration when no entry is left, and folds each dropped entry into the D3 fingerprint as `withheld:NAME`. The member is asked once per posture. An absent member, an `undefined` answer or a throw drops every entry; a throw is logged at warn. The seat ruled drop, not the D6 5xx, because the caller needs nothing that depends on it. A `passthrough` posture (D4-exempt caller, D8, no security service) and an `undetermined` posture keep the decoration as served. Every outlet that projects through `resolveObjectSchemaMaskPosture` is covered with no door edit. - No label in the decoration. **Pins (each ablated red, then green, restored by blob)** - plugin-security `get-metadata-readable-withheld-fields.test.ts` (real `SchemaRegistry`, real plugin): denied by a set's `readable: false`, denied by `requiredPermissions`, admitted, with the live-field answer as the control; the computed-field fold; through a reference; the D7 fallback; the delegator; system; no storage read means `undefined`. - metadata-core `object-schema-fls.test.ts`: drop, admit by reference, fail closed (member absent, `undefined`, throw), passthrough, a posture built without the answer, the D3 fingerprint (it differs for different withheld sets, is equal for the same set, and is qualified), asked once. - REST `meta-disabled-package-doors.test.ts` and runtime `meta-disabled-package-doors.test.ts`, with the real protocol, registry and `SecurityPlugin`: REST `GET /meta/object/:name` cached and uncached, REST `GET /meta/object`, runtime `/metadata/object/:name` and `/metadata/object`. Two callers are denied (by a set, by `requiredPermissions`) and are served no entry; two are admitted and are served it. The cached ETag differs between the denied and the admitted callers, and is equal within each group. With a service that lacks the member, every caller gets no entry. <details><summary>Ablations (ablation-replace, dist preflight where the suite reads dist)</summary> - A1, the projection's drop (`withheldDropped` forced empty, metadata-core rebuilt, marker in 2 dist files): metadata-core 4 red, REST 5 red, runtime 2 red. Restored: blob `1541a6b7af54` equals HEAD, rebuilt, marker absent from 12 dist files, all green. - A2, fail-closed (the empty fallback set admits every entry): the first try's marker was constant-folded out of dist, so the preflight refused it and that reading is void. The re-run used a marker that survives the build and was found in 2 dist files: the fail-closed pins went red in metadata-core, REST and runtime (1 each). Restored and green. - A3, the ETag fold (no `withheld:` entries in the fingerprint): the metadata-core D3 pin and the REST ETag pin went red. Restored and green. - P1, the stored `requiredPermissions` not folded (plugin-security rebuilt): plugin 2 red (capability denial, D7 fallback), REST 4 red, runtime 1 red. Restored: blob `fbd483eb2e95`, green. - P2, the permission-set entry ignored: plugin 3 red, REST 4 red, runtime 1 red. Restored and green. - R, the service registration deleted: plugin 8 red (the registered-service read and every case that reads through it). Restored: blob `440aa81de1f8`, green. - Registered-members pin, its `getMetadataReadableWithheldFields` entry deleted: plugin-security `typecheck` exit 1 (a type error in the pin file). Restored: exit 0. </details> **Harness note.** The previous WIP's pins were red at the restart. They registered the permission sets only in `metadata.list`, but the plugin binds its catalog to the engine's registry at start, and from then on it resolves every set from that registry. The harnesses now register the sets on the registry. **CI reds on `01192b432f5`, fixed in `74073018f05`, `24d71a88271` and `610ee495e41`** - `check:engine-double-contract`: the runtime engine double's `findOne`, `update` and `delete`, and the `ql` doubles of the three harnesses, now open with the shared `assertEngine*` predicates. The pinned ledger records the new coverage; the baseline is untouched. Local reading: exit 1 with 5 problems, then exit 0. - `check:system-context-census` (the docs-anchors lane): row 4 on `content/docs/permissions/system-context.mdx` names `computeMetadataReadableWithheldFields`, and the register was regenerated with `--write`. Local reading: exit 1, then exit 0. The self-test passes, and `check:doc-anchors` exits 0. - plugin-security `delegated-organization-membership.test.ts`: the new reader resolves one delegator and asks the organization refusal once (1 = 1), so the census pin lists eight files. The full plugin-security suite is green (below). **Files this round adds to the claimed surface:** `packages/plugins/plugin-security/src/security-plugin-withheld-field-readers.ts` (new), `get-metadata-readable-withheld-fields.test.ts` (new), `security-plugin.ts`, `security-plugin-security-service.ts`, `registered-security-service-members.pin.test.ts`, `delegated-organization-membership.test.ts`, `packages/spec/src/contracts/security-service.ts` (+test), `packages/metadata-core/src/object-schema-fls.ts` (+test), `scripts/engine-double-contract.pinned.json`, `content/docs/permissions/system-context.mdx`. The REST and runtime pin files and the changeset were already claimed. **Verification** - Suites (the tree of `610ee495e41`; spec and metadata-core ran before the last two test-only commits): spec 943 files, 28822 passed; metadata-core 27 files, 1045 passed; plugin-security 277 files, 6936 passed, 45 skipped; rest 423 files, 8912 passed, 373 skipped; runtime 622 files, 12904 passed, 23 skipped. Typecheck exit 0 on all five. Runtime's test-layer typecheck first failed on `@objectstack/driver-turso`, which had no build in this worktree (TS2307 in two files this PR does not touch); after building it, the check exits 0. - `pnpm --filter @objectstack/spec check:generated`: all 14 artifacts up to date. - `dispatch-gates --commands` (derived at `24d71a88271`): 136 families. `--ran` exit 0: 132 run, 4 NOT MEASURED with exit 3 (prerequisite not met in this worktree: `check:skill-examples`, `check:dual-build-cjs-loads`, `check:i18n`, `check:type-check-debt`). `pnpm --dir ui exec vitest run scripts/` exits 1 on module resolution (packages outside this worktree's build have no dist). CI measures all five. - `check-governed-merges --branch`: 0 of 51 paths governed; 2445 changed lines (under 3000). `overlap-check`: VERDICT clean against `origin/main` and #34999, #34910, #34817, #34791. - Changeset: `@objectstack/metadata-core` and `@objectstack/plugin-security` join at `patch`. `Metadata-protocol: none`: no authorable key, value or type moves. Full dogfood is not owed: the title has no `!` and the Clause-② line has no `(narrowing)` arm. --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzg2evNa1V3zxrQq3KX)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzg2evNa1V3zxrQq3KX --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: os-support-ai <support@objectstack.ai>
1 parent cc5472e commit 2487242

51 files changed

Lines changed: 2375 additions & 70 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
'@objectstack/objectql': patch
3+
'@objectstack/metadata-protocol': patch
4+
'@objectstack/spec': patch
5+
'@objectstack/metadata-core': patch
6+
'@objectstack/plugin-security': patch
7+
'@object-ui/core': patch
8+
'@object-ui/plugin-list': patch
9+
'@object-ui/plugin-grid': patch
10+
'@object-ui/i18n': patch
11+
---
12+
13+
fix(objectql, metadata-protocol, console): a list view column on a field a disabled package adds no longer fails the whole list
14+
15+
Clause-②: yes (widening: the view save door accepts withheld names; one spec read-decoration member; one locale key; one optional security-service member, add-only)
16+
Metadata-protocol: none
17+
18+
A package can add fields to another package's object. While that package is disabled, the platform leaves those fields out of the served object, and the data door refuses every request that names one (`400 INVALID_FIELD`, or `400 INVALID_SORT` for a sort). The owner's views still named the field, so a view with such a column, sort, filter, grouping level or searchable field failed for everyone. Saving the view (a rename, a pin, a Studio edit) was refused too (`422`, `list-view-field-unknown` / `sort-field-unknown`).
19+
20+
- **The served object read names what is withheld.** `GET /api/v1/meta/object/:name` and the object list read carry `_withheldFields: { [field]: { packageId } }` when a disabled package withholds a field from the object. It is a read decoration (`METADATA_READ_DECORATIONS`), so the save door strips it, and the execution face and the layered editor read do not carry it. The registry gains `getWithheldExtensionFields(name)`.
21+
- **A caller who may not read a withheld field is not told it exists.** The object-schema projection (ADR-0106) keeps a `_withheldFields` entry only for a caller the security service admits. `ISecurityService` gains an optional member, `getMetadataReadableWithheldFields(object, context)`, which answers the withheld names the caller may read; `@objectstack/plugin-security` implements it from each field's stored definition: the permission set's field entry, the field's own `requiredPermissions`, the fallback set for a caller with no set, and the on-behalf-of delegator. A security service without the member, an `undefined` answer or a throw drops every entry. Each dropped entry moves the caller's ETag, so two callers who are told different things never share a `304`. A caller exempt from the projection (a platform admin, a system context) is served every entry, as before.
22+
- **The view save door judges a view against the stored object.** A `view` write is judged against the object with every disabled package's extension folded in (the new fold option `includeDisabledExtensions`). A withheld field is a real stored field, so the view saves and keeps its column and sort. A misspelled field is still refused. Other writes are still judged against the served object, so a page or flow that names a withheld field is still refused while the package is off. A served view's `_diagnostics` is judged against the same stored object, so it no longer warns `list-view-field-unknown` or `form-field-unknown` on a withheld name the save door accepts; a misspelled field still warns.
23+
- **The console leaves withheld names out.** The list view and the grid leave a withheld field out of `$select`, `$filter`, `$orderby`, `$searchFields` and `groupBy`, and do not draw its column. A line above the rows names it (`list.withheldFieldsLeftOut`). Nothing is written to the view or to the user's list preferences, and a sort the user saves keeps the withheld entry. Once the package is enabled, the column, the sort and the grouping come back without any write.

‎content/docs/permissions/system-context.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ bugs — it is the protection or the side effect that silently does not happen.
103103
| 1b | **App-authored automation's system context is REFUSED governed writes to the identity-assignment objects** — a flow run's, an app-authored hook's (`runAs: 'system'`, a system context it inherits, its `sudo()`) and an action body's; checked ahead of the middleware's short-circuit, beside the append-only refusal (`assertAppAutomationAppendOnlyWriteAllowed`) | plugin-security | Get: nothing — an insert, update, delete, transfer, restore or purge of `sys_user_position`, `sys_user_permission_set`, `sys_invitation` or `sys_member` from a context carrying `isSystem` and either a `flowRunId` (a `runAs: 'system'` flow's data nodes) or the app-automation elevation mark (`@objectstack/core`; set only by a hook's `runAs: 'system'` derivation, by the action body's execution-context builder and `ObjectRepository.execute`, and on the api of a hook bound through the hook binder, whose inherited system context and `sudo()` it marks), at any depth of their writes, is refused `PERMISSION_DENIED` before the short-circuit skips the ADR-0090 D12 gate and the identity write guard. Lose: nothing a platform writer held — a system context with neither (the seeders, better-auth and its reconciliation, invitation placement, platform code's `sudo()`, which never sets the mark, and a hook registered in code) passes on to the short-circuit unchanged, reads are not judged, and a `runAs: 'user'` flow or hook carries no `isSystem`, so the D12 gate judges it as the user it acts for | `elevationSource`, `appAuthoredHookApi` |
104104
| 2 | **`owner_id` is not auto-stamped on INSERT** (the step 3.5 anchor guard is inside the block row 1 skips) — except an action body's insert | plugin-security | Lose: the row lands `owner_id = NULL`, so the default `owner_only_writes` policy hides it **from its own creator**. Get: nothing — this is a gap, not a capability. Except an action body's: an insert from a context carrying `isSystem` and the `'action'` app-automation elevation mark, with no `flowRunId`, has every EMPTY `owner_id` stamped with the envelope's own `userId` ahead of the short-circuit, by the same stamp step 3.5 applies (nothing for the guest; an owner the body sets is kept; an `owner_id` supplied empty beside a supplied queue parks the row). Like a direct create, such an insert is the invoker's own record, so assignment rules (ADR-0142 D5), which route only a row whose owner and queue are both still empty, route neither; a body has no spelling today that asks a rule to route its row. The mark is set on every handler an action door dispatches (a host code action handler included) and by `ObjectRepository.execute`. A flow run, a hook's `runAs: 'system'`, the seeders and every other system context still land the owner they write, or none, and an unowned, queue-less one is still routed | the step 3.5 guard block and the short-circuit that skips it are both inside `registerAuthzMiddleware`; the action-body exception is `isActionBodyElevation` |
105105
| 3 | Row-level read filter resolves to "no filter" | plugin-security | Get: unscoped reads. Lose: row-level scoping entirely | `getReadFilter` |
106-
| 4 | Field-level security returns **all** fields | plugin-security | Get: every column readable (`getReadableFields`) and writable (`getWritableFields`). Lose: field masking | `resolveProjectionFieldMask` |
106+
| 4 | Field-level security returns **all** fields | plugin-security | Get: every column readable (`getReadableFields`) and writable (`getWritableFields`), and every field a disabled package withholds named to it (`getMetadataReadableWithheldFields`, so the served object's `_withheldFields` keeps every entry). Lose: field masking | `resolveProjectionFieldMask`, `computeMetadataReadableWithheldFields` |
107107
| 5 | Export permission granted unconditionally | plugin-security | Get: `canExport` is `true` | `canExport` |
108108
| 6 | Object-level read admission granted unconditionally | plugin-security | Get: `canReadObject` is `true`. This is the OBJECT-level half of a read — "may this caller read this object at all" — which the doors that bypass this middleware ask before they compile a statement of their own; `getReadFilter` is its row-level half, and the two are not interchangeable | `canReadObject` |
109109
| 6b | WRITE admission granted unconditionally | plugin-security | Get: `canWriteObject` is `true`. The WRITE twin of the object-level read admission above, asked by the write PREVIEW (`ObjectQL.validate()`), which runs no middleware for its target object and so has no gate of its own. It exists because a validation rule that reads one hop through a reference field is evaluated against a related row fetched under system authority, and that elevation is bounded to the arms the question RUNS — named, ⛔ never a category of the write decision, and ⛔ not a promise the write would succeed. The arms: the ADR-0103 engine-owned affordance gate and the ADR-0090 D12 delegated-admin gate (both ahead of every resolution), the fail-closed postures (#3545's unresolvable posture, the D10 dangling delegator and, on a walled posture, the D10 delegator who is not a member of the organization the request runs in), the ADR-0066 D3 capability arm, the CRUD grant, the ADR-0090 D10 delegator arm that a bare CRUD-grant check misses, the field-level-security write gate over the caller's payload when one is supplied, and the ADR-0123 D2 no-active-organization wall | `canWriteObject` |
@@ -617,6 +617,7 @@ and CI refuses one that differs from what the tree produces.
617617
| `packages/plugins/plugin-security/src/security-plugin-object-admission.ts#canWriteObject` | 1 | 6b |
618618
| `packages/plugins/plugin-security/src/security-plugin-read-filter.ts#getReadFilter` | 1 | 3 |
619619
| `packages/plugins/plugin-security/src/security-plugin-security-service.ts#registerSecurityService` | 3 | 7 |
620+
| `packages/plugins/plugin-security/src/security-plugin-withheld-field-readers.ts#computeMetadataReadableWithheldFields` | 1 | 4 |
620621
| `packages/plugins/plugin-security/src/security-plugin-write-tenant-wall.ts#writeWallVerdict` | 1 | 6c |
621622
| `packages/plugins/plugin-security/src/stored-permission-set-package-stamp.ts#holderLeftToEngine` | 1 | 23h |
622623
| `packages/plugins/plugin-security/src/stored-permission-set-package-stamp.ts#onUpdate` | 1 | 23h |

‎packages/metadata-core/src/object-schema-fls.test.ts‎

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* per-exit contract suites consume rather than re-derive.
66
*/
77

8-
import { describe, it, expect } from 'vitest';
8+
import { describe, it, expect, vi } from 'vitest';
99
import {
1010
ObjectSchemaMaskEvaluationError,
1111
actionObjectOverrideTargets,
@@ -721,3 +721,91 @@ describe('[decision 6840464379] an object whose owner declares a schemaReadDeleg
721721
expect(await bare.declaredDelegate('sys_request')).toBeUndefined();
722722
});
723723
});
724+
725+
describe('[ADR-0106 D1/D3, #34901] a disabled package\'s withheld fields, judged per caller', () => {
726+
/** A served object read whose package-disabled extension withholds two fields. */
727+
const SERVED = {
728+
name: 'deal',
729+
label: 'Deal',
730+
fields: { id: { type: 'text' }, amount: { type: 'number' } },
731+
_withheldFields: { crm_project: { packageId: 'com.acme.projects' }, crm_margin: { packageId: 'com.acme.projects' } },
732+
};
733+
const caller = { userId: 'u1', systemPermissions: [] as string[] };
734+
/** A service that reads every live field and admits `admitted` of the withheld ones. */
735+
const service = (admitted: string[] | undefined | (() => never)) => ({
736+
getMetadataReadableFields: async () => ['id', 'amount'],
737+
getMetadataReadableWithheldFields: async () => (typeof admitted === 'function' ? admitted() : admitted),
738+
});
739+
const servedTo = async (security: Record<string, unknown> | undefined, context: unknown = caller, telemetry?: Record<string, unknown>) => {
740+
const posture = await resolveObjectSchemaMaskPosture({ objectName: 'deal', context, security: security as any, enabled: true, telemetry: telemetry as any });
741+
return applyObjectSchemaMask(SERVED, posture);
742+
};
743+
744+
it('drops every entry the member does not admit, and the decoration with the last one', async () => {
745+
const some = await servedTo(service(['crm_margin']));
746+
expect((some.document as any)._withheldFields).toEqual({ crm_margin: { packageId: 'com.acme.projects' } });
747+
expect(some.document).not.toBe(SERVED);
748+
expect(SERVED._withheldFields, 'the cached document is never mutated').toHaveProperty('crm_project');
749+
const none = await servedTo(service([]));
750+
expect('_withheldFields' in (none.document as object)).toBe(false);
751+
// Nothing else moves: every live field, no denied field, not emptied.
752+
expect(Object.keys((none.document as any).fields)).toEqual(['id', 'amount']);
753+
expect({ denied: none.denied, emptied: none.emptied, hidden: none.hidden }).toEqual({ denied: [], emptied: false, hidden: false });
754+
});
755+
756+
it('an admitted caller is served the decoration whole, by reference, with no fingerprint', async () => {
757+
const all = await servedTo(service(['crm_project', 'crm_margin']));
758+
expect(all.document).toBe(SERVED);
759+
expect(all.fingerprint).toBe('');
760+
});
761+
762+
it('fails closed: a service without the member, an undefined answer and a throw each drop every entry', async () => {
763+
const warn = vi.fn();
764+
const cases = {
765+
'member absent': { getMetadataReadableFields: async () => ['id', 'amount'] },
766+
'undefined answer': service(undefined),
767+
throws: service(() => { throw new Error('security service unhealthy (test)'); }),
768+
};
769+
for (const [label, security] of Object.entries(cases)) {
770+
const masked = await servedTo(security, caller, { warn });
771+
expect('_withheldFields' in (masked.document as object), label).toBe(false);
772+
expect(Object.keys((masked.document as any).fields), label).toEqual(['id', 'amount']);
773+
}
774+
// A throw is no D6 fault — nothing the caller needs depends on it — and is said once, at warn.
775+
expect(warn.mock.calls.filter(([, meta]) => meta?.decision === 'drop-withheld-fields')).toHaveLength(1);
776+
});
777+
778+
it('a passthrough posture keeps the decoration: a D4-exempt caller, no security service, the D8 switch', async () => {
779+
const admin = { userId: 'u_admin', systemPermissions: [OBJECT_SCHEMA_MASK_EXEMPT_CAPABILITIES[0]] };
780+
expect((await servedTo(service([]), admin)).document).toBe(SERVED);
781+
expect((await servedTo(undefined)).document).toBe(SERVED);
782+
const disabled = await resolveObjectSchemaMaskPosture({ objectName: 'deal', context: caller, security: service([]) as any, enabled: false });
783+
expect(applyObjectSchemaMask(SERVED, disabled).document).toBe(SERVED);
784+
});
785+
786+
it('a project posture built without the answer drops every entry', () => {
787+
const masked = applyObjectSchemaMask(SERVED, { kind: 'project', readable: new Set(['id', 'amount']) });
788+
expect('_withheldFields' in (masked.document as object)).toBe(false);
789+
});
790+
791+
it('[D3] the ETag fingerprint differs between callers who see different withheld sets, and is equal for the same set', async () => {
792+
const a = await servedTo(service([]));
793+
const b = await servedTo(service(['crm_margin']));
794+
const c = await servedTo(service([]));
795+
expect(a.fingerprint).not.toBe('');
796+
expect(a.fingerprint).not.toBe(b.fingerprint);
797+
expect(a.fingerprint).toBe(c.fingerprint);
798+
// Qualified: a dropped withheld entry never hashes equal to a removed field of the same name.
799+
expect(a.fingerprint).not.toBe(objectFieldVisibilityFingerprint(['crm_margin', 'crm_project']));
800+
expect(foldVisibilityFingerprintIntoEtag('shared', a.fingerprint)).not.toBe(foldVisibilityFingerprintIntoEtag('shared', b.fingerprint));
801+
});
802+
803+
it('the member is asked once per posture, with the caller\'s context', async () => {
804+
const ask = vi.fn(async () => ['crm_margin']);
805+
await resolveObjectSchemaMaskPosture({
806+
objectName: 'deal', context: caller, enabled: true,
807+
security: { getMetadataReadableFields: async () => ['id', 'amount'], getMetadataReadableWithheldFields: ask } as any,
808+
});
809+
expect(ask.mock.calls).toEqual([['deal', caller]]);
810+
});
811+
});

0 commit comments

Comments
 (0)