diff --git a/CHANGELOG.md b/CHANGELOG.md index 793ce0b..abc9c90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- A validation-coverage gate (`scripts/check-validation-coverage.sh`, wired into + `scripts/check-all.sh` and CI) enforcing the validation-rules discipline that every public type is + either validated or excluded. It enumerates the public surface from the compiler symbol graph (the + authoritative source, not a grep heuristic) and fails the build, by name, if any public type is + missing from `scripts/validation-coverage.tsv` or any manifest entry is no longer public. All 58 + public types are classified: the value models carrying a runtime invariant (mapping-key + uniqueness) are `validated`, and the caseless namespaces, closed sum types, data-transfer values, + error types, and engine/machinery are `excluded` with a one-line reason each. This is the first + phase of adopting the OpenAPIKit-style validation idiom; the type-directed `Validation` + framework that backs the `validated` entries follows. - An opt-in conformance harness against the official YAML test-suite, the canonical YAML 1.2 corpus (`Tests/YAMLTestSuiteConformanceTests.swift`, `scripts/fetch-yaml-test-suite.sh`). Gated behind `PUREYAML_RUN_YAML_TEST_SUITE=1` diff --git a/scripts/check-all.sh b/scripts/check-all.sh index 57abb81..44322fc 100755 --- a/scripts/check-all.sh +++ b/scripts/check-all.sh @@ -15,6 +15,7 @@ run_gate() { run_gate "style" bash scripts/check-style.sh run_gate "namespacing" bash scripts/check-namespacing.sh +run_gate "validation coverage" bash scripts/check-validation-coverage.sh run_gate "forbidden patterns" bash scripts/check-forbidden-patterns.sh run_gate "changelog" bash scripts/check-changelog-touched.sh run_gate "roadmap" bash scripts/check-roadmap.sh diff --git a/scripts/check-validation-coverage.sh b/scripts/check-validation-coverage.sh new file mode 100755 index 0000000..eeae5cf --- /dev/null +++ b/scripts/check-validation-coverage.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash +# Validation coverage gate (validation-rules.md, "Every public type is validated or excluded"). +# +# Enumerates every public type in the PureYAML target from the compiler's symbol graph (the +# authoritative public surface, not a grep heuristic), then checks each against the coverage +# manifest. Every public type MUST be classified exactly once as `validated` or `excluded`; an +# unclassified type, or a manifest entry that is no longer public, fails the build by name. +# +# Phase 1 enforces classification completeness. The framework phase additionally asserts that each +# `validated` entry is backed by a `Validation` whose Subject is that type. +set -euo pipefail + +cd "$(dirname "$0")/.." + +MANIFEST="scripts/validation-coverage.tsv" +GRAPH_DIR=".build/symbolgraph" + +if [[ ! -f "$MANIFEST" ]]; then + echo "check-validation-coverage: missing manifest $MANIFEST" >&2 + exit 1 +fi + +mkdir -p "$GRAPH_DIR" +swift build --target PureYAML \ + -Xswiftc -emit-symbol-graph \ + -Xswiftc -emit-symbol-graph-dir -Xswiftc "$GRAPH_DIR" >/dev/null + +python3 - "$GRAPH_DIR/PureYAML.symbols.json" "$MANIFEST" <<'PY' +import json +import sys + +graph_path, manifest_path = sys.argv[1], sys.argv[2] + +type_kinds = {"swift.struct", "swift.enum", "swift.class", "swift.actor", "swift.protocol"} +with open(graph_path) as handle: + graph = json.load(handle) + +public_types = { + ".".join(symbol["pathComponents"]) + for symbol in graph["symbols"] + if symbol["kind"]["identifier"] in type_kinds and symbol.get("accessLevel") == "public" +} + +classified = {} +duplicates = [] +with open(manifest_path) as handle: + for raw in handle: + line = raw.split("#", 1)[0].strip() + if not line: + continue + parts = line.split("\t") + if len(parts) < 3 or parts[1] not in ("validated", "excluded"): + print(f"check-validation-coverage: malformed manifest line: {raw.rstrip()}", file=sys.stderr) + sys.exit(1) + name, kind = parts[0], parts[1] + if name in classified: + duplicates.append(name) + classified[name] = kind + +errors = [] +for name in sorted(public_types - set(classified)): + errors.append(f" unclassified public type (add to {manifest_path} as validated or excluded): {name}") +for name in sorted(set(classified) - public_types): + errors.append(f" stale manifest entry (no longer a public type): {name}") +for name in sorted(set(duplicates)): + errors.append(f" duplicate manifest entry: {name}") + +if errors: + print("check-validation-coverage: FAILED", file=sys.stderr) + print("\n".join(errors), file=sys.stderr) + sys.exit(1) + +validated = sum(1 for k in classified.values() if k == "validated") +excluded = sum(1 for k in classified.values() if k == "excluded") +print(f"check-validation-coverage: OK, {len(public_types)} public types ({validated} validated, {excluded} excluded)") +PY diff --git a/scripts/validation-coverage.tsv b/scripts/validation-coverage.tsv new file mode 100644 index 0000000..19b9d54 --- /dev/null +++ b/scripts/validation-coverage.tsv @@ -0,0 +1,83 @@ +# Public-type validation coverage manifest (validation-rules.md). +# Every public type in the PureYAML target is classified exactly once. +# Columns (tab-separated): +# `validated`: carries a runtime invariant the type system does not enforce; backed by a +# Validation in the framework phase. +# `excluded`: a caseless namespace, a closed sum type whose illegal states are unrepresentable, +# a pure data-transfer type, an error value, or engine/machinery that is not a validated subject. +# scripts/check-validation-coverage.sh fails the build if a public type is missing here or a line +# here is no longer public. + +# --- namespaces (caseless enums) --- +PureYAML excluded caseless namespace; holds no instances or state +PureYAML.Decoding excluded caseless namespace; holds no instances or state +PureYAML.Emitting excluded caseless namespace; holds no instances or state +PureYAML.Encoding excluded caseless namespace; holds no instances or state +PureYAML.Model excluded caseless namespace; holds no instances or state +PureYAML.Parsing excluded caseless namespace; holds no instances or state +PureYAML.Stream excluded caseless namespace; holds no instances or state +PureYAML.Tagged excluded caseless namespace; holds no instances or state +PureYAML.Validation excluded caseless namespace; holds no instances or state + +# --- model --- +PureYAML.Model.Value validated core YAML value; mapping-key uniqueness and merge/alias shape are runtime invariants +PureYAML.Model.Mapping validated mapping keys must be unique within a mapping +PureYAML.Model.Pair excluded data-transfer key/value pair; no invariant beyond its components +PureYAML.Model.Key excluded closed sum type (string/sequence/mapping); illegal states unrepresentable + +# --- stream --- +PureYAML.Stream.Document excluded wraps a validated Model.Value plus an index; no own invariant +PureYAML.Stream.Issue excluded diagnostic data-transfer type +PureYAML.Stream.Issue.Collection excluded error aggregate; data-transfer +PureYAML.Stream.Result excluded diagnostic result data-transfer type + +# --- parsing --- +PureYAML.Parsing.ParseError excluded error enum; cases are unrepresentable-illegal, carries diagnostics only +PureYAML.Parsing.Parser excluded parsing engine; produces values, is not itself a validated subject + +# --- emitting --- +PureYAML.Emitting.Dumper excluded emitter engine; not a validated subject +PureYAML.Emitting.Options excluded emitter configuration; no cross-field invariant +PureYAML.Emitting.CollectionStyle excluded closed enum; illegal states unrepresentable +PureYAML.Emitting.ScalarStyle excluded closed enum; illegal states unrepresentable + +# --- decoding / encoding (Codable machinery) --- +PureYAML.Decoding.Decoder excluded Codable decoding machinery; not a validated subject +PureYAML.Decoding.Error excluded error enum; data-transfer +PureYAML.Encoding.Encoder excluded Codable encoding machinery; not a validated subject +PureYAML.Encoding.Error excluded error enum; data-transfer + +# --- tagged node subsystem --- +PureYAML.Tagged.Node validated tagged node tree; mapping-key uniqueness is a runtime invariant +PureYAML.Tagged.Mapping validated tagged mapping keys must be unique +PureYAML.Tagged.Pair excluded data-transfer key/value pair +PureYAML.Tagged.Scalar excluded data-transfer scalar (value + tag) +PureYAML.Tagged.Sequence excluded data-transfer ordered nodes +PureYAML.Tagged.Tag excluded data-transfer tag identifier +PureYAML.Tagged.NodeKind excluded closed enum; illegal states unrepresentable +PureYAML.Tagged.Document excluded wraps a validated Tagged.Node +PureYAML.Tagged.Context excluded construction context data-transfer type +PureYAML.Tagged.ConstructionContext excluded construction context data-transfer type +PureYAML.Tagged.ConstructionError excluded error enum; data-transfer +PureYAML.Tagged.Constructor excluded tag-construction engine; not a validated subject +PureYAML.Tagged.Rule excluded validation machinery; duplicates Validation.Rule, slated for de-dup (principle 10) +PureYAML.Tagged.Validator excluded validation machinery; duplicates Validation.Validator, slated for de-dup (principle 10) + +# --- validation framework's own types --- +PureYAML.Validation.Validator excluded validation machinery; not a validated subject +PureYAML.Validation.Rule excluded the Validation analog; a rule type, not a subject +PureYAML.Validation.Context excluded validation context passed to checks; not a subject +PureYAML.Validation.Issue excluded validation error data-transfer type +PureYAML.Validation.Issue.Collection excluded error aggregate; data-transfer +PureYAML.Validation.Result excluded validation result data-transfer type +PureYAML.Validation.Severity excluded closed enum; illegal states unrepresentable +PureYAML.Validation.Path excluded coding-path data-transfer type +PureYAML.Validation.Path.Component excluded coding-path element; closed enum +PureYAML.Validation.Report excluded diagnostic report data-transfer type +PureYAML.Validation.ReportError excluded error type; data-transfer +PureYAML.Validation.SourceReport excluded diagnostic report data-transfer type +PureYAML.Validation.Source excluded source descriptor data-transfer type +PureYAML.Validation.BatchReport excluded diagnostic report data-transfer type +PureYAML.Validation.Diagnostic excluded diagnostic data-transfer type +PureYAML.Validation.DiagnosticKind excluded closed enum; illegal states unrepresentable +PureYAML.Validation.PreflightScanner excluded pre-parse scanner engine; not a validated subject