refactor(install): prefer native plugin install across targets (#609)
Some checks failed
CI / pr-title (push) Has been cancelled
CI / test (push) Has been cancelled
Release PR / release-pr (push) Has been cancelled
Release PR / publish-cli (push) Has been cancelled

Co-authored-by: John Cavanaugh <cavanaug@users.noreply.github.com>
This commit is contained in:
Trevin Chow
2026-04-20 18:47:07 -07:00
committed by GitHub
parent 9497a00d90
commit c2d60b47be
104 changed files with 7073 additions and 7068 deletions

View File

@@ -4,6 +4,8 @@ import path from "path"
import os from "os"
import { writeGeminiBundle } from "../src/targets/gemini"
import type { GeminiBundle } from "../src/types/gemini"
import { loadClaudePlugin } from "../src/parsers/claude"
import { convertClaudeToGemini } from "../src/converters/claude-to-gemini"
async function exists(filePath: string): Promise<boolean> {
try {
@@ -41,10 +43,12 @@ describe("writeGeminiBundle", () => {
expect(rewritten).toContain("Fresh generated skill.")
})
test("writes skills, commands, and settings.json", async () => {
test("writes agents, skills, commands, and settings.json", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "gemini-test-"))
const bundle: GeminiBundle = {
generatedSkills: [
pluginName: "compound-engineering",
generatedSkills: [],
agents: [
{
name: "security-reviewer",
content: "---\nname: security-reviewer\ndescription: Security\n---\n\nReview code.",
@@ -69,16 +73,17 @@ describe("writeGeminiBundle", () => {
await writeGeminiBundle(tempRoot, bundle)
expect(await exists(path.join(tempRoot, ".gemini", "skills", "security-reviewer", "SKILL.md"))).toBe(true)
expect(await exists(path.join(tempRoot, ".gemini", "agents", "security-reviewer.md"))).toBe(true)
expect(await exists(path.join(tempRoot, ".gemini", "skills", "skill-one", "SKILL.md"))).toBe(true)
expect(await exists(path.join(tempRoot, ".gemini", "commands", "plan.toml"))).toBe(true)
expect(await exists(path.join(tempRoot, ".gemini", "settings.json"))).toBe(true)
expect(await exists(path.join(tempRoot, ".gemini", "compound-engineering", "install-manifest.json"))).toBe(true)
const skillContent = await fs.readFile(
path.join(tempRoot, ".gemini", "skills", "security-reviewer", "SKILL.md"),
const agentContent = await fs.readFile(
path.join(tempRoot, ".gemini", "agents", "security-reviewer.md"),
"utf8",
)
expect(skillContent).toContain("Review code.")
expect(agentContent).toContain("Review code.")
const commandContent = await fs.readFile(
path.join(tempRoot, ".gemini", "commands", "plan.toml"),
@@ -124,9 +129,9 @@ Run these research agents:
"utf8",
)
expect(installedSkill).toContain("Use the repo-research-analyst skill to: feature_description")
expect(installedSkill).toContain("Use the learnings-researcher skill to: feature_description")
expect(installedSkill).toContain("Use the code-simplicity-reviewer skill")
expect(installedSkill).toContain("Use the @repo-research-analyst subagent to: feature_description")
expect(installedSkill).toContain("Use the @learnings-researcher subagent to: feature_description")
expect(installedSkill).toContain("Use the @code-simplicity-reviewer subagent")
expect(installedSkill).not.toContain("Task compound-engineering:")
})
@@ -152,9 +157,8 @@ Run these research agents:
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "gemini-home-"))
const geminiRoot = path.join(tempRoot, ".gemini")
const bundle: GeminiBundle = {
generatedSkills: [
{ name: "reviewer", content: "Reviewer skill content" },
],
generatedSkills: [],
agents: [{ name: "reviewer", content: "Reviewer agent content" }],
skillDirs: [],
commands: [
{ name: "plan", content: "Plan content" },
@@ -163,7 +167,7 @@ Run these research agents:
await writeGeminiBundle(geminiRoot, bundle)
expect(await exists(path.join(geminiRoot, "skills", "reviewer", "SKILL.md"))).toBe(true)
expect(await exists(path.join(geminiRoot, "agents", "reviewer.md"))).toBe(true)
expect(await exists(path.join(geminiRoot, "commands", "plan.toml"))).toBe(true)
// Should NOT double-nest under .gemini/.gemini
expect(await exists(path.join(geminiRoot, ".gemini"))).toBe(false)
@@ -242,4 +246,119 @@ Run these research agents:
// Should add new MCP server
expect(content.mcpServers.newServer.command).toBe("new-cmd")
})
test("removes previously managed Gemini artifacts that disappear on reinstall", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "gemini-managed-cleanup-"))
await writeGeminiBundle(tempRoot, {
pluginName: "compound-engineering",
generatedSkills: [],
agents: [{ name: "old-agent", content: "---\nname: old-agent\n---\n\nBody" }],
skillDirs: [
{
name: "skill-one",
sourceDir: path.join(import.meta.dir, "fixtures", "sample-plugin", "skills", "skill-one"),
},
],
commands: [{ name: "old/cmd", content: 'description = "Old"\nprompt = """\nold\n"""' }],
})
await writeGeminiBundle(tempRoot, {
pluginName: "compound-engineering",
generatedSkills: [],
agents: [{ name: "new-agent", content: "---\nname: new-agent\n---\n\nBody" }],
skillDirs: [],
commands: [{ name: "new/cmd", content: 'description = "New"\nprompt = """\nnew\n"""' }],
})
expect(await exists(path.join(tempRoot, ".gemini", "skills", "skill-one", "SKILL.md"))).toBe(false)
expect(await exists(path.join(tempRoot, ".gemini", "agents", "old-agent.md"))).toBe(false)
expect(await exists(path.join(tempRoot, ".gemini", "agents", "new-agent.md"))).toBe(true)
expect(await exists(path.join(tempRoot, ".gemini", "commands", "old", "cmd.toml"))).toBe(false)
expect(await exists(path.join(tempRoot, ".gemini", "commands", "new", "cmd.toml"))).toBe(true)
})
test("namespaces managed install manifests per plugin so installs do not collide", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "gemini-multi-plugin-"))
// Install plugin A first, with a skill and an agent
await writeGeminiBundle(tempRoot, {
pluginName: "compound-engineering",
generatedSkills: [],
agents: [{ name: "ce-agent", content: "---\nname: ce-agent\n---\n\nBody" }],
skillDirs: [
{
name: "ce-skill",
sourceDir: path.join(import.meta.dir, "fixtures", "sample-plugin", "skills", "skill-one"),
},
],
commands: [],
})
// Install plugin B into the same Gemini root
await writeGeminiBundle(tempRoot, {
pluginName: "coding-tutor",
generatedSkills: [],
agents: [{ name: "tutor-agent", content: "---\nname: tutor-agent\n---\n\nBody" }],
skillDirs: [
{
name: "tutor-skill",
sourceDir: path.join(import.meta.dir, "fixtures", "sample-plugin", "skills", "skill-one"),
},
],
commands: [],
})
// Both plugins must keep their own namespaced manifest
expect(await exists(path.join(tempRoot, ".gemini", "compound-engineering", "install-manifest.json"))).toBe(true)
expect(await exists(path.join(tempRoot, ".gemini", "coding-tutor", "install-manifest.json"))).toBe(true)
// Reinstall plugin A with no agents/skills — it must clean up only its own
// managed artifacts, leaving plugin B's intact (the bug the namespacing fix
// addresses: a shared manifest path would have lost B's manifest after A
// was installed, and a later A reinstall would skip B's stale-file cleanup).
await writeGeminiBundle(tempRoot, {
pluginName: "compound-engineering",
generatedSkills: [],
agents: [],
skillDirs: [],
commands: [],
})
expect(await exists(path.join(tempRoot, ".gemini", "agents", "ce-agent.md"))).toBe(false)
expect(await exists(path.join(tempRoot, ".gemini", "skills", "ce-skill"))).toBe(false)
expect(await exists(path.join(tempRoot, ".gemini", "agents", "tutor-agent.md"))).toBe(true)
expect(await exists(path.join(tempRoot, ".gemini", "skills", "tutor-skill"))).toBe(true)
expect(await exists(path.join(tempRoot, ".gemini", "coding-tutor", "install-manifest.json"))).toBe(true)
})
test("moves legacy Gemini CE artifacts to a namespaced backup", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "gemini-legacy-artifacts-"))
const geminiRoot = path.join(tempRoot, ".gemini")
await fs.mkdir(path.join(geminiRoot, "skills", "reproduce-bug"), { recursive: true })
await fs.writeFile(path.join(geminiRoot, "skills", "reproduce-bug", "SKILL.md"), "legacy removed skill")
await fs.mkdir(path.join(geminiRoot, "skills", "bug-reproduction-validator"), { recursive: true })
await fs.writeFile(path.join(geminiRoot, "skills", "bug-reproduction-validator", "SKILL.md"), "legacy removed agent skill")
await fs.mkdir(path.join(geminiRoot, "agents"), { recursive: true })
await fs.writeFile(path.join(geminiRoot, "agents", "bug-reproduction-validator.md"), "legacy removed agent")
await fs.mkdir(path.join(geminiRoot, "commands"), { recursive: true })
await fs.writeFile(path.join(geminiRoot, "commands", "reproduce-bug.toml"), "legacy removed command")
await fs.writeFile(path.join(geminiRoot, "commands", "report-bug.toml"), "legacy deleted command")
const plugin = await loadClaudePlugin(path.join(import.meta.dir, "..", "plugins", "compound-engineering"))
const bundle = convertClaudeToGemini(plugin, {
agentMode: "subagent",
inferTemperature: true,
permissions: "none",
})
await writeGeminiBundle(geminiRoot, bundle)
expect(await exists(path.join(geminiRoot, "skills", "reproduce-bug"))).toBe(false)
expect(await exists(path.join(geminiRoot, "skills", "bug-reproduction-validator"))).toBe(false)
expect(await exists(path.join(geminiRoot, "agents", "bug-reproduction-validator.md"))).toBe(false)
expect(await exists(path.join(geminiRoot, "commands", "reproduce-bug.toml"))).toBe(false)
expect(await exists(path.join(geminiRoot, "commands", "report-bug.toml"))).toBe(false)
expect(await exists(path.join(geminiRoot, "compound-engineering", "legacy-backup"))).toBe(true)
})
})