Skip to content

Commit 9c30ce0

Browse files
tachyon-beepclaude
andcommitted
test(conformance): legis git-rename consumer reaches the bar
The consumer half of the legis->loomweave git-rename seam: drive the REAL parse_legis_rename_json over a byte-identical vendored copy of the shared golden git_renames.v1.json (blob 74f69ee..., frozen from legis's real GET /git/renames), asserting the projected (old_path,new_path) pairs and pinning the blob sha1 (Layer-1 fail-closed byte-pin). Producer (legis) and consumer (loomweave) now load the SAME bytes and AGREE; a wire drift on either side reds in CI. The two #[test]s live in sei_git.rs's existing test module (not under tests/) because parse_legis_rename_json is private to this binary crate and unreachable from an integration test. No existing test altered. Byte-pin negative-probed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9f611d2 commit 9c30ce0

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

crates/loomweave-cli/src/sei_git.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,74 @@ mod tests {
628628
assert!(parse_legis_rename_json(r#"{"not":"an array"}"#).is_empty());
629629
}
630630

631+
// ── Weft shared golden: legis (producer) → Loomweave (consumer) ────────────
632+
//
633+
// This is the CONSUMER half of a single cross-member golden,
634+
// `tests/fixtures/weft/git_renames.v1.json`. The byte-identical file lives in
635+
// legis at `tests/contract/weft/vectors/git_renames.v1.json`; legis's
636+
// producer oracle drives its REAL `GET /git/renames` and proves the same
637+
// projection. Here we drive the REAL `parse_legis_rename_json` over the
638+
// frozen bytes and prove it accepts exactly that wire shape.
639+
//
640+
// Why a `#[cfg(test)]`-module test and not an integration test under
641+
// `tests/`: `parse_legis_rename_json` is private to this binary crate (no
642+
// `lib.rs`), so it is unreachable from `tests/` — the consumer oracle MUST
643+
// live next to the parser it exercises.
644+
//
645+
// The golden was FROZEN from legis's actual endpoint output (a real
646+
// `auth.py → authn.py` rename captured via FastAPI `TestClient`), with one
647+
// synthetic empty-`new_path` item appended that git/legis never emit — the
648+
// skip case the parser must drop. `include_bytes!` pins the exact vendored
649+
// bytes at compile time (a moved/renamed file fails the build, loudly).
650+
651+
/// The byte-identical vendored copy of the shared Weft golden.
652+
const VENDORED_GOLDEN: &[u8] = include_bytes!("../tests/fixtures/weft/git_renames.v1.json");
653+
654+
/// The git blob sha1 of the frozen golden bytes:
655+
/// `sha1(b"blob <len>\0" + bytes)`. legis's producer oracle pins the SAME
656+
/// constant against the SAME bytes — the two repos are locked to one wire
657+
/// shape. Re-pin only by re-freezing the golden and updating BOTH repos.
658+
const VENDORED_BLOB_SHA: &str = "74f69ee81b030a31f9fdd37dc1c49543fbe389c2";
659+
660+
/// The REAL parser accepts the frozen golden bytes and projects exactly the
661+
/// real rename, dropping the synthetic empty-`new_path` skip item — proving
662+
/// legis's actual output and Loomweave's actual parser AGREE on these bytes.
663+
#[test]
664+
fn vendored_golden_parses_to_expected_pairs_via_real_parser() {
665+
let body = std::str::from_utf8(VENDORED_GOLDEN).expect("golden is utf-8");
666+
let pairs = parse_legis_rename_json(body);
667+
assert_eq!(
668+
pairs,
669+
vec![("auth.py".to_owned(), "authn.py".to_owned())],
670+
"the real parser must accept legis's frozen output and skip the \
671+
empty-new_path item; got {pairs:?}"
672+
);
673+
}
674+
675+
/// Layer-1 byte-pin: recompute the git blob sha1 of the vendored bytes and
676+
/// assert it equals `VENDORED_BLOB_SHA`. This is the canonicalization-drift
677+
/// detector — re-serialize the golden (key order / whitespace / trailing
678+
/// newline) on either side and the sha1 stops reproducing, failing CI before
679+
/// the drift reaches production. legis pins the identical sha over the
680+
/// identical bytes.
681+
#[test]
682+
fn vendored_golden_blob_sha_is_byte_pinned() {
683+
use sha1::{Digest, Sha1};
684+
let mut hasher = Sha1::new();
685+
hasher.update(format!("blob {}\0", VENDORED_GOLDEN.len()).as_bytes());
686+
hasher.update(VENDORED_GOLDEN);
687+
let recomputed: String = hasher
688+
.finalize()
689+
.iter()
690+
.map(|b| format!("{b:02x}"))
691+
.collect();
692+
assert_eq!(
693+
recomputed, VENDORED_BLOB_SHA,
694+
"golden bytes changed: {recomputed} != pinned {VENDORED_BLOB_SHA}. \
695+
Re-freeze from the real endpoint and update BOTH repos' constant."
696+
);
697+
}
698+
631699
// --- G16: silent-under-carry is detectable, not swallowed (clarion-73dff1d2d1) ---
632700
// Defensive half: the parser still never hard-fails, but the cases that
633701
// silently zero the rename signal are now classified so they can be logged.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"commit_sha": "0000000000000000000000000000000000000000",
4+
"new_blob": "",
5+
"new_path": "authn.py",
6+
"old_blob": "",
7+
"old_path": "auth.py",
8+
"similarity": 100
9+
},
10+
{
11+
"commit_sha": "0000000000000000000000000000000000000000",
12+
"new_blob": "",
13+
"new_path": "",
14+
"old_blob": "",
15+
"old_path": "ghost.py",
16+
"similarity": 0
17+
}
18+
]

0 commit comments

Comments
 (0)