diff --git a/rivetkit-typescript/packages/rivetkit/tests/fixtures/napi-runtime-server.ts b/rivetkit-typescript/packages/rivetkit/tests/fixtures/napi-runtime-server.ts index a7fedd554d..0a95c209db 100644 --- a/rivetkit-typescript/packages/rivetkit/tests/fixtures/napi-runtime-server.ts +++ b/rivetkit-typescript/packages/rivetkit/tests/fixtures/napi-runtime-server.ts @@ -7,7 +7,6 @@ import { db } from "../../src/db/mod"; import { actor, event, queue, setup, UserError } from "../../src/mod"; import { buildNativeRegistry } from "../../src/registry/native"; -const textDecoder = new TextDecoder(); const fixtureDir = dirname(fileURLToPath(import.meta.url)); const repoEngineBinary = resolve( fixtureDir, @@ -79,9 +78,10 @@ const integrationActor = actor({ await c.db.execute( "CREATE TABLE IF NOT EXISTS increments (value INTEGER NOT NULL)", ); - await c.db.execute("INSERT INTO increments (value) VALUES (?)", [ + await c.db.execute( + "INSERT INTO increments (value) VALUES (?)", c.state.count, - ]); + ); const rows = await c.db.execute<{ value: number }>( "SELECT value FROM increments ORDER BY rowid ASC", @@ -102,7 +102,7 @@ const integrationActor = actor({ return { count: c.state.count, - kvCount: kvValue ? Number(textDecoder.decode(kvValue)) : null, + kvCount: kvValue ? Number(kvValue) : null, sqliteValues: rows.map(({ value }) => Number(value)), }; }, @@ -117,12 +117,14 @@ const integrationActor = actor({ const kvValue = await c.kv.get("count"); return { count: c.state.count, - kvCount: kvValue ? Number(textDecoder.decode(kvValue)) : null, + kvCount: kvValue ? Number(kvValue) : null, }; }, getCountViaClient: async (c) => { const client = c.client(); - return await client.integrationActor.getForId(c.actorId).getCount(); + return await client.integrationActor + .getForId(c.actorId, { params: c.conn.params }) + .getCount(); }, throwTypedError: async () => { throw new UserError("native typed error", { @@ -159,4 +161,20 @@ const { registry: nativeRegistry, serveConfig } = await buildNativeRegistry( ); serveConfig.engineBinaryPath = resolveEngineBinaryPath(); -await nativeRegistry.serve(serveConfig); +const shutdown = new Promise<"signal">((resolve) => { + process.once("SIGINT", () => resolve("signal")); +}); +const serving = nativeRegistry.serve(serveConfig); + +await nativeRegistry.waitReady(); +const stopReason = await Promise.race([ + shutdown, + serving.then(() => "registry" as const), +]); +if (stopReason === "registry") { + throw new Error( + "native registry stopped before the test requested shutdown", + ); +} +await nativeRegistry.shutdown(); +await serving; diff --git a/rivetkit-typescript/packages/rivetkit/tests/napi-runtime-integration.test.ts b/rivetkit-typescript/packages/rivetkit/tests/napi-runtime-integration.test.ts index c5c605017b..ade7af7afb 100644 --- a/rivetkit-typescript/packages/rivetkit/tests/napi-runtime-integration.test.ts +++ b/rivetkit-typescript/packages/rivetkit/tests/napi-runtime-integration.test.ts @@ -291,9 +291,10 @@ describe.sequential("native NAPI runtime integration", () => { const handle = await waitForActorReady( () => - client.integrationActor.create([ - `napi-runtime-${crypto.randomUUID()}`, - ]), + client.integrationActor.create( + [`napi-runtime-${crypto.randomUUID()}`], + { params: { userId: "native-integration-test" } }, + ), 30_000, ); const actorId = await handle.resolve(); @@ -384,7 +385,7 @@ describe.sequential("native NAPI runtime integration", () => { }, }); await expect(handle.throwUntypedError()).rejects.toMatchObject({ - group: "core", + group: "rivetkit", code: "internal_error", message: "An internal error occurred", });