rivetkit 0.0.0-feat-sqlite-sync.32022a9 → 0.0.0-feat-sqlite-sync-3x.a00b07f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/client.d.ts +58 -9
- package/dist/browser/client.js +193 -23
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +1 -5
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/agent-os/index.cjs +3 -2652
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +1 -2758
- package/dist/tsup/agent-os/index.d.ts +1 -2758
- package/dist/tsup/agent-os/index.js +3 -2652
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-6ZHUGY2E.cjs → chunk-3JPXBFED.cjs} +4 -4
- package/dist/tsup/{chunk-6ZHUGY2E.cjs.map → chunk-3JPXBFED.cjs.map} +1 -1
- package/dist/tsup/{chunk-6VNQCLKF.js → chunk-5X35FD2T.js} +4 -4
- package/dist/tsup/{chunk-BJGWUWNE.js → chunk-6QNBANXM.js} +3 -3
- package/dist/tsup/{chunk-Z6IVW2Y5.js → chunk-7HILY7QU.js} +188 -28
- package/dist/tsup/chunk-7HILY7QU.js.map +1 -0
- package/dist/tsup/{chunk-JI6GZ2C2.js → chunk-A2CF6PFH.js} +18 -1
- package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
- package/dist/tsup/{chunk-7XBDAFGQ.cjs → chunk-CT6GQRUN.cjs} +3 -3
- package/dist/tsup/{chunk-7XBDAFGQ.cjs.map → chunk-CT6GQRUN.cjs.map} +1 -1
- package/dist/tsup/{chunk-M27XAZNI.js → chunk-DRZTELHJ.js} +10 -14
- package/dist/tsup/chunk-DRZTELHJ.js.map +1 -0
- package/dist/tsup/{chunk-EDJKDOI2.js → chunk-DUGEPEJO.js} +2 -2
- package/dist/tsup/{chunk-PMU5EDGT.cjs → chunk-EA6P3N4I.cjs} +3 -3
- package/dist/tsup/{chunk-PMU5EDGT.cjs.map → chunk-EA6P3N4I.cjs.map} +1 -1
- package/dist/tsup/{chunk-WE7D64FW.cjs → chunk-ERZDCOQ3.cjs} +10 -10
- package/dist/tsup/{chunk-WE7D64FW.cjs.map → chunk-ERZDCOQ3.cjs.map} +1 -1
- package/dist/tsup/{chunk-UZ5O42HF.js → chunk-GHTA76HT.js} +2 -2
- package/dist/tsup/{chunk-IAVZH6HH.js → chunk-ID5VJNZY.js} +2 -2
- package/dist/tsup/{chunk-2LRKNNQJ.cjs → chunk-PXIOH445.cjs} +327 -167
- package/dist/tsup/chunk-PXIOH445.cjs.map +1 -0
- package/dist/tsup/{chunk-MYWZCDML.cjs → chunk-RTWH3AX3.cjs} +19 -2
- package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
- package/dist/tsup/{chunk-5LBUG2IK.cjs → chunk-UV4KDO4W.cjs} +3 -3
- package/dist/tsup/{chunk-5LBUG2IK.cjs.map → chunk-UV4KDO4W.cjs.map} +1 -1
- package/dist/tsup/{chunk-HHALUH4L.js → chunk-VI2S336K.js} +2 -2
- package/dist/tsup/{chunk-6BRDJRCZ.cjs → chunk-W7NPIYWC.cjs} +10 -14
- package/dist/tsup/chunk-W7NPIYWC.cjs.map +1 -0
- package/dist/tsup/{chunk-4SIQMCXI.cjs → chunk-ZZQM77UA.cjs} +7 -7
- package/dist/tsup/{chunk-4SIQMCXI.cjs.map → chunk-ZZQM77UA.cjs.map} +1 -1
- package/dist/tsup/client/mod.cjs +6 -6
- package/dist/tsup/client/mod.d.cts +15 -3
- package/dist/tsup/client/mod.d.ts +15 -3
- package/dist/tsup/client/mod.js +5 -5
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-DfVrAigH.d.ts → config-B4erdavw.d.ts} +43 -12
- package/dist/tsup/{config-BaUctMNL.d.cts → config-BfG1qpYz.d.cts} +7 -1
- package/dist/tsup/{config-BaUctMNL.d.ts → config-BfG1qpYz.d.ts} +7 -1
- package/dist/tsup/{config-D6T6Ud_V.d.cts → config-DK144OAw.d.cts} +43 -12
- package/dist/tsup/{context-CowF_zyQ.d.cts → context-Cvnf3BRe.d.cts} +2 -2
- package/dist/tsup/{context-BsFWwi3i.d.ts → context-Oxi6YWcG.d.ts} +2 -2
- package/dist/tsup/db/drizzle.cjs +2 -2
- package/dist/tsup/db/drizzle.d.cts +1 -1
- package/dist/tsup/db/drizzle.d.ts +1 -1
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +3 -3
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +2 -2
- package/dist/tsup/dynamic/mod.d.cts +2 -2
- package/dist/tsup/dynamic/mod.d.ts +2 -2
- package/dist/tsup/inspector/mod.cjs +5 -5
- package/dist/tsup/inspector/mod.js +4 -4
- package/dist/tsup/inspector/workflow.cjs +4 -4
- package/dist/tsup/inspector/workflow.js +3 -3
- package/dist/tsup/inspector-tab/mod.d.cts +3 -3
- package/dist/tsup/inspector-tab/mod.d.ts +3 -3
- package/dist/tsup/mod.cjs +256 -174
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +4 -4
- package/dist/tsup/mod.d.ts +4 -4
- package/dist/tsup/mod.js +170 -88
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +7 -7
- package/dist/tsup/test/mod.d.cts +2 -2
- package/dist/tsup/test/mod.d.ts +2 -2
- package/dist/tsup/test/mod.js +5 -5
- package/dist/tsup/unstable/migrations.d.cts +1 -1
- package/dist/tsup/unstable/migrations.d.ts +1 -1
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +17 -17
- package/dist/tsup/workflow/mod.d.cts +4 -4
- package/dist/tsup/workflow/mod.d.ts +4 -4
- package/dist/tsup/workflow/mod.js +5 -5
- package/package.json +9 -13
- package/src/actor/keys.ts +86 -0
- package/src/agent-os/index.ts +5 -65
- package/src/client/actor-conn.ts +92 -6
- package/src/client/actor-handle.ts +24 -4
- package/src/client/client.ts +14 -4
- package/src/client/config.ts +12 -1
- package/src/client/lifecycle-errors.ts +16 -1
- package/src/client/retry-budget.ts +78 -0
- package/src/client/utils.ts +13 -2
- package/src/common/database/config.ts +7 -1
- package/src/common/database/native-database.ts +17 -9
- package/src/common/router.ts +1 -1
- package/src/engine-api/actors.ts +3 -3
- package/src/engine-client/actor-websocket-client.ts +4 -2
- package/src/engine-client/api-endpoints.ts +44 -14
- package/src/engine-client/mod.ts +2 -2
- package/src/registry/config/envoy.ts +1 -1
- package/src/registry/config/index.ts +28 -31
- package/src/registry/index.ts +51 -19
- package/src/registry/napi-runtime.ts +3 -2
- package/src/registry/native.ts +129 -40
- package/src/registry/runtime.ts +27 -10
- package/src/registry/wasm-runtime.ts +6 -3
- package/src/utils/env-vars.ts +15 -10
- package/dist/tsup/chunk-2LRKNNQJ.cjs.map +0 -1
- package/dist/tsup/chunk-6BRDJRCZ.cjs.map +0 -1
- package/dist/tsup/chunk-JI6GZ2C2.js.map +0 -1
- package/dist/tsup/chunk-M27XAZNI.js.map +0 -1
- package/dist/tsup/chunk-MYWZCDML.cjs.map +0 -1
- package/dist/tsup/chunk-Z6IVW2Y5.js.map +0 -1
- package/src/actor/config.test.ts +0 -78
- package/src/actor/keys.test.ts +0 -275
- package/src/actor/utils.test.ts +0 -48
- package/src/agent-os/actor/cron.ts +0 -84
- package/src/agent-os/actor/db.ts +0 -54
- package/src/agent-os/actor/filesystem.ts +0 -131
- package/src/agent-os/actor/index.ts +0 -285
- package/src/agent-os/actor/network.ts +0 -58
- package/src/agent-os/actor/preview.ts +0 -190
- package/src/agent-os/actor/process.ts +0 -177
- package/src/agent-os/actor/session.ts +0 -518
- package/src/agent-os/actor/shell.ts +0 -60
- package/src/agent-os/config.ts +0 -79
- package/src/agent-os/fs/database-vfs.ts +0 -624
- package/src/agent-os/types.ts +0 -148
- package/src/client/test.ts +0 -44
- package/src/client/token-provider.test.ts +0 -86
- package/src/common/database/mod.test.ts +0 -364
- package/src/common/database/native-database.test.ts +0 -241
- package/src/common/inline-websocket-adapter.test.ts +0 -51
- package/src/db/drizzle.test.ts +0 -164
- package/src/registry/config/index.test.ts +0 -25
- package/src/registry/run-handler-coordinator.test.ts +0 -252
- package/src/registry/runtime.test.ts +0 -124
- package/src/unstable/migrations.test.ts +0 -170
- package/src/utils/endpoint-parser.test.ts +0 -206
- package/src/utils.test.ts +0 -34
- package/src/workflow/driver.test.ts +0 -62
- /package/dist/tsup/{chunk-6VNQCLKF.js.map → chunk-5X35FD2T.js.map} +0 -0
- /package/dist/tsup/{chunk-BJGWUWNE.js.map → chunk-6QNBANXM.js.map} +0 -0
- /package/dist/tsup/{chunk-EDJKDOI2.js.map → chunk-DUGEPEJO.js.map} +0 -0
- /package/dist/tsup/{chunk-UZ5O42HF.js.map → chunk-GHTA76HT.js.map} +0 -0
- /package/dist/tsup/{chunk-IAVZH6HH.js.map → chunk-ID5VJNZY.js.map} +0 -0
- /package/dist/tsup/{chunk-HHALUH4L.js.map → chunk-VI2S336K.js.map} +0 -0
package/src/agent-os/types.ts
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AgentCapabilities,
|
|
3
|
-
AgentInfo,
|
|
4
|
-
AgentOs,
|
|
5
|
-
CronEvent,
|
|
6
|
-
JsonRpcNotification,
|
|
7
|
-
JsonRpcResponse,
|
|
8
|
-
PermissionRequest,
|
|
9
|
-
} from "@rivet-dev/agent-os-core";
|
|
10
|
-
import type { ActionContext } from "@/actor/config";
|
|
11
|
-
|
|
12
|
-
// --- Actor state (persisted across sleep/wake) ---
|
|
13
|
-
|
|
14
|
-
// biome-ignore lint/complexity/noBannedTypes: empty state placeholder, consumers extend via generics
|
|
15
|
-
export type AgentOsActorState = {};
|
|
16
|
-
|
|
17
|
-
// --- Actor vars (ephemeral, recreated on wake) ---
|
|
18
|
-
|
|
19
|
-
export interface AgentOsActorVars {
|
|
20
|
-
agentOs: AgentOs | null;
|
|
21
|
-
activeSessionIds: Set<string>;
|
|
22
|
-
activeProcesses: Set<number>;
|
|
23
|
-
activeHooks: Set<Promise<void>>;
|
|
24
|
-
activeShells: Set<string>;
|
|
25
|
-
sessions: Set<string>;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// --- Event payloads ---
|
|
29
|
-
|
|
30
|
-
export interface SessionEventPayload {
|
|
31
|
-
sessionId: string;
|
|
32
|
-
event: JsonRpcNotification;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface PermissionRequestPayload {
|
|
36
|
-
sessionId: string;
|
|
37
|
-
request: PermissionRequest;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type VmBootedPayload = Record<string, never>;
|
|
41
|
-
|
|
42
|
-
export interface VmShutdownPayload {
|
|
43
|
-
reason: "sleep" | "destroy" | "error";
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface ProcessOutputPayload {
|
|
47
|
-
pid: number;
|
|
48
|
-
stream: "stdout" | "stderr";
|
|
49
|
-
data: Uint8Array;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface ProcessExitPayload {
|
|
53
|
-
pid: number;
|
|
54
|
-
exitCode: number;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface ShellDataPayload {
|
|
58
|
-
shellId: string;
|
|
59
|
-
data: Uint8Array;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface CronEventPayload {
|
|
63
|
-
event: CronEvent;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// --- Event schema map (used by actor() events config) ---
|
|
67
|
-
|
|
68
|
-
export interface AgentOsEvents {
|
|
69
|
-
sessionEvent: SessionEventPayload;
|
|
70
|
-
permissionRequest: PermissionRequestPayload;
|
|
71
|
-
vmBooted: VmBootedPayload;
|
|
72
|
-
vmShutdown: VmShutdownPayload;
|
|
73
|
-
processOutput: ProcessOutputPayload;
|
|
74
|
-
processExit: ProcessExitPayload;
|
|
75
|
-
shellData: ShellDataPayload;
|
|
76
|
-
cronEvent: CronEventPayload;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// --- Prompt result ---
|
|
80
|
-
|
|
81
|
-
/** Result from sendPrompt. */
|
|
82
|
-
export interface PromptResult {
|
|
83
|
-
/** Raw JSON-RPC response from the ACP adapter. */
|
|
84
|
-
response: JsonRpcResponse;
|
|
85
|
-
/** Accumulated agent text output from streamed message chunks. */
|
|
86
|
-
text: string;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// --- Session serialization ---
|
|
90
|
-
|
|
91
|
-
export interface SessionRecord {
|
|
92
|
-
sessionId: string;
|
|
93
|
-
agentType: string;
|
|
94
|
-
capabilities: AgentCapabilities;
|
|
95
|
-
agentInfo: AgentInfo | null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// --- Persisted session types ---
|
|
99
|
-
|
|
100
|
-
export interface PersistedSessionRecord {
|
|
101
|
-
sessionId: string;
|
|
102
|
-
agentType: string;
|
|
103
|
-
capabilities: AgentCapabilities;
|
|
104
|
-
agentInfo: AgentInfo | null;
|
|
105
|
-
createdAt: number;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export interface PersistedSessionEvent {
|
|
109
|
-
sessionId: string;
|
|
110
|
-
seq: number;
|
|
111
|
-
event: JsonRpcNotification;
|
|
112
|
-
createdAt: number;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// --- Serializable cron action (excludes callback type) ---
|
|
116
|
-
|
|
117
|
-
export type SerializableCronAction =
|
|
118
|
-
| { type: "session"; agentType: string; prompt: string; cwd?: string }
|
|
119
|
-
| { type: "exec"; command: string; args?: string[] };
|
|
120
|
-
|
|
121
|
-
export interface SerializableCronJobOptions {
|
|
122
|
-
id?: string;
|
|
123
|
-
schedule: string;
|
|
124
|
-
action: SerializableCronAction;
|
|
125
|
-
overlap?: "allow" | "skip" | "queue";
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export interface SerializableCronJobInfo {
|
|
129
|
-
id: string;
|
|
130
|
-
schedule: string;
|
|
131
|
-
action: SerializableCronAction;
|
|
132
|
-
overlap: "allow" | "skip" | "queue";
|
|
133
|
-
lastRun?: string;
|
|
134
|
-
nextRun?: string;
|
|
135
|
-
runCount: number;
|
|
136
|
-
running: boolean;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// --- Action context alias ---
|
|
140
|
-
|
|
141
|
-
export type AgentOsActionContext<TConnParams = undefined> = ActionContext<
|
|
142
|
-
AgentOsActorState,
|
|
143
|
-
TConnParams,
|
|
144
|
-
undefined,
|
|
145
|
-
AgentOsActorVars,
|
|
146
|
-
undefined,
|
|
147
|
-
any
|
|
148
|
-
>;
|
package/src/client/test.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
//import { exec as execCallback } from "node:child_process";
|
|
2
|
-
//import { setupLogging } from "@/common//log";
|
|
3
|
-
//import type { ClientOptions } from "./client";
|
|
4
|
-
//import { InternalError } from "./errors";
|
|
5
|
-
//import { Client } from "./mod.ts";
|
|
6
|
-
//
|
|
7
|
-
///**
|
|
8
|
-
// * Uses the Rivet CLI to read the manager endpoint to connect to. This allows
|
|
9
|
-
// * for writing tests that run locally without hardcoding the manager endpoint.
|
|
10
|
-
// */
|
|
11
|
-
//export async function readEndpointFromCli(): Promise<string> {
|
|
12
|
-
// // Read endpoint
|
|
13
|
-
// const cliPath = process.env.RIVET_CLI_PATH ?? "rivet";
|
|
14
|
-
//
|
|
15
|
-
// try {
|
|
16
|
-
// const { stdout, stderr } = await new Promise<{
|
|
17
|
-
// stdout: string;
|
|
18
|
-
// stderr: string;
|
|
19
|
-
// }>((resolve, reject) => {
|
|
20
|
-
// execCallback(`${cliPath} manager endpoint`, (error, stdout, stderr) => {
|
|
21
|
-
// if (error) reject(error);
|
|
22
|
-
// else resolve({ stdout, stderr });
|
|
23
|
-
// });
|
|
24
|
-
// });
|
|
25
|
-
//
|
|
26
|
-
// if (stderr) {
|
|
27
|
-
// throw new Error(stderr);
|
|
28
|
-
// }
|
|
29
|
-
//
|
|
30
|
-
// // Decode output
|
|
31
|
-
// return stdout.trim();
|
|
32
|
-
// } catch (error) {
|
|
33
|
-
// throw new InternalError(`Read endpoint failed: ${error}`);
|
|
34
|
-
// }
|
|
35
|
-
//}
|
|
36
|
-
//
|
|
37
|
-
//export class TestClient extends Client {
|
|
38
|
-
// public constructor(opts?: ClientOptions) {
|
|
39
|
-
// // Setup logging automatically
|
|
40
|
-
// setupLogging();
|
|
41
|
-
//
|
|
42
|
-
// super(readEndpointFromCli(), opts);
|
|
43
|
-
// }
|
|
44
|
-
//}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test, vi } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
isInvalidToken,
|
|
4
|
-
isInvalidTokenResponse,
|
|
5
|
-
TokenProvider,
|
|
6
|
-
} from "./token-provider";
|
|
7
|
-
|
|
8
|
-
describe("renewable client tokens", () => {
|
|
9
|
-
test("single-flights initial issuance and concurrent rejection refreshes", async () => {
|
|
10
|
-
const getToken = vi.fn(
|
|
11
|
-
async ({ forceRefresh }: { forceRefresh: boolean }) =>
|
|
12
|
-
forceRefresh ? "renewed" : "initial",
|
|
13
|
-
);
|
|
14
|
-
const provider = new TokenProvider(getToken);
|
|
15
|
-
expect(
|
|
16
|
-
await Promise.all([provider.current(), provider.current()]),
|
|
17
|
-
).toEqual(["initial", "initial"]);
|
|
18
|
-
expect(getToken).toHaveBeenCalledTimes(1);
|
|
19
|
-
expect(
|
|
20
|
-
await Promise.all([
|
|
21
|
-
provider.refreshIfCurrent("initial"),
|
|
22
|
-
provider.refreshIfCurrent("initial"),
|
|
23
|
-
]),
|
|
24
|
-
).toEqual(["renewed", "renewed"]);
|
|
25
|
-
expect(getToken).toHaveBeenCalledTimes(2);
|
|
26
|
-
expect(await provider.refreshIfCurrent("initial")).toBe("renewed");
|
|
27
|
-
expect(getToken).toHaveBeenCalledTimes(2);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("retries failed issuance and refuses empty credentials", async () => {
|
|
31
|
-
const getToken = vi
|
|
32
|
-
.fn()
|
|
33
|
-
.mockRejectedValueOnce(new Error("issuer down"))
|
|
34
|
-
.mockResolvedValueOnce("ok");
|
|
35
|
-
const provider = new TokenProvider(getToken);
|
|
36
|
-
await expect(provider.current()).rejects.toThrow("issuer down");
|
|
37
|
-
expect(await provider.current()).toBe("ok");
|
|
38
|
-
await expect(
|
|
39
|
-
new TokenProvider(async () => "").current(),
|
|
40
|
-
).rejects.toThrow("nonempty");
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("refreshes before a known JWT expiry and treats opaque tokens as unexpiring hints", async () => {
|
|
44
|
-
const payload = btoa(
|
|
45
|
-
JSON.stringify({ exp: Math.floor(Date.now() / 1_000) + 1 }),
|
|
46
|
-
).replaceAll("=", "");
|
|
47
|
-
const getToken = vi.fn(async () => `header.${payload}.signature`);
|
|
48
|
-
const provider = new TokenProvider(getToken);
|
|
49
|
-
await provider.current();
|
|
50
|
-
await provider.current();
|
|
51
|
-
expect(getToken).toHaveBeenCalledTimes(2);
|
|
52
|
-
const opaque = vi.fn(async () => "opaque");
|
|
53
|
-
const opaqueProvider = new TokenProvider(opaque);
|
|
54
|
-
await opaqueProvider.current();
|
|
55
|
-
await opaqueProvider.current();
|
|
56
|
-
expect(opaque).toHaveBeenCalledTimes(1);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test("only confirmed 401 invalid/expired errors permit renewal", () => {
|
|
60
|
-
expect(isInvalidToken("auth", "invalid_token")).toBe(true);
|
|
61
|
-
expect(isInvalidToken("auth", "token_expired")).toBe(true);
|
|
62
|
-
for (const code of [
|
|
63
|
-
"insufficient_permissions",
|
|
64
|
-
"verification_unavailable",
|
|
65
|
-
"issuance_unavailable",
|
|
66
|
-
]) {
|
|
67
|
-
expect(isInvalidToken("auth", code)).toBe(false);
|
|
68
|
-
}
|
|
69
|
-
expect(
|
|
70
|
-
isInvalidTokenResponse(
|
|
71
|
-
new Response(null, {
|
|
72
|
-
status: 401,
|
|
73
|
-
headers: { "x-rivet-error": "auth.token_expired" },
|
|
74
|
-
}),
|
|
75
|
-
),
|
|
76
|
-
).toBe(true);
|
|
77
|
-
expect(
|
|
78
|
-
isInvalidTokenResponse(
|
|
79
|
-
new Response(null, {
|
|
80
|
-
status: 503,
|
|
81
|
-
headers: { "x-rivet-error": "auth.token_expired" },
|
|
82
|
-
}),
|
|
83
|
-
),
|
|
84
|
-
).toBe(false);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
import { pino } from "pino";
|
|
2
|
-
import { beforeEach, describe, expect, test } from "vitest";
|
|
3
|
-
import { configureBaseLogger } from "@/common/log";
|
|
4
|
-
import type {
|
|
5
|
-
DatabaseProviderContext,
|
|
6
|
-
SqliteBindings,
|
|
7
|
-
SqliteDatabase,
|
|
8
|
-
SqliteExecuteResult,
|
|
9
|
-
SqliteTransactionDatabase,
|
|
10
|
-
} from "./config";
|
|
11
|
-
import { db, registerNativeStateTransactionOpener } from "./mod";
|
|
12
|
-
|
|
13
|
-
let logLines: string[];
|
|
14
|
-
|
|
15
|
-
class FakeSqliteDatabase implements SqliteDatabase {
|
|
16
|
-
failSql = new Map<string, Error>();
|
|
17
|
-
executeCalls: { sql: string; params?: SqliteBindings }[] = [];
|
|
18
|
-
stateTransactionTimeouts: Array<number | undefined> = [];
|
|
19
|
-
transactionTimeouts: Array<number | undefined> = [];
|
|
20
|
-
transactionNames: Array<string | undefined> = [];
|
|
21
|
-
|
|
22
|
-
async exec(): Promise<void> {}
|
|
23
|
-
|
|
24
|
-
async execute(
|
|
25
|
-
sql: string,
|
|
26
|
-
params?: SqliteBindings,
|
|
27
|
-
): Promise<SqliteExecuteResult> {
|
|
28
|
-
this.record(sql, params);
|
|
29
|
-
return emptyResult();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async beginTransaction(
|
|
33
|
-
timeoutMs?: number,
|
|
34
|
-
name?: string,
|
|
35
|
-
): Promise<SqliteTransactionDatabase> {
|
|
36
|
-
this.transactionTimeouts.push(timeoutMs);
|
|
37
|
-
this.transactionNames.push(name);
|
|
38
|
-
this.record("BEGIN");
|
|
39
|
-
return {
|
|
40
|
-
exec: async () => {},
|
|
41
|
-
execute: async (sql, params) => {
|
|
42
|
-
this.record(sql, params);
|
|
43
|
-
return emptyResult();
|
|
44
|
-
},
|
|
45
|
-
commit: async () => this.record("COMMIT"),
|
|
46
|
-
rollback: async () => this.record("ROLLBACK"),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
async beginStateTransaction(
|
|
50
|
-
timeoutMs?: number,
|
|
51
|
-
): Promise<SqliteTransactionDatabase> {
|
|
52
|
-
this.stateTransactionTimeouts.push(timeoutMs);
|
|
53
|
-
this.record("BEGIN_STATE");
|
|
54
|
-
return {
|
|
55
|
-
exec: async () => {},
|
|
56
|
-
execute: async (sql, params) => {
|
|
57
|
-
this.record(sql, params);
|
|
58
|
-
return emptyResult();
|
|
59
|
-
},
|
|
60
|
-
commit: async () => this.record("COMMIT"),
|
|
61
|
-
rollback: async () => this.record("ROLLBACK"),
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async executeBatch(
|
|
66
|
-
statements: Array<{ sql: string; params?: SqliteBindings }>,
|
|
67
|
-
): Promise<SqliteExecuteResult[]> {
|
|
68
|
-
const results: SqliteExecuteResult[] = [];
|
|
69
|
-
for (const statement of statements) {
|
|
70
|
-
results.push(await this.execute(statement.sql, statement.params));
|
|
71
|
-
}
|
|
72
|
-
return results;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async run(sql: string, params?: SqliteBindings): Promise<void> {
|
|
76
|
-
await this.execute(sql, params);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async query(sql: string, params?: SqliteBindings) {
|
|
80
|
-
const { columns, rows } = await this.execute(sql, params);
|
|
81
|
-
return { columns, rows };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async close(): Promise<void> {}
|
|
85
|
-
|
|
86
|
-
private record(sql: string, params?: SqliteBindings): void {
|
|
87
|
-
this.executeCalls.push({ sql, params });
|
|
88
|
-
const error = this.failSql.get(sql);
|
|
89
|
-
if (error) throw error;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function emptyResult(): SqliteExecuteResult {
|
|
94
|
-
return {
|
|
95
|
-
columns: [],
|
|
96
|
-
rows: [],
|
|
97
|
-
changes: 0,
|
|
98
|
-
lastInsertRowId: null,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function testProviderContext(
|
|
103
|
-
database: FakeSqliteDatabase,
|
|
104
|
-
includeStateTransactions = false,
|
|
105
|
-
): DatabaseProviderContext {
|
|
106
|
-
return {
|
|
107
|
-
actorId: "actor-a",
|
|
108
|
-
kv: {
|
|
109
|
-
batchPut: async () => {},
|
|
110
|
-
batchGet: async (keys) => keys.map(() => null),
|
|
111
|
-
batchDelete: async () => {},
|
|
112
|
-
deleteRange: async () => {},
|
|
113
|
-
},
|
|
114
|
-
nativeDatabaseProvider: includeStateTransactions
|
|
115
|
-
? registerNativeStateTransactionOpener(
|
|
116
|
-
{ open: async () => database },
|
|
117
|
-
async (timeoutMs?: number) =>
|
|
118
|
-
await database.beginStateTransaction(timeoutMs),
|
|
119
|
-
)
|
|
120
|
-
: { open: async () => database },
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
describe("db", () => {
|
|
125
|
-
beforeEach(() => {
|
|
126
|
-
logLines = [];
|
|
127
|
-
configureBaseLogger(
|
|
128
|
-
pino(
|
|
129
|
-
{ level: "warn", base: {}, timestamp: false },
|
|
130
|
-
{ write: (line: string) => logLines.push(line) },
|
|
131
|
-
),
|
|
132
|
-
);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test("runs onMigrate through the shared transaction handle", async () => {
|
|
136
|
-
const nativeDb = new FakeSqliteDatabase();
|
|
137
|
-
const provider = db({
|
|
138
|
-
onMigrate: async (client) => {
|
|
139
|
-
await client.execute(
|
|
140
|
-
"CREATE TABLE items(id INTEGER PRIMARY KEY)",
|
|
141
|
-
);
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
const client = await provider.createClient(
|
|
145
|
-
testProviderContext(nativeDb),
|
|
146
|
-
);
|
|
147
|
-
await provider.onMigrate(client);
|
|
148
|
-
|
|
149
|
-
expect(nativeDb.executeCalls.map(({ sql }) => sql)).toEqual([
|
|
150
|
-
"BEGIN",
|
|
151
|
-
"SAVEPOINT __rivet_on_migrate",
|
|
152
|
-
"CREATE TABLE items(id INTEGER PRIMARY KEY)",
|
|
153
|
-
"RELEASE SAVEPOINT __rivet_on_migrate",
|
|
154
|
-
"COMMIT",
|
|
155
|
-
]);
|
|
156
|
-
expect(nativeDb.transactionTimeouts).toEqual([300_000]);
|
|
157
|
-
expect(nativeDb.transactionNames).toEqual(["rivetkit-migration"]);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
test("exposes profiling controls to the actor runtime", () => {
|
|
161
|
-
const provider = db({
|
|
162
|
-
profiling: {
|
|
163
|
-
enabled: false,
|
|
164
|
-
maxTrackedStatementFingerprints: 12,
|
|
165
|
-
baselineSampleRate: 0.25,
|
|
166
|
-
},
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
expect(provider.sqliteProfiling).toEqual({
|
|
170
|
-
enabled: false,
|
|
171
|
-
maxTrackedStatementFingerprints: 12,
|
|
172
|
-
baselineSampleRate: 0.25,
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
test("rolls back migrations when onMigrate fails", async () => {
|
|
177
|
-
const nativeDb = new FakeSqliteDatabase();
|
|
178
|
-
const provider = db({
|
|
179
|
-
onMigrate: async () => {
|
|
180
|
-
throw new Error("migration failed");
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
const client = await provider.createClient(
|
|
184
|
-
testProviderContext(nativeDb),
|
|
185
|
-
);
|
|
186
|
-
await expect(provider.onMigrate(client)).rejects.toThrow(
|
|
187
|
-
"migration failed",
|
|
188
|
-
);
|
|
189
|
-
expect(nativeDb.executeCalls.map(({ sql }) => sql)).toEqual([
|
|
190
|
-
"BEGIN",
|
|
191
|
-
"SAVEPOINT __rivet_on_migrate",
|
|
192
|
-
"ROLLBACK TO SAVEPOINT __rivet_on_migrate",
|
|
193
|
-
"RELEASE SAVEPOINT __rivet_on_migrate",
|
|
194
|
-
"ROLLBACK",
|
|
195
|
-
]);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test("commits transaction work and forwards timeout", async () => {
|
|
199
|
-
const nativeDb = new FakeSqliteDatabase();
|
|
200
|
-
const client = await db().createClient(testProviderContext(nativeDb));
|
|
201
|
-
const value = await client.transaction(
|
|
202
|
-
async (tx) => {
|
|
203
|
-
await tx.execute(
|
|
204
|
-
"INSERT INTO items(value) VALUES (?)",
|
|
205
|
-
"inside",
|
|
206
|
-
);
|
|
207
|
-
return 42;
|
|
208
|
-
},
|
|
209
|
-
{ name: "insert-item", timeout: 120_000 },
|
|
210
|
-
);
|
|
211
|
-
expect(value).toBe(42);
|
|
212
|
-
expect(nativeDb.transactionTimeouts).toEqual([120_000]);
|
|
213
|
-
expect(nativeDb.transactionNames).toEqual(["insert-item"]);
|
|
214
|
-
expect(nativeDb.executeCalls.map(({ sql }) => sql)).toEqual([
|
|
215
|
-
"BEGIN",
|
|
216
|
-
"INSERT INTO items(value) VALUES (?)",
|
|
217
|
-
"COMMIT",
|
|
218
|
-
]);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
test("validates transaction names", async () => {
|
|
222
|
-
const client = await db().createClient(
|
|
223
|
-
testProviderContext(new FakeSqliteDatabase()),
|
|
224
|
-
);
|
|
225
|
-
await expect(
|
|
226
|
-
client.transaction(async () => {}, { name: "" }),
|
|
227
|
-
).rejects.toThrow("must not be empty");
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
test("defers the configured transaction name byte limit to the runtime", async () => {
|
|
231
|
-
const nativeDb = new FakeSqliteDatabase();
|
|
232
|
-
const client = await db().createClient(testProviderContext(nativeDb));
|
|
233
|
-
const name = "x".repeat(129);
|
|
234
|
-
|
|
235
|
-
await client.transaction(async () => {}, { name });
|
|
236
|
-
|
|
237
|
-
expect(nativeDb.transactionNames).toEqual([name]);
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
test("rolls back a transaction when the callback throws", async () => {
|
|
241
|
-
const nativeDb = new FakeSqliteDatabase();
|
|
242
|
-
const client = await db().createClient(testProviderContext(nativeDb));
|
|
243
|
-
await expect(
|
|
244
|
-
client.transaction(async (tx) => {
|
|
245
|
-
await tx.execute(
|
|
246
|
-
"INSERT INTO items(value) VALUES (?)",
|
|
247
|
-
"inside",
|
|
248
|
-
);
|
|
249
|
-
throw new Error("callback failed");
|
|
250
|
-
}),
|
|
251
|
-
).rejects.toThrow("callback failed");
|
|
252
|
-
expect(nativeDb.executeCalls.map(({ sql }) => sql)).toEqual([
|
|
253
|
-
"BEGIN",
|
|
254
|
-
"INSERT INTO items(value) VALUES (?)",
|
|
255
|
-
"ROLLBACK",
|
|
256
|
-
]);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
test("uses the state-aware transaction bridge when explicitly requested", async () => {
|
|
260
|
-
const nativeDb = new FakeSqliteDatabase();
|
|
261
|
-
const client = await db().createClient(
|
|
262
|
-
testProviderContext(nativeDb, true),
|
|
263
|
-
);
|
|
264
|
-
|
|
265
|
-
await client.transaction(
|
|
266
|
-
async (tx) => {
|
|
267
|
-
await tx.execute(
|
|
268
|
-
"INSERT INTO items(value) VALUES (?)",
|
|
269
|
-
"inside",
|
|
270
|
-
);
|
|
271
|
-
},
|
|
272
|
-
{
|
|
273
|
-
timeout: 120_000,
|
|
274
|
-
experimental: { includeState: true },
|
|
275
|
-
},
|
|
276
|
-
);
|
|
277
|
-
|
|
278
|
-
expect(nativeDb.transactionTimeouts).toEqual([]);
|
|
279
|
-
expect(nativeDb.stateTransactionTimeouts).toEqual([120_000]);
|
|
280
|
-
expect(nativeDb.executeCalls.map(({ sql }) => sql)).toEqual([
|
|
281
|
-
"BEGIN_STATE",
|
|
282
|
-
"INSERT INTO items(value) VALUES (?)",
|
|
283
|
-
"COMMIT",
|
|
284
|
-
]);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
test("rolls back state-aware transactions when the callback throws", async () => {
|
|
288
|
-
const nativeDb = new FakeSqliteDatabase();
|
|
289
|
-
const client = await db().createClient(
|
|
290
|
-
testProviderContext(nativeDb, true),
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
await expect(
|
|
294
|
-
client.transaction(
|
|
295
|
-
async (tx) => {
|
|
296
|
-
await tx.execute(
|
|
297
|
-
"INSERT INTO items(value) VALUES (?)",
|
|
298
|
-
"inside",
|
|
299
|
-
);
|
|
300
|
-
throw new Error("callback failed");
|
|
301
|
-
},
|
|
302
|
-
{ experimental: { includeState: true } },
|
|
303
|
-
),
|
|
304
|
-
).rejects.toThrow("callback failed");
|
|
305
|
-
expect(nativeDb.executeCalls.map(({ sql }) => sql)).toEqual([
|
|
306
|
-
"BEGIN_STATE",
|
|
307
|
-
"INSERT INTO items(value) VALUES (?)",
|
|
308
|
-
"ROLLBACK",
|
|
309
|
-
]);
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
test("rejects nested state-aware transactions", async () => {
|
|
313
|
-
const nativeDb = new FakeSqliteDatabase();
|
|
314
|
-
const client = await db().createClient(
|
|
315
|
-
testProviderContext(nativeDb, true),
|
|
316
|
-
);
|
|
317
|
-
|
|
318
|
-
await expect(
|
|
319
|
-
client.transaction(
|
|
320
|
-
async (tx) => {
|
|
321
|
-
await tx.transaction(async () => {}, {
|
|
322
|
-
experimental: { includeState: true },
|
|
323
|
-
});
|
|
324
|
-
},
|
|
325
|
-
{ experimental: { includeState: true } },
|
|
326
|
-
),
|
|
327
|
-
).rejects.toThrow("not supported for nested transactions");
|
|
328
|
-
expect(nativeDb.executeCalls.map(({ sql }) => sql)).toEqual([
|
|
329
|
-
"BEGIN_STATE",
|
|
330
|
-
"ROLLBACK",
|
|
331
|
-
]);
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
test("validates transaction timeouts", async () => {
|
|
335
|
-
const client = await db().createClient(
|
|
336
|
-
testProviderContext(new FakeSqliteDatabase()),
|
|
337
|
-
);
|
|
338
|
-
for (const timeout of [0, -1, Number.NaN, Number.POSITIVE_INFINITY]) {
|
|
339
|
-
await expect(
|
|
340
|
-
client.transaction(async () => {}, { timeout }),
|
|
341
|
-
).rejects.toThrow("positive finite");
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
test("warns once for manual cross-call transactions and names the opt-out", async () => {
|
|
346
|
-
const client = await db().createClient(
|
|
347
|
-
testProviderContext(new FakeSqliteDatabase()),
|
|
348
|
-
);
|
|
349
|
-
await client.execute("BEGIN");
|
|
350
|
-
await client.execute("COMMIT");
|
|
351
|
-
expect(logLines).toHaveLength(1);
|
|
352
|
-
expect(JSON.parse(logLines[0] ?? "{}").msg).toContain(
|
|
353
|
-
"Set warnOnManualTransactions: false",
|
|
354
|
-
);
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
test("can suppress the manual transaction warning", async () => {
|
|
358
|
-
const client = await db({
|
|
359
|
-
warnOnManualTransactions: false,
|
|
360
|
-
}).createClient(testProviderContext(new FakeSqliteDatabase()));
|
|
361
|
-
await client.execute("BEGIN");
|
|
362
|
-
expect(logLines).toHaveLength(0);
|
|
363
|
-
});
|
|
364
|
-
});
|