Skip to content

Commit 4ea3182

Browse files
test: reduce and improve tests in src/compile/filter_ir.rs (#667)
- test_spec_validates_against_schema: removed — never called generate_gate_spec_schema(), making the name incorrect; assertions were a weaker subset of test_gate_spec_serializes_to_valid_json - test_lower_pr_filters_labels: strengthened — replaced Predicate::LabelSetMatch { .. } wildcard with pattern that verifies any_of and none_of field values are preserved through lowering - test_lower_pr_filters_author_include_exclude: strengthened — added predicate-type and value assertions for both the include (ValueInSet) and exclude (ValueNotInSet) checks, previously only names were verified Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 908947b commit 4ea3182

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

src/compile/filter_ir.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,23 @@ mod tests {
13421342
let checks = lower_pr_filters(&filters);
13431343
assert_eq!(checks.len(), 2);
13441344
assert_eq!(checks[0].name, "author include");
1345+
assert!(
1346+
matches!(
1347+
&checks[0].predicate,
1348+
Predicate::ValueInSet { fact: Fact::AuthorEmail, values, .. }
1349+
if values == &["alice@corp.com"]
1350+
),
1351+
"include should lower to ValueInSet on AuthorEmail"
1352+
);
13451353
assert_eq!(checks[1].name, "author exclude");
1354+
assert!(
1355+
matches!(
1356+
&checks[1].predicate,
1357+
Predicate::ValueNotInSet { fact: Fact::AuthorEmail, values, .. }
1358+
if values == &["bot@noreply.com"]
1359+
),
1360+
"exclude should lower to ValueNotInSet on AuthorEmail"
1361+
);
13461362
}
13471363

13481364
#[test]
@@ -1357,10 +1373,15 @@ mod tests {
13571373
};
13581374
let checks = lower_pr_filters(&filters);
13591375
assert_eq!(checks.len(), 1);
1360-
assert!(matches!(
1361-
&checks[0].predicate,
1362-
Predicate::LabelSetMatch { .. }
1363-
));
1376+
assert_eq!(checks[0].name, "labels");
1377+
assert!(
1378+
matches!(
1379+
&checks[0].predicate,
1380+
Predicate::LabelSetMatch { any_of, none_of, .. }
1381+
if any_of == &["run-agent"] && none_of == &["do-not-run"]
1382+
),
1383+
"labels should lower to LabelSetMatch preserving any_of and none_of"
1384+
);
13641385
}
13651386

13661387
#[test]
@@ -1817,27 +1838,6 @@ mod tests {
18171838
}
18181839
}
18191840

1820-
#[test]
1821-
fn test_spec_validates_against_schema() {
1822-
// Generate a spec and verify it matches the schema structure
1823-
let checks = vec![FilterCheck {
1824-
name: "title",
1825-
predicate: Predicate::GlobMatch {
1826-
fact: Fact::PrTitle,
1827-
pattern: "test".into(),
1828-
},
1829-
build_tag_suffix: "title-mismatch",
1830-
}];
1831-
let spec = build_gate_spec(GateContext::PullRequest, &checks).unwrap();
1832-
let spec_json = serde_json::to_value(&spec).unwrap();
1833-
1834-
// Verify structural expectations from schema
1835-
assert!(spec_json["context"]["build_reason"].is_string());
1836-
assert!(spec_json["facts"].is_array());
1837-
assert!(spec_json["checks"].is_array());
1838-
assert!(spec_json["checks"][0]["predicate"]["type"].as_str() == Some("glob_match"));
1839-
}
1840-
18411841
#[test]
18421842
#[ignore] // Writes to source tree — run manually with `cargo test test_write_schema -- --ignored`
18431843
fn test_write_schema_to_scripts() {

0 commit comments

Comments
 (0)