feat/one-api
needs attentionviewing older commit345f42e · incrementalpre-PRreviewed 2026-08-04 17:28 UTC2H · 6M · 9L · 6I- 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
- 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+21−43packages/database+44−8apps/platform/src/__tests__+14−1apps/platform/src/api/utils/__tests__+109−35.claude/rules+14−6
- Blast
- 8 files, +202/−93. Cross-domain onboarding shell, utility seed data (demo + bulk), 3 test files, 2 rule docs.
Findings · 23
correctness4
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.
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.
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.
Trailing whitespace in ontology.md BART path line
.claude/rules/ontology.md:158
Cosmetic only.
security3
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.
RLS tenancy consolidated to single path — net security improvement
domains/cross-domain/src/contract-wizard.shells.ts:232
Seed files use privileged access outside RLS — appropriate for dev/demo
packages/database/src/seed-utility-bulk.ts:507
conventions3
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.
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.
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
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').
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.
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.
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.
stripComments URL-in-line-comment edge case not unit-tested
apps/platform/src/api/utils/__tests__/public-v1-telemetry.test.ts:133
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
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.
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.
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.
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.
Trailing whitespace in ontology.md creates unintended hard line break
.claude/rules/ontology.md:158
Two trailing spaces = Markdown hard break.
Two new throwing-handler tests share near-identical structure
apps/platform/src/api/utils/__tests__/public-v1-meta-gate.test.ts:321
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
- 82bb5b9blockedincremental5H · 5M · 4L2026-08-12 01:48
- 90aa3d5needs attentionincremental1H · 5M · 3L2026-08-11 19:37
- 29d19a0needs attentionincremental1H · 5M · 9L2026-08-11 17:41
- 9bd8a0cneeds attentionfull0H · 5M · 9L2026-08-11 02:14
- 62ec3f7needs attentionincremental2H · 5M · 6L2026-08-10 22:51
- f93bca9needs attentionincremental2H · 5M · 8L2026-08-10 17:51
- 052db6fneeds attentionincremental1H · 3M · 4L2026-08-09 21:13
- 45699caneeds attentionincremental0H · 7M · 11L2026-08-09 17:44
- b843d8aneeds attentionincremental1H · 7M · 9L2026-08-09 04:05
- e1757b8needs attentionincremental0H · 3M · 6L2026-08-05 02:11
- 7a762faneeds attentionincremental2H · 5M · 5L2026-08-05 01:25
- 3300a60needs attentionincremental2H · 4M · 7L2026-08-04 19:06
- 0c8a7f5needs attentionincremental0H · 4M · 9L2026-08-04 18:15
- 345f42eneeds attentionincremental2H · 6M · 9L2026-08-04 17:28current
- 8338a9aneeds attentionincremental5H · 14M · 14L2026-08-04 00:33
- 41be4c3needs attentionincremental0H · 5M · 7L2026-08-03 23:49
- 5ed593dneeds attentionincremental1H · 6M · 6L2026-08-03 21:32
- b333e25needs attentionincremental4H · 9M · 8L2026-08-03 21:00
- 5642cccneeds attentionincremental2H · 3M · 2L2026-08-03 20:17
- 73b0b39needs attentionincremental3H · 10M · 13L2026-07-31 18:29
- b19852eneeds attentionincremental0H · 1M · 5L2026-07-29 05:04
- 3845205needs attentionincremental3H · 6M · 4L2026-07-29 04:47
- eb8eb50needs attentionincremental0H · 1M · 2L2026-07-29 03:03
- f4720a3needs attentionincremental6H · 8M · 7L2026-07-29 02:54
- f8d341ablockedincremental2H · 2M · 5L2026-07-29 00:00
- a7f1a64needs attentionincremental2H · 8M · 8L2026-07-28 18:41
- 738b60bblockedincremental3H · 6M · 5L2026-07-28 00:46
- 2c248b6needs attentionincremental8H · 12M · 8L2026-07-27 23:23
- 1346cc0needs attentionincremental2H · 8M · 6L2026-07-27 20:15
- 0716018needs attentionincremental2H · 11M · 12L2026-07-27 19:22
- 215cd2dneeds attentionincremental3H · 6M · 5L2026-07-27 17:04
- ec46958needs attentionincremental0H · 3M · 5L2026-07-27 16:51
- de7b337blockedincremental4H · 9M · 14L2026-07-27 06:36
- b1bb9c0needs attentionincremental1H · 2M · 4L2026-07-27 05:09
- 4701d11needs attentionincremental0H · 4M · 3L2026-07-27 04:44
- e1626c4needs attentionincremental3H · 9M · 10L2026-07-27 03:21
- 195f198needs attentionincremental3H · 3M · 3L2026-07-25 01:22
- 42c7358safeincremental0H · 0M · 0L2026-07-22 20:46
- 85b9018needs attentionincremental0H · 1M · 6L2026-07-21 23:51
- a7b2a9aneeds attentionincremental0H · 9M · 12L2026-07-21 18:49
- c2ee0daneeds attentionincremental4H · 7M · 7L2026-07-21 02:17
- e8ffa5eneeds attentionincremental4H · 7M · 5L2026-07-21 01:33
- a2d2a54needs attentionincremental2H · 7M · 3L2026-07-21 00:51
- 576fbd6needs attentionfull1H · 6M · 7L2026-07-21 00:35
- d3465e8needs attentionincremental1H · 7M · 10L2026-07-21 00:23
- dc794a7needs attentionincremental0H · 5M · 5L2026-07-20 23:46
- 9082773needs attentionfull1H · 3M · 3L2026-07-20 23:13