Files
ctask/cmd/resume_test.go
T
typebasedio c204d87b47 polish(v0.5.3): v0.4 lease-prompt hint, invocation-name in user-facing commands, smoke-checklist fixes
Three independent v0.5.3 polish items surfaced during manual WSL smoke testing,
bundled into one commit since they're all string/UX touches with no behavior change.

1. v0.4 lease-prompt tightening (`internal/session/{lease,run,run_preflight}.go`,
   `cmd/entry.go`): when ctask is about to enter direct mode on a workspace that
   already has a live tmux session, the "Continue anyway?" prompt now suggests
   `ctask attach <slug>` as the reattach path. Threaded via
   `PreflightOpts.ActiveLeaseHint` / `LaunchOpts.ActiveLeaseHint`; computed in
   `cmd/entry.go::directModeTmuxHint` (best-effort: silent when no tmux on PATH
   or no session for the workspace). Closes the footgun where a user forgot to
   `export CTASK_SESSION_MODE=persistent` in a second terminal and hit the v0.4
   coexistence prompt without realizing tmux passive-reattach was the intended
   path.

2. Invocation-name in user-facing command hints (`cmd/invocation.go` new,
   `cmd/{persistent,entry,resume,doctor}.go`): the binary name printed in
   bypass / restore / "create one with" suggestions now reflects
   `filepath.Base(os.Args[0])` instead of a hard-coded "ctask". Local-build
   PowerShell users running `.\ctask.exe` see `ctask.exe new <ws> --direct`,
   matching what they need to type. Installed contexts continue to see `ctask`.
   Test seam (`invocationNameOverride`) pins the name to "ctask" in unit tests
   so substring assertions stay stable across Go test binary names. Descriptive
   prose ("ctask persistent mode requires...") and the ssh-remote hint
   (`ssh -t <host> ctask <subcmd>`) intentionally keep the literal "ctask" —
   they refer to the program identity / remote invocation, not the local
   command form. Affected tests: `cmd/{persistent,resume}_test.go` tightened to
   check the full `"<binary> <subcmd> <workspace> --direct"` form.

3. Smoke-checklist fixes (`docs/.../2026-05-08-v0.5.3-smoke-test-checklist.md`):
   six issues caught during the run -- S2 now exports CTASK_SESSION_MODE in
   both terminals (previously only WSL-A had it, which routed WSL-B's
   secondary resume through direct mode instead of passive reattach); O3/A2
   tmux-ls expectations corrected (tmux doesn't emit a literal "(detached)"
   token); P2 expected behavior rewritten (passive reattach detach returns to
   prompt immediately -- AttachExisting calls only shell.AttachSession with
   no PollSessionEnd, the owner is responsible for finalize); A1 no longer
   asks for Ctrl-C in WSL-B; A6 path now uses a glob (was hardcoded to the
   checklist's authoring date, broke on v0.5.1 local-time directory naming);
   M1 PATH-hide rewritten to `$HOME/.local/bin` only (was `:/bin` which is a
   symlink to /usr/bin on usrmerge systems, did not hide tmux) and uses
   `command -v` instead of `which` (which is itself in /usr/bin, unreachable
   under the minimal PATH); M3/M4 reordered so the no-workspace verification
   runs after PATH is restored (was silently failing under minimal PATH);
   T1 wording made "substring match" explicit; T2 wording made N/A
   unambiguous; section 10 split into 10a-10f, each a separate input, to
   work around PSReadLine multi-line paste parsing.
2026-05-14 18:22:27 -04:00

87 lines
2.5 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, "", false)
errW.Close()
var buf bytes.Buffer
buf.ReadFrom(errR)
return buf.String(), err
}
func TestResumeArchivedWorkspaceShowsRestoreHint(t *testing.T) {
// Pin the binary name surfaced in user-facing hints so the substring
// assertion below ("ctask restore resume-archived") is stable across
// Go test binary naming.
invocationNameOverride = "ctask"
t.Cleanup(func() { invocationNameOverride = "" })
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)
}
}