

























@@ -0,0 +1,110 @@
1+import { beforeEach, describe, expect, it, vi } from "vitest";
2+import type { LegacyConfigRule } from "./legacy.shared.js";
3+4+const { collectChannelLegacyConfigRulesMock, listPluginDoctorLegacyConfigRulesMock } = vi.hoisted(
5+() => ({
6+collectChannelLegacyConfigRulesMock: vi.fn((): LegacyConfigRule[] => []),
7+listPluginDoctorLegacyConfigRulesMock: vi.fn((): LegacyConfigRule[] => []),
8+}),
9+);
10+11+vi.mock("../channels/plugins/legacy-config.js", () => ({
12+collectChannelLegacyConfigRules: collectChannelLegacyConfigRulesMock,
13+}));
14+15+vi.mock("../plugins/doctor-contract-registry.js", () => ({
16+listPluginDoctorLegacyConfigRules: listPluginDoctorLegacyConfigRulesMock,
17+}));
18+19+import { validateConfigObjectRaw } from "./validation.js";
20+21+describe("config validation legacy rule loading", () => {
22+beforeEach(() => {
23+collectChannelLegacyConfigRulesMock.mockReset();
24+collectChannelLegacyConfigRulesMock.mockReturnValue([]);
25+listPluginDoctorLegacyConfigRulesMock.mockReset();
26+listPluginDoctorLegacyConfigRulesMock.mockReturnValue([]);
27+});
28+29+it("does not load channel or plugin doctor legacy rules for valid raw config", () => {
30+collectChannelLegacyConfigRulesMock.mockReturnValue([
31+{
32+path: ["channels", "discord", "legacy"],
33+message: "legacy discord key",
34+},
35+]);
36+37+const result = validateConfigObjectRaw({
38+channels: {
39+discord: {},
40+},
41+});
42+43+expect(result.ok).toBe(true);
44+expect(collectChannelLegacyConfigRulesMock).not.toHaveBeenCalled();
45+expect(listPluginDoctorLegacyConfigRulesMock).not.toHaveBeenCalled();
46+});
47+48+it("does not load plugin doctor legacy rules for invalid raw config", () => {
49+listPluginDoctorLegacyConfigRulesMock.mockReturnValue([
50+{
51+path: ["plugins", "entries", "demo", "legacy"],
52+message: "legacy demo key",
53+},
54+]);
55+56+const result = validateConfigObjectRaw({
57+plugins: {
58+entries: {
59+demo: {
60+legacy: true,
61+},
62+},
63+},
64+});
65+66+expect(result.ok).toBe(false);
67+expect(collectChannelLegacyConfigRulesMock).not.toHaveBeenCalled();
68+expect(listPluginDoctorLegacyConfigRulesMock).not.toHaveBeenCalled();
69+});
70+71+it("skips enabled-only and empty-config plugin entries", () => {
72+const result = validateConfigObjectRaw({
73+plugins: {
74+entries: {
75+anthropic: {
76+enabled: true,
77+},
78+discord: {
79+config: {},
80+enabled: true,
81+},
82+},
83+},
84+});
85+86+expect(result.ok).toBe(true);
87+expect(collectChannelLegacyConfigRulesMock).not.toHaveBeenCalled();
88+expect(listPluginDoctorLegacyConfigRulesMock).not.toHaveBeenCalled();
89+});
90+91+it("does not use touched paths to load doctor rules during raw validation", () => {
92+const result = validateConfigObjectRaw(
93+{
94+plugins: {
95+entries: {
96+demo: {},
97+other: {},
98+},
99+},
100+},
101+{
102+touchedPaths: [["plugins", "entries", "demo", "enabled"]],
103+},
104+);
105+106+expect(result.ok).toBe(true);
107+expect(collectChannelLegacyConfigRulesMock).not.toHaveBeenCalled();
108+expect(listPluginDoctorLegacyConfigRulesMock).not.toHaveBeenCalled();
109+});
110+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。