From a29079924356fb4a71f79db207db1d5ecc92dd0e Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Sat, 14 Nov 2026 08:30:39 +0000 Subject: [PATCH 1/4] chore(release): publish fensu-facts and fensu-native for Rust consumers --- Cargo.toml | 2 +- crates/fensu-facts/Cargo.toml | 7 ++++++- crates/fensu-facts/README.md | 3 +++ crates/fensu-native/Cargo.toml | 7 ++++++- crates/fensu-native/README.md | 3 +++ 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 crates/fensu-facts/README.md create mode 100644 crates/fensu-native/README.md diff --git a/Cargo.toml b/Cargo.toml index db178c92..cfb49b83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ rusqlite = { version = "0.38", features = ["bundled"] } serde_json = { version = "1", features = ["preserve_order"] } serde = { version = "1", features = ["derive"] } sha2 = "0.10" -fensu-facts = { path = "crates/fensu-facts", default-features = false } +fensu-facts = { path = "crates/fensu-facts", version = "0.1.0", default-features = false } fensu-native = { path = "crates/fensu-native", default-features = false } fensu-policy = { path = "crates/fensu-policy" } fensu-rust = { path = "crates/fensu-rust" } diff --git a/crates/fensu-facts/Cargo.toml b/crates/fensu-facts/Cargo.toml index cf92fb97..142400fe 100644 --- a/crates/fensu-facts/Cargo.toml +++ b/crates/fensu-facts/Cargo.toml @@ -3,7 +3,12 @@ name = "fensu-facts" version = "0.1.0" edition.workspace = true license.workspace = true -publish = false +publish = true +description = "Python source facts for Fensu: parsed modules, imports, symbols and file inventory" +repository = "https://github.com/sqlstack-io/fensu" +readme = "README.md" +keywords = ["lint", "architecture", "python", "static-analysis"] +categories = ["development-tools"] rust-version.workspace = true [lints] diff --git a/crates/fensu-facts/README.md b/crates/fensu-facts/README.md new file mode 100644 index 00000000..19ddc37d --- /dev/null +++ b/crates/fensu-facts/README.md @@ -0,0 +1,3 @@ +# fensu-facts + +Part of [Fensu](https://github.com/sqlstack-io/fensu). Use it from Rust with `default-features = false` to leave out the Python bindings. diff --git a/crates/fensu-native/Cargo.toml b/crates/fensu-native/Cargo.toml index f97caf07..cb9bd86f 100644 --- a/crates/fensu-native/Cargo.toml +++ b/crates/fensu-native/Cargo.toml @@ -3,7 +3,12 @@ name = "fensu-native" version = "0.1.0" edition.workspace = true license.workspace = true -publish = false +publish = true +description = "Fensu's core rule engine and Python rules, usable from Rust without the Python bindings" +repository = "https://github.com/sqlstack-io/fensu" +readme = "README.md" +keywords = ["lint", "architecture", "python", "static-analysis"] +categories = ["development-tools"] rust-version.workspace = true [lints] diff --git a/crates/fensu-native/README.md b/crates/fensu-native/README.md new file mode 100644 index 00000000..b462050b --- /dev/null +++ b/crates/fensu-native/README.md @@ -0,0 +1,3 @@ +# fensu-native + +Part of [Fensu](https://github.com/sqlstack-io/fensu). Use it from Rust with `default-features = false` to leave out the Python bindings. From fed54300ebad85c9b0f797ec00b4b8faea993105 Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Sat, 14 Nov 2026 08:58:21 +0000 Subject: [PATCH 2/4] feat: give fensu-facts and fensu-native a deliberate Rust API and release them with Fensu --- .../scripts/verify_shared_crate_packages.sh | 45 ++++++++++++++++ .github/workflows/publish.yml | 12 ++++- .github/workflows/verify.yml | 5 +- Cargo.lock | 4 +- Cargo.toml | 2 +- .../src/check/_helpers/evaluation.rs | 21 +++----- .../fensu-cli/src/check/_helpers/project.rs | 4 +- .../src/configuration/_helpers/parsing.rs | 2 +- crates/fensu-facts/Cargo.toml | 2 +- crates/fensu-facts/README.md | 10 +++- crates/fensu-facts/src/extension/models.rs | 5 ++ crates/fensu-facts/src/lib.rs | 14 ++++- .../src/syntax/main/breadth_first_from.rs | 2 +- .../src/syntax/main/breadth_first_nodes.rs | 2 +- .../syntax/main/breadth_first_with_parents.rs | 4 +- .../fensu-facts/src/syntax/main/children.rs | 2 +- .../fensu-facts/src/syntax/main/kind_name.rs | 2 +- crates/fensu-facts/src/syntax/main/mod.rs | 18 +++---- .../src/syntax/main/push_clause_orelse.rs | 2 +- crates/fensu-facts/src/syntax/main/span.rs | 2 +- .../fensu-facts/src/syntax/main/start_of.rs | 2 +- .../src/syntax/main/strict_reference_parts.rs | 2 +- crates/fensu-facts/src/syntax/mod.rs | 6 +-- crates/fensu-facts/src/syntax/types.rs | 2 +- crates/fensu-native/Cargo.toml | 8 +-- crates/fensu-native/README.md | 25 ++++++++- crates/fensu-native/src/extension/main/mod.rs | 2 +- .../src/extension/main/register_module.rs | 2 +- crates/fensu-native/src/extension/mod.rs | 2 +- crates/fensu-native/src/lib.rs | 19 +++++-- crates/fensu-native/src/rules/main/mod.rs | 12 ++--- crates/fensu-native/src/rules/mod.rs | 8 +-- crates/fensu-native/tests/rules/helpers.rs | 22 ++++---- .../tests/rules/test_contracts.rs | 6 +-- crates/fensu-native/tests/rules/test_types.rs | 2 +- release-please-config.json | 12 +++++ .../release_metadata/_helpers/validation.py | 53 +++++++++++++++++++ scripts/release_metadata/constants.py | 9 +++- .../main/test_validate_release_delta.py | 47 ++++++++++++++++ 39 files changed, 314 insertions(+), 87 deletions(-) diff --git a/.github/scripts/verify_shared_crate_packages.sh b/.github/scripts/verify_shared_crate_packages.sh index 267b3483..0c39a46a 100755 --- a/.github/scripts/verify_shared_crate_packages.sh +++ b/.github/scripts/verify_shared_crate_packages.sh @@ -14,3 +14,48 @@ cargo +stable new --quiet --lib "${consumer_root}/consumer" cargo +stable add --quiet --manifest-path "${consumer_root}/consumer/Cargo.toml" \ --path "${package_root}/package/fensu-policy-${version}" cargo +1.85.0 check --locked --manifest-path "${consumer_root}/consumer/Cargo.toml" + +# The Python analysis crates are packaged together, as fensu-native depends on fensu-facts. A fresh +# project then runs the core rules without default features, and must not pull in the Python +# bindings or the cache's SQLite and compression libraries. +analysis_version="$(cargo +1.95.0 metadata --locked --no-deps --format-version 1 \ + | jq -r '.packages[] | select(.name == "fensu-native") | .version')" +facts_package="${package_root}/package/fensu-facts-${analysis_version}" +native_package="${package_root}/package/fensu-native-${analysis_version}" +analysis_consumer="${consumer_root}/analysis-consumer" + +CARGO_TARGET_DIR="${package_root}" cargo +1.95.0 package --locked -p fensu-facts -p fensu-native + +cargo +stable new --quiet --bin "${analysis_consumer}" +cat >> "${analysis_consumer}/Cargo.toml" < "${analysis_consumer}/src/main.rs" <<'RUST' +use fensu_facts::ProgramHandle; +use fensu_native::rules::constants::PARAMETER_ANNOTATION_CODE; +use fensu_native::{evaluate_core_rules, NativeProjectPlane, NativeRuleContext}; + +fn main() { + let program = ProgramHandle::parse_source("def total(items):\n return items\n", 3, 12) + .expect("the module parses"); + let faults = evaluate_core_rules( + &program, + &[PARAMETER_ANNOTATION_CODE.to_owned()], + &NativeRuleContext::default(), + &NativeProjectPlane::new(Vec::new(), Vec::new()), + ) + .expect("the core rules run"); + assert_eq!(faults.len(), 1, "one unannotated parameter: {faults:?}"); + assert_eq!(faults[0].code, PARAMETER_ANNOTATION_CODE); +} +RUST +cargo +1.95.0 run --quiet --manifest-path "${analysis_consumer}/Cargo.toml" +if cargo +1.95.0 tree --manifest-path "${analysis_consumer}/Cargo.toml" -e normal \ + | grep -E '\b(pyo3|rusqlite|flate2) v'; then + echo "the analysis crates pulled in Python, SQLite or compression dependencies" >&2 + exit 1 +fi diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6d36eb9d..1ac10b8c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -63,6 +63,8 @@ jobs: ("CLI package", "packages/fensu-cli/pyproject.toml"), ("CLI crate", "crates/fensu-cli/Cargo.toml"), ("policy crate", "crates/fensu-policy/Cargo.toml"), + ("facts crate", "crates/fensu-facts/Cargo.toml"), + ("native crate", "crates/fensu-native/Cargo.toml"), ]: with Path(path).open("rb") as file: document = tomllib.load(file) @@ -197,6 +199,9 @@ jobs: - uses: dtolnay/rust-toolchain@master with: toolchain: 1.85.0 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.95.0 - name: Refresh released workspace versions in lockfile run: cargo +1.85.0 metadata --format-version 1 > /dev/null - name: Verify shared crate packages @@ -210,6 +215,7 @@ jobs: run: | publish_if_missing() { package="$1" + toolchain="$2" version="$(cargo metadata --no-deps --format-version 1 \ | jq -r --arg package "${package}" '.packages[] | select(.name == $package) | .version')" status="$(curl --retry 3 --silent --show-error --output /dev/null \ @@ -220,7 +226,7 @@ jobs: echo "${package} ${version} is already published" ;; 404) - cargo publish --locked -p "${package}" + cargo "+${toolchain}" publish --locked -p "${package}" ;; *) echo "Could not determine ${package} ${version} publication status: HTTP ${status}" >&2 @@ -229,7 +235,9 @@ jobs: esac } - publish_if_missing fensu-policy + publish_if_missing fensu-facts 1.95.0 + publish_if_missing fensu-native 1.95.0 + publish_if_missing fensu-policy 1.85.0 pypi: name: Publish to PyPI diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index b171340a..48fc16c1 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -113,13 +113,16 @@ jobs: - run: make test-rust shared-crates: - name: Shared crate packages (Rust 1.85) + name: Shared crate packages needs: changes if: needs.changes.outputs.full == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.95.0 - uses: dtolnay/rust-toolchain@master with: toolchain: 1.85.0 diff --git a/Cargo.lock b/Cargo.lock index 267e62f8..63c93f59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -424,7 +424,7 @@ dependencies = [ [[package]] name = "fensu-facts" -version = "0.1.0" +version = "0.29.3" dependencies = [ "dunce", "globset", @@ -440,7 +440,7 @@ dependencies = [ [[package]] name = "fensu-native" -version = "0.1.0" +version = "0.29.3" dependencies = [ "fensu-facts", "flate2", diff --git a/Cargo.toml b/Cargo.toml index cfb49b83..b3a9d844 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ rusqlite = { version = "0.38", features = ["bundled"] } serde_json = { version = "1", features = ["preserve_order"] } serde = { version = "1", features = ["derive"] } sha2 = "0.10" -fensu-facts = { path = "crates/fensu-facts", version = "0.1.0", default-features = false } +fensu-facts = { path = "crates/fensu-facts", version = "0.29.3", default-features = false } # x-release-please-version fensu-native = { path = "crates/fensu-native", default-features = false } fensu-policy = { path = "crates/fensu-policy" } fensu-rust = { path = "crates/fensu-rust" } diff --git a/crates/fensu-cli/src/check/_helpers/evaluation.rs b/crates/fensu-cli/src/check/_helpers/evaluation.rs index 3440ce12..fbd37dd3 100644 --- a/crates/fensu-cli/src/check/_helpers/evaluation.rs +++ b/crates/fensu-cli/src/check/_helpers/evaluation.rs @@ -2,10 +2,10 @@ use std::collections::{HashMap, HashSet}; use std::path::Path; use fensu_facts::extension::models::ProgramHandle; -use fensu_native::rules::main::evaluate_core_rules::evaluate_core_rules; -use fensu_native::rules::main::plan_core_rule_queries::plan_core_rule_queries; -use fensu_native::rules::main::plan_execution_owners::plan_execution_owners; -use fensu_native::rules::models::{NativeExecutionRule, NativeExecutionTarget, NativeRuleContext}; +use fensu_native::evaluate_core_rules; +use fensu_native::plan_core_rule_queries; +use fensu_native::plan_execution_owners; +use fensu_native::{NativeExecutionRule, NativeExecutionTarget, NativeRuleContext}; use fensu_policy::lifecycle::models::FindingSeverity; use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator}; @@ -169,11 +169,7 @@ pub(crate) fn evaluate(request: EvaluationRequest<'_>) -> Result>(); - for row in fensu_native::rules::main::evaluate_dead_code::evaluate_dead_code( - &codes, - &dead_code_context, - &project, - ) { + for row in fensu_native::evaluate_dead_code(&codes, &dead_code_context, &project) { let metadata = rule_metadata(&row.code)? .ok_or_else(|| format!("Unknown native rule code: {}", row.code))?; faults.push(Fault { @@ -239,10 +235,7 @@ pub(crate) fn evaluate(request: EvaluationRequest<'_>) -> Result fensu_native::rules::models::NativeDeadCodeContext { +fn dead_code_context(config: &Config, project_root: &Path) -> fensu_native::NativeDeadCodeContext { const PYPROJECT_SOURCE: &str = "pyproject"; if !config.dead_code.enabled { return Default::default(); @@ -256,7 +249,7 @@ fn dead_code_context( } else { "fensu.toml" }; - fensu_native::rules::models::NativeDeadCodeContext { + fensu_native::NativeDeadCodeContext { enabled: config.dead_code.enabled, roots: config .dead_code diff --git a/crates/fensu-cli/src/check/_helpers/project.rs b/crates/fensu-cli/src/check/_helpers/project.rs index be10d2c8..9d331228 100644 --- a/crates/fensu-cli/src/check/_helpers/project.rs +++ b/crates/fensu-cli/src/check/_helpers/project.rs @@ -5,7 +5,7 @@ use std::fs; use std::path::{Component, Path, PathBuf}; use fensu_facts::extension::models::ProgramHandle; -use fensu_native::rules::models::{NativeProjectModule, NativeProjectPlane}; +use fensu_native::{NativeProjectModule, NativeProjectPlane}; use globset::GlobBuilder; use serde_json::Value; use walkdir::DirEntry; @@ -215,7 +215,7 @@ fn collect_entrypoint_values<'a>(value: &'a toml::Value, mut values: Vec<&'a str pub(crate) fn observe( root: &Path, - plans: &[fensu_native::rules::models::NativeProjectQuery], + plans: &[fensu_native::NativeProjectQuery], programs: &HashMap<&str, &ProgramHandle>, modules: &HashMap, ) -> Result>, String> { diff --git a/crates/fensu-cli/src/configuration/_helpers/parsing.rs b/crates/fensu-cli/src/configuration/_helpers/parsing.rs index 302ca5d3..e5c2dc1f 100644 --- a/crates/fensu-cli/src/configuration/_helpers/parsing.rs +++ b/crates/fensu-cli/src/configuration/_helpers/parsing.rs @@ -148,7 +148,7 @@ pub(crate) fn parse_dead_code( value: Option<&toml::Value>, ) -> Result { let value = serde_json::to_value(value).map_err(|error| error.to_string())?; - let (enabled, roots) = fensu_native::rules::main::parse_dead_code::parse_dead_code(&value)?; + let (enabled, roots) = fensu_native::parse_dead_code(&value)?; Ok(crate::models::DeadCodeConfig { enabled, roots: roots diff --git a/crates/fensu-facts/Cargo.toml b/crates/fensu-facts/Cargo.toml index 142400fe..433298b8 100644 --- a/crates/fensu-facts/Cargo.toml +++ b/crates/fensu-facts/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fensu-facts" -version = "0.1.0" +version = "0.29.3" # x-release-please-version edition.workspace = true license.workspace = true publish = true diff --git a/crates/fensu-facts/README.md b/crates/fensu-facts/README.md index 19ddc37d..88255e43 100644 --- a/crates/fensu-facts/README.md +++ b/crates/fensu-facts/README.md @@ -1,3 +1,11 @@ # fensu-facts -Part of [Fensu](https://github.com/sqlstack-io/fensu). Use it from Rust with `default-features = false` to leave out the Python bindings. +Python source facts for [Fensu](https://github.com/sqlstack-io/fensu): parse a module once into a `ProgramHandle`, then read its fact rows. + +```toml +fensu-facts = { version = "0.30", default-features = false } +``` + +`default-features = false` leaves out the Python bindings. + +The public API is `ProgramHandle` (built with `ProgramHandle::parse_source(source, major, minor)`), `ParseFailure`, and the row types in `facts`. Modules hidden from the documentation are shared with the rest of Fensu's workspace and may change in any release. diff --git a/crates/fensu-facts/src/extension/models.rs b/crates/fensu-facts/src/extension/models.rs index 5376c8c3..b8a6476f 100644 --- a/crates/fensu-facts/src/extension/models.rs +++ b/crates/fensu-facts/src/extension/models.rs @@ -83,6 +83,11 @@ pub struct ProgramHandle { } impl ProgramHandle { + /// Parse `source` as a Python `major.minor` module. + pub fn parse_source(source: &str, major: u8, minor: u8) -> Result { + Self::parse(source, PythonVersion { major, minor }) + } + pub(crate) fn parse(source: &str, version: PythonVersion) -> Result { let parsed = parse_strict(source, version)?; Ok(Self { diff --git a/crates/fensu-facts/src/lib.rs b/crates/fensu-facts/src/lib.rs index dd48eb8a..b9763d73 100644 --- a/crates/fensu-facts/src/lib.rs +++ b/crates/fensu-facts/src/lib.rs @@ -1,12 +1,22 @@ -//! Native fact-extraction core for fensu. +//! Python source facts for Fensu: [`ProgramHandle`] parses a module once and serves its fact rows. #![forbid(unsafe_code)] +#[doc(hidden)] pub mod constants; +#[doc(hidden)] pub mod dead_code; +#[doc(hidden)] pub mod extension; pub mod facts; +#[doc(hidden)] pub mod mapping; +#[doc(hidden)] pub mod parsing; +#[doc(hidden)] pub mod positions; +#[doc(hidden)] pub mod snapshot; -pub mod syntax; +pub(crate) mod syntax; + +pub use extension::models::ProgramHandle; +pub use parsing::models::ParseFailure; diff --git a/crates/fensu-facts/src/syntax/main/breadth_first_from.rs b/crates/fensu-facts/src/syntax/main/breadth_first_from.rs index 61fb8070..ed06edb1 100644 --- a/crates/fensu-facts/src/syntax/main/breadth_first_from.rs +++ b/crates/fensu-facts/src/syntax/main/breadth_first_from.rs @@ -1,6 +1,6 @@ //! Walk breadth first from one node. use crate::syntax::types::ShapeNode; -pub fn breadth_first_from(root: ShapeNode<'_>) -> Vec> { +pub(crate) fn breadth_first_from(root: ShapeNode<'_>) -> Vec> { crate::syntax::_helpers::breadth::breadth_first_from(root) } diff --git a/crates/fensu-facts/src/syntax/main/breadth_first_nodes.rs b/crates/fensu-facts/src/syntax/main/breadth_first_nodes.rs index 73b6e530..f2a65b10 100644 --- a/crates/fensu-facts/src/syntax/main/breadth_first_nodes.rs +++ b/crates/fensu-facts/src/syntax/main/breadth_first_nodes.rs @@ -3,6 +3,6 @@ use ruff_python_ast::ModModule; use crate::syntax::types::ShapeNode; -pub fn breadth_first_nodes(module: &ModModule) -> Vec> { +pub(crate) fn breadth_first_nodes(module: &ModModule) -> Vec> { crate::syntax::_helpers::breadth::breadth_first_nodes(module) } diff --git a/crates/fensu-facts/src/syntax/main/breadth_first_with_parents.rs b/crates/fensu-facts/src/syntax/main/breadth_first_with_parents.rs index b92b78c9..d37c7386 100644 --- a/crates/fensu-facts/src/syntax/main/breadth_first_with_parents.rs +++ b/crates/fensu-facts/src/syntax/main/breadth_first_with_parents.rs @@ -3,6 +3,8 @@ use ruff_python_ast::ModModule; use crate::syntax::types::ShapeNode; -pub fn breadth_first_with_parents(module: &ModModule) -> (Vec>, Vec>) { +pub(crate) fn breadth_first_with_parents( + module: &ModModule, +) -> (Vec>, Vec>) { crate::syntax::_helpers::breadth::breadth_first_with_parents(module) } diff --git a/crates/fensu-facts/src/syntax/main/children.rs b/crates/fensu-facts/src/syntax/main/children.rs index 64d3c362..e119def0 100644 --- a/crates/fensu-facts/src/syntax/main/children.rs +++ b/crates/fensu-facts/src/syntax/main/children.rs @@ -3,6 +3,6 @@ use crate::syntax::_helpers::children::ChildOutput; use crate::syntax::types::ShapeNode; -pub fn children<'a>(node: &ShapeNode<'a>, out: &mut Vec>) { +pub(crate) fn children<'a>(node: &ShapeNode<'a>, out: &mut Vec>) { ChildOutput { out }.collect(node); } diff --git a/crates/fensu-facts/src/syntax/main/kind_name.rs b/crates/fensu-facts/src/syntax/main/kind_name.rs index 5c060097..6a5e4d47 100644 --- a/crates/fensu-facts/src/syntax/main/kind_name.rs +++ b/crates/fensu-facts/src/syntax/main/kind_name.rs @@ -1,6 +1,6 @@ //! Name the syntax kind of a node. use crate::syntax::types::ShapeNode; -pub fn kind_name(node: &ShapeNode<'_>) -> &'static str { +pub(crate) fn kind_name(node: &ShapeNode<'_>) -> &'static str { crate::syntax::_helpers::nodes::kind_name(node) } diff --git a/crates/fensu-facts/src/syntax/main/mod.rs b/crates/fensu-facts/src/syntax/main/mod.rs index 2616c074..d360283c 100644 --- a/crates/fensu-facts/src/syntax/main/mod.rs +++ b/crates/fensu-facts/src/syntax/main/mod.rs @@ -1,11 +1,11 @@ //! Syntax entries. -pub mod breadth_first_from; -pub mod breadth_first_nodes; -pub mod breadth_first_with_parents; -pub mod children; -pub mod kind_name; -pub mod push_clause_orelse; -pub mod span; -pub mod start_of; -pub mod strict_reference_parts; +pub(crate) mod breadth_first_from; +pub(crate) mod breadth_first_nodes; +pub(crate) mod breadth_first_with_parents; +pub(crate) mod children; +pub(crate) mod kind_name; +pub(crate) mod push_clause_orelse; +pub(crate) mod span; +pub(crate) mod start_of; +pub(crate) mod strict_reference_parts; diff --git a/crates/fensu-facts/src/syntax/main/push_clause_orelse.rs b/crates/fensu-facts/src/syntax/main/push_clause_orelse.rs index c3b07ceb..d7c35e4d 100644 --- a/crates/fensu-facts/src/syntax/main/push_clause_orelse.rs +++ b/crates/fensu-facts/src/syntax/main/push_clause_orelse.rs @@ -5,6 +5,6 @@ use ruff_python_ast::ElifElseClause; use crate::syntax::_helpers::statement_children::ClauseOutput; use crate::syntax::types::ShapeNode; -pub fn push_clause_orelse<'a>(clauses: &'a [ElifElseClause], out: &mut Vec>) { +pub(crate) fn push_clause_orelse<'a>(clauses: &'a [ElifElseClause], out: &mut Vec>) { ClauseOutput { out }.collect(clauses); } diff --git a/crates/fensu-facts/src/syntax/main/span.rs b/crates/fensu-facts/src/syntax/main/span.rs index b6de1021..0d6a454e 100644 --- a/crates/fensu-facts/src/syntax/main/span.rs +++ b/crates/fensu-facts/src/syntax/main/span.rs @@ -3,6 +3,6 @@ use crate::positions::models::{LineIndex, SourceSpan}; use crate::syntax::types::ShapeNode; -pub fn span(node: &ShapeNode<'_>, index: &LineIndex, source: &str) -> Option { +pub(crate) fn span(node: &ShapeNode<'_>, index: &LineIndex, source: &str) -> Option { crate::syntax::_helpers::spans::span(node, index, source) } diff --git a/crates/fensu-facts/src/syntax/main/start_of.rs b/crates/fensu-facts/src/syntax/main/start_of.rs index ba3ce0ea..d9e87d81 100644 --- a/crates/fensu-facts/src/syntax/main/start_of.rs +++ b/crates/fensu-facts/src/syntax/main/start_of.rs @@ -3,6 +3,6 @@ use crate::positions::models::LineIndex; use crate::syntax::types::ShapeNode; -pub fn start_of(node: &ShapeNode<'_>, index: &LineIndex, source: &str) -> (u32, u32) { +pub(crate) fn start_of(node: &ShapeNode<'_>, index: &LineIndex, source: &str) -> (u32, u32) { crate::syntax::_helpers::spans::start_of(node, index, source) } diff --git a/crates/fensu-facts/src/syntax/main/strict_reference_parts.rs b/crates/fensu-facts/src/syntax/main/strict_reference_parts.rs index 06763f2f..57afc8eb 100644 --- a/crates/fensu-facts/src/syntax/main/strict_reference_parts.rs +++ b/crates/fensu-facts/src/syntax/main/strict_reference_parts.rs @@ -2,6 +2,6 @@ use ruff_python_ast::Expr; -pub fn strict_reference_parts(expression: &Expr) -> Vec { +pub(crate) fn strict_reference_parts(expression: &Expr) -> Vec { crate::syntax::_helpers::references::strict_reference_parts(expression) } diff --git a/crates/fensu-facts/src/syntax/mod.rs b/crates/fensu-facts/src/syntax/mod.rs index 102a748a..4b7a5245 100644 --- a/crates/fensu-facts/src/syntax/mod.rs +++ b/crates/fensu-facts/src/syntax/mod.rs @@ -1,5 +1,5 @@ //! Python syntax primitives shared across fact extraction and call mapping. -pub mod _helpers; -pub mod main; -pub mod types; +pub(crate) mod _helpers; +pub(crate) mod main; +pub(crate) mod types; diff --git a/crates/fensu-facts/src/syntax/types.rs b/crates/fensu-facts/src/syntax/types.rs index 9363aab1..9ef9389a 100644 --- a/crates/fensu-facts/src/syntax/types.rs +++ b/crates/fensu-facts/src/syntax/types.rs @@ -9,7 +9,7 @@ use ruff_text_size::TextRange; /// One node of the CPython-equivalent syntax tree projected from ruff nodes. #[derive(Clone, Copy)] -pub enum ShapeNode<'a> { +pub(crate) enum ShapeNode<'a> { Module(&'a ModModule), Stmt(&'a Stmt), IfTail(&'a [ElifElseClause]), diff --git a/crates/fensu-native/Cargo.toml b/crates/fensu-native/Cargo.toml index cb9bd86f..f1f1562a 100644 --- a/crates/fensu-native/Cargo.toml +++ b/crates/fensu-native/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fensu-native" -version = "0.1.0" +version = "0.29.3" # x-release-please-version edition.workspace = true license.workspace = true publish = true @@ -20,12 +20,12 @@ path = "src/lib.rs" crate-type = ["cdylib", "rlib"] [dependencies] -flate2.workspace = true +flate2 = { workspace = true, optional = true } globset.workspace = true pyo3 = { workspace = true, optional = true } rayon.workspace = true ruff_python_ast.workspace = true -rusqlite.workspace = true +rusqlite = { workspace = true, optional = true } sha2.workspace = true serde_json.workspace = true fensu-facts = { workspace = true, default-features = false } @@ -34,7 +34,7 @@ unicode-ident.workspace = true [features] default = ["python"] extension-module = ["python", "pyo3/extension-module"] -python = ["dep:pyo3", "fensu-facts/python"] +python = ["dep:pyo3", "dep:rusqlite", "dep:flate2", "fensu-facts/python"] [dev-dependencies] serde.workspace = true diff --git a/crates/fensu-native/README.md b/crates/fensu-native/README.md index b462050b..23c6b74f 100644 --- a/crates/fensu-native/README.md +++ b/crates/fensu-native/README.md @@ -1,3 +1,26 @@ # fensu-native -Part of [Fensu](https://github.com/sqlstack-io/fensu). Use it from Rust with `default-features = false` to leave out the Python bindings. +[Fensu](https://github.com/sqlstack-io/fensu)'s Python rule engine: core rules and dead-code analysis over programs parsed by `fensu-facts`. + +```toml +fensu-facts = { version = "0.30", default-features = false } +fensu-native = { version = "0.30", default-features = false } +``` + +`default-features = false` leaves out the Python bindings and the cache, and their SQLite and compression dependencies. + +The public API is at the crate root: `evaluate_core_rules`, `evaluate_dead_code`, `parse_dead_code`, `plan_core_rule_queries`, `plan_execution_owners`, `generated_policy_owners`, and their models such as `NativeRuleContext`, `NativeProjectPlane` and `NativeFaultRow`. Rule codes are in `rules::constants`. + +```rust +use fensu_facts::ProgramHandle; +use fensu_native::{evaluate_core_rules, NativeProjectPlane, NativeRuleContext}; +use fensu_native::rules::constants::PARAMETER_ANNOTATION_CODE; + +let program = ProgramHandle::parse_source("def total(items):\n return items\n", 3, 12)?; +let faults = evaluate_core_rules( + &program, + &[PARAMETER_ANNOTATION_CODE.to_owned()], + &NativeRuleContext::default(), + &NativeProjectPlane::new(Vec::new(), Vec::new()), +)?; +``` diff --git a/crates/fensu-native/src/extension/main/mod.rs b/crates/fensu-native/src/extension/main/mod.rs index 9503835e..f7270cb8 100644 --- a/crates/fensu-native/src/extension/main/mod.rs +++ b/crates/fensu-native/src/extension/main/mod.rs @@ -1,3 +1,3 @@ //! Extension registration entry modules. -pub mod register_module; +pub(crate) mod register_module; diff --git a/crates/fensu-native/src/extension/main/register_module.rs b/crates/fensu-native/src/extension/main/register_module.rs index c9c0202c..3e06099e 100644 --- a/crates/fensu-native/src/extension/main/register_module.rs +++ b/crates/fensu-native/src/extension/main/register_module.rs @@ -9,7 +9,7 @@ use pyo3::wrap_pyfunction; /// Register Fensu's private native Python module. #[pymodule] -pub fn _native(module: &Bound<'_, PyModule>) -> PyResult<()> { +pub(crate) fn _native(module: &Bound<'_, PyModule>) -> PyResult<()> { fensu_facts::extension::main::register_module::register_fact_functions(module)?; module.add_class::()?; module.add_function(wrap_pyfunction!( diff --git a/crates/fensu-native/src/extension/mod.rs b/crates/fensu-native/src/extension/mod.rs index 34082a4c..da035fb2 100644 --- a/crates/fensu-native/src/extension/mod.rs +++ b/crates/fensu-native/src/extension/mod.rs @@ -2,4 +2,4 @@ pub(crate) mod _helpers; pub(crate) mod constants; -pub mod main; +pub(crate) mod main; diff --git a/crates/fensu-native/src/lib.rs b/crates/fensu-native/src/lib.rs index c19ed40f..affbae49 100644 --- a/crates/fensu-native/src/lib.rs +++ b/crates/fensu-native/src/lib.rs @@ -1,8 +1,21 @@ -//! Private native extension for Fensu capabilities. +//! Fensu's Python rule engine over `fensu-facts` programs; use it with `default-features = false`. #![forbid(unsafe_code)] #[cfg(feature = "python")] -pub mod cache; +pub(crate) mod cache; #[cfg(feature = "python")] -pub mod extension; +pub(crate) mod extension; pub mod rules; + +pub use crate::rules::main::evaluate_core_rules::evaluate_core_rules; +pub use crate::rules::main::evaluate_dead_code::evaluate_dead_code; +pub use crate::rules::main::generated_policy_owners::generated_policy_owners; +pub use crate::rules::main::parse_dead_code::parse_dead_code; +pub use crate::rules::main::plan_core_rule_queries::plan_core_rule_queries; +pub use crate::rules::main::plan_execution_owners::plan_execution_owners; +pub use crate::rules::models::{ + CustomRegistration, NativeDeadCodeContext, NativeExecutionPlan, NativeExecutionRule, + NativeExecutionTarget, NativeFaultRow, NativeProjectModule, NativeProjectPlane, + NativeProjectQuery, NativeRuleContext, +}; +pub use crate::rules::types::NativeDeadCodeSettings; diff --git a/crates/fensu-native/src/rules/main/mod.rs b/crates/fensu-native/src/rules/main/mod.rs index 116a0fb0..2da72ac7 100644 --- a/crates/fensu-native/src/rules/main/mod.rs +++ b/crates/fensu-native/src/rules/main/mod.rs @@ -1,8 +1,8 @@ //! Native core-rule evaluation entries. -pub mod evaluate_core_rules; -pub mod evaluate_dead_code; -pub mod generated_policy_owners; -pub mod parse_dead_code; -pub mod plan_core_rule_queries; -pub mod plan_execution_owners; +pub(crate) mod evaluate_core_rules; +pub(crate) mod evaluate_dead_code; +pub(crate) mod generated_policy_owners; +pub(crate) mod parse_dead_code; +pub(crate) mod plan_core_rule_queries; +pub(crate) mod plan_execution_owners; diff --git a/crates/fensu-native/src/rules/mod.rs b/crates/fensu-native/src/rules/mod.rs index 1ad2743d..6193fef5 100644 --- a/crates/fensu-native/src/rules/mod.rs +++ b/crates/fensu-native/src/rules/mod.rs @@ -1,7 +1,7 @@ -//! Native core-rule kernels over shared fact rows. +//! Core rules and dead-code analysis; the rule codes are public in [`constants`]. pub(crate) mod _helpers; pub mod constants; -pub mod main; -pub mod models; -pub mod types; +pub(crate) mod main; +pub(crate) mod models; +pub(crate) mod types; diff --git a/crates/fensu-native/tests/rules/helpers.rs b/crates/fensu-native/tests/rules/helpers.rs index aa79a3d5..f6294579 100644 --- a/crates/fensu-native/tests/rules/helpers.rs +++ b/crates/fensu-native/tests/rules/helpers.rs @@ -5,9 +5,9 @@ use std::fs; use std::path::Path; use fensu_facts::extension::models::ProgramHandle; +use fensu_native::evaluate_core_rules; use fensu_native::rules::constants::NATIVE_RULE_FACT_FAMILIES; -use fensu_native::rules::main::evaluate_core_rules::evaluate_core_rules; -use fensu_native::rules::models::{ +use fensu_native::{ NativeDeadCodeContext, NativeProjectModule, NativeProjectPlane, NativeRuleContext, }; use ruff_python_ast::PythonVersion; @@ -159,16 +159,14 @@ fn evaluate_fixture(test_case: &CoreRuleFixture) -> Vec { .context .custom_registrations .iter() - .map( - |registration| fensu_native::rules::models::CustomRegistration { - code: registration.0.clone(), - module: registration.1.clone(), - name: registration.2.clone(), - source_path: registration.3.replace("", &repo_root), - line: registration.4, - column: registration.5, - }, - ) + .map(|registration| fensu_native::CustomRegistration { + code: registration.0.clone(), + module: registration.1.clone(), + name: registration.2.clone(), + source_path: registration.3.replace("", &repo_root), + line: registration.4, + column: registration.5, + }) .collect(), repo_root, rule_options: HashMap::new(), diff --git a/crates/fensu-native/tests/rules/test_contracts.rs b/crates/fensu-native/tests/rules/test_contracts.rs index 715df10b..deeb8ba0 100644 --- a/crates/fensu-native/tests/rules/test_contracts.rs +++ b/crates/fensu-native/tests/rules/test_contracts.rs @@ -3,12 +3,12 @@ use std::collections::HashMap; use fensu_facts::extension::models::ProgramHandle; +use fensu_native::evaluate_core_rules; +use fensu_native::plan_execution_owners; use fensu_native::rules::constants::{ DAGSTER_AUTOLOAD_EXTERNAL_DISCOVERY_CODE, TOP_LEVEL_DIRECT_MODULES_CODE, }; -use fensu_native::rules::main::evaluate_core_rules::evaluate_core_rules; -use fensu_native::rules::main::plan_execution_owners::plan_execution_owners; -use fensu_native::rules::models::{ +use fensu_native::{ NativeExecutionRule, NativeExecutionTarget, NativeProjectModule, NativeProjectPlane, NativeRuleContext, }; diff --git a/crates/fensu-native/tests/rules/test_types.rs b/crates/fensu-native/tests/rules/test_types.rs index 5bfb08dd..dfe7fd07 100644 --- a/crates/fensu-native/tests/rules/test_types.rs +++ b/crates/fensu-native/tests/rules/test_types.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; -use fensu_native::rules::models::NativeFaultRow; +use fensu_native::NativeFaultRow; use serde::Deserialize; #[derive(Debug, Deserialize)] diff --git a/release-please-config.json b/release-please-config.json index 804f5514..eb1688e0 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -33,6 +33,18 @@ "type": "generic", "path": "crates/fensu-policy/Cargo.toml" }, + { + "type": "generic", + "path": "crates/fensu-facts/Cargo.toml" + }, + { + "type": "generic", + "path": "crates/fensu-native/Cargo.toml" + }, + { + "type": "generic", + "path": "Cargo.toml" + }, { "type": "generic", "path": "packages/fensu-cli/pyproject.toml" diff --git a/scripts/release_metadata/_helpers/validation.py b/scripts/release_metadata/_helpers/validation.py index 4c148052..f89870b2 100644 --- a/scripts/release_metadata/_helpers/validation.py +++ b/scripts/release_metadata/_helpers/validation.py @@ -14,7 +14,9 @@ NORMALIZED_VERSION, OWNED_CARGO_PACKAGES, OWNED_UV_PACKAGES, + OWNED_WORKSPACE_DEPENDENCIES, RELEASE_MANIFEST_PATH, + ROOT_CARGO_PATH, ROOT_PROJECT_PATH, SEMVER_PART_COUNT, UV_LOCK_PATH, @@ -65,6 +67,8 @@ def version_file_is_valid( section="package", delta=delta, ) + elif path == ROOT_CARGO_PATH: + semantic_valid = _workspace_is_valid(base=base, head=head, delta=delta) elif path == CARGO_LOCK_PATH: semantic_valid = _lock_is_valid( base=base, @@ -171,6 +175,33 @@ def _root_project_is_valid( return base_normalized is not None and base_normalized == head_normalized +def _workspace_is_valid( + *, + base: dict[str, Any], + head: dict[str, Any], + delta: ReleaseDelta, +) -> bool: + base_normalized: dict[str, Any] | None = _normalized_workspace( + document=base, + expected=delta.old_version, + ) + head_normalized: dict[str, Any] | None = _normalized_workspace( + document=head, + expected=delta.new_version, + ) + return base_normalized is not None and base_normalized == head_normalized + + +def _normalized_workspace(*, document: dict[str, Any], expected: str) -> dict[str, Any] | None: + normalized: dict[str, Any] = copy.deepcopy(document) + dependencies: dict[str, Any] = normalized["workspace"]["dependencies"] + for name in OWNED_WORKSPACE_DEPENDENCIES: + if dependencies[name].get("version") != expected: + return None + dependencies[name]["version"] = NORMALIZED_VERSION + return normalized + + def _normalized_field( *, document: dict[str, Any], @@ -284,6 +315,12 @@ def _version_text_is_valid( old_version=delta.old_version, new_version=delta.new_version, ) + elif path == ROOT_CARGO_PATH: + expected = _replace_workspace_versions( + value=base, + old_version=delta.old_version, + new_version=delta.new_version, + ) elif path == CARGO_LOCK_PATH: expected = _replace_lock_versions( value=base, @@ -326,6 +363,22 @@ def _replace_manifest_version( ) +def _replace_workspace_versions(*, value: str, old_version: str, new_version: str) -> str | None: + replaced: str | None = value + for name in sorted(OWNED_WORKSPACE_DEPENDENCIES): + if replaced is None: + return None + replaced = _replace_once( + value=replaced, + pattern=( + rf'(?m)(^{re.escape(name)}\s*=\s*\{{[^\n]*\bversion\s*=\s*")' + rf'{re.escape(old_version)}("[^\n]*$)' + ), + replacement=rf"\g<1>{new_version}\g<2>", + ) + return replaced + + def _replace_lock_versions( *, value: str, diff --git a/scripts/release_metadata/constants.py b/scripts/release_metadata/constants.py index 106f1867..ced451b5 100644 --- a/scripts/release_metadata/constants.py +++ b/scripts/release_metadata/constants.py @@ -7,6 +7,7 @@ ROOT_PROJECT_PATH: str = "pyproject.toml" CLI_PROJECT_PATH: str = "packages/fensu-cli/pyproject.toml" CARGO_LOCK_PATH: str = "Cargo.lock" +ROOT_CARGO_PATH: str = "Cargo.toml" UV_LOCK_PATH: str = "uv.lock" VERSION_PATHS: tuple[str, ...] = ( RELEASE_MANIFEST_PATH, @@ -14,9 +15,15 @@ CLI_PROJECT_PATH, "crates/fensu-cli/Cargo.toml", "crates/fensu-policy/Cargo.toml", + "crates/fensu-facts/Cargo.toml", + "crates/fensu-native/Cargo.toml", + ROOT_CARGO_PATH, UV_LOCK_PATH, CARGO_LOCK_PATH, ) -OWNED_CARGO_PACKAGES: frozenset[str] = frozenset({"fensu-cli", "fensu-policy"}) +OWNED_CARGO_PACKAGES: frozenset[str] = frozenset( + {"fensu-cli", "fensu-facts", "fensu-native", "fensu-policy"} +) +OWNED_WORKSPACE_DEPENDENCIES: frozenset[str] = frozenset({"fensu-facts"}) OWNED_UV_PACKAGES: frozenset[str] = frozenset({"fensu", "fensu-cli"}) ALLOWED_PATHS: frozenset[str] = frozenset((*VERSION_PATHS, CHANGELOG_PATH)) diff --git a/tests/unit/scripts/release_metadata/main/test_validate_release_delta.py b/tests/unit/scripts/release_metadata/main/test_validate_release_delta.py index 8e50c7fd..3f7146a2 100644 --- a/tests/unit/scripts/release_metadata/main/test_validate_release_delta.py +++ b/tests/unit/scripts/release_metadata/main/test_validate_release_delta.py @@ -24,6 +24,18 @@ "crates/fensu-policy/Cargo.toml": ( f'[package]\nname = "fensu-policy"\nversion = "{OLD_VERSION}"\n' ), + "crates/fensu-facts/Cargo.toml": ( + f'[package]\nname = "fensu-facts"\nversion = "{OLD_VERSION}" # x-release-please-version\n' + ), + "crates/fensu-native/Cargo.toml": ( + f'[package]\nname = "fensu-native"\nversion = "{OLD_VERSION}" # x-release-please-version\n' + ), + "Cargo.toml": ( + "[workspace.dependencies]\n" + f'fensu-facts = {{ path = "crates/fensu-facts", version = "{OLD_VERSION}", ' + "default-features = false } # x-release-please-version\n" + 'third-party = "=0.11.0"\n' + ), "uv.lock": ( "version = 1\n" f'[[package]]\nname = "fensu"\nversion = "{OLD_VERSION}"\n' @@ -33,6 +45,8 @@ "Cargo.lock": ( "version = 4\n" f'[[package]]\nname = "fensu-cli"\nversion = "{OLD_VERSION}"\n' + f'[[package]]\nname = "fensu-facts"\nversion = "{OLD_VERSION}"\n' + f'[[package]]\nname = "fensu-native"\nversion = "{OLD_VERSION}"\n' f'[[package]]\nname = "fensu-policy"\nversion = "{OLD_VERSION}"\n' f'[[package]]\nname = "third-party"\nversion = "{OLD_VERSION}"\n' ), @@ -52,6 +66,15 @@ "crates/fensu-policy/Cargo.toml": BASE_FILES["crates/fensu-policy/Cargo.toml"].replace( OLD_VERSION, NEW_VERSION ), + "crates/fensu-facts/Cargo.toml": BASE_FILES["crates/fensu-facts/Cargo.toml"].replace( + OLD_VERSION, NEW_VERSION + ), + "crates/fensu-native/Cargo.toml": BASE_FILES["crates/fensu-native/Cargo.toml"].replace( + OLD_VERSION, NEW_VERSION + ), + "Cargo.toml": BASE_FILES["Cargo.toml"].replace( + f'version = "{OLD_VERSION}"', f'version = "{NEW_VERSION}"', 1 + ), "uv.lock": BASE_FILES["uv.lock"] .replace( f'name = "fensu"\nversion = "{OLD_VERSION}"', f'name = "fensu"\nversion = "{NEW_VERSION}"' @@ -65,6 +88,14 @@ f'name = "fensu-cli"\nversion = "{OLD_VERSION}"', f'name = "fensu-cli"\nversion = "{NEW_VERSION}"', ) + .replace( + f'name = "fensu-facts"\nversion = "{OLD_VERSION}"', + f'name = "fensu-facts"\nversion = "{NEW_VERSION}"', + ) + .replace( + f'name = "fensu-native"\nversion = "{OLD_VERSION}"', + f'name = "fensu-native"\nversion = "{NEW_VERSION}"', + ) .replace( f'name = "fensu-policy"\nversion = "{OLD_VERSION}"', f'name = "fensu-policy"\nversion = "{NEW_VERSION}"', @@ -122,6 +153,22 @@ "packages/fensu-cli/pyproject.toml contains changes beyond the release version substitution" ], ), + ReleaseDeltaTestCase( + description="workspace dependency tampering", + delta=ReleaseDelta( + old_version=OLD_VERSION, + new_version=NEW_VERSION, + changed_paths=frozenset((*VERSION_PATHS, CHANGELOG_PATH)), + base_files=BASE_FILES, + head_files={ + **VALID_HEAD_FILES, + "Cargo.toml": VALID_HEAD_FILES["Cargo.toml"].replace( + 'third-party = "=0.11.0"', 'third-party = "=9.9.9"' + ), + }, + ), + expected_errors=["Cargo.toml contains changes beyond the release version substitution"], + ), ReleaseDeltaTestCase( description="lockfile dependency tampering", delta=ReleaseDelta( From 26466493889f2b53602a4fc4dfbbd3b152e8db02 Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Sat, 14 Nov 2026 09:01:43 +0000 Subject: [PATCH 3/4] fix(facts): pin get-size2 so a fresh project can build ruff_python_ast 0.0.4 --- Cargo.lock | 1 + Cargo.toml | 1 + crates/fensu-facts/Cargo.toml | 2 ++ 3 files changed, 4 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 63c93f59..3f111026 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -427,6 +427,7 @@ name = "fensu-facts" version = "0.29.3" dependencies = [ "dunce", + "get-size2", "globset", "hex", "pyo3", diff --git a/Cargo.toml b/Cargo.toml index b3a9d844..f853d3f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ command-group = "=5.0.1" dunce = "1.0" encoding_rs = "0.8" flate2 = { version = "1", default-features = false, features = ["zlib"] } +get-size2 = { version = "=0.10.1", default-features = false } globset = "=0.4.19" hex = "0.4" ignore = "0.4" diff --git a/crates/fensu-facts/Cargo.toml b/crates/fensu-facts/Cargo.toml index 433298b8..e1a1048b 100644 --- a/crates/fensu-facts/Cargo.toml +++ b/crates/fensu-facts/Cargo.toml @@ -21,6 +21,8 @@ crate-type = ["rlib"] [dependencies] dunce.workspace = true +# Not used directly: ruff_python_ast 0.0.4 needs a get-size2 built on compact_str 0.9, and 0.10.2 moved to 0.10. +get-size2.workspace = true globset.workspace = true hex.workspace = true pyo3 = { workspace = true, optional = true } From 1aa7c072c90bc89a2bac37bcc62575ea9688bfbc Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Sat, 14 Nov 2026 09:09:19 +0000 Subject: [PATCH 4/4] fix(release): keep the required check name, gate sha2, hide shared fact internals, harden the consumer check --- .github/scripts/verify_shared_crate_packages.sh | 4 ++-- .github/workflows/verify.yml | 2 +- .github/workflows/version-guard.yml | 6 ++++++ crates/fensu-facts/src/facts/mod.rs | 2 ++ crates/fensu-native/Cargo.toml | 4 ++-- .../main/test_validate_release_delta.py | 11 +++++++++++ 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.github/scripts/verify_shared_crate_packages.sh b/.github/scripts/verify_shared_crate_packages.sh index 0c39a46a..e92457df 100755 --- a/.github/scripts/verify_shared_crate_packages.sh +++ b/.github/scripts/verify_shared_crate_packages.sh @@ -54,8 +54,8 @@ fn main() { } RUST cargo +1.95.0 run --quiet --manifest-path "${analysis_consumer}/Cargo.toml" -if cargo +1.95.0 tree --manifest-path "${analysis_consumer}/Cargo.toml" -e normal \ - | grep -E '\b(pyo3|rusqlite|flate2) v'; then +analysis_tree="$(cargo +1.95.0 tree --manifest-path "${analysis_consumer}/Cargo.toml" -e normal)" +if grep -E '\b(pyo3|rusqlite|flate2) v' <<< "${analysis_tree}"; then echo "the analysis crates pulled in Python, SQLite or compression dependencies" >&2 exit 1 fi diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 48fc16c1..041d5a00 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -113,7 +113,7 @@ jobs: - run: make test-rust shared-crates: - name: Shared crate packages + name: Shared crate packages (Rust 1.85) needs: changes if: needs.changes.outputs.full == 'true' runs-on: ubuntu-latest diff --git a/.github/workflows/version-guard.yml b/.github/workflows/version-guard.yml index aaa1cea8..a6e125b3 100644 --- a/.github/workflows/version-guard.yml +++ b/.github/workflows/version-guard.yml @@ -39,6 +39,10 @@ jobs: cli_crate_version = tomllib.load(cargo)["package"]["version"] with Path("crates/fensu-policy/Cargo.toml").open("rb") as cargo: policy_crate_version = tomllib.load(cargo)["package"]["version"] + with Path("crates/fensu-facts/Cargo.toml").open("rb") as cargo: + facts_crate_version = tomllib.load(cargo)["package"]["version"] + with Path("crates/fensu-native/Cargo.toml").open("rb") as cargo: + native_crate_version = tomllib.load(cargo)["package"]["version"] versions = { version, @@ -46,6 +50,8 @@ jobs: cli_package_version, cli_crate_version, policy_crate_version, + facts_crate_version, + native_crate_version, } if len(versions) != 1: print(f"Fensu package versions are not locked: {sorted(versions)}", file=sys.stderr) diff --git a/crates/fensu-facts/src/facts/mod.rs b/crates/fensu-facts/src/facts/mod.rs index e74a3fb8..16b10d58 100644 --- a/crates/fensu-facts/src/facts/mod.rs +++ b/crates/fensu-facts/src/facts/mod.rs @@ -1,6 +1,8 @@ //! CPython-shaped fact extraction over the ruff syntax tree. +#[doc(hidden)] pub mod _helpers; +#[doc(hidden)] pub mod main; pub mod models; pub mod types; diff --git a/crates/fensu-native/Cargo.toml b/crates/fensu-native/Cargo.toml index f1f1562a..658bf56a 100644 --- a/crates/fensu-native/Cargo.toml +++ b/crates/fensu-native/Cargo.toml @@ -26,7 +26,7 @@ pyo3 = { workspace = true, optional = true } rayon.workspace = true ruff_python_ast.workspace = true rusqlite = { workspace = true, optional = true } -sha2.workspace = true +sha2 = { workspace = true, optional = true } serde_json.workspace = true fensu-facts = { workspace = true, default-features = false } unicode-ident.workspace = true @@ -34,7 +34,7 @@ unicode-ident.workspace = true [features] default = ["python"] extension-module = ["python", "pyo3/extension-module"] -python = ["dep:pyo3", "dep:rusqlite", "dep:flate2", "fensu-facts/python"] +python = ["dep:pyo3", "dep:rusqlite", "dep:flate2", "dep:sha2", "fensu-facts/python"] [dev-dependencies] serde.workspace = true diff --git a/tests/unit/scripts/release_metadata/main/test_validate_release_delta.py b/tests/unit/scripts/release_metadata/main/test_validate_release_delta.py index 3f7146a2..288d7a08 100644 --- a/tests/unit/scripts/release_metadata/main/test_validate_release_delta.py +++ b/tests/unit/scripts/release_metadata/main/test_validate_release_delta.py @@ -169,6 +169,17 @@ ), expected_errors=["Cargo.toml contains changes beyond the release version substitution"], ), + ReleaseDeltaTestCase( + description="workspace dependency version left behind", + delta=ReleaseDelta( + old_version=OLD_VERSION, + new_version=NEW_VERSION, + changed_paths=frozenset((*VERSION_PATHS, CHANGELOG_PATH)), + base_files=BASE_FILES, + head_files={**VALID_HEAD_FILES, "Cargo.toml": BASE_FILES["Cargo.toml"]}, + ), + expected_errors=["Cargo.toml contains changes beyond the release version substitution"], + ), ReleaseDeltaTestCase( description="lockfile dependency tampering", delta=ReleaseDelta(