diff --git a/docs/run-loop.md b/docs/run-loop.md index 6a372a3..d11c6ee 100644 --- a/docs/run-loop.md +++ b/docs/run-loop.md @@ -113,7 +113,7 @@ by `meitheal decisions`. | Kind | When | |---|---| | `escalate` | The coder stalled; the Workload failed (see below); the gate failed again after the feedback pass; the GPU node stayed busy; the loop lost track of the issue's run; the loop kept failing on the issue. | -| `needs-decision` | A task raised a concern (one the loop cannot read, or with no text, counts); the planner found a decision only a maintainer can make, its answer was unreadable, or its call failed; the issue carries the `--decision-label` label. | +| `needs-decision` | A task raised a concern (one the loop cannot read, or with no text, counts); the planner found a decision only a maintainer can make, its answer was unreadable, its call failed, or its intent failed the lint (it names a path the repository does not have, or its files list holds an existing file the intent never mentions); the issue carries the `--decision-label` label. | | `needs-split` | The planner judged the issue too big for one run. | A failed Workload's reason comes from its tasks' outcomes, judged by the diff --git a/pkg/cli/intents.go b/pkg/cli/intents.go index 73558ca..6094e60 100644 --- a/pkg/cli/intents.go +++ b/pkg/cli/intents.go @@ -209,6 +209,9 @@ type PlanConfig struct { BashTimeoutSeconds int // Progress, when set, gets one line per issue. Progress io.Writer + // ShowLint adds each planned intent's lint result to its progress line, + // and prints a failed lint's report before the park line. + ShowLint bool // MaintainerDecisions maps an issue to a decision its maintainer made // (a '/meitheal decide' answer). It reaches that issue's prompt as // settled, and the decision label no longer parks the issue: the human @@ -266,8 +269,8 @@ func planIssuesTo(ctx context.Context, f RunForge, call PlannerCaller, repo, rep if err := os.MkdirAll(outDir, 0o755); err != nil { return plannedQueue{}, fmt.Errorf("create --out: %w", err) } - p := planner{f: f, call: call, repo: repo, listing: listing, outDir: outDir, decisionsDir: decisionsDir, - cfg: cfg} + p := planner{f: f, call: call, repo: repo, listing: listing, paths: newRepoPaths(listing.Files), + outDir: outDir, decisionsDir: decisionsDir, cfg: cfg} q := Queue{Repo: repo} planned := map[int32][]string{} for _, issue := range issues { @@ -294,6 +297,7 @@ type planner struct { call PlannerCaller repo string listing repoListing + paths repoPaths outDir string decisionsDir string cfg PlanConfig @@ -357,6 +361,20 @@ func (p planner) planOne(ctx context.Context, issue int32) (*QueueItem, []string return nil, nil, p.park(issue, ParkNeedsSplit, reasonNeedsSplit, ev) } + // A planned intent that names a path the repository does not have, or + // whose header disagrees with its body, is parked before a coder run is + // spent on it. + lint := lintIntent(v, p.paths) + if !lint.ok() { + if p.cfg.ShowLint { + p.progress("issue %d: intent failed lint:\n%s", issue, indentLines(lint.report())) + } + return nil, nil, p.park(issue, ParkNeedsDecision, lint.reason(), map[string]string{ + "lint": lint.report(), + "intent": capString(v.Intent, unreadableEvidenceCap), + }) + } + intentPath := filepath.Join(p.outDir, fmt.Sprintf("%d.intent.md", issue)) if err := os.WriteFile(intentPath, []byte(v.Intent+"\n"), 0o644); err != nil { return nil, nil, fmt.Errorf("write intent for issue %d: %w", issue, err) @@ -368,7 +386,12 @@ func (p planner) planOne(ctx context.Context, issue int32) (*QueueItem, []string if p.forcesGPU(d.Labels, v.Files) { lane = "gpu" } - p.progress("issue %d: planned, lane %s, intent %s\n", issue, lane, intentPath) + if p.cfg.ShowLint { + p.progress("issue %d: planned, lane %s, intent %s, lint passed (%d repository paths checked)\n", + issue, lane, intentPath, lint.Checked) + } else { + p.progress("issue %d: planned, lane %s, intent %s\n", issue, lane, intentPath) + } return &QueueItem{Issue: issue, IntentPath: intentPath, Lane: lane}, v.Files, nil } @@ -472,6 +495,11 @@ func sharesFile(a, b []string) bool { return false } +// indentLines indents every line of a report under its progress line. +func indentLines(s string) string { + return " " + strings.ReplaceAll(strings.TrimSuffix(s, "\n"), "\n", "\n ") + "\n" +} + func capString(s string, n int) string { if len(s) <= n { return s @@ -692,6 +720,11 @@ plan, labelled --decision-label, or whose answer cannot be read is parked as a decision under --decisions-dir for 'meitheal decisions', and is never put in the queue. +A planned intent is linted against --repo-dir before it is queued, and parked +when it names a path under a tracked directory that the repository does not +have and its files list does not create, or when its files list holds an +existing file the intent never mentions. --hold prints each lint result. + Rules that belong to one repository go in --rules-file; they reach the planner verbatim, and override the general rules where the two conflict. --gpu-labels and --gpu-paths put an issue in the gpu lane. @@ -714,7 +747,7 @@ Example: } f := cmd.Flags() addPlannerFlags(f, o, " (required)") - f.BoolVar(&o.hold, "hold", false, "Write the intents and queue, then stop for review") + f.BoolVar(&o.hold, "hold", false, "Write the intents and queue, print each intent's lint result, then stop for review") f.StringVar(&o.decisionsDir, "decisions-dir", defaultDecisionsDir, "Where parked decisions are written") for _, name := range []string{"repo", "issues", "repo-dir", "planner-url"} { _ = cmd.MarkFlagRequired(name) @@ -786,6 +819,7 @@ func (o *intentsOptions) plannerSetup(progress io.Writer) (PlanConfig, PlannerCa TrustedCommenters: splitList(o.trustedCommenters), BashTimeoutSeconds: o.bashTimeout, Progress: progress, + ShowLint: o.hold, } if o.rulesFile != "" { b, err := os.ReadFile(o.rulesFile) @@ -821,6 +855,13 @@ func runIntents(ctx context.Context, w io.Writer, o *intentsOptions) error { if ctx == nil { ctx = context.Background() } + return planAndReport(ctx, w, o, forge, call, cfg, issues) +} + +// planAndReport plans the issues and prints the summary 'meitheal intents' +// ends with. +func planAndReport(ctx context.Context, w io.Writer, o *intentsOptions, forge RunForge, call PlannerCaller, + cfg PlanConfig, issues []int32) error { q, err := PlanIssues(ctx, forge, call, o.repo, o.repoDir, issues, o.out, o.decisionsDir, cfg) if err != nil { return err diff --git a/pkg/cli/intents_lint.go b/pkg/cli/intents_lint.go new file mode 100644 index 0000000..ae3f853 --- /dev/null +++ b/pkg/cli/intents_lint.go @@ -0,0 +1,227 @@ +/* +Copyright 2026. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cli + +import ( + "fmt" + "path" + "regexp" + "strings" +) + +// The intent lint checks a planned intent against the repository before it is +// queued: no model judgement, only the tracked file list. It is tuned for +// precision. A token is checked only when it is shaped like a path from the +// repository root under a top-level directory the repository tracks, so URLs, +// import paths, flags, globs and absolute paths pass unchecked, and a false +// park costs a human more than a missed one. + +// The lint check names. They reach the public park comment through the +// reason, so they are fixed strings and never model text. +const ( + lintUnknownPaths = "unknown paths" + lintUnmentionedFile = "files the intent never mentions" + reasonLintPrefix = "intent failed lint: " + // lintLinesCap bounds the offending intent lines kept per check. + lintLinesCap = 20 +) + +// repoPaths indexes a checkout's tracked files for the lint. +type repoPaths struct { + files map[string]bool + // dirs holds every directory a tracked file is under. + dirs map[string]bool + // top holds the top-level directories; only a token under one of them + // is checked. + top map[string]bool +} + +func newRepoPaths(files []string) repoPaths { + r := repoPaths{files: make(map[string]bool, len(files)), dirs: map[string]bool{}, top: map[string]bool{}} + for _, f := range files { + r.files[f] = true + if first, _, ok := strings.Cut(f, "/"); ok { + r.top[first] = true + } + for d := path.Dir(f); d != "." && !r.dirs[d]; d = path.Dir(d) { + r.dirs[d] = true + } + } + return r +} + +// lintFailure is one failed check and what failed it. +type lintFailure struct { + Check string + // Tokens are the offending paths, in the order the intent names them. + Tokens []string + // Lines are the intent lines that name an offending path. + Lines []string +} + +// intentLint is the result of linting one intent. +type intentLint struct { + // Checked counts the distinct repository paths the intent names. + Checked int + Failures []lintFailure +} + +func (l intentLint) ok() bool { return len(l.Failures) == 0 } + +// reason is the fixed park reason: the failed checks' names. +func (l intentLint) reason() string { + names := make([]string, 0, len(l.Failures)) + for _, f := range l.Failures { + names = append(names, f.Check) + } + return reasonLintPrefix + strings.Join(names, ", ") +} + +// report is the evidence a human reads: each failed check, its tokens and +// the lines that name them. +func (l intentLint) report() string { + var b strings.Builder + for _, f := range l.Failures { + fmt.Fprintf(&b, "%s: %s\n", f.Check, strings.Join(f.Tokens, ", ")) + for _, line := range f.Lines { + fmt.Fprintf(&b, " %s\n", line) + } + } + return b.String() +} + +// lintIntent runs the checks on a planned verdict: +// +// 1. unknown paths: every repository path the intent names is tracked (a +// file or a directory), or is in the header's files list (a file to +// create) or under a directory one of those creates. This also catches a +// file the intent says to create but the header leaves out. +// 2. files the intent never mentions: every header file that already exists +// is named in the intent, by its path or its base name. +func lintIntent(v PlanVerdict, repo repoPaths) intentLint { + header := map[string]bool{} + headerDirs := map[string]bool{} + for _, f := range v.Files { + header[f] = true + for d := path.Dir(f); d != "." && !headerDirs[d]; d = path.Dir(d) { + headerDirs[d] = true + } + } + var res intentLint + unknown := lintFailure{Check: lintUnknownPaths} + checked := map[string]bool{} + missing := map[string]bool{} + // words holds every word of the intent and its base name, for check 2. + words := map[string]bool{} + for _, line := range strings.Split(v.Intent, "\n") { + hit := false + for _, raw := range intentWordRE.FindAllString(line, -1) { + word := trimWord(raw) + if word == "" { + continue + } + words[word], words[path.Base(word)] = true, true + p, ok := repoPathToken(word, repo) + if !ok { + continue + } + if !checked[p] { + checked[p] = true + if !repo.known(p) && !header[p] && !headerDirs[p] { + missing[p] = true + unknown.Tokens = append(unknown.Tokens, p) + } + } + hit = hit || missing[p] + } + if hit { + unknown.Lines = appendLine(unknown.Lines, line) + } + } + res.Checked = len(checked) + if len(unknown.Tokens) > 0 { + res.Failures = append(res.Failures, unknown) + } + + unmentioned := lintFailure{Check: lintUnmentionedFile} + for _, f := range v.Files { + if !repo.files[f] || words[path.Base(f)] || strings.Contains(v.Intent, f) { + continue + } + unmentioned.Tokens = append(unmentioned.Tokens, f) + } + if len(unmentioned.Tokens) > 0 { + res.Failures = append(res.Failures, unmentioned) + } + return res +} + +func appendLine(lines []string, line string) []string { + if len(lines) >= lintLinesCap { + return lines + } + return append(lines, strings.TrimSpace(line)) +} + +// known reports whether p is a tracked file or directory, or a Go symbol in +// a tracked package directory ("pkg/cli.ParsePlanVerdict"). +func (r repoPaths) known(p string) bool { + if r.files[p] || r.dirs[p] { + return true + } + dir, base := path.Split(p) + if pkg, _, ok := strings.Cut(base, "."); ok && pkg != "" { + return r.dirs[dir+pkg] + } + return false +} + +// intentWordRE splits intent text into words: Markdown and shell punctuation +// end a word, and so does = (a --flag=value names its value as a word). +var intentWordRE = regexp.MustCompile("[^\\s`'\"()<>,;|=]+") + +// trimWord drops Markdown emphasis and sentence punctuation around a word. +func trimWord(w string) string { + w = strings.Trim(w, "*_~") + w = strings.TrimRight(w, ".:!?") + return w +} + +// repoPathToken returns the repository path a word names, if it is shaped +// like one: relative, under a tracked top-level directory, with no glob, +// variable or template characters. Everything from the first : or # is +// dropped (a :line, an #anchor, or a URL after its scheme), and so is a +// leading ./ or a trailing / or /... (a directory or a Go package pattern). +func repoPathToken(w string, repo repoPaths) (string, bool) { + w, _, _ = strings.Cut(w, "#") + w, _, _ = strings.Cut(w, ":") + w = strings.TrimPrefix(w, "./") + w = strings.TrimRight(w, "/.") + if !strings.Contains(w, "/") || strings.HasPrefix(w, "/") || strings.HasPrefix(w, "-") || + strings.ContainsAny(w, "*?[]{}$@~%\\") { + return "", false + } + first, _, _ := strings.Cut(w, "/") + if !repo.top[first] { + return "", false + } + p := path.Clean(w) + if p == "." || strings.HasPrefix(p, "../") { + return "", false + } + return p, true +} diff --git a/pkg/cli/intents_lint_test.go b/pkg/cli/intents_lint_test.go new file mode 100644 index 0000000..5ce9b05 --- /dev/null +++ b/pkg/cli/intents_lint_test.go @@ -0,0 +1,271 @@ +/* +Copyright 2026. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cli + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "reflect" + "strings" + "testing" + "time" +) + +// lintFixtureFiles is the fixture repository the lint tests check against. +func lintFixtureFiles() map[string]string { + return map[string]string{ + "pkg/cli/intents.go": "package cli\n", + "pkg/cli/intents_test.go": "package cli\n", + "docs/run-loop.md": "# Run loop\n", + "docs/images/flow.png": "png", + "cmd/meitheal/main.go": "package main\n", + ".github/workflows/ci.yml": "on: push\n", + "README.md": "# widgets\n", + "Makefile": "all:\n", + } +} + +func lintFixture(t *testing.T) repoPaths { + t.Helper() + listing, err := repoFiles(gitRepo(t, lintFixtureFiles())) + if err != nil { + t.Fatal(err) + } + return newRepoPaths(listing.Files) +} + +func TestLintIntent(t *testing.T) { + repo := lintFixture(t) + type failure struct { + check string + tokens []string + } + cases := []struct { + name string + files []string + intent string + want []failure + }{ + { + name: "existing paths in the forms an intent writes them", + files: []string{"pkg/cli/intents.go"}, + intent: "Edit `pkg/cli/intents.go` (see pkg/cli/intents.go:120 and ./pkg/cli/intents_test.go).\n" + + "Mirror **docs/run-loop.md**, [the template](docs/run-loop.md#the-template) and docs/images/.\n" + + "Run `go test ./pkg/cli/...` and `go build ./cmd/meitheal`. Call pkg/cli.ParsePlanVerdict.\n" + + "The workflow is .github/workflows/ci.yml.", + }, + { + name: "URLs, import paths, globs, flags and absolute paths are not checked", + files: []string{"pkg/cli/intents.go"}, + intent: "Edit pkg/cli/intents.go. See https://example.com/widgets/blob/main/docs/missing.md and\n" + + "import github.com/example/widgets/pkg/missing. Match docs/*.md and pkg/**/gone.go.\n" + + "Pass --rules-file=docs/run-loop.md -o /tmp/docs/out.md, $HOME/docs/x.md, ~/docs/y.md.\n" + + "Write the binary to bin/meitheal and the intents to .meitheal/intents/52.intent.md.", + }, + { + name: "a root-level name without a slash is not checked", + files: []string{"pkg/cli/intents.go"}, + intent: "Edit pkg/cli/intents.go and add a line to CHANGES.md and intents.go.", + }, + { + name: "a file to create is in the header, and so is the directory it creates", + files: []string{"docs/guides/intent-lint.md", "pkg/cli/intents.go"}, + intent: "Create docs/guides/intent-lint.md under docs/guides/, linked from pkg/cli/intents.go.", + }, + { + name: "a header file the intent names by its base name is mentioned", + files: []string{"pkg/cli/intents.go"}, + intent: "Open `intents.go` in the cli package and change planOne.", + }, + { + name: "a path that does not exist", + files: []string{"pkg/cli/intents.go"}, + intent: "Edit pkg/cli/intents.go. Use only the sources in **docs/planner-notes.md** and pkg/cli/intent.go,\n" + + "and pass --rules-file=docs/rules.md.", + want: []failure{{lintUnknownPaths, + []string{"docs/planner-notes.md", "pkg/cli/intent.go", "docs/rules.md"}}}, + }, + { + name: "a file the intent says to create but the header leaves out", + files: []string{"pkg/cli/intents.go"}, + intent: "Create `docs/intent-lint.md` and link it from pkg/cli/intents.go.", + want: []failure{{lintUnknownPaths, []string{"docs/intent-lint.md"}}}, + }, + { + name: "an existing header file the intent never mentions", + files: []string{"pkg/cli/intents.go", "pkg/cli/intents_test.go"}, + intent: "Edit pkg/cli/intents.go.", + want: []failure{{lintUnmentionedFile, []string{"pkg/cli/intents_test.go"}}}, + }, + { + name: "a new header file the intent never mentions is not this check's", + files: []string{"pkg/cli/intents.go", "pkg/cli/intents_lint.go"}, + intent: "Edit pkg/cli/intents.go.", + }, + { + name: "both checks fail", + files: []string{"README.md"}, + intent: "Rewrite docs/gone.md.", + want: []failure{ + {lintUnknownPaths, []string{"docs/gone.md"}}, + {lintUnmentionedFile, []string{"README.md"}}, + }, + }, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + got := lintIntent(PlanVerdict{Kind: VerdictPlanned, Files: tc.files, Intent: tc.intent}, repo) + var gotF []failure + for _, f := range got.Failures { + gotF = append(gotF, failure{f.Check, f.Tokens}) + } + if !reflect.DeepEqual(gotF, tc.want) { + t.Fatalf("failures = %+v, want %+v\nreport:\n%s", gotF, tc.want, got.report()) + } + if got.ok() != (len(tc.want) == 0) { + t.Fatalf("ok() = %v with failures %+v", got.ok(), gotF) + } + }) + } +} + +// The park reason names the failed checks only: it is posted on the public +// issue, so no token from the model's intent may reach it. +func TestLintIntent_ReasonIsFixedAndEvidenceNamesLines(t *testing.T) { + repo := lintFixture(t) + intent := "Step one: edit docs/secret-host.example.md.\nStep two: nothing.\n" + + "Step three: docs/secret-host.example.md again." + got := lintIntent(PlanVerdict{Files: []string{"README.md"}, Intent: intent}, repo) + if want := "intent failed lint: unknown paths, files the intent never mentions"; got.reason() != want { + t.Fatalf("reason = %q, want %q", got.reason(), want) + } + if strings.Contains(got.reason(), "secret-host") { + t.Fatal("reason carries model text") + } + want := "unknown paths: docs/secret-host.example.md\n" + + " Step one: edit docs/secret-host.example.md.\n" + + " Step three: docs/secret-host.example.md again.\n" + + "files the intent never mentions: README.md\n" + if got.report() != want { + t.Fatalf("report = %q, want %q", got.report(), want) + } + if got.Checked != 1 { + t.Fatalf("checked = %d, want 1 distinct path", got.Checked) + } +} + +// lintPlannerServer answers the planner call for each issue in answers, +// found by the prompt's issue header. +func lintPlannerServer(t *testing.T, answers map[int32]string) *httptest.Server { + t.Helper() + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + var req struct { + Messages []struct { + Content string `json:"content"` + } `json:"messages"` + } + if err := json.NewDecoder(r.Body).Decode(&req); err != nil || len(req.Messages) == 0 { + t.Errorf("decode request: %v", err) + return + } + answer := "VERDICT: needs-decision\nreason: unknown issue" + for n, a := range answers { + if strings.Contains(req.Messages[0].Content, fmt.Sprintf("Issue #%d.", n)) { + answer = a + } + } + choice := map[string]any{"message": map[string]string{"content": answer}, "finish_reason": "stop"} + _ = json.NewEncoder(w).Encode(map[string]any{"choices": []map[string]any{choice}}) + })) + t.Cleanup(srv.Close) + return srv +} + +// End to end through 'meitheal intents': an intent naming a file the +// repository does not have is parked as needs-decision, not queued, and +// with --hold the lint result is printed. +func TestIntents_HoldParksAnIntentThatFailsLint(t *testing.T) { + for _, hold := range []bool{true, false} { + t.Run(map[bool]string{true: "hold", false: "no hold"}[hold], func(t *testing.T) { + root := t.TempDir() + repoDir := gitRepo(t, lintFixtureFiles()) + srv := lintPlannerServer(t, map[int32]string{ + 52: "VERDICT: planned\n```yaml\nlane: cpu\nfiles:\n - pkg/cli/intents.go\n```\n" + + "Edit pkg/cli/intents.go, mirroring docs/planner-notes.md.\n", + 53: "VERDICT: planned\n```yaml\nlane: cpu\nfiles:\n - pkg/cli/intents.go\n```\n" + + "Edit pkg/cli/intents.go, mirroring docs/run-loop.md.\n", + }) + o := &intentsOptions{ + repo: planRepo, issues: "52,53", repoDir: repoDir, out: filepath.Join(root, "out"), + decisionsDir: filepath.Join(root, "decisions"), hold: hold, plannerURL: srv.URL, + plannerKwargs: defaultPlannerKwargs, plannerTimeout: time.Minute, maxTokens: 100, + bashTimeout: defaultBashTimeoutSeconds, decisionLabel: "decision", + } + var out bytes.Buffer + cfg, call, err := o.plannerSetup(&out) + if err != nil { + t.Fatal(err) + } + forge := newPlanForge(map[int32]IssueDetail{52: {Title: "t", Body: "b"}, 53: {Title: "t", Body: "b"}}) + if err := planAndReport(context.Background(), &out, o, forge, call, cfg, []int32{52, 53}); err != nil { + t.Fatalf("intents: %v", err) + } + + d := readDecision(t, o.decisionsDir, 52, ParkNeedsDecision) + assertPlannerPark(t, d, 52, ParkNeedsDecision, "intent failed lint: unknown paths") + if !strings.Contains(d.Evidence["lint"], "docs/planner-notes.md") || + !strings.Contains(d.Evidence["intent"], "mirroring docs/planner-notes.md") { + t.Fatalf("evidence = %v", d.Evidence) + } + if _, err := os.Stat(filepath.Join(o.out, "52.intent.md")); !os.IsNotExist(err) { + t.Fatalf("a parked intent was written: %v", err) + } + b, err := os.ReadFile(filepath.Join(o.out, queueFileName)) + if err != nil { + t.Fatal(err) + } + q, err := ParseQueue(b) + if err != nil { + t.Fatal(err) + } + if len(q.Items) != 1 || q.Items[0].Issue != 53 { + t.Fatalf("queue = %+v, want only issue 53", q.Items) + } + + text := out.String() + for _, want := range []string{ + "issue 52: intent failed lint:\n unknown paths: docs/planner-notes.md\n" + + " Edit pkg/cli/intents.go, mirroring docs/planner-notes.md.\n", + "lint passed (2 repository paths checked)", + } { + if strings.Contains(text, want) != hold { + t.Errorf("hold=%v: output contains %q = %v:\n%s", hold, want, !hold, text) + } + } + if !strings.Contains(text, "issue 52: parked needs-decision (intent failed lint: unknown paths)") || + !strings.Contains(text, "planned 1, parked 1") { + t.Errorf("output:\n%s", text) + } + }) + } +} diff --git a/pkg/cli/intents_test.go b/pkg/cli/intents_test.go index 4941c5c..fb6fb20 100644 --- a/pkg/cli/intents_test.go +++ b/pkg/cli/intents_test.go @@ -56,6 +56,17 @@ func plannedAnswer(lane string, files ...string) string { return b.String() } +// namingAnswer is plannedAnswer with a step naming each header file, so an +// intent whose header lists files other than src/lib.rs passes the lint. +func namingAnswer(lane string, files ...string) string { + var b strings.Builder + b.WriteString(plannedAnswer(lane, files...)) + for i, f := range files { + fmt.Fprintf(&b, "%d. Edit `%s`.\n", i+1, f) + } + return b.String() +} + func TestParsePlanVerdict(t *testing.T) { ok := []struct { name string @@ -481,7 +492,7 @@ func TestPlanIssues_LaneRule(t *testing.T) { e := newPlanEnv(t) e.cfg = tc.cfg f := newPlanForge(map[int32]IssueDetail{52: {Title: "t", Body: "b", Labels: tc.labels}}) - s := &stubPlanner{answers: map[int32]string{52: plannedAnswer(tc.lane, tc.files...)}} + s := &stubPlanner{answers: map[int32]string{52: namingAnswer(tc.lane, tc.files...)}} q := e.plan(t, f, s.call, 52) if len(q.Items) != 1 || q.Items[0].Lane != tc.want { t.Fatalf("queue = %+v, want lane %s", q.Items, tc.want) @@ -498,9 +509,9 @@ func TestPlanIssues_SharedFileOrders(t *testing.T) { 54: {Title: "t", Body: "b"}, }) s := &stubPlanner{answers: map[int32]string{ - 52: plannedAnswer("cpu", "crates/dluth-serve/src/server.rs", "src/lib.rs"), - 53: plannedAnswer("cpu", "README.md", "crates/dluth-serve/src/server.rs"), - 54: plannedAnswer("cpu", "src/other.rs"), + 52: namingAnswer("cpu", "crates/dluth-serve/src/server.rs", "src/lib.rs"), + 53: namingAnswer("cpu", "README.md", "crates/dluth-serve/src/server.rs"), + 54: namingAnswer("cpu", "src/other.rs"), }} q := e.plan(t, f, s.call, 52, 53, 54) if len(q.Items) != 3 { @@ -1189,7 +1200,7 @@ func TestPlanIssues_MaintainerDecisionReachesThePrompt(t *testing.T) { 53: {Title: "t", Body: "b"}, }) s := &stubPlanner{answers: map[int32]string{ - 52: plannedAnswer("cpu", "src/lib.rs"), 53: plannedAnswer("cpu", "README.md"), + 52: plannedAnswer("cpu", "src/lib.rs"), 53: namingAnswer("cpu", "README.md"), }} q := e.plan(t, f, s.call, 52, 53) if len(q.Items) != 2 {