diff --git a/CHANGELOG.md b/CHANGELOG.md index 8033cde..ca8cdb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,17 @@ output schemas (see `spec/non-functional/NFR-006-cli-stability.md`). ## [Unreleased] +### Changed + +- Adopt quire-rs 0.65.0 (tag `v0.65.0`). The checked semantic clause language is + `filament`, not `quire` (engine #814). `quire impact --check-tags` entries for + invalid, unverifiable and non-binding findings now carry the engine's changed + `symbol` and revision `side` (`base` or `head`); `source_line` is removed and + `line` is the engine's line, shown for non-binding attributes only. A symbol present on + both revisions now gives one entry per side, including for invalid and + unverifiable ids. The + `--dependency-move` runner `filter` is the engine's. + ## [0.54.4] — 2026-11-30 ### Fixed diff --git a/Cargo.lock b/Cargo.lock index cb51270..1528668 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,7 +5,7 @@ version = 4 [[package]] name = "agent-ix-semantic-schema" version = "0.3.0" -source = "git+https://github.com/agent-ix/filament-core-data?tag=semantic-schema-v0.6.0#327a49ca9d7ab2c12269a8db65b75f1331e165bd" +source = "git+https://github.com/agent-ix/filament-core-data?rev=850129fa6b8499de5d61e6cf916c00838df18953#850129fa6b8499de5d61e6cf916c00838df18953" [[package]] name = "ahash" @@ -1751,7 +1751,7 @@ dependencies = [ [[package]] name = "quire-code-extraction" version = "0.1.0" -source = "git+https://github.com/agent-ix/quire-rs?tag=v0.64.1#67adafff42bc82278ea5d2546631520fe8ceb159" +source = "git+https://github.com/agent-ix/quire-rs?tag=v0.65.0#3a10a2b14920e66b237c52c7751c15cc972b3a32" dependencies = [ "quire-code-parse", ] @@ -1797,8 +1797,8 @@ dependencies = [ [[package]] name = "quire-rs" -version = "0.64.1" -source = "git+https://github.com/agent-ix/quire-rs?tag=v0.64.1#67adafff42bc82278ea5d2546631520fe8ceb159" +version = "0.65.0" +source = "git+https://github.com/agent-ix/quire-rs?tag=v0.65.0#3a10a2b14920e66b237c52c7751c15cc972b3a32" dependencies = [ "agent-ix-semantic-schema", "globset", diff --git a/Cargo.toml b/Cargo.toml index 17ae601..b7e32d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ path = "src/main.rs" [dependencies] ix-cli-kit = { git = "https://github.com/agent-ix/ix-cli-kit", branch = "main", features = ["self-update"] } -quire-rs = { version = "=0.64.1", git = "https://github.com/agent-ix/quire-rs", tag = "v0.64.1" } +quire-rs = { version = "=0.65.0", git = "https://github.com/agent-ix/quire-rs", tag = "v0.65.0" } ix-trace-rs = { version = "=0.1.0", git = "https://github.com/agent-ix/ix-trace-rs", rev = "2ce4ebf47f726b9d76388220545cd0abda8a5cfb" } clap = { version = "4", features = ["derive"] } serde = { version = "1", features = ["derive"] } diff --git a/docs/how-to-analyze-change-impact.md b/docs/how-to-analyze-change-impact.md index 6fc2d4e..6c373a2 100644 --- a/docs/how-to-analyze-change-impact.md +++ b/docs/how-to-analyze-change-impact.md @@ -36,7 +36,7 @@ HEAD=$(git -C "$REPO" rev-parse HEAD) --format json --check-tags ``` - The report then includes missing, invalid, unavailable, and non-binding link findings. In JSON they are listed in `tag_check.entries`, each with its `kind` (`missing_link`, `invalid_id`, `unverifiable_id` or `non_binding_attribute`), path, the changed symbol and source line when they can be told, and a `reason_chain`. The human report prints one block per finding under the same four names. The check covers Rust sources only; a clean result says nothing about other languages. To make any such finding fail the command, add `--fail-on-tag-findings`. That option requires `--check-tags`. + The report then includes missing, invalid, unavailable, and non-binding link findings. In JSON they are listed in `tag_check.entries`, each with its `kind` (`missing_link`, `invalid_id`, `unverifiable_id` or `non_binding_attribute`), path, the changed `symbol` and its `side` (`base` or `head`) from the engine (not on `missing_link`), a `line` for `non_binding_attribute` only, and a `reason_chain`. A symbol present on both revisions gives one entry per side. The human report prints one block per finding under the same four names. The check covers Rust sources only; a clean result says nothing about other languages. To make any such finding fail the command, add `--fail-on-tag-findings`. That option requires `--check-tags`. 3. **Compare a dependency move.** Pass the local upstream repository and the old and new revisions for each dependency move: @@ -54,4 +54,4 @@ The default JSON report contains `changed_symbols`, `selected_tests`, `related_i ## Verify the report -Check `selection_complete` before relying on the selected tests. For dependency moves, inspect each entry in `dependency_moves`; an empty `selected_tests` list is meaningful only when the report is resolved and its upstream inputs are available. Use the emitted `filter` values with your project's test runner when you decide to run the suggested tests. Each dependency-move row has a `filter`: the engine's test symbol, a name path inside its file. A test runner treats it as a substring and it carries no crate or target, so also read the row's `test_path` and select the package with `-p` or `--workspace`. The JSON `selected_tests` holds one row per chain from an upstream item to a test, so the same test appears in many rows; deduplicate on `filter` and `test_path`. The human report lists the test once with one `Reason:` line for each way the move reaches it. Upstream changes with no local reference are shown as unmatched. A test that is not listed is not shown to be unaffected. +Check `selection_complete` before relying on the selected tests. For dependency moves, inspect each entry in `dependency_moves`; an empty `selected_tests` list is meaningful only when the report is resolved and its upstream inputs are available. Use the emitted `filter` values with your project's test runner when you decide to run the suggested tests. Each dependency-move row has a `filter`: the engine's runner filter, a name path inside its file. A test runner treats it as a substring and it carries no crate or target, so also read the row's `test_path` and select the package with `-p` or `--workspace`. The JSON `selected_tests` holds one row per chain from an upstream item to a test, so the same test appears in many rows; deduplicate on `filter` and `test_path`. The human report lists the test once with one `Reason:` line for each way the move reaches it. Upstream changes with no local reference are shown as unmatched. A test that is not listed is not shown to be unaffected. diff --git a/src/commands/impact.rs b/src/commands/impact.rs index 183a553..8fd4ace 100644 --- a/src/commands/impact.rs +++ b/src/commands/impact.rs @@ -130,9 +130,7 @@ pub fn run(ctx: &Ctx, args: Args) -> Result<()> { caller_search_depth: args.caller_depth, })?; let tag_findings = report.findings.iter().any(is_tag_finding); - let tag_check = args - .check_tags - .then(|| impact_tags::tag_check(&report, &head)); + let tag_check = args.check_tags.then(|| impact_tags::tag_check(&report)); if !args.check_tags { report.findings.retain(|finding| !is_tag_finding(finding)); } @@ -332,7 +330,6 @@ fn dependency_moves( traceability, }); let mut value = serde_json::to_value(report)?; - impact_dependency::add_filters(&mut value); if let Some(object) = value.as_object_mut() { object.insert( "repository_path".into(), diff --git a/src/commands/impact_dependency.rs b/src/commands/impact_dependency.rs index 61ebe71..ff63f8f 100644 --- a/src/commands/impact_dependency.rs +++ b/src/commands/impact_dependency.rs @@ -2,34 +2,14 @@ //! `quire impact --dependency-move` (FR-049-AC-6). //! //! The engine decides which upstream files and items changed, which local symbols refer -//! to them and which tests are reached. This module only adds the runner filter to each -//! selected test and writes the result as text, one block per selected test. +//! to them, which tests are reached and the runner filter of each. This module only writes +//! the result as text, one block per selected test. use std::collections::BTreeMap; use ix_trace_rs::implements; use serde_json::Value; -/// Names every selected test of one dependency move with the filter a Rust test runner takes. -/// -/// The engine names a test by its qualified symbol, which is also the substring the runner -/// matches, so the filter is that name. -#[implements("FR-049-AC-6")] -pub fn add_filters(movement: &mut Value) { - let Some(tests) = movement - .get_mut("selected_tests") - .and_then(Value::as_array_mut) - else { - return; - }; - for test in tests { - let filter = test["test_symbol"].clone(); - if let Some(object) = test.as_object_mut() { - object.insert("filter".into(), filter); - } - } -} - /// The note printed after every dependency move: a short list is not a claim about the rest. pub const NOT_LISTED: &str = " Tests that are not listed are not shown to be unaffected; the engine only lists tests it reached."; @@ -98,12 +78,12 @@ pub fn render_human(movement: &Value) -> Vec { let mut tests: BTreeMap<(String, String), Vec<&Value>> = BTreeMap::new(); for selected in movement["selected_tests"].as_array().into_iter().flatten() { tests - .entry((text(selected, "test_path"), text(selected, "test_symbol"))) + .entry((text(selected, "test_path"), text(selected, "filter"))) .or_default() .push(selected); } - for ((path, symbol), reasons) in tests { - lines.push(format!(" Selected test filter={symbol} ({path})")); + for ((path, filter), reasons) in tests { + lines.push(format!(" Selected test filter={filter} ({path})")); for reason in reasons { let call_path = reason["call_path"] .as_array() diff --git a/src/commands/impact_tags.rs b/src/commands/impact_tags.rs index eb84198..5951587 100644 --- a/src/commands/impact_tags.rs +++ b/src/commands/impact_tags.rs @@ -2,11 +2,11 @@ //! `quire impact --check-tags` (FR-049-AC-5). //! //! The engine decides what each finding is. This module only separates the four -//! kinds, names the changed symbol a finding concerns and writes the reason chain +//! kinds, shows the changed symbol and revision side the engine names and writes the reason chain //! in words. It does not bind attributes or resolve specification ids. use ix_trace_rs::implements; -use quire_rs::impact::{ChangedSymbol, ImpactFinding, ImpactReport, RevisionSide, SourceSnapshot}; +use quire_rs::impact::{ImpactFinding, ImpactReport, RevisionSide}; use serde_json::{json, Value}; /// What the tag check covers, shown so a clean result is not read as wider than it is. @@ -58,13 +58,14 @@ fn kind_of(finding: &ImpactFinding) -> Option { } /// The `tag_check` section of the machine-readable report: one entry per distinct -/// finding, ordered by kind, path, id and line. +/// finding, ordered by kind, path, id, line, symbol and side. #[implements("FR-049-AC-5")] -pub fn tag_check(report: &ImpactReport, head: &SourceSnapshot) -> Value { +pub fn tag_check(report: &ImpactReport) -> Value { let mut entries: Vec<(Kind, Value)> = Vec::new(); for finding in &report.findings { - for found in entry(finding, &report.changed_symbols, head) { - // The engine reports both revision sides, so identical entries are shown once. + if let Some(found) = entry(finding) { + // The engine names the revision side of every symbol, so only a finding + // it repeats exactly is shown once. if !entries.contains(&found) { entries.push(found); } @@ -78,6 +79,7 @@ pub fn tag_check(report: &ImpactReport, head: &SourceSnapshot) -> Value { value["trace_id"].as_str().unwrap_or_default().to_owned(), value["line"].as_u64().unwrap_or_default(), value["symbol"].as_str().unwrap_or_default().to_owned(), + value["side"].as_str().unwrap_or_default().to_owned(), ) }; key(a_kind, a).cmp(&key(b_kind, b)) @@ -88,23 +90,24 @@ pub fn tag_check(report: &ImpactReport, head: &SourceSnapshot) -> Value { }) } -/// The entries for one engine finding. An id named by several changed symbols gives -/// one entry per symbol rather than a silent pick of the first. -fn entry( - finding: &ImpactFinding, - changed: &[ChangedSymbol], - head: &SourceSnapshot, -) -> Vec<(Kind, Value)> { - let Some(kind) = kind_of(finding) else { - return Vec::new(); - }; - let with_kind = |value: Value| (kind, value); - match finding { +/// The name of a revision side as shown. +fn side_name(side: RevisionSide) -> &'static str { + match side { + RevisionSide::Base => "base", + RevisionSide::Head => "head", + } +} + +/// The entry for one engine finding. The changed symbol and its revision side are the +/// engine's; nothing is looked up in the source text. +fn entry(finding: &ImpactFinding) -> Option<(Kind, Value)> { + let kind = kind_of(finding)?; + let value = match finding { ImpactFinding::UnlinkedSymbol { path, symbol, changed_lines, - } => vec![with_kind(json!({ + } => json!({ "kind": kind.name(), "path": path, "symbol": symbol, @@ -113,204 +116,60 @@ fn entry( format!("{path}#{symbol} changed on lines {}-{}", changed_lines.start, changed_lines.end), "the symbol has no requirement link bound by the declared implements markers".to_owned(), ], - }))], - ImpactFinding::UnresolvedId { path, trace_id } => { - let base = json!({ - "kind": kind.name(), - "path": path, - "trace_id": trace_id, - "reason_chain": [ - format!("{path} names {trace_id}"), - format!("no specification artifact has the id {trace_id}"), - ], - }); - places_for_id(head, changed, path, trace_id) - .into_iter() - .map(|place| with_kind(with_place(base.clone(), place))) - .collect() - } - ImpactFinding::UnavailableSpecification { path, trace_id } => { - let base = json!({ - "kind": kind.name(), - "path": path, - "trace_id": trace_id, - "reason_chain": [ - format!("{path} names {trace_id}"), - format!("the specification that holds {trace_id} could not be read, so the id cannot be verified"), - ], - }); - places_for_id(head, changed, path, trace_id) - .into_iter() - .map(|place| with_kind(with_place(base.clone(), place))) - .collect() - } + }), + ImpactFinding::UnresolvedId { + path, + trace_id, + symbol, + side, + } => json!({ + "kind": kind.name(), + "path": path, + "trace_id": trace_id, + "symbol": symbol, + "side": side_name(*side), + "reason_chain": [ + format!("{path}#{symbol} ({}) names {trace_id}", side_name(*side)), + format!("no specification artifact has the id {trace_id}"), + ], + }), + ImpactFinding::UnavailableSpecification { + path, + trace_id, + symbol, + side, + } => json!({ + "kind": kind.name(), + "path": path, + "trace_id": trace_id, + "symbol": symbol, + "side": side_name(*side), + "reason_chain": [ + format!("{path}#{symbol} ({}) names {trace_id}", side_name(*side)), + format!("the specification that holds {trace_id} could not be read, so the id cannot be verified"), + ], + }), ImpactFinding::NonBindingMarker { path, trace_id, line, - } => { - let place = locate_marker(head, changed, path, trace_id, *line); - let value = json!({ - "kind": kind.name(), - "path": path, - "trace_id": trace_id, - "reason_chain": [ - match &place { - Some(place) => format!("{path} line {} carries {trace_id} in an attribute", place.line), - None => format!("{path} carries {trace_id} in an attribute"), - }, - "the attribute binds no implementation relation to a changed symbol (for example a path-qualified attribute or one the declared grammar does not bind)".to_owned(), - ], - }); - vec![with_kind(with_place(value, place))] - } - _ => Vec::new(), - } -} - -/// Adds the located symbol and source line, when found. -fn with_place(mut value: Value, place: Option) -> Value { - if let Some(place) = place { - value["line"] = json!(place.line); - value["source_line"] = json!(place.source_line); - if let Some(symbol) = place.symbol { - value["symbol"] = json!(symbol); - } - } - value -} - -struct Place { - line: usize, - source_line: String, - symbol: Option, -} - -/// Changed head symbols on `path`, ordered by position and name. -fn head_symbols<'a>(changed: &'a [ChangedSymbol], path: &str) -> Vec<&'a ChangedSymbol> { - let mut symbols: Vec<&ChangedSymbol> = changed - .iter() - .filter(|symbol| symbol.side == RevisionSide::Head && symbol.path == path) - .collect(); - symbols.sort_by_key(|symbol| (symbol.lines.start, symbol.name.clone())); - symbols -} - -/// The first line of the attribute and comment block directly above `symbol`. -fn block_start(lines: &[&str], symbol: &ChangedSymbol) -> usize { - let mut start = symbol.lines.start.max(1); - while start > 1 { - let above = lines.get(start - 2).map(|line| line.trim()).unwrap_or(""); - if above.starts_with("#[") || above.starts_with("//") { - start -= 1; - } else { - break; - } - } - start -} - -/// Whether `source` names `trace_id` as a whole quoted id. -fn names_id(source: &str, trace_id: &str) -> bool { - source.contains(&format!("\"{trace_id}\"")) -} - -fn place_at(lines: &[&str], line: usize, symbol: Option<&ChangedSymbol>) -> Place { - Place { - line, - source_line: lines[line - 1].trim().to_owned(), - symbol: symbol.map(|symbol| symbol.name.clone()), - } -} - -/// The lines of `symbol`, with its attribute block, that name `trace_id`. -fn id_lines(lines: &[&str], symbol: &ChangedSymbol, trace_id: &str) -> Vec { - let end = symbol.lines.end.min(lines.len()); - (block_start(lines, symbol)..=end) - .filter(|line| *line >= 1 && names_id(lines[line - 1], trace_id)) - .collect() -} - -/// Places for an id the engine could not resolve or verify. The changed head -/// symbols whose bound ids contain it are the answer, one place each; only when -/// no symbol binds it is the head text searched for a single whole-id mention. -fn places_for_id( - head: &SourceSnapshot, - changed: &[ChangedSymbol], - path: &str, - trace_id: &str, -) -> Vec> { - let Some(text) = head.files.get(path) else { - return vec![None]; - }; - let lines: Vec<&str> = text.lines().collect(); - let bound: Vec<&ChangedSymbol> = head_symbols(changed, path) - .into_iter() - .filter(|symbol| symbol.implemented_ids.iter().any(|id| id == trace_id)) - .collect(); - if !bound.is_empty() { - return bound - .into_iter() - .map(|symbol| { - let line = id_lines(&lines, symbol, trace_id) - .first() - .copied() - .unwrap_or_else(|| symbol.lines.start.max(1)); - (line <= lines.len()).then(|| place_at(&lines, line, Some(symbol))) - }) - .collect(); - } - let mentions: Vec = (1..=lines.len()) - .filter(|line| names_id(lines[line - 1], trace_id)) - .collect(); - match mentions.as_slice() { - [line] => { - let symbol = head_symbols(changed, path) - .into_iter() - .find(|symbol| id_lines(&lines, symbol, trace_id).contains(line)); - vec![Some(place_at(&lines, *line, symbol))] - } - _ => vec![None], - } -} - -/// Places a non-binding attribute in the head file. The engine reports markers on -/// both revision sides without saying which, so its line is used only when the head -/// text at that line is an attribute naming the id; otherwise the head is searched -/// for a single such attribute inside a changed symbol. No place is invented. -fn locate_marker( - head: &SourceSnapshot, - changed: &[ChangedSymbol], - path: &str, - trace_id: &str, - engine_line: usize, -) -> Option { - let text = head.files.get(path)?; - let lines: Vec<&str> = text.lines().collect(); - let symbols = head_symbols(changed, path); - let is_marker = |line: usize| { - line >= 1 && line <= lines.len() && { - let source = lines[line - 1].trim(); - source.starts_with("#[") && names_id(source, trace_id) - } - }; - let owner = |line: usize| { - symbols - .iter() - .find(|symbol| id_lines(&lines, symbol, trace_id).contains(&line)) - .copied() + symbol, + side, + } => json!({ + "kind": kind.name(), + "path": path, + "trace_id": trace_id, + "symbol": symbol, + "side": side_name(*side), + "line": line, + "reason_chain": [ + format!("{path} line {line} ({}) carries {trace_id} in an attribute of {symbol}", side_name(*side)), + "the attribute binds no implementation relation to a changed symbol (for example a path-qualified attribute or one the declared grammar does not bind)".to_owned(), + ], + }), + _ => return None, }; - if is_marker(engine_line) { - return Some(place_at(&lines, engine_line, owner(engine_line))); - } - let candidates: Vec<(usize, &ChangedSymbol)> = (1..=lines.len()) - .filter(|line| is_marker(*line)) - .filter_map(|line| owner(line).map(|symbol| (line, symbol))) - .collect(); - match candidates.as_slice() { - [(line, symbol)] => Some(place_at(&lines, *line, Some(symbol))), - _ => None, - } + Some((kind, value)) } /// Writes the human-readable tag check section. @@ -356,10 +215,8 @@ pub fn render_human(check: &Value) -> Vec { lines.push(head); if kind != Kind::MissingLink { if let Some(symbol) = entry["symbol"].as_str() { - lines.push(format!(" Affected changed symbol: {symbol}")); - } - if let Some(source) = entry["source_line"].as_str() { - lines.push(format!(" Source: {source}")); + let side = entry["side"].as_str().unwrap_or(""); + lines.push(format!(" Affected changed symbol: {symbol} ({side})")); } } for reason in entry["reason_chain"].as_array().into_iter().flatten() { diff --git a/tests/cli_impact.rs b/tests/cli_impact.rs index aed16db..26fff78 100644 --- a/tests/cli_impact.rs +++ b/tests/cli_impact.rs @@ -755,6 +755,8 @@ fn it_impact_tag_check_presents_an_invalid_id() { assert_eq!(entry["trace_id"], "FR-999-AC-1"); assert_eq!(entry["path"], "src/lib.rs"); assert_eq!(entry["symbol"], "invalid_link"); + assert_eq!(entry["side"], "head"); + assert!(entry.get("source_line").is_none(), "{entry}"); assert!(entry["reason_chain"] .to_string() .contains("no specification artifact")); @@ -784,6 +786,7 @@ fn it_impact_tag_check_presents_an_unverifiable_id() { let entry = only_kind(&entries, "unverifiable_id"); assert_eq!(entry["trace_id"], "FR-901-AC-1"); assert_eq!(entry["symbol"], "unavailable_link"); + assert_eq!(entry["side"], "head"); assert!(entry["reason_chain"] .to_string() .contains("could not be read")); @@ -813,7 +816,11 @@ fn it_impact_tag_check_presents_non_binding_attributes_including_path_qualified( ); assert_eq!(entry["trace_id"], "FR-900-AC-1"); assert_eq!(entry["symbol"], "nonbinding_link"); - assert_eq!(entry["source_line"], "#[trace(\"FR-900-AC-1\")]"); + assert_eq!(entry["side"], "head"); + assert_eq!( + entry["line"], 5, + "the engine's mention line is the display line" + ); let human = run(&repo, "human", &["--check-tags"]); let human = String::from_utf8_lossy(&human.stdout); @@ -835,10 +842,8 @@ fn it_impact_tag_check_presents_non_binding_attributes_including_path_qualified( "qualified_link" ); assert_eq!(entry["symbol"], "qualified_link"); - assert_eq!( - entry["source_line"], - "#[ix_trace_rs::implements(\"FR-900-AC-1\")]" - ); + assert_eq!(entry["side"], "head"); + assert_eq!(entry["line"], 5); } #[test] @@ -885,6 +890,13 @@ fn of_kind(entries: &[Value], kind: &str) -> Vec { .collect() } +fn sides_of(entries: &[Value]) -> Vec { + entries + .iter() + .map(|entry| entry["side"].as_str().unwrap_or("").to_owned()) + .collect() +} + fn symbols_of(entries: &[Value]) -> Vec { entries .iter() @@ -894,7 +906,7 @@ fn symbols_of(entries: &[Value]) -> Vec { #[test] #[trace("FR-049-AC-5")] -fn it_impact_tag_check_never_reads_a_base_side_line_in_the_head_file() { +fn it_impact_tag_check_shows_the_engines_symbol_side_and_line_for_each_revision() { let base = "pub fn target() { let _value = 1; }\n\ #[ix_trace_rs::implements(\"FR-900-AC-1\")]\n\ pub fn moved() { let _value = 1; }\n"; @@ -907,12 +919,36 @@ fn it_impact_tag_check_never_reads_a_base_side_line_in_the_head_file() { let repo = with_base_and_head(repository(false), base, head); let (entries, _) = tag_check(&repo, &[]); let nonbinding = of_kind(&entries, "non_binding_attribute"); - assert_eq!(nonbinding.len(), 1, "{entries:?}"); - assert_eq!(nonbinding[0]["symbol"], "moved", "{entries:?}"); - assert_eq!(nonbinding[0]["line"], 5, "{entries:?}"); - assert_eq!( - nonbinding[0]["source_line"], - "#[ix_trace_rs::implements(\"FR-900-AC-1\")]" + assert_eq!(nonbinding.len(), 2, "{entries:?}"); + let place = |side: &str| -> (String, u64) { + let entry = nonbinding + .iter() + .find(|entry| entry["side"] == side) + .unwrap_or_else(|| panic!("no {side} entry: {entries:?}")); + assert_eq!(entry["symbol"], "moved", "{entries:?}"); + assert!(entry.get("source_line").is_none(), "{entry}"); + (entry["symbol"].to_string(), entry["line"].as_u64().unwrap()) + }; + assert_eq!(place("base").1, 2, "{entries:?}"); + assert_eq!(place("head").1, 5, "{entries:?}"); +} + +#[test] +#[trace("FR-049-AC-5")] +fn it_impact_tag_check_names_the_base_side_for_a_removed_symbol() { + let base = "#[implements(\"FR-999-AC-1\")]\npub fn removed() {}\n"; + let head = "pub fn kept() {}\n"; + let repo = with_base_and_head(repository(false), base, head); + let (entries, _) = tag_check(&repo, &[]); + let invalid = of_kind(&entries, "invalid_id"); + assert_eq!(invalid.len(), 1, "{entries:?}"); + assert_eq!(invalid[0]["symbol"], "removed", "{entries:?}"); + assert_eq!(invalid[0]["side"], "base", "{entries:?}"); + let human = run(&repo, "human", &["--check-tags"]); + let human = String::from_utf8_lossy(&human.stdout); + assert!( + human.contains("Affected changed symbol: removed (base)"), + "{human}" ); } @@ -928,8 +964,8 @@ fn it_impact_tag_check_names_the_changed_symbol_that_carries_the_invalid_id() { let repo = with_base_and_head(repository(false), base, head); let (entries, _) = tag_check(&repo, &[]); let invalid = of_kind(&entries, "invalid_id"); - assert_eq!(symbols_of(&invalid), vec!["c"], "{entries:?}"); - assert_eq!(invalid[0]["line"], 4, "{entries:?}"); + assert_eq!(symbols_of(&invalid), vec!["c", "c"], "{entries:?}"); + assert_eq!(sides_of(&invalid), vec!["base", "head"], "{entries:?}"); } #[test] @@ -942,7 +978,16 @@ fn it_impact_tag_check_lists_every_changed_symbol_with_the_same_invalid_id() { let repo = with_base_and_head(repository(false), base, head); let (entries, _) = tag_check(&repo, &[]); let invalid = of_kind(&entries, "invalid_id"); - assert_eq!(symbols_of(&invalid), vec!["c", "d"], "{entries:?}"); + assert_eq!( + symbols_of(&invalid), + vec!["c", "c", "d", "d"], + "{entries:?}" + ); + assert_eq!( + sides_of(&invalid), + vec!["base", "head", "base", "head"], + "{entries:?}" + ); } #[test] @@ -960,8 +1005,8 @@ fn it_impact_tag_check_does_not_match_an_id_that_is_a_prefix_of_another() { .into_iter() .filter(|entry| entry["trace_id"] == "FR-999-AC-1") .collect(); - assert_eq!(symbols_of(&short), vec!["c"], "{entries:?}"); - assert_eq!(short[0]["source_line"], "#[implements(\"FR-999-AC-1\")]"); + assert_eq!(symbols_of(&short), vec!["c", "c"], "{entries:?}"); + assert_eq!(sides_of(&short), vec!["base", "head"], "{entries:?}"); } #[test] @@ -974,7 +1019,7 @@ fn it_impact_tag_check_presents_identical_findings_once() { let repo = with_base_and_head(repository(false), base, head); let (entries, _) = tag_check(&repo, &[]); assert_eq!(of_kind(&entries, "missing_link").len(), 1, "{entries:?}"); - assert_eq!(of_kind(&entries, "invalid_id").len(), 1, "{entries:?}"); + assert_eq!(of_kind(&entries, "invalid_id").len(), 2, "{entries:?}"); let mut unique: Vec = entries.iter().map(Value::to_string).collect(); unique.dedup(); assert_eq!(unique.len(), entries.len(), "{entries:?}");