Repository navigation
Commit 79a0d30
fix(plugin-audit): a comment write leaves a ledger row and an activity row, stamped when the author was impersonated (#31128)
<!-- claude-projects-attribution: {"github_login":"marchtian"} -->
_Requested by **田騏** · [project
thread](https://claude.ai/code/project/chan_01VmuUhXU9SSUzqJYyXSmYSi?thread=cmsg_01VmuUhXU9SSUzqJYyXSmYSi9Hju7DThD7eoLKoJU9hnHj)_
Fixes #30979
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
**改了什么**:评论(`sys_comment`)不再在审计镜像的跳过名单里。新建、编辑、删除评论现在和其他记录一样,各写一行审计(`sys_audit_log`)和一行动态(`sys_activity`);管理员模拟员工时写的评论,两行都带上「谁代谁」的标记。
- **为什么改**:按你在 #30213 选的 A(「A 评论也记审计和动态」)。之前模拟时写的评论和员工本人写的完全分不出来。
-
**风险与回滚**:每条评论多两行数据;这两行只给能读这条评论(即能读评论所在记录)的人看,复用评论自己的读权限,没有新判断。记录详情页的动态流不会重复显示(它只读记录本身的动态)。回滚即撤销本
PR,已写下的行保留。
-
**先看**:`packages/plugins/plugin-audit/src/audit-writers.ts`(跳过名单那一处);`src/activity-read-visibility.integration.test.ts`
末尾新增的读可见性用例。
- **两分钟验证**:`pnpm --filter @objectstack/plugin-audit exec vitest run
src/activity-actor-name.test.ts
src/activity-read-visibility.integration.test.ts`,预期全部通过(34 条)。
- **需要你做的**:无,席位落地。
## What changes
- `packages/plugins/plugin-audit/src/audit-writers.ts`: `'sys_comment'`
leaves `SKIP_OBJECTS`, so `AUDIT_EXCLUDED_OBJECTS` (derived from it) no
longer lists it. A comment insert, update and delete now pass through
`writeAudit` like any other object: one ledger row, one activity row,
and PR #30800's impersonation stamp (`metadata.impersonated_by` on both,
`impersonated_by_name` on the activity row) when the write came from an
impersonation session. A comment above the list says why comments are
not on it. Two stale code comments that said comments are skipped are
corrected. No new column, no migration (option B was not chosen).
- Readers of `AUDIT_EXCLUDED_OBJECTS`, checked:
- the hook registrations' `excludeObjects` (the same list): comment
writes now open the global after-phase hooks;
- `parent-record-read-gate.ts` `enumerateParentObjects`: the activity
and ledger gates now enumerate `sys_comment` as a parent. `sys_comment`
carries an object-scoped read middleware
(`installCommentReadVisibility`), so the planner routes it to the
bounded probe (ADR-0139 D5.2), which reads `sys_comment` as the caller
under that same comment gate. That is the read visibility the card asks
for, with no second judgment;
- `comment-access-hooks.ts` `commentThreadGate().namedParents`: it
shrinks by `sys_comment`, which the comment gate already skips as its
own gated object (`name === gate.object` is tested first), so the
comment gate's parent set is unchanged.
- Recursion: the "(1) recursion" group is about the audit and activity
tables themselves, which stay listed. The writer writes only
`sys_audit_log` and `sys_activity`; nothing it writes is a comment.
- `.changeset/30979-comment-writes-audited.md`: patch for
`@objectstack/plugin-audit`.
## Step 1 measurement: no timeline duplication (read at origin/main
5f00374)
- The record page's 动态 stream reads `sys_activity` filtered to the
RECORD's own pair: ui `RecordDetailView` `activityWindowQuery`
(`object_name: objectName, record_id: recordId`), and the server
record-page payload and timeline count
(`packages/rest/src/record-page-routes.ts`, `where: { object_name:
object, record_id: id }` and `ofRecord`).
- The mirror writes a comment's activity row with `object_name:
'sys_comment'` and `record_id` the comment's id
(`activityRow.object_name = ctx.object`), so it never matches the parent
record's filter. No writer emits the `commented` activity type.
- So a comment shows once on its record (from `sys_comment`), as before.
Its new activity row appears only in the object-agnostic feeds (home
recent activity, the bell's Activity tab, the `sys_activity` list) as a
created/updated/deleted Comment entry, where no comment entry existed.
No UI change is needed.
## Tests
- `activity-actor-name.test.ts`, new describe "a comment written from an
impersonation session is recorded like any other write": an impersonated
comment insert writes one ledger row and one activity row, both stamped
with the administrator; an impersonated edit and delete are stamped too;
CONTROL: the user's own comment writes both rows, unstamped.
- `activity-read-visibility.integration.test.ts`, new describe "a
comment's ledger and activity rows are served only to a reader of the
comment" (real kernel, real `AuditPlugin`, SQLite): each member is
served the activity and ledger rows of the comment on its own record and
neither row of the other member's comment (list, id-scoped find, count);
controls: both comments' rows exist (system read), the comment gate
answers each member its own comment, the admin is served both.
- `audit-hook-object-scope.test.ts`: the two assertions that pinned
`sys_comment` as excluded now pin the reverse (not in `excludeObjects`;
the comment insert has a `create` ledger row).
## Acceptance notes
- A holder of the ledger's audit capability (`view_all_audit_log`) keeps
reading every ledger row of the organization, comment rows included, as
for every other object (the gate's declared exemption). The activity
stream has no exemption.
- Comments written before this change have no rows; nothing is
backfilled.
- `os migrate comment-parent-pair --apply` boots `AuditPlugin` and
updates unstamped comments through the engine as the system, so each
stamped comment now also leaves one system-actor `update` ledger row and
activity row. Raised for the seat in the report; not changed here
(outside this card's file surface and a separate decision).
- `identity-objects-feeds-off.test.ts` boots a `single` posture without
a Default Organization, so its comment writes now print the writer's own
one-time `Audit write FAILED ... ERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED`
error line. That suite still passes; the line is the writer correctly
reporting its harness.
## Verification
All readings at head `8bc2feca4` (merge base `5f0037449` = current
`origin/main`; no main commits since).
- `bash scripts/pm/os-verify-lock.sh -c "pnpm --filter
@objectstack/plugin-audit test"` :: exit 0 — Test Files 76 passed (76),
Tests 1201 passed (1201).
- `pnpm --filter @objectstack/plugin-audit typecheck` :: exit 0 (tsc src
+ scripts + test-typecheck).
- `eslint --no-inline-config` over the four touched source and test
files :: exit 0 (the package declares no lint script; the repo-wide
`pnpm lint` is CI's).
- Ablation 1, writer (`node scripts/ablation-replace.mjs`, anchor hit 1,
restored blob == HEAD): `'sys_comment'` put back on `SKIP_OBJECTS` →
`activity-actor-name.test.ts` +
`activity-read-visibility.integration.test.ts`: 6 failed / 28 passed
(all three impersonation pins, the CONTROL pin, the rows-exist control,
the visibility pin and the admin control). Restored: green.
- Ablation 2, read visibility: the comment read gate's registration
(`engine.registerMiddleware(gate, { object: COMMENT_OBJECT })` in
`comment-access-hooks.ts`) deleted → 2 failed / 14 passed: the
comment-gate control and "a reader without read access to the comment's
record is served neither of its rows" (`expected [ two comment ids ] to
deeply equal [ one ]`: the other member's comment rows were served).
Restored: green. So the rows' visibility is the comment gate's own
answer, read through the probe.
<details><summary>Derived gates: 65 / 65 exit 0 on the final head;
`dispatch-gates --ran`: 65 derived, 65 run, 0 NOT-MEASURED, 0
UNRUN</summary>
Three gates first answered exit 3 (PREREQUISITE NOT MET) and were re-run
after the prerequisite: `check-plugin-teardown-shape --self-test` after
fetching its pinned fixture commit, `check:dual-build-cjs-loads` and
`check:i18n` after a full `pnpm build`. `check:query-options-erasure`
first counted one new test-surface options cast; the cast was removed
(`8bc2feca4`) and the whole list re-run on that head:
```
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-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/check-tenant-audit-census.mjs :: exit 0
node scripts/check-tenant-audit-census.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/spec run check:duration-unit-keys :: exit 0
pnpm check:changeset-gate-self-tests :: exit 0
pnpm check:ci-filter-parity :: 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: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:i18n :: exit 0
pnpm check:i18n-stale-fill :: 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:nul-bytes :: exit 0
pnpm check:objectql-double-limit :: 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: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:slot-lookup :: exit 0
pnpm check:sourcemap-no-sources-content :: 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
```
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent af3451b commit 79a0d30
5 files changed
Lines changed: 226 additions & 9 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 | |
|---|---|---|---|
| |||
477 | 477 | | |
478 | 478 | | |
479 | 479 | | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
521 | 521 | | |
522 | 522 | | |
523 | 523 | | |
524 | | - | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
525 | 527 | | |
526 | 528 | | |
527 | 529 | | |
| |||
609 | 611 | | |
610 | 612 | | |
611 | 613 | | |
612 | | - | |
613 | | - | |
| 614 | + | |
| 615 | + | |
614 | 616 | | |
615 | 617 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
262 | 270 | | |
263 | 271 | | |
264 | 272 | | |
| |||
2481 | 2489 | | |
2482 | 2490 | | |
2483 | 2491 | | |
2484 | | - | |
2485 | | - | |
| 2492 | + | |
| 2493 | + | |
2486 | 2494 | | |
2487 | 2495 | | |
2488 | 2496 | | |
| |||
2634 | 2642 | | |
2635 | 2643 | | |
2636 | 2644 | | |
2637 | | - | |
2638 | | - | |
2639 | | - | |
| 2645 | + | |
| 2646 | + | |
| 2647 | + | |
2640 | 2648 | | |
2641 | 2649 | | |
2642 | 2650 | | |
| |||
0 commit comments