Synchronize Git enrichment tests explicitly (#40006)

## What changed

- Track Git enrichment completion with a watch channel and unblock waiters when enrichment finishes or is canceled.
- Let the test sync tool wait for the current turn's enrichment with a bounded timeout.
- Replace polling in metadata tests and wait for enrichment before asserting workspace metadata in the guardian integration test.

GitOrigin-RevId: 8d35f75a0ebfe412674e1e797c6a13c03b1ea373
This commit is contained in:
felixxia-oai authored and copyberry committed 2026-08-21 20:53:30 +00:00
1 parent dbe9dac1ae
commit 51d8d12236
6 files changed
+99 -59

No files matched your search

+23 -16
View File
@@ -10,6 +10,7 @@ use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use serde_json::Value;
use tokio::sync::watch;
use tokio::task::JoinHandle;
use crate::responses_metadata::AGENT_NAME_KEY;
@@ -124,6 +125,7 @@ pub(crate) struct TurnMetadataState {
root_turn_ambiguous: AtomicBool,
user_input_requested_during_turn: AtomicBool,
enrichment_task: Mutex<Option<JoinHandle<()>>>,
git_enrichment_complete: watch::Sender<bool>,
}
impl TurnMetadataState {
@@ -185,6 +187,7 @@ impl TurnMetadataState {
root_turn_ambiguous: AtomicBool::new(false),
user_input_requested_during_turn: AtomicBool::new(false),
enrichment_task: Mutex::new(None),
git_enrichment_complete: watch::channel(/*init*/ true).0,
}
}
@@ -405,9 +408,9 @@ impl TurnMetadataState {
}
pub(crate) fn spawn_git_enrichment_task(self: &Arc<Self>) {
if self.repo_root.is_none() {
let Some(repo_root) = self.repo_root.clone() else {
return;
}
};
let mut task_guard = self
.enrichment_task
@@ -417,29 +420,32 @@ impl TurnMetadataState {
return;
}
self.git_enrichment_complete.send_replace(/*value*/ false);
let state = Arc::clone(self);
*task_guard = Some(tokio::spawn(async move {
let Some(repo_root) = state.repo_root.clone() else {
return;
};
let workspace_git_metadata = state.fetch_workspace_git_metadata(&repo_root).await;
if workspace_git_metadata.is_empty() {
return;
if !workspace_git_metadata.is_empty() {
let mut workspaces = BTreeMap::new();
workspaces.insert(
repo_root.to_string_lossy().into_owned(),
workspace_git_metadata.into(),
);
*state
.enriched_workspaces
.write()
.unwrap_or_else(std::sync::PoisonError::into_inner) = Some(workspaces);
}
let mut workspaces = BTreeMap::new();
workspaces.insert(
repo_root.to_string_lossy().into_owned(),
workspace_git_metadata.into(),
);
*state
.enriched_workspaces
.write()
.unwrap_or_else(std::sync::PoisonError::into_inner) = Some(workspaces);
state.git_enrichment_complete.send_replace(/*value*/ true);
}));
}
pub(crate) async fn wait_for_git_enrichment(&self) {
let mut completion = self.git_enrichment_complete.subscribe();
let _ = completion.wait_for(|complete| *complete).await;
}
pub(crate) fn cancel_git_enrichment_task(&self) {
let mut task_guard = self
.enrichment_task
@@ -447,6 +453,7 @@ impl TurnMetadataState {
.unwrap_or_else(std::sync::PoisonError::into_inner);
if let Some(task) = task_guard.take() {
task.abort();
self.git_enrichment_complete.send_replace(/*value*/ true);
}
}