-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress.test.ts
More file actions
163 lines (131 loc) · 5.29 KB
/
Copy pathprogress.test.ts
File metadata and controls
163 lines (131 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import type { AgentResult } from "../types.js";
import { createProgressTracker } from "./progress.js";
function makeAgent(overrides: Partial<AgentResult> = {}): AgentResult {
return {
id: 1,
worktree: "/tmp/thinktank-agent-1",
status: "success",
exitCode: 0,
duration: 45000,
output: "",
diff: "diff --git a/file.ts b/file.ts\n+added line",
filesChanged: ["file.ts", "other.ts"],
linesAdded: 2,
linesRemoved: 0,
...overrides,
};
}
function createMockStream(): { write(s: string): boolean; output: string[] } {
const output: string[] = [];
return {
write(s: string) {
output.push(s);
return true;
},
output,
};
}
describe("createProgressTracker — TTY mode", () => {
it("writes a running line for each agent on start", () => {
const stream = createMockStream();
const tracker = createProgressTracker([1, 2, 3], true, stream);
tracker.start();
assert.equal(stream.output.length, 3);
assert.ok(stream.output[0].includes("Agent #1: running..."));
assert.ok(stream.output[1].includes("Agent #2: running..."));
assert.ok(stream.output[2].includes("Agent #3: running..."));
});
it("updates the correct line when an agent completes", () => {
const stream = createMockStream();
const tracker = createProgressTracker([1, 2, 3], true, stream);
tracker.start();
const agent = makeAgent({ id: 2, duration: 45000, filesChanged: ["a.ts", "b.ts"] });
tracker.onAgentComplete(agent);
// Should have ANSI escape to move up and rewrite
const updateOutput = stream.output.slice(3).join("");
assert.ok(updateOutput.includes("Agent #2: done (45s, 2 files)"));
});
it("shows singular 'file' for 1 file changed", () => {
const stream = createMockStream();
const tracker = createProgressTracker([1], true, stream);
tracker.start();
const agent = makeAgent({ id: 1, duration: 10000, filesChanged: ["a.ts"] });
tracker.onAgentComplete(agent);
const updateOutput = stream.output.slice(1).join("");
assert.ok(updateOutput.includes("1 file)"), `Expected singular 'file' in: ${updateOutput}`);
});
it("shows status for failed agents", () => {
const stream = createMockStream();
const tracker = createProgressTracker([1], true, stream);
tracker.start();
const agent = makeAgent({ id: 1, status: "error", duration: 5000 });
tracker.onAgentComplete(agent);
const updateOutput = stream.output.slice(1).join("");
assert.ok(updateOutput.includes("error (5s)"));
});
it("shows status for timed-out agents", () => {
const stream = createMockStream();
const tracker = createProgressTracker([1], true, stream);
tracker.start();
const agent = makeAgent({ id: 1, status: "timeout", duration: 300000 });
tracker.onAgentComplete(agent);
const updateOutput = stream.output.slice(1).join("");
assert.ok(updateOutput.includes("timeout (300s)"));
});
it("handles all agents completing", () => {
const stream = createMockStream();
const tracker = createProgressTracker([1, 2], true, stream);
tracker.start();
tracker.onAgentComplete(makeAgent({ id: 1, duration: 30000, filesChanged: ["a.ts"] }));
tracker.onAgentComplete(makeAgent({ id: 2, duration: 40000, filesChanged: ["b.ts", "c.ts"] }));
tracker.finish();
const all = stream.output.join("");
assert.ok(all.includes("Agent #1: done (30s, 1 file)"));
assert.ok(all.includes("Agent #2: done (40s, 2 files)"));
});
});
describe("createProgressTracker — non-TTY mode", () => {
it("does not write anything on start", () => {
const stream = createMockStream();
const tracker = createProgressTracker([1, 2, 3], false, stream);
tracker.start();
assert.equal(stream.output.length, 0);
});
it("writes progress count on each completion", () => {
const stream = createMockStream();
const tracker = createProgressTracker([1, 2, 3], false, stream);
tracker.start();
tracker.onAgentComplete(makeAgent({ id: 1 }));
assert.ok(stream.output[0].includes("1/3 agents complete..."));
tracker.onAgentComplete(makeAgent({ id: 2 }));
assert.ok(stream.output[1].includes("2/3 agents complete..."));
tracker.onAgentComplete(makeAgent({ id: 3 }));
assert.ok(stream.output[2].includes("3/3 agents complete..."));
});
it("writes a trailing newline on finish", () => {
const stream = createMockStream();
const tracker = createProgressTracker([1, 2], false, stream);
tracker.start();
tracker.onAgentComplete(makeAgent({ id: 1 }));
tracker.onAgentComplete(makeAgent({ id: 2 }));
tracker.finish();
const last = stream.output[stream.output.length - 1];
assert.equal(last, "\n");
});
it("does not write trailing newline if no agents completed", () => {
const stream = createMockStream();
const tracker = createProgressTracker([1, 2], false, stream);
tracker.start();
tracker.finish();
assert.equal(stream.output.length, 0);
});
it("uses carriage return for in-place updates", () => {
const stream = createMockStream();
const tracker = createProgressTracker([1, 2], false, stream);
tracker.start();
tracker.onAgentComplete(makeAgent({ id: 1 }));
assert.ok(stream.output[0].startsWith("\r"));
});
});