Repository navigation
feat(service-bridge): /v1 engine read ops — search, attachments, filters/sort, sub-collection paging - #22
Conversation
…rch) Expose the fork's PDP-gated PdpSearchService as POST /api/service/content/search so the platform's /v1 search can retire the broad-principal 503: search IS the authorization gate (filter-then-retrieve; ADR-0005), not a privileged data plane, so a principal too broad to LIST can still SEARCH. - New ServiceSearchService — a SEPARATE provider from ServiceContentService, which keeps its structural "no authorization collaborator" invariant (the arity-2 proof in service-content.service.spec.ts). It injects the SearchService token, bound to PdpSearchService in AUTHZ_MODE=remote via seam #5 (ServiceBridgeModule now imports SearchModule — no cycle: SearchModule imports no modules). - New least-privilege scope ServiceScope.ContentSearch, distinct from content:read. - PII-free projection: drops creatorId (an ADR-0001 Docmost-user-id leak) and rank/slugId (no ranking side-channel). Keeps space{id,name,slug}; ISO timestamps. - Wire/contract/coverage specs + service-bridge.openapi.json (ContentSearchRequest + PublicSearchHit) updated; a unit spec proves the projection, the userId/workspace threading, and that no shareId leaks onto the authenticated path. Consumed by the platform's POST /v1/search (cccvu/wiki-v2#159, commit C11). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…:read)
Two read-only ops backing the platform's /v1 attachment surface (Option A —
resolve→page, no attachment tuple in the PDP):
- GET /api/service/attachments/:attachmentId/page → { attachmentId, pageId, spaceId }.
The platform maps attachment→page, then authorizes page#view/#edit ITSELF (the
schema already inherits attachment access from the page). pageId/spaceId are null
for non-page attachments (avatars, workspace/space icons, chat), so the platform
denies them. Workspace-scoped, active only; unknown/cross-workspace/deleted → 404.
- GET /api/service/attachments/by-page/:pageId → { items: PublicAttachmentSummary[] }.
type='file' rows only, workspace-scoped + soft-delete-excluded, compact projection.
New ServiceAttachmentController + ServiceAttachmentService + ServiceScope.AttachmentsRead.
The service reads the attachments table with raw `sql` (mirroring ServiceContentService)
rather than adding a method to the upstream AttachmentRepo — so every change stays inside
the CCC service-bridge subtree (no upstream-owned-file edit, no boundary-check divergence).
Coverage/contract specs + service-bridge.openapi.json (PublicAttachmentSummary + the two
paths + attachments tag) updated; a unit spec proves the workspace/soft-delete scoping,
the null-page projection, the file-type filter, and the int8→number fileSize coercion.
The bytes themselves are NOT served here: the platform streams them through Docmost's
existing native GET /api/files/:id/:name. Consumed by /v1 attachments (cccvu/wiki-v2#159, C10).
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…n content lists
Extend the /v1 content read model (listPagesByIds / listSpacesByIds) with an allowlist
of filters and a configurable sort key, all pushed into the keyset SQL (never a
post-filter). BACKWARD-COMPATIBLE: with no `sort`/filters the compiled SQL is
byte-identical to today (`date_trunc('milliseconds', updated_at) desc`, id-tiebroken),
so an un-updated platform (the C9 submodule-bump gap) and the SQL-shape guard tests are
unchanged.
- Filters (allowlist only): pages — parentPageId, titleContains (ilike; metacharacters
escaped so %/_ match literally), creatorId (the platform translates identity→docmost
id BEFORE calling), updatedSince/Until; spaces — nameContains, createdSince/Until,
updatedSince/Until.
- Sort field∈{updatedAt,createdAt,title|name} × direction asc|desc, always id-tiebroken.
title is pages-only / name spaces-only (a cross-resource field is a 400). The keyset
generalizes to `(sortExpr, id) <op> (value, id)`; text sorts coalesce null→'' so null
titles/names page deterministically. ContentCursorDto gains a generic `value` (the
legacy `updatedAt` still decodes) — cursor encode/decode stays on the platform.
- Real-Postgres proof (service-content.pg.spec.ts): title asc walks the whole set two at
a time across a duplicate-title boundary with NO skip and NO duplicate; a null title
coalesces first; createdAt desc orders on created_at; titleContains narrows on the
engine. Plus SQL-shape unit tests + the openapi ContentListRequest schema (the new
fields + the generalized `before`).
Consumed by /v1 list filtering + sort + cursor-v2 (cccvu/wiki-v2#159, C12).
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…CL reads
Add opt-in {limit, before} keyset paging to the two bare sub-collection reads
(GET /spaces/:id/members, GET /pages/:id/permissions). BACKWARD-COMPATIBLE: without
`limit` the reads stay unpaged and the query is byte-identical to today (`created_at
asc`), so an un-updated platform (the C9 submodule-bump gap) keeps getting all rows; the
response shapes (a bare array / {items}) are unchanged either way.
- Shared parseSubCollectionQuery({limit, beforeCreatedAt, beforeId}) — paging is opt-in
on `limit`; a malformed limit, a half-supplied cursor, a cursor without a limit, or a
non-ISO timestamp is a 400 (never a 500 at the SQL cast). Cap 200.
- When paged: walk `(date_trunc('milliseconds', created_at), id::text)` ascending
(id-tiebroken, ms-truncated — the same discipline as the content keyset) and return
limit+1 so the platform detects hasMore + builds the next cursor from the last kept row.
- Real-Postgres proof (service-space.pg.spec.ts): a 4-member walk across a shared-ms tie
pages with NO skip and NO duplicate; unpaged still returns all members. Plus parser unit
tests + SQL-shape unit tests for both reads + the openapi query params.
Consumed by /v1 opt-in members/permissions pagination (cccvu/wiki-v2#159, C14).
Co-Authored-By: Claude Opus 4.8 <[email protected]>
🎨 Frontend / UI / UX ReviewReviewer: Frontend / UI / UX Reviewer Summary: This is a pure back-end service-bridge change (4 read-only M2M ops: content search, attachment→page resolution, content-list filters/sort, opt-in sub-collection keyset paging) with its OpenAPI contract. There is no UI surface for a frontend/UX lens to assess, so nothing here blocks merge on frontend grounds. Correctness, security (the privileged-data-plane vs authorization-gate distinction), performance (keyset SQL), and API/contract design belong to the sibling reviewers. One minor, pre-existing response-shape consistency observation is noted below as a cross-lane hand-off, not a defect this PR introduces. Findings2. Is it consistent with the rest of the app? (API-contract consistency — cross-lane note)[Minor · Priority 2 · optional] — API response-shape consistency —
|
⚡ Performance ReviewReviewer: Performance Reviewer Summary: Every new/changed op issues a single bounded SQL query (plus one lightweight Findings[Minor] — Caching —
|
🏛️ Architecture ReviewReviewer: Architecture Reviewer Summary: Four read-only ops added cleanly inside the fork-owned Findings[Minor] — Coupling / Abstraction boundaries —
|
🧪 Test Review — QA Engineer's EyeReviewer role: Test Reviewer Verdict💬 Comment Genuinely well-tested — every new branch I enumerated has a test that would fail if it broke, and the keyset walks, the PII-projection, and the backward-compat default paths are all pinned with real assertions. I found no merge-blocking gap. Two optional depth gaps are worth the author's attention before merge (both Priority 3, both optional): the two new attachment SQL queries are never executed against real Postgres (only string-matched by the Kysely spy), and the class-validator DTO 400 paths are never run through a ValidationPipe. SummaryThe PR adds four read-only service-bridge ops: PDP-gated content search ( Findings🟠 Major (optional, Priority 3) — The two new attachment queries are never executed on real Postgres
🟠 Major (optional, Priority 3) — DTO 400 validation paths are never exercised through a ValidationPipe
🟡 Minor (optional, Priority 2) — Legacy-path keyset cursor missing
|
| Behavior / branch | Covered? | Test that guards it |
|---|---|---|
| Search: userId+workspaceId threaded, never shareId | ✅ | service-search.service.spec.ts:1255 |
| Search: PII-free projection (drop creatorId/rank/slugId) | ✅ strong (asserts absence) | ...:1273 |
| Search: null space maps through | ✅ | ...:1295 |
| Search: DTO validation 400s (query/limit/offset/uuids) | ❌ | none — Major #2 |
Search: wire shape bare {items} |
✅ | service-bridge.wire.spec.ts:98 |
Search: scope content:search |
✅ | service-scope-coverage.spec.ts |
| Attachment: resolvePage page+space, ws-scoped, active | service-attachment.service.spec.ts:363 — not executed |
|
| Attachment: resolvePage null non-page / 404 unknown | ✅ (mock) | ...:373, ...:382 |
| Attachment: listByPage file-only, deleted-excl, fileSize coerce | ...:389, ...:413 — not executed |
|
| Attachment: queries run on real Postgres | ❌ | none — Major #1 |
| Content: default path = legacy SQL, no coalesce | ✅ strong negative | service-content.service.spec.ts:812 |
| Content: page/space filters pushed, ilike escaped | ✅ | ...:822, ...:844 |
| Content: sort createdAt/title/name keyset + coalesce | ✅ unit+pg | ...:859, ...:872, ...:888 + pg :748 |
| Content: cross-resource sort field → 400 | ✅ | ...:898 |
| Content: sort-path cursor missing bound → 400 | ✅ | ...:910 |
| Content: legacy-path cursor missing updatedAt → 400 | ❌ | none — Minor #3 |
| Content: title keyset duplicate split across page | timestamp analog in members pg walk — Minor #4 | |
| Content: ilike escape proven on engine | pg only tests 'ban' (no metacharacter) |
|
| Sub-collection parse: all 400 shapes | ✅ strong | sub-collection-page.dto.spec.ts |
| Sub-collection parse: lenient Date.parse edge | Minor #5 | |
| listMembers unpaged legacy / paged keyset walk | ✅ unit+pg | service-space.service.spec.ts:1503 + pg :1468 |
| listPagePermissions unpaged / paged keyset | ✅ shape only | service-content.service.spec.ts:926 — not run on pg (members proves pattern) |
What I checked
- Behavior coverage — each new branch mapped; two untested (legacy-cursor 400, DTO validators) + attachment SQL unexecuted
- Edge cases and boundaries — ms-truncation ties, same-ms/duplicate-title tiebreaks, null title/name coalesce, null fileSize, limit+1 overflow all pinned; text split-duplicate is the one edge left indirect
- Failure modes — 404 (attachment), cross-resource 400, missing-bound 400 covered; DTO-level 400s not
- Assertions are meaningful — projection asserts field absence, default path uses
not.toContain, keyset assertslimit+1param and exact id order; verified they'd go red on a real break - Tests aren't brittle — pg fixtures control created_at explicitly (no wall-clock), walks assert set-size not just order, no sleeps/UUID-equality
- Regression resistance — the PII leak, the byte-identical legacy SQL, and no-skip/no-dupe would all be caught; attachment SQL and validator regressions would NOT
- Test design — clean; the shared pg harness and Kysely-spy are reused well
Open questions for the author
- Was the attachment pg spec deliberately skipped (queries deemed too simple), or is it a follow-up? Content and space each got one for the same raw-SQL pattern.
- Is DTO validation intended to be covered by a super-repo/platform-side test (the real
/v1ValidationPipe), rather than here? If so, a one-line note would settle whether the fork owns that coverage.
🔒 Security ReviewSecurity Reviewer: Security Reviewer — Claude (independent Security lens, PR #22) Verdict🟡 Approve with comments. No merge-blocking security issues. This is a security-conscious change: every new SQL fragment is parameterized through Kysely's Summary
Task-scale mapping: BLOCKING: 0 · OPTIONAL: 3 · Priority-Level-3+ among optional: 0 · MAXSEV: 2. What I verified clean (the load-bearing checks)
Findings[LOW] Malformed keyset cursor casts to a 500, not the intended 400 (robustness) — optional, Priority 2
[INFO]
|
🚀 DevOps / Operations / Reliability ReviewReviewer role: DevOps / Operations / Reliability Reviewer Verdict✅ Approve Safe to deploy and operate. This is additive, backward-compatible application code on a privileged east-west read surface — no infra, migration, env, or config changes; new behavior is opt-in; the module-wiring change is a safe Nest diamond import; rollback is a submodule-pointer revert. No merge-blocking operational risk in the DevOps/reliability lane. Three optional notes below, one at Priority 3. Blast radiusApplication-only: 4 new read-only ops under SummaryThe change exposes existing engine capabilities (the Phase-5 Operationally the strong parts are worth naming, because they're the things that usually break this class of change and here they're done right:
Findings🟡 Minor —
|
🐛 Correctness Review — Bug HunterReviewer role: Correctness Reviewer Verdict✅ Approve Safe to merge on correctness grounds. I traced every hot-spot the change is built around — the generalized keyset SQL (asc/desc × timestamp/text), the byte-identical backward-compat invariant, the null-title coalesce, the int8→number coercion, the SummaryThis adds four read-only service-bridge ops: PDP-gated Findings🟡 Minor — Sub-collection cursor uses lenient
|
…ge, DTO validation, keyset hardening
All four round-justifying (non-blocking Level-3) findings from the 7-lens review, plus overlapping Level-2
robustness folded in while in the same files:
- [Testing L3 / DevOps L3] listByPage: give it opt-in {limit,before} keyset paging (consistent with the
members/ACL reads), and add service-attachment.pg.spec.ts — resolvePage + listByPage now execute on real
Postgres (a raw-sql column/table typo no longer ships green), and the paging keyset walks a shared-ms tie
with no skip / no duplicate.
- [Testing L3] Add dto-validation.spec.ts — the new class-validator DTOs (ContentSearchDto, ContentSortDto,
ContentCursorDto, ContentListDto incl. nested sort) now run through validate(), so dropping a constraint
(@Max/@IsUUID/@IsIn/@IsNotEmpty/@IsISO8601, …) reds a test.
- [Correctness L3] Add a real-Postgres walk for the generalized TIMESTAMP keyset (only title was walked) and
for value='' (null-title) as a mid-walk cursor bound.
- [Security F1 / Correctness #1 / Testing P2] A malformed keyset/cursor timestamp now 400s instead of
500-ing at the ::timestamptz cast: a shared isIsoInstant() guard (rejects Date.parse-lenient-but-PG-invalid
values like '2026') used by parseSubCollectionQuery and the content keyset builder.
- [Correctness #2] A text sort (title/name) now REQUIRES its cursor `value` (400) instead of silently
falling back to a timestamp `updatedAt` and paginating on the wrong boundary.
- [DevOps #3] Bump service-bridge.openapi.json version 1.1.1 → 1.2.0 (additive expansion).
Non-blocking Level ≤2 polish is deferred to a follow-up issue. Verified: nest build, 19 service-bridge suites
(179 tests), 3 real-Postgres pg specs (30 tests), eslint, import-boundary — all green.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Round 1 addressed — HEAD →
|
🎨 Frontend / UI / UX Re-review (round 2)Reviewer: Frontend / UI / UX Reviewer Summary: I re-reviewed the round-1 changes for my lens only. The delta stays entirely in the machine-to-machine service-bridge layer: opt-in keyset paging is extended to Round-1 note follow-up
Positive note (not a finding)
Checklist coverage (all n/a — no UI)
Deferred to other reviewers
|
⚡ Performance Re-Review (round 2)Reviewer: Performance Reviewer Summary: Re-checked my two round-1 notes and swept the delta for anything the fix introduced in the Performance lane. The one runtime-affecting change ( Prior findings — status
Delta review — new code in the Performance lane
Checklist coverage (delta)
No merge-blocking or Level-3+ performance findings at |
🔒 Security Re-Review (round 2)Security Reviewer: Security Reviewer — Claude (independent Security lens, PR #22) Verdict✅ Approve. The round-1 fix resolves my one Low finding cleanly and introduces no new security issue in my lane. No blocking issues; no open Security findings remain. Prior findings — disposition[LOW → RESOLVED] Malformed keyset cursor casts to 500 not 400 (F1, was Priority 2)Fixed correctly. A shared
I checked the guard for the two things that matter to this lens:
The related text-sort change (a [INFO — deferred, agreed] Search
|
🚀 DevOps / Operations / Reliability Re-Review (round 2)Reviewer role: DevOps / Operations / Reliability Reviewer Verdict✅ Approve Both actionable findings from round 1 are fixed; the third is an accepted L2 deferral. The delta is fail-closed hardening plus test coverage — I found nothing new in the DevOps/reliability lane, and the operationally load-bearing surfaces (module wiring, boot path, rollout/rollback, env/infra) are untouched. Delta reviewed
Prior findings — status✅ FIXED — 🟡 #1 (P3)
|
🏛️ Architecture Re-Review (round 2)Reviewer: Architecture Reviewer Summary: The round-1 fix ( Prior findings — status at
|
🧪 Test Re-Review — QA Engineer's Eye (round 2)Reviewer role: Test Reviewer Verdict✅ Approve (Testing lens) Both of my Priority-3 gaps and the Priority-2 lenient-date gap are fixed with real, non-vacuous tests, and the fix introduced no new testing gap in my lane. Suite green at HEAD: 19 suites / 179 tests (was 18 / 162); Prior findings — status✅ FIXED — Major/P3 #1: attachment queries now executed on real Postgres
✅ FIXED — Major/P3 #2: DTO 400 paths now run through
|
🐛 Correctness Review — Bug Hunter (Re-review, round 2)Reviewer role: Correctness Reviewer Verdict✅ Approve — 0 merge-blocking. The round-1 fixes are real and I traced each one on the engine's terms. All three prior findings are resolved on the platform call path; the one residual below is a narrower recurrence of my round-1 #1 (a 500 reachable only by a direct, secret-holding service-bridge caller sending a malformed cursor — never by the platform, which sends canonical Prior findings — status#1 (lenient date parse → 500 at
|
✅ 7-lens comprehensive review GREEN at
|
What
The paired fork half of the
/v1API engine expansion (super-repo epic cccvu/wiki-v2#213, audit cccvu/wiki-v2#159). Four read-only service-bridge ops the platform's next/v1commits consume. All changes live inside the CCCservice-bridge/subtree (fork-owned, boundary-excluded) plus the canonicalservice-bridge.openapi.json— no upstream-owned file is edited (check-upstream-boundary.shpasses).Per the established paired-merge order, this PR merges first, then a single super-repo commit bumps the
docmost/submodule onto the merged SHA, then the platform consumers land.The four ops
POST /api/service/content/search(content:search) — exposes the fork's PDP-gatedPdpSearchService(filter-then-retrieve; ADR-0005) so/v1search can retire the broad-principal 503. A separateServiceSearchService(keepsServiceContentService's "no authorization collaborator" arity-2 invariant);ServiceBridgeModulenow importsSearchModule(seam CCC header lockup + sidebar icon rail (incl. settings rail) #5 bindsSearchService→PdpSearchServicein remote mode). PII-free projection: nocreatorId(ADR-0001), norank/count (no side-channel).attachments:read) —GET /api/service/attachments/:id/page(resolve attachment→page; Option A, no PDP tuple) +GET /api/service/attachments/by-page/:pageId(compacttype='file'list). The bytes are not served here — the platform streams them through Docmost's nativeGET /api/files/:id/:name.content:read) — allowlisted filters (pages: parentPageId, titleContains, creatorId, updatedSince/Until; spaces: nameContains, date ranges) +sort {field,direction}pushed into the keyset SQL. Text sorts coalescenull→''; the cursor gains a genericvalue(legacyupdatedAtstill decodes).{limit, before}keyset paging on space members + page ACL reads.Backward compatibility (load-bearing)
Every change is additive and backward-compatible: with no new fields the compiled SQL is byte-identical to today (the content default keyset,
created_at ascfor sub-collections), and the response shapes are unchanged. So the currently-deployed platform keeps working across the submodule bump — the super-repo consumers opt into the new capabilities only after they land.Tests
service-content.pg.spec.ts,service-space.pg.spec.ts): the generalized sort keyset (title asc across a duplicate-title boundary, null-coalesce, createdAt) and the sub-collection keyset (members walk across a shared-ms tie) page with no skip and no duplicate.nest build(full typecheck), the AGPL import-boundary spec, andcheck-upstream-boundary.shall green.service-bridge.openapi.jsonextended (2 new schemas + ContentSearchRequest + PublicAttachmentSummary + the two new paths + query params).🤖 Generated with Claude Code