Skip to content

feat(#658): add a viewer composite to mock-services for MSW-regime tests - #715

Merged
zgeoff merged 3 commits into
mainfrom
feat/658-mock-viewer-composite
Jul 20, 2026
Merged

feat(#658): add a viewer composite to mock-services for MSW-regime tests#715
zgeoff merged 3 commits into
mainfrom
feat/658-mock-viewer-composite

Conversation

@zgeoff

@zgeoff zgeoff commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Description

Closes #658

Adds a createViewer composite to @vers/mock-services — one call seeding a user row, a linked avatar row, and a test access token in the @msw/data store — and adopts it across idle-client's worker and resync tests, replacing the inlined user/avatar seed blocks.

  • Returns data only (user, avatar, token); tests keep building their own oRPC client, mirroring how the real-database viewer composite leaves client construction in-test
  • user/avatar override bags pass through to the collections' defaults; the avatar's user linkage comes free, and an explicit avatar.userID override still wins
  • Exports AvatarRowSchema from the db subpath so the composite's override types derive from the row schema, matching the user row

Testing

  • bun run typecheck passes
  • bun run test passes
  • bun run lint passes
  • New tests added for new functionality

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 6c2690a6-2155-462a-98f6-a9534233a51e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Changes

Viewer fixture and test adoption

Layer / File(s) Summary
Viewer fixture implementation and exports
libs/testing/mock-services/src/create-viewer.ts, libs/testing/mock-services/src/create-viewer.test.ts, libs/testing/mock-services/src/db/*, libs/testing/mock-services/src/index.ts
Adds createViewer() for linked user/avatar rows and access tokens, supports overrides, validates persistence and JWT linkage, and exports the helper and avatar schema.
Resync, continuation, and simulation test fixtures
libs/game/idle-client/src/resync/run-resync.test.ts, libs/game/idle-client/src/worker/run-continuation.test.ts, libs/game/idle-client/src/worker/run-simulation.test.ts
Replaces manual identity seeding with viewer-derived IDs across resync, continuation, conflict, checkpoint, and simulation scenarios.
Worker runtime, stop, and message fixtures
libs/game/idle-client/src/worker/create-worker-runtime.test.ts, libs/game/idle-client/src/worker/flush-pending-stop.test.ts, libs/game/idle-client/src/worker/handle-client-message.test.ts, libs/game/idle-client/src/worker/handle-stop-activity-message.test.ts
Uses createViewer() for worker runtime, pending-stop, client-message, and stop-message test setup.
Request resync behavior tests
libs/game/idle-client/src/worker/handle-request-resync-message.test.ts
Updates resync activity, queue, continuation, status, failure, and stop assertions to use viewer identities; adds failure-action cache and avatar-state checks.
Failure-action message tests
libs/game/idle-client/src/worker/handle-set-failure-action-message.test.ts
Uses viewer identities in failure-action messages and cached-state assertions while retaining dirty-state and broadcast coverage.

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

Possibly related PRs

  • zgeoff/vers#580: Refactors overlapping idle-client resync and worker tests to use createViewer().
  • zgeoff/vers#613: Changes mocking approaches in several of the same worker test suites.
  • zgeoff/vers#642: Changes resync failure status behavior covered by these updated assertions.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed It clearly states the main change: adding a viewer composite to mock-services for MSW tests.
Description check ✅ Passed It directly describes the composite addition and its adoption across idle-client tests.
Linked Issues check ✅ Passed The PR adds createViewer, tests it, exports AvatarRowSchema, and adopts it across idle-client worker tests as requested.
Out of Scope Changes check ✅ Passed The changes stay within the viewer-composite work and related test refactors; no unrelated edits are indicated.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/658-mock-viewer-composite

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@libs/testing/mock-services/src/create-viewer.ts`:
- Line 26: Update the avatar creation call in createViewer so config.avatar
cannot overwrite userID when its value is undefined; preserve user.id as the
fallback owner while still allowing an explicitly provided defined userID to be
honored.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 29d1047a-83c8-47f0-882b-62da9a11b73e

📥 Commits

Reviewing files that changed from the base of the PR and between 5e06526 and 8be6355.

📒 Files selected for processing (14)
  • libs/game/idle-client/src/resync/run-resync.test.ts
  • libs/game/idle-client/src/worker/create-worker-runtime.test.ts
  • libs/game/idle-client/src/worker/flush-pending-stop.test.ts
  • libs/game/idle-client/src/worker/handle-client-message.test.ts
  • libs/game/idle-client/src/worker/handle-request-resync-message.test.ts
  • libs/game/idle-client/src/worker/handle-set-failure-action-message.test.ts
  • libs/game/idle-client/src/worker/handle-stop-activity-message.test.ts
  • libs/game/idle-client/src/worker/run-continuation.test.ts
  • libs/game/idle-client/src/worker/run-simulation.test.ts
  • libs/testing/mock-services/src/create-viewer.test.ts
  • libs/testing/mock-services/src/create-viewer.ts
  • libs/testing/mock-services/src/db/avatar-collection.ts
  • libs/testing/mock-services/src/db/index.ts
  • libs/testing/mock-services/src/index.ts

Comment thread libs/testing/mock-services/src/create-viewer.ts Outdated
@zgeoff
zgeoff merged commit ac920c2 into main Jul 20, 2026
6 checks passed
@zgeoff
zgeoff deleted the feat/658-mock-viewer-composite branch July 20, 2026 12: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.

add a viewer composite to mock-services for MSW-regime tests

1 participant