Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

test(codex): the abrupt-exit race has three branches, not two

Samir Hanna Verza32086e9354d3
diff --git a/crates/ai-memory-llm/src/codex.rs b/crates/ai-memory-llm/src/codex.rs
index 57e8672a..fccc4bd2 100644
--- a/crates/ai-memory-llm/src/codex.rs
+++ b/crates/ai-memory-llm/src/codex.rs
@@ -812,26 +812,42 @@ mod tests {
"new-token"
);
+ // An abrupt exit is a *three*-way race, and each outcome is the same
+ // correct verdict reached down a different path: the stdout reader
+ // sees EOF ("...ended before replying"), the stderr monitor sees EOF
+ // ("...ended before completing"), or the request write loses to the
+ // exit and takes EPIPE ("Could not write to..."). The first de-flake
+ // widened the assertion to the shared prefix of the first two, and a
+ // loaded runner then produced the third. Enumerate the branches
+ // instead of asserting a prefix: a substring wide enough to cover all
+ // three would no longer say anything.
+ const ABRUPT_EXIT: &[&str] = &[
+ "Codex recovery process ended before replying",
+ "Codex recovery process ended before completing",
+ "Could not write to Codex recovery process",
+ ];
for (mode, expected) in [
- ("wrong-id", "unexpected JSON-RPC response id"),
- ("invalid", "invalid JSON"),
- ("oversized", "exceeded its limit"),
- ("stderr", "stderr exceeded its limit"),
- // An abrupt exit is a race between the stdout reader (EOF ->
- // "...ended before replying") and the stderr monitor (EOF ->
- // "...ended before completing"); both are correct early-exit
- // errors, and which wins is timing-dependent (it flaked on a loaded
- // CI runner). Assert the shared, meaningful part rather than the
- // racy tail.
- ("exit", "recovery process ended before"),
- ("exit-nonzero", "recovery process ended before"),
+ ("wrong-id", &["unexpected JSON-RPC response id"][..]),
+ ("invalid", &["invalid JSON"][..]),
+ ("oversized", &["exceeded its limit"][..]),
+ ("stderr", &["stderr exceeded its limit"][..]),
+ ("exit", ABRUPT_EXIT),
+ ("exit-nonzero", ABRUPT_EXIT),
] {
fs::write(dir.path().join("fake-mode"), mode).unwrap();
let error = recover_with_codex(&auth, Duration::from_secs(3))
.await
.unwrap_err()
.to_string();
- assert!(error.contains(expected), "mode={mode}, error={error}");
+ assert!(
+ expected.iter().any(|want| error.contains(want)),
+ "mode={mode}, error={error}, expected one of {expected:?}"
+ );
+ // Whichever branch won, the operator has to be told how to fix it.
+ assert!(
+ error.contains("run `codex login status`"),
+ "mode={mode} must surface as a re-auth error, got {error}"
+ );
}
fs::write(dir.path().join("fake-mode"), "sleep").unwrap();