auto-harness-client 0.7.0 → 0.8.0
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/README.md +180 -0
- package/package.json +1 -1
- package/src/cli/args.js +17 -1
- package/src/cli/commands/attach-repository.js +117 -0
- package/src/cli/commands/detach-repository.js +109 -0
- package/src/cli/commands/host-repo-add.js +81 -0
- package/src/cli/commands/host-repo-rm.js +9 -86
- package/src/cli/commands/host-repo.js +7 -2
- package/src/cli/commands/host-smoke-format.js +30 -0
- package/src/cli/commands/host-smoke-poll.js +77 -0
- package/src/cli/commands/host-smoke-provider.js +172 -0
- package/src/cli/commands/host-smoke-repository.js +49 -0
- package/src/cli/commands/host-smoke-session-attempt.js +104 -0
- package/src/cli/commands/host-smoke-teardown.js +164 -0
- package/src/cli/commands/host-smoke.js +151 -0
- package/src/cli/commands/host.js +7 -1
- package/src/cli/commands/parse-worktree-flag.js +30 -0
- package/src/cli/commands/repo-add.js +38 -0
- package/src/cli/commands/repo.js +3 -0
- package/src/cli/commands/session-cancel.js +28 -0
- package/src/cli/commands/session-create.js +117 -0
- package/src/cli/commands/session-get.js +26 -0
- package/src/cli/commands/session-logs.js +65 -0
- package/src/cli/commands/session-target.js +29 -0
- package/src/cli/commands/session.js +22 -0
- package/src/cli/main.js +2 -0
- package/src/cli/session-format.js +15 -0
- package/src/cli/usage.js +17 -0
- package/src/cli/wait-for-session.js +46 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copied from `TERMINAL_SESSION_STATUSES` in modules/shared/src/constants.ts — this package is
|
|
2
|
+
// dependency-free (no `@auto-harness/shared` import), so the list is duplicated here rather than
|
|
3
|
+
// imported. Keep in sync if the shared list ever changes.
|
|
4
|
+
const TERMINAL_SESSION_STATUSES = ["completed", "failed", "cancelled", "timed_out"];
|
|
5
|
+
|
|
6
|
+
function defaultSleep(ms) {
|
|
7
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Polls `client.getSession(id)` until it reports a terminal status (see
|
|
12
|
+
* `TERMINAL_SESSION_STATUSES` above), or until `timeoutMs` elapses while the session is still
|
|
13
|
+
* active. The first fetch always happens, before the budget is even checked, so an
|
|
14
|
+
* already-terminal session resolves correctly even with a tiny `timeoutMs`. `onStatus(status,
|
|
15
|
+
* session)` fires once per *change* in status, including the first observed one — never on every
|
|
16
|
+
* poll — so a caller can stream progress (e.g. to stderr) without duplicate lines.
|
|
17
|
+
*
|
|
18
|
+
* Resolves — never rejects on a timeout — to `{ timedOut: false, session }` once terminal, or
|
|
19
|
+
* `{ timedOut: true, session }` (the last fetched, still-active record) once the budget elapses.
|
|
20
|
+
* This never cancels the session itself; the caller decides what a timeout means. A `getSession`
|
|
21
|
+
* rejection (a real API/network failure) propagates as-is.
|
|
22
|
+
*
|
|
23
|
+
* `sleep`/`now` are injectable so tests never really wait; `intervalMs` is clamped to the time
|
|
24
|
+
* remaining before `timeoutMs` on the final poll.
|
|
25
|
+
*/
|
|
26
|
+
export async function waitForSession(
|
|
27
|
+
client,
|
|
28
|
+
id,
|
|
29
|
+
{ timeoutMs, intervalMs, sleep = defaultSleep, now = Date.now, onStatus } = {},
|
|
30
|
+
) {
|
|
31
|
+
const deadline = now() + timeoutMs;
|
|
32
|
+
let lastStatus;
|
|
33
|
+
for (;;) {
|
|
34
|
+
const session = await client.getSession(id);
|
|
35
|
+
if (session.status !== lastStatus) {
|
|
36
|
+
lastStatus = session.status;
|
|
37
|
+
onStatus?.(session.status, session);
|
|
38
|
+
}
|
|
39
|
+
if (TERMINAL_SESSION_STATUSES.includes(session.status)) {
|
|
40
|
+
return { timedOut: false, session };
|
|
41
|
+
}
|
|
42
|
+
const remainingMs = deadline - now();
|
|
43
|
+
if (remainingMs <= 0) return { timedOut: true, session };
|
|
44
|
+
await sleep(Math.min(intervalMs, remainingMs));
|
|
45
|
+
}
|
|
46
|
+
}
|