

























@@ -24,6 +24,42 @@ afterEach(() => {
2424cleanupTrackedTempDirs(tempDirs);
2525});
262627+function requireRecord(value: unknown): Record<string, unknown> {
28+expect(value).toBeTruthy();
29+expect(typeof value).toBe("object");
30+expect(Array.isArray(value)).toBe(false);
31+return value as Record<string, unknown>;
32+}
33+34+function requirePlugin(
35+plugins: readonly Record<string, unknown>[],
36+id: string,
37+): Record<string, unknown> {
38+const plugin = plugins.find((entry) => entry.id === id);
39+expect(plugin).toBeTruthy();
40+return requireRecord(plugin);
41+}
42+43+function requireRecordArray(value: unknown): Record<string, unknown>[] {
44+expect(Array.isArray(value)).toBe(true);
45+return value as Record<string, unknown>[];
46+}
47+48+function requireNamedEntry(
49+entries: readonly Record<string, unknown>[],
50+name: string,
51+): Record<string, unknown> {
52+const entry = entries.find((candidate) => candidate.name === name);
53+expect(entry).toBeTruthy();
54+return requireRecord(entry);
55+}
56+57+function expectFields(actual: Record<string, unknown>, expected: Record<string, unknown>): void {
58+for (const [key, value] of Object.entries(expected)) {
59+expect(actual[key]).toEqual(value);
60+}
61+}
62+2763describe("buildPluginRegistrySnapshotReport", () => {
2864it("keeps recovered managed npm plugins visible when the persisted registry is stale", () => {
2965const tempRoot = makeTempDir();
@@ -64,19 +100,17 @@ describe("buildPluginRegistrySnapshotReport", () => {
64100});
6510166102expect(report.registrySource).toBe("derived");
67-expect(report.registryDiagnostics).toContainEqual(
68-expect.objectContaining({ code: "persisted-registry-stale-source" }),
69-);
70-expect(report.plugins).toEqual(
71-expect.arrayContaining([
72-expect.objectContaining({
73-id: "whatsapp",
74-name: "WhatsApp",
75-source: fs.realpathSync(path.join(whatsappDir, "dist", "index.js")),
76-status: "loaded",
77-}),
78-]),
79-);
103+expect(
104+report.registryDiagnostics.some(
105+(diagnostic) => diagnostic.code === "persisted-registry-stale-source",
106+),
107+).toBe(true);
108+expectFields(requirePlugin(report.plugins, "whatsapp"), {
109+id: "whatsapp",
110+name: "WhatsApp",
111+source: fs.realpathSync(path.join(whatsappDir, "dist", "index.js")),
112+status: "loaded",
113+});
80114});
8111582116it("reconstructs list metadata from indexed manifests without importing plugin runtime", () => {
@@ -113,8 +147,7 @@ describe("buildPluginRegistrySnapshotReport", () => {
113147},
114148});
115149116-const plugin = report.plugins.find((entry) => entry.id === "indexed-demo");
117-expect(plugin).toMatchObject({
150+expectFields(requirePlugin(report.plugins, "indexed-demo"), {
118151id: "indexed-demo",
119152name: "Indexed Demo",
120153description: "Manifest-backed list metadata",
@@ -160,36 +193,37 @@ describe("buildPluginRegistrySnapshotReport", () => {
160193},
161194});
162195163-const plugin = report.plugins.find((entry) => entry.id === "dependency-demo");
164-expect(plugin?.dependencyStatus).toMatchObject({
196+const plugin = requirePlugin(report.plugins, "dependency-demo");
197+const dependencyStatus = requireRecord(plugin.dependencyStatus);
198+expectFields(dependencyStatus, {
165199hasDependencies: true,
166200installed: false,
167201requiredInstalled: false,
168202optionalInstalled: false,
169203missing: ["missing-required"],
170204missingOptional: ["missing-optional"],
171- dependencies: [
172- {
173- name: "missing-required",
174- spec: "1.0.0",
175- installed: false,
176- optional: false,
177- },
178- {
179- name: "present-required",
180- spec: "1.0.0",
181- installed: true,
182- optional: false,
183- },
184-],
185- optionalDependencies: [
186- {
187- name: "missing-optional",
188- spec: "1.0.0",
189- installed: false,
190- optional: true,
191- },
192-],
205+});
206+const dependencies = requireRecordArray(dependencyStatus.dependencies);
207+expect(dependencies).toHaveLength(2);
208+expectFields(requireNamedEntry(dependencies, "missing-required"), {
209+name: "missing-required",
210+spec: "1.0.0",
211+installed: false,
212+optional: false,
213+});
214+expectFields(requireNamedEntry(dependencies, "present-required"), {
215+name: "present-required",
216+spec: "1.0.0",
217+installed: true,
218+optional: false,
219+});
220+const optionalDependencies = requireRecordArray(dependencyStatus.optionalDependencies);
221+expect(optionalDependencies).toHaveLength(1);
222+expectFields(requireNamedEntry(optionalDependencies, "missing-optional"), {
223+name: "missing-optional",
224+spec: "1.0.0",
225+installed: false,
226+optional: true,
193227});
194228expect(isColdPluginRuntimeLoaded(fixture)).toBe(false);
195229});
@@ -230,20 +264,16 @@ describe("buildPluginRegistrySnapshotReport", () => {
230264});
231265232266expect(report.registrySource).toBe("persisted");
233-expect(report.plugins).toEqual(
234-expect.arrayContaining([
235-expect.objectContaining({
236-id: "persisted-demo",
237-name: "Persisted Demo",
238-description: "Persisted registry metadata",
239-version: "2.0.0",
240-providerIds: ["persisted-provider"],
241-commands: ["persisted-demo"],
242-source: fs.realpathSync(fixture.runtimeSource),
243-status: "loaded",
244-}),
245-]),
246-);
267+expectFields(requirePlugin(report.plugins, "persisted-demo"), {
268+id: "persisted-demo",
269+name: "Persisted Demo",
270+description: "Persisted registry metadata",
271+version: "2.0.0",
272+providerIds: ["persisted-provider"],
273+commands: ["persisted-demo"],
274+source: fs.realpathSync(fixture.runtimeSource),
275+status: "loaded",
276+});
247277expect(isColdPluginRuntimeLoaded(fixture)).toBe(false);
248278});
249279@@ -269,17 +299,13 @@ describe("buildPluginRegistrySnapshotReport", () => {
269299}),
270300});
271301272-expect(report.plugins).toEqual(
273-expect.arrayContaining([
274-expect.objectContaining({
275-id: "snapshot-demo",
276-name: "Snapshot Demo",
277-source: fs.realpathSync(fixture.runtimeSource),
278-status: "loaded",
279-imported: false,
280-}),
281-]),
282-);
302+expectFields(requirePlugin(report.plugins, "snapshot-demo"), {
303+id: "snapshot-demo",
304+name: "Snapshot Demo",
305+source: fs.realpathSync(fixture.runtimeSource),
306+status: "loaded",
307+imported: false,
308+});
283309expect(isColdPluginRuntimeLoaded(fixture)).toBe(false);
284310});
285311});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。