Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions atomic-agent/src/turn/orchestrator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,3 +769,69 @@ fn test_orchestrator_debug() {
assert!(debug.contains("TurnOrchestrator"));
assert!(debug.contains("repo_root"));
}

#[tokio::test]
async fn test_file_recorded_on_another_view_records_again_on_new_view() {
let dir = TempDir::new().unwrap();
Repository::init(dir.path()).unwrap();

// Session A records shared.rs on its own per-session view.
let store_a = SessionStore::for_repo(dir.path()).unwrap();
let watcher_a = FallbackWatcher::new(WatcherConfig::new(dir.path()));
let mut orch_a = TurnOrchestrator::with_watcher(dir.path(), store_a, Box::new(watcher_a));
orch_a.set_agent("claude-code", "Claude Code");
orch_a
.dispatch(session_start_event("sess-A"))
.await
.unwrap();
orch_a
.dispatch(turn_start_event("sess-A", "create shared"))
.await
.unwrap();
fs::write(dir.path().join("shared.rs"), "fn shared() {}\n").unwrap();
let ra = orch_a.dispatch(turn_end_event("sess-A")).await.unwrap();
assert!(ra.was_recorded(), "session A must record shared.rs");
orch_a.dispatch(session_end_event("sess-A")).await.unwrap();

// Session A's file should not be present on the parent view.
let _ = fs::remove_file(dir.path().join("shared.rs"));

// Session B re-creates the same path on a different view.
let store_b = SessionStore::for_repo(dir.path()).unwrap();
let watcher_b = FallbackWatcher::new(WatcherConfig::new(dir.path()));
let mut orch_b = TurnOrchestrator::with_watcher(dir.path(), store_b, Box::new(watcher_b));
orch_b.set_agent("claude-code", "Claude Code");
orch_b
.dispatch(session_start_event("sess-B"))
.await
.unwrap();

orch_b
.dispatch(turn_start_event("sess-B", "unrelated work"))
.await
.unwrap();
fs::write(dir.path().join("other.rs"), "fn other() {}\n").unwrap();
let rb1 = orch_b.dispatch(turn_end_event("sess-B")).await.unwrap();
assert!(rb1.was_recorded(), "session B turn 1 must record");

orch_b
.dispatch(turn_start_event("sess-B", "recreate shared"))
.await
.unwrap();
fs::write(dir.path().join("shared.rs"), "fn shared_v2() {}\n").unwrap();
let rb2 = orch_b.dispatch(turn_end_event("sess-B")).await.unwrap();
assert!(
rb2.was_recorded(),
"re-creating a file another view already tracks must record — \
regression: add=already-tracked + status=untracked ⇒ false EmptyTurn"
);
let outcome = rb2.change_recorded.as_ref().unwrap();
assert!(
outcome
.recorded_file_list()
.iter()
.any(|f| f.contains("shared.rs")),
"the re-created file itself must be in the recorded change: {:?}",
outcome.recorded_file_list()
);
}
23 changes: 15 additions & 8 deletions atomic-repository/src/repository/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,26 @@ impl Repository {
for result in tree_iter {
let (path, inode) = result.map_err(|e| RepositoryError::Database(e.to_string()))?;

// View filter: skip files whose creating change is not on
// the current view. Files in TREE without a graph position
// must be classified as Added, not Clean. Files whose
// creating change is not in the current view's filter are
// skipped entirely — they belong to other views and must not
// appear in this view's status.
// Cross-view entries are hidden from this view unless the file
// exists on disk again. In that case it is new content for the
// current view and should classify as Added.
let has_graph = if let Ok(Some(position)) = txn.inode_position(inode) {
if let Some(ref ids) = current_view_change_ids {
if !position.change.is_root() && !ids.contains(&position.change) {
continue;
let on_disk = self
.root
.join(normalize_tracked_path(&path, &self.root))
.is_file();
if !on_disk {
continue;
}
false
} else {
true
}
} else {
true
}
true
} else {
false
};
Expand Down
Loading