@vibes.diy/api-impl 14.3.324 → 14.3.326
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/LICENSE.md +54 -201
- package/api-connection.js +0 -1
- package/chat-event-feed.js +0 -1
- package/chat-session.js +0 -1
- package/codegen-shard-index.js +0 -1
- package/firefly-api-adapter.js +0 -1
- package/index.d.ts +2 -1
- package/index.js +4 -2
- package/llm-chat.js +0 -1
- package/package.json +7 -7
- package/query-docs-walk.js +0 -1
- package/reconnect-backoff.js +0 -1
- package/reconnect-kick.js +0 -1
- package/shard-roll.js +0 -1
- package/user-settings-response.js +0 -1
- package/vibes-diy-api-apps.js +0 -1
- package/vibes-diy-api-chat.js +0 -1
- package/vibes-diy-api-ctx.js +0 -1
- package/vibes-diy-api-docs.js +0 -1
- package/vibes-diy-api-invites.js +0 -1
- package/vibes-diy-api-listeners.js +0 -1
- package/vibes-diy-api-reports.js +0 -1
- package/vibes-diy-api-settings.js +0 -1
- package/vibes-diy-api-transport.js +0 -1
- package/vibes-diy-api-types.js +0 -1
- package/websocket-connection.js +0 -1
- package/ws-proxy-tunnel.js +0 -1
- package/ws-proxy.js +0 -1
- package/api-connection.js.map +0 -1
- package/campaign-health-decode.test.d.ts +0 -1
- package/campaign-health-decode.test.js +0 -124
- package/campaign-health-decode.test.js.map +0 -1
- package/chat-event-feed.js.map +0 -1
- package/chat-session.js.map +0 -1
- package/chat-session.test.d.ts +0 -1
- package/chat-session.test.js +0 -734
- package/chat-session.test.js.map +0 -1
- package/codegen-shard-index.js.map +0 -1
- package/codegen-shard-index.test.d.ts +0 -1
- package/codegen-shard-index.test.js +0 -62
- package/codegen-shard-index.test.js.map +0 -1
- package/firefly-api-adapter.js.map +0 -1
- package/firefly-api-adapter.test.d.ts +0 -1
- package/firefly-api-adapter.test.js +0 -480
- package/firefly-api-adapter.test.js.map +0 -1
- package/get-app-by-fsid-auth-indeterminate.test.d.ts +0 -1
- package/get-app-by-fsid-auth-indeterminate.test.js +0 -99
- package/get-app-by-fsid-auth-indeterminate.test.js.map +0 -1
- package/get-chat-response-decode.test.d.ts +0 -1
- package/get-chat-response-decode.test.js +0 -56
- package/get-chat-response-decode.test.js.map +0 -1
- package/index.js.map +0 -1
- package/llm-chat-disconnect.test.d.ts +0 -1
- package/llm-chat-disconnect.test.js +0 -173
- package/llm-chat-disconnect.test.js.map +0 -1
- package/llm-chat.js.map +0 -1
- package/query-docs-walk.js.map +0 -1
- package/query-docs-walk.test.d.ts +0 -1
- package/query-docs-walk.test.js +0 -91
- package/query-docs-walk.test.js.map +0 -1
- package/reconnect-backoff.js.map +0 -1
- package/reconnect-backoff.test.d.ts +0 -1
- package/reconnect-backoff.test.js +0 -69
- package/reconnect-backoff.test.js.map +0 -1
- package/reconnect-failed-dial.test.d.ts +0 -1
- package/reconnect-failed-dial.test.js +0 -400
- package/reconnect-failed-dial.test.js.map +0 -1
- package/reconnect-kick.js.map +0 -1
- package/reconnect-kick.test.d.ts +0 -1
- package/reconnect-kick.test.js +0 -88
- package/reconnect-kick.test.js.map +0 -1
- package/request-idle-visibility.test.d.ts +0 -1
- package/request-idle-visibility.test.js +0 -112
- package/request-idle-visibility.test.js.map +0 -1
- package/request-validation.test.d.ts +0 -1
- package/request-validation.test.js +0 -216
- package/request-validation.test.js.map +0 -1
- package/shard-roll.js.map +0 -1
- package/shard-roll.test.d.ts +0 -1
- package/shard-roll.test.js +0 -604
- package/shard-roll.test.js.map +0 -1
- package/user-settings-response.js.map +0 -1
- package/user-settings-response.test.d.ts +0 -1
- package/user-settings-response.test.js +0 -98
- package/user-settings-response.test.js.map +0 -1
- package/vibes-diy-api-apps.js.map +0 -1
- package/vibes-diy-api-chat.js.map +0 -1
- package/vibes-diy-api-ctx.js.map +0 -1
- package/vibes-diy-api-docs.js.map +0 -1
- package/vibes-diy-api-invites.js.map +0 -1
- package/vibes-diy-api-listeners.js.map +0 -1
- package/vibes-diy-api-reports.js.map +0 -1
- package/vibes-diy-api-settings.js.map +0 -1
- package/vibes-diy-api-transport.js.map +0 -1
- package/vibes-diy-api-types.js.map +0 -1
- package/vitest.config.d.ts +0 -2
- package/vitest.config.js +0 -10
- package/vitest.config.js.map +0 -1
- package/websocket-connection.js.map +0 -1
- package/websocket-connection.test.d.ts +0 -1
- package/websocket-connection.test.js +0 -187
- package/websocket-connection.test.js.map +0 -1
- package/whoami-auth-indeterminate.test.d.ts +0 -1
- package/whoami-auth-indeterminate.test.js +0 -125
- package/whoami-auth-indeterminate.test.js.map +0 -1
- package/ws-proxy-connect.test.d.ts +0 -1
- package/ws-proxy-connect.test.js +0 -176
- package/ws-proxy-connect.test.js.map +0 -1
- package/ws-proxy-tunnel.js.map +0 -1
- package/ws-proxy.js.map +0 -1
- package/ws-proxy.test.d.ts +0 -1
- package/ws-proxy.test.js +0 -86
- package/ws-proxy.test.js.map +0 -1
package/chat-session.test.js
DELETED
|
@@ -1,734 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { Result } from "@adviser/cement";
|
|
3
|
-
import { MAX_ROLL_INDEX, mkResError, resErrorToError, SHARD_OVERLOADED_CODE } from "@vibes.diy/api-types";
|
|
4
|
-
import { decodeChatWireMessage, drainChatSession, isPlatformIsolateClose, isRestyleBlock, makeStreamGenerations, openChatSession, OpenChatSessionError, promptWithShardRoll, releaseIsLive, reopenStillOwed, untilSuperseded, wireEventKey, } from "./chat-session.js";
|
|
5
|
-
describe("decodeChatWireMessage", () => {
|
|
6
|
-
const section = (promptId, blocks) => ({ type: "section", promptId, blocks });
|
|
7
|
-
it("marks a server-dispatched prompt.req as a build and reads its message count", () => {
|
|
8
|
-
const out = decodeChatWireMessage(section("b", [{ type: "prompt.req", seq: 0, agentDispatched: true, request: { messages: [1, 2, 3] } }]));
|
|
9
|
-
expect(out).toEqual([{ kind: "block", promptId: "b", seq: 0, type: "prompt.req", agentDispatched: true, reqMessageCount: 3 }]);
|
|
10
|
-
});
|
|
11
|
-
it("carries a prose section's message end, so a text thread splits where the server did", () => {
|
|
12
|
-
const out = decodeChatWireMessage(section("a", [
|
|
13
|
-
{ type: "block.toplevel.end", seq: 3, messageEnd: true },
|
|
14
|
-
{ type: "block.toplevel.end", seq: 7 },
|
|
15
|
-
]));
|
|
16
|
-
expect(out[0]).toMatchObject({ type: "block.toplevel.end", messageEnd: true });
|
|
17
|
-
expect(out[1]).not.toHaveProperty("messageEnd");
|
|
18
|
-
});
|
|
19
|
-
it("marks a design repair's prompt.req, so a follower does not take it for a build (#6748)", () => {
|
|
20
|
-
const out = decodeChatWireMessage(section("r", [{ type: "prompt.req", seq: 0, origin: "design-repair", request: { messages: [1] } }]));
|
|
21
|
-
expect(out[0]).toMatchObject({ agentDispatched: false, designRepair: true });
|
|
22
|
-
const plain = decodeChatWireMessage(section("b", [{ type: "prompt.req", seq: 0, request: { messages: [1] } }]));
|
|
23
|
-
expect(plain[0]).not.toHaveProperty("designRepair");
|
|
24
|
-
});
|
|
25
|
-
it("marks the agent's own commit, so a follower tells a no-model save from a build (#5450)", () => {
|
|
26
|
-
const out = decodeChatWireMessage(section("m", [{ type: "prompt.req", seq: 1, agentDispatched: true, agentCommit: true, request: { messages: [] } }]));
|
|
27
|
-
expect(out[0]).toMatchObject({ agentDispatched: true, agentCommit: true });
|
|
28
|
-
expect(out[0]).not.toHaveProperty("model");
|
|
29
|
-
const build = decodeChatWireMessage(section("n", [{ type: "prompt.req", seq: 0, agentDispatched: true, request: { messages: [1], model: "m/x" } }]));
|
|
30
|
-
expect(build[0]).not.toHaveProperty("agentCommit");
|
|
31
|
-
});
|
|
32
|
-
it("reads an empty message list as the wake's zero", () => {
|
|
33
|
-
const out = decodeChatWireMessage(section("c", [{ type: "prompt.req", seq: 0, request: { messages: [] } }]));
|
|
34
|
-
expect(out[0]).toMatchObject({ agentDispatched: false, reqMessageCount: 0 });
|
|
35
|
-
});
|
|
36
|
-
it("lifts fsId out of the block.end fsRef", () => {
|
|
37
|
-
const out = decodeChatWireMessage(section("b", [{ type: "block.end", seq: 2, fsRef: { fsId: "fs9" }, touchedPaths: ["/App.jsx"] }]));
|
|
38
|
-
expect(out[0]).toMatchObject({ fsId: "fs9", touchedPaths: ["/App.jsx"] });
|
|
39
|
-
});
|
|
40
|
-
it("carries prompt.raw text and prompt.error verbatim", () => {
|
|
41
|
-
expect(decodeChatWireMessage(section("a", [{ type: "prompt.raw", seq: 1, text: "hi" }]))[0]).toMatchObject({ text: "hi" });
|
|
42
|
-
expect(decodeChatWireMessage(section("a", [{ type: "prompt.error", seq: 1, error: "boom" }]))[0]).toMatchObject({
|
|
43
|
-
error: "boom",
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
it("expands a multi-block event into one normalized event per block", () => {
|
|
47
|
-
const out = decodeChatWireMessage(section("a", [
|
|
48
|
-
{ type: "prompt.raw", seq: 1, text: "x" },
|
|
49
|
-
{ type: "prompt.block-end", seq: 2 },
|
|
50
|
-
]));
|
|
51
|
-
expect(out.map((e) => (e.kind === "block" ? e.type : e.kind))).toEqual(["prompt.raw", "prompt.block-end"]);
|
|
52
|
-
});
|
|
53
|
-
it("reads the served model off prompt.req's request", () => {
|
|
54
|
-
const out = decodeChatWireMessage(section("a", [{ type: "prompt.req", seq: 0, request: { messages: [1], model: "anthropic/opus" } }]));
|
|
55
|
-
expect(out[0]).toMatchObject({ type: "prompt.req", model: "anthropic/opus" });
|
|
56
|
-
});
|
|
57
|
-
it("carries prompt.model-resolved — the model a fallback actually dispatched with", () => {
|
|
58
|
-
const out = decodeChatWireMessage(section("a", [{ type: "prompt.model-resolved", seq: 3, model: "anthropic/sonnet" }]));
|
|
59
|
-
expect(out).toEqual([{ kind: "block", promptId: "a", seq: 3, type: "prompt.model-resolved", model: "anthropic/sonnet" }]);
|
|
60
|
-
});
|
|
61
|
-
it("leaves the model absent when the wire named none", () => {
|
|
62
|
-
const out = decodeChatWireMessage(section("a", [{ type: "prompt.req", seq: 0, request: { messages: [1] } }]));
|
|
63
|
-
expect(out[0]).not.toHaveProperty("model");
|
|
64
|
-
expect(decodeChatWireMessage(section("a", [{ type: "prompt.model-resolved", seq: 3 }]))[0]).not.toHaveProperty("model");
|
|
65
|
-
});
|
|
66
|
-
it("drops a message that is neither a section event, an app claim, nor an error", () => {
|
|
67
|
-
expect(decodeChatWireMessage({ type: "something-else" })).toEqual([]);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
describe("what the instant-build lane wrote (#6700)", () => {
|
|
71
|
-
it("drops the instant-build ready frame (evt-draft-ready) and any open-chat ack, like every frame it does not model", () => {
|
|
72
|
-
expect(decodeChatWireMessage({ type: "vibes.diy.evt-draft-ready", chatId: "chat-1", files: [] })).toEqual([]);
|
|
73
|
-
const ack = { type: "vibes.diy.res-open-chat", chatId: "chat-1", appSlug: "a", ownerHandle: "alice", mode: "codegen" };
|
|
74
|
-
expect(decodeChatWireMessage({ ...ack, firstTurnFire: "denied" })).toEqual([]);
|
|
75
|
-
});
|
|
76
|
-
it("marks the instant-build turn's own prompt.req, so a reader keeps it apart from the agent's builds", () => {
|
|
77
|
-
const out = decodeChatWireMessage({
|
|
78
|
-
type: "section",
|
|
79
|
-
promptId: "p-draft",
|
|
80
|
-
blocks: [{ type: "prompt.req", seq: 1, firstDraft: true, request: { messages: [1] } }],
|
|
81
|
-
});
|
|
82
|
-
expect(out[0]).toMatchObject({ kind: "block", promptId: "p-draft", firstDraft: true, agentDispatched: false });
|
|
83
|
-
});
|
|
84
|
-
it("still drops an unknown frame, the path every frame this decoder does not model takes", () => {
|
|
85
|
-
expect(decodeChatWireMessage({ type: "vibes.diy.evt-something-new", chatId: "chat-1" })).toEqual([]);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
describe("prompt.restyle", () => {
|
|
89
|
-
it("marks a restyle block, which is the only wire evidence that set_app_style ran", () => {
|
|
90
|
-
const out = decodeChatWireMessage({
|
|
91
|
-
type: "section",
|
|
92
|
-
promptId: "a",
|
|
93
|
-
blocks: [{ type: "prompt.restyle", seq: 3, style: { name: "dusk" }, description: "darker and warmer" }],
|
|
94
|
-
});
|
|
95
|
-
expect(out).toEqual([{ kind: "block", promptId: "a", seq: 3, type: "prompt.restyle", restyle: true }]);
|
|
96
|
-
});
|
|
97
|
-
it("says nothing about a block that is not a restyle", () => {
|
|
98
|
-
expect(isRestyleBlock({ type: "prompt.raw", text: "hi" })).toBe(false);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
describe("releaseIsLive", () => {
|
|
102
|
-
const items = [
|
|
103
|
-
{ fsId: "fs2", mode: "dev", published: false },
|
|
104
|
-
{ fsId: "fs1", mode: "production", published: true },
|
|
105
|
-
];
|
|
106
|
-
it("is true only for a release that is BOTH production and published", () => {
|
|
107
|
-
expect(releaseIsLive(items, "fs1")).toBe(true);
|
|
108
|
-
expect(releaseIsLive(items, "fs2")).toBe(false);
|
|
109
|
-
});
|
|
110
|
-
it("is false for an fsId the version list has never heard of", () => {
|
|
111
|
-
expect(releaseIsLive(items, "fs9")).toBe(false);
|
|
112
|
-
expect(releaseIsLive([], "fs1")).toBe(false);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
describe("promptWithShardRoll", () => {
|
|
116
|
-
const overloaded = mkResError("codegen shard at capacity (3 concurrent streams)", SHARD_OVERLOADED_CODE);
|
|
117
|
-
function roller(rollsAvailable) {
|
|
118
|
-
let index = 0;
|
|
119
|
-
return {
|
|
120
|
-
index: () => index,
|
|
121
|
-
rollCodegenShard() {
|
|
122
|
-
if (index >= rollsAvailable)
|
|
123
|
-
return false;
|
|
124
|
-
index += 1;
|
|
125
|
-
return true;
|
|
126
|
-
},
|
|
127
|
-
currentCodegenShard: () => (index === 0 ? "notify-user-u1" : `notify-user-u1~${index}`),
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
it("rolls to the next shard and retries, reporting the shard it landed on", async () => {
|
|
131
|
-
const r = roller(MAX_ROLL_INDEX);
|
|
132
|
-
const lines = [];
|
|
133
|
-
let reopens = 0;
|
|
134
|
-
let sends = 0;
|
|
135
|
-
let clock = 0;
|
|
136
|
-
const res = await promptWithShardRoll({
|
|
137
|
-
send: async () => {
|
|
138
|
-
sends += 1;
|
|
139
|
-
return sends <= 2 ? Result.Err(overloaded) : Result.Ok({ promptId: "p1" });
|
|
140
|
-
},
|
|
141
|
-
roller: r,
|
|
142
|
-
reopen: async () => {
|
|
143
|
-
reopens += 1;
|
|
144
|
-
clock += 100;
|
|
145
|
-
},
|
|
146
|
-
now: () => clock,
|
|
147
|
-
log: (line) => lines.push(line),
|
|
148
|
-
});
|
|
149
|
-
expect(res.value).toEqual({ promptId: "p1" });
|
|
150
|
-
expect(sends).toBe(3);
|
|
151
|
-
expect(reopens).toBe(2);
|
|
152
|
-
expect(r.index()).toBe(2);
|
|
153
|
-
expect(res.rolledMs).toBe(200);
|
|
154
|
-
expect(lines).toEqual([
|
|
155
|
-
" shard at capacity — rolled to notify-user-u1~1 (roll 1 of 8)",
|
|
156
|
-
" shard at capacity — rolled to notify-user-u1~2 (roll 2 of 8)",
|
|
157
|
-
]);
|
|
158
|
-
});
|
|
159
|
-
it("fails the rep exactly as it does today once the family is exhausted", async () => {
|
|
160
|
-
const lines = [];
|
|
161
|
-
await expect(promptWithShardRoll({
|
|
162
|
-
send: async () => Result.Err(overloaded),
|
|
163
|
-
roller: roller(0),
|
|
164
|
-
reopen: async () => undefined,
|
|
165
|
-
log: (line) => lines.push(line),
|
|
166
|
-
})).rejects.toThrow(/^prompt: codegen shard at capacity/);
|
|
167
|
-
expect(lines.some((l) => l.includes("no shard left to roll to"))).toBe(true);
|
|
168
|
-
});
|
|
169
|
-
it("never rolls on an unrelated refusal", async () => {
|
|
170
|
-
let rolls = 0;
|
|
171
|
-
await expect(promptWithShardRoll({
|
|
172
|
-
send: async () => Result.Err(mkResError("credits exhausted", "credits-exhausted")),
|
|
173
|
-
roller: {
|
|
174
|
-
rollCodegenShard: () => {
|
|
175
|
-
rolls += 1;
|
|
176
|
-
return true;
|
|
177
|
-
},
|
|
178
|
-
currentCodegenShard: () => "notify-user-u1",
|
|
179
|
-
},
|
|
180
|
-
reopen: async () => undefined,
|
|
181
|
-
})).rejects.toThrow(/credits exhausted/);
|
|
182
|
-
expect(rolls).toBe(0);
|
|
183
|
-
});
|
|
184
|
-
it("is bounded by the family size even if the roller never says no", async () => {
|
|
185
|
-
let sends = 0;
|
|
186
|
-
await expect(promptWithShardRoll({
|
|
187
|
-
send: async () => {
|
|
188
|
-
sends += 1;
|
|
189
|
-
return Result.Err(overloaded);
|
|
190
|
-
},
|
|
191
|
-
roller: { rollCodegenShard: () => true, currentCodegenShard: () => "notify-user-u1" },
|
|
192
|
-
reopen: async () => undefined,
|
|
193
|
-
})).rejects.toThrow();
|
|
194
|
-
expect(sends).toBe(MAX_ROLL_INDEX + 1);
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
describe("makeStreamGenerations", () => {
|
|
198
|
-
it("wakes a waiter on the bump a roll makes", async () => {
|
|
199
|
-
const g = makeStreamGenerations();
|
|
200
|
-
let woke = false;
|
|
201
|
-
const waiting = g.whenSuperseded(g.current()).then(() => {
|
|
202
|
-
woke = true;
|
|
203
|
-
});
|
|
204
|
-
await Promise.resolve();
|
|
205
|
-
expect(woke).toBe(false);
|
|
206
|
-
g.bump();
|
|
207
|
-
await waiting;
|
|
208
|
-
expect(g.current()).toBe(1);
|
|
209
|
-
});
|
|
210
|
-
it("resolves at once for a reader that is ALREADY on a superseded generation", async () => {
|
|
211
|
-
const g = makeStreamGenerations();
|
|
212
|
-
const stale = g.current();
|
|
213
|
-
g.bump();
|
|
214
|
-
await g.whenSuperseded(stale);
|
|
215
|
-
});
|
|
216
|
-
it("wakes every waiter once, and leaves later waiters to the NEXT bump", async () => {
|
|
217
|
-
const g = makeStreamGenerations();
|
|
218
|
-
const woken = [];
|
|
219
|
-
const first = g.whenSuperseded(0).then(() => void woken.push("a"));
|
|
220
|
-
const second = g.whenSuperseded(0).then(() => void woken.push("b"));
|
|
221
|
-
g.bump();
|
|
222
|
-
await Promise.all([first, second]);
|
|
223
|
-
expect(woken.sort()).toEqual(["a", "b"]);
|
|
224
|
-
let later = false;
|
|
225
|
-
void g.whenSuperseded(1).then(() => {
|
|
226
|
-
later = true;
|
|
227
|
-
});
|
|
228
|
-
await Promise.resolve();
|
|
229
|
-
expect(later).toBe(false);
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
describe("untilSuperseded", () => {
|
|
233
|
-
function neverEndingStream(values) {
|
|
234
|
-
return new ReadableStream({
|
|
235
|
-
start(controller) {
|
|
236
|
-
for (const v of values)
|
|
237
|
-
controller.enqueue(v);
|
|
238
|
-
},
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
it("returns when the chat is rolled, instead of blocking on the shard we left (#5893)", async () => {
|
|
242
|
-
const g = makeStreamGenerations();
|
|
243
|
-
const seen = [];
|
|
244
|
-
const done = (async () => {
|
|
245
|
-
for await (const v of untilSuperseded({
|
|
246
|
-
stream: neverEndingStream([1, 2]),
|
|
247
|
-
superseded: g.whenSuperseded(g.current()),
|
|
248
|
-
}))
|
|
249
|
-
seen.push(v);
|
|
250
|
-
})();
|
|
251
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
252
|
-
g.bump();
|
|
253
|
-
await done;
|
|
254
|
-
expect(seen).toEqual([1, 2]);
|
|
255
|
-
});
|
|
256
|
-
it("ends on the stream's own close, the measured silent death", async () => {
|
|
257
|
-
const g = makeStreamGenerations();
|
|
258
|
-
const stream = new ReadableStream({
|
|
259
|
-
start(controller) {
|
|
260
|
-
controller.enqueue(7);
|
|
261
|
-
controller.close();
|
|
262
|
-
},
|
|
263
|
-
});
|
|
264
|
-
const seen = [];
|
|
265
|
-
for await (const v of untilSuperseded({ stream, superseded: g.whenSuperseded(g.current()) }))
|
|
266
|
-
seen.push(v);
|
|
267
|
-
expect(seen).toEqual([7]);
|
|
268
|
-
});
|
|
269
|
-
it("propagates a read failure through onReadError rather than swallowing it", async () => {
|
|
270
|
-
const g = makeStreamGenerations();
|
|
271
|
-
const stream = new ReadableStream({
|
|
272
|
-
start(controller) {
|
|
273
|
-
controller.error(new Error("idle timeout"));
|
|
274
|
-
},
|
|
275
|
-
});
|
|
276
|
-
await expect((async () => {
|
|
277
|
-
for await (const _ of untilSuperseded({
|
|
278
|
-
stream,
|
|
279
|
-
superseded: g.whenSuperseded(g.current()),
|
|
280
|
-
onReadError: (e) => new Error(`annotated: ${e.message}`),
|
|
281
|
-
}))
|
|
282
|
-
;
|
|
283
|
-
})()).rejects.toThrow("annotated: idle timeout");
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
describe("reopenStillOwed", () => {
|
|
287
|
-
it("owes an open when nothing has re-opened since the roll began", () => {
|
|
288
|
-
expect(reopenStillOwed({ current: 3, generationAtRoll: 3 })).toBe(true);
|
|
289
|
-
});
|
|
290
|
-
it("owes nothing once the drain has already re-opened inside the roll's window (#5893)", () => {
|
|
291
|
-
expect(reopenStillOwed({ current: 4, generationAtRoll: 3 })).toBe(false);
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
describe("wireEventKey", () => {
|
|
295
|
-
it("keys a replayed block by promptId, seq and type — the measured dedupe (#5401)", () => {
|
|
296
|
-
const [ev] = decodeChatWireMessage({ promptId: "p", blocks: [{ type: "prompt.raw", seq: 2, text: "hi" }] });
|
|
297
|
-
expect(ev.kind).toBe("block");
|
|
298
|
-
if (ev.kind !== "block")
|
|
299
|
-
return;
|
|
300
|
-
expect(wireEventKey(ev)).toBe("p|2|prompt.raw");
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
describe("drainChatSession", () => {
|
|
304
|
-
function fakeSession(streams) {
|
|
305
|
-
let iteration = 0;
|
|
306
|
-
let generation = 0;
|
|
307
|
-
const reopens = [];
|
|
308
|
-
return {
|
|
309
|
-
reopens,
|
|
310
|
-
bumpGeneration: () => (generation += 1),
|
|
311
|
-
streamGeneration: () => generation,
|
|
312
|
-
async reopen() {
|
|
313
|
-
reopens.push(iteration);
|
|
314
|
-
},
|
|
315
|
-
events: {
|
|
316
|
-
async *[Symbol.asyncIterator]() {
|
|
317
|
-
const stream = streams[Math.min(iteration, streams.length - 1)];
|
|
318
|
-
iteration += 1;
|
|
319
|
-
for (const e of stream)
|
|
320
|
-
yield e;
|
|
321
|
-
},
|
|
322
|
-
},
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
const block = (promptId, seq, type) => ({ kind: "block", promptId, seq, type });
|
|
326
|
-
it("re-opens on the silent stream death and dedupes the replay (#5401 fact 3)", async () => {
|
|
327
|
-
const session = fakeSession([
|
|
328
|
-
[block("p", 0, "prompt.req")],
|
|
329
|
-
[block("p", 0, "prompt.req"), block("p", 1, "block.end")],
|
|
330
|
-
]);
|
|
331
|
-
const seen = [];
|
|
332
|
-
let stop = false;
|
|
333
|
-
await drainChatSession(session, {
|
|
334
|
-
onEvent: (event) => {
|
|
335
|
-
if (event.kind === "block")
|
|
336
|
-
seen.push(wireEventKey(event));
|
|
337
|
-
if (seen.length === 2)
|
|
338
|
-
stop = true;
|
|
339
|
-
},
|
|
340
|
-
shouldStop: () => stop,
|
|
341
|
-
});
|
|
342
|
-
expect(seen).toEqual(["p|0|prompt.req", "p|1|block.end"]);
|
|
343
|
-
expect(session.reopens).toEqual([1]);
|
|
344
|
-
});
|
|
345
|
-
it("follows a rolled shard instead of opening a third chat (#5893)", async () => {
|
|
346
|
-
const session = fakeSession([[block("p", 0, "prompt.req")], []]);
|
|
347
|
-
let stop = false;
|
|
348
|
-
await drainChatSession(session, {
|
|
349
|
-
onEvent: () => {
|
|
350
|
-
session.bumpGeneration();
|
|
351
|
-
stop = true;
|
|
352
|
-
},
|
|
353
|
-
shouldStop: () => stop,
|
|
354
|
-
});
|
|
355
|
-
expect(session.reopens).toEqual([]);
|
|
356
|
-
});
|
|
357
|
-
it("reports every event before the dedupe, so a replay still proves the stream is alive", async () => {
|
|
358
|
-
const session = fakeSession([[block("p", 0, "prompt.req")], [block("p", 0, "prompt.req")]]);
|
|
359
|
-
const observed = [];
|
|
360
|
-
let reopened = false;
|
|
361
|
-
await drainChatSession(session, {
|
|
362
|
-
onEvent: () => undefined,
|
|
363
|
-
onObserved: (event) => {
|
|
364
|
-
if (event.kind === "block")
|
|
365
|
-
observed.push(wireEventKey(event));
|
|
366
|
-
},
|
|
367
|
-
onReopen: () => {
|
|
368
|
-
reopened = true;
|
|
369
|
-
},
|
|
370
|
-
shouldStop: () => reopened,
|
|
371
|
-
});
|
|
372
|
-
expect(observed).toEqual(["p|0|prompt.req", "p|0|prompt.req"]);
|
|
373
|
-
});
|
|
374
|
-
});
|
|
375
|
-
describe("decode seams the CLI needs (#6037)", () => {
|
|
376
|
-
it("keeps the raw block beside the decoded one ONLY when asked", () => {
|
|
377
|
-
const msg = { type: "section", promptId: "a", blocks: [{ type: "prompt.raw", seq: 1, text: "hi" }] };
|
|
378
|
-
const plain = decodeChatWireMessage(msg);
|
|
379
|
-
expect(plain).toEqual([{ kind: "block", promptId: "a", seq: 1, type: "prompt.raw", text: "hi" }]);
|
|
380
|
-
const kept = decodeChatWireMessage(msg, { keepBlock: true });
|
|
381
|
-
expect(kept[0].block).toEqual({ type: "prompt.raw", seq: 1, text: "hi" });
|
|
382
|
-
});
|
|
383
|
-
it("carries the claim's ownerHandle and chatId, which name the app the CLI writes to disk", () => {
|
|
384
|
-
const out = decodeChatWireMessage({
|
|
385
|
-
type: "vibes.diy.evt-chat-app-claimed",
|
|
386
|
-
chatId: "chat-1",
|
|
387
|
-
ownerHandle: "alice",
|
|
388
|
-
appSlug: "todo-app",
|
|
389
|
-
});
|
|
390
|
-
expect(out).toEqual([{ kind: "app-claimed", appSlug: "todo-app", ownerHandle: "alice", chatId: "chat-1" }]);
|
|
391
|
-
});
|
|
392
|
-
});
|
|
393
|
-
describe("openChatSession — a client-fired turn restates the run's options", () => {
|
|
394
|
-
function fakeApi(o) {
|
|
395
|
-
return {
|
|
396
|
-
async openChat(req) {
|
|
397
|
-
o.opens.push(req);
|
|
398
|
-
return Result.Ok({
|
|
399
|
-
chatId: "chat-1",
|
|
400
|
-
appSlug: "todo-app",
|
|
401
|
-
ownerHandle: "alice",
|
|
402
|
-
firstTurnFired: o.fired ?? true,
|
|
403
|
-
agentFirstTurn: true,
|
|
404
|
-
sectionStream: new ReadableStream({ start: () => undefined }),
|
|
405
|
-
async prompt(req, opts) {
|
|
406
|
-
o.sent.push({ req, ...(opts === undefined ? {} : { opts }) });
|
|
407
|
-
return Result.Ok({ promptId: "p-1" });
|
|
408
|
-
},
|
|
409
|
-
async close() {
|
|
410
|
-
return undefined;
|
|
411
|
-
},
|
|
412
|
-
});
|
|
413
|
-
},
|
|
414
|
-
rollCodegenShard: () => false,
|
|
415
|
-
currentCodegenShard: () => "shard-0",
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
it("puts the turn's model in the REQUEST, where the server reads it", async () => {
|
|
419
|
-
const sent = [];
|
|
420
|
-
const session = await openChatSession({
|
|
421
|
-
api: fakeApi({ sent, opens: [] }),
|
|
422
|
-
openReq: { ownerHandle: "alice", mode: "codegen" },
|
|
423
|
-
});
|
|
424
|
-
await session.prompt("add a dark mode", { model: "anthropic/claude-opus-4", apiKey: "sk-byok-1", focusPath: "App.jsx" });
|
|
425
|
-
expect(sent).toHaveLength(1);
|
|
426
|
-
expect(sent[0].req.model).toBe("anthropic/claude-opus-4");
|
|
427
|
-
expect(sent[0].opts).toEqual({
|
|
428
|
-
model: "anthropic/claude-opus-4",
|
|
429
|
-
apiKey: "sk-byok-1",
|
|
430
|
-
focusPath: "App.jsx",
|
|
431
|
-
clientMessageId: expect.any(String),
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
it("resends the builder pin on every reopen, so a recovered build keeps it (#6395)", async () => {
|
|
435
|
-
const opens = [];
|
|
436
|
-
const session = await openChatSession({
|
|
437
|
-
api: fakeApi({ sent: [], opens }),
|
|
438
|
-
openReq: { ownerHandle: "alice", mode: "codegen", builderModel: "~anthropic/claude-sonnet-latest" },
|
|
439
|
-
});
|
|
440
|
-
await session.reopen();
|
|
441
|
-
expect(opens).toHaveLength(2);
|
|
442
|
-
expect(opens[1].builderModel).toBe("~anthropic/claude-sonnet-latest");
|
|
443
|
-
});
|
|
444
|
-
it("resends the eval-only instruction variant on every reopen (entry C)", async () => {
|
|
445
|
-
const opens = [];
|
|
446
|
-
const session = await openChatSession({
|
|
447
|
-
api: fakeApi({ sent: [], opens }),
|
|
448
|
-
openReq: { ownerHandle: "eval", mode: "codegen", instructionVariant: "direct-write" },
|
|
449
|
-
});
|
|
450
|
-
await session.reopen();
|
|
451
|
-
expect(opens).toHaveLength(2);
|
|
452
|
-
expect(opens[1].instructionVariant).toBe("direct-write");
|
|
453
|
-
});
|
|
454
|
-
it("appends a turn's pictures to the user content after the text, and passes no options for them", async () => {
|
|
455
|
-
const sent = [];
|
|
456
|
-
const session = await openChatSession({
|
|
457
|
-
api: fakeApi({ sent, opens: [] }),
|
|
458
|
-
openReq: { ownerHandle: "alice", mode: "codegen" },
|
|
459
|
-
});
|
|
460
|
-
const block = {
|
|
461
|
-
type: "vibes_file",
|
|
462
|
-
uploadId: "up-1",
|
|
463
|
-
name: "reference-2.png",
|
|
464
|
-
mimeType: "image/png",
|
|
465
|
-
kind: "image",
|
|
466
|
-
};
|
|
467
|
-
await session.prompt("Use this board layout", { fileBlocks: [block] });
|
|
468
|
-
expect(sent[0].req).toEqual({
|
|
469
|
-
messages: [{ role: "user", content: [{ type: "text", text: "Use this board layout" }, block] }],
|
|
470
|
-
});
|
|
471
|
-
expect(sent[0].opts).toEqual({ clientMessageId: expect.any(String) });
|
|
472
|
-
await session.prompt("again", { fileBlocks: [block], nonInteractive: true });
|
|
473
|
-
expect(sent[1].opts).toEqual({ nonInteractive: true, clientMessageId: expect.any(String) });
|
|
474
|
-
expect(sent[1].opts?.clientMessageId).not.toBe(sent[0].opts?.clientMessageId);
|
|
475
|
-
});
|
|
476
|
-
it("puts no instruction variant on a reopen when the open carried none", async () => {
|
|
477
|
-
const opens = [];
|
|
478
|
-
const session = await openChatSession({
|
|
479
|
-
api: fakeApi({ sent: [], opens }),
|
|
480
|
-
openReq: { ownerHandle: "alice", mode: "codegen" },
|
|
481
|
-
});
|
|
482
|
-
await session.reopen();
|
|
483
|
-
expect("instructionVariant" in opens[1]).toBe(false);
|
|
484
|
-
});
|
|
485
|
-
it("puts no builder pin on a reopen when the open carried none", async () => {
|
|
486
|
-
const opens = [];
|
|
487
|
-
const session = await openChatSession({
|
|
488
|
-
api: fakeApi({ sent: [], opens }),
|
|
489
|
-
openReq: { ownerHandle: "alice", mode: "codegen" },
|
|
490
|
-
});
|
|
491
|
-
await session.reopen();
|
|
492
|
-
expect("builderModel" in opens[1]).toBe(false);
|
|
493
|
-
});
|
|
494
|
-
it("leaves the request byte-identical when the caller named no model", async () => {
|
|
495
|
-
const sent = [];
|
|
496
|
-
const session = await openChatSession({
|
|
497
|
-
api: fakeApi({ sent, opens: [] }),
|
|
498
|
-
openReq: { ownerHandle: "alice", mode: "codegen" },
|
|
499
|
-
});
|
|
500
|
-
await session.prompt("add a dark mode");
|
|
501
|
-
expect(sent[0].req).toEqual({ messages: [{ role: "user", content: [{ type: "text", text: "add a dark mode" }] }] });
|
|
502
|
-
expect("model" in sent[0].req).toBe(false);
|
|
503
|
-
});
|
|
504
|
-
it("resends the turn options on every reopen, so a first turn recovered there fires with them (#6533 R4)", async () => {
|
|
505
|
-
const opens = [];
|
|
506
|
-
const session = await openChatSession({
|
|
507
|
-
api: fakeApi({ sent: [], opens }),
|
|
508
|
-
openReq: {
|
|
509
|
-
ownerHandle: "alice",
|
|
510
|
-
mode: "codegen",
|
|
511
|
-
prompt: "a habit tracker",
|
|
512
|
-
model: "m-agent",
|
|
513
|
-
apiKey: "sk-byok-1",
|
|
514
|
-
focusPath: "App.jsx",
|
|
515
|
-
nonInteractive: true,
|
|
516
|
-
},
|
|
517
|
-
});
|
|
518
|
-
await session.reopen();
|
|
519
|
-
expect(opens[1]).toMatchObject({
|
|
520
|
-
chatId: "chat-1",
|
|
521
|
-
model: "m-agent",
|
|
522
|
-
apiKey: "sk-byok-1",
|
|
523
|
-
focusPath: "App.jsx",
|
|
524
|
-
nonInteractive: true,
|
|
525
|
-
});
|
|
526
|
-
expect("prompt" in opens[1]).toBe(false);
|
|
527
|
-
});
|
|
528
|
-
it("forwards the caller's cancellation fence to the open, so a denied admission stops rolling", async () => {
|
|
529
|
-
const opens = [];
|
|
530
|
-
let rolls = 0;
|
|
531
|
-
const api = {
|
|
532
|
-
...fakeApi({ sent: [], opens, fired: false }),
|
|
533
|
-
rollCodegenShard: () => {
|
|
534
|
-
rolls += 1;
|
|
535
|
-
return true;
|
|
536
|
-
},
|
|
537
|
-
};
|
|
538
|
-
const caught = await openChatSession({
|
|
539
|
-
api: api,
|
|
540
|
-
openReq: { ownerHandle: "alice", mode: "codegen" },
|
|
541
|
-
shouldProceed: () => false,
|
|
542
|
-
}).catch((e) => e);
|
|
543
|
-
expect(caught).toBeInstanceOf(OpenChatSessionError);
|
|
544
|
-
expect(caught.stage).toBe("fenced");
|
|
545
|
-
expect(opens).toHaveLength(1);
|
|
546
|
-
expect(rolls).toBe(0);
|
|
547
|
-
});
|
|
548
|
-
});
|
|
549
|
-
describe("isPlatformIsolateClose (#6728)", () => {
|
|
550
|
-
it("names the platform's restart closes, through a wrapping cause", () => {
|
|
551
|
-
expect(isPlatformIsolateClose(new Error("This script has been upgraded. Please send a new request."))).toBe(true);
|
|
552
|
-
expect(isPlatformIsolateClose(new Error("Durable Object connection closed because the object was reset."))).toBe(true);
|
|
553
|
-
expect(isPlatformIsolateClose(mkResError("This script has been upgraded."))).toBe(true);
|
|
554
|
-
const wrapped = new Error("stream idle for 120s — wave cut", {
|
|
555
|
-
cause: new Error("This script has been upgraded"),
|
|
556
|
-
});
|
|
557
|
-
expect(isPlatformIsolateClose(wrapped)).toBe(true);
|
|
558
|
-
});
|
|
559
|
-
it("is not every failure", () => {
|
|
560
|
-
expect(isPlatformIsolateClose(new Error("credits exhausted"))).toBe(false);
|
|
561
|
-
expect(isPlatformIsolateClose(mkResError("codegen shard at capacity", SHARD_OVERLOADED_CODE))).toBe(false);
|
|
562
|
-
expect(isPlatformIsolateClose(undefined)).toBe(false);
|
|
563
|
-
});
|
|
564
|
-
});
|
|
565
|
-
describe("drainChatSession — a platform isolate close (#6728)", () => {
|
|
566
|
-
it("reopens and keeps reading instead of failing the run", async () => {
|
|
567
|
-
let iteration = 0;
|
|
568
|
-
let reopens = 0;
|
|
569
|
-
const events = [];
|
|
570
|
-
const block = { kind: "block", promptId: "p", seq: 0, type: "prompt.block-end" };
|
|
571
|
-
const session = {
|
|
572
|
-
events: {
|
|
573
|
-
async *[Symbol.asyncIterator]() {
|
|
574
|
-
iteration += 1;
|
|
575
|
-
if (iteration === 1)
|
|
576
|
-
throw new Error("This script has been upgraded. Please send a new request.");
|
|
577
|
-
yield block;
|
|
578
|
-
},
|
|
579
|
-
},
|
|
580
|
-
async reopen() {
|
|
581
|
-
reopens += 1;
|
|
582
|
-
},
|
|
583
|
-
};
|
|
584
|
-
await drainChatSession(session, {
|
|
585
|
-
onEvent: (e) => events.push(e),
|
|
586
|
-
shouldStop: () => iteration >= 2,
|
|
587
|
-
});
|
|
588
|
-
expect(reopens).toBe(1);
|
|
589
|
-
expect(events).toEqual([block]);
|
|
590
|
-
});
|
|
591
|
-
it("still fails on any other read error", async () => {
|
|
592
|
-
const session = {
|
|
593
|
-
events: {
|
|
594
|
-
async *[Symbol.asyncIterator]() {
|
|
595
|
-
throw new Error("decoder blew up");
|
|
596
|
-
},
|
|
597
|
-
},
|
|
598
|
-
async reopen() {
|
|
599
|
-
return undefined;
|
|
600
|
-
},
|
|
601
|
-
};
|
|
602
|
-
await expect(drainChatSession(session, { onEvent: () => undefined })).rejects.toThrow("decoder blew up");
|
|
603
|
-
});
|
|
604
|
-
});
|
|
605
|
-
describe("openChatSession — a follow-up sticks to the chat's shard (#6728)", () => {
|
|
606
|
-
const overloaded = mkResError("codegen shard at capacity (3 concurrent streams)", SHARD_OVERLOADED_CODE);
|
|
607
|
-
function stickyApi(o) {
|
|
608
|
-
let sends = 0;
|
|
609
|
-
return {
|
|
610
|
-
sends: () => sends,
|
|
611
|
-
api: {
|
|
612
|
-
async openChat(req) {
|
|
613
|
-
o.opens.push(req);
|
|
614
|
-
return Result.Ok({
|
|
615
|
-
chatId: "chat-1",
|
|
616
|
-
appSlug: "todo-app",
|
|
617
|
-
ownerHandle: "alice",
|
|
618
|
-
firstTurnFired: o.fired,
|
|
619
|
-
agentFirstTurn: o.fired,
|
|
620
|
-
sectionStream: new ReadableStream({ start: () => undefined }),
|
|
621
|
-
async prompt() {
|
|
622
|
-
sends += 1;
|
|
623
|
-
return sends <= o.refusals ? Result.Err(o.refusal ?? overloaded) : Result.Ok({ promptId: `p-${sends}` });
|
|
624
|
-
},
|
|
625
|
-
async close() {
|
|
626
|
-
return undefined;
|
|
627
|
-
},
|
|
628
|
-
});
|
|
629
|
-
},
|
|
630
|
-
rollCodegenShard: () => {
|
|
631
|
-
o.rolls.n += 1;
|
|
632
|
-
return true;
|
|
633
|
-
},
|
|
634
|
-
currentCodegenShard: () => `shard-${o.rolls.n}`,
|
|
635
|
-
},
|
|
636
|
-
};
|
|
637
|
-
}
|
|
638
|
-
it("retries a refused pick on the SAME shard and never rolls or reopens", async () => {
|
|
639
|
-
const opens = [];
|
|
640
|
-
const rolls = { n: 0 };
|
|
641
|
-
const waits = [];
|
|
642
|
-
const fake = stickyApi({ refusals: 2, fired: true, opens, rolls });
|
|
643
|
-
const session = await openChatSession({
|
|
644
|
-
api: fake.api,
|
|
645
|
-
openReq: { ownerHandle: "alice", mode: "codegen", prompt: "a habit tracker" },
|
|
646
|
-
wait: async (ms) => {
|
|
647
|
-
waits.push(ms);
|
|
648
|
-
},
|
|
649
|
-
});
|
|
650
|
-
const promptId = await session.prompt("make it blue");
|
|
651
|
-
expect(promptId).toBe("p-3");
|
|
652
|
-
expect(rolls.n, "a follow-up rolled to another shard and split the agent session").toBe(0);
|
|
653
|
-
expect(opens, "a follow-up reopened the chat somewhere else").toHaveLength(1);
|
|
654
|
-
expect(waits).toHaveLength(2);
|
|
655
|
-
});
|
|
656
|
-
it("re-sends a send the platform closed, after reopening on the chat's own shard (#6728)", async () => {
|
|
657
|
-
const opens = [];
|
|
658
|
-
const rolls = { n: 0 };
|
|
659
|
-
let sends = 0;
|
|
660
|
-
const ids = [];
|
|
661
|
-
const api = {
|
|
662
|
-
async openChat(req) {
|
|
663
|
-
opens.push(req);
|
|
664
|
-
return Result.Ok({
|
|
665
|
-
chatId: "chat-1",
|
|
666
|
-
appSlug: "todo-app",
|
|
667
|
-
ownerHandle: "alice",
|
|
668
|
-
firstTurnFired: true,
|
|
669
|
-
agentFirstTurn: true,
|
|
670
|
-
sectionStream: new ReadableStream({ start: () => undefined }),
|
|
671
|
-
async prompt(_req, opts) {
|
|
672
|
-
ids.push(opts?.clientMessageId);
|
|
673
|
-
sends += 1;
|
|
674
|
-
return sends === 1
|
|
675
|
-
? Result.Err(mkResError("This script has been upgraded. Please send a new request to connect to the new version."))
|
|
676
|
-
: Result.Ok({ promptId: "p-after" });
|
|
677
|
-
},
|
|
678
|
-
async close() {
|
|
679
|
-
return undefined;
|
|
680
|
-
},
|
|
681
|
-
});
|
|
682
|
-
},
|
|
683
|
-
rollCodegenShard: () => {
|
|
684
|
-
rolls.n += 1;
|
|
685
|
-
return true;
|
|
686
|
-
},
|
|
687
|
-
currentCodegenShard: () => "shard-0",
|
|
688
|
-
};
|
|
689
|
-
const session = await openChatSession({ api: api, openReq: { ownerHandle: "alice", mode: "codegen" } });
|
|
690
|
-
expect(await session.prompt("make it blue")).toBe("p-after");
|
|
691
|
-
expect(rolls.n).toBe(0);
|
|
692
|
-
expect(opens).toHaveLength(2);
|
|
693
|
-
expect(opens[1].chatId).toBe("chat-1");
|
|
694
|
-
expect(ids).toHaveLength(2);
|
|
695
|
-
expect(ids[0]).toEqual(expect.any(String));
|
|
696
|
-
expect(ids[1]).toBe(ids[0]);
|
|
697
|
-
});
|
|
698
|
-
it("rolls a follow-up whose refusal says no session lives on the chat's shard", async () => {
|
|
699
|
-
const opens = [];
|
|
700
|
-
const rolls = { n: 0 };
|
|
701
|
-
const waits = [];
|
|
702
|
-
const refusal = resErrorToError({
|
|
703
|
-
type: "vibes.diy.res-error",
|
|
704
|
-
error: { message: "codegen shard at capacity (3 concurrent streams)", code: SHARD_OVERLOADED_CODE, noLiveSession: true },
|
|
705
|
-
});
|
|
706
|
-
const fake = stickyApi({ refusals: 1, fired: true, opens, rolls, refusal });
|
|
707
|
-
const session = await openChatSession({
|
|
708
|
-
api: fake.api,
|
|
709
|
-
openReq: { ownerHandle: "alice", mode: "codegen", prompt: "a habit tracker" },
|
|
710
|
-
wait: async (ms) => {
|
|
711
|
-
waits.push(ms);
|
|
712
|
-
},
|
|
713
|
-
});
|
|
714
|
-
expect(await session.prompt("make it blue")).toBe("p-2");
|
|
715
|
-
expect(rolls.n).toBe(1);
|
|
716
|
-
expect(waits).toEqual([]);
|
|
717
|
-
expect(opens).toHaveLength(2);
|
|
718
|
-
});
|
|
719
|
-
it("still rolls the client-fired FIRST turn of an existing chat, then sticks", async () => {
|
|
720
|
-
const opens = [];
|
|
721
|
-
const rolls = { n: 0 };
|
|
722
|
-
const fake = stickyApi({ refusals: 1, fired: false, opens, rolls });
|
|
723
|
-
const session = await openChatSession({
|
|
724
|
-
api: fake.api,
|
|
725
|
-
openReq: { ownerHandle: "alice", appSlug: "todo-app", mode: "codegen" },
|
|
726
|
-
wait: async () => undefined,
|
|
727
|
-
});
|
|
728
|
-
await session.prompt("first turn");
|
|
729
|
-
expect(rolls.n).toBe(1);
|
|
730
|
-
await session.prompt("follow-up");
|
|
731
|
-
expect(rolls.n).toBe(1);
|
|
732
|
-
});
|
|
733
|
-
});
|
|
734
|
-
//# sourceMappingURL=chat-session.test.js.map
|