You've already forked agentic-coding-workflow
feat(workspace): clear prune_warning_at on SetWorktreeActive/Idle
This commit is contained in:
@@ -136,3 +136,53 @@ func errsAlreadyActive() error {
|
||||
type shimErr struct{}
|
||||
|
||||
func (e *shimErr) Error() string { return "already active" }
|
||||
|
||||
// TestRepo_SetWorktreeActive_ClearsPruneWarning 验证 SetWorktreeActive
|
||||
// 会清空 prune_warning_at 列;同样验证 SetWorktreeIdle。前置:用直接 SQL
|
||||
// 把列写成非 NULL;行为:repo 调用后再读 DB 应回到 NULL。
|
||||
func TestRepo_SetWorktreeActive_ClearsPruneWarning(t *testing.T) {
|
||||
t.Parallel()
|
||||
repo, pool, pid := setupRepo(t)
|
||||
ctx := context.Background()
|
||||
wsID := uuid.New()
|
||||
_, err := repo.CreateWorkspace(ctx, &Workspace{
|
||||
ID: wsID, ProjectID: pid, Slug: "ws-pw", Name: "PW",
|
||||
GitRemoteURL: "https://x", DefaultBranch: "main", MainPath: "/x", SyncStatus: SyncStatusIdle,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
wtID := uuid.New()
|
||||
require.NoError(t, repo.InTx(ctx, func(tx Tx) error {
|
||||
_, e := tx.InsertWorktree(ctx, &Worktree{
|
||||
ID: wtID, WorkspaceID: wsID, Branch: "warn-branch",
|
||||
Path: "/x/.worktrees/warn", Status: WorktreeStatusIdle,
|
||||
})
|
||||
return e
|
||||
}))
|
||||
|
||||
// 把 prune_warning_at 写成非 NULL。
|
||||
_, err = pool.Exec(ctx, `UPDATE workspace_worktrees SET prune_warning_at = now() WHERE id = $1`, wtID)
|
||||
require.NoError(t, err)
|
||||
|
||||
var pwAt *time.Time
|
||||
require.NoError(t, pool.QueryRow(ctx, `SELECT prune_warning_at FROM workspace_worktrees WHERE id = $1`, wtID).Scan(&pwAt))
|
||||
require.NotNil(t, pwAt, "precondition: prune_warning_at should be set")
|
||||
|
||||
// SetWorktreeActive 应该清空它。
|
||||
require.NoError(t, repo.InTx(ctx, func(tx Tx) error {
|
||||
_, e := tx.SetWorktreeActive(ctx, wtID, "user:tester")
|
||||
return e
|
||||
}))
|
||||
require.NoError(t, pool.QueryRow(ctx, `SELECT prune_warning_at FROM workspace_worktrees WHERE id = $1`, wtID).Scan(&pwAt))
|
||||
require.Nil(t, pwAt, "SetWorktreeActive should clear prune_warning_at")
|
||||
|
||||
// 再写回非 NULL,验证 SetWorktreeIdle 也会清空。
|
||||
_, err = pool.Exec(ctx, `UPDATE workspace_worktrees SET prune_warning_at = now() WHERE id = $1`, wtID)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, repo.InTx(ctx, func(tx Tx) error {
|
||||
_, e := tx.SetWorktreeIdle(ctx, wtID)
|
||||
return e
|
||||
}))
|
||||
require.NoError(t, pool.QueryRow(ctx, `SELECT prune_warning_at FROM workspace_worktrees WHERE id = $1`, wtID).Scan(&pwAt))
|
||||
require.Nil(t, pwAt, "SetWorktreeIdle should clear prune_warning_at")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user