Skip to content

test(rivetkit): cover c.db access from onWake/onSleep/onDestroy#4786

Merged
NathanFlurry merged 1 commit intomainfrom
cleanup/db-lifecycle-coverage
Apr 27, 2026
Merged

test(rivetkit): cover c.db access from onWake/onSleep/onDestroy#4786
NathanFlurry merged 1 commit intomainfrom
cleanup/db-lifecycle-coverage

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member Author

NathanFlurry commented Apr 26, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown

claude Bot commented Apr 26, 2026

PR Review for test(rivetkit): cover c.db access from onWake/onSleep/onDestroy

SUMMARY

This PR extends the db-init-order test fixture to verify that c.db is accessible from onWake, onSleep, and onDestroy lifecycle hooks. It refactors initOrderProvider() to eliminate repetition.

WHAT IS DONE WELL

  • DRY refactor: initOrderProvider() returns a fresh db() config instance per call
  • Test isolation: UUID-based actor keys + fresh spawned process per test, no cross-contamination
  • Observer actor pattern: dbInitOrderObserver avoids resetting the sleep deadline on the actor under test
  • No vi.mock or jest.mock usage; no new vi.waitFor calls

ISSUES

  1. Missing sleep-skip guard on sleep-dependent tests (Actionable)

The onWake and onSleep tests depend on actor sleep but are not guarded by a skip condition. Other sleep tests consistently use describe.skipIf(driverTestConfig.skip?.sleep) or equivalent (see actor-run.test.ts:9, actor-workflow.test.ts:387, actor-sleep-db.test.ts:114). The onDestroy test does not involve sleep and is fine. The two sleep-dependent tests should be wrapped for forward-compatibility with driver variants that disable sleep.

File: rivetkit-typescript/packages/rivetkit/tests/driver/actor-db-init-order.test.ts:60-155

  1. Polling the sleeping actor can reset the sleep deadline (Minor)

CLAUDE.md states: Driver tests that wait for actor sleep must not poll actor actions while waiting. In the onWake test, after waitFor(150ms), there is a loop calling actor.getWakeCount() every 25ms (actor-db-init-order.test.ts:77-81). Under CI load this could reset the sleep deadline before the actor sleeps. The same pattern exists in actor-run.test.ts so it is not a new regression.

  1. Static observer key across encoding variants (Low)

Both onSleep and onDestroy tests use the hardcoded key db-init-order-observer (actor-db-init-order.test.ts:92, 132). Tests run sequentially in isolated namespaces so no collision occurs today, but a UUID suffix would make isolation explicit.

NO ISSUES FOUND

  • Registry registration in registry-static.ts is correct; all four new actors imported and registered
  • initOrderProvider() correctly produces a fresh db() instance per call
  • scheduleActorSleep follows the established import pattern
  • Module-level Maps are test-only; fresh processes per test keep them empty

RECOMMENDED CHANGES

  1. Wrap the two sleep-dependent tests with test.skipIf(driverTestConfig.skip?.sleep) for forward compatibility
  2. Consider appending crypto.randomUUID() to the observer key to make isolation explicit

Overall this is a solid, well-structured test addition. The main actionable item is adding the sleep-skip guard.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 26, 2026

Preview packages published to npm

Install with:

npm install rivetkit@pr-4786

All packages published as 0.0.0-pr.4786.a7c25b1 with tag pr-4786.

Engine binary is shipped via @rivetkit/engine-cli on linux-x64-musl, linux-arm64-musl, darwin-x64, and darwin-arm64. Windows users should use the release installer or set RIVET_ENGINE_BINARY.

Docker images:

docker pull rivetdev/engine:slim-a7c25b1
docker pull rivetdev/engine:full-a7c25b1
Individual packages
npm install rivetkit@pr-4786
npm install @rivetkit/react@pr-4786
npm install @rivetkit/rivetkit-napi@pr-4786
npm install @rivetkit/workflow-engine@pr-4786

@NathanFlurry NathanFlurry force-pushed the cleanup/db-lifecycle-coverage branch from 7ecf3ef to 7b73290 Compare April 27, 2026 01:06
@NathanFlurry NathanFlurry force-pushed the cleanup/on-migrate-ordering branch from d5ebf66 to 2652aa5 Compare April 27, 2026 01:06
@NathanFlurry NathanFlurry force-pushed the cleanup/db-lifecycle-coverage branch from 7b73290 to 796c8b3 Compare April 27, 2026 01:17
@NathanFlurry NathanFlurry force-pushed the cleanup/on-migrate-ordering branch from 2652aa5 to 33fb1d1 Compare April 27, 2026 01:17
@NathanFlurry NathanFlurry marked this pull request as ready for review April 27, 2026 01:33
@NathanFlurry NathanFlurry force-pushed the cleanup/db-lifecycle-coverage branch from 796c8b3 to 63dbe6f Compare April 27, 2026 01:47
@NathanFlurry NathanFlurry force-pushed the cleanup/on-migrate-ordering branch from 33fb1d1 to 547636c Compare April 27, 2026 01:47
Base automatically changed from cleanup/on-migrate-ordering to main April 27, 2026 07:13
@NathanFlurry NathanFlurry merged commit fc55a97 into main Apr 27, 2026
23 of 77 checks passed
@NathanFlurry NathanFlurry deleted the cleanup/db-lifecycle-coverage branch April 27, 2026 07:13
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.

1 participant