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.
233 lines
10 KiB
Rust
233 lines
10 KiB
Rust
//! ct.1: E2E coverage for the CLI surface of the canonical-type-names
|
|
//! validator. The unit tests in `workspace.rs` already prove the
|
|
//! validator fires; these tests prove the diagnostic survives the
|
|
//! `WorkspaceLoadError -> Diagnostic` translation in
|
|
//! `crates/ail/src/main.rs::workspace_error_to_diagnostic` AND is
|
|
//! observable on the CLI in both `--json` and human modes (exit code
|
|
//! + diagnostic code in the output stream).
|
|
//!
|
|
//! Companion to the happy-path test below: post-migration
|
|
//! `examples/ordering_match.ail.json` must `ail check` cleanly. If
|
|
//! someone reverts the migration (or breaks the canonical-form
|
|
//! acceptance path in the registry), that test goes red.
|
|
|
|
use std::path::PathBuf;
|
|
use std::process::Command;
|
|
|
|
fn ail_bin() -> PathBuf {
|
|
// CARGO_BIN_EXE_<name> is set by cargo when building integration tests.
|
|
PathBuf::from(env!("CARGO_BIN_EXE_ail"))
|
|
}
|
|
|
|
fn examples_dir() -> PathBuf {
|
|
// CARGO_MANIFEST_DIR points at `crates/ail`; examples/ sits at the
|
|
// workspace root, two levels up.
|
|
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
|
.join("..")
|
|
.join("..")
|
|
.join("examples")
|
|
}
|
|
|
|
/// Property: a workspace whose entry module contains a bare
|
|
/// cross-module Type::Con / Term::Ctor reference — here `Ordering`,
|
|
/// satisfiable only via the auto-injected `prelude` — is rejected by
|
|
/// `ail check --json` with diagnostic code `bare-cross-module-type-ref`
|
|
/// and non-zero exit. Guards against `workspace_error_to_diagnostic`
|
|
/// losing the `BareCrossModuleTypeRef` arm or the validator no longer
|
|
/// firing through the CLI loader path.
|
|
#[test]
|
|
fn check_json_emits_bare_cross_module_type_ref() {
|
|
let fixture = examples_dir().join("test_ct1_bare_xmod_rejected.ail.json");
|
|
let output = Command::new(ail_bin())
|
|
.args(["check", "--json", fixture.to_str().unwrap()])
|
|
.output()
|
|
.expect("ail binary must launch");
|
|
assert!(
|
|
!output.status.success(),
|
|
"ail check must fail on bare cross-module ref; stdout={} stderr={}",
|
|
String::from_utf8_lossy(&output.stdout),
|
|
String::from_utf8_lossy(&output.stderr),
|
|
);
|
|
let stdout = String::from_utf8(output.stdout).expect("stdout is utf-8");
|
|
let diags: serde_json::Value =
|
|
serde_json::from_str(&stdout).expect("--json mode emits a JSON array on stdout");
|
|
let arr = diags.as_array().expect("diagnostics is a JSON array");
|
|
assert!(
|
|
arr.iter().any(|d| d["code"] == "bare-cross-module-type-ref"),
|
|
"expected `bare-cross-module-type-ref` in diagnostics array; got {stdout}"
|
|
);
|
|
}
|
|
|
|
/// Property: a qualified `<owner>.<name>` Type::Con where `<owner>` is
|
|
/// not a known module is rejected by `ail check --json` with
|
|
/// diagnostic code `bad-cross-module-type-ref` and non-zero exit.
|
|
/// Guards against `workspace_error_to_diagnostic` losing the
|
|
/// `BadCrossModuleTypeRef` arm.
|
|
#[test]
|
|
fn check_json_emits_bad_cross_module_type_ref() {
|
|
let fixture = examples_dir().join("test_ct1_bad_qualifier.ail.json");
|
|
let output = Command::new(ail_bin())
|
|
.args(["check", "--json", fixture.to_str().unwrap()])
|
|
.output()
|
|
.expect("ail binary must launch");
|
|
assert!(
|
|
!output.status.success(),
|
|
"ail check must fail on unknown qualifier; stdout={} stderr={}",
|
|
String::from_utf8_lossy(&output.stdout),
|
|
String::from_utf8_lossy(&output.stderr),
|
|
);
|
|
let stdout = String::from_utf8(output.stdout).expect("stdout is utf-8");
|
|
let diags: serde_json::Value =
|
|
serde_json::from_str(&stdout).expect("--json mode emits a JSON array on stdout");
|
|
let arr = diags.as_array().expect("diagnostics is a JSON array");
|
|
assert!(
|
|
arr.iter().any(|d| d["code"] == "bad-cross-module-type-ref"),
|
|
"expected `bad-cross-module-type-ref` in diagnostics array; got {stdout}"
|
|
);
|
|
}
|
|
|
|
/// Property: mq.1 — a qualified class name in an `InstanceDef.class`
|
|
/// field is the canonical form, not a rejection. The
|
|
/// `test_ct1_qualified_class_rejected` fixture (declares
|
|
/// `instance prelude.Eq Int` outside prelude and outside Int's
|
|
/// defining module) is now rejected by the downstream coherence
|
|
/// check with `orphan-instance` instead of the pre-mq.1
|
|
/// `qualified-class-name`. Guards against
|
|
/// `workspace_error_to_diagnostic` losing the OrphanInstance arm
|
|
/// AND against any regression that would reintroduce
|
|
/// `qualified-class-name` on a referencing field.
|
|
#[test]
|
|
fn check_json_emits_orphan_instance_on_xmod_class_without_coherence_post_mq1() {
|
|
let fixture = examples_dir().join("test_ct1_qualified_class_rejected.ail.json");
|
|
let output = Command::new(ail_bin())
|
|
.args(["check", "--json", fixture.to_str().unwrap()])
|
|
.output()
|
|
.expect("ail binary must launch");
|
|
assert!(
|
|
!output.status.success(),
|
|
"ail check must fail; stdout={} stderr={}",
|
|
String::from_utf8_lossy(&output.stdout),
|
|
String::from_utf8_lossy(&output.stderr),
|
|
);
|
|
let stdout = String::from_utf8(output.stdout).expect("stdout is utf-8");
|
|
let diags: serde_json::Value =
|
|
serde_json::from_str(&stdout).expect("--json mode emits a JSON array on stdout");
|
|
let arr = diags.as_array().expect("diagnostics is a JSON array");
|
|
assert!(
|
|
arr.iter().any(|d| d["code"] == "orphan-instance"),
|
|
"expected `orphan-instance` in diagnostics array; got {stdout}"
|
|
);
|
|
assert!(
|
|
!arr.iter().any(|d| d["code"] == "qualified-class-name"),
|
|
"must NOT fire `qualified-class-name` on a referencing field post-mq.1; got {stdout}"
|
|
);
|
|
}
|
|
|
|
/// Property: in non-JSON (human) mode `ail check` exits non-zero on a
|
|
/// ct.1 validator failure and writes an actionable error message to
|
|
/// stderr — naming both the offending type and the migration command
|
|
/// the author should run. Pinning the human-mode path separately
|
|
/// because in this mode the loader error short-circuits via `anyhow`
|
|
/// (no diagnostic-code prefix) and is formatted by the
|
|
/// `WorkspaceLoadError`'s `thiserror` Display impl rather than by
|
|
/// `workspace_error_to_diagnostic`. A regression that left `--json`
|
|
/// working but stripped the actionable hint from the human path
|
|
/// would otherwise ship unnoticed. The bare-cross-module fixture is
|
|
/// the representative case; the property — actionable hint in the
|
|
/// Display impl — is named per-variant.
|
|
#[test]
|
|
fn check_human_mode_emits_actionable_message_to_stderr() {
|
|
let fixture = examples_dir().join("test_ct1_bare_xmod_rejected.ail.json");
|
|
let output = Command::new(ail_bin())
|
|
.args(["check", fixture.to_str().unwrap()])
|
|
.output()
|
|
.expect("ail binary must launch");
|
|
assert!(
|
|
!output.status.success(),
|
|
"ail check (human mode) must fail on bare cross-module ref"
|
|
);
|
|
let stderr = String::from_utf8(output.stderr).expect("stderr is utf-8");
|
|
assert!(
|
|
stderr.contains("Ordering"),
|
|
"expected the offending type name in stderr; got {stderr}"
|
|
);
|
|
assert!(
|
|
stderr.contains("ail migrate-canonical-types"),
|
|
"expected the migration-command hint in stderr; got {stderr}"
|
|
);
|
|
}
|
|
|
|
/// Property: the post-migration `examples/ordering_match.ail.json`
|
|
/// (Term::Ctor `Ordering` -> `prelude.Ordering`) typechecks cleanly
|
|
/// through the CLI — `ail check` exits 0 with no diagnostics.
|
|
/// Guards against (a) a revert of the ct.1.5 migration, (b) a
|
|
/// regression in `Registry::normalize_type_for_lookup` that would make
|
|
/// the canonical (qualified) form fail to dispatch where the bare
|
|
/// form used to succeed.
|
|
#[test]
|
|
fn check_ordering_match_post_migration_is_clean() {
|
|
let fixture = examples_dir().join("ordering_match.ail");
|
|
let output = Command::new(ail_bin())
|
|
.args(["check", "--json", fixture.to_str().unwrap()])
|
|
.output()
|
|
.expect("ail binary must launch");
|
|
assert!(
|
|
output.status.success(),
|
|
"ail check must succeed on migrated ordering_match; stdout={} stderr={}",
|
|
String::from_utf8_lossy(&output.stdout),
|
|
String::from_utf8_lossy(&output.stderr),
|
|
);
|
|
let stdout = String::from_utf8(output.stdout).expect("stdout is utf-8");
|
|
let diags: serde_json::Value =
|
|
serde_json::from_str(&stdout).expect("--json mode emits a JSON array on stdout");
|
|
let arr = diags.as_array().expect("diagnostics is a JSON array");
|
|
assert!(
|
|
arr.is_empty(),
|
|
"expected zero diagnostics on migrated fixture; got {stdout}"
|
|
);
|
|
}
|
|
|
|
/// Property: `ail check --json` on a `.ail` (Form A) source file with
|
|
/// a syntax error returns a structured `surface-parse-error`
|
|
/// diagnostic (non-empty diagnostics array, exit code != 0), rather
|
|
/// than crashing with the misleading JSON-parse fall-through that
|
|
/// ext-cli.1 was built to eliminate. Guards against
|
|
/// `workspace_error_to_diagnostic` losing the `SurfaceParse` arm or
|
|
/// the surface dispatcher silently swallowing the parse error.
|
|
#[test]
|
|
fn ail_check_json_on_ail_with_syntax_error_returns_structured_diagnostic() {
|
|
let tmp = tempfile::tempdir().expect("tempdir");
|
|
let bad = tmp.path().join("bad.ail");
|
|
// Deliberately broken — missing closing paren in the module header.
|
|
std::fs::write(&bad, "(module bad\n").expect("write");
|
|
|
|
let output = Command::new(ail_bin())
|
|
.args(["check", "--json", bad.to_str().unwrap()])
|
|
.output()
|
|
.expect("run ail check --json");
|
|
|
|
// ail check --json on a bad .ail should NOT crash with the misleading
|
|
// JSON-parse fall-through; it should return exit code != 0 and emit a
|
|
// parseable JSON diagnostic on stdout.
|
|
assert!(
|
|
!output.status.success(),
|
|
"expected non-zero exit on bad source; stdout={} stderr={}",
|
|
String::from_utf8_lossy(&output.stdout),
|
|
String::from_utf8_lossy(&output.stderr),
|
|
);
|
|
|
|
let stdout = String::from_utf8(output.stdout).expect("stdout is UTF-8");
|
|
let parsed: serde_json::Value = serde_json::from_str(&stdout)
|
|
.unwrap_or_else(|e| panic!("stdout not valid JSON: {e}\ngot:\n{stdout}"));
|
|
|
|
let diags = parsed.as_array().expect("diagnostics array");
|
|
assert!(!diags.is_empty(), "at least one diagnostic emitted");
|
|
let first = &diags[0];
|
|
assert_eq!(first["code"].as_str(), Some("surface-parse-error"));
|
|
// The offending path goes into the ctx payload (matching the
|
|
// shape every other workspace-error diagnostic uses, e.g.
|
|
// `schema-mismatch` puts `expected`/`actual` there).
|
|
assert!(first["ctx"]["path"].is_string(), "ctx.path is the file path");
|
|
assert!(first["message"].is_string(), "message is the formatted ParseError");
|
|
}
|