Skip to main content

norm_spec_core/
lib.rs

1//! Canonical semantic engine for the `.norm` format.
2
3#![forbid(unsafe_code)]
4
5mod collector;
6mod parser;
7mod protocol;
8mod scan;
9mod schema;
10mod semantics;
11#[cfg(test)]
12mod test_support;
13mod validator;
14
15pub use collector::{CollectPathError, collect_candidate_paths, project_path};
16pub use parser::{ParseError, ParseOptions, ParsedNorm, parse_norm};
17pub use protocol::{
18    CollectResponse, CollectedNorm, CompatibilityConformance, CompatibilityProduct,
19    CompatibilityResponse, CompatibilityRustApi, Diagnostic, ErrorDetail, ErrorResponse,
20    InitAction, InitResponse, ParseResponse, ValidateResponse, ValidationResult, ValidationStatus,
21    ValidationSummary,
22};
23pub use scan::{
24    DirectoryObservation, NormCoverage, RecurringFilename, ScanNaming, ScanResponse, ScanSymlink,
25    ScanSymlinkAction, ScanSymlinkKind, ScannedDirectory, classify_name, is_ignored_directory,
26};
27pub use schema::{SchemaCompileError, SchemaViolation, validate_draft7};
28pub use semantics::{ReferenceResolver, ReferenceStatus, validate_frontmatter};
29pub use validator::{SchemaBundle, ValidationDiagnostics, ValidationOptions, validate_structure};
30
31/// Identifier for the initial `.norm` format contract.
32pub const FORMAT_ID: &str = "norm-spec/a1";
33
34/// Machine API identifier for parse responses.
35pub const PARSE_API_VERSION: &str = "norm-spec/parse/v1";
36
37/// Machine API identifier for collect responses.
38pub const COLLECT_API_VERSION: &str = "norm-spec/collect/v1";
39
40/// Machine API identifier for validate responses.
41pub const VALIDATE_API_VERSION: &str = "norm-spec/validate/v1";
42
43/// Machine API identifier for init responses.
44pub const INIT_API_VERSION: &str = "norm-spec/init/v1";
45
46/// Machine API identifier for scan responses.
47pub const SCAN_API_VERSION: &str = "norm-spec/scan/v1";
48
49/// Machine API identifier for handled CLI failures in machine mode.
50pub const ERROR_API_VERSION: &str = "norm-spec/error/v1";
51
52/// Machine API identifier for compatibility discovery responses.
53pub const COMPATIBILITY_API_VERSION: &str = "norm-spec/compatibility/v1";
54
55/// Identifier for the public high-level Rust consumer surface.
56pub const RUST_API_VERSION: &str = "norm-spec/rust-api/v1";
57
58/// Identifier for the locked contract-bundle format.
59pub const CONTRACT_BUNDLE_API_VERSION: &str = "norm-spec/contract-bundle/v1";
60
61/// Machine API identifier for arbitrary-candidate conformance reports.
62pub const CONFORMANCE_API_VERSION: &str = "norm-spec/conformance/v1";
63
64/// Identifier for the frozen initial A1 CLI conformance suite.
65pub const A1_CLI_SUITE_ID: &str = "norm-spec/a1-cli/v1";
66
67/// Number of executable cases in the frozen initial A1 CLI suite.
68pub const A1_CLI_CASE_COUNT: usize = 82;
69
70/// SHA-256 identity of the exact frozen initial A1 CLI contract bundle.
71pub const A1_CLI_CONTRACT_DIGEST: &str =
72    "sha256:3d94441e9cde3ef9489618bdb8fbf37f6979331bea099acadf0136b65df7e2eb";
73
74/// Return the compiled crate version.
75#[must_use]
76pub const fn crate_version() -> &'static str {
77    env!("CARGO_PKG_VERSION")
78}
79
80#[cfg(test)]
81mod tests {
82    use super::{
83        A1_CLI_CASE_COUNT, A1_CLI_CONTRACT_DIGEST, A1_CLI_SUITE_ID, COLLECT_API_VERSION,
84        COMPATIBILITY_API_VERSION, CONFORMANCE_API_VERSION, CONTRACT_BUNDLE_API_VERSION,
85        ERROR_API_VERSION, FORMAT_ID, INIT_API_VERSION, PARSE_API_VERSION, RUST_API_VERSION,
86        SCAN_API_VERSION, VALIDATE_API_VERSION,
87    };
88
89    #[test]
90    fn protocol_identifiers_are_explicitly_versioned() {
91        assert_eq!(PARSE_API_VERSION, "norm-spec/parse/v1");
92        assert_eq!(COLLECT_API_VERSION, "norm-spec/collect/v1");
93        assert_eq!(VALIDATE_API_VERSION, "norm-spec/validate/v1");
94        assert_eq!(INIT_API_VERSION, "norm-spec/init/v1");
95        assert_eq!(SCAN_API_VERSION, "norm-spec/scan/v1");
96        assert_eq!(ERROR_API_VERSION, "norm-spec/error/v1");
97        assert_eq!(COMPATIBILITY_API_VERSION, "norm-spec/compatibility/v1");
98        assert_eq!(RUST_API_VERSION, "norm-spec/rust-api/v1");
99        assert_eq!(CONTRACT_BUNDLE_API_VERSION, "norm-spec/contract-bundle/v1");
100        assert_eq!(CONFORMANCE_API_VERSION, "norm-spec/conformance/v1");
101        assert_eq!(A1_CLI_SUITE_ID, "norm-spec/a1-cli/v1");
102        assert_eq!(A1_CLI_CASE_COUNT, 82);
103        assert_eq!(
104            A1_CLI_CONTRACT_DIGEST,
105            "sha256:3d94441e9cde3ef9489618bdb8fbf37f6979331bea099acadf0136b65df7e2eb"
106        );
107        assert_eq!(FORMAT_ID, "norm-spec/a1");
108    }
109}