@kirrosh/zond 0.26.0 → 0.27.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/CHANGELOG.md +59 -0
- package/README.md +22 -21
- package/bin/zond.mjs +23 -0
- package/package.json +13 -16
- package/scripts/npm/postinstall.mjs +76 -0
- package/src/CLAUDE.md +0 -112
- package/src/bun-types.d.ts +0 -5
- package/src/cli/argv.ts +0 -122
- package/src/cli/commands/add-api.ts +0 -146
- package/src/cli/commands/api/annotate/idempotency.ts +0 -59
- package/src/cli/commands/api/annotate/index.ts +0 -880
- package/src/cli/commands/api/annotate/lifecycle.ts +0 -74
- package/src/cli/commands/api/annotate/overlay.ts +0 -206
- package/src/cli/commands/api/annotate/pagination.ts +0 -64
- package/src/cli/commands/api/annotate/prompts.ts +0 -220
- package/src/cli/commands/api/annotate/readback.ts +0 -58
- package/src/cli/commands/api/annotate/resources.ts +0 -91
- package/src/cli/commands/api/annotate/seed-bodies.ts +0 -61
- package/src/cli/commands/audit.ts +0 -786
- package/src/cli/commands/catalog.ts +0 -97
- package/src/cli/commands/check.ts +0 -361
- package/src/cli/commands/checks.ts +0 -1072
- package/src/cli/commands/ci-init.ts +0 -223
- package/src/cli/commands/clean.ts +0 -212
- package/src/cli/commands/cleanup.ts +0 -236
- package/src/cli/commands/completions.ts +0 -192
- package/src/cli/commands/coverage.ts +0 -872
- package/src/cli/commands/db.ts +0 -611
- package/src/cli/commands/describe.ts +0 -120
- package/src/cli/commands/discover.ts +0 -1356
- package/src/cli/commands/doctor.ts +0 -661
- package/src/cli/commands/fixtures.ts +0 -402
- package/src/cli/commands/generate.ts +0 -577
- package/src/cli/commands/init/agents-md.ts +0 -61
- package/src/cli/commands/init/bootstrap.ts +0 -111
- package/src/cli/commands/init/index.ts +0 -244
- package/src/cli/commands/init/skills.ts +0 -141
- package/src/cli/commands/init/templates/agents.md +0 -86
- package/src/cli/commands/init/templates/markdown.d.ts +0 -4
- package/src/cli/commands/init/templates/skills/warm-up-target.md +0 -122
- package/src/cli/commands/init/templates/skills/zond-checks.md +0 -621
- package/src/cli/commands/init/templates/skills/zond-seed.md +0 -114
- package/src/cli/commands/init/templates/skills/zond-triage.md +0 -272
- package/src/cli/commands/init/templates/skills/zond.md +0 -861
- package/src/cli/commands/init/templates/zond-config.yml +0 -14
- package/src/cli/commands/prepare-fixtures.ts +0 -97
- package/src/cli/commands/probe/_seed-bodies.ts +0 -52
- package/src/cli/commands/probe/mass-assignment.ts +0 -594
- package/src/cli/commands/probe/security.ts +0 -537
- package/src/cli/commands/probe/static.ts +0 -255
- package/src/cli/commands/probe/webhooks.ts +0 -163
- package/src/cli/commands/probe.ts +0 -535
- package/src/cli/commands/reference.ts +0 -87
- package/src/cli/commands/refresh-api.ts +0 -227
- package/src/cli/commands/remove-api.ts +0 -150
- package/src/cli/commands/report-bundle.ts +0 -310
- package/src/cli/commands/report.ts +0 -241
- package/src/cli/commands/request.ts +0 -548
- package/src/cli/commands/run.ts +0 -1142
- package/src/cli/commands/schema-from-runs.ts +0 -128
- package/src/cli/commands/secrets.ts +0 -133
- package/src/cli/commands/session.ts +0 -244
- package/src/cli/commands/use.ts +0 -74
- package/src/cli/index.ts +0 -55
- package/src/cli/json-envelope.ts +0 -108
- package/src/cli/json-schemas.ts +0 -314
- package/src/cli/output.ts +0 -40
- package/src/cli/program.ts +0 -219
- package/src/cli/resolve.ts +0 -105
- package/src/cli/runtime.ts +0 -7
- package/src/cli/safe-live.ts +0 -24
- package/src/cli/status-filter.ts +0 -114
- package/src/cli/util/api-context.ts +0 -85
- package/src/cli/version.ts +0 -8
- package/src/core/audit/persist.ts +0 -183
- package/src/core/checks/budget.ts +0 -59
- package/src/core/checks/checks/_crud-helpers.ts +0 -133
- package/src/core/checks/checks/_negative_mutator.ts +0 -133
- package/src/core/checks/checks/_readback-helpers.ts +0 -133
- package/src/core/checks/checks/content_type_conformance.ts +0 -39
- package/src/core/checks/checks/cross_call_references.ts +0 -147
- package/src/core/checks/checks/cursor_boundary_fuzzing.ts +0 -219
- package/src/core/checks/checks/ensure_resource_availability.ts +0 -62
- package/src/core/checks/checks/idempotency_replay.ts +0 -242
- package/src/core/checks/checks/ignored_auth.ts +0 -254
- package/src/core/checks/checks/index.ts +0 -68
- package/src/core/checks/checks/lifecycle_transitions.ts +0 -416
- package/src/core/checks/checks/missing_required_header.ts +0 -40
- package/src/core/checks/checks/negative_data_rejection.ts +0 -148
- package/src/core/checks/checks/not_a_server_error.ts +0 -35
- package/src/core/checks/checks/open_cors_on_sensitive.ts +0 -160
- package/src/core/checks/checks/pagination_invariants.ts +0 -419
- package/src/core/checks/checks/positive_data_acceptance.ts +0 -33
- package/src/core/checks/checks/rate_limit_headers_absent.ts +0 -77
- package/src/core/checks/checks/response_headers_conformance.ts +0 -74
- package/src/core/checks/checks/response_schema_conformance.ts +0 -30
- package/src/core/checks/checks/status_code_conformance.ts +0 -132
- package/src/core/checks/checks/unsupported_method.ts +0 -63
- package/src/core/checks/checks/use_after_free.ts +0 -78
- package/src/core/checks/index.ts +0 -30
- package/src/core/checks/mode.ts +0 -82
- package/src/core/checks/recommended-action.ts +0 -68
- package/src/core/checks/registry.ts +0 -78
- package/src/core/checks/runner.ts +0 -1461
- package/src/core/checks/sarif.ts +0 -230
- package/src/core/checks/spec-findings.ts +0 -308
- package/src/core/checks/stateful.ts +0 -121
- package/src/core/checks/types.ts +0 -305
- package/src/core/checks/zond-extensions.ts +0 -73
- package/src/core/classifier/recommended-action.ts +0 -251
- package/src/core/context/current.ts +0 -51
- package/src/core/context/session.ts +0 -78
- package/src/core/coverage/loader.ts +0 -216
- package/src/core/coverage/reasons.ts +0 -300
- package/src/core/diagnostics/db-analysis.ts +0 -666
- package/src/core/diagnostics/failure-class.ts +0 -140
- package/src/core/diagnostics/failure-hints.ts +0 -112
- package/src/core/diagnostics/spec-pointer.ts +0 -99
- package/src/core/diagnostics/suggested-fixes.ts +0 -155
- package/src/core/exporter/case-study/index.ts +0 -270
- package/src/core/exporter/curl.ts +0 -40
- package/src/core/exporter/exporter.ts +0 -48
- package/src/core/exporter/html-report/escape.ts +0 -24
- package/src/core/exporter/html-report/index.ts +0 -479
- package/src/core/exporter/html-report/script.ts +0 -100
- package/src/core/exporter/html-report/styles.ts +0 -408
- package/src/core/generator/catalog-builder.ts +0 -179
- package/src/core/generator/chunker.ts +0 -78
- package/src/core/generator/coverage-phase.ts +0 -0
- package/src/core/generator/coverage-scanner.ts +0 -87
- package/src/core/generator/data-factory.ts +0 -759
- package/src/core/generator/describe.ts +0 -302
- package/src/core/generator/endpoint-warnings.ts +0 -52
- package/src/core/generator/fixtures-builder.ts +0 -332
- package/src/core/generator/index.ts +0 -14
- package/src/core/generator/openapi-reader.ts +0 -297
- package/src/core/generator/path-param-disambig.ts +0 -140
- package/src/core/generator/resources-builder.ts +0 -898
- package/src/core/generator/schema-utils.ts +0 -112
- package/src/core/generator/serializer.ts +0 -343
- package/src/core/generator/suite-generator.ts +0 -1301
- package/src/core/generator/types.ts +0 -63
- package/src/core/identity/identity-file.ts +0 -0
- package/src/core/lint/affects.ts +0 -28
- package/src/core/lint/config.ts +0 -96
- package/src/core/lint/format.ts +0 -42
- package/src/core/lint/index.ts +0 -94
- package/src/core/lint/reporter.ts +0 -128
- package/src/core/lint/rules/consistency.ts +0 -158
- package/src/core/lint/rules/heuristics.ts +0 -97
- package/src/core/lint/rules/strictness.ts +0 -109
- package/src/core/lint/types.ts +0 -96
- package/src/core/lint/walker.ts +0 -248
- package/src/core/meta/meta-store.ts +0 -11
- package/src/core/output/README.md +0 -73
- package/src/core/output/index.ts +0 -13
- package/src/core/output/run.ts +0 -91
- package/src/core/output/types.ts +0 -122
- package/src/core/parser/dynamic-values.ts +0 -160
- package/src/core/parser/env-interpolation.ts +0 -104
- package/src/core/parser/filter.ts +0 -97
- package/src/core/parser/schema.ts +0 -359
- package/src/core/parser/types.ts +0 -117
- package/src/core/parser/variables.ts +0 -0
- package/src/core/parser/yaml-parser.ts +0 -181
- package/src/core/probe/bootstrap.ts +0 -34
- package/src/core/probe/dry-run-envelope.ts +0 -61
- package/src/core/probe/mass-assignment/classify.ts +0 -175
- package/src/core/probe/mass-assignment/cleanup.ts +0 -52
- package/src/core/probe/mass-assignment/digest.ts +0 -114
- package/src/core/probe/mass-assignment/orchestrator.ts +0 -459
- package/src/core/probe/mass-assignment/regression.ts +0 -141
- package/src/core/probe/mass-assignment/suspects.ts +0 -92
- package/src/core/probe/mass-assignment/types.ts +0 -135
- package/src/core/probe/mass-assignment-probe-class.ts +0 -198
- package/src/core/probe/mass-assignment-probe.ts +0 -27
- package/src/core/probe/mass-assignment-template.ts +0 -240
- package/src/core/probe/method-probe.ts +0 -164
- package/src/core/probe/method-shared.ts +0 -69
- package/src/core/probe/negative-probe.ts +0 -691
- package/src/core/probe/orphan-tracker.ts +0 -188
- package/src/core/probe/path-discovery.ts +0 -439
- package/src/core/probe/probe-harness.ts +0 -119
- package/src/core/probe/registry.ts +0 -89
- package/src/core/probe/runner.ts +0 -136
- package/src/core/probe/security/baseline.ts +0 -174
- package/src/core/probe/security/classify.ts +0 -341
- package/src/core/probe/security/cleanup.ts +0 -125
- package/src/core/probe/security/detectors.ts +0 -71
- package/src/core/probe/security/digest.ts +0 -104
- package/src/core/probe/security/orchestrator.ts +0 -398
- package/src/core/probe/security/regression.ts +0 -103
- package/src/core/probe/security/types.ts +0 -151
- package/src/core/probe/security-probe-class.ts +0 -207
- package/src/core/probe/security-probe.ts +0 -32
- package/src/core/probe/shared.ts +0 -531
- package/src/core/probe/static-probe-class.ts +0 -125
- package/src/core/probe/types.ts +0 -165
- package/src/core/probe/verdict-aggregator.ts +0 -33
- package/src/core/probe/webhooks-probe.ts +0 -282
- package/src/core/reporter/console.ts +0 -240
- package/src/core/reporter/index.ts +0 -22
- package/src/core/reporter/json.ts +0 -22
- package/src/core/reporter/junit.ts +0 -93
- package/src/core/reporter/ndjson.ts +0 -37
- package/src/core/reporter/types.ts +0 -15
- package/src/core/runner/assertions.ts +0 -383
- package/src/core/runner/async-pool.ts +0 -108
- package/src/core/runner/auth-path.ts +0 -8
- package/src/core/runner/ci-context.ts +0 -72
- package/src/core/runner/executor.ts +0 -652
- package/src/core/runner/expr-eval.ts +0 -41
- package/src/core/runner/form-encode.ts +0 -41
- package/src/core/runner/http-client.ts +0 -224
- package/src/core/runner/learn-drift.ts +0 -293
- package/src/core/runner/preflight-vars.ts +0 -153
- package/src/core/runner/progress-tracker.ts +0 -73
- package/src/core/runner/rate-limiter.ts +0 -185
- package/src/core/runner/run-kind.ts +0 -45
- package/src/core/runner/schema-validator.ts +0 -308
- package/src/core/runner/send-request.ts +0 -232
- package/src/core/runner/transforms.ts +0 -65
- package/src/core/runner/types.ts +0 -94
- package/src/core/secrets/registry.ts +0 -164
- package/src/core/secrets/secrets-file.ts +0 -115
- package/src/core/selectors/operation-filter.ts +0 -144
- package/src/core/setup-api.ts +0 -590
- package/src/core/severity/category.ts +0 -94
- package/src/core/severity/index.ts +0 -58
- package/src/core/spec/infer-schema.ts +0 -102
- package/src/core/spec/layers.ts +0 -154
- package/src/core/spec/merge-specs.ts +0 -156
- package/src/core/spec/schema-from-runs.ts +0 -117
- package/src/core/spec/schema-overlay.ts +0 -130
- package/src/core/util/ajv.ts +0 -13
- package/src/core/util/format-eta.ts +0 -21
- package/src/core/util/headers.ts +0 -9
- package/src/core/util/url.ts +0 -24
- package/src/core/utils.ts +0 -13
- package/src/core/workspace/config.ts +0 -129
- package/src/core/workspace/fixture-gap-report.ts +0 -84
- package/src/core/workspace/fixture-gaps.ts +0 -71
- package/src/core/workspace/manifest.ts +0 -283
- package/src/core/workspace/output-rotation.ts +0 -62
- package/src/core/workspace/root.ts +0 -96
- package/src/core/workspace/triage-path.ts +0 -87
- package/src/db/lint-runs.ts +0 -47
- package/src/db/migrate.ts +0 -128
- package/src/db/migrations/0001_run_kind.sql +0 -25
- package/src/db/migrations/0002_run_kind_request.sql +0 -59
- package/src/db/migrations/sql.d.ts +0 -4
- package/src/db/queries/collections.ts +0 -133
- package/src/db/queries/coverage.ts +0 -9
- package/src/db/queries/dashboard.ts +0 -59
- package/src/db/queries/results.ts +0 -216
- package/src/db/queries/runs.ts +0 -289
- package/src/db/queries/sessions.ts +0 -42
- package/src/db/queries/settings.ts +0 -28
- package/src/db/queries/types.ts +0 -172
- package/src/db/queries.ts +0 -75
- package/src/db/schema.ts +0 -298
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import type { TestSuite, TestStep, AssertionRule } from "../parser/types.ts";
|
|
2
|
-
import { GENERATORS } from "../parser/variables.ts";
|
|
3
|
-
|
|
4
|
-
const VAR_PATTERN = /\{\{([^{}]+)\}\}/g;
|
|
5
|
-
|
|
6
|
-
function scanRefs(value: unknown, out: Set<string>): void {
|
|
7
|
-
if (typeof value === "string") {
|
|
8
|
-
for (const match of value.matchAll(VAR_PATTERN)) {
|
|
9
|
-
const key = match[1]!.trim();
|
|
10
|
-
if (!key.startsWith("$")) out.add(key);
|
|
11
|
-
}
|
|
12
|
-
} else if (Array.isArray(value)) {
|
|
13
|
-
for (const item of value) scanRefs(item, out);
|
|
14
|
-
} else if (typeof value === "object" && value !== null) {
|
|
15
|
-
for (const v of Object.values(value)) scanRefs(v, out);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function collectCapturesAndSets(step: TestStep, out: Set<string>): void {
|
|
20
|
-
if (step.set) {
|
|
21
|
-
for (const k of Object.keys(step.set)) out.add(k);
|
|
22
|
-
}
|
|
23
|
-
if (step.for_each?.var) out.add(step.for_each.var);
|
|
24
|
-
const scanRule = (rule: AssertionRule | undefined): void => {
|
|
25
|
-
if (!rule) return;
|
|
26
|
-
if (rule.capture) out.add(rule.capture);
|
|
27
|
-
if (rule.each) {
|
|
28
|
-
for (const r of Object.values(rule.each)) scanRule(r);
|
|
29
|
-
}
|
|
30
|
-
if (rule.contains_item) {
|
|
31
|
-
for (const r of Object.values(rule.contains_item)) scanRule(r);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
if (step.expect?.body) {
|
|
35
|
-
for (const r of Object.values(step.expect.body)) scanRule(r);
|
|
36
|
-
}
|
|
37
|
-
if (step.expect?.headers) {
|
|
38
|
-
for (const v of Object.values(step.expect.headers)) {
|
|
39
|
-
if (typeof v === "object" && v !== null) scanRule(v as AssertionRule);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface MissingVarHit {
|
|
45
|
-
suite: string;
|
|
46
|
-
file?: string;
|
|
47
|
-
step?: string;
|
|
48
|
-
variable: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Pre-flight scan: find {{var}} references in suites that have no producer
|
|
53
|
-
* (env value, suite-level parameterize/set, prior-step capture). Excludes
|
|
54
|
-
* built-in $generators.
|
|
55
|
-
*
|
|
56
|
-
* Conservative: per-suite — accumulates all captures/sets across steps, so
|
|
57
|
-
* forward references inside the suite are tolerated (correctness requires
|
|
58
|
-
* runtime ordering checks anyway).
|
|
59
|
-
*/
|
|
60
|
-
/** All non-generator {{var}} references a step reads (path, headers, body,
|
|
61
|
-
* query, skip_if, retry_until, set, for_each). Excludes `$generators`. */
|
|
62
|
-
export function collectStepRefs(step: TestStep): Set<string> {
|
|
63
|
-
const refs = new Set<string>();
|
|
64
|
-
scanRefs(step.path, refs);
|
|
65
|
-
scanRefs(step.headers, refs);
|
|
66
|
-
scanRefs(step.json, refs);
|
|
67
|
-
scanRefs(step.form, refs);
|
|
68
|
-
scanRefs(step.multipart, refs);
|
|
69
|
-
scanRefs(step.query, refs);
|
|
70
|
-
if (step.skip_if) scanRefs(step.skip_if, refs);
|
|
71
|
-
if (step.retry_until) scanRefs(step.retry_until.condition, refs);
|
|
72
|
-
if (step.set) scanRefs(step.set, refs);
|
|
73
|
-
if (step.for_each) scanRefs(step.for_each.in, refs);
|
|
74
|
-
return refs;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function preflightCheckVars(
|
|
78
|
-
suites: TestSuite[],
|
|
79
|
-
env: Record<string, string>,
|
|
80
|
-
): MissingVarHit[] {
|
|
81
|
-
const hits: MissingVarHit[] = [];
|
|
82
|
-
const generatorKeys = new Set(Object.keys(GENERATORS));
|
|
83
|
-
|
|
84
|
-
for (const suite of suites) {
|
|
85
|
-
const known = new Set<string>(Object.keys(env));
|
|
86
|
-
if (suite.parameterize) {
|
|
87
|
-
for (const k of Object.keys(suite.parameterize)) known.add(k);
|
|
88
|
-
}
|
|
89
|
-
for (const step of suite.tests) collectCapturesAndSets(step, known);
|
|
90
|
-
|
|
91
|
-
const scanStepRefs = collectStepRefs;
|
|
92
|
-
|
|
93
|
-
const suiteRefs = new Set<string>();
|
|
94
|
-
if (suite.base_url) scanRefs(suite.base_url, suiteRefs);
|
|
95
|
-
if (suite.headers) scanRefs(suite.headers, suiteRefs);
|
|
96
|
-
for (const v of suiteRefs) {
|
|
97
|
-
if (!known.has(v) && !generatorKeys.has(v)) {
|
|
98
|
-
hits.push({ suite: suite.name, file: suite.filePath, variable: v });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
for (const step of suite.tests) {
|
|
103
|
-
const refs = scanStepRefs(step);
|
|
104
|
-
for (const v of refs) {
|
|
105
|
-
if (!known.has(v) && !generatorKeys.has(v)) {
|
|
106
|
-
hits.push({
|
|
107
|
-
suite: suite.name,
|
|
108
|
-
file: suite.filePath,
|
|
109
|
-
step: step.name,
|
|
110
|
-
variable: v,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return hits;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export function formatMissingVarLine(hit: MissingVarHit): string {
|
|
121
|
-
const where = hit.step ? `${hit.suite} → ${hit.step}` : hit.suite;
|
|
122
|
-
const file = hit.file ? ` (${hit.file})` : "";
|
|
123
|
-
return `Undefined variable {{${hit.variable}}} in ${where}${file}`;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* TASK-248: collapse per-(suite,step,variable) hits into one summary line per
|
|
128
|
-
* unique variable. When the same {{var}} is referenced in 8–12 places (typical
|
|
129
|
-
* when running outside a workspace and `.env.yaml` is missing), per-hit emit
|
|
130
|
-
* spams stderr — the aggregated form keeps signal (the *names* of the missing
|
|
131
|
-
* vars) while dropping noise.
|
|
132
|
-
*/
|
|
133
|
-
export function summarizeMissingVars(hits: MissingVarHit[]): string[] {
|
|
134
|
-
if (hits.length === 0) return [];
|
|
135
|
-
const byVar = new Map<string, { refs: number; suites: Set<string> }>();
|
|
136
|
-
for (const h of hits) {
|
|
137
|
-
let entry = byVar.get(h.variable);
|
|
138
|
-
if (!entry) {
|
|
139
|
-
entry = { refs: 0, suites: new Set() };
|
|
140
|
-
byVar.set(h.variable, entry);
|
|
141
|
-
}
|
|
142
|
-
entry.refs++;
|
|
143
|
-
entry.suites.add(h.suite);
|
|
144
|
-
}
|
|
145
|
-
const names = [...byVar.keys()].sort();
|
|
146
|
-
const totalRefs = hits.length;
|
|
147
|
-
const totalSuites = new Set(hits.map((h) => h.suite)).size;
|
|
148
|
-
const head = names.slice(0, 6).map((n) => `{{${n}}}`).join(", ");
|
|
149
|
-
const tail = names.length > 6 ? `, … and ${names.length - 6} more` : "";
|
|
150
|
-
return [
|
|
151
|
-
`Undefined variables: ${head}${tail} (${totalRefs} reference${totalRefs === 1 ? "" : "s"} across ${totalSuites} suite${totalSuites === 1 ? "" : "s"})`,
|
|
152
|
-
];
|
|
153
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ARV-249: lightweight progress tracker for `zond run`. A separate module
|
|
3
|
-
* so the formatter can be unit-tested without spinning up an executor.
|
|
4
|
-
*
|
|
5
|
-
* Architecture: run.ts owns the tracker + `setInterval`. Every completed
|
|
6
|
-
* step calls `tracker.recordStep(...)` via `RunSuiteOptions.onStepDone`,
|
|
7
|
-
* the interval ticks every PROGRESS_INTERVAL_MS and writes one stderr
|
|
8
|
-
* line, and run.ts clears the interval before printing the final report.
|
|
9
|
-
*/
|
|
10
|
-
import { formatEta } from "../util/format-eta.ts";
|
|
11
|
-
import type { StepResult } from "./types.ts";
|
|
12
|
-
|
|
13
|
-
export const PROGRESS_INTERVAL_MS = 5000;
|
|
14
|
-
/** Wait this long before emitting the first progress line. Short runs
|
|
15
|
-
* that finish under the threshold stay silent. */
|
|
16
|
-
export const PROGRESS_QUIET_MS = 5000;
|
|
17
|
-
|
|
18
|
-
export interface ProgressSnapshot {
|
|
19
|
-
elapsedMs: number;
|
|
20
|
-
completedSteps: number;
|
|
21
|
-
totalSteps: number;
|
|
22
|
-
httpRequests: number;
|
|
23
|
-
effectiveRps: number;
|
|
24
|
-
etaSeconds: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class ProgressTracker {
|
|
28
|
-
private completedSteps = 0;
|
|
29
|
-
private httpRequests = 0;
|
|
30
|
-
private readonly startedAt: number;
|
|
31
|
-
|
|
32
|
-
constructor(private readonly totalSteps: number, now: number = Date.now()) {
|
|
33
|
-
this.startedAt = now;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
recordStep(step: StepResult): void {
|
|
37
|
-
this.completedSteps += 1;
|
|
38
|
-
if (step.status !== "skip" && step.response !== undefined) {
|
|
39
|
-
this.httpRequests += 1;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
snapshot(now: number = Date.now()): ProgressSnapshot {
|
|
44
|
-
const elapsedMs = Math.max(0, now - this.startedAt);
|
|
45
|
-
const elapsedSec = elapsedMs / 1000;
|
|
46
|
-
const effectiveRps = elapsedSec > 0 ? this.httpRequests / elapsedSec : 0;
|
|
47
|
-
const remaining = Math.max(0, this.totalSteps - this.completedSteps);
|
|
48
|
-
const stepRate = elapsedSec > 0 ? this.completedSteps / elapsedSec : 0;
|
|
49
|
-
const etaSeconds = stepRate > 0 ? remaining / stepRate : Infinity;
|
|
50
|
-
return {
|
|
51
|
-
elapsedMs,
|
|
52
|
-
completedSteps: this.completedSteps,
|
|
53
|
-
totalSteps: this.totalSteps,
|
|
54
|
-
httpRequests: this.httpRequests,
|
|
55
|
-
effectiveRps,
|
|
56
|
-
etaSeconds,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** Format a progress snapshot for stderr. Stable wording — agents may
|
|
62
|
-
* grep the line. */
|
|
63
|
-
export function formatProgressLine(snap: ProgressSnapshot): string {
|
|
64
|
-
const elapsed = formatEta(snap.elapsedMs / 1000);
|
|
65
|
-
const pct = snap.totalSteps > 0
|
|
66
|
-
? Math.min(100, Math.floor((snap.completedSteps / snap.totalSteps) * 100))
|
|
67
|
-
: 0;
|
|
68
|
-
const rps = snap.effectiveRps >= 10
|
|
69
|
-
? Math.round(snap.effectiveRps).toString()
|
|
70
|
-
: snap.effectiveRps.toFixed(1);
|
|
71
|
-
const eta = Number.isFinite(snap.etaSeconds) ? formatEta(snap.etaSeconds) : "?";
|
|
72
|
-
return `zond: [${elapsed}] ${snap.completedSteps}/${snap.totalSteps} steps (${pct}%), ${snap.httpRequests} req, ~${rps} req/s, ETA ${eta}`;
|
|
73
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
export interface RateLimiter {
|
|
2
|
-
acquire(): Promise<void>;
|
|
3
|
-
/**
|
|
4
|
-
* Feed rate-limit metadata from the latest response back into the limiter.
|
|
5
|
-
* Two effects: (1) when `remaining` falls at or below the threshold, the
|
|
6
|
-
* limiter postpones the next acquire until the API's reset window expires;
|
|
7
|
-
* (2) when the response carries a `RateLimit-Policy` (RFC 9568), the
|
|
8
|
-
* limiter learns the per-request spacing so subsequent parallel acquires
|
|
9
|
-
* are forced into single-file at burst=1.
|
|
10
|
-
*
|
|
11
|
-
* Optional so existing callers / mocks need not implement it.
|
|
12
|
-
*/
|
|
13
|
-
note?(meta: RateLimitMeta, now?: number): void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface RateLimitMeta {
|
|
17
|
-
/** Requests remaining in the current window. */
|
|
18
|
-
remaining?: number;
|
|
19
|
-
/** Either seconds-until-reset (RFC draft) or a Unix epoch in seconds (GitHub style). */
|
|
20
|
-
reset?: number;
|
|
21
|
-
/** Window cap; used for diagnostics and spacing fallback. */
|
|
22
|
-
limit?: number;
|
|
23
|
-
/**
|
|
24
|
-
* Minimum spacing between requests in ms — derived from `RateLimit-Policy:
|
|
25
|
-
* N;w=W` (RFC 9568). When set, the limiter raises its own interval to at
|
|
26
|
-
* least this value so a burst of parallel requests is paced one-by-one
|
|
27
|
-
* instead of overshooting the window.
|
|
28
|
-
*/
|
|
29
|
-
intervalMs?: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* When `remaining` is at or below this number we proactively pause until reset.
|
|
34
|
-
* Conservative threshold — at 2, we still have buffer for one in-flight retry
|
|
35
|
-
* (if we paused at 5 we'd over-throttle on small windows like 5-req/1-sec
|
|
36
|
-
* policies, where every request would trigger a sleep).
|
|
37
|
-
*/
|
|
38
|
-
const THROTTLE_THRESHOLD = 2;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Padding added to policy-derived spacing to absorb clock drift between the
|
|
42
|
-
* server's window and our local Date.now() (TASK-88). Without this, spacing
|
|
43
|
-
* exactly at `W/N` ms can still hit the window boundary on the wrong side.
|
|
44
|
-
*/
|
|
45
|
-
const POLICY_SAFETY_MS = 50;
|
|
46
|
-
|
|
47
|
-
/** Magnitudes above this are treated as Unix timestamps; below as relative
|
|
48
|
-
* seconds. 10^9 seconds ≈ Sep 2001, so any real reset window is far below. */
|
|
49
|
-
const UNIX_TS_BOUNDARY = 1_000_000_000;
|
|
50
|
-
|
|
51
|
-
function applyResetPause(prevNextAvailable: number, meta: RateLimitMeta, now: number): number {
|
|
52
|
-
if (meta.remaining === undefined) return prevNextAvailable;
|
|
53
|
-
if (meta.remaining > THROTTLE_THRESHOLD) return prevNextAvailable;
|
|
54
|
-
if (meta.reset === undefined || !Number.isFinite(meta.reset)) return prevNextAvailable;
|
|
55
|
-
const resetMs = meta.reset > UNIX_TS_BOUNDARY ? meta.reset * 1000 : now + Math.max(0, meta.reset) * 1000;
|
|
56
|
-
return Math.max(prevNextAvailable, resetMs);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
class IntervalRateLimiter implements RateLimiter {
|
|
60
|
-
private nextAvailable = 0;
|
|
61
|
-
/** 0 means adaptive: no proactive throttling until a policy is learned
|
|
62
|
-
* from a response (matches the original AdaptiveRateLimiter behaviour). */
|
|
63
|
-
private intervalMs: number;
|
|
64
|
-
|
|
65
|
-
constructor(reqPerSec?: number) {
|
|
66
|
-
if (reqPerSec === undefined) {
|
|
67
|
-
this.intervalMs = 0;
|
|
68
|
-
} else {
|
|
69
|
-
if (!Number.isFinite(reqPerSec) || reqPerSec <= 0) {
|
|
70
|
-
throw new Error(`Invalid rate limit: ${reqPerSec}`);
|
|
71
|
-
}
|
|
72
|
-
this.intervalMs = 1000 / reqPerSec;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async acquire(): Promise<void> {
|
|
77
|
-
const now = Date.now();
|
|
78
|
-
const slot = Math.max(now, this.nextAvailable);
|
|
79
|
-
const waitMs = slot - now;
|
|
80
|
-
this.nextAvailable = slot + this.intervalMs;
|
|
81
|
-
if (waitMs > 0) {
|
|
82
|
-
await Bun.sleep(waitMs);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
note(meta: RateLimitMeta, now: number = Date.now()): void {
|
|
87
|
-
if (meta.intervalMs !== undefined && meta.intervalMs > this.intervalMs) {
|
|
88
|
-
// Already-reserved slots were spaced at the OLD interval; push
|
|
89
|
-
// nextAvailable forward by the delta so the new spacing kicks in
|
|
90
|
-
// immediately rather than only on the next-next request.
|
|
91
|
-
this.nextAvailable += meta.intervalMs - this.intervalMs;
|
|
92
|
-
this.intervalMs = meta.intervalMs;
|
|
93
|
-
}
|
|
94
|
-
this.nextAvailable = applyResetPause(this.nextAvailable, meta, now);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function createRateLimiter(reqPerSec: number | undefined): RateLimiter | undefined {
|
|
99
|
-
if (reqPerSec === undefined || reqPerSec === null) return undefined;
|
|
100
|
-
if (!Number.isFinite(reqPerSec) || reqPerSec <= 0) return undefined;
|
|
101
|
-
return new IntervalRateLimiter(reqPerSec);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Adaptive limiter for `--rate-limit auto`. Issues no proactive throttling on
|
|
106
|
-
* its own initially, but reacts to ratelimit-* response headers via `note()`:
|
|
107
|
-
* (a) pauses the request stream until the API's reset window elapses when
|
|
108
|
-
* remaining headroom drops; (b) once a `RateLimit-Policy` is seen, paces
|
|
109
|
-
* subsequent requests at the policy's `W/N` spacing — this prevents bursts
|
|
110
|
-
* from blowing through small windows (e.g. 5-req/1-sec policies).
|
|
111
|
-
*/
|
|
112
|
-
export function createAdaptiveRateLimiter(): RateLimiter {
|
|
113
|
-
return new IntervalRateLimiter();
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Read RFC 9568 `ratelimit-*` headers (was draft-ietf-httpapi-ratelimit-headers)
|
|
118
|
-
* plus the GitHub / Stripe style `x-ratelimit-*` aliases out of a response
|
|
119
|
-
* header bag. All keys are matched case-insensitively. Unparseable values are
|
|
120
|
-
* dropped.
|
|
121
|
-
*
|
|
122
|
-
* `RateLimit-Policy: N;w=W` is parsed into a per-request `intervalMs` of
|
|
123
|
-
* `(W/N)*1000 + POLICY_SAFETY_MS` so the limiter can pace bursts.
|
|
124
|
-
*/
|
|
125
|
-
export function parseRateLimitHeaders(headers: Record<string, string>): RateLimitMeta {
|
|
126
|
-
const lower: Record<string, string> = {};
|
|
127
|
-
for (const [k, v] of Object.entries(headers)) lower[k.toLowerCase()] = v;
|
|
128
|
-
const num = (v: string | undefined): number | undefined => {
|
|
129
|
-
if (v === undefined) return undefined;
|
|
130
|
-
// RFC draft `ratelimit-remaining` may carry `q="value"` quoted-string form;
|
|
131
|
-
// strip leading numeric run.
|
|
132
|
-
const match = v.match(/-?\d+(?:\.\d+)?/);
|
|
133
|
-
if (!match) return undefined;
|
|
134
|
-
const n = Number.parseFloat(match[0]);
|
|
135
|
-
return Number.isFinite(n) ? n : undefined;
|
|
136
|
-
};
|
|
137
|
-
const policy = lower["ratelimit-policy"] ?? lower["x-ratelimit-policy"];
|
|
138
|
-
const intervalMs = derivePolicyIntervalMs(policy);
|
|
139
|
-
return {
|
|
140
|
-
limit: num(lower["ratelimit-limit"] ?? lower["x-ratelimit-limit"]),
|
|
141
|
-
remaining: num(lower["ratelimit-remaining"] ?? lower["x-ratelimit-remaining"]),
|
|
142
|
-
reset: num(lower["ratelimit-reset"] ?? lower["x-ratelimit-reset"]),
|
|
143
|
-
intervalMs,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Parse `RateLimit-Policy: 5;w=1` (or comma-separated multi-policy — we honour
|
|
149
|
-
* the *strictest* one). Returns the implied per-request interval in ms,
|
|
150
|
-
* including a small safety margin. Returns undefined when the header is
|
|
151
|
-
* malformed or missing.
|
|
152
|
-
*/
|
|
153
|
-
function derivePolicyIntervalMs(policy: string | undefined): number | undefined {
|
|
154
|
-
if (!policy) return undefined;
|
|
155
|
-
let strictest: number | undefined;
|
|
156
|
-
for (const item of policy.split(",")) {
|
|
157
|
-
const parts = item.trim().split(";").map(s => s.trim()).filter(Boolean);
|
|
158
|
-
if (parts.length === 0) continue;
|
|
159
|
-
const limit = Number.parseFloat(parts[0]!);
|
|
160
|
-
if (!Number.isFinite(limit) || limit <= 0) continue;
|
|
161
|
-
const wPart = parts.find(p => p.startsWith("w="));
|
|
162
|
-
if (!wPart) continue;
|
|
163
|
-
const window = Number.parseFloat(wPart.slice(2));
|
|
164
|
-
if (!Number.isFinite(window) || window <= 0) continue;
|
|
165
|
-
const interval = (window / limit) * 1000 + POLICY_SAFETY_MS;
|
|
166
|
-
if (strictest === undefined || interval > strictest) strictest = interval;
|
|
167
|
-
}
|
|
168
|
-
return strictest;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export function parseRetryAfter(header: string | null | undefined, now: number = Date.now()): number | undefined {
|
|
172
|
-
if (!header) return undefined;
|
|
173
|
-
const trimmed = header.trim();
|
|
174
|
-
if (trimmed === "") return undefined;
|
|
175
|
-
if (/^\d+(\.\d+)?$/.test(trimmed)) {
|
|
176
|
-
const seconds = Number.parseFloat(trimmed);
|
|
177
|
-
if (Number.isFinite(seconds) && seconds >= 0) return Math.round(seconds * 1000);
|
|
178
|
-
return undefined;
|
|
179
|
-
}
|
|
180
|
-
const date = Date.parse(trimmed);
|
|
181
|
-
if (!Number.isNaN(date)) {
|
|
182
|
-
return Math.max(0, date - now);
|
|
183
|
-
}
|
|
184
|
-
return undefined;
|
|
185
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ARV-55: single source of truth for classifying a run by *what kind of
|
|
3
|
-
* suites it executed*. Before this module the answer was inferred from
|
|
4
|
-
* `suite_file` paths in three places (coverage's `isProbeOnlyRun`,
|
|
5
|
-
* `db diagnose` recommendation branching, and a handful of skill prompts).
|
|
6
|
-
*
|
|
7
|
-
* We resolve the kind once at INSERT-time and persist it in `runs.run_kind`;
|
|
8
|
-
* downstream filters become a column compare instead of a per-result regex.
|
|
9
|
-
*
|
|
10
|
-
* Encoding:
|
|
11
|
-
* - `probe` — every suite path lives under `apis/<api>/probes/` (or a
|
|
12
|
-
* bare `probes/` segment for ad-hoc setups). Coverage hides
|
|
13
|
-
* these by default — probe runs deliberately exercise a
|
|
14
|
-
* subset of endpoints and would otherwise read as a
|
|
15
|
-
* regression vs the prior smoke/CRUD run.
|
|
16
|
-
* - `check` — every suite path lives under `apis/<api>/checks/`. Mirrors
|
|
17
|
-
* the same logic: conformance checks don't reflect endpoint
|
|
18
|
-
* coverage breadth.
|
|
19
|
-
* - `request` — a single ad-hoc `zond request` invocation persisted into
|
|
20
|
-
* the session DB (ARV-265). Excluded from `pass-coverage`
|
|
21
|
-
* but counted toward `audit-coverage`.
|
|
22
|
-
* - `fixture` — `prepare-fixtures --cascade` discovery list-calls
|
|
23
|
-
* (ARV-265). Pure HTTP touches in service of fixture
|
|
24
|
-
* derivation; audit-coverage only.
|
|
25
|
-
* - `regular` — anything else, including mixed runs (probe + smoke). A
|
|
26
|
-
* mixed run is treated as regular because at least one
|
|
27
|
-
* suite contributed real coverage signal.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
export type RunKind = "regular" | "probe" | "check" | "request" | "fixture";
|
|
31
|
-
|
|
32
|
-
const PROBE_SEGMENT_RE = /(^|\/)probes(\/|$)/;
|
|
33
|
-
const CHECK_SEGMENT_RE = /(^|\/)checks(\/|$)/;
|
|
34
|
-
|
|
35
|
-
export function detectRunKind(suiteFiles: ReadonlyArray<string | null | undefined>): RunKind {
|
|
36
|
-
// Empty / all-empty arrays default to 'regular' — the DB CHECK constraint
|
|
37
|
-
// refuses NULL so callers always receive a concrete kind.
|
|
38
|
-
const paths = suiteFiles
|
|
39
|
-
.filter((p): p is string => typeof p === "string" && p.length > 0);
|
|
40
|
-
if (paths.length === 0) return "regular";
|
|
41
|
-
|
|
42
|
-
if (paths.every((p) => PROBE_SEGMENT_RE.test(p))) return "probe";
|
|
43
|
-
if (paths.every((p) => CHECK_SEGMENT_RE.test(p))) return "check";
|
|
44
|
-
return "regular";
|
|
45
|
-
}
|