crates/cli/git-ents/tests/effect.rs
effect.rshistorycomment on this file
| 1 | //! Integration coverage for `git ents effect list`/`log` output against a |
| 2 | //! real local composition root (`roots.local`): the human listing and the |
| 3 | //! stable `--porcelain` record grammar (`lens.parity`), both derived from |
| 4 | //! [`ents_model::Effect`]'s and [`ents_model::ResultRecord`]'s own |
| 5 | //! `#[facet(ents::...)]`-annotated shapes. |
| 6 | |
| 7 | #![allow(clippy::expect_used, reason = "integration test")] |
| 8 | |
| 9 | mod common; |
| 10 | |
| 11 | use std::process::Command; |
| 12 | |
| 13 | use ents_model::Status; |
| 14 | use git_ents::commands::effect; |
| 15 | use git_ents::root::LocalRoot; |
| 16 | |
| 17 | fn run(fixture: &common::Fixture, args: &[&str]) -> String { |
| 18 | let output = Command::new(common::bin_path()) |
| 19 | .current_dir(fixture.path()) |
| 20 | .args(args) |
| 21 | .output() |
| 22 | .expect("runs"); |
| 23 | assert!(output.status.success(), "{output:?}"); |
| 24 | String::from_utf8(output.stdout).expect("utf8") |
| 25 | } |
| 26 | |
| 27 | /// `git ents effect list --porcelain` emits the stable record grammar |
| 28 | /// (`lens.parity`): a `<name>` head line, then `trigger`, `toolchains` |
| 29 | /// (omitted when empty), and `run` keyed lines, records blank-line |
| 30 | /// separated; the human listing stays `<name>\t<trigger>`. |
| 31 | // @relation(lens.porcelain, lens.parity, model.effect-definition, roots.local, scope=function, role=Verifies) |
| 32 | #[test] |
| 33 | fn effect_list_porcelain_emits_one_record_per_definition() { |
| 34 | let fixture = common::Fixture::new(1); |
| 35 | let root = LocalRoot::open(fixture.path()).expect("opens"); |
| 36 | effect::add( |
| 37 | &root, |
| 38 | "unit", |
| 39 | "rev(refs/heads/main)".to_owned(), |
| 40 | "cargo test".to_owned(), |
| 41 | vec![], |
| 42 | Some(fixture.key_path.clone()), |
| 43 | ) |
| 44 | .expect("defines"); |
| 45 | effect::add( |
| 46 | &root, |
| 47 | "with-tools", |
| 48 | "rev(refs/heads/main)".to_owned(), |
| 49 | "cargo build".to_owned(), |
| 50 | vec!["rust-stable".to_owned(), "node-lts".to_owned()], |
| 51 | Some(fixture.key_path.clone()), |
| 52 | ) |
| 53 | .expect("defines"); |
| 54 | |
| 55 | assert_eq!( |
| 56 | run(&fixture, &["effect", "list", "--porcelain"]), |
| 57 | "unit\ntrigger rev(refs/heads/main)\nrun cargo test\n\ |
| 58 | \n\ |
| 59 | with-tools\ntrigger rev(refs/heads/main)\ntoolchains rust-stable, node-lts\nrun cargo build\n" |
| 60 | ); |
| 61 | assert_eq!( |
| 62 | run(&fixture, &["effect", "list"]), |
| 63 | "unit\trev(refs/heads/main)\nwith-tools\trev(refs/heads/main)\n" |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | /// `git ents effect log --porcelain` emits one `<commit> <status>` record |
| 68 | /// per judged commit, the commit's full oid (`model.result-identity`, |
| 69 | /// `lens.parity`); the human listing abbreviates it like git does. |
| 70 | // @relation(lens.porcelain, lens.parity, model.result-identity, roots.local, scope=function, role=Verifies) |
| 71 | #[test] |
| 72 | fn effect_log_porcelain_carries_the_full_judged_commit_oid() { |
| 73 | let fixture = common::Fixture::new(2); |
| 74 | let root = LocalRoot::open(fixture.path()).expect("opens"); |
| 75 | |
| 76 | let target = gix_hash::ObjectId::from_hex(b"0123456789abcdef0123456789abcdef01234567") |
| 77 | .expect("valid hex"); |
| 78 | let signer = git_ents::sign::Signer::load(&fixture.key_path).expect("loads"); |
| 79 | let author = gix::actor::Signature { |
| 80 | name: "worker".into(), |
| 81 | email: "worker@ents.test".into(), |
| 82 | time: gix::date::Time { |
| 83 | seconds: 1_000, |
| 84 | offset: 0, |
| 85 | }, |
| 86 | }; |
| 87 | let results_ref = |
| 88 | ents_model::namespace::result_ref("unit", &ents_effect::run::short_oid(target)) |
| 89 | .expect("valid refname"); |
| 90 | ents_effect::write_result( |
| 91 | &root.refs, |
| 92 | &root.objects, |
| 93 | &root.events, |
| 94 | results_ref, |
| 95 | "unit", |
| 96 | target, |
| 97 | Status::Pass, |
| 98 | &author, |
| 99 | |payload| signer.sign(payload), |
| 100 | ents_receive::Mode::Advisory, |
| 101 | ) |
| 102 | .expect("records"); |
| 103 | |
| 104 | assert_eq!( |
| 105 | run(&fixture, &["effect", "log", "unit", "--porcelain"]), |
| 106 | "0123456789abcdef0123456789abcdef01234567 pass\n" |
| 107 | ); |
| 108 | assert_eq!(run(&fixture, &["effect", "log", "unit"]), "0123456\tpass\n"); |
| 109 | } |