|
| 1 | +import assert from "node:assert/strict" |
| 2 | +import test from "node:test" |
| 3 | +import type { PluginConfig } from "../lib/config" |
| 4 | +import { registerOpencodeCommands } from "../lib/commands/register" |
| 5 | + |
| 6 | +function buildConfig(permission: "allow" | "deny" = "allow"): PluginConfig { |
| 7 | + return { |
| 8 | + enabled: true, |
| 9 | + debug: false, |
| 10 | + pruneNotification: "off", |
| 11 | + pruneNotificationType: "chat", |
| 12 | + commands: { enabled: true, protectedTools: [] }, |
| 13 | + manualMode: { enabled: false, automaticStrategies: true }, |
| 14 | + turnProtection: { enabled: false, turns: 4 }, |
| 15 | + experimental: { allowSubAgents: false, customPrompts: false }, |
| 16 | + protectedFilePatterns: [], |
| 17 | + compress: { |
| 18 | + mode: "message", |
| 19 | + permission, |
| 20 | + showCompression: false, |
| 21 | + maxContextLimit: 150000, |
| 22 | + minContextLimit: 50000, |
| 23 | + nudgeFrequency: 5, |
| 24 | + iterationNudgeThreshold: 15, |
| 25 | + nudgeForce: "soft", |
| 26 | + protectedTools: ["task"], |
| 27 | + protectTags: false, |
| 28 | + protectUserMessages: false, |
| 29 | + }, |
| 30 | + strategies: { |
| 31 | + deduplication: { enabled: true, protectedTools: [] }, |
| 32 | + purgeErrors: { enabled: true, turns: 4, protectedTools: [] }, |
| 33 | + }, |
| 34 | + } as PluginConfig |
| 35 | +} |
| 36 | + |
| 37 | +test("registerOpencodeCommands exposes /dcp and /dcp-compress", () => { |
| 38 | + const opencodeConfig: Record<string, unknown> = {} |
| 39 | + registerOpencodeCommands(opencodeConfig, buildConfig("allow")) |
| 40 | + |
| 41 | + const commands = opencodeConfig.command as Record<string, { description: string }> |
| 42 | + assert.ok(commands.dcp) |
| 43 | + assert.match(commands.dcp.description, /\/dcp manual/) |
| 44 | + assert.ok(commands["dcp-compress"]) |
| 45 | +}) |
| 46 | + |
| 47 | +test("registerOpencodeCommands skips commands when compress is denied", () => { |
| 48 | + const opencodeConfig: Record<string, unknown> = {} |
| 49 | + registerOpencodeCommands(opencodeConfig, buildConfig("deny")) |
| 50 | + |
| 51 | + assert.equal(opencodeConfig.command, undefined) |
| 52 | +}) |
0 commit comments