Repository navigation
Commit 047f37b
fix(plugin-audit): an activity summary names a referenced record by a title the writer may read, else by its id (#34493)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9CEjuTu4HVEtNH1742UngyH)_
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:活动动态摘要里提到被引用的记录时(跟踪的查找字段变更、里程碑句子里的
`{token}`),记录名称按写入者自己的读取范围取得;写入者读不到该记录或其名称字段时,摘要写记录 id。
- 为什么改:加固规则——活动摘要只用写入者本人可读的名称来指称被引用记录,否则用 id;与同一活动行的记录标签用同一读取范围。
- 风险与回滚:只影响此后写入的活动行,已写入的行不变;有权读取的写入者和系统写入的摘要与之前相同;读取次数不变。回滚即 revert 本
PR,无数据迁移。
- 先看:`packages/plugins/plugin-audit/src/audit-writers.ts`(两个摘要分支调用
`resolveLookupTitles` 的两处,以及该函数 "Whose read it is"
一节);`packages/plugins/plugin-audit/src/activity-summary-title-writer-scope.test.ts`。
- 两分钟验证:`pnpm --filter @objectstack/plugin-audit exec vitest run
src/activity-summary-title-writer-scope.test.ts`,预期 1 个文件、11 个用例全部通过。
- 需要你做的:无,席位落地。
## What changes
Hardening rule: **an activity summary names a referenced record by a
title the writer may read, else by its id.**
`sys_activity.summary` names a referenced record in two branches: the
tracked-change diff (`Vault: A → B`) and a fired milestone's `{token}`
(`Escalated to {vault}`). Both take the title from `resolveLookupTitles`
in `audit-writers.ts`. Both now hand it the hook's own `api`, the
writer's scope. The row's record label already reads there, so every
title an activity row writes follows one rule.
- A record the writer may not read keeps its stored id: the object
refuses the writer, or the writer's row scope leaves the record out.
- A record the writer may read without its title column keeps its stored
id.
- The rule holds per id. One change can title the side the writer may
read and keep the id of the side it may not.
- A writer who may read the target, and every system write, gets the
same summary as before.
- No read is added. It is still one `id: { $in }` read per distinct
target object, and only when a tracked reference moved or a fired
milestone names one.
The resolver's docblock now states the rule for every caller. Rows
already written keep the summary they were written with.
## Tests
New file `src/activity-summary-title-writer-scope.test.ts` (11 cases)
runs a bare engine with the real `installAuditWriters`. The restrictions
are engine middleware on the target object: a refused read, a row left
out by row scope, and a row served without its title column. For each
branch it pins the three restricted writers, a writer who may read and a
system write. The tracked branch also pins the per-id case. The cases
assert the stored sentence and the stored summary code that the read
side composes from.
<details><summary>Red first: the new file against the base
source</summary>
At `origin/main` `bf76922925`, before the fix:
```
Test Files 1 failed (1)
Tests 7 failed | 4 passed (11)
```
The 4 that pass are the controls (a writer who may read, and a system
write, in each branch).
</details>
<details><summary>Ablations via scripts/ablation-replace.mjs, each
restored to the HEAD blob with an empty git diff HEAD</summary>
| Mutation | Red |
|---|---|
| M1: the tracked-change branch's call takes its base-source argument
again | 4 (the three restricted writers and the per-id case) |
| M2: the milestone branch's call takes its base-source argument again |
3 (the three restricted writers) |
Each logged `ok mutation landed: anchor 1 -> 0` and `ok restored: blob
== HEAD (b8e96db) and git diff HEAD is empty`.
</details>
<details><summary>Package suite and typecheck at 7c093c0 (after merging
origin/main)</summary>
Closure rebuilt after the merge (`turbo run build
--filter=@objectstack/plugin-audit...`, 16/16 tasks), `@objectstack/spec
check:generated` reports all 14 generated artifacts up to date. Under
`scripts/pm/os-verify-lock.sh`:
```
pnpm --filter @objectstack/plugin-audit test && pnpm --filter @objectstack/plugin-audit typecheck
Test Files 100 passed (100)
Tests 1665 passed (1665)
check:test-typecheck: OK — @objectstack/plugin-audit's test layer compiles
os-verify-lock: VERDICT command-exit 0
```
</details>
## Acceptance notes
- **Scope.** Only the two summary branches change. The record label
already read its title in the writer's scope.
- **`referenceNameVisible`.** A lookup that declares it follows the same
rule in the summary as in the record label. Whether that key should
widen what activity rows name is a question raised with the owning seat.
This PR does not decide it.
- **Already-written rows** keep the summary they were written with.
Snapshots are not rewritten.
- **Test placement.** The summary branches have no shared harness file
(each audit suite carries its own), so the pins are a new file named for
the rule.
## Verification
Local gate subset: the `scripts/pm/dispatch-gates.mjs --commands` list
derived at `7c093c01` (72 commands). 70 answered exit 0, one of them
after its pinned fixture commit was fetched into this shallow clone.
`check:dual-build-cjs-loads` refused locally (PREREQUISITE NOT MET: it
reads every package's build output), and so did `check:i18n` (it needs
the CLI build closure). Both are NOT MEASURED here. CI runs both in
`Lint & Repo Gates`, and CI runs the full farm.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmRiaNzHVY81pCjZrpv)_
<!-- signed: security#1 · os-steve · session_01ADHkmRiaNzHVY81pCjZrpv
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 1efe7a2 commit 047f37b
3 files changed
Lines changed: 394 additions & 17 deletions
File tree
- .changeset
- packages/plugins/plugin-audit/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 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 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
0 commit comments