feat: scaffold OpenCode V2 toolkit with safe project installer
This commit is contained in:
commit
aac5627e98
30 files changed
+7533
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import assert from "node:assert/strict"
|
||||
import test from "node:test"
|
||||
import { addPlugin, removePlugin } from "../dist/installer/config.js"
|
||||
|
||||
const pluginName = "@sargatxet/opencode-toolkit"
|
||||
|
||||
test("adds a package plugin while preserving unrelated JSONC and comments", () => {
|
||||
const original = `{
|
||||
// Keep the user's settings intact.
|
||||
"model": "provider/model",
|
||||
"plugins": ["existing-plugin"]
|
||||
}`
|
||||
|
||||
const result = addPlugin(original, pluginName)
|
||||
const parsed = JSON.parse(result.content.replace("// Keep the user's settings intact.\n ", ""))
|
||||
|
||||
assert.equal(result.added, true)
|
||||
assert.equal(parsed.model, "provider/model")
|
||||
assert.deepEqual(parsed.plugins, ["existing-plugin", pluginName])
|
||||
assert.match(result.content, /Keep the user's settings intact/)
|
||||
})
|
||||
|
||||
test("does not duplicate an already configured package plugin", () => {
|
||||
const original = JSON.stringify({ plugins: [pluginName] }, null, 2)
|
||||
const result = addPlugin(original, pluginName)
|
||||
|
||||
assert.equal(result.added, false)
|
||||
assert.equal(result.content, original)
|
||||
})
|
||||
|
||||
test("removes only the requested package plugin", () => {
|
||||
const original = JSON.stringify({ plugins: ["other-plugin", pluginName] }, null, 2)
|
||||
const result = removePlugin(original, pluginName)
|
||||
|
||||
assert.equal(result.removed, true)
|
||||
assert.deepEqual(JSON.parse(result.content).plugins, ["other-plugin"])
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
Reference in new issue
Block a user