Files
next-tjwater-agent/tests/routes/task-execution-ownership.test.ts
T
jiang 6336157ff4
Generic Container CI/CD / test-build-publish (push) Successful in 1m6s
Agent CI/CD / build-test-publish-and-deploy (push) Successful in 1m7s
feat: upgrade investigation and presentation runtime
2026-10-30 17:30:19 +08:00

77 lines
2.6 KiB
TypeScript

import { afterEach, expect, it } from "bun:test";
import express from "express";
import type { Server } from "node:http";
import { config } from "../../src/config.js";
import { buildChatRouter } from "../../src/routes/chat.js";
import { buildTaskExecutionPrompt } from "../../src/routes/chatSessionRoutes.js";
const http = globalThis.fetch;
let server: Server | undefined;
it("tells background investigations to read the current Server Skill explicitly", () => {
const prompt = buildTaskExecutionPrompt("burst_report");
expect(prompt).toContain("mcp_tjwater_get_task_context");
expect(prompt).toContain('section="skill"');
expect(prompt).toContain("skill.version");
expect(prompt).toContain("不沿用记忆中的旧版本");
});
afterEach(async () => {
globalThis.fetch = http;
if (server) {
server.closeAllConnections();
await new Promise<void>((resolve) => server!.close(() => resolve()));
server = undefined;
}
});
it("rejects a durable task execution addressed to another Agent instance", async () => {
const projectId = "10000000-0000-4000-8000-000000000001";
globalThis.fetch = (async (_input, init) => {
const headers = new Headers(init?.headers);
return Response.json({
user_id: "worker",
project_id: headers.get("x-project-id"),
network: "supply",
});
}) as typeof fetch;
const app = express();
app.use(express.json());
app.use("/api/v1", buildChatRouter({
frontendActionCoordinator: {} as never,
learningOrchestrator: {} as never,
memoryStore: {} as never,
runtime: {} as never,
sessionBridge: {} as never,
sessionMetadataStore: {} as never,
sessionTranscriptStore: {} as never,
sessionUiStateStore: {} as never,
}));
server = app.listen(0, "127.0.0.1");
await new Promise<void>((resolve) => server!.once("listening", resolve));
const address = server.address();
if (!address || typeof address === "string") throw new Error("missing server address");
const response = await http(`http://127.0.0.1:${address.port}/api/v1/task-executions`, {
method: "POST",
headers: {
Authorization: "Bearer worker",
"Content-Type": "application/json",
"X-Project-Id": projectId,
},
body: JSON.stringify({
task_id: "50000000-0000-4000-8000-000000000001",
run_id: "55000000-0000-4000-8000-000000000001",
execution_request_id: "60000000-0000-4000-8000-000000000001",
agent_instance_id: `${config.AGENT_INSTANCE_ID}-foreign`,
}),
});
expect(response.status).toBe(409);
expect(await response.json()).toEqual({
message: "task execution targeted a different Agent instance",
});
});