@testsprite/testsprite-cli 0.1.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/LICENSE +201 -0
- package/README.md +190 -0
- package/dist/assets/agent-skill/testsprite-verify.codex.md +119 -0
- package/dist/assets/agent-skill/testsprite-verify.skill.md +423 -0
- package/dist/commands/agent.d.ts +51 -0
- package/dist/commands/agent.js +552 -0
- package/dist/commands/auth.d.ts +38 -0
- package/dist/commands/auth.js +247 -0
- package/dist/commands/init.d.ts +63 -0
- package/dist/commands/init.js +350 -0
- package/dist/commands/project.d.ts +72 -0
- package/dist/commands/project.js +400 -0
- package/dist/commands/test.d.ts +1245 -0
- package/dist/commands/test.js +6214 -0
- package/dist/commands/usage.d.ts +63 -0
- package/dist/commands/usage.js +156 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +146 -0
- package/dist/lib/agent-targets.d.ts +50 -0
- package/dist/lib/agent-targets.js +99 -0
- package/dist/lib/bundle.d.ts +178 -0
- package/dist/lib/bundle.js +600 -0
- package/dist/lib/client-factory.d.ts +72 -0
- package/dist/lib/client-factory.js +120 -0
- package/dist/lib/config.d.ts +24 -0
- package/dist/lib/config.js +30 -0
- package/dist/lib/credentials.d.ts +17 -0
- package/dist/lib/credentials.js +122 -0
- package/dist/lib/dry-run/fetch.d.ts +18 -0
- package/dist/lib/dry-run/fetch.js +52 -0
- package/dist/lib/dry-run/samples.d.ts +50 -0
- package/dist/lib/dry-run/samples.js +676 -0
- package/dist/lib/errors.d.ts +118 -0
- package/dist/lib/errors.js +388 -0
- package/dist/lib/facade.d.ts +48 -0
- package/dist/lib/facade.js +104 -0
- package/dist/lib/failing-fe-resolver.d.ts +60 -0
- package/dist/lib/failing-fe-resolver.js +103 -0
- package/dist/lib/http.d.ts +255 -0
- package/dist/lib/http.js +608 -0
- package/dist/lib/output.d.ts +55 -0
- package/dist/lib/output.js +70 -0
- package/dist/lib/pagination.d.ts +56 -0
- package/dist/lib/pagination.js +81 -0
- package/dist/lib/poll.d.ts +88 -0
- package/dist/lib/poll.js +221 -0
- package/dist/lib/prompt.d.ts +8 -0
- package/dist/lib/prompt.js +97 -0
- package/dist/lib/rate-throttle.d.ts +49 -0
- package/dist/lib/rate-throttle.js +75 -0
- package/dist/lib/render-error.d.ts +15 -0
- package/dist/lib/render-error.js +44 -0
- package/dist/lib/runs.types.d.ts +344 -0
- package/dist/lib/runs.types.js +25 -0
- package/dist/lib/target-url.d.ts +25 -0
- package/dist/lib/target-url.js +127 -0
- package/dist/lib/ticker.d.ts +37 -0
- package/dist/lib/ticker.js +63 -0
- package/dist/lib/validate.d.ts +82 -0
- package/dist/lib/validate.js +165 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +2 -0
- package/package.json +65 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* §6.7 FailureContext bundle writer.
|
|
3
|
+
*
|
|
4
|
+
* Given a `FailureContext` JSON envelope (returned by
|
|
5
|
+
* `GET /api/cli/v1/tests/{id}/failure`), `writeBundle` dereferences
|
|
6
|
+
* every presigned URL into local bytes and writes the §7 disk layout
|
|
7
|
+
* under `<dir>`. The contract is "agent-safe" — every guarantee in
|
|
8
|
+
* the FailureContext spec §3 + §7 is enforced here:
|
|
9
|
+
*
|
|
10
|
+
* 1. **Atomic** — every artifact in the bundle came from one
|
|
11
|
+
* `snapshotId`. We refuse a forged response where
|
|
12
|
+
* `bundle.snapshotId !== result.snapshotId` or steps disagree on
|
|
13
|
+
* `runIdIfAvailable` (`assertContextIntegrity`).
|
|
14
|
+
* 2. **Atomic on disk** — we write to `<dir>/.tmp/...` first and
|
|
15
|
+
* `rename()` each file into place. `meta.json` is renamed last so
|
|
16
|
+
* the presence of `<dir>/meta.json` ⇔ "bundle is complete and
|
|
17
|
+
* self-consistent".
|
|
18
|
+
* 3. **`.partial` on failure** — any download or fs failure leaves
|
|
19
|
+
* a `<dir>/.partial` marker (with `requestId`, error summary,
|
|
20
|
+
* snapshotId) and exits non-zero. Agents check `.partial` before
|
|
21
|
+
* consuming.
|
|
22
|
+
* 4. **Bounded budget** — the writer streams URL → file (no full-
|
|
23
|
+
* buffer), so a 200MB video doesn't sit in V8's heap.
|
|
24
|
+
*
|
|
25
|
+
* What this module deliberately does NOT do:
|
|
26
|
+
*
|
|
27
|
+
* - Re-derive `snapshotId`. The CLI trusts whatever the facade
|
|
28
|
+
* returned. A snapshotId mismatch is a backend bug and we surface
|
|
29
|
+
* it as a typed validation error rather than try to "heal" it.
|
|
30
|
+
* - Generate `summary` strings. Those are server-side per §6.1 of
|
|
31
|
+
* the spec; the CLI emits whatever the facade produced.
|
|
32
|
+
* - Resume after a partial bundle. M2 always re-fetches from scratch
|
|
33
|
+
* when the agent re-runs. M3 may add resume.
|
|
34
|
+
*/
|
|
35
|
+
import type { CliFailureContext } from '../commands/test.js';
|
|
36
|
+
import type { FetchImpl } from './http.js';
|
|
37
|
+
/** Schema version stamped into `meta.json`. Bumps with the contract. */
|
|
38
|
+
export declare const BUNDLE_SCHEMA_VERSION: "cli-v1";
|
|
39
|
+
/** Default radius around the failed step when `--failed-only` is set. */
|
|
40
|
+
export declare const FAILED_ONLY_RADIUS = 1;
|
|
41
|
+
/**
|
|
42
|
+
* Sentinel reasons emitted on the `details.reason` field when the
|
|
43
|
+
* integrity check throws. Exported so callers can branch on a typed
|
|
44
|
+
* literal rather than parsing the message text.
|
|
45
|
+
*/
|
|
46
|
+
export type BundleIntegrityReason = 'snapshot_id_mismatch' | 'run_id_mismatch' | 'code_version_mismatch' | 'evidence_missing_failed_step' | 'run_id_missing' | 'test_id_mismatch';
|
|
47
|
+
/**
|
|
48
|
+
* Options for {@link assertContextIntegrity}.
|
|
49
|
+
*/
|
|
50
|
+
export interface AssertContextIntegrityOptions {
|
|
51
|
+
/**
|
|
52
|
+
* When `true`, the run-scoped path requires `ctx.meta.runId` (i.e.,
|
|
53
|
+
* `ctx.result.runIdIfAvailable`) to be present. M2 callers pass
|
|
54
|
+
* `{}` (or omit entirely) to preserve the opt-in behavior.
|
|
55
|
+
*/
|
|
56
|
+
requireRunId?: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Identity card written as `<dir>/meta.json`. Agents read this first —
|
|
60
|
+
* if any other file's `snapshotId` disagrees, the bundle is corrupt
|
|
61
|
+
* and they must refuse to act.
|
|
62
|
+
*
|
|
63
|
+
* `runIdIfAvailable` and `codeVersion` are surfaced from `result`
|
|
64
|
+
* (already shared across every step in a valid bundle, so the meta
|
|
65
|
+
* carries the bundle-wide value rather than the per-step one).
|
|
66
|
+
*/
|
|
67
|
+
export interface BundleMeta {
|
|
68
|
+
schemaVersion: typeof BUNDLE_SCHEMA_VERSION;
|
|
69
|
+
snapshotId: string;
|
|
70
|
+
testId: string;
|
|
71
|
+
projectId: string;
|
|
72
|
+
codeVersion: string | null;
|
|
73
|
+
runIdIfAvailable: string | null;
|
|
74
|
+
targetUrl: string | null;
|
|
75
|
+
failedStepIndex: number | null;
|
|
76
|
+
failureKind: string | null;
|
|
77
|
+
/** When the backend captured the snapshot. Mirrors `result.finishedAt`. */
|
|
78
|
+
capturedAt: string | null;
|
|
79
|
+
/** When the CLI fetched the bundle (this run's clock). */
|
|
80
|
+
fetchedAt: string;
|
|
81
|
+
}
|
|
82
|
+
export interface WriteBundleOptions {
|
|
83
|
+
/** Absolute or relative target directory. */
|
|
84
|
+
dir: string;
|
|
85
|
+
/** Apply the §7.4 `--failed-only` filter (failed step ± 1) before downloading. */
|
|
86
|
+
failedOnly: boolean;
|
|
87
|
+
/** Custom fetch impl for tests. Defaults to global `fetch`. */
|
|
88
|
+
fetchImpl?: FetchImpl;
|
|
89
|
+
/** Server requestId to embed in `.partial` on failure. */
|
|
90
|
+
requestId?: string;
|
|
91
|
+
}
|
|
92
|
+
export interface WriteBundleResult {
|
|
93
|
+
meta: BundleMeta;
|
|
94
|
+
/** Absolute path of the bundle directory. */
|
|
95
|
+
dir: string;
|
|
96
|
+
/** Files actually written, relative to `dir`. */
|
|
97
|
+
files: string[];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Compose the FailureContext spec §3 invariants into a single
|
|
101
|
+
* trip wire. Throwing here is the agent-safety gate — we trust the
|
|
102
|
+
* facade for the data, not for self-consistency.
|
|
103
|
+
*
|
|
104
|
+
* - Bundle-level `snapshotId` MUST equal `result.snapshotId`.
|
|
105
|
+
* - All steps in the bundle MUST share `runIdIfAvailable` (or all
|
|
106
|
+
* be `null`). Mixed values means a stitched read leaked through.
|
|
107
|
+
*
|
|
108
|
+
* The error envelope is `VALIDATION_ERROR` rather than `INTERNAL`
|
|
109
|
+
* because the operator-facing remediation is "retry once" (the
|
|
110
|
+
* snapshot may genuinely have been mid-mutation; a fresh fetch will
|
|
111
|
+
* succeed). `requestId` is the original request id so support can
|
|
112
|
+
* trace the bad envelope back.
|
|
113
|
+
*/
|
|
114
|
+
export declare function assertContextIntegrity(ctx: CliFailureContext, requestId: string, opts?: AssertContextIntegrityOptions): void;
|
|
115
|
+
/**
|
|
116
|
+
* Apply the `--failed-only` filter — drop neighbor steps and their
|
|
117
|
+
* evidence, keep the failed step. Idempotent: returns `ctx` unchanged
|
|
118
|
+
* when `failedStepIndex` is null (no step-level diagnosis to filter)
|
|
119
|
+
* or when the existing window already matches.
|
|
120
|
+
*/
|
|
121
|
+
export declare function applyFailedOnly(ctx: CliFailureContext): CliFailureContext;
|
|
122
|
+
/**
|
|
123
|
+
* Resolve the user-supplied `--out` path into an absolute directory.
|
|
124
|
+
* Empty strings are rejected with `VALIDATION_ERROR` for consistency
|
|
125
|
+
* with `test code get --out`. We do NOT pre-create the directory or
|
|
126
|
+
* its `.tmp` child — `writeBundle` mkdir's after the integrity check
|
|
127
|
+
* passes so a forged response never modifies the operator's filesystem.
|
|
128
|
+
*/
|
|
129
|
+
export declare function resolveBundleDir(rawPath: string): string;
|
|
130
|
+
/**
|
|
131
|
+
* Pick a code-file extension for `<dir>/code.<ext>` based on the §6.3
|
|
132
|
+
* `language` + `framework`. The extension matches the test code's
|
|
133
|
+
* language, not the user-app code under test.
|
|
134
|
+
*/
|
|
135
|
+
export declare function pickCodeExtension(language: string, framework: string): string;
|
|
136
|
+
/**
|
|
137
|
+
* Step filename per §7.2 — 1-based index, zero-padded to two digits
|
|
138
|
+
* for indices ≤ 99, three digits for ≥ 100. `${stepIndex}-snapshot.html`
|
|
139
|
+
* etc. Never truncates: an agent constructing the path with
|
|
140
|
+
* `padStart(2, '0')` works for the common case, and step ≥ 100 widens
|
|
141
|
+
* naturally without breaking existing fixtures.
|
|
142
|
+
*/
|
|
143
|
+
export declare function stepFilenamePrefix(stepIndex: number): string;
|
|
144
|
+
/**
|
|
145
|
+
* Build the §7.1 meta.json given a context. Pure function, no I/O —
|
|
146
|
+
* lets specs assert the meta shape without touching disk.
|
|
147
|
+
*/
|
|
148
|
+
export declare function buildMeta(ctx: CliFailureContext, fetchedAt?: Date): BundleMeta;
|
|
149
|
+
/**
|
|
150
|
+
* Top-level bundle writer. The order matters:
|
|
151
|
+
*
|
|
152
|
+
* 1. `assertContextIntegrity` — fail closed on a forged envelope.
|
|
153
|
+
* 2. `applyFailedOnly` — narrow before download (saves bytes).
|
|
154
|
+
* 3. `mkdir <dir>/.tmp/` — fresh; clean any stale temp.
|
|
155
|
+
* 4. `writeFile result.json / failure.json / code.<ext>` — local data.
|
|
156
|
+
* 5. `fetch + stream` for `video.mp4` (when set) and per-step
|
|
157
|
+
* snapshot/screenshot/evidence-json files.
|
|
158
|
+
* 6. `writeFile meta.json` LAST — its presence means "bundle complete".
|
|
159
|
+
* 7. `rename .tmp/<file> -> <file>` for every file. Last rename
|
|
160
|
+
* makes meta.json visible.
|
|
161
|
+
*
|
|
162
|
+
* On any failure between (3) and (6), write a `<dir>/.partial` marker
|
|
163
|
+
* and re-throw so `index.ts` produces a typed exit code (UNAVAILABLE
|
|
164
|
+
* → 10 by default; the original ApiError is preserved when applicable).
|
|
165
|
+
*/
|
|
166
|
+
export declare function writeBundle(ctx: CliFailureContext, options: WriteBundleOptions): Promise<WriteBundleResult>;
|
|
167
|
+
/**
|
|
168
|
+
* Stream a presigned URL into a file with bounded retry on transport
|
|
169
|
+
* failures. 4xx (presigned URL expired or unauthorized) is NOT
|
|
170
|
+
* retried — the URL won't recover on its own; an upstream re-fetch
|
|
171
|
+
* is the only fix. Maps to `UNAVAILABLE` so `index.ts` exits 10.
|
|
172
|
+
*
|
|
173
|
+
* Streaming uses `pipeline` to honor backpressure: a slow disk pauses
|
|
174
|
+
* the upstream reader rather than buffering chunks in V8 heap. This
|
|
175
|
+
* matters for video files (multi-MB) and for very large HTML
|
|
176
|
+
* snapshots.
|
|
177
|
+
*/
|
|
178
|
+
export declare function streamUrlToFile(url: string, filePath: string, fetchImpl: FetchImpl): Promise<void>;
|