Skip to content

test(rivetkit-core): cover sleep/destroy guards and prevent_sleep no-op#4750

Merged
NathanFlurry merged 1 commit intomainfrom
sleep-cleanup/09-rust-sleep-tests
Apr 27, 2026
Merged

test(rivetkit-core): cover sleep/destroy guards and prevent_sleep no-op#4750
NathanFlurry merged 1 commit intomainfrom
sleep-cleanup/09-rust-sleep-tests

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 24, 2026

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

@NathanFlurry NathanFlurry force-pushed the sleep-cleanup/08-sleep-docs branch from d844ecd to e68bdc2 Compare April 24, 2026 11:48
@NathanFlurry NathanFlurry force-pushed the sleep-cleanup/09-rust-sleep-tests branch 3 times, most recently from 89647d5 to ed93ef7 Compare April 24, 2026 12:32
@NathanFlurry NathanFlurry force-pushed the sleep-cleanup/08-sleep-docs branch from 391fcaa to e4395f8 Compare April 24, 2026 12:32
@NathanFlurry NathanFlurry force-pushed the sleep-cleanup/08-sleep-docs branch from e4395f8 to d1c2bbf Compare April 24, 2026 13:16
@NathanFlurry NathanFlurry force-pushed the sleep-cleanup/09-rust-sleep-tests branch from ed93ef7 to 8d93174 Compare April 24, 2026 13:16
@claude
Copy link
Copy Markdown

claude Bot commented Apr 24, 2026

Code Review

PR: test(rivetkit-core): cover sleep/destroy guards and prevent_sleep no-op
Scope: 87 additions, 0 deletions — pure test additions to rivetkit-rust/packages/rivetkit-core/src/actor/sleep.rs

Summary

This PR adds 6 targeted tests verifying documented invariants from the rivetkit-core CLAUDE.md. The coverage is well-chosen and the test structure is consistent with existing tests in the module.

Strengths

  • Invariant coverage matches the spec. The rivetkit-core CLAUDE.md explicitly states ctx.sleep() and ctx.destroy() return ActorLifecycleError::Starting before startup and ActorLifecycleError::Stopping on re-request. Each new test pins exactly one of those behaviors.
  • Deprecated no-op tested both ways. set_prevent_sleep_is_a_deprecated_noop calls the API with both true and false and asserts can_sleep() returns CanSleep::Yes in both cases.
  • Precise error assertions. Tests assert both group() and code(), tying them to the canonical RivetError taxonomy rather than just checking that an error occurred.
  • Inline test placement is justified. The tests need pub(crate) helpers (new_for_sleep_tests, set_sleep_started, can_sleep, etc.) that are inaccessible from an external tests/ crate. The CLAUDE.md exception for private internals applies.

Minor Issues

1. Comment describes "what", not "why"

In set_prevent_sleep_is_a_deprecated_noop:

// The sleep predicate ignores prevent_sleep entirely.
assert_eq!(ctx.can_sleep().await, CanSleep::Yes);

CLAUDE.md says to write comments only when the why is non-obvious, not to describe what the code does. The assert! message above already states the intent. Either remove this line or replace it with the invariant it encodes (e.g. "no CanSleep::PreventSleep variant; set_prevent_sleep is kept only for NAPI bridge compat").

2. Cross-guard scenarios not tested (optional follow-up)

sleep_requested and destroy_requested are independent atomics. Calling sleep() after destroy() has been requested (and vice versa) succeeds silently today. If this is intentional, a comment in the source or a test pinning that behavior would prevent someone from incorrectly adding a cross-guard later.

Not Issues

  • double_sleep / double_destroy omit set_ready(true): correct — sleep()/destroy() gate only on sleep.started, not sleep.ready.
  • The first sleep() in double_sleep spawns a tracked shutdown task internally. This does not affect the sleep_requested atomic read by the second call, so the test is sound.
  • The second can_sleep().await in set_prevent_sleep_is_a_deprecated_noop is technically redundant, but confirming both true and false arguments leave the result unchanged is reasonable for a two-state no-op.

Verdict

Clean, well-scoped test additions. The comment-style issue is minor and does not block merging. The cross-guard gap is a follow-up, not a blocker.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

Preview packages published to npm

Install with:

npm install rivetkit@pr-4750

All packages published as 0.0.0-pr.4750.8a663b7 with tag pr-4750.

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-8a663b7
docker pull rivetdev/engine:full-8a663b7
Individual packages
npm install rivetkit@pr-4750
npm install @rivetkit/react@pr-4750
npm install @rivetkit/rivetkit-napi@pr-4750
npm install @rivetkit/workflow-engine@pr-4750

Base automatically changed from sleep-cleanup/08-sleep-docs to main April 27, 2026 07:13
@NathanFlurry NathanFlurry merged commit 35af6e8 into main Apr 27, 2026
35 of 42 checks passed
@NathanFlurry NathanFlurry deleted the sleep-cleanup/09-rust-sleep-tests branch April 27, 2026 07:14
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