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

+18 -1
View File
@@ -23,6 +23,7 @@ use codex_tools::ToolSpec;
pub struct TestSyncHandler;
const DEFAULT_TIMEOUT_MS: u64 = 1_000;
const GIT_ENRICHMENT_TIMEOUT: Duration = Duration::from_secs(10);
static BARRIERS: OnceLock<tokio::sync::Mutex<HashMap<String, BarrierState>>> = OnceLock::new();
@@ -47,6 +48,8 @@ struct TestSyncArgs {
sleep_after_ms: Option<u64>,
#[serde(default)]
barrier: Option<BarrierArgs>,
#[serde(default)]
wait_for_git_enrichment: bool,
}
fn default_timeout_ms() -> u64 {
@@ -80,7 +83,7 @@ impl TestSyncHandler {
&self,
invocation: ToolInvocation,
) -> Result<Box<dyn crate::tools::context::ToolOutput>, FunctionCallError> {
let ToolInvocation { payload, .. } = invocation;
let ToolInvocation { payload, turn, .. } = invocation;
let arguments = match payload {
ToolPayload::Function { arguments } => arguments,
@@ -103,6 +106,20 @@ impl TestSyncHandler {
wait_on_barrier(barrier).await?;
}
if args.wait_for_git_enrichment {
tokio::time::timeout(
GIT_ENRICHMENT_TIMEOUT,
turn.turn_metadata_state.wait_for_git_enrichment(),
)
.await
.map_err(|_| {
FunctionCallError::RespondToModel(format!(
"test_sync_tool git enrichment wait timed out after {} seconds",
GIT_ENRICHMENT_TIMEOUT.as_secs()
))
})?;
}
if let Some(delay) = args.sleep_after_ms
&& delay > 0
{
@@ -46,6 +46,13 @@ pub fn create_test_sync_tool() -> ToolSpec {
Some(false.into()),
),
),
(
"wait_for_git_enrichment".to_string(),
JsonSchema::boolean(Some(
"Wait for Git enrichment for the current turn to finish, subject to a timeout."
.to_string(),
)),
),
]);
ToolSpec::Function(ResponsesApiTool {
@@ -57,6 +57,13 @@ fn test_sync_tool_matches_expected_spec() {
"Delay before any other action. Defaults to no delay.".to_string(),
)),
),
(
"wait_for_git_enrichment".to_string(),
JsonSchema::boolean(Some(
"Wait for Git enrichment for the current turn to finish, subject to a timeout."
.to_string(),
)),
),
]), /*required*/ None, Some(false.into())),
output_schema: None,
})