@kirrosh/zond 0.21.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 +758 -3
- package/README.md +78 -15
- package/package.json +17 -10
- 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 +55 -6
- package/src/cli/commands/clean.ts +212 -0
- package/src/cli/commands/cleanup.ts +262 -0
- package/src/cli/commands/completions.ts +192 -0
- package/src/cli/commands/coverage.ts +605 -132
- package/src/cli/commands/db.ts +180 -8
- 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 -47
- package/src/cli/commands/init/agents-md.ts +61 -0
- package/src/cli/commands/init/bootstrap.ts +108 -0
- package/src/cli/commands/init/index.ts +244 -0
- package/src/cli/commands/init/skills.ts +98 -0
- package/src/cli/commands/init/templates/agents.md +77 -0
- package/src/cli/commands/init/templates/markdown.d.ts +4 -0
- 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 +651 -0
- package/src/cli/commands/init/templates/zond-config.yml +14 -0
- 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 +911 -33
- package/src/cli/commands/session.ts +244 -0
- package/src/cli/commands/use.ts +74 -0
- package/src/cli/index.ts +36 -607
- package/src/cli/json-envelope.ts +112 -3
- package/src/cli/json-schemas.ts +263 -0
- package/src/cli/program.ts +218 -0
- 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 +8 -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 +51 -0
- 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 +161 -12
- 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 +53 -15
- 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 +490 -33
- 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 +55 -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 +114 -15
- package/src/core/generator/suite-generator.ts +484 -77
- 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 +132 -5
- package/src/core/parser/types.ts +29 -2
- package/src/core/parser/variables.ts +0 -0
- package/src/core/parser/yaml-parser.ts +108 -13
- 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 +164 -0
- package/src/core/probe/method-shared.ts +69 -0
- package/src/core/probe/negative-probe.ts +691 -0
- 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 +69 -4
- package/src/core/reporter/index.ts +2 -3
- package/src/core/reporter/json.ts +15 -2
- 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 +62 -2
- 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 +391 -52
- package/src/core/runner/form-encode.ts +51 -0
- package/src/core/runner/http-client.ts +115 -7
- 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 +203 -0
- 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 +419 -17
- 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/root.ts +94 -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 +179 -48
- package/src/cli/commands/export.ts +0 -144
- package/src/cli/commands/guide.ts +0 -127
- package/src/cli/commands/init.ts +0 -57
- package/src/cli/commands/serve.ts +0 -81
- package/src/cli/commands/sync.ts +0 -269
- package/src/cli/commands/update.ts +0 -189
- package/src/cli/commands/validate.ts +0 -34
- package/src/core/exporter/postman.ts +0 -963
- package/src/core/generator/guide-builder.ts +0 -253
- package/src/core/meta/types.ts +0 -21
- 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
|
@@ -9,6 +9,7 @@ import { jsonOk, jsonError, printJson } from "../json-envelope.ts";
|
|
|
9
9
|
|
|
10
10
|
export interface CatalogOptions {
|
|
11
11
|
specPath: string;
|
|
12
|
+
/** Output directory. Defaults to the API's base dir when --api is given, otherwise cwd. */
|
|
12
13
|
output?: string;
|
|
13
14
|
json?: boolean;
|
|
14
15
|
}
|
|
@@ -60,3 +61,37 @@ export async function catalogCommand(options: CatalogOptions): Promise<number> {
|
|
|
60
61
|
return 2;
|
|
61
62
|
}
|
|
62
63
|
}
|
|
64
|
+
|
|
65
|
+
import type { Command } from "commander";
|
|
66
|
+
import { globalJson, resolveSpecArg, resolveApiCollection } from "../resolve.ts";
|
|
67
|
+
|
|
68
|
+
export function registerCatalog(program: Command): void {
|
|
69
|
+
program
|
|
70
|
+
.command("catalog [spec]")
|
|
71
|
+
.description("Generate API catalog (compact endpoint reference). For registered APIs prefer --api <name>; the artifact is also available at apis/<name>/.api-catalog.yaml.")
|
|
72
|
+
.option("--api <name>", "Use the registered API's spec (apis/<name>/spec.json)")
|
|
73
|
+
.option("--db <path>", "Path to SQLite database file")
|
|
74
|
+
.option("--output <dir>", "Output directory (default: apis/<name>/ when --api is given, else cwd)")
|
|
75
|
+
.action(async (specPos: string | undefined, opts, cmd: Command) => {
|
|
76
|
+
const resolved = resolveSpecArg(specPos, opts.api, opts.db);
|
|
77
|
+
if ("error" in resolved) { printError(resolved.error); process.exitCode = 2; return; }
|
|
78
|
+
|
|
79
|
+
// When --api is given and no explicit --output, default to the API's base dir so
|
|
80
|
+
// the artifact lands alongside spec.json / .api-resources.yaml / .api-fixtures.yaml.
|
|
81
|
+
let outputDir: string | undefined = opts.output;
|
|
82
|
+
if (!outputDir && opts.api) {
|
|
83
|
+
const col = resolveApiCollection(opts.api, opts.db);
|
|
84
|
+
if (!("error" in col) && col.testPath) {
|
|
85
|
+
// testPath is apis/<name>/tests — go up one level to get apis/<name>/
|
|
86
|
+
const { dirname } = await import("path");
|
|
87
|
+
outputDir = dirname(col.testPath);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
process.exitCode = await catalogCommand({
|
|
92
|
+
specPath: resolved.spec,
|
|
93
|
+
output: outputDir,
|
|
94
|
+
json: globalJson(cmd),
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `zond check` — unified conformance entry point.
|
|
3
|
+
*
|
|
4
|
+
* `check tests <path>` → schema-validate YAML test files (no HTTP).
|
|
5
|
+
* `check spec [spec]` → static-analyse the OpenAPI document.
|
|
6
|
+
*
|
|
7
|
+
* TASK-298 (m-13 block D): replaces the old top-level `validate` and
|
|
8
|
+
* `lint-spec` commands with a single mental model.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { parse } from "../../core/parser/yaml-parser.ts";
|
|
12
|
+
import { readOpenApiSpec } from "../../core/generator/openapi-reader.ts";
|
|
13
|
+
import {
|
|
14
|
+
lintSpec,
|
|
15
|
+
loadConfig,
|
|
16
|
+
formatHuman,
|
|
17
|
+
formatNdjson,
|
|
18
|
+
formatGrouped,
|
|
19
|
+
buildRuleSummary,
|
|
20
|
+
} from "../../core/lint/index.ts";
|
|
21
|
+
import type { Issue, Severity } from "../../core/lint/index.ts";
|
|
22
|
+
import { getDb } from "../../db/schema.ts";
|
|
23
|
+
import { createLintRun, finalizeLintRun } from "../../db/lint-runs.ts";
|
|
24
|
+
import { jsonOk, jsonError, printJson, zerr } from "../json-envelope.ts";
|
|
25
|
+
import { printError, printSuccess } from "../output.ts";
|
|
26
|
+
|
|
27
|
+
import type { Command } from "commander";
|
|
28
|
+
import { globalJson, resolveSpecArg } from "../resolve.ts";
|
|
29
|
+
import { parsePositiveInt } from "../argv.ts";
|
|
30
|
+
|
|
31
|
+
// ── check tests ────────────────────────────────────────────────────────────
|
|
32
|
+
|
|
33
|
+
export interface CheckTestsOptions {
|
|
34
|
+
path: string;
|
|
35
|
+
json?: boolean;
|
|
36
|
+
verbose?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function checkTestsCommand(options: CheckTestsOptions): Promise<number> {
|
|
40
|
+
try {
|
|
41
|
+
const suites = await parse(options.path, { verbose: options.verbose });
|
|
42
|
+
const totalSteps = suites.reduce((sum, s) => sum + s.tests.length, 0);
|
|
43
|
+
if (options.json) {
|
|
44
|
+
printJson(jsonOk("check tests", {
|
|
45
|
+
files: suites.length,
|
|
46
|
+
suites: suites.length,
|
|
47
|
+
tests: totalSteps,
|
|
48
|
+
valid: true,
|
|
49
|
+
}));
|
|
50
|
+
} else {
|
|
51
|
+
printSuccess(`OK: ${suites.length} suite(s), ${totalSteps} test(s) validated successfully`);
|
|
52
|
+
}
|
|
53
|
+
return 0;
|
|
54
|
+
} catch (err) {
|
|
55
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
56
|
+
if (options.json) {
|
|
57
|
+
printJson(jsonError("check tests", [message]));
|
|
58
|
+
} else {
|
|
59
|
+
printError(message);
|
|
60
|
+
}
|
|
61
|
+
return 2;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ── check spec ─────────────────────────────────────────────────────────────
|
|
66
|
+
|
|
67
|
+
export interface CheckSpecOptions {
|
|
68
|
+
specPath: string;
|
|
69
|
+
json?: boolean;
|
|
70
|
+
ndjson?: boolean;
|
|
71
|
+
strict?: boolean;
|
|
72
|
+
rule?: string;
|
|
73
|
+
config?: string;
|
|
74
|
+
includePath?: string[];
|
|
75
|
+
maxIssues?: number;
|
|
76
|
+
noDb?: boolean;
|
|
77
|
+
verbose?: boolean;
|
|
78
|
+
severityFilter?: Severity[];
|
|
79
|
+
filterRule?: string[];
|
|
80
|
+
top?: number;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export async function checkSpecCommand(opts: CheckSpecOptions): Promise<number> {
|
|
84
|
+
let doc;
|
|
85
|
+
try {
|
|
86
|
+
doc = await readOpenApiSpec(opts.specPath);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
89
|
+
if (opts.json || opts.ndjson) {
|
|
90
|
+
printJson(jsonError("check spec", [
|
|
91
|
+
zerr("spec_load_failure", `Failed to load spec: ${message}`, { specPath: opts.specPath }),
|
|
92
|
+
]));
|
|
93
|
+
} else {
|
|
94
|
+
printError(`Failed to load spec: ${message}`);
|
|
95
|
+
}
|
|
96
|
+
return 2;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let config;
|
|
100
|
+
try {
|
|
101
|
+
config = loadConfig({
|
|
102
|
+
configPath: opts.config,
|
|
103
|
+
cliRule: opts.rule,
|
|
104
|
+
includePaths: opts.includePath,
|
|
105
|
+
maxIssues: opts.maxIssues,
|
|
106
|
+
});
|
|
107
|
+
} catch (err) {
|
|
108
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
109
|
+
if (opts.json || opts.ndjson) {
|
|
110
|
+
printJson(jsonError("check spec", [zerr("argument_invalid", message)]));
|
|
111
|
+
} else {
|
|
112
|
+
printError(message);
|
|
113
|
+
}
|
|
114
|
+
return 2;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let runId: number | null = null;
|
|
118
|
+
if (!opts.noDb) {
|
|
119
|
+
try {
|
|
120
|
+
const db = getDb();
|
|
121
|
+
runId = createLintRun(db, opts.specPath);
|
|
122
|
+
} catch {
|
|
123
|
+
runId = null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const result = lintSpec(doc, config);
|
|
128
|
+
|
|
129
|
+
if (runId !== null) {
|
|
130
|
+
try {
|
|
131
|
+
finalizeLintRun(getDb(), runId, result.issues, result.stats, config);
|
|
132
|
+
} catch {
|
|
133
|
+
// best-effort
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const filtered = applyFilters(result.issues, opts);
|
|
138
|
+
const filteredStats = recomputeStats(filtered);
|
|
139
|
+
|
|
140
|
+
if (opts.ndjson) {
|
|
141
|
+
process.stdout.write(formatNdjson(filtered));
|
|
142
|
+
} else if (opts.json) {
|
|
143
|
+
printJson(jsonOk("check spec", {
|
|
144
|
+
issues: filtered,
|
|
145
|
+
stats: filteredStats,
|
|
146
|
+
summary: buildRuleSummary(filtered),
|
|
147
|
+
}));
|
|
148
|
+
} else if (opts.verbose) {
|
|
149
|
+
process.stdout.write(formatHuman(filtered, filteredStats));
|
|
150
|
+
} else {
|
|
151
|
+
process.stdout.write(formatGrouped(filtered, filteredStats, { top: opts.top }));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ARV-255: lint is hygiene — never gates CI by default. `--strict`
|
|
155
|
+
// opts back into a non-zero exit when any issue lands. The old "high
|
|
156
|
+
// → 1, medium → 2" gating is gone because no rule emits HIGH/MEDIUM
|
|
157
|
+
// anymore (severity matrix forbids it for static analysis).
|
|
158
|
+
if (opts.strict && result.stats.total > 0) return 2;
|
|
159
|
+
return 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function applyFilters(issues: Issue[], opts: CheckSpecOptions): Issue[] {
|
|
163
|
+
let out = issues;
|
|
164
|
+
if (opts.severityFilter && opts.severityFilter.length > 0) {
|
|
165
|
+
const allow = new Set(opts.severityFilter);
|
|
166
|
+
out = out.filter(i => allow.has(i.severity));
|
|
167
|
+
}
|
|
168
|
+
if (opts.filterRule && opts.filterRule.length > 0) {
|
|
169
|
+
const allow = new Set(opts.filterRule.map(r => r.toUpperCase()));
|
|
170
|
+
out = out.filter(i => allow.has(i.rule));
|
|
171
|
+
}
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function recomputeStats(issues: Issue[]) {
|
|
176
|
+
const endpoints = new Set<string>();
|
|
177
|
+
for (const i of issues) {
|
|
178
|
+
if (i.path) endpoints.add(`${i.method ?? "*"} ${i.path}`);
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
total: issues.length,
|
|
182
|
+
critical: issues.filter(i => i.severity === "critical").length,
|
|
183
|
+
high: issues.filter(i => i.severity === "high").length,
|
|
184
|
+
medium: issues.filter(i => i.severity === "medium").length,
|
|
185
|
+
low: issues.filter(i => i.severity === "low").length,
|
|
186
|
+
info: issues.filter(i => i.severity === "info").length,
|
|
187
|
+
endpoints: endpoints.size,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function parseSeverityList(raw: unknown): Severity[] | undefined {
|
|
192
|
+
if (typeof raw !== "string" || raw.trim() === "") return undefined;
|
|
193
|
+
const allowed: Severity[] = ["critical", "high", "medium", "low", "info"];
|
|
194
|
+
const items = raw.split(",").map(s => s.trim().toLowerCase()).filter(Boolean) as Severity[];
|
|
195
|
+
return items.filter(s => allowed.includes(s));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* TASK-291 / TASK-298: parse --rule (and the deprecated --filter-rule) into
|
|
200
|
+
* the two downstream channels: cliRule (severity overrides + disables, fed
|
|
201
|
+
* to loadConfig) and whitelist (rule-id allow-list, applied post-lint).
|
|
202
|
+
*/
|
|
203
|
+
export function mergeRuleFlags(
|
|
204
|
+
ruleArg: unknown,
|
|
205
|
+
filterRuleArg: unknown,
|
|
206
|
+
): { cliRule: string | undefined; whitelist: string[] | undefined } {
|
|
207
|
+
const ruleItems = splitCsv(ruleArg);
|
|
208
|
+
const filterItems = splitCsv(filterRuleArg);
|
|
209
|
+
|
|
210
|
+
if (filterItems.length > 0) {
|
|
211
|
+
process.stderr.write(
|
|
212
|
+
"[zond] --filter-rule is deprecated, use --rule with the same comma-separated rule ids (TASK-291).\n",
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const cliRuleItems: string[] = [];
|
|
217
|
+
const whitelist = new Set<string>();
|
|
218
|
+
let anyPositive = false;
|
|
219
|
+
|
|
220
|
+
for (const raw of ruleItems) {
|
|
221
|
+
const item = raw.trim();
|
|
222
|
+
if (!item) continue;
|
|
223
|
+
if (item.startsWith("!")) {
|
|
224
|
+
cliRuleItems.push(item);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const eq = item.indexOf("=");
|
|
228
|
+
if (eq >= 0) {
|
|
229
|
+
const id = item.slice(0, eq).trim().toUpperCase();
|
|
230
|
+
const sev = item.slice(eq + 1).trim().toLowerCase();
|
|
231
|
+
if (sev === "off") {
|
|
232
|
+
cliRuleItems.push(`!${id}`);
|
|
233
|
+
} else {
|
|
234
|
+
cliRuleItems.push(`${id}=${sev}`);
|
|
235
|
+
whitelist.add(id);
|
|
236
|
+
anyPositive = true;
|
|
237
|
+
}
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
whitelist.add(item.toUpperCase());
|
|
241
|
+
anyPositive = true;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
for (const raw of filterItems) {
|
|
245
|
+
const id = raw.trim().toUpperCase();
|
|
246
|
+
if (!id) continue;
|
|
247
|
+
whitelist.add(id);
|
|
248
|
+
anyPositive = true;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return {
|
|
252
|
+
cliRule: cliRuleItems.length > 0 ? cliRuleItems.join(",") : undefined,
|
|
253
|
+
whitelist: anyPositive ? [...whitelist] : undefined,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function splitCsv(raw: unknown): string[] {
|
|
258
|
+
if (typeof raw !== "string") return [];
|
|
259
|
+
return raw.split(",").map(s => s.trim()).filter(Boolean);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ── registration ───────────────────────────────────────────────────────────
|
|
263
|
+
|
|
264
|
+
export function registerCheck(program: Command): void {
|
|
265
|
+
const check = program
|
|
266
|
+
.command("check")
|
|
267
|
+
.description("Conformance checks: YAML test files (`check tests`) and the OpenAPI spec (`check spec`)");
|
|
268
|
+
|
|
269
|
+
check
|
|
270
|
+
.command("tests <path>")
|
|
271
|
+
.description("Schema-validate test files without running them")
|
|
272
|
+
.option("--verbose", "Show full zod issue stack instead of human-friendly summary")
|
|
273
|
+
.action(async (path: string, opts: { verbose?: boolean }, cmd: Command) => {
|
|
274
|
+
process.exitCode = await checkTestsCommand({
|
|
275
|
+
path,
|
|
276
|
+
json: globalJson(cmd),
|
|
277
|
+
verbose: opts.verbose === true,
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
defineCheckSpec(check, "spec");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* ARV-255 (m-21 pivot): register `zond lint` as a top-level command,
|
|
286
|
+
* aliasing the existing `check spec` workflow. Spec-lint is hygiene —
|
|
287
|
+
* not part of the security/contract audit — so it gets a dedicated
|
|
288
|
+
* verb that makes the workflow explicit and keeps the audit report
|
|
289
|
+
* uncluttered. Same flag wiring, same code path, just a clearer name.
|
|
290
|
+
*/
|
|
291
|
+
export function registerLint(program: Command): void {
|
|
292
|
+
defineCheckSpec(program, "lint");
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function defineCheckSpec(parent: Command, name: string): void {
|
|
296
|
+
parent
|
|
297
|
+
.command(`${name} [spec]`)
|
|
298
|
+
.description(
|
|
299
|
+
name === "lint"
|
|
300
|
+
? "ARV-255: spec-lint (hygiene category). Static-analyse an OpenAPI spec for style and structural gaps. Severity capped at LOW/INFO — never gates CI unless --strict. Equivalent to `zond check spec`."
|
|
301
|
+
: "Static-analyse an OpenAPI spec for internal-consistency and strictness gaps (catches bugs before any HTTP). ARV-255: severity capped at LOW/INFO — no HIGH/MEDIUM from static analysis.",
|
|
302
|
+
)
|
|
303
|
+
.option("--api <name>", "Use the registered API's spec (apis/<name>/spec.json)")
|
|
304
|
+
.option("--strict", "Exit non-zero even on LOW-severity issues")
|
|
305
|
+
.option("--ndjson", "Stream issues as one JSON per line (NDJSON), instead of the wrapped envelope")
|
|
306
|
+
.option(
|
|
307
|
+
"--rule <list>",
|
|
308
|
+
"Unified rule selector (TASK-291). Comma-separated items: 'B1' (whitelist), " +
|
|
309
|
+
"'!B2' (disable), 'B3=low|info' (severity override; also implicitly whitelists). " +
|
|
310
|
+
"All-plain or all-override → whitelist mode (only these rules render). All-'!' → blacklist mode " +
|
|
311
|
+
"(exclude these). Mixed → whitelist + overrides + disables together. ARV-255: high/medium overrides ignored (cap is LOW).",
|
|
312
|
+
)
|
|
313
|
+
.option(
|
|
314
|
+
"--filter-rule <list>",
|
|
315
|
+
"Deprecated alias for the whitelist subset of --rule (TASK-291). Will be removed; emits a stderr warning.",
|
|
316
|
+
)
|
|
317
|
+
.option("--config <path>", "Path to .zond-lint.json")
|
|
318
|
+
.option("--include-path <glob...>", "Only lint endpoints whose path matches glob (repeatable)")
|
|
319
|
+
.option("--max-issues <N>", "Stop after N issues", parsePositiveInt("--max-issues"))
|
|
320
|
+
.option("--verbose, --flat", "Render the legacy flat one-line-per-issue list (default is now a rule × severity rollup, TASK-279)")
|
|
321
|
+
.option("--severity <list>", "Filter rendered/JSON output to severities (comma-separated: low,info)")
|
|
322
|
+
.option("--top <N>", "In the grouped summary, show only the top-N rules by count", parsePositiveInt("--top"))
|
|
323
|
+
.option("--no-db", "Don't write to lint_runs SQLite history")
|
|
324
|
+
.action(async (specPos: string | undefined, opts, cmd: Command) => {
|
|
325
|
+
const dbPath = typeof opts.db === "string" ? opts.db : undefined;
|
|
326
|
+
const resolved = resolveSpecArg(specPos, opts.api, dbPath);
|
|
327
|
+
if ("error" in resolved) { printError(resolved.error); process.exitCode = 2; return; }
|
|
328
|
+
const sevFilter = parseSeverityList(opts.severity);
|
|
329
|
+
|
|
330
|
+
const merged = mergeRuleFlags(opts.rule, opts.filterRule);
|
|
331
|
+
|
|
332
|
+
process.exitCode = await checkSpecCommand({
|
|
333
|
+
specPath: resolved.spec,
|
|
334
|
+
json: globalJson(cmd),
|
|
335
|
+
ndjson: opts.ndjson === true,
|
|
336
|
+
strict: opts.strict === true,
|
|
337
|
+
rule: merged.cliRule,
|
|
338
|
+
config: opts.config,
|
|
339
|
+
includePath: opts.includePath,
|
|
340
|
+
maxIssues: opts.maxIssues,
|
|
341
|
+
noDb: opts.db === false,
|
|
342
|
+
verbose: opts.verbose === true || opts.flat === true,
|
|
343
|
+
severityFilter: sevFilter,
|
|
344
|
+
filterRule: merged.whitelist,
|
|
345
|
+
top: typeof opts.top === "number" ? opts.top : undefined,
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
}
|