Skip to content

Crew Sync v2 Phase 5e: coverage convention + guardrail - #533

Merged
smj1860 merged 1 commit into
mainfrom
claude/k6-artillery-setup-3k7b2l
Jul 29, 2026
Merged

Crew Sync v2 Phase 5e: coverage convention + guardrail#533
smj1860 merged 1 commit into
mainfrom
claude/k6-artillery-setup-3k7b2l

Conversation

@smj1860

@smj1860 smj1860 commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Adds the CLAUDE.md convention and unit/guardrails/crew-sync-coverage.test.ts per docs/CREW_SYNC_V2_PHASES.md section 5e: every Supabase-backed table the crew PWA caches in Dexie must be classified in lib/dexie/schema.ts's new CREW_SYNCED_TABLES/LOCAL_ONLY_TABLES exports, and (if synced) covered by either a broadcast trigger or the guardrail's SAFETY_POLL_ONLY allowlist — a new cached table now fails CI until it's consciously placed in one of these sets.

Classified the current schema: turnovers/checklist_instances/ checklist_instance_items/crew_work_orders(->work_orders) are covered by the Phase 2 broadcast triggers; inventory_items/properties (pulled inside the turnovers scope pull, not their own trigger)/crew_availability/ messages/property_assets rely on the safety poll only.

Also records the Realtime concurrent-clients quota check from docs/CREW_SYNC_V2_PHASES.md section 5a (10,000 max vs ~1,500 crew-fleet target — comfortable headroom) and the accompanying database connection pool size bump (2 -> 15, since Phase 3's all-private-channel design routes every join/reconnect's RLS authorization through that pool).

Claude-Session: https://claude.ai/code/session_01WboJd7a4GYvZK5BedZC2M6

Summary by CodeRabbit

  • Documentation

    • Added guidance for maintaining complete Crew Sync v2 coverage when introducing cached tables.
    • Updated Phase 5 progress and quota verification details.
  • Tests

    • Added automated guardrails that verify cached tables are classified and covered by broadcast triggers or safety polling.
    • Added checks to detect stale coverage lists and unclassified Dexie tables.

Adds the CLAUDE.md convention and unit/guardrails/crew-sync-coverage.test.ts
per docs/CREW_SYNC_V2_PHASES.md section 5e: every Supabase-backed table the
crew PWA caches in Dexie must be classified in lib/dexie/schema.ts's new
CREW_SYNCED_TABLES/LOCAL_ONLY_TABLES exports, and (if synced) covered by
either a broadcast trigger or the guardrail's SAFETY_POLL_ONLY allowlist —
a new cached table now fails CI until it's consciously placed in one of
these sets.

Classified the current schema: turnovers/checklist_instances/
checklist_instance_items/crew_work_orders(->work_orders) are covered by
the Phase 2 broadcast triggers; inventory_items/properties (pulled inside
the turnovers scope pull, not their own trigger)/crew_availability/
messages/property_assets rely on the safety poll only.

Also records the Realtime concurrent-clients quota check from
docs/CREW_SYNC_V2_PHASES.md section 5a (10,000 max vs ~1,500 crew-fleet
target — comfortable headroom) and the accompanying database connection
pool size bump (2 -> 15, since Phase 3's all-private-channel design routes
every join/reconnect's RLS authorization through that pool).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WboJd7a4GYvZK5BedZC2M6
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
fieldstay Ready Ready Preview, Comment Jul 29, 2026 8:56am

Request Review

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR documents the Crew Sync v2 coverage convention, exports Dexie table classifications, and adds a guardrail test validating Supabase triggers, safety-poll allowlists, and complete FieldStayDexie table coverage.

Changes

Crew Sync v2 coverage

Layer / File(s) Summary
Coverage contract and schema classification
lib/dexie/schema.ts, CLAUDE.md
Defines synced-table mappings, local-only tables, and the required coverage convention for new cached tables.
Coverage guardrail validation
unit/guardrails/crew-sync-coverage.test.ts, docs/CREW_SYNC_V2_PHASES.md
Validates migration trigger coverage, safety-poll classification, and schema table classification; updates Phase 5 status and quota-check details.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant crew-sync-coverage
  participant FieldStayDexie
  participant SupabaseMigration
  crew-sync-coverage->>SupabaseMigration: Read broadcast-trigger migration SQL
  crew-sync-coverage->>SupabaseMigration: Check TRIGGERED_TABLES coverage
  crew-sync-coverage->>FieldStayDexie: Parse declared Dexie tables
  crew-sync-coverage->>crew-sync-coverage: Check synced and local-only classifications
Loading

Possibly related PRs

Suggested reviewers: claude

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding the Crew Sync v2 Phase 5e coverage convention and guardrail.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/k6-artillery-setup-3k7b2l

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
unit/guardrails/crew-sync-coverage.test.ts (2)

42-50: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Read all matching broadcast-trigger migrations.

Line 43 selects only one file. Split or follow-up *crew_sync_broadcast*.sql migrations will be validated incorrectly. Aggregate every matching SQL file before checking triggers.

Proposed fix
-function findBroadcastMigrationSql(): string {
-  const file = readdirSync(MIGRATIONS_DIR).find((f) => f.includes('crew_sync_broadcast'))
-  if (!file) {
+function readBroadcastMigrationSql(): string {
+  const files = readdirSync(MIGRATIONS_DIR).filter(
+    (file) => file.endsWith('.sql') && file.includes('crew_sync_broadcast'),
+  )
+  if (files.length === 0) {
     throw new Error(
       'No supabase/migrations/*crew_sync_broadcast*.sql file found — did the ' +
       'Crew Sync v2 Phase 2 migration get renamed, moved, or deleted?'
     )
   }
-  return readFileSync(join(MIGRATIONS_DIR, file), 'utf8')
+  return files.map((file) => readFileSync(join(MIGRATIONS_DIR, file), 'utf8')).join('\n')
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@unit/guardrails/crew-sync-coverage.test.ts` around lines 42 - 50, Update
findBroadcastMigrationSql to collect every migration filename matching
crew_sync_broadcast rather than selecting only the first result. Read each
matching file from MIGRATIONS_DIR and combine their SQL contents into one
string, while preserving the existing error when no matching files are found.

79-90: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Parse the full Dexie class for Table fields.

The current substring stops at the constructor and only matches name!: Table<...>, so valid Dexie Table fields declared after the constructor, or under modifiers such as readonly, would be omitted from this guardrail. Parse all property declarations for FieldStayDexie instead, for example at the dexie schema class definition.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@unit/guardrails/crew-sync-coverage.test.ts` around lines 79 - 90, Update the
guardrail around class FieldStayDexie to inspect the entire class body rather
than stopping at constructor(userId: string). Expand the Table field extraction
to recognize valid property declarations regardless of modifiers such as
readonly, while retaining the zero-match sanity check and declared table-name
collection.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@unit/guardrails/crew-sync-coverage.test.ts`:
- Around line 42-50: Update findBroadcastMigrationSql to collect every migration
filename matching crew_sync_broadcast rather than selecting only the first
result. Read each matching file from MIGRATIONS_DIR and combine their SQL
contents into one string, while preserving the existing error when no matching
files are found.
- Around line 79-90: Update the guardrail around class FieldStayDexie to inspect
the entire class body rather than stopping at constructor(userId: string).
Expand the Table field extraction to recognize valid property declarations
regardless of modifiers such as readonly, while retaining the zero-match sanity
check and declared table-name collection.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b092d82e-7fd6-466f-b879-0fa2c6a19191

📥 Commits

Reviewing files that changed from the base of the PR and between 12d195d and 88edade.

📒 Files selected for processing (4)
  • CLAUDE.md
  • docs/CREW_SYNC_V2_PHASES.md
  • lib/dexie/schema.ts
  • unit/guardrails/crew-sync-coverage.test.ts

@smj1860
smj1860 merged commit 5efbe64 into main Jul 29, 2026
8 checks passed
@smj1860
smj1860 deleted the claude/k6-artillery-setup-3k7b2l branch August 4, 2026 18:22
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.

2 participants