test: preserve Windows PATH casing and exercise real fetch aborts
This commit is contained in:
@@ -67,3 +67,38 @@ test("aborting an in-flight stream reports aborted without leaking a rejection",
|
||||
assert.equal((await stream.result()).stopReason, "aborted");
|
||||
assert.deepEqual(rejections, []);
|
||||
});
|
||||
|
||||
test("real fetch cancellation after a response chunk leaves the process usable", { timeout: 10_000 }, async (t) => {
|
||||
const { createServer } = await import("node:http");
|
||||
const { once } = await import("node:events");
|
||||
const { encodeString, encodeVarintField, frameConnectStream } = await import("../src/wire.ts");
|
||||
clearCachedUserJwt(); t.after(clearCachedUserJwt);
|
||||
let chats = 0;
|
||||
const server = createServer((req, res) => {
|
||||
if (req.url.endsWith("/GetUserJwt")) {
|
||||
res.end(encodeString(1, "eyJtest.jwt")); return;
|
||||
}
|
||||
chats++;
|
||||
res.writeHead(200, { "Content-Type": "application/connect+proto" });
|
||||
res.write(frameConnectStream(encodeString(3, "started"), false));
|
||||
if (chats > 1) {
|
||||
res.write(frameConnectStream(encodeVarintField(5, 0), false));
|
||||
res.end(Buffer.from([2, 0, 0, 0, 2, 123, 125]));
|
||||
}
|
||||
});
|
||||
t.after(() => { server.closeAllConnections(); server.close(); });
|
||||
server.listen(0, "127.0.0.1"); await once(server, "listening");
|
||||
const ac = new AbortController();
|
||||
const options = { apiKey: "synthetic-test-key", env: { DEVIN_API_SERVER_URL: `http://127.0.0.1:${server.address().port}` } };
|
||||
const stream = streamDevin(model, normalizeContext({ messages: [user("hello")] }), { ...options, signal: ac.signal });
|
||||
let sawText = false;
|
||||
for await (const event of stream) {
|
||||
if (event.type === "text_delta") { sawText = true; ac.abort(); }
|
||||
}
|
||||
assert.equal(sawText, true);
|
||||
assert.equal((await stream.result()).stopReason, "aborted");
|
||||
const next = streamDevin(model, normalizeContext({ messages: [user("again")] }), options);
|
||||
for await (const event of next) assert.notEqual(event.type, "error");
|
||||
assert.equal((await next.result()).stopReason, "stop");
|
||||
assert.equal(chats, 2);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user