Something went wrong. Try again.
CLI tool that records the reasoning behind AI-assisted development as a versioned graph of decision nodes
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041use assert_cmd::Command;use predicates::prelude::*;use std::fs;use tempfile::TempDir;
fn memex() -> Command { Command::cargo_bin("memex").unwrap()}
/// Initialize a memex repo in `dir` using stdin so no editor is opened.fn init_in(dir: &TempDir) { memex() .current_dir(dir.path()) .arg("init") .write_stdin("My test project\n") .assert() .success();}
/// Create a node with the given goal and return its short ID (first 8 chars).fn create_node(dir: &TempDir, goal: &str) -> String { let output = memex() .current_dir(dir.path()) .args(["node", "create", "--goal", goal]) .assert() .success() .get_output() .stdout .clone(); let text = String::from_utf8(output).unwrap(); // "Created node: <full-uuid>\n" text.lines() .find(|l| l.starts_with("Created node:")) .unwrap() .split_whitespace() .last() .unwrap()[..8] .to_string()}
// ─── Init ────────────────────────────────────────────────────────────────────
#[test]fn init_creates_memex_directory() { let tmp = TempDir::new().unwrap(); memex() .current_dir(tmp.path()) .arg("init") .write_stdin("My project\n") .assert() .success() .stdout(predicate::str::contains("Initialized .memex/"));
assert!(tmp.path().join(".memex").is_dir()); assert!(tmp.path().join(".memex/nodes").is_dir()); assert!(tmp.path().join(".memex/config.toml").exists()); assert!(tmp.path().join(".memex/.gitignore").exists()); let gitignore = fs::read_to_string(tmp.path().join(".memex/.gitignore")).unwrap(); assert!(gitignore.contains("state.json"));}
#[test]fn init_does_not_overwrite_existing_gitignore() { let tmp = TempDir::new().unwrap(); // Pre-create the .memex dir and a custom .gitignore before init let memex_dir = tmp.path().join(".memex"); fs::create_dir_all(&memex_dir).unwrap(); fs::write(memex_dir.join(".gitignore"), "custom-content\n").unwrap();
// init should skip writing .gitignore because it already exists memex() .current_dir(tmp.path()) .arg("init") .write_stdin("My project\n") .assert() .success();
let content = fs::read_to_string(memex_dir.join(".gitignore")).unwrap(); assert_eq!(content, "custom-content\n");}
#[test]fn init_twice_warns_already_exists() { let tmp = TempDir::new().unwrap(); init_in(&tmp); // Second init should exit 0 but warn on stderr memex() .current_dir(tmp.path()) .arg("init") .write_stdin("irrelevant\n") .assert() .success() .stderr(predicate::str::contains("already"));}
#[test]fn command_without_init_fails() { let tmp = TempDir::new().unwrap(); memex() .current_dir(tmp.path()) .args(["node", "list"]) .assert() .failure() .stderr(predicate::str::contains("No .memex directory found"));}
// ─── Node create ─────────────────────────────────────────────────────────────
#[test]fn node_create_with_goal_flag() { let tmp = TempDir::new().unwrap(); init_in(&tmp); let short_id = create_node(&tmp, "Build a search index");
// Node file exists on disk let nodes_dir = tmp.path().join(".memex/nodes"); let entries: Vec<_> = fs::read_dir(&nodes_dir) .unwrap() // init creates a root node, so look for the one matching our short_id .filter_map(|e| e.ok()) .filter(|e| e.file_name().to_string_lossy().starts_with(&short_id)) .collect(); assert_eq!(entries.len(), 1, "expected node file for {short_id}");}
#[test]fn node_create_sets_active() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "My active task");
memex() .current_dir(tmp.path()) .args(["node", "show"]) .assert() .success() .stdout(predicate::str::contains("My active task"));}
#[test]fn node_create_with_parent_flag() { let tmp = TempDir::new().unwrap(); init_in(&tmp); let parent_id = create_node(&tmp, "Parent node"); let child_id = create_node(&tmp, "Child node"); // Re-create child with explicit parent (use `node create` with parent pointing to parent_id) // (The previous create_node already set parent to the current active; re-verify via graph view) let _ = child_id;
memex() .current_dir(tmp.path()) .args(["graph", "view"]) .assert() .success() .stdout(predicate::str::contains(&parent_id));}
#[test]fn node_create_unknown_parent_fails() { let tmp = TempDir::new().unwrap(); init_in(&tmp); memex() .current_dir(tmp.path()) .args(["node", "create", "--parent", "00000000", "--goal", "Orphan"]) .assert() .failure();}
// ─── Node edit ───────────────────────────────────────────────────────────────
#[test]fn node_edit_goal_flag() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Original goal");
memex() .current_dir(tmp.path()) .args(["node", "edit", "--goal", "Updated goal"]) .assert() .success();
memex() .current_dir(tmp.path()) .args(["node", "show"]) .assert() .success() .stdout(predicate::str::contains("Updated goal")) .stdout(predicate::str::contains("Original goal").not());}
#[test]fn node_edit_decision_flag() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Planning");
memex() .current_dir(tmp.path()) .args([ "node", "edit", "--decision", "Use PostgreSQL", "--decision", "Use Rust", ]) .assert() .success();
memex() .current_dir(tmp.path()) .args(["node", "show"]) .assert() .success() .stdout(predicate::str::contains("Use PostgreSQL")) .stdout(predicate::str::contains("Use Rust"));}
#[test]fn node_edit_artifact_flag() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Work");
memex() .current_dir(tmp.path()) .args(["node", "edit", "--artifact", "src/main.rs"]) .assert() .success();
memex() .current_dir(tmp.path()) .args(["node", "show"]) .assert() .success() .stdout(predicate::str::contains("src/main.rs"));}
#[test]fn node_edit_open_thread_flag() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Design");
memex() .current_dir(tmp.path()) .args(["node", "edit", "--open-thread", "How to handle auth?"]) .assert() .success();
memex() .current_dir(tmp.path()) .args(["node", "show"]) .assert() .success() .stdout(predicate::str::contains("How to handle auth?"));}
#[test]fn node_edit_summary_and_goal_conflict() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Task");
memex() .current_dir(tmp.path()) .args([ "node", "edit", "--summary", r#"goal = "Full TOML"decisions = []rejected_approaches = []open_threads = []key_artifacts = []"#, "--goal", "conflicting", ]) .assert() .failure() .stderr( predicate::str::contains("cannot be combined").or(predicate::str::contains("conflict")), );}
#[test]fn node_edit_empty_goal_fails() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Task");
memex() .current_dir(tmp.path()) .args(["node", "edit", "--goal", ""]) .assert() .failure() .stderr(predicate::str::contains("cannot be empty").or(predicate::str::contains("empty")));}
// ─── Node auto ───────────────────────────────────────────────────────────────
#[test]fn node_auto_dry_run_prints_diff_without_writing() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Auto-target");
memex() .current_dir(tmp.path()) .args(["node", "auto", "--from-stdin"]) .write_stdin( r#"{"decisions":["Use SQLite"],"open_threads":["audit fts5"],"key_artifacts":["src/db.rs"]}"#, ) .assert() .success() .stdout(predicate::str::contains("+ Decisions:")) .stdout(predicate::str::contains("Use SQLite")) .stdout(predicate::str::contains("audit fts5")) .stdout(predicate::str::contains("src/db.rs")) .stdout(predicate::str::contains("Run with --apply"));
// Verify nothing was written: the show output should not contain the // dry-run additions. memex() .current_dir(tmp.path()) .args(["node", "show"]) .assert() .success() .stdout(predicate::str::contains("Use SQLite").not()) .stdout(predicate::str::contains("audit fts5").not());}
#[test]fn node_auto_apply_writes_all_fields() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Auto-apply");
memex() .current_dir(tmp.path()) .args(["node", "auto", "--from-stdin", "--apply"]) .write_stdin( r#"{ "decisions":["Use SQLite"], "rejected_approaches":[{"description":"Postgres","reason":"Too heavyweight"}], "open_threads":["audit fts5"], "key_artifacts":["src/db.rs"] }"#, ) .assert() .success() .stdout(predicate::str::contains("Applied 1 decision"));
memex() .current_dir(tmp.path()) .args(["node", "show"]) .assert() .success() .stdout(predicate::str::contains("Use SQLite")) .stdout(predicate::str::contains("Postgres — Too heavyweight")) .stdout(predicate::str::contains("audit fts5")) .stdout(predicate::str::contains("src/db.rs"));}
#[test]fn node_auto_apply_is_idempotent() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Idempotent");
let payload = r#"{"decisions":["Use SQLite"],"key_artifacts":["src/db.rs"]}"#; memex() .current_dir(tmp.path()) .args(["node", "auto", "--from-stdin", "--apply"]) .write_stdin(payload) .assert() .success() .stdout(predicate::str::contains("Applied"));
// Second apply with identical payload: no-op. memex() .current_dir(tmp.path()) .args(["node", "auto", "--from-stdin", "--apply"]) .write_stdin(payload) .assert() .success() .stdout(predicate::str::contains("No changes"));}
#[test]fn node_auto_dedupes_on_normalized_text() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Dedupe");
// First write the canonical form. memex() .current_dir(tmp.path()) .args(["node", "auto", "--from-stdin", "--apply"]) .write_stdin(r#"{"decisions":["Use SQLite for storage"]}"#) .assert() .success();
// Re-emit with extra whitespace, different case, and a trailing // period. Normalized dedupe should treat it as a duplicate. memex() .current_dir(tmp.path()) .args(["node", "auto", "--from-stdin", "--apply"]) .write_stdin(r#"{"decisions":[" use sqlite for storage. "]}"#) .assert() .success() .stdout(predicate::str::contains("No changes"));}
#[test]fn node_auto_requires_from_stdin() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Needs-flag");
memex() .current_dir(tmp.path()) .args(["node", "auto"]) .assert() .failure() .stderr(predicate::str::contains("--from-stdin is required"));}
#[test]fn node_auto_empty_payload_errors() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Empty");
memex() .current_dir(tmp.path()) .args(["node", "auto", "--from-stdin"]) .write_stdin("") .assert() .failure() .stderr(predicate::str::contains("Empty payload"));}
#[test]fn node_auto_invalid_json_errors() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Bad-json");
memex() .current_dir(tmp.path()) .args(["node", "auto", "--from-stdin"]) .write_stdin("not json") .assert() .failure() .stderr(predicate::str::contains("Failed to parse JSON"));}
#[test]fn node_auto_apply_and_dry_run_are_exclusive() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Conflict");
memex() .current_dir(tmp.path()) .args(["node", "auto", "--from-stdin", "--apply", "--dry-run"]) .write_stdin("{}") .assert() .failure() .stderr(predicate::str::contains("cannot be used with"));}
#[test]fn node_auto_targets_explicit_id() { let tmp = TempDir::new().unwrap(); init_in(&tmp); let target = create_node(&tmp, "Target"); // Make a second node active so the auto must use the explicit id arg. create_node(&tmp, "Different active");
memex() .current_dir(tmp.path()) .args(["node", "auto", &target, "--from-stdin", "--apply"]) .write_stdin(r#"{"decisions":["Routed to target"]}"#) .assert() .success();
memex() .current_dir(tmp.path()) .args(["node", "show", &target]) .assert() .success() .stdout(predicate::str::contains("Routed to target"));}
#[test]fn node_auto_no_active_node_errors() { let tmp = TempDir::new().unwrap(); init_in(&tmp); // No node create → init left active pointing at the root, so call auto // against a node id we know does not exist. memex() .current_dir(tmp.path()) .args(["node", "auto", "deadbeef", "--from-stdin"]) .write_stdin(r#"{"decisions":["x"]}"#) .assert() .failure();}
#[test]fn node_auto_partial_payload_only_new_section() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Partial");
memex() .current_dir(tmp.path()) .args(["node", "auto", "--from-stdin"]) .write_stdin(r#"{"open_threads":["follow up later"]}"#) .assert() .success() .stdout(predicate::str::contains("+ Open Threads:")) .stdout(predicate::str::contains("+ Decisions:").not()) .stdout(predicate::str::contains("+ Rejected Approaches:").not()) .stdout(predicate::str::contains("+ Key Artifacts:").not());}
// ─── Node status ─────────────────────────────────────────────────────────────
#[test]fn node_resolve_marks_resolved() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Task to resolve");
memex() .current_dir(tmp.path()) .args(["node", "resolve"]) .assert() .success();
memex() .current_dir(tmp.path()) .args(["node", "show"]) .assert() .success() .stdout(predicate::str::contains("Resolved"));}
#[test]fn node_resolve_already_resolved_errors() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Task");
memex() .current_dir(tmp.path()) .args(["node", "resolve"]) .assert() .success();
memex() .current_dir(tmp.path()) .args(["node", "resolve"]) .assert() .failure() .stderr( predicate::str::contains("already resolved").or(predicate::str::contains("already")), );}
#[test]fn node_abandon_marks_abandoned() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Abandoned task");
memex() .current_dir(tmp.path()) .args(["node", "abandon"]) .assert() .success();
memex() .current_dir(tmp.path()) .args(["node", "show"]) .assert() .success() .stdout(predicate::str::contains("Abandoned"));}
#[test]fn node_reopen_resolved_node() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Task");
memex() .current_dir(tmp.path()) .args(["node", "resolve"]) .assert() .success(); memex() .current_dir(tmp.path()) .args(["node", "reopen"]) .assert() .success();
memex() .current_dir(tmp.path()) .args(["node", "show"]) .assert() .success() .stdout(predicate::str::contains("Active"));}
#[test]fn node_reopen_already_active_errors() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Task");
memex() .current_dir(tmp.path()) .args(["node", "reopen"]) .assert() .failure() .stderr(predicate::str::contains("already active").or(predicate::str::contains("already")));}
// ─── Node resolve/abandon --force ────────────────────────────────────────────
#[test]fn node_resolve_with_force_flag() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Task to force-resolve");
memex() .current_dir(tmp.path()) .args(["node", "resolve", "--force"]) .assert() .success();
memex() .current_dir(tmp.path()) .args(["node", "show"]) .assert() .success() .stdout(predicate::str::contains("Resolved"));}
#[test]fn node_resolve_with_short_force_flag() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Task to force-resolve short");
memex() .current_dir(tmp.path()) .args(["node", "resolve", "-y"]) .assert() .success();
memex() .current_dir(tmp.path()) .args(["node", "show"]) .assert() .success() .stdout(predicate::str::contains("Resolved"));}
#[test]fn node_abandon_with_force_flag() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Task to force-abandon");
memex() .current_dir(tmp.path()) .args(["node", "abandon", "--force"]) .assert() .success();
memex() .current_dir(tmp.path()) .args(["node", "show"]) .assert() .success() .stdout(predicate::str::contains("Abandoned"));}
// ─── Node show / list ────────────────────────────────────────────────────────
#[test]fn node_show_by_short_id() { let tmp = TempDir::new().unwrap(); init_in(&tmp); let short_id = create_node(&tmp, "Specific node");
memex() .current_dir(tmp.path()) .args(["node", "show", &short_id]) .assert() .success() .stdout(predicate::str::contains("Specific node"));}
#[test]fn node_list_shows_all_nodes() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Alpha node"); create_node(&tmp, "Beta node");
memex() .current_dir(tmp.path()) .args(["node", "list"]) .assert() .success() .stdout(predicate::str::contains("Alpha node")) .stdout(predicate::str::contains("Beta node"));}
#[test]fn node_list_marks_active() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Active node");
let output = memex() .current_dir(tmp.path()) .args(["node", "list"]) .assert() .success() .get_output() .stdout .clone();
let text = String::from_utf8(output).unwrap(); assert!( text.lines().any(|l| l.starts_with('*')), "Expected a line starting with '*' in:\n{text}" );}
// ─── Graph ───────────────────────────────────────────────────────────────────
#[test]fn graph_view_single_node() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Lone node");
memex() .current_dir(tmp.path()) .args(["graph", "view"]) .assert() .success() .stdout(predicate::str::contains("Conversation Graph")) .stdout(predicate::str::contains("Legend:"));}
#[test]fn graph_view_tree_connectors() { let tmp = TempDir::new().unwrap(); init_in(&tmp); let parent_id = create_node(&tmp, "Parent"); let _child_id = create_node(&tmp, "Child"); // auto-parented to active (parent) let _ = parent_id;
memex() .current_dir(tmp.path()) .args(["graph", "view"]) .assert() .success() .stdout(predicate::str::contains("──"));}
// ─── Search ──────────────────────────────────────────────────────────────────
#[test]fn search_finds_goal() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Build a database indexer");
memex() .current_dir(tmp.path()) .args(["search", "database"]) .assert() .success() .stdout(predicate::str::contains(">>database<<"));}
#[test]fn search_case_insensitive() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Build a DATABASE indexer");
memex() .current_dir(tmp.path()) .args(["search", "database"]) .assert() .success() .stdout(predicate::str::contains(">>DATABASE<<"));}
#[test]fn search_no_match() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Build a web server");
memex() .current_dir(tmp.path()) .args(["search", "zzznomatch"]) .assert() .success() .stdout(predicate::str::contains("No nodes found matching"));}
#[test]fn search_finds_decisions() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Design system");
memex() .current_dir(tmp.path()) .args(["node", "edit", "--decision", "Use microservices"]) .assert() .success();
memex() .current_dir(tmp.path()) .args(["search", "microservices"]) .assert() .success() .stdout(predicate::str::contains("decision[0]"));}
// ─── Context ─────────────────────────────────────────────────────────────────
#[test]fn context_markdown_output() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Root project");
memex() .current_dir(tmp.path()) .args(["context", "--format", "markdown"]) .assert() .success() .stdout(predicate::str::contains("## Project Context")) .stdout(predicate::str::contains("**Goal:**"));}
#[test]fn context_xml_output() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Root project");
memex() .current_dir(tmp.path()) .args(["context", "--format", "xml"]) .assert() .success() .stdout(predicate::str::contains("<memex_context>")) .stdout(predicate::str::contains("<goal>"));}
#[test]fn context_plain_output() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Root project");
memex() .current_dir(tmp.path()) .args(["context", "--format", "plain"]) .assert() .success() .stdout(predicate::str::contains("PROJECT CONTEXT"));}
#[test]fn context_invalid_format_fails() { let tmp = TempDir::new().unwrap(); init_in(&tmp);
memex() .current_dir(tmp.path()) .args(["context", "--format", "json"]) .assert() .failure() .stderr(predicate::str::contains("Unknown format"));}
#[test]fn context_depth_trimming() { let tmp = TempDir::new().unwrap(); init_in(&tmp);
// Build a 4-level chain: root → level1 → level2 → current let root_id = create_node(&tmp, "Root node"); let level1_id = create_node(&tmp, "Level one node"); let level2_id = create_node(&tmp, "Level two node"); let _current_id = create_node(&tmp, "Current node"); let _ = (root_id, level1_id, level2_id);
// --depth 1: only keep 1 ancestor between root and current → Level one should be trimmed memex() .current_dir(tmp.path()) .args(["context", "--format", "plain", "--depth", "1"]) .assert() .success() .stdout(predicate::str::contains("Level one node").not()) .stdout(predicate::str::contains("Current node"));}
// ─── pr-context ──────────────────────────────────────────────────────────────
#[test]fn pr_context_emits_marker_and_no_match_message_when_empty() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Root");
memex() .current_dir(tmp.path()) .args(["pr-context", "--file", "src/nothing.rs"]) .assert() .success() .stdout(predicate::str::contains("<!-- memex-pr-context -->")) .stdout(predicate::str::contains( "No prior memex nodes touched the changed files.", ));}
#[test]fn pr_context_lists_node_with_matching_artifact() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Root"); let child = create_node(&tmp, "Touched main");
memex() .current_dir(tmp.path()) .args(["node", "edit", "--artifact", "src/main.rs"]) .assert() .success();
memex() .current_dir(tmp.path()) .args(["pr-context", "--file", "src/main.rs"]) .assert() .success() .stdout(predicate::str::contains(&child)) .stdout(predicate::str::contains("Touched main")) .stdout(predicate::str::contains("**Artifacts:** src/main.rs"));}
#[test]fn pr_context_excludes_non_matching_nodes() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Root"); let on_main = create_node(&tmp, "Touched main"); memex() .current_dir(tmp.path()) .args(["node", "edit", "--artifact", "src/main.rs"]) .assert() .success();
let on_store = create_node(&tmp, "Touched store"); memex() .current_dir(tmp.path()) .args(["node", "edit", "--artifact", "src/store.rs"]) .assert() .success();
memex() .current_dir(tmp.path()) .args(["pr-context", "--file", "src/main.rs"]) .assert() .success() .stdout(predicate::str::contains(&on_main)) .stdout(predicate::str::contains(&on_store).not());}
#[test]fn pr_context_limit_caps_rendered_nodes() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Root");
// Create 4 child nodes that all touch src/main.rs for i in 0..4 { let _id = create_node(&tmp, &format!("Touch {}", i)); memex() .current_dir(tmp.path()) .args(["node", "edit", "--artifact", "src/main.rs"]) .assert() .success(); }
memex() .current_dir(tmp.path()) .args(["pr-context", "--limit", "2", "--file", "src/main.rs"]) .assert() .success() .stdout(predicate::str::contains("2 older matching nodes omitted"));}
#[test]fn pr_context_supports_custom_marker() { let tmp = TempDir::new().unwrap(); init_in(&tmp); create_node(&tmp, "Root");
memex() .current_dir(tmp.path()) .args([ "pr-context", "--marker", "<!-- custom-marker -->", "--file", "src/main.rs", ]) .assert() .success() .stdout(predicate::str::contains("<!-- custom-marker -->")) .stdout(predicate::str::contains("<!-- memex-pr-context -->").not());}