Repository navigation
Commit 8feef82
fix(plugin-sharing)!: refuse a sharing-rule criteria that compares a choice field with an option label (#39543)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DMmPgXVVfb8MdCS5amdMX6N)_
Fixes #39434
Refs #39418
Clause-②: yes (narrowing)
Metadata-protocol: none
Skills-docs: follow-up #39583 —
content/docs/permissions/sharing-rules.mdx (the page lists each
save-time refusal on this door; outside this claim's file surface). No
`skills/**` change owed: the skills teach declared `stack.sharingRules`
CEL conditions, which are not `sys_sharing_rule` rows and never pass
this door.
`Metadata-protocol: none` is provisional, as the ruling leaves it:
narrowed versus none is the contract reviewer's. Both same-door
precedents declared `none` (PR #30953, the object-enforcement refusal;
PR #39361, the user-recipient refusal), because a `sys_sharing_rule` row
is an organization's data, not package metadata.
## 维护者速读
- 管理员或替他搭应用的 AI
在共享规则里把下拉、单选、多选字段的「显示名」当成值写(例如写「紧急」而记录里存的是内部值),以前照常保存却一条都不共享(取反写法则反过来共享给所有记录),现在保存时当场被拒,并告诉他该写哪个值。
-
属于共享规则「存得进却永远不生效」这一类问题的收口,替报修单场景里发现规则静默失效的管理员解决(上一张卡已补界面上的选项选择器,这次补接口和手写条件)。
- 只影响新保存或改了条件的规则;已存的旧规则照常加载、照常可以停用;如果误拦,撤回这一个改动即可恢复原样。
- 需要你确认这是一个破坏性收紧(保存时拒绝)并在合并前给出同意。
## What changes
A sharing rule's criteria that compares a choice field with one of its
option **labels**, where the records hold the option's **value**, is
refused at save, at both `sys_sharing_rule` doors, with one sentence
naming the field, the label written and the value to write. Maintainer
ruling recorded on the card (comment 7403149741, option A), verbatim:
> 「refuse a `sys_sharing_rule` save when a criteria literal on a choice
field is an option label where the row holds the value. The refusal
names the value to write. Judged only when the criteria change.」
- New module `plugin-sharing/src/rule-criteria-option-label.ts`: the
label reading (the one `flow-condition-option-label` defined for flows,
read from the runtime registry via `engine.getSchema`), the refusal
sentence, and `sameCriteria` (key order and string-or-object spelling
aside).
- `/data` door: `bindRuleCriteriaGuard` (`rule-hooks.ts`) refuses
`VALIDATION_FAILED` (400) with one `fields` entry `{ field:
'criteria_json', code: 'invalid_option' }`, after its existing match-all
check.
- `POST /sharing/rules`: `defineRule` (`sharing-rule-service.ts`) throws
an error whose message is `VALIDATION_FAILED: ` followed by the same
sentence, which the route already maps to 400.
- Judged on insert, and on update/upsert only when the supplied criteria
differs from the stored one. System-context writes are judged too, like
the match-all check in the same guard (and unlike the object and
recipient guards): the verdict depends on the criteria alone. A first
draft skipped system writes; `check:system-context-census` then required
a new row on `content/docs/permissions/system-context.mdx` (outside this
claim) for that elevation read, and judging every caller is the more
consistent reading anyway. Pinned both ways (ablation 3).
**Scope (as ruled).** Fields: `select`, `radio`, `multiselect`,
`checkboxes` of the rule's object, inline non-empty options, not
`readonly`, not bound to a shared `picklist`. A literal equal to an
option's label that is also some option's value is **not** a
label-for-value mistake and is accepted (pinned: `stage: 'open'` where
`open` is one option's label and another's value). A literal that is
neither a value nor a label is accepted unchanged (the spec admits
stored values outside the options, `createMissingOptions`).
**Comparand shapes, enumerated from the filter grammar
(`FILTER_OPERATORS`, `LOGICAL_OPERATORS`) and the drivers' multi-value
semantics:**
| Shape | Covered | Why |
|:--|:--|:--|
| bare `F: L`, `$eq`, `$in` (each member) on a single-value field | yes
| positive: shares nothing (measured) |
| `$ne`, `$nin` (each member) on a single-value field | yes | negated:
shares every record (measured, below) |
| `$contains`, `$notContains` on a multi-value field | yes | the
membership tests the engine runs on a JSON-stored column |
| anywhere under `$and` / `$or` / `$not` | yes | walked at any depth |
| equality family on a multi-value field | no | the engine refuses
equality on a JSON-stored column for a reason of its own; naming a value
would not make the rule run |
|
`$contains`/`$notContains`/`$startsWith`/`$endsWith`/`$icontains`/`$like`/`$ilike`
on a single-value field | no | a pattern names no option, and its text
may legitimately sit inside a value |
| `$gt`/`$gte`/`$lt`/`$lte`/`$between` | no | order text, claim no
option |
| `$null`/`$exists`/`$empty` | no | no literal |
| array (AST) spelling `['F','=','L']` | not reached | both doors
already refuse it first as a criteria that narrows nothing
(`isMatchAllCriteria`), measured while writing the pins |
| dotted path (`owner.status`) | no | not a field of the rule's object |
<details><summary>Carried item 2: negated comparands measured first
(over-share)</summary>
Real `ObjectQL` + `SqlDriver` (better-sqlite3), five repair orders
(three `gao`, two `jinji`), a rule row stored as before this guard,
`evaluateRule`, then `sys_record_share` read off the driver:
- `{"jinji_chengdu":{"$ne":"紧急"}}` → grants on all 5 records (the 2
urgent ones the author meant to exclude included); control `$ne:
"jinji"` → the 3 non-urgent.
- `{"jinji_chengdu":{"$nin":["紧急"]}}` → all 5; control `$nin: ["jinji"]`
→ the 3 non-urgent.
- bare / `$eq` / `$in` on the label → 0; control on the value → the 2
urgent.
These eight cases are pinned in the first `describe` of the new test and
passed both before and after the fix (they measure the evaluator, not
the guard).
</details>
## Tests
New file
`packages/plugins/plugin-sharing/src/sharing-rule-option-label-39434.test.ts`
(30 cases): the measurement above; the /data door refusing bare, `$eq`,
`$ne`, `$in`, `$nin`, nested `$and`/`$or`/`$not`, multiselect
`$contains`, checkboxes `$notContains`, each naming the value; controls
(value; value under `$ne`/`$in`; a literal outside values and labels; a
label that is also a value; a readonly choice field; a non-choice field;
a substring operator); an update changing criteria to a label refused
with the row kept; a criteria-untouched update on a legacy label row
saved (also with the unchanged criteria re-sent); `defineRule` refusing
with the /data door's sentence behind `VALIDATION_FAILED: `; an upsert
keeping a stored label criteria saved and one changing to a label
refused; the system context judged at both doors.
<details><summary>Red-first, green, ablations</summary>
- Red at `10ad9101` (test only): `Tests 13 failed | 17 passed (30)` —
every refusal case red, every measurement and control green.
- Green at `da6cbc17`: `pnpm --filter @objectstack/plugin-sharing test`
→ `Test Files 84 passed (84)` / `Tests 1828 passed | 11 skipped (1839)`;
`pnpm --filter @objectstack/plugin-sharing typecheck` → exit 0
(`check:test-typecheck: OK`).
- Ablation 1 (`scripts/ablation-replace.mjs`, mutation landed anchor 1 →
0, restored blob == HEAD): `$ne` dropped from the single-value scalar
set → `Tests 3 failed | 26 passed (29)` (run before the system-context
case was added) (the `$ne` /data, the update-to-`$ne`, the `$ne`
defineRule cases).
- Ablation 2: the /data door's `sameCriteria` skip deleted → `Tests 1
failed | 28 passed (29)` (the criteria-untouched update on a legacy
label row).
- Ablation 3: an `isSystem` skip re-inserted in the /data guard → `Tests
1 failed | 29 passed (30)` (the system-context case); restored blob ==
HEAD, `git diff HEAD` empty.
</details>
## Acceptance notes
- `content/docs/permissions/sharing-rules.mdx` describes each save-time
refusal on this door; this one is not added there (outside the claim's
file surface) — filed as #39583.
- Picklist-bound fields are skipped as ruled (analysis 7399582338
scope). At runtime the registry folds a picklist's options into the
field, so the same reading would be sound there; widening is a later
decision, not taken here.
- "Judged only when the criteria change" is read literally: an update
that moves a rule to another object without touching `criteria_json` is
not judged by this check.
- The option reading duplicates `selectOptionsOf` in `@objectstack/lint`
(`flow-select-options.ts`): plugin-sharing does not depend on
`@objectstack/lint`, that helper is not exported from its index, and
`packages/lint/src/**` is outside this claim.
- A label in a declared `stack.sharingRules` CEL condition is not judged
here (declared rules are not rows); the lint rule for it is the seat's
follow-up after the claims holding `packages/lint/src` release.
## Verification
Read first, by risk: `packages/plugins/plugin-sharing/src/rule-hooks.ts`
(the `bindRuleCriteriaGuard` hunk: ordering after match-all, no system
skip, the `sameCriteria` early return);
`packages/plugins/plugin-sharing/src/sharing-rule-service.ts` (the
`defineRule` hunk, judged for every caller before the non-system block);
`packages/plugins/plugin-sharing/src/rule-criteria-option-label.ts`
(`choiceOptionsOf`, `judgeComparand`).
Two-minute check: `pnpm --filter @objectstack/plugin-sharing exec vitest
run --maxWorkers=2 src/sharing-rule-option-label-39434.test.ts` → expect
`Tests 30 passed (30)`.
<details><summary>Gates (local subset at da6cbc1)</summary>
Derived with `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` at `da6cbc17` (73 commands), each run with
its exit code captured before any pipe; reconciliation:
```
Run reconciliation — 73 derived, 73 run, 0 NOT-MEASURED, 0 UNRUN.
✓ dispatch-gates --ran: 73 derived famil(ies) accounted for — 73 run, 0 NOT-MEASURED (a DERIVED zero — all 73 recorded an exit code and none of them is 3).
```
All 73 exited 0. ADR-0087 disposition:
```
✓ check-adr-0087-registration: 1 declared-breaking changeset(s), each carrying an ADR-0087 disposition.
.changeset/39434-sharing-rule-option-label-criteria.md [BREAKING+clause-②-narrowing] not-required (no-migration-prescription)
```
Package: `pnpm --filter @objectstack/plugin-sharing test` / `typecheck`
/ `build` exit 0 at `da6cbc17` (dependency closure built first with
`pnpm --filter '@objectstack/plugin-sharing^...' build`). `test:repo`,
`pnpm lint` and the whole-tree families are CI's.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4czHUJLmdQAqm4fdDs9
<!-- signed: repo:objectstack@os-elon-musk · os-elon-musk ·
session_016WV4czHUJLmdQAqm4fdDs9 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 4fed008 commit 8feef82
5 files changed
Lines changed: 622 additions & 3 deletions
File tree
- .changeset
- packages/plugins/plugin-sharing/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
463 | 464 | | |
464 | 465 | | |
465 | 466 | | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
466 | 477 | | |
467 | | - | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
468 | 482 | | |
469 | 483 | | |
470 | 484 | | |
| |||
474 | 488 | | |
475 | 489 | | |
476 | 490 | | |
477 | | - | |
478 | | - | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
479 | 501 | | |
480 | 502 | | |
481 | 503 | | |
| |||
0 commit comments