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/capstone/exercise/config_test.go

View on GitHub
package main

import (
	"context"
	"errors"
	"fmt"
	"io/fs"
	"os"
	"path/filepath"
	"slices"
	"strings"
	"testing"
)

// resolve parses args against a fresh tree and resolves the settings for the
// command they select — without running it. Find picks the command, ParseFlags
// fills its flag set (including the persistent flags inherited from root).
func resolve(t *testing.T, app *App, args ...string) (Settings, error) {
	t.Helper()
	root := NewRootCmd(app)
	target, rest, err := root.Find(args)
	if err != nil {
		t.Fatalf("Find(%q): %v", args, err)
	}
	if err := target.ParseFlags(rest); err != nil {
		t.Fatalf("ParseFlags(%q): %v", rest, err)
	}
	return app.Resolve(target)
}

// writeConfig writes a config file at the app's default location.
func writeConfig(t *testing.T, app *App, body string) string {
	t.Helper()
	path := filepath.Join(app.ConfigDir, "scout", "config.json")
	if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
		t.Fatalf("mkdir: %v", err)
	}
	if err := os.WriteFile(path, []byte(body), 0o644); err != nil {
		t.Fatalf("write config: %v", err)
	}
	return path
}

// writeConfigAt writes a config file anywhere and returns its path.
func writeConfigAt(t *testing.T, body string) string {
	t.Helper()
	path := filepath.Join(t.TempDir(), "scout.json")
	if err := os.WriteFile(path, []byte(body), 0o644); err != nil {
		t.Fatalf("write config: %v", err)
	}
	return path
}

func TestResolveDefaults(t *testing.T) {
	app := newApp(t, nil)
	set, err := resolve(t, app, "scan")
	if err != nil {
		t.Fatalf("Resolve: %v", err)
	}
	if set.Top != DefaultTop || set.Limit != DefaultLimit {
		t.Errorf("Top/Limit = %d/%d, want %d/%d", set.Top, set.Limit, DefaultTop, DefaultLimit)
	}
	if set.JSON {
		t.Error("JSON = true, want false by default")
	}
	if set.Color {
		t.Error("Color = true, want false: stdout is not a terminal in tests")
	}
	if !slices.Equal(set.Ignore, DefaultIgnore) {
		t.Errorf("Ignore = %v, want %v", set.Ignore, DefaultIgnore)
	}
	// A missing file at the *default* location is the normal case, not an
	// error — and it must be this app's location, not a fresh one, or the
	// check proves nothing about the values resolved above.
	if _, err := os.Stat(filepath.Join(app.ConfigDir, "scout", "config.json")); !errors.Is(err, fs.ErrNotExist) {
		t.Fatalf("test setup: the default config path should not exist")
	}
}

func TestResolvePrecedence(t *testing.T) {
	cases := []struct {
		name   string
		config string            // written to the default location when non-empty
		env    map[string]string //
		args   []string
		want   Settings
	}{
		{
			name: "config file beats the defaults",
			config: `{"top": 3, "limit": 4, "json": true,
			          "ignore": ["dist"], "color": "never"}`,
			args: []string{"scan"},
			want: Settings{Top: 3, Limit: 4, JSON: true, Ignore: []string{"dist"}},
		},
		{
			name:   "environment beats the config file",
			config: `{"top": 3, "ignore": ["dist"]}`,
			env:    map[string]string{"SCOUT_TOP": "5", "SCOUT_IGNORE": "out, tmp"},
			args:   []string{"scan"},
			want:   Settings{Top: 5, Limit: DefaultLimit, Ignore: []string{"out", "tmp"}},
		},
		{
			name:   "flag beats the environment",
			config: `{"top": 3}`,
			env:    map[string]string{"SCOUT_TOP": "5"},
			args:   []string{"scan", "--top", "7"},
			want:   Settings{Top: 7, Limit: DefaultLimit, Ignore: DefaultIgnore},
		},
		{
			name: "a flag left alone does not overwrite the environment",
			env:  map[string]string{"SCOUT_TOP": "5"},
			args: []string{"scan"},
			want: Settings{Top: 5, Limit: DefaultLimit, Ignore: DefaultIgnore},
		},
		{
			name: "a flag typed at its default value still wins",
			env:  map[string]string{"SCOUT_TOP": "5"},
			args: []string{"scan", "--top", "10"},
			want: Settings{Top: DefaultTop, Limit: DefaultLimit, Ignore: DefaultIgnore},
		},
		{
			name: "an explicit false flag beats a true environment",
			env:  map[string]string{"SCOUT_JSON": "true"},
			args: []string{"scan", "--json=false"},
			want: Settings{Top: DefaultTop, Limit: DefaultLimit, JSON: false, Ignore: DefaultIgnore},
		},
		{
			name: "environment turns JSON on",
			env:  map[string]string{"SCOUT_JSON": "1"},
			args: []string{"scan"},
			want: Settings{Top: DefaultTop, Limit: DefaultLimit, JSON: true, Ignore: DefaultIgnore},
		},
		{
			name: "authors sees its own --limit and not scan's --top",
			env:  map[string]string{"SCOUT_LIMIT": "2"},
			args: []string{"authors", "--limit", "3"},
			want: Settings{Top: DefaultTop, Limit: 3, Ignore: DefaultIgnore},
		},
	}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			app := newApp(t, c.env)
			if c.config != "" {
				writeConfig(t, app, c.config)
			}
			got, err := resolve(t, app, c.args...)
			if err != nil {
				t.Fatalf("Resolve: %v", err)
			}
			if got.Top != c.want.Top || got.Limit != c.want.Limit || got.JSON != c.want.JSON {
				t.Errorf("Top/Limit/JSON = %d/%d/%v, want %d/%d/%v",
					got.Top, got.Limit, got.JSON, c.want.Top, c.want.Limit, c.want.JSON)
			}
			if !slices.Equal(got.Ignore, c.want.Ignore) {
				t.Errorf("Ignore = %v, want %v", got.Ignore, c.want.Ignore)
			}
		})
	}
}

func TestConfigFileLocation(t *testing.T) {
	t.Run("SCOUT_CONFIG points at a file", func(t *testing.T) {
		path := writeConfigAt(t, `{"top": 2}`)
		app := newApp(t, map[string]string{"SCOUT_CONFIG": path})
		writeConfig(t, app, `{"top": 9}`) // the default location must lose
		got, err := resolve(t, app, "scan")
		if err != nil {
			t.Fatalf("Resolve: %v", err)
		}
		if got.Top != 2 {
			t.Errorf("Top = %d, want 2 from SCOUT_CONFIG", got.Top)
		}
	})

	t.Run("--config beats SCOUT_CONFIG", func(t *testing.T) {
		flagPath := writeConfigAt(t, `{"top": 1}`)
		envPath := writeConfigAt(t, `{"top": 2}`)
		app := newApp(t, map[string]string{"SCOUT_CONFIG": envPath})
		got, err := resolve(t, app, "scan", "--config", flagPath)
		if err != nil {
			t.Fatalf("Resolve: %v", err)
		}
		if got.Top != 1 {
			t.Errorf("Top = %d, want 1 from --config", got.Top)
		}
	})

	t.Run("a named file that does not exist is an error", func(t *testing.T) {
		missing := filepath.Join(t.TempDir(), "nope.json")
		_, err := resolve(t, newApp(t, nil), "scan", "--config", missing)
		if !errors.Is(err, fs.ErrNotExist) {
			t.Errorf("err = %v, want one matching fs.ErrNotExist", err)
		}
		if !errors.Is(err, ErrUsage) {
			t.Errorf("err = %v, want one matching ErrUsage: the user named a file that is not there", err)
		}
	})

	t.Run("no config directory at all is fine", func(t *testing.T) {
		app := newApp(t, nil)
		app.ConfigDir = ""
		if _, err := resolve(t, app, "scan"); err != nil {
			t.Errorf("Resolve: %v, want defaults when there is nowhere to look", err)
		}
	})
}

func TestLoadConfigFile(t *testing.T) {
	t.Run("missing file returns fs.ErrNotExist unchanged", func(t *testing.T) {
		_, err := LoadConfigFile(filepath.Join(t.TempDir(), "nope.json"))
		if !errors.Is(err, fs.ErrNotExist) {
			t.Errorf("err = %v, want one matching fs.ErrNotExist", err)
		}
	})

	t.Run("unknown key is rejected", func(t *testing.T) {
		path := writeConfigAt(t, `{"tpo": 3}`)
		_, err := LoadConfigFile(path)
		if err == nil {
			t.Fatal("no error for an unknown config key: a typo must not be silently ignored")
		}
		if !errors.Is(err, ErrUsage) || !strings.Contains(err.Error(), "tpo") {
			t.Errorf("err = %v, want a usage error naming the key %q", err, "tpo")
		}
	})

	t.Run("malformed JSON names the file", func(t *testing.T) {
		path := writeConfigAt(t, `{"top": `)
		_, err := LoadConfigFile(path)
		if err == nil || !strings.Contains(err.Error(), path) {
			t.Errorf("err = %v, want an error naming %s", err, path)
		}
	})

	t.Run("absent keys stay absent", func(t *testing.T) {
		fc, err := LoadConfigFile(writeConfigAt(t, `{"json": false}`))
		if err != nil {
			t.Fatalf("LoadConfigFile: %v", err)
		}
		if fc.JSON == nil || *fc.JSON {
			t.Error(`"json": false must decode to a pointer to false, not nil`)
		}
		if fc.Top != nil {
			t.Error("a key that is not in the file must decode to nil, so it cannot overwrite a lower layer")
		}
	})
}

func TestResolveErrors(t *testing.T) {
	cases := []struct {
		name    string
		config  string
		env     map[string]string
		args    []string
		wantMsg string
	}{
		{
			name:    "unparseable SCOUT_TOP",
			env:     map[string]string{"SCOUT_TOP": "abc"},
			args:    []string{"scan"},
			wantMsg: `invalid SCOUT_TOP "abc"`,
		},
		{
			name:    "negative --top",
			args:    []string{"scan", "--top", "-1"},
			wantMsg: "invalid --top -1",
		},
		{
			name:    "negative value in the config file",
			config:  `{"top": -2}`,
			args:    []string{"scan"},
			wantMsg: "invalid top in",
		},
		{
			name:    "unknown colour policy",
			args:    []string{"scan", "--color", "purple"},
			wantMsg: `invalid color "purple"`,
		},
		{
			name:    "unknown colour policy from the environment",
			env:     map[string]string{"SCOUT_COLOR": "beige"},
			args:    []string{"scan"},
			wantMsg: `invalid color "beige"`,
		},
		{
			name:    "unparseable SCOUT_JSON",
			env:     map[string]string{"SCOUT_JSON": "maybe"},
			args:    []string{"scan"},
			wantMsg: `invalid SCOUT_JSON "maybe"`,
		},
	}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			app := newApp(t, c.env)
			if c.config != "" {
				writeConfig(t, app, c.config)
			}
			_, err := resolve(t, app, c.args...)
			if err == nil {
				t.Fatalf("no error, want one containing %q", c.wantMsg)
			}
			if !strings.Contains(err.Error(), c.wantMsg) {
				t.Errorf("err = %v, want one containing %q", err, c.wantMsg)
			}
			if !errors.Is(err, ErrUsage) {
				t.Errorf("err = %v, want one matching ErrUsage so exitCode can return 2", err)
			}
		})
	}
}

func TestResolveColorPolicy(t *testing.T) {
	cases := []struct {
		name       string
		mode       ColorMode
		isTerminal bool
		env        map[string]string
		want       bool
	}{
		{"never wins over everything", ColorNever, true, nil, false},
		{"always beats NO_COLOR", ColorAlways, false, map[string]string{"NO_COLOR": "1"}, true},
		{"auto on a terminal", ColorAuto, true, nil, true},
		{"auto off a terminal", ColorAuto, false, nil, false},
		{"NO_COLOR vetoes auto", ColorAuto, true, map[string]string{"NO_COLOR": "1"}, false},
		{"empty NO_COLOR is not a veto", ColorAuto, true, map[string]string{"NO_COLOR": ""}, true},
		{"TERM=dumb vetoes auto", ColorAuto, true, map[string]string{"TERM": "dumb"}, false},
	}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			getenv := func(k string) string { return c.env[k] }
			if got := ResolveColor(c.mode, c.isTerminal, getenv); got != c.want {
				t.Errorf("ResolveColor(%v, terminal=%v, %v) = %v, want %v",
					c.mode, c.isTerminal, c.env, got, c.want)
			}
		})
	}
}

func TestJSONForcesColorOff(t *testing.T) {
	app := newApp(t, nil)
	app.StdoutIsTerminal = true

	got, err := resolve(t, app, "scan", "--json", "--color", "always")
	if err != nil {
		t.Fatalf("Resolve: %v", err)
	}
	if got.Color {
		t.Error("Color = true with --json: machine-readable output is never styled, whatever the policy says")
	}
}

func TestExitCode(t *testing.T) {
	cases := []struct {
		name string
		err  error
		want int
	}{
		{"success", nil, 0},
		{"usage", ErrUsage, 2},
		{"wrapped usage", fmt.Errorf("scan: %w", ErrUsage), 2},
		{"cancelled", context.Canceled, 130},
		{"wrapped cancellation", fmt.Errorf("walk: %w", context.Canceled), 130},
		{"deadline", context.DeadlineExceeded, 130},
		{"wrapped deadline", fmt.Errorf("scan: %w", context.DeadlineExceeded), 130},
		{"vcs failure", ErrVCS, 1},
		{"anything else", errors.New("boom"), 1},
	}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			if got := exitCode(c.err); got != c.want {
				t.Errorf("exitCode(%v) = %d, want %d", c.err, got, c.want)
			}
		})
	}
}
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: 471kUpdated 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