forked from Nomadcxx/opencode-cursor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin-toggle.test.ts
More file actions
63 lines (54 loc) · 2.22 KB
/
plugin-toggle.test.ts
File metadata and controls
63 lines (54 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/// <reference types="bun-types/test-globals" />
import { mkdtempSync, rmSync, writeFileSync } from "fs";
import { join } from "path";
import { tmpdir } from "os";
import {
isCursorPluginEnabledInConfig,
resolveOpenCodeConfigPath,
shouldEnableCursorPlugin,
} from "../../src/plugin-toggle";
describe("plugin toggle", () => {
it("enables plugin when plugin array includes cursor-acp", () => {
expect(isCursorPluginEnabledInConfig({ plugin: ["cursor-acp"] })).toBe(true);
});
it("disables plugin when plugin array excludes cursor-acp", () => {
expect(isCursorPluginEnabledInConfig({ plugin: ["other-plugin"] })).toBe(false);
});
it("keeps legacy behavior when plugin array is missing", () => {
expect(isCursorPluginEnabledInConfig({ provider: { "cursor-acp": {} } })).toBe(true);
expect(isCursorPluginEnabledInConfig({ provider: {} })).toBe(true);
});
it("resolves config from OPENCODE_CONFIG first", () => {
const customConfig = join(tmpdir(), "custom-opencode.json");
const xdgHome = join(tmpdir(), "xdg");
const path = resolveOpenCodeConfigPath({
OPENCODE_CONFIG: customConfig,
XDG_CONFIG_HOME: xdgHome,
});
expect(path).toBe(customConfig);
});
it("disables when config file exists and plugin array excludes cursor-acp", () => {
const dir = mkdtempSync(join(tmpdir(), "cursor-toggle-"));
const configPath = join(dir, "opencode.json");
try {
writeFileSync(configPath, JSON.stringify({ plugin: ["other-plugin"] }));
const state = shouldEnableCursorPlugin({ OPENCODE_CONFIG: configPath });
expect(state.enabled).toBe(false);
expect(state.reason).toBe("disabled_in_plugin_array");
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
it("stays enabled when config is invalid JSON", () => {
const dir = mkdtempSync(join(tmpdir(), "cursor-toggle-"));
const configPath = join(dir, "opencode.json");
try {
writeFileSync(configPath, "{not-json");
const state = shouldEnableCursorPlugin({ OPENCODE_CONFIG: configPath });
expect(state.enabled).toBe(true);
expect(state.reason).toBe("config_unreadable_or_invalid");
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
});