| 1 | package instruction |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestExtractHostChecksFromStructuredSection(t *testing.T) { |
| 9 | docs := []Document{{ |
| 10 | Path: "AGENTS.md", |
| 11 | Scope: ScopeProject, |
| 12 | Body: strings.Join([]string{ |
| 13 | "# Project rules", |
| 14 | "## Reasonix host checks", |
| 15 | "- verify: go test ./internal/...", |
| 16 | "* verify: git diff --check", |
| 17 | "- verify: go test ./internal/...", |
| 18 | "- note: ignored", |
| 19 | "## Other", |
| 20 | "- verify: ignored after section", |
| 21 | }, "\n"), |
| 22 | }} |
| 23 | |
| 24 | checks := ExtractHostChecks(docs) |
| 25 | if len(checks) != 2 { |
| 26 | t.Fatalf("checks len = %d, want 2: %#v", len(checks), checks) |
| 27 | } |
| 28 | if checks[0].Command != "go test ./internal/..." || checks[0].SourcePath != "AGENTS.md" || checks[0].Line != 3 { |
| 29 | t.Fatalf("first check = %#v", checks[0]) |
| 30 | } |
| 31 | if checks[1].Command != "git diff --check" || checks[1].SourcePath != "AGENTS.md" || checks[1].Line != 4 { |
| 32 | t.Fatalf("second check = %#v", checks[1]) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func TestExtractHostChecksIgnoresOrdinaryGuidance(t *testing.T) { |
| 37 | docs := []Document{{ |
| 38 | Path: "REASONIX.md", |
| 39 | Body: "Always run go test before committing.\n\n- verify: go test ./...", |
| 40 | }} |
| 41 | |
| 42 | if checks := ExtractHostChecks(docs); len(checks) != 0 { |
| 43 | t.Fatalf("ordinary guidance should not create hard checks: %#v", checks) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | func TestExtractHostChecksIsCaseInsensitive(t *testing.T) { |
| 48 | docs := []Document{{ |
| 49 | Path: "REASONIX.md", |
| 50 | Body: "## reasonix HOST checks\n- verify: go test ./...", |
| 51 | }} |
| 52 | |
| 53 | checks := ExtractHostChecks(docs) |
| 54 | if len(checks) != 1 || checks[0].Command != "go test ./..." { |
| 55 | t.Fatalf("case-insensitive heading not extracted: %#v", checks) |
| 56 | } |
| 57 | } |
| 58 |