@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,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `.zond/manifest.json` — auto-generated file tracking (TASK-156, m-9).
|
|
3
|
+
*
|
|
4
|
+
* Every command that writes files into the workspace appends an entry
|
|
5
|
+
* here so `zond clean` can later remove only what zond produced, leaving
|
|
6
|
+
* user edits intact (sha256 mismatch → manually-edited → skipped).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, statSync } from "node:fs";
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
12
|
+
|
|
13
|
+
const MANIFEST_VERSION = 1;
|
|
14
|
+
const MANIFEST_RELPATH = ".zond/manifest.json";
|
|
15
|
+
|
|
16
|
+
export type ManifestCategory =
|
|
17
|
+
| "spec"
|
|
18
|
+
| "catalog"
|
|
19
|
+
| "resources"
|
|
20
|
+
| "fixtures"
|
|
21
|
+
| "env"
|
|
22
|
+
| "tests"
|
|
23
|
+
| "probes"
|
|
24
|
+
| "other";
|
|
25
|
+
|
|
26
|
+
export interface ManifestEntry {
|
|
27
|
+
/** Workspace-relative POSIX path. */
|
|
28
|
+
path: string;
|
|
29
|
+
/** sha256 of the file contents at write-time. */
|
|
30
|
+
sha256: string;
|
|
31
|
+
/** Command that emitted the file (e.g. "zond generate", "zond probe-validation --emit"). */
|
|
32
|
+
by: string;
|
|
33
|
+
/** ISO 8601 timestamp. */
|
|
34
|
+
ts: string;
|
|
35
|
+
/** API name when applicable (used by `zond clean --api <name>`). */
|
|
36
|
+
api?: string;
|
|
37
|
+
/** Logical category for `zond clean --probes` etc. */
|
|
38
|
+
category?: ManifestCategory;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface Manifest {
|
|
42
|
+
version: number;
|
|
43
|
+
generated: ManifestEntry[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function getManifestPath(workspaceRoot: string): string {
|
|
47
|
+
return join(workspaceRoot, MANIFEST_RELPATH);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function loadManifest(workspaceRoot: string): Manifest {
|
|
51
|
+
const p = getManifestPath(workspaceRoot);
|
|
52
|
+
if (!existsSync(p)) return { version: MANIFEST_VERSION, generated: [] };
|
|
53
|
+
try {
|
|
54
|
+
const raw = readFileSync(p, "utf-8");
|
|
55
|
+
const parsed = JSON.parse(raw);
|
|
56
|
+
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.generated)) {
|
|
57
|
+
return { version: MANIFEST_VERSION, generated: [] };
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
version: typeof parsed.version === "number" ? parsed.version : MANIFEST_VERSION,
|
|
61
|
+
generated: parsed.generated as ManifestEntry[],
|
|
62
|
+
};
|
|
63
|
+
} catch {
|
|
64
|
+
return { version: MANIFEST_VERSION, generated: [] };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function saveManifest(workspaceRoot: string, manifest: Manifest): void {
|
|
69
|
+
const p = getManifestPath(workspaceRoot);
|
|
70
|
+
mkdirSync(dirname(p), { recursive: true });
|
|
71
|
+
writeFileSync(p, JSON.stringify(manifest, null, 2) + "\n", "utf-8");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Workspace-relative POSIX path. */
|
|
75
|
+
export function toWorkspacePath(workspaceRoot: string, filePath: string): string {
|
|
76
|
+
const abs = isAbsolute(filePath) ? filePath : resolve(filePath);
|
|
77
|
+
let rel = relative(workspaceRoot, abs);
|
|
78
|
+
if (sep === "\\") rel = rel.split(sep).join("/");
|
|
79
|
+
return rel;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function sha256OfFile(filePath: string): string | null {
|
|
83
|
+
try {
|
|
84
|
+
const buf = readFileSync(filePath);
|
|
85
|
+
return createHash("sha256").update(buf).digest("hex");
|
|
86
|
+
} catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function sha256OfString(content: string): string {
|
|
92
|
+
return createHash("sha256").update(content).digest("hex");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface RecordInput {
|
|
96
|
+
/** Absolute or workspace-relative path of the file just written. */
|
|
97
|
+
path: string;
|
|
98
|
+
by: string;
|
|
99
|
+
api?: string;
|
|
100
|
+
category?: ManifestCategory;
|
|
101
|
+
/** Pre-computed sha256; if absent, the file is read from disk. */
|
|
102
|
+
sha256?: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Append (or replace) entries in the manifest. Existing entries with the
|
|
107
|
+
* same `path` are replaced so re-running a generator updates the hash
|
|
108
|
+
* instead of accumulating duplicates.
|
|
109
|
+
*/
|
|
110
|
+
export function recordGeneratedFiles(workspaceRoot: string, entries: RecordInput[]): void {
|
|
111
|
+
if (entries.length === 0) return;
|
|
112
|
+
const ts = new Date().toISOString();
|
|
113
|
+
const accepted: ManifestEntry[] = [];
|
|
114
|
+
|
|
115
|
+
for (const e of entries) {
|
|
116
|
+
const abs = isAbsolute(e.path) ? e.path : resolve(workspaceRoot, e.path);
|
|
117
|
+
const rel = toWorkspacePath(workspaceRoot, abs);
|
|
118
|
+
// Refuse to record paths that escape the workspace — happens when tests
|
|
119
|
+
// run setupApi from a tmp dir but findWorkspaceRoot walks up to the host
|
|
120
|
+
// project root. Without this guard, a `../../../tmp/...` entry pollutes
|
|
121
|
+
// the host workspace's manifest.
|
|
122
|
+
if (rel.startsWith("..") || isAbsolute(rel)) continue;
|
|
123
|
+
const sha = e.sha256 ?? sha256OfFile(abs);
|
|
124
|
+
if (!sha) continue; // file vanished; skip
|
|
125
|
+
accepted.push({
|
|
126
|
+
path: rel,
|
|
127
|
+
sha256: sha,
|
|
128
|
+
by: e.by,
|
|
129
|
+
ts,
|
|
130
|
+
api: e.api,
|
|
131
|
+
category: e.category,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Don't touch disk when nothing applied to this workspace — keeps tests
|
|
136
|
+
// (which run from /tmp but inherit the host's workspace root) from
|
|
137
|
+
// creating an empty `.zond/manifest.json` in the dev repo.
|
|
138
|
+
if (accepted.length === 0) return;
|
|
139
|
+
|
|
140
|
+
const manifest = loadManifest(workspaceRoot);
|
|
141
|
+
const byPath = new Map<string, ManifestEntry>();
|
|
142
|
+
for (const e of manifest.generated) byPath.set(e.path, e);
|
|
143
|
+
for (const e of accepted) byPath.set(e.path, e);
|
|
144
|
+
|
|
145
|
+
manifest.version = MANIFEST_VERSION;
|
|
146
|
+
manifest.generated = [...byPath.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
147
|
+
saveManifest(workspaceRoot, manifest);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function recordGeneratedFile(workspaceRoot: string, entry: RecordInput): void {
|
|
151
|
+
recordGeneratedFiles(workspaceRoot, [entry]);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface CleanFilter {
|
|
155
|
+
api?: string;
|
|
156
|
+
category?: ManifestCategory;
|
|
157
|
+
/** When true, include all entries regardless of api/category. */
|
|
158
|
+
all?: boolean;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface SelectEntriesResult {
|
|
162
|
+
selected: ManifestEntry[];
|
|
163
|
+
/** Entries that match `api` filter but were excluded because the user
|
|
164
|
+
* did not explicitly opt into the `probes` category. Surfaced so the
|
|
165
|
+
* CLI can hint at how to reach them (TASK-258). */
|
|
166
|
+
probesPreserved: ManifestEntry[];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function selectEntries(manifest: Manifest, filter: CleanFilter): ManifestEntry[] {
|
|
170
|
+
return selectEntriesEx(manifest, filter).selected;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function selectEntriesEx(manifest: Manifest, filter: CleanFilter): SelectEntriesResult {
|
|
174
|
+
const selected: ManifestEntry[] = [];
|
|
175
|
+
const probesPreserved: ManifestEntry[] = [];
|
|
176
|
+
// TASK-258: when scoping by --api alone (no explicit --probes / --all),
|
|
177
|
+
// probes/ belongs to a separate pipeline (zond probe-validation/-methods)
|
|
178
|
+
// and re-generating it costs ~30s on a 200-endpoint spec. Treat it as
|
|
179
|
+
// out-of-scope and surface a hint instead of silently nuking suites.
|
|
180
|
+
const protectProbes = !!filter.api && filter.category !== "probes" && !filter.all;
|
|
181
|
+
for (const e of manifest.generated) {
|
|
182
|
+
// spec.json is the source-of-truth snapshot downloaded from the network.
|
|
183
|
+
// It is never auto-deleted — removal requires manual action or re-adding the API.
|
|
184
|
+
if (e.category === "spec") continue;
|
|
185
|
+
if (filter.all) {
|
|
186
|
+
selected.push(e);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (filter.api) {
|
|
190
|
+
const matchesApi = e.api === filter.api ||
|
|
191
|
+
e.path.startsWith(`apis/${filter.api}/`);
|
|
192
|
+
if (!matchesApi) continue;
|
|
193
|
+
}
|
|
194
|
+
if (filter.category && e.category !== filter.category) continue;
|
|
195
|
+
if (protectProbes && e.category === "probes") {
|
|
196
|
+
probesPreserved.push(e);
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
selected.push(e);
|
|
200
|
+
}
|
|
201
|
+
return { selected, probesPreserved };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export type CleanVerdict = "delete" | "modified" | "missing";
|
|
205
|
+
|
|
206
|
+
export interface CleanItem {
|
|
207
|
+
entry: ManifestEntry;
|
|
208
|
+
absPath: string;
|
|
209
|
+
verdict: CleanVerdict;
|
|
210
|
+
/** Current sha256 if file exists. */
|
|
211
|
+
currentSha256?: string;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function inspectEntries(workspaceRoot: string, entries: ManifestEntry[]): CleanItem[] {
|
|
215
|
+
const items: CleanItem[] = [];
|
|
216
|
+
for (const entry of entries) {
|
|
217
|
+
const abs = resolve(workspaceRoot, entry.path);
|
|
218
|
+
if (!existsSync(abs)) {
|
|
219
|
+
items.push({ entry, absPath: abs, verdict: "missing" });
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
const cur = sha256OfFile(abs);
|
|
223
|
+
if (cur && cur !== entry.sha256) {
|
|
224
|
+
items.push({ entry, absPath: abs, verdict: "modified", currentSha256: cur });
|
|
225
|
+
} else {
|
|
226
|
+
items.push({ entry, absPath: abs, verdict: "delete", currentSha256: cur ?? undefined });
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return items;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Drop entries from the manifest by absolute or workspace-relative path.
|
|
234
|
+
*/
|
|
235
|
+
export function removeManifestEntries(workspaceRoot: string, paths: string[]): void {
|
|
236
|
+
if (paths.length === 0) return;
|
|
237
|
+
const manifest = loadManifest(workspaceRoot);
|
|
238
|
+
const drop = new Set(paths.map((p) => toWorkspacePath(workspaceRoot, p)));
|
|
239
|
+
manifest.generated = manifest.generated.filter((e) => !drop.has(e.path));
|
|
240
|
+
saveManifest(workspaceRoot, manifest);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** True when the workspace has a manifest file. */
|
|
244
|
+
export function hasManifest(workspaceRoot: string): boolean {
|
|
245
|
+
return existsSync(getManifestPath(workspaceRoot));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Header comment prepended to every YAML/MD file zond writes, so a human
|
|
250
|
+
* opening the file sees who wrote it and how to regenerate it. Pair with
|
|
251
|
+
* `recordGeneratedFile` for the machine-readable audit trail.
|
|
252
|
+
*/
|
|
253
|
+
export function autoGenHeader(by: string, regenerate?: string): string {
|
|
254
|
+
const lines = [
|
|
255
|
+
`# Auto-generated by ${by}.`,
|
|
256
|
+
`# ⚠️ Edits will be overwritten on regenerate. Drop from .zond/manifest.json (or rename) to keep changes.`,
|
|
257
|
+
];
|
|
258
|
+
if (regenerate) lines.push(`# Regenerate: ${regenerate}`);
|
|
259
|
+
return lines.join("\n") + "\n";
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Best-effort: derive the API name from a path like `apis/<name>/tests`.
|
|
264
|
+
* Returns undefined for non-conventional layouts so manifest entries stay
|
|
265
|
+
* un-tagged rather than mis-tagged.
|
|
266
|
+
*/
|
|
267
|
+
export function inferApiName(outputDir: string): string | undefined {
|
|
268
|
+
const norm = outputDir.replace(/\\/g, "/");
|
|
269
|
+
const m = norm.match(/(?:^|\/)apis\/([^/]+)(?:\/|$)/);
|
|
270
|
+
return m?.[1];
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Cheap sanity check used by zond doctor — true when path lives in workspace. */
|
|
274
|
+
function isWithinWorkspace(workspaceRoot: string, candidate: string): boolean {
|
|
275
|
+
const abs = isAbsolute(candidate) ? candidate : resolve(workspaceRoot, candidate);
|
|
276
|
+
try {
|
|
277
|
+
statSync(abs);
|
|
278
|
+
} catch {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
const rel = relative(workspaceRoot, abs);
|
|
282
|
+
return !rel.startsWith("..") && !isAbsolute(rel);
|
|
283
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-rotate `--output <path>` targets so a second `zond report ...` (or
|
|
3
|
+
* `zond probe-* --output ...`) does not silently clobber the previous
|
|
4
|
+
* artifact (TASK-162, m-9 P6).
|
|
5
|
+
*
|
|
6
|
+
* Strategy: when `path` already exists, rename it to `<basename>-vN<ext>`
|
|
7
|
+
* with the smallest free N (≥ 2) and return that rotation info so the
|
|
8
|
+
* caller can print it. The `--overwrite` flag short-circuits to no-op so
|
|
9
|
+
* users keep the previous behaviour when they explicitly ask for it.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { existsSync, renameSync } from "node:fs";
|
|
13
|
+
import { basename, dirname, extname, join } from "node:path";
|
|
14
|
+
|
|
15
|
+
export interface RotationResult {
|
|
16
|
+
/** The path that was renamed (the old artifact). undefined when no rotation happened. */
|
|
17
|
+
rotatedFrom?: string;
|
|
18
|
+
/** Where the old artifact moved to. undefined when no rotation happened. */
|
|
19
|
+
rotatedTo?: string;
|
|
20
|
+
/** True when caller asked for `--overwrite` (or the target didn't exist). */
|
|
21
|
+
overwrite: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface RotateOptions {
|
|
25
|
+
/** When true, skip rotation entirely (overwrite-in-place). */
|
|
26
|
+
overwrite?: boolean;
|
|
27
|
+
/** Optional callback for the human-facing notice; defaults to stderr. */
|
|
28
|
+
notice?: (msg: string) => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Rename `targetPath` to `<base>-vN<ext>` if it exists and `--overwrite`
|
|
33
|
+
* is not set. Returns rotation info; the caller is responsible for
|
|
34
|
+
* actually writing the new artifact at `targetPath`.
|
|
35
|
+
*/
|
|
36
|
+
export function rotateOutputTarget(targetPath: string, opts: RotateOptions = {}): RotationResult {
|
|
37
|
+
if (opts.overwrite) return { overwrite: true };
|
|
38
|
+
if (!existsSync(targetPath)) return { overwrite: false };
|
|
39
|
+
|
|
40
|
+
const dir = dirname(targetPath);
|
|
41
|
+
const ext = extname(targetPath);
|
|
42
|
+
const stem = basename(targetPath, ext);
|
|
43
|
+
// Strip an existing `-vN` suffix from the stem so successive rotations
|
|
44
|
+
// produce `digest-v2.md`, `digest-v3.md` rather than
|
|
45
|
+
// `digest-v2-v2.md` etc.
|
|
46
|
+
const stemBare = stem.replace(/-v\d+$/, "");
|
|
47
|
+
|
|
48
|
+
let n = 2;
|
|
49
|
+
while (n < 1000) {
|
|
50
|
+
const candidate = join(dir, `${stemBare}-v${n}${ext}`);
|
|
51
|
+
if (!existsSync(candidate)) {
|
|
52
|
+
renameSync(targetPath, candidate);
|
|
53
|
+
const notice = opts.notice ?? ((m: string) => process.stderr.write(m + "\n"));
|
|
54
|
+
notice(`Previous artifact moved to ${candidate}`);
|
|
55
|
+
return { rotatedFrom: targetPath, rotatedTo: candidate, overwrite: false };
|
|
56
|
+
}
|
|
57
|
+
n++;
|
|
58
|
+
}
|
|
59
|
+
// Pathological: 1000 versions exist. Fall back to overwrite to avoid
|
|
60
|
+
// an infinite-loop UX failure.
|
|
61
|
+
return { overwrite: true };
|
|
62
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default `triage/` path for `--output` (TASK-163, m-9 P7).
|
|
3
|
+
*
|
|
4
|
+
* Rule: when the user runs a report-emitting command without `--output`,
|
|
5
|
+
* we drop the artifact into:
|
|
6
|
+
*
|
|
7
|
+
* <workspace>/triage/<api|"adhoc">/<run-id>/<command>-<timestamp>.<ext>
|
|
8
|
+
*
|
|
9
|
+
* If they pass `--output some-filename.md` (no slash), that filename is
|
|
10
|
+
* used as the basename inside the same directory. An `--output` that
|
|
11
|
+
* includes a directory component is honoured verbatim.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
15
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
16
|
+
import { findWorkspaceRoot } from "./root.ts";
|
|
17
|
+
|
|
18
|
+
export interface TriageOpts {
|
|
19
|
+
/** Logical command name — used in the auto-filename. */
|
|
20
|
+
command: string;
|
|
21
|
+
/** Run id (or undefined for ad-hoc artifacts). */
|
|
22
|
+
runId?: number | null;
|
|
23
|
+
/** API/collection name; falls back to `"adhoc"` when not known. */
|
|
24
|
+
api?: string | null;
|
|
25
|
+
/** Default extension (md / html / json). Without a leading dot. */
|
|
26
|
+
ext: string;
|
|
27
|
+
/** What the user typed in --output (may be undefined). */
|
|
28
|
+
userOutput?: string;
|
|
29
|
+
/** Optional explicit timestamp for tests. */
|
|
30
|
+
now?: Date;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ResolvedTriagePath {
|
|
34
|
+
/** Absolute path to write. */
|
|
35
|
+
absolute: string;
|
|
36
|
+
/** Workspace-relative path for prettier console output. */
|
|
37
|
+
relative: string;
|
|
38
|
+
/** True when we landed under triage/ vs. honoured the user path. */
|
|
39
|
+
underTriage: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function pad(n: number): string {
|
|
43
|
+
return n < 10 ? `0${n}` : `${n}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function timestamp(d: Date): string {
|
|
47
|
+
return `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}-${pad(d.getHours())}${pad(d.getMinutes())}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function resolveTriageOutput(opts: TriageOpts): ResolvedTriagePath {
|
|
51
|
+
const ws = findWorkspaceRoot();
|
|
52
|
+
const root = ws.root;
|
|
53
|
+
const ext = opts.ext.replace(/^\./, "");
|
|
54
|
+
const ts = timestamp(opts.now ?? new Date());
|
|
55
|
+
const apiSlug = opts.api ?? "adhoc";
|
|
56
|
+
const runSlug = opts.runId != null ? `run-${opts.runId}` : "adhoc";
|
|
57
|
+
|
|
58
|
+
// 1) User passed a path with a directory component → honour verbatim.
|
|
59
|
+
if (opts.userOutput && /[\\/]/.test(opts.userOutput)) {
|
|
60
|
+
const abs = isAbsolute(opts.userOutput) ? opts.userOutput : resolve(opts.userOutput);
|
|
61
|
+
mkdirSync(dirname(abs), { recursive: true });
|
|
62
|
+
return {
|
|
63
|
+
absolute: abs,
|
|
64
|
+
relative: relPath(abs, root),
|
|
65
|
+
underTriage: false,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 2) Default location.
|
|
70
|
+
const dir = join(root, "triage", apiSlug, runSlug);
|
|
71
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
72
|
+
const basename = opts.userOutput ?? `${opts.command}-${ts}.${ext}`;
|
|
73
|
+
const abs = join(dir, basename);
|
|
74
|
+
return {
|
|
75
|
+
absolute: abs,
|
|
76
|
+
relative: relPath(abs, root),
|
|
77
|
+
underTriage: true,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function relPath(abs: string, root: string): string {
|
|
82
|
+
if (abs.startsWith(root)) {
|
|
83
|
+
const r = abs.slice(root.length).replace(/^[\\/]+/, "");
|
|
84
|
+
return r.replace(/\\/g, "/");
|
|
85
|
+
}
|
|
86
|
+
return abs;
|
|
87
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
import type { Issue, LintConfig, LintStats } from "../core/lint/index.ts";
|
|
3
|
+
|
|
4
|
+
export interface LintRunRow {
|
|
5
|
+
id: number;
|
|
6
|
+
spec_path: string;
|
|
7
|
+
started_at: string;
|
|
8
|
+
finished_at: string | null;
|
|
9
|
+
total: number;
|
|
10
|
+
high_count: number;
|
|
11
|
+
medium_count: number;
|
|
12
|
+
low_count: number;
|
|
13
|
+
endpoint_count: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function createLintRun(db: Database, specPath: string): number {
|
|
17
|
+
const startedAt = new Date().toISOString();
|
|
18
|
+
const stmt = db.prepare(
|
|
19
|
+
"INSERT INTO lint_runs (spec_path, started_at) VALUES (?, ?)",
|
|
20
|
+
);
|
|
21
|
+
const info = stmt.run(specPath, startedAt) as { lastInsertRowid: number | bigint };
|
|
22
|
+
return Number(info.lastInsertRowid);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function finalizeLintRun(
|
|
26
|
+
db: Database,
|
|
27
|
+
id: number,
|
|
28
|
+
issues: Issue[],
|
|
29
|
+
stats: LintStats,
|
|
30
|
+
config: LintConfig,
|
|
31
|
+
): void {
|
|
32
|
+
db.prepare(
|
|
33
|
+
`UPDATE lint_runs SET
|
|
34
|
+
finished_at = ?,
|
|
35
|
+
total = ?, high_count = ?, medium_count = ?, low_count = ?,
|
|
36
|
+
endpoint_count = ?,
|
|
37
|
+
config_json = ?, issues_json = ?
|
|
38
|
+
WHERE id = ?`,
|
|
39
|
+
).run(
|
|
40
|
+
new Date().toISOString(),
|
|
41
|
+
stats.total, stats.high, stats.medium, stats.low,
|
|
42
|
+
stats.endpoints,
|
|
43
|
+
JSON.stringify({ rules: config.rules, heuristics: config.heuristics, ignore_paths: config.ignore_paths }),
|
|
44
|
+
JSON.stringify(issues),
|
|
45
|
+
id,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ARV-127 (m-19): file-based SQLite migration runner.
|
|
3
|
+
*
|
|
4
|
+
* Why a new runner. The legacy migration path in `schema.ts`
|
|
5
|
+
* (`runMigrations` + `PRAGMA user_version`) is fine for the additive
|
|
6
|
+
* column changes shipped through v10, but the knowledge-base work
|
|
7
|
+
* planned past m-19 will need richer migrations (multi-statement,
|
|
8
|
+
* data backfills, optional rollback notes). Inlining those as `if
|
|
9
|
+
* (ver >= N && ver < N+1)` blocks in TypeScript stops scaling once
|
|
10
|
+
* each migration becomes a small project of its own.
|
|
11
|
+
*
|
|
12
|
+
* This module sits on top of the legacy path:
|
|
13
|
+
* - `runMigrations()` is untouched — it owns the PRAGMA-version era
|
|
14
|
+
* and keeps fresh DBs / older snapshots correct.
|
|
15
|
+
* - `applyMigrations()` runs *after* `runMigrations()`, walks the
|
|
16
|
+
* registered migration list, and applies anything not yet recorded
|
|
17
|
+
* in `schema_migrations`. New work (v11+) lands as files; the
|
|
18
|
+
* 0001_run_kind.sql file mirrors the most recent legacy migration
|
|
19
|
+
* so the two systems agree on the post-v10 schema for fresh DBs.
|
|
20
|
+
*
|
|
21
|
+
* Existing-DB compatibility (AC#5). On a `.zond/zond.db` that already
|
|
22
|
+
* survived the legacy `runMigrations` path (user_version >= 10), the
|
|
23
|
+
* `run_kind` column already exists — re-running `0001_run_kind.sql`
|
|
24
|
+
* would throw a `duplicate column` error. We seed the legacy ids into
|
|
25
|
+
* `schema_migrations` once, on first contact with the new runner, so
|
|
26
|
+
* those rows are treated as "already applied" without executing.
|
|
27
|
+
*
|
|
28
|
+
* Distribution. The SQL bodies are imported as embedded text so
|
|
29
|
+
* `bun build --compile` packs them into the binary (no on-disk
|
|
30
|
+
* lookup at runtime — same pattern as the init/templates skills).
|
|
31
|
+
*/
|
|
32
|
+
import type { Database } from "bun:sqlite";
|
|
33
|
+
|
|
34
|
+
import migration_0001_run_kind from "./migrations/0001_run_kind.sql" with { type: "text" };
|
|
35
|
+
|
|
36
|
+
/** Migration manifest. Each entry is a `{ id, sql }` pair; order in
|
|
37
|
+
* this array is the apply order, matching the lexical sort that the
|
|
38
|
+
* Django / Rails-style `<id>_<slug>.sql` convention would produce on
|
|
39
|
+
* disk. Adding a new migration = add a text-import + push to this
|
|
40
|
+
* list. The runner reads this constant, not the filesystem. */
|
|
41
|
+
const MIGRATIONS: ReadonlyArray<{ id: string; sql: string }> = [
|
|
42
|
+
{ id: "0001_run_kind", sql: migration_0001_run_kind },
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
/** Pre-existing migration ids that were already applied by the legacy
|
|
46
|
+
* PRAGMA-version path. When the new runner first encounters a DB
|
|
47
|
+
* whose `user_version >= 10`, we record these as applied without
|
|
48
|
+
* running them — the inline `runMigrations` already did. */
|
|
49
|
+
const LEGACY_SEED_IDS: ReadonlyArray<{ id: string; minUserVersion: number }> = [
|
|
50
|
+
{ id: "0001_run_kind", minUserVersion: 10 },
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
function currentUserVersion(db: Database): number {
|
|
54
|
+
const row = db.query("PRAGMA user_version").get() as
|
|
55
|
+
| { user_version: number }
|
|
56
|
+
| undefined;
|
|
57
|
+
return row?.user_version ?? 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Idempotently apply every pending migration. Safe to call on every
|
|
62
|
+
* DB open — the registry table makes the no-op case cheap.
|
|
63
|
+
*
|
|
64
|
+
* Failure semantics: each migration runs in its own transaction. A
|
|
65
|
+
* script that throws (bad SQL, constraint violation) rolls its own
|
|
66
|
+
* statements back and re-raises; later migrations don't run. The
|
|
67
|
+
* caller (DB open path) treats this as fatal — there is no partial
|
|
68
|
+
* upgrade.
|
|
69
|
+
*
|
|
70
|
+
* The optional `overrides` parameter lets tests inject a synthetic
|
|
71
|
+
* migration list (e.g. to exercise a migration order or a failing
|
|
72
|
+
* script) without touching the shipped manifest.
|
|
73
|
+
*/
|
|
74
|
+
export function applyMigrations(
|
|
75
|
+
db: Database,
|
|
76
|
+
overrides?: { migrations?: ReadonlyArray<{ id: string; sql: string }>; legacySeed?: ReadonlyArray<{ id: string; minUserVersion: number }> },
|
|
77
|
+
): { applied: string[]; skipped: string[] } {
|
|
78
|
+
const migrations = overrides?.migrations ?? MIGRATIONS;
|
|
79
|
+
const legacySeed = overrides?.legacySeed ?? LEGACY_SEED_IDS;
|
|
80
|
+
|
|
81
|
+
db.exec(`
|
|
82
|
+
CREATE TABLE IF NOT EXISTS schema_migrations (
|
|
83
|
+
id TEXT PRIMARY KEY,
|
|
84
|
+
applied_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
85
|
+
)
|
|
86
|
+
`);
|
|
87
|
+
|
|
88
|
+
// Legacy seed: mark already-applied-by-the-PRAGMA-runner ids as done.
|
|
89
|
+
const userVersion = currentUserVersion(db);
|
|
90
|
+
const insertSeed = db.prepare(
|
|
91
|
+
"INSERT OR IGNORE INTO schema_migrations (id) VALUES (?)",
|
|
92
|
+
);
|
|
93
|
+
for (const seed of legacySeed) {
|
|
94
|
+
if (userVersion >= seed.minUserVersion) {
|
|
95
|
+
insertSeed.run(seed.id);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const appliedRows = db
|
|
100
|
+
.query("SELECT id FROM schema_migrations")
|
|
101
|
+
.all() as Array<{ id: string }>;
|
|
102
|
+
const alreadyApplied = new Set(appliedRows.map((r) => r.id));
|
|
103
|
+
|
|
104
|
+
const applied: string[] = [];
|
|
105
|
+
const skipped: string[] = [];
|
|
106
|
+
|
|
107
|
+
for (const migration of migrations) {
|
|
108
|
+
if (alreadyApplied.has(migration.id)) {
|
|
109
|
+
skipped.push(migration.id);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
db.transaction(() => {
|
|
113
|
+
db.exec(migration.sql);
|
|
114
|
+
db.prepare("INSERT INTO schema_migrations (id) VALUES (?)").run(migration.id);
|
|
115
|
+
})();
|
|
116
|
+
applied.push(migration.id);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return { applied, skipped };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Exported for tests + downstream tooling that wants to know which
|
|
123
|
+
* migration ids ship with the binary. */
|
|
124
|
+
export function listShippedMigrations(): string[] {
|
|
125
|
+
return MIGRATIONS.map((m) => m.id);
|
|
126
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
-- ARV-127 (m-19): captures the legacy v9→v10 inline migration as the
|
|
2
|
+
-- first file-based migration of the new runner. Mirrors the SQL block
|
|
3
|
+
-- previously written in src/db/schema.ts `runMigrations()`. Existing
|
|
4
|
+
-- `.zond/zond.db` files that already ran the inline migration are
|
|
5
|
+
-- pre-seeded as "applied" by `applyMigrations`, so this script never
|
|
6
|
+
-- re-executes the ALTER on a DB where `run_kind` already exists.
|
|
7
|
+
--
|
|
8
|
+
-- Source: ARV-55 — classify each historical run by suite kind so the
|
|
9
|
+
-- coverage default query becomes a column compare.
|
|
10
|
+
|
|
11
|
+
ALTER TABLE runs ADD COLUMN run_kind TEXT NOT NULL DEFAULT 'regular';
|
|
12
|
+
|
|
13
|
+
UPDATE runs SET run_kind = 'probe'
|
|
14
|
+
WHERE id IN (
|
|
15
|
+
SELECT r.id FROM runs r
|
|
16
|
+
WHERE EXISTS (SELECT 1 FROM results WHERE run_id = r.id AND suite_file IS NOT NULL AND suite_file LIKE '%probes/%')
|
|
17
|
+
AND NOT EXISTS (SELECT 1 FROM results WHERE run_id = r.id AND suite_file IS NOT NULL AND suite_file NOT LIKE '%probes/%')
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
UPDATE runs SET run_kind = 'check'
|
|
21
|
+
WHERE id IN (
|
|
22
|
+
SELECT r.id FROM runs r
|
|
23
|
+
WHERE EXISTS (SELECT 1 FROM results WHERE run_id = r.id AND suite_file IS NOT NULL AND suite_file LIKE '%checks/%')
|
|
24
|
+
AND NOT EXISTS (SELECT 1 FROM results WHERE run_id = r.id AND suite_file IS NOT NULL AND suite_file NOT LIKE '%checks/%')
|
|
25
|
+
);
|