Repository navigation
test(service-bridge): real-Postgres installer and retention specs (wiki-v2 issue 174 core) - #17
Merged
Merged
Conversation
… the authz outbox (docmost#174 core) Adds two real-Postgres jest specs under service-bridge. Both self-skip without AUTHZ_TEST_PG_URL and FAIL (not skip) under AUTHZ_REQUIRE_PG=1 without it, the same anti-vacuity block as authz-outbox-commit-safety.pg.spec.ts. - authz-outbox-installer.pg.spec.ts: legacy-upgrade backfill (a pre-R2 outbox without xact_id and with rows present: sentinel backfill, NOT NULL, the gc singleton and the (xact_id, id) index; the backfilled rows are then served by the real feed), idempotent fresh install through install() and the public onApplicationBootstrap path (identical inventory, one trigger per table, none on users, column-scoped pages/spaces triggers), and the G1 trigger chain: real install() over real base tables, INSERT/UPDATE/DELETE on every authz table, rows asserted on the table (jsonb objects via json(), never double-encoded) and mapped through the real AuthzChangeFeedService under the production Kysely config (CamelCasePlugin, bigint parser) into the typed events; non-structural pages/spaces edits produce no row, the docmost#181 DROPPED detector never fires, and the page_access cascade no-op is pinned. - authz-outbox-retention.pg.spec.ts: gc() invoked directly (the hourly timer is never awaited) reclaims only rows past the retention window, advances the gc mark to the max deleted (xact_id, id) TUPLE (a commit-reordered pair makes max-by-id wrong), and stays monotonic; the stale gate is strict: a cursor below the mark throws StaleCursorError, at and above the mark pass. Each spec owns a private schema (search_path) so the three pg specs can share one database under parallel jest workers. Mutation-checked: removing the backfill, un-scoping the pages trigger, reading payload as jsonb instead of text, changing > to >= in the stale check, advancing the mark by max id, and dropping the monotonic guard each turn the relevant spec red. Refs cccvu/wiki-v2#174 and cccvu/wiki-v2#171. Co-Authored-By: Claude Fable 5.1 <[email protected]>
gc() now ends every hourly sweep, reclaiming or not, with one greppable line: AUTHZ_OUTBOX_GC_SWEEP removed=<n> mark=<xact_id>.<id> retentionDays=<d>, where mark is the gc high-water mark the table holds after the sweep (none until something has ever been reclaimed). Previously a no-op sweep logged nothing, so an operator could not tell a sweep that found nothing from a sweep that never ran (S2 observability gap on wiki-v2 issue 174). The existing reclaim detail line is kept. The stale-cursor check itself is unchanged; its doc comments now say what the code does: a cursor STRICTLY below the mark is stale, AT the mark the reclaimed row was already consumed and passes. Unit spec: the line on a no-op sweep (with the current mark, and mark=none on the zero mark) and on a reclaiming sweep, via the fake Kysely spy. Retention pg spec: the real sweep logs the observed mark. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…installer pg spec Contract spec: for every AuthzChangeEvent variant, a Record<keyof ..., true> key map typed against the fork type is compared as a closed set to the matching components.schemas.AuthzChangeEvent.oneOf member (properties, and required when declared); the same for ChangesResult and SnapshotResult against the changes and snapshot response schemas. A fork-side rename fails to compile, a document-side rename fails the comparison (both proven with a temporary rename, then reverted). This is the provider half of the wiki-v2 issue 179 tether; the platform consumer spec pins its client types to the same document. Installer pg spec: the G1 case gets an explicit 30 s jest timeout above its 15 s drain deadline, and afterAll closes both pools with a bounded end() via allSettled (Kysely destroy() is an unbounded postgres.end() that a timed-out case could wedge). Header and G1 comments now state the target is a throwaway Postgres and why the CI lane runs in band (pg_snapshot_xmin is cluster-wide, not schema-isolated). Co-Authored-By: Claude Fable 5.1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
Two new real-Postgres specs under
apps/server/src/service-bridge/give the R2 change feed the executed coverage it never had: the outbox installer (legacy upgrade, idempotent fresh install, and the full trigger -> outbox -> mapper chain over real base tables) and the retention sweep (gc mark advances to the max deleted(xact_id, id), strict stale-cursor gate). The only production code change is one observability line ingc()(AUTHZ_OUTBOX_GC_SWEEP, every hourly sweep) plus doc-comment corrections on the stale gate. This is the fork half of wiki-v2 issue 174's R3-precondition core (items C.1 and C.2 of the R3 evidence gate on cccvu/wiki-v2#171).Context
Before this PR the trigger -> outbox row path had zero executed coverage (the existing pg spec hand-creates two tables and never calls
install()), andgc()plus the stale 409 had never run on a real Postgres end to end. The R2 payload-key defect behind wiki-v2 incident 181 slipped through a double-encoded fixture; these specs use real jsonb objects and the production Kysely configuration (CamelCasePlugin, bigint parser) so the same class of defect fails here.Related issues
test/174-core(points the submodule at this branch head; repointed to the merge commit after this merges).What changed
authz-outbox-installer.pg.spec.ts(new): anti-vacuity gate; LEGACY outbox upgrade (noxact_id, rows present: sentinel backfill, NOT NULL, gc table + index, backfilled rows served by the real feed); idempotent fresh install (same inventory afterinstall()and the public bootstrap path; one trigger per table with the documented column scoping; none onusers); G1 trigger chain (realinstall()over realusers,spaces,space_members,group_users,pages,page_access,page_permissions; every INSERT/UPDATE/DELETE lands an outbox object that the realAuthzChangeFeedServicemaps to the expected typed event; name/title/content edits produce no row;AUTHZ_CHANGE_EVENT_DROPPEDnever fires; cursor ends at the head).authz-outbox-retention.pg.spec.ts(new): anti-vacuity gate;gc()reclaims only rows past the window and advances the mark to the max deleted tuple monotonically (commit-reordered pair so max-by-tuple differs from max-by-id; idle sweep is a no-op); the stale gate is strict: a cursor BELOW the mark throwsStaleCursorError, AT and ABOVE pass (via the publicgetChanges, which the controller maps to 409). Both sides are asserted so a future>to>=edit fails.search_path) so the pg specs can share one database.service-bridge.contract.spec.ts: the provider half of the feed-schema tether (wiki-v2 issue 179). For everyAuthzChangeEventvariant aRecord<keyof ..., true>key map typed against the fork type is compared as a closed set to the matchingcomponents.schemas.AuthzChangeEvent.oneOfmember (properties, plusrequiredwhere declared); the same forChangesResultandSnapshotResultagainst the changes and snapshot response schemas. A fork-side rename fails to compile (TS2561), a document-side rename fails the comparison; both proven with a temporary rename and reverted.authz-change-feed.service.ts:gc()now ends EVERY hourly sweep with one greppable line,AUTHZ_OUTBOX_GC_SWEEP removed=<n> mark=<xact_id>.<id> retentionDays=<d>(mark = the gc mark the table holds after the sweep,noneuntil something has ever been reclaimed), so a sweep that found nothing is distinguishable from a sweep that never ran (S2). The existing reclaim detail line stays; the stale check is unchanged, its doc comments now say STRICTLY below the mark (AT the mark the reclaimed row was already consumed). Covered by the feed unit spec (no-op and reclaiming sweep via the Kysely spy) and by the retention pg spec (the real sweep logs the observed mark).authz-outbox-installer.pg.spec.ts: the G1 case carries an explicit 30 s jest timeout above its 15 s drain deadline, andafterAllcloses both pools with a boundedend()(each independently, viaallSettled) so a timed-out case cannot wedge the worker (Kyselydestroy()is an unboundedpostgres.end()). Header and G1 comments now say the target is a throwaway Postgres and why the lane runs in band (pg_snapshot_xminis cluster-wide, not schema-isolated).Verification
AUTHZ_TEST_PG_URL=... pnpm exec jest --runInBand 'src/service-bridge/.*\.pg\.spec\.ts$': 3 suites, 12 tests green (commit-safety 5, installer 4, retention 3).env -u AUTHZ_TEST_PG_URL AUTHZ_REQUIRE_PG=1 pnpm exec jest ...: 3 failed, 9 skipped, exit 1 (the required failure).pnpm exec jest src/service-bridge src/authz: 40 suites, 333 passed, 9 skipped. ESLint clean.check-upstream-boundary.shexit 0.tsconfig.build.jsonexcludes spec files (0 in--listFilesOnly).payload::text->payload(the incident 181 class) -> 2 fail; stale>->>=-> retention fails; mark by max id -> fails; monotonic guard removed -> fails.Notes for review
authz-outbox-commit-safety.pg.spec.tsassumes a quiet cluster (it reads the xmin-gated feed right after its insert). Under parallel jest workers a sibling's DDL transaction pinspg_snapshot_xminand its read withholds the row (timing dependent: reproducible deterministically by holding any xid-bearing transaction open on the cluster; in band it cannot happen). The paired super PR runs the CI lane with--runInBand; a bounded-poll hardening of that sibling stays on wiki-v2 issue 174's remainder.🤖 Generated with Claude Code