@testsprite/testsprite-cli 0.15.0 → 0.17.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 +53 -141
- package/dist/commands/agent.d.ts +12 -4
- package/dist/commands/agent.js +55 -65
- package/dist/commands/auth.d.ts +6 -10
- package/dist/commands/auth.js +44 -56
- package/dist/commands/ci.d.ts +23 -100
- package/dist/commands/ci.js +297 -489
- package/dist/commands/completion.js +2 -1
- package/dist/commands/conversation.d.ts +27 -0
- package/dist/commands/conversation.js +702 -0
- package/dist/commands/doctor.d.ts +5 -1
- package/dist/commands/doctor.js +130 -34
- package/dist/commands/init.d.ts +4 -45
- package/dist/commands/init.js +116 -68
- package/dist/commands/project-env.d.ts +62 -2
- package/dist/commands/project-env.js +426 -53
- package/dist/commands/project-sign-in.d.ts +0 -48
- package/dist/commands/project-sign-in.js +1 -224
- package/dist/commands/project.d.ts +15 -186
- package/dist/commands/project.js +93 -921
- package/dist/commands/result.d.ts +10 -0
- package/dist/commands/result.js +215 -0
- package/dist/commands/schedule.d.ts +0 -29
- package/dist/commands/schedule.js +47 -97
- package/dist/commands/test.d.ts +315 -1824
- package/dist/commands/test.js +1962 -13733
- package/dist/commands/testlist.d.ts +128 -5
- package/dist/commands/testlist.js +269 -329
- package/dist/commands/tunnel.d.ts +2 -2
- package/dist/commands/tunnel.js +43 -41
- package/dist/commands/usage.d.ts +12 -45
- package/dist/commands/usage.js +51 -131
- package/dist/index.js +189 -108
- package/dist/lib/agent-detect.js +9 -5
- package/dist/lib/agent-targets.d.ts +21 -2
- package/dist/lib/agent-targets.js +88 -11
- package/dist/lib/args.d.ts +13 -0
- package/dist/lib/args.js +49 -0
- package/dist/lib/basic-auth.d.ts +3 -0
- package/dist/lib/basic-auth.js +15 -0
- package/dist/lib/billing-refusal.js +4 -3
- package/dist/lib/ci-linkage.d.ts +4 -82
- package/dist/lib/ci-linkage.js +4 -157
- package/dist/lib/ci-run.js +1 -1
- package/dist/lib/client-factory.d.ts +10 -2
- package/dist/lib/client-factory.js +38 -26
- package/dist/lib/commit-signal.d.ts +65 -0
- package/dist/lib/commit-signal.js +305 -0
- package/dist/lib/concurrency-limiter.d.ts +6 -0
- package/dist/lib/concurrency-limiter.js +29 -0
- package/dist/lib/config.js +10 -5
- package/dist/lib/conflict-reason.d.ts +31 -4
- package/dist/lib/conflict-reason.js +38 -4
- package/dist/lib/conversation/answers.d.ts +9 -0
- package/dist/lib/conversation/answers.js +49 -0
- package/dist/lib/conversation/api.d.ts +71 -0
- package/dist/lib/conversation/api.js +150 -0
- package/dist/lib/conversation/change.d.ts +31 -0
- package/dist/lib/conversation/change.js +124 -0
- package/dist/lib/conversation/context.d.ts +19 -0
- package/dist/lib/conversation/context.js +70 -0
- package/dist/lib/conversation/environment.d.ts +15 -0
- package/dist/lib/conversation/environment.js +33 -0
- package/dist/lib/conversation/follow.d.ts +24 -0
- package/dist/lib/conversation/follow.js +42 -0
- package/dist/lib/conversation/render.d.ts +33 -0
- package/dist/lib/conversation/render.js +315 -0
- package/dist/lib/conversation/title.d.ts +2 -0
- package/dist/lib/conversation/title.js +18 -0
- package/dist/lib/conversation/types.d.ts +156 -0
- package/dist/lib/conversation/types.js +6 -0
- package/dist/lib/credentials.js +67 -11
- package/dist/lib/cron.d.ts +1 -1
- package/dist/lib/cron.js +2 -2
- package/dist/lib/dispatch-stop.d.ts +20 -0
- package/dist/lib/dispatch-stop.js +30 -0
- package/dist/lib/download.d.ts +71 -0
- package/dist/lib/download.js +274 -0
- package/dist/lib/dry-run/fetch.d.ts +10 -0
- package/dist/lib/dry-run/fetch.js +20 -0
- package/dist/lib/dry-run/samples.d.ts +6 -34
- package/dist/lib/dry-run/samples.js +389 -751
- package/dist/lib/environment-tunnel.d.ts +16 -26
- package/dist/lib/environment-tunnel.js +161 -157
- package/dist/lib/errors.d.ts +20 -4
- package/dist/lib/errors.js +36 -16
- package/dist/lib/facade.d.ts +7 -29
- package/dist/lib/facade.js +7 -36
- package/dist/lib/failing-fe-resolver.d.ts +13 -58
- package/dist/lib/failing-fe-resolver.js +47 -132
- package/dist/lib/first-suite-hint.d.ts +16 -22
- package/dist/lib/first-suite-hint.js +38 -47
- package/dist/lib/gh-output.d.ts +76 -21
- package/dist/lib/gh-output.js +171 -90
- package/dist/lib/git-utils.d.ts +56 -0
- package/dist/lib/git-utils.js +212 -0
- package/dist/lib/github-context.d.ts +2 -0
- package/dist/lib/github-context.js +40 -8
- package/dist/lib/history-retention.d.ts +6 -2
- package/dist/lib/history-retention.js +10 -7
- package/dist/lib/http.d.ts +58 -134
- package/dist/lib/http.js +352 -271
- package/dist/lib/interrupt.d.ts +14 -8
- package/dist/lib/interrupt.js +28 -10
- package/dist/lib/junit-report.d.ts +60 -4
- package/dist/lib/junit-report.js +209 -32
- package/dist/lib/local-target.d.ts +3 -3
- package/dist/lib/local-target.js +3 -3
- package/dist/lib/output.d.ts +0 -29
- package/dist/lib/output.js +10 -33
- package/dist/lib/pagination.d.ts +2 -5
- package/dist/lib/pagination.js +2 -5
- package/dist/lib/presigned-url.d.ts +22 -0
- package/dist/lib/presigned-url.js +90 -0
- package/dist/lib/prompt.js +36 -2
- package/dist/lib/proxy.js +2 -1
- package/dist/lib/redact.d.ts +2 -2
- package/dist/lib/redact.js +3 -4
- package/dist/lib/removed-commands.d.ts +18 -0
- package/dist/lib/removed-commands.js +154 -0
- package/dist/lib/render-error.d.ts +31 -6
- package/dist/lib/render-error.js +88 -25
- package/dist/lib/response-schemas.d.ts +38 -30
- package/dist/lib/response-schemas.js +210 -207
- package/dist/lib/result/api.d.ts +24 -0
- package/dist/lib/result/api.js +28 -0
- package/dist/lib/result/evidence.d.ts +71 -0
- package/dist/lib/result/evidence.js +420 -0
- package/dist/lib/result/render.d.ts +20 -0
- package/dist/lib/result/render.js +194 -0
- package/dist/lib/result/types.d.ts +122 -0
- package/dist/lib/result/types.js +19 -0
- package/dist/lib/run-output.d.ts +275 -0
- package/dist/lib/run-output.js +227 -0
- package/dist/lib/run-render.d.ts +101 -0
- package/dist/lib/run-render.js +183 -0
- package/dist/lib/run-wait.d.ts +192 -0
- package/dist/lib/run-wait.js +452 -0
- package/dist/lib/runs.types.d.ts +134 -367
- package/dist/lib/runs.types.js +0 -14
- package/dist/lib/secret-file.d.ts +1 -1
- package/dist/lib/secret-file.js +11 -2
- package/dist/lib/skill-nudge.d.ts +7 -27
- package/dist/lib/skill-nudge.js +9 -37
- package/dist/lib/target-path.d.ts +15 -0
- package/dist/lib/target-path.js +35 -0
- package/dist/lib/target-url-advisory.d.ts +19 -0
- package/dist/lib/target-url-advisory.js +31 -0
- package/dist/lib/target-url-preflight.d.ts +9 -0
- package/dist/lib/target-url-preflight.js +214 -106
- package/dist/lib/target-url.d.ts +1 -1
- package/dist/lib/target-url.js +6 -16
- package/dist/lib/telemetry.d.ts +32 -12
- package/dist/lib/telemetry.js +39 -8
- package/dist/lib/terminal-text.d.ts +41 -0
- package/dist/lib/terminal-text.js +127 -0
- package/dist/lib/testlist.types.d.ts +16 -8
- package/dist/lib/testlist.types.js +1 -1
- package/dist/lib/text-equality.d.ts +2 -0
- package/dist/lib/text-equality.js +5 -0
- package/dist/lib/text-file.d.ts +16 -0
- package/dist/lib/text-file.js +41 -0
- package/dist/lib/text-table.d.ts +46 -0
- package/dist/lib/text-table.js +72 -4
- package/dist/lib/ticker.d.ts +9 -2
- package/dist/lib/ticker.js +16 -3
- package/dist/lib/transport-failure.d.ts +22 -0
- package/dist/lib/transport-failure.js +126 -0
- package/dist/lib/tunnel-session.d.ts +7 -1
- package/dist/lib/tunnel-session.js +22 -9
- package/dist/lib/update-check.js +3 -2
- package/dist/lib/url-template.d.ts +43 -0
- package/dist/lib/url-template.js +151 -0
- package/dist/lib/validate.d.ts +0 -64
- package/dist/lib/validate.js +2 -131
- package/dist/lib/version-notice.js +4 -3
- package/dist/lib/wait-exit.d.ts +37 -2
- package/dist/lib/wait-exit.js +88 -30
- package/dist/lib/workspace-status.js +10 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -4
- package/skills/testsprite-ci.skill.md +48 -18
- package/skills/testsprite-onboard.skill.md +66 -151
- package/skills/testsprite-verify.codex.md +54 -56
- package/skills/testsprite-verify.skill.md +194 -358
- package/dist/lib/browser.d.ts +0 -6
- package/dist/lib/browser.js +0 -54
- package/dist/lib/bundle.d.ts +0 -234
- package/dist/lib/bundle.js +0 -781
- package/dist/lib/deprecate.d.ts +0 -10
- package/dist/lib/deprecate.js +0 -13
- package/dist/lib/flaky.d.ts +0 -91
- package/dist/lib/flaky.js +0 -71
- package/dist/lib/plan-poll.d.ts +0 -171
- package/dist/lib/plan-poll.js +0 -441
- package/dist/lib/plans.types.d.ts +0 -130
- package/dist/lib/plans.types.js +0 -31
- package/dist/lib/poll.d.ts +0 -100
- package/dist/lib/poll.js +0 -290
- package/dist/lib/rate-throttle.d.ts +0 -49
- package/dist/lib/rate-throttle.js +0 -75
- package/dist/lib/run-progress.d.ts +0 -41
- package/dist/lib/run-progress.js +0 -56
- package/dist/lib/v3-advisory.d.ts +0 -55
- package/dist/lib/v3-advisory.js +0 -74
- package/schemas/plan.schema.json +0 -61
package/dist/lib/deprecate.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared helper for the hidden, deprecated command aliases introduced by the
|
|
3
|
-
* setup consolidation (`init`/`auth configure`/`auth whoami`/`auth logout`).
|
|
4
|
-
*
|
|
5
|
-
* The aliases are hidden from `--help` (so a coding agent never sees the old
|
|
6
|
-
* names) but still work (so existing scripts and any agent trained on the old
|
|
7
|
-
* commands keep running). When invoked, they print this one-line notice to
|
|
8
|
-
* stderr — stdout stays clean so JSON pipelines are unaffected.
|
|
9
|
-
*/
|
|
10
|
-
export declare function emitDeprecationNotice(oldCmd: string, newCmd: string, stderr?: (line: string) => void): void;
|
package/dist/lib/deprecate.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared helper for the hidden, deprecated command aliases introduced by the
|
|
3
|
-
* setup consolidation (`init`/`auth configure`/`auth whoami`/`auth logout`).
|
|
4
|
-
*
|
|
5
|
-
* The aliases are hidden from `--help` (so a coding agent never sees the old
|
|
6
|
-
* names) but still work (so existing scripts and any agent trained on the old
|
|
7
|
-
* commands keep running). When invoked, they print this one-line notice to
|
|
8
|
-
* stderr — stdout stays clean so JSON pipelines are unaffected.
|
|
9
|
-
*/
|
|
10
|
-
export function emitDeprecationNotice(oldCmd, newCmd, stderr = (line) => process.stderr.write(`${line}\n`)) {
|
|
11
|
-
stderr(`[deprecated] \`testsprite ${oldCmd}\` is deprecated — use \`testsprite ${newCmd}\`.`);
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=deprecate.js.map
|
package/dist/lib/flaky.d.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure aggregation + rendering for `test flaky` — the repeat-run flaky-test
|
|
3
|
-
* detector. This module performs no I/O: the orchestrator in
|
|
4
|
-
* `commands/test.ts` feeds it the per-attempt outcomes, and it returns a
|
|
5
|
-
* machine-readable stability report plus the text rendering and exit code.
|
|
6
|
-
*
|
|
7
|
-
* Keeping the scoring logic pure makes it trivially unit-testable in isolation
|
|
8
|
-
* (deterministic, no network / credentials), matching the repo's mock-based
|
|
9
|
-
* test convention.
|
|
10
|
-
*/
|
|
11
|
-
import type { RerunAdvisory } from './runs.types.js';
|
|
12
|
-
/**
|
|
13
|
-
* Outcome of a single flaky-detector attempt. The first four mirror the
|
|
14
|
-
* terminal `RunStatus` values; `timeout` and `error` are orchestration
|
|
15
|
-
* outcomes (per-attempt deadline exceeded, or a non-fatal trigger/transport
|
|
16
|
-
* error that was recorded rather than aborting the whole probe).
|
|
17
|
-
*/
|
|
18
|
-
export type FlakyOutcome = 'passed' | 'failed' | 'blocked' | 'cancelled' | 'timeout' | 'error';
|
|
19
|
-
/** Overall stability verdict across all observed attempts. */
|
|
20
|
-
export type FlakyVerdict = 'stable' | 'flaky' | 'failing';
|
|
21
|
-
/** One recorded attempt in a flaky run. */
|
|
22
|
-
export interface FlakyAttempt {
|
|
23
|
-
/** 1-based attempt index. */
|
|
24
|
-
attempt: number;
|
|
25
|
-
/** The runId of this attempt, or `null` when the trigger never returned one. */
|
|
26
|
-
runId: string | null;
|
|
27
|
-
outcome: FlakyOutcome;
|
|
28
|
-
/**
|
|
29
|
-
* Server `failureKind` for non-passing runs (or the error code for `error`
|
|
30
|
-
* outcomes). `null` / omitted when the attempt passed or the kind is unknown.
|
|
31
|
-
*/
|
|
32
|
-
failureKind?: string | null;
|
|
33
|
-
}
|
|
34
|
-
/** A single non-passing attempt as surfaced in the report. */
|
|
35
|
-
export interface FlakyFailure {
|
|
36
|
-
attempt: number;
|
|
37
|
-
runId: string | null;
|
|
38
|
-
outcome: FlakyOutcome;
|
|
39
|
-
failureKind: string | null;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Machine-readable stability report. This is also the exact `--output json`
|
|
43
|
-
* shape, so dashboards / agents / CI can consume it directly.
|
|
44
|
-
*/
|
|
45
|
-
export interface FlakyReport {
|
|
46
|
-
testId: string;
|
|
47
|
-
/**
|
|
48
|
-
* Attempts actually observed. May be fewer than requested when
|
|
49
|
-
* `--until-fail` short-circuits on the first non-passing attempt.
|
|
50
|
-
*/
|
|
51
|
-
runs: number;
|
|
52
|
-
passed: number;
|
|
53
|
-
failed: number;
|
|
54
|
-
/** `passed / runs`, rounded to 4 decimal places. `0` when `runs === 0`. */
|
|
55
|
-
stableRatio: number;
|
|
56
|
-
verdict: FlakyVerdict;
|
|
57
|
-
/** Non-passing attempts, in attempt order. */
|
|
58
|
-
failures: FlakyFailure[];
|
|
59
|
-
/**
|
|
60
|
-
* Server-side advisories collected across all replay attempts and deduped
|
|
61
|
-
* (by `feature`+`message`) — surfaced ONCE per probe, not once per attempt.
|
|
62
|
-
* Empty when the server sent none, which is the common case: absent on
|
|
63
|
-
* every V2 response and every V3 response that isn't a V3-routed rerun
|
|
64
|
-
* with an explicit `autoHeal:false` opt-out (see `RerunAdvisory`). `test
|
|
65
|
-
* flaky` always sends `autoHeal:false`, so this is populated whenever the
|
|
66
|
-
* probe's reruns are routed to V3.
|
|
67
|
-
*/
|
|
68
|
-
advisories: RerunAdvisory[];
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Aggregate per-attempt outcomes into a stability report.
|
|
72
|
-
*
|
|
73
|
-
* Verdict rules:
|
|
74
|
-
* - every attempt passed → `stable`
|
|
75
|
-
* - no attempt passed → `failing`
|
|
76
|
-
* - a mix of pass and non-pass → `flaky`
|
|
77
|
-
* An empty attempt list (no runs observed) is reported as `failing` with a
|
|
78
|
-
* `0` ratio — there is no evidence the test is stable.
|
|
79
|
-
*/
|
|
80
|
-
export declare function summarizeFlaky(testId: string, attempts: FlakyAttempt[], advisories?: RerunAdvisory[]): FlakyReport;
|
|
81
|
-
/**
|
|
82
|
-
* Exit code for the command: `0` only when the verdict is `stable` (every
|
|
83
|
-
* observed attempt passed). Anything else is non-zero so CI can gate a merge
|
|
84
|
-
* on flakiness (`testsprite test flaky <id> --runs 5 || exit 1`).
|
|
85
|
-
*/
|
|
86
|
-
export declare function flakyExitCode(report: FlakyReport): number;
|
|
87
|
-
/**
|
|
88
|
-
* Render a report to human-readable text. JSON-mode callers ship the report
|
|
89
|
-
* verbatim via `out.print`; this is the text-mode rendering.
|
|
90
|
-
*/
|
|
91
|
-
export declare function renderFlakyText(report: FlakyReport): string;
|
package/dist/lib/flaky.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Aggregate per-attempt outcomes into a stability report.
|
|
3
|
-
*
|
|
4
|
-
* Verdict rules:
|
|
5
|
-
* - every attempt passed → `stable`
|
|
6
|
-
* - no attempt passed → `failing`
|
|
7
|
-
* - a mix of pass and non-pass → `flaky`
|
|
8
|
-
* An empty attempt list (no runs observed) is reported as `failing` with a
|
|
9
|
-
* `0` ratio — there is no evidence the test is stable.
|
|
10
|
-
*/
|
|
11
|
-
export function summarizeFlaky(testId, attempts, advisories = []) {
|
|
12
|
-
const runs = attempts.length;
|
|
13
|
-
const passed = attempts.filter(a => a.outcome === 'passed').length;
|
|
14
|
-
const failed = runs - passed;
|
|
15
|
-
const stableRatio = runs === 0 ? 0 : Math.round((passed / runs) * 10000) / 10000;
|
|
16
|
-
const verdict = runs > 0 && passed === runs ? 'stable' : passed === 0 ? 'failing' : 'flaky';
|
|
17
|
-
const failures = attempts
|
|
18
|
-
.filter(a => a.outcome !== 'passed')
|
|
19
|
-
.map(a => ({
|
|
20
|
-
attempt: a.attempt,
|
|
21
|
-
runId: a.runId,
|
|
22
|
-
outcome: a.outcome,
|
|
23
|
-
failureKind: a.failureKind ?? null,
|
|
24
|
-
}));
|
|
25
|
-
return { testId, runs, passed, failed, stableRatio, verdict, failures, advisories };
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Exit code for the command: `0` only when the verdict is `stable` (every
|
|
29
|
-
* observed attempt passed). Anything else is non-zero so CI can gate a merge
|
|
30
|
-
* on flakiness (`testsprite test flaky <id> --runs 5 || exit 1`).
|
|
31
|
-
*/
|
|
32
|
-
export function flakyExitCode(report) {
|
|
33
|
-
return report.verdict === 'stable' ? 0 : 1;
|
|
34
|
-
}
|
|
35
|
-
/** Human-readable label for a verdict. */
|
|
36
|
-
function verdictLabel(verdict) {
|
|
37
|
-
switch (verdict) {
|
|
38
|
-
case 'stable':
|
|
39
|
-
return 'STABLE';
|
|
40
|
-
case 'flaky':
|
|
41
|
-
return 'FLAKY';
|
|
42
|
-
case 'failing':
|
|
43
|
-
return 'FAILING';
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Render a report to human-readable text. JSON-mode callers ship the report
|
|
48
|
-
* verbatim via `out.print`; this is the text-mode rendering.
|
|
49
|
-
*/
|
|
50
|
-
export function renderFlakyText(report) {
|
|
51
|
-
const pct = Math.round(report.stableRatio * 100);
|
|
52
|
-
const lines = [
|
|
53
|
-
`Ran ${report.testId} ${report.runs}x — ${report.passed} passed, ${report.failed} failed → ` +
|
|
54
|
-
`${verdictLabel(report.verdict)} (${pct}% stable)`,
|
|
55
|
-
];
|
|
56
|
-
if (report.failures.length > 0) {
|
|
57
|
-
lines.push(' failed attempts:');
|
|
58
|
-
for (const f of report.failures) {
|
|
59
|
-
const kind = f.failureKind ? ` failureKind=${f.failureKind}` : '';
|
|
60
|
-
const rid = f.runId ?? '(no runId)';
|
|
61
|
-
lines.push(` #${f.attempt} ${rid} ${f.outcome}${kind}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (report.advisories.length > 0) {
|
|
65
|
-
for (const advisory of report.advisories) {
|
|
66
|
-
lines.push(` [advisory] ${advisory.message}`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return lines.join('\n');
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=flaky.js.map
|
package/dist/lib/plan-poll.d.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generation-ladder driver for `test plan generate`.
|
|
3
|
-
*
|
|
4
|
-
* This is a NEW loop, deliberately not a reuse of `poll.ts`: the run poller
|
|
5
|
-
* is hard-typed to runs (its `RunClient` contract, `isTerminalStatus` check,
|
|
6
|
-
* and `TimeoutError.runId` are all run-specific), while generation settles on
|
|
7
|
-
* a completely different state machine — the facade-synthesized
|
|
8
|
-
* `CliGenerationStatus` — and additionally has to RE-TRIGGER between stages
|
|
9
|
-
* (writes happen on POST; the read stays pure, so when a stage finishes while
|
|
10
|
-
* a later one is still missing the client must POST again to start it).
|
|
11
|
-
*
|
|
12
|
-
* What it shares with the run poller, by design:
|
|
13
|
-
*
|
|
14
|
-
* - **The shutdown handle is armed here** for the whole ladder (first POST
|
|
15
|
-
* included). Arm/disarm lives inside the run poller, not for free in the
|
|
16
|
-
* harness — without arming, Ctrl-C during a generate wait would hard-kill
|
|
17
|
-
* the process instead of running the honest-detach UX.
|
|
18
|
-
* - Long-poll preferred (`?waitSeconds = min(remaining, 25)`), with a
|
|
19
|
-
* plain-GET + fixed-sleep fallback when the server rejects `waitSeconds`
|
|
20
|
-
* with VALIDATION_ERROR (older deployment).
|
|
21
|
-
* - ONE session-scoped `AbortController` firing at the deadline plus a 2s
|
|
22
|
-
* transport cushion (a fixed absolute instant, so per-request minting
|
|
23
|
-
* would be pure churn), composed with the shutdown signal via explicit
|
|
24
|
-
* add/removeEventListener — NOT `AbortSignal.any`, whose dependent-signal
|
|
25
|
-
* tracking against the long-lived shutdown signal is the known
|
|
26
|
-
* FinalizationRegistry backlog. poll.ts CONTAINS that backlog by hoisting
|
|
27
|
-
* a single `.any()` per session (it still calls it); only http.ts
|
|
28
|
-
* eliminated it outright (`composeAbortSignals`). This module composes
|
|
29
|
-
* explicitly, like http.ts — don't go hunting for a poll.ts replacement
|
|
30
|
-
* that isn't there.
|
|
31
|
-
* A hung fetch can never overrun `--timeout` and an interrupt aborts the
|
|
32
|
-
* in-flight request instantly.
|
|
33
|
-
* - Every sleep is clamped to the remaining deadline and bails on interrupt.
|
|
34
|
-
*
|
|
35
|
-
* The deadline throws {@link PlanGenerationTimeoutError} — which, exactly
|
|
36
|
-
* like poll.ts's `TimeoutError`, is NOT a typed CLI error. The command layer
|
|
37
|
-
* must convert it into the typed exit-7 envelope (`code: 'UNSUPPORTED'`) the
|
|
38
|
-
* way every existing wait site does; letting it propagate raw would surface
|
|
39
|
-
* as a generic exit 1.
|
|
40
|
-
*
|
|
41
|
-
* ── Billing safety (why re-POSTs are guarded) ──────────────────────────────
|
|
42
|
-
*
|
|
43
|
-
* The proposals stage has NO server-side duplicate guard: a second append
|
|
44
|
-
* request wipes the staged batch, regenerates, and bills another 2 credits.
|
|
45
|
-
* The facade refuses to restart when it can SEE the stage (staged proposals,
|
|
46
|
-
* or in-flight per-feature flags) — but those flags are set asynchronously
|
|
47
|
-
* by the append listener, so a client that re-POSTs in the gap between
|
|
48
|
-
* "append accepted" and "flags visible" would still double-bill. Two ladder
|
|
49
|
-
* rules make that structurally impossible:
|
|
50
|
-
*
|
|
51
|
-
* 1. **Never re-POST after the proposals rung.** The trigger response names
|
|
52
|
-
* the remaining stages; when the last accepted trigger reported
|
|
53
|
-
* `stagesRemaining: []` there is no later stage a re-POST could start,
|
|
54
|
-
* so an idle-and-empty read just keeps polling.
|
|
55
|
-
* 2. **Dwell before any other re-POST.** A re-POST fires only once the
|
|
56
|
-
* started stage was actually observed running (it has genuinely
|
|
57
|
-
* finished), or after two consecutive idle reads (covering a stage that
|
|
58
|
-
* finished faster than our first poll). Exploration and strategy are
|
|
59
|
-
* server-idempotent (per-project ledger key / row lock), so a duplicate
|
|
60
|
-
* POST there wastes nothing even if the dwell heuristic misjudges.
|
|
61
|
-
*/
|
|
62
|
-
import { ApiError } from './errors.js';
|
|
63
|
-
import type { ShutdownHandle } from './interrupt.js';
|
|
64
|
-
import type { CliGeneratePlansResponse, CliGetPlansResponse } from './plans.types.js';
|
|
65
|
-
/**
|
|
66
|
-
* Minimal structural interface the ladder needs from the HTTP client —
|
|
67
|
-
* mirrors `RunClient` in poll.ts so tests supply a lightweight fake instead
|
|
68
|
-
* of the full `HttpClient`.
|
|
69
|
-
*/
|
|
70
|
-
export interface PlanLadderClient {
|
|
71
|
-
generatePlans(projectId: string, options: {
|
|
72
|
-
idempotencyKey: string;
|
|
73
|
-
signal?: AbortSignal;
|
|
74
|
-
}): Promise<CliGeneratePlansResponse>;
|
|
75
|
-
getPlans(projectId: string, options?: {
|
|
76
|
-
waitSeconds?: number;
|
|
77
|
-
signal?: AbortSignal;
|
|
78
|
-
}): Promise<CliGetPlansResponse>;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Thrown when the ladder's deadline elapses. NOT a typed CLI error — the
|
|
82
|
-
* command layer converts it to the exit-7 `UNSUPPORTED` envelope (see the
|
|
83
|
-
* module doc). Carries the last observed plans read so the caller can print
|
|
84
|
-
* an honest partial before exiting.
|
|
85
|
-
*/
|
|
86
|
-
export declare class PlanGenerationTimeoutError extends Error {
|
|
87
|
-
readonly projectId: string;
|
|
88
|
-
readonly timeoutSeconds: number;
|
|
89
|
-
readonly lastPlans: CliGetPlansResponse | null;
|
|
90
|
-
constructor(projectId: string, timeoutSeconds: number, lastPlans: CliGetPlansResponse | null);
|
|
91
|
-
}
|
|
92
|
-
export interface PlanLadderOptions {
|
|
93
|
-
/** Total wall-clock budget for the WHOLE ladder (all stages), in seconds. */
|
|
94
|
-
timeoutSeconds: number;
|
|
95
|
-
/**
|
|
96
|
-
* Idempotency key for the first trigger POST. Every later POST attempt —
|
|
97
|
-
* 409-attaches included — suffixes it (`<key>:post2`, `<key>:post3`, …):
|
|
98
|
-
* each POST is fresh work, so replaying an earlier POST's cached 202
|
|
99
|
-
* would silently never start the next stage.
|
|
100
|
-
*/
|
|
101
|
-
idempotencyKey: string;
|
|
102
|
-
/** Injectable sleep (tests use an instant fake). */
|
|
103
|
-
sleep?: (ms: number) => Promise<void>;
|
|
104
|
-
/**
|
|
105
|
-
* Graceful-detach coordinator. The ladder arms it for its whole
|
|
106
|
-
* duration; a SIGINT/SIGTERM surfaces as `InterruptError` out of this
|
|
107
|
-
* function and the caller renders the honest detach.
|
|
108
|
-
*/
|
|
109
|
-
shutdown?: ShutdownHandle;
|
|
110
|
-
/**
|
|
111
|
-
* Fired after every trigger POST outcome: an accepted stage start
|
|
112
|
-
* (`acceptedPosts` counts it) or the `nothing_to_start` answer. The
|
|
113
|
-
* command layer prints the first-run hint / credentials warning from the
|
|
114
|
-
* FIRST accepted response.
|
|
115
|
-
*/
|
|
116
|
-
onTrigger?: (response: CliGeneratePlansResponse, acceptedPosts: number) => void;
|
|
117
|
-
/** Fired when a trigger answered 409 `stage_in_flight` (attach + poll). */
|
|
118
|
-
onAttach?: (err: ApiError) => void;
|
|
119
|
-
/** Fired after every successful plans read (ticker updates). */
|
|
120
|
-
onTick?: (plans: CliGetPlansResponse, elapsedMs: number) => void;
|
|
121
|
-
/** Low-volume mode-switch messages (wired to stderr at `--verbose`). */
|
|
122
|
-
onTransition?: (msg: string) => void;
|
|
123
|
-
}
|
|
124
|
-
export interface PlanLadderResult {
|
|
125
|
-
/** The settled read: staged proposals (success), empty-idle, or `failed`. */
|
|
126
|
-
plans: CliGetPlansResponse;
|
|
127
|
-
/**
|
|
128
|
-
* The first ACCEPTED trigger response, or `null` when the ladder only ever
|
|
129
|
-
* attached to stages started elsewhere (409) or found the batch already
|
|
130
|
-
* staged (`nothing_to_start`).
|
|
131
|
-
*/
|
|
132
|
-
firstTrigger: CliGeneratePlansResponse | null;
|
|
133
|
-
/** How many trigger POSTs were accepted (stages this invocation started). */
|
|
134
|
-
acceptedPosts: number;
|
|
135
|
-
/**
|
|
136
|
-
* `skippedCategories` from the accepted trigger that carried it (the
|
|
137
|
-
* proposals rung), or `null` when no accepted trigger did. Read from the
|
|
138
|
-
* LAST such trigger, not `firstTrigger`: on a fresh backend project the
|
|
139
|
-
* first accepted POST starts strategy, and the field rides only on the
|
|
140
|
-
* proposals POST that follows.
|
|
141
|
-
*/
|
|
142
|
-
skippedCategories: number | null;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Hard cap on accepted trigger POSTs per invocation. The ladder has one rung
|
|
146
|
-
* per pipeline stage, so one more accepted POST than stages means the server
|
|
147
|
-
* keeps reporting "idle and nothing staged" after every stage was started — a
|
|
148
|
-
* contract violation worth failing loudly on instead of re-POSTing forever.
|
|
149
|
-
*/
|
|
150
|
-
export declare const MAX_ACCEPTED_TRIGGER_POSTS: 3;
|
|
151
|
-
/**
|
|
152
|
-
* Companion cap on TOTAL trigger POSTs (attaches included), so an
|
|
153
|
-
* attach-dominated pathological sequence also fails fast instead of
|
|
154
|
-
* silently burning the whole `--timeout`: the accepted rungs + headroom for
|
|
155
|
-
* an attach per rung.
|
|
156
|
-
*/
|
|
157
|
-
export declare const MAX_TRIGGER_POSTS_TOTAL: number;
|
|
158
|
-
/**
|
|
159
|
-
* Drive the generate ladder to a settled state: trigger the next missing
|
|
160
|
-
* stage, poll, re-trigger between stages, and return the settled plans read.
|
|
161
|
-
*
|
|
162
|
-
* @returns the settled read — the caller maps it to exit codes (staged
|
|
163
|
-
* proposals → 0, `failed` → 1) and renders it.
|
|
164
|
-
* @throws `PlanGenerationTimeoutError` when `timeoutSeconds` elapses (the
|
|
165
|
-
* caller converts to the typed exit-7 envelope).
|
|
166
|
-
* @throws `InterruptError` on SIGINT/SIGTERM while armed (the caller renders
|
|
167
|
-
* the honest detach and index.ts exits 128+signum).
|
|
168
|
-
* @throws `ApiError` for trigger/read failures (412 preconditions, 402
|
|
169
|
-
* credits, 404, 429 — already typed with their exit codes).
|
|
170
|
-
*/
|
|
171
|
-
export declare function runGenerationLadder(client: PlanLadderClient, projectId: string, options: PlanLadderOptions): Promise<PlanLadderResult>;
|