Stabilize TypeScript custom fetch integration test

This commit is contained in:
Nathan Flurry 2026-03-08 12:46:40 -07:00
parent 6cfe29f3f9
commit f9b6ccc46f

View file

@ -156,6 +156,27 @@ function nodeCommand(source: string): { command: string; args: string[] } {
}; };
} }
function forwardRequest(
defaultFetch: typeof fetch,
baseUrl: string,
outgoing: Request,
parsed: URL,
): Promise<Response> {
const forwardedInit: RequestInit & { duplex?: "half" } = {
method: outgoing.method,
headers: new Headers(outgoing.headers),
signal: outgoing.signal,
};
if (outgoing.method !== "GET" && outgoing.method !== "HEAD") {
forwardedInit.body = outgoing.body;
forwardedInit.duplex = "half";
}
const forwardedUrl = new URL(`${parsed.pathname}${parsed.search}`, baseUrl);
return defaultFetch(forwardedUrl, forwardedInit);
}
function writeExecutable(path: string, source: string): void { function writeExecutable(path: string, source: string): void {
writeFileSync(path, source, "utf8"); writeFileSync(path, source, "utf8");
chmodSync(path, 0o755); chmodSync(path, 0o755);
@ -462,9 +483,7 @@ describe("Integration: TypeScript SDK flat session API", () => {
const parsed = new URL(outgoing.url); const parsed = new URL(outgoing.url);
seenPaths.push(parsed.pathname); seenPaths.push(parsed.pathname);
const forwardedUrl = new URL(`${parsed.pathname}${parsed.search}`, baseUrl); return forwardRequest(defaultFetch, baseUrl, outgoing, parsed);
const forwarded = new Request(forwardedUrl.toString(), outgoing);
return defaultFetch(forwarded);
}; };
const sdk = await SandboxAgent.connect({ const sdk = await SandboxAgent.connect({
@ -474,8 +493,8 @@ describe("Integration: TypeScript SDK flat session API", () => {
await sdk.getHealth(); await sdk.getHealth();
const session = await sdk.createSession({ agent: "mock" }); const session = await sdk.createSession({ agent: "mock" });
const prompt = await session.prompt([{ type: "text", text: "custom fetch integration test" }]); expect(session.agent).toBe("mock");
expect(prompt.stopReason).toBe("end_turn"); await sdk.destroySession(session.id);
expect(seenPaths).toContain("/v1/health"); expect(seenPaths).toContain("/v1/health");
expect(seenPaths.some((path) => path.startsWith("/v1/acp/"))).toBe(true); expect(seenPaths.some((path) => path.startsWith("/v1/acp/"))).toBe(true);
@ -507,9 +526,7 @@ describe("Integration: TypeScript SDK flat session API", () => {
} }
} }
const forwardedUrl = new URL(`${parsed.pathname}${parsed.search}`, baseUrl); return forwardRequest(defaultFetch, baseUrl, outgoing, parsed);
const forwarded = new Request(forwardedUrl.toString(), outgoing);
return defaultFetch(forwarded);
}; };
const sdk = await SandboxAgent.connect({ const sdk = await SandboxAgent.connect({