|
| 1 | +// Verifies exec command highlighting resolution across global and agent-scoped config. |
| 2 | +import { describe, expect, it } from "vitest"; |
| 3 | +import { resolveExecCommandHighlighting } from "./exec-command-highlighting.js"; |
| 4 | +import type { OpenClawConfig } from "./types.openclaw.js"; |
| 5 | + |
| 6 | +describe("resolveExecCommandHighlighting", () => { |
| 7 | + it("defaults to false when no config is provided", () => { |
| 8 | + expect(resolveExecCommandHighlighting({})).toBe(false); |
| 9 | + }); |
| 10 | + |
| 11 | + it("defaults to false when config is null", () => { |
| 12 | + expect(resolveExecCommandHighlighting({ config: null })).toBe(false); |
| 13 | + }); |
| 14 | + |
| 15 | + it("reads global exec commandHighlighting", () => { |
| 16 | + const config = { |
| 17 | + tools: { exec: { commandHighlighting: true } }, |
| 18 | + } satisfies OpenClawConfig; |
| 19 | + |
| 20 | + expect(resolveExecCommandHighlighting({ config })).toBe(true); |
| 21 | + }); |
| 22 | + |
| 23 | + it("returns false when global exec commandHighlighting is disabled", () => { |
| 24 | + const config = { |
| 25 | + tools: { exec: { commandHighlighting: false } }, |
| 26 | + } satisfies OpenClawConfig; |
| 27 | + |
| 28 | + expect(resolveExecCommandHighlighting({ config })).toBe(false); |
| 29 | + }); |
| 30 | + |
| 31 | + it("agent-scoped true overrides global false", () => { |
| 32 | + const config = { |
| 33 | + agents: { |
| 34 | + list: [ |
| 35 | + { |
| 36 | + id: "alpha", |
| 37 | + tools: { exec: { commandHighlighting: true } }, |
| 38 | + }, |
| 39 | + ], |
| 40 | + }, |
| 41 | + tools: { exec: { commandHighlighting: false } }, |
| 42 | + } satisfies OpenClawConfig; |
| 43 | + |
| 44 | + expect(resolveExecCommandHighlighting({ config, agentId: "alpha" })).toBe(true); |
| 45 | + }); |
| 46 | + |
| 47 | + it("agent-scoped false overrides global true", () => { |
| 48 | + const config = { |
| 49 | + agents: { |
| 50 | + list: [ |
| 51 | + { |
| 52 | + id: "alpha", |
| 53 | + tools: { exec: { commandHighlighting: false } }, |
| 54 | + }, |
| 55 | + ], |
| 56 | + }, |
| 57 | + tools: { exec: { commandHighlighting: true } }, |
| 58 | + } satisfies OpenClawConfig; |
| 59 | + |
| 60 | + expect(resolveExecCommandHighlighting({ config, agentId: "alpha" })).toBe(false); |
| 61 | + }); |
| 62 | + |
| 63 | + it("agent without override falls back to global true", () => { |
| 64 | + const config = { |
| 65 | + agents: { |
| 66 | + list: [{ id: "alpha" }], |
| 67 | + }, |
| 68 | + tools: { exec: { commandHighlighting: true } }, |
| 69 | + } satisfies OpenClawConfig; |
| 70 | + |
| 71 | + expect(resolveExecCommandHighlighting({ config, agentId: "alpha" })).toBe(true); |
| 72 | + }); |
| 73 | + |
| 74 | + it("agent without override falls back to global false", () => { |
| 75 | + const config = { |
| 76 | + agents: { |
| 77 | + list: [{ id: "alpha" }], |
| 78 | + }, |
| 79 | + tools: { exec: { commandHighlighting: false } }, |
| 80 | + } satisfies OpenClawConfig; |
| 81 | + |
| 82 | + expect(resolveExecCommandHighlighting({ config, agentId: "alpha" })).toBe(false); |
| 83 | + }); |
| 84 | + |
| 85 | + it("agent with explicit true and no global returns true", () => { |
| 86 | + const config = { |
| 87 | + agents: { |
| 88 | + list: [ |
| 89 | + { |
| 90 | + id: "alpha", |
| 91 | + tools: { exec: { commandHighlighting: true } }, |
| 92 | + }, |
| 93 | + ], |
| 94 | + }, |
| 95 | + } satisfies OpenClawConfig; |
| 96 | + |
| 97 | + expect(resolveExecCommandHighlighting({ config, agentId: "alpha" })).toBe(true); |
| 98 | + }); |
| 99 | + |
| 100 | + it("agent with explicit false and no global falls back to false", () => { |
| 101 | + const config = { |
| 102 | + agents: { |
| 103 | + list: [ |
| 104 | + { |
| 105 | + id: "alpha", |
| 106 | + tools: { exec: { commandHighlighting: false } }, |
| 107 | + }, |
| 108 | + ], |
| 109 | + }, |
| 110 | + } satisfies OpenClawConfig; |
| 111 | + |
| 112 | + expect(resolveExecCommandHighlighting({ config, agentId: "alpha" })).toBe(false); |
| 113 | + }); |
| 114 | + |
| 115 | + it("falls back to global config when agent ID is not in the agent list", () => { |
| 116 | + const config = { |
| 117 | + tools: { exec: { commandHighlighting: true } }, |
| 118 | + } satisfies OpenClawConfig; |
| 119 | + |
| 120 | + expect(resolveExecCommandHighlighting({ config, agentId: "nonexistent" })).toBe(true); |
| 121 | + }); |
| 122 | + |
| 123 | + it("agent ID normalization matches agent list entries", () => { |
| 124 | + // normalizeAgentId lowercases and trims the agent ID, so "ALPHA" should |
| 125 | + // match an entry with id "alpha". |
| 126 | + const config = { |
| 127 | + agents: { |
| 128 | + list: [ |
| 129 | + { |
| 130 | + id: "alpha", |
| 131 | + tools: { exec: { commandHighlighting: true } }, |
| 132 | + }, |
| 133 | + ], |
| 134 | + }, |
| 135 | + } satisfies OpenClawConfig; |
| 136 | + |
| 137 | + expect(resolveExecCommandHighlighting({ config, agentId: "ALPHA" })).toBe(true); |
| 138 | + }); |
| 139 | + |
| 140 | + it("unrelated agent ID does not affect the result", () => { |
| 141 | + const config = { |
| 142 | + agents: { |
| 143 | + list: [ |
| 144 | + { |
| 145 | + id: "other", |
| 146 | + tools: { exec: { commandHighlighting: true } }, |
| 147 | + }, |
| 148 | + ], |
| 149 | + }, |
| 150 | + } satisfies OpenClawConfig; |
| 151 | + |
| 152 | + expect(resolveExecCommandHighlighting({ config, agentId: "alpha" })).toBe(false); |
| 153 | + }); |
| 154 | +}); |
0 commit comments