Files
ctask/cmd/resume_test.go
T
typebasedio b923ae8892 feat(v0.5.2): direct lookup includes archived; resume hint for archived
Apply the v0.5.2 lookup policy to the existing commands and wire
ValidArgsFunction hooks across the workspace-accepting surface.

info: drop the --all/-a flag entirely. Direct lookup is now
archived-inclusive by default — the user typed a name, so we find
the workspace and surface its status in the output. The Status
line already distinguishes active vs archived clearly.

resume: when targeting an archived workspace, fail with a useful
hint instead of letting the resolver report "not found":

  [ctask] error: workspace "X" is archived

  To restore it:
    ctask restore X

This is implemented by resolving archived-inclusive and rejecting
status==archived before any session-launch logic runs. Genuine
not-found and ambiguous-match behavior are unchanged.

Adds ValidArgsFunction hooks to archive (active), delete (active),
open (active), info (any), resume (active). Restore/notes/path
already have hooks from the previous commit. Shell completion now
covers the full direct-lookup surface.
2026-05-07 19:47:24 -04:00

81 lines
2.3 KiB
Go

package cmd
import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
"time"
"github.com/warrenronsiek/ctask/internal/workspace"
)
// callDoResumeArchived is a focused harness: it sets CTASK_ROOT, captures
// stderr, and runs doResume. The test fixtures only exercise the early
// archived-status branch; we never reach session.Run because the archived
// branch returns first.
func callDoResumeArchived(t *testing.T, root, query string) (stderr string, err error) {
t.Helper()
prevRoot := os.Getenv("CTASK_ROOT")
os.Setenv("CTASK_ROOT", root)
defer func() {
if prevRoot == "" {
os.Unsetenv("CTASK_ROOT")
} else {
os.Setenv("CTASK_ROOT", prevRoot)
}
}()
errR, errW, _ := os.Pipe()
prevStderr := os.Stderr
os.Stderr = errW
defer func() { os.Stderr = prevStderr }()
err = doResume(query, false, false, false, "")
errW.Close()
var buf bytes.Buffer
buf.ReadFrom(errR)
return buf.String(), err
}
func TestResumeArchivedWorkspaceShowsRestoreHint(t *testing.T) {
root := t.TempDir()
wsDir := filepath.Join(root, "general", "2026-04-22_resume-archived")
os.MkdirAll(wsDir, 0755)
now := time.Now().UTC().Truncate(time.Second)
archived := now.Add(-time.Hour)
meta := &workspace.TaskMeta{
ID: "t", Slug: "resume-archived", Title: "resume-archived",
CreatedAt: now, UpdatedAt: archived,
ArchivedAt: &archived,
Status: "archived",
Category: "general",
Type: "task",
Mode: "local",
Agent: "claude",
}
workspace.WriteMeta(filepath.Join(wsDir, "task.yaml"), meta)
stderr, err := callDoResumeArchived(t, root, "resume-archived")
if err == nil {
t.Fatal("expected error resuming archived workspace")
}
if !strings.Contains(stderr, `workspace "resume-archived" is archived`) {
t.Errorf("stderr should explain archived state: %q", stderr)
}
if !strings.Contains(stderr, "ctask restore resume-archived") {
t.Errorf("stderr should contain restore hint: %q", stderr)
}
// Workspace metadata must be unchanged (no UpdatedAt bump).
got, _ := workspace.ReadMeta(filepath.Join(wsDir, "task.yaml"))
if got.Status != "archived" {
t.Errorf("workspace mutated despite refusal: status=%s", got.Status)
}
if !got.UpdatedAt.Equal(archived) {
t.Errorf("UpdatedAt advanced despite refusal: was %v, now %v", archived, got.UpdatedAt)
}
}