Files
wehub-resource-sync e0e362d700
SDK Tests / SDK CI (push) Blocked by required conditions
SDK Tests / changes (push) Successful in 2m29s
Real E2E Tests / changes (push) Successful in 2m29s
SDK Tests / Python SDK Tests (sandbox) (push) Waiting to run
SDK Tests / CLI Quality (push) Waiting to run
SDK Tests / CLI Tests (push) Waiting to run
SDK Tests / Python SDK Quality (code-interpreter) (push) Waiting to run
SDK Tests / Python SDK Quality (sandbox) (push) Waiting to run
SDK Tests / Python SDK Tests (code-interpreter) (push) Waiting to run
SDK Tests / JavaScript SDK Quality And Tests (code-interpreter) (push) Waiting to run
SDK Tests / JavaScript SDK Quality And Tests (sandbox) (push) Waiting to run
SDK Tests / Kotlin SDK Quality And Tests (sandbox) (push) Waiting to run
SDK Tests / Kotlin SDK Quality And Tests (code-interpreter) (push) Waiting to run
SDK Tests / C# SDK Quality And Tests (code-interpreter) (push) Waiting to run
SDK Tests / C# SDK Quality And Tests (sandbox) (push) Waiting to run
SDK Tests / Go SDK Quality And Tests (push) Waiting to run
Deploy Docs Pages / build (push) Has been cancelled
Deploy Docs Pages / deploy (push) Has been cancelled
Real E2E Tests / JavaScript E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Python E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Java E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / C# E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Go E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Real E2E CI (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:39:33 +08:00

67 lines
2.1 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import { DefaultAdapterFactory } from "../dist/index.js";
test("DefaultAdapterFactory merges sandbox and endpoint headers for code requests", async () => {
const recorded = [];
const fetchImpl = async (input, init = {}) => {
const request = input instanceof Request ? input : new Request(input, init);
const url = new URL(request.url);
const headers = Object.fromEntries(request.headers.entries());
recorded.push({
url: request.url,
method: request.method,
headers,
});
if (url.pathname === "/code/context") {
return new Response(JSON.stringify({ id: "ctx-1", language: "python" }), {
status: 200,
headers: { "content-type": "application/json" },
});
}
return new Response(
[
JSON.stringify({ type: "stdout", text: "hello", timestamp: 1 }),
JSON.stringify({ type: "execution_complete", execution_time: 2, timestamp: 2 }),
].join("\n"),
{
status: 200,
headers: { "content-type": "text/event-stream" },
}
);
};
const sandbox = {
connectionConfig: {
headers: { "x-global": "global" },
fetch: fetchImpl,
sseFetch: fetchImpl,
},
};
const factory = new DefaultAdapterFactory();
const codes = factory.createCodes({
sandbox,
execdBaseUrl: "http://sandbox.internal:3456",
endpointHeaders: { "x-endpoint": "endpoint" },
});
const context = await codes.createContext("python");
assert.equal(context.id, "ctx-1");
const execution = await codes.run("print('hello')");
assert.equal(execution.logs.stdout[0]?.text, "hello");
assert.equal(recorded.length, 2);
assert.equal(recorded[0].url, "http://sandbox.internal:3456/code/context");
assert.equal(recorded[0].headers["x-global"], "global");
assert.equal(recorded[0].headers["x-endpoint"], "endpoint");
assert.equal(recorded[1].url, "http://sandbox.internal:3456/code");
assert.equal(recorded[1].headers["x-global"], "global");
assert.equal(recorded[1].headers["x-endpoint"], "endpoint");
assert.equal(recorded[1].headers.accept, "text/event-stream");
});