@ligeti/testing 0.0.0-stage → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +242 -2
- package/bin/argv-recorder.mjs +53 -0
- package/bin/clean-test-databases.mjs +146 -0
- package/bin/fake-claude.mjs +560 -0
- package/bin/fake-herdr.mjs +468 -0
- package/bin/fake-opencode.mjs +45 -0
- package/dist/agents.d.ts +5 -0
- package/dist/agents.d.ts.map +1 -0
- package/dist/agents.js +21 -0
- package/dist/agents.js.map +1 -0
- package/dist/bitbucket.d.ts +26 -0
- package/dist/bitbucket.d.ts.map +1 -0
- package/dist/bitbucket.js +162 -0
- package/dist/bitbucket.js.map +1 -0
- package/dist/callback-server.d.ts +20 -0
- package/dist/callback-server.d.ts.map +1 -0
- package/dist/callback-server.js +79 -0
- package/dist/callback-server.js.map +1 -0
- package/dist/claude-profile.d.ts +3 -0
- package/dist/claude-profile.d.ts.map +1 -0
- package/dist/claude-profile.js +16 -0
- package/dist/claude-profile.js.map +1 -0
- package/dist/env.d.ts +2 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +15 -0
- package/dist/env.js.map +1 -0
- package/dist/fake-http.d.ts +25 -0
- package/dist/fake-http.d.ts.map +1 -0
- package/dist/fake-http.js +129 -0
- package/dist/fake-http.js.map +1 -0
- package/dist/github.d.ts +184 -0
- package/dist/github.d.ts.map +1 -0
- package/dist/github.js +919 -0
- package/dist/github.js.map +1 -0
- package/dist/gitlab-merge-requests.d.ts +23 -0
- package/dist/gitlab-merge-requests.d.ts.map +1 -0
- package/dist/gitlab-merge-requests.js +228 -0
- package/dist/gitlab-merge-requests.js.map +1 -0
- package/dist/gitlab.d.ts +9 -0
- package/dist/gitlab.d.ts.map +1 -0
- package/dist/gitlab.js +13 -0
- package/dist/gitlab.js.map +1 -0
- package/dist/herdr.d.ts +9 -0
- package/dist/herdr.d.ts.map +1 -0
- package/dist/herdr.js +16 -0
- package/dist/herdr.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/jira.d.ts +7 -0
- package/dist/jira.d.ts.map +1 -0
- package/dist/jira.js +7 -0
- package/dist/jira.js.map +1 -0
- package/dist/postgres.d.ts +6 -0
- package/dist/postgres.d.ts.map +1 -0
- package/dist/postgres.js +122 -0
- package/dist/postgres.js.map +1 -0
- package/dist/recorded-turns.d.ts +9 -0
- package/dist/recorded-turns.d.ts.map +1 -0
- package/dist/recorded-turns.js +45 -0
- package/dist/recorded-turns.js.map +1 -0
- package/dist/repo.d.ts +6 -0
- package/dist/repo.d.ts.map +1 -0
- package/dist/repo.js +30 -0
- package/dist/repo.js.map +1 -0
- package/dist/telegram.d.ts +11 -0
- package/dist/telegram.d.ts.map +1 -0
- package/dist/telegram.js +37 -0
- package/dist/telegram.js.map +1 -0
- package/dist/wait.d.ts +2 -0
- package/dist/wait.d.ts.map +1 -0
- package/dist/wait.js +15 -0
- package/dist/wait.js.map +1 -0
- package/dist/worker.d.ts +19 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +56 -0
- package/dist/worker.js.map +1 -0
- package/fixtures/claude-profile/settings.json +26 -0
- package/package.json +32 -3
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// ABOUTME: Stand-in for the real `herdr` CLI, used by HerdrBackend's own unit/integration tests
|
|
3
|
+
// ABOUTME: and by small-factory's full workflow integration test.
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
readFileSync,
|
|
7
|
+
writeFileSync,
|
|
8
|
+
appendFileSync,
|
|
9
|
+
existsSync,
|
|
10
|
+
mkdirSync,
|
|
11
|
+
rmSync,
|
|
12
|
+
} from "node:fs";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
import { execFileSync } from "node:child_process";
|
|
15
|
+
|
|
16
|
+
function loadState(statePath) {
|
|
17
|
+
if (!existsSync(statePath)) {
|
|
18
|
+
return { nextId: 0, workspaces: {}, tabs: {}, panes: {}, worktrees: {} };
|
|
19
|
+
}
|
|
20
|
+
return JSON.parse(readFileSync(statePath, "utf8"));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function saveState(statePath, state) {
|
|
24
|
+
writeFileSync(statePath, JSON.stringify(state));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function fail(code, message) {
|
|
28
|
+
process.stderr.write(JSON.stringify({ error: { code, message } }));
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function ok(payload) {
|
|
33
|
+
if (payload !== undefined) {
|
|
34
|
+
process.stdout.write(JSON.stringify(payload));
|
|
35
|
+
}
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function shouldFail(phase) {
|
|
40
|
+
return process.env.FAKE_HERDR_FAIL_PHASE === phase;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function failCode() {
|
|
44
|
+
return process.env.FAKE_HERDR_FAIL_CODE ?? "boom";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function flagValue(args, flag) {
|
|
48
|
+
const idx = args.indexOf(flag);
|
|
49
|
+
return idx >= 0 ? args[idx + 1] : undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function openTab(state, workspaceId, label, cwd) {
|
|
53
|
+
const workspace = state.workspaces[workspaceId];
|
|
54
|
+
const index = workspace.nextTab++;
|
|
55
|
+
const number = index + 1;
|
|
56
|
+
const tabId = `${workspaceId}:t${String(index)}`;
|
|
57
|
+
const paneId = `${workspaceId}:${String(index)}`;
|
|
58
|
+
state.tabs[tabId] = { workspaceId, customLabel: label ?? null, number, closed: false };
|
|
59
|
+
state.panes[paneId] = { workspaceId, tabId, running: false, closed: false, cwd };
|
|
60
|
+
return { tabId, paneId };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function tabDisplayLabel(state, tabId) {
|
|
64
|
+
const tab = state.tabs[tabId];
|
|
65
|
+
if (tab.customLabel !== null) {
|
|
66
|
+
return tab.customLabel;
|
|
67
|
+
}
|
|
68
|
+
const openTabsOfWorkspace = Object.keys(state.tabs).filter(
|
|
69
|
+
(id) => state.tabs[id].workspaceId === tab.workspaceId && !state.tabs[id].closed,
|
|
70
|
+
);
|
|
71
|
+
return String(openTabsOfWorkspace.indexOf(tabId) + 1);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function openWorkspace(state, workspaceId, fields) {
|
|
75
|
+
state.workspaces[workspaceId] = { ...fields, nextTab: 0, closed: false };
|
|
76
|
+
return openTab(state, workspaceId, undefined, fields.cwd);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function closeWorkspace(state, workspaceId) {
|
|
80
|
+
state.workspaces[workspaceId].closed = true;
|
|
81
|
+
for (const tab of Object.values(state.tabs)) {
|
|
82
|
+
if (tab.workspaceId === workspaceId) {
|
|
83
|
+
tab.closed = true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for (const pane of Object.values(state.panes)) {
|
|
87
|
+
if (pane.workspaceId === workspaceId) {
|
|
88
|
+
pane.closed = true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function closeTab(state, tabId) {
|
|
94
|
+
const tab = state.tabs[tabId];
|
|
95
|
+
tab.closed = true;
|
|
96
|
+
for (const pane of Object.values(state.panes)) {
|
|
97
|
+
if (pane.tabId === tabId) {
|
|
98
|
+
pane.closed = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const remaining = Object.values(state.tabs).filter(
|
|
102
|
+
(t) => t.workspaceId === tab.workspaceId && !t.closed,
|
|
103
|
+
);
|
|
104
|
+
if (remaining.length === 0) {
|
|
105
|
+
closeWorkspace(state, tab.workspaceId);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function closePane(state, paneId) {
|
|
110
|
+
const pane = state.panes[paneId];
|
|
111
|
+
pane.closed = true;
|
|
112
|
+
const remaining = Object.values(state.panes).filter((p) => p.tabId === pane.tabId && !p.closed);
|
|
113
|
+
if (remaining.length === 0) {
|
|
114
|
+
closeTab(state, pane.tabId);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const LOCK_TIMEOUT_MS = 30_000;
|
|
119
|
+
const LOCK_POLL_MS = 20;
|
|
120
|
+
|
|
121
|
+
function holdStateLock(statePath) {
|
|
122
|
+
const lockDir = `${statePath}.lock`;
|
|
123
|
+
const deadline = Date.now() + LOCK_TIMEOUT_MS;
|
|
124
|
+
for (;;) {
|
|
125
|
+
try {
|
|
126
|
+
mkdirSync(lockDir);
|
|
127
|
+
break;
|
|
128
|
+
} catch (err) {
|
|
129
|
+
if (err.code !== "EEXIST") {
|
|
130
|
+
throw err;
|
|
131
|
+
}
|
|
132
|
+
if (Date.now() > deadline) {
|
|
133
|
+
fail("lock_timeout", `fake-herdr: could not take ${lockDir} within ${LOCK_TIMEOUT_MS}ms`);
|
|
134
|
+
}
|
|
135
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, LOCK_POLL_MS);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const release = () => {
|
|
139
|
+
rmSync(lockDir, { recursive: true, force: true });
|
|
140
|
+
};
|
|
141
|
+
process.on("exit", release);
|
|
142
|
+
process.on("SIGTERM", () => {
|
|
143
|
+
process.exit(143);
|
|
144
|
+
});
|
|
145
|
+
process.on("SIGINT", () => {
|
|
146
|
+
process.exit(130);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function main() {
|
|
151
|
+
const statePath = process.env.FAKE_HERDR_STATE;
|
|
152
|
+
if (!statePath) {
|
|
153
|
+
console.error("fake-herdr: FAKE_HERDR_STATE env var is required");
|
|
154
|
+
process.exit(2);
|
|
155
|
+
}
|
|
156
|
+
const logPath = process.env.FAKE_HERDR_LOG;
|
|
157
|
+
const argv = process.argv.slice(2);
|
|
158
|
+
if (logPath) {
|
|
159
|
+
appendFileSync(logPath, JSON.stringify(argv) + "\n");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
holdStateLock(statePath);
|
|
163
|
+
const state = loadState(statePath);
|
|
164
|
+
const [group, action, ...rest] = argv;
|
|
165
|
+
|
|
166
|
+
if (group === "workspace" && action === "create") {
|
|
167
|
+
if (shouldFail("create")) {
|
|
168
|
+
fail(failCode(), "fake create failure");
|
|
169
|
+
}
|
|
170
|
+
const cwd = flagValue(rest, "--cwd");
|
|
171
|
+
const label = flagValue(rest, "--label");
|
|
172
|
+
const id = state.nextId++;
|
|
173
|
+
const workspaceId = `ws-${String(id)}`;
|
|
174
|
+
const { tabId, paneId } = openWorkspace(state, workspaceId, { label, cwd });
|
|
175
|
+
saveState(statePath, state);
|
|
176
|
+
ok({
|
|
177
|
+
result: {
|
|
178
|
+
root_pane: { pane_id: paneId, tab_id: tabId, workspace_id: workspaceId },
|
|
179
|
+
tab: { tab_id: tabId, label: tabDisplayLabel(state, tabId), workspace_id: workspaceId },
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (group === "workspace" && action === "rename") {
|
|
185
|
+
const [workspaceId, label] = rest;
|
|
186
|
+
if (shouldFail("rename")) {
|
|
187
|
+
fail(failCode(), "fake rename failure");
|
|
188
|
+
}
|
|
189
|
+
const workspace = state.workspaces[workspaceId];
|
|
190
|
+
if (!workspace) {
|
|
191
|
+
fail("workspace_not_found", `no such workspace: ${workspaceId}`);
|
|
192
|
+
}
|
|
193
|
+
workspace.label = label;
|
|
194
|
+
saveState(statePath, state);
|
|
195
|
+
ok();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (group === "workspace" && action === "list") {
|
|
199
|
+
const workspaces = Object.entries(state.workspaces)
|
|
200
|
+
.filter(([, w]) => !w.closed)
|
|
201
|
+
.map(([workspace_id, w]) => ({
|
|
202
|
+
workspace_id,
|
|
203
|
+
label: w.label,
|
|
204
|
+
...(w.checkoutPath ? { worktree: { checkout_path: w.checkoutPath } } : {}),
|
|
205
|
+
}));
|
|
206
|
+
ok({ result: { workspaces } });
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (group === "workspace" && action === "close") {
|
|
210
|
+
if (shouldFail("close")) {
|
|
211
|
+
fail(failCode(), "fake workspace close failure");
|
|
212
|
+
}
|
|
213
|
+
const [workspaceId] = rest;
|
|
214
|
+
const workspace = state.workspaces[workspaceId];
|
|
215
|
+
if (!workspace || workspace.closed) {
|
|
216
|
+
fail("workspace_not_found", `no such workspace: ${workspaceId}`);
|
|
217
|
+
}
|
|
218
|
+
closeWorkspace(state, workspaceId);
|
|
219
|
+
saveState(statePath, state);
|
|
220
|
+
ok();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (group === "tab" && action === "create") {
|
|
224
|
+
if (shouldFail("tab_create") || shouldFail("tab_create_and_close")) {
|
|
225
|
+
fail(failCode(), "fake tab create failure");
|
|
226
|
+
}
|
|
227
|
+
const workspaceId = flagValue(rest, "--workspace");
|
|
228
|
+
const workspace = workspaceId ? state.workspaces[workspaceId] : undefined;
|
|
229
|
+
if (!workspace || workspace.closed) {
|
|
230
|
+
fail("workspace_not_found", `no such workspace: ${String(workspaceId)}`);
|
|
231
|
+
}
|
|
232
|
+
const { tabId, paneId } = openTab(
|
|
233
|
+
state,
|
|
234
|
+
workspaceId,
|
|
235
|
+
flagValue(rest, "--label"),
|
|
236
|
+
flagValue(rest, "--cwd"),
|
|
237
|
+
);
|
|
238
|
+
saveState(statePath, state);
|
|
239
|
+
ok({
|
|
240
|
+
result: {
|
|
241
|
+
root_pane: { pane_id: paneId, tab_id: tabId, workspace_id: workspaceId },
|
|
242
|
+
tab: { tab_id: tabId, label: tabDisplayLabel(state, tabId), workspace_id: workspaceId },
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (group === "tab" && action === "list") {
|
|
248
|
+
const workspaceId = flagValue(rest, "--workspace");
|
|
249
|
+
const tabs = Object.entries(state.tabs)
|
|
250
|
+
.filter(([, t]) => !t.closed && (workspaceId === undefined || t.workspaceId === workspaceId))
|
|
251
|
+
.map(([tab_id, t]) => ({
|
|
252
|
+
tab_id,
|
|
253
|
+
workspace_id: t.workspaceId,
|
|
254
|
+
label: tabDisplayLabel(state, tab_id),
|
|
255
|
+
number: t.number,
|
|
256
|
+
focused: tab_id === state.focusedTabId,
|
|
257
|
+
}));
|
|
258
|
+
ok({ result: { tabs } });
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (group === "tab" && action === "focus") {
|
|
262
|
+
const [tabId] = rest;
|
|
263
|
+
const tab = state.tabs[tabId];
|
|
264
|
+
if (!tab || tab.closed) {
|
|
265
|
+
fail("tab_not_found", `tab ${tabId} not found`);
|
|
266
|
+
}
|
|
267
|
+
state.focusedTabId = tabId;
|
|
268
|
+
saveState(statePath, state);
|
|
269
|
+
ok({ result: { type: "ok" } });
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (group === "tab" && action === "rename") {
|
|
273
|
+
const [tabId, label] = rest;
|
|
274
|
+
if (shouldFail("rename")) {
|
|
275
|
+
fail(failCode(), "fake rename failure");
|
|
276
|
+
}
|
|
277
|
+
const tab = state.tabs[tabId];
|
|
278
|
+
if (!tab || tab.closed) {
|
|
279
|
+
fail("tab_not_found", `tab ${tabId} not found`);
|
|
280
|
+
}
|
|
281
|
+
tab.customLabel = label;
|
|
282
|
+
saveState(statePath, state);
|
|
283
|
+
ok({ result: { type: "ok" } });
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (group === "tab" && action === "close") {
|
|
287
|
+
const [tabId] = rest;
|
|
288
|
+
const tab = state.tabs[tabId];
|
|
289
|
+
if (!tab || tab.closed) {
|
|
290
|
+
fail("tab_not_found", `tab ${tabId} not found`);
|
|
291
|
+
}
|
|
292
|
+
const isDefaultLabelled = tabDisplayLabel(state, tabId) === "1";
|
|
293
|
+
if (
|
|
294
|
+
shouldFail("close") ||
|
|
295
|
+
shouldFail("tab_create_and_close") ||
|
|
296
|
+
(shouldFail("reclaim") && isDefaultLabelled)
|
|
297
|
+
) {
|
|
298
|
+
fail(failCode(), "fake tab close failure");
|
|
299
|
+
}
|
|
300
|
+
closeTab(state, tabId);
|
|
301
|
+
saveState(statePath, state);
|
|
302
|
+
ok({ result: { type: "ok" } });
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (group === "pane" && action === "run") {
|
|
306
|
+
const [paneId] = rest;
|
|
307
|
+
if (shouldFail("run")) {
|
|
308
|
+
fail(failCode(), "fake run failure");
|
|
309
|
+
}
|
|
310
|
+
const pane = state.panes[paneId];
|
|
311
|
+
if (!pane) {
|
|
312
|
+
fail("pane_not_found", `no such pane: ${paneId}`);
|
|
313
|
+
}
|
|
314
|
+
pane.running = true;
|
|
315
|
+
pane.command = rest.slice(1).join(" ");
|
|
316
|
+
saveState(statePath, state);
|
|
317
|
+
ok();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (group === "pane" && action === "exit") {
|
|
321
|
+
const [paneId] = rest;
|
|
322
|
+
const pane = state.panes[paneId];
|
|
323
|
+
if (!pane || pane.closed) {
|
|
324
|
+
fail("pane_not_found", `no such pane: ${paneId}`);
|
|
325
|
+
}
|
|
326
|
+
pane.running = false;
|
|
327
|
+
saveState(statePath, state);
|
|
328
|
+
ok();
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (group === "pane" && action === "list") {
|
|
332
|
+
const workspaceIdx = rest.indexOf("--workspace");
|
|
333
|
+
const workspaceId = workspaceIdx >= 0 ? rest[workspaceIdx + 1] : undefined;
|
|
334
|
+
const panes = Object.entries(state.panes)
|
|
335
|
+
.filter(([, p]) => p.workspaceId === workspaceId && !p.closed)
|
|
336
|
+
.map(([pane_id, p]) => ({
|
|
337
|
+
pane_id,
|
|
338
|
+
tab_id: p.tabId,
|
|
339
|
+
workspace_id: p.workspaceId,
|
|
340
|
+
...(p.cwd !== undefined ? { cwd: p.cwd } : {}),
|
|
341
|
+
}));
|
|
342
|
+
ok({ result: { panes } });
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (group === "pane" && action === "process-info") {
|
|
346
|
+
const paneIdx = rest.indexOf("--pane");
|
|
347
|
+
const paneId = paneIdx >= 0 ? rest[paneIdx + 1] : undefined;
|
|
348
|
+
const pane = paneId ? state.panes[paneId] : undefined;
|
|
349
|
+
if (!pane || pane.closed) {
|
|
350
|
+
fail("pane_not_found", `no such pane: ${String(paneId)}`);
|
|
351
|
+
}
|
|
352
|
+
const shellPid = 1;
|
|
353
|
+
const foreground_processes = pane.running
|
|
354
|
+
? [{ pid: shellPid }, { pid: 2 }]
|
|
355
|
+
: [{ pid: shellPid }];
|
|
356
|
+
ok({ result: { process_info: { shell_pid: shellPid, foreground_processes } } });
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (group === "pane" && action === "close") {
|
|
360
|
+
if (shouldFail("close")) {
|
|
361
|
+
fail(failCode(), "fake pane close failure");
|
|
362
|
+
}
|
|
363
|
+
const [paneId] = rest;
|
|
364
|
+
const pane = state.panes[paneId];
|
|
365
|
+
if (!pane || pane.closed) {
|
|
366
|
+
fail("pane_not_found", `no such pane: ${paneId}`);
|
|
367
|
+
}
|
|
368
|
+
closePane(state, paneId);
|
|
369
|
+
saveState(statePath, state);
|
|
370
|
+
ok();
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (group === "worktree" && action === "create") {
|
|
374
|
+
if (shouldFail("worktree_create")) {
|
|
375
|
+
fail(failCode(), "fake worktree create failure");
|
|
376
|
+
}
|
|
377
|
+
const cwdIdx = rest.indexOf("--cwd");
|
|
378
|
+
const branchIdx = rest.indexOf("--branch");
|
|
379
|
+
const pathIdx = rest.indexOf("--path");
|
|
380
|
+
const labelIdx = rest.indexOf("--label");
|
|
381
|
+
const cwd = cwdIdx >= 0 ? rest[cwdIdx + 1] : undefined;
|
|
382
|
+
const branch = branchIdx >= 0 ? rest[branchIdx + 1] : undefined;
|
|
383
|
+
const worktreePath = pathIdx >= 0 ? rest[pathIdx + 1] : undefined;
|
|
384
|
+
const label = labelIdx >= 0 ? rest[labelIdx + 1] : branch;
|
|
385
|
+
if (!cwd || !branch || !worktreePath) {
|
|
386
|
+
fail("invalid_args", "worktree create requires --cwd, --branch and --path");
|
|
387
|
+
}
|
|
388
|
+
mkdirSync(path.dirname(worktreePath), { recursive: true });
|
|
389
|
+
try {
|
|
390
|
+
execFileSync("git", ["-C", cwd, "worktree", "add", worktreePath, "-b", branch], {
|
|
391
|
+
stdio: "pipe",
|
|
392
|
+
});
|
|
393
|
+
} catch {
|
|
394
|
+
try {
|
|
395
|
+
execFileSync("git", ["-C", cwd, "worktree", "add", worktreePath, branch], {
|
|
396
|
+
stdio: "pipe",
|
|
397
|
+
});
|
|
398
|
+
} catch (err) {
|
|
399
|
+
fail("worktree_create_failed", err instanceof Error ? err.message : String(err));
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
const id = state.nextId++;
|
|
403
|
+
const workspaceId = `ws-wt-${String(id)}`;
|
|
404
|
+
state.worktrees[workspaceId] = {
|
|
405
|
+
repoPath: cwd,
|
|
406
|
+
worktreePath,
|
|
407
|
+
branchName: branch,
|
|
408
|
+
label,
|
|
409
|
+
closed: false,
|
|
410
|
+
};
|
|
411
|
+
openWorkspace(state, workspaceId, { label, cwd: worktreePath, checkoutPath: worktreePath });
|
|
412
|
+
saveState(statePath, state);
|
|
413
|
+
ok({
|
|
414
|
+
result: {
|
|
415
|
+
workspace: { workspace_id: workspaceId },
|
|
416
|
+
worktree: { path: worktreePath, branch },
|
|
417
|
+
},
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (group === "worktree" && action === "list") {
|
|
422
|
+
const cwdIdx = rest.indexOf("--cwd");
|
|
423
|
+
const cwd = cwdIdx >= 0 ? rest[cwdIdx + 1] : undefined;
|
|
424
|
+
const worktrees = Object.entries(state.worktrees)
|
|
425
|
+
.filter(([, w]) => w.repoPath === cwd)
|
|
426
|
+
.map(([workspace_id, w]) => ({
|
|
427
|
+
path: w.worktreePath,
|
|
428
|
+
branch: w.branchName,
|
|
429
|
+
...(w.closed ? {} : { open_workspace_id: workspace_id }),
|
|
430
|
+
}));
|
|
431
|
+
ok({ result: { worktrees } });
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (group === "worktree" && action === "remove") {
|
|
435
|
+
const workspaceIdx = rest.indexOf("--workspace");
|
|
436
|
+
const workspaceId = workspaceIdx >= 0 ? rest[workspaceIdx + 1] : undefined;
|
|
437
|
+
const worktree = workspaceId ? state.worktrees[workspaceId] : undefined;
|
|
438
|
+
if (!worktree || worktree.closed) {
|
|
439
|
+
fail("workspace_not_found", `no such workspace: ${String(workspaceId)}`);
|
|
440
|
+
}
|
|
441
|
+
if (shouldFail("worktree_remove")) {
|
|
442
|
+
fail(failCode(), "fake worktree remove failure");
|
|
443
|
+
}
|
|
444
|
+
try {
|
|
445
|
+
execFileSync(
|
|
446
|
+
"git",
|
|
447
|
+
["-C", worktree.repoPath, "worktree", "remove", worktree.worktreePath, "--force"],
|
|
448
|
+
{
|
|
449
|
+
stdio: "pipe",
|
|
450
|
+
},
|
|
451
|
+
);
|
|
452
|
+
} catch (err) {
|
|
453
|
+
const stderr = err.stderr?.toString() ?? "";
|
|
454
|
+
if (!/is not a working tree|not a valid path/.test(stderr)) {
|
|
455
|
+
fail("worktree_remove_failed", err instanceof Error ? err.message : String(err));
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
worktree.closed = true;
|
|
459
|
+
closeWorkspace(state, workspaceId);
|
|
460
|
+
saveState(statePath, state);
|
|
461
|
+
ok({ result: {} });
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
console.error(`fake-herdr: unrecognized command: ${argv.join(" ")}`);
|
|
465
|
+
process.exit(2);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
main();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// ABOUTME: Stand-in for the real `opencode` CLI, used by wrapper.sh and workflow tests. Emits the
|
|
3
|
+
// ABOUTME: NDJSON event stream `opencode run --format json` prints, with a fixed session id.
|
|
4
|
+
const argv = process.argv.slice(2);
|
|
5
|
+
const doubleDashIndex = argv.indexOf("--");
|
|
6
|
+
const prompt = doubleDashIndex === -1 ? "" : argv.slice(doubleDashIndex + 1).join(" ");
|
|
7
|
+
|
|
8
|
+
const sessionID = "ses_fake";
|
|
9
|
+
|
|
10
|
+
let tick = 0;
|
|
11
|
+
function emit(event) {
|
|
12
|
+
tick += 1;
|
|
13
|
+
process.stdout.write(`${JSON.stringify({ ...event, timestamp: tick, sessionID })}\n`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
emit({ type: "step_start", part: { type: "step-start" } });
|
|
17
|
+
emit({
|
|
18
|
+
type: "text",
|
|
19
|
+
part: { id: "prt_fake_text", type: "text", text: "Let me look at the working directory." },
|
|
20
|
+
});
|
|
21
|
+
emit({
|
|
22
|
+
type: "tool_use",
|
|
23
|
+
part: {
|
|
24
|
+
id: "prt_fake_tool",
|
|
25
|
+
type: "tool",
|
|
26
|
+
tool: "bash",
|
|
27
|
+
callID: "call_fake_0001",
|
|
28
|
+
state: {
|
|
29
|
+
status: "completed",
|
|
30
|
+
input: { command: "ls" },
|
|
31
|
+
output: "fake-work.txt\n",
|
|
32
|
+
title: "ls",
|
|
33
|
+
metadata: { exit: 0 },
|
|
34
|
+
time: { start: 1, end: 2 },
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
emit({
|
|
39
|
+
type: "text",
|
|
40
|
+
part: { id: "prt_fake_result", type: "text", text: `fake result for: ${prompt.trim()}` },
|
|
41
|
+
});
|
|
42
|
+
emit({
|
|
43
|
+
type: "step_finish",
|
|
44
|
+
part: { id: "prt_fake_finish", type: "step-finish", reason: "stop", cost: 0.01 },
|
|
45
|
+
});
|
package/dist/agents.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAUA,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC"}
|
package/dist/agents.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// ABOUTME: Path resolvers for the fake claude/opencode/herdr/argv-recorder executables shipped in bin/,
|
|
2
|
+
// ABOUTME: resolved via import.meta.url so they work whether this module runs from src/ or dist/.
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
function binDir() {
|
|
6
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
return path.join(here, "..", "bin");
|
|
8
|
+
}
|
|
9
|
+
export function fakeClaudePath() {
|
|
10
|
+
return path.join(binDir(), "fake-claude.mjs");
|
|
11
|
+
}
|
|
12
|
+
export function fakeOpencodePath() {
|
|
13
|
+
return path.join(binDir(), "fake-opencode.mjs");
|
|
14
|
+
}
|
|
15
|
+
export function fakeHerdrPath() {
|
|
16
|
+
return path.join(binDir(), "fake-herdr.mjs");
|
|
17
|
+
}
|
|
18
|
+
export function argvRecorderPath() {
|
|
19
|
+
return path.join(binDir(), "argv-recorder.mjs");
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=agents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,kGAAkG;AAClG,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,SAAS,MAAM;IACb,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,iBAAiB,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,mBAAmB,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,gBAAgB,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,mBAAmB,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface FakeBitbucketRequest {
|
|
2
|
+
readonly method: string;
|
|
3
|
+
readonly path: string;
|
|
4
|
+
readonly query: Readonly<Record<string, string>>;
|
|
5
|
+
readonly queryAll: Readonly<Record<string, readonly string[]>>;
|
|
6
|
+
readonly headers: Readonly<Record<string, string | string[] | undefined>>;
|
|
7
|
+
readonly body: unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface FakeBitbucketResponse {
|
|
10
|
+
readonly status?: number;
|
|
11
|
+
readonly body?: unknown;
|
|
12
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
13
|
+
readonly delayMs?: number;
|
|
14
|
+
}
|
|
15
|
+
export type FakeBitbucketHandler = FakeBitbucketResponse | FakeBitbucketResponse[] | ((req: FakeBitbucketRequest) => FakeBitbucketResponse | Promise<FakeBitbucketResponse>);
|
|
16
|
+
export interface FakeBitbucket {
|
|
17
|
+
readonly origin: string;
|
|
18
|
+
readonly apiUrl: string;
|
|
19
|
+
readonly requests: readonly FakeBitbucketRequest[];
|
|
20
|
+
repositoryUrl(workspace: string, repoSlug: string): string;
|
|
21
|
+
pullRequestUrl(workspace: string, repoSlug: string, id: number): string;
|
|
22
|
+
respond(method: string, path: string, handler: FakeBitbucketHandler): void;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare function startFakeBitbucket(): Promise<FakeBitbucket>;
|
|
26
|
+
//# sourceMappingURL=bitbucket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitbucket.d.ts","sourceRoot":"","sources":["../src/bitbucket.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACjD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;IAC/D,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC;IAC1E,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,MAAM,oBAAoB,GAC5B,qBAAqB,GACrB,qBAAqB,EAAE,GACvB,CAAC,CAAC,GAAG,EAAE,oBAAoB,KAAK,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC;AAE5F,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,SAAS,oBAAoB,EAAE,CAAC;IACnD,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3D,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACxE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC3E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AA8CD,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,aAAa,CAAC,CA0IjE"}
|