Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 83dca59

Browse files
committed
chore(core): clean up token configs (#1298)
1 parent 624aff1 commit 83dca59

File tree

9 files changed

+78
-35
lines changed

9 files changed

+78
-35
lines changed

packages/rivetkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
"@bare-ts/lib": "~0.3.0",
164164
"@hono/standard-validator": "^0.1.3",
165165
"@hono/zod-openapi": "^0.19.10",
166-
"@rivetkit/engine-runner": "https://pkg.pr.new/rivet-dev/engine/@rivetkit/engine-runner@a0639d0",
166+
"@rivetkit/engine-runner": "https://pkg.pr.new/rivet-dev/engine/@rivetkit/engine-runner@0cfcf3d",
167167
"@rivetkit/fast-json-patch": "^3.1.2",
168168
"cbor-x": "^1.6.0",
169169
"hono": "^4.7.0",

packages/rivetkit/src/client/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export const ClientConfigSchema = z.object({
1616

1717
token: z
1818
.string()
19-
.nullable()
20-
.default(() => getEnvUniversal("RIVET_TOKEN") ?? null),
19+
.optional()
20+
.transform((x) => x ?? getEnvUniversal("RIVET_TOKEN")),
2121

2222
headers: z.record(z.string()).optional().default({}),
2323

packages/rivetkit/src/driver-test-suite/mod.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { runRequestAccessTests } from "./tests/request-access";
3333
export interface SkipTests {
3434
schedule?: boolean;
3535
sleep?: boolean;
36+
sse?: boolean;
3637
}
3738

3839
export interface DriverTestConfig {
@@ -87,7 +88,10 @@ export function runDriverTests(
8788
runActorDriverTests(driverTestConfig);
8889
runManagerDriverTests(driverTestConfig);
8990

90-
for (const transport of ["websocket", "sse"] as Transport[]) {
91+
const transports: Transport[] = driverTestConfig.skip?.sse
92+
? ["websocket"]
93+
: ["websocket", "sse"];
94+
for (const transport of transports) {
9195
describe(`transport (${transport})`, () => {
9296
runActorConnTests({
9397
...driverTestConfig,

packages/rivetkit/src/drivers/default.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ import { loggerWithoutContext } from "@/actor/log";
33
import { createEngineDriver } from "@/drivers/engine/mod";
44
import { createFileSystemOrMemoryDriver } from "@/drivers/file-system/mod";
55
import type { DriverConfig, RunConfig } from "@/registry/run-config";
6-
import { getEnvUniversal } from "@/utils";
76

87
/**
98
* Chooses the appropriate driver based on the run configuration.
109
*/
1110
export function chooseDefaultDriver(runConfig: RunConfig): DriverConfig {
12-
const engineEndpoint = runConfig.endpoint ?? getEnvUniversal("RIVET_ENGINE");
13-
14-
if (engineEndpoint && runConfig.driver) {
11+
if (runConfig.endpoint && runConfig.driver) {
1512
throw new UserError(
1613
"Cannot specify both 'engine' and 'driver' in configuration",
1714
);
@@ -21,12 +18,16 @@ export function chooseDefaultDriver(runConfig: RunConfig): DriverConfig {
2118
return runConfig.driver;
2219
}
2320

24-
if (engineEndpoint) {
21+
if (runConfig.endpoint) {
2522
loggerWithoutContext().debug({
2623
msg: "using rivet engine driver",
27-
endpoint: engineEndpoint,
24+
endpoint: runConfig.endpoint,
25+
});
26+
// TODO: Add all properties from config
27+
return createEngineDriver({
28+
endpoint: runConfig.endpoint,
29+
token: runConfig.token,
2830
});
29-
return createEngineDriver({ endpoint: engineEndpoint });
3031
}
3132

3233
loggerWithoutContext().debug({ msg: "using default file system driver" });

packages/rivetkit/src/drivers/engine/actor-driver.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ export class EngineActorDriver implements ActorDriver {
8686
const runnerConfig: RunnerConfig = {
8787
version: this.#version,
8888
endpoint: config.endpoint,
89+
token: config.token,
8990
pegboardEndpoint: config.pegboardEndpoint,
9091
namespace: config.namespace,
9192
totalSlots: config.totalSlots,
9293
runnerName: config.runnerName,
9394
runnerKey: config.runnerKey,
94-
token: config.token,
9595
metadata: {
9696
inspectorToken: this.#runConfig.inspector.token(),
9797
},
@@ -304,15 +304,13 @@ export class EngineActorDriver implements ActorDriver {
304304

305305
const url = new URL(request.url);
306306

307+
// Parse configuration from Sec-WebSocket-Protocol header
307308
const protocols = request.headers.get("sec-websocket-protocol");
308309
if (protocols === null)
309310
throw new Error(`Missing sec-websocket-protocol header`);
310311

311-
// Parse configuration from Sec-WebSocket-Protocol header
312-
const protocols = request.headers.get("sec-websocket-protocol");
313312
let encodingRaw: string | undefined;
314313
let connParamsRaw: string | undefined;
315-
let token: string | undefined;
316314

317315
if (protocols) {
318316
const protocolList = protocols.split(",").map((p) => p.trim());
@@ -323,8 +321,6 @@ export class EngineActorDriver implements ActorDriver {
323321
connParamsRaw = decodeURIComponent(
324322
protocol.substring(WS_PROTOCOL_CONN_PARAMS.length),
325323
);
326-
} else if (protocol.startsWith(WS_PROTOCOL_TOKEN)) {
327-
token = protocol.substring(WS_PROTOCOL_TOKEN.length);
328324
}
329325
}
330326
}

packages/rivetkit/src/drivers/engine/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export const ConfigSchema = z
1010
.default(
1111
() => getEnvUniversal("RIVET_ENGINE") ?? "http://localhost:6420",
1212
),
13+
token: z
14+
.string()
15+
.optional()
16+
.transform((val) => val ?? getEnvUniversal("RIVET_TOKEN")),
1317
pegboardEndpoint: z.string().optional(),
1418
namespace: z
1519
.string()
@@ -23,10 +27,6 @@ export const ConfigSchema = z
2327
.default(
2428
() => getEnvUniversal("RIVET_RUNNER_KEY") ?? crypto.randomUUID(),
2529
),
26-
token: z
27-
.string()
28-
.optional()
29-
.transform((val) => val ?? getEnvUniversal("RIVET_TOKEN")),
3030
totalSlots: z.number().default(100_000),
3131
})
3232
.default({});

packages/rivetkit/tests/driver-engine.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ runDriverTests({
1111
skip: {
1212
// Skip tests that aren't applicable for engine-runner
1313
schedule: true, // Scheduling handled by engine
14+
sse: true,
1415
},
1516
async start() {
1617
return await createTestRuntime(

pnpm-lock.yaml

Lines changed: 53 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vitest.base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import type { ViteUserConfig } from "vitest/config";
22

33
export default {
44
test: {
5-
testTimeout: 5_000,
6-
hookTimeout: 5_000,
5+
testTimeout: 10_000,
6+
hookTimeout: 10_000,
77
// Enable parallelism
88
sequence: {
99
// TODO: This breaks fake timers, unsure how to make tests run in parallel within the same file

0 commit comments

Comments
 (0)