|
| 1 | +import { describe, expect, test, beforeEach, afterEach } from "bun:test" |
| 2 | +import path from "path" |
| 3 | +import { tmpdir } from "../fixture/fixture" |
| 4 | +import { Instance } from "../../src/project/instance" |
| 5 | +import { Skill } from "../../src/skill/skill" |
| 6 | + |
| 7 | +// Helper to write a minimal SKILL.md into a dir |
| 8 | +async function writeSkill(dir: string, name: string) { |
| 9 | + await Bun.write( |
| 10 | + path.join(dir, "SKILL.md"), |
| 11 | + `--- |
| 12 | +name: ${name} |
| 13 | +description: Test skill ${name} |
| 14 | +--- |
| 15 | +
|
| 16 | +# ${name} |
| 17 | +`, |
| 18 | + ) |
| 19 | +} |
| 20 | + |
| 21 | +describe("skill disable flags", () => { |
| 22 | + const saved: Record<string, string | undefined> = {} |
| 23 | + const envKeys = [ |
| 24 | + "OPENCODE_DISABLE_CLAUDE_CODE", |
| 25 | + "OPENCODE_DISABLE_CLAUDE_CODE_SKILLS", |
| 26 | + "OPENCODE_DISABLE_EXTERNAL_SKILLS", |
| 27 | + "OPENCODE_TEST_HOME", |
| 28 | + ] |
| 29 | + |
| 30 | + beforeEach(() => { |
| 31 | + for (const key of envKeys) { |
| 32 | + saved[key] = process.env[key] |
| 33 | + } |
| 34 | + }) |
| 35 | + |
| 36 | + afterEach(() => { |
| 37 | + for (const key of envKeys) { |
| 38 | + if (saved[key] === undefined) delete process.env[key] |
| 39 | + else process.env[key] = saved[key] |
| 40 | + } |
| 41 | + }) |
| 42 | + |
| 43 | + test("both .claude and .agents skills load by default", async () => { |
| 44 | + delete process.env.OPENCODE_DISABLE_CLAUDE_CODE |
| 45 | + delete process.env.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS |
| 46 | + delete process.env.OPENCODE_DISABLE_EXTERNAL_SKILLS |
| 47 | + |
| 48 | + await using tmp = await tmpdir({ |
| 49 | + git: true, |
| 50 | + init: async (dir) => { |
| 51 | + await writeSkill(path.join(dir, ".claude", "skills", "claude-skill"), "claude-skill") |
| 52 | + await writeSkill(path.join(dir, ".agents", "skills", "agents-skill"), "agents-skill") |
| 53 | + }, |
| 54 | + }) |
| 55 | + |
| 56 | + process.env.OPENCODE_TEST_HOME = tmp.path |
| 57 | + |
| 58 | + await Instance.provide({ |
| 59 | + directory: tmp.path, |
| 60 | + fn: async () => { |
| 61 | + const skills = await Skill.all() |
| 62 | + const names = skills.map((s) => s.name) |
| 63 | + expect(names).toContain("claude-skill") |
| 64 | + expect(names).toContain("agents-skill") |
| 65 | + }, |
| 66 | + }) |
| 67 | + }) |
| 68 | + |
| 69 | + test("OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=1 blocks .claude but not .agents", async () => { |
| 70 | + // Note: We need to reload the flag module to pick up env changes. |
| 71 | + // Since Flag values are computed at import time for the chained ones, |
| 72 | + // we test via the skill.ts logic which reads the flags. |
| 73 | + // The fix decoupled EXTERNAL_SKILLS from CLAUDE_CODE_SKILLS, so we |
| 74 | + // test the skill scanning code directly. |
| 75 | + delete process.env.OPENCODE_DISABLE_CLAUDE_CODE |
| 76 | + process.env.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS = "1" |
| 77 | + delete process.env.OPENCODE_DISABLE_EXTERNAL_SKILLS |
| 78 | + |
| 79 | + await using tmp = await tmpdir({ |
| 80 | + git: true, |
| 81 | + init: async (dir) => { |
| 82 | + await writeSkill(path.join(dir, ".claude", "skills", "claude-skill"), "claude-skill") |
| 83 | + await writeSkill(path.join(dir, ".agents", "skills", "agents-skill"), "agents-skill") |
| 84 | + }, |
| 85 | + }) |
| 86 | + |
| 87 | + process.env.OPENCODE_TEST_HOME = tmp.path |
| 88 | + |
| 89 | + await Instance.provide({ |
| 90 | + directory: tmp.path, |
| 91 | + fn: async () => { |
| 92 | + const skills = await Skill.all() |
| 93 | + const names = skills.map((s) => s.name) |
| 94 | + // .claude skills blocked |
| 95 | + expect(names).not.toContain("claude-skill") |
| 96 | + // .agents skills still load |
| 97 | + expect(names).toContain("agents-skill") |
| 98 | + }, |
| 99 | + }) |
| 100 | + }) |
| 101 | + |
| 102 | + test("OPENCODE_DISABLE_EXTERNAL_SKILLS=1 blocks .agents but not .claude", async () => { |
| 103 | + delete process.env.OPENCODE_DISABLE_CLAUDE_CODE |
| 104 | + delete process.env.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS |
| 105 | + process.env.OPENCODE_DISABLE_EXTERNAL_SKILLS = "1" |
| 106 | + |
| 107 | + await using tmp = await tmpdir({ |
| 108 | + git: true, |
| 109 | + init: async (dir) => { |
| 110 | + await writeSkill(path.join(dir, ".claude", "skills", "claude-skill"), "claude-skill") |
| 111 | + await writeSkill(path.join(dir, ".agents", "skills", "agents-skill"), "agents-skill") |
| 112 | + }, |
| 113 | + }) |
| 114 | + |
| 115 | + process.env.OPENCODE_TEST_HOME = tmp.path |
| 116 | + |
| 117 | + await Instance.provide({ |
| 118 | + directory: tmp.path, |
| 119 | + fn: async () => { |
| 120 | + const skills = await Skill.all() |
| 121 | + const names = skills.map((s) => s.name) |
| 122 | + // .claude skills still load |
| 123 | + expect(names).toContain("claude-skill") |
| 124 | + // .agents skills blocked |
| 125 | + expect(names).not.toContain("agents-skill") |
| 126 | + }, |
| 127 | + }) |
| 128 | + }) |
| 129 | + |
| 130 | + test("both flags set blocks both directories", async () => { |
| 131 | + delete process.env.OPENCODE_DISABLE_CLAUDE_CODE |
| 132 | + process.env.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS = "1" |
| 133 | + process.env.OPENCODE_DISABLE_EXTERNAL_SKILLS = "1" |
| 134 | + |
| 135 | + await using tmp = await tmpdir({ |
| 136 | + git: true, |
| 137 | + init: async (dir) => { |
| 138 | + await writeSkill(path.join(dir, ".claude", "skills", "claude-skill"), "claude-skill") |
| 139 | + await writeSkill(path.join(dir, ".agents", "skills", "agents-skill"), "agents-skill") |
| 140 | + }, |
| 141 | + }) |
| 142 | + |
| 143 | + process.env.OPENCODE_TEST_HOME = tmp.path |
| 144 | + |
| 145 | + await Instance.provide({ |
| 146 | + directory: tmp.path, |
| 147 | + fn: async () => { |
| 148 | + const skills = await Skill.all() |
| 149 | + const names = skills.map((s) => s.name) |
| 150 | + expect(names).not.toContain("claude-skill") |
| 151 | + expect(names).not.toContain("agents-skill") |
| 152 | + }, |
| 153 | + }) |
| 154 | + }) |
| 155 | + |
| 156 | + test(".opencode skills always load regardless of disable flags", async () => { |
| 157 | + process.env.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS = "1" |
| 158 | + process.env.OPENCODE_DISABLE_EXTERNAL_SKILLS = "1" |
| 159 | + |
| 160 | + await using tmp = await tmpdir({ |
| 161 | + git: true, |
| 162 | + init: async (dir) => { |
| 163 | + await writeSkill(path.join(dir, ".opencode", "skill", "opencode-skill"), "opencode-skill") |
| 164 | + }, |
| 165 | + }) |
| 166 | + |
| 167 | + process.env.OPENCODE_TEST_HOME = tmp.path |
| 168 | + |
| 169 | + await Instance.provide({ |
| 170 | + directory: tmp.path, |
| 171 | + fn: async () => { |
| 172 | + const skills = await Skill.all() |
| 173 | + const names = skills.map((s) => s.name) |
| 174 | + // .opencode skills are never blocked by these flags |
| 175 | + expect(names).toContain("opencode-skill") |
| 176 | + }, |
| 177 | + }) |
| 178 | + }) |
| 179 | +}) |
0 commit comments