




























@@ -1,68 +1,69 @@
11import { beforeEach, describe, expect, it, vi } from "vitest";
2233const mocks = vi.hoisted(() => ({
4-getCurrentPluginMetadataSnapshot: vi.fn(),
54loadPluginMetadataSnapshot: vi.fn(),
6-}));
7-8-vi.mock("./current-plugin-metadata-snapshot.js", () => ({
9-getCurrentPluginMetadataSnapshot: mocks.getCurrentPluginMetadataSnapshot,
5+resolvePluginMetadataSnapshot: vi.fn(),
106}));
117128vi.mock("./plugin-metadata-snapshot.js", () => ({
139loadPluginMetadataSnapshot: mocks.loadPluginMetadataSnapshot,
10+resolvePluginMetadataSnapshot: mocks.resolvePluginMetadataSnapshot,
1411}));
15121613import { loadManifestContractSnapshot } from "./manifest-contract-eligibility.js";
17141815describe("loadManifestContractSnapshot", () => {
1916beforeEach(() => {
2017vi.clearAllMocks();
21-mocks.getCurrentPluginMetadataSnapshot.mockReturnValue(undefined);
2218mocks.loadPluginMetadataSnapshot.mockReturnValue({
2319index: { plugins: [] },
2420plugins: [],
2521});
22+mocks.resolvePluginMetadataSnapshot.mockImplementation(
23+(params?: Parameters<typeof mocks.loadPluginMetadataSnapshot>[0]) =>
24+mocks.loadPluginMetadataSnapshot(params),
25+);
2626});
272728-it("checks the current metadata snapshot with env and workspace scope", () => {
28+it("resolves metadata with env and workspace scope", () => {
2929const env = { HOME: "/home/snapshot" } as NodeJS.ProcessEnv;
30-const current = {
30+const snapshot = {
3131index: { plugins: [] },
3232plugins: [],
3333};
34-mocks.getCurrentPluginMetadataSnapshot.mockReturnValue(current);
34+mocks.resolvePluginMetadataSnapshot.mockReturnValue(snapshot);
35353636expect(loadManifestContractSnapshot({ config: {}, workspaceDir: "/workspace", env })).toEqual({
37-index: current.index,
38-plugins: current.plugins,
37+index: snapshot.index,
38+plugins: snapshot.plugins,
3939});
404041-expect(mocks.getCurrentPluginMetadataSnapshot).toHaveBeenCalledWith({
41+expect(mocks.resolvePluginMetadataSnapshot).toHaveBeenCalledWith({
4242config: {},
4343 env,
4444workspaceDir: "/workspace",
45+allowWorkspaceScopedCurrent: false,
4546});
4647expect(mocks.loadPluginMetadataSnapshot).not.toHaveBeenCalled();
4748});
48494950it("opts unscoped callers into the stored workspace-scoped snapshot", () => {
5051const env = { HOME: "/home/snapshot" } as NodeJS.ProcessEnv;
51-const current = {
52+const snapshot = {
5253index: { plugins: [] },
5354plugins: [],
5455};
55-mocks.getCurrentPluginMetadataSnapshot.mockReturnValue(current);
56+mocks.resolvePluginMetadataSnapshot.mockReturnValue(snapshot);
56575758expect(loadManifestContractSnapshot({ config: {}, env })).toEqual({
58-index: current.index,
59-plugins: current.plugins,
59+index: snapshot.index,
60+plugins: snapshot.plugins,
6061});
616262-expect(mocks.getCurrentPluginMetadataSnapshot).toHaveBeenCalledWith({
63+expect(mocks.resolvePluginMetadataSnapshot).toHaveBeenCalledWith({
6364config: {},
6465 env,
65-allowWorkspaceScopedSnapshot: true,
66+allowWorkspaceScopedCurrent: true,
6667});
6768expect(mocks.loadPluginMetadataSnapshot).not.toHaveBeenCalled();
6869});
@@ -80,14 +81,15 @@ describe("loadManifestContractSnapshot", () => {
8081plugins: snapshot.plugins,
8182});
828383-expect(mocks.getCurrentPluginMetadataSnapshot).toHaveBeenCalledWith({
84+expect(mocks.resolvePluginMetadataSnapshot).toHaveBeenCalledWith({
8485config: {},
8586 env,
86-allowWorkspaceScopedSnapshot: true,
87+allowWorkspaceScopedCurrent: true,
8788});
8889expect(mocks.loadPluginMetadataSnapshot).toHaveBeenCalledWith({
8990config: {},
9091 env,
92+allowWorkspaceScopedCurrent: true,
9193});
9294});
9395@@ -107,6 +109,7 @@ describe("loadManifestContractSnapshot", () => {
107109expect(mocks.loadPluginMetadataSnapshot).toHaveBeenCalledWith({
108110config: {},
109111 env,
112+allowWorkspaceScopedCurrent: true,
110113});
111114});
112115});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。