test: use synthetic ui channel fixtures

This commit is contained in:
Peter Steinberger
2026-04-20 23:54:59 +01:00
parent 73f36b0c80
commit 871aa9d0b9
3 changed files with 38 additions and 38 deletions

View File

@@ -37,18 +37,18 @@ describe("qmd scope", () => {
it("supports rawKeyPrefix matches for agent-prefixed keys", () => {
const scope: ResolvedQmdConfig["scope"] = {
default: "allow",
rules: [{ action: "deny", match: { rawKeyPrefix: "agent:main:discord:" } }],
rules: [{ action: "deny", match: { rawKeyPrefix: "agent:main:guildchat:" } }],
};
expect(isQmdScopeAllowed(scope, "agent:main:discord:channel:c123")).toBe(false);
expect(isQmdScopeAllowed(scope, "agent:main:slack:channel:c123")).toBe(true);
expect(isQmdScopeAllowed(scope, "agent:main:guildchat:channel:c123")).toBe(false);
expect(isQmdScopeAllowed(scope, "agent:main:workspace:channel:c123")).toBe(true);
});
it("keeps legacy agent-prefixed keyPrefix rules working", () => {
const scope: ResolvedQmdConfig["scope"] = {
default: "allow",
rules: [{ action: "deny", match: { keyPrefix: "agent:main:discord:" } }],
rules: [{ action: "deny", match: { keyPrefix: "agent:main:guildchat:" } }],
};
expect(isQmdScopeAllowed(scope, "agent:main:discord:channel:c123")).toBe(false);
expect(isQmdScopeAllowed(scope, "agent:main:slack:channel:c123")).toBe(true);
expect(isQmdScopeAllowed(scope, "agent:main:guildchat:channel:c123")).toBe(false);
expect(isQmdScopeAllowed(scope, "agent:main:workspace:channel:c123")).toBe(true);
});
});

View File

@@ -92,7 +92,7 @@ describe("agents tools panel (browser)", () => {
description: "Send and manage messages in this channel",
rawDescription: "Send and manage messages in this channel",
source: "channel",
channelId: "discord",
channelId: "guildchat",
},
],
},
@@ -110,7 +110,7 @@ describe("agents tools panel (browser)", () => {
expect(text).toContain("optional");
expect(text).toContain("Available Right Now");
expect(text).toContain("Message Actions");
expect(text).toContain("Channel: discord");
expect(text).toContain("Channel: guildchat");
});
it("shows fallback warning when runtime catalog fails", async () => {

View File

@@ -45,76 +45,76 @@ describe("channel display selectors", () => {
it("returns the channel summary configured flag when present", () => {
const props = createProps({
ts: Date.now(),
channelOrder: ["discord"],
channelLabels: { discord: "Discord" },
channels: { discord: { configured: false } },
channelOrder: ["guildchat"],
channelLabels: { guildchat: "Guild Chat" },
channels: { guildchat: { configured: false } },
channelAccounts: {
discord: [{ accountId: "discord-main", configured: true }],
guildchat: [{ accountId: "guild-main", configured: true }],
},
channelDefaultAccountId: { discord: "discord-main" },
channelDefaultAccountId: { guildchat: "guild-main" },
});
expect(resolveChannelConfigured("discord", props)).toBe(false);
expect(resolveChannelDisplayState("discord", props).configured).toBe(false);
expect(resolveChannelConfigured("guildchat", props)).toBe(false);
expect(resolveChannelDisplayState("guildchat", props).configured).toBe(false);
});
it("falls back to the default account when the channel summary omits configured", () => {
const props = createProps({
ts: Date.now(),
channelOrder: ["discord"],
channelLabels: { discord: "Discord" },
channels: { discord: { running: true } },
channelOrder: ["guildchat"],
channelLabels: { guildchat: "Guild Chat" },
channels: { guildchat: { running: true } },
channelAccounts: {
discord: [
guildchat: [
{ accountId: "default", configured: false },
{ accountId: "discord-main", configured: true },
{ accountId: "guild-main", configured: true },
],
},
channelDefaultAccountId: { discord: "discord-main" },
channelDefaultAccountId: { guildchat: "guild-main" },
});
const displayState = resolveChannelDisplayState("discord", props);
const displayState = resolveChannelDisplayState("guildchat", props);
expect(resolveChannelConfigured("discord", props)).toBe(true);
expect(displayState.defaultAccount?.accountId).toBe("discord-main");
expect(channelEnabled("discord", props)).toBe(true);
expect(resolveChannelConfigured("guildchat", props)).toBe(true);
expect(displayState.defaultAccount?.accountId).toBe("guild-main");
expect(channelEnabled("guildchat", props)).toBe(true);
});
it("falls back to the first account when no default account id is available", () => {
const props = createProps({
ts: Date.now(),
channelOrder: ["slack"],
channelLabels: { slack: "Slack" },
channels: { slack: { running: true } },
channelOrder: ["workspace"],
channelLabels: { workspace: "Workspace" },
channels: { workspace: { running: true } },
channelAccounts: {
slack: [{ accountId: "workspace-a", configured: true }],
workspace: [{ accountId: "workspace-a", configured: true }],
},
channelDefaultAccountId: {},
});
const displayState = resolveChannelDisplayState("slack", props);
const displayState = resolveChannelDisplayState("workspace", props);
expect(resolveChannelConfigured("slack", props)).toBe(true);
expect(resolveChannelConfigured("workspace", props)).toBe(true);
expect(displayState.defaultAccount?.accountId).toBe("workspace-a");
});
it("keeps disabled channels hidden when neither summary nor accounts are active", () => {
const props = createProps({
ts: Date.now(),
channelOrder: ["signal"],
channelLabels: { signal: "Signal" },
channels: { signal: {} },
channelOrder: ["quietchat"],
channelLabels: { quietchat: "Quiet Chat" },
channels: { quietchat: {} },
channelAccounts: {
signal: [{ accountId: "default", configured: false, running: false, connected: false }],
quietchat: [{ accountId: "default", configured: false, running: false, connected: false }],
},
channelDefaultAccountId: { signal: "default" },
channelDefaultAccountId: { quietchat: "default" },
});
const displayState = resolveChannelDisplayState("signal", props);
const displayState = resolveChannelDisplayState("quietchat", props);
expect(displayState.configured).toBe(false);
expect(displayState.running).toBeNull();
expect(displayState.connected).toBeNull();
expect(channelEnabled("signal", props)).toBe(false);
expect(channelEnabled("quietchat", props)).toBe(false);
});
});