Skip to content

Commit 2cc626c

Browse files
fix: 修复测试文件
1 parent eb86e34 commit 2cc626c

2 files changed

Lines changed: 36 additions & 96 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"bun": ">=1.2.0"
2626
},
2727
"bin": {
28-
"ccb": "dist/cli.js"
28+
"ccb": "dist/cli.js",
29+
"claude-code-best": "dist/cli.js"
2930
},
3031
"workspaces": [
3132
"packages/*",

src/tools/AgentTool/__tests__/agentToolUtils.test.ts

Lines changed: 34 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,14 @@
11
import { mock, describe, expect, test } from "bun:test";
22

3-
// ─── Comprehensive mocks for agentToolUtils.ts dependencies ───
4-
// These must cover ALL named exports used by the module's transitive imports.
3+
// ─── Mocks for agentToolUtils.ts dependencies ───
4+
// Only mock modules that are truly unavailable or cause side effects.
5+
// Do NOT mock common/shared modules (zod/v4, bootstrap/state, etc.) to avoid
6+
// corrupting the module cache for other test files in the same Bun process.
57

68
const noop = () => {};
7-
const emptySet = () => new Set<string>();
8-
9-
// Utility: create a mock module factory that returns an object with arbitrary named exports
10-
function stubModule(exportNames: string[]) {
11-
const obj: Record<string, any> = {};
12-
for (const name of exportNames) {
13-
obj[name] = noop;
14-
}
15-
return () => obj;
16-
}
179

1810
mock.module("bun:bundle", () => ({ feature: () => false }));
1911

20-
mock.module("zod/v4", () => ({
21-
z: {
22-
object: () => ({ extend: () => ({ parse: noop }) }),
23-
strictObject: () => ({ extend: noop }),
24-
string: () => ({ optional: () => ({ describe: noop }) }),
25-
number: () => ({ optional: noop }),
26-
boolean: () => ({ describe: noop }),
27-
enum: () => ({ optional: noop }),
28-
array: noop,
29-
union: noop,
30-
optional: noop,
31-
preprocess: noop,
32-
nullable: noop,
33-
record: noop,
34-
any: noop,
35-
unknown: noop,
36-
default: noop,
37-
},
38-
}));
39-
40-
mock.module("src/bootstrap/state.js", () => ({
41-
clearInvokedSkillsForAgent: noop,
42-
}));
43-
4412
mock.module("src/constants/tools.js", () => ({
4513
ALL_AGENT_DISALLOWED_TOOLS: new Set(),
4614
ASYNC_AGENT_ALLOWED_TOOLS: new Set(),
@@ -54,6 +22,10 @@ mock.module("src/services/AgentSummary/agentSummary.js", () => ({
5422

5523
mock.module("src/services/analytics/index.js", () => ({
5624
logEvent: noop,
25+
logEventAsync: async () => {},
26+
stripProtoFields: (v: any) => v,
27+
attachAnalyticsSink: noop,
28+
_resetForTesting: noop,
5729
AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS: undefined,
5830
}));
5931

@@ -64,7 +36,6 @@ mock.module("src/services/api/dumpPrompts.js", () => ({
6436
mock.module("src/Tool.js", () => ({
6537
toolMatchesName: () => false,
6638
findToolByName: noop,
67-
toolMatchesName: () => false,
6839
}));
6940

7041
// messages.ts is complex - provide stubs for all named exports
@@ -116,71 +87,43 @@ mock.module("src/tasks/LocalAgentTask/LocalAgentTask.js", () => ({
11687
updateProgressFromMessage: noop,
11788
}));
11889

119-
mock.module("src/utils/agentSwarmsEnabled.js", () => ({
120-
isAgentSwarmsEnabled: () => false,
121-
}));
122-
12390
mock.module("src/utils/debug.js", () => ({
91+
getMinDebugLogLevel: () => "warn",
92+
isDebugMode: () => false,
93+
enableDebugLogging: () => false,
94+
getDebugFilter: () => null,
95+
isDebugToStdErr: () => false,
96+
getDebugFilePath: () => null,
97+
setHasFormattedOutput: noop,
98+
getHasFormattedOutput: () => false,
99+
flushDebugLogs: async () => {},
124100
logForDebugging: noop,
125-
}));
126-
127-
mock.module("src/utils/envUtils.js", () => ({
128-
isInProtectedNamespace: () => false,
101+
getDebugLogPath: () => "",
102+
logAntError: noop,
129103
}));
130104

131105
mock.module("src/utils/errors.js", () => ({
106+
ClaudeError: class extends Error {},
107+
MalformedCommandError: class extends Error {},
132108
AbortError: class extends Error {},
109+
ConfigParseError: class extends Error {},
110+
ShellError: class extends Error {},
111+
TeleportOperationError: class extends Error {},
112+
TelemetrySafeError_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS: class extends Error {},
113+
isAbortError: () => false,
114+
hasExactErrorMessage: () => false,
115+
toError: (e: any) => e instanceof Error ? e : new Error(String(e)),
133116
errorMessage: (e: any) => String(e),
117+
getErrnoCode: () => undefined,
118+
isENOENT: () => false,
119+
getErrnoPath: () => undefined,
120+
shortErrorStack: () => "",
121+
isFsInaccessible: () => false,
122+
classifyAxiosError: () => ({ category: "unknown" }),
134123
}));
135124

136125
mock.module("src/utils/forkedAgent.js", () => ({}));
137126

138-
mock.module("src/utils/lazySchema.js", () => ({
139-
lazySchema: (fn: () => any) => fn,
140-
}));
141-
142-
mock.module("src/utils/permissions/PermissionMode.js", () => ({}));
143-
144-
// Provide working permissionRuleValueFromString to avoid polluting other test files
145-
const LEGACY_ALIASES: Record<string, string> = {
146-
Task: "Agent",
147-
KillShell: "TaskStop",
148-
AgentOutputTool: "TaskOutput",
149-
BashOutputTool: "TaskOutput",
150-
};
151-
152-
function normalizeLegacyToolName(name: string): string {
153-
return LEGACY_ALIASES[name] ?? name;
154-
}
155-
156-
function escapeRuleContent(content: string): string {
157-
return content.replace(/\\/g, "\\\\").replace(/\(/g, "\\(").replace(/\)/g, "\\)");
158-
}
159-
160-
function unescapeRuleContent(content: string): string {
161-
return content.replace(/\\\(/g, "(").replace(/\\\)/g, ")").replace(/\\\\/g, "\\");
162-
}
163-
164-
mock.module("src/utils/permissions/permissionRuleParser.js", () => ({
165-
permissionRuleValueFromString: (ruleString: string) => {
166-
const openIdx = ruleString.indexOf("(");
167-
if (openIdx === -1) return { toolName: normalizeLegacyToolName(ruleString) };
168-
const closeIdx = ruleString.lastIndexOf(")");
169-
if (closeIdx === -1 || closeIdx <= openIdx) return { toolName: normalizeLegacyToolName(ruleString) };
170-
if (closeIdx !== ruleString.length - 1) return { toolName: normalizeLegacyToolName(ruleString) };
171-
const toolName = ruleString.substring(0, openIdx);
172-
const rawContent = ruleString.substring(openIdx + 1, closeIdx);
173-
if (!toolName) return { toolName: normalizeLegacyToolName(ruleString) };
174-
if (rawContent === "" || rawContent === "*") return { toolName: normalizeLegacyToolName(toolName) };
175-
return { toolName: normalizeLegacyToolName(toolName), ruleContent: unescapeRuleContent(rawContent) };
176-
},
177-
permissionRuleValueToString: (v: any) => {
178-
if (!v.ruleContent) return v.toolName;
179-
return `${v.toolName}(${escapeRuleContent(v.ruleContent)})`;
180-
},
181-
normalizeLegacyToolName,
182-
}));
183-
184127
mock.module("src/utils/permissions/yoloClassifier.js", () => ({
185128
buildTranscriptForClassifier: () => "",
186129
classifyYoloAction: () => null,
@@ -190,10 +133,6 @@ mock.module("src/utils/task/sdkProgress.js", () => ({
190133
emitTaskProgress: noop,
191134
}));
192135

193-
mock.module("src/utils/teammateContext.js", () => ({
194-
isInProcessTeammate: () => false,
195-
}));
196-
197136
mock.module("src/utils/tokens.js", () => ({
198137
getTokenCountFromUsage: () => 0,
199138
}));

0 commit comments

Comments
 (0)