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.
51 lines
2.9 KiB
TypeScript
51 lines
2.9 KiB
TypeScript
import { expect, it, mock } from "bun:test";
|
|
import { ResponseInputTracker, type ResponseInput } from "../../src/chat/response-inputs.js";
|
|
|
|
const input = (id: number): ResponseInput => ({ id: `msg_${String(id).padStart(32, "0")}`, text: `Input ${id}`, delivery: "steer", status: "pending" });
|
|
|
|
it("waits for admission at completion, deduplicates concurrent retries and closes only after native consumption", async () => {
|
|
let release = () => {};
|
|
const gate = new Promise<void>((resolve) => { release = resolve; });
|
|
const runtime = { listPendingUserInputs: async () => [], enqueueUserInput: mock(async () => { await gate; }) };
|
|
const changed = mock((_input: ResponseInput) => {});
|
|
const tracker = new ResponseInputTracker(runtime, "owned", changed);
|
|
tracker.markReady();
|
|
const first = tracker.submit(input(1));
|
|
const retry = tracker.submit(input(1));
|
|
const closing = tracker.canClose();
|
|
release();
|
|
expect((await first).status).toBe("pending");
|
|
expect((await retry).status).toBe("pending");
|
|
expect(runtime.enqueueUserInput).toHaveBeenCalledTimes(1);
|
|
expect(await closing).toBe(false);
|
|
tracker.observe("session.inbox.delivery.changed", { inboxID: input(1).id, delivery: "queue" });
|
|
expect(changed.mock.calls.at(-1)?.[0]).toMatchObject({ delivery: "queue" });
|
|
tracker.observe("session.inbox.delivered", { inboxID: input(1).id });
|
|
expect(changed.mock.calls.at(-1)?.[0]).toMatchObject({ status: "delivered" });
|
|
expect(await tracker.canClose()).toBe(true);
|
|
await expect(tracker.submit(input(2))).rejects.toMatchObject({ status: 409 });
|
|
});
|
|
|
|
it("rejects a failed admission and permits a later retry without acknowledging nonexistent input", async () => {
|
|
let attempts = 0;
|
|
const runtime = { listPendingUserInputs: async () => [], enqueueUserInput: async () => { if (attempts++ === 0) throw new Error("fixture failure"); } };
|
|
const tracker = new ResponseInputTracker(runtime, "owned", () => {});
|
|
tracker.markReady();
|
|
const first = tracker.submit(input(1));
|
|
const duplicate = tracker.submit(input(1));
|
|
const results = await Promise.allSettled([first, duplicate]);
|
|
expect(results.map((result) => result.status)).toEqual(["rejected", "rejected"]);
|
|
for (const result of results) if (result.status === "rejected") expect(result.reason.message).toBe("fixture failure");
|
|
await expect(tracker.submit(input(1))).resolves.toMatchObject({ status: "pending" });
|
|
});
|
|
|
|
it("bounds pending input and refuses admission after an explicit stop", async () => {
|
|
const runtime = { listPendingUserInputs: async () => [], enqueueUserInput: async () => {} };
|
|
const tracker = new ResponseInputTracker(runtime, "owned", () => {});
|
|
tracker.markReady();
|
|
for (let id = 0; id < 20; id++) await tracker.submit(input(id));
|
|
await expect(tracker.submit(input(20))).rejects.toMatchObject({ status: 429 });
|
|
tracker.close();
|
|
await expect(tracker.submit(input(21))).rejects.toMatchObject({ status: 409 });
|
|
});
|