diff --git a/.hyperhive/review-classifier.yml b/.hyperhive/review-classifier.yml new file mode 100644 index 00000000..2070c1ea --- /dev/null +++ b/.hyperhive/review-classifier.yml @@ -0,0 +1,52 @@ +classifications: + - name: no-ads + description: >- + A commit message contains a co-authored-by line or other advertising + for an AI model, such as a "generated with" footer. + polarity: negative + threshold: 80 + - name: no-secrets + description: >- + The diff adds a secret as literal text: a password, API key, access + token or private key. A path or name that points at a secret is not + one. + polarity: negative + threshold: 60 + - name: no-lint-suppression + description: >- + The diff adds a Rust `#[allow(clippy::...)]` or `#![allow(clippy::...)]` + attribute instead of fixing what the lint reports. + polarity: negative + threshold: 70 + - name: no-debug-leftovers + description: >- + The diff adds leftover debugging: a `dbg!` call, a print statement + that only inspects a value, or a block of commented-out code. + polarity: negative + threshold: 70 + - name: no-dead-code + description: >- + The diff adds a function, type, option or module that nothing in the + diff calls, uses or registers, and that is not a test, a trait + implementation or public API. + polarity: negative + threshold: 75 + - name: tests-with-behaviour + description: >- + Every change to how the code behaves comes with a new or updated test + that exercises it. + polarity: positive + threshold: 65 + - name: docs-updated + description: >- + A change to what an operator or user sees, such as a command, flag, + option, endpoint, service or default, updates the matching page under + docs/ or the crate's README in the same diff. + polarity: positive + threshold: 65 + - name: one-purpose + description: >- + Every change in the diff serves what the commit messages say the PR + does, and nothing unrelated is bundled in. + polarity: positive + threshold: 65 diff --git a/nix/rust.nix b/nix/rust.nix index 0ea9a604..71ef2719 100644 --- a/nix/rust.nix +++ b/nix/rust.nix @@ -35,9 +35,15 @@ rec { # `hyperhive-assets` derivation and are loaded by the binaries at # runtime from `$HIVE_ASSETS_DIR`. Net effect: only `*.rs` / # `*.toml` / `Cargo.lock` edits rebuild the rust derivations. + # + # The one other file in it is the repo's own review-classifier rules: a + # `swarm-controller` test parses them, so they must be in the sandbox. cleanSrc = lib.fileset.toSource { root = ../.; - fileset = craneLib.fileset.commonCargoSources ../.; + fileset = lib.fileset.unions [ + (craneLib.fileset.commonCargoSources ../.) + ../.hyperhive/review-classifier.yml + ]; }; # The workspace's dependency tree, built once and cached as its own diff --git a/swarm-controller/src/review_classifier.rs b/swarm-controller/src/review_classifier.rs index 11ea9710..006784d9 100644 --- a/swarm-controller/src/review_classifier.rs +++ b/swarm-controller/src/review_classifier.rs @@ -1087,6 +1087,30 @@ classifications: assert_eq!(parse_rules(json_path, json.as_bytes()), Ok(want)); } + #[test] + fn this_repos_own_rules_file_loads() { + let [yml_path, _] = RULES_PATHS; + let rules = parse_rules( + yml_path, + include_str!("../../.hyperhive/review-classifier.yml").as_bytes(), + ) + .expect("the repo's rules file parses"); + let names: Vec<_> = rules.iter().map(|c| c.name.as_str()).collect(); + assert_eq!( + names, + [ + "no-ads", + "no-secrets", + "no-lint-suppression", + "no-debug-leftovers", + "no-dead-code", + "tests-with-behaviour", + "docs-updated", + "one-purpose", + ] + ); + } + #[test] fn a_bad_rules_file_is_an_error_in_either_format() { let mut unknown_rule_field = datetime();