feat(v0.5.2): add restore, notes, path commands with completion plumbing
Three new direct-lookup commands per v0.5.2-spec.md:
- ctask restore <ws> un-archive a workspace (metadata-only flip,
mirrors archive's lease guard, refuses to
restore an already-active workspace)
- ctask notes <ws> stream a workspace's notes.md to stdout (raw,
no framing, [ctask]-prefixed stderr on error)
so AI agents can read prior workspace context
through standard shell pipelines
- ctask path <ws> print the absolute filesystem path of a
workspace, OS-native separators, one line
All three resolve archived-inclusive: the user typed a name, so we
find the workspace whether or not it's archived. Listing stays
filtered (active-only by default) per the v0.5.2 design rule
"listing is filtered, direct lookup is comprehensive".
Adds shared completion infrastructure (cmd/completion.go) used by
these commands and wired into the existing workspace-accepting
commands in a follow-up commit. Candidates are workspace directory
basenames (e.g. 2026-04-22_promptvolley) rather than bare slugs
because basenames are unique under the resolver's exact-match step
while slugs can collide across categories or dates.
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/warrenronsiek/ctask/internal/workspace"
|
||||
)
|
||||
|
||||
// callPath invokes runPath with stdout captured.
|
||||
func callPath(t *testing.T, root, query string) (string, 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)
|
||||
}
|
||||
}()
|
||||
|
||||
r, w, _ := os.Pipe()
|
||||
prevStdout := os.Stdout
|
||||
os.Stdout = w
|
||||
defer func() { os.Stdout = prevStdout }()
|
||||
|
||||
err := runPath(pathCmd, []string{query})
|
||||
w.Close()
|
||||
var buf bytes.Buffer
|
||||
buf.ReadFrom(r)
|
||||
return buf.String(), err
|
||||
}
|
||||
|
||||
func TestPathPrintsAbsolutePath(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dirName := "2026-04-22_path-active"
|
||||
wsDir := filepath.Join(root, "general", dirName)
|
||||
os.MkdirAll(wsDir, 0755)
|
||||
now := time.Now().UTC().Truncate(time.Second)
|
||||
meta := &workspace.TaskMeta{
|
||||
ID: "t", Slug: "path-active", Title: "path-active",
|
||||
CreatedAt: now, UpdatedAt: now,
|
||||
Status: "active", Category: "general", Type: "task",
|
||||
Mode: "local", Agent: "claude",
|
||||
}
|
||||
workspace.WriteMeta(filepath.Join(wsDir, "task.yaml"), meta)
|
||||
|
||||
out, err := callPath(t, root, "path-active")
|
||||
if err != nil {
|
||||
t.Fatalf("path: %v", err)
|
||||
}
|
||||
got := strings.TrimRight(out, "\r\n")
|
||||
want, _ := filepath.Abs(wsDir)
|
||||
if got != want {
|
||||
t.Errorf("output path mismatch:\nwant: %q\ngot: %q", want, got)
|
||||
}
|
||||
if !strings.HasSuffix(out, "\n") {
|
||||
t.Errorf("output should end with a newline, got: %q", out)
|
||||
}
|
||||
if filepath.IsAbs(got) != true {
|
||||
t.Errorf("output must be absolute, got: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPathWorksOnArchivedWorkspace(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dirName := "2026-04-22_path-archived"
|
||||
wsDir := filepath.Join(root, "general", dirName)
|
||||
os.MkdirAll(wsDir, 0755)
|
||||
now := time.Now().UTC().Truncate(time.Second)
|
||||
meta := &workspace.TaskMeta{
|
||||
ID: "t", Slug: "path-archived", Title: "path-archived",
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
ArchivedAt: &now,
|
||||
Status: "archived",
|
||||
Category: "general",
|
||||
Type: "task",
|
||||
Mode: "local",
|
||||
Agent: "claude",
|
||||
}
|
||||
workspace.WriteMeta(filepath.Join(wsDir, "task.yaml"), meta)
|
||||
|
||||
out, err := callPath(t, root, "path-archived")
|
||||
if err != nil {
|
||||
t.Fatalf("path should find archived workspace: %v", err)
|
||||
}
|
||||
got := strings.TrimRight(out, "\r\n")
|
||||
want, _ := filepath.Abs(wsDir)
|
||||
if got != want {
|
||||
t.Errorf("output path mismatch:\nwant: %q\ngot: %q", want, got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user