Skip to content
This repository was archived by the owner on Jun 4, 2026. It is now read-only.
This repository was archived by the owner on Jun 4, 2026. It is now read-only.

Need a test suite #7

@christse

Description

@christse

Test Suite Implementation Plan

Overview

Add comprehensive test coverage to boxel-cli. Currently Vitest is configured but no tests exist.

Test Categories

Priority 1: Unit Tests (Pure Functions)

These require no mocking and provide immediate value:

batch-upload.ts

  • sortDefinitionsFirst() - .gts files sorted before .json
  • createBatches() - respects batch size and payload limits
  • buildAtomicRequest() - correct JSON:API format for /_atomic

edit-lock.ts

  • addToEditLock() - adds file to lock list
  • removeFromEditLock() - removes file from lock list
  • isFileBeingEdited() - correctly identifies locked files
  • getEditingFiles() - returns all locked files

sync.ts - Action Computation

  • Local changed + remote unchanged → PUSH
  • Local unchanged + remote changed → PULL
  • Both changed → CONFLICT
  • Local deleted + remote changed → CONFLICT
  • Remote deleted + local changed → CONFLICT
  • New local file → PUSH
  • New remote file → PULL

profile-manager.ts

  • getEnvironmentFromMatrixId() - detects staging vs production
  • Credential resolution order (profile > env vars)
  • Profile file permissions (0o600)

Priority 2: File-Based Tests (Temp Directories)

checkpoint-manager.ts

  • createCheckpoint() - creates git commit with changes
  • restore() - reverts to previous checkpoint
  • getMilestones() - lists tagged checkpoints
  • markMilestone() / unmarkMilestone()
  • Checkpoint classification (MAJOR vs minor)
  • Change tracking (added/modified/deleted)

realm-config.ts

  • loadConfig() / saveConfig()
  • getRealmForFile() - pattern matching
  • Multi-realm file routing

Priority 3: Integration Tests (Mock HTTP)

sync command

  • Full push flow (local → remote)
  • Full pull flow (remote → local)
  • Conflict resolution with --prefer-local
  • Conflict resolution with --prefer-remote
  • Manifest migration (old → new format)
  • --dry-run mode
  • Batch upload integration

track command

  • File change detection (add/modify/delete)
  • Debounce timer behavior
  • Minimum interval enforcement
  • --push mode with batch upload
  • Skip internal files (.boxel-*, .git)

watch command

  • Remote polling interval
  • Debounce before checkpoint
  • JWT caching (no re-fetch per poll)

status command

  • Single workspace status
  • --all flag for multiple workspaces
  • --pull auto-pull mode

Proposed Structure

src/
  __mocks__/
    fs.ts                    # Mock file system
    fetch.ts                 # Mock HTTP calls
    matrix-client.ts         # Stub auth client
  __tests__/
    unit/
      batch-upload.test.ts
      edit-lock.test.ts
      sync-actions.test.ts
      profile-manager.test.ts
      checkpoint-manager.test.ts
      realm-config.test.ts
    integration/
      sync.test.ts
      track.test.ts
      watch.test.ts
      status.test.ts
    fixtures/
      manifests/             # Sample .boxel-sync.json files
      workspaces/            # Test workspace structures

Mock Strategy

Dependency Mock Approach
fs In-memory file system or temp directories
fetch Mock responses for Matrix/Boxel APIs
MatrixClient Stub that returns test JWT
child_process Mock git commands
fs.watch Event emitter simulation

Implementation Order

  1. Setup - Configure Vitest, create mock utilities
  2. batch-upload.test.ts - Easiest wins, pure functions
  3. edit-lock.test.ts - Simple file operations
  4. sync-actions.test.ts - Critical conflict logic
  5. checkpoint-manager.test.ts - Core feature
  6. Integration tests - Full command flows

Success Criteria

  • All pure functions have unit tests
  • Conflict detection has 100% case coverage
  • Core commands (sync, track, watch) have integration tests
  • CI runs tests on PR
  • Coverage report generated

Notes

  • Vitest already configured in package.json
  • Focus on testing logic, not CLI output formatting
  • Use temp directories for file-based tests to avoid pollution
  • Mock network calls to avoid flaky tests

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions