@assistant-ui/react-statewire 0.28.0 → 0.29.0
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/StatewireThread.d.ts +6 -0
- package/dist/StatewireThread.d.ts.map +1 -1
- package/dist/StatewireThread.js +55 -12
- package/dist/StatewireThread.js.map +1 -1
- package/dist/localStorage.d.ts +1 -1
- package/dist/localStorage.d.ts.map +1 -1
- package/dist/localStorage.js +2 -2
- package/dist/localStorage.js.map +1 -1
- package/package.json +2 -2
- package/src/StatewireThread.failed.test.tsx +36 -13
- package/src/StatewireThread.retract.test.tsx +175 -0
- package/src/StatewireThread.runs.test.tsx +41 -36
- package/src/StatewireThread.test.tsx +20 -5
- package/src/StatewireThread.ts +99 -45
- package/src/localStorage.test.ts +14 -22
- package/src/localStorage.ts +3 -3
|
@@ -42,7 +42,7 @@ const extras = (aui: () => ReturnType<typeof useAui>) =>
|
|
|
42
42
|
// canonical state, for the covered contract.
|
|
43
43
|
const createSettlingServer = (init?: Partial<ServerState>) => {
|
|
44
44
|
const received: { method: string; params: unknown[]; seq: number }[] = [];
|
|
45
|
-
const clients = new Map<string, { seq: number
|
|
45
|
+
const clients = new Map<string, { seq: number }>();
|
|
46
46
|
const encoder = new TextEncoder();
|
|
47
47
|
const frame = (chunk: unknown) => `data: ${JSON.stringify(chunk)}\n\n`;
|
|
48
48
|
let stream: ReadableStreamDefaultController<Uint8Array> | undefined;
|
|
@@ -53,14 +53,10 @@ const createSettlingServer = (init?: Partial<ServerState>) => {
|
|
|
53
53
|
const push = (chunk: unknown) =>
|
|
54
54
|
stream!.enqueue(encoder.encode(frame(chunk)));
|
|
55
55
|
type Frame = {
|
|
56
|
-
ctx?: { seq: number }[];
|
|
57
56
|
cmd?: { method: string; params: unknown[]; seq: number }[];
|
|
58
57
|
};
|
|
59
58
|
const admit = (clientId: string, body: Frame) => {
|
|
60
59
|
const rec = clients.get(clientId)!;
|
|
61
|
-
for (const statement of body.ctx ?? []) {
|
|
62
|
-
rec.ctxSeq = Math.max(rec.ctxSeq, statement.seq);
|
|
63
|
-
}
|
|
64
60
|
for (const statement of body.cmd ?? []) {
|
|
65
61
|
rec.seq = Math.max(rec.seq, statement.seq);
|
|
66
62
|
received.push({
|
|
@@ -68,8 +64,10 @@ const createSettlingServer = (init?: Partial<ServerState>) => {
|
|
|
68
64
|
params: statement.params,
|
|
69
65
|
seq: statement.seq,
|
|
70
66
|
});
|
|
71
|
-
push({ cmd: [{ seq: statement.seq, dur: true }] });
|
|
72
|
-
push({
|
|
67
|
+
push({ cmd: [{ protocol: "default", seq: statement.seq, dur: true }] });
|
|
68
|
+
push({
|
|
69
|
+
cmd: [{ protocol: "default", seq: statement.seq, ...verdict() }],
|
|
70
|
+
});
|
|
73
71
|
}
|
|
74
72
|
};
|
|
75
73
|
const fetchImpl = (async (input: RequestInfo | URL, init2?: RequestInit) => {
|
|
@@ -78,7 +76,7 @@ const createSettlingServer = (init?: Partial<ServerState>) => {
|
|
|
78
76
|
const clientId =
|
|
79
77
|
headers.get("Statewire-Client-Id") ?? [...clients.keys()].at(-1)!;
|
|
80
78
|
if (url.endsWith("/stream")) {
|
|
81
|
-
if (!clients.has(clientId)) clients.set(clientId, { seq: 0
|
|
79
|
+
if (!clients.has(clientId)) clients.set(clientId, { seq: 0 });
|
|
82
80
|
const rec = clients.get(clientId)!;
|
|
83
81
|
const attachFrame = JSON.parse(String(init2?.body ?? "{}")) as Frame;
|
|
84
82
|
const body = new ReadableStream<Uint8Array>({
|
|
@@ -96,10 +94,10 @@ const createSettlingServer = (init?: Partial<ServerState>) => {
|
|
|
96
94
|
},
|
|
97
95
|
],
|
|
98
96
|
syn: {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
version: "2026-09-13",
|
|
98
|
+
protocols: [
|
|
99
|
+
{ name: "default", version: "2026-09-13", seq: rec.seq },
|
|
100
|
+
],
|
|
103
101
|
},
|
|
104
102
|
}),
|
|
105
103
|
),
|
|
@@ -195,7 +193,7 @@ describe("StatewireThread failed lane", () => {
|
|
|
195
193
|
expect(runs().runId).toBeNull();
|
|
196
194
|
});
|
|
197
195
|
|
|
198
|
-
it("retry
|
|
196
|
+
it("repeated retry actions dispatch once and remove the entry", async () => {
|
|
199
197
|
const { server, aui, runs } = await mountFailed({
|
|
200
198
|
type: "run/enqueue",
|
|
201
199
|
runId: "run-1",
|
|
@@ -205,6 +203,7 @@ describe("StatewireThread failed lane", () => {
|
|
|
205
203
|
server.accept();
|
|
206
204
|
act(() => {
|
|
207
205
|
extras(aui).retryFailed("m1");
|
|
206
|
+
extras(aui).retryFailed("m1");
|
|
208
207
|
});
|
|
209
208
|
await waitFor(() => expect(runs().failed).toHaveLength(0));
|
|
210
209
|
const sends = server.received.filter((r) => r.method === "run/enqueue");
|
|
@@ -216,6 +215,30 @@ describe("StatewireThread failed lane", () => {
|
|
|
216
215
|
expect((sends[1]!.params[0] as { runId: string }).runId).not.toBe("run-1");
|
|
217
216
|
});
|
|
218
217
|
|
|
218
|
+
it("allows another retry after the previous retry is rejected", async () => {
|
|
219
|
+
const { server, aui, runs } = await mountFailed({
|
|
220
|
+
type: "run/enqueue",
|
|
221
|
+
runId: "run-1",
|
|
222
|
+
message: wireMessage("m1", "hello"),
|
|
223
|
+
runAnchorMessageId: null,
|
|
224
|
+
});
|
|
225
|
+
act(() => {
|
|
226
|
+
extras(aui).retryFailed("m1");
|
|
227
|
+
});
|
|
228
|
+
await waitFor(() => {
|
|
229
|
+
expect(server.received).toHaveLength(2);
|
|
230
|
+
expect(runs().failed).toHaveLength(1);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
server.accept();
|
|
234
|
+
act(() => {
|
|
235
|
+
extras(aui).retryFailed("m1");
|
|
236
|
+
extras(aui).retryFailed("m1");
|
|
237
|
+
});
|
|
238
|
+
await waitFor(() => expect(runs().failed).toHaveLength(0));
|
|
239
|
+
expect(server.received).toHaveLength(3);
|
|
240
|
+
});
|
|
241
|
+
|
|
219
242
|
it("a failed steer whose run is gone retries as a plain enqueue", async () => {
|
|
220
243
|
const { server, aui, runs } = await mountFailed({
|
|
221
244
|
type: "run/steer",
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
// Contract tests for the stopping client's pop: the run/stop verdict carries
|
|
4
|
+
// the run's retracted items, and the client that stopped dequeues them into
|
|
5
|
+
// an empty composer. A non-empty composer and rejected dequeues leave them
|
|
6
|
+
// queued.
|
|
7
|
+
|
|
8
|
+
import { act, render, waitFor } from "@testing-library/react";
|
|
9
|
+
import type { FC } from "react";
|
|
10
|
+
import { describe, expect, it } from "vitest";
|
|
11
|
+
import { AuiProvider, useAui } from "@assistant-ui/store";
|
|
12
|
+
import { resource } from "@assistant-ui/tap";
|
|
13
|
+
import {
|
|
14
|
+
StatewireReject,
|
|
15
|
+
useStatewireCommands,
|
|
16
|
+
useStatewireState,
|
|
17
|
+
} from "statewire/host";
|
|
18
|
+
import { asStatewireExtras, StatewireThread } from "./StatewireThread";
|
|
19
|
+
import { toThreadMessage } from "./__tests__/testHelpers";
|
|
20
|
+
|
|
21
|
+
type QueueItem = {
|
|
22
|
+
id: string;
|
|
23
|
+
role: "user";
|
|
24
|
+
parts: { type: "text"; text: string }[];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type ServerState = {
|
|
28
|
+
messages: { id: string; role: "user" | "assistant"; text: string }[];
|
|
29
|
+
status: "ready" | StatewireThread.RunStatus;
|
|
30
|
+
runs: {
|
|
31
|
+
runId: string | null;
|
|
32
|
+
status: StatewireThread.RunStatus;
|
|
33
|
+
queue: QueueItem[];
|
|
34
|
+
steerQueue: QueueItem[];
|
|
35
|
+
}[];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const item = (id: string, text: string): QueueItem => ({
|
|
39
|
+
id,
|
|
40
|
+
role: "user",
|
|
41
|
+
parts: [{ type: "text", text }],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const converter: StatewireThread.StateConverter<ServerState> = (state) => ({
|
|
45
|
+
messages: state.messages.map(toThreadMessage),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// A host whose run/stop retracts the given items into the lanes and answers
|
|
49
|
+
// with them; run/dequeue removes an item unless `rejectDequeue` names it.
|
|
50
|
+
const createServer = (opts: {
|
|
51
|
+
retract: { queue?: QueueItem[]; steer?: QueueItem[] };
|
|
52
|
+
rejectDequeue?: string;
|
|
53
|
+
}) => {
|
|
54
|
+
const received: { method: string; params: unknown }[] = [];
|
|
55
|
+
const transport = resource(() => {
|
|
56
|
+
const [state] = useStatewireState<ServerState>(() => ({
|
|
57
|
+
messages: [{ id: "m1", role: "user", text: "hello" }],
|
|
58
|
+
status: "running",
|
|
59
|
+
runs: [{ runId: "run-1", status: "running", queue: [], steerQueue: [] }],
|
|
60
|
+
}));
|
|
61
|
+
const commands = useStatewireCommands({
|
|
62
|
+
"run/stop": (params: unknown) => {
|
|
63
|
+
received.push({ method: "run/stop", params });
|
|
64
|
+
const entry = state.runs[0]!;
|
|
65
|
+
entry.queue = opts.retract.queue ?? [];
|
|
66
|
+
entry.steerQueue = opts.retract.steer ?? [];
|
|
67
|
+
entry.status = "stopped";
|
|
68
|
+
state.status = "stopped";
|
|
69
|
+
state.messages = [];
|
|
70
|
+
return [...entry.queue, ...entry.steerQueue];
|
|
71
|
+
},
|
|
72
|
+
"run/dequeue": (params: { messageId: string }) => {
|
|
73
|
+
received.push({ method: "run/dequeue", params });
|
|
74
|
+
if (params.messageId === opts.rejectDequeue)
|
|
75
|
+
throw new StatewireReject("not yours", {
|
|
76
|
+
payload: { reason: "not-owner" },
|
|
77
|
+
});
|
|
78
|
+
const entry = state.runs[0]!;
|
|
79
|
+
entry.queue = entry.queue.filter((q) => q.id !== params.messageId);
|
|
80
|
+
entry.steerQueue = entry.steerQueue.filter(
|
|
81
|
+
(q) => q.id !== params.messageId,
|
|
82
|
+
);
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
return { state, commands };
|
|
86
|
+
})();
|
|
87
|
+
return { transport, received };
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const mountThread = (
|
|
91
|
+
transport: ReturnType<typeof createServer>["transport"],
|
|
92
|
+
) => {
|
|
93
|
+
const captured: { aui?: ReturnType<typeof useAui> } = {};
|
|
94
|
+
const Capture: FC = () => {
|
|
95
|
+
captured.aui = useAui();
|
|
96
|
+
return null;
|
|
97
|
+
};
|
|
98
|
+
const App: FC = () => {
|
|
99
|
+
const aui = useAui({
|
|
100
|
+
thread: StatewireThread<ServerState>({
|
|
101
|
+
initialState: { messages: [], status: "ready", runs: [] },
|
|
102
|
+
converter,
|
|
103
|
+
transport,
|
|
104
|
+
}),
|
|
105
|
+
});
|
|
106
|
+
return (
|
|
107
|
+
<AuiProvider value={aui}>
|
|
108
|
+
<Capture />
|
|
109
|
+
</AuiProvider>
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
render(<App />);
|
|
113
|
+
return () => captured.aui!;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const composerText = (aui: () => ReturnType<typeof useAui>) =>
|
|
117
|
+
aui().thread().composer().getState().text;
|
|
118
|
+
|
|
119
|
+
const dequeued = (received: { method: string; params: unknown }[]) =>
|
|
120
|
+
received
|
|
121
|
+
.filter((r) => r.method === "run/dequeue")
|
|
122
|
+
.map((r) => (r.params as { messageId: string }).messageId);
|
|
123
|
+
|
|
124
|
+
describe("StatewireThread retraction pop", () => {
|
|
125
|
+
it("dequeues the retracted items into the empty composer in thread order", async () => {
|
|
126
|
+
const server = createServer({
|
|
127
|
+
retract: {
|
|
128
|
+
queue: [item("m1", "hello")],
|
|
129
|
+
steer: [item("s1", "and this")],
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
const aui = mountThread(server.transport);
|
|
133
|
+
await waitFor(() => expect(aui().thread().getState().isRunning).toBe(true));
|
|
134
|
+
act(() => {
|
|
135
|
+
aui().thread().cancelRun();
|
|
136
|
+
});
|
|
137
|
+
await waitFor(() => expect(composerText(aui)).toBe("hello\n\nand this"));
|
|
138
|
+
expect(dequeued(server.received)).toEqual(["m1", "s1"]);
|
|
139
|
+
await waitFor(() => {
|
|
140
|
+
const runs = asStatewireExtras(aui().thread().getState().extras).runs;
|
|
141
|
+
expect([...runs.queue, ...runs.steerQueue]).toHaveLength(0);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("leaves the items queued while the composer holds text", async () => {
|
|
146
|
+
const server = createServer({ retract: { queue: [item("m1", "hello")] } });
|
|
147
|
+
const aui = mountThread(server.transport);
|
|
148
|
+
await waitFor(() => expect(aui().thread().getState().isRunning).toBe(true));
|
|
149
|
+
act(() => {
|
|
150
|
+
aui().thread().composer().setText("draft");
|
|
151
|
+
aui().thread().cancelRun();
|
|
152
|
+
});
|
|
153
|
+
await waitFor(() =>
|
|
154
|
+
expect(aui().thread().getState().isRunning).toBe(false),
|
|
155
|
+
);
|
|
156
|
+
await waitFor(() =>
|
|
157
|
+
expect(server.received.map((r) => r.method)).toEqual(["run/stop"]),
|
|
158
|
+
);
|
|
159
|
+
expect(composerText(aui)).toBe("draft");
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("keeps an item whose dequeue rejects and pops the rest", async () => {
|
|
163
|
+
const server = createServer({
|
|
164
|
+
retract: { queue: [item("m1", "mine")], steer: [item("s1", "theirs")] },
|
|
165
|
+
rejectDequeue: "s1",
|
|
166
|
+
});
|
|
167
|
+
const aui = mountThread(server.transport);
|
|
168
|
+
await waitFor(() => expect(aui().thread().getState().isRunning).toBe(true));
|
|
169
|
+
act(() => {
|
|
170
|
+
aui().thread().cancelRun();
|
|
171
|
+
});
|
|
172
|
+
await waitFor(() => expect(composerText(aui)).toBe("mine"));
|
|
173
|
+
expect(dequeued(server.received)).toEqual(["m1", "s1"]);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -125,10 +125,11 @@ const createServer = (init?: Partial<RunsServerState>) => {
|
|
|
125
125
|
// snapshot until `release()` to expose the pre-attach window.
|
|
126
126
|
const createRemoteServer = (
|
|
127
127
|
init?: Partial<RunsServerState>,
|
|
128
|
-
opts?: { hold?: boolean },
|
|
128
|
+
opts?: { hold?: boolean; protocol?: string },
|
|
129
129
|
) => {
|
|
130
|
+
const protocol = opts?.protocol ?? "default";
|
|
130
131
|
const received: { method: string; params: unknown[] }[] = [];
|
|
131
|
-
const clients = new Map<string, { seq: number
|
|
132
|
+
const clients = new Map<string, { seq: number }>();
|
|
132
133
|
const encoder = new TextEncoder();
|
|
133
134
|
const frame = (chunk: unknown) => `data: ${JSON.stringify(chunk)}\n\n`;
|
|
134
135
|
let released = !(opts?.hold ?? false);
|
|
@@ -150,14 +151,10 @@ const createRemoteServer = (
|
|
|
150
151
|
stream!.close();
|
|
151
152
|
};
|
|
152
153
|
type Frame = {
|
|
153
|
-
ctx?: { seq: number }[];
|
|
154
154
|
cmd?: { method: string; params: unknown[]; seq: number }[];
|
|
155
155
|
};
|
|
156
156
|
const admit = (clientId: string, body: Frame) => {
|
|
157
157
|
const rec = clients.get(clientId)!;
|
|
158
|
-
for (const statement of body.ctx ?? []) {
|
|
159
|
-
rec.ctxSeq = Math.max(rec.ctxSeq, statement.seq);
|
|
160
|
-
}
|
|
161
158
|
for (const statement of body.cmd ?? []) {
|
|
162
159
|
rec.seq = Math.max(rec.seq, statement.seq);
|
|
163
160
|
received.push({ method: statement.method, params: statement.params });
|
|
@@ -169,7 +166,7 @@ const createRemoteServer = (
|
|
|
169
166
|
const clientId =
|
|
170
167
|
headers.get("Statewire-Client-Id") ?? [...clients.keys()].at(-1)!;
|
|
171
168
|
if (url.endsWith("/stream")) {
|
|
172
|
-
if (!clients.has(clientId)) clients.set(clientId, { seq: 0
|
|
169
|
+
if (!clients.has(clientId)) clients.set(clientId, { seq: 0 });
|
|
173
170
|
const rec = clients.get(clientId)!;
|
|
174
171
|
const attachFrame = JSON.parse(String(init2?.body ?? "{}")) as Frame;
|
|
175
172
|
const body = new ReadableStream<Uint8Array>({
|
|
@@ -184,16 +181,16 @@ const createRemoteServer = (
|
|
|
184
181
|
ops: [
|
|
185
182
|
{
|
|
186
183
|
op: "mount",
|
|
187
|
-
protocol
|
|
184
|
+
protocol,
|
|
188
185
|
main: true,
|
|
189
186
|
value: { ...INITIAL_STATE, ...init },
|
|
190
187
|
},
|
|
191
188
|
],
|
|
192
189
|
syn: {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
190
|
+
version: "2026-09-13",
|
|
191
|
+
protocols: [
|
|
192
|
+
{ name: protocol, version: "2026-09-13", seq: rec.seq },
|
|
193
|
+
],
|
|
197
194
|
},
|
|
198
195
|
}),
|
|
199
196
|
),
|
|
@@ -222,6 +219,7 @@ const createRemoteServer = (
|
|
|
222
219
|
transport: StatewireHttp<RunsServerState>({
|
|
223
220
|
url: "http://fake/api",
|
|
224
221
|
fetch: fetchImpl,
|
|
222
|
+
protocol,
|
|
225
223
|
}),
|
|
226
224
|
};
|
|
227
225
|
};
|
|
@@ -718,34 +716,41 @@ describe("StatewireThread runs mode", () => {
|
|
|
718
716
|
expect(aui().thread().getState().isRunning).toBe(true);
|
|
719
717
|
});
|
|
720
718
|
|
|
721
|
-
it(
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
719
|
+
it.each([undefined, "athena"])(
|
|
720
|
+
"preloads initialState: interactive before attach, sends fold in (protocol: %s)",
|
|
721
|
+
async (protocol) => {
|
|
722
|
+
const server = createRemoteServer(
|
|
723
|
+
{},
|
|
724
|
+
{ hold: true, ...(protocol !== undefined && { protocol }) },
|
|
725
|
+
);
|
|
726
|
+
const { aui, runs } = mountThread({
|
|
727
|
+
transport: server.transport,
|
|
728
|
+
materialize: rollbackMaterialize,
|
|
729
|
+
protocol,
|
|
730
|
+
});
|
|
727
731
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
+
expect(threadStatus(aui())).toBe("ready");
|
|
733
|
+
act(() => {
|
|
734
|
+
aui().thread().append("hello");
|
|
735
|
+
});
|
|
732
736
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
737
|
+
// The pre-attach send renders through the same optimistic + materialize
|
|
738
|
+
// folds; while connecting, the run presents as disconnected.
|
|
739
|
+
await waitFor(() => expect(threadStatus(aui())).toBe("disconnected"));
|
|
740
|
+
expect(runs().runId).toEqual(expect.any(String));
|
|
741
|
+
expect(aui().thread().getState().messages).toHaveLength(1);
|
|
742
|
+
expect(server.received).toEqual([]);
|
|
739
743
|
|
|
740
|
-
|
|
744
|
+
server.release();
|
|
741
745
|
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
746
|
+
// Attach posts the queued command; the still-unapplied overlay survives the snapshot.
|
|
747
|
+
await waitFor(() =>
|
|
748
|
+
expect(server.received.map((c) => c.method)).toEqual(["run/enqueue"]),
|
|
749
|
+
);
|
|
750
|
+
expect(aui().thread().getState().messages).toHaveLength(1);
|
|
751
|
+
expect(threadStatus(aui())).toBe("running");
|
|
752
|
+
},
|
|
753
|
+
);
|
|
749
754
|
|
|
750
755
|
it("preloads again after a transport swap on a persistent thread", async () => {
|
|
751
756
|
const serverA = createRemoteServer({
|
|
@@ -436,7 +436,9 @@ describe("StatewireThread", () => {
|
|
|
436
436
|
await waitFor(() => expect(mock.commands).toHaveLength(1));
|
|
437
437
|
await act(async () => {
|
|
438
438
|
await mock.sendEnvelope({
|
|
439
|
-
cmd: [
|
|
439
|
+
cmd: [
|
|
440
|
+
{ protocol: "default", seq: 1, type: "rejected", message: "retry" },
|
|
441
|
+
],
|
|
440
442
|
});
|
|
441
443
|
});
|
|
442
444
|
await waitFor(() => expect(errors).toHaveLength(1));
|
|
@@ -635,11 +637,22 @@ describe("StatewireThread", () => {
|
|
|
635
637
|
});
|
|
636
638
|
|
|
637
639
|
describe("contextSync: command-send", () => {
|
|
638
|
-
const contextValueOf = (command: {
|
|
639
|
-
|
|
640
|
+
const contextValueOf = (command: {
|
|
641
|
+
protocol: string;
|
|
642
|
+
method: string;
|
|
643
|
+
params: unknown[];
|
|
644
|
+
}) => {
|
|
645
|
+
expect([command.protocol, command.method]).toEqual([
|
|
646
|
+
"default/context",
|
|
647
|
+
"set",
|
|
648
|
+
]);
|
|
649
|
+
return command.params[0] as Record<string, unknown>;
|
|
650
|
+
};
|
|
640
651
|
|
|
641
652
|
it("sends the ambient model context on connect and on every change", async () => {
|
|
642
|
-
const mock = createMockTransport<ServerState>(INITIAL_STATE
|
|
653
|
+
const mock = createMockTransport<ServerState>(INITIAL_STATE, "default", {
|
|
654
|
+
ephemeral: ["context"],
|
|
655
|
+
});
|
|
643
656
|
const { aui } = mountThread({
|
|
644
657
|
transport: mock.transport,
|
|
645
658
|
converter,
|
|
@@ -659,7 +672,9 @@ describe("StatewireThread", () => {
|
|
|
659
672
|
});
|
|
660
673
|
|
|
661
674
|
it("skips resends while the serialized context is unchanged", async () => {
|
|
662
|
-
const mock = createMockTransport<ServerState>(INITIAL_STATE
|
|
675
|
+
const mock = createMockTransport<ServerState>(INITIAL_STATE, "default", {
|
|
676
|
+
ephemeral: ["context"],
|
|
677
|
+
});
|
|
663
678
|
const { aui } = mountThread({
|
|
664
679
|
transport: mock.transport,
|
|
665
680
|
converter,
|