Skip to content

Commit 870ce55

Browse files
fix(lint, metadata-protocol)!: an object publish that makes a field readonly while a live flow of its package writes it is refused (#32952)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DSSTCMHG96EByEM5ULvQjKY)_ Fixes #32666 Clause-②: yes (narrowing) — accept set narrowed at the runtime object write doors; the `@objectstack/lint` type surface grows by four optional fields reachable from the package entry: `ReferenceIntegrityRule.subjects`, `ReferenceIntegrityRunOptions.subjectPass`, `AuthoringRuleContext.subjectPass`, and `runRuntimeAuthoringRules`' `subjectObjects` argument. Metadata-protocol: narrowed Skills-docs: none — `skills/objectstack-automation` and `skills/objectstack-data` already teach that a `runAs: 'user'` write to a `readonly` field is stripped and that a flow maintaining one runs `runAs: 'system'`; the refusal names the flow and node and carries that remedy. The limit that callout leaves out (a button starts an elevated flow only as a `screen` or `api` flow; an autolaunched one answers 403) is #32832, open in the skills lane. ## 维护者速读 - **改了什么**:发布对象时(批量发布和直接保存两扇门),平台会把同一软件包里已上线的流程一起拿来检查:如果这次把某个字段改成只读,而某个以用户身份运行的流程还在写这个字段,发布直接被拒(422),报错里写明是哪个流程、哪个节点。字段改成「条件只读」(readonlyWhen)则只给提示、照常发布。 - **为什么改**:卡上的现象是「先上线流程、后把字段锁成只读」,对象照常发布,之后员工点按钮显示成功却什么也没改。按裁决 A(6837273204),在改只读的那一刻就告诉管理员哪个流程会失效。 - **风险与回滚**:这是一次收窄(以前能发布的对象现在可能被拒);`@objectstack/lint` 对外类型多了四个可选字段(`subjects`、两处 `subjectPass`、`subjectObjects`),所以 Clause-② 记为 yes。只追究这次发布新造成的冲突,租户上原本就存在的冲突不算在这次头上;别的软件包的流程不检查。示例库实测 0 误报(34 个对象、45 个流程)。只有「只读字段/流程」这一项判断会看到这些流程,对象的其他发布检查与改动前完全一致(复审后收窄)。每次发布对象多一次元数据读取;批量发布里有对象草稿时,每个流程草稿多读一次(未在生产库上测耗时)。回滚即 revert 本 PR。 - **先看**:`packages/lint/src/runtime-gate.ts`(流程只进单独的「判断对象」一轮,普通一轮与 main 一致;流程写入时路径保持 `flows[0]`)、`packages/metadata-protocol/src/runtime-authoring-gate.ts`(批量发布里被写对象的草稿只在那一轮里不当作「已存储版本」)、`packages/metadata-protocol/src/protocol-authoring-gate.ts`(只取本包流程)。 - **两分钟验证**:`pnpm --filter @objectstack/metadata-protocol exec vitest run src/protocol-publish-drafts-closure.test.ts -t "#32666"`,预期 13 条全部通过,其中「object made readonly after the flow went live is refused 422」两条覆盖两扇门,「confined: …」一条证明其他对象规则照旧。 - **需要你做的**:无,席位落地。 ## What changes The ruled letter A (ruling 6837273204): an OBJECT publish carries the written package's live flows into the same `flow-update-readonly-field` (and `-when`) judgment a flow publish runs, and refuses only the conflicts this write newly causes. - **`packages/lint` — the member.** `validateReadonlyFlowWrites` in the reference-integrity suite declares `runtimeTypes: ['flow', 'object']`, the way `validateObjectFieldRefs` already does, and `subjects: ['flows']` (new `ReferenceIntegrityRule.subjects`). The `object` member roster pin in `runtime-gate.object-writes.test.ts` names it as the seventh crossing. - **`packages/lint` — the subject pass (review round 1).** The gate withholds every judged-subject collection (`SUBJECT_ONLY_CONTEXT_KEYS`) from its ordinary differential, so every rule of the object door, `validatePresetComparands` and `validateStackExpressions` included, judges exactly the snapshot it judged on main. A separate SUBJECT differential (same baseline / stored / candidate passes) runs only the reference-integrity entry (`SUBJECT_PASS_ENTRIES`) with `subjectPass: true`, and the suite then runs only members declaring `subjects`. `runRuntimeAuthoringRules` gains `subjectObjects`: the objects that pass judges against when they differ from `context.objects`. - **`packages/lint` — the snapshot.** `RuntimeStackContext` gains `flows?` (judged subjects of an object write). The docblock's admission rule ("only collections a rule's resolution references enter the context") is reworded to admit judged subjects, and states the three properties that keep the admission narrow (condition 2 of the ruling). `CONTEXT_STACK_KEY_ORDER` gains `flows` last, so the four existing collections keep their order and the derived pattern source. - **`packages/lint` — flow writes stay positional.** New `SUBJECT_ONLY_CONTEXT_KEYS = {'flows'}`: on a `flow` write the gate drops any passed `flows` context, so the written flow is the sole member and `flows[0]` IS the write; `nameKeyFindingPath` takes the written stack key and keeps that index positional. On an object write, a finding on a carried flow is name-keyed (`flows.FLOW_NAME.nodes[1].config.fields.status`), since the index is the gate's private snapshot slot. - **`packages/metadata-protocol` — the host gather.** `judgeRuntimeAuthoringRules` reads `listCollection('flow', 'flows')` on an OBJECT write only, in the same `Promise.all` as the other four reads, and keeps the flows whose `_packageId` is the written package (`flowsOfWrittenPackage`; a package-less write meets package-less flows). Flows of other packages are out of scope. - **`packages/metadata-protocol` — the batch.** `CLOSURE_CONTEXT_KEY_BY_TYPE` gains `flow: 'flows'` and the `-?` pending literal gains `flows: []` (both forced by the compile-time completeness guards). `objectWriteFlowSubjects` subtracts the flows the batch redrafts from the live set: a redrafted flow is its own write's to answer for, and judging its stale live copy would refuse the one-batch way out. Pending flows are never added as subjects, so the existing "flow and object drafted in ONE batch" pin still names the flow as the causal item. - **`packages/metadata-protocol` — the stored universe of the subject pass.** On an object write that carries flows, the host hands the batch fold WITHOUT the written object's own draft as `subjectObjects`; `context.objects` keeps the full fold, exactly as on main. The batch folds the written draft into the context, so the gate's stored self (#22118) IS the candidate and a finding the write adds on another entry cancels against itself; that is still what every other object-door rule sees (a draft that breaks a live sibling under them publishes as on main, pinned). Only the subject pass judges against the written object's live body, the universe the live save door already judges against. Round 1 left the draft out for every rule, which widened refusals at publish-drafts; the review probe confirmed it (an object draft dropping a column a live lookup's `lookupColumns` names: refused `object-field-ref-unknown` at `495824e8`, published with main's gate files) and round 2 publishes it. - **`packages/metadata-protocol` — the flow-draft read.** `collectBatchPendingDeclarations` reads a flow draft only in a batch that also holds an object draft, the one case `pending.flows` is read (`objectWriteFlowSubjects`). A batch without an object draft pays no extra read. - **`packages/spec`** — ADR-0087 D3 semantic entry `object-readonly-field-written-by-live-flow-refused`. - Changeset: minor for `@objectstack/lint`, `@objectstack/metadata-protocol`, `@objectstack/spec`, with the BREAKING banner and migration. ## Tests - `packages/lint/src/runtime-gate.object-readonly-flow-writes.test.ts` (new, 9): the reverse order refuses with the name-keyed path; `readonlyWhen` gives the `-when` advisory and no refusal; the way out (flow already `runAs: 'system'`) is clean; a conflict already in the stored universe is not charged to a label edit; an object write handed no flows judges none; a flow write ignores a passed `flows` context and keeps `flows[0]`; the fence (an object write turning a field into a `date` while a carried flow filters on it with a preset name gets no `validatePresetComparands` finding); `subjectObjects` (the fold with the written draft cancels, the subject objects refuse); the suite on its subject pass runs only subject-declaring members. - `packages/metadata-protocol/src/protocol-publish-drafts-closure.test.ts` (9 new door pins): publish-drafts refuses the reverse order 422 `INVALID_METADATA`; the live save refuses it 422; `readonlyWhen` publishes with the `-when` advisory; the way out (flow elevated and published first, then the field made readonly) publishes clean; the way out in ONE batch publishes clean; a conflict already on the tenant (made through `OS_ALLOW_UNLINTED_METADATA_WRITES`) does not refuse a label edit; a flow of another package is out of scope; a flow redrafted UNFIXED in the same batch is the causal item, refused `INVALID_METADATA` with `flow-update-readonly-field` at `flows[0]…`; confinement: a master draft dropping a column a live detail's `lookupColumns` names publishes, as on main, with a live flow in the package. - Pins moved with the widened context set: `runtime-gate.test.ts`, `runtime-gate.derived-context-keys.test.ts`, `runtime-gate.derived-name-keys.test.ts`, `runtime-gate.object-writes.test.ts`. ## Acceptance notes - **False positives on the shipped corpus (condition 2): 0.** Every object in `examples/app-crm`, `app-multi-package` (both packages), `app-showcase`, `app-todo` and `packages/apps/connector-{docusign,github,stripe}` was written through `runRuntimeAuthoringRules` as an update and as a create, with and without its package's flows: 34 objects, 45 flows, 68 object writes, 0 findings added by the flows. Positive controls (lock the first field a `runAs: 'user'` `update_record` of that package writes): 4 of 4 refused. `packages/apps/account`, `setup` and `studio` have no `objectstack.config.ts` and declare no flows. - **Other object-dispatched rules that read `stack.flows`.** None sees the carried flows: they are withheld from the ordinary differential, and the subject pass runs only `validateReadonlyFlowWrites` (pinned, ablations F1 and F2). The census above was rerun on the round-2 head: same 0 added, 4 of 4 controls. - **Cost:** one more indexed `sys_metadata` read per object publish, issued with the four existing reads, plus a registry walk; on a package publish holding an object draft, one draft-row read per flow draft in the batch (none in a batch without an object draft); and, on an object write carrying a non-empty flow set, one more three-pass run of the one suite entry. Not measured on a production store. - **Limits (D3 entry states them):** flows of other packages are not judged; a package-less tenant overlay save meets only package-less flows, so locking a field of a packaged object through such an overlay is not judged against that package's flows. - **Out of scope, by the ruling:** hook and action bodies that write readonly fields, flows of other packages, tenants already in the broken state. Option C (the person who clicked is told) is #32861. ## Verification Round 2 on head `13c704fe` (review record 6839975695; main not merged again, no conflict). Round 3 (delta review 6841160520) changes only the changeset's declarations; the changeset and clause-② gate families and `check-adr-0087-registration` were rerun on its head (listed at the end of the gates block). - `pnpm --filter @objectstack/lint test`: 8591 tests passed. `pnpm --filter @objectstack/metadata-protocol test`: 22799 passed, 36 skipped. Both typechecks exit 0. - Full dogfood battery (`(narrowing)` arm) under the lock: VERDICT command-exit 0; 456 files passed / 3 skipped, 3831 tests passed / 42 skipped. - `node scripts/pm/dispatch-gates.mjs --commands`: 93 families derived (round 1's 92 plus `check:cli-command-ids`), all run, all exit 0. `--ran`: 93 derived, 93 run, 0 NOT-MEASURED, 0 UNRUN. - Corpus census rerun on the round-2 head: 34 objects, 45 flows, 68 object writes, 0 findings added; 4 of 4 positive controls refused. <details><summary>Ablations (one per new behaviour, each through <code>scripts/ablation-replace.mjs</code>, restored to the HEAD blob)</summary> | # | Mutation | Result | |---|---|---| | A1 | member `runtimeTypes` back to `['flow']` | lint pins: refusal and `-when` advisory red (2 failed) | | A2 | flow-write drop of the `flows` context removed | lint pin: flow write path red (1 failed) | | A3 | name-key guard for a subject's own write removed | name-key pin red (1 failed) | | A4 | host gather off | door pins red (publish-drafts, live save, `-when`: 3 failed) | | A5 | package filter accepts every flow | other-package pin red (1 failed) | | A6 | redrafted-flow subtraction removed | one-batch way-out pin red (1 failed). First run was a no-op: the pin staged the flow first, so its promotion was already live when the object was judged; the pin now stages the object first and the rerun went red | | A7 | (round 1) written draft folded back into the object-write context | publish-drafts refusal and `-when` pins red (2 failed) | | C1 | (round 2) confinement removed: `context.objects` takes `subjectObjects` again, as round 1 did | confinement door pin red (1 failed) | | C2 | (round 2) host stops handing `subjectObjects` | publish-drafts refusal and `-when` pins red (2 failed) | | F1 | (round 2) fence removed: carried flows stay in the ordinary differential | refusal, `-when` (finding now doubled) and the `validatePresetComparands` fence pin red (3 failed) | | F2 | (round 2) suite member filter on the subject pass removed | subject-pass member pin red (1 failed). No shipped object-dispatched member other than `validateReadonlyFlowWrites` reads `flows` (probed), so this filter is the in-suite guard for the next one | </details> <details><summary>Gates ran</summary> ``` node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-adoption.mjs :: exit 0 node scripts/check-comment-mask-adoption.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-dev-prereqs.mjs --self-test :: exit 0 node scripts/check-dts-emitted.mjs --self-test :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 node scripts/check-issue-citations.mjs :: exit 0 node scripts/check-plugin-teardown-shape.mjs :: exit 0 node scripts/check-plugin-teardown-shape.mjs --self-test :: exit 0 node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0 node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0 node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0 node scripts/ci/snapshot-next.mjs --self-test :: exit 0 node scripts/docs-audit/check-affected-docs.mjs :: exit 0 node scripts/docs-audit/check-drift-comment.mjs :: exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0 node scripts/release-pending-publish.mjs --self-test :: exit 0 pnpm --filter @objectstack/lint run check:doc-formula-expressions :: exit 0 pnpm --filter @objectstack/spec run check:api-surface :: exit 0 pnpm --filter @objectstack/spec run check:authorable-surface :: exit 0 pnpm --filter @objectstack/spec run check:browser-reachable-entries :: exit 0 pnpm --filter @objectstack/spec run check:docs :: exit 0 pnpm --filter @objectstack/spec run check:dual-source-exports :: exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0 pnpm --filter @objectstack/spec run check:empty-state :: exit 0 pnpm --filter @objectstack/spec run check:entry-nameability :: exit 0 pnpm --filter @objectstack/spec run check:error-code-provenance :: exit 0 pnpm --filter @objectstack/spec run check:export-origins :: exit 0 pnpm --filter @objectstack/spec run check:exported-any :: exit 0 pnpm --filter @objectstack/spec run check:liveness :: exit 0 pnpm --filter @objectstack/spec run check:llms-txt :: exit 0 pnpm --filter @objectstack/spec run check:skill-refs :: exit 0 pnpm --filter @objectstack/spec run check:spec-changes :: exit 0 pnpm --filter @objectstack/spec run check:strictness-ledger :: exit 0 pnpm --filter @objectstack/spec run check:upgrade-guide :: exit 0 pnpm --filter @objectstack/spec run check:variant-docs :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 pnpm check:ci-filter-parity :: exit 0 pnpm check:cli-command-ids :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:dispatcher-error-vocabulary :: exit 0 pnpm check:doc-authoring :: exit 0 pnpm check:docs-transcript-drift :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:dts-closure :: exit 0 pnpm check:dual-build-cjs-loads :: exit 0 pnpm check:durability-log-level :: exit 0 pnpm check:engine-double-contract :: exit 0 pnpm check:error-status-conformance :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:init-service-contract :: exit 0 pnpm check:issue-citations :: exit 0 pnpm check:keyed-text-bounds :: exit 0 pnpm check:lean-entry-closure :: exit 0 pnpm check:logger-receiver-detach :: exit 0 pnpm check:merge-driver :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:object-def-param-keys :: exit 0 pnpm check:objectql-double-limit :: exit 0 pnpm check:optional-error-sink :: exit 0 pnpm check:org-identifier :: exit 0 pnpm check:page-declaration-shape :: exit 0 pnpm check:platform-object-tenancy-census :: exit 0 pnpm check:pm-prior-rulings :: exit 0 pnpm check:published-files :: exit 0 pnpm check:query-options-erasure :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:registry-log-declared :: exit 0 pnpm check:rest-log-spy-declared :: exit 0 pnpm check:role-word :: exit 0 pnpm check:settings-bind-window :: exit 0 pnpm check:slot-lookup :: exit 0 pnpm check:sourcemap-no-sources-content :: exit 0 pnpm check:spec-docblock-symbol-anchors :: exit 0 pnpm check:spec-parsed-alias :: exit 0 pnpm check:startup-registry-verdict :: exit 0 pnpm check:system-context-census :: exit 0 pnpm check:test-source-alias :: exit 0 pnpm check:tier-file-adoption :: exit 0 pnpm check:type-check-coverage :: exit 0 pnpm check:type-check-debt :: exit 0 pnpm check:undeclared-dep-imports :: exit 0 pnpm check:vouch-for-reference-callers :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm check:where-matcher :: exit 0 pnpm check:wildcard-fallthrough :: exit 0 # round 3 (changeset declarations only), head c5c41e4 node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 node scripts/pm/clause2-line.mjs --self-test :: exit 0 ``` </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (one D3 migration entry, data only) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` is CI's run. - [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. (a migration entry only: `gen:migration-registry` writes gitignored output; `check:spec-changes` / `check:upgrade-guide` exit 0) - [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. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4cyHr6StnLZNnnjngzY <!-- signed: domain:spec#3 · os-elon-musk · session_016WV4d1T5HEokjRgR6vCBX8 --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent c8c76f8 commit 870ce55

14 files changed

Lines changed: 896 additions & 48 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
'@objectstack/lint': minor
3+
'@objectstack/metadata-protocol': minor
4+
'@objectstack/spec': minor
5+
---
6+
7+
fix(lint, metadata-protocol)!: an object publish that makes a field readonly while a live flow of the same package writes it as the user is refused, naming the flow, instead of publishing clean and leaving the flow's button to succeed and change nothing
8+
9+
Clause-②: yes (narrowing) — the runtime object write doors (package publish and the live save) refuse an object they accepted before: one that makes a field `readonly` while a live `runAs: 'user'` flow of the same package writes it from an `update_record` or `create_record` node. A field made `readonlyWhen` publishes with the `flow-update-readonly-when-field` advisory. Only conflicts the write adds are charged: a conflict already on the tenant is not. Measured first-party: 0 (34 objects and 45 flows across `examples/*` and `packages/apps/*`, each object written as an update and as a create; 4 of 4 positive controls refused). The accept set at the doors only narrows; the `yes` is the `@objectstack/lint` type surface, which grows by four optional fields, each reachable from the package entry: `ReferenceIntegrityRule.subjects`, `ReferenceIntegrityRunOptions.subjectPass`, `AuthoringRuleContext.subjectPass`, and the `subjectObjects` argument of `runRuntimeAuthoringRules`. Omitted, each leaves a caller's verdict as it was.
10+
Metadata-protocol: narrowed
11+
Skills-docs: none — `skills/objectstack-automation` and `skills/objectstack-data` already teach that a `runAs: 'user'` write to a `readonly` field is stripped and that a flow maintaining one runs `runAs: 'system'`; the refusal names the flow and node and carries that remedy. The limit that callout leaves out (a button starts an elevated flow only as a `screen` or `api` flow; an autolaunched one answers 403) is #32832, open in the skills lane.
12+
13+
<!-- adr-0087: registered object-readonly-field-written-by-live-flow-refused -->
14+
15+
**BREAKING** accept-set narrowing at the runtime object write doors: `POST /api/v1/packages/:id/publish-drafts` and the active save of an object.
16+
17+
A `runAs: 'user'` flow that writes a `readonly` field is a silent no-op at run time: the engine strips the field and the step reports success. A flow write was already refused for it. The reverse order was not: the flow went live while the field was writable, then the object made it readonly, and the object published clean.
18+
19+
- The `validateReadonlyFlowWrites` member of the reference-integrity suite now judges `object` writes as well as `flow` writes (`flow-update-readonly-field` at `error`, `flow-update-readonly-when-field` at `warning`).
20+
- On an object write the host carries the written package's live flows (`RuntimeStackContext.flows`, a new optional key) as the subjects that rule judges. Flows of other packages are not carried. A flow the same batch redrafts is judged on its own write, not as a subject. The finding is located on the flow by name, e.g. `flows.leave_submit.nodes[1].config.fields.status`.
21+
- The carried flows are judged in a separate subject pass: the gate runs the reference-integrity suite with `subjectPass: true` (new on `AuthoringRuleContext` and `ReferenceIntegrityRunOptions`), and the suite then runs only the members declaring them (`ReferenceIntegrityRule.subjects`, new). `runRuntimeAuthoringRules` gains `subjectObjects`, the objects that pass judges against. Every other rule of the object door judges exactly the snapshot it judged before, so no other refusal or advisory moves.
22+
- A flow write is unchanged: it is handed no flows, and its findings keep the positional `flows[0]` path.
23+
- Cost: one more indexed `sys_metadata` read per object publish (issued together with the four the gate already makes), and on a package publish holding an object draft one draft read per flow draft in the batch; a batch with no object draft reads none. Not measured on a production store.
24+
25+
Migration: before making a field readonly, publish the flow that writes it with `runAs: 'system'` (a button or action starts an elevated flow only as a `screen` or `api` flow, or through a `subflow` node), remove the field from the flow's node, or keep the field writable.

‎packages/lint/src/authoring-rules.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,14 @@ export interface AuthoringRuleContext {
354354
* platform names, a platform-prefixed name advised at `warning`) applies.
355355
*/
356356
runtimeWriteType?: string;
357+
/**
358+
* [#32666] Set by the runtime gate on its SUBJECT pass only, which judges
359+
* the subject collections it withholds from every other pass
360+
* (`RuntimeStackContext.flows` on an object write). Read by the
361+
* reference-integrity suite, the one entry whose members declare a subject;
362+
* the gate runs no other entry on that pass.
363+
*/
364+
subjectPass?: boolean;
357365
/**
358366
* [#16546] `hooks[*].handler` ref strings whose metadata `body` was minted
359367
* by `lowerCallables` from the author's inline `handler` function, rather

‎packages/lint/src/reference-integrity-suite.ts‎

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@
8585
* given per-write snapshot is the suite's own, finer axis —
8686
* `ReferenceIntegrityRule.runtimeTypes`, default `['flow']` — because the
8787
* snapshot deliberately carries only the measured context collections
88-
* (objects / permissions / books / datasets), and a member resolving against
88+
* (objects / permissions / books / datasets, and [#32666] on an object write
89+
* the written package's flows, which only a member declaring `subjects` sees,
90+
* on the gate's separate subject pass), and a member resolving against
8991
* any other collection would read every reference into it as dead. The CLI
9092
* commands ignore the axis entirely: a whole-stack run is always the full
9193
* suite.
@@ -165,7 +167,9 @@ export interface ReferenceIntegrityRule {
165167
* gate. This field is the finer axis the entry cannot express: which MEMBERS
166168
* are safe to judge that per-write snapshot. The two axes differ because the
167169
* snapshot is partial by design (`RuntimeStackContext` carries objects /
168-
* permissions / books / datasets and nothing else): a member that resolves
170+
* permissions / books / datasets — plus [#32666] the written package's flows
171+
* on an object write, judged only by the members declaring them in
172+
* {@link ReferenceIntegrityRule.subjects} — and nothing else): a member that resolves
169173
* against a collection the snapshot does not carry would not go quiet — it
170174
* would report every reference into that collection as dead. Measured on the
171175
* `view` widening: `validateActionNameRefs` resolves the action names in
@@ -185,6 +189,15 @@ export interface ReferenceIntegrityRule {
185189
* {@link validateReferenceIntegrity}).
186190
*/
187191
runtimeTypes?: readonly string[];
192+
/**
193+
* [#32666] The context collections this member judges as SUBJECTS — entries
194+
* the written item can break without touching them (`RuntimeStackContext.flows`
195+
* on an object write). The runtime gate withholds those collections from its
196+
* ordinary pass and judges them in a separate subject pass, which runs only
197+
* the members declaring them (see {@link ReferenceIntegrityRunOptions.subjectPass}),
198+
* so no other rule of the door ever reads a carried subject. ABSENT = none.
199+
*/
200+
subjects?: readonly string[];
188201
/**
189202
* `ctx` is the same {@link ReferenceIntegrityRunOptions} `validateReferenceIntegrity`
190203
* received — optional because most members read only `stack`; the two hook
@@ -753,7 +766,26 @@ export const REFERENCE_INTEGRITY_RULES: readonly ReferenceIntegrityRule[] = [
753766
// `os validate` refuses — and this one gates, so the divergence shipped a
754767
// build the other command would have stopped. Joining the suite is the whole
755768
// fix; the two hand-wired call sites are deleted with it (#4345 follow-up).
756-
{ name: 'validateReadonlyFlowWrites', run: validateReadonlyFlowWrites },
769+
//
770+
// [#32666] `runtimeTypes` gains `object`, as `validateObjectFieldRefs` above
771+
// has it, and for the reverse of the order the flow write judges: a live
772+
// `runAs:'user'` flow writes `status`, then the OBJECT makes `status`
773+
// readonly. The flow is untouched, so its own write never runs again, and
774+
// the object write was the one place left to say so. On an object write the
775+
// host carries the written package's live flows as judged subjects
776+
// (`RuntimeStackContext.flows`), and the gate's differential charges the
777+
// object write only with the findings it ADDS — a flow already broken on the
778+
// tenant sits in the stored universe and cancels. MEASURED over the shipped
779+
// corpus: 0 findings on any object write (the PR carries the census).
780+
// `flow` for the floor, unchanged. `subjects: ['flows']` is what lets it, and
781+
// only it, see the carried flows: the gate's subject pass runs the members
782+
// declaring a subject and nothing else.
783+
{
784+
name: 'validateReadonlyFlowWrites',
785+
runtimeTypes: ['flow', 'object'],
786+
subjects: ['flows'],
787+
run: validateReadonlyFlowWrites,
788+
},
757789
// [commit 36d287803] The SAME question as the member above, on the surface that had no
758790
// answer for it: a hook body's `ctx.api.object('x').update({ readonlyField })`.
759791
// A hook's `ctx.api` is a ScopedContext over the TRIGGERING operation's
@@ -839,6 +871,12 @@ export interface ReferenceIntegrityRunOptions {
839871
* caller, which run all members unconditionally.
840872
*/
841873
runtimeWriteType?: string;
874+
/**
875+
* [#32666] Set by the runtime gate on its SUBJECT pass only: run just the
876+
* members declaring a {@link ReferenceIntegrityRule.subjects} collection.
877+
* Spells the same key as `AuthoringRuleContext.subjectPass`.
878+
*/
879+
subjectPass?: boolean;
842880
/**
843881
* [#16546] `hooks[*].handler` ref strings whose metadata `body` was minted
844882
* by `lowerCallables` from the author's inline `handler` function — spells
@@ -881,6 +919,8 @@ export function validateReferenceIntegrity(
881919
for (const rule of REFERENCE_INTEGRITY_RULES) {
882920
if (writeType !== undefined
883921
&& !(rule.runtimeTypes ?? DEFAULT_MEMBER_RUNTIME_TYPES).includes(writeType)) continue;
922+
// [#32666] The subject pass judges the carried subjects and nothing else.
923+
if (options?.subjectPass === true && !(rule.subjects && rule.subjects.length > 0)) continue;
884924
findings.push(...rule.run(stack, options));
885925
}
886926
return findings;

‎packages/lint/src/runtime-gate.derived-context-keys.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ describe('the derived context-collection set (#13977)', () => {
7575
// being relaxed to a subset check: naming the whole set in order is the
7676
// only thing this pin does, so a removal has to be written here the same
7777
// way #13216's addition was.
78-
expect(carriedStackKeys()).toEqual(['objects', 'permissions', 'books', 'datasets']);
78+
//
79+
// [#32666] `flows` joins LAST, as judged subjects of an object write; the
80+
// four ahead of it keep their positions.
81+
expect(carriedStackKeys()).toEqual(['objects', 'permissions', 'books', 'datasets', 'flows']);
7982
});
8083

8184
it('derives the same set whatever the write is, since the write does not choose it', () => {
@@ -114,9 +117,13 @@ describe('the derived context-collection set (#13977)', () => {
114117
permissions: [{ name: 'sales' }],
115118
books: [{ name: 'handbook' }],
116119
datasets: [{ name: 'revenue' }],
120+
flows: [{ name: 'acme_flow' }],
117121
pages: [{ name: 'home' }],
118122
};
119-
const baseline = buildRuntimeWriteSnapshots({ type: 'flow', item: { name: 'f1' }, context })!.baseline;
123+
// [#32666] A `view` write, a type outside every context collection: on a
124+
// `flow` write the gate drops the context's flows by design
125+
// (`SUBJECT_ONLY_CONTEXT_KEYS`), which is not the validity question here.
126+
const baseline = buildRuntimeWriteSnapshots({ type: 'view', item: { name: 'v1' }, context })!.baseline;
120127

121128
for (const key of carriedStackKeys()) {
122129
expect(context).toHaveProperty(key);

‎packages/lint/src/runtime-gate.derived-name-keys.test.ts‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ describe('the derived name-keyed set (#13390)', () => {
6565
'permissions',
6666
'books',
6767
'datasets',
68+
// [#32666] Carried as judged subjects of an object write.
69+
'flows',
6870
]);
6971
});
7072

@@ -104,11 +106,22 @@ describe('the derived name-keyed set (#13390)', () => {
104106
});
105107

106108
it('a write type mapping onto a NON-context key contributes nothing', () => {
107-
// `flow` -> `flows` is a real mapping onto a collection the context never
108-
// fills; `flows[0]` IS the write, trivially stable, and must stay positional.
109-
expect(deriveNameKeyedStackKeys(['objects'], ['objects', 'flows'])).toEqual(['objects']);
110-
expect(nameKeyFindingPath('flows[0].name', { flows: [{ name: 'acme_flow' }] })).toBe(
111-
'flows[0].name',
109+
// `view` -> `views` is a real mapping onto a collection the context never
110+
// fills; `views[0]` IS the write, trivially stable, and must stay positional.
111+
// [#32666] It used `flows`, which the context now fills on an object write.
112+
expect(deriveNameKeyedStackKeys(['objects'], ['objects', 'views'])).toEqual(['objects']);
113+
expect(nameKeyFindingPath('views[0].name', { views: [{ name: 'acme_view' }] })).toBe(
114+
'views[0].name',
115+
);
116+
});
117+
118+
it('[#32666] a judged-subject collection keeps its index on a write of its own type', () => {
119+
const candidate = { flows: [{ name: 'acme_flow' }] };
120+
// A flow write: the context copy was dropped, `flows[0]` IS the write.
121+
expect(nameKeyFindingPath('flows[0].nodes[1].config', candidate, 'flows')).toBe('flows[0].nodes[1].config');
122+
// An object write: the flow is a subject, keyed by its name on the wire.
123+
expect(nameKeyFindingPath('flows[0].nodes[1].config', candidate, 'objects')).toBe(
124+
'flows.acme_flow.nodes[1].config',
112125
);
113126
});
114127

0 commit comments

Comments
 (0)