test: narrow doctor shared channel mocks

This commit is contained in:
Peter Steinberger
2026-04-11 05:58:47 +01:00
parent c836fd22d0
commit cb01b0072d
3 changed files with 67 additions and 3 deletions

View File

@@ -1,8 +1,38 @@
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";
import { applyChannelDoctorCompatibilityMigrations } from "./channel-legacy-config-migrate.js";
const applyPluginDoctorCompatibilityMigrations = vi.hoisted(() => vi.fn());
vi.mock("../../../plugins/doctor-contract-registry.js", () => ({
applyPluginDoctorCompatibilityMigrations: (...args: unknown[]) =>
applyPluginDoctorCompatibilityMigrations(...args),
}));
describe("bundled channel legacy config migrations", () => {
it("normalizes legacy private-network aliases exposed through bundled contract surfaces", () => {
applyPluginDoctorCompatibilityMigrations.mockReturnValueOnce({
config: {
channels: {
mattermost: {
network: {
dangerouslyAllowPrivateNetwork: true,
},
accounts: {
work: {
network: {
dangerouslyAllowPrivateNetwork: false,
},
},
},
},
},
},
changes: [
"Moved channels.mattermost.allowPrivateNetwork → channels.mattermost.network.dangerouslyAllowPrivateNetwork (true).",
"Moved channels.mattermost.accounts.work.allowPrivateNetwork → channels.mattermost.accounts.work.network.dangerouslyAllowPrivateNetwork (false).",
],
});
const result = applyChannelDoctorCompatibilityMigrations({
channels: {
mattermost: {
@@ -16,6 +46,10 @@ describe("bundled channel legacy config migrations", () => {
},
});
expect(applyPluginDoctorCompatibilityMigrations).toHaveBeenCalledWith(expect.any(Object), {
pluginIds: ["mattermost"],
});
const nextChannels = (result.next.channels ?? {}) as {
mattermost?: Record<string, unknown>;
};

View File

@@ -1,6 +1,23 @@
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";
import { collectEmptyAllowlistPolicyWarningsForAccount } from "./empty-allowlist-policy.js";
vi.mock("../channel-capabilities.js", () => ({
getDoctorChannelCapabilities: (channelName?: string) => ({
dmAllowFromMode: "topOnly",
groupModel: channelName === "discord" ? "route" : "sender",
groupAllowFromFallbackToAllowFrom: channelName !== "imessage",
warnOnEmptyGroupSenderAllowlist: channelName !== "discord",
}),
}));
vi.mock("./channel-doctor.js", () => ({
shouldSkipChannelDoctorDefaultEmptyGroupAllowlistWarning: ({
channelName,
}: {
channelName?: string;
}) => channelName === "zalouser",
}));
describe("doctor empty allowlist policy warnings", () => {
it("warns when dm allowlist mode has no allowFrom entries", () => {
const warnings = collectEmptyAllowlistPolicyWarningsForAccount({

View File

@@ -1,6 +1,19 @@
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";
import { scanEmptyAllowlistPolicyWarnings } from "./empty-allowlist-scan.js";
vi.mock("../channel-capabilities.js", () => ({
getDoctorChannelCapabilities: (channelName?: string) => ({
dmAllowFromMode: "topOnly",
groupModel: "sender",
groupAllowFromFallbackToAllowFrom: channelName !== "imessage",
warnOnEmptyGroupSenderAllowlist: channelName !== "discord",
}),
}));
vi.mock("./channel-doctor.js", () => ({
shouldSkipChannelDoctorDefaultEmptyGroupAllowlistWarning: () => false,
}));
describe("doctor empty allowlist policy scan", () => {
it("scans top-level and account-scoped channel warnings", () => {
const warnings = scanEmptyAllowlistPolicyWarnings(