TestShortcutExampleCommands checks the example commands embedded in every shortcut's Tips against the live command tree. A shortcut that defines no example is simply skipped. Because the examples and the command definitions live in the same Go code, this is a self-consistency check: any mismatch (a
(t *testing.T)
| 36 | // It runs over all shortcuts — no baseline, no diff — since a wrong example is |
| 37 | // always a defect, never acceptable "pre-existing drift". |
| 38 | func TestShortcutExampleCommands(t *testing.T) { |
| 39 | // Reproducibility: use the embedded API metadata (not a developer's stale |
| 40 | // ~/.lark-cli remote cache, which can miss commands) and an empty config |
| 41 | // dir so local strict mode / plugins / policy cannot reshape the tree. |
| 42 | // t.Setenv auto-restores after the test, so other cmd tests are unaffected. |
| 43 | t.Setenv("LARKSUITE_CLI_REMOTE_META", "off") |
| 44 | t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()) |
| 45 | |
| 46 | cat := buildCmdExampleCatalog() |
| 47 | |
| 48 | type located struct { |
| 49 | shortcut string |
| 50 | f finding |
| 51 | } |
| 52 | var findings []located |
| 53 | for _, sc := range shortcuts.AllShortcuts() { |
| 54 | var refs []ref |
| 55 | for _, tip := range sc.Tips { |
| 56 | refs = append(refs, parseRefs(tip)...) |
| 57 | } |
| 58 | label := strings.TrimSpace(sc.Service + " " + sc.Command) |
| 59 | for _, f := range checkRefs(cat, refs) { |
| 60 | findings = append(findings, located{shortcut: label, f: f}) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if len(findings) == 0 { |
| 65 | return |
| 66 | } |
| 67 | sort.Slice(findings, func(i, j int) bool { return findings[i].shortcut < findings[j].shortcut }) |
| 68 | for _, lf := range findings { |
| 69 | hint := "" |
| 70 | if lf.f.suggest != "" { |
| 71 | hint = " (did you mean " + lf.f.suggest + "?)" |
| 72 | } |
| 73 | if lf.f.kind == unknownFlag { |
| 74 | t.Errorf("shortcut %q example uses unknown flag %s on %q%s\n %s", |
| 75 | lf.shortcut, lf.f.flag, lf.f.path, hint, strings.TrimSpace(lf.f.raw)) |
| 76 | } else { |
| 77 | t.Errorf("shortcut %q example uses unknown command %q%s\n %s", |
| 78 | lf.shortcut, lf.f.path, hint, strings.TrimSpace(lf.f.raw)) |
| 79 | } |
| 80 | } |
| 81 | t.Fatalf("%d shortcut example command(s) don't match the real CLI — "+ |
| 82 | "fix the Example in the shortcut definition.", len(findings)) |
| 83 | } |
| 84 | |
| 85 | // buildCmdExampleCatalog walks the live cobra command tree and records every |
| 86 | // command path (minus the "lark-cli" root prefix) with its accepted flags and |
nothing calls this directly
no test coverage detected