Add explicit flush to append_entry and strengthen commit ordering docs

Add file.flush() call in append_entry() to ensure planner history
entries are written to disk before git commits execute. While the
file handle drop should flush, explicit flush simplifies reasoning
about the ordering invariant.

Extend code comments in stage_and_commit() to document that the
write_git_commit-before-git::commit ordering has regressed multiple
times and must be preserved in any refactoring.

Requirements: completed_requirements_2025-12-11_10-05-08.md
This commit is contained in:
Jochen
2025-12-11 10:05:39 +11:00
parent b3ac7746b9
commit 1a13fc5345
8 changed files with 323 additions and 14 deletions

View File

@@ -308,6 +308,27 @@ pub fn stage_files(codepath: &Path, plan_dir: &Path) -> Result<StagingResult> {
Ok(result)
}
/// Re-stage the g3-plan directory to capture any changes made after initial staging.
///
/// This is specifically needed because `planner_history.txt` is modified AFTER the initial
/// `stage_files()` call (to write the GIT COMMIT entry) but BEFORE `git commit`.
/// Without this re-staging, the GIT COMMIT entry would not be included in the commit.
pub fn stage_plan_dir(codepath: &Path, plan_dir: &Path) -> Result<()> {
let plan_dir_str = plan_dir.to_string_lossy();
let add_output = Command::new("git")
.args(["add", &plan_dir_str])
.current_dir(codepath)
.output()
.context("Failed to re-stage g3-plan directory")?;
if !add_output.status.success() {
let stderr = String::from_utf8_lossy(&add_output.stderr);
anyhow::bail!("Failed to re-stage g3-plan directory: {}", stderr);
}
Ok(())
}
/// Result of staging operation
#[derive(Debug, Default)]
pub struct StagingResult {