chore(wip): checkpoint P8/C avant chantier Codex inter-agents

Sauvegarde de l'arbre de travail en cours (persistance P8, conversations
C-series, write-portal frontend, médiation d'entrée) avant d'attaquer le
support de la délégation inter-agents pour les profils Codex.

Le round-trip inter-agent question/réponse est couvert sans tokens par
les tests loopback existants (state::mcp_e2e_loopback_tests).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-13 21:42:53 +02:00
parent 4509f0db9d
commit fdcf16c387
76 changed files with 3783 additions and 1404 deletions

View File

@ -71,7 +71,8 @@ impl TempDir {
}
/// `<root>/.ideai/conversations/<conversationId>/providers.json.tmp` — the atomic-write tmp (P5).
fn providers_tmp_path(&self, conversation: ConversationId) -> PathBuf {
self.conversation_dir(conversation).join("providers.json.tmp")
self.conversation_dir(conversation)
.join("providers.json.tmp")
}
}
impl Drop for TempDir {
@ -119,10 +120,13 @@ async fn append_writes_one_valid_json_line_per_turn() {
let lines: Vec<&str> = raw.lines().filter(|l| !l.trim().is_empty()).collect();
assert_eq!(lines.len(), 3, "one line per append, got: {raw:?}");
for line in &lines {
let parsed: ConversationTurn =
serde_json::from_str(line).unwrap_or_else(|e| panic!("invalid JSON line {line:?}: {e}"));
let parsed: ConversationTurn = serde_json::from_str(line)
.unwrap_or_else(|e| panic!("invalid JSON line {line:?}: {e}"));
// camelCase shape leaks through to the file (sanity on the persisted format).
assert!(line.contains("\"atMs\""), "expected camelCase atMs in {line:?}");
assert!(
line.contains("\"atMs\""),
"expected camelCase atMs in {line:?}"
);
let _ = parsed;
}
}
@ -144,7 +148,9 @@ async fn persists_across_a_fresh_instance_restart() {
(2, TurnRole::Response, "b"),
(3, TurnRole::Prompt, "c"),
] {
log.append(c, turn(c, turn_id(id), role, txt)).await.unwrap();
log.append(c, turn(c, turn_id(id), role, txt))
.await
.unwrap();
}
}
@ -184,7 +190,10 @@ async fn conversations_land_in_disjoint_files() {
assert_ne!(p1, p2, "the two conversations must use distinct files");
// No cross-leak through the API, and the c2 file holds only c2's single line.
assert_eq!(texts(&log.read(c1, None).await.unwrap()), vec!["c1-a", "c1-b"]);
assert_eq!(
texts(&log.read(c1, None).await.unwrap()),
vec!["c1-a", "c1-b"]
);
assert_eq!(texts(&log.read(c2, None).await.unwrap()), vec!["c2-a"]);
let c2_raw = std::fs::read_to_string(&p2).unwrap();
assert_eq!(
@ -192,7 +201,10 @@ async fn conversations_land_in_disjoint_files() {
1,
"c2 file must not contain c1's turns"
);
assert!(!c2_raw.contains("c1-"), "no c1 content leaked into c2's file");
assert!(
!c2_raw.contains("c1-"),
"no c1 content leaked into c2's file"
);
}
// ---------------------------------------------------------------------------
@ -228,11 +240,21 @@ async fn corrupted_line_is_skipped_without_panic() {
// A fresh instance must skip the junk line and return only the two valid turns.
let log = FsConversationLog::new(&tmp.project_path());
let all = log.read(c, None).await.unwrap();
assert_eq!(texts(&all), vec!["good-1", "good-2"], "garbage line skipped");
assert_eq!(
texts(&all),
vec!["good-1", "good-2"],
"garbage line skipped"
);
// `last` must be just as tolerant.
assert_eq!(texts(&log.last(c, 5).await.unwrap()), vec!["good-1", "good-2"]);
assert_eq!(
texts(&log.last(c, 5).await.unwrap()),
vec!["good-1", "good-2"]
);
// And the cursor still works across the corrupted tail.
assert_eq!(texts(&log.read(c, Some(turn_id(1))).await.unwrap()), vec!["good-2"]);
assert_eq!(
texts(&log.read(c, Some(turn_id(1))).await.unwrap()),
vec!["good-2"]
);
}
#[tokio::test]
@ -260,7 +282,11 @@ async fn good_line_appended_after_corruption_is_still_read() {
.unwrap();
let all = log.read(c, None).await.unwrap();
assert_eq!(texts(&all), vec!["before", "after"], "junk in the middle is skipped, both reals survive");
assert_eq!(
texts(&all),
vec!["before", "after"],
"junk in the middle is skipped, both reals survive"
);
}
// ---------------------------------------------------------------------------
@ -274,7 +300,11 @@ async fn missing_conversation_reads_empty() {
// Nothing was ever appended: no .ideai dir at all.
assert!(log.read(conv_id(99), None).await.unwrap().is_empty());
assert!(log.read(conv_id(99), Some(turn_id(1))).await.unwrap().is_empty());
assert!(log
.read(conv_id(99), Some(turn_id(1)))
.await
.unwrap()
.is_empty());
assert!(log.last(conv_id(99), 5).await.unwrap().is_empty());
}
@ -293,8 +323,14 @@ async fn read_cursor_is_strictly_exclusive() {
.unwrap();
}
assert_eq!(texts(&log.read(c, Some(turn_id(1))).await.unwrap()), vec!["b", "c"]);
assert_eq!(texts(&log.read(c, Some(turn_id(2))).await.unwrap()), vec!["c"]);
assert_eq!(
texts(&log.read(c, Some(turn_id(1))).await.unwrap()),
vec!["b", "c"]
);
assert_eq!(
texts(&log.read(c, Some(turn_id(2))).await.unwrap()),
vec!["c"]
);
// Cursor on the last id => nothing after.
assert!(log.read(c, Some(turn_id(3))).await.unwrap().is_empty());
// Unknown cursor => empty (cohérent avec le double in-memory de P1).
@ -317,9 +353,15 @@ async fn last_contract_zero_and_bounds() {
// last(n < len) => the n last, in insertion order.
assert_eq!(texts(&log.last(c, 2).await.unwrap()), vec!["c", "d"]);
// last(n > len) => everything.
assert_eq!(texts(&log.last(c, 10).await.unwrap()), vec!["a", "b", "c", "d"]);
assert_eq!(
texts(&log.last(c, 10).await.unwrap()),
vec!["a", "b", "c", "d"]
);
// last(n == len) => everything.
assert_eq!(texts(&log.last(c, 4).await.unwrap()), vec!["a", "b", "c", "d"]);
assert_eq!(
texts(&log.last(c, 4).await.unwrap()),
vec!["a", "b", "c", "d"]
);
}
// ---------------------------------------------------------------------------
@ -352,7 +394,11 @@ async fn concurrent_appends_on_same_conversation_keep_both_lines_intact() {
// Exactly two non-empty lines, each a fully-parseable turn (no interleaving).
let raw = std::fs::read_to_string(tmp.log_path(c)).unwrap();
let lines: Vec<&str> = raw.lines().filter(|l| !l.trim().is_empty()).collect();
assert_eq!(lines.len(), 2, "two concurrent appends => two lines, got: {raw:?}");
assert_eq!(
lines.len(),
2,
"two concurrent appends => two lines, got: {raw:?}"
);
for line in &lines {
serde_json::from_str::<ConversationTurn>(line)
.unwrap_or_else(|e| panic!("interleaved/corrupted line {line:?}: {e}"));
@ -391,15 +437,23 @@ async fn handoff_round_trip_multiline_summary_with_objective() {
// summary_md délibérément multi-ligne, avec un `---` interne et des espaces de fin
// pour éprouver la fidélité octet-pour-octet du corps.
let summary = "# Résumé de reprise\n\n- point un\n- point deux\n\n---\n\nbloc final avec trailing \n";
let summary =
"# Résumé de reprise\n\n- point un\n- point deux\n\n---\n\nbloc final avec trailing \n";
let handoff = Handoff::new(summary, turn_id(42), Some("livrer le lot P3".to_string()));
store.save(c, handoff.clone()).await.unwrap();
let loaded = store.load(c).await.unwrap();
assert_eq!(loaded, Some(handoff.clone()), "round-trip doit redonner le Handoff exact");
assert_eq!(
loaded,
Some(handoff.clone()),
"round-trip doit redonner le Handoff exact"
);
let loaded = loaded.unwrap();
assert_eq!(loaded.summary_md, summary, "summary_md conservé octet pour octet");
assert_eq!(
loaded.summary_md, summary,
"summary_md conservé octet pour octet"
);
assert_eq!(loaded.up_to, turn_id(42), "up_to conservé à l'identique");
assert_eq!(loaded.objective.as_deref(), Some("livrer le lot P3"));
}
@ -428,8 +482,14 @@ async fn handoff_round_trip_without_objective() {
// Sanity sur le format brut : pas de ligne `objective:` quand None.
let raw = std::fs::read_to_string(tmp.handoff_path(c)).unwrap();
assert!(!raw.contains("objective:"), "aucune clé objective ne doit être écrite, got: {raw:?}");
assert!(raw.contains("upTo: "), "upTo toujours présent, got: {raw:?}");
assert!(
!raw.contains("objective:"),
"aucune clé objective ne doit être écrite, got: {raw:?}"
);
assert!(
raw.contains("upTo: "),
"upTo toujours présent, got: {raw:?}"
);
}
// ---------------------------------------------------------------------------
@ -464,8 +524,15 @@ async fn handoff_save_is_atomic_no_tmp_left_behind() {
"le fichier temporaire handoff.md.tmp ne doit pas subsister après save"
);
// Le fichier final existe et est complet/relisible.
assert!(tmp.handoff_path(c).exists(), "handoff.md final doit exister");
assert_eq!(store.load(c).await.unwrap(), Some(handoff), "contenu final lisible et complet");
assert!(
tmp.handoff_path(c).exists(),
"handoff.md final doit exister"
);
assert_eq!(
store.load(c).await.unwrap(),
Some(handoff),
"contenu final lisible et complet"
);
}
// ---------------------------------------------------------------------------
@ -485,10 +552,20 @@ async fn handoff_overwrite_keeps_only_the_last() {
store.save(c, second.clone()).await.unwrap();
// load renvoie le dernier, aucune trace du premier.
assert_eq!(store.load(c).await.unwrap(), Some(second), "load doit renvoyer le dernier save");
assert_eq!(
store.load(c).await.unwrap(),
Some(second),
"load doit renvoyer le dernier save"
);
let raw = std::fs::read_to_string(tmp.handoff_path(c)).unwrap();
assert!(!raw.contains("première version"), "le contenu du premier save ne doit pas subsister");
assert!(!raw.contains("obj-1"), "l'objective du premier save ne doit pas subsister");
assert!(
!raw.contains("première version"),
"le contenu du premier save ne doit pas subsister"
);
assert!(
!raw.contains("obj-1"),
"l'objective du premier save ne doit pas subsister"
);
}
// ---------------------------------------------------------------------------
@ -515,11 +592,20 @@ async fn handoff_is_isolated_per_conversation() {
// Deux fichiers distincts sur disque.
let p1 = tmp.handoff_path(c1);
let p2 = tmp.handoff_path(c2);
assert_ne!(p1, p2, "deux conversations => deux fichiers handoff distincts");
assert_ne!(
p1, p2,
"deux conversations => deux fichiers handoff distincts"
);
assert!(p1.exists() && p2.exists());
let raw2 = std::fs::read_to_string(&p2).unwrap();
assert!(!raw2.contains("résumé c1"), "aucune fuite de c1 dans le handoff de c2");
assert!(!raw2.contains("obj-c1"), "aucune fuite de l'objective de c1 dans c2");
assert!(
!raw2.contains("résumé c1"),
"aucune fuite de c1 dans le handoff de c2"
);
assert!(
!raw2.contains("obj-c1"),
"aucune fuite de l'objective de c1 dans c2"
);
}
// ---------------------------------------------------------------------------
@ -537,11 +623,23 @@ async fn handoff_corruption_yields_serialization_error_no_panic() {
// (4) `upTo` non-UUID.
// (5) ligne de front-matter sans `:`.
let cases: [(u128, &str, &str); 5] = [
(101, "pas de fence ouvrant\nupTo: 00000000-0000-0000-0000-000000000001\n---\ncorps\n", "fence ouvrant absent"),
(102, "---\nupTo: 00000000-0000-0000-0000-000000000001\ncorps sans fence fermant\n", "fence fermant absent"),
(
101,
"pas de fence ouvrant\nupTo: 00000000-0000-0000-0000-000000000001\n---\ncorps\n",
"fence ouvrant absent",
),
(
102,
"---\nupTo: 00000000-0000-0000-0000-000000000001\ncorps sans fence fermant\n",
"fence fermant absent",
),
(103, "---\nobjective: but\n---\ncorps\n", "upTo absent"),
(104, "---\nupTo: pas-un-uuid\n---\ncorps\n", "upTo non-UUID"),
(105, "---\nligne sans deux-points\n---\ncorps\n", "ligne front-matter sans `:`"),
(
105,
"---\nligne sans deux-points\n---\ncorps\n",
"ligne front-matter sans `:`",
),
];
for (n, content, label) in cases {
@ -575,7 +673,10 @@ async fn handoff_corruption_yields_serialization_error_no_panic() {
/// Compte les lignes-tours (`- **…`) dans un `summary_md` rendu.
fn turn_lines(summary_md: &str) -> Vec<&str> {
summary_md.lines().filter(|l| l.starts_with("- **")).collect()
summary_md
.lines()
.filter(|l| l.starts_with("- **"))
.collect()
}
/// `fold(None, turns)` = calcul de base : tours rendus, curseur = dernier id,
@ -595,7 +696,8 @@ async fn fold_none_renders_base_window_objective_and_cursor() {
// Objectif extrait du 1er Prompt.
assert_eq!(h.objective.as_deref(), Some("Implémente la feature X"));
assert!(
h.summary_md.contains("**Objectif :** Implémente la feature X"),
h.summary_md
.contains("**Objectif :** Implémente la feature X"),
"ligne d'objectif attendue, got:\n{}",
h.summary_md
);
@ -603,7 +705,12 @@ async fn fold_none_renders_base_window_objective_and_cursor() {
assert_eq!(h.up_to, turn_id(3));
// Les 3 tours rendus, un par ligne, avec le bon label.
let lines = turn_lines(&h.summary_md);
assert_eq!(lines.len(), 3, "3 lignes-tours attendues, got:\n{}", h.summary_md);
assert_eq!(
lines.len(),
3,
"3 lignes-tours attendues, got:\n{}",
h.summary_md
);
assert_eq!(lines[0], "- **Prompt:** Implémente la feature X");
assert_eq!(lines[1], "- **Tool:** ran grep");
assert_eq!(lines[2], "- **Response:** fait");
@ -626,11 +733,18 @@ async fn fold_is_incremental_does_not_re_pass_old_turns() {
// Le 2e appel ne re-fournit QUE t6.
let h2 = s
.fold(Some(h1.clone()), &[turn(c, turn_id(6), TurnRole::Response, "r6")])
.fold(
Some(h1.clone()),
&[turn(c, turn_id(6), TurnRole::Response, "r6")],
)
.await;
let lines = turn_lines(&h2.summary_md);
assert_eq!(lines.len(), 6, "t1..t6 reconstitués depuis prev + incrément");
assert_eq!(
lines.len(),
6,
"t1..t6 reconstitués depuis prev + incrément"
);
assert_eq!(lines[0], "- **Prompt:** obj un");
assert_eq!(lines[5], "- **Response:** r6");
assert_eq!(h2.up_to, turn_id(6), "curseur = dernier de l'incrément");
@ -686,7 +800,10 @@ async fn fold_keeps_existing_objective_over_new_prompt() {
);
let h = s
.fold(Some(prev), &[turn(c, turn_id(2), TurnRole::Prompt, "un autre but")])
.fold(
Some(prev),
&[turn(c, turn_id(2), TurnRole::Prompt, "un autre but")],
)
.await;
assert_eq!(h.objective.as_deref(), Some("but initial"), "objectif figé");
@ -752,10 +869,13 @@ async fn fold_flattens_multiline_and_marker_like_text_into_one_line() {
// Le tour piégeux est aplati en une seule ligne (whitespace collapsé).
let lines = turn_lines(&h1.summary_md);
assert_eq!(lines.len(), 2, "2 lignes-tours seulement, pas de ligne fantôme");
assert_eq!(
lines[1],
"- **Response:** ligne une - **Prompt:** faux marqueur ligne trois",
lines.len(),
2,
"2 lignes-tours seulement, pas de ligne fantôme"
);
assert_eq!(
lines[1], "- **Response:** ligne une - **Prompt:** faux marqueur ligne trois",
"texte multi-lignes + marqueur aplati en une ligne"
);
@ -765,10 +885,17 @@ async fn fold_flattens_multiline_and_marker_like_text_into_one_line() {
// (préfixée par `- **Response:** ligne une `), le reparse par `starts_with("- **")`
// la compte comme UNE seule ligne — la fenêtre reste cohérente.
let h2 = s
.fold(Some(h1.clone()), &[turn(c, turn_id(3), TurnRole::Response, "suite")])
.fold(
Some(h1.clone()),
&[turn(c, turn_id(3), TurnRole::Response, "suite")],
)
.await;
let lines2 = turn_lines(&h2.summary_md);
assert_eq!(lines2.len(), 3, "fenêtre cohérente après repli (pas de split parasite)");
assert_eq!(
lines2.len(),
3,
"fenêtre cohérente après repli (pas de split parasite)"
);
assert_eq!(lines2[2], "- **Response:** suite");
assert_eq!(h2.up_to, turn_id(3));
}
@ -902,8 +1029,16 @@ async fn provider_corrupted_file_yields_serialization_error_no_panic() {
// Cas de contenus non-désérialisables en map<String,String>.
let cases: [(u128, &str, &str); 3] = [
(201, "{ ceci n'est pas du json", "JSON syntaxiquement invalide"),
(202, "[\"pas\", \"un\", \"objet\"]", "JSON valide mais pas un objet map"),
(
201,
"{ ceci n'est pas du json",
"JSON syntaxiquement invalide",
),
(
202,
"[\"pas\", \"un\", \"objet\"]",
"JSON valide mais pas un objet map",
),
(203, "{\"claude\": 123}", "valeur non-String"),
];
@ -986,8 +1121,14 @@ async fn provider_is_isolated_per_conversation() {
store.set(c2, "claude", "c2-id").await.unwrap();
// Chacune relit la sienne.
assert_eq!(store.get(c1, "claude").await.unwrap(), Some("c1-id".to_string()));
assert_eq!(store.get(c2, "claude").await.unwrap(), Some("c2-id".to_string()));
assert_eq!(
store.get(c1, "claude").await.unwrap(),
Some("c1-id".to_string())
);
assert_eq!(
store.get(c2, "claude").await.unwrap(),
Some("c2-id".to_string())
);
// Deux fichiers distincts sur disque, sans fuite de contenu.
let p1 = tmp.providers_path(c1);
@ -995,5 +1136,8 @@ async fn provider_is_isolated_per_conversation() {
assert_ne!(p1, p2, "deux conversations ⇒ deux providers.json distincts");
assert!(p1.exists() && p2.exists());
let raw2 = std::fs::read_to_string(&p2).unwrap();
assert!(!raw2.contains("c1-id"), "aucune fuite de c1 dans le providers.json de c2");
assert!(
!raw2.contains("c1-id"),
"aucune fuite de c1 dans le providers.json de c2"
);
}