← Commit history
Merge PR #543: A run records the adom-aiflow version it runs on and warns once when it changes (feat/run-binary-version -> main) merge
Showing changes introduced by the merge (against its first parent).
2 files changed
+81
crates/adom-aiflow/src/main.rs+42@@ -734,6 +734,38 @@ fn read_json(p: &str) -> Value { serde_json::from_str(&std::fs::read_to_string(p).unwrap_or_else(|e| err(&format!("{p}: {e}"), &[]))).unwrap_or_else(|e| err(&format!("{p}: not JSON: {e}"), &[])) } +/// The adom-aiflow version a run's commands run on. A run records the version it started on+/// (`aiflowVersion`); when a later command runs on another one (the package updated itself, or was+/// reinstalled, in the middle of a run), the change goes into `aiflowVersions` and the ledger, and the+/// command says so once: checks and hints may have changed under the steps already done.+fn binary_version_change(data: &mut Value, version: &str, at: &str) -> Option<String> {+ let before = data["aiflowVersion"].as_str().map(str::to_string);+ if before.as_deref() == Some(version) { return None; }+ data["aiflowVersion"] = json!(version);+ if !data["aiflowVersions"].is_array() { data["aiflowVersions"] = json!([]); }+ let entry = match &before { Some(b) => json!({"version": version, "from": at, "previous": b}), None => json!({"version": version, "from": at}) };+ data["aiflowVersions"].as_array_mut().unwrap().push(entry);+ let old = before?;+ Some(format!("adom-aiflow changed under this run: {old} ran its earlier commands, {version} runs this one (it was updated or reinstalled during the run). Checks and hints may differ from what the earlier steps saw: read the release notes from {old} to {version} (docs/release-<version>.md on adom/adom-aiflow) and run again any step whose check changed. run.json aiflowVersions lists every version this run used."))+}++#[cfg(test)]+mod binary_version_tests {+ use serde_json::json;++ #[test]+ fn a_version_change_is_recorded_once_and_said_once() {+ let mut d = json!({});+ assert_eq!(super::binary_version_change(&mut d, "0.2.84", "t0"), None);+ assert_eq!(d["aiflowVersion"], "0.2.84");+ assert_eq!(super::binary_version_change(&mut d, "0.2.84", "t1"), None);+ let w = super::binary_version_change(&mut d, "0.2.86", "t2").unwrap();+ assert!(w.contains("0.2.84 ran its earlier commands, 0.2.86 runs this one"), "{w}");+ assert_eq!(super::binary_version_change(&mut d, "0.2.86", "t3"), None);+ assert_eq!(d["aiflowVersions"], json!([{"version": "0.2.84", "from": "t0"}, {"version": "0.2.86", "from": "t2", "previous": "0.2.84"}]));+ }+}+ /// The `start` hint for the design-rule card (rules_card.rs). fn rules_card_hint(flags: &[String]) -> String { if flags.is_empty() { "Design-rule card: every spec size is inside the fab lane's range (drawn to scale on the dashboard; rules-card.json). It changes no gate.".into() }@@ -3659,6 +3691,12 @@ fn main() { let idx = r.turn_begin(&command_line()); // the thread that last drove the run: the dashboard header and the tab registry name it if let Some(t) = cli.ai_thread.as_deref().map(str::trim).filter(|t| !t.is_empty()) { r.data["lastAiThread"] = json!(t); r.data["lastAiThreadAt"] = json!(now()); }+ // a run that outlives an update of adom-aiflow: said once, at the first command on the new version+ let had = r.data["aiflowVersion"].as_str().map(str::to_string);+ if let Some(w) = binary_version_change(&mut r.data, VERSION, &now()) {+ r.log("binary-changed", json!({"from": had, "to": VERSION}));+ eprintln!("WARNING: {w}");+ } let _ = r.save(); let _ = TURN.set((dir.clone(), idx)); // the over-budget nag: a run that sits in one step far past its expected minutes is most@@ -4042,6 +4080,8 @@ fn main() { let pt = r.data["clock"]["promptTime"].as_str().unwrap_or("").to_string(); let differs = prompt_time.as_ref().filter(|p| **p != pt).map(|p| format!("--prompt-time {p} ignored: the intake run's clock started at {pt} and stays there. ")); r.attach_board(©.display().to_string(), &specp, engine, target.as_deref(), remote_board.as_deref());+ let had = r.data["aiflowVersion"].as_str().map(str::to_string);+ if let Some(w) = binary_version_change(&mut r.data, VERSION, &now()) { r.log("binary-changed", json!({"from": had, "to": VERSION})); eprintln!("WARNING: {w}"); } r.data["sourceBoard"] = json!(std::fs::canonicalize(board).map(|p| p.display().to_string()).unwrap_or(board.clone())); if let Err(e) = pagedir::set(&mut r.data, "page", "pageDir", page.as_deref(), page_dir.as_deref()) { err(&e, &[]); } if let Some(s) = sch { r.data["schematic"] = json!(std::fs::canonicalize(s).map(|p| p.display().to_string()).unwrap_or(s.clone())); }@@ -4068,6 +4108,7 @@ fn main() { } let pt = prompt_time.clone().unwrap_or_else(now); let mut r = Run::create(&dir, ©.display().to_string(), &specp, engine, &pt, &t, target.as_deref(), remote_board.as_deref()).unwrap_or_else(|e| err(&e, &[]));+ let _ = binary_version_change(&mut r.data, VERSION, &now()); r.data["sourceBoard"] = json!(std::fs::canonicalize(board).map(|p| p.display().to_string()).unwrap_or(board.clone())); if let Some(s) = sch { r.data["schematic"] = json!(std::fs::canonicalize(s).map(|p| p.display().to_string()).unwrap_or(s.clone())); } if let Err(e) = pagedir::set(&mut r.data, "page", "pageDir", page.as_deref(), page_dir.as_deref()) { err(&e, &[]); }@@ -4105,6 +4146,7 @@ fn main() { // a brief that is already a requirements file (aiflow-intake's shape) is recorded as both let req = requirements.as_ref().map(canon).or_else(|| brief.as_ref().filter(|b| std::fs::read_to_string(b).ok().and_then(|t| serde_json::from_str::<Value>(&t).ok()).map(|v| v.get("fab").is_some() || v.get("sourcing").is_some() || v.get("outputs").is_some()).unwrap_or(false)).map(canon)); let mut r = Run::create_intake(&dir, prompt_time, &t, engine.as_deref(), brief.as_ref().map(canon).as_deref(), req.as_deref(), target.as_deref()).unwrap_or_else(|e| err(&e, &[]));+ let _ = binary_version_change(&mut r.data, VERSION, &now()); if let Err(e) = pagedir::set(&mut r.data, "page", "pageDir", page.as_deref(), page_dir.as_deref()) { err(&e, &[]); } // the EDA tool, named: the step sequence is fixed at the first step after intake, before any // backend project exists, so a brief that never says "Altium" must not fall into kicad-new
tests/binary-version-workflow.pyadded+39@@ -0,0 +1,39 @@+"""A run records the adom-aiflow version it started on, and says once when a later command runs on+another version (an update or a reinstall during the run): a WARNING on that command, a+`binary-changed` event in the ledger and the versions in run.json `aiflowVersions`. No CAD, desktop+or dashboard.++ python3 tests/binary-version-workflow.py <adom-aiflow binary>+"""+import json, os, pathlib, subprocess, sys, tempfile+binary = str(pathlib.Path(sys.argv[1]).resolve())+version = subprocess.run([binary, '--version'], capture_output=True, text=True).stdout.split()[-1]++with tempfile.TemporaryDirectory(prefix='aiflow-binary-version-') as td:+ run = pathlib.Path(td) / 'run'+ env = dict(os.environ, AIFLOW_DASHBOARD='off')+ def call(*args):+ r = subprocess.run([binary, '--run', str(run), '--ai-thread', 'version-test', *args], env=env, capture_output=True, text=True, timeout=120)+ assert r.returncode == 0, r.stdout + r.stderr+ return r.stdout + r.stderr+ def data(): return json.loads((run / 'run.json').read_text())+ def events(): return [json.loads(l) for l in (run / 'run.jsonl').read_text().splitlines()]++ call('intake', '--prompt-time', '2026-11-19T01:00:00Z', '--engine', 'test')+ assert data()['aiflowVersion'] == version and [v['version'] for v in data()['aiflowVersions']] == [version], data()+ out = call('step', 'rules')+ assert 'changed under this run' not in out, out++ # the run was started on an older build, then the package updated itself+ d = data(); d['aiflowVersion'] = '0.0.1'; d['aiflowVersions'] = [{'version': '0.0.1', 'from': '2026-11-19T01:00:00Z'}]+ (run / 'run.json').write_text(json.dumps(d))+ out = call('step', 'test-plan')+ assert f'WARNING: adom-aiflow changed under this run: 0.0.1 ran its earlier commands, {version} runs this one' in out, out+ assert data()['aiflowVersion'] == version and [v['version'] for v in data()['aiflowVersions']] == ['0.0.1', version], data()+ ch = [e for e in events() if e['event'] == 'binary-changed']+ assert len(ch) == 1 and ch[0]['from'] == '0.0.1' and ch[0]['to'] == version, ch+ # said once+ out = call('step', 'parts')+ assert 'changed under this run' not in out, out+ assert len([e for e in events() if e['event'] == 'binary-changed']) == 1+print('PASS: a run records the version it starts on; the first command on another version warns once, logs binary-changed and lists both versions in aiflowVersions; later commands stay quiet')