mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 13:55:50 +00:00
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:
67
src/utils/shell/__tests__/outputLimits.test.ts
Normal file
67
src/utils/shell/__tests__/outputLimits.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user