77b28ad64d
First half of the form-a-default-authoring milestone-close iter (Boss-decided strategy C, big-bang). All five tasks DONE; cargo test --workspace green at every per-task boundary. T1 — Add three new tests: - parse_is_deterministic_over_every_ail_fixture (round_trip.rs) - cli_parse_then_render_then_parse_is_idempotent (roundtrip_cli.rs) - carve_out_inventory.rs (new file; #[ignore]'d until T8 deletion) T2 — Bulk-render the 99 missing examples/<stem>.ail files via `ail render`. Corpus 58 .ail (pre-iter) -> 157 .ail. Eight .ail.json carve-outs (7 §C4(a) subject-matter + 1 §C4(b) prelude) preserved. One re-loop triggered: load_workspace prefers .ail siblings since ext-cli.1, so the newly-rendered imports broke seven Group-A entries whose JSON entry-paths now resolved imports to fresh .ail. Repair: pre-emptive forward-pull of five T3 migrations + 4 transient #[ignore]s on workspace.rs mod tests (cleanly relocated in T5). T3 — 14 Group-A test files migrated from ailang_core::load_workspace to ailang_surface::load_workspace + .ail paths. Carve-out lines preserved verbatim (7 sites in typeclass_22b2.rs / typeclass_22b3.rs). T4 — 12 Group-B test files: bulk regex flip on build_and_run / build_and_run_with_alloc / build_and_run_with_rc_stats call sites (~70 e2e.rs invocations + 11 subprocess sites). Four files mis-classified Group-A as Group-B in plan recon (mono_hash_stability, prelude_free_fns, print_mono_body_shape, show_mono_synthesis); two files mis-classified Group-B as Group-A (mono_recursive_fn, mono_xmod_qualified_ref). Migrated per actual shape, not plan label. T5 — Relocated #[cfg(test)] mod tests from production source to integration test crates with ailang-surface dev-dependency: - crates/ailang-core/tests/hash_pin.rs (10 tests from hash.rs) - crates/ailang-core/tests/workspace_pin.rs (10 non-carve-out tests from workspace.rs) - crates/ailang-codegen/tests/eq_primitives_pin.rs (3 tests from codegen/src/lib.rs:3717-3799) - ailang-prose/tests/snapshot.rs migrated (helper + 8 fixtures) to .ail + ailang_surface::load_module Carve-out tests in workspace.rs mod tests preserved in-place (3× 22b2 + 3× ct1 = 6 tests). Tempdir-based loader-mechanism tests (3 sites) also preserved — they don't consume examples/. Tests: 560 passed, 0 failed, 4 ignored (was 558 + 3 T1 new - 1 transit carve_out_inventory #[ignore] = 560 active). Tasks 6-12 (bench-driver suffix flips, e2e diff-test rewrite + 4 additional raw-JSON-inspect handlers, .ail.json deletion, retiring obsolete roundtrip tests + schema_coverage corpus flip, §C3 DESIGN.md restatement, §A4 doctrine edits, WhatsNew + roadmap strike) ship in the next dispatch on this iter ID. Known debt inherited to T6-12: 4 raw-JSON-inspect tests in e2e.rs (borrow_own_demo / reuse_as_demo / render_parse_round_trip_canonical / ail_run_accepts_ail_source_with_same_stdout_as_ail_json dual-form smoke) need rewrite or #[ignore] before T8 deletion; recorded in journal Concerns + Known debt sections.
262 lines
9.9 KiB
Rust
262 lines
9.9 KiB
Rust
//! Hash-pin integration tests, relocated from `ailang-core/src/hash.rs`
|
|
//! `#[cfg(test)] mod tests` to a `tests/*` integration crate in iter
|
|
//! form-a.1 Task 5. The relocation removes the production-source file's
|
|
//! ad-hoc `examples/<stem>.ail.json` reads in favour of loading the
|
|
//! `.ail` siblings via `ailang_surface::load_module`, mirroring the
|
|
//! Form-A authoring discipline of the form-a-default-authoring
|
|
//! milestone. Hash assertions are unchanged: post-form-a the canonical
|
|
//! JSON-AST is still the hashable representation, derived in-process
|
|
//! from `.ail` by the surface loader.
|
|
//!
|
|
//! The `examples/<stem>.ail.json` fixtures that backed the original
|
|
//! tests are deleted in Task 8; the `.ail` siblings rendered in Task 2
|
|
//! are the authored form going forward. The four schema-stability pins
|
|
//! (iter13a / iter19b / iter22b1 / ct4) plus the two structural pins
|
|
//! (hash_is_stable / hash_changes_with_content / classdef-empty-optionals
|
|
//! / forall-without-constraints) all keep their assertion shape.
|
|
|
|
use ailang_core::ast::*;
|
|
use ailang_core::canonical;
|
|
use ailang_core::hash::def_hash;
|
|
|
|
fn examples_dir() -> std::path::PathBuf {
|
|
let manifest_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
manifest_dir.parent().unwrap().parent().unwrap().join("examples")
|
|
}
|
|
|
|
fn sample_fn() -> Def {
|
|
Def::Fn(FnDef {
|
|
name: "add".into(),
|
|
ty: Type::Fn {
|
|
params: vec![Type::int(), Type::int()],
|
|
ret: Box::new(Type::int()),
|
|
effects: vec![],
|
|
param_modes: vec![],
|
|
ret_mode: ParamMode::Implicit,
|
|
},
|
|
params: vec!["a".into(), "b".into()],
|
|
body: Term::App {
|
|
callee: Box::new(Term::Var { name: "+".into() }),
|
|
args: vec![
|
|
Term::Var { name: "a".into() },
|
|
Term::Var { name: "b".into() },
|
|
],
|
|
tail: false,
|
|
},
|
|
suppress: vec![],
|
|
doc: None,
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn hash_is_stable() {
|
|
let h1 = def_hash(&sample_fn());
|
|
let h2 = def_hash(&sample_fn());
|
|
assert_eq!(h1, h2);
|
|
assert_eq!(h1.len(), 16);
|
|
}
|
|
|
|
#[test]
|
|
fn hash_changes_with_content() {
|
|
let mut def = sample_fn();
|
|
let h1 = def_hash(&def);
|
|
if let Def::Fn(ref mut f) = def {
|
|
f.name = "mul".into();
|
|
}
|
|
let h2 = def_hash(&def);
|
|
assert_ne!(h1, h2);
|
|
}
|
|
|
|
/// Iter 13a regression: adding `vars` to TypeDef and `args` to
|
|
/// `Type::Con` must NOT change canonical-JSON hashes of any pre-13a
|
|
/// definition. Recorded hashes were captured from on-disk modules
|
|
/// before the schema extension; if this fires, a
|
|
/// `skip_serializing_if` is missing or wrong.
|
|
#[test]
|
|
fn iter13a_schema_extension_preserves_pre_13a_hashes() {
|
|
let examples = examples_dir();
|
|
|
|
let sum_mod = ailang_surface::load_module(&examples.join("sum.ail"))
|
|
.expect("examples/sum.ail loads");
|
|
let sum_def = sum_mod.defs.iter().find(|d| d.name() == "sum").unwrap();
|
|
assert_eq!(def_hash(sum_def), "db33f57cb329935e");
|
|
|
|
let list_mod = ailang_surface::load_module(&examples.join("list.ail"))
|
|
.expect("examples/list.ail loads");
|
|
let int_list_def = list_mod.defs.iter().find(|d| d.name() == "IntList").unwrap();
|
|
assert_eq!(def_hash(int_list_def), "b082192bd0c99202");
|
|
}
|
|
|
|
/// Iter 19b regression: adding `suppress` to FnDef must NOT change
|
|
/// canonical-JSON hashes of any pre-19b fn whose `suppress` is empty.
|
|
/// The `skip_serializing_if = "Vec::is_empty"` predicate on the field
|
|
/// is what enforces this; if it is wrong, every existing fixture's
|
|
/// hash drifts and `ail diff` / `ail manifest` output breaks.
|
|
#[test]
|
|
fn iter19b_empty_suppress_preserves_pre_19b_hashes() {
|
|
let with_empty_suppress = sample_fn();
|
|
// Mutate the bare sample to set suppress explicitly to a
|
|
// non-empty Vec, then mutate it back to empty: two distinct
|
|
// construction paths that should still hash identically.
|
|
let mut with_explicit_empty = sample_fn();
|
|
if let Def::Fn(ref mut f) = with_explicit_empty {
|
|
f.suppress = vec![];
|
|
}
|
|
assert_eq!(
|
|
def_hash(&with_empty_suppress),
|
|
def_hash(&with_explicit_empty),
|
|
"two FnDefs with empty suppress must hash identically"
|
|
);
|
|
|
|
// And: a FnDef with a *non-empty* suppress hashes differently.
|
|
let mut with_suppress = sample_fn();
|
|
if let Def::Fn(ref mut f) = with_suppress {
|
|
f.suppress = vec![Suppress {
|
|
code: "over-strict-mode".into(),
|
|
because: "test reason".into(),
|
|
}];
|
|
}
|
|
assert_ne!(
|
|
def_hash(&with_empty_suppress),
|
|
def_hash(&with_suppress),
|
|
"non-empty suppress must produce a distinct hash"
|
|
);
|
|
}
|
|
|
|
/// Iter 19b: an on-disk pre-19b fixture must still load cleanly
|
|
/// (no `suppress` field present in the JSON) and produce its
|
|
/// canonical-byte hash unchanged.
|
|
#[test]
|
|
fn iter19b_schema_extension_preserves_pre_19b_hashes() {
|
|
let examples = examples_dir();
|
|
|
|
let sum_mod = ailang_surface::load_module(&examples.join("sum.ail"))
|
|
.expect("examples/sum.ail loads");
|
|
let sum_def = sum_mod.defs.iter().find(|d| d.name() == "sum").unwrap();
|
|
assert_eq!(def_hash(sum_def), "db33f57cb329935e");
|
|
}
|
|
|
|
/// Iter 22b.1 regression: adding `Def::Class` and `Def::Instance` must
|
|
/// NOT change canonical-JSON hashes of any pre-22b def. The new variants
|
|
/// are alternatives, not field additions — pre-22b fixtures simply do
|
|
/// not produce a `Class` / `Instance` `Def`, and the existing arms are
|
|
/// unchanged.
|
|
#[test]
|
|
fn iter22b1_schema_extension_preserves_pre_22b_hashes() {
|
|
let examples = examples_dir();
|
|
|
|
let sum_mod = ailang_surface::load_module(&examples.join("sum.ail"))
|
|
.expect("examples/sum.ail loads");
|
|
let sum_def = sum_mod.defs.iter().find(|d| d.name() == "sum").unwrap();
|
|
assert_eq!(def_hash(sum_def), "db33f57cb329935e");
|
|
|
|
let list_mod = ailang_surface::load_module(&examples.join("list.ail"))
|
|
.expect("examples/list.ail loads");
|
|
let int_list_def = list_mod
|
|
.defs
|
|
.iter()
|
|
.find(|d| d.name() == "IntList")
|
|
.unwrap();
|
|
assert_eq!(def_hash(int_list_def), "b082192bd0c99202");
|
|
}
|
|
|
|
/// Iter 22b.1: a ClassDef with no doc, no superclass, and an empty
|
|
/// methods list serialises to a stable canonical form. Two construction
|
|
/// paths (default-elided optionals vs. JSON without those keys at all)
|
|
/// hash bit-identically.
|
|
#[test]
|
|
fn iter22b1_classdef_empty_optionals_hash_stable() {
|
|
let bare = Def::Class(ClassDef {
|
|
name: "Empty".into(),
|
|
param: "a".into(),
|
|
superclass: None,
|
|
methods: vec![],
|
|
doc: None,
|
|
});
|
|
|
|
let json = r#"{"kind":"class","name":"Empty","param":"a","methods":[]}"#;
|
|
let parsed: Def = serde_json::from_str(json).unwrap();
|
|
|
|
assert_eq!(
|
|
def_hash(&bare),
|
|
def_hash(&parsed),
|
|
"ClassDef with elided optionals must hash identically to construction with explicit None"
|
|
);
|
|
}
|
|
|
|
/// Iter 22b.2: adding `constraints` to `Type::Forall` must NOT alter
|
|
/// canonical-JSON bytes of any pre-22b.2 polymorphic type.
|
|
#[test]
|
|
fn forall_without_constraints_hashes_bit_identical_to_pre_22b2() {
|
|
let t = Type::Forall {
|
|
vars: vec!["a".into()],
|
|
constraints: vec![],
|
|
body: Box::new(Type::fn_implicit(
|
|
vec![Type::Var { name: "a".into() }],
|
|
Type::Var { name: "a".into() },
|
|
vec![],
|
|
)),
|
|
};
|
|
let bytes = canonical::to_bytes(&t);
|
|
let s = std::str::from_utf8(&bytes).unwrap();
|
|
assert!(
|
|
!s.contains("constraints"),
|
|
"Type::Forall serialised must omit `constraints` when empty; got: {s}"
|
|
);
|
|
}
|
|
|
|
/// Iter ct.4 (canonical-type-names milestone close): pin the
|
|
/// canonical-form hashes of the two cross-module fixtures migrated by
|
|
/// `ail migrate-canonical-types` in ct.1. These hashes are the
|
|
/// post-migration state.
|
|
#[test]
|
|
fn ct4_migrated_fixtures_have_canonical_form_hashes() {
|
|
let examples = examples_dir();
|
|
|
|
let ord_mod = ailang_surface::load_module(&examples.join("ordering_match.ail"))
|
|
.expect("examples/ordering_match.ail loads");
|
|
let main_def = ord_mod.defs.iter().find(|d| d.name() == "main").unwrap();
|
|
assert_eq!(
|
|
def_hash(main_def),
|
|
"8d17235aa3d2e127",
|
|
"ordering_match::main canonical hash must match captured post-migration value"
|
|
);
|
|
|
|
let dup_a_mod = ailang_surface::load_module(&examples.join("test_22b1_dup_a.ail"))
|
|
.expect("examples/test_22b1_dup_a.ail loads");
|
|
assert_eq!(dup_a_mod.defs.len(), 1, "test_22b1_dup_a expected to have exactly 1 def (the instance)");
|
|
assert_eq!(
|
|
def_hash(&dup_a_mod.defs[0]),
|
|
"392c247f07de6517",
|
|
"test_22b1_dup_a instance hash drifted; expected post-24.2 captured value"
|
|
);
|
|
|
|
let dup_classmod_mod = ailang_surface::load_module(&examples.join("test_22b1_dup_classmod.ail"))
|
|
.expect("examples/test_22b1_dup_classmod.ail loads");
|
|
assert_eq!(dup_classmod_mod.defs.len(), 1, "test_22b1_dup_classmod expected to have exactly 1 def (class TShow)");
|
|
assert_eq!(
|
|
def_hash(&dup_classmod_mod.defs[0]),
|
|
"b8bca96c2d09ed93",
|
|
"test_22b1_dup_classmod class TShow canonical hash; post-24.2 captured value"
|
|
);
|
|
}
|
|
|
|
/// Iter ct.4: re-assert that the canonical-form tightening did NOT
|
|
/// change hashes of intra-module-only fixtures.
|
|
#[test]
|
|
fn ct4_unmigrated_fixtures_remain_bit_identical() {
|
|
let examples = examples_dir();
|
|
|
|
let sum_mod = ailang_surface::load_module(&examples.join("sum.ail"))
|
|
.expect("examples/sum.ail loads");
|
|
let sum_def = sum_mod.defs.iter().find(|d| d.name() == "sum").unwrap();
|
|
assert_eq!(def_hash(sum_def), "db33f57cb329935e",
|
|
"sum.sum hash drifted across canonical-form tightening — unexpected");
|
|
|
|
let list_mod = ailang_surface::load_module(&examples.join("list.ail"))
|
|
.expect("examples/list.ail loads");
|
|
let int_list_def = list_mod.defs.iter().find(|d| d.name() == "IntList").unwrap();
|
|
assert_eq!(def_hash(int_list_def), "b082192bd0c99202",
|
|
"list.IntList hash drifted across canonical-form tightening — unexpected");
|
|
}
|