Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 237 additions & 0 deletions shared/assets/oh-my-opencode-slim.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://github.com/alvinunreal/oh-my-opencode-slim/config-schema",
"title": "oh-my-opencode-slim Plugin Configuration",
"description": "Configuration schema for the oh-my-opencode-slim PluginConfig.",
"type": "object",
"properties": {
"preset": {
"type": "string"
},
"presets": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/presetConfig"
}
},
"scoringEngineVersion": {
"type": "string",
"enum": ["v1", "v2-shadow", "v2"]
},
"balanceProviderUsage": {
"type": "boolean"
},
"manualPlan": {
"$ref": "#/definitions/manualPlan"
},
"agents": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/agentConfig"
}
},
"disabled_mcps": {
"type": "array",
"items": {
"type": "string"
}
},
"tmux": {
"$ref": "#/definitions/tmuxConfig"
},
"background": {
"$ref": "#/definitions/backgroundTaskConfig"
},
"fallback": {
"$ref": "#/definitions/failoverConfig"
}
},
"definitions": {
"providerModelId": {
"type": "string",
"pattern": "^[^/\\s]+/[^\\s]+$"
},
"manualAgentPlan": {
"type": "object",
"properties": {
"primary": {
"$ref": "#/definitions/providerModelId"
},
"fallback1": {
"$ref": "#/definitions/providerModelId"
},
"fallback2": {
"$ref": "#/definitions/providerModelId"
},
"fallback3": {
"$ref": "#/definitions/providerModelId"
}
},
"required": ["primary", "fallback1", "fallback2", "fallback3"]
},
"manualPlan": {
"type": "object",
"properties": {
"orchestrator": {
"$ref": "#/definitions/manualAgentPlan"
},
"oracle": {
"$ref": "#/definitions/manualAgentPlan"
},
"designer": {
"$ref": "#/definitions/manualAgentPlan"
},
"explorer": {
"$ref": "#/definitions/manualAgentPlan"
},
"librarian": {
"$ref": "#/definitions/manualAgentPlan"
},
"fixer": {
"$ref": "#/definitions/manualAgentPlan"
}
},
"required": [
"orchestrator",
"oracle",
"designer",
"explorer",
"librarian",
"fixer"
],
"additionalProperties": false
},

"agentConfig": {
"type": "object",
"description": "AgentOverrideConfigSchema (record value for presets/agents).",
"properties": {
"model": {
"type": "string"
},
"temperature": {
"type": "number",
"minimum": 0,
"maximum": 2
},
"variant": {
"type": "string"
},
"skills": {
"type": "array",
"items": {
"type": "string"
}
},
"mcps": {
"type": "array",
"items": {
"type": "string"
}
}
}
},

"presetConfig": {
"type": "object",
"description": "PresetSchema: record of string -> agentConfig.",
"additionalProperties": {
"$ref": "#/definitions/agentConfig"
}
},

"backgroundTaskConfig": {
"type": "object",
"properties": {
"maxConcurrentStarts": {
"type": "number",
"minimum": 1,
"maximum": 50,
"default": 10
}
}
},

"tmuxLayout": {
"type": "string",
"enum": [
"main-horizontal",
"main-vertical",
"tiled",
"even-horizontal",
"even-vertical"
]
},
"tmuxConfig": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean",
"default": false
},
"layout": {
"$ref": "#/definitions/tmuxLayout",
"default": "main-vertical"
},
"main_pane_size": {
"type": "number",
"minimum": 20,
"maximum": 80,
"default": 60
}
}
},

"agentModelChain": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1
},
"fallbackChains": {
"type": "object",
"properties": {
"orchestrator": {
"$ref": "#/definitions/agentModelChain"
},
"oracle": {
"$ref": "#/definitions/agentModelChain"
},
"designer": {
"$ref": "#/definitions/agentModelChain"
},
"explorer": {
"$ref": "#/definitions/agentModelChain"
},
"librarian": {
"$ref": "#/definitions/agentModelChain"
},
"fixer": {
"$ref": "#/definitions/agentModelChain"
}
},
"additionalProperties": {
"$ref": "#/definitions/agentModelChain"
}
},
"failoverConfig": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean",
"default": true
},
"timeoutMs": {
"type": "number",
"minimum": 0,
"default": 15000
},
"chains": {
"$ref": "#/definitions/fallbackChains",
"default": {}
}
}
}
}
}
123 changes: 123 additions & 0 deletions src/commands/add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ vi.mock("../utils/validator", () => {
};
});

// Mock OmosValidator for slim mode tests
vi.mock("../utils/omos-validator", () => {
const mockValidate = vi.fn(() => ({ valid: true, errors: [] }));
return {
OmosValidator: class {
validate = mockValidate;
constructor(_schemaPath: string) {}
},
__mockValidate: mockValidate,
};
});

vi.mock("../utils/scope-resolver", async () => {
const actual = await vi.importActual<typeof import("../utils/scope-resolver")>("../utils/scope-resolver");
return {
Expand Down Expand Up @@ -141,6 +153,9 @@ vi.mock("../store", () => {
createBackup() {
return null;
}
getTargetPath() {
return "/config/opencode/oh-my-opencode-slim.json";
}
},
__createdStoreInstances,
__createdProjectStoreInstances,
Expand Down Expand Up @@ -216,6 +231,9 @@ describe("addCommand", () => {
if (name === "oh-my-opencode.schema.json") {
return '{"$schema":"test"}';
}
if (name === "oh-my-opencode-slim.schema.json") {
return '{"$schema":"test-slim"}';
}
return null;
});
// fs exists/read behavior: normalize paths so tests are robust on Windows and Unix
Expand All @@ -224,6 +242,7 @@ describe("addCommand", () => {
const base = path.basename(s).toLowerCase();
// force download of schema by default
if (base === "oh-my-opencode.schema.json") return false;
if (base === "oh-my-opencode-slim.schema.json") return false;
// treat common test files as present
if (["config.json", "config.jsonc", "valid.json", "config.txt", "invalid.json"].includes(base)) return true;
// pretend store/index files do not exist
Expand Down Expand Up @@ -476,4 +495,108 @@ describe("addCommand", () => {
expect(mockSpinner.fail).toHaveBeenCalled();
expect(chalk.red).toHaveBeenCalled();
});

// --- Slim mode tests ---

it("adds preset in slim mode", async () => {
const storeModule = await import("../store");
vi.spyOn(storeModule.SettingsManager.prototype, "getEffectiveType").mockReturnValue("slim");
vi.spyOn(storeModule.OmosConfigManager.prototype, "addPreset").mockImplementation(() => {});
vi.spyOn(storeModule.OmosConfigManager.prototype, "createBackup").mockReturnValue(null);
vi.spyOn(storeModule.OmosConfigManager.prototype, "getPreset").mockReturnValue(null);
vi.spyOn(storeModule.OmosConfigManager.prototype, "getTargetPath").mockReturnValue("/config/opencode/oh-my-opencode-slim.json");
vi.mocked(fs.existsSync).mockImplementation((p: any) => {
const s = path.normalize(String(p || ""));
const base = path.basename(s).toLowerCase();
if (base === "preset.json") return true;
// Mock schema file exists in cache
if (base === "oh-my-opencode-slim.schema.json") return true;
return false;
});
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify({ orchestrator: { model: "test/model" } }));
vi.mocked(select).mockResolvedValue("user" as any);

await runAdd("/path/to/preset.json", { scope: "user" });

expect(storeModule.OmosConfigManager.prototype.addPreset).toHaveBeenCalled();
expect(mockSpinner.succeed).toHaveBeenCalledWith(expect.stringContaining("Added preset"));
});

it("fails when slim schema not in cache", async () => {
const storeModule = await import("../store");
vi.spyOn(storeModule.SettingsManager.prototype, "getEffectiveType").mockReturnValue("slim");
vi.mocked(fs.existsSync).mockImplementation((p: any) => {
const s = path.normalize(String(p || ""));
const base = path.basename(s).toLowerCase();
if (base === "preset.json") return true;
return false;
});
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify({ orchestrator: { model: "test/model" } }));
vi.mocked(readBundledAsset).mockReturnValue(null);

await runAdd("/path/to/preset.json", { scope: "user" });

expect(mockSpinner.fail).toHaveBeenCalledWith(expect.stringContaining("schema not found in cache"));
});

it("uses bundled slim schema fallback when not in cache", async () => {
const storeModule = await import("../store");
vi.spyOn(storeModule.SettingsManager.prototype, "getEffectiveType").mockReturnValue("slim");
vi.spyOn(storeModule.OmosConfigManager.prototype, "addPreset").mockImplementation(() => {});
vi.spyOn(storeModule.OmosConfigManager.prototype, "createBackup").mockReturnValue(null);
vi.spyOn(storeModule.OmosConfigManager.prototype, "getPreset").mockReturnValue(null);
vi.spyOn(storeModule.OmosConfigManager.prototype, "getTargetPath").mockReturnValue("/config/opencode/oh-my-opencode-slim.json");
vi.mocked(readBundledAsset).mockImplementation((name: string) => {
if (name === "oh-my-opencode-slim.schema.json") return '{"$schema":"test-slim"}';
return null;
});
vi.mocked(fs.existsSync).mockImplementation((p: any) => {
const s = path.normalize(String(p || ""));
const base = path.basename(s).toLowerCase();
if (base === "preset.json") return true;
return false;
});
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify({ orchestrator: { model: "test/model" } }));
vi.mocked(select).mockResolvedValue("user" as any);

await runAdd("/path/to/preset.json", { scope: "user" });

expect(readBundledAsset).toHaveBeenCalledWith("oh-my-opencode-slim.schema.json");
expect(storeModule.OmosConfigManager.prototype.addPreset).toHaveBeenCalled();
});

it("rejects .jsonc files in slim mode", async () => {
const storeModule = await import("../store");
vi.spyOn(storeModule.SettingsManager.prototype, "getEffectiveType").mockReturnValue("slim");
vi.mocked(fs.existsSync).mockImplementation((p: any) => {
const s = path.normalize(String(p || ""));
const base = path.basename(s).toLowerCase();
if (base === "preset.jsonc") return true;
return false;
});

await runAdd("/path/to/preset.jsonc", { scope: "user" });

expect(mockSpinner.fail).toHaveBeenCalledWith(expect.stringContaining("Invalid file extension"));
});

it("exits when slim preset exists without --force", async () => {
const storeModule = await import("../store");
vi.spyOn(storeModule.SettingsManager.prototype, "getEffectiveType").mockReturnValue("slim");
vi.spyOn(storeModule.OmosConfigManager.prototype, "getPreset").mockReturnValue({ orchestrator: { model: "test/model" } });
vi.spyOn(storeModule.OmosConfigManager.prototype, "getTargetPath").mockReturnValue("/config/opencode/oh-my-opencode-slim.json");
vi.mocked(fs.existsSync).mockImplementation((p: any) => {
const s = path.normalize(String(p || ""));
const base = path.basename(s).toLowerCase();
if (base === "preset.json") return true;
if (base === "oh-my-opencode-slim.schema.json") return true;
return false;
});
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify({ orchestrator: { model: "test/model" } }));
vi.mocked(select).mockResolvedValue("user" as any);

await runAdd("/path/to/preset.json", { scope: "user", id: "my-preset" });

expect(mockSpinner.fail).toHaveBeenCalledWith(expect.stringContaining("already exists"));
});
});
Loading