Files
next-tjwater-agent/tests/opencode/queryMcp.test.ts
T
jiang 6a49d2209e feat(agent): unify MCP tools and adopt Responses delivery
Move project and host queries into native MCP with host-owned OAuth/context,
while retaining memory, skills, actions and publication plugins. Add nearby-model
queries and explicit chat/task/learning model defaults.

Adopt Responses HTTP/SSE and native steer/queue inbox delivery, preserving scoped
session ownership, pending input edits and investigation communication.

Disable local-provider discovery: Server /health allowed native vLLM to probe
/v1/models on port 8000. A native before/after regression prevents recurrence.

Validation: 170 focused Bun tests; service/plugin typechecks; native discovery,
provider-discovery and input-inbox smoke checks; no paid model inference.
2026-10-19 18:46:58 +08:00

28 lines
1.7 KiB
TypeScript

import { afterEach, expect, it } from "bun:test";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { queryMcpConnection } from "../../.opencode/query-mcp.js";
import { writeQueryMcpConnection } from "../../src/runtime/query-mcp-connection.js";
const previous = { path: process.env.TJWATER_AGENT_MCP_CONNECTION_PATH, token: process.env.AGENT_INTERNAL_TOKEN };
const roots: string[] = [];
afterEach(() => {
for (const [key, value] of [["TJWATER_AGENT_MCP_CONNECTION_PATH", previous.path], ["AGENT_INTERNAL_TOKEN", previous.token]]) {
if (value === undefined) delete process.env[key!]; else process.env[key!] = value;
}
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true });
});
it("configures a pinned native MCP connection using the host-owned endpoint and private channel credential", () => {
const root = mkdtempSync(join(tmpdir(), "query-connection-")); roots.push(root);
process.env.AGENT_INTERNAL_TOKEN = "MCP_TEST_ONLY";
writeQueryMcpConnection(join(root, "sessions"), "http://127.0.0.1:12345/mcp");
expect(queryMcpConnection()).toMatchObject({ type: "remote", protocol: "2026-07-28", oauth: false, codemode: false, headers: { "x-agent-internal-token": "MCP_TEST_ONLY" } });
writeQueryMcpConnection(join(root, "sessions"), "http://127.0.0.1:12345/mcp", 3_665_000);
expect(queryMcpConnection()?.timeout?.execution).toBe(3_665_000);
writeQueryMcpConnection(join(root, "sessions"), "http://127.0.0.1:12345/mcp", Infinity);
expect(() => queryMcpConnection()).toThrow("timeout");
writeQueryMcpConnection(join(root, "sessions"), "https://foreign.test/mcp");
expect(() => queryMcpConnection()).toThrow("loopback");
});