From f08ff726f109fbc4dfcd5e67d1cd576b38bdb39c Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Mon, 16 Nov 2026 05:06:44 +0000 Subject: [PATCH] perf: keep the build identity out of sqlbuild-rules so edits stop rebuilding it The source hash that keys local caches was a compile-time constant in sqlbuild-rules, whose build script hashes every workspace crate. Any source edit therefore rebuilt sqlbuild-rules and every crate above it, and the constant changed the same codegen units of the extension on every build. The hash now lives in a leaf crate, sqlbuild-build-identity, behind one non-inlined accessor. sqb and the extension install it into sqlbuild-rules at startup through sqlbuild-cli; reading it before then fails instead of falling back. Cache keys and BUILD_IDENTITY keep the same value. --- Cargo.lock | 8 ++ Cargo.toml | 3 + crates/README.md | 4 +- crates/sqlbuild-build-identity/Cargo.toml | 18 ++++ .../build.rs | 0 .../src/identity/main/mod.rs | 3 + .../identity/main/native_build_identity.rs | 8 ++ .../src/identity/mod.rs | 6 ++ .../src/identity/tests.rs | 4 + .../src/identity/tests/test_identity.rs | 46 +++++++++ .../src/identity/tests/test_types.rs | 10 ++ crates/sqlbuild-build-identity/src/lib.rs | 5 + crates/sqlbuild-cli/Cargo.toml | 1 + .../main/install_native_build_identity.rs | 12 +++ crates/sqlbuild-cli/src/launcher/main/mod.rs | 1 + .../src/launcher/main/run_launcher.rs | 6 ++ .../src/native_commands/tests/test_rules.rs | 2 + .../_helpers/change_selection/base_cache.rs | 4 +- .../exported_constants/registration.rs | 6 +- .../src/bindings/_helpers/rules/guidance.rs | 4 +- .../src/bindings/main/register.rs | 3 +- .../src/bindings/tests/test_since_cache.rs | 3 + crates/sqlbuild-rules/Cargo.toml | 3 - .../src/build_identity/_helpers/installed.rs | 6 ++ .../src/build_identity/_helpers/mod.rs | 3 + .../src/build_identity/constants.rs | 4 + .../src/build_identity/errors.rs | 26 +++++ .../build_identity/main/build_field_digest.rs | 17 ++++ .../main/install_build_identity.rs | 19 ++++ .../src/build_identity/main/mod.rs | 5 + .../main/native_build_identity.rs | 13 +++ .../sqlbuild-rules/src/build_identity/mod.rs | 9 ++ .../src/build_identity/tests.rs | 6 ++ .../src/build_identity/tests/helpers.rs | 16 ++++ .../tests/test_build_identity.rs | 96 +++++++++++++++++++ .../src/build_identity/tests/test_types.rs | 19 ++++ crates/sqlbuild-rules/src/constants.rs | 2 - .../src/custom_rule_cache/_helpers/digest.rs | 12 +-- .../tests/test_custom_rule_cache.rs | 3 + .../src/engine/_helpers/evaluation.rs | 6 +- .../src/engine/tests/test_domain_layout.rs | 2 + .../engine/tests/test_empty_input_tests.rs | 5 + .../src/engine/tests/test_evaluation.rs | 65 ++++--------- .../engine/tests/test_incremental_rules.rs | 9 ++ .../src/engine/tests/test_published_layers.rs | 2 + .../src/engine/tests/test_query_facts.rs | 2 + .../src/engine/tests/test_retained_rows.rs | 2 + .../src/engine/tests/test_speculative_rows.rs | 3 + .../src/engine/tests/test_sql_test_rules.rs | 3 + .../src/engine/tests/test_types.rs | 11 --- crates/sqlbuild-rules/src/lib.rs | 4 + .../tests/test_named_selector_limit.rs | 2 + .../src/python_rules/main/python_catalogue.rs | 4 +- .../tests/test_compile_purity_rules.rs | 3 + .../tests/test_evaluate_python_rules.rs | 3 + .../src/python_rules/tests/test_node_units.rs | 3 + .../tests/test_orchestration_rules.rs | 2 + .../python_rules/tests/test_provider_rules.rs | 2 + .../python_rules/tests/test_python_cache.rs | 2 + .../tests/test_python_catalogue.rs | 4 + .../python_rules/tests/test_python_scaling.rs | 5 + .../tests/test_python_test_rules.rs | 2 + .../src/rule_cache/_helpers/digest.rs | 12 +-- .../src/rule_cache/main/parse_rule_cache.rs | 4 +- .../src/rule_cache/main/rule_cache_text.rs | 4 +- .../src/rule_cache/tests/test_rule_cache.rs | 2 + .../main/ruleset_fingerprint.rs | 4 +- .../src/rules/_helpers/catalogue.rs | 11 ++- .../src/rules/_helpers/sql_test_rules.rs | 7 +- crates/sqlbuild-rules/src/tests.rs | 2 + crates/sqlbuild-rules/src/tests/helpers.rs | 9 ++ fensu.toml | 13 ++- 72 files changed, 520 insertions(+), 110 deletions(-) create mode 100644 crates/sqlbuild-build-identity/Cargo.toml rename crates/{sqlbuild-rules => sqlbuild-build-identity}/build.rs (100%) create mode 100644 crates/sqlbuild-build-identity/src/identity/main/mod.rs create mode 100644 crates/sqlbuild-build-identity/src/identity/main/native_build_identity.rs create mode 100644 crates/sqlbuild-build-identity/src/identity/mod.rs create mode 100644 crates/sqlbuild-build-identity/src/identity/tests.rs create mode 100644 crates/sqlbuild-build-identity/src/identity/tests/test_identity.rs create mode 100644 crates/sqlbuild-build-identity/src/identity/tests/test_types.rs create mode 100644 crates/sqlbuild-build-identity/src/lib.rs create mode 100644 crates/sqlbuild-cli/src/launcher/main/install_native_build_identity.rs create mode 100644 crates/sqlbuild-rules/src/build_identity/_helpers/installed.rs create mode 100644 crates/sqlbuild-rules/src/build_identity/_helpers/mod.rs create mode 100644 crates/sqlbuild-rules/src/build_identity/constants.rs create mode 100644 crates/sqlbuild-rules/src/build_identity/errors.rs create mode 100644 crates/sqlbuild-rules/src/build_identity/main/build_field_digest.rs create mode 100644 crates/sqlbuild-rules/src/build_identity/main/install_build_identity.rs create mode 100644 crates/sqlbuild-rules/src/build_identity/main/mod.rs create mode 100644 crates/sqlbuild-rules/src/build_identity/main/native_build_identity.rs create mode 100644 crates/sqlbuild-rules/src/build_identity/mod.rs create mode 100644 crates/sqlbuild-rules/src/build_identity/tests.rs create mode 100644 crates/sqlbuild-rules/src/build_identity/tests/helpers.rs create mode 100644 crates/sqlbuild-rules/src/build_identity/tests/test_build_identity.rs create mode 100644 crates/sqlbuild-rules/src/build_identity/tests/test_types.rs create mode 100644 crates/sqlbuild-rules/src/tests.rs create mode 100644 crates/sqlbuild-rules/src/tests/helpers.rs diff --git a/Cargo.lock b/Cargo.lock index 1f71eb3035..5f326f5e2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4247,6 +4247,13 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "sqlbuild-build-identity" +version = "0.0.0" +dependencies = [ + "sha2 0.10.9", +] + [[package]] name = "sqlbuild-cache" version = "0.0.0" @@ -4278,6 +4285,7 @@ dependencies = [ "serde_json", "sqlbuild-analysis", "sqlbuild-build-features", + "sqlbuild-build-identity", "sqlbuild-cache", "sqlbuild-config", "sqlbuild-core", diff --git a/Cargo.toml b/Cargo.toml index bfc5666be3..dab96d2616 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ "crates/sqlbuild-build-features", + "crates/sqlbuild-build-identity", "crates/sqlbuild-core", "crates/sqlbuild-cursor", "crates/sqlbuild-process-ownership", @@ -33,6 +34,7 @@ resolver = "2" [workspace.metadata.native-layers] order = [ "sqlbuild-build-features", + "sqlbuild-build-identity", "sqlbuild-core", "sqlbuild-cursor", "sqlbuild-process-ownership", @@ -162,6 +164,7 @@ utoipa = { version = "5", features = ["chrono", "uuid"] } sqlbuild-analysis = { path = "crates/sqlbuild-analysis" } sqlbuild-attachments = { path = "crates/sqlbuild-attachments" } sqlbuild-build-features = { path = "crates/sqlbuild-build-features" } +sqlbuild-build-identity = { path = "crates/sqlbuild-build-identity" } sqlbuild-cache = { path = "crates/sqlbuild-cache" } sqlbuild-cli = { path = "crates/sqlbuild-cli" } sqlbuild-config = { path = "crates/sqlbuild-config" } diff --git a/crates/README.md b/crates/README.md index 5f69aad8d3..72b7ed43eb 100644 --- a/crates/README.md +++ b/crates/README.md @@ -8,6 +8,7 @@ tested and benchmarked with `cargo test` alone. | Crate | Responsibility | |---|---| | `sqlbuild-build-features` | No code. Enables, in the `sqb` build, the dependency features the extension build resolves, so Cargo compiles the crates both builds share (polyglot-sql, `sqlbuild-analysis`, `sqlbuild-rules` and the rest) once. `make check-build-features` (part of `make check-ci`) fails when the two builds resolve a shared crate differently and names the features to add. | +| `sqlbuild-build-identity` | The content identity of the native build: a hash of every workspace crate's sources, manifest and lockfile, behind one accessor. It rebuilds after any source edit, so only the top-level crates (`sqlbuild-python` and `sqlbuild-cli`) depend on it; they install the identity into `sqlbuild-rules` at startup, so the crates in between keep their incremental builds. | | `sqlbuild-core` | Constants shared by several crates, the panic boundary that turns an unwinding native failure into a named compiler error, passive identity, diagnostic and SQL value types, text positions, a JSON emitter whose output matches Python's `json.dumps` and `orjson` byte for byte, and run-cost allocation with exact Python `decimal` default-context arithmetic and Snowflake query-history SQL. | | `sqlbuild-cursor` | Microbatch cursor algebra: typed cursor values, grain flooring and stepping, half-open interval clamping, merging and batch splitting, timestamp text normalization and calendar durations, with Python `datetime` results and errors. Zones other than fixed offsets are resolved through a caller-supplied lookup. | | `sqlbuild-process-ownership` | Proof that a live process owns a scheduler worker claim, and the only way to stop one: an inherited claim lock on Linux and macOS, checked through `/proc` and a pidfd or through libproc with a start-time recheck, and a private named Job object on Windows. It is the only crate allowed unsafe code, for those platform calls. | @@ -23,7 +24,7 @@ tested and benchmarked with `cargo test` alone. | `sqlbuild-render` | Macro call scanning, argument evaluation, expansion, splicing, memoisation and persistent call-store keys. Python executes user macro bodies at the extension boundary. | | `sqlbuild-attachments` | Native attachment of tests, audits, sources, functions, scenarios and seeds, including argument merging, validation and audit policy resolution. Adapter value rendering remains an extension boundary. | | `sqlbuild-analysis` | SQL analysis over polyglot: query analysis, binding, semantic validation and usage, column references, type normalization, FAST/RICH lineage, SQL-test/scenario extraction and compiler-side assembly, and Snowflake cost statement classification and query-tag parsing. | -| `sqlbuild-rules` | Built-in rules and the rules engine, the custom-rule host, SQL lint, quality checks and formatting, rules configuration and the request models. It also owns the build identity script. | +| `sqlbuild-rules` | Built-in rules and the rules engine, the custom-rule host, SQL lint, quality checks and formatting, rules configuration and the request models. Its caches and rule fingerprints key on the build identity the binary installs at startup. | | `sqlbuild-refactor` | Native rename/move plans, contract-adoption edits, MODEL/SCHEMA/YAML text edits and atomic staging/commit with rollback. Shared scope placement delegates to the native scope implementation; user Python source inspection remains at the Python AST boundary. | | `sqlbuild-project` | The compiled project as plain Rust: `CompiledProject` with the producers' facts and each resource's records (model inputs and schemas, compiled models and their analysis, sources, functions, audits and seeds), and what those records answer without Python, such as lineage rows, resolved namespaces and dependency keys. Values the host owns, such as user config and discovered files, and the views it builds lazily live in one slot per record, whose types `sqlbuild-python` supplies through the `ProjectHost` trait; reads that need Python stay in the bindings as extension traits. | | `sqlbuild-cli` | The `sqb` and `sqlbuild` executables: `--version`, unchanged compiles replayed from the shared reuse store with Python's exact streams, exit code and compute log capture, and a handoff of every other invocation to the installed `sqlbuild-python` script. Built as its own wheel (`crates/sqlbuild-cli/pyproject.toml`). | @@ -40,6 +41,7 @@ sqlbuild-python -> sqlbuild-python-base -> sqlbuild-model-config -> sqlbuild-scopes -> sqlbuild-render -> sqlbuild-discovery -> sqlbuild-host -> sqlbuild-config -> sqlbuild-sqltext -> sqlbuild-cache -> sqlbuild-pysource -> sqlbuild-state -> sqlbuild-cursor -> sqlbuild-core sqlbuild-cli -> sqlbuild-cache, sqlbuild-core, sqlbuild-build-features, sqlbuild-process-ownership +sqlbuild-python, sqlbuild-cli -> sqlbuild-build-identity ``` `sqlbuild-scopes` reuses the macro scanner in `sqlbuild-render`; render itself depends only on diff --git a/crates/sqlbuild-build-identity/Cargo.toml b/crates/sqlbuild-build-identity/Cargo.toml new file mode 100644 index 0000000000..b2420918a7 --- /dev/null +++ b/crates/sqlbuild-build-identity/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "sqlbuild-build-identity" +version.workspace = true +description = "The content identity of this native build, which local caches key on so they notice source changes." +edition.workspace = true +license.workspace = true +publish.workspace = true +rust-version.workspace = true + +# The build script hashes the sources of every workspace crate, so this crate rebuilds after any +# source edit, and so does every crate that depends on it. Only the top-level crates that are +# rebuilt anyway (sqlbuild-python and sqlbuild-cli) depend on it; they install the identity into +# sqlbuild-rules at startup. +[build-dependencies] +sha2.workspace = true + +[lints] +workspace = true diff --git a/crates/sqlbuild-rules/build.rs b/crates/sqlbuild-build-identity/build.rs similarity index 100% rename from crates/sqlbuild-rules/build.rs rename to crates/sqlbuild-build-identity/build.rs diff --git a/crates/sqlbuild-build-identity/src/identity/main/mod.rs b/crates/sqlbuild-build-identity/src/identity/main/mod.rs new file mode 100644 index 0000000000..ab6672f6dd --- /dev/null +++ b/crates/sqlbuild-build-identity/src/identity/main/mod.rs @@ -0,0 +1,3 @@ +//! The build identity accessor. + +pub mod native_build_identity; diff --git a/crates/sqlbuild-build-identity/src/identity/main/native_build_identity.rs b/crates/sqlbuild-build-identity/src/identity/main/native_build_identity.rs new file mode 100644 index 0000000000..9b7312f979 --- /dev/null +++ b/crates/sqlbuild-build-identity/src/identity/main/native_build_identity.rs @@ -0,0 +1,8 @@ +//! A content hash of every native crate, including the release version in their manifests. + +/// The source content hash, never inlined so callers do not change, and lose incremental reuse, after every edit. +#[inline(never)] +#[must_use] +pub fn native_build_identity() -> &'static str { + env!("SQLBUILD_NATIVE_SOURCE_HASH") +} diff --git a/crates/sqlbuild-build-identity/src/identity/mod.rs b/crates/sqlbuild-build-identity/src/identity/mod.rs new file mode 100644 index 0000000000..7ef226518f --- /dev/null +++ b/crates/sqlbuild-build-identity/src/identity/mod.rs @@ -0,0 +1,6 @@ +//! The source content hash the build script derives, behind one accessor. + +pub mod main; + +#[cfg(test)] +mod tests; diff --git a/crates/sqlbuild-build-identity/src/identity/tests.rs b/crates/sqlbuild-build-identity/src/identity/tests.rs new file mode 100644 index 0000000000..27b44fa8de --- /dev/null +++ b/crates/sqlbuild-build-identity/src/identity/tests.rs @@ -0,0 +1,4 @@ +#[path = "tests/test_identity.rs"] +mod identity; +#[path = "tests/test_types.rs"] +mod test_types; diff --git a/crates/sqlbuild-build-identity/src/identity/tests/test_identity.rs b/crates/sqlbuild-build-identity/src/identity/tests/test_identity.rs new file mode 100644 index 0000000000..beb3e0e456 --- /dev/null +++ b/crates/sqlbuild-build-identity/src/identity/tests/test_identity.rs @@ -0,0 +1,46 @@ +use crate::identity::main::native_build_identity::native_build_identity; +use crate::identity::tests::test_types; + +#[test] +fn given_native_build_when_reading_cache_identity_then_it_is_a_source_hash() { + let test_cases = [test_types::BuildIdentityTestCase { + description: "cache identity is a source content hash", + expected_hash_length: 16, + }]; + for test_case in &test_cases { + let hash = native_build_identity(); + + assert!( + hash.len() == test_case.expected_hash_length + && hash.bytes().all(|byte| byte.is_ascii_hexdigit()), + "{}", + test_case.description + ); + } +} + +#[test] +fn given_workspace_checkout_when_deriving_build_identity_then_workspace_files_are_hashed() { + let test_cases = [ + test_types::HashedWorkspaceFileTestCase { + description: "dependency features and build profiles change the identity", + workspace_file: "../../Cargo.toml", + expected_hashed: true, + }, + test_types::HashedWorkspaceFileTestCase { + description: "resolved dependency versions change the identity", + workspace_file: "../../Cargo.lock", + expected_hashed: true, + }, + ]; + for test_case in &test_cases { + let hashed = env!("SQLBUILD_NATIVE_HASHED_WORKSPACE_FILES") + .split(',') + .any(|file| file == test_case.workspace_file); + assert_eq!( + hashed, test_case.expected_hashed, + "{}", + test_case.description + ); + } +} diff --git a/crates/sqlbuild-build-identity/src/identity/tests/test_types.rs b/crates/sqlbuild-build-identity/src/identity/tests/test_types.rs new file mode 100644 index 0000000000..c484548d27 --- /dev/null +++ b/crates/sqlbuild-build-identity/src/identity/tests/test_types.rs @@ -0,0 +1,10 @@ +pub(crate) struct BuildIdentityTestCase { + pub(crate) description: &'static str, + pub(crate) expected_hash_length: usize, +} + +pub(crate) struct HashedWorkspaceFileTestCase { + pub(crate) description: &'static str, + pub(crate) workspace_file: &'static str, + pub(crate) expected_hashed: bool, +} diff --git a/crates/sqlbuild-build-identity/src/lib.rs b/crates/sqlbuild-build-identity/src/lib.rs new file mode 100644 index 0000000000..39626d10cc --- /dev/null +++ b/crates/sqlbuild-build-identity/src/lib.rs @@ -0,0 +1,5 @@ +//! The content identity of this native build, which local caches key on so they notice source changes. + +#![forbid(unsafe_code)] + +pub mod identity; diff --git a/crates/sqlbuild-cli/Cargo.toml b/crates/sqlbuild-cli/Cargo.toml index a77e38b24f..2f34f170ac 100644 --- a/crates/sqlbuild-cli/Cargo.toml +++ b/crates/sqlbuild-cli/Cargo.toml @@ -29,6 +29,7 @@ serde.workspace = true serde_json = { workspace = true, features = ["arbitrary_precision"] } sqlbuild-analysis.workspace = true sqlbuild-build-features.workspace = true +sqlbuild-build-identity.workspace = true sqlbuild-cache.workspace = true sqlbuild-config.workspace = true sqlbuild-core.workspace = true diff --git a/crates/sqlbuild-cli/src/launcher/main/install_native_build_identity.rs b/crates/sqlbuild-cli/src/launcher/main/install_native_build_identity.rs new file mode 100644 index 0000000000..ffbbca3e96 --- /dev/null +++ b/crates/sqlbuild-cli/src/launcher/main/install_native_build_identity.rs @@ -0,0 +1,12 @@ +//! Install this build's identity into the rules engine, first thing in every native entry point. + +use sqlbuild_build_identity::identity::main::native_build_identity::native_build_identity; +use sqlbuild_rules::build_identity::errors::BuildIdentityError; +use sqlbuild_rules::build_identity::main::install_build_identity::install_build_identity; + +/// Install this build's identity into the rules engine and return it, before anything reads a cache key. +pub fn install_native_build_identity() -> Result<&'static str, BuildIdentityError> { + let identity: &'static str = native_build_identity(); + install_build_identity(identity)?; + Ok(identity) +} diff --git a/crates/sqlbuild-cli/src/launcher/main/mod.rs b/crates/sqlbuild-cli/src/launcher/main/mod.rs index 092024d70e..01dda9223b 100644 --- a/crates/sqlbuild-cli/src/launcher/main/mod.rs +++ b/crates/sqlbuild-cli/src/launcher/main/mod.rs @@ -1 +1,2 @@ +pub mod install_native_build_identity; pub mod run_launcher; diff --git a/crates/sqlbuild-cli/src/launcher/main/run_launcher.rs b/crates/sqlbuild-cli/src/launcher/main/run_launcher.rs index 4db160c179..e7421f827d 100644 --- a/crates/sqlbuild-cli/src/launcher/main/run_launcher.rs +++ b/crates/sqlbuild-cli/src/launcher/main/run_launcher.rs @@ -1,14 +1,20 @@ //! The `sqb` executable's whole process. use std::ffi::OsString; +use std::io::Write; use std::process::ExitCode; use std::time::{Instant, SystemTime}; use crate::launcher::_helpers::dispatch::launch; use crate::launcher::_helpers::handoff::process_exit; +use crate::launcher::main::install_native_build_identity::install_native_build_identity; /// Run this process's invocation; an exit code beyond one byte ends the process directly. pub fn run_launcher() -> ExitCode { + if let Err(error) = install_native_build_identity() { + let _ = writeln!(std::io::stderr(), "sqb: {error}"); + return ExitCode::FAILURE; + } let started = (Instant::now(), SystemTime::now()); let arguments: Vec = std::env::args_os().skip(1).collect(); process_exit(launch(arguments, started)) diff --git a/crates/sqlbuild-cli/src/native_commands/tests/test_rules.rs b/crates/sqlbuild-cli/src/native_commands/tests/test_rules.rs index 4eedd7443e..f2005d0266 100644 --- a/crates/sqlbuild-cli/src/native_commands/tests/test_rules.rs +++ b/crates/sqlbuild-cli/src/native_commands/tests/test_rules.rs @@ -1,3 +1,4 @@ +use crate::launcher::main::install_native_build_identity::install_native_build_identity; use crate::native_commands::_helpers::rules::run_rules; use crate::native_commands::errors::PythonNeeded; use crate::native_commands::models::{RulesAction, RulesOptions}; @@ -9,6 +10,7 @@ const OPTIONS_PROJECT: &str = "name = \"shop\"\nadapter = \"duckdb\"\n\n[rules.r #[test] fn given_project_when_inspecting_rules_then_builtin_catalogue_prints_unless_python_owns_it() { + install_native_build_identity().expect("the build identity installs once"); let test_cases = [ RulesTestCase { description: "list prints code and message lines", diff --git a/crates/sqlbuild-python/src/bindings/_helpers/change_selection/base_cache.rs b/crates/sqlbuild-python/src/bindings/_helpers/change_selection/base_cache.rs index 2e88520c54..af9ef841bc 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/change_selection/base_cache.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/change_selection/base_cache.rs @@ -5,7 +5,7 @@ use std::path::{Path, PathBuf}; use std::time::{Duration, SystemTime, UNIX_EPOCH}; use sqlbuild_analysis::definition_changes::main::definition_digest::definition_digest; -use sqlbuild_rules::constants::NATIVE_BUILD_IDENTITY; +use sqlbuild_rules::build_identity::main::native_build_identity::native_build_identity; use crate::bindings::_helpers::change_selection::base_compile::NOTES_EXTENSION; use crate::bindings::_helpers::change_selection::fingerprints::{ @@ -82,7 +82,7 @@ pub(crate) fn cache_key_with( lookup: &dyn Fn(&str) -> Option, ) -> std::io::Result { Ok(definition_digest(&[ - NATIVE_BUILD_IDENTITY, + native_build_identity(), target.unwrap_or_default(), vars, local_config, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/exported_constants/registration.rs b/crates/sqlbuild-python/src/bindings/_helpers/exported_constants/registration.rs index dc98dd87c1..cecee1955a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/exported_constants/registration.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/exported_constants/registration.rs @@ -1,4 +1,4 @@ -//! Register the exported native constants and the cursor grain order on `sqlbuild._native`. +//! Register the exported native constants, the installed build identity and the cursor grain order on `sqlbuild._native`. use pyo3::prelude::{Bound, PyAnyMethods, PyModule, PyModuleMethods, PyResult}; use pyo3::types::{PyDict, PyDictMethods, PyFrozenSet, PyTuple}; @@ -7,11 +7,15 @@ use crate::bindings::_helpers::cursor::conversion::GRAIN_NAMES; use crate::bindings::_helpers::exported_constants::constants::{ EXPORTED_INTEGERS, EXPORTED_TEXT_SETS, EXPORTED_TEXT_TUPLES, EXPORTED_TEXTS, }; +use sqlbuild_cli::launcher::main::install_native_build_identity::install_native_build_identity; +use sqlbuild_python_base::boundary::main::compiler_error::compiler_error; use sqlbuild_python_base::records::main::fields::field::field as native_field; /// Registers after the native enums, since `GRAIN_ORDER` is keyed by `CursorGrain` members. pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { let py = module.py(); + let identity: &str = install_native_build_identity().map_err(compiler_error)?; + module.add("BUILD_IDENTITY", identity)?; for (name, value) in EXPORTED_TEXTS { module.add(*name, *value)?; } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/rules/guidance.rs b/crates/sqlbuild-python/src/bindings/_helpers/rules/guidance.rs index b9f6b09716..1036aed53e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/rules/guidance.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/rules/guidance.rs @@ -8,7 +8,7 @@ use pyo3::prelude::{ }; use pyo3::types::{PyDict, PyDictMethods}; use pyo3::{pyfunction, wrap_pyfunction}; -use sqlbuild_rules::constants::NATIVE_BUILD_IDENTITY; +use sqlbuild_rules::build_identity::main::native_build_identity::native_build_identity; use sqlbuild_rules::errors::{SkillInstallError, SkillInstallErrorKind}; use sqlbuild_rules::models::RulesConfig; use sqlbuild_rules::rule_catalogue::main::format_rule_text::format_rule_text; @@ -118,7 +118,7 @@ fn fingerprint_rule( implementation_hash: if custom { custom_rule_implementation_fingerprint(rule, project_dir, None)? } else { - NATIVE_BUILD_IDENTITY.to_owned() + native_build_identity().to_owned() }, }) } diff --git a/crates/sqlbuild-python/src/bindings/main/register.rs b/crates/sqlbuild-python/src/bindings/main/register.rs index 3f4aea1537..2b824dfc40 100644 --- a/crates/sqlbuild-python/src/bindings/main/register.rs +++ b/crates/sqlbuild-python/src/bindings/main/register.rs @@ -1,6 +1,6 @@ use pyo3::prelude::{Bound, PyModule, PyModuleMethods, PyResult}; use pyo3::pymodule; -use sqlbuild_rules::constants::{API_VERSION, NATIVE_BUILD_IDENTITY}; +use sqlbuild_rules::constants::API_VERSION; use crate::bindings::_helpers::{ analysis, analysis_session, attachments, auditing, authored_values, cache, cli, @@ -45,7 +45,6 @@ pub fn _native(module: &Bound<'_, PyModule>) -> PyResult<()> { register_project_stages(module)?; register_analysis_stages(module)?; module.add("API_VERSION", API_VERSION)?; - module.add("BUILD_IDENTITY", NATIVE_BUILD_IDENTITY)?; verify_attributes(module) } diff --git a/crates/sqlbuild-python/src/bindings/tests/test_since_cache.rs b/crates/sqlbuild-python/src/bindings/tests/test_since_cache.rs index 6f08b2ecb1..1a23669b32 100644 --- a/crates/sqlbuild-python/src/bindings/tests/test_since_cache.rs +++ b/crates/sqlbuild-python/src/bindings/tests/test_since_cache.rs @@ -1,5 +1,7 @@ use std::path::PathBuf; +use sqlbuild_cli::launcher::main::install_native_build_identity::install_native_build_identity; + use crate::bindings::tests::helpers::{cache_key_under, project_reading_environment}; use crate::bindings::tests::test_types::CacheKeyTestCase; @@ -7,6 +9,7 @@ const BASE_ENVIRONMENT: [(&str, &str); 2] = [("ORDERS_REGION", "eu"), ("UNREAD_S #[test] fn given_referenced_environment_variable_when_keying_base_cache_then_its_value_counts() { + install_native_build_identity().expect("the build identity installs once"); let project: PathBuf = project_reading_environment(); let base_key: String = cache_key_under(&project, &BASE_ENVIRONMENT); let test_cases = [ diff --git a/crates/sqlbuild-rules/Cargo.toml b/crates/sqlbuild-rules/Cargo.toml index 098bb91940..1c5a31e933 100644 --- a/crates/sqlbuild-rules/Cargo.toml +++ b/crates/sqlbuild-rules/Cargo.toml @@ -33,9 +33,6 @@ sqlclean.workspace = true stacker.workspace = true toml.workspace = true -[build-dependencies] -sha2.workspace = true - [dev-dependencies] tempfile.workspace = true diff --git a/crates/sqlbuild-rules/src/build_identity/_helpers/installed.rs b/crates/sqlbuild-rules/src/build_identity/_helpers/installed.rs new file mode 100644 index 0000000000..18abaee5d7 --- /dev/null +++ b/crates/sqlbuild-rules/src/build_identity/_helpers/installed.rs @@ -0,0 +1,6 @@ +//! The identity the binary installed, once per process. + +use std::sync::OnceLock; + +/// The build identity the binary installed at startup; empty until then. +pub(crate) static INSTALLED_BUILD_IDENTITY: OnceLock = OnceLock::new(); diff --git a/crates/sqlbuild-rules/src/build_identity/_helpers/mod.rs b/crates/sqlbuild-rules/src/build_identity/_helpers/mod.rs new file mode 100644 index 0000000000..7daacf3274 --- /dev/null +++ b/crates/sqlbuild-rules/src/build_identity/_helpers/mod.rs @@ -0,0 +1,3 @@ +//! The installed identity cell. + +pub(crate) mod installed; diff --git a/crates/sqlbuild-rules/src/build_identity/constants.rs b/crates/sqlbuild-rules/src/build_identity/constants.rs new file mode 100644 index 0000000000..bef14a0d12 --- /dev/null +++ b/crates/sqlbuild-rules/src/build_identity/constants.rs @@ -0,0 +1,4 @@ +//! Messages of the build identity. + +/// Why reading the identity before the binary installed it fails. +pub(crate) const MISSING_BUILD_IDENTITY: &str = "the native build identity was not installed: the binary must call install_build_identity at startup, before any cache key or rule fingerprint is read"; diff --git a/crates/sqlbuild-rules/src/build_identity/errors.rs b/crates/sqlbuild-rules/src/build_identity/errors.rs new file mode 100644 index 0000000000..92dfdd3d12 --- /dev/null +++ b/crates/sqlbuild-rules/src/build_identity/errors.rs @@ -0,0 +1,26 @@ +//! Why a build identity cannot be installed. + +use std::fmt; + +/// The reason `install_build_identity` refused an identity. +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum BuildIdentityError { + /// The offered identity is empty, so it would match builds of any sources. + Empty, + /// A different identity is already installed in this process. + Conflicting { installed: String, offered: String }, +} + +impl fmt::Display for BuildIdentityError { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Empty => formatter.write_str("the native build identity is empty"), + Self::Conflicting { installed, offered } => write!( + formatter, + "the native build identity {installed} is already installed; refusing {offered}" + ), + } + } +} + +impl std::error::Error for BuildIdentityError {} diff --git a/crates/sqlbuild-rules/src/build_identity/main/build_field_digest.rs b/crates/sqlbuild-rules/src/build_identity/main/build_field_digest.rs new file mode 100644 index 0000000000..127bdc45c3 --- /dev/null +++ b/crates/sqlbuild-rules/src/build_identity/main/build_field_digest.rs @@ -0,0 +1,17 @@ +//! BLAKE3 over length-prefixed fields keyed on a cache version and this build, so no two field lists share a key. + +use crate::build_identity::main::native_build_identity::native_build_identity; + +/// The hex digest of `version`, the native build, `kind` and each field in order. +#[must_use] +pub fn build_field_digest(version: &str, kind: &str, fields: &[&str]) -> String { + let mut digest = blake3::Hasher::new(); + for field in [version, native_build_identity(), kind] + .iter() + .chain(fields.iter()) + { + digest.update(&(field.len() as u64).to_le_bytes()); + digest.update(field.as_bytes()); + } + digest.finalize().to_hex().to_string() +} diff --git a/crates/sqlbuild-rules/src/build_identity/main/install_build_identity.rs b/crates/sqlbuild-rules/src/build_identity/main/install_build_identity.rs new file mode 100644 index 0000000000..227c5c4f35 --- /dev/null +++ b/crates/sqlbuild-rules/src/build_identity/main/install_build_identity.rs @@ -0,0 +1,19 @@ +//! Install the running build's identity. + +use crate::build_identity::_helpers::installed::INSTALLED_BUILD_IDENTITY; +use crate::build_identity::errors::BuildIdentityError; + +/// Install the running build's non-empty identity once per process; installing the same one again succeeds. +pub fn install_build_identity(identity: &str) -> Result<(), BuildIdentityError> { + if identity.is_empty() { + return Err(BuildIdentityError::Empty); + } + let installed: &String = INSTALLED_BUILD_IDENTITY.get_or_init(|| identity.to_owned()); + if installed != identity { + return Err(BuildIdentityError::Conflicting { + installed: installed.clone(), + offered: identity.to_owned(), + }); + } + Ok(()) +} diff --git a/crates/sqlbuild-rules/src/build_identity/main/mod.rs b/crates/sqlbuild-rules/src/build_identity/main/mod.rs new file mode 100644 index 0000000000..ae7b23fe90 --- /dev/null +++ b/crates/sqlbuild-rules/src/build_identity/main/mod.rs @@ -0,0 +1,5 @@ +//! Installing and reading the build identity, and digests keyed on it. + +pub mod build_field_digest; +pub mod install_build_identity; +pub mod native_build_identity; diff --git a/crates/sqlbuild-rules/src/build_identity/main/native_build_identity.rs b/crates/sqlbuild-rules/src/build_identity/main/native_build_identity.rs new file mode 100644 index 0000000000..52e275e0f9 --- /dev/null +++ b/crates/sqlbuild-rules/src/build_identity/main/native_build_identity.rs @@ -0,0 +1,13 @@ +//! The running build's identity. + +use crate::build_identity::_helpers::installed::INSTALLED_BUILD_IDENTITY; +use crate::build_identity::constants::MISSING_BUILD_IDENTITY; + +/// The installed content hash of every native crate; panics when none was installed, as there is no fallback. +#[must_use] +pub fn native_build_identity() -> &'static str { + match INSTALLED_BUILD_IDENTITY.get() { + Some(identity) => identity, + None => panic!("{MISSING_BUILD_IDENTITY}"), + } +} diff --git a/crates/sqlbuild-rules/src/build_identity/mod.rs b/crates/sqlbuild-rules/src/build_identity/mod.rs new file mode 100644 index 0000000000..ee20a901e3 --- /dev/null +++ b/crates/sqlbuild-rules/src/build_identity/mod.rs @@ -0,0 +1,9 @@ +//! The running native build's content identity, installed by the binary at startup instead of compiled in. + +pub(crate) mod _helpers; +pub(crate) mod constants; +pub mod errors; +pub mod main; + +#[cfg(test)] +mod tests; diff --git a/crates/sqlbuild-rules/src/build_identity/tests.rs b/crates/sqlbuild-rules/src/build_identity/tests.rs new file mode 100644 index 0000000000..3ca2346d4e --- /dev/null +++ b/crates/sqlbuild-rules/src/build_identity/tests.rs @@ -0,0 +1,6 @@ +#[path = "tests/test_build_identity.rs"] +mod build_identity; +#[path = "tests/helpers.rs"] +mod helpers; +#[path = "tests/test_types.rs"] +mod test_types; diff --git a/crates/sqlbuild-rules/src/build_identity/tests/helpers.rs b/crates/sqlbuild-rules/src/build_identity/tests/helpers.rs new file mode 100644 index 0000000000..7ceae53c09 --- /dev/null +++ b/crates/sqlbuild-rules/src/build_identity/tests/helpers.rs @@ -0,0 +1,16 @@ +use crate::build_identity::_helpers::installed::INSTALLED_BUILD_IDENTITY; +use crate::build_identity::main::native_build_identity::native_build_identity; + +/// Set only on the fresh process the missing-identity test starts, so other runs of ignored tests skip the read. +pub(crate) const FRESH_PROCESS_ENV_VAR: &str = "SQLBUILD_RULES_FRESH_IDENTITY_PROCESS"; + +/// In the fresh process, whether an identity was installed before a read that panics without one; elsewhere `false`. +pub(crate) fn read_identity_in_fresh_process() -> bool { + std::env::var_os(FRESH_PROCESS_ENV_VAR) + .map(|_| { + let installed: bool = INSTALLED_BUILD_IDENTITY.get().is_some(); + let _ = native_build_identity(); + installed + }) + .unwrap_or(false) +} diff --git a/crates/sqlbuild-rules/src/build_identity/tests/test_build_identity.rs b/crates/sqlbuild-rules/src/build_identity/tests/test_build_identity.rs new file mode 100644 index 0000000000..e6415fa34e --- /dev/null +++ b/crates/sqlbuild-rules/src/build_identity/tests/test_build_identity.rs @@ -0,0 +1,96 @@ +use std::process::Command; + +use crate::build_identity::constants::MISSING_BUILD_IDENTITY; +use crate::build_identity::errors::BuildIdentityError; +use crate::build_identity::main::install_build_identity::install_build_identity; +use crate::build_identity::tests::helpers::{ + FRESH_PROCESS_ENV_VAR, read_identity_in_fresh_process, +}; +use crate::build_identity::tests::test_types; +use crate::tests::helpers::TEST_BUILD_IDENTITY; + +#[test] +#[ignore = "runs only in the fresh process the missing-identity test starts"] +fn given_a_fresh_process_when_reading_the_identity_then_the_read_panics() { + let test_cases = [test_types::FreshProcessTestCase { + description: "nothing installed an identity in this process", + expected_installed: false, + }]; + for test_case in test_cases { + assert_eq!( + read_identity_in_fresh_process(), + test_case.expected_installed, + "{}", + test_case.description + ); + } +} + +#[test] +fn given_no_installed_identity_when_reading_it_then_the_read_fails_with_the_reason() +-> Result<(), String> { + let test_cases = [test_types::MissingIdentityTestCase { + description: "reading before installing fails with the reason instead of falling back", + fresh_process_test: "build_identity::tests::build_identity::given_a_fresh_process_when_reading_the_identity_then_the_read_panics", + expected_failed: "1 failed", + expected_reason: MISSING_BUILD_IDENTITY, + }]; + for test_case in test_cases { + let output = Command::new(std::env::current_exe().map_err(|error| error.to_string())?) + .args([ + test_case.fresh_process_test, + "--exact", + "--ignored", + "--test-threads=1", + ]) + .env(FRESH_PROCESS_ENV_VAR, "1") + .output() + .map_err(|error| error.to_string())?; + let printed = format!( + "{}{}", + String::from_utf8_lossy(&output.stdout), + String::from_utf8_lossy(&output.stderr) + ); + + assert!( + !output.status.success() + && printed.contains(test_case.expected_failed) + && printed.contains(test_case.expected_reason), + "{}: {printed}", + test_case.description + ); + } + Ok(()) +} + +#[test] +fn given_an_identity_when_installing_then_only_a_non_empty_matching_identity_is_accepted() { + let test_cases = [ + test_types::InstallTestCase { + description: "an empty identity would match builds of any sources", + identity: "", + expected_result: Err(BuildIdentityError::Empty), + }, + test_types::InstallTestCase { + description: "the test identity is installed, again harmlessly when another test did", + identity: TEST_BUILD_IDENTITY, + expected_result: Ok(()), + }, + test_types::InstallTestCase { + description: "a second, different identity is refused", + identity: "fedcba9876543210", + expected_result: Err(BuildIdentityError::Conflicting { + installed: TEST_BUILD_IDENTITY.to_owned(), + offered: "fedcba9876543210".to_owned(), + }), + }, + ]; + for test_case in test_cases { + assert_eq!( + install_build_identity(test_case.identity), + test_case.expected_result, + "{}", + test_case.description + ); + } +} diff --git a/crates/sqlbuild-rules/src/build_identity/tests/test_types.rs b/crates/sqlbuild-rules/src/build_identity/tests/test_types.rs new file mode 100644 index 0000000000..cfe714190d --- /dev/null +++ b/crates/sqlbuild-rules/src/build_identity/tests/test_types.rs @@ -0,0 +1,19 @@ +use crate::build_identity::errors::BuildIdentityError; + +pub(crate) struct InstallTestCase { + pub(crate) description: &'static str, + pub(crate) identity: &'static str, + pub(crate) expected_result: Result<(), BuildIdentityError>, +} + +pub(crate) struct MissingIdentityTestCase { + pub(crate) description: &'static str, + pub(crate) fresh_process_test: &'static str, + pub(crate) expected_failed: &'static str, + pub(crate) expected_reason: &'static str, +} + +pub(crate) struct FreshProcessTestCase { + pub(crate) description: &'static str, + pub(crate) expected_installed: bool, +} diff --git a/crates/sqlbuild-rules/src/constants.rs b/crates/sqlbuild-rules/src/constants.rs index 2fa7cbf84b..639f46e68b 100644 --- a/crates/sqlbuild-rules/src/constants.rs +++ b/crates/sqlbuild-rules/src/constants.rs @@ -1,6 +1,4 @@ pub const API_VERSION: u32 = 1; -/// A content hash of every native crate, including the release version in their manifests. -pub const NATIVE_BUILD_IDENTITY: &str = env!("SQLBUILD_NATIVE_SOURCE_HASH"); pub(crate) const SCOPE_METADATA_SCHEMA_VERSION: u32 = 3; pub(crate) const BUILT_IN_RULE_NAMESPACE: &str = "SQBR"; pub(crate) const PIPELINE_SUBJECT: &str = "pipeline"; diff --git a/crates/sqlbuild-rules/src/custom_rule_cache/_helpers/digest.rs b/crates/sqlbuild-rules/src/custom_rule_cache/_helpers/digest.rs index 75c4553175..4da0cddc23 100644 --- a/crates/sqlbuild-rules/src/custom_rule_cache/_helpers/digest.rs +++ b/crates/sqlbuild-rules/src/custom_rule_cache/_helpers/digest.rs @@ -1,19 +1,11 @@ //! BLAKE3 over length-prefixed fields, so no two field lists share an identity. -use crate::constants::NATIVE_BUILD_IDENTITY; +use crate::build_identity::main::build_field_digest::build_field_digest; use crate::custom_rule_cache::constants::CACHE_VERSION; /// The hex digest of the cache version, the native build and each field in order. pub(crate) fn field_digest(kind: &str, fields: &[&str]) -> String { - let mut digest = blake3::Hasher::new(); - for field in [CACHE_VERSION, NATIVE_BUILD_IDENTITY, kind] - .iter() - .chain(fields.iter()) - { - digest.update(&(field.len() as u64).to_le_bytes()); - digest.update(field.as_bytes()); - } - digest.finalize().to_hex().to_string() + build_field_digest(CACHE_VERSION, kind, fields) } /// An optional field as a presence flag and its text. diff --git a/crates/sqlbuild-rules/src/custom_rule_cache/tests/test_custom_rule_cache.rs b/crates/sqlbuild-rules/src/custom_rule_cache/tests/test_custom_rule_cache.rs index d253b278c4..8f306ff3ac 100644 --- a/crates/sqlbuild-rules/src/custom_rule_cache/tests/test_custom_rule_cache.rs +++ b/crates/sqlbuild-rules/src/custom_rule_cache/tests/test_custom_rule_cache.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use std::collections::BTreeMap; use serde_json::json; @@ -15,6 +16,7 @@ use crate::custom_rule_cache::types::ReadSet; #[test] fn given_rule_identity_inputs_when_one_changes_then_only_relevant_edits_change_the_identity() { + install_test_identity(); let test_cases = [ IdentityTestCase { description: "the same inputs give the same identity", @@ -53,6 +55,7 @@ fn given_rule_identity_inputs_when_one_changes_then_only_relevant_edits_change_t #[test] fn given_stored_results_when_looking_up_then_unchanged_subjects_and_reads_hit() { + install_test_identity(); let test_cases = [ LookupTestCase { description: "unchanged reads and subjects hit every subject", diff --git a/crates/sqlbuild-rules/src/engine/_helpers/evaluation.rs b/crates/sqlbuild-rules/src/engine/_helpers/evaluation.rs index 51f5939936..bd33ed3e7a 100644 --- a/crates/sqlbuild-rules/src/engine/_helpers/evaluation.rs +++ b/crates/sqlbuild-rules/src/engine/_helpers/evaluation.rs @@ -1,7 +1,7 @@ +use crate::build_identity::main::native_build_identity::native_build_identity; use crate::configuration::main::validate as config; use crate::constants::{ - API_VERSION, NATIVE_BUILD_IDENTITY, ORCHESTRATION_RULE_PREFIX, PYTHON_RULE_PREFIX, - RELATION_EXCEPTION_RULES, + API_VERSION, ORCHESTRATION_RULE_PREFIX, PYTHON_RULE_PREFIX, RELATION_EXCEPTION_RULES, }; use crate::engine::_helpers::cache::{Cache, PendingBucketWrite, RuleCacheBucket, RuleCacheEntry}; use crate::lint_text::constants::LINT_UNAVAILABLE_CODE; @@ -589,7 +589,7 @@ fn model_cache_identity(model: &crate::models::Model, model_rules: &str) -> Resu let mut digest = blake3::Hasher::new(); digest.update(MODEL_RULES_IDENTITY_SEED); digest.update(&[0]); - digest.update(NATIVE_BUILD_IDENTITY.as_bytes()); + digest.update(native_build_identity().as_bytes()); digest.update(&[0]); digest.update(model_rules.as_bytes()); digest.update(&[0]); diff --git a/crates/sqlbuild-rules/src/engine/tests/test_domain_layout.rs b/crates/sqlbuild-rules/src/engine/tests/test_domain_layout.rs index 3a4979e8d3..40b6061f83 100644 --- a/crates/sqlbuild-rules/src/engine/tests/test_domain_layout.rs +++ b/crates/sqlbuild-rules/src/engine/tests/test_domain_layout.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use serde_json::json; use tempfile::TempDir; @@ -6,6 +7,7 @@ use crate::engine::tests::{helpers, test_types}; #[test] fn given_owner_and_declaration_layouts_when_evaluating_then_returns_expected_faults() -> Result<(), String> { + install_test_identity(); let oversized_paths: Vec = (0..11) .map(|index| format!("models/commerce/_macros/item_{index}.py")) .collect(); diff --git a/crates/sqlbuild-rules/src/engine/tests/test_empty_input_tests.rs b/crates/sqlbuild-rules/src/engine/tests/test_empty_input_tests.rs index d2ae02afe7..492206bde4 100644 --- a/crates/sqlbuild-rules/src/engine/tests/test_empty_input_tests.rs +++ b/crates/sqlbuild-rules/src/engine/tests/test_empty_input_tests.rs @@ -1,4 +1,5 @@ use crate::engine::tests::{helpers, test_types}; +use crate::tests::helpers::install_test_identity; use serde_json::json; use tempfile::TempDir; @@ -20,6 +21,7 @@ const FLAGGED_MESSAGE: &str = "SQBRTEST203 tests/unit/test_orders__empty_inputs_ #[test] fn given_sql_test_shapes_when_evaluating_empty_input_rule_then_flags_only_filler_tests() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let test_cases = [ test_types::EmptyInputTestRuleTestCase { @@ -320,6 +322,7 @@ fn given_sql_test_shapes_when_evaluating_empty_input_rule_then_flags_only_filler #[test] fn given_empty_input_only_tests_when_evaluating_minimum_tests_then_they_do_not_count() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let real_test = helpers::empty_input_test_fact( "orders__doubles_amounts", @@ -376,6 +379,7 @@ fn given_empty_input_only_tests_when_evaluating_minimum_tests_then_they_do_not_c #[test] fn given_cached_minimum_tests_when_filler_becomes_real_test_then_model_cache_is_invalidated() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let real_test = helpers::empty_input_test_fact( "orders__empty_inputs_produce_no_rows", @@ -422,6 +426,7 @@ fn given_cached_minimum_tests_when_filler_becomes_real_test_then_model_cache_is_ #[test] fn given_sql_server_conversions_when_evaluating_empty_input_rule_then_reports_the_dialect_unavailable() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let empty_orders = ( "__source__raw_orders", diff --git a/crates/sqlbuild-rules/src/engine/tests/test_evaluation.rs b/crates/sqlbuild-rules/src/engine/tests/test_evaluation.rs index 4557377612..5c1148a44d 100644 --- a/crates/sqlbuild-rules/src/engine/tests/test_evaluation.rs +++ b/crates/sqlbuild-rules/src/engine/tests/test_evaluation.rs @@ -1,7 +1,7 @@ +use crate::tests::helpers::install_test_identity; use serde_json::{Value, json}; use tempfile::TempDir; -use crate::constants::NATIVE_BUILD_IDENTITY; use crate::engine::_helpers::evaluation::evaluate_json; use crate::engine::main::build_models::build_models; use crate::engine::tests::helpers; @@ -13,6 +13,7 @@ use crate::query_facts::models::ModelSource; #[test] fn given_dependency_tokens_when_classifying_imports_then_preserves_dialect_and_original_sql() -> Result<(), String> { + install_test_identity(); let test_cases = [ test_types::DependencyTokenTestCase { description: "comments and escaped literals retain canonical arguments", @@ -122,6 +123,7 @@ fn given_dependency_tokens_when_classifying_imports_then_preserves_dialect_and_o #[test] fn given_conflicting_model_identity_when_evaluating_layer_rules_then_reports_independent_findings() -> Result<(), String> { + install_test_identity(); let test_cases = [test_types::ModelLayerRulesTestCase { description: "conflicting model metadata reports every independent boundary", expected_codes: &[ @@ -176,6 +178,7 @@ fn given_conflicting_model_identity_when_evaluating_layer_rules_then_reports_ind #[test] fn given_internal_dependency_edges_when_evaluating_graph_rule_then_only_exact_live_exceptions_apply() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let models = json!([ { @@ -274,6 +277,7 @@ fn given_internal_dependency_edges_when_evaluating_graph_rule_then_only_exact_li #[test] fn given_repeated_native_evaluation_when_faulting_then_returns_deterministic_complete_facts() -> Result<(), String> { + install_test_identity(); let test_cases = [test_types::NativeEvaluationTestCase { description: "repeated native evaluation preserves every fault fact", config: json!({ @@ -315,6 +319,7 @@ fn given_repeated_native_evaluation_when_faulting_then_returns_deterministic_com #[test] fn given_enforced_contract_when_column_type_is_missing_then_typed_contract_rule_faults() -> Result<(), String> { + install_test_identity(); let test_cases = [ test_types::TypedContractColumnTestCase { description: "enforced contract has one untyped column", @@ -387,6 +392,7 @@ fn given_enforced_contract_when_column_type_is_missing_then_typed_contract_rule_ #[test] fn given_scoped_suppression_when_evaluating_native_fault_then_returns_no_faults() -> Result<(), String> { + install_test_identity(); let test_cases = [test_types::NativeEvaluationTestCase { description: "native evaluation applies a matching scoped suppression", config: json!({ @@ -419,6 +425,7 @@ fn given_scoped_suppression_when_evaluating_native_fault_then_returns_no_faults( #[test] fn given_declaration_only_project_when_evaluating_project_rule_then_rule_still_runs() -> Result<(), String> { + install_test_identity(); let test_cases = [test_types::NativeEvaluationTestCase { description: "duplicate enum rule runs without a model anchor", config: json!({ @@ -467,6 +474,7 @@ fn given_declaration_only_project_when_evaluating_project_rule_then_rule_still_r #[test] fn given_scoped_and_global_declarations_when_evaluating_domain_rule_then_only_global_is_checked() -> Result<(), String> { + install_test_identity(); let test_cases = [ test_types::DeclarationScopeTestCase { description: "local test declaration is outside global domain policy", @@ -509,6 +517,7 @@ fn given_scoped_and_global_declarations_when_evaluating_domain_rule_then_only_gl #[test] fn given_snowflake_expression_when_evaluating_rules_then_uses_project_dialect() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let test_cases = [ test_types::DialectEvaluationTestCase { @@ -568,6 +577,7 @@ fn given_snowflake_expression_when_evaluating_rules_then_uses_project_dialect() #[test] fn given_dialect_quoting_around_table_functions_when_evaluating_rules_then_model_parses() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let test_cases = [ test_types::DialectEvaluationTestCase { @@ -621,6 +631,7 @@ fn given_dialect_quoting_around_table_functions_when_evaluating_rules_then_model #[test] fn given_unparseable_model_when_evaluating_then_retains_named_rule_fault() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let deep_sql = format!("SELECT {}1 AS order_id FROM orders", "1 + ".repeat(50_000)); let test_cases = [ @@ -680,6 +691,7 @@ fn given_unparseable_model_when_evaluating_then_retains_named_rule_fault() -> Re #[test] fn given_comment_apostrophes_when_generic_fallback_normalizes_rules_sql_then_model_parses() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let test_cases = [ test_types::DialectEvaluationTestCase { @@ -722,6 +734,7 @@ fn given_comment_apostrophes_when_generic_fallback_normalizes_rules_sql_then_mod #[test] fn given_enforced_contract_outputs_when_evaluating_explicit_type_rule_then_returns_expected_faults() -> Result<(), String> { + install_test_identity(); let test_cases = [ test_types::ExplicitOutputTypeTestCase { description: "proven direct passthrough in final CTE", @@ -990,6 +1003,7 @@ fn given_enforced_contract_outputs_when_evaluating_explicit_type_rule_then_retur #[test] fn given_compiler_proven_duckdb_dynamic_pivot_when_evaluating_contract_rules_then_skips_query_parse() -> Result<(), String> { + install_test_identity(); let test_cases = [test_types::DynamicPivotEvaluationTestCase { description: "compiler-proven bare DuckDB pivot", expected_faults: json!([]), @@ -1036,6 +1050,7 @@ fn given_compiler_proven_duckdb_dynamic_pivot_when_evaluating_contract_rules_the #[test] fn given_contract_name_type_options_when_evaluating_then_accepts_configured_interfaces() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let test_cases = [ test_types::ContractNameTypeOptionsTestCase { @@ -1111,6 +1126,7 @@ fn given_contract_name_type_options_when_evaluating_then_accepts_configured_inte #[test] fn given_numeric_comparisons_when_evaluating_named_decisions_then_only_authored_decisions_fault() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let test_cases = [ test_types::NumericDecisionTestCase { @@ -1297,6 +1313,7 @@ fn given_model_sql_when_stubbing_shape_then_offsets_map_back_to_source_positions #[test] fn given_deep_valid_expression_when_evaluating_rules_then_parser_budget_is_sufficient() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let test_cases = [test_types::DeepExpressionTestCase { description: "deep valid expression remains within the parser budget", @@ -1328,6 +1345,7 @@ fn given_deep_valid_expression_when_evaluating_rules_then_parser_budget_is_suffi #[test] fn given_path_threshold_overrides_when_evaluating_then_matches_in_authored_order() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let test_cases = [ test_types::ThresholdEvaluationTestCase { @@ -1441,6 +1459,7 @@ fn given_path_threshold_overrides_when_evaluating_then_matches_in_authored_order #[test] fn given_threshold_override_change_when_evaluating_then_ruleset_fingerprint_changes() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let test_cases = [test_types::ThresholdFingerprintTestCase { description: "path threshold changes the ruleset fingerprint", @@ -1490,50 +1509,6 @@ fn given_threshold_override_change_when_evaluating_then_ruleset_fingerprint_chan Ok(()) } -#[test] -fn given_native_build_when_reading_cache_identity_then_it_is_a_source_hash() { - let test_cases = [test_types::BuildIdentityTestCase { - description: "cache identity is a source content hash", - expected_hash_length: 16, - }]; - for test_case in &test_cases { - let hash = NATIVE_BUILD_IDENTITY; - - assert!( - hash.len() == test_case.expected_hash_length - && hash.bytes().all(|byte| byte.is_ascii_hexdigit()), - "{}", - test_case.description - ); - } -} - -#[test] -fn given_workspace_checkout_when_deriving_build_identity_then_workspace_files_are_hashed() { - let test_cases = [ - test_types::HashedWorkspaceFileTestCase { - description: "dependency features and build profiles change the identity", - workspace_file: "../../Cargo.toml", - expected_hashed: true, - }, - test_types::HashedWorkspaceFileTestCase { - description: "resolved dependency versions change the identity", - workspace_file: "../../Cargo.lock", - expected_hashed: true, - }, - ]; - for test_case in &test_cases { - let hashed = env!("SQLBUILD_NATIVE_HASHED_WORKSPACE_FILES") - .split(',') - .any(|file| file == test_case.workspace_file); - assert_eq!( - hashed, test_case.expected_hashed, - "{}", - test_case.description - ); - } -} - #[test] fn given_a_model_whose_analysis_was_skipped_when_building_rules_rows_then_its_rules_are_off() -> Result<(), String> { diff --git a/crates/sqlbuild-rules/src/engine/tests/test_incremental_rules.rs b/crates/sqlbuild-rules/src/engine/tests/test_incremental_rules.rs index f8521c390b..b4c7d5645d 100644 --- a/crates/sqlbuild-rules/src/engine/tests/test_incremental_rules.rs +++ b/crates/sqlbuild-rules/src/engine/tests/test_incremental_rules.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use std::collections::BTreeMap; use serde_json::{Value, json}; @@ -167,6 +168,7 @@ const REVIEWED_SCOPES: &[(&str, RuleScope)] = &[ #[test] fn given_built_in_catalogue_when_reading_rule_scopes_then_every_rule_matches_reviewed_scope() { + install_test_identity(); let test_cases = [test_types::RuleScopeTestCase { description: "every built-in rule declares its reviewed scope", expected_scopes: REVIEWED_SCOPES, @@ -199,6 +201,7 @@ fn given_built_in_catalogue_when_reading_rule_scopes_then_every_rule_matches_rev #[test] fn given_every_built_in_rule_when_evaluating_then_findings_stay_inside_declared_scopes() -> Result<(), String> { + install_test_identity(); let test_cases = [test_types::ScopedEvaluationTestCase { description: "model and project findings come from scoped phases", expected_codes: &["SQBRCONTRACT101", "SQBRGRAPH102", "SQBRTEST202"], @@ -233,6 +236,7 @@ fn given_every_built_in_rule_when_evaluating_then_findings_stay_inside_declared_ #[test] fn given_split_model_payloads_when_evaluating_then_response_matches_single_request() -> Result<(), String> { + install_test_identity(); let test_cases = [ test_types::IncrementalRulesTestCase { description: "uncached split request", @@ -314,6 +318,7 @@ fn given_malformed_split_request_when_evaluating_then_request_is_rejected() -> R #[test] fn given_cached_models_when_editing_one_model_then_only_it_reevaluates_with_uncached_findings() -> Result<(), String> { + install_test_identity(); let test_cases = [test_types::ModelCacheReuseTestCase { description: "one edited model misses while the others hit", expected_hits: 2, @@ -356,6 +361,7 @@ fn given_cached_models_when_editing_one_model_then_only_it_reevaluates_with_unca #[test] fn given_suppression_change_when_evaluating_then_cached_models_are_reused_with_uncached_findings() -> Result<(), String> { + install_test_identity(); let test_cases = [test_types::ModelCacheReuseTestCase { description: "a scoped ignore does not invalidate model findings", expected_hits: 3, @@ -402,6 +408,7 @@ fn given_suppression_change_when_evaluating_then_cached_models_are_reused_with_u #[test] fn given_removed_model_file_when_cache_is_rewritten_then_only_its_entry_is_dropped() -> Result<(), String> { + install_test_identity(); let test_cases = [test_types::CachePruningTestCase { description: "deleted model is pruned while an unselected model is kept", expected_paths: &[ @@ -443,6 +450,7 @@ fn given_removed_model_file_when_cache_is_rewritten_then_only_its_entry_is_dropp #[test] fn given_configured_cache_path_when_evaluating_then_only_that_file_is_used() -> Result<(), String> { + install_test_identity(); let test_cases = [test_types::ConfiguredCachePathTestCase { description: "an engine-owned cache file replaces the default bulk cache", cache_file: "target/rules-cache-native-v1/bulk/native.json", @@ -484,6 +492,7 @@ fn given_configured_cache_path_when_evaluating_then_only_that_file_is_used() -> #[test] fn given_corrupt_model_cache_when_evaluating_then_every_model_reevaluates() -> Result<(), String> { + install_test_identity(); let test_cases = [test_types::ModelCacheReuseTestCase { description: "a truncated cache file is a miss for every model", expected_hits: 0, diff --git a/crates/sqlbuild-rules/src/engine/tests/test_published_layers.rs b/crates/sqlbuild-rules/src/engine/tests/test_published_layers.rs index 510783eee1..4fdae82d0b 100644 --- a/crates/sqlbuild-rules/src/engine/tests/test_published_layers.rs +++ b/crates/sqlbuild-rules/src/engine/tests/test_published_layers.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use serde_json::json; use crate::engine::tests::helpers::published_layer_faults; @@ -6,6 +7,7 @@ use crate::engine::tests::test_types::PublishedLayerTestCase; #[test] fn given_published_models_when_evaluating_layer_rules_then_reads_and_shapes_match() -> Result<(), String> { + install_test_identity(); let test_cases = [ PublishedLayerTestCase { description: "a consumer variant reads its own domain's published model", diff --git a/crates/sqlbuild-rules/src/engine/tests/test_query_facts.rs b/crates/sqlbuild-rules/src/engine/tests/test_query_facts.rs index fca1058f78..f93bcf2a37 100644 --- a/crates/sqlbuild-rules/src/engine/tests/test_query_facts.rs +++ b/crates/sqlbuild-rules/src/engine/tests/test_query_facts.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use serde_json::json; use crate::engine::tests::helpers; @@ -12,6 +13,7 @@ const STATUS: &[&str] = &["status"]; #[test] fn given_dialect_sql_when_reading_query_facts_then_findings_match_the_authored_sql() -> Result<(), String> { + install_test_identity(); let test_cases = [ QueryFactsTestCase { description: "a Snowflake // comment holds no dependency call", diff --git a/crates/sqlbuild-rules/src/engine/tests/test_retained_rows.rs b/crates/sqlbuild-rules/src/engine/tests/test_retained_rows.rs index eb8f0503f8..e3c03b8a47 100644 --- a/crates/sqlbuild-rules/src/engine/tests/test_retained_rows.rs +++ b/crates/sqlbuild-rules/src/engine/tests/test_retained_rows.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use serde_json::Value; use tempfile::TempDir; @@ -15,6 +16,7 @@ use crate::models::{EvaluateRequest, Fault, Model, RetainedRows, RowsEvaluation, #[test] fn given_retained_rows_when_evaluating_without_sql_then_only_cached_findings_stand_in() -> Result<(), String> { + install_test_identity(); let test_cases = [ RetainedRowsTestCase { description: "the findings cached by the retaining evaluation stand in", diff --git a/crates/sqlbuild-rules/src/engine/tests/test_speculative_rows.rs b/crates/sqlbuild-rules/src/engine/tests/test_speculative_rows.rs index 9c73e1f4f9..37127e28ab 100644 --- a/crates/sqlbuild-rules/src/engine/tests/test_speculative_rows.rs +++ b/crates/sqlbuild-rules/src/engine/tests/test_speculative_rows.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use std::path::{Path, PathBuf}; use std::sync::atomic::AtomicBool; @@ -21,6 +22,7 @@ use crate::models::SpeculativeAnswer; #[test] fn given_speculative_rows_when_answering_then_result_and_writes_match_ordinary_evaluation() -> Result<(), String> { + install_test_identity(); let test_cases = [ SpeculativeRowsTestCase { description: "identical cached request uses the speculation", @@ -99,6 +101,7 @@ fn given_speculative_rows_when_answering_then_result_and_writes_match_ordinary_e #[test] fn given_speculative_rows_when_discarded_or_stopped_then_nothing_is_written() -> Result<(), String> { + install_test_identity(); let test_cases = [ SpeculativeStopTestCase { description: "discarding after it ran a while", diff --git a/crates/sqlbuild-rules/src/engine/tests/test_sql_test_rules.rs b/crates/sqlbuild-rules/src/engine/tests/test_sql_test_rules.rs index 963d696cc3..aa2b20dd82 100644 --- a/crates/sqlbuild-rules/src/engine/tests/test_sql_test_rules.rs +++ b/crates/sqlbuild-rules/src/engine/tests/test_sql_test_rules.rs @@ -1,11 +1,13 @@ use crate::engine::_helpers::evaluation::evaluate_json; use crate::engine::tests::{helpers, test_types}; +use crate::tests::helpers::install_test_identity; use serde_json::{Value, json}; use tempfile::TempDir; #[test] fn given_sql_test_facts_when_evaluating_project_rules_then_returns_expected_faults() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let mut misplaced_test = helpers::sql_test_fact( "quality/test_orders__paid.sql", @@ -267,6 +269,7 @@ fn given_sql_test_facts_when_evaluating_project_rules_then_returns_expected_faul #[test] fn given_test_fact_change_when_evaluating_cached_project_rule_then_project_rule_reruns_over_cached_models() -> Result<(), String> { + install_test_identity(); let project_dir = TempDir::new().map_err(|error| error.to_string())?; let test_cases = [test_types::SqlTestRulesCacheTestCase { description: "test fact change re-evaluates the project rule and reuses the model", diff --git a/crates/sqlbuild-rules/src/engine/tests/test_types.rs b/crates/sqlbuild-rules/src/engine/tests/test_types.rs index 7bd4f88f21..47e67ffbdc 100644 --- a/crates/sqlbuild-rules/src/engine/tests/test_types.rs +++ b/crates/sqlbuild-rules/src/engine/tests/test_types.rs @@ -103,17 +103,6 @@ pub(crate) struct ThresholdEvaluationTestCase { pub(crate) expected_codes: &'static [&'static str], } -pub(crate) struct BuildIdentityTestCase { - pub(crate) description: &'static str, - pub(crate) expected_hash_length: usize, -} - -pub(crate) struct HashedWorkspaceFileTestCase { - pub(crate) description: &'static str, - pub(crate) workspace_file: &'static str, - pub(crate) expected_hashed: bool, -} - pub(crate) struct ThresholdFingerprintTestCase { pub(crate) description: &'static str, pub(crate) base_config: Value, diff --git a/crates/sqlbuild-rules/src/lib.rs b/crates/sqlbuild-rules/src/lib.rs index 8e5e959270..6a17aa20b2 100644 --- a/crates/sqlbuild-rules/src/lib.rs +++ b/crates/sqlbuild-rules/src/lib.rs @@ -2,6 +2,7 @@ #![forbid(unsafe_code)] +pub mod build_identity; pub mod configuration; pub mod constants; pub mod custom_host_pool; @@ -23,3 +24,6 @@ pub mod rule_results; pub mod rules; pub mod scope_metadata; pub mod types; + +#[cfg(test)] +mod tests; diff --git a/crates/sqlbuild-rules/src/orchestration_rules/tests/test_named_selector_limit.rs b/crates/sqlbuild-rules/src/orchestration_rules/tests/test_named_selector_limit.rs index 587c84bdfb..699456e581 100644 --- a/crates/sqlbuild-rules/src/orchestration_rules/tests/test_named_selector_limit.rs +++ b/crates/sqlbuild-rules/src/orchestration_rules/tests/test_named_selector_limit.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use serde_json::json; use crate::orchestration_rules::tests::helpers::{ @@ -8,6 +9,7 @@ use crate::orchestration_rules::tests::test_types::NamedSelectorLimitTestCase; #[test] fn given_job_and_sensor_selections_when_evaluating_then_more_named_nodes_than_the_limit_are_findings() { + install_test_identity(); let selected = json!({ "select": ["SQBRORCHESTRATION101"] }); let test_cases = [ NamedSelectorLimitTestCase { diff --git a/crates/sqlbuild-rules/src/python_rules/main/python_catalogue.rs b/crates/sqlbuild-rules/src/python_rules/main/python_catalogue.rs index 35229d244f..d8294204f7 100644 --- a/crates/sqlbuild-rules/src/python_rules/main/python_catalogue.rs +++ b/crates/sqlbuild-rules/src/python_rules/main/python_catalogue.rs @@ -1,6 +1,6 @@ //! The Python rules as catalogue entries. -use crate::constants::NATIVE_BUILD_IDENTITY; +use crate::build_identity::main::native_build_identity::native_build_identity; use crate::models::{RuleMetadata, RuleScope}; use crate::python_rules::constants::PYTHON_RULES; use crate::python_rules::models::PythonRuleSpec; @@ -19,7 +19,7 @@ fn metadata(rule: &PythonRuleSpec) -> RuleMetadata { message: rule.message.into(), remediation: rule.remediation.into(), guidance: None, - implementation_fingerprint: NATIVE_BUILD_IDENTITY.into(), + implementation_fingerprint: native_build_identity().into(), enabled_by_default: rule.enabled_by_default, project_wide: true, custom: false, diff --git a/crates/sqlbuild-rules/src/python_rules/tests/test_compile_purity_rules.rs b/crates/sqlbuild-rules/src/python_rules/tests/test_compile_purity_rules.rs index ec5d6273bc..b9cbbd3e96 100644 --- a/crates/sqlbuild-rules/src/python_rules/tests/test_compile_purity_rules.rs +++ b/crates/sqlbuild-rules/src/python_rules/tests/test_compile_purity_rules.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use serde_json::json; use crate::python_rules::tests::helpers::{owned_faults, python_rule_faults}; @@ -125,6 +126,7 @@ def deferred_runner(): #[test] fn given_compile_time_python_when_evaluating_compile_time_purity_then_reports_calls_reaching_external_systems() { + install_test_identity(); let test_cases = [ PythonRunTestCase { description: "static specs, node bodies, main() and provider methods report nothing", @@ -250,6 +252,7 @@ fn given_compile_time_python_when_evaluating_compile_time_purity_then_reports_ca #[test] fn given_a_boundary_naming_a_module_when_evaluating_compile_time_purity_then_the_run_fails() { + install_test_identity(); let test_cases = [PythonRunFailureTestCase { description: "a module is not a loader boundary", files: &[ diff --git a/crates/sqlbuild-rules/src/python_rules/tests/test_evaluate_python_rules.rs b/crates/sqlbuild-rules/src/python_rules/tests/test_evaluate_python_rules.rs index 0a0c34f9db..165a83d120 100644 --- a/crates/sqlbuild-rules/src/python_rules/tests/test_evaluate_python_rules.rs +++ b/crates/sqlbuild-rules/src/python_rules/tests/test_evaluate_python_rules.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use serde_json::json; use crate::python_rules::tests::helpers::{owned_faults, python_rule_faults}; @@ -6,6 +7,7 @@ use crate::python_rules::tests::test_types::{PythonParseFailureTestCase, PythonR #[test] fn given_project_python_when_evaluating_python_rules_then_reports_fensu_findings_in_sqlbuild_terms() { + install_test_identity(); let test_cases = [ PythonRunTestCase { description: "a file outside python/ reports at a character column after non-ASCII text", @@ -235,6 +237,7 @@ fn given_project_python_when_evaluating_python_rules_then_reports_fensu_findings #[test] fn given_python_the_parser_rejects_when_evaluating_python_rules_then_the_run_fails_at_the_file() { + install_test_identity(); let test_cases = [PythonParseFailureTestCase { description: "a parameter list cut short", files: &[("python/orders/main/bad.py", "def broken(:\n")], diff --git a/crates/sqlbuild-rules/src/python_rules/tests/test_node_units.rs b/crates/sqlbuild-rules/src/python_rules/tests/test_node_units.rs index 2a8ce141c0..46a5c1d3c8 100644 --- a/crates/sqlbuild-rules/src/python_rules/tests/test_node_units.rs +++ b/crates/sqlbuild-rules/src/python_rules/tests/test_node_units.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use serde_json::json; use crate::python_rules::tests::helpers::{owned_faults, python_rule_faults}; @@ -33,6 +34,7 @@ def main(ctx: TaskContext) -> PythonNodeResult: #[test] fn given_node_units_when_evaluating_unit_rules_then_reports_each_broken_convention() { + install_test_identity(); let test_cases = [ PythonRunTestCase { description: "a project laid out in units reports nothing", @@ -616,6 +618,7 @@ def tables(): #[test] fn given_valid_shapes_and_hidden_mistakes_when_evaluating_unit_rules_then_reports_only_the_mistakes() { + install_test_identity(); let test_cases = [ PythonRunTestCase { description: "a node.py in utils/, a role folder or a unit's _helpers/ is not a unit", diff --git a/crates/sqlbuild-rules/src/python_rules/tests/test_orchestration_rules.rs b/crates/sqlbuild-rules/src/python_rules/tests/test_orchestration_rules.rs index d2dc267d49..8f53f8e5fa 100644 --- a/crates/sqlbuild-rules/src/python_rules/tests/test_orchestration_rules.rs +++ b/crates/sqlbuild-rules/src/python_rules/tests/test_orchestration_rules.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use serde_json::json; use crate::python_rules::tests::helpers::{owned_faults, python_rule_faults}; @@ -14,6 +15,7 @@ const ORCHESTRATION_RULES: [&str; 5] = [ #[test] fn given_sensor_and_calendar_modules_when_evaluating_orchestration_rules_then_reports_each_broken_convention() { + install_test_identity(); let test_cases = [ PythonRunTestCase { description: "domain folders with one declaration per module, private support and allowed imports report nothing", diff --git a/crates/sqlbuild-rules/src/python_rules/tests/test_provider_rules.rs b/crates/sqlbuild-rules/src/python_rules/tests/test_provider_rules.rs index 1dbe18cb4c..779d1124fe 100644 --- a/crates/sqlbuild-rules/src/python_rules/tests/test_provider_rules.rs +++ b/crates/sqlbuild-rules/src/python_rules/tests/test_provider_rules.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use serde_json::json; use crate::python_rules::tests::helpers::{owned_faults, python_rule_faults}; @@ -7,6 +8,7 @@ const PROVIDER_RULES: [&str; 3] = ["SQBRPYTHON013", "SQBRPYTHON014", "SQBRPYTHON #[test] fn given_providers_when_evaluating_provider_rules_then_reports_each_broken_convention() { + install_test_identity(); let test_cases = [ PythonRunTestCase { description: "capability folders with provider.py, role files and private folders report nothing", diff --git a/crates/sqlbuild-rules/src/python_rules/tests/test_python_cache.rs b/crates/sqlbuild-rules/src/python_rules/tests/test_python_cache.rs index 33e247394c..df9a9397fb 100644 --- a/crates/sqlbuild-rules/src/python_rules/tests/test_python_cache.rs +++ b/crates/sqlbuild-rules/src/python_rules/tests/test_python_cache.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use serde_json::json; use fensu_native::NativeProjectQuery; @@ -13,6 +14,7 @@ const ANNOTATED: &str = "def send(count: int) -> None:\n pass\n"; #[test] fn given_a_cached_python_run_when_running_again_then_only_changed_inputs_are_evaluated() { + install_test_identity(); let test_cases = [ PythonCacheTestCase { description: "an unchanged project is answered from the cache", diff --git a/crates/sqlbuild-rules/src/python_rules/tests/test_python_catalogue.rs b/crates/sqlbuild-rules/src/python_rules/tests/test_python_catalogue.rs index 8faa13bcfb..d12291234a 100644 --- a/crates/sqlbuild-rules/src/python_rules/tests/test_python_catalogue.rs +++ b/crates/sqlbuild-rules/src/python_rules/tests/test_python_catalogue.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use fensu_native::rules::constants as fensu; use crate::python_rules::tests::helpers::{ @@ -12,6 +13,7 @@ use crate::rules::models::BuiltinOptionKind; #[test] fn given_the_catalogue_when_listing_python_rules_then_each_has_its_own_project_wide_code() { + install_test_identity(); let test_cases = [ CatalogueTestCase { description: "21 SQLBuild layout, unit, provider, orchestration and test placement rules and 86 Fensu core and test rules have distinct codes", @@ -36,6 +38,7 @@ fn given_the_catalogue_when_listing_python_rules_then_each_has_its_own_project_w #[test] fn given_python_selectors_when_selecting_then_opt_in_rules_need_their_exact_code() { + install_test_identity(); let test_cases = [ SelectionTestCase { description: "the family selects a default rule", @@ -177,6 +180,7 @@ fn given_python_rules_when_reading_their_options_then_fensu_thresholds_are_whole #[test] fn given_a_python_edit_when_preparing_rules_then_only_python_selections_see_it() { + install_test_identity(); const ORIGINAL: &str = "def total(amount: int) -> int:\n return amount\n"; let test_cases = [ SourceKeyTestCase { diff --git a/crates/sqlbuild-rules/src/python_rules/tests/test_python_scaling.rs b/crates/sqlbuild-rules/src/python_rules/tests/test_python_scaling.rs index 9a8561239f..24ac1db8cf 100644 --- a/crates/sqlbuild-rules/src/python_rules/tests/test_python_scaling.rs +++ b/crates/sqlbuild-rules/src/python_rules/tests/test_python_scaling.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use std::collections::BTreeMap; use std::time::Duration; @@ -14,6 +15,7 @@ use crate::python_rules::tests::test_types::{ #[test] fn given_many_modules_and_dense_findings_when_evaluating_python_rules_then_finishes_within_budget() { + install_test_identity(); let _serial = serial_timing(); let test_cases = [PythonScalingTestCase { description: "default rules over 4000 modules and 40 hooks of 300 findings each", @@ -44,6 +46,7 @@ fn given_many_modules_and_dense_findings_when_evaluating_python_rules_then_finis #[test] fn given_four_times_the_modules_when_finding_unreachable_definitions_then_time_grows_near_linearly() { + install_test_identity(); let _serial = serial_timing(); let test_cases = [PythonGrowthTestCase { description: "unreachable definitions walking every import, 500 against 2000 modules", @@ -83,6 +86,7 @@ fn given_four_times_the_modules_when_finding_unreachable_definitions_then_time_g #[test] fn given_many_linked_node_units_when_evaluating_unit_rules_then_finishes_within_budget_and_grows_near_linearly() { + install_test_identity(); let _serial = serial_timing(); let test_cases = [UnitScalingTestCase { description: "default rules over a chain of 2000 units of node, main and checks, and 200 undescribed units", @@ -131,6 +135,7 @@ fn given_many_linked_node_units_when_evaluating_unit_rules_then_finishes_within_ #[test] fn given_many_roots_sharing_deep_call_chains_when_checking_compile_time_purity_then_finishes_within_budget() { + install_test_identity(); let _serial = serial_timing(); let test_cases = [PurityScalingTestCase { description: "5000 module-scope roots into 10 helper chains of 400 calls each", diff --git a/crates/sqlbuild-rules/src/python_rules/tests/test_python_test_rules.rs b/crates/sqlbuild-rules/src/python_rules/tests/test_python_test_rules.rs index 0091005320..3357c58220 100644 --- a/crates/sqlbuild-rules/src/python_rules/tests/test_python_test_rules.rs +++ b/crates/sqlbuild-rules/src/python_rules/tests/test_python_test_rules.rs @@ -1,3 +1,4 @@ +use crate::tests::helpers::install_test_identity; use serde_json::json; use crate::python_rules::tests::helpers::{owned_faults, python_rule_faults}; @@ -118,6 +119,7 @@ def test_given_raw_order_when_mapping_then_status_is_normalised(test_case: RowMa #[test] fn given_project_python_tests_when_evaluating_test_rules_then_reports_misplaced_and_unconventional_tests() { + install_test_identity(); let test_cases = [ PythonRunTestCase { description: "tests mirroring a unit, its helpers and a provider, with dataclass cases, report nothing", diff --git a/crates/sqlbuild-rules/src/rule_cache/_helpers/digest.rs b/crates/sqlbuild-rules/src/rule_cache/_helpers/digest.rs index 78503eda68..2b018f20a0 100644 --- a/crates/sqlbuild-rules/src/rule_cache/_helpers/digest.rs +++ b/crates/sqlbuild-rules/src/rule_cache/_helpers/digest.rs @@ -1,17 +1,9 @@ //! BLAKE3 over length-prefixed fields, so no two field lists share a key. -use crate::constants::NATIVE_BUILD_IDENTITY; +use crate::build_identity::main::build_field_digest::build_field_digest; use crate::rule_cache::constants::CACHE_VERSION; /// The hex digest of the cache version, the native build and each field in order. pub(crate) fn field_digest(kind: &str, fields: &[&str]) -> String { - let mut digest = blake3::Hasher::new(); - for field in [CACHE_VERSION, NATIVE_BUILD_IDENTITY, kind] - .iter() - .chain(fields.iter()) - { - digest.update(&(field.len() as u64).to_le_bytes()); - digest.update(field.as_bytes()); - } - digest.finalize().to_hex().to_string() + build_field_digest(CACHE_VERSION, kind, fields) } diff --git a/crates/sqlbuild-rules/src/rule_cache/main/parse_rule_cache.rs b/crates/sqlbuild-rules/src/rule_cache/main/parse_rule_cache.rs index 626fa2952d..b055933269 100644 --- a/crates/sqlbuild-rules/src/rule_cache/main/parse_rule_cache.rs +++ b/crates/sqlbuild-rules/src/rule_cache/main/parse_rule_cache.rs @@ -1,8 +1,8 @@ //! `parse_rule_cache`: the usable entries of a stored SQL rule cache. +use crate::build_identity::main::native_build_identity::native_build_identity; use serde_json::{Map, Value}; -use crate::constants::NATIVE_BUILD_IDENTITY; use crate::rule_cache::constants::{ BUILD_IDENTITY_KEY, CACHE_VERSION, ENTRIES_KEY, FINDINGS_KEY, IDENTITY_KEY, VERSION_KEY, }; @@ -24,7 +24,7 @@ pub fn parse_rule_cache(text: &str) -> CachedEntries { return CachedEntries::new(); }; let current: bool = payload.get(VERSION_KEY).and_then(Value::as_str) == Some(CACHE_VERSION) - && payload.get(BUILD_IDENTITY_KEY).and_then(Value::as_str) == Some(NATIVE_BUILD_IDENTITY); + && payload.get(BUILD_IDENTITY_KEY).and_then(Value::as_str) == Some(native_build_identity()); let Some(Value::Object(entries)) = payload.get(ENTRIES_KEY).filter(|_| current) else { return CachedEntries::new(); }; diff --git a/crates/sqlbuild-rules/src/rule_cache/main/rule_cache_text.rs b/crates/sqlbuild-rules/src/rule_cache/main/rule_cache_text.rs index 0eabbd6065..cd161a1a65 100644 --- a/crates/sqlbuild-rules/src/rule_cache/main/rule_cache_text.rs +++ b/crates/sqlbuild-rules/src/rule_cache/main/rule_cache_text.rs @@ -1,8 +1,8 @@ //! `rule_cache_text`: the stored form of the SQL rule cache. +use crate::build_identity::main::native_build_identity::native_build_identity; use serde_json::{Map, Value, json}; -use crate::constants::NATIVE_BUILD_IDENTITY; use crate::rule_cache::constants::{ BUILD_IDENTITY_KEY, CACHE_VERSION, ENTRIES_KEY, FINDINGS_KEY, IDENTITY_KEY, VERSION_KEY, }; @@ -20,7 +20,7 @@ pub fn rule_cache_text(entries: &CachedEntries) -> String { .collect(); json!({ VERSION_KEY: CACHE_VERSION, - BUILD_IDENTITY_KEY: NATIVE_BUILD_IDENTITY, + BUILD_IDENTITY_KEY: native_build_identity(), ENTRIES_KEY: stored, }) .to_string() diff --git a/crates/sqlbuild-rules/src/rule_cache/tests/test_rule_cache.rs b/crates/sqlbuild-rules/src/rule_cache/tests/test_rule_cache.rs index dd616aa6a2..86716c95d0 100644 --- a/crates/sqlbuild-rules/src/rule_cache/tests/test_rule_cache.rs +++ b/crates/sqlbuild-rules/src/rule_cache/tests/test_rule_cache.rs @@ -2,10 +2,12 @@ use crate::rule_cache::_helpers::model_rule_key::model_rule_key; use crate::rule_cache::main::model_rule_keys::model_rule_keys; use crate::rule_cache::models::ModelKeyInput; use crate::rule_cache::tests::test_types::ModelRuleKeysTestCase; +use crate::tests::helpers::install_test_identity; #[test] fn given_models_when_hashing_rule_keys_together_then_each_key_matches_its_single_model_key_in_order() { + install_test_identity(); let test_cases = [ ModelRuleKeysTestCase { description: "no models give no keys", diff --git a/crates/sqlbuild-rules/src/rule_catalogue/main/ruleset_fingerprint.rs b/crates/sqlbuild-rules/src/rule_catalogue/main/ruleset_fingerprint.rs index 4a20a55fe4..f2476a0d7a 100644 --- a/crates/sqlbuild-rules/src/rule_catalogue/main/ruleset_fingerprint.rs +++ b/crates/sqlbuild-rules/src/rule_catalogue/main/ruleset_fingerprint.rs @@ -1,11 +1,11 @@ //! The fingerprint of one resolved ruleset that generated guidance records. +use crate::build_identity::main::native_build_identity::native_build_identity; use std::collections::BTreeMap; use serde_json::{Value, json}; use sha2::{Digest, Sha256}; -use crate::constants::NATIVE_BUILD_IDENTITY; use crate::models::RulesConfig; use crate::rule_catalogue::models::FingerprintRule; @@ -35,7 +35,7 @@ pub fn ruleset_fingerprint( })); } let rules_payload: Value = json!({ - "engine": NATIVE_BUILD_IDENTITY, + "engine": native_build_identity(), "rules": payload, "thresholds": config.thresholds, "threshold_overrides": config.threshold_overrides, diff --git a/crates/sqlbuild-rules/src/rules/_helpers/catalogue.rs b/crates/sqlbuild-rules/src/rules/_helpers/catalogue.rs index 812a79497f..6242dc9e10 100644 --- a/crates/sqlbuild-rules/src/rules/_helpers/catalogue.rs +++ b/crates/sqlbuild-rules/src/rules/_helpers/catalogue.rs @@ -1,4 +1,5 @@ -use crate::constants::{API_VERSION, NATIVE_BUILD_IDENTITY, PYTHON_RULE_PREFIX, SQL_RULE_PREFIX}; +use crate::build_identity::main::native_build_identity::native_build_identity; +use crate::constants::{API_VERSION, PYTHON_RULE_PREFIX, SQL_RULE_PREFIX}; use crate::models::RulesCodeGrammar; use crate::models::{CustomRule, ResolveRulesRequest, RuleGuidance, RuleMetadata, RuleScope}; use crate::python_rules::main::python_catalogue::python_catalogue; @@ -19,7 +20,7 @@ macro_rules! rule { message: $message.into(), remediation: $remediation.into(), guidance: None, - implementation_fingerprint: NATIVE_BUILD_IDENTITY.into(), + implementation_fingerprint: native_build_identity().into(), enabled_by_default: true, project_wide: matches!( $code, @@ -394,7 +395,7 @@ pub(crate) fn catalogue() -> Vec { message: rule.message.into(), remediation: rule.remediation.into(), guidance: None, - implementation_fingerprint: NATIVE_BUILD_IDENTITY.into(), + implementation_fingerprint: native_build_identity().into(), enabled_by_default: defaults.contains(&rule.code), project_wide: false, custom: false, @@ -424,7 +425,7 @@ fn minimum_tests_rule() -> RuleMetadata { "Add a SQL unit test that mocks each real import and asserts concrete transformed rows. Empty-input-only tests flagged by SQBRTEST203 do not count toward this minimum unless they are listed in its allowed_tests option; do not write them to satisfy the minimum.", ), guidance: Some(guidance), - implementation_fingerprint: NATIVE_BUILD_IDENTITY.into(), + implementation_fingerprint: native_build_identity().into(), enabled_by_default: true, project_wide: false, custom: false, @@ -606,7 +607,7 @@ pub(crate) fn fingerprint( config: &crate::models::RulesConfig, dialect: &str, ) -> Result { - let payload = serde_json::to_vec(&(rules, config, dialect, NATIVE_BUILD_IDENTITY)) + let payload = serde_json::to_vec(&(rules, config, dialect, native_build_identity())) .map_err(|e| e.to_string())?; Ok(format!("{:x}", Sha256::digest(payload))) } diff --git a/crates/sqlbuild-rules/src/rules/_helpers/sql_test_rules.rs b/crates/sqlbuild-rules/src/rules/_helpers/sql_test_rules.rs index f53e86786c..1faa38d2e7 100644 --- a/crates/sqlbuild-rules/src/rules/_helpers/sql_test_rules.rs +++ b/crates/sqlbuild-rules/src/rules/_helpers/sql_test_rules.rs @@ -1,3 +1,4 @@ +use crate::build_identity::main::native_build_identity::native_build_identity; use crate::models::{ DeclarationKind, EvaluateRequest, Fault, Model, ResourceKind, RuleMetadata, RulesConfig, ScopeResource, SqlScenarioFact, SqlTestCteFact, SqlTestFact, SqlTestMode, @@ -19,8 +20,6 @@ use std::collections::{BTreeMap, BTreeSet, HashMap}; use std::path::Path; use std::rc::Rc; -use crate::constants::NATIVE_BUILD_IDENTITY; - const UNIT_ROOT: &str = "tests/unit"; const SCENARIO_ROOT: &str = "tests/scenarios"; const EMPTY_INPUT_RULE_CODE: &str = "SQBRTEST203"; @@ -838,7 +837,7 @@ struct StoredSummaries { pub(crate) fn with_fixture_memo(store: Option<&Path>, body: impl FnOnce() -> (T, bool)) -> T { let loaded: BTreeMap = store .and_then(stored_summaries) - .filter(|stored| stored.build == NATIVE_BUILD_IDENTITY) + .filter(|stored| stored.build == native_build_identity()) .map(|stored| stored.summaries) .unwrap_or_default(); let loaded_count: usize = loaded.len(); @@ -866,7 +865,7 @@ pub(crate) fn with_fixture_memo(store: Option<&Path>, body: impl FnOnce() -> summaries, used, .. } = memo; let stored: StoredSummaries = StoredSummaries { - build: NATIVE_BUILD_IDENTITY.to_owned(), + build: native_build_identity().to_owned(), summaries: summaries .into_iter() .filter(|(key, _)| used.contains(key)) diff --git a/crates/sqlbuild-rules/src/tests.rs b/crates/sqlbuild-rules/src/tests.rs new file mode 100644 index 0000000000..d8231d7efc --- /dev/null +++ b/crates/sqlbuild-rules/src/tests.rs @@ -0,0 +1,2 @@ +#[path = "tests/helpers.rs"] +pub(crate) mod helpers; diff --git a/crates/sqlbuild-rules/src/tests/helpers.rs b/crates/sqlbuild-rules/src/tests/helpers.rs new file mode 100644 index 0000000000..6b6dc795ac --- /dev/null +++ b/crates/sqlbuild-rules/src/tests/helpers.rs @@ -0,0 +1,9 @@ +use crate::build_identity::main::install_build_identity::install_build_identity; + +/// The build identity every test of this crate installs; the binary installs the real one. +pub(crate) const TEST_BUILD_IDENTITY: &str = "0123456789abcdef"; + +/// Install the test build identity, for tests that read cache keys or rule fingerprints. +pub(crate) fn install_test_identity() { + install_build_identity(TEST_BUILD_IDENTITY).expect("tests install only the test identity"); +} diff --git a/fensu.toml b/fensu.toml index b982896a8b..6c20eb1d09 100644 --- a/fensu.toml +++ b/fensu.toml @@ -1387,6 +1387,10 @@ rule = "FFR601" path = "src/sqlbuild/adapters/sqlserver/classes/sqlserver_adapter.py" reason = "The SQL Server adapter intentionally keeps overrideable backend behavior on one class." +[[dupes.allowlist]] +paths = ["crates/sqlbuild-rules/src/custom_rule_cache/main/parse_custom_rule_cache.rs", "crates/sqlbuild-rules/src/rule_cache/main/parse_rule_cache.rs"] +reason = "Each reads its own cache format: the SQL rule cache checks its version and the build identity and returns findings by path, the custom-rule cache checks only its version, because its identities already include the build, and returns rules by code. Only the parse-and-filter shape is alike." + [[dupes.allowlist]] paths = ["crates/sqlbuild-orchestration/src/api/_helpers/resources/administrators.rs", "crates/sqlbuild-orchestration/src/api/_helpers/resources/audit.rs", "crates/sqlbuild-orchestration/src/api/_helpers/resources/location_health.rs", "crates/sqlbuild-orchestration/src/api/_helpers/resources/location_work.rs", "crates/sqlbuild-orchestration/src/api/_helpers/resources/person_checks.rs", "crates/sqlbuild-orchestration/src/api/_helpers/resources/person_location_work.rs", "crates/sqlbuild-orchestration/src/api/_helpers/resources/person_maintenance.rs", "crates/sqlbuild-orchestration/src/api/_helpers/resources/person_node_sql.rs", "crates/sqlbuild-orchestration/src/api/_helpers/resources/person_operations.rs", "crates/sqlbuild-orchestration/src/api/_helpers/resources/person_plans.rs", "crates/sqlbuild-orchestration/src/api/_helpers/resources/person_reads.rs", "crates/sqlbuild-orchestration/src/api/_helpers/resources/run_reads.rs", "crates/sqlbuild-orchestration/src/api/_helpers/resources/runs.rs", "crates/sqlbuild-orchestration/src/api/_helpers/resources/snapshots.rs", "crates/sqlbuild-orchestration/src/api/_helpers/resources/trigger_reads.rs", "crates/sqlbuild-orchestration/src/api/_helpers/resources/warehouse_metadata.rs"] reason = "Each function is one utoipa-annotated axum route: OpenAPI needs one annotated handler per operation, and each body only checks the caller's scope and calls one store operation. Scope checks and store work live in their shared owners." @@ -1699,7 +1703,7 @@ select = ["FPRS", "XSB072", "XSB073", "XSB075", "XSB076", "XSB077", "XSB078", "X [[targets.rust.threshold_overrides]] paths = ["crates/sqlbuild-python/Cargo.toml"] -thresholds = { max_crate_code_lines = 206335 } +thresholds = { max_crate_code_lines = 206338 } reason = "The Python bindings crate is above the code-line limit; this caps it at its current size until it is split into crates by area. Lower the cap as code moves out." [[targets.rust.threshold_overrides]] @@ -1822,6 +1826,12 @@ rule = "FPRSS201" path = "crates/sqlbuild-analysis/src/assembly/analysis_session/models.rs" reason = "NullabilityCallback implements Debug manually because it holds the adapter's nullability rule closure, which cannot implement Debug; other models derive it." +[[targets.rust.rule_exceptions]] +rule = "FPRSH003" +path = "crates/sqlbuild-rules/src/build_identity/main/native_build_identity.rs" +symbols = ["native_build_identity"] +reason = "Every native entry point installs the build identity before anything reads it, so a missing identity is a programming error in a binary. Caches and rule fingerprints must never key on a substitute, and threading a Result through every infallible cache key and catalogue reader would only re-raise the same failure; a test covers the panic in a fresh process." + [[targets.rust.rule_exceptions]] rule = "FPRSS130" path = "crates/sqlbuild-python/src/bindings/_helpers/native_threads/exit_signal.rs" @@ -1897,6 +1907,7 @@ crate_names = [ "sqlbuild-analysis", "sqlbuild-attachments", "sqlbuild-build-features", + "sqlbuild-build-identity", "sqlbuild-cache", "sqlbuild-cli", "sqlbuild-config",