+46
-6
@@ -30,6 +30,16 @@ const unrelated = {
|
||||
},
|
||||
};
|
||||
const names = ["agents", "multi-work", "quota", "optchat"];
|
||||
const empty = {
|
||||
agents: {
|
||||
"fast-lo": "",
|
||||
"fast-hi": "",
|
||||
"good-lo": "",
|
||||
"good-hi": "",
|
||||
"deep-lo": "",
|
||||
"deep-hi": "",
|
||||
},
|
||||
};
|
||||
const helper = new URL("../scripts/install.ts", import.meta.url);
|
||||
async function run(
|
||||
command: string[],
|
||||
@@ -123,7 +133,9 @@ test("upgrades retain selection and options; explicit selection replaces only ow
|
||||
const f = await fixture();
|
||||
await install(f.source, f.config, "agents,quota");
|
||||
const current = await contents(f.config);
|
||||
current.plugins[1].options = { mode: "gpt", provider: "openai", lunaPriority: false };
|
||||
current.plugins[1].options = {
|
||||
agents: { ...empty.agents, "fast-lo": "openai/gpt-6-luna#low" },
|
||||
};
|
||||
current.plugins.push({ package: "after", options: { untouched: 1 } });
|
||||
await writeFile(join(f.config, "opencode.json"), JSON.stringify(current));
|
||||
await install(f.source, f.config);
|
||||
@@ -159,7 +171,7 @@ test("mixed string/object registrations upgrade without flags and preserve unrel
|
||||
before,
|
||||
{
|
||||
package: "./plugins/stanp-opencode/agents",
|
||||
options: { mode: "gpt", provider: "openai", lunaPriority: true },
|
||||
options: empty,
|
||||
},
|
||||
{ package: "./plugins/stanp-opencode/quota" },
|
||||
after,
|
||||
@@ -188,7 +200,7 @@ test("owned string registrations retain their selection and explicit selection r
|
||||
"before",
|
||||
{
|
||||
package: "./plugins/stanp-opencode/agents",
|
||||
options: { mode: "gpt", provider: "openai", lunaPriority: true },
|
||||
options: empty,
|
||||
},
|
||||
{ package: "./plugins/stanp-opencode/multi-work" },
|
||||
{ package: "./plugins/stanp-opencode/quota" },
|
||||
@@ -216,7 +228,7 @@ for (const target of ["./plugins/stanp-opencode", "stanp-opencode@1.0.0", "absol
|
||||
"before",
|
||||
{
|
||||
package: "./plugins/stanp-opencode/agents",
|
||||
options: { mode: "gpt", provider: "openai", lunaPriority: true },
|
||||
options: empty,
|
||||
},
|
||||
{ package: "./plugins/stanp-opencode/multi-work" },
|
||||
{ package: "./plugins/stanp-opencode/quota" },
|
||||
@@ -225,6 +237,34 @@ for (const target of ["./plugins/stanp-opencode", "stanp-opencode@1.0.0", "absol
|
||||
});
|
||||
}
|
||||
|
||||
test("installer writes empty option skeletons, fills only missing keys, and is idempotent", async () => {
|
||||
const f = await fixture();
|
||||
await install(f.source, f.config, "agents,multi-work,quota,optchat");
|
||||
const fresh = await contents(f.config);
|
||||
expect(fresh.plugins.slice(1)).toEqual([
|
||||
{ package: "./plugins/stanp-opencode/agents", options: empty },
|
||||
{ package: "./plugins/stanp-opencode/multi-work" },
|
||||
{ package: "./plugins/stanp-opencode/quota" },
|
||||
{
|
||||
package: "./plugins/stanp-opencode/optchat",
|
||||
options: { compactionModel: "", dataDir: "" },
|
||||
},
|
||||
]);
|
||||
fresh.plugins[1].options = { agents: { "fast-lo": "openai/gpt-6-luna#low" }, extra: 1 };
|
||||
fresh.plugins[4].options = { compactionModel: "acme/cheap" };
|
||||
await writeFile(join(f.config, "opencode.json"), JSON.stringify(fresh));
|
||||
await install(f.source, f.config);
|
||||
const filled = await contents(f.config);
|
||||
expect(filled.plugins[1].options).toEqual({
|
||||
agents: { ...empty.agents, "fast-lo": "openai/gpt-6-luna#low" },
|
||||
extra: 1,
|
||||
});
|
||||
expect(filled.plugins[4].options).toEqual({ compactionModel: "acme/cheap", dataDir: "" });
|
||||
expect(filled).toMatchObject(unrelated);
|
||||
await install(f.source, f.config);
|
||||
expect(await contents(f.config)).toEqual(filled);
|
||||
});
|
||||
|
||||
test("local installer retains executable permissions and supports direct invocation", async () => {
|
||||
const f = await fixture();
|
||||
const path = new URL("../install-local.sh", import.meta.url).pathname;
|
||||
@@ -244,7 +284,7 @@ test("replaces the legacy monolith without duplicates and retains Agents options
|
||||
{ package: "before" },
|
||||
{
|
||||
package: "./plugins/stanp-opencode",
|
||||
options: { mode: "gpt", provider: "openai", lunaPriority: false },
|
||||
options: { agents: { "fast-lo": "openai/gpt-6-luna#low" } },
|
||||
},
|
||||
{ package: "stanp-opencode" },
|
||||
{ package: "after" },
|
||||
@@ -263,7 +303,7 @@ test("replaces the legacy monolith without duplicates and retains Agents options
|
||||
.map((name) => `./plugins/stanp-opencode/${name}`),
|
||||
"after",
|
||||
]);
|
||||
expect(result.plugins[1].options.lunaPriority).toBe(false);
|
||||
expect(result.plugins[1].options.agents["fast-lo"]).toBe("openai/gpt-6-luna#low");
|
||||
expect(await Bun.file(join(f.config, "plugins", "stanp-opencode.js")).exists()).toBe(false);
|
||||
expect(result).toMatchObject(unrelated);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user