Skip to content

chore: fix driver test suite#4591

Open
NathanFlurry wants to merge 1 commit intomainfrom
04-08-chore_fix_driver_test_suite
Open

chore: fix driver test suite#4591
NathanFlurry wants to merge 1 commit intomainfrom
04-08-chore_fix_driver_test_suite

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

@NathanFlurry NathanFlurry mentioned this pull request Apr 8, 2026
11 tasks
@claude
Copy link
Copy Markdown

claude bot commented Apr 8, 2026

PR Review: chore: fix driver test suite

Summary

This PR bundles several distinct improvements: driver test suite restructuring (splitting the monolithic actor-driver.ts into per-category files), native SQLite NAPI bindings, envoy shutdown robustness fixes, and several client-side bug fixes. The changes are generally well-motivated. A few items are worth flagging.


POTENTIAL ISSUES

  1. serialize_actor_key -- Breaking serialization format change
    (engine/packages/guard/src/routing/pegboard_gateway/resolve_actor_query.rs)

The old implementation used serde_json::to_string(key) (output: ["foo","bar"]). The new implementation uses a custom /-separated escape scheme (output: foo/bar). Any existing actors stored with the old JSON key format will no longer be found at query time. If this function is used for both storage and lookup, a migration path is needed -- or confirmation that actor key data does not survive restarts and this is purely a runtime routing lookup.

Also, the EMPTY_KEY constant is confusing -- it reads as "empty key" but is used as both the sentinel for an empty key array AND the join separator. Rename to SEPARATOR.

  1. JsNativeDatabase::as_ptr() -- Lock released before pointer is used
    (rivetkit-typescript/packages/rivetkit-native/src/database.rs)

The MutexGuard is dropped at the end of the and_then chain, so the returned raw pointer is not protected. A concurrent close() call would free the database while the caller holds the dangling pointer. The new Arc<Mutex<Option<...>>> wrapper makes this a realistic scenario. If as_ptr() is only used internally before close, a safety comment explaining the contract is needed.

  1. extractNamedSqliteParameters -- False matches inside string literals
    (rivetkit-typescript/packages/rivetkit-native/wrapper.js)

The regex /([:@$][A-Za-z_][A-Za-z0-9_]*)/g matches parameter-like patterns inside SQL string literals (e.g., SELECT ':user' would incorrectly capture :user). This can silently produce wrong bindings. A comment acknowledging the limitation and usage constraints would be appropriate.

  1. Blob column values returned as Array
    (rivetkit-typescript/packages/rivetkit-native/src/database.rs)

Blobs are serialized as serde_json::Value::Array of byte integers rather than Buffer/Uint8Array. Most SQLite wrappers represent blobs as typed arrays. The JS wrapper layer in wrapper.js does not convert this, so consumers receive an array of numbers -- likely breaking compatibility with the existing WASM SQLite VFS layer.

  1. Redundant Uint8Array check in normalizeBindings
    (rivetkit-typescript/packages/rivetkit-native/wrapper.js)

!(args[0] instanceof Uint8Array) is redundant -- isPlainObject already excludes Uint8Array via Object.getPrototypeOf(value) === Object.prototype. Minor, but can be cleaned up.


POSITIVE CHANGES

  • Envoy shutdown atomics (connection.rs, envoy.rs, handle.rs): Correct use of Ordering::Acquire/Release pair. The two-point shutdown check in the reconnect loop (before and after the connection attempt) prevents a reconnect from being initiated during shutdown.

  • sendWsMessage silent no-op on missing sender (envoy_handle.rs): Changing a hard error to a best-effort send is the right call for the shutdown-race case. The comment explains the intent well.

  • onOpen race fix with queueMicrotask (actor-conn.ts): Correctly handles the case where onOpen is registered after the connection is already established. Using queueMicrotask preserves async delivery semantics; checking #openHandlers.has(callback) before firing guards against the unsubscribe-before-fire race.

  • startServerless promoted to Promise: Proper fix for async error handling in the serverless start path.

  • onBeforeConnect deadline (connection-manager.ts): Good addition; an infinite onBeforeConnect would previously deadlock the connection.

  • URL robustness in router.ts: The fallback chain (c.req.url || c.req.raw.url || constructed path) handles environments where the request URL may not be a fully qualified URL.

  • createNodeRequire / nativeDynamicImport patterns (sqlite-vfs/src/vfs.ts, pool.ts): Valid ESM/CJS interop techniques for environments where import.meta.url is unavailable or bundlers block direct imports.

  • Test suite restructuring: Splitting the monolithic actor-driver.ts into per-category test files (actor-state, actor-schedule, actor-sleep, etc.) is a meaningful improvement for isolation and targeted debugging. The agent tracking note in .agent/notes/ is a useful complement.

  • Pool name randomization in driver-engine.test.ts: Using crypto.randomUUID().slice(0, 8) for the pool name avoids cross-test collisions from shared pool state.


MINOR NOTES

  • The isActorStoppingDbError string match in actor-db.ts is fragile; consider matching on a structured error code if one is available.
  • vitest.base.ts now sets maxConcurrency from availableParallelism() -- good default, but worth noting this can be surprising on CI machines with many cores if tests share external state.

Generated with Claude Code

@NathanFlurry NathanFlurry force-pushed the 04-08-chore_fix_driver_test_suite branch from 1919c35 to 7283250 Compare April 8, 2026 11:01
@MasterPtato MasterPtato changed the base branch from 04-07-chore_remove_udb_as_a_dependency_of_envoy-client to graphite-base/4591 April 8, 2026 20:11
@MasterPtato MasterPtato force-pushed the 04-08-chore_fix_driver_test_suite branch from 7283250 to 5c3dbdf Compare April 8, 2026 20:11
@MasterPtato MasterPtato force-pushed the 04-08-chore_fix_driver_test_suite branch from 5c3dbdf to 5037448 Compare April 8, 2026 20:14
@MasterPtato MasterPtato changed the base branch from graphite-base/4591 to 04-08-chore_tunnel_auth April 8, 2026 20:14
@MasterPtato MasterPtato force-pushed the 04-08-chore_fix_driver_test_suite branch from 5037448 to ffdf968 Compare April 8, 2026 20:30
@NathanFlurry NathanFlurry changed the base branch from 04-08-chore_tunnel_auth to graphite-base/4591 April 8, 2026 20:39
@NathanFlurry NathanFlurry force-pushed the 04-08-chore_fix_driver_test_suite branch from ffdf968 to 9b6c03d Compare April 8, 2026 20:39
@NathanFlurry NathanFlurry changed the base branch from graphite-base/4591 to 04-07-chore_remove_udb_as_a_dependency_of_envoy-client April 8, 2026 20:39
@MasterPtato MasterPtato changed the base branch from 04-07-chore_remove_udb_as_a_dependency_of_envoy-client to graphite-base/4591 April 8, 2026 20:46
@MasterPtato MasterPtato force-pushed the 04-08-chore_fix_driver_test_suite branch from 9b6c03d to 7319f2d Compare April 8, 2026 20:46
@MasterPtato MasterPtato changed the base branch from graphite-base/4591 to 04-08-chore_tunnel_auth April 8, 2026 20:46
@MasterPtato MasterPtato force-pushed the 04-08-chore_fix_driver_test_suite branch from 7319f2d to 8a1d3a0 Compare April 8, 2026 20:49
@MasterPtato MasterPtato changed the base branch from 04-08-chore_tunnel_auth to graphite-base/4591 April 8, 2026 21:32
@MasterPtato MasterPtato force-pushed the 04-08-chore_fix_driver_test_suite branch from 8a1d3a0 to a84fd3d Compare April 8, 2026 21:38
@graphite-app graphite-app bot changed the base branch from graphite-base/4591 to main April 8, 2026 21:38
@MasterPtato MasterPtato force-pushed the 04-08-chore_fix_driver_test_suite branch from a84fd3d to 124d6d9 Compare April 8, 2026 21:38
@NathanFlurry NathanFlurry force-pushed the 04-08-chore_fix_driver_test_suite branch from 124d6d9 to c84f9db Compare April 8, 2026 22:11
@MasterPtato MasterPtato force-pushed the 04-08-chore_fix_driver_test_suite branch from c84f9db to ab96a82 Compare April 8, 2026 23:26
@MasterPtato MasterPtato mentioned this pull request Apr 9, 2026
11 tasks
@NathanFlurry NathanFlurry mentioned this pull request Apr 9, 2026
11 tasks
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