Repository navigation
fix(plugin-audit): a comment write leaves a ledger row and an activity row, stamped when the author was impersonated - #31128
Conversation
… stream Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2btLZBoQgqLephBLfF
…tamp and read visibility Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2btLZBoQgqLephBLfF
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2btLZBoQgqLephBLfF
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2btLZBoQgqLephBLfF
📓 Docs Drift CheckThis PR changes 1 package(s): 8 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 7 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 10 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin d780ece0b6710e45c3ca433dfadc185d402b0e0f && git checkout d780ece0b6710e45c3ca433dfadc185d402b0e0f
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 5f0037449256ccb0855e258ffc4fd4bff84d1a67 8bc2feca437e2a223aaac449bee0f169c22b265a && git checkout -B drift-repro 5f0037449256ccb0855e258ffc4fd4bff84d1a67 && git merge --no-ff 8bc2feca437e2a223aaac449bee0f169c22b265a
node scripts/docs-audit/affected-docs.mjs --json 5f0037449256ccb0855e258ffc4fd4bff84d1a67
|
|
domain:server#3 · marchtian · session_017ihL2dFb2QdZEHEJ83cR2B 维护者速读
席位核对ACCEPT · Head-sha:
|
Requested by 田騏 · project thread
Fixes #30979
Clause-②: no
Metadata-protocol: none
维护者速读
sys_comment)不再在审计镜像的跳过名单里。新建、编辑、删除评论现在和其他记录一样,各写一行审计(sys_audit_log)和一行动态(sys_activity);管理员模拟员工时写的评论,两行都带上「谁代谁」的标记。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'leavesSKIP_OBJECTS, soAUDIT_EXCLUDED_OBJECTS(derived from it) no longer lists it. A comment insert, update and delete now pass throughwriteAuditlike any other object: one ledger row, one activity row, and PR feat(audit): record the administrator on writes made while impersonating a user #30800's impersonation stamp (metadata.impersonated_byon both,impersonated_by_nameon 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).AUDIT_EXCLUDED_OBJECTS, checked:excludeObjects(the same list): comment writes now open the global after-phase hooks;parent-record-read-gate.tsenumerateParentObjects: the activity and ledger gates now enumeratesys_commentas a parent.sys_commentcarries an object-scoped read middleware (installCommentReadVisibility), so the planner routes it to the bounded probe (ADR-0139 D5.2), which readssys_commentas the caller under that same comment gate. That is the read visibility the card asks for, with no second judgment;comment-access-hooks.tscommentThreadGate().namedParents: it shrinks bysys_comment, which the comment gate already skips as its own gated object (name === gate.objectis tested first), so the comment gate's parent set is unchanged.sys_audit_logandsys_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)
sys_activityfiltered to the RECORD's own pair: uiRecordDetailViewactivityWindowQuery(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 }andofRecord).object_name: 'sys_comment'andrecord_idthe comment's id (activityRow.object_name = ctx.object), so it never matches the parent record's filter. No writer emits thecommentedactivity type.sys_comment), as before. Its new activity row appears only in the object-agnostic feeds (home recent activity, the bell's Activity tab, thesys_activitylist) 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, realAuditPlugin, 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 pinnedsys_commentas excluded now pin the reverse (not inexcludeObjects; the comment insert has acreateledger row).Acceptance notes
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.os migrate comment-parent-pair --applybootsAuditPluginand updates unstamped comments through the engine as the system, so each stamped comment now also leaves one system-actorupdateledger 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.tsboots asingleposture without a Default Organization, so its comment writes now print the writer's own one-timeAudit write FAILED ... ERR_SYSTEM_WRITE_ORGANIZATION_REQUIREDerror line. That suite still passes; the line is the writer correctly reporting its harness.Verification
All readings at head
8bc2feca4(merge base5f0037449= currentorigin/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-configover the four touched source and test files :: exit 0 (the package declares no lint script; the repo-widepnpm lintis CI's).node scripts/ablation-replace.mjs, anchor hit 1, restored blob == HEAD):'sys_comment'put back onSKIP_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.engine.registerMiddleware(gate, { object: COMMENT_OBJECT })incomment-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.Derived gates: 65 / 65 exit 0 on the final head; `dispatch-gates --ran`: 65 derived, 65 run, 0 NOT-MEASURED, 0 UNRUN
Three gates first answered exit 3 (PREREQUISITE NOT MET) and were re-run after the prerequisite:
check-plugin-teardown-shape --self-testafter fetching its pinned fixture commit,check:dual-build-cjs-loadsandcheck:i18nafter a fullpnpm build.check:query-options-erasurefirst counted one new test-surface options cast; the cast was removed (8bc2feca4) and the whole list re-run on that head:🤖 Generated with Claude Code