14a91f0ae5
Closes Gitea #4. Removes the Boehm-Demers-Weiser conservative GC backend wholesale across six layers in one atomic iteration. After this iter, `AllocStrategy` has two variants (`Rc`, `Bump`), `--alloc=gc` is rejected at CLI parse with `unknown --alloc value`, the libgc link arm is gone, and the design ledger describes RC (canonical) + bump (raw-alloc bench-floor) as the only allocators. Layer-by-layer summary: CLI surface — `crates/ail/src/main.rs`: `parse_alloc_strategy` arm `"gc" => Ok(AllocStrategy::Gc)` removed; error wording updated to `(expected `rc` or `bump`)`; clap-derive `value_parser = ["gc","bump","rc"]` allowlist on BOTH `Build` and `Run` subcommands DROPPED so that `parse_alloc_strategy` remains the sole gatekeeper for the unknown-value diagnostic (otherwise clap shadows the runtime diagnostic with `invalid value 'gc' for '--alloc'`, which would miss the milestone-pin's stderr substring check). The `default_value = "rc"` stays. Codegen — `crates/ailang-codegen/src/lib.rs`: `AllocStrategy::Gc` variant + `Default` derive removed (no caller of `AllocStrategy::default()` existed in the workspace, so the trait derivation was dead). `fn_name` (spec called it `runtime_alloc_fn` loosely; actual identifier is `fn_name`) drops the `Gc => "GC_malloc"` arm. `lower_workspace` and `lower_workspace_staticlib` defaults flip from `Gc` to `Rc`. In-source negative-complement codegen test (mod tests, lib.rs:3571ff) retargets from `AllocStrategy::Gc` to `AllocStrategy::Bump` (bump also doesn't emit per-type drop fns; the test's semantic "no drop fns under non-RC" is preserved). Link branch — `crates/ail/src/main.rs:2389ff`: The `match strategy { AllocStrategy::Gc => { ... cmd.arg("-lgc"); ... } }` arm and its libgc-link block are entirely gone. The surviving match exhausts on `Bump` and `Rc` (Rust's exhaustiveness check confirms; no `error[E0004]`). Staticlib-guard diagnostic rewritten to drop the "shared Boehm collector" phrasing while preserving the prefix `staticlib (swarm) artefact is RC-only` verbatim (the surviving `staticlib_bump_is_rejected` test depends on that substring). Test suite — 3 pure-differential e2e tests deleted (`gc_handles_recursive_list_construction`, `alloc_rc_produces_same_stdout_as_gc`, `alloc_rc_matches_gc_on_std_list_demo`); 9 RC-feature tests stripped of their `stdout_gc` build call and differential `assert_eq!(stdout_gc, stdout_rc, ...)` (absolute `assert_eq!(stdout_rc.trim(), "<n>")` pin retained as correctness oracle); `staticlib_gc_is_rejected` deleted; new milestone-pin `crates/ail/tests/boehm_retirement_pin.rs` asserts `ail build --alloc=gc` exits ≠ 0 with stderr containing `unknown --alloc value` and `\`gc\``; `examples/gc_stress.ail` fixture deleted (no remaining references). Implementer expansion (not in plan): `iter17a_local_box_alloca` (in `e2e.rs`) carried an IR-shape assertion against `@GC_malloc`-absence as the witness for non-escaping allocation. After the Task-2 codegen default flip, the witness shifts to `@ailang_rc_alloc`-absence in escape-targeted positions; assertion + doc-comment updated. Property protected ("no heap allocation in non-escaping contexts") is unchanged; only the named allocator shifts. Bench harness — `bench/run.sh` 9→6 column compaction (workload + bump(s) + rc(s) + rc/bump + bump RSS + rc RSS); gc-arm `bench_latency_implicit_gc` build call + harness invocation dropped from latency block; header comment reframed from "GC-overhead bench harness" to "RC-overhead bench harness"; "Decision 10's Boehm-retirement target (1.3x)" rewording to "RC-overhead-vs-bump bench-health regression gate". `bench/check.py:62` header-sentinel changes from `"gc(s)" in line` to `"bump(s)" in line`; column-count check at `:72` flips from `!= 9` to `!= 6`; per-workload field set drops `gc_s`/`gc_over_bump`/`gc_rss_kb`; `ARM_LABEL_TO_KEY` drops the `"implicit @ gc": "implicit_at_gc"` entry. `bench/baseline.json` regenerated via `--update-baseline`. Implementer note (planner-defect): `write_new_baseline` iterated over the *existing* baseline's metric list when emitting the regenerated file, so even after parser-level `gc_*` removal, the fallback emitted them back into the JSON. Scrubbed post-update; the cleaner fix (have `write_new_baseline` emit only keys present in `parsed_throughput[workload]`) is a follow-up if the script becomes load-bearing for further allocator changes. Design ledger — `design/models/rc-uniqueness.md` excises the `## Dual allocator — RC canonical, Boehm parity oracle` section and the `Boehm-Demers-Weiser conservative GC` choice block + rationale + trade-offs; the per-fn-alloca section generalises Boehm-specific language to allocator-agnostic; the memory-model section's `## Choice.` paragraph reframes the 1.3× target from "Boehm-retirement gate" to "bench-health regression gate". `design/models/pipeline.md` drops the `--alloc=gc → links libgc` arm of the pipeline diagram and replaces it with `--alloc=bump → links bump-floor`; the accompanying prose rewrites accordingly. `design/contracts/scope-boundaries.md` rewrites the "Memory management via Boehm conservative GC" bullet to describe RC + per-fn-arena present-tense; the dead reference to `examples/gc_stress.ail.json` (file never existed; the fixture only ever had a `.ail` form, deleted by this iter) is dropped along with the `examples/std_list_stress.ail.json` reference whose purpose was Boehm-only soak testing. `:67`'s `@printf` / `@GC_malloc` parenthetical updated. `design/contracts/memory-model.md:232` drops the "leaks like the pre-Boehm era" phrase; the RC inc/dec instrumentation is wired up, so the "until then" conditional that referenced pre-Boehm is closed. `design/contracts/embedding-abi.md:42-44` rewrites the staticlib-guard prose to drop the `--alloc=gc` clause (gc is now a CLI-parser-level unknown-value, not a staticlib-guard rejection) and reframe the swarm-safety justification around `--alloc=bump` (leak-only bench instrument) rather than the historical Boehm collector. Honesty pin — `crates/ailang-core/tests/docs_honesty_pin.rs` inverts the polarity: the present-tense Boehm-anchor assertion on `pipeline.md` (`:116-117`) is deleted, and four absence-pins are added to `design_md_has_no_wunschdenken` against the Boehm-zombie strings `transitional Boehm`, `parity oracle`, `GC_malloc`, `libgc`. The `design_corpus()` already includes `rc-uniqueness.md` so no path-list change was needed for the new pins to scan. `crates/ailang-core/tests/design_index_pin.rs:166` drops the `"pre-Boehm"` token from the protected-exception comment list (the phrase no longer appears in `memory-model.md` after this iter, so the exception is dead). Runtime docs — `runtime/bump.c`, `runtime/rc.c`, `runtime/str.c` header comments scrubbed of Boehm/`GC_malloc`/`libgc` references. `bump.c`'s function signature description still documents `void *bump_malloc(size_t)` as the bench-floor allocator interface, but no longer cross-references libgc. Example fixtures — `examples/bench_latency_implicit.ail`, `bench_latency_explicit.ail`, `escape_local_demo.ail`, `reuse_as_demo.ail`, `rc_pin_recurse_implicit.ail` doc-comment headers scrubbed of `--alloc=gc` / Boehm references. The `.ail` surface (AST) is untouched in every case; round-trip invariant holds (`cargo test -p ailang-surface --test round_trip` green). Skill / agent prompts — `skills/audit/agents/ailang-bencher.md` rewritten to use an RC-vs-bump worked example pattern for the hypothesis-driven bench tutorial, replacing the recurring "RC vs Boehm under heap pressure" example. `skills/implement/agents/ailang-implementer.md` Decision-10 / Boehm references replaced with present-tense RC-commitment framing. IR snapshots — the 5 checked-in snapshots (`crates/ail/tests/snapshots/{hello,list,max3,sum,ws_main}.ll`) regenerated via `UPDATE_SNAPSHOTS=1 cargo test -p ail --test ir_snapshot`. Each previously contained `declare ptr @GC_malloc(i64)` and (for `list.ll`) a `call ptr @GC_malloc(...)` invocation; post-flip the snapshots contain `declare ptr @ailang_rc_alloc(i64)` plus the rc inc/dec runtime declarations. Spec-vs-acceptance addendum (caught at orchestrator end-report, absorbed here rather than in a follow-up spec edit): spec §6 acceptance criteria said "Boehm-grep returns matches ONLY in docs_honesty_pin.rs". The plan itself prescribed historical Boehm references in 3 additional files: (a) the new milestone-pin `boehm_retirement_pin.rs` (must literally invoke `--alloc=gc` to assert its rejection), (b) `embed_staticlib_alloc_guard.rs` file doc-comment historical note ("`--alloc=gc` no longer exists as a CLI value"), (c) `embedding-abi.md:44-45` contract historical clause ("see the Boehm-retirement iter"). All three are prescribed; the spec's grep wording was too narrow. The four absence-pins in `docs_honesty_pin.rs` catch the actual zombies (Boehm-narrative re-emerging in the design ledger), which is the substantive intent the spec was aiming at — the four extra documented-by-design exceptions are the cost of having an explicit milestone-pin and contract-level historical anchors. Net delta: - 32 files modified, 2 new (boehm_retirement_pin.rs + stats), 1 deleted (gc_stress.ail); - workspace tests: every binary `0 failed`. Pass-count delta: -3 net (4 e2e tests deleted, 1 new milestone-pin test added); - boehm-grep state: hits only in the four by-design exceptions documented above; - `bench/check.py` exit 0 against regenerated baseline; - CLI must-fail fixture: `ail build --alloc=gc examples/hello.ail` exits non-zero with stderr containing `unknown --alloc value` and `\`gc\``; - design ledger present-tense honest (Boehm-narrative gone from `rc-uniqueness.md` + `pipeline.md`; the few historical references in `embedding-abi.md` / `boehm_retirement_pin.rs` / `embed_staticlib_alloc_guard.rs` are explicit milestone-pins or contract anchors, not silent ledger residue). Bench measurement variance noted: closure-chain and hof-pipeline are ±1-5% jittery between runs; one regeneration flagged 2 metrics as `regressed` before a second run returned 0. The captured baseline is within self-comparison range. Existing per-metric tolerances absorb the jitter. Stats file: `bench/orchestrator-stats/2026-05-20-iter-boehm-retirement.1.json`. closes #4
371 lines
14 KiB
Rust
371 lines
14 KiB
Rust
//! Structural pin for the design/ ledger. Sibling of
|
|
//! docs_honesty_pin.rs. Fails RED the instant the design/ split
|
|
//! re-conflates contract + rationale + narrative, an INDEX row
|
|
//! dangles, a contract loses its ratifying test, docs/DESIGN.md is
|
|
//! resurrected, or a design/ body cross-link fails to resolve into
|
|
//! the durable tier (clause-5; spec
|
|
//! docs/specs/2026-05-19-design-ledger-formal-links.md). Spec for
|
|
//! the split: docs/specs/2026-05-19-design-md-rolesplit.md.
|
|
|
|
use std::fs;
|
|
use std::path::PathBuf;
|
|
|
|
fn root() -> PathBuf {
|
|
PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/../../"))
|
|
}
|
|
|
|
fn read(rel: &str) -> String {
|
|
fs::read_to_string(root().join(rel))
|
|
.unwrap_or_else(|e| panic!("read {rel}: {e}"))
|
|
}
|
|
|
|
fn norm(s: &str) -> String {
|
|
s.split_whitespace().collect::<Vec<_>>().join(" ")
|
|
}
|
|
|
|
/// Parse the two pipe-tables out of design/INDEX.md.
|
|
/// Returns (contracts, models) as rows of trimmed cells.
|
|
fn index_tables() -> (Vec<Vec<String>>, Vec<Vec<String>>) {
|
|
let idx = read("design/INDEX.md");
|
|
let mut contracts = Vec::new();
|
|
let mut models = Vec::new();
|
|
let mut section = "";
|
|
for line in idx.lines() {
|
|
let t = line.trim();
|
|
if t.starts_with("## Contracts") {
|
|
section = "c";
|
|
continue;
|
|
}
|
|
if t.starts_with("## Models") {
|
|
section = "m";
|
|
continue;
|
|
}
|
|
if !t.starts_with('|') {
|
|
continue;
|
|
}
|
|
let cells: Vec<String> = t
|
|
.trim_matches('|')
|
|
.split('|')
|
|
.map(|c| c.trim().to_string())
|
|
.collect();
|
|
// skip header + separator rows
|
|
if cells.iter().any(|c| c.starts_with("---")) {
|
|
continue;
|
|
}
|
|
if cells.first().map(|c| c.as_str()) == Some("id") {
|
|
continue;
|
|
}
|
|
match section {
|
|
"c" => contracts.push(cells),
|
|
"m" => models.push(cells),
|
|
_ => {}
|
|
}
|
|
}
|
|
(contracts, models)
|
|
}
|
|
|
|
/// A link cell may be a design/ path, a source path, a dual-link
|
|
/// "A + B", or carry a trailing "(in-source ...)" / "§..." note.
|
|
/// Resolve to the first concrete path token and check it exists.
|
|
fn link_target_exists(cell: &str) -> bool {
|
|
let first = cell.split(" + ").next().unwrap_or(cell).trim();
|
|
// strip a trailing parenthetical or §-note
|
|
let path = first
|
|
.split(" (")
|
|
.next()
|
|
.unwrap_or(first)
|
|
.split(" §")
|
|
.next()
|
|
.unwrap_or(first)
|
|
.trim()
|
|
.trim_end_matches("//!")
|
|
.trim();
|
|
!path.is_empty() && root().join(path).exists()
|
|
}
|
|
|
|
#[test]
|
|
fn design_md_is_gone() {
|
|
// clause 4 — clean-cut pin
|
|
assert!(
|
|
!root().join("docs/DESIGN.md").exists(),
|
|
"docs/DESIGN.md was resurrected; the split is clean-cut"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn every_index_link_resolves() {
|
|
// clause 1
|
|
let (contracts, models) = index_tables();
|
|
assert!(contracts.len() >= 15, "expected >=15 contract rows, got {}", contracts.len());
|
|
assert!(models.len() >= 5, "expected >=5 model rows, got {}", models.len());
|
|
for row in contracts.iter().chain(models.iter()) {
|
|
let link = row.last().expect("row has a link cell");
|
|
assert!(
|
|
link_target_exists(link),
|
|
"INDEX link does not resolve: {:?} (row {:?})",
|
|
link,
|
|
row
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn every_contract_names_a_resolvable_ratifying_test() {
|
|
// clause 2 — ratifying-test token resolves to a real file under
|
|
// crates/**/tests, crates/**/src (in-source #[cfg(test)] mod
|
|
// tests are first-class ratifiers — spec OQ1/OQ2), bench/, or
|
|
// skills/**/SKILL.md.
|
|
let (contracts, _) = index_tables();
|
|
for row in &contracts {
|
|
// columns: id | consumer/lifetime | ratifying-test | link
|
|
let rt = &row[2];
|
|
// take the path token (before any " (" note)
|
|
let path = rt.split(" (").next().unwrap_or(rt).trim();
|
|
assert!(
|
|
root().join(path).exists(),
|
|
"ratifying-test does not resolve to a real file: {:?} (contract {:?})",
|
|
path,
|
|
row[0]
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn contracts_carry_no_decision_record_prose() {
|
|
// clause 3 — the conflation tripwire, widened (design-md-rolesplit.tidy,
|
|
// audit Resolution-4) to a FAITHFUL SUPERSET of
|
|
// bench/architect_sweeps.sh Sweep-1's history-anchor regex over the
|
|
// design/contracts/ scope, PLUS the audit-named decision-record
|
|
// phrases (the deliberate widening that closes the case-variance
|
|
// dodge the 6 literal markers left open).
|
|
//
|
|
// Invariant: clause-3 GREEN ⟹ Sweep-1 finds nothing in design/contracts/.
|
|
//
|
|
// Sweep-1 = 'Iter [0-9]+[a-z]?(\.[0-9]+)?|Family [0-9]+
|
|
// |^[^/]*2026-[0-9]{2}-[0-9]{2}|\*\*Status: |pre-[0-9]+[a-z]?
|
|
// |[0-9]+[a-z]? sketch|21\.g'
|
|
// Faithfulness, per Sweep-1 alternative:
|
|
// - Iter / Family / pre- / <n> sketch / 21.g / **Status:
|
|
// → sweep1_line_anchor() reproduces each verbatim,
|
|
// case-SENSITIVE (grep -E, no -i) — exactly Sweep-1 here,
|
|
// never narrower.
|
|
// - ^[^/]*2026-NN-NN → date_anchor() reproduces Sweep-1's
|
|
// ^[^/]* PATH-EXCLUSION (only the line prefix before the
|
|
// first '/' is scanned) and generalises 2026→20NN
|
|
// (⊇ Sweep-1, never narrower). A `docs/specs/2026-..`
|
|
// citation has '/' before the date ⇒ NOT flagged — faithful
|
|
// to Sweep-1, no over-fire on legit present-tense spec
|
|
// cross-refs (the iter-.1 plan defect this repairs).
|
|
// - PHRASES: literal decision-record idioms (case-insensitive) —
|
|
// the deliberate widening that closes the capital-variance
|
|
// dodge ("An earlier draft" vs "an earlier draft").
|
|
//
|
|
// A blanket case-insensitive iter/milestone detector was evaluated
|
|
// and REJECTED (audit Resolution-4 corrected): it conflates the
|
|
// memory-model rule-names "Iter A"/"Iter B", and ordinary words
|
|
// "pre-existing"/"pre-set"/"pre-tail-call", with
|
|
// provenance stamps — unworkable. faithful-Sweep-1 (the capital-I,
|
|
// digit-anchored form) already excludes those by construction and
|
|
// is confirmed ZERO across every contract file; lowercase
|
|
// `(iter <code>)` provenance is removed by the strip tasks, not by
|
|
// a fragile hard-gate regex. The load-bearing invariant
|
|
// (clause-3 GREEN ⟹ Sweep-1 clean in contracts/) holds with
|
|
// sweep1_line_anchor + date_anchor + PHRASES alone.
|
|
let dir = root().join("design/contracts");
|
|
|
|
const PHRASES: &[&str] = &[
|
|
"we rejected", "an earlier draft", "earlier draft committed",
|
|
"why not other", "was retired", "were retired", "rollback plan",
|
|
"previously all", "deliberately deferred", "new-baseline decision",
|
|
"amends the above", "out of scope per",
|
|
"the journal records when", "unchanged from the original draft",
|
|
];
|
|
|
|
// Sweep-1's non-date alternatives, hand-rolled verbatim, case-SENSITIVE
|
|
// (grep -E without -i), on the raw physical line.
|
|
fn sweep1_line_anchor(line: &str) -> Option<&'static str> {
|
|
let kw_digit = |kw: &str| -> bool {
|
|
let mut from = 0;
|
|
while let Some(i) = line[from..].find(kw) {
|
|
let p = from + i + kw.len();
|
|
if line[p..].chars().next().map_or(false, |c| c.is_ascii_digit()) {
|
|
return true;
|
|
}
|
|
from = p;
|
|
}
|
|
false
|
|
};
|
|
if kw_digit("Iter ") { return Some("Iter <n>"); }
|
|
if kw_digit("Family ") { return Some("Family <n>"); }
|
|
if kw_digit("pre-") { return Some("pre-<n>"); }
|
|
if line.contains("**Status: ") { return Some("**Status:"); }
|
|
if line.contains("21.g") { return Some("21.g"); }
|
|
if let Some(s) = line.find(" sketch") {
|
|
let pre = line[..s].as_bytes();
|
|
if pre.last().map_or(false, u8::is_ascii_alphanumeric)
|
|
&& pre.iter().rev()
|
|
.take_while(|c| c.is_ascii_alphanumeric())
|
|
.any(u8::is_ascii_digit)
|
|
{
|
|
return Some("<n> sketch");
|
|
}
|
|
}
|
|
None
|
|
}
|
|
|
|
// Sweep-1's `^[^/]*2026-NN-NN`, generalised to 20NN-NN-NN,
|
|
// PATH-EXCLUDED: scan only the line prefix BEFORE the first '/'.
|
|
fn date_anchor(line: &str) -> Option<String> {
|
|
let prefix = line.split('/').next().unwrap_or(line).as_bytes();
|
|
for w in prefix.windows(10) {
|
|
if w[0] == b'2' && w[1] == b'0'
|
|
&& w[2].is_ascii_digit() && w[3].is_ascii_digit()
|
|
&& w[4] == b'-' && w[5].is_ascii_digit() && w[6].is_ascii_digit()
|
|
&& w[7] == b'-' && w[8].is_ascii_digit() && w[9].is_ascii_digit()
|
|
{
|
|
return Some(String::from_utf8_lossy(w).into_owned());
|
|
}
|
|
}
|
|
None
|
|
}
|
|
|
|
for entry in fs::read_dir(&dir).expect("design/contracts/ exists") {
|
|
let p = entry.unwrap().path();
|
|
if p.extension().and_then(|e| e.to_str()) != Some("md") {
|
|
continue;
|
|
}
|
|
let raw = fs::read_to_string(&p).unwrap();
|
|
let fname = p.file_name().unwrap().to_string_lossy().into_owned();
|
|
let low = norm(&raw).to_lowercase();
|
|
for ph in PHRASES {
|
|
assert!(
|
|
!low.contains(ph),
|
|
"clause-3: history phrase {ph:?} in contract {fname:?}"
|
|
);
|
|
}
|
|
for line in raw.lines() {
|
|
if let Some(a) = sweep1_line_anchor(line) {
|
|
panic!("clause-3: Sweep-1 anchor {a:?} in contract {fname:?}: {line:?}");
|
|
}
|
|
if let Some(d) = date_anchor(line) {
|
|
panic!("clause-3: history date {d:?} in contract {fname:?}: {line:?}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#[test]
|
|
fn design_body_links_are_durable_and_resolve() {
|
|
// clause 5 — every inline Markdown link in design/ body prose
|
|
// (contracts/ + models/, NOT INDEX.md — the spine is the
|
|
// structured registry tier resolved by clause-1, commitment 4)
|
|
// resolves, relative to its CONTAINING file, to an existing
|
|
// file under design/ or source (crates/** | runtime/**); never
|
|
// under docs/; never an in-file #anchor. Fenced code blocks are
|
|
// not scanned (a `](` inside ``` is literal text, not a link).
|
|
// Composes with clause-3: a surviving cross-reference is a
|
|
// resolving durable file-link or it is clause-3-forbidden
|
|
// decision-record prose.
|
|
|
|
// Fenced code (``` … ``` / ~~~ … ~~~) is literal text, not
|
|
// Markdown — a `](` inside a fence is NOT a navigable link on
|
|
// any renderer. Strip fenced regions before scanning (gate
|
|
// correctness: prevents false extraction of code-example byte
|
|
// sequences and of non-rendering in-fence links).
|
|
fn strip_fences(md: &str) -> String {
|
|
let mut out = String::new();
|
|
let mut in_fence = false;
|
|
for line in md.lines() {
|
|
let t = line.trim_start();
|
|
if t.starts_with("```") || t.starts_with("~~~") {
|
|
in_fence = !in_fence;
|
|
continue; // drop the fence marker line itself
|
|
}
|
|
if !in_fence {
|
|
out.push_str(line);
|
|
out.push('\n');
|
|
}
|
|
}
|
|
out
|
|
}
|
|
|
|
// link target := first capture of \]\(([^)]+)\)
|
|
fn targets(md: &str) -> Vec<String> {
|
|
let mut out = Vec::new();
|
|
let b = md.as_bytes();
|
|
let mut i = 0;
|
|
while i + 1 < b.len() {
|
|
if b[i] == b']' && b[i + 1] == b'(' {
|
|
if let Some(end) = md[i + 2..].find(')') {
|
|
out.push(md[i + 2..i + 2 + end].trim().to_string());
|
|
}
|
|
}
|
|
i += 1;
|
|
}
|
|
out
|
|
}
|
|
|
|
fn is_durable(repo_rel: &str) -> bool {
|
|
repo_rel.starts_with("design/")
|
|
|| repo_rel.starts_with("crates/")
|
|
|| repo_rel.starts_with("runtime/")
|
|
}
|
|
|
|
// RED-first synthetic vectors (proves the gate bites before it
|
|
// is pointed at the live tree).
|
|
{
|
|
let t = targets("see [x](../docs/specs/foo.md) and [y](#sec) and [z](./gone.md)");
|
|
assert_eq!(t, vec!["../docs/specs/foo.md", "#sec", "./gone.md"]);
|
|
assert!(!is_durable("docs/specs/foo.md")); // durable-tier reject
|
|
assert!("#sec".starts_with('#')); // in-file anchor reject
|
|
// fenced code is not a link surface (gate correctness)
|
|
assert!(targets(&strip_fences("```\nsee [E](e.md)\n```\n")).is_empty());
|
|
assert_eq!(targets(&strip_fences("[k](k.md)\n```\n[n](n.md)\n```")), vec!["k.md"]);
|
|
}
|
|
|
|
let bases = ["design/contracts", "design/models"];
|
|
for base in bases {
|
|
let dir = root().join(base);
|
|
for entry in fs::read_dir(&dir).expect("design/ subdir exists") {
|
|
let p = entry.unwrap().path();
|
|
if p.extension().and_then(|e| e.to_str()) != Some("md") {
|
|
continue;
|
|
}
|
|
let raw = fs::read_to_string(&p).unwrap();
|
|
let fname = format!("{base}/{}", p.file_name().unwrap().to_string_lossy());
|
|
for tgt in targets(&strip_fences(&raw)) {
|
|
if tgt.starts_with("http://")
|
|
|| tgt.starts_with("https://")
|
|
|| tgt.starts_with("mailto:")
|
|
{
|
|
continue;
|
|
}
|
|
let file_part = tgt.split('#').next().unwrap_or(&tgt);
|
|
assert!(
|
|
!file_part.is_empty(),
|
|
"clause-5: in-file #anchor link {tgt:?} in {fname:?} — \
|
|
commitment 1 forbids fragments; split the file"
|
|
);
|
|
let resolved = p.parent().unwrap().join(file_part);
|
|
let canon = resolved
|
|
.canonicalize()
|
|
.unwrap_or_else(|e| panic!(
|
|
"clause-5: link {tgt:?} in {fname:?} does not resolve: {e}"
|
|
));
|
|
let repo_rel = canon
|
|
.strip_prefix(root().canonicalize().unwrap())
|
|
.unwrap_or(&canon)
|
|
.to_string_lossy()
|
|
.replace('\\', "/");
|
|
assert!(
|
|
is_durable(&repo_rel),
|
|
"clause-5: link {tgt:?} in {fname:?} targets the \
|
|
non-durable tier ({repo_rel:?}); commitment 2 \
|
|
permits design/ + crates/ + runtime/ only"
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|