Repository navigation
Commit 107be28
fix(plugin-security): type explainAccessForCaller's request as the contract's ExplainAccessRequest (#29578)
<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8VXJ5hk8EG2fKt5gobE64M1)_
Fixes #29481
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:`SecurityPlugin#explainAccessForCaller` 的请求参数类型从内联的 `{ object;
operation; userId?; recordId? }` 改为契约里的 `ExplainAccessRequest`,于是批量形态
`recordIds` 也在声明类型里了。
- 为什么改:方法体早已支持 `recordIds`,公开契约也已声明它,只有方法签名漏掉;类型化调用方想批量解释访问权限必须强转。
- 风险与回滚:纯类型改动,运行时零变化;回滚即撤回 `security-plugin.ts` 的一行签名与一个 import。
- 先看:`packages/plugins/plugin-security/src/security-plugin.ts`(签名与
import),`packages/plugins/plugin-security/src/explain-batch-parity.test.ts`(新增的类型钉与直调用例)。
- 两分钟验证:`pnpm --filter @objectstack/plugin-security typecheck`,预期退出
0;把签名改回旧的内联类型后同一命令出现 3 个错误(见 Verification)。
- 需要你做的:无,席位落地。
## What changes
- `packages/plugins/plugin-security/src/security-plugin.ts`:
`explainAccessForCaller(request: ExplainAccessRequest, callerContext?)`,
importing the interface from `@objectstack/spec/contracts`. The body
module (`security-plugin-explain-access.ts`) already reads
`request.recordIds`; nothing else moves.
`SecurityServiceHost['explainAccessForCaller']` is
`SecurityPlugin['explainAccessForCaller']`, so the service host picks
the contract type up with no edit.
- `packages/plugins/plugin-security/src/explain-batch-parity.test.ts`: a
new `describe` (item 3 of the file header, "THE TYPED DOOR"):
- compile-time: `expectTypeOf` holds the method's first parameter equal
to `ExplainAccessRequest`, with a `@ts-expect-error` control showing the
matcher can fail (the selector without `recordIds` is a different type).
Both are live: `tsconfig.test.json` compiles this file, and
`check:test-typecheck` runs it from the package's `typecheck` script.
- runtime: a typed caller passes `recordIds` as an object literal
straight to `plugin.explainAccessForCaller` and gets exactly the answer
the registered `security` service gives for the same batch.
- `plugin` is lifted from a `beforeAll` local to a module binding so the
case can call it.
- `.changeset/29481-explain-access-request-type.md`: `patch` for
`@objectstack/plugin-security` (a published package; the method is
public on the exported class).
## Why
The published `ExplainAccessRequest` gained `recordIds?:
ExplainRequest['recordIds']` with #29297, and the body honours it, but
the reference implementation's own method still declared a request
without it. A typed caller of `SecurityPlugin.explainAccessForCaller`
could not pass a batch without a cast, and the declared type disagreed
with what the method honours.
## Tests
- `pnpm --filter @objectstack/plugin-security test`: Test Files 241
passed (241), Tests 5202 passed, 45 skipped (5247), lock VERDICT
command-exit 0 (run at ace9462; the later head eafb125 changes only
the new test case, re-run below).
- `pnpm --filter @objectstack/plugin-security exec vitest run
--maxWorkers=2 src/explain-batch-parity.test.ts` at eafb125: Test Files
1 passed (1), Tests 46 passed (46), exit 0.
- `pnpm --filter @objectstack/plugin-security typecheck` at eafb125:
exit 0; `check:test-typecheck: OK`, the test layer compiles under
`tsconfig.test.json` with 0 errors.
## Acceptance notes
- No runtime change, so no ablation: the reverse verification below is
the proof the pin can fail.
- The runtime case passes the request as an object literal on purpose,
so the excess-property check would refuse `recordIds` against the old
declared type.
## Verification
<details><summary>Reverse verification: the old signature restored, the
test kept (3 errors, then restored)</summary>
`security-plugin.ts` replaced by its `origin/main` blob (old inline
request type), the committed test unchanged, `tsc --noEmit -p
tsconfig.test.json` under the verify lock: exit 2, VERDICT command-exit
2.
```
src/explain-batch-parity.test.ts(290,91): error TS2344: Type 'ExplainAccessRequest' does not satisfy the constraint '{ object: string; operation: string; userId?: string | undefined; recordId?: string | undefined; ...
src/explain-batch-parity.test.ts(292,5): error TS2578: Unused '@ts-expect-error' directive.
src/explain-batch-parity.test.ts(298,93): error TS2561: Object literal may only specify known properties, but 'recordIds' does not exist in type '{ object: string; operation: string; userId?: string | undefined; recordId ...
```
Restored with `git checkout HEAD -- PATH`; `git hash-object` equals the
HEAD blob and `git status --porcelain` is empty. Direction observed:
red, as expected.
</details>
<details><summary>Gates (local subset, head eafb125)</summary>
`node scripts/pm/dispatch-gates.mjs --commands` derived 62 families for
this diff; each ran at eafb125 with its exit code captured before any
pipe, then `--ran` reconciled the record: **62 derived, 61 run, 1
NOT-MEASURED, 0 UNRUN** (exit 0).
- 61 families exit 0. Two of them first exited 3 (prerequisite not met)
and were re-run after the stated prerequisite: `node
scripts/check-plugin-teardown-shape.mjs --self-test` after fetching its
pinned fixture commit (48 cases pass), and `pnpm check:i18n` after its
own one-command build closure (`check-i18n-bundles: OK (10 package(s) —
all bundles in sync, no undeclared authoring keys)`).
- NOT MEASURED: `pnpm check:dual-build-cjs-loads`, exit 3 (reads every
package's `dist/`, which needs a whole-workspace `pnpm build`); declared
to CI's `Lint & Repo Gates`.
- `pnpm lint`: exit 0.
- Dogfood battery: n/a, no `!` in the title and no `(narrowing)` arm.
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(No spec change.)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes (exit 0 at eafb125).
- [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: n/a, not touched.
- [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 (the 维护者速读 block is the
dispatch contract's Chinese summary).
Card thread for seat `domain:server#4`; dispatch claim on #29481.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01JQwxbZiGjTXK1aGW4idvJ7)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 3557366 commit 107be28
3 files changed
Lines changed: 43 additions & 3 deletions
File tree
- .changeset
- packages/plugins/plugin-security/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
26 | 32 | | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
30 | 36 | | |
31 | | - | |
| 37 | + | |
32 | 38 | | |
33 | 39 | | |
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
| 43 | + | |
37 | 44 | | |
38 | 45 | | |
39 | 46 | | |
| |||
99 | 106 | | |
100 | 107 | | |
101 | 108 | | |
| 109 | + | |
102 | 110 | | |
103 | 111 | | |
104 | 112 | | |
| |||
199 | 207 | | |
200 | 208 | | |
201 | 209 | | |
202 | | - | |
| 210 | + | |
203 | 211 | | |
204 | 212 | | |
205 | 213 | | |
| |||
277 | 285 | | |
278 | 286 | | |
279 | 287 | | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
280 | 305 | | |
281 | 306 | | |
282 | 307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| 290 | + | |
290 | 291 | | |
291 | 292 | | |
292 | 293 | | |
| |||
2372 | 2373 | | |
2373 | 2374 | | |
2374 | 2375 | | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
2375 | 2380 | | |
2376 | 2381 | | |
2377 | | - | |
| 2382 | + | |
2378 | 2383 | | |
2379 | 2384 | | |
2380 | 2385 | | |
| |||
0 commit comments