instinct-cli 0.3.8

Shared local memory for coding agents. Save a fix once and find it again in a new session or another connected tool.
1
2
3
4
5
6
7
8
9
10
11
# Strict graph wire and reachability through CLI, composition and receipts.
TAA # use std::{io::Write,process::{Command,Stdio}};
TAA # fn call(mode:&str,input:&str)->(bool,String){let mut c=Command::new(env!("CARGO_BIN_EXE_instinct")).args(["check",mode,"--input","-"]).stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped()).spawn().unwrap();c.stdin.take().unwrap().write_all(input.as_bytes()).unwrap();let out=c.wait_with_output().unwrap();(out.status.success(),String::from_utf8(out.stdout).unwrap())}
TAA # fn request(graph:&str,from:&str,to:&str)->String{format!(r#"{{"check":{{"schema":"instinct.check/v1","id":"path","revision":1,"inputs":{{"g":"graph","a":"string","b":"string"}},"claim":{{"op":"reachable","graph":{{"fact":"g"}},"from":{{"fact":"a"}},"to":{{"fact":"b"}}}}}},"facts":{{"g":{graph},"a":"{from}","b":"{to}"}}}}"#)}
TAA # const GRAPH:&str=r#"{"nodes":["a","b","c"],"edges":[["a","b"],["b","c"]]}"#;
TAA # #[test] fn directed_and_zero_length_paths(){for(a,b,want)in[("a","c","pass"),("c","a","fail"),("a","a","pass"),("missing","a","abstain")]{let(ok,out)=call("run",&request(GRAPH,a,b));assert!(ok,"{out}");assert!(out.contains(&format!("\"verdict\":\"{want}\"")),"{out}");}}
TAA # #[test] fn malformed_graphs_fail_even_under_short_circuit(){for graph in[r#"{"nodes":["a","a"],"edges":[]}"#,r#"{"nodes":["a"],"edges":[["a","b"]]}"#,r#"{"nodes":["a"],"edges":[["a","a"],["a","a"]]}"#,r#"{"nodes":[""],"edges":[]}"#,r#"{"nodes":["a"],"edges":[["a"]]}"#,r#"{"nodes":["a"],"edges":[],"secret":true}"#,r#"{"nodes":["a"],"edges":[],"nodes":[]}"#]{let raw=request(graph,"a","a");let leaf=r#"{"op":"reachable","graph":{"fact":"g"},"from":{"fact":"a"},"to":{"fact":"b"}}"#;let short=format!(r#"{{"op":"any","args":[{{"op":"eq","left":{{"fact":"a"}},"right":{{"fact":"a"}}}},{leaf}]}}"#);for input in[raw.clone(),raw.replace(leaf,&short)]{let(ok,out)=call("run",&input);assert!(!ok,"{out}");}}}
TAA # #[test] fn receipt_replay_and_composition_keep_graph_semantics(){let raw=request(GRAPH,"a","c");let(ok,receipt)=call("receipt",&raw);assert!(ok,"{receipt}");let(ok,out)=call("replay",&format!("{{\"request\":{raw},\"receipt\":{receipt}}}"));assert!(ok,"{out}");let(ok,composed)=call("compose",&format!("{{\"id\":\"composed\",\"revision\":1,\"checks\":[{raw}]}}"));assert!(ok,"{composed}");let(ok,out)=call("run",&composed);assert!(ok,"{out}");assert!(out.contains("\"verdict\":\"pass\""),"{out}");}
TAA # #[test] fn long_paths_consume_fuel(){let nodes=(0..2000).map(|i|format!("\"n{i}\"")).collect::<Vec<_>>().join(",");let edges=(0..1999).map(|i|format!("[\"n{i}\",\"n{}\"]",i+1)).collect::<Vec<_>>().join(",");let graph=format!("{{\"nodes\":[{nodes}],\"edges\":[{edges}]}}");let raw=request(&graph,"n0","n1999");let leaf=r#"{"op":"reachable","graph":{"fact":"g"},"from":{"fact":"a"},"to":{"fact":"b"}}"#;for(count,want)in[(1,"pass"),(40,"abstain")]{let claim=format!("{{\"op\":\"all\",\"args\":[{}]}}",vec![leaf;count].join(","));let(ok,out)=call("run",&raw.replace(leaf,&claim));assert!(ok,"{out}");assert!(out.contains(&format!("\"verdict\":\"{want}\"")),"{out}");if count==40{assert!(out.contains("resource_limit"),"{out}");}}}
TAA # #[test] fn graph_entry_limits_are_enforced(){let nodes=(0..10001).map(|i|format!("\"n{i}\"")).collect::<Vec<_>>().join(",");let graph=format!("{{\"nodes\":[{nodes}],\"edges\":[]}}");let(ok,out)=call("run",&request(&graph,"n0","n0"));assert!(!ok,"{out}");assert!(out.contains("limit_exceeded"),"{out}");}
TAA # #[test] fn graph_equality_is_labelled_not_isomorphism(){let claim=r#"{"op":"eq","left":{"fact":"g"},"right":{"fact":"h"}}"#;for(other,want)in[(r#"{"nodes":["c","b","a"],"edges":[["b","c"],["a","b"]]}"#,"pass"),(r#"{"nodes":["x","y","z"],"edges":[["x","y"],["y","z"]]}"#,"fail")]{let input=format!(r#"{{"check":{{"schema":"instinct.check/v1","id":"equal","revision":1,"inputs":{{"g":"graph","h":"graph"}},"claim":{claim}}},"facts":{{"g":{GRAPH},"h":{other}}}}}"#);let(ok,out)=call("run",&input);assert!(ok,"{out}");assert!(out.contains(&format!("\"verdict\":\"{want}\"")),"{out}");}}