|
| 1 | +// Scenario-owned proof for the source-internal preview App SDK package boundary. |
| 2 | +import { describe, it } from "vitest"; |
| 3 | +import { createPackedSdkConsumer } from "./package.e2e.test-support.js"; |
| 4 | + |
| 5 | +describe("external preview App SDK boundary", () => { |
| 6 | + it("packs an external consumer that uses only the exported entrypoint and a custom transport", async () => { |
| 7 | + const consumer = await createPackedSdkConsumer(); |
| 8 | + try { |
| 9 | + await consumer.run(` |
| 10 | + import { OpenClaw, normalizeGatewayEvent } from "@openclaw/sdk"; |
| 11 | +
|
| 12 | + const event = normalizeGatewayEvent({ |
| 13 | + event: "agent", |
| 14 | + payload: { runId: "packed-run", stream: "lifecycle", data: { phase: "start" } } |
| 15 | + }); |
| 16 | + if (event.type !== "run.started") throw new Error("exported normalizer failed"); |
| 17 | +
|
| 18 | + const calls = []; |
| 19 | + let closed = false; |
| 20 | + const transport = { |
| 21 | + async request(method, params, options) { |
| 22 | + calls.push({ method, params, options }); |
| 23 | + if (method === "agents.list") return { agents: [{ id: "external" }] }; |
| 24 | + if (method === "agent.wait") { |
| 25 | + return { status: "ok", runId: "packed-run", sessionKey: "agent:main:external" }; |
| 26 | + } |
| 27 | + if (method === "artifacts.list") { |
| 28 | + return { artifacts: [{ id: "artifact-packed", type: "file", title: "packed.txt" }] }; |
| 29 | + } |
| 30 | + if (method === "environments.list") { |
| 31 | + return { environments: [{ id: "gateway", type: "local", status: "available" }] }; |
| 32 | + } |
| 33 | + throw new Error(\`unexpected method: \${method}\`); |
| 34 | + }, |
| 35 | + async *events() {}, |
| 36 | + async close() { |
| 37 | + closed = true; |
| 38 | + }, |
| 39 | + }; |
| 40 | +
|
| 41 | + const client = new OpenClaw({ transport }); |
| 42 | + const agents = await client.agents.list(); |
| 43 | + const run = await client.runs.wait("packed-run", { timeoutMs: 25 }); |
| 44 | + const artifacts = await client.artifacts.list({ sessionKey: "agent:main:external" }); |
| 45 | + const environments = await client.environments.list(); |
| 46 | + await client.close(); |
| 47 | +
|
| 48 | + if (agents.agents[0]?.id !== "external") throw new Error("agent operation failed"); |
| 49 | + if (run.status !== "completed") throw new Error("run result normalization failed"); |
| 50 | + if (artifacts.artifacts[0]?.id !== "artifact-packed") { |
| 51 | + throw new Error("artifact operation failed"); |
| 52 | + } |
| 53 | + if (environments.environments[0]?.id !== "gateway") { |
| 54 | + throw new Error("environment operation failed"); |
| 55 | + } |
| 56 | + if (!closed) throw new Error("custom transport was not closed"); |
| 57 | + const expectedMethods = ["agents.list", "agent.wait", "artifacts.list", "environments.list"]; |
| 58 | + if (JSON.stringify(calls.map((call) => call.method)) !== JSON.stringify(expectedMethods)) { |
| 59 | + throw new Error(\`unexpected calls: \${JSON.stringify(calls)}\`); |
| 60 | + } |
| 61 | + if (calls[1]?.options?.timeoutMs !== null || calls[1]?.params?.timeoutMs !== 25) { |
| 62 | + throw new Error(\`run wait ownership changed: \${JSON.stringify(calls[1])}\`); |
| 63 | + } |
| 64 | + `); |
| 65 | + } finally { |
| 66 | + await consumer.cleanup(); |
| 67 | + } |
| 68 | + }, 240_000); |
| 69 | +}); |
0 commit comments