feat(workspace,jobs): emit sync_aborted_on_restart audit + enrich worktree.pruned metadata

- workspace.ResetStuckSyncStatuses now returns affected IDs so app.New can record one workspace.sync_aborted_on_restart audit per reset row
- worktree_prune audit metadata gains workspace_id and path alongside existing branch
- updated fakeRepo + integration test for new ResetStuckSyncStatuses signature
- add TestWorktreePrune_AuditMetadataContainsWorkspaceIDAndPath
This commit is contained in:
2026-05-07 10:14:46 +08:00
parent b1ccce567e
commit a2b6d5382e
8 changed files with 110 additions and 22 deletions
@@ -10,10 +10,20 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/yan1h/agent-coding-workflow/internal/audit"
"github.com/yan1h/agent-coding-workflow/internal/infra/notify"
"github.com/yan1h/agent-coding-workflow/internal/jobs/runners"
)
type recordingRecorder struct {
entries []audit.Entry
}
func (r *recordingRecorder) Record(_ context.Context, e audit.Entry) error {
r.entries = append(r.entries, e)
return nil
}
// fakeWorktreeRepo is a fresh fake distinct from fakeWorkspaceFetchRepo.
type fakeWorktreeRepo struct {
warnList []runners.WorktreeRow
@@ -172,6 +182,37 @@ func TestWorktreePrune_NoRowsIsNoOp(t *testing.T) {
assert.Empty(t, disp.msgs)
}
func TestWorktreePrune_AuditMetadataContainsWorkspaceIDAndPath(t *testing.T) {
t.Parallel()
id := uuid.New()
workspaceID := uuid.New()
ownerID := uuid.New()
row := runners.WorktreeRow{
ID: id, WorkspaceID: workspaceID, OwnerID: ownerID,
Branch: "feat-audit", MainPath: "/main", Path: "/main/.worktrees/feat-audit",
}
repo := &fakeWorktreeRepo{
pruneList: []runners.WorktreeRow{row},
tryStartResult: row,
}
gitr := &fakePruner{}
rec := &recordingRecorder{}
cfg := runners.WorktreePruneConfig{IdleThreshold: 7 * 24 * time.Hour, WarningLead: 3 * 24 * time.Hour}
r := runners.NewWorktreePrune(repo, gitr, &recordingDispatcher{}, cfg, discardLogger(), rec)
r.Run(context.Background())
require.Len(t, rec.entries, 1)
e := rec.entries[0]
assert.Equal(t, "worktree.pruned", e.Action)
assert.Equal(t, "worktree", e.TargetType)
assert.Equal(t, id.String(), e.TargetID)
assert.Equal(t, workspaceID.String(), e.Metadata["workspace_id"])
assert.Equal(t, "feat-audit", e.Metadata["branch"])
assert.Equal(t, "/main/.worktrees/feat-audit", e.Metadata["path"])
}
func TestWorktreePrune_CASLostSkipsSilently(t *testing.T) {
t.Parallel()
id := uuid.New()