mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
f3f47cf455
## What changed - This PR changes only the flaky test setup for `turn_start_notify_payload_includes_initialize_client_name`. - Instead of shelling out to `python3` to write the notify payload, the test uses the first-party `codex-app-server-test-notify-capture` helper. - The helper writes `notify.json` atomically and the test waits for the file to exist before reading it. ## Why this fixes the flake - The old test depended on an external Python interpreter being present and behaving consistently on every CI runner. - It also raced the file write: the test could observe the path before the payload had been fully written, which produced partial reads and intermittent assertion failures. - Moving the write into a repo-owned helper removes the external dependency, and atomic write-plus-wait makes the handoff deterministic. ## Scope - Test-only change.
45 lines
1.3 KiB
Rust
45 lines
1.3 KiB
Rust
use std::env;
|
|
use std::fs;
|
|
use std::fs::File;
|
|
use std::io::Write;
|
|
use std::path::PathBuf;
|
|
|
|
use anyhow::Context;
|
|
use anyhow::Result;
|
|
use anyhow::anyhow;
|
|
use anyhow::bail;
|
|
|
|
fn main() -> Result<()> {
|
|
let mut args = env::args_os();
|
|
let _program = args.next();
|
|
let output_path = PathBuf::from(
|
|
args.next()
|
|
.ok_or_else(|| anyhow!("expected output path as first argument"))?,
|
|
);
|
|
let payload = args
|
|
.next()
|
|
.ok_or_else(|| anyhow!("expected payload as final argument"))?;
|
|
|
|
if args.next().is_some() {
|
|
bail!("expected payload as final argument");
|
|
}
|
|
|
|
let payload = payload.to_string_lossy();
|
|
let temp_path = PathBuf::from(format!("{}.tmp", output_path.display()));
|
|
let mut file = File::create(&temp_path)
|
|
.with_context(|| format!("failed to create {}", temp_path.display()))?;
|
|
file.write_all(payload.as_bytes())
|
|
.with_context(|| format!("failed to write {}", temp_path.display()))?;
|
|
file.sync_all()
|
|
.with_context(|| format!("failed to sync {}", temp_path.display()))?;
|
|
fs::rename(&temp_path, &output_path).with_context(|| {
|
|
format!(
|
|
"failed to move {} into {}",
|
|
temp_path.display(),
|
|
output_path.display()
|
|
)
|
|
})?;
|
|
|
|
Ok(())
|
|
}
|