refactor(channels): centralize match metadata

This commit is contained in:
Peter Steinberger
2026-01-21 18:21:19 +00:00
parent b52ab96e2c
commit 88d76d4be5
11 changed files with 73 additions and 38 deletions

View File

@@ -6,6 +6,8 @@ import {
resolveChannelEntryMatch,
resolveChannelEntryMatchWithFallback,
resolveNestedAllowlistDecision,
applyChannelMatchMeta,
resolveChannelMatchConfig,
} from "./channel-config.js";
describe("buildChannelKeyCandidates", () => {
@@ -90,6 +92,33 @@ describe("resolveChannelEntryMatchWithFallback", () => {
});
});
describe("applyChannelMatchMeta", () => {
it("copies match metadata onto resolved configs", () => {
const resolved = applyChannelMatchMeta(
{ allowed: true },
{ matchKey: "general", matchSource: "direct" },
);
expect(resolved.matchKey).toBe("general");
expect(resolved.matchSource).toBe("direct");
});
});
describe("resolveChannelMatchConfig", () => {
it("returns null when no entry is matched", () => {
const resolved = resolveChannelMatchConfig({ matchKey: "x" }, () => ({ allowed: true }));
expect(resolved).toBeNull();
});
it("resolves entry and applies match metadata", () => {
const resolved = resolveChannelMatchConfig(
{ entry: { allow: true }, matchKey: "*", matchSource: "wildcard" },
() => ({ allowed: true }),
);
expect(resolved?.matchKey).toBe("*");
expect(resolved?.matchSource).toBe("wildcard");
});
});
describe("resolveNestedAllowlistDecision", () => {
it("allows when outer allowlist is disabled", () => {
expect(