magus-cli 7.12.2 → 7.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/package.json +4 -4
- package/src/__tests__/market-bases.test.ts +112 -0
- package/src/__tests__/market-config.test.ts +84 -0
- package/src/__tests__/market-conflicts.test.ts +175 -0
- package/src/__tests__/market-consent.test.ts +185 -0
- package/src/__tests__/market-content.test.ts +183 -0
- package/src/__tests__/market-delivery.test.ts +308 -0
- package/src/__tests__/market-fixture.ts +1167 -0
- package/src/__tests__/market-git.test.ts +130 -0
- package/src/__tests__/market-identity.test.ts +127 -0
- package/src/__tests__/market-install.test.ts +143 -0
- package/src/__tests__/market-layout.test.ts +206 -0
- package/src/__tests__/market-publish.test.ts +263 -0
- package/src/__tests__/market-r2-adapters.test.ts +190 -0
- package/src/__tests__/market-r2-company-cli.test.ts +350 -0
- package/src/__tests__/market-r2-company-unit.test.ts +224 -0
- package/src/__tests__/market-r2-local-items.test.ts +197 -0
- package/src/__tests__/market-r2-plugin-add.test.ts +470 -0
- package/src/__tests__/market-r2-plugin-publish.test.ts +568 -0
- package/src/__tests__/market-r2-routing.test.ts +127 -0
- package/src/__tests__/market-r2-skill-create-plugin.test.ts +315 -0
- package/src/__tests__/market-r2b-display-path.test.ts +180 -0
- package/src/__tests__/market-r2b-fit-row.test.ts +287 -0
- package/src/__tests__/market-r2b-local-items.test.ts +253 -0
- package/src/__tests__/market-r2b-plugin-add.test.ts +130 -0
- package/src/__tests__/market-readonly.test.ts +162 -0
- package/src/__tests__/market-repositories.test.ts +263 -0
- package/src/__tests__/market-results.test.ts +198 -0
- package/src/__tests__/market-router.test.ts +65 -0
- package/src/__tests__/market-safety.test.ts +357 -0
- package/src/__tests__/market-teammates.test.ts +304 -0
- package/src/cli/install.ts +64 -5
- package/src/cli/market-view.ts +329 -0
- package/src/cli/market.ts +664 -0
- package/src/cli/router.ts +69 -3
- package/src/cli/update-view.ts +56 -0
- package/src/cli/update.ts +111 -9
- package/src/data/marketplaces.ts +8 -2
- package/src/main.tsx +20 -2
- package/src/market-tui.tsx +21 -0
- package/src/services/active-closure.ts +71 -9
- package/src/services/claude-cli.ts +140 -10
- package/src/services/claude-settings.ts +19 -25
- package/src/services/doctor.ts +5 -5
- package/src/services/git-write.ts +615 -0
- package/src/services/github-cli.ts +309 -0
- package/src/services/local-marketplace.ts +112 -50
- package/src/services/market-bases.ts +191 -0
- package/src/services/market-change.ts +242 -0
- package/src/services/market-clone.ts +572 -0
- package/src/services/market-fs.ts +138 -0
- package/src/services/market-install.ts +172 -0
- package/src/services/market-layout.ts +311 -0
- package/src/services/market-local.ts +93 -0
- package/src/services/market-marker.ts +49 -0
- package/src/services/market-ops-content.ts +277 -0
- package/src/services/market-ops-plugin.ts +655 -0
- package/src/services/market-ops-publish.ts +1227 -0
- package/src/services/market-ops-repo.ts +916 -0
- package/src/services/market-ops-skill.ts +788 -0
- package/src/services/market-ops.ts +686 -0
- package/src/services/market-publish.ts +468 -0
- package/src/services/market-registry.ts +382 -0
- package/src/services/market-types.ts +268 -0
- package/src/services/marketplace-conflicts.ts +127 -0
- package/src/services/marketplace-refresh.ts +33 -3
- package/src/services/marketplace-sync.ts +253 -22
- package/src/services/plugin-dependencies.ts +17 -0
- package/src/services/plugin-manager.ts +1 -1
- package/src/services/plugin-mcp-config.ts +6 -9
- package/src/services/plugin-requires.ts +20 -8
- package/src/services/profile-absorb.ts +88 -3
- package/src/services/profile-adopt.ts +10 -1
- package/src/services/profiles.ts +64 -1
- package/src/services/resolver.ts +17 -5
- package/src/services/settings-manager.ts +2 -2
- package/src/services/skills-manager.ts +2 -2
- package/src/services/update-plan.ts +67 -8
- package/src/tui-runtime.tsx +142 -0
- package/src/tui.tsx +7 -124
- package/src/types/index.ts +7 -0
- package/src/ui/adapters/marketAdapter.ts +366 -0
- package/src/ui/adapters/pluginsAdapter.ts +45 -3
- package/src/ui/components/layout/ScreenLayout.tsx +43 -17
- package/src/ui/components/modals/ConfirmModal.tsx +145 -8
- package/src/ui/components/modals/HelpOverlay.tsx +10 -3
- package/src/ui/components/modals/ModalContainer.tsx +47 -5
- package/src/ui/components/primitives/ListCategoryRow.tsx +22 -2
- package/src/ui/components/primitives/ScopeBadge.tsx +28 -0
- package/src/ui/components/primitives/ScopeVersionLine.tsx +27 -0
- package/src/ui/components/primitives/SelectableRow.tsx +14 -1
- package/src/ui/components/primitives/ToneLine.tsx +25 -0
- package/src/ui/components/primitives/index.ts +5 -0
- package/src/ui/keymap.ts +21 -5
- package/src/ui/market/MarketApp.tsx +59 -0
- package/src/ui/market/MarketplaceScreen.tsx +280 -0
- package/src/ui/market/MarketplacesDetail.snowflake.tsx +161 -0
- package/src/ui/market/MarketplacesScreen.tsx +264 -0
- package/src/ui/market/PluginDetail.snowflake.tsx +61 -0
- package/src/ui/market/SkillDetail.snowflake.tsx +71 -0
- package/src/ui/market/marketKeymap.ts +243 -0
- package/src/ui/market/useMarketState.ts +694 -0
- package/src/ui/renderers/pluginRenderers.tsx +31 -3
- package/src/ui/renderers/pluginStatusText.ts +6 -0
- package/src/ui/screens/PluginsScreen.tsx +49 -5
- package/src/ui/screens/SkillsScreen.tsx +2 -2
- package/src/ui/state/AppContext.tsx +14 -2
- package/src/ui/state/types.ts +9 -2
- package/src/utils/config-dir.ts +29 -9
- package/src/utils/display-path.ts +33 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { afterEach, expect, test } from "bun:test";
|
|
2
|
+
import { mkdirSync, symlinkSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import type { LocalItem } from "../services/market-types.js";
|
|
5
|
+
import {
|
|
6
|
+
MarketFixture,
|
|
7
|
+
SKILL,
|
|
8
|
+
sourceModule,
|
|
9
|
+
write,
|
|
10
|
+
writeJson,
|
|
11
|
+
} from "./market-fixture.js";
|
|
12
|
+
|
|
13
|
+
let f: MarketFixture | undefined;
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
f?.close();
|
|
16
|
+
f = undefined;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
function discover(
|
|
20
|
+
world: MarketFixture,
|
|
21
|
+
companySkills: string[] = [],
|
|
22
|
+
): LocalItem[] {
|
|
23
|
+
return world.value<LocalItem[]>(
|
|
24
|
+
`const {localItems}=await import(${JSON.stringify(sourceModule("services/market-local.js"))});console.log(JSON.stringify(await localItems(${JSON.stringify(world.project)},new Set(${JSON.stringify(companySkills)}))));`,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
test("R4.1 TEST-31 absent skills roots yield no local items and create no folders", () => {
|
|
29
|
+
f = new MarketFixture(true);
|
|
30
|
+
const before = f.snapshot();
|
|
31
|
+
|
|
32
|
+
expect(discover(f)).toEqual([]);
|
|
33
|
+
expect(f.snapshot()).toEqual(before);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("R4.1 TEST-31 localItems detects both scopes, distinguishes plugins, and sorts by name then scope", () => {
|
|
37
|
+
f = new MarketFixture(true);
|
|
38
|
+
const projectAlpha = f.folder("project", "alpha");
|
|
39
|
+
const userAlpha = f.folder("global", "alpha");
|
|
40
|
+
write(join(projectAlpha, "SKILL.md"), SKILL);
|
|
41
|
+
write(join(userAlpha, "SKILL.md"), SKILL);
|
|
42
|
+
const renamedPlugin = f.folder("project", "folder-label");
|
|
43
|
+
writeJson(join(renamedPlugin, ".claude-plugin", "plugin.json"), {
|
|
44
|
+
name: "beta-kit",
|
|
45
|
+
version: "1.2.3",
|
|
46
|
+
});
|
|
47
|
+
write(join(renamedPlugin, "SKILL.md"), SKILL);
|
|
48
|
+
const fallbackPlugin = f.folder("global", "gamma-kit");
|
|
49
|
+
writeJson(join(fallbackPlugin, ".claude-plugin", "plugin.json"), {
|
|
50
|
+
version: "1.0.0",
|
|
51
|
+
});
|
|
52
|
+
write(join(f.folder("global", "zeta"), "SKILL.md"), SKILL);
|
|
53
|
+
write(
|
|
54
|
+
join(f.folder("project", "not-a-skill"), "README.md"),
|
|
55
|
+
"No skill entry point\n",
|
|
56
|
+
);
|
|
57
|
+
write(join(f.project, ".claude", "skills", "regular-file"), SKILL);
|
|
58
|
+
write(join(f.home, ".claude", "skills", "wrong-config"), SKILL);
|
|
59
|
+
write(join(f.home, ".claude", "skills", "decoy", "SKILL.md"), SKILL);
|
|
60
|
+
const before = f.snapshot();
|
|
61
|
+
|
|
62
|
+
const items = discover(f);
|
|
63
|
+
|
|
64
|
+
expect(items).toEqual([
|
|
65
|
+
{ kind: "skill", name: "alpha", scope: "project", path: projectAlpha },
|
|
66
|
+
{ kind: "skill", name: "alpha", scope: "user", path: userAlpha },
|
|
67
|
+
{ kind: "plugin", name: "beta-kit", scope: "project", path: renamedPlugin },
|
|
68
|
+
{ kind: "plugin", name: "gamma-kit", scope: "user", path: fallbackPlugin },
|
|
69
|
+
{
|
|
70
|
+
kind: "skill",
|
|
71
|
+
name: "zeta",
|
|
72
|
+
scope: "user",
|
|
73
|
+
path: f.folder("global", "zeta"),
|
|
74
|
+
},
|
|
75
|
+
]);
|
|
76
|
+
expect(f.snapshot()).toEqual(before);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("R4.1 TEST-32 origin copies, held-by-name skills and project profile skills are omitted, not USER namesakes", () => {
|
|
80
|
+
f = new MarketFixture(true);
|
|
81
|
+
for (const scope of ["project", "global"] as const) {
|
|
82
|
+
write(join(f.folder(scope, "company-name"), "SKILL.md"), SKILL);
|
|
83
|
+
write(join(f.folder(scope, "origin-copy"), "SKILL.md"), SKILL);
|
|
84
|
+
write(
|
|
85
|
+
join(f.folder(scope, "origin-copy"), ".magus-origin"),
|
|
86
|
+
"Even an unrecognized token excludes this copy\n",
|
|
87
|
+
);
|
|
88
|
+
write(join(f.folder(scope, "managed"), "SKILL.md"), SKILL);
|
|
89
|
+
}
|
|
90
|
+
f.profile({}, {});
|
|
91
|
+
f.active({ managed: "a".repeat(64) });
|
|
92
|
+
const unmanaged = f.folder("project", "unmanaged");
|
|
93
|
+
write(join(unmanaged, "SKILL.md"), SKILL);
|
|
94
|
+
const before = f.snapshot();
|
|
95
|
+
|
|
96
|
+
const items = discover(f, ["company-name"]);
|
|
97
|
+
|
|
98
|
+
expect(items).toEqual([
|
|
99
|
+
{
|
|
100
|
+
kind: "skill",
|
|
101
|
+
name: "managed",
|
|
102
|
+
scope: "user",
|
|
103
|
+
path: f.folder("global", "managed"),
|
|
104
|
+
},
|
|
105
|
+
{ kind: "skill", name: "unmanaged", scope: "project", path: unmanaged },
|
|
106
|
+
]);
|
|
107
|
+
expect(f.snapshot()).toEqual(before);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("R4.1 TEST-32 linked directories and nonregular plugin manifests are not local items", () => {
|
|
111
|
+
f = new MarketFixture();
|
|
112
|
+
const outside = join(f.root, "outside");
|
|
113
|
+
write(join(outside, "SKILL.md"), SKILL);
|
|
114
|
+
writeJson(join(outside, ".claude-plugin", "plugin.json"), {
|
|
115
|
+
name: "outside-kit",
|
|
116
|
+
});
|
|
117
|
+
mkdirSync(join(f.project, ".claude", "skills"), { recursive: true });
|
|
118
|
+
mkdirSync(join(f.config, "skills"), { recursive: true });
|
|
119
|
+
symlinkSync(outside, f.folder("project", "linked-project"));
|
|
120
|
+
symlinkSync(outside, f.folder("global", "linked-user"));
|
|
121
|
+
const linkedManifest = join(
|
|
122
|
+
f.folder("project", "linked-manifest"),
|
|
123
|
+
".claude-plugin",
|
|
124
|
+
);
|
|
125
|
+
mkdirSync(linkedManifest, { recursive: true });
|
|
126
|
+
symlinkSync(
|
|
127
|
+
join(outside, ".claude-plugin", "plugin.json"),
|
|
128
|
+
join(linkedManifest, "plugin.json"),
|
|
129
|
+
);
|
|
130
|
+
mkdirSync(
|
|
131
|
+
join(
|
|
132
|
+
f.folder("project", "directory-manifest"),
|
|
133
|
+
".claude-plugin",
|
|
134
|
+
"plugin.json",
|
|
135
|
+
),
|
|
136
|
+
{ recursive: true },
|
|
137
|
+
);
|
|
138
|
+
const before = f.snapshot();
|
|
139
|
+
|
|
140
|
+
expect(discover(f)).toEqual([]);
|
|
141
|
+
expect(f.snapshot()).toEqual(before);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test.each([false, true])(
|
|
145
|
+
"R4.1 R4.4 TEST-33 text and JSON list the same local items; company marketplace=%s",
|
|
146
|
+
(withCompany) => {
|
|
147
|
+
f = new MarketFixture(true);
|
|
148
|
+
const repo = withCompany ? f.seed() : undefined;
|
|
149
|
+
if (repo) {
|
|
150
|
+
f.register(repo);
|
|
151
|
+
write(join(f.folder(), "SKILL.md"), SKILL);
|
|
152
|
+
}
|
|
153
|
+
const skill = f.folder("project", "authoring");
|
|
154
|
+
const plugin = f.folder("global", "personal-kit");
|
|
155
|
+
write(
|
|
156
|
+
join(skill, "SKILL.md"),
|
|
157
|
+
"---\nname: authoring\n---\nWrite guides.\n",
|
|
158
|
+
);
|
|
159
|
+
writeJson(join(plugin, ".claude-plugin", "plugin.json"), {
|
|
160
|
+
name: "personal-kit",
|
|
161
|
+
version: "1.0.0",
|
|
162
|
+
});
|
|
163
|
+
write(join(f.folder("project", "tracked-copy"), "SKILL.md"), SKILL);
|
|
164
|
+
write(
|
|
165
|
+
join(f.folder("project", "tracked-copy"), ".magus-origin"),
|
|
166
|
+
"tracked\n",
|
|
167
|
+
);
|
|
168
|
+
const before = f.snapshot();
|
|
169
|
+
const head = repo ? f.head(repo) : undefined;
|
|
170
|
+
|
|
171
|
+
const json = f.market(["list"]);
|
|
172
|
+
const text = f.cli(["market", "list"]);
|
|
173
|
+
|
|
174
|
+
expect(json.code).toBe(0);
|
|
175
|
+
expect(json.result.local).toEqual([
|
|
176
|
+
{ kind: "skill", name: "authoring", scope: "project", path: skill },
|
|
177
|
+
{ kind: "plugin", name: "personal-kit", scope: "user", path: plugin },
|
|
178
|
+
]);
|
|
179
|
+
expect(json.result.marketplaces?.map((entry) => entry.name)).toEqual(
|
|
180
|
+
withCompany ? ["acme"] : [],
|
|
181
|
+
);
|
|
182
|
+
expect(text.code).toBe(0);
|
|
183
|
+
expect(text.out).toContain("authoring");
|
|
184
|
+
expect(text.out).toContain("personal-kit");
|
|
185
|
+
expect(text.out).toContain("PROJECT");
|
|
186
|
+
expect(text.out).toContain("USER");
|
|
187
|
+
expect(text.out).not.toContain("tracked-copy");
|
|
188
|
+
if (repo) {
|
|
189
|
+
expect(text.out.indexOf("authoring")).toBeGreaterThan(
|
|
190
|
+
text.out.indexOf("acme"),
|
|
191
|
+
);
|
|
192
|
+
expect(f.head(repo)).toBe(head!);
|
|
193
|
+
}
|
|
194
|
+
expect(f.snapshot()).toEqual(before);
|
|
195
|
+
},
|
|
196
|
+
30_000,
|
|
197
|
+
);
|
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
import { afterEach, expect, test } from "bun:test";
|
|
2
|
+
import { mkdirSync, readFileSync, symlinkSync } from "node:fs";
|
|
3
|
+
import { join, relative } from "node:path";
|
|
4
|
+
import {
|
|
5
|
+
MANIFEST,
|
|
6
|
+
MarketFixture,
|
|
7
|
+
type Repo,
|
|
8
|
+
SKILL,
|
|
9
|
+
write,
|
|
10
|
+
writeJson,
|
|
11
|
+
} from "./market-fixture.js";
|
|
12
|
+
|
|
13
|
+
let f: MarketFixture | undefined;
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
f?.close();
|
|
16
|
+
f = undefined;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
function localPlugin(
|
|
20
|
+
world: MarketFixture,
|
|
21
|
+
name = "local-kit",
|
|
22
|
+
version: string | undefined = "1.2.3",
|
|
23
|
+
): string {
|
|
24
|
+
const folder = world.folder("project", "copy-me");
|
|
25
|
+
writeJson(join(folder, ".claude-plugin", "plugin.json"), {
|
|
26
|
+
name,
|
|
27
|
+
description: "Local tools",
|
|
28
|
+
...(version === undefined ? {} : { version }),
|
|
29
|
+
});
|
|
30
|
+
write(join(folder, "README.md"), "Local tools documentation\n");
|
|
31
|
+
return folder;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function sourceSnapshot(
|
|
35
|
+
world: MarketFixture,
|
|
36
|
+
folder: string,
|
|
37
|
+
): Record<string, string> {
|
|
38
|
+
const prefix = relative(world.root, folder);
|
|
39
|
+
return Object.fromEntries(
|
|
40
|
+
Object.entries(world.snapshot()).filter(
|
|
41
|
+
([path]) => path === prefix || path.startsWith(`${prefix}/`),
|
|
42
|
+
),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function oneCommit(world: MarketFixture, repo: Repo, old: string): void {
|
|
47
|
+
expect(
|
|
48
|
+
world.git(
|
|
49
|
+
world.root,
|
|
50
|
+
"--git-dir",
|
|
51
|
+
repo.bare,
|
|
52
|
+
"rev-list",
|
|
53
|
+
"--count",
|
|
54
|
+
`${old}..HEAD`,
|
|
55
|
+
),
|
|
56
|
+
).toBe("1");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
test("R4.3 R4.5 TEST-38 plugin add copies the exact allowed set in one approved commit and keeps the entire local folder", () => {
|
|
60
|
+
f = new MarketFixture();
|
|
61
|
+
const repo = f.seed({
|
|
62
|
+
extras: { ".gitignore": "plugins/local-kit/ignored-there.txt\n" },
|
|
63
|
+
});
|
|
64
|
+
f.register(repo);
|
|
65
|
+
const folder = localPlugin(f);
|
|
66
|
+
writeJson(join(folder, ".claude-plugin", "metadata.json"), { public: true });
|
|
67
|
+
write(join(folder, "src", "main.ts"), "export const greeting = 'hello';\n");
|
|
68
|
+
write(join(folder, "skills", "solo", "SKILL.md"), SKILL);
|
|
69
|
+
write(join(folder, ".env"), "KEEP_SECRET=here\n");
|
|
70
|
+
write(join(folder, ".mcp.json"), '{"private":"kept locally"}\n');
|
|
71
|
+
write(join(folder, ".hidden", "notes.md"), "Private notes\n");
|
|
72
|
+
write(join(folder, "src", ".credentials"), "Private credentials\n");
|
|
73
|
+
write(join(folder, "node_modules", "package", "index.js"), "dependency\n");
|
|
74
|
+
write(
|
|
75
|
+
join(folder, "src", "node_modules", "nested", "index.js"),
|
|
76
|
+
"nested dependency\n",
|
|
77
|
+
);
|
|
78
|
+
write(join(folder, "ignored-here.txt"), "Ignored by source\n");
|
|
79
|
+
write(join(folder, "ignored-there.txt"), "Ignored by destination\n");
|
|
80
|
+
write(
|
|
81
|
+
join(f.project, ".gitignore"),
|
|
82
|
+
`${relative(f.project, folder)}/ignored-here.txt\n`,
|
|
83
|
+
);
|
|
84
|
+
const secret = join(f.root, "private-file");
|
|
85
|
+
write(secret, "Never follow this link\n");
|
|
86
|
+
symlinkSync(secret, join(folder, "linked-secret"));
|
|
87
|
+
const privateDirectory = join(f.root, "private-directory");
|
|
88
|
+
write(join(privateDirectory, "outside.txt"), "Outside plugin\n");
|
|
89
|
+
symlinkSync(privateDirectory, join(folder, "linked-directory"));
|
|
90
|
+
const before = f.snapshot();
|
|
91
|
+
const sourceBefore = sourceSnapshot(f, folder);
|
|
92
|
+
const old = f.head(repo);
|
|
93
|
+
const args = ["plugin", "add", relative(f.project, folder), "--to", "acme"];
|
|
94
|
+
|
|
95
|
+
const plan = f.market(args);
|
|
96
|
+
|
|
97
|
+
expect({ exit: plan.code, outcome: plan.result.outcome }).toEqual({
|
|
98
|
+
exit: 3,
|
|
99
|
+
outcome: "needs-consent",
|
|
100
|
+
});
|
|
101
|
+
expect(typeof plan.result.planId).toBe("string");
|
|
102
|
+
for (const [path, reason] of [
|
|
103
|
+
[".env", "dotfile"],
|
|
104
|
+
[".mcp.json", "dotfile"],
|
|
105
|
+
[".hidden/notes.md", "dotfile"],
|
|
106
|
+
["src/.credentials", "dotfile"],
|
|
107
|
+
["node_modules/package/index.js", "node_modules"],
|
|
108
|
+
["src/node_modules/nested/index.js", "node_modules"],
|
|
109
|
+
["ignored-here.txt", "ignored-here"],
|
|
110
|
+
["ignored-there.txt", "ignored-by-marketplace"],
|
|
111
|
+
["linked-secret", "symlink"],
|
|
112
|
+
["linked-directory", "symlink"],
|
|
113
|
+
]) {
|
|
114
|
+
expect(
|
|
115
|
+
plan.result.notPublished?.some(
|
|
116
|
+
(file) => file.path.endsWith(path!) && file.reason === reason,
|
|
117
|
+
),
|
|
118
|
+
).toBe(true);
|
|
119
|
+
}
|
|
120
|
+
expect(f.snapshot()).toEqual(before);
|
|
121
|
+
expect(f.head(repo)).toBe(old);
|
|
122
|
+
|
|
123
|
+
const result = f.market([...args, `--yes=${plan.result.planId}`]);
|
|
124
|
+
|
|
125
|
+
expect({ exit: result.code, outcome: result.result.outcome }).toEqual({
|
|
126
|
+
exit: 0,
|
|
127
|
+
outcome: "ok",
|
|
128
|
+
});
|
|
129
|
+
oneCommit(f, repo, old);
|
|
130
|
+
const expected = [
|
|
131
|
+
"plugins/local-kit/.claude-plugin/metadata.json",
|
|
132
|
+
"plugins/local-kit/.claude-plugin/plugin.json",
|
|
133
|
+
"plugins/local-kit/README.md",
|
|
134
|
+
"plugins/local-kit/skills/solo/SKILL.md",
|
|
135
|
+
"plugins/local-kit/src/main.ts",
|
|
136
|
+
];
|
|
137
|
+
expect(
|
|
138
|
+
f
|
|
139
|
+
.remotePaths(repo)
|
|
140
|
+
.filter((path) => path.startsWith("plugins/local-kit/"))
|
|
141
|
+
.sort(),
|
|
142
|
+
).toEqual(expected.sort());
|
|
143
|
+
expect(
|
|
144
|
+
f
|
|
145
|
+
.git(f.root, "--git-dir", repo.bare, "diff", "--name-only", old, "HEAD")
|
|
146
|
+
.split("\n")
|
|
147
|
+
.sort(),
|
|
148
|
+
).toEqual([MANIFEST, ...expected].sort());
|
|
149
|
+
expect(f.remoteBytes(repo, "plugins/local-kit/skills/solo/SKILL.md")).toBe(
|
|
150
|
+
SKILL,
|
|
151
|
+
);
|
|
152
|
+
expect(f.remoteJson(repo, MANIFEST).plugins).toContainEqual({
|
|
153
|
+
name: "local-kit",
|
|
154
|
+
source: "./plugins/local-kit",
|
|
155
|
+
description: "Local tools",
|
|
156
|
+
version: "1.2.3",
|
|
157
|
+
});
|
|
158
|
+
expect(result.result.steps.map((step) => step.id)).toEqual([
|
|
159
|
+
"copy",
|
|
160
|
+
"validate",
|
|
161
|
+
"commit",
|
|
162
|
+
"deliver",
|
|
163
|
+
"refresh",
|
|
164
|
+
]);
|
|
165
|
+
expect(f.version("local-kit@acme")).toBeNull();
|
|
166
|
+
expect(sourceSnapshot(f, folder)).toEqual(sourceBefore);
|
|
167
|
+
f.assertOwned();
|
|
168
|
+
}, 60_000);
|
|
169
|
+
|
|
170
|
+
test.each([
|
|
171
|
+
{
|
|
172
|
+
version: "2.3.4",
|
|
173
|
+
override: undefined,
|
|
174
|
+
expectedName: "local-kit",
|
|
175
|
+
expectedVersion: "2.3.4",
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
version: undefined,
|
|
179
|
+
override: undefined,
|
|
180
|
+
expectedName: "local-kit",
|
|
181
|
+
expectedVersion: "0.1.0",
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
version: "not-a-version",
|
|
185
|
+
override: undefined,
|
|
186
|
+
expectedName: "local-kit",
|
|
187
|
+
expectedVersion: "0.1.0",
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
version: "1.2.3-beta",
|
|
191
|
+
override: undefined,
|
|
192
|
+
expectedName: "local-kit",
|
|
193
|
+
expectedVersion: "0.1.0",
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
version: "2.3.4",
|
|
197
|
+
override: "renamed-kit",
|
|
198
|
+
expectedName: "renamed-kit",
|
|
199
|
+
expectedVersion: "2.3.4",
|
|
200
|
+
},
|
|
201
|
+
])(
|
|
202
|
+
"R4.3 TEST-39 plugin add normalizes target name/version while keeping the original: %j",
|
|
203
|
+
({ version, override, expectedName, expectedVersion }) => {
|
|
204
|
+
f = new MarketFixture();
|
|
205
|
+
const repo = f.seed();
|
|
206
|
+
f.register(repo);
|
|
207
|
+
const folder = localPlugin(f, "local-kit", version);
|
|
208
|
+
// The helper's default argument is bypassed for the no-version case.
|
|
209
|
+
if (version === undefined)
|
|
210
|
+
writeJson(join(folder, ".claude-plugin", "plugin.json"), {
|
|
211
|
+
name: "local-kit",
|
|
212
|
+
description: "Local tools",
|
|
213
|
+
});
|
|
214
|
+
const before = sourceSnapshot(f, folder);
|
|
215
|
+
const old = f.head(repo);
|
|
216
|
+
|
|
217
|
+
const result = f.market([
|
|
218
|
+
"plugin",
|
|
219
|
+
"add",
|
|
220
|
+
folder,
|
|
221
|
+
...(override ? ["--name", override] : []),
|
|
222
|
+
"--yes",
|
|
223
|
+
]);
|
|
224
|
+
|
|
225
|
+
expect(result.code).toBe(0);
|
|
226
|
+
oneCommit(f, repo, old);
|
|
227
|
+
const plugin = f.remoteJson(
|
|
228
|
+
repo,
|
|
229
|
+
`plugins/${expectedName}/.claude-plugin/plugin.json`,
|
|
230
|
+
);
|
|
231
|
+
expect(plugin.name).toBe(expectedName);
|
|
232
|
+
expect(plugin.version).toBe(expectedVersion);
|
|
233
|
+
expect(f.remoteJson(repo, MANIFEST).plugins).toContainEqual({
|
|
234
|
+
name: expectedName,
|
|
235
|
+
source: `./plugins/${expectedName}`,
|
|
236
|
+
description: "Local tools",
|
|
237
|
+
version: expectedVersion,
|
|
238
|
+
});
|
|
239
|
+
expect(sourceSnapshot(f, folder)).toEqual(before);
|
|
240
|
+
f.assertOwned();
|
|
241
|
+
},
|
|
242
|
+
60_000,
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
test.each([false, true])(
|
|
246
|
+
"R4.3 TEST-40 a taken plugin name refuses the copy; override=%s",
|
|
247
|
+
(override) => {
|
|
248
|
+
f = new MarketFixture();
|
|
249
|
+
const repo = f.seed();
|
|
250
|
+
f.register(repo);
|
|
251
|
+
const folder = localPlugin(f, override ? "my-tools" : "review-kit");
|
|
252
|
+
const before = f.snapshot();
|
|
253
|
+
const old = f.head(repo);
|
|
254
|
+
|
|
255
|
+
const result = f.market([
|
|
256
|
+
"plugin",
|
|
257
|
+
"add",
|
|
258
|
+
folder,
|
|
259
|
+
...(override ? ["--name", "review-kit"] : []),
|
|
260
|
+
"--yes",
|
|
261
|
+
]);
|
|
262
|
+
|
|
263
|
+
expect({
|
|
264
|
+
exit: result.code,
|
|
265
|
+
outcome: result.result.outcome,
|
|
266
|
+
error: result.result.error?.code,
|
|
267
|
+
}).toEqual({
|
|
268
|
+
exit: 1,
|
|
269
|
+
outcome: "failed",
|
|
270
|
+
error: "name-taken",
|
|
271
|
+
});
|
|
272
|
+
expect(f.head(repo)).toBe(old);
|
|
273
|
+
expect(f.snapshot()).toEqual(before);
|
|
274
|
+
},
|
|
275
|
+
30_000,
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
test.each([
|
|
279
|
+
{ kind: "missing", code: 2, error: "not-found" },
|
|
280
|
+
{ kind: "no-manifest", code: 2, error: "not-found" },
|
|
281
|
+
{ kind: "file", code: 1, error: "other" },
|
|
282
|
+
{ kind: "folder-link", code: 1, error: "other" },
|
|
283
|
+
{ kind: "config-plugins", code: 1, error: "other" },
|
|
284
|
+
{ kind: "manifest-link", code: 1, error: "other" },
|
|
285
|
+
{ kind: "invalid-json", code: 1, error: "other" },
|
|
286
|
+
{ kind: "invalid-name", code: 2, error: "invalid-name" },
|
|
287
|
+
])(
|
|
288
|
+
"R4.3 TEST-41 plugin add refuses $kind source with the contracted exit",
|
|
289
|
+
({ kind, code, error }) => {
|
|
290
|
+
f = new MarketFixture();
|
|
291
|
+
const repo = f.seed();
|
|
292
|
+
f.register(repo);
|
|
293
|
+
let folder = join(f.project, "source-plugin");
|
|
294
|
+
switch (kind) {
|
|
295
|
+
case "missing":
|
|
296
|
+
break;
|
|
297
|
+
case "no-manifest":
|
|
298
|
+
write(join(folder, "README.md"), "No plugin manifest\n");
|
|
299
|
+
break;
|
|
300
|
+
case "file":
|
|
301
|
+
write(folder, "Not a directory\n");
|
|
302
|
+
break;
|
|
303
|
+
case "folder-link": {
|
|
304
|
+
const actual = localPlugin(f);
|
|
305
|
+
symlinkSync(actual, folder);
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
case "config-plugins":
|
|
309
|
+
folder = join(f.config, "plugins", "cache", "local", "local-kit");
|
|
310
|
+
writeJson(join(folder, ".claude-plugin", "plugin.json"), {
|
|
311
|
+
name: "local-kit",
|
|
312
|
+
version: "1.0.0",
|
|
313
|
+
});
|
|
314
|
+
break;
|
|
315
|
+
case "manifest-link": {
|
|
316
|
+
mkdirSync(join(folder, ".claude-plugin"), { recursive: true });
|
|
317
|
+
const actual = join(f.root, "external-plugin.json");
|
|
318
|
+
writeJson(actual, { name: "local-kit", version: "1.0.0" });
|
|
319
|
+
symlinkSync(actual, join(folder, ".claude-plugin", "plugin.json"));
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
case "invalid-json":
|
|
323
|
+
write(join(folder, ".claude-plugin", "plugin.json"), "{invalid");
|
|
324
|
+
break;
|
|
325
|
+
case "invalid-name":
|
|
326
|
+
writeJson(join(folder, ".claude-plugin", "plugin.json"), {
|
|
327
|
+
name: "../escape",
|
|
328
|
+
version: "1.0.0",
|
|
329
|
+
});
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
const before = f.snapshot();
|
|
333
|
+
const old = f.head(repo);
|
|
334
|
+
|
|
335
|
+
const result = f.market(["plugin", "add", folder, "--yes"]);
|
|
336
|
+
|
|
337
|
+
expect({
|
|
338
|
+
exit: result.code,
|
|
339
|
+
outcome: result.result.outcome,
|
|
340
|
+
error: result.result.error?.code,
|
|
341
|
+
}).toEqual({
|
|
342
|
+
exit: code,
|
|
343
|
+
outcome: "failed",
|
|
344
|
+
error,
|
|
345
|
+
});
|
|
346
|
+
expect(f.head(repo)).toBe(old);
|
|
347
|
+
expect(f.snapshot()).toEqual(before);
|
|
348
|
+
},
|
|
349
|
+
30_000,
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
test.each([
|
|
353
|
+
{ args: ["plugin", "add"] },
|
|
354
|
+
{ args: ["plugin", "add", "one", "two"] },
|
|
355
|
+
])(
|
|
356
|
+
"R4.3 TEST-42 plugin add rejects the wrong positional argument count: $args",
|
|
357
|
+
({ args }) => {
|
|
358
|
+
f = new MarketFixture();
|
|
359
|
+
const before = f.snapshot();
|
|
360
|
+
|
|
361
|
+
const result = f.market(args);
|
|
362
|
+
|
|
363
|
+
expect(result.code).toBe(2);
|
|
364
|
+
expect(f.snapshot()).toEqual(before);
|
|
365
|
+
},
|
|
366
|
+
30_000,
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
test("R4.3 TEST-42 --to is required with several marketplaces and changes only the chosen marketplace", () => {
|
|
370
|
+
f = new MarketFixture();
|
|
371
|
+
const a = f.seed();
|
|
372
|
+
const b = f.seed({ name: "beta", slug: "beta/market" });
|
|
373
|
+
f.register(a);
|
|
374
|
+
f.register(b);
|
|
375
|
+
const folder = localPlugin(f);
|
|
376
|
+
const before = f.snapshot();
|
|
377
|
+
const oldA = f.head(a);
|
|
378
|
+
const oldB = f.head(b);
|
|
379
|
+
|
|
380
|
+
const ambiguous = f.market(["plugin", "add", folder]);
|
|
381
|
+
|
|
382
|
+
expect(ambiguous.code).toBe(2);
|
|
383
|
+
expect(ambiguous.result.error?.code).toBe("ambiguous");
|
|
384
|
+
expect(f.snapshot()).toEqual(before);
|
|
385
|
+
const result = f.market(["plugin", "add", folder, "--to", "beta", "--yes"]);
|
|
386
|
+
expect(result.code).toBe(0);
|
|
387
|
+
expect(f.head(a)).toBe(oldA);
|
|
388
|
+
oneCommit(f, b, oldB);
|
|
389
|
+
expect(
|
|
390
|
+
f
|
|
391
|
+
.remoteJson(b, MANIFEST)
|
|
392
|
+
.plugins.some((plugin: { name: string }) => plugin.name === "local-kit"),
|
|
393
|
+
).toBe(true);
|
|
394
|
+
f.assertOwned();
|
|
395
|
+
}, 60_000);
|
|
396
|
+
|
|
397
|
+
test.each(["skill", "plugin"] as const)(
|
|
398
|
+
"R4.4 TEST-43 adding a local %s with no company explains create/connect first and keeps it",
|
|
399
|
+
(kind) => {
|
|
400
|
+
f = new MarketFixture();
|
|
401
|
+
const folder =
|
|
402
|
+
kind === "plugin" ? localPlugin(f) : f.folder("project", "solo");
|
|
403
|
+
if (kind === "skill") write(join(folder, "SKILL.md"), SKILL);
|
|
404
|
+
const before = f.snapshot();
|
|
405
|
+
const args =
|
|
406
|
+
kind === "plugin"
|
|
407
|
+
? ["plugin", "add", folder]
|
|
408
|
+
: ["skill", "add", "solo", "--plugin", "fresh-kit", "--create-plugin"];
|
|
409
|
+
|
|
410
|
+
const result = f.market([...args, "--yes"]);
|
|
411
|
+
|
|
412
|
+
expect(result.code).toBe(2);
|
|
413
|
+
expect(result.result.error?.code).toBe("not-found");
|
|
414
|
+
expect(JSON.stringify(result.result)).toMatch(/create|connect/i);
|
|
415
|
+
expect(JSON.stringify(result.result)).toMatch(/marketplace/i);
|
|
416
|
+
expect(f.snapshot()).toEqual(before);
|
|
417
|
+
},
|
|
418
|
+
30_000,
|
|
419
|
+
);
|
|
420
|
+
|
|
421
|
+
test.each(["source", "name", "target"] as const)(
|
|
422
|
+
"R4.5 TEST-44 plugin add refuses consent after changing %s",
|
|
423
|
+
(changed) => {
|
|
424
|
+
f = new MarketFixture();
|
|
425
|
+
const repo = f.seed();
|
|
426
|
+
f.register(repo);
|
|
427
|
+
const beta =
|
|
428
|
+
changed === "target"
|
|
429
|
+
? f.seed({ name: "beta", slug: "beta/market" })
|
|
430
|
+
: undefined;
|
|
431
|
+
if (beta) f.register(beta);
|
|
432
|
+
const folder = localPlugin(f);
|
|
433
|
+
const args = ["plugin", "add", folder, "--to", "acme"];
|
|
434
|
+
const before = f.snapshot();
|
|
435
|
+
const plan = f.market(args);
|
|
436
|
+
expect(plan.code).toBe(3);
|
|
437
|
+
expect(typeof plan.result.planId).toBe("string");
|
|
438
|
+
expect(f.snapshot()).toEqual(before);
|
|
439
|
+
if (changed === "source")
|
|
440
|
+
write(join(folder, "README.md"), "Changed after consent\n");
|
|
441
|
+
const sourceBefore = sourceSnapshot(f, folder);
|
|
442
|
+
const old = f.head(repo);
|
|
443
|
+
const oldBeta = beta ? f.head(beta) : undefined;
|
|
444
|
+
const changedArgs =
|
|
445
|
+
changed === "target"
|
|
446
|
+
? ["plugin", "add", folder, "--to", "beta"]
|
|
447
|
+
: [...args, ...(changed === "name" ? ["--name", "different-kit"] : [])];
|
|
448
|
+
|
|
449
|
+
const result = f.market([...changedArgs, `--yes=${plan.result.planId}`]);
|
|
450
|
+
|
|
451
|
+
expect({
|
|
452
|
+
exit: result.code,
|
|
453
|
+
outcome: result.result.outcome,
|
|
454
|
+
error: result.result.error?.code,
|
|
455
|
+
}).toEqual({
|
|
456
|
+
exit: 3,
|
|
457
|
+
outcome: "needs-consent",
|
|
458
|
+
error: "plan-changed",
|
|
459
|
+
});
|
|
460
|
+
expect(result.result.planId).not.toBe(plan.result.planId);
|
|
461
|
+
expect(f.head(repo)).toBe(old);
|
|
462
|
+
if (beta) expect(f.head(beta)).toBe(oldBeta!);
|
|
463
|
+
expect(sourceSnapshot(f, folder)).toEqual(sourceBefore);
|
|
464
|
+
expect(
|
|
465
|
+
readFileSync(join(folder, ".claude-plugin", "plugin.json"), "utf8"),
|
|
466
|
+
).toContain('"local-kit"');
|
|
467
|
+
f.assertOwned();
|
|
468
|
+
},
|
|
469
|
+
60_000,
|
|
470
|
+
);
|