Skip to content

qtsone/learning / skills/tutor

tutor

Flagged

Turn this agent into a personal programming tutor with a versioned 0-to-expert curriculum (Go available; more languages coming). Use when the user wants to learn a programming language, start or resume lessons, get their exercise code graded, check learning progress, or contribute curriculum fixes — e.g. "/tutor go", "/tutor resume", "teach me Go", "continue my lessons", "grade my exercise".

FileKindSize
SKILL.mdskill md9.2 KB
curriculum/content/focus/cli-tooling/capstone/LESSON.mdmarkdown17.1 KB
curriculum/content/focus/cli-tooling/capstone/TUTOR.mdmarkdown5.4 KB
curriculum/content/focus/cli-tooling/capstone/exercise/app.goscript5.8 KB
curriculum/content/focus/cli-tooling/capstone/exercise/authors.goscript1.6 KB
curriculum/content/focus/cli-tooling/capstone/exercise/authors_test.goscript7.3 KB
curriculum/content/focus/cli-tooling/capstone/exercise/cli_test.goscript11.5 KB
curriculum/content/focus/cli-tooling/capstone/exercise/config_test.goscript11.5 KB
curriculum/content/focus/cli-tooling/capstone/exercise/go.modmanifest187 B
curriculum/content/focus/cli-tooling/capstone/exercise/go.summanifest900 B
curriculum/content/focus/cli-tooling/capstone/exercise/main.goscript2.0 KB
curriculum/content/focus/cli-tooling/capstone/exercise/render.goscript1.9 KB
curriculum/content/focus/cli-tooling/capstone/exercise/root.goscript2.4 KB
curriculum/content/focus/cli-tooling/capstone/exercise/scan.goscript2.5 KB
curriculum/content/focus/cli-tooling/capstone/exercise/scan_test.goscript4.0 KB
curriculum/content/focus/cli-tooling/capstone/exercise/signal_unix_test.goscript1.4 KB
curriculum/content/focus/cli-tooling/capstone/exercise/version.goscript942 B
curriculum/content/focus/cli-tooling/capstone/quiz.jsonconfig5.0 KB
curriculum/content/focus/cli-tooling/capstone/solution/app.goscript9.9 KB
curriculum/content/focus/cli-tooling/capstone/solution/authors.goscript2.9 KB
curriculum/content/focus/cli-tooling/capstone/solution/render.goscript2.6 KB
curriculum/content/focus/cli-tooling/capstone/solution/root.goscript4.7 KB
curriculum/content/focus/cli-tooling/capstone/solution/scan.goscript3.7 KB
curriculum/content/focus/cli-tooling/cobra/LESSON.mdmarkdown12.8 KB
curriculum/content/focus/cli-tooling/cobra/TUTOR.mdmarkdown5.9 KB
curriculum/content/focus/cli-tooling/cobra/exercise/app.goscript1.7 KB
curriculum/content/focus/cli-tooling/cobra/exercise/go.modmanifest193 B
curriculum/content/focus/cli-tooling/cobra/exercise/go.summanifest900 B
curriculum/content/focus/cli-tooling/cobra/exercise/main.goscript422 B
curriculum/content/focus/cli-tooling/cobra/exercise/notes_test.goscript9.8 KB
curriculum/content/focus/cli-tooling/cobra/exercise/root.goscript919 B
curriculum/content/focus/cli-tooling/cobra/exercise/store.goscript1.7 KB
curriculum/content/focus/cli-tooling/cobra/quiz.jsonconfig5.1 KB
curriculum/content/focus/cli-tooling/cobra/solution/app.goscript2.4 KB
curriculum/content/focus/cli-tooling/cobra/solution/root.goscript4.2 KB
curriculum/content/focus/cli-tooling/distribution/LESSON.mdmarkdown17.2 KB
curriculum/content/focus/cli-tooling/distribution/TUTOR.mdmarkdown7.0 KB
curriculum/content/focus/cli-tooling/distribution/exercise/check.shexecutablescript12.0 KB
curriculum/content/focus/cli-tooling/distribution/exercise/go.modmanifest35 B
curriculum/content/focus/cli-tooling/distribution/exercise/internal/buildinfo/buildinfo.goscript1.4 KB
curriculum/content/focus/cli-tooling/distribution/exercise/main.goscript1.2 KB
curriculum/content/focus/cli-tooling/distribution/quiz.jsonconfig5.0 KB
curriculum/content/focus/cli-tooling/distribution/solution/.goreleaser.yamlconfig2.1 KB
curriculum/content/focus/cli-tooling/distribution/solution/internal/buildinfo/buildinfo.goscript1.3 KB
curriculum/content/focus/cli-tooling/files-processes/LESSON.mdmarkdown18.8 KB
curriculum/content/focus/cli-tooling/files-processes/TUTOR.mdmarkdown7.8 KB
curriculum/content/focus/cli-tooling/files-processes/exercise/atomicfile.goscript772 B
curriculum/content/focus/cli-tooling/files-processes/exercise/atomicfile_test.goscript2.6 KB
curriculum/content/focus/cli-tooling/files-processes/exercise/exec.goscript3.8 KB
curriculum/content/focus/cli-tooling/files-processes/exercise/exec_test.goscript10.7 KB
curriculum/content/focus/cli-tooling/files-processes/exercise/go.modmanifest44 B
curriculum/content/focus/cli-tooling/files-processes/exercise/main.goscript1.9 KB
curriculum/content/focus/cli-tooling/files-processes/exercise/paths.goscript1.6 KB
curriculum/content/focus/cli-tooling/files-processes/exercise/paths_test.goscript3.1 KB
curriculum/content/focus/cli-tooling/files-processes/exercise/signal.goscript1.6 KB
curriculum/content/focus/cli-tooling/files-processes/exercise/signal_test.goscript1.6 KB
curriculum/content/focus/cli-tooling/files-processes/exercise/signal_unix_test.goscript2.4 KB
curriculum/content/focus/cli-tooling/files-processes/quiz.jsonconfig7.9 KB
curriculum/content/focus/cli-tooling/files-processes/solution/atomicfile.goscript2.1 KB
curriculum/content/focus/cli-tooling/files-processes/solution/exec.goscript5.4 KB
curriculum/content/focus/cli-tooling/files-processes/solution/paths.goscript2.2 KB
curriculum/content/focus/cli-tooling/files-processes/solution/signal.goscript2.1 KB
curriculum/content/focus/cli-tooling/flags-config/LESSON.mdmarkdown12.3 KB
curriculum/content/focus/cli-tooling/flags-config/TUTOR.mdmarkdown6.7 KB
curriculum/content/focus/cli-tooling/flags-config/exercise/config.goscript2.4 KB
curriculum/content/focus/cli-tooling/flags-config/exercise/config_test.goscript3.1 KB
curriculum/content/focus/cli-tooling/flags-config/exercise/flagvalue.goscript769 B
curriculum/content/focus/cli-tooling/flags-config/exercise/flagvalue_test.goscript1.9 KB
curriculum/content/focus/cli-tooling/flags-config/exercise/go.modmanifest41 B
curriculum/content/focus/cli-tooling/flags-config/exercise/loader.goscript5.5 KB
curriculum/content/focus/cli-tooling/flags-config/exercise/loader_test.goscript12.4 KB
curriculum/content/focus/cli-tooling/flags-config/exercise/main.goscript1.2 KB
curriculum/content/focus/cli-tooling/flags-config/quiz.jsonconfig5.3 KB
curriculum/content/focus/cli-tooling/flags-config/solution/config.goscript3.2 KB
curriculum/content/focus/cli-tooling/flags-config/solution/flagvalue.goscript957 B
curriculum/content/focus/cli-tooling/flags-config/solution/loader.goscript9.0 KB
curriculum/content/focus/cli-tooling/terminal-ux/LESSON.mdmarkdown14.8 KB
curriculum/content/focus/cli-tooling/terminal-ux/TUTOR.mdmarkdown6.2 KB
curriculum/content/focus/cli-tooling/terminal-ux/exercise/color.goscript1.6 KB
curriculum/content/focus/cli-tooling/terminal-ux/exercise/color_test.goscript2.3 KB
curriculum/content/focus/cli-tooling/terminal-ux/exercise/go.modmanifest40 B
curriculum/content/focus/cli-tooling/terminal-ux/exercise/main.goscript3.6 KB
curriculum/content/focus/cli-tooling/terminal-ux/exercise/progress.goscript1.9 KB
curriculum/content/focus/cli-tooling/terminal-ux/exercise/progress_test.goscript1.9 KB
curriculum/content/focus/cli-tooling/terminal-ux/exercise/prompt.goscript2.3 KB
curriculum/content/focus/cli-tooling/terminal-ux/exercise/prompt_test.goscript4.7 KB
curriculum/content/focus/cli-tooling/terminal-ux/exercise/render.goscript3.8 KB
curriculum/content/focus/cli-tooling/terminal-ux/exercise/render_test.goscript6.1 KB
curriculum/content/focus/cli-tooling/terminal-ux/quiz.jsonconfig5.9 KB
curriculum/content/focus/cli-tooling/terminal-ux/solution/color.goscript1.8 KB
curriculum/content/focus/cli-tooling/terminal-ux/solution/progress.goscript2.0 KB
curriculum/content/focus/cli-tooling/terminal-ux/solution/prompt.goscript2.2 KB
curriculum/content/focus/cli-tooling/terminal-ux/solution/render.goscript4.3 KB
curriculum/content/focus/containers/capstone/LESSON.mdmarkdown20.0 KB
curriculum/content/focus/containers/capstone/TUTOR.mdmarkdown6.7 KB
curriculum/content/focus/containers/capstone/exercise/.dockerignoreother190 B
curriculum/content/focus/containers/capstone/exercise/.github/workflows/release.ymlconfig2.4 KB
curriculum/content/focus/containers/capstone/exercise/Dockerfileother903 B
curriculum/content/focus/containers/capstone/exercise/RUNBOOK.mdmarkdown1.6 KB
curriculum/content/focus/containers/capstone/exercise/check.shscript62.6 KB
curriculum/content/focus/containers/capstone/exercise/deploy/base/deployment.yamlconfig2.8 KB
curriculum/content/focus/containers/capstone/exercise/deploy/base/kustomization.yamlconfig845 B
curriculum/content/focus/containers/capstone/exercise/deploy/base/service.yamlconfig316 B
curriculum/content/focus/containers/capstone/exercise/deploy/overlays/dev/kustomization.yamlconfig1.3 KB
curriculum/content/focus/containers/capstone/exercise/deploy/overlays/dev/resources-patch.yamlconfig906 B
curriculum/content/focus/containers/capstone/exercise/deploy/overlays/prod/kustomization.yamlconfig899 B
curriculum/content/focus/containers/capstone/exercise/deploy/overlays/prod/resources-patch.yamlconfig341 B
curriculum/content/focus/containers/capstone/exercise/go.modmanifest48 B
curriculum/content/focus/containers/capstone/exercise/main.goscript6.4 KB
curriculum/content/focus/containers/capstone/quiz.jsonconfig6.5 KB
curriculum/content/focus/containers/capstone/solution/.github/workflows/release.ymlconfig6.4 KB
curriculum/content/focus/containers/capstone/solution/Dockerfileother1.2 KB
curriculum/content/focus/containers/capstone/solution/RUNBOOK.mdmarkdown7.7 KB
curriculum/content/focus/containers/capstone/solution/deploy/overlays/prod/kustomization.yamlconfig1.4 KB
curriculum/content/focus/containers/capstone/solution/deploy/overlays/prod/resources-patch.yamlconfig1.1 KB
curriculum/content/focus/containers/compose/LESSON.mdmarkdown13.5 KB
curriculum/content/focus/containers/compose/TUTOR.mdmarkdown5.2 KB
curriculum/content/focus/containers/compose/exercise/.env.exampleother348 B
curriculum/content/focus/containers/compose/exercise/app/Dockerfileother962 B
curriculum/content/focus/containers/compose/exercise/app/go.modmanifest40 B
curriculum/content/focus/containers/compose/exercise/app/main.goscript2.2 KB
curriculum/content/focus/containers/compose/exercise/check.shscript24.5 KB
curriculum/content/focus/containers/compose/exercise/compose.yamlconfig877 B
curriculum/content/focus/containers/compose/quiz.jsonconfig4.5 KB
curriculum/content/focus/containers/compose/solution/.envconfig203 B
curriculum/content/focus/containers/compose/solution/compose.yamlconfig1.6 KB
curriculum/content/focus/containers/deploying-go/LESSON.mdmarkdown21.1 KB
curriculum/content/focus/containers/deploying-go/TUTOR.mdmarkdown6.5 KB
curriculum/content/focus/containers/deploying-go/exercise/.dockerignoreother150 B
curriculum/content/focus/containers/deploying-go/exercise/Dockerfileother851 B
curriculum/content/focus/containers/deploying-go/exercise/SHUTDOWN.mdmarkdown1.4 KB
curriculum/content/focus/containers/deploying-go/exercise/check.shscript43.5 KB
curriculum/content/focus/containers/deploying-go/exercise/configmap.yamlconfig526 B
curriculum/content/focus/containers/deploying-go/exercise/deployment.yamlconfig2.5 KB
curriculum/content/focus/containers/deploying-go/exercise/go.modmanifest41 B
curriculum/content/focus/containers/deploying-go/exercise/main.goscript6.1 KB
curriculum/content/focus/containers/deploying-go/exercise/service.yamlconfig347 B
curriculum/content/focus/containers/deploying-go/exercise/shutdown_test.goscript3.3 KB
curriculum/content/focus/containers/deploying-go/quiz.jsonconfig6.5 KB
curriculum/content/focus/containers/deploying-go/solution/SHUTDOWN.mdmarkdown5.4 KB
curriculum/content/focus/containers/deploying-go/solution/configmap.yamlconfig541 B
curriculum/content/focus/containers/deploying-go/solution/deployment.yamlconfig4.0 KB
curriculum/content/focus/containers/deploying-go/solution/main.goscript6.1 KB
curriculum/content/focus/containers/docker-fundamentals/LESSON.mdmarkdown14.4 KB
curriculum/content/focus/containers/docker-fundamentals/TUTOR.mdmarkdown5.4 KB
curriculum/content/focus/containers/docker-fundamentals/exercise/Dockerfileother261 B
curriculum/content/focus/containers/docker-fundamentals/exercise/NOTES.mdmarkdown1.4 KB
curriculum/content/focus/containers/docker-fundamentals/exercise/check.shscript10.7 KB
curriculum/content/focus/containers/docker-fundamentals/exercise/go.modmanifest38 B
curriculum/content/focus/containers/docker-fundamentals/exercise/local.envconfig218 B
curriculum/content/focus/containers/docker-fundamentals/exercise/main.goscript780 B
curriculum/content/focus/containers/docker-fundamentals/exercise/scratch/notes.mdmarkdown153 B
curriculum/content/focus/containers/docker-fundamentals/quiz.jsonconfig5.5 KB
curriculum/content/focus/containers/docker-fundamentals/solution/.dockerignoreother230 B
curriculum/content/focus/containers/docker-fundamentals/solution/Dockerfileother504 B
curriculum/content/focus/containers/docker-fundamentals/solution/NOTES.mdmarkdown3.8 KB
curriculum/content/focus/containers/dockerizing-go/LESSON.mdmarkdown14.0 KB
curriculum/content/focus/containers/dockerizing-go/TUTOR.mdmarkdown5.4 KB
curriculum/content/focus/containers/dockerizing-go/exercise/.dockerignoreother143 B
curriculum/content/focus/containers/dockerizing-go/exercise/Dockerfile.naiveother512 B
curriculum/content/focus/containers/dockerizing-go/exercise/NOTES.mdmarkdown1.1 KB
curriculum/content/focus/containers/dockerizing-go/exercise/check.shscript14.2 KB
curriculum/content/focus/containers/dockerizing-go/exercise/go.modmanifest43 B
curriculum/content/focus/containers/dockerizing-go/exercise/go.summanifest0 B
curriculum/content/focus/containers/dockerizing-go/exercise/main.goscript1.7 KB
curriculum/content/focus/containers/dockerizing-go/quiz.jsonconfig4.5 KB
curriculum/content/focus/containers/dockerizing-go/solution/Dockerfileother755 B
curriculum/content/focus/containers/dockerizing-go/solution/NOTES.mdmarkdown2.7 KB
curriculum/content/focus/containers/helm-kustomize/LESSON.mdmarkdown19.1 KB
curriculum/content/focus/containers/helm-kustomize/TUTOR.mdmarkdown9.5 KB
curriculum/content/focus/containers/helm-kustomize/exercise/NOTES.mdmarkdown1.5 KB
curriculum/content/focus/containers/helm-kustomize/exercise/chart/Chart.yamlconfig518 B
curriculum/content/focus/containers/helm-kustomize/exercise/chart/templates/_helpers.tplother1.8 KB
curriculum/content/focus/containers/helm-kustomize/exercise/chart/templates/configmap.yamlconfig392 B
curriculum/content/focus/containers/helm-kustomize/exercise/chart/templates/deployment.yamlconfig3.2 KB
curriculum/content/focus/containers/helm-kustomize/exercise/chart/templates/service.yamlconfig512 B
curriculum/content/focus/containers/helm-kustomize/exercise/chart/values.yamlconfig1.4 KB
curriculum/content/focus/containers/helm-kustomize/exercise/check.shscript55.4 KB
curriculum/content/focus/containers/helm-kustomize/exercise/kustomize/base/deployment.yamlconfig2.1 KB
curriculum/content/focus/containers/helm-kustomize/exercise/kustomize/base/kustomization.yamlconfig798 B
curriculum/content/focus/containers/helm-kustomize/exercise/kustomize/base/service.yamlconfig347 B
curriculum/content/focus/containers/helm-kustomize/exercise/kustomize/overlays/dev/kustomization.yamlconfig616 B
curriculum/content/focus/containers/helm-kustomize/exercise/kustomize/overlays/dev/resources-patch.yamlconfig506 B
curriculum/content/focus/containers/helm-kustomize/exercise/kustomize/overlays/prod/kustomization.yamlconfig477 B
curriculum/content/focus/containers/helm-kustomize/exercise/kustomize/overlays/prod/resources-patch.yamlconfig614 B
curriculum/content/focus/containers/helm-kustomize/quiz.jsonconfig7.4 KB
curriculum/content/focus/containers/helm-kustomize/solution/NOTES.mdmarkdown3.3 KB
curriculum/content/focus/containers/helm-kustomize/solution/chart/Chart.yamlconfig366 B
curriculum/content/focus/containers/helm-kustomize/solution/chart/templates/configmap.yamlconfig547 B
curriculum/content/focus/containers/helm-kustomize/solution/chart/templates/deployment.yamlconfig2.5 KB
curriculum/content/focus/containers/helm-kustomize/solution/chart/values.yamlconfig1.2 KB
curriculum/content/focus/containers/helm-kustomize/solution/kustomize/base/kustomization.yamlconfig915 B
curriculum/content/focus/containers/helm-kustomize/solution/kustomize/overlays/dev/kustomization.yamlconfig820 B
curriculum/content/focus/containers/helm-kustomize/solution/kustomize/overlays/dev/resources-patch.yamlconfig515 B
curriculum/content/focus/containers/helm-kustomize/solution/kustomize/overlays/prod/kustomization.yamlconfig267 B
curriculum/content/focus/containers/helm-kustomize/solution/kustomize/overlays/prod/resources-patch.yamlconfig649 B
curriculum/content/focus/containers/kubernetes-config/LESSON.mdmarkdown19.4 KB
curriculum/content/focus/containers/kubernetes-config/TUTOR.mdmarkdown6.3 KB
curriculum/content/focus/containers/kubernetes-config/exercise/NOTES.mdmarkdown1.3 KB
curriculum/content/focus/containers/kubernetes-config/exercise/app/Dockerfileother1.0 KB

curriculum/content/focus/cli-tooling/cobra/exercise/notes_test.go

View on GitHub
package main

import (
	"bytes"
	"errors"
	"fmt"
	"strings"
	"testing"

	"github.com/spf13/cobra"
)

type result struct {
	stdout string
	stderr string
	err    error
}

func newApp(env map[string]string) *App {
	return &App{
		Store:  NewMemStore(),
		Getenv: func(k string) string { return env[k] },
	}
}

// run builds a fresh command tree, executes it with args, and captures
// everything the tree wrote. This is the whole testable-command pattern: no
// subprocess, no os.Args, no os.Exit.
func run(t *testing.T, app *App, args ...string) result {
	t.Helper()
	if args == nil {
		// SetArgs(nil) makes cobra fall back to os.Args[1:], which under
		// `go test` is full of -test.* flags. Always pass a non-nil slice.
		args = []string{}
	}
	var out, errOut bytes.Buffer
	root := NewRootCmd(app)
	root.SetOut(&out)
	root.SetErr(&errOut)
	root.SetArgs(args)
	err := root.Execute()
	return result{stdout: out.String(), stderr: errOut.String(), err: err}
}

func wantOK(t *testing.T, got result, wantStdout string) {
	t.Helper()
	if got.err != nil {
		t.Fatalf("unexpected error: %v", got.err)
	}
	if got.stdout != wantStdout {
		t.Errorf("stdout = %q, want %q", got.stdout, wantStdout)
	}
	if got.stderr != "" {
		t.Errorf("stderr = %q, want empty: cobra must not print diagnostics for you", got.stderr)
	}
}

func findCmd(t *testing.T, parent *cobra.Command, name string) *cobra.Command {
	t.Helper()
	for _, c := range parent.Commands() {
		if c.Name() == name {
			return c
		}
	}
	t.Fatalf("no %q subcommand under %q", name, parent.Name())
	return nil
}

func TestAddThenList(t *testing.T) {
	app := newApp(nil)

	wantOK(t, run(t, app, "add", "buy milk"), "added n1\n")
	wantOK(t, run(t, app, "add", "call ana", "--tag", "home", "--tag", "urgent"), "added n2\n")
	wantOK(t, run(t, app, "list"), "n1 buy milk\nn2 call ana #home #urgent\n")
}

func TestListEmpty(t *testing.T) {
	wantOK(t, run(t, newApp(nil), "list"), "no notes\n")
}

func TestListLimitFlag(t *testing.T) {
	app := newApp(nil)
	for i, text := range []string{"one", "two", "three"} {
		wantOK(t, run(t, app, "add", text), fmt.Sprintf("added n%d\n", i+1))
	}
	wantOK(t, run(t, app, "list", "--limit", "2"), "n1 one\nn2 two\n")
	wantOK(t, run(t, app, "list", "--limit", "0"), "n1 one\nn2 two\nn3 three\n")
}

func TestJSONOutput(t *testing.T) {
	app := newApp(nil)

	// A persistent flag is accepted before the subcommand …
	wantOK(t, run(t, app, "--format", "json", "add", "buy milk"),
		`{"id":"n1","text":"buy milk","tags":[]}`+"\n")
	// … and after it, because the child inherits the same flag.
	wantOK(t, run(t, app, "add", "call ana", "--tag", "home", "--format", "json"),
		`{"id":"n2","text":"call ana","tags":["home"]}`+"\n")
	wantOK(t, run(t, app, "list", "--format", "json"),
		`{"notes":[{"id":"n1","text":"buy milk","tags":[]},{"id":"n2","text":"call ana","tags":["home"]}]}`+"\n")
}

func TestFormatPrecedence(t *testing.T) {
	cases := []struct {
		name       string
		env        map[string]string
		args       []string
		wantStdout string
		wantErr    string
	}{
		{
			name:       "default is text",
			args:       []string{"add", "x"},
			wantStdout: "added n1\n",
		},
		{
			name:       "environment beats the default",
			env:        map[string]string{"NOTES_FORMAT": "json"},
			args:       []string{"add", "x"},
			wantStdout: `{"id":"n1","text":"x","tags":[]}` + "\n",
		},
		{
			name:       "flag beats the environment",
			env:        map[string]string{"NOTES_FORMAT": "json"},
			args:       []string{"--format", "text", "add", "x"},
			wantStdout: "added n1\n",
		},
		{
			name:    "invalid value from the environment",
			env:     map[string]string{"NOTES_FORMAT": "yaml"},
			args:    []string{"add", "x"},
			wantErr: `invalid format "yaml"`,
		},
		{
			name:    "invalid value from the flag",
			args:    []string{"--format", "yaml", "add", "x"},
			wantErr: `invalid format "yaml"`,
		},
	}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			got := run(t, newApp(c.env), c.args...)
			if c.wantErr != "" {
				if got.err == nil || !strings.Contains(got.err.Error(), c.wantErr) {
					t.Fatalf("error = %v, want one containing %q", got.err, c.wantErr)
				}
				if got.stdout != "" {
					t.Errorf("stdout = %q, want empty on a failed run", got.stdout)
				}
				return
			}
			wantOK(t, got, c.wantStdout)
		})
	}
}

func TestLimitPrecedence(t *testing.T) {
	cases := []struct {
		name       string
		env        map[string]string
		args       []string
		wantStdout string
		wantErr    string
	}{
		{
			name:       "default shows everything",
			args:       []string{"list"},
			wantStdout: "n1 one\nn2 two\nn3 three\n",
		},
		{
			name:       "environment beats the default",
			env:        map[string]string{"NOTES_LIMIT": "1"},
			args:       []string{"list"},
			wantStdout: "n1 one\n",
		},
		{
			name:       "flag beats the environment",
			env:        map[string]string{"NOTES_LIMIT": "1"},
			args:       []string{"list", "--limit", "2"},
			wantStdout: "n1 one\nn2 two\n",
		},
		{
			name:    "unparseable environment value is an error",
			env:     map[string]string{"NOTES_LIMIT": "abc"},
			args:    []string{"list"},
			wantErr: `invalid NOTES_LIMIT "abc"`,
		},
	}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			app := newApp(c.env)
			for _, text := range []string{"one", "two", "three"} {
				app.Store.Add(text, nil)
			}
			got := run(t, app, c.args...)
			if c.wantErr != "" {
				if got.err == nil || !strings.Contains(got.err.Error(), c.wantErr) {
					t.Fatalf("error = %v, want one containing %q", got.err, c.wantErr)
				}
				return
			}
			wantOK(t, got, c.wantStdout)
		})
	}
}

func TestTagSubtree(t *testing.T) {
	app := newApp(nil)

	wantOK(t, run(t, app, "add", "buy milk"), "added n1\n")
	wantOK(t, run(t, app, "tag", "add", "n1", "home", "shopping"), "tagged n1\n")
	wantOK(t, run(t, app, "list"), "n1 buy milk #home #shopping\n")
	wantOK(t, run(t, app, "tag", "list"), "home\nshopping\n")
	// The persistent flag declared on root reaches a grandchild command.
	wantOK(t, run(t, app, "tag", "list", "--format", "json"), `{"tags":["home","shopping"]}`+"\n")
}

func TestTagListEmpty(t *testing.T) {
	wantOK(t, run(t, newApp(nil), "tag", "list"), "no tags\n")
}

func TestTagAddUnknownNote(t *testing.T) {
	got := run(t, newApp(nil), "tag", "add", "n9", "home")
	if !errors.Is(got.err, ErrNoteNotFound) {
		t.Fatalf("error = %v, want one matching ErrNoteNotFound via errors.Is", got.err)
	}
	if got.stdout != "" {
		t.Errorf("stdout = %q, want empty on a failed run", got.stdout)
	}
}

func TestCommandErrors(t *testing.T) {
	cases := []struct {
		name string
		args []string
		want string
	}{
		{"unknown top-level command", []string{"frobnicate"}, `unknown command "frobnicate"`},
		{"unknown child of a group command", []string{"tag", "frobnicate"}, `unknown command "frobnicate"`},
		{"add needs exactly one argument", []string{"add"}, "accepts 1 arg"},
		{"add rejects a second argument", []string{"add", "a", "b"}, "accepts 1 arg"},
		{"list takes no positional arguments", []string{"list", "extra"}, `unknown command "extra"`},
		{"tag add needs a note and a tag", []string{"tag", "add", "n1"}, "requires at least 2 arg"},
		{"unknown flag", []string{"add", "x", "--nope"}, "unknown flag"},
	}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			got := run(t, newApp(nil), c.args...)
			if got.err == nil || !strings.Contains(got.err.Error(), c.want) {
				t.Fatalf("error = %v, want one containing %q", got.err, c.want)
			}
			if got.stdout != "" {
				t.Errorf("stdout = %q, want empty on a failed run", got.stdout)
			}
			if got.stderr != "" {
				t.Errorf("stderr = %q, want empty: main decides how errors are printed", got.stderr)
			}
		})
	}
}

func TestFlagScopes(t *testing.T) {
	root := NewRootCmd(newApp(nil))
	add := findCmd(t, root, "add")
	list := findCmd(t, root, "list")
	tag := findCmd(t, root, "tag")
	tagAdd := findCmd(t, tag, "add")

	if root.LocalFlags().Lookup("format") == nil {
		t.Error("--format must be declared on root as a persistent flag")
	}
	if add.InheritedFlags().Lookup("format") == nil {
		t.Error("add must inherit --format from root")
	}
	if add.LocalFlags().Lookup("format") != nil {
		t.Error("--format must be inherited by add, not redeclared on it")
	}
	if add.LocalFlags().Lookup("tag") == nil {
		t.Error("--tag must be a local flag on add")
	}
	if list.LocalFlags().Lookup("tag") != nil {
		t.Error("add's local --tag must not be visible on list")
	}
	if add.Flags().Lookup("limit") != nil {
		t.Error("list's local --limit must not be visible on add")
	}
	if list.LocalFlags().Lookup("limit") == nil {
		t.Error("--limit must be a local flag on list")
	}
	if tagAdd.InheritedFlags().Lookup("format") == nil {
		t.Error("a persistent flag must reach grandchildren such as `tag add`")
	}
}

// A command that only groups other commands must still answer for itself: with
// no arguments it prints its help and succeeds.
func TestGroupCommandsPrintHelp(t *testing.T) {
	cases := []struct {
		name string
		args []string
		want []string
	}{
		{"root", []string{}, []string{"add", "list", "tag"}},
		{"tag group", []string{"tag"}, []string{"add", "list"}},
	}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			got := run(t, newApp(nil), c.args...)
			if got.err != nil {
				t.Fatalf("unexpected error: %v", got.err)
			}
			for _, want := range c.want {
				if !strings.Contains(got.stdout, want) {
					t.Errorf("help output does not mention %q; got:\n%s", want, got.stdout)
				}
			}
		})
	}
}

func TestHelpGoesToTheInjectedWriter(t *testing.T) {
	got := run(t, newApp(nil), "--help")
	if got.err != nil {
		t.Fatalf("--help returned an error: %v", got.err)
	}
	for _, want := range []string{"add", "list", "tag", "--format"} {
		if !strings.Contains(got.stdout, want) {
			t.Errorf("help output does not mention %q; got:\n%s", want, got.stdout)
		}
	}
	if got.stderr != "" {
		t.Errorf("stderr = %q, want empty: help is not a diagnostic", got.stderr)
	}
}
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 470kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall