test(cli): dedupe repeated gateway node and slack pairing setup

This commit is contained in:
Peter Steinberger
2026-02-18 13:22:35 +00:00
parent 2d0ce40ed6
commit 3af9f704c8
2 changed files with 53 additions and 76 deletions

View File

@@ -23,6 +23,29 @@ function formatRuntimeLogCallArg(value: unknown): string {
}
describe("cli program (nodes basics)", () => {
function mockGatewayWithIosNodeListAnd(method: "node.describe" | "node.invoke", result: unknown) {
callGateway.mockImplementation(async (...args: unknown[]) => {
const opts = (args[0] ?? {}) as { method?: string };
if (opts.method === "node.list") {
return {
ts: Date.now(),
nodes: [
{
nodeId: "ios-node",
displayName: "iOS Node",
remoteIp: "192.168.0.88",
connected: true,
},
],
};
}
if (opts.method === method) {
return result;
}
return { ok: true };
});
}
beforeEach(() => {
vi.clearAllMocks();
runTui.mockResolvedValue(undefined);
@@ -190,32 +213,13 @@ describe("cli program (nodes basics)", () => {
});
it("runs nodes describe and calls node.describe", async () => {
callGateway.mockImplementation(async (...args: unknown[]) => {
const opts = (args[0] ?? {}) as { method?: string };
if (opts.method === "node.list") {
return {
ts: Date.now(),
nodes: [
{
nodeId: "ios-node",
displayName: "iOS Node",
remoteIp: "192.168.0.88",
connected: true,
},
],
};
}
if (opts.method === "node.describe") {
return {
ts: Date.now(),
nodeId: "ios-node",
displayName: "iOS Node",
caps: ["canvas", "camera"],
commands: ["canvas.eval", "canvas.snapshot", "camera.snap"],
connected: true,
};
}
return { ok: true };
mockGatewayWithIosNodeListAnd("node.describe", {
ts: Date.now(),
nodeId: "ios-node",
displayName: "iOS Node",
caps: ["canvas", "camera"],
commands: ["canvas.eval", "canvas.snapshot", "camera.snap"],
connected: true,
});
const program = buildProgram();
@@ -257,30 +261,11 @@ describe("cli program (nodes basics)", () => {
});
it("runs nodes invoke and calls node.invoke", async () => {
callGateway.mockImplementation(async (...args: unknown[]) => {
const opts = (args[0] ?? {}) as { method?: string };
if (opts.method === "node.list") {
return {
ts: Date.now(),
nodes: [
{
nodeId: "ios-node",
displayName: "iOS Node",
remoteIp: "192.168.0.88",
connected: true,
},
],
};
}
if (opts.method === "node.invoke") {
return {
ok: true,
nodeId: "ios-node",
command: "canvas.eval",
payload: { result: "ok" },
};
}
return { ok: true };
mockGatewayWithIosNodeListAnd("node.invoke", {
ok: true,
nodeId: "ios-node",
command: "canvas.eval",
payload: { result: "ok" },
});
const program = buildProgram();

View File

@@ -84,6 +84,22 @@ describe("monitorSlackProvider tool results", () => {
});
}
function setPairingOnlyDirectMessages() {
const currentConfig = slackTestState.config as {
channels?: { slack?: Record<string, unknown> };
};
slackTestState.config = {
...currentConfig,
channels: {
...currentConfig.channels,
slack: {
...currentConfig.channels?.slack,
dm: { enabled: true, policy: "pairing", allowFrom: [] },
},
},
};
}
it("skips tool summaries with responsePrefix", async () => {
replyMock.mockResolvedValue({ text: "final reply" });
@@ -483,19 +499,7 @@ describe("monitorSlackProvider tool results", () => {
});
it("replies with pairing code when dmPolicy is pairing and no allowFrom is set", async () => {
const currentConfig = slackTestState.config as {
channels?: { slack?: Record<string, unknown> };
};
slackTestState.config = {
...currentConfig,
channels: {
...currentConfig.channels,
slack: {
...currentConfig.channels?.slack,
dm: { enabled: true, policy: "pairing", allowFrom: [] },
},
},
};
setPairingOnlyDirectMessages();
await runSlackMessageOnce(monitorSlackProvider, {
event: makeSlackMessageEvent(),
@@ -509,19 +513,7 @@ describe("monitorSlackProvider tool results", () => {
});
it("does not resend pairing code when a request is already pending", async () => {
const currentConfig = slackTestState.config as {
channels?: { slack?: Record<string, unknown> };
};
slackTestState.config = {
...currentConfig,
channels: {
...currentConfig.channels,
slack: {
...currentConfig.channels?.slack,
dm: { enabled: true, policy: "pairing", allowFrom: [] },
},
},
};
setPairingOnlyDirectMessages();
upsertPairingRequestMock
.mockResolvedValueOnce({ code: "PAIRCODE", created: true })
.mockResolvedValueOnce({ code: "PAIRCODE", created: false });