|
@@ -7,6 +7,7 @@ test("a reachable control plane distinguishes an unavailable execution service",
|
|
|
const server = Bun.serve({
|
|
const server = Bun.serve({
|
|
|
port: 0,
|
|
port: 0,
|
|
|
fetch(request) {
|
|
fetch(request) {
|
|
|
|
|
+ if (new URL(request.url).pathname.endsWith("/auth/me")) return new Response("missing", { status: 404 })
|
|
|
if (new URL(request.url).pathname === "/api/v1/agents") return Response.json({ agents: [] })
|
|
if (new URL(request.url).pathname === "/api/v1/agents") return Response.json({ agents: [] })
|
|
|
return Response.json(
|
|
return Response.json(
|
|
|
{ detail: { code: "LOCAL_SERVICE_UNAVAILABLE", message: "Local Agent Service is required" } },
|
|
{ detail: { code: "LOCAL_SERVICE_UNAVAILABLE", message: "Local Agent Service is required" } },
|
|
@@ -32,6 +33,7 @@ test("desktop transport isolates windows and only checks resources without invok
|
|
|
const server = Bun.serve({
|
|
const server = Bun.serve({
|
|
|
port: 0,
|
|
port: 0,
|
|
|
async fetch(request) {
|
|
async fetch(request) {
|
|
|
|
|
+ if (new URL(request.url).pathname.endsWith("/auth/me")) return new Response("missing", { status: 404 })
|
|
|
requests.push({
|
|
requests.push({
|
|
|
path: new URL(request.url).pathname,
|
|
path: new URL(request.url).pathname,
|
|
|
method: request.method,
|
|
method: request.method,
|
|
@@ -70,6 +72,7 @@ test("failed replacement clears the old account and does not expose server error
|
|
|
const server = Bun.serve({
|
|
const server = Bun.serve({
|
|
|
port: 0,
|
|
port: 0,
|
|
|
fetch(request) {
|
|
fetch(request) {
|
|
|
|
|
+ if (new URL(request.url).pathname.endsWith("/auth/me")) return new Response("missing", { status: 404 })
|
|
|
if (request.headers.get("Authorization") === "Bearer old") return Response.json({ agents: [] })
|
|
if (request.headers.get("Authorization") === "Bearer old") return Response.json({ agents: [] })
|
|
|
return new Response("secret credentials", { status: 401 })
|
|
return new Response("secret credentials", { status: 401 })
|
|
|
},
|
|
},
|
|
@@ -113,6 +116,7 @@ test("chat executes the selected agent, preserves thread identity and rejects du
|
|
|
const server = Bun.serve({
|
|
const server = Bun.serve({
|
|
|
port: 0,
|
|
port: 0,
|
|
|
async fetch(request) {
|
|
async fetch(request) {
|
|
|
|
|
+ if (new URL(request.url).pathname.endsWith("/auth/me")) return new Response("missing", { status: 404 })
|
|
|
if (new URL(request.url).pathname.endsWith("/agents")) return Response.json({ agents: [] })
|
|
if (new URL(request.url).pathname.endsWith("/agents")) return Response.json({ agents: [] })
|
|
|
received.push({ path: new URL(request.url).pathname, method: request.method, body: await request.json() })
|
|
received.push({ path: new URL(request.url).pathname, method: request.method, body: await request.json() })
|
|
|
started.resolve()
|
|
started.resolve()
|
|
@@ -212,6 +216,7 @@ test("thread history and AgentPack operations use the platform's typed routes",
|
|
|
port: 0,
|
|
port: 0,
|
|
|
hostname: "127.0.0.1",
|
|
hostname: "127.0.0.1",
|
|
|
async fetch(request) {
|
|
async fetch(request) {
|
|
|
|
|
+ if (new URL(request.url).pathname.endsWith("/auth/me")) return new Response("missing", { status: 404 })
|
|
|
const path = new URL(request.url).pathname
|
|
const path = new URL(request.url).pathname
|
|
|
requests.push({
|
|
requests.push({
|
|
|
path,
|
|
path,
|
|
@@ -253,6 +258,7 @@ test("resolves only the selected agent’s existing work directory", async () =>
|
|
|
port: 0,
|
|
port: 0,
|
|
|
hostname: "127.0.0.1",
|
|
hostname: "127.0.0.1",
|
|
|
fetch(request) {
|
|
fetch(request) {
|
|
|
|
|
+ if (new URL(request.url).pathname.endsWith("/auth/me")) return new Response("missing", { status: 404 })
|
|
|
const route = new URL(request.url).pathname
|
|
const route = new URL(request.url).pathname
|
|
|
if (route === "/api/v1/agents") return Response.json({ agents: [] })
|
|
if (route === "/api/v1/agents") return Response.json({ agents: [] })
|
|
|
if (route === "/api/v1/agents/a1") return Response.json({ id: "a1", work_dir: tmpdir(), run_dir: "/" })
|
|
if (route === "/api/v1/agents/a1") return Response.json({ id: "a1", work_dir: tmpdir(), run_dir: "/" })
|
|
@@ -295,6 +301,7 @@ test("task controls, input files and downloads use the authenticated platform ro
|
|
|
port: 0,
|
|
port: 0,
|
|
|
hostname: "127.0.0.1",
|
|
hostname: "127.0.0.1",
|
|
|
async fetch(request) {
|
|
async fetch(request) {
|
|
|
|
|
+ if (new URL(request.url).pathname.endsWith("/auth/me")) return new Response("missing", { status: 404 })
|
|
|
const path = new URL(request.url).pathname
|
|
const path = new URL(request.url).pathname
|
|
|
expect(request.headers.get("Authorization")).toBe("Bearer test-only")
|
|
expect(request.headers.get("Authorization")).toBe("Bearer test-only")
|
|
|
requests.push({ path, method: request.method, body: await request.text() })
|
|
requests.push({ path, method: request.method, body: await request.text() })
|
|
@@ -356,6 +363,7 @@ test("detaching closes only the subscription and keeps the backend job alive", a
|
|
|
port: 0,
|
|
port: 0,
|
|
|
hostname: "127.0.0.1",
|
|
hostname: "127.0.0.1",
|
|
|
async fetch(request) {
|
|
async fetch(request) {
|
|
|
|
|
+ if (new URL(request.url).pathname.endsWith("/auth/me")) return new Response("missing", { status: 404 })
|
|
|
requests.push(new URL(request.url).pathname)
|
|
requests.push(new URL(request.url).pathname)
|
|
|
if (request.method === "GET") return Response.json({ agents: [] })
|
|
if (request.method === "GET") return Response.json({ agents: [] })
|
|
|
const body = await request.json()
|
|
const body = await request.json()
|
|
@@ -393,6 +401,7 @@ test("separate conversations execute concurrently and detach only their own stre
|
|
|
const server = Bun.serve({
|
|
const server = Bun.serve({
|
|
|
port: 0,
|
|
port: 0,
|
|
|
fetch(request) {
|
|
fetch(request) {
|
|
|
|
|
+ if (new URL(request.url).pathname.endsWith("/auth/me")) return new Response("missing", { status: 404 })
|
|
|
if (new URL(request.url).pathname.endsWith("/agents")) return Response.json({ agents: [] })
|
|
if (new URL(request.url).pathname.endsWith("/agents")) return Response.json({ agents: [] })
|
|
|
return new Response(
|
|
return new Response(
|
|
|
new ReadableStream({
|
|
new ReadableStream({
|
|
@@ -441,6 +450,7 @@ test("upload progress reports consumed bytes without changing file contents", as
|
|
|
const server = Bun.serve({
|
|
const server = Bun.serve({
|
|
|
port: 0,
|
|
port: 0,
|
|
|
async fetch(request) {
|
|
async fetch(request) {
|
|
|
|
|
+ if (new URL(request.url).pathname.endsWith("/auth/me")) return new Response("missing", { status: 404 })
|
|
|
if (new URL(request.url).pathname.endsWith("/agents")) return Response.json({ agents: [] })
|
|
if (new URL(request.url).pathname.endsWith("/agents")) return Response.json({ agents: [] })
|
|
|
expect(new Uint8Array(await request.arrayBuffer())).toEqual(bytes)
|
|
expect(new Uint8Array(await request.arrayBuffer())).toEqual(bytes)
|
|
|
return Response.json({ file_id: "uploaded", name: "data.bin" })
|
|
return Response.json({ file_id: "uploaded", name: "data.bin" })
|
|
@@ -466,6 +476,7 @@ test("submission identity travels in the stream header and receipt lookup never
|
|
|
const server = Bun.serve({
|
|
const server = Bun.serve({
|
|
|
port: 0,
|
|
port: 0,
|
|
|
fetch(request) {
|
|
fetch(request) {
|
|
|
|
|
+ if (new URL(request.url).pathname.endsWith("/auth/me")) return new Response("missing", { status: 404 })
|
|
|
const path = new URL(request.url).pathname
|
|
const path = new URL(request.url).pathname
|
|
|
requests.push({ path, method: request.method, key: request.headers.get("Idempotency-Key") })
|
|
requests.push({ path, method: request.method, key: request.headers.get("Idempotency-Key") })
|
|
|
if (path === "/api/v1/agents") return Response.json({ agents: [] })
|
|
if (path === "/api/v1/agents") return Response.json({ agents: [] })
|
|
@@ -515,3 +526,37 @@ test("history paging carries the active-task option and rejects invalid offsets"
|
|
|
await expect(connection.request(1, { action: "history", agentID: "a", offset: -1 })).rejects.toThrow("页码无效")
|
|
await expect(connection.request(1, { action: "history", agentID: "a", offset: -1 })).rejects.toThrow("页码无效")
|
|
|
connection.disconnect(1)
|
|
connection.disconnect(1)
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+test("authenticated identity keeps equal-permission key rotations together and other users isolated", async () => {
|
|
|
|
|
+ const server = Bun.serve({
|
|
|
|
|
+ port: 0,
|
|
|
|
|
+ hostname: "127.0.0.1",
|
|
|
|
|
+ fetch(request) {
|
|
|
|
|
+ if (new URL(request.url).pathname.endsWith("/agents")) return Response.json({ agents: [] })
|
|
|
|
|
+ const key = request.headers.get("authorization")
|
|
|
|
|
+ if (key?.includes("legacy")) return new Response("missing", { status: 404 })
|
|
|
|
|
+ return Response.json({
|
|
|
|
|
+ tenant_id: "t",
|
|
|
|
|
+ user_id: key?.includes("other") ? "other" : "same",
|
|
|
|
|
+ role: "researcher",
|
|
|
|
|
+ permissions: key?.includes("limited") ? ["agents:read"] : ["agents:execute", "agents:read"],
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ })
|
|
|
|
|
+ const api = createPaasConnections()
|
|
|
|
|
+ try {
|
|
|
|
|
+ const connect = (apiKey: string) => api.connect(1, { url: server.url.origin, apiKey })
|
|
|
|
|
+ const before = await connect("old")
|
|
|
|
|
+ const after = await connect("new")
|
|
|
|
|
+ expect(after.scope).toBe(before.scope)
|
|
|
|
|
+ expect(after.legacyScope).not.toBe(before.legacyScope)
|
|
|
|
|
+ expect((await connect("other")).scope).not.toBe(before.scope)
|
|
|
|
|
+ expect((await connect("limited")).scope).not.toBe(before.scope)
|
|
|
|
|
+ const legacy = await connect("legacy")
|
|
|
|
|
+ expect(legacy.legacyScope).toBeUndefined()
|
|
|
|
|
+ expect(legacy.scope).toMatch(/^[a-f0-9]{64}$/)
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ api.disconnect(1)
|
|
|
|
|
+ await server.stop(true)
|
|
|
|
|
+ }
|
|
|
|
|
+})
|