Skip to content

test(rivetkit-napi): move private tests to crate root#4793

Closed
NathanFlurry wants to merge 1 commit into04-24-replay/rivetkit-core-private-test-layoutfrom
04-24-replay/rivetkit-napi-private-test-layout
Closed

test(rivetkit-napi): move private tests to crate root#4793
NathanFlurry wants to merge 1 commit into04-24-replay/rivetkit-core-private-test-layoutfrom
04-24-replay/rivetkit-napi-private-test-layout

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

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

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

@claude
Copy link
Copy Markdown

claude Bot commented Apr 27, 2026

PR #4793 Review: Move private tests to crate root tests/

Overview

This PR moves inline #[cfg(test)] mod tests blocks from three rivetkit-napi source files into corresponding files under tests/. Because the crate is cdylib-only (no lib target), true Cargo integration tests can't link against it, so the approach uses #[path = "../tests/..."] shims to physically place the code in tests/ while keeping it compiled as inline module tests. autotests = false is added to prevent Cargo from mistakenly trying to build those files as standalone integration test binaries.

Issues

Bug: core_ctx.set_started(true) silently dropped in run_adapter_loop_resets_stale_shared_end_reason_before_wake

The original test in src/napi_actor_events.rs sets up the stale actor state like this:

let stale_ctx = ActorContext::new(core_ctx.clone());
core_ctx.set_started(true);   // sets started=true on the shared inner Arc
stale_ctx.set_end_reason(EndReason::Sleep);

The moved test in tests/napi_actor_events.rs omits the set_started call:

let stale_ctx = ActorContext::new(core_ctx.clone());
stale_ctx.set_end_reason(EndReason::Sleep);

Since core_ctx.clone() is an Arc clone, both handles share the same inner state, so set_started(true) was establishing the precondition that the actor had previously been running. Dropping it changes the test's setup and could allow the test to pass for the wrong reason or miss a real regression. This should be restored.

Unnecessary mod moved_tests nesting

Every test file introduces a gratuitous extra module:

use super::*;

mod moved_tests {   // not needed
    use super::*;
    ...
}

The name moved_tests leaks an implementation detail and adds an extra indirection that makes stack traces and cargo test filter paths harder to read (tests become tests::moved_tests::foo instead of tests::foo). The outer use super::*; at file scope is also redundant since nothing uses it there. The tests could live directly at the file root, mirroring the original mod tests { ... } layout:

// tests/actor_context.rs
use super::*;

#[test]
fn reset_runtime_state_clears_end_reason_without_touching_core_lifecycle_flags() { ... }

Missing explanation for autotests = false

The Cargo.toml change is a non-obvious footgun: someone who later adds a normal tests/ integration test will wonder why it never runs. A brief inline comment explaining the cdylib/#[path] coupling would prevent future confusion:

autotests = false  # tests/ files are #[path] shims, not standalone binaries (cdylib has no lib target)

Comment style nit (CLAUDE.md § Comments)

The shim comments use a dash-separated fragment structure. Per project convention, write as a normal complete sentence ending with a period: // Tests live in tests/ via #[path] to keep private-module access while satisfying the crate test layout rule.

What's Good

  • The motivation is sound: CLAUDE.md mandates tests live in tests/; this crate tests private internals that can't be reached from a true integration binary; the #[path] shim is the correct workaround.
  • autotests = false prevents a silent breakage where Cargo would try (and fail) to link the tests/ files as standalone binaries.
  • All test logic is preserved and the tests are functionally identical — except for the one dropped set_started line noted above.

Summary

The approach is architecturally correct. There is one real defect (dropped set_started call that changes a test's precondition), one readability issue (superfluous mod moved_tests wrapper that clutters test output paths), and a few minor comment/documentation nits. The dropped call is the only change that could affect test correctness and should be fixed before merging.

@github-actions
Copy link
Copy Markdown
Contributor

Preview packages published to npm

Install with:

npm install rivetkit@pr-4793

All packages published as 0.0.0-pr.4793.d6c7015 with tag pr-4793.

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

@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-napi-private-test-layout branch from 4020a4b to 7cd073f Compare April 27, 2026 03:27
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from e113941 to 448a22d Compare April 27, 2026 03:27
@NathanFlurry NathanFlurry marked this pull request as ready for review April 27, 2026 03:53
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from 448a22d to f691ba2 Compare April 27, 2026 03:59
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-napi-private-test-layout branch 2 times, most recently from 8691b85 to f2496c3 Compare April 27, 2026 04:35
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from 27bb588 to da8c2af Compare April 27, 2026 04:35
@NathanFlurry NathanFlurry changed the base branch from 04-24-replay/rivetkit-core-private-test-layout to graphite-base/4793 April 27, 2026 05:01
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-napi-private-test-layout branch from f2496c3 to bb40216 Compare April 27, 2026 05:37
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from 6fdd701 to c23eb1d Compare April 27, 2026 07:30
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-napi-private-test-layout branch from bb40216 to 86aa51c Compare April 27, 2026 07:31
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from c23eb1d to 81d507e Compare April 27, 2026 07:57
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-napi-private-test-layout branch from 86aa51c to dcc5feb Compare April 27, 2026 07:57
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from 81d507e to 752dc10 Compare April 27, 2026 08:31
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-napi-private-test-layout branch from dcc5feb to 0a08146 Compare April 27, 2026 08:31
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-napi-private-test-layout branch 3 times, most recently from ab43d8c to 9ec450d Compare April 27, 2026 19:40
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from 0a6cfad to f19a1d1 Compare April 27, 2026 20:48
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-napi-private-test-layout branch from 9ec450d to b0f27e8 Compare April 27, 2026 20:48
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-napi-private-test-layout branch from b0f27e8 to 9d22436 Compare April 27, 2026 21:38
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from f19a1d1 to 4e4050a Compare April 27, 2026 21:38
@NathanFlurry
Copy link
Copy Markdown
Member Author

Landed in main via stack-merge fast-forward push. Commits are in main; closing to match.

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