mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 13:55:50 +00:00
Apply proper TypeScript type corrections without any unsafe casts:
- Fix unknown/never/{} types from decompilation
- Correct function signatures and parameter types
- Add missing type declarations and interfaces
- Fix Ink component prop types
- Update API client/provider type annotations
Test files with mock data casts are included as-is (acceptable pattern).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
95 lines
3.2 KiB
TypeScript
95 lines
3.2 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { collapseTeammateShutdowns } from "../collapseTeammateShutdowns";
|
|
|
|
function makeShutdownMsg(uuid = "1"): any {
|
|
return {
|
|
type: "attachment",
|
|
uuid,
|
|
timestamp: Date.now(),
|
|
attachment: {
|
|
type: "task_status",
|
|
taskType: "in_process_teammate",
|
|
status: "completed",
|
|
},
|
|
};
|
|
}
|
|
|
|
function makeNonShutdownMsg(): any {
|
|
return { type: "user", message: { content: "hello" } };
|
|
}
|
|
|
|
describe("collapseTeammateShutdowns", () => {
|
|
test("returns same messages when no teammate shutdowns", () => {
|
|
const msgs = [makeNonShutdownMsg(), makeNonShutdownMsg()];
|
|
expect(collapseTeammateShutdowns(msgs)).toEqual(msgs);
|
|
});
|
|
|
|
test("leaves single shutdown message unchanged", () => {
|
|
const msgs = [makeShutdownMsg()];
|
|
const result = collapseTeammateShutdowns(msgs);
|
|
expect(result).toHaveLength(1);
|
|
expect(result[0]).toEqual(msgs[0]);
|
|
});
|
|
|
|
test("collapses consecutive shutdown messages into batch", () => {
|
|
const msgs = [makeShutdownMsg("1"), makeShutdownMsg("2")];
|
|
const result = collapseTeammateShutdowns(msgs);
|
|
expect(result).toHaveLength(1);
|
|
expect((result[0] as any).attachment.type).toBe("teammate_shutdown_batch");
|
|
});
|
|
|
|
test("batch attachment has correct count", () => {
|
|
const msgs = [makeShutdownMsg("1"), makeShutdownMsg("2"), makeShutdownMsg("3")];
|
|
const result = collapseTeammateShutdowns(msgs);
|
|
expect((result[0] as any).attachment.count).toBe(3);
|
|
});
|
|
|
|
test("does not collapse non-consecutive shutdowns", () => {
|
|
const msgs = [makeShutdownMsg("1"), makeNonShutdownMsg(), makeShutdownMsg("2")];
|
|
const result = collapseTeammateShutdowns(msgs);
|
|
expect(result).toHaveLength(3);
|
|
expect((result[0] as any).attachment.type).toBe("task_status");
|
|
expect((result[2] as any).attachment.type).toBe("task_status");
|
|
});
|
|
|
|
test("preserves non-shutdown messages between shutdowns", () => {
|
|
const msgs = [makeShutdownMsg("1"), makeNonShutdownMsg(), makeShutdownMsg("2")];
|
|
const result = collapseTeammateShutdowns(msgs);
|
|
expect(result[1]).toEqual(makeNonShutdownMsg());
|
|
});
|
|
|
|
test("handles empty array", () => {
|
|
expect(collapseTeammateShutdowns([])).toEqual([]);
|
|
});
|
|
|
|
test("handles mixed message types", () => {
|
|
const msgs = [makeNonShutdownMsg(), makeShutdownMsg("1"), makeShutdownMsg("2"), makeNonShutdownMsg()];
|
|
const result = collapseTeammateShutdowns(msgs);
|
|
expect(result).toHaveLength(3);
|
|
expect((result[1] as any).attachment.type).toBe("teammate_shutdown_batch");
|
|
});
|
|
|
|
test("collapses more than 2 consecutive shutdowns", () => {
|
|
const msgs = Array.from({ length: 5 }, (_, i) => makeShutdownMsg(String(i)));
|
|
const result = collapseTeammateShutdowns(msgs);
|
|
expect(result).toHaveLength(1);
|
|
expect((result[0] as any).attachment.count).toBe(5);
|
|
});
|
|
|
|
test("non-teammate task_status messages are not collapsed", () => {
|
|
const nonTeammate: any = {
|
|
type: "attachment",
|
|
uuid: "x",
|
|
timestamp: Date.now(),
|
|
attachment: {
|
|
type: "task_status",
|
|
taskType: "subagent",
|
|
status: "completed",
|
|
},
|
|
};
|
|
const msgs = [nonTeammate, { ...nonTeammate, uuid: "y" }];
|
|
const result = collapseTeammateShutdowns(msgs);
|
|
expect(result).toHaveLength(2);
|
|
});
|
|
});
|