@kirrosh/zond 0.22.0 → 0.23.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 +648 -0
- package/README.md +58 -6
- package/package.json +9 -6
- package/src/cli/argv.ts +122 -0
- package/src/cli/commands/add-api.ts +134 -0
- package/src/cli/commands/api/annotate/idempotency.ts +59 -0
- package/src/cli/commands/api/annotate/index.ts +525 -0
- package/src/cli/commands/api/annotate/lifecycle.ts +74 -0
- package/src/cli/commands/api/annotate/overlay.ts +206 -0
- package/src/cli/commands/api/annotate/pagination.ts +60 -0
- package/src/cli/commands/api/annotate/prompts.ts +183 -0
- package/src/cli/commands/api/annotate/readback.ts +58 -0
- package/src/cli/commands/api/annotate/resources.ts +91 -0
- package/src/cli/commands/api/annotate/seed-bodies.ts +61 -0
- package/src/cli/commands/audit.ts +480 -0
- package/src/cli/commands/bootstrap.ts +710 -0
- package/src/cli/commands/catalog.ts +35 -0
- package/src/cli/commands/check.ts +348 -0
- package/src/cli/commands/checks.ts +756 -0
- package/src/cli/commands/ci-init.ts +43 -0
- package/src/cli/commands/clean.ts +212 -0
- package/src/cli/commands/cleanup.ts +262 -0
- package/src/cli/commands/completions.ts +16 -0
- package/src/cli/commands/coverage.ts +605 -132
- package/src/cli/commands/db.ts +178 -7
- package/src/cli/commands/describe.ts +37 -2
- package/src/cli/commands/discover.ts +1236 -0
- package/src/cli/commands/doctor.ts +607 -0
- package/src/cli/commands/fixtures.ts +402 -0
- package/src/cli/commands/generate.ts +420 -46
- package/src/cli/commands/init/bootstrap.ts +30 -1
- package/src/cli/commands/{init.ts → init/index.ts} +99 -5
- package/src/cli/commands/init/skills.ts +56 -3
- package/src/cli/commands/init/templates/agents.md +65 -61
- package/src/cli/commands/init/templates/skills/zond-checks.md +397 -0
- package/src/cli/commands/init/templates/skills/zond-triage.md +210 -0
- package/src/cli/commands/init/templates/skills/zond.md +592 -125
- package/src/cli/commands/init/templates/zond-config.yml +8 -9
- package/src/cli/commands/prepare-fixtures.ts +135 -0
- package/src/cli/commands/probe/mass-assignment.ts +503 -0
- package/src/cli/commands/probe/security.ts +454 -0
- package/src/cli/commands/probe/static.ts +255 -0
- package/src/cli/commands/probe/webhooks.ts +161 -0
- package/src/cli/commands/probe.ts +459 -0
- package/src/cli/commands/reference.ts +87 -0
- package/src/cli/commands/refresh-api.ts +169 -0
- package/src/cli/commands/remove-api.ts +150 -0
- package/src/cli/commands/report-bundle.ts +318 -0
- package/src/cli/commands/report.ts +241 -0
- package/src/cli/commands/request.ts +379 -4
- package/src/cli/commands/run.ts +842 -53
- package/src/cli/commands/session.ts +244 -0
- package/src/cli/commands/use.ts +18 -1
- package/src/cli/index.ts +20 -3
- package/src/cli/json-envelope.ts +112 -3
- package/src/cli/json-schemas.ts +263 -0
- package/src/cli/program.ts +198 -635
- package/src/cli/resolve.ts +105 -0
- package/src/cli/status-filter.ts +124 -0
- package/src/cli/util/api-context.ts +85 -0
- package/src/cli/version.ts +5 -0
- package/src/core/anti-fp/bootstrap.ts +34 -0
- package/src/core/anti-fp/index.ts +33 -0
- package/src/core/anti-fp/registry.ts +44 -0
- package/src/core/anti-fp/rules/baseline-echo.ts +74 -0
- package/src/core/anti-fp/rules/schemathesis/body_negation_becomes_valid.ts +52 -0
- package/src/core/anti-fp/rules/schemathesis/coverage_phase_boundary_positive.ts +38 -0
- package/src/core/anti-fp/rules/schemathesis/has_unverifiable_mutations.ts +35 -0
- package/src/core/anti-fp/rules/schemathesis/index.ts +24 -0
- package/src/core/anti-fp/rules/schemathesis/string_type_mutation_becomes_valid.ts +53 -0
- package/src/core/anti-fp/rules/subscription-gated/index.ts +11 -0
- package/src/core/anti-fp/rules/subscription-gated/paid-plan-403.ts +75 -0
- package/src/core/anti-fp/types.ts +68 -0
- package/src/core/checks/checks/_crud-helpers.ts +133 -0
- package/src/core/checks/checks/_negative_mutator.ts +133 -0
- package/src/core/checks/checks/_readback-helpers.ts +133 -0
- package/src/core/checks/checks/content_type_conformance.ts +39 -0
- package/src/core/checks/checks/cross_call_references.ts +134 -0
- package/src/core/checks/checks/ensure_resource_availability.ts +62 -0
- package/src/core/checks/checks/idempotency_replay.ts +246 -0
- package/src/core/checks/checks/ignored_auth.ts +211 -0
- package/src/core/checks/checks/index.ts +65 -0
- package/src/core/checks/checks/lifecycle_transitions.ts +273 -0
- package/src/core/checks/checks/missing_required_header.ts +40 -0
- package/src/core/checks/checks/negative_data_rejection.ts +45 -0
- package/src/core/checks/checks/not_a_server_error.ts +27 -0
- package/src/core/checks/checks/open_cors_on_sensitive.ts +131 -0
- package/src/core/checks/checks/pagination_invariants.ts +238 -0
- package/src/core/checks/checks/positive_data_acceptance.ts +36 -0
- package/src/core/checks/checks/rate_limit_headers_absent.ts +77 -0
- package/src/core/checks/checks/response_headers_conformance.ts +74 -0
- package/src/core/checks/checks/response_schema_conformance.ts +30 -0
- package/src/core/checks/checks/status_code_conformance.ts +61 -0
- package/src/core/checks/checks/unsupported_method.ts +63 -0
- package/src/core/checks/checks/use_after_free.ts +78 -0
- package/src/core/checks/index.ts +30 -0
- package/src/core/checks/mode.ts +79 -0
- package/src/core/checks/recommended-action.ts +64 -0
- package/src/core/checks/registry.ts +78 -0
- package/src/core/checks/runner.ts +874 -0
- package/src/core/checks/sarif.ts +230 -0
- package/src/core/checks/stateful.ts +121 -0
- package/src/core/checks/types.ts +189 -0
- package/src/core/classifier/recommended-action.ts +222 -0
- package/src/core/context/current.ts +22 -6
- package/src/core/context/session.ts +78 -0
- package/src/core/coverage/loader.ts +185 -0
- package/src/core/coverage/reasons.ts +300 -0
- package/src/core/diagnostics/db-analysis.ts +151 -11
- package/src/core/diagnostics/failure-class.ts +120 -0
- package/src/core/diagnostics/failure-hints.ts +212 -9
- package/src/core/diagnostics/spec-pointer.ts +99 -0
- package/src/core/diagnostics/suggested-fixes.ts +156 -0
- package/src/core/exporter/case-study/index.ts +270 -0
- package/src/core/exporter/curl.ts +40 -0
- package/src/core/exporter/exporter.ts +48 -0
- package/src/core/exporter/html-report/escape.ts +24 -0
- package/src/core/exporter/html-report/index.ts +479 -0
- package/src/core/exporter/html-report/script.ts +100 -0
- package/src/core/exporter/html-report/styles.ts +408 -0
- package/src/core/generator/chunker.ts +42 -16
- package/src/core/generator/coverage-phase.ts +0 -0
- package/src/core/generator/create-body.ts +89 -0
- package/src/core/generator/data-factory.ts +445 -19
- package/src/core/generator/describe.ts +1 -1
- package/src/core/generator/fixtures-builder.ts +325 -0
- package/src/core/generator/index.ts +7 -5
- package/src/core/generator/openapi-reader.ts +37 -3
- package/src/core/generator/path-param-disambig.ts +114 -0
- package/src/core/generator/resources-builder.ts +648 -0
- package/src/core/generator/schema-utils.ts +11 -3
- package/src/core/generator/serializer.ts +103 -13
- package/src/core/generator/suite-generator.ts +419 -111
- package/src/core/generator/types.ts +8 -0
- package/src/core/identity/identity-file.ts +129 -0
- package/src/core/lint/affects.ts +28 -0
- package/src/core/lint/config.ts +96 -0
- package/src/core/lint/format.ts +42 -0
- package/src/core/lint/index.ts +94 -0
- package/src/core/lint/reporter.ts +128 -0
- package/src/core/lint/rules/consistency.ts +158 -0
- package/src/core/lint/rules/heuristics.ts +97 -0
- package/src/core/lint/rules/strictness.ts +109 -0
- package/src/core/lint/types.ts +96 -0
- package/src/core/lint/walker.ts +248 -0
- package/src/core/meta/meta-store.ts +6 -73
- package/src/core/output/README.md +91 -0
- package/src/core/output/index.ts +13 -0
- package/src/core/output/run.ts +126 -0
- package/src/core/output/types.ts +129 -0
- package/src/core/parser/env-interpolation.ts +104 -0
- package/src/core/parser/filter.ts +57 -0
- package/src/core/parser/schema.ts +129 -4
- package/src/core/parser/types.ts +19 -1
- package/src/core/parser/variables.ts +0 -0
- package/src/core/parser/yaml-parser.ts +58 -12
- package/src/core/probe/bootstrap.ts +34 -0
- package/src/core/probe/dry-run-envelope.ts +57 -0
- package/src/core/probe/mass-assignment-probe-class.ts +198 -0
- package/src/core/probe/mass-assignment-probe.ts +1122 -0
- package/src/core/probe/mass-assignment-template.ts +212 -0
- package/src/core/probe/method-probe.ts +43 -76
- package/src/core/probe/method-shared.ts +69 -0
- package/src/core/probe/negative-probe.ts +183 -149
- package/src/core/probe/orphan-tracker.ts +188 -0
- package/src/core/probe/path-discovery.ts +440 -0
- package/src/core/probe/probe-harness.ts +120 -0
- package/src/core/probe/registry.ts +89 -0
- package/src/core/probe/runner.ts +136 -0
- package/src/core/probe/security-probe-class.ts +201 -0
- package/src/core/probe/security-probe.ts +1453 -0
- package/src/core/probe/shared.ts +505 -0
- package/src/core/probe/static-probe-class.ts +125 -0
- package/src/core/probe/types.ts +165 -0
- package/src/core/probe/verdict-aggregator.ts +33 -0
- package/src/core/probe/webhooks-probe.ts +284 -0
- package/src/core/reporter/console.ts +41 -2
- package/src/core/reporter/index.ts +2 -3
- package/src/core/reporter/json.ts +11 -1
- package/src/core/reporter/junit.ts +27 -12
- package/src/core/reporter/ndjson.ts +37 -0
- package/src/core/reporter/types.ts +3 -0
- package/src/core/runner/assertions.ts +58 -1
- package/src/core/runner/async-pool.ts +108 -0
- package/src/core/runner/auth-path.ts +8 -0
- package/src/core/runner/ci-context.ts +72 -0
- package/src/core/runner/executor.ts +264 -20
- package/src/core/runner/form-encode.ts +51 -0
- package/src/core/runner/http-client.ts +75 -2
- package/src/core/runner/learn-drift.ts +293 -0
- package/src/core/runner/preflight-vars.ts +149 -0
- package/src/core/runner/progress-tracker.ts +73 -0
- package/src/core/runner/rate-limiter.ts +89 -17
- package/src/core/runner/run-kind.ts +39 -0
- package/src/core/runner/schema-validator.ts +312 -0
- package/src/core/runner/send-request.ts +153 -20
- package/src/core/runner/types.ts +38 -0
- package/src/core/secrets/registry.ts +164 -0
- package/src/core/secrets/secrets-file.ts +115 -0
- package/src/core/selectors/operation-filter.ts +144 -0
- package/src/core/setup-api.ts +415 -16
- package/src/core/severity/category.ts +94 -0
- package/src/core/severity/index.ts +121 -0
- package/src/core/spec/layers.ts +154 -0
- package/src/core/util/format-eta.ts +21 -0
- package/src/core/utils.ts +5 -1
- package/src/core/workspace/config.ts +129 -0
- package/src/core/workspace/manifest.ts +283 -0
- package/src/core/workspace/output-rotation.ts +62 -0
- package/src/core/workspace/triage-path.ts +87 -0
- package/src/db/lint-runs.ts +47 -0
- package/src/db/migrate.ts +126 -0
- package/src/db/migrations/0001_run_kind.sql +25 -0
- package/src/db/migrations/sql.d.ts +4 -0
- package/src/db/queries/collections.ts +133 -0
- package/src/db/queries/coverage.ts +9 -0
- package/src/db/queries/dashboard.ts +59 -0
- package/src/db/queries/results.ts +128 -0
- package/src/db/queries/runs.ts +235 -0
- package/src/db/queries/sessions.ts +42 -0
- package/src/db/queries/settings.ts +28 -0
- package/src/db/queries/types.ts +172 -0
- package/src/db/queries.ts +72 -802
- package/src/db/schema.ts +178 -50
- package/src/cli/commands/export.ts +0 -144
- package/src/cli/commands/guide.ts +0 -127
- package/src/cli/commands/init/templates/skills/scenarios.md +0 -97
- package/src/cli/commands/probe-methods.ts +0 -108
- package/src/cli/commands/probe-validation.ts +0 -124
- package/src/cli/commands/serve.ts +0 -114
- package/src/cli/commands/sync.ts +0 -268
- package/src/cli/commands/update.ts +0 -189
- package/src/cli/commands/validate.ts +0 -34
- package/src/core/diagnostics/render-md.ts +0 -112
- package/src/core/exporter/postman.ts +0 -963
- package/src/core/generator/guide-builder.ts +0 -253
- package/src/core/meta/types.ts +0 -19
- package/src/core/parser/index.ts +0 -21
- package/src/core/runner/execute-run.ts +0 -132
- package/src/core/runner/index.ts +0 -12
- package/src/core/sync/spec-differ.ts +0 -38
- package/src/web/data/collection-state.ts +0 -362
- package/src/web/routes/api.ts +0 -314
- package/src/web/routes/dashboard.ts +0 -350
- package/src/web/routes/runs.ts +0 -64
- package/src/web/schemas.ts +0 -121
- package/src/web/server.ts +0 -134
- package/src/web/static/htmx.min.cjs +0 -1
- package/src/web/static/style.css +0 -1148
- package/src/web/views/endpoints-tab.ts +0 -174
- package/src/web/views/explorer-tab.ts +0 -402
- package/src/web/views/health-strip.ts +0 -92
- package/src/web/views/layout.ts +0 -48
- package/src/web/views/results.ts +0 -210
- package/src/web/views/runs-tab.ts +0 -126
- package/src/web/views/suites-tab.ts +0 -181
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `${VAR}` / `${VAR:-default}` substitution for `.env.yaml` (TASK-169, m-10).
|
|
3
|
+
*
|
|
4
|
+
* Lets a workspace commit `.env.yaml` without bare secrets:
|
|
5
|
+
*
|
|
6
|
+
* auth_token: "${MYAPI_AUTH_TOKEN}"
|
|
7
|
+
* base_url: "${MYAPI_BASE_URL:-https://api.example.com}"
|
|
8
|
+
*
|
|
9
|
+
* Rules:
|
|
10
|
+
* - `${VAR}` → process.env.VAR (throws if missing).
|
|
11
|
+
* - `${VAR:-default}` → process.env.VAR ?? default. The default may
|
|
12
|
+
* contain `:` (everything after `:-` up to the closing `}` is the
|
|
13
|
+
* default).
|
|
14
|
+
* - `\${LITERAL}` → literal `${LITERAL}` (the backslash is
|
|
15
|
+
* stripped). Matches the `dotenv-expand` / docker-compose convention.
|
|
16
|
+
* - One level of resolution only — values pulled from env are NOT
|
|
17
|
+
* re-scanned for further `${...}` (cycle-risk).
|
|
18
|
+
* - Variable names matching /TOKEN|SECRET|PASSWORD|KEY|DSN/i are NOT
|
|
19
|
+
* auto-registered with the redaction registry. Auto-registration is
|
|
20
|
+
* opt-in via `@secret:` (TASK-170). We do print a one-line warning
|
|
21
|
+
* suggesting the user mark them as a secret, but only the first time.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const ENV_REF_RE = /(\\?)\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g;
|
|
25
|
+
const SUSPICIOUS_NAME_RE = /TOKEN|SECRET|PASSWORD|API_KEY|^KEY$|_KEY$|DSN/i;
|
|
26
|
+
|
|
27
|
+
export interface EnvInterpolationContext {
|
|
28
|
+
/** Absolute path of the file we're resolving — used for error messages. */
|
|
29
|
+
filePath: string;
|
|
30
|
+
/** YAML key whose value contains the reference — used for error messages. */
|
|
31
|
+
key: string;
|
|
32
|
+
/** Source of variables; defaults to `process.env`. Override in tests. */
|
|
33
|
+
env?: Record<string, string | undefined>;
|
|
34
|
+
/** Sink for human-facing warnings. Default: stderr write. */
|
|
35
|
+
warn?: (msg: string) => void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Module-level set of variable names we've already warned about, so the
|
|
39
|
+
* same `${MYAPI_AUTH_TOKEN}` reference doesn't yell once per env file. */
|
|
40
|
+
const warned = new Set<string>();
|
|
41
|
+
|
|
42
|
+
export function _resetEnvInterpolationWarnings(): void {
|
|
43
|
+
warned.clear();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Substitute every `${VAR}` / `${VAR:-default}` in `text`. Returns the
|
|
48
|
+
* fully-resolved string. Throws `Error` when an unresolved reference has
|
|
49
|
+
* no default.
|
|
50
|
+
*/
|
|
51
|
+
export function interpolateEnvRefs(text: string, ctx: EnvInterpolationContext): string {
|
|
52
|
+
if (typeof text !== "string" || text.length === 0) return text;
|
|
53
|
+
if (text.indexOf("${") === -1 && text.indexOf("\\$") === -1) return text;
|
|
54
|
+
const env = ctx.env ?? (process.env as Record<string, string | undefined>);
|
|
55
|
+
const warn = ctx.warn ?? ((m: string) => process.stderr.write(m + "\n"));
|
|
56
|
+
|
|
57
|
+
return text.replace(ENV_REF_RE, (full, escape: string, name: string, def: string | undefined) => {
|
|
58
|
+
if (escape === "\\") {
|
|
59
|
+
// Escaped reference → strip the backslash, keep the literal.
|
|
60
|
+
return full.slice(1);
|
|
61
|
+
}
|
|
62
|
+
const value = env[name];
|
|
63
|
+
if (value === undefined || value === "") {
|
|
64
|
+
if (def !== undefined) {
|
|
65
|
+
return def;
|
|
66
|
+
}
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Environment variable \${${name}} is not set (referenced from "${ctx.filePath}", key "${ctx.key}"). ` +
|
|
69
|
+
`Provide it via your shell, CI secret, or use the \${${name}:-<default>} form to give it a fallback.`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
if (SUSPICIOUS_NAME_RE.test(name) && !warned.has(name)) {
|
|
73
|
+
warned.add(name);
|
|
74
|
+
warn(
|
|
75
|
+
`[zond] ${ctx.filePath}: variable \${${name}} looks like a secret. ` +
|
|
76
|
+
`Consider mapping it through @secret:${ctx.key} (TASK-170) so it is redacted in artifacts.`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Apply interpolation to every string value in a flat env object. Other
|
|
85
|
+
* value types (numbers, booleans, nulls coming back from YAML) are
|
|
86
|
+
* stringified untouched, matching the existing loader behaviour.
|
|
87
|
+
*/
|
|
88
|
+
export function interpolateEnvObject(
|
|
89
|
+
obj: Record<string, unknown>,
|
|
90
|
+
filePath: string,
|
|
91
|
+
env?: Record<string, string | undefined>,
|
|
92
|
+
): Record<string, string> {
|
|
93
|
+
const out: Record<string, string> = {};
|
|
94
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
95
|
+
if (typeof v === "string") {
|
|
96
|
+
out[k] = interpolateEnvRefs(v, { filePath, key: k, env });
|
|
97
|
+
} else {
|
|
98
|
+
out[k] = String(v);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const SUSPICIOUS_ENV_NAME_RE = SUSPICIOUS_NAME_RE;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { TestSuite } from "./types.ts";
|
|
2
|
+
import { compileOperationFilter } from "../selectors/operation-filter.ts";
|
|
3
|
+
import type { EndpointInfo } from "../generator/types.ts";
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Filter suites by tags (OR logic, case-insensitive).
|
|
@@ -38,3 +40,58 @@ export function filterSuitesByMethod(suites: TestSuite[], method: string): TestS
|
|
|
38
40
|
}));
|
|
39
41
|
return filtered.filter(s => s.tests.length > 0);
|
|
40
42
|
}
|
|
43
|
+
|
|
44
|
+
export interface SuiteFilterResult {
|
|
45
|
+
suites: TestSuite[];
|
|
46
|
+
errors: string[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* ARV-25: parity with `zond generate`/`zond checks run` — apply the unified
|
|
51
|
+
* `--include`/`--exclude` selector grammar (path/method/tag/operation-id)
|
|
52
|
+
* to a list of test suites. Step-level selectors (path, method, operation-id)
|
|
53
|
+
* filter steps within a suite; suite-level selectors (tag) borrow each
|
|
54
|
+
* step's parent suite tags. A suite drops out once it has no steps left.
|
|
55
|
+
*
|
|
56
|
+
* Reuses `compileOperationFilter` so semantics match generate/checks 1:1
|
|
57
|
+
* (multiple --include combine with OR; --exclude evaluated after includes).
|
|
58
|
+
*
|
|
59
|
+
* `operation-id` matches against `step.source?.endpoint` ("METHOD /path"),
|
|
60
|
+
* which is what the generator records; tests authored manually without
|
|
61
|
+
* `source.endpoint` simply never match operation-id selectors.
|
|
62
|
+
*/
|
|
63
|
+
export function filterSuitesByOperationFilter(
|
|
64
|
+
suites: TestSuite[],
|
|
65
|
+
includes: string[],
|
|
66
|
+
excludes: string[],
|
|
67
|
+
): SuiteFilterResult {
|
|
68
|
+
if (includes.length === 0 && excludes.length === 0) {
|
|
69
|
+
return { suites, errors: [] };
|
|
70
|
+
}
|
|
71
|
+
const compiled = compileOperationFilter({ includes, excludes });
|
|
72
|
+
if (compiled.errors.length > 0) {
|
|
73
|
+
return { suites: [], errors: compiled.errors };
|
|
74
|
+
}
|
|
75
|
+
const filtered = suites.map(suite => ({
|
|
76
|
+
...suite,
|
|
77
|
+
tests: suite.tests.filter(step => compiled.filter(stepToEndpoint(suite, step))),
|
|
78
|
+
}));
|
|
79
|
+
return { suites: filtered.filter(s => s.tests.length > 0), errors: [] };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function stepToEndpoint(suite: TestSuite, step: TestSuite["tests"][number]): EndpointInfo {
|
|
83
|
+
const sourceEndpoint = typeof step.source?.endpoint === "string" ? step.source.endpoint : undefined;
|
|
84
|
+
return {
|
|
85
|
+
path: step.path,
|
|
86
|
+
method: step.method,
|
|
87
|
+
operationId: sourceEndpoint,
|
|
88
|
+
summary: undefined,
|
|
89
|
+
tags: suite.tags ?? [],
|
|
90
|
+
parameters: [],
|
|
91
|
+
requestBodySchema: undefined,
|
|
92
|
+
requestBodyContentType: undefined,
|
|
93
|
+
responseContentTypes: [],
|
|
94
|
+
responses: [],
|
|
95
|
+
security: [],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import type { TestSuite, TestStep, AssertionRule, TestStepExpect, SuiteConfig, RetryUntil, ForEach, MultipartField } from "./types.ts";
|
|
2
|
+
import type { TestSuite, TestStep, AssertionRule, TestStepExpect, SuiteConfig, RetryUntil, ForEach, MultipartField, SourceMetadata } from "./types.ts";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// ARV-223 (R16/F28): include OPTIONS / HEAD / TRACE so probe-method generated
|
|
5
|
+
// suites (which emit one step per missing-method per path) parse and run.
|
|
6
|
+
// Without this, `zond probe static --emit-tests → zond run` breaks end-to-end
|
|
7
|
+
// on every API where these methods aren't already declared (= almost always).
|
|
8
|
+
const HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD", "TRACE"] as const;
|
|
5
9
|
|
|
6
10
|
function extractMethodAndPath(raw: unknown): unknown {
|
|
7
11
|
if (typeof raw !== "object" || raw === null) return raw;
|
|
@@ -120,6 +124,44 @@ const TestStepExpectSchema: z.ZodType<TestStepExpect> = z.preprocess(
|
|
|
120
124
|
(val) => {
|
|
121
125
|
if (typeof val !== "object" || val === null) return val;
|
|
122
126
|
const obj = val as Record<string, unknown>;
|
|
127
|
+
// Reject `expect.capture: {...}` — non-canonical syntax some users
|
|
128
|
+
// reach for. zond captures live INSIDE body-rules
|
|
129
|
+
// (`body: { "path.to.field": { capture: var_name } }`); a top-level
|
|
130
|
+
// `capture:` block inside `expect:` is silently dropped, leaving the
|
|
131
|
+
// test green with no captured values. Throw with a clear pointer.
|
|
132
|
+
// (TASK-247)
|
|
133
|
+
if ("capture" in obj && typeof obj.capture === "object" && obj.capture !== null && !Array.isArray(obj.capture)) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
`'expect.capture: {...}' is not a valid step shape. Captures are defined per-field: ` +
|
|
136
|
+
`\`expect.body: { "<path>": { capture: <var_name> } }\`. ` +
|
|
137
|
+
`Top-level 'capture' inside 'expect' is silently ignored — the test would pass with no captured values.`,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
// expect.status: spot-message for common wrong shapes.
|
|
141
|
+
// Schema accepts `number | number[]`. Users reaching from other tools often
|
|
142
|
+
// write `oneOf: [...]`, `any: [...]`, a string `"200"`, or an array
|
|
143
|
+
// containing strings. The raw zod-issue path (`tests.N.expect.status.0`)
|
|
144
|
+
// is hard to read — surface a single-line hint here. (TASK-249, feedback-13#F1)
|
|
145
|
+
if ("status" in obj && obj.status !== undefined && obj.status !== null) {
|
|
146
|
+
const s = obj.status;
|
|
147
|
+
const STATUS_HINT =
|
|
148
|
+
"expect.status: use a number (200), an array of numbers ([200, 404]), or omit. " +
|
|
149
|
+
"oneOf/any/anyOf are not supported.";
|
|
150
|
+
if (typeof s === "object" && !Array.isArray(s)) {
|
|
151
|
+
const keys = Object.keys(s as Record<string, unknown>);
|
|
152
|
+
const wrong = keys.find((k) => ["oneOf", "anyOf", "any", "in", "one_of"].includes(k));
|
|
153
|
+
if (wrong) {
|
|
154
|
+
throw new Error(`'expect.status' got '${wrong}: [...]' — ${STATUS_HINT}`);
|
|
155
|
+
}
|
|
156
|
+
throw new Error(`'expect.status' got an object — ${STATUS_HINT}`);
|
|
157
|
+
}
|
|
158
|
+
if (typeof s === "string") {
|
|
159
|
+
throw new Error(`'expect.status' got string "${s}" — ${STATUS_HINT}`);
|
|
160
|
+
}
|
|
161
|
+
if (Array.isArray(s) && s.some((v) => typeof v !== "number")) {
|
|
162
|
+
throw new Error(`'expect.status' array must contain only numbers — ${STATUS_HINT}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
123
165
|
// body: null → remove it
|
|
124
166
|
if (obj.body === null) {
|
|
125
167
|
const { body: _, ...rest } = obj;
|
|
@@ -158,12 +200,57 @@ const MultipartFileFieldSchema = z.object({
|
|
|
158
200
|
|
|
159
201
|
const MultipartFieldSchema: z.ZodType<MultipartField> = z.union([z.string(), MultipartFileFieldSchema]);
|
|
160
202
|
|
|
203
|
+
// Provenance metadata: passthrough — все поля optional, неизвестные пропускаем без warning
|
|
204
|
+
const SourceMetadataSchema: z.ZodType<SourceMetadata> = z.object({
|
|
205
|
+
type: z.enum(["openapi-generated", "manual", "probe-suite"]).optional(),
|
|
206
|
+
spec: z.string().optional(),
|
|
207
|
+
generator: z.string().optional(),
|
|
208
|
+
generated_at: z.string().optional(),
|
|
209
|
+
endpoint: z.string().optional(),
|
|
210
|
+
response_branch: z.string().optional(),
|
|
211
|
+
schema_pointer: z.string().optional(),
|
|
212
|
+
}).passthrough() as z.ZodType<SourceMetadata>;
|
|
213
|
+
|
|
214
|
+
const KNOWN_STEP_KEYS = new Set([
|
|
215
|
+
"name", "source", "method", "path", "headers",
|
|
216
|
+
"json", "form", "multipart", "query", "expect",
|
|
217
|
+
"skip_if", "retry_until", "for_each", "set", "always",
|
|
218
|
+
// raw HTTP method keys are folded into method/path by extractMethodAndPath
|
|
219
|
+
...HTTP_METHODS,
|
|
220
|
+
]);
|
|
221
|
+
|
|
222
|
+
// Common typo / wrong-name body keys we detect explicitly to emit an
|
|
223
|
+
// actionable error instead of silently dropping. Real APIs reject the empty
|
|
224
|
+
// POST that follows, but the user spends 10+ minutes debugging — this hint
|
|
225
|
+
// turns it into a one-line fix. (TASK-244)
|
|
226
|
+
const BODY_KEY_HINTS: Record<string, string> = {
|
|
227
|
+
body: "json (for application/json), form (urlencoded), or multipart (file upload)",
|
|
228
|
+
data: "json (for application/json) or form (urlencoded)",
|
|
229
|
+
payload: "json",
|
|
230
|
+
// TASK-257: previous hint pointed only at `form:` which is x-www-form-urlencoded
|
|
231
|
+
// and useless for file uploads. Surface `multipart:` explicitly so users with
|
|
232
|
+
// file-upload endpoints (file-upload endpoints, etc.) find it.
|
|
233
|
+
raw: "json for raw JSON, multipart: { field: { file: <path> } } for file upload, or form for urlencoded — raw bodies are not parsed",
|
|
234
|
+
};
|
|
235
|
+
|
|
161
236
|
const TestStepSchema: z.ZodType<TestStep> = z.preprocess(
|
|
162
237
|
(raw) => {
|
|
163
238
|
const obj = extractMethodAndPath(raw);
|
|
164
|
-
// Make expect optional for set-only steps
|
|
165
239
|
if (typeof obj === "object" && obj !== null) {
|
|
166
240
|
const o = obj as Record<string, unknown>;
|
|
241
|
+
|
|
242
|
+
// Reject silently-dropped body-shaped keys with a clear suggestion.
|
|
243
|
+
for (const [bad, hint] of Object.entries(BODY_KEY_HINTS)) {
|
|
244
|
+
if (bad in o) {
|
|
245
|
+
const stepName = typeof o.name === "string" ? ` in step "${o.name}"` : "";
|
|
246
|
+
throw new Error(
|
|
247
|
+
`Unknown step key '${bad}'${stepName}. Did you mean '${hint}'? ` +
|
|
248
|
+
`(zond does not recognize '${bad}:' and would silently drop the body)`,
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Make expect optional for set-only steps
|
|
167
254
|
if (o.set && !o.expect) {
|
|
168
255
|
o.expect = {};
|
|
169
256
|
}
|
|
@@ -172,6 +259,7 @@ const TestStepSchema: z.ZodType<TestStep> = z.preprocess(
|
|
|
172
259
|
},
|
|
173
260
|
z.object({
|
|
174
261
|
name: z.string(),
|
|
262
|
+
source: SourceMetadataSchema.optional(),
|
|
175
263
|
method: z.enum(HTTP_METHODS),
|
|
176
264
|
path: z.string(),
|
|
177
265
|
headers: z.record(z.string(), z.string()).optional(),
|
|
@@ -219,6 +307,7 @@ const TestSuiteSchema = z.preprocess(
|
|
|
219
307
|
description: z.string().optional(),
|
|
220
308
|
setup: z.boolean().optional(),
|
|
221
309
|
tags: z.array(z.string()).optional(),
|
|
310
|
+
source: SourceMetadataSchema.optional(),
|
|
222
311
|
base_url: z.string().optional(),
|
|
223
312
|
headers: z.record(z.string(), z.string()).optional(),
|
|
224
313
|
parameterize: z.record(z.string(), z.array(z.unknown()).min(1)).optional(),
|
|
@@ -231,4 +320,40 @@ export function validateSuite(raw: unknown): TestSuite {
|
|
|
231
320
|
return TestSuiteSchema.parse(raw) as TestSuite;
|
|
232
321
|
}
|
|
233
322
|
|
|
234
|
-
|
|
323
|
+
/** Render a zod path array (`["tests", 0, "expect", "status"]`) as
|
|
324
|
+
* `tests[0].expect.status`. Numeric segments become bracket-indices, string
|
|
325
|
+
* segments dot-join. */
|
|
326
|
+
function pathToHuman(path: ReadonlyArray<string | number>): string {
|
|
327
|
+
let out = "";
|
|
328
|
+
for (const seg of path) {
|
|
329
|
+
if (typeof seg === "number") out += `[${seg}]`;
|
|
330
|
+
else out += out ? `.${seg}` : seg;
|
|
331
|
+
}
|
|
332
|
+
return out || "(root)";
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Format a {@link z.ZodError} as a compact, multi-line, human-readable list:
|
|
337
|
+
*
|
|
338
|
+
* N validation issue(s):
|
|
339
|
+
* <path>: <message>
|
|
340
|
+
* ...
|
|
341
|
+
*
|
|
342
|
+
* The default `ZodError.message` is a JSON dump of the full issue list with
|
|
343
|
+
* internal field names (`_def`, deeply numeric paths, "Invalid input" prefix).
|
|
344
|
+
* The wrapper that callers used to surface ("Validation error in <file>:
|
|
345
|
+
* [{...}]") was unreadable for tester users — they had to mentally parse the
|
|
346
|
+
* stack to find the real path. (TASK-249)
|
|
347
|
+
*/
|
|
348
|
+
export function formatZodError(err: z.ZodError): string {
|
|
349
|
+
const lines = err.issues.map((i) => {
|
|
350
|
+
const path = pathToHuman(i.path as ReadonlyArray<string | number>);
|
|
351
|
+
// zod v4 messages are already readable; strip the redundant "Invalid input: "
|
|
352
|
+
// prefix that adds noise without info.
|
|
353
|
+
const msg = i.message.replace(/^Invalid input:\s*/, "");
|
|
354
|
+
return ` ${path}: ${msg}`;
|
|
355
|
+
});
|
|
356
|
+
const header = `${err.issues.length} validation issue${err.issues.length === 1 ? "" : "s"}:`;
|
|
357
|
+
return `${header}\n${lines.join("\n")}`;
|
|
358
|
+
}
|
|
359
|
+
|
package/src/core/parser/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
1
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "HEAD" | "TRACE";
|
|
2
2
|
|
|
3
3
|
export interface AssertionRule {
|
|
4
4
|
capture?: string;
|
|
@@ -41,6 +41,22 @@ export interface ForEach {
|
|
|
41
41
|
in: unknown;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Provenance metadata: «откуда этот test/suite». Optional, не участвует в
|
|
46
|
+
* matching/dedup/validation. Suite-level задаёт общие поля; step-level
|
|
47
|
+
* наследует через shallow merge `{ ...suite.source, ...step.source }`.
|
|
48
|
+
*/
|
|
49
|
+
export interface SourceMetadata {
|
|
50
|
+
type?: "openapi-generated" | "manual" | "probe-suite";
|
|
51
|
+
spec?: string;
|
|
52
|
+
generator?: string;
|
|
53
|
+
generated_at?: string;
|
|
54
|
+
endpoint?: string;
|
|
55
|
+
response_branch?: string;
|
|
56
|
+
schema_pointer?: string;
|
|
57
|
+
[key: string]: unknown;
|
|
58
|
+
}
|
|
59
|
+
|
|
44
60
|
export interface MultipartFileField {
|
|
45
61
|
file: string;
|
|
46
62
|
filename?: string;
|
|
@@ -51,6 +67,7 @@ export type MultipartField = string | MultipartFileField;
|
|
|
51
67
|
|
|
52
68
|
export interface TestStep {
|
|
53
69
|
name: string;
|
|
70
|
+
source?: SourceMetadata;
|
|
54
71
|
method: HttpMethod;
|
|
55
72
|
path: string;
|
|
56
73
|
headers?: Record<string, string>;
|
|
@@ -85,6 +102,7 @@ export interface TestSuite {
|
|
|
85
102
|
/** If true, this suite runs before all regular suites and its captures are shared into their env */
|
|
86
103
|
setup?: boolean;
|
|
87
104
|
tags?: string[];
|
|
105
|
+
source?: SourceMetadata;
|
|
88
106
|
base_url?: string;
|
|
89
107
|
headers?: Record<string, string>;
|
|
90
108
|
/** Cross-product parameterisation: each key contributes one variable
|
|
Binary file
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { Glob } from "bun";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import YAML from "yaml";
|
|
4
|
-
import {
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { validateSuite, formatZodError } from "./schema.ts";
|
|
5
6
|
import type { TestSuite } from "./types.ts";
|
|
6
7
|
|
|
8
|
+
export interface ParseOptions {
|
|
9
|
+
/** Surface raw `ZodError.message` (the JSON-formatted issue stack) instead
|
|
10
|
+
* of the human-friendly summary. Useful for filing zod bugs / debugging the
|
|
11
|
+
* schema itself; default output is human-readable. (TASK-249) */
|
|
12
|
+
verbose?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
/** Convert a 0-based byte offset into a 1-based (line, col) position. */
|
|
8
16
|
function offsetToLineCol(text: string, offset: number): { line: number; col: number } {
|
|
9
17
|
let line = 1;
|
|
@@ -41,7 +49,7 @@ export function formatYamlParseError(filePath: string, text: string, primary: Er
|
|
|
41
49
|
return new Error(`Invalid YAML in ${filePath}: ${primary.message}`);
|
|
42
50
|
}
|
|
43
51
|
|
|
44
|
-
export async function parseFile(filePath: string): Promise<TestSuite> {
|
|
52
|
+
export async function parseFile(filePath: string, opts: ParseOptions = {}): Promise<TestSuite> {
|
|
45
53
|
let text: string;
|
|
46
54
|
try {
|
|
47
55
|
text = await Bun.file(filePath).text();
|
|
@@ -72,22 +80,40 @@ export async function parseFile(filePath: string): Promise<TestSuite> {
|
|
|
72
80
|
suite.filePath = resolve(filePath);
|
|
73
81
|
return suite;
|
|
74
82
|
} catch (err) {
|
|
83
|
+
if (err instanceof z.ZodError && !opts.verbose) {
|
|
84
|
+
throw new Error(`Validation error in ${filePath}:\n${formatZodError(err)}`);
|
|
85
|
+
}
|
|
75
86
|
throw new Error(`Validation error in ${filePath}: ${(err as Error).message}`);
|
|
76
87
|
}
|
|
77
88
|
}
|
|
78
89
|
|
|
79
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Files that live alongside test suites but aren't suites themselves. The
|
|
92
|
+
* yaml-parser scans recursively from the workspace root, so picking these up
|
|
93
|
+
* would surface spurious "Validation error: missing field name" noise.
|
|
94
|
+
*/
|
|
95
|
+
function isNonSuiteYaml(file: string): boolean {
|
|
96
|
+
if (file.match(/\.env(\..+)?\.ya?ml$/)) return true;
|
|
97
|
+
// Workspace marker — present at the root of every zond workspace.
|
|
98
|
+
if (file === "zond.config.yml" || file === "zond.config.yaml") return true;
|
|
99
|
+
// Per-API artifact files written by `zond add api` / `zond refresh-api`.
|
|
100
|
+
// Match the basename so it works for files at any depth (apis/<name>/...).
|
|
101
|
+
const basename = file.split("/").pop() ?? file;
|
|
102
|
+
if (/^\.api-[a-z0-9-]+\.ya?ml$/i.test(basename)) return true;
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function parseDirectory(dirPath: string, opts: ParseOptions = {}): Promise<TestSuite[]> {
|
|
80
107
|
const glob = new Glob("**/*.{yaml,yml}");
|
|
81
108
|
const suites: TestSuite[] = [];
|
|
82
109
|
|
|
83
110
|
for await (const file of glob.scan({ cwd: dirPath, absolute: false })) {
|
|
84
|
-
|
|
85
|
-
if (file.match(/\.env(\..+)?\.yaml$/) || file.match(/\.env(\..+)?\.yml$/)) {
|
|
111
|
+
if (isNonSuiteYaml(file)) {
|
|
86
112
|
continue;
|
|
87
113
|
}
|
|
88
114
|
const fullPath = `${dirPath}/${file}`;
|
|
89
115
|
try {
|
|
90
|
-
suites.push(await parseFile(fullPath));
|
|
116
|
+
suites.push(await parseFile(fullPath, opts));
|
|
91
117
|
} catch {
|
|
92
118
|
// Skip files that fail to parse (e.g. invalid AI-generated YAML)
|
|
93
119
|
// so one bad file doesn't block the entire directory
|
|
@@ -102,18 +128,18 @@ export interface ParseDirectoryResult {
|
|
|
102
128
|
errors: { file: string; error: string }[];
|
|
103
129
|
}
|
|
104
130
|
|
|
105
|
-
export async function parseDirectorySafe(dirPath: string): Promise<ParseDirectoryResult> {
|
|
131
|
+
export async function parseDirectorySafe(dirPath: string, opts: ParseOptions = {}): Promise<ParseDirectoryResult> {
|
|
106
132
|
const glob = new Glob("**/*.{yaml,yml}");
|
|
107
133
|
const suites: TestSuite[] = [];
|
|
108
134
|
const errors: { file: string; error: string }[] = [];
|
|
109
135
|
|
|
110
136
|
for await (const file of glob.scan({ cwd: dirPath, absolute: false })) {
|
|
111
|
-
if (
|
|
137
|
+
if (isNonSuiteYaml(file)) {
|
|
112
138
|
continue;
|
|
113
139
|
}
|
|
114
140
|
const fullPath = `${dirPath}/${file}`;
|
|
115
141
|
try {
|
|
116
|
-
suites.push(await parseFile(fullPath));
|
|
142
|
+
suites.push(await parseFile(fullPath, opts));
|
|
117
143
|
} catch (err) {
|
|
118
144
|
errors.push({ file, error: (err as Error).message });
|
|
119
145
|
}
|
|
@@ -122,14 +148,34 @@ export async function parseDirectorySafe(dirPath: string): Promise<ParseDirector
|
|
|
122
148
|
return { suites, errors };
|
|
123
149
|
}
|
|
124
150
|
|
|
125
|
-
export async function parse(path: string): Promise<TestSuite[]> {
|
|
151
|
+
export async function parse(path: string, opts: ParseOptions = {}): Promise<TestSuite[]> {
|
|
126
152
|
const file = Bun.file(path);
|
|
127
153
|
const exists = await file.exists();
|
|
128
154
|
|
|
129
155
|
if (exists) {
|
|
130
|
-
return [await parseFile(path)];
|
|
156
|
+
return [await parseFile(path, opts)];
|
|
131
157
|
}
|
|
132
158
|
|
|
133
159
|
// Not a file, try as directory
|
|
134
|
-
return parseDirectory(path);
|
|
160
|
+
return parseDirectory(path, opts);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Like {@link parse}, but never silently drops files. Returns both successfully
|
|
165
|
+
* parsed suites and per-file parse errors so callers (run, validate, tag-filter)
|
|
166
|
+
* can surface failures instead of pretending the file did not exist.
|
|
167
|
+
*/
|
|
168
|
+
export async function parseSafe(path: string, opts: ParseOptions = {}): Promise<ParseDirectoryResult> {
|
|
169
|
+
const file = Bun.file(path);
|
|
170
|
+
const exists = await file.exists();
|
|
171
|
+
|
|
172
|
+
if (exists) {
|
|
173
|
+
try {
|
|
174
|
+
return { suites: [await parseFile(path, opts)], errors: [] };
|
|
175
|
+
} catch (err) {
|
|
176
|
+
return { suites: [], errors: [{ file: path, error: (err as Error).message }] };
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return parseDirectorySafe(path, opts);
|
|
135
181
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Probe registry bootstrap (m-17 / ARV-49).
|
|
3
|
+
*
|
|
4
|
+
* Called once from the CLI program init. Imports each Probe class and
|
|
5
|
+
* runs `registerProbe`, which validates the contract from `types.ts`
|
|
6
|
+
* and throws if a slot is missing. Boot-time failure is louder than
|
|
7
|
+
* runtime — adding a new probe class without --dry-run / --report
|
|
8
|
+
* support won't ship; that's the whole point of the m-17 contract.
|
|
9
|
+
*
|
|
10
|
+
* Idempotent: repeated calls are no-ops (matters for unit tests that
|
|
11
|
+
* run the bootstrap multiple times).
|
|
12
|
+
*/
|
|
13
|
+
import { listProbes, registerProbe } from "./registry.ts";
|
|
14
|
+
import { SecurityProbe } from "./security-probe-class.ts";
|
|
15
|
+
import { MassAssignmentProbe } from "./mass-assignment-probe-class.ts";
|
|
16
|
+
import { StaticProbe } from "./static-probe-class.ts";
|
|
17
|
+
|
|
18
|
+
let bootstrapped = false;
|
|
19
|
+
|
|
20
|
+
export function bootstrapProbes(): void {
|
|
21
|
+
if (bootstrapped) return;
|
|
22
|
+
if (listProbes().length === 0) {
|
|
23
|
+
registerProbe(new StaticProbe());
|
|
24
|
+
registerProbe(new MassAssignmentProbe());
|
|
25
|
+
registerProbe(new SecurityProbe());
|
|
26
|
+
}
|
|
27
|
+
bootstrapped = true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Test helper — resets the singleton so the next `bootstrapProbes()`
|
|
31
|
+
* re-registers from scratch. Pair with `clearProbes()` from registry. */
|
|
32
|
+
export function resetBootstrap(): void {
|
|
33
|
+
bootstrapped = false;
|
|
34
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dry-run envelope helpers (m-17 / ARV-50).
|
|
3
|
+
*
|
|
4
|
+
* `--dry-run` answers "what would I attack" — severity is undefined
|
|
5
|
+
* because nothing was classified. Both probe-security and
|
|
6
|
+
* probe-mass-assignment write this shape into `data` instead of the
|
|
7
|
+
* legacy severity-bucket structure that conflated planned attacks
|
|
8
|
+
* with skipped endpoints (F1-15).
|
|
9
|
+
*/
|
|
10
|
+
import type { EndpointPlan } from "./types.ts";
|
|
11
|
+
|
|
12
|
+
export interface DryRunSummary {
|
|
13
|
+
totalEndpoints: number;
|
|
14
|
+
planned: number;
|
|
15
|
+
skipped: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface DryRunEnvelopeData {
|
|
19
|
+
endpoints: EndpointPlan[];
|
|
20
|
+
summary: DryRunSummary;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function summarizeDryRun(plans: EndpointPlan[]): DryRunEnvelopeData {
|
|
24
|
+
let planned = 0;
|
|
25
|
+
let skipped = 0;
|
|
26
|
+
for (const p of plans) {
|
|
27
|
+
if (p.planned) planned++;
|
|
28
|
+
else skipped++;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
endpoints: plans,
|
|
32
|
+
summary: {
|
|
33
|
+
totalEndpoints: plans.length,
|
|
34
|
+
planned,
|
|
35
|
+
skipped,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Render a short human digest for the dry-run plan (used by non-json
|
|
41
|
+
* output). One line per endpoint, planned/skipped counts at the end. */
|
|
42
|
+
export function formatDryRunDigest(plans: EndpointPlan[]): string {
|
|
43
|
+
const lines: string[] = [];
|
|
44
|
+
for (const p of plans) {
|
|
45
|
+
if (p.planned) {
|
|
46
|
+
const fields = p.fields_planned.length > 0 ? ` fields=${p.fields_planned.join(",")}` : "";
|
|
47
|
+
const cls = p.classes_planned.length > 0 ? ` classes=${p.classes_planned.join(",")}` : "";
|
|
48
|
+
lines.push(` + ${p.method} ${p.path}${cls}${fields}`);
|
|
49
|
+
} else {
|
|
50
|
+
lines.push(` - ${p.method} ${p.path} (skipped: ${p.skip_reason ?? "unknown"})`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const summary = summarizeDryRun(plans).summary;
|
|
54
|
+
lines.push("");
|
|
55
|
+
lines.push(`Plan: ${summary.planned} planned · ${summary.skipped} skipped · ${summary.totalEndpoints} total`);
|
|
56
|
+
return lines.join("\n");
|
|
57
|
+
}
|