42 lines
2.4 KiB
TypeScript
42 lines
2.4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import type { ConversationRuntime } from "../src/acp/types.js";
|
|
import type { PlatformAdapter } from "../src/core/adapter.js";
|
|
import { Gateway } from "../src/core/gateway.js";
|
|
import type { IncomingMessage } from "../src/core/types.js";
|
|
|
|
class FakeRuntime implements ConversationRuntime {
|
|
prompts = 0; cancelled = 0; resets = 0; release?: () => void;
|
|
async prompt() { this.prompts++; await new Promise<void>((resolve) => { this.release = resolve; }); return { text: "done", botId: "test-bot", agentId: "kimi" }; }
|
|
async cancel() { this.cancelled++; this.release?.(); return true; }
|
|
async reset() { this.resets++; }
|
|
status() { return { bot: "test-bot", agent: "kimi", workspace: "/tmp", running: Boolean(this.release) }; }
|
|
stats() { return { activeWorkers: 0, inFlight: 0, crashes: 0, persistedBindings: 0 }; }
|
|
async shutdown() {}
|
|
}
|
|
|
|
const policy = { allowedUsers: [] as string[], allowedChats: [] as string[], requireMentionInGroup: false };
|
|
const adapter: PlatformAdapter = { name: "test", async handleWebhook() { return {}; }, async sendMessage() {} };
|
|
const message = (text: string): IncomingMessage => ({ platform: "qq", chatId: "chat", userId: "user", text });
|
|
|
|
test("cancel bypasses the chat lock and new resets", async () => {
|
|
const runtime = new FakeRuntime(); const gateway = new Gateway(policy, runtime);
|
|
const turn = gateway.receive(message("work"), adapter, { synchronous: true });
|
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
const cancelled = await gateway.receive(message("/cancel"), adapter, { synchronous: true });
|
|
assert.equal(cancelled.reply, "Cancellation requested.");
|
|
await turn;
|
|
const reset = await gateway.receive(message("/new"), adapter, { synchronous: true });
|
|
assert.match(reset.reply || "", /new native ACP session/);
|
|
assert.equal(runtime.resets, 1);
|
|
});
|
|
|
|
test("fixed Bot status and retired role commands never reach ACP", async () => {
|
|
const runtime = new FakeRuntime(); const gateway = new Gateway(policy, runtime);
|
|
for (const command of ["/roles", "/role ops", "/agents", "/agent ops"]) {
|
|
assert.match((await gateway.receive(message(command), adapter, { synchronous: true })).reply || "", /removed in Config v3/);
|
|
}
|
|
assert.match((await gateway.receive(message("/status"), adapter, { synchronous: true })).reply || "", /bot=test-bot/);
|
|
assert.equal(runtime.prompts, 0);
|
|
});
|