|
| 1 | +//! Cross-version upgrade: prove the CURRENT binary handles a GENUINE old-format |
| 2 | +//! (internal schema v3) graph minted by omnigraph 0.7.2 — not a v4-shaped graph |
| 3 | +//! with a rewound stamp. Two things the stamp-rewind stand-in |
| 4 | +//! (`sub_current_graph_is_refused_then_rebuilt_via_export_import`) cannot prove: |
| 5 | +//! |
| 6 | +//! 1. the open-refusal fires on the REAL on-disk v3 shape (lineage in |
| 7 | +//! `_graph_commits.lance`, lineage-free `__manifest`) and NAMES the writing |
| 8 | +//! release, and |
| 9 | +//! 2. the documented `export → init → load` rebuild round-trips the data, |
| 10 | +//! including a `Vector` column, off a genuine v3 export. |
| 11 | +//! |
| 12 | +//! Gated: requires `OMNIGRAPH_OLD_BIN` (an absolute path to a 0.7.2 `omnigraph` |
| 13 | +//! binary). Skips gracefully when unset — the same convention as the S3 and |
| 14 | +//! system-e2e gates — so the default `cargo test --workspace` stays green |
| 15 | +//! without it. CI sets it in the `crossversion_upgrade` job (see |
| 16 | +//! `docs/dev/testing.md`). |
| 17 | +
|
| 18 | +mod support; |
| 19 | + |
| 20 | +use std::path::{Path, PathBuf}; |
| 21 | +use std::process::Command; |
| 22 | + |
| 23 | +use support::{HERMETIC_OPERATOR_HOME, cli, fixture, output_failure, output_success}; |
| 24 | +use tempfile::tempdir; |
| 25 | + |
| 26 | +/// Resolve the old (0.7.2) binary. `None` ONLY when `OMNIGRAPH_OLD_BIN` is |
| 27 | +/// unset — the legitimate skip. A var that is SET but points at a missing path |
| 28 | +/// is a misconfiguration (wrong install path / renamed binary) and must fail |
| 29 | +/// loudly, never skip vacuously: in CI the var is deliberately set so the test |
| 30 | +/// is expected to run. |
| 31 | +fn old_bin() -> Option<PathBuf> { |
| 32 | + let path = PathBuf::from(std::env::var_os("OMNIGRAPH_OLD_BIN")?); |
| 33 | + assert!( |
| 34 | + path.exists(), |
| 35 | + "OMNIGRAPH_OLD_BIN is set but does not exist: {} \ |
| 36 | + (unset it to skip, or point it at a real 0.7.2 omnigraph binary)", |
| 37 | + path.display(), |
| 38 | + ); |
| 39 | + Some(path) |
| 40 | +} |
| 41 | + |
| 42 | +/// Run the OLD (0.7.2) binary hermetically (no developer `~/.omnigraph`). |
| 43 | +fn run_old(bin: &Path, args: &[&str]) -> std::process::Output { |
| 44 | + Command::new(bin) |
| 45 | + .env("OMNIGRAPH_HOME", HERMETIC_OPERATOR_HOME) |
| 46 | + .env_remove("OMNIGRAPH_CONFIG") |
| 47 | + .args(args) |
| 48 | + .output() |
| 49 | + .expect("spawn old omnigraph binary") |
| 50 | +} |
| 51 | + |
| 52 | +fn assert_ok(label: &str, out: &std::process::Output) { |
| 53 | + assert!( |
| 54 | + out.status.success(), |
| 55 | + "old binary `{label}` failed\nstdout:\n{}\nstderr:\n{}", |
| 56 | + String::from_utf8_lossy(&out.stdout), |
| 57 | + String::from_utf8_lossy(&out.stderr), |
| 58 | + ); |
| 59 | +} |
| 60 | + |
| 61 | +fn nonblank_lines(bytes: &[u8]) -> usize { |
| 62 | + String::from_utf8_lossy(bytes) |
| 63 | + .lines() |
| 64 | + .filter(|l| !l.trim().is_empty()) |
| 65 | + .count() |
| 66 | +} |
| 67 | + |
| 68 | +#[test] |
| 69 | +fn current_binary_refuses_and_rebuilds_a_genuine_v3_graph() { |
| 70 | + let Some(old) = old_bin() else { |
| 71 | + eprintln!( |
| 72 | + "skipping cross-version upgrade test: OMNIGRAPH_OLD_BIN is not set to a 0.7.2 binary" |
| 73 | + ); |
| 74 | + return; |
| 75 | + }; |
| 76 | + |
| 77 | + let temp = tempdir().unwrap(); |
| 78 | + let old_graph = temp.path().join("old-v3.omni"); |
| 79 | + // `search.pg` / `search.jsonl` are byte-identical in v0.7.2 and exercise a |
| 80 | + // `Vector(4)` column plus indexed strings — a fixture both binaries parse. |
| 81 | + let schema = fixture("search.pg"); |
| 82 | + let data = fixture("search.jsonl"); |
| 83 | + let og = old_graph.to_str().unwrap(); |
| 84 | + |
| 85 | + // 1. Mint a GENUINE v3 graph with the old binary. |
| 86 | + assert_ok( |
| 87 | + "init", |
| 88 | + &run_old(&old, &["init", "--schema", schema.to_str().unwrap(), og]), |
| 89 | + ); |
| 90 | + assert_ok( |
| 91 | + "load", |
| 92 | + &run_old( |
| 93 | + &old, |
| 94 | + &["load", "--mode", "overwrite", "--data", data.to_str().unwrap(), og], |
| 95 | + ), |
| 96 | + ); |
| 97 | + |
| 98 | + // Prove it is really v3 on disk: pre-v4 graphs carry the now-retired |
| 99 | + // `_graph_commits.lance` lineage dataset (a v4 graph has neither). |
| 100 | + assert!( |
| 101 | + old_graph.join("_graph_commits.lance").exists(), |
| 102 | + "a genuine v3 graph must have the legacy _graph_commits.lance dataset", |
| 103 | + ); |
| 104 | + |
| 105 | + // 2. Old binary export → JSONL. |
| 106 | + let export = run_old(&old, &["export", og]); |
| 107 | + assert_ok("export", &export); |
| 108 | + assert!(!export.stdout.is_empty(), "old export produced no rows"); |
| 109 | + let v3_jsonl = temp.path().join("v3.jsonl"); |
| 110 | + std::fs::write(&v3_jsonl, &export.stdout).unwrap(); |
| 111 | + |
| 112 | + // 3. The CURRENT binary refuses the genuine v3 graph, names the writing |
| 113 | + // release, and nudges to export — on the real on-disk shape. |
| 114 | + let refusal = output_failure(cli().arg("snapshot").arg(&old_graph)); |
| 115 | + let stderr = String::from_utf8_lossy(&refusal.stderr); |
| 116 | + assert!( |
| 117 | + stderr.contains("export"), |
| 118 | + "refusal must nudge the operator to export, got: {stderr}", |
| 119 | + ); |
| 120 | + assert!( |
| 121 | + stderr.contains("0.6.2 to 0.7.2"), |
| 122 | + "refusal must name the full release range that wrote this stamp (v3 → 0.6.2 to 0.7.2), \ |
| 123 | + got: {stderr}", |
| 124 | + ); |
| 125 | + |
| 126 | + // 4. The CURRENT binary rebuilds: fresh init + load the v3 export. |
| 127 | + let new_graph = temp.path().join("new-v4.omni"); |
| 128 | + output_success(cli().arg("init").arg("--schema").arg(&schema).arg(&new_graph)); |
| 129 | + output_success( |
| 130 | + cli() |
| 131 | + .arg("load") |
| 132 | + .arg("--mode") |
| 133 | + .arg("overwrite") |
| 134 | + .arg("--data") |
| 135 | + .arg(&v3_jsonl) |
| 136 | + .arg(&new_graph), |
| 137 | + ); |
| 138 | + |
| 139 | + // 5. Round-trip fidelity: re-export with the current binary and compare. |
| 140 | + let reexport = output_success(cli().arg("export").arg(&new_graph)); |
| 141 | + assert_eq!( |
| 142 | + nonblank_lines(&export.stdout), |
| 143 | + nonblank_lines(&reexport.stdout), |
| 144 | + "row count must round-trip v3 → v4", |
| 145 | + ); |
| 146 | + let rebuilt = String::from_utf8_lossy(&reexport.stdout); |
| 147 | + assert!( |
| 148 | + rebuilt.contains("embedding"), |
| 149 | + "the Vector column must survive the rebuild, got: {rebuilt}", |
| 150 | + ); |
| 151 | + assert!( |
| 152 | + rebuilt.contains("ml-intro"), |
| 153 | + "the rebuilt graph must preserve node data, got: {rebuilt}", |
| 154 | + ); |
| 155 | +} |
0 commit comments