From 4aac79db5a5e2e700870c78984863c20929a635a Mon Sep 17 00:00:00 2001 From: humuhumu33 Date: Thu, 12 Nov 2026 19:58:49 +0000 Subject: [PATCH 1/4] RP-19: a check-only build, as its register row, scenario and failing test (#495) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The register row, the SPEC.md §31 row and total, the scenario, and conformance_rp_19, which builds the crate with --no-default-features and holds it to the default build: no library source in its image, a version report that names the variant, equal exit codes, JSON diagnostics and lock bytes for lock and check, and LLC0205 before anything is published for verify and production build. RP-10 now also requires the checked-in language-1.2 ID to equal the ID recomputed from disk. SPEC.md §8.4 names the production-data feature as the one exception to its rule, §21.2 says how a build without it takes the 1.2 ID, §24.7 lists LLC0205, and §30.3 says such a build is never a release binary. These tests fail here: the constant and the feature do not exist yet. Co-Authored-By: Claude Opus 5.5 --- CONFORMANCE.md | 1 + README.md | 4 +- SPEC.md | 15 +- crates/conformance/src/cases/repository.rs | 205 ++++++++++++++++++++- crates/conformance/src/support.rs | 68 +++++++ crates/conformance/tests/conformance.rs | 5 + features/suites/repository.feature | 10 + model/ids.toml | 6 + xtask/src/spec_links.rs | 4 +- 9 files changed, 310 insertions(+), 8 deletions(-) diff --git a/CONFORMANCE.md b/CONFORMANCE.md index 5e0010e5e9..e4d4648c17 100644 --- a/CONFORMANCE.md +++ b/CONFORMANCE.md @@ -523,6 +523,7 @@ the error registry does not sanction (R5, `ERRORS.md`). | `RP-15` | `build` | Every match over a closed semantic enum (the IR, the production realization calculus, and its Rust AST) that names at least five of the enum's variants names all of them, with no wildcard or binding catch-all arm, so that a variant added to the enum is a compile error in each Lean, LaTeX, validation, charge, and calculus consumer and never a silent fallback; the audit rejects a catch-all planted in each consumer group and fails when a consumer it must read has no such match left. | | `RP-16` | `build` | The development container installs, at image build, exactly the Rust toolchain that rust-toolchain.toml pins and exactly the Lean toolchain that lean-toolchain pins and selects no other default, so that nothing is fetched when a session starts, and a Dockerfile that names another version of either, installs a second toolchain, or selects an unpinned default is refused. | | `RP-18` | `build` | The release workflow packages the lexlean crate twice to the same bytes, runs cargo publish --dry-run, and refuses a crate whose SHA-256 differs from the one release/checksums.txt lists for it or from the bytes cargo would upload, or whose archive lacks the metadata and size crates.io requires, and uploads to crates.io only when a CARGO_REGISTRY_TOKEN secret or trusted publishing authorises it; a commit of a release line release/vX.Y is published as the pre-release X.Y.0-dev.N, N being its number of first-parent commits, and a plant in each of these checks is refused. | +| `RP-19` | `build` | A build of the lexlean crate without its default production-data feature embeds no file of language/preservation-1.2/library/, reports the compiler-semantics IDs of a default build and its version report with a fifth line naming the check-only variant, gives check and lock the same exit code, diagnostics, and lock bytes as a default build, and refuses production build and the verify of a project with a production root with LLC0205 before any build, verification, or export is published. | ## runtime diff --git a/README.md b/README.md index d93a9f1395..b49b6f0b05 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ just vv # the complete normative acceptance gate (SPEC.md §9.2) just release # vv, then the §30 release criterion; refused until 1.0.0 ``` -All 493 registered conformance IDs have their named tests; `just vv` checks them with the pinned toolchain installed. +All 494 registered conformance IDs have their named tests; `just vv` checks them with the pinned toolchain installed. The differential against the independent generator `lean4-prod` (SPEC.md §17.19, `OR-01`..`OR-08`) acquires it at its pinned commit: from the checkout `LEXLEAN_ORACLE_DIR` names, or by fetching the commit with `git` into the Cargo target directory (`LEXLEAN_ORACLE_CACHE` overrides), and builds it with the pinned Lean and Rust toolchains. It is validation evidence only and no input to any identity. An oracle that cannot be acquired, is not the pinned files, or fails is unavailable: that fails the gate on Linux x86-64 and is printed as `NOT VALIDATED` elsewhere, and is never reported as agreement. @@ -168,7 +168,7 @@ Every row is validated by `just vv`; the IDs link the claim to its register row, | Capability | IDs | Level | | --- | --- | --- | -| Exact repository identity, layout, generated documents, release gate, total classification of every closed enum by every consumer, and the devcontainer pinned to the toolchains | `RP-01`..`RP-18` | `build` | +| Exact repository identity, layout, generated documents, release gate, total classification of every closed enum by every consumer, the devcontainer pinned to the toolchains, and a check-only build without the production data | `RP-01`..`RP-19` | `build` | | Closed project configuration, canonical lock file, and offline dependency policy | `CF-01`..`CF-18` | `build` | | Total lexical closure: every accepted atom is covered by exactly one declared origin | `LX-01`..`LX-14` | `build` | | Versioned lexicon packages with closed schemas, denotations, and renderer tokens | `GL-01`..`GL-18` | `build` | diff --git a/SPEC.md b/SPEC.md index b7e6bd3a82..f9805b0d4d 100644 --- a/SPEC.md +++ b/SPEC.md @@ -577,7 +577,7 @@ Non-UTF-8 project paths are outside language 1.0 and produce a registered enviro - Unknown registries and unknown Git sources are denied. - `repo-model`, `repo-conformance`, and `xtask` are `publish = false`. - No shipped crate may depend on a `publish = false` repository crate. -- Cargo features MUST NOT disable a normative capability. LexLean 1.0 defines no optional capability feature. +- Cargo features MUST NOT disable a normative capability, with one exception. The `lexlean` crate's `production-data` feature, on by default, embeds `language/preservation-1.2/library/`, the native preservation library that only certificate generation reads (§17.17). A build without it is a checker: it embeds every other file of §21.2, reports the language-1.2 compiler-semantics ID from the constant `LANGUAGE_1_2_SEMANTICS_ID` that `RP-10` holds to the full tree, behaves as a default build for every command that generates no certificate, refuses `production build` and the `verify` of a project with a production root with `LLC0205` before any build, verification, or export is published, and adds the line `variant check-only` to its version report (§30.3) (`RP-19`). It shares the compiler-semantics IDs of a full build, not its executable identity: it does not replace a full binary for any certifying or producing use. Released binaries and the normative gate use the default features. LexLean defines no other optional capability feature. - Dependency additions require a license decision and an update to `deny.toml` only when the actual graph requires it. ### 8.5 Required implementation dependencies @@ -9590,6 +9590,11 @@ The released binary embeds all three closed language IDs. Repository tests recompute the complete current input tree and, from the exclusion lists of this section, the compatibility-filtered trees independently, compare each with the embedded ID, and pin the 1.0 and 1.1 IDs to the committed example locks. +A build without the `production-data` feature (§8.4) lacks part of the full +tree, so it reports the language-1.2 ID from the checked-in constant +`LANGUAGE_1_2_SEMANTICS_ID`; the same tests require that constant to equal the +recomputed ID, because a wrong one would lock and check consistently with +itself. Its 1.0 and 1.1 IDs are computed, since no file they cover is left out. ### 21.3 Source ID @@ -10652,7 +10657,7 @@ pub fn verify_artifact(bundle: &Utf8Path) -> Result; **Request.** `lexlean/production-request/1` is closed: `roots`, non-empty and strictly ascending by name, each a fully qualified production root of the project's entrypoint closure with a crate `name` and `version` of the §17.16 package forms and `targets` strictly ascending by ID, each a registered ID with its descriptor digest; an optional `expect` pinning the source ID, the semantic ID, and the SHA-256 of the lock file; and optional `evidence`, strictly ascending by root, each a requested root, the kind `gnaf`, project-relative paths of a `lexlean/gnaf-request/1` and a `lexlean/gnaf-certificate/1` document, and the certificate identity the caller means. No field states a certification, an optimality claim, a preservation result, a certificate verdict, Lean, LCNF, a program, or Rust, and an unknown field does not deserialize. A root name is looked up, never interpreted, and one that cannot be a Lean name is refused by form. -**Run.** `build` refuses, before any Lean process runs and before anything is published: a malformed request (`LLC0201`); a root that is not a production root (`LLC0202`); an unregistered or undeclared target or another digest (`LLC0203`); a pin the project no longer matches (`LLC0204`); an evidence path that escapes the project or a symlinked bundle area (`LLS8001`); malformed evidence (`LLB6006`, `LLB6007`); evidence whose certificate is not the pinned one, earns a `refused` verdict, or is for a request whose reference program is not the root's lowered program (`LLV7101`); and a package the renderer refuses (`LLB6005`). Every check and eligibility failure of the project fails as it does for `check`. The project is then verified by the unchanged §22 pipeline over the entrypoint selection, so every production root of the project is certified; a project edited during the run is `LLC0204`. For each requested root and target, `build` renders the exporting package `verify` does not assemble (§17.17): the renderer of §17.16 over the verified lowered program, exporting the recorded entry alone as `run` with every parameter owned, with `sources` the semantic ID; its `src/lib.rs` begins with the certified crate's bytes. The bundle is published atomically, content-addressed, at `/production//`; there is no output-directory option. +**Run.** `build` refuses, before any Lean process runs and before anything is published: a malformed request (`LLC0201`); a root that is not a production root (`LLC0202`); an unregistered or undeclared target or another digest (`LLC0203`); a pin the project no longer matches (`LLC0204`); a compiler built without the production data (`LLC0205`, §8.4); an evidence path that escapes the project or a symlinked bundle area (`LLS8001`); malformed evidence (`LLB6006`, `LLB6007`); evidence whose certificate is not the pinned one, earns a `refused` verdict, or is for a request whose reference program is not the root's lowered program (`LLV7101`); and a package the renderer refuses (`LLB6005`). Every check and eligibility failure of the project fails as it does for `check`. The project is then verified by the unchanged §22 pipeline over the entrypoint selection, so every production root of the project is certified; a project edited during the run is `LLC0204`. For each requested root and target, `build` renders the exporting package `verify` does not assemble (§17.17): the renderer of §17.16 over the verified lowered program, exporting the recorded entry alone as `run` with every parameter owned, with `sources` the semantic ID; its `src/lib.rs` begins with the certified crate's bytes. The bundle is published atomically, content-addressed, at `/production//`; there is no output-directory option. **Bundle.** `result.json`; `packages///` with `Cargo.toml`, `src/lib.rs`, `provenance.json` (`lexlean/rust-provenance/1`), and `package.json` (the `lexlean/rust-package/1` manifest); and `evidence/`: `attestation.json`, `compiler-input.json`, `preservation.json`, `program/R.json`, `crate/R..rs`, `certificates/.lex.tex` for certificates A, B, and E (their kernel data in the authoring notation, §17.17), and `gnaf/R/request.json` and `certificate.json` where evidence was offered. @@ -10837,6 +10842,7 @@ The initial registry MUST include at least these exact codes and meanings: | `LLC0202` | Requested root is not a production root (§24.7). | | `LLC0203` | Unknown or mismatched production target (§24.7). | | `LLC0204` | Stale production expectation (§24.7). | +| `LLC0205` | Production data not embedded in this build (§8.4). | | `LLL1001` | Invalid UTF-8, forbidden scalar, or line-ending form. | | `LLL1002` | Forbidden comment, raw percent, tab, or TeX escape. | | `LLL1003` | Non-NFC or noncanonical source requiring formatting. | @@ -11546,6 +11552,8 @@ compiler-semantics lean-toolchain leanprover/lean4:v4.32.1 ``` +A build without the `production-data` feature (§8.4) is never a release binary. It reports these four lines followed by `variant check-only`. + The crate package MUST be the crate `cargo publish` would upload: the release workflow packages the crate twice to the same bytes, runs `cargo publish --dry-run`, and refuses a package whose SHA-256 differs from the one `checksums.txt` lists for the crate, from the dry-run package, or from what crates.io requires of an archive (a description, a license, a repository, the readme it names, and at most 10 MiB). It uploads to crates.io only when a `CARGO_REGISTRY_TOKEN` secret or trusted publishing authorises it, and otherwise creates the release without the upload and says so. A commit of a release line `release/vX.Y` is published as the pre-release `X.Y.0-dev.N`, `N` being the number of first-parent commits of the line at that commit, so that a release `X.Y.0` supersedes every one of them; `RP-18` reads the workflows and runs the script that decides each of these. ### 30.4 Completion criterion @@ -11605,6 +11613,7 @@ Every row below is normative, has honesty level `build`, and MUST be copied byte | `RP-15` | `repository` | Every match over a closed semantic enum (the IR, the production realization calculus, and its Rust AST) that names at least five of the enum's variants names all of them, with no wildcard or binding catch-all arm, so that a variant added to the enum is a compile error in each Lean, LaTeX, validation, charge, and calculus consumer and never a silent fallback; the audit rejects a catch-all planted in each consumer group and fails when a consumer it must read has no such match left. | §27.2 | | `RP-16` | `repository` | The development container installs, at image build, exactly the Rust toolchain that rust-toolchain.toml pins and exactly the Lean toolchain that lean-toolchain pins and selects no other default, so that nothing is fetched when a session starts, and a Dockerfile that names another version of either, installs a second toolchain, or selects an unpinned default is refused. | §9.3 | | `RP-18` | `repository` | The release workflow packages the lexlean crate twice to the same bytes, runs cargo publish --dry-run, and refuses a crate whose SHA-256 differs from the one release/checksums.txt lists for it or from the bytes cargo would upload, or whose archive lacks the metadata and size crates.io requires, and uploads to crates.io only when a CARGO_REGISTRY_TOKEN secret or trusted publishing authorises it; a commit of a release line release/vX.Y is published as the pre-release X.Y.0-dev.N, N being its number of first-parent commits, and a plant in each of these checks is refused. | §30.3 | +| `RP-19` | `repository` | A build of the lexlean crate without its default production-data feature embeds no file of language/preservation-1.2/library/, reports the compiler-semantics IDs of a default build and its version report with a fifth line naming the check-only variant, gives check and lock the same exit code, diagnostics, and lock bytes as a default build, and refuses production build and the verify of a project with a production root with LLC0205 before any build, verification, or export is published. | §8.4, §21.2 | | `CF-01` | `configuration-lock` | Project configuration accepts exactly the project/1 schema and rejects unknown or missing fields. | §10.1 | | `CF-02` | `configuration-lock` | Every operational limit is explicit, positive, parsed with checked arithmetic, and has no hidden default. | §10.2 | | `CF-03` | `configuration-lock` | Configured paths resolve within the project under the specified UTF-8 and nonsymlink rules. | §10.1, §25.1 | @@ -12083,7 +12092,7 @@ Every row below is normative, has honesty level `build`, and MUST be copied byte | `LM-09` | `language-models` | No prompt is code: no member of the closed language maps `string` or `bytes` to a function, a term, or source — every operation of the primitive registry that takes a `string` or `bytes` operand is classified by the audit with a data result, the registry's schema enumeration and the production registry's primitive rows equal one another and equal that classified set, and the text declarations of `lexlean/semantic-module/2` state no `string`-typed member, so a prompt reaches a model only as the tokens `encodeText` makes of it; a planted operation or text member of that shape is caught by the audit with its name. | §17.12 | | `LM-13` | `language-models` | The text laws a tokenizer elaborates through are LexLean source and not authored text: the module that states them is one language-1.2 native core module of the embedded `language/text-1.2` project, the project holds no file of Lean source, no independently authored Lean file anywhere in the release tree declares the `LexLeanText` namespace or lies under its module root, and the one-time migration input is absent; the registry lists only that module, the declarations and their exact axiom policies are read from its native data, which the compiler embeds and hashes into the language-1.2 semantics, and a module that declares a text component imports the generated module rather than splicing any Lean text. | §17.10, §17.12 | -**Total required capability IDs:** 493. +**Total required capability IDs:** 494. No row may be downgraded to `some-true` or `open`. Upstream Lean facts are ledger/authority rows, not substitutions for these build behaviors. diff --git a/crates/conformance/src/cases/repository.rs b/crates/conformance/src/cases/repository.rs index 9c227c41dd..153da0e1c5 100644 --- a/crates/conformance/src/cases/repository.rs +++ b/crates/conformance/src/cases/repository.rs @@ -898,7 +898,7 @@ pub(crate) fn run(id: &str) { let model = repo_model::Model::load(&root.join("model").into_std_path_buf()) .expect("the model loads"); let table = spec_table(); - assert_eq!(table.len(), 493, "§31 has 493 rows"); + assert_eq!(table.len(), 494, "§31 has 494 rows"); assert_eq!(model.ids.id.len(), table.len(), "register row count"); for ((spec_id, spec_suite, spec_statement), row) in table.iter().zip(model.ids.id.iter()) @@ -1037,6 +1037,15 @@ pub(crate) fn run(id: &str) { let (only_1_2, only_1_1) = support::introduced_later(); let (ten, eleven, twelve) = support::semantics_ids(&borrowed); assert_eq!(twelve, recomputed, "RP-10: the 1.2 ID"); + // §8.4: a build without production-data reports this constant in + // place of the ID it cannot compute. Nothing else would notice a + // stale one: that build locks and checks with it consistently. + assert_eq!( + lexlean::LANGUAGE_1_2_SEMANTICS_ID, + twelve.to_hex(), + "RP-10: lexlean::LANGUAGE_1_2_SEMANTICS_ID is stale; the tree's language-1.2 ID is {}", + twelve.to_hex() + ); assert_eq!( eleven, lexlean::compiler_semantics_id_for("1.1"), @@ -2419,10 +2428,204 @@ pub(crate) fn run(id: &str) { // §30.3: the crate that goes to crates.io is the crate the release // attaches, proved on every run, and uploaded only with a credential. "RP-18" => rp_18(), + // §8.4: a build without the production data checks and locks as the + // default build does, and refuses the work that needs that data. + "RP-19" => rp_19(), other => panic!("no repository case is wired for {other}"), } } +/// RP-19: the binary built without `production-data`, held to the default +/// build this harness links. The language-1.2 ID it reports is a constant, +/// which RP-10 holds to the tree; here it must also land in the lock bytes, +/// which is what a wrong constant would change while every verdict agreed. +fn rp_19() { + use lexlean::api::production::{ + self, Expectation, PackageName, ProductionRequest, RootRequest, TargetRef, REQUEST_SPEC, + }; + let root = support::repo_root(); + let binary = + support::check_only_binary(&root).expect("the crate builds without its default features"); + + // The library is left out and the rest of the tree is not: the binary + // holds no library source and does hold the library's module list, which + // is outside `library/`. + let image = std::fs::read(binary.as_std_path()).expect("the binary is readable"); + let holds = |needle: &[u8]| image.windows(needle.len()).any(|window| window == needle); + let rows = support::normative_rows(); + let library: Vec<&(String, Vec)> = rows + .iter() + .filter(|(path, _)| path.starts_with("language/preservation-1.2/library/")) + .collect(); + assert!( + library.len() > 10, + "RP-19: the library has its sources on disk" + ); + let largest = library + .iter() + .max_by_key(|(_, bytes)| bytes.len()) + .expect("a library file"); + assert!( + !holds(&largest.1), + "RP-19: the build without production-data embeds `{}`", + largest.0 + ); + let kept = rows + .iter() + .find(|(path, _)| path == "language/preservation-1.2/library.toml") + .expect("the library's module list"); + assert!(holds(&kept.1), "RP-19: `{}` is embedded", kept.0); + + let normalized = + |text: &str, project: &camino::Utf8Path| text.replace(project.as_str(), ""); + let same = |what: &str, linked: &support::P, built: &support::P, arguments: &[&str]| { + let (exit_a, out_a, err_a) = linked.cli(arguments); + let (exit_b, out_b, err_b) = support::cli_binary_in(&binary, &built.root, arguments); + assert_eq!( + exit_a, + exit_b, + "RP-19: {what}: `{}` exit code", + arguments.join(" ") + ); + assert_eq!( + normalized(&out_a, &linked.root), + normalized(&out_b, &built.root), + "RP-19: {what}: `{}` stdout", + arguments.join(" ") + ); + assert_eq!( + normalized(&err_a, &linked.root), + normalized(&err_b, &built.root), + "RP-19: {what}: `{}` stderr", + arguments.join(" ") + ); + }; + + let (_, version, _) = support::cli_in(&root, &["--version"]); + let (exit, built_version, _) = support::cli_binary_in(&binary, &root, &["--version"]); + assert_eq!(exit, 0, "RP-19: --version"); + // The same four lines, and a fifth that keeps it from passing for a + // release binary, which it cannot replace (§30.3). + assert_eq!( + format!( + "{version}variant check-only +" + ), + built_version, + "RP-19: --version" + ); + + // A lock records its language's compiler-semantics ID, so equal lock + // bytes for a 1.0, 1.1, and 1.2 project are equal IDs. + for example in ["nat-add-zero", "semantic-1.1", "language-1.2", "production"] { + let linked = support::P::copy_example(example); + let built = support::P::copy_example(example); + for project in [&linked, &built] { + std::fs::remove_file(project.root.join("lexlean.lock").as_std_path()) + .expect("the example has a lock"); + } + same(example, &linked, &built, &["lock"]); + let lock = |project: &support::P| { + std::fs::read_to_string(project.root.join("lexlean.lock").as_std_path()) + .expect("a lock was written") + }; + assert_eq!( + lock(&linked), + lock(&built), + "RP-19: {example}: lexlean.lock bytes" + ); + same( + example, + &linked, + &built, + &["--diagnostic-format", "json", "check"], + ); + } + for negative in [ + "type-parameter-capture", + "term-cases-scrutinee-not-inductive", + "induction-nested-type", + ] { + let linked = support::P::negative(negative); + let built = support::P::negative(negative); + same( + negative, + &linked, + &built, + &["--diagnostic-format", "json", "check"], + ); + } + + // The two commands that generate certificates are refused with LLC0205 + // before any work is published: no build, verification, or export. + let refused = |project: &support::P, arguments: &[&str]| { + let (exit, out, err) = support::cli_binary_in(&binary, &project.root, arguments); + assert_eq!( + exit, + 2, + "RP-19: `{}` exits 2: {out}{err}", + arguments.join(" ") + ); + assert!( + out.contains("LLC0205") || err.contains("LLC0205"), + "RP-19: `{}` reports LLC0205: {out}{err}", + arguments.join(" ") + ); + for area in ["build", "verified", "production"] { + assert!( + !project + .root + .join(".lexlean") + .join(area) + .as_std_path() + .exists(), + "RP-19: `{}` published `.lexlean/{area}`", + arguments.join(" ") + ); + } + }; + let project = support::P::copy_example("production"); + refused(&project, &["--diagnostic-format", "json", "verify"]); + let digests: std::collections::BTreeMap = production::targets() + .expect("targets") + .into_iter() + .map(|descriptor| (descriptor.id, descriptor.digest)) + .collect(); + let request = ProductionRequest { + spec: REQUEST_SPEC.to_owned(), + roots: vec![RootRequest { + root: "Production.Main.checkedSum".to_owned(), + package: PackageName { + name: "pkg".to_owned(), + version: "1.0.0".to_owned(), + }, + targets: vec![TargetRef { + id: "rust-std".to_owned(), + digest: digests["rust-std"], + }], + }], + expect: Expectation::default(), + evidence: Vec::new(), + }; + let project = support::P::copy_example("production"); + std::fs::write( + project.root.join("request.json").as_std_path(), + serde_json::to_vec(&request).expect("the request serializes"), + ) + .expect("write the request"); + refused( + &project, + &[ + "--diagnostic-format", + "json", + "production", + "build", + "--request", + "request.json", + ], + ); +} + /// RP-16: every toolchain the Dockerfile installs is the pinned one. A Rust /// toolchain is installed by `--default-toolchain ` or `rustup toolchain /// install `, a Lean toolchain by `elan toolchain install `, and diff --git a/crates/conformance/src/support.rs b/crates/conformance/src/support.rs index 1809bb2546..e96a9aca7a 100644 --- a/crates/conformance/src/support.rs +++ b/crates/conformance/src/support.rs @@ -3230,6 +3230,74 @@ pub fn packaged_crate_version(root: &Utf8Path) -> Result { run(binary.as_str(), &["--version"], &unpacked, &[]) } +/// RP-19 (§8.4): build the `lexlean` binary without its default +/// `production-data` feature and return its path. The build has a directory +/// of its own (`target/check-only-verify`): the workspace build directory is +/// held by the running test, and RP-12 builds a default binary at the same +/// path under `target/package-verify`. +/// +/// # Errors +/// +/// The build failing, with its output. +pub fn check_only_binary(root: &Utf8Path) -> Result { + let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_owned()); + let target_dir = root.join("target/check-only-verify"); + let output = std::process::Command::new(&cargo) + .args([ + "build", + "--offline", + "--locked", + "-p", + "lexlean", + "--bin", + "lexlean", + "--no-default-features", + ]) + .current_dir(root.as_std_path()) + .env("CARGO_TARGET_DIR", target_dir.as_str()) + // Debug info is not what is compared; leaving it out keeps the + // directory small. + .env("CARGO_PROFILE_DEV_DEBUG", "0") + .output() + .map_err(|error| format!("{cargo} build: {error}"))?; + if !output.status.success() { + return Err(format!( + "{cargo} build --no-default-features exited {:?}\n{}", + output.status.code(), + String::from_utf8_lossy(&output.stderr) + )); + } + Ok(target_dir.join("debug").join(if cfg!(windows) { + "lexlean.exe" + } else { + "lexlean" + })) +} + +/// Run a `lexlean` executable in `directory` and return its exit code, +/// stdout, and stderr, as [`cli_in`] does for the library linked here. +/// +/// # Panics +/// +/// When the executable cannot be started. +#[must_use] +pub fn cli_binary_in( + binary: &Utf8Path, + directory: &Utf8Path, + arguments: &[&str], +) -> (i32, String, String) { + let output = std::process::Command::new(binary.as_std_path()) + .args(arguments) + .current_dir(directory.as_std_path()) + .output() + .unwrap_or_else(|error| panic!("{binary}: {error}")); + ( + output.status.code().unwrap_or(-1), + String::from_utf8_lossy(&output.stdout).into_owned(), + String::from_utf8_lossy(&output.stderr).into_owned(), + ) +} + /// Run the pinned `lean` on a tiny module with `#print axioms` commands and /// return `(the successful output, the output of a run whose fourth command /// names an unknown constant)`, both normalized to LF. Requires the pinned diff --git a/crates/conformance/tests/conformance.rs b/crates/conformance/tests/conformance.rs index 2056b03d10..55991ca799 100644 --- a/crates/conformance/tests/conformance.rs +++ b/crates/conformance/tests/conformance.rs @@ -90,6 +90,11 @@ fn conformance_rp_18() { repo_conformance::cases::run("RP-18"); } +#[test] +fn conformance_rp_19() { + repo_conformance::cases::run("RP-19"); +} + #[test] fn conformance_cf_01() { repo_conformance::cases::run("CF-01"); diff --git a/features/suites/repository.feature b/features/suites/repository.feature index c3cb5f0698..dffa57327f 100644 --- a/features/suites/repository.feature +++ b/features/suites/repository.feature @@ -72,6 +72,7 @@ Feature: repository Given every file under language, schemas, tests/golden/axiom-parser, and tests/golden/canonical-json sorted by path bytes When lexlean::artifact::content_id::tree_digest recomputes the tree digest from those files Then the recomputed digest equals lexlean::compiler_semantics_id() + And the recomputed language-1.2 digest equals lexlean::LANGUAGE_1_2_SEMANTICS_ID, which a build without the production-data feature reports @RP-11 @build Scenario: Every public README capability claim is tied to a registered model ID and honesty level. @@ -128,3 +129,12 @@ Feature: repository Then the crate is packaged twice to the same bytes and dry-run on every run, and the crate cargo would upload is the crate release/lexlean.crate holds and release/checksums.txt lists And the only step that uploads to crates.io runs after those checks, and only when a token or trusted publishing is present And a commit of a release line is named X.Y.0-dev.N, and a package, checksum, metadata, version, or credential check that is removed or planted is refused + + @RP-19 @build + Scenario: A build of the lexlean crate without its default production-data feature embeds no file of language/preservation-1.2/library/, reports the compiler-semantics IDs of a default build and its version report with a fifth line naming the check-only variant, gives check and lock the same exit code, diagnostics, and lock bytes as a default build, and refuses production build and the verify of a project with a production root with LLC0205 before any build, verification, or export is published. + Given the lexlean binary built with --no-default-features and the default build this harness links + When both lock and check the committed examples nat-add-zero, semantic-1.1, language-1.2, and production, and check three language-1.2 negative fixtures, and the binary runs verify and production build on the production example + Then the binary holds no file of language/preservation-1.2/library/ and does hold language/preservation-1.2/library.toml + And --version of the binary is the default report followed by the line variant check-only + And every exit code, every JSON diagnostic, and every written lexlean.lock are byte-equal between the two + And verify and production build exit 2 with LLC0205 and publish no build, verified, or production directory diff --git a/model/ids.toml b/model/ids.toml index 7a3ca502f5..78a31642ae 100644 --- a/model/ids.toml +++ b/model/ids.toml @@ -109,6 +109,12 @@ level = "build" suite = "repository" statement = "The release workflow packages the lexlean crate twice to the same bytes, runs cargo publish --dry-run, and refuses a crate whose SHA-256 differs from the one release/checksums.txt lists for it or from the bytes cargo would upload, or whose archive lacks the metadata and size crates.io requires, and uploads to crates.io only when a CARGO_REGISTRY_TOKEN secret or trusted publishing authorises it; a commit of a release line release/vX.Y is published as the pre-release X.Y.0-dev.N, N being its number of first-parent commits, and a plant in each of these checks is refused." +[[id]] +id = "RP-19" +level = "build" +suite = "repository" +statement = "A build of the lexlean crate without its default production-data feature embeds no file of language/preservation-1.2/library/, reports the compiler-semantics IDs of a default build and its version report with a fifth line naming the check-only variant, gives check and lock the same exit code, diagnostics, and lock bytes as a default build, and refuses production build and the verify of a project with a production root with LLC0205 before any build, verification, or export is published." + [[id]] id = "CF-01" level = "build" diff --git a/xtask/src/spec_links.rs b/xtask/src/spec_links.rs index 231545c396..bc36890817 100644 --- a/xtask/src/spec_links.rs +++ b/xtask/src/spec_links.rs @@ -61,8 +61,8 @@ fn parse_table(spec: &str) -> Result, Fail> { pub fn validate(root: &Path) -> Result<(), Fail> { let spec = std::fs::read_to_string(root.join("SPEC.md"))?; let rows = parse_table(&spec)?; - if rows.len() != 493 { - return Err(format!("RP-07: the §31 table has {} rows, not 493", rows.len()).into()); + if rows.len() != 494 { + return Err(format!("RP-07: the §31 table has {} rows, not 494", rows.len()).into()); } // The prose total under the table is part of the contract a reader // relies on; a row added without it would leave §31 contradicting itself. From f8c868933a0bf0d188768a7c5f9005fefb760fcc Mon Sep 17 00:00:00 2001 From: humuhumu33 Date: Thu, 12 Nov 2026 19:58:49 +0000 Subject: [PATCH 2/4] The production-data feature: a check-only build with the 1.2 ID as a constant (#495) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On by default, it embeds language/preservation-1.2/library/, the native preservation library only certificate generation reads (32.2 of the 36.4 MB of embedded data). Without it, build.rs leaves those files out, compiler_semantics_id_for("1.2") returns LANGUAGE_1_2_SEMANTICS_ID, the version report adds "variant check-only", and production build and the verify of a project with a production root refuse with LLC0205 before a build is rendered or published. The 1.0 and 1.1 IDs are computed as before: §21.2 excludes every preservation-1.2 file from them. A default build differs only by a constant it tests. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 17 +++++++++++++++++ ERRORS.md | 6 ++++++ crates/lexlean/Cargo.toml | 12 ++++++++++++ crates/lexlean/build.rs | 15 +++++++++++++++ crates/lexlean/src/api.rs | 12 ++++++++++++ crates/lexlean/src/api/production.rs | 1 + crates/lexlean/src/cli.rs | 12 ++++++++++-- crates/lexlean/src/lib.rs | 19 ++++++++++++++++++- crates/lexlean/src/production/preserve.rs | 23 +++++++++++++++++++++++ model/errors.toml | 7 +++++++ 10 files changed, 121 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20399e3a34..8d850e99f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,23 @@ workspace carried at those versions without a tag. ## Unreleased +- A check-only build of the crate, #495. The `lexlean` crate's + `production-data` feature, on by default, embeds + `language/preservation-1.2/library/`, the native preservation library that + only certificate generation reads (32.2 of the 36.4 MB of embedded data). + Built with `--no-default-features`, the crate leaves it out and reports the + language-1.2 compiler-semantics ID from `LANGUAGE_1_2_SEMANTICS_ID`, which + `RP-10` now requires to equal the ID recomputed from disk; a project's + `check`, `lock`, `fmt`, and `build` behave as in a default build, and + `production build` and the `verify` of a project with a production root are + refused with the new `LLC0205` before anything is published (`RP-19`). + Its version report adds the line `variant check-only`: it shares the + compiler-semantics IDs of a full build, not its executable identity. + SPEC.md §8.4 names this feature as the one exception to its rule that no + feature disables a normative capability. A default build is unchanged. + A landing that moves the language-1.2 ID now also updates the constant; + `RP-10` names the new value when it is stale. + - A one-pass writer for the counts of the bootstrap count cases, #92. Under `LEXLEAN_COUNTS=fast` each of `BS-05` to `BS-08` and `BS-11` to `BS-15` records every count it checks in `target/count-report/` instead of diff --git a/ERRORS.md b/ERRORS.md index 9a995e313f..4c441c7851 100644 --- a/ERRORS.md +++ b/ERRORS.md @@ -136,6 +136,12 @@ The source ID, semantic ID, or lock digest a production request pins differs fro Class: `cli-configuration`. Exit code: 2. +## `LLC0205` --- Production data not embedded in this build + +The compiler was built without the production data, which production export and the certification of a production root read. + +Class: `cli-configuration`. Exit code: 2. + ## `LLF5001` --- Invalid definition form, self head, or recursion Invalid definition form, self head, or recursion. diff --git a/crates/lexlean/Cargo.toml b/crates/lexlean/Cargo.toml index ab72c8f8be..17859ce1ea 100644 --- a/crates/lexlean/Cargo.toml +++ b/crates/lexlean/Cargo.toml @@ -39,6 +39,18 @@ walkdir = { workspace = true } rustix = { workspace = true } signal-hook = { workspace = true } +# `production-data` embeds the native preservation library +# (`language/preservation-1.2/library/`, 32.2 of the 36.4 MB of language data), +# which only certificate generation reads: `production build`, and `verify` +# of a project with a production root. A build without it (SPEC.md §8.4) is +# a checker for hosts where 31 MB costs start time and memory, such as +# WebAssembly; it reports the language-1.2 compiler-semantics ID from the +# constant RP-10 holds to the full tree, and refuses those two commands with +# LLC0205 instead of reading data it does not have. +[features] +default = ["production-data"] +production-data = [] + [dev-dependencies] proptest = { workspace = true } diff --git a/crates/lexlean/build.rs b/crates/lexlean/build.rs index ddac668a2e..95d47990ef 100644 --- a/crates/lexlean/build.rs +++ b/crates/lexlean/build.rs @@ -28,6 +28,9 @@ const SEMANTIC_DIRS: [(&str, &str); 4] = [ ("tests/golden/canonical-json", "tests/golden/canonical-json"), ]; +/// The embedded directory the `production-data` feature carries. +const PRODUCTION_DATA_DIR: &str = "language/preservation-1.2/library"; + fn main() { let manifest = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("cargo sets this")); @@ -46,7 +49,16 @@ fn main() { // Bytewise-sorted repository-relative path order, the §11.5 tree order. files.sort_by(|a, b| a.0.as_bytes().cmp(b.0.as_bytes())); + // Without `production-data` the native preservation library is left out + // (SPEC.md §8.4): only certificate generation reads it, and it is most of + // the embedded bytes. Its files are absent, not empty, so a reader that + // reached one would find it missing rather than read an empty library. + let production_data = env::var_os("CARGO_FEATURE_PRODUCTION_DATA").is_some(); let mut out = String::new(); + out.push_str(&format!( + "/// Whether this build embeds the production data (`{PRODUCTION_DATA_DIR}/`).\n\ + pub const PRODUCTION_DATA: bool = {production_data};\n\n" + )); out.push_str( "/// Every embedded normative file as `(repository-relative path, bytes)`,\n\ /// in bytewise-sorted path order.\n\ @@ -54,6 +66,9 @@ fn main() { ); for (rel, abs) in &files { println!("cargo:rerun-if-changed={}", abs.display()); + if !production_data && rel.starts_with(&format!("{PRODUCTION_DATA_DIR}/")) { + continue; + } out.push_str(&format!( " ({:?}, include_bytes!({:?})),\n", rel, diff --git a/crates/lexlean/src/api.rs b/crates/lexlean/src/api.rs index 883407efaf..400fa59f31 100644 --- a/crates/lexlean/src/api.rs +++ b/crates/lexlean/src/api.rs @@ -1056,6 +1056,18 @@ impl Engine { let operational = crate::verify::operational::Operational::from_environment() .map_err(LexLeanError::from_diagnostic)?; let (mut checked, lock) = self.checked(&request.selection)?; + // A project with a production root is certified, which needs the + // native library; a build without it refuses here, before a build is + // rendered or published (§8.4), not partway through verification. + if checked + .modules + .values() + .filter_map(|module| module.production.as_ref()) + .any(|report| !report.roots.is_empty()) + { + crate::production::preserve::require_library() + .map_err(LexLeanError::from_diagnostic)?; + } let mut rendered = render_build(&self.project, &checked)?; // Rendering is the last consumer of parser atoms, // declaration-origin tables, visibility sets, and the core diff --git a/crates/lexlean/src/api/production.rs b/crates/lexlean/src/api/production.rs index cc8bcefb7d..ac5dea0272 100644 --- a/crates/lexlean/src/api/production.rs +++ b/crates/lexlean/src/api/production.rs @@ -1061,6 +1061,7 @@ fn build_inner( request: &ProductionRequest, ) -> Result { request.validate()?; + crate::production::preserve::require_library().map_err(LexLeanError::from_diagnostic)?; let project = &engine.project; let (checked, _lock) = engine.checked(&Selection::Entrypoints)?; let lock_bytes = diff --git a/crates/lexlean/src/cli.rs b/crates/lexlean/src/cli.rs index d68338dc15..fe5c226dde 100644 --- a/crates/lexlean/src/cli.rs +++ b/crates/lexlean/src/cli.rs @@ -341,13 +341,21 @@ fn print_human_diagnostics(stderr: &mut dyn Write, error: &LexLeanError, colors: } fn version_text() -> String { - format!( + let report = format!( "lexlean {}\nlanguage {}\ncompiler-semantics {}\nlean-toolchain {}\n", crate::COMPILER_VERSION, crate::LANGUAGE_VERSION, crate::compiler_semantics_id().to_hex(), crate::LEAN_TOOLCHAIN - ) + ); + // A build without the production data shares the compiler-semantics IDs + // of a full build but cannot certify, so it says what it is: the same + // four lines would let it pass for a release binary (§8.4, §30.3). + if crate::embedded::PRODUCTION_DATA { + report + } else { + report + "variant check-only\n" + } } /// The generated `ERRORS.md` entry for one registered code (§23.4). diff --git a/crates/lexlean/src/lib.rs b/crates/lexlean/src/lib.rs index dd7664959b..92f5c8325f 100644 --- a/crates/lexlean/src/lib.rs +++ b/crates/lexlean/src/lib.rs @@ -278,6 +278,16 @@ fn embedded_digest(keep: impl Fn(&str) -> bool) -> Sha256Digest { tree_digest(&files) } +/// The language-1.2 compiler-semantics ID of the full embedded tree, checked +/// in for a build without the `production-data` feature, which lacks part of +/// that tree and so cannot compute it (SPEC.md §8.4, §21.2). A build with the +/// feature computes the ID and never reads this. RP-10 recomputes the ID from +/// disk and fails when this differs: a wrong value here would lock and check +/// consistently with itself, so agreement on verdicts could not reveal it. +/// The 1.0 and 1.1 IDs need no constant: no file they cover is left out. +pub const LANGUAGE_1_2_SEMANTICS_ID: &str = + "635a25acb886587f8777525e778092e9599d1f2df26da59403ee39e9e299151a"; + /// The compiler-semantics ID for one selected language. Language 1.0 excludes /// all files introduced solely for 1.1 and 1.2, and Language 1.1 excludes /// all files introduced solely for 1.2, preserving historical identities. @@ -292,7 +302,14 @@ pub fn compiler_semantics_id_for(language: &str) -> Sha256Digest { *V1_0.get_or_init(|| embedded_digest(|path| !is_v1_1_file(path) && !is_v1_2_file(path))) } LANGUAGE_1_1 => *V1_1.get_or_init(|| embedded_digest(|path| !is_v1_2_file(path))), - LANGUAGE_1_2 => *V1_2.get_or_init(|| embedded_digest(|_| true)), + LANGUAGE_1_2 => *V1_2.get_or_init(|| { + if embedded::PRODUCTION_DATA { + embedded_digest(|_| true) + } else { + Sha256Digest::from_hex(LANGUAGE_1_2_SEMANTICS_ID) + .expect("RP-10 parses the checked-in language-1.2 ID") + } + }), // An unsupported language never shares an identity with a supported // one; configuration rejects it before any identity is published. other => Sha256Digest::of(format!("unsupported-language\0{other}").as_bytes()), diff --git a/crates/lexlean/src/production/preserve.rs b/crates/lexlean/src/production/preserve.rs index 68dacfc30c..26c5936e03 100644 --- a/crates/lexlean/src/production/preserve.rs +++ b/crates/lexlean/src/production/preserve.rs @@ -151,6 +151,28 @@ fn internal(reason: impl std::fmt::Display) -> Diagnostic { Diagnostic::new(code!("LLI9001"), format!("phase preservation: {reason}")) } +/// Refuse, as `LLC0205`, work that needs the native library in a build that +/// does not embed it (the `production-data` feature, SPEC.md §8.4). +/// Certificate generation calls this before reading the library, so the +/// refusal is the registered code rather than whatever the first missing +/// file would turn into on the way out. +/// +/// # Errors +/// +/// `LLC0205` when this build was made without the production data. +pub fn require_library() -> Result<(), Diagnostic> { + if crate::embedded::PRODUCTION_DATA { + Ok(()) + } else { + Err(Diagnostic::new( + code!("LLC0205"), + format!( + "this lexlean was built without the `production-data` feature and does not embed `{LIBRARY_DIR}/`, which certificate generation reads; use a build with default features" + ), + )) + } +} + fn embedded_text(path: &str) -> Result<&'static str, Diagnostic> { crate::embedded::FILES .iter() @@ -437,6 +459,7 @@ pub fn check_native_sources( fn native() -> Result<&'static Native, Diagnostic> { static NATIVE: OnceLock> = OnceLock::new(); + require_library()?; NATIVE.get_or_init(load_native).as_ref().map_err(internal) } diff --git a/model/errors.toml b/model/errors.toml index be2aea77a4..9647343aa0 100644 --- a/model/errors.toml +++ b/model/errors.toml @@ -154,6 +154,13 @@ exit = 2 title = "Stale production expectation" statement = "The source ID, semantic ID, or lock digest a production request pins differs from the project's, or the project changed while it was being exported." +[[error]] +code = "LLC0205" +class = "cli-configuration" +exit = 2 +title = "Production data not embedded in this build" +statement = "The compiler was built without the production data, which production export and the certification of a production root read." + [[error]] code = "LLF5001" class = "language" From 425f15e321337c1bb50f331e61a132235c067cb5 Mon Sep 17 00:00:00 2001 From: humuhumu33 Date: Thu, 12 Nov 2026 20:09:19 +0000 Subject: [PATCH 3/4] VERIFICATION.md: the check-only build's constant can fail (RP-10, RP-19) Co-Authored-By: Claude Opus 5.5 --- VERIFICATION.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/VERIFICATION.md b/VERIFICATION.md index 9dac0f5c81..5d2f83fa56 100644 --- a/VERIFICATION.md +++ b/VERIFICATION.md @@ -14446,3 +14446,31 @@ repository gate have not run here. This branch is source preparation for a draft PR, with existing generated records untouched; its source changes are not qualified by those preceding records. Coordinate the single identity/writer wave with the release owner before readiness, merge or downstream SDK adoption. + +### the check-only build's language-1.2 constant can fail (RP-10, RP-19) + +A build without `production-data` (§8.4) reports `LANGUAGE_1_2_SEMANTICS_ID` in +place of the language-1.2 ID it cannot compute. A wrong constant would not change +a verdict: such a build locks and checks consistently with itself. So the +constant is held twice: `RP-10` against the ID recomputed from disk, and `RP-19` +against the lock bytes of the default build. + +Planted: the last digit of the constant, `…151a` to `…151b`, in +`crates/lexlean/src/lib.rs`. Command: +`cargo test -p repo-conformance --all-features --test conformance -- conformance_rp_10 conformance_rp_19 --exact --test-threads=1`. +Observed: + +```text +test conformance_rp_10 ... FAILED +test conformance_rp_19 ... FAILED +RP-10: lexlean::LANGUAGE_1_2_SEMANTICS_ID is stale; the tree's language-1.2 ID is 635a25acb886587f8777525e778092e9599d1f2df26da59403ee39e9e299151a + left: "635a25acb886587f8777525e778092e9599d1f2df26da59403ee39e9e299151b" + right: "635a25acb886587f8777525e778092e9599d1f2df26da59403ee39e9e299151a" +RP-19: language-1.2: lexlean.lock bytes +test result: FAILED. 0 passed; 2 failed +``` + +`RP-19` failed at the first language-1.2 lock, whose `compiler_semantics` line +carried the planted digit while the default build's carried the tree's. +Restored, `conformance_rp_10` passes; `conformance_rp_19` passed on the same +tree before the plant. From 84ca191cbf79cbdd6b4ed371622e50bcc1520533 Mon Sep 17 00:00:00 2001 From: humuhumu33 Date: Fri, 13 Nov 2026 11:00:48 +0000 Subject: [PATCH 4/4] RP-19: bind the whole excluded inventory, and the counts and ID the merge moved (#495) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review of 425f15e (P2): RP-19's image assertion read the largest library file alone, so a build that left that one out and embedded another would have passed a case that states no library file is embedded. It now binds every file of the inventory: each is witnessed by bytes of its own --- the whole file when it is short, else a window from its middle --- and the image is read once for all of them, a table of first bytes naming the candidates at each position, so the cost is the image's length and not its length times the inventory's size. The one file whose witness the retained data carries anyway is named with its reason, and the reason is checked. The scan is shown to find what is there: the preservation data outside `library/`, which this build embeds, is found in the same image. The same reduced build and the same lock and constant comparisons carry it; no second build and no generator. R4 (SPEC.md §27.2, AGENTS.md) read that no feature switch disables a normative capability, which §8.4 now excepts; both rows say `unsanctioned`, the word RP-08's registered statement already uses, and name §8.4, which names R4 in turn. No registered statement changed. The merge moved the language-1.2 compiler-semantics ID to 06639c99a4cb1dbcb7fc9c0c87544ee05c599079d85272d8af66c8045900680b, which RP-10 reports when the constant is stale, and the register to 495 rows. Co-Authored-By: Claude Opus 5 --- AGENTS.md | 2 +- README.md | 2 +- SPEC.md | 6 +- VERIFICATION.md | 48 ++++++--- crates/conformance/src/cases/repository.rs | 113 +++++++++++++++++---- crates/lexlean/src/lib.rs | 2 +- xtask/src/spec_links.rs | 4 +- 7 files changed, 135 insertions(+), 42 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index fe0430a0f7..5305f37a49 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -29,7 +29,7 @@ rules, from SPEC.md §27.2; nothing else in the repository defines an | R1 | `model/*.toml` is the single source of every repository conformance claim and public diagnostic code; generated claim/error documentation must match. | `cargo xtask validate-model` | | R2 | Honesty levels are load-bearing: `some-true`, `build`, and `open` are never blurred. | the honesty meta-gate (`just bdd`) and the vocabulary checks in `validate-model` | | R3 | A capability begins with a register row, then one scenario, then one failing named test, then implementation. | `just bdd` | -| R4 | Nothing is deferred: no deferral marker, stub, placeholder component, empty branch, or feature switch that disables a normative capability. | `audit-deferral`, inside `validate-model` | +| R4 | Nothing is deferred: no deferral marker, stub, placeholder component, empty branch, or unsanctioned feature switch that disables a normative capability; §8.4 names the one sanctioned feature and what a build without it must do. | `audit-deferral`, inside `validate-model` | | R5 | Every public failure is registered and emitted through the closed error model; user input never panics. | `audit-errors`, inside `validate-model`, and the negative fixture suite | | R6 | Shipped dependency boundaries, versions, licenses, and sources are explicit and audited. | `just deny` and `audit-shipped` | | R7 | Every accepted LexLean source and canonical output satisfies complete lexical and symbolic closure. | the `lexical-closure` and `latex-pdf` conformance suites | diff --git a/README.md b/README.md index 9144bd6874..18d01acd13 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ just vv # the complete normative acceptance gate (SPEC.md §9.2) just release # vv, then the §30 release criterion; refused until 1.0.0 ``` -All 494 registered conformance IDs have their named tests; `just vv` checks them with the pinned toolchain installed. +All 495 registered conformance IDs have their named tests; `just vv` checks them with the pinned toolchain installed. The differential against the independent generator `lean4-prod` (SPEC.md §17.19, `OR-01`..`OR-08`) acquires it at its pinned commit: from the checkout `LEXLEAN_ORACLE_DIR` names, or by fetching the commit with `git` into the Cargo target directory (`LEXLEAN_ORACLE_CACHE` overrides), and builds it with the pinned Lean and Rust toolchains. It is validation evidence only and no input to any identity. An oracle that cannot be acquired, is not the pinned files, or fails is unavailable: that fails the gate on Linux x86-64 and is printed as `NOT VALIDATED` elsewhere, and is never reported as agreement. diff --git a/SPEC.md b/SPEC.md index 6006a44c86..5a7251cc52 100644 --- a/SPEC.md +++ b/SPEC.md @@ -577,7 +577,7 @@ Non-UTF-8 project paths are outside language 1.0 and produce a registered enviro - Unknown registries and unknown Git sources are denied. - `repo-model`, `repo-conformance`, and `xtask` are `publish = false`. - No shipped crate may depend on a `publish = false` repository crate. -- Cargo features MUST NOT disable a normative capability, with one exception. The `lexlean` crate's `production-data` feature, on by default, embeds `language/preservation-1.2/library/`, the native preservation library that only certificate generation reads (§17.17). A build without it is a checker: it embeds every other file of §21.2, reports the language-1.2 compiler-semantics ID from the constant `LANGUAGE_1_2_SEMANTICS_ID` that `RP-10` holds to the full tree, behaves as a default build for every command that generates no certificate, refuses `production build` and the `verify` of a project with a production root with `LLC0205` before any build, verification, or export is published, and adds the line `variant check-only` to its version report (§30.3) (`RP-19`). It shares the compiler-semantics IDs of a full build, not its executable identity: it does not replace a full binary for any certifying or producing use. Released binaries and the normative gate use the default features. LexLean defines no other optional capability feature. +- Cargo features MUST NOT disable a normative capability, with one exception, which R4 (§27.2) sanctions by this section. The `lexlean` crate's `production-data` feature, on by default, embeds `language/preservation-1.2/library/`, the native preservation library that only certificate generation reads (§17.17). A build without it is a checker: it embeds every other file of §21.2, reports the language-1.2 compiler-semantics ID from the constant `LANGUAGE_1_2_SEMANTICS_ID` that `RP-10` holds to the full tree, behaves as a default build for every command that generates no certificate, refuses `production build` and the `verify` of a project with a production root with `LLC0205` before any build, verification, or export is published, and adds the line `variant check-only` to its version report (§30.3) (`RP-19`). It shares the compiler-semantics IDs of a full build, not its executable identity: it does not replace a full binary for any certifying or producing use. Released binaries and the normative gate use the default features. LexLean defines no other optional capability feature. - Dependency additions require a license decision and an update to `deny.toml` only when the actual graph requires it. ### 8.5 Required implementation dependencies @@ -10957,7 +10957,7 @@ A user's mathematical declarations never become repository conformance IDs merel | R1 | `model/*.toml` is the single source of every repository conformance claim and public diagnostic code; generated claim/error documentation must match. | | R2 | Honesty levels are load-bearing: `some-true`, `build`, and `open` are never blurred. | | R3 | A capability begins with a register row, then one scenario, then one failing named test, then implementation. | -| R4 | Nothing is deferred: no deferral marker, stub, placeholder component, empty branch, or feature switch that disables a normative capability. | +| R4 | Nothing is deferred: no deferral marker, stub, placeholder component, empty branch, or unsanctioned feature switch that disables a normative capability; §8.4 names the one sanctioned feature and what a build without it must do. | | R5 | Every public failure is registered and emitted through the closed error model; user input never panics. | | R6 | Shipped dependency boundaries, versions, licenses, and sources are explicit and audited. | | R7 | Every accepted LexLean source and canonical output satisfies complete lexical and symbolic closure. | @@ -12114,7 +12114,7 @@ Every row below is normative, has honesty level `build`, and MUST be copied byte | `LM-09` | `language-models` | No prompt is code: no member of the closed language maps `string` or `bytes` to a function, a term, or source — every operation of the primitive registry that takes a `string` or `bytes` operand is classified by the audit with a data result, the registry's schema enumeration and the production registry's primitive rows equal one another and equal that classified set, and the text declarations of `lexlean/semantic-module/2` state no `string`-typed member, so a prompt reaches a model only as the tokens `encodeText` makes of it; a planted operation or text member of that shape is caught by the audit with its name. | §17.12 | | `LM-13` | `language-models` | The text laws a tokenizer elaborates through are LexLean source and not authored text: the module that states them is one language-1.2 native core module of the embedded `language/text-1.2` project, the project holds no file of Lean source, no independently authored Lean file anywhere in the release tree declares the `LexLeanText` namespace or lies under its module root, and the one-time migration input is absent; the registry lists only that module, the declarations and their exact axiom policies are read from its native data, which the compiler embeds and hashes into the language-1.2 semantics, and a module that declares a text component imports the generated module rather than splicing any Lean text. | §17.10, §17.12 | -**Total required capability IDs:** 494. +**Total required capability IDs:** 495. No row may be downgraded to `some-true` or `open`. Upstream Lean facts are ledger/authority rows, not substitutions for these build behaviors. diff --git a/VERIFICATION.md b/VERIFICATION.md index 68adfbd942..875e94b7b8 100644 --- a/VERIFICATION.md +++ b/VERIFICATION.md @@ -14453,30 +14453,48 @@ PR, with existing generated records untouched; its source changes are not qualified by those preceding records. Coordinate the single identity/writer wave with the release owner before readiness, merge or downstream SDK adoption. -### the check-only build's language-1.2 constant can fail (RP-10, RP-19) +### the check-only build's excluded inventory and its constant can fail (RP-19, RP-10) -A build without `production-data` (§8.4) reports `LANGUAGE_1_2_SEMANTICS_ID` in -place of the language-1.2 ID it cannot compute. A wrong constant would not change -a verdict: such a build locks and checks consistently with itself. So the -constant is held twice: `RP-10` against the ID recomputed from disk, and `RP-19` -against the lock bytes of the default build. +A build without `production-data` (§8.4) embeds no file of +`language/preservation-1.2/library/` and reports the language-1.2 +compiler-semantics ID from `LANGUAGE_1_2_SEMANTICS_ID`. Neither holds by +construction once a binary exists, so `RP-19` reads the built image against the +complete excluded inventory and `RP-10` reads the constant against the tree. -Planted: the last digit of the constant, `…151a` to `…151b`, in -`crates/lexlean/src/lib.rs`. Command: -`cargo test -p repo-conformance --all-features --test conformance -- conformance_rp_10 conformance_rp_19 --exact --test-threads=1`. +Planted, the inventory: `build.rs` keeps out every file of the library except +`src/Values.lex.tex` (70,609 bytes), while the largest, `src/RustLemmas.lex.tex` +(17,189,578 bytes), stays out --- so an assertion that read the largest file +alone would have passed. Command: `cargo test -p repo-conformance +--all-features --test conformance -- conformance_rp_19 --exact`. Observed: + +```text +test conformance_rp_19 ... FAILED +RP-19: the build without production-data embeds ["language/preservation-1.2/library/src/Values.lex.tex"] of `language/preservation-1.2/library/` +test result: FAILED. 0 passed; 1 failed +``` + +Read directly, that planted binary (77,585,088 bytes, the debug build the case +makes) holds the witness of `src/Values.lex.tex` and not the witness of +`src/RustLemmas.lex.tex`. + +Planted, the constant: its last digit, `...680b` to `...680c`, in +`crates/lexlean/src/lib.rs`. A wrong constant changes no verdict, because such +a build locks and checks consistently with itself, so it is held twice --- +against the tree by `RP-10`, and against the default build's lock bytes by +`RP-19`. Command: `cargo test -p repo-conformance --all-features --test +conformance -- conformance_rp_10 conformance_rp_19 --exact --test-threads=1`. Observed: ```text test conformance_rp_10 ... FAILED test conformance_rp_19 ... FAILED -RP-10: lexlean::LANGUAGE_1_2_SEMANTICS_ID is stale; the tree's language-1.2 ID is 635a25acb886587f8777525e778092e9599d1f2df26da59403ee39e9e299151a - left: "635a25acb886587f8777525e778092e9599d1f2df26da59403ee39e9e299151b" - right: "635a25acb886587f8777525e778092e9599d1f2df26da59403ee39e9e299151a" +RP-10: lexlean::LANGUAGE_1_2_SEMANTICS_ID is stale; the tree's language-1.2 ID is 06639c99a4cb1dbcb7fc9c0c87544ee05c599079d85272d8af66c8045900680b + left: "06639c99a4cb1dbcb7fc9c0c87544ee05c599079d85272d8af66c8045900680c" + right: "06639c99a4cb1dbcb7fc9c0c87544ee05c599079d85272d8af66c8045900680b" RP-19: language-1.2: lexlean.lock bytes test result: FAILED. 0 passed; 2 failed ``` `RP-19` failed at the first language-1.2 lock, whose `compiler_semantics` line -carried the planted digit while the default build's carried the tree's. -Restored, `conformance_rp_10` passes; `conformance_rp_19` passed on the same -tree before the plant. +carried the planted digit while the default build's carried the tree's. With +each plant removed, `conformance_rp_10` and `conformance_rp_19` pass. diff --git a/crates/conformance/src/cases/repository.rs b/crates/conformance/src/cases/repository.rs index 153da0e1c5..674678d759 100644 --- a/crates/conformance/src/cases/repository.rs +++ b/crates/conformance/src/cases/repository.rs @@ -898,7 +898,7 @@ pub(crate) fn run(id: &str) { let model = repo_model::Model::load(&root.join("model").into_std_path_buf()) .expect("the model loads"); let table = spec_table(); - assert_eq!(table.len(), 494, "§31 has 494 rows"); + assert_eq!(table.len(), 495, "§31 has 495 rows"); assert_eq!(model.ids.id.len(), table.len(), "register row count"); for ((spec_id, spec_suite, spec_statement), row) in table.iter().zip(model.ids.id.iter()) @@ -2439,6 +2439,47 @@ pub(crate) fn run(id: &str) { /// build this harness links. The language-1.2 ID it reports is a constant, /// which RP-10 holds to the tree; here it must also land in the lock bytes, /// which is what a wrong constant would change while every verdict agreed. +/// A file of the normative tree: its repository-relative path and its bytes, +/// as `support::normative_rows` reads them. +type NormativeRow = (String, Vec); + +/// How many bytes of a file witness that an image holds it: the whole file +/// when it is short, else a window from its middle, past the header that +/// every file of a kind repeats (RP-19). +const WITNESS_BYTES: usize = 64; + +/// The witness of one file: its own bytes, or a window of them. +fn witness_of(bytes: &[u8]) -> Vec { + if bytes.len() <= WITNESS_BYTES { + bytes.to_vec() + } else { + bytes[bytes.len() / 2 - WITNESS_BYTES / 2..][..WITNESS_BYTES].to_vec() + } +} + +/// Which of `witnesses`, each a path and the bytes that witness it, occur in +/// `image`, in one pass over it: a table of first bytes names the candidates +/// at each position and only a candidate is compared, so the cost is the +/// image's length and not its length times the inventory's size. RP-19 reads +/// a binary of twenty-three megabytes against an inventory of thirty-one. +fn witnessed(image: &[u8], witnesses: &[NormativeRow]) -> BTreeSet { + let mut by_first: Vec> = vec![Vec::new(); 256]; + for (index, (path, bytes)) in witnesses.iter().enumerate() { + assert!(!bytes.is_empty(), "{path}: a witness is not empty"); + by_first[bytes[0] as usize].push(index); + } + let mut found = BTreeSet::new(); + for (at, byte) in image.iter().enumerate() { + for index in &by_first[*byte as usize] { + let (path, witness) = &witnesses[*index]; + if !found.contains(path) && image[at..].starts_with(witness) { + found.insert(path.clone()); + } + } + } + found +} + fn rp_19() { use lexlean::api::production::{ self, Expectation, PackageName, ProductionRequest, RootRequest, TargetRef, REQUEST_SPEC, @@ -2447,34 +2488,68 @@ fn rp_19() { let binary = support::check_only_binary(&root).expect("the crate builds without its default features"); - // The library is left out and the rest of the tree is not: the binary - // holds no library source and does hold the library's module list, which - // is outside `library/`. + // The whole excluded inventory is bound to the built variant, not its + // largest file alone: a build that left the largest out and embedded any + // other would pass that and still break what RP-19 states. Every file of + // the inventory is witnessed by bytes of its own, and the image is read + // once for all of them. let image = std::fs::read(binary.as_std_path()).expect("the binary is readable"); - let holds = |needle: &[u8]| image.windows(needle.len()).any(|window| window == needle); let rows = support::normative_rows(); - let library: Vec<&(String, Vec)> = rows + let (library, retained_rows): (Vec<&NormativeRow>, Vec<&NormativeRow>) = rows .iter() - .filter(|(path, _)| path.starts_with("language/preservation-1.2/library/")) - .collect(); + .partition(|(path, _)| path.starts_with("language/preservation-1.2/library/")); assert!( library.len() > 10, - "RP-19: the library has its sources on disk" + "RP-19: the excluded inventory is the library's files on disk" ); - let largest = library + let witnesses: Vec = library .iter() - .max_by_key(|(_, bytes)| bytes.len()) - .expect("a library file"); + .map(|(path, bytes)| (path.clone(), witness_of(bytes))) + .collect(); + // A file whose witness the retained data carries anyway cannot be told + // from that data in an image. Such a file is named here with its reason + // rather than passing in silence, and the reason is checked: its own + // bytes are embedded outside the library, so an image holding them holds + // no library source. + let retained: Vec = retained_rows + .iter() + .flat_map(|(_, bytes)| bytes.iter().copied().chain(std::iter::once(0))) + .collect(); + let indistinguishable = witnessed(&retained, &witnesses); + for path in &indistinguishable { + let (_, bytes) = library + .iter() + .find(|(candidate, _)| candidate == path) + .expect("a file of the inventory"); + let whole = vec![(path.clone(), bytes.clone())]; + assert!( + !witnessed(&retained, &whole).is_empty(), + "RP-19: `{path}` cannot be told from the retained data in an image, and its own bytes are not part of that data; the inventory is not bound" + ); + } + let found = witnessed(&image, &witnesses); + let embedded: Vec<&String> = found.difference(&indistinguishable).collect(); assert!( - !holds(&largest.1), - "RP-19: the build without production-data embeds `{}`", - largest.0 + embedded.is_empty(), + "RP-19: the build without production-data embeds {embedded:?} of `language/preservation-1.2/library/`" ); - let kept = rows + // The scan finds what is there: the preservation data outside `library/`, + // which this build does embed, is found in the same image by the same + // method, so an absence above is an absence and not a broken search. + let siblings: Vec = retained_rows .iter() - .find(|(path, _)| path == "language/preservation-1.2/library.toml") - .expect("the library's module list"); - assert!(holds(&kept.1), "RP-19: `{}` is embedded", kept.0); + .filter(|(path, _)| path.starts_with("language/preservation-1.2/")) + .map(|(path, bytes)| (path.clone(), witness_of(bytes))) + .collect(); + assert!( + siblings.len() > 1, + "RP-19: the retained preservation data is more than one file" + ); + assert_eq!( + witnessed(&image, &siblings).len(), + siblings.len(), + "RP-19: the embedded preservation data outside `library/` is in the image" + ); let normalized = |text: &str, project: &camino::Utf8Path| text.replace(project.as_str(), ""); diff --git a/crates/lexlean/src/lib.rs b/crates/lexlean/src/lib.rs index 92f5c8325f..0ff46f51e4 100644 --- a/crates/lexlean/src/lib.rs +++ b/crates/lexlean/src/lib.rs @@ -286,7 +286,7 @@ fn embedded_digest(keep: impl Fn(&str) -> bool) -> Sha256Digest { /// consistently with itself, so agreement on verdicts could not reveal it. /// The 1.0 and 1.1 IDs need no constant: no file they cover is left out. pub const LANGUAGE_1_2_SEMANTICS_ID: &str = - "635a25acb886587f8777525e778092e9599d1f2df26da59403ee39e9e299151a"; + "06639c99a4cb1dbcb7fc9c0c87544ee05c599079d85272d8af66c8045900680b"; /// The compiler-semantics ID for one selected language. Language 1.0 excludes /// all files introduced solely for 1.1 and 1.2, and Language 1.1 excludes diff --git a/xtask/src/spec_links.rs b/xtask/src/spec_links.rs index bc36890817..4b5b4ed499 100644 --- a/xtask/src/spec_links.rs +++ b/xtask/src/spec_links.rs @@ -61,8 +61,8 @@ fn parse_table(spec: &str) -> Result, Fail> { pub fn validate(root: &Path) -> Result<(), Fail> { let spec = std::fs::read_to_string(root.join("SPEC.md"))?; let rows = parse_table(&spec)?; - if rows.len() != 494 { - return Err(format!("RP-07: the §31 table has {} rows, not 494", rows.len()).into()); + if rows.len() != 495 { + return Err(format!("RP-07: the §31 table has {} rows, not 495", rows.len()).into()); } // The prose total under the table is part of the contract a reader // relies on; a row added without it would leave §31 contradicting itself.