agents_doc_test.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package main
  2. import (
  3. "os"
  4. "strings"
  5. "testing"
  6. )
  7. // README.md is the single source of truth for documented behaviour; agents are
  8. // told to read it whole. AGENTS.md therefore carries discipline, not a second
  9. // copy of the reference. Duplicated reference is what went stale: the
  10. // `rgb <subcommand>` prefix survived in eleven lines of prose, and ledLayout was
  11. // promised in AGENTS.md while the code never read it.
  12. //
  13. // These tests fail if the duplication creeps back.
  14. func TestAgentsDocDoesNotDuplicateTheEffectCatalog(t *testing.T) {
  15. data, err := os.ReadFile("../../AGENTS.md")
  16. if err != nil {
  17. t.Fatalf("read AGENTS.md: %v", err)
  18. }
  19. body := string(data)
  20. // Effect names that exist only as catalog entries. The Discipline chapters
  21. // legitimately mention a few by name, so match a representative set of
  22. // obscure ones plus the literal range statements.
  23. for _, name := range []string{
  24. "jellybean_raindrops", "band_pinwheel_sat", "hue_pendulum",
  25. "starlight_dual_sat", "solid_reactive_multinexus", "riverflow",
  26. "multisplash",
  27. } {
  28. if strings.Contains(body, name) {
  29. t.Errorf("AGENTS.md lists the effect %q; the catalog comes live from `qmk-rgb-tool effect --list`", name)
  30. }
  31. }
  32. for _, rangeStmt := range []string{"ID 0–45 family", "ID 0-45 family", "IDs 0–45", "IDs 0-45"} {
  33. if strings.Contains(body, rangeStmt) {
  34. t.Errorf("AGENTS.md states %q; the per-zone catalog comes from `qmk-rgb-tool effect --list`", rangeStmt)
  35. }
  36. }
  37. }
  38. func TestAgentsDocDoesNotDuplicateTheCommandTable(t *testing.T) {
  39. data, err := os.ReadFile("../../AGENTS.md")
  40. if err != nil {
  41. t.Fatalf("read AGENTS.md: %v", err)
  42. }
  43. body := string(data)
  44. // A fenced block enumerating invocations is the duplicated CLI table.
  45. commands := []string{
  46. "qmk-rgb-tool effect breathing",
  47. "qmk-rgb-tool brightness <val>",
  48. "qmk-rgb-tool color <hex>",
  49. "qmk-rgb-tool speed <val>",
  50. "qmk-rgb-tool mode <index>",
  51. }
  52. for _, cmd := range commands {
  53. if strings.Contains(body, cmd) {
  54. t.Errorf("AGENTS.md lists the invocation %q; the command surface lives in README.md", cmd)
  55. }
  56. }
  57. }
  58. func TestAgentsDocTellsAgentsToReadTheReadme(t *testing.T) {
  59. data, err := os.ReadFile("../../AGENTS.md")
  60. if err != nil {
  61. t.Fatalf("read AGENTS.md: %v", err)
  62. }
  63. body := string(data)
  64. if !strings.Contains(body, "README.md") {
  65. t.Fatal("AGENTS.md never points at README.md, so nothing tells an agent to read the real reference")
  66. }
  67. // The instruction must be a directive, not a passing mention.
  68. lowered := strings.ToLower(body)
  69. directives := []string{"read it in full", "read it whole", "read it entirely"}
  70. found := false
  71. for _, directive := range directives {
  72. if strings.Contains(lowered, directive) {
  73. found = true
  74. break
  75. }
  76. }
  77. if !found {
  78. t.Errorf("AGENTS.md does not instruct the agent to read README.md in full; wanted one of %v", directives)
  79. }
  80. }