fix(plugin): load local toolkit and expose status tool

This commit is contained in:
sargatxet committed 2026-10-08 13:35:44 +02:00
1 parent aac5627e98
commit 2fcfe2fbf7
14 files changed
+145 -34

No files matched your search

+17 -1
View File
@@ -1,6 +1,6 @@
import assert from "node:assert/strict"
import test from "node:test"
import { addPlugin, removePlugin } from "../dist/installer/config.js"
import { addPlugin, removePlugin, replacePlugin } from "../dist/installer/config.js"
const pluginName = "@sargatxet/opencode-toolkit"
@@ -36,6 +36,22 @@ test("removes only the requested package plugin", () => {
assert.deepEqual(JSON.parse(result.content).plugins, ["other-plugin"])
})
test("replaces a managed plugin entry while preserving JSONC comments", () => {
const original = `{
"plugins": [
// Added by the previous installer version.
"${pluginName}"
]
}`
const replacement = "../node_modules/@sargatxet/opencode-toolkit"
const result = replacePlugin(original, pluginName, replacement)
assert.equal(result.replaced, true)
assert.deepEqual(JSON.parse(result.content.replace(" // Added by the previous installer version.\n", "")).plugins, [replacement])
assert.match(result.content, /Added by the previous installer version/)
})
test("rejects malformed or incompatible plugin configuration", () => {
assert.throws(() => addPlugin('{ "plugins": "not-an-array" }', pluginName), /plugins.*array/i)
assert.throws(() => addPlugin('{ broken', pluginName), /invalid JSONC/i)
+23 -1
View File
@@ -35,11 +35,33 @@ test("installs curated content and package registration idempotently", async ()
"toolkit-security-review",
"toolkit-tdd-workflow",
])
assert.match(config, new RegExp(PACKAGE_NAME.replaceAll("/", "\\/")))
assert.deepEqual(JSON.parse(config.replace(" // keep this comment\n", "")).plugins, [
"./node_modules/@sargatxet/opencode-toolkit",
])
assert.match(await readFile(path.join(project, "opencode.json"), "utf8"), /keep this comment/)
})
})
test("registers a config-relative package path and migrates the previously managed npm entry", async () => {
await withProject(async (project) => {
await mkdir(path.join(project, ".opencode"), { recursive: true })
const configPath = path.join(project, ".opencode", "opencode.json")
await writeFile(configPath, "{}\n")
await installProject(project)
await writeFile(configPath, `{
"plugins": ["${PACKAGE_NAME}"]
}\n`)
await installProject(project)
const config = JSON.parse(await readFile(configPath, "utf8"))
assert.deepEqual(config.plugins, ["../node_modules/@sargatxet/opencode-toolkit"])
const result = await uninstallProject(project)
assert.equal(result.pluginRemoved, true)
assert.deepEqual(JSON.parse(await readFile(configPath, "utf8")).plugins, [])
})
})
test("refuses to overwrite unowned files and leaves installation unchanged", async () => {
await withProject(async (project) => {
const target = path.join(project, ".opencode", "skills", "toolkit-tdd-workflow", "SKILL.md")
+1
View File
@@ -45,6 +45,7 @@ test("registers namespaced read-only project status tool", async () => {
assert.equal(registered.length, 1)
assert.equal(registered[0].name, "project_status")
assert.deepEqual(registered[0].options, { namespace: "toolkit", codemode: true })
assert.equal(typeof registered[0].execute, "function")
assert.deepEqual(registered[0].input, {
type: "object",