test: Phase 2-4 — 添加 12 个测试文件 (+321 tests, 968 total)

Phase 2 (轻 Mock): envUtils, sleep/sequential, memoize, groupToolUses, dangerousPatterns, outputLimits
Phase 3 (补全): zodToJsonSchema, PermissionMode, envValidation
Phase 4 (工具模块): mcpStringUtils, destructiveCommandWarning, commandSemantics

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-02 09:29:01 +08:00
parent 2d9c2adce3
commit 21ac9e441f
13 changed files with 1668 additions and 44 deletions

View File

@@ -0,0 +1,67 @@
import { mock, describe, expect, test, afterEach } from "bun:test";
// Mock debug.ts to cut the bootstrap/state dependency chain
mock.module("src/utils/debug.ts", () => ({
logForDebugging: () => {},
isDebugMode: () => false,
isDebugToStdErr: () => false,
getDebugFilePath: () => null,
getDebugFilter: () => null,
getMinDebugLogLevel: () => "debug",
getDebugLogPath: () => "/tmp/mock-debug.log",
flushDebugLogs: async () => {},
enableDebugLogging: () => false,
setHasFormattedOutput: () => {},
getHasFormattedOutput: () => false,
logAntError: () => {},
}));
const {
getMaxOutputLength,
BASH_MAX_OUTPUT_UPPER_LIMIT,
BASH_MAX_OUTPUT_DEFAULT,
} = await import("../outputLimits");
describe("outputLimits constants", () => {
test("BASH_MAX_OUTPUT_UPPER_LIMIT is 150000", () => {
expect(BASH_MAX_OUTPUT_UPPER_LIMIT).toBe(150_000);
});
test("BASH_MAX_OUTPUT_DEFAULT is 30000", () => {
expect(BASH_MAX_OUTPUT_DEFAULT).toBe(30_000);
});
});
describe("getMaxOutputLength", () => {
const saved = process.env.BASH_MAX_OUTPUT_LENGTH;
afterEach(() => {
if (saved === undefined) delete process.env.BASH_MAX_OUTPUT_LENGTH;
else process.env.BASH_MAX_OUTPUT_LENGTH = saved;
});
test("returns default when env not set", () => {
delete process.env.BASH_MAX_OUTPUT_LENGTH;
expect(getMaxOutputLength()).toBe(30_000);
});
test("returns parsed value when valid", () => {
process.env.BASH_MAX_OUTPUT_LENGTH = "50000";
expect(getMaxOutputLength()).toBe(50_000);
});
test("caps at upper limit", () => {
process.env.BASH_MAX_OUTPUT_LENGTH = "999999";
expect(getMaxOutputLength()).toBe(150_000);
});
test("returns default for invalid value", () => {
process.env.BASH_MAX_OUTPUT_LENGTH = "not-a-number";
expect(getMaxOutputLength()).toBe(30_000);
});
test("returns default for negative value", () => {
process.env.BASH_MAX_OUTPUT_LENGTH = "-1";
expect(getMaxOutputLength()).toBe(30_000);
});
});