Skip to content

test(service-bridge): real-Postgres read-model coverage + 2xx OpenAPI tether (#174 remainder) - #21

Merged
PMQ9 merged 3 commits into
wiki-v2from
test/174-remainder
Sep 8, 2026
Merged

PMQ9 merged 3 commits into
wiki-v2from
test/174-remainder

Conversation

@PMQ9

@PMQ9 PMQ9 commented Sep 8, 2026

Copy link
Copy Markdown

Summary

Post-R3 remainder of wiki-v2#174 (paired with the super PR): re-home the executed real-Postgres contract coverage for the read-model service-bridge paths that today are proven only by the Kysely spy (compiled-SQL string matching), and extend the C.4 OpenAPI key-set tether to the response bodies.

Test-only. No runtime code, no upstream Docmost edits, no tag. Every file lives under apps/server/src/service-bridge/ (boundary-excluded; specs excluded from the runtime image by tsconfig.build.json).

What's covered

Real-Postgres pg specs (new; run in the docmost-authz-pg lane via the *.pg.spec.ts glob, each with the AUTHZ_REQUIRE_PG anti-vacuity guard, self-skipping without AUTHZ_TEST_PG_URL):

  • service-content.pg.spec.ts — F1 the /v1 keyset read model: date_trunc('milliseconds', updated_at) is applied symmetrically in the WHERE tuple and the ORDER BY with an id::text tiebreak, so rows sharing a truncated millisecond page without duplicate or skip (the issue-122 class a SQL-string assertion cannot catch); F2 confidentiality: a supplied id that is cross-workspace or soft-deleted is excluded by the ENGINE (listPagesByIds / listSpacesByIds / getSpace / resolvePageSpace / listPagePermissions).
  • service-space.pg.spec.ts — F2 the space read paths (list / listMembers / getDetail), previously untested: workspace_id, coalesce(is_personal,false)=false, deleted_at is null, live-only member count.
  • service-workspace.pg.spec.ts — F3 the settings JSONB shallow-merge round-trip: a sibling key survives coalesce(settings,'{}') || jsonb_build_object(...).
  • read-model-pg.testkit.ts — shared harness (postgres.js + PostgresJSDialect + CamelCasePlugin + private-schema search_path), mirroring the production Kysely config.

OpenAPI tether (service-bridge.contract.spec.ts): C.4 tethered only the two feed responses; this extends the same typed Record<keyof T, true> key-map tether to the 16 body-bearing 2xx ops (the 7 reusable component schemas tied to the fork return types + per-op body wiring for arrays / {items} / inline bodies), so a renamed or dropped response field fails from both directions (compile + runtime).

Fixture gotcha (documented in-code): postgres.js coerces a bound ISO string to a millisecond-precision Date before sending, so the sub-millisecond F1 fixtures are built with a SQL interval, not a bound string (to_char(updated_at,'US') shows the true sub-ms value only via the interval path).

Verification

  • docmost-authz-pg glob: 6 suites / 31 tests green on real postgres:18; anti-vacuity (AUTHZ_REQUIRE_PG=1, no URL) fails as designed.
  • Non-pg lane (src/service-bridge src/authz): 44 suites / 363 tests; provider contract spec 22 tests.
  • Mutation-verified (each new assertion reddens on a deliberate defect, then reverted): ORDER-BY date_trunc removed to F1 ordering red; WHERE date_trunc removed to F1 boundary paging red (row skipped); workspace_id removed to cross-workspace page leaks; deleted_at is null removed to soft-deleted leaks; listMembers deleted_at removed to deleted member leaks; jsonb merge to plain jsonb_build_object to sibling key dropped; doc field rename to tether red; op mis-wiring to tether red.
  • tsc: zero new errors vs wiki-v2; check-upstream-boundary.sh exit 0 (no upstream file touched); no em/en dashes added.

Paired with the super PR. Merge this fork PR first, then the super repo repoints its docmost submodule to this PR's merge commit.

🤖 Generated with Claude Code

PMQ9 and others added 3 commits September 7, 2026 21:12
… tether (docmost#174 remainder)

Post-R3 remainder of wiki-v2#174 (paired with the super PR): re-home the executed
contract coverage for the read-model paths proven today only by the Kysely spy
(compiled-SQL string matching), and extend the C.4 tether to the response bodies.

- read-model-pg.testkit.ts: shared postgres.js + CamelCasePlugin harness
  (private-schema search_path, base tables, deterministic workspace resolver).
- service-content.pg.spec.ts: F1 keyset millisecond-truncation ordering +
  cross-boundary paging (issue-122 class) and F2 confidentiality (a supplied id
  that is cross-workspace or soft-deleted is excluded by the engine).
- service-space.pg.spec.ts: list / listMembers / getDetail confidentiality
  (workspace_id, is_personal, deleted_at), previously untested.
- service-workspace.pg.spec.ts: settings JSONB shallow-merge round-trip
  (sibling key survives).
- service-bridge.contract.spec.ts: extend the C.4 key-set tether to the 16
  body-bearing 2xx ops (typed Record<keyof T,true> maps + per-op body wiring).

Mutation-verified (each new assertion reddens on a deliberate defect); every pg
spec carries the AUTHZ_REQUIRE_PG anti-vacuity guard and self-skips without
AUTHZ_TEST_PG_URL. No runtime code, no upstream edits, no tag.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
- service-content.pg.spec.ts: replace the mis-named listSpacesByIds test with a
  real spaceId-narrowing test on listPagesByIds (the space_id filter branch was
  untested + a misleading comment; mutation-verified), and add a spaces keyset
  tie/paging test mirroring the pages fixtures (listSpacesByIds was only
  smoke-tested). insertSpace now builds sub-ms fixtures via a SQL interval.
- service-workspace.pg.spec.ts: cover the no-op update short-circuit and the
  unknown-mode view normalization on real Postgres.
- service-bridge.contract.spec.ts: tether ProvisionedUser to the controller
  return type instead of a hand-written literal; note the tether validates
  key-sets, not per-field value types.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…circuit (docmost#174)

The workspace no-op test claimed "issues no write" but asserted only that the
settings jsonb was unchanged, which stays true under an updated_at-only UPDATE
(Testing + Correctness both flagged this). Now capture updated_at before/after
and assert it is byte-identical, so dropping the short-circuit (which would run
the fragments UPDATE setting updated_at = now()) reddens the test.
Mutation-verified.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@PMQ9
PMQ9 merged commit e9836b8 into wiki-v2 Sep 8, 2026
@PMQ9
PMQ9 deleted the test/174-remainder branch September 8, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant