Skip to content

Commit 5953477

Browse files
committed
Update tests to use store-passing pattern instead of adapter
Fixed all test files to work with the new @runtimed/agent-core API: ✅ lib/test/mod.test.ts: - Updated to create stores via createStorePromise - Made tests async to handle store creation ✅ lib/test/runtime-agent-adapter-injection.test.ts: - Replaced adapter passing with store creation - Updated all test cases to create stores explicitly - Proper sync payload creation for each test scenario ✅ pyodide-runtime-agent/test/config-cli.test.ts: - Updated makeBaseConfig to be async and create stores - Fixed assertThrows tests to handle async config creation - Added fallback values for testing validation edge cases All tests now compile successfully and use the intended store-passing architecture. Ready for 0.x.0 breaking change release!
1 parent ce59183 commit 5953477

File tree

3 files changed

+244
-53
lines changed

3 files changed

+244
-53
lines changed

packages/lib/test/mod.test.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
/// <reference lib="deno.ns" />
22
import { assertEquals } from "jsr:@std/assert";
33
import {
4+
createRuntimeSyncPayload,
5+
createStorePromise,
46
DEFAULT_CONFIG,
57
RuntimeAgent,
68
RuntimeConfig,
79
} from "@runtimed/agent-core";
10+
import type { CreateStoreConfig } from "@runtimed/agent-core";
811
import { makeInMemoryAdapter } from "npm:@livestore/adapter-web";
912

10-
Deno.test("Library exports are available", () => {
13+
Deno.test("Library exports are available", async () => {
1114
// Test that main exports are defined
1215
assertEquals(typeof RuntimeAgent, "function");
1316
assertEquals(typeof RuntimeConfig, "function");
@@ -22,7 +25,7 @@ Deno.test("DEFAULT_CONFIG has expected values", () => {
2225
);
2326
});
2427

25-
Deno.test("RuntimeConfig validation works", () => {
28+
Deno.test("RuntimeConfig validation works", async () => {
2629
// Should throw for missing required fields
2730
try {
2831
const config = new RuntimeConfig({
@@ -33,7 +36,16 @@ Deno.test("RuntimeConfig validation works", () => {
3336
notebookId: "", // Missing
3437

3538
userId: "test-user-id",
36-
adapter: makeInMemoryAdapter({}),
39+
store: await createStorePromise({
40+
adapter: makeInMemoryAdapter({}),
41+
notebookId: "test-notebook",
42+
syncPayload: createRuntimeSyncPayload({
43+
authToken: "test-token",
44+
runtimeId: "test-runtime",
45+
sessionId: "test-session",
46+
userId: "test-user-id",
47+
}),
48+
}),
3749
capabilities: {
3850
canExecuteCode: true,
3951
canExecuteSql: false,
@@ -58,7 +70,16 @@ Deno.test("RuntimeConfig validation works", () => {
5870
notebookId: "test-notebook",
5971

6072
userId: "test-user-id",
61-
adapter: makeInMemoryAdapter({}),
73+
store: await createStorePromise({
74+
adapter: makeInMemoryAdapter({}),
75+
notebookId: "test-notebook",
76+
syncPayload: createRuntimeSyncPayload({
77+
authToken: "test-token",
78+
runtimeId: "test-runtime",
79+
sessionId: "test-session",
80+
userId: "test-user-id",
81+
}),
82+
}),
6283
capabilities: {
6384
canExecuteCode: true,
6485
canExecuteSql: false,

packages/lib/test/runtime-agent-adapter-injection.test.ts

Lines changed: 166 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,48 @@ import { assertEquals, assertExists } from "jsr:@std/assert";
99
import { crypto } from "jsr:@std/crypto";
1010

1111
import {
12+
createRuntimeSyncPayload,
13+
createStorePromise,
1214
RuntimeAgent,
1315
type RuntimeAgentOptions,
1416
type RuntimeCapabilities,
1517
RuntimeConfig,
1618
} from "@runtimed/agent-core";
19+
import type { CreateStoreConfig } from "@runtimed/agent-core";
1720
import { makeInMemoryAdapter } from "npm:@livestore/adapter-web";
1821
import { makeAdapter } from "npm:@livestore/adapter-node";
1922

20-
// Helper function for creating test configs since createBaseRuntimeConfig moved to pyodide package
21-
function createTestRuntimeConfig(
23+
// Helper function for creating test configs with store
24+
async function createTestRuntimeConfig(
2225
_args: string[],
2326
defaults: Partial<RuntimeAgentOptions> = {},
24-
): RuntimeConfig {
27+
): Promise<RuntimeConfig> {
2528
// Create default in-memory adapter for testing
2629
const defaultAdapter = makeInMemoryAdapter({});
2730

31+
// Create sync payload
32+
const syncPayload = createRuntimeSyncPayload({
33+
authToken: "test-token",
34+
runtimeId: "test-runtime-id",
35+
sessionId: crypto.randomUUID(),
36+
userId: "test-user-id",
37+
});
38+
39+
// Create store
40+
const store = await createStorePromise({
41+
adapter: defaultAdapter,
42+
notebookId: "test-notebook",
43+
syncPayload,
44+
});
45+
2846
const config: RuntimeAgentOptions = {
2947
runtimeId: "test-runtime-id",
3048
runtimeType: "test-runtime",
3149
syncUrl: "ws://fake-url:9999",
3250
authToken: "test-token",
3351
notebookId: "test-notebook",
3452
userId: "test-user-id",
35-
adapter: defaultAdapter,
53+
store,
3654
capabilities: {
3755
canExecuteCode: true,
3856
canExecuteSql: false,
@@ -47,8 +65,8 @@ function createTestRuntimeConfig(
4765
Deno.test("RuntimeAgent adapter injection", async (t) => {
4866
await t.step(
4967
"should work with default adapter (backward compatibility)",
50-
() => {
51-
const config = createTestRuntimeConfig([], {
68+
async () => {
69+
const config = await createTestRuntimeConfig([], {
5270
userId: "test-user-id",
5371
notebookId: "test-notebook",
5472
syncUrl: "ws://fake-url:9999", // Will fail but that's expected
@@ -74,20 +92,45 @@ Deno.test("RuntimeAgent adapter injection", async (t) => {
7492
// No sync backend needed for pure in-memory testing
7593
});
7694

77-
const config = createTestRuntimeConfig([], {
78-
adapter,
95+
// Create sync payload
96+
const syncPayload = createRuntimeSyncPayload({
97+
authToken: "test-token",
98+
runtimeId: "test-runtime-id",
99+
sessionId: crypto.randomUUID(),
79100
userId: "test-user-id",
101+
});
102+
103+
// Create store with custom adapter
104+
const store = await createStorePromise({
105+
adapter,
80106
notebookId: "adapter-test",
81-
syncUrl: "ws://fake-url:9999",
107+
syncPayload,
82108
});
83109

110+
const config: RuntimeAgentOptions = {
111+
runtimeId: "test-runtime-id",
112+
runtimeType: "test-runtime",
113+
syncUrl: "ws://fake-url:9999",
114+
authToken: "test-token",
115+
notebookId: "adapter-test",
116+
userId: "test-user-id",
117+
store,
118+
capabilities: {
119+
canExecuteCode: true,
120+
canExecuteSql: false,
121+
canExecuteAi: false,
122+
},
123+
};
124+
125+
const runtimeConfig = new RuntimeConfig(config);
126+
84127
const capabilities: RuntimeCapabilities = {
85128
canExecuteCode: true,
86129
canExecuteSql: false,
87130
canExecuteAi: false,
88131
};
89132

90-
const agent = new RuntimeAgent(config, capabilities);
133+
const agent = new RuntimeAgent(runtimeConfig, capabilities);
91134

92135
assertExists(agent);
93136
assertEquals(agent.config.notebookId, "adapter-test");
@@ -107,21 +150,45 @@ Deno.test("RuntimeAgent adapter injection", async (t) => {
107150
// Create custom in-memory adapter
108151
const adapter = makeInMemoryAdapter({});
109152

110-
const config = createTestRuntimeConfig([], {
111-
adapter,
153+
// Create sync payload
154+
const syncPayload = createRuntimeSyncPayload({
155+
authToken: "test-token",
156+
runtimeId: "test-runtime-id",
157+
sessionId: crypto.randomUUID(),
112158
userId: "test-user-id",
159+
});
160+
161+
// Create store with custom adapter
162+
const store = await createStorePromise({
163+
adapter,
113164
notebookId: "adapter-test-2",
114-
authToken: "test-token",
115-
syncUrl: "ws://fake-url:9999",
165+
syncPayload,
116166
});
117167

168+
const config: RuntimeAgentOptions = {
169+
runtimeId: "test-runtime-id",
170+
runtimeType: "test-runtime",
171+
syncUrl: "ws://fake-url:9999",
172+
authToken: "test-token",
173+
notebookId: "adapter-test-2",
174+
userId: "test-user-id",
175+
store,
176+
capabilities: {
177+
canExecuteCode: true,
178+
canExecuteSql: false,
179+
canExecuteAi: false,
180+
},
181+
};
182+
183+
const runtimeConfig = new RuntimeConfig(config);
184+
118185
const capabilities: RuntimeCapabilities = {
119186
canExecuteCode: true,
120187
canExecuteSql: false,
121188
canExecuteAi: false,
122189
};
123190

124-
const agent = new RuntimeAgent(config, capabilities);
191+
const agent = new RuntimeAgent(runtimeConfig, capabilities);
125192

126193
await agent.start();
127194

@@ -136,30 +203,76 @@ Deno.test("RuntimeAgent adapter injection", async (t) => {
136203
// Create shared adapter
137204
const adapter = makeInMemoryAdapter({});
138205

139-
// Create two agents using the same adapter
140-
const config1 = createTestRuntimeConfig([], {
206+
// Create sync payloads for each agent
207+
const syncPayload1 = createRuntimeSyncPayload({
208+
authToken: "token1",
209+
runtimeId: "agent-1",
210+
sessionId: crypto.randomUUID(),
211+
userId: "test-user-id",
212+
});
213+
214+
const syncPayload2 = createRuntimeSyncPayload({
215+
authToken: "token2",
216+
runtimeId: "agent-2",
217+
sessionId: crypto.randomUUID(),
218+
userId: "test-user-id",
219+
});
220+
221+
// Create stores with shared adapter
222+
const store1 = await createStorePromise({
141223
adapter,
142224
notebookId: "shared-adapter-1",
143-
runtimeId: "agent-1",
144-
authToken: "token1",
225+
syncPayload: syncPayload1,
145226
});
146227

147-
const config2 = createTestRuntimeConfig([], {
228+
const store2 = await createStorePromise({
148229
adapter,
149230
notebookId: "shared-adapter-2",
231+
syncPayload: syncPayload2,
232+
});
233+
234+
// Create configs with stores
235+
const config1: RuntimeAgentOptions = {
236+
runtimeId: "agent-1",
237+
runtimeType: "test-runtime",
238+
syncUrl: "ws://fake-url:9999",
239+
authToken: "token1",
240+
notebookId: "shared-adapter-1",
241+
userId: "test-user-id",
242+
store: store1,
243+
capabilities: {
244+
canExecuteCode: true,
245+
canExecuteSql: false,
246+
canExecuteAi: false,
247+
},
248+
};
249+
250+
const config2: RuntimeAgentOptions = {
150251
runtimeId: "agent-2",
151-
authToken: "token2",
252+
runtimeType: "test-runtime",
152253
syncUrl: "ws://fake-url:9999",
153-
});
254+
authToken: "token2",
255+
notebookId: "shared-adapter-2",
256+
userId: "test-user-id",
257+
store: store2,
258+
capabilities: {
259+
canExecuteCode: true,
260+
canExecuteSql: false,
261+
canExecuteAi: false,
262+
},
263+
};
264+
265+
const runtimeConfig1 = new RuntimeConfig(config1);
266+
const runtimeConfig2 = new RuntimeConfig(config2);
154267

155268
const capabilities: RuntimeCapabilities = {
156269
canExecuteCode: true,
157270
canExecuteSql: false,
158271
canExecuteAi: false,
159272
};
160273

161-
const agent1 = new RuntimeAgent(config1, capabilities);
162-
const agent2 = new RuntimeAgent(config2, capabilities);
274+
const agent1 = new RuntimeAgent(runtimeConfig1, capabilities);
275+
const agent2 = new RuntimeAgent(runtimeConfig2, capabilities);
163276

164277
await agent1.start();
165278
await agent2.start();
@@ -183,20 +296,45 @@ Deno.test("RuntimeAgent adapter injection", async (t) => {
183296
},
184297
});
185298

186-
const config = createTestRuntimeConfig([], {
299+
// Create sync payload
300+
const syncPayload = createRuntimeSyncPayload({
301+
authToken: "test-token",
302+
runtimeId: "test-runtime-id",
303+
sessionId: crypto.randomUUID(),
304+
userId: "test-user-id",
305+
});
306+
307+
// Create store with file system adapter
308+
const store = await createStorePromise({
187309
adapter: fsAdapter,
188310
notebookId: "fs-test",
189-
authToken: "test-token",
190-
syncUrl: "ws://fake-url:9999",
311+
syncPayload,
191312
});
192313

314+
const config: RuntimeAgentOptions = {
315+
runtimeId: "test-runtime-id",
316+
runtimeType: "test-runtime",
317+
syncUrl: "ws://fake-url:9999",
318+
authToken: "test-token",
319+
notebookId: "fs-test",
320+
userId: "test-user-id",
321+
store,
322+
capabilities: {
323+
canExecuteCode: true,
324+
canExecuteSql: false,
325+
canExecuteAi: false,
326+
},
327+
};
328+
329+
const runtimeConfig = new RuntimeConfig(config);
330+
193331
const capabilities: RuntimeCapabilities = {
194332
canExecuteCode: true,
195333
canExecuteSql: false,
196334
canExecuteAi: false,
197335
};
198336

199-
const agent = new RuntimeAgent(config, capabilities);
337+
const agent = new RuntimeAgent(runtimeConfig, capabilities);
200338

201339
await agent.start();
202340

0 commit comments

Comments
 (0)