pub fn diff(base: &Surface, head: &Surface) -> Vec<SurfaceChange>Expand description
Every way the contract moved between two surfaces.
A capability that was renamed appears as a removal and an addition, and deliberately so: that is what happened to a caller holding the old name, and collapsing the two into one “rename” would lose the breaking half while looking tidier.
use majordomus_cli::release::compat::{diff, Impact};
use majordomus_cli::release::surface::{public_capabilities, Origin, Surface, SURFACE_SCHEMA};
use serde_json::json;
let surface = |caps| Surface {
schema: SURFACE_SCHEMA.to_string(),
origin: Origin::WorkingTree,
capabilities: public_capabilities(&json!({"capabilities": caps})),
};
let before = surface(json!([{"id": "a.one", "kind": "query", "visibility": "public"}]));
let after = surface(json!([
{"id": "a.one", "kind": "query", "visibility": "public"},
{"id": "a.two", "kind": "query", "visibility": "public"},
]));
assert!(diff(&before, &before).is_empty(), "a surface diffed with itself is empty");
let found = diff(&before, &after);
assert_eq!(found.len(), 1);
assert_eq!(found[0].impact, Impact::Minor, "an addition breaks nobody");
// and the other way round, the same movement is breaking
assert_eq!(diff(&after, &before)[0].impact, Impact::Major);