← all branches

feat/one-api

needs attentionviewing older commit
345f42e · incrementalpre-PRreviewed 2026-08-04 17:28 UTC2H · 6M · 9L · 6I
The branch
Purpose
Close the entity_relationships secondary tenancy path to utility contracts, which was the last blocker for enabling RLS on the bill/contract read path.
Goal
Make site resolution unconditional in the contract wizard shell, repair seed data that created invisible contracts, and verify the telemetry layer handles all error paths correctly.
Sub-goals
  • SG-1: Remove PATH 2 (entity_relationship) creation from contract-wizard.shells.ts
  • SG-2: Repair seed data so all contracts have a site_utility_contracts row
  • SG-3: Fix CI flake in api-telemetry-persistence.test.ts (static import)
  • SG-4: Add coverage for throwing handler paths in withMetaGate
  • SG-5: Harden next/server guard against rename attacks
The changes (whole branch)
What
The contract-wizard shell now always resolves a site (removes the conditional PATH 2 else-branch). Bulk and demo seeds updated to give all contracts a site link. Integration test moved its expensive import to module scope to avoid CI timeout flakes. Two new unit tests cover throwing-handler telemetry. The next/server guard now checks the module specifier in both telemetry files.
Why
Production data showed 0 live contracts reachable only via entity_relationships (10,847 of 10,908 resolve via sites; the 61 without a site link were 59 soft-deleted + 2 failed onboarding attempts that were soft-deleted). With filter and policy now resolving the same set, the RLS wrapping can proceed.
Areas
domains/cross-domain+2143packages/database+448apps/platform/src/__tests__+141apps/platform/src/api/utils/__tests__+10935.claude/rules+146
Blast
8 files, +202/−93. Cross-domain onboarding shell, utility seed data (demo + bulk), 3 test files, 2 rule docs.
onboarding-path-change seed-data-state-change no-regression-test-for-path2-removal
typecheck· not run in this contexttests· not run in this contextcoderabbit· no .coderabbit.yamlgh-ci· gh not authenticated on runner

Findings · 23

correctness4

medium

Static import of publicV1GatedHandlers may cause test isolation issues

apps/platform/src/__tests__/integration/api-telemetry-persistence.test.ts:30

Static top-level import may capture unmocked auth config state before mocks are set up.

low

stripComments regex may strip // inside string literals

apps/platform/src/api/utils/__tests__/public-v1-telemetry.test.ts:136

Heuristic (^|[^:])// fails for string literals containing // not preceded by :. Acceptable for these files.

low

seed-utility-bulk.ts filter removal seeds SUC rows for all contracts

packages/database/src/seed-utility-bulk.ts:510

Intended, removes guard for ER-path plans. Seed-only impact.

info

Trailing whitespace in ontology.md BART path line

.claude/rules/ontology.md:158

Cosmetic only.

security3

low

Telemetry next/server guard is heuristic — runtime import bypass possible

apps/platform/src/api/utils/__tests__/public-v1-telemetry.test.ts:1

require(['next','server'].join('/')) bypasses the module-specifier check. No production security impact.

info

RLS tenancy consolidated to single path — net security improvement

domains/cross-domain/src/contract-wizard.shells.ts:232

info

Seed files use privileged access outside RLS — appropriate for dev/demo

packages/database/src/seed-utility-bulk.ts:507

conventions3

high

Seed file calls siteContractQueries.insert directly — bypasses FCIS shell

packages/database/src/seed-utility-demo.ts:478

ADR-016: shells own the transaction boundary. Inserting directly skips outbox event emission. Either call the shell or document why it's bypassed.

medium

Removed PATH 2 deleted outbox event — confirmation needed it's intentionally dropped

domains/cross-domain/src/contract-wizard.shells.ts:232

PATH 2 emitted core.entity_relationship.created. If dropped rather than made unnecessary, this breaks EventBridge delivery guarantees.

low

Tests use try/finally for expect().rejects — non-idiomatic Vitest

apps/platform/src/api/utils/__tests__/public-v1-meta-gate.test.ts:321

Convention in this codebase is afterEach for cleanup.

tests6

high

No regression test for PATH 2 removal in contract-wizard.shells.ts

domains/cross-domain/src/contract-wizard.shells.ts:232

~43 lines of entity_relationship creation removed with no integration test asserting the new invariant ('a contract always gets a site').

medium

Throwing-handler tests assert exact line count — brittle

apps/platform/src/api/utils/__tests__/public-v1-meta-gate.test.ts:309

expect(lines).toHaveLength(1) fails with confusing message on any incidental future log.

medium

No test verifying rethrow reaches publicApiErrorHandler

apps/platform/src/api/utils/__tests__/public-v1-meta-gate.test.ts:309

If withMetaGate swallows the error after logging, telemetry passes but error contract is broken.

low

No guard protecting cold-load fix from reverting to dynamic import

apps/platform/src/__tests__/integration/api-telemetry-persistence.test.ts:27

Comment documents the 26.8s measured cost but no lint rule prevents regression.

low

stripComments URL-in-line-comment edge case not unit-tested

apps/platform/src/api/utils/__tests__/public-v1-telemetry.test.ts:133

info

Source-file guard is fragile to file renames

apps/platform/src/api/utils/__tests__/public-v1-telemetry.test.ts:133

readFileSync silently throws on rename — read() should assert non-empty result.

improvement7

medium

Stale PATH 2 terminology in contract-wizard.shells.ts JSDoc

domains/cross-domain/src/contract-wizard.shells.ts:181

JSDoc still references 'PATH 1 + PATH 2'; enableMonitoringShell opens with 'PATH 2 contract'. Creation side is gone.

medium

ContractPlan.path discriminator is now semantically dead

packages/database/src/seed-utility-bulk.ts:165

path: 'suc' | 'er' no longer means 'er = no site'. Rename to includeErRow: boolean to prevent re-introduction of -1 siteIndex.

low

Comment at line ~302 still says '(entity_relationship, no site)'

packages/database/src/seed-utility-bulk.ts:302

ER contracts now also get a site — the 'no site' parenthetical is wrong.

low

cross-domain CLAUDE.md still describes enableMonitoringShell as 'PATH 2 contract (no site yet)'

domains/cross-domain/CLAUDE.md

Should note this is legacy handling; new contracts arrive with a site.

low

Trailing whitespace in ontology.md creates unintended hard line break

.claude/rules/ontology.md:158

Two trailing spaces = Markdown hard break.

info

Two new throwing-handler tests share near-identical structure

apps/platform/src/api/utils/__tests__/public-v1-meta-gate.test.ts:321

info

stripComments helper could be more robust against URLs in string literals

apps/platform/src/api/utils/__tests__/public-v1-telemetry.test.ts

History · 47 commits

  1. 82bb5b9blockedincremental5H · 5M · 4L2026-08-12 01:48
  2. 90aa3d5needs attentionincremental1H · 5M · 3L2026-08-11 19:37
  3. 29d19a0needs attentionincremental1H · 5M · 9L2026-08-11 17:41
  4. 9bd8a0cneeds attentionfull0H · 5M · 9L2026-08-11 02:14
  5. 62ec3f7needs attentionincremental2H · 5M · 6L2026-08-10 22:51
  6. f93bca9needs attentionincremental2H · 5M · 8L2026-08-10 17:51
  7. 052db6fneeds attentionincremental1H · 3M · 4L2026-08-09 21:13
  8. 45699caneeds attentionincremental0H · 7M · 11L2026-08-09 17:44
  9. b843d8aneeds attentionincremental1H · 7M · 9L2026-08-09 04:05
  10. e1757b8needs attentionincremental0H · 3M · 6L2026-08-05 02:11
  11. 7a762faneeds attentionincremental2H · 5M · 5L2026-08-05 01:25
  12. 3300a60needs attentionincremental2H · 4M · 7L2026-08-04 19:06
  13. 0c8a7f5needs attentionincremental0H · 4M · 9L2026-08-04 18:15
  14. 345f42eneeds attentionincremental2H · 6M · 9L2026-08-04 17:28current
  15. 8338a9aneeds attentionincremental5H · 14M · 14L2026-08-04 00:33
  16. 41be4c3needs attentionincremental0H · 5M · 7L2026-08-03 23:49
  17. 5ed593dneeds attentionincremental1H · 6M · 6L2026-08-03 21:32
  18. b333e25needs attentionincremental4H · 9M · 8L2026-08-03 21:00
  19. 5642cccneeds attentionincremental2H · 3M · 2L2026-08-03 20:17
  20. 73b0b39needs attentionincremental3H · 10M · 13L2026-07-31 18:29
  21. b19852eneeds attentionincremental0H · 1M · 5L2026-07-29 05:04
  22. 3845205needs attentionincremental3H · 6M · 4L2026-07-29 04:47
  23. eb8eb50needs attentionincremental0H · 1M · 2L2026-07-29 03:03
  24. f4720a3needs attentionincremental6H · 8M · 7L2026-07-29 02:54
  25. f8d341ablockedincremental2H · 2M · 5L2026-07-29 00:00
  26. a7f1a64needs attentionincremental2H · 8M · 8L2026-07-28 18:41
  27. 738b60bblockedincremental3H · 6M · 5L2026-07-28 00:46
  28. 2c248b6needs attentionincremental8H · 12M · 8L2026-07-27 23:23
  29. 1346cc0needs attentionincremental2H · 8M · 6L2026-07-27 20:15
  30. 0716018needs attentionincremental2H · 11M · 12L2026-07-27 19:22
  31. 215cd2dneeds attentionincremental3H · 6M · 5L2026-07-27 17:04
  32. ec46958needs attentionincremental0H · 3M · 5L2026-07-27 16:51
  33. de7b337blockedincremental4H · 9M · 14L2026-07-27 06:36
  34. b1bb9c0needs attentionincremental1H · 2M · 4L2026-07-27 05:09
  35. 4701d11needs attentionincremental0H · 4M · 3L2026-07-27 04:44
  36. e1626c4needs attentionincremental3H · 9M · 10L2026-07-27 03:21
  37. 195f198needs attentionincremental3H · 3M · 3L2026-07-25 01:22
  38. 42c7358safeincremental0H · 0M · 0L2026-07-22 20:46
  39. 85b9018needs attentionincremental0H · 1M · 6L2026-07-21 23:51
  40. a7b2a9aneeds attentionincremental0H · 9M · 12L2026-07-21 18:49
  41. c2ee0daneeds attentionincremental4H · 7M · 7L2026-07-21 02:17
  42. e8ffa5eneeds attentionincremental4H · 7M · 5L2026-07-21 01:33
  43. a2d2a54needs attentionincremental2H · 7M · 3L2026-07-21 00:51
  44. 576fbd6needs attentionfull1H · 6M · 7L2026-07-21 00:35
  45. d3465e8needs attentionincremental1H · 7M · 10L2026-07-21 00:23
  46. dc794a7needs attentionincremental0H · 5M · 5L2026-07-20 23:46
  47. 9082773needs attentionfull1H · 3M · 3L2026-07-20 23:13