refactor(trail): tidy tune onboarding after review · Entire
refactor(trail): tidy tune onboarding after review
8e6e24b→main·
Soph·3w ago·4 files·+34 added/-26 removed
- Extract runnersDir(repoRoot) using paths.EntireDir; share it between loadTuneRunners and ensureRunnersPresent instead of duplicating the ".entire/runners" path literal.
- Drop the unused
createdbool from ensureRunnersPresent (caller ignored it); tests now assert filesystem state (defaults written / existing runner left untouched), a stronger check than the bool.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Sessions
b59e6739990aView transcript
Changes
4
cmd/entire/cli
Mtrail_tune_cmd.go+1/-1
Mtrail_tune_init.go+16/-15
Mtrail_tune_init_test.go+9/-9
Mtrail_tune_prompt.go+8/-1
90 unmodified lines
// Onboarding: a repo with no runners yet gets the default set scaffolded
// (on confirmation), which tune then tailors below.
if _, err := ensureRunnersPresent(w, errW, repoRoot, opts.assumeYes); err != nil {
if err := ensureRunnersPresent(w, errW, repoRoot, opts.assumeYes); err != nil {
return err
}
ensureRunnersPresent Function
// ensureRunnersPresent scaffolds the default runner set when a repo has none
// yet, so `tune` doubles as onboarding. It returns (true, nil) when it created
// the defaults, (false, nil) when runners already existed, and an error when
// the user declined or creation failed. Writing is gated on confirmation
// (interactive prompt, or the --yes flag for non-interactive runs).
func ensureRunnersPresent(w, errW io.Writer, repoRoot string, assumeYes bool) (created bool, err error) {
dir := filepath.Join(repoRoot, ".entire", "runners")
existing, _ := filepath.Glob(filepath.Join(dir, "*.json")) //nolint:errcheck // bad pattern only; treated as "none found"
if len(existing) > 0 {
return false, nil
}
defaults, err := runnerdefaults.Files()
if err != nil {
return false, fmt.Errorf("loading default runners: %w", err)
}
if !assumeYes {
if !interactive.CanPromptInteractively() {
return false, fmt.Errorf("no runner configs found under %s; re-run with --yes to create the default set (%d runners)", dir, len(defaults))
}
confirmed, err := confirmCreateRunners(len(defaults))
if err != nil {
return false, err
}
if !confirmed {
return false, errors.New("no runner configs created (declined)")
}
}
if err := os.MkdirAll(dir, 0o755); err != nil { //nolint:gosec // config dir, conventional perms
return false, fmt.Errorf("creating %s: %w", dir, err)
}
for _, f := range defaults {
dest := filepath.Join(dir, f.Name)
if err := os.WriteFile(dest, f.Data, 0o644); err != nil { //nolint:gosec // runner configs are repo-committed, world-readable config
return false, fmt.Errorf("writing %s: %w", dest, err)
}
fmt.Fprintf(w, "created %s\n", filepath.Join(".entire", "runners", f.Name))
}
fmt.Fprintf(errW, "Created %d default runner(s); tailoring them to this repo…\n", len(defaults))
return true, nil
}
confirmCreateRunners Function
func confirmCreateRunners(n int) (bool, error) {
// Implementation here...
}
runnersDir Function
// runnersDir is the canonical location of the trail runner configs for a repo.
func runnersDir(repoRoot string) string {
return filepath.Join(repoRoot, paths.EntireDir, "runners")
}