From ffb6b5ace1d74bf42ff4534e9e8f37516c88f672 Mon Sep 17 00:00:00 2001 From: deimagjas Date: Sun, 10 May 2026 21:06:48 -0500 Subject: [PATCH] fix: corregir commits=0 en status.json por safe.directory de git MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Git ≥ 2.35.2 rechaza operar en repos poseídos por un usuario distinto. Después de chown al usuario agent, las métricas post-agente fallaban silenciosamente como root. Se añade -c safe.directory= a los comandos de métricas y se usa BASE..HEAD para contar solo commits del agente. Co-Authored-By: Claude Sonnet 4.6 --- config/entrypoint.sh | 8 ++++++-- config/spec/entrypoint_spec.sh | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/config/entrypoint.sh b/config/entrypoint.sh index 782e463..cbbfd82 100644 --- a/config/entrypoint.sh +++ b/config/entrypoint.sh @@ -51,6 +51,8 @@ create_worktree() { # Create destination directory if it doesn't exist mkdir -p "$(dirname "$WORKTREE_PATH")" + WORKTREE_BASE_SHA=$(git -C /workspace rev-parse HEAD 2>/dev/null || echo "") + # Add worktree (idempotent: if branch already exists, reuses it) if git -C /workspace worktree add "$WORKTREE_PATH" -b "$WORKTREE_BRANCH" 2>/dev/null; then echo "[entrypoint] Worktree created on new branch: ${WORKTREE_BRANCH}" @@ -124,8 +126,10 @@ run_agent() { # Collect post-run metrics local commit_count last_commit finished_at end_epoch duration_secs - commit_count=$(git -C "$WORKTREE_PATH" rev-list --count HEAD 2>/dev/null || echo 0) - last_commit=$(git -C "$WORKTREE_PATH" log --oneline -1 2>/dev/null || echo "none") + commit_count=$(git -C "$WORKTREE_PATH" -c "safe.directory=$WORKTREE_PATH" \ + rev-list --count "${WORKTREE_BASE_SHA:-HEAD}..HEAD" 2>/dev/null || echo 0) + last_commit=$(git -C "$WORKTREE_PATH" -c "safe.directory=$WORKTREE_PATH" \ + log --oneline -1 2>/dev/null || echo "none") finished_at=$(date -u +"%Y-%m-%dT%H:%M:%SZ") end_epoch=$(date +%s) duration_secs=$((end_epoch - start_epoch)) diff --git a/config/spec/entrypoint_spec.sh b/config/spec/entrypoint_spec.sh index 879f2b8..0770c0e 100644 --- a/config/spec/entrypoint_spec.sh +++ b/config/spec/entrypoint_spec.sh @@ -61,6 +61,9 @@ git() { [[ "$GIT_WORKTREE_NEW_BRANCH_SUCCEEDS" == "true" ]] && return 0 || return 1 elif [[ "$*" == *"worktree add"* ]]; then [[ "$GIT_WORKTREE_EXISTING_BRANCH_SUCCEEDS" == "true" ]] && return 0 || return 1 + elif [[ "$*" == *"rev-parse HEAD"* ]]; then + echo "basef00d" + return 0 elif [[ "$*" == *"rev-list --count"* ]]; then echo "3" return 0 @@ -486,7 +489,19 @@ WRAPPER_EOF It "collects commit count after agent finishes" When run run_entrypoint --worktree agent-br --task "do work" - The output should include "[MOCK] git -C /worktrees/agent-br rev-list --count HEAD" + The output should include "rev-list --count" + The status should equal 0 + End + + It "uses safe.directory flag when collecting git metrics" + When run run_entrypoint --worktree agent-br --task "do work" + The output should include "safe.directory=/worktrees/agent-br" + The status should equal 0 + End + + It "counts only agent commits using BASE..HEAD" + When run run_entrypoint --worktree agent-br --task "do work" + The output should include "basef00d..HEAD" The status should equal 0 End End