Skip to content

Commit 5b0a869

Browse files
taylordowns2000josephjclark
authored andcommitted
put back tests
1 parent 72880ae commit 5b0a869

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

packages/ws-worker/test/events/run-complete.test.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,80 @@ test('should send final_state when a single leaf node is reached by two paths',
398398
t.deepEqual(completeEvent.final_state, result);
399399
t.falsy(completeEvent.final_dataclip_id);
400400
});
401+
402+
test('should properly serialize final_state as JSON', async (t) => {
403+
const plan = createPlan();
404+
const state = createRunState(plan);
405+
406+
const complexState = {
407+
data: {
408+
users: [
409+
{ id: 1, name: 'Alice' },
410+
{ id: 2, name: 'Bob' },
411+
],
412+
metadata: {
413+
timestamp: new Date('2024-01-01').toISOString(),
414+
nested: { deeply: { value: 42 } },
415+
},
416+
},
417+
configuration: { setting: true },
418+
references: [],
419+
};
420+
421+
let completeEvent: any;
422+
423+
const channel = mockChannel({
424+
[RUN_LOG]: () => true,
425+
[RUN_COMPLETE]: (evt) => {
426+
completeEvent = evt;
427+
},
428+
});
429+
430+
const context: any = {
431+
channel,
432+
state,
433+
onFinish: () => {},
434+
};
435+
436+
const event: any = { state: complexState };
437+
438+
await handleRunComplete(context, event);
439+
440+
t.deepEqual(completeEvent.final_state, complexState);
441+
t.deepEqual(completeEvent.final_state.data.users[0], { id: 1, name: 'Alice' });
442+
t.is(completeEvent.final_state.data.metadata.nested.deeply.value, 42);
443+
444+
const jsonString = JSON.stringify(completeEvent.final_state);
445+
const parsed = JSON.parse(jsonString);
446+
t.deepEqual(parsed, complexState);
447+
});
448+
449+
test('should handle Uint8Array in final_state', async (t) => {
450+
const plan = createPlan();
451+
const state = createRunState(plan);
452+
453+
const stateWithBinary = {
454+
data: { buffer: new Uint8Array([1, 2, 3, 4, 5]) },
455+
};
456+
457+
let completeEvent: any;
458+
459+
const channel = mockChannel({
460+
[RUN_LOG]: () => true,
461+
[RUN_COMPLETE]: (evt) => {
462+
completeEvent = evt;
463+
},
464+
});
465+
466+
const context: any = {
467+
channel,
468+
state,
469+
onFinish: () => {},
470+
};
471+
472+
const event: any = { state: stateWithBinary };
473+
474+
await handleRunComplete(context, event);
475+
476+
t.deepEqual(completeEvent.final_state.data.buffer, new Uint8Array([1, 2, 3, 4, 5]));
477+
});

0 commit comments

Comments
 (0)