Skip to content

Conversation

@MentalGear
Copy link

🎯 Changes

βœ… Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm test:pr.

πŸš€ Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

claude and others added 25 commits December 31, 2025 17:01
Add comprehensive end-to-end tests for the TrailBase collection sync:
- Initial sync behavior tests
- Live query filtering tests (eq, gt, isNull)
- Live update tests (insert, update, delete events)
- Collection mutation tests
- Subscription lifecycle tests
- Error handling and data integrity tests

Following the same patterns as electric-db-collection e2e tests.
Update trailbase e2e tests to use the shared test infrastructure:
- Import and use createPredicatesTestSuite, createPaginationTestSuite,
  createJoinsTestSuite, createDeduplicationTestSuite, createCollationTestSuite,
  createMutationsTestSuite, createLiveUpdatesTestSuite
- Use shared types (User, Post, Comment) and generateSeedData()
- Add parse/serialize conversions for TrailBase snake_case columns
- Add @tanstack/db-collection-e2e as workspace dev dependency

Note: Progressive test suite is skipped as TrailBase has unified sync mode.
Implement syncMode (eager, on-demand, progressive) following Electric's pattern:

- eager (default): Syncs all data immediately, marks ready after full sync
- on-demand: Marks ready immediately, loads data via loadSubset when queried
- progressive: Marks ready immediately, starts background full sync,
  loadSubset available during initial sync phase

Key changes:
- Add TrailBaseSyncMode type and syncMode config option
- Use AbortController for proper cleanup on cancel
- Return loadSubset function for on-demand/progressive modes
- Add getSyncMetadata to expose sync state
- Export TrailBaseSyncMode from index.ts
- Update e2e tests to create collections for each sync mode
Add the progressive test suite from db-collection-e2e for completeness.
Most tests will skip since TrailBase doesn't have progressiveTestControl
or Electric-specific utilities like awaitTxId, but including it ensures
we're using the full shared test suite.
Implement TRAILBASE_TEST_HOOKS similar to Electric's pattern:

- Add TRAILBASE_TEST_HOOKS symbol for internal test hooks
- Add TrailBaseTestHooks interface with beforeMarkingReady callback
- Update sync function to await beforeMarkingReady in progressive mode
- Export TRAILBASE_TEST_HOOKS and TrailBaseTestHooks from index.ts
- Update e2e tests to:
  - Create progressive collections with test hooks (startSync: false)
  - Provide progressiveTestControl with releaseInitialSync
  - Allow progressive test suite to run with proper test control

This enables the same test coverage as packages/electric for all sync modes.
- Add Docker configuration:
  - Dockerfile: Based on trailbase/trailbase:latest with config and migrations
  - config.textproto: Record APIs for users_e2e, posts_e2e, comments_e2e
  - init.sql: SQLite schema with TEXT IDs and snake_case columns
  - docker-compose.yml: Optional compose file for manual testing

- Update global-setup.ts to:
  - Build TrailBase Docker image before tests
  - Start container with proper port mapping
  - Wait for TrailBase to be healthy (60s timeout)
  - Stop and cleanup container after tests
The global-setup now checks for a local binary at testing-bin-linux/trail
before falling back to Docker, making it easier to run tests in environments
without Docker support.
…ction

- Changed init.sql to use BLOB PRIMARY KEY with uuid_v7() default
  (TrailBase requires INTEGER or UUID primary keys, not TEXT)
- Updated global-setup to check multiple binary paths
- Added .gitignore for temp e2e data directories
- Updated README with architecture-specific download instructions
- Added STRICT mode to init.sql (required by TrailBase)
- Fixed trailbase import: use initClient instead of Client constructor
- Added workspace package aliases in vitest config
- Use serializeUserForInsert/serializePostForInsert in mutations config
- These omit the id field since TrailBase auto-generates with INTEGER PRIMARY KEY
- Removed unused full serialize functions
- Remaining failures are mostly progressive mode timeouts
- Use BLOB PKs with CHECK(is_uuid_v7(id)) DEFAULT (uuid_v7())
- Remove unused config objects (linting fix)
TrailBase auto-generates INTEGER PRIMARY KEY IDs. To support test
mutations that use client-provided UUIDs, maintain a mapping from
original UUID to TrailBase-generated ID for delete/update operations.

Test status: 109/118 passing. Remaining failures:
- 3 progressive mode tests (timeout)
- 4 pagination/mutation tests (sync timing)
Test status: 111/118 passing
- 3 progressive mode tests (timeout)
- 2 mutation/live-update tests (reactive update timing)
- 2 pagination tests (multi-column orderBy)
- Switch to BLOB UUID schema with base64 encoding
- Implement client-provided UUIDs to match shared test suite expectations
- Add cleanup step to remove stale records before seeding
- Skip Electric-specific progressive test control tests
- Update parse/serialize functions to handle base64 UUID encoding
…5/118 passing)

- Cache loadSubset completion to prevent redundant fetches
- Fixes mutation subscription test by ensuring consistent data
- 3 remaining failures are edge cases with multi-column orderBy tie-breaking
…rting

- Change schema to use camelCase column names (userId, isActive, createdAt, etc.)
  to match @tanstack/db-collection-e2e types directly
- Simplify parse/serialize functions by removing snake_case conversion
- Add decodeIdForSorting() helper to properly sort base64-encoded UUIDs
- Sort records by decoded UUID before insertion for deterministic tie-breaking
…conditions

- Replace boolean flag with promise for loadSubset to handle concurrent calls
- All concurrent calls now return the same promise instead of racing
- Maintains 114-115/118 tests passing

Remaining issues:
- 3 multi-column orderBy tests with mixed directions on posts collection
- 1 flaky mutation test
…GRew7

merge latest main with branch Claude/add-trailbase-e2e-tests
The SSE event handling (Insert/Update/Delete) and mutation tests are now
fully covered by the comprehensive E2E test suites:
- createMutationsTestSuite
- createLiveUpdatesTestSuite

Keep only the cancellation test as it tests internal cleanup behavior
(stream closing, double-cancel safety) not covered by E2E tests.
@changeset-bot
Copy link

changeset-bot bot commented Jan 5, 2026

⚠️ No Changeset found

Latest commit: 96e1b3a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@samwillis
Copy link
Collaborator

Hey, @ignatz I don't suppose you could take a look at this and #1090?

@ignatz
Copy link
Contributor

ignatz commented Jan 7, 2026

@samwillis Ack

@MentalGear could you clarify the relationship between #1090 and #1089, I looked at the history:

Screenshot From 2026-01-07 09-59-14

And it seems like they are close siblings with both removing "redundant unit tests", maybe you didn't want to open two PRs? For now I will ignore #1089 and comment on #1090 only.

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.

4 participants