|
6 | 6 |
|
7 | 7 | "github.com/spf13/cobra" |
8 | 8 |
|
| 9 | + "github.com/gate/gate-cli/internal/intelcmd" |
9 | 10 | "github.com/gate/gate-cli/internal/intelfacade" |
| 11 | + "github.com/gate/gate-cli/internal/mcpspec" |
10 | 12 | "github.com/gate/gate-cli/internal/toolschema" |
11 | 13 | ) |
12 | 14 |
|
@@ -65,3 +67,114 @@ func TestInfoGetCoinInfoHasStaticFlatFlagsWhenLoaderEmpty(t *testing.T) { |
65 | 67 | } |
66 | 68 | } |
67 | 69 | } |
| 70 | + |
| 71 | +func TestInfoIntelLeafToolAnnotation(t *testing.T) { |
| 72 | + for _, tool := range intelfacade.InfoToolBaseline { |
| 73 | + parts := strings.Split(tool, "_") |
| 74 | + if len(parts) < 3 { |
| 75 | + t.Fatalf("invalid tool %q", tool) |
| 76 | + } |
| 77 | + group := parts[1] |
| 78 | + leaf := strings.Join(parts[2:], "-") |
| 79 | + leafCmd, _, err := Cmd.Find([]string{group, leaf}) |
| 80 | + if err != nil || leafCmd == nil { |
| 81 | + t.Fatalf("find %s/%s for %q: %v", group, leaf, tool, err) |
| 82 | + } |
| 83 | + if got := leafCmd.Annotations[intelcmd.AnnotationIntelToolName]; got != tool { |
| 84 | + t.Fatalf("%s/%s: annotation %q want %q", group, leaf, got, tool) |
| 85 | + } |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +// TestInfoEachLeafRegistersAllBaselineFlags ensures every baseline JSON-schema property |
| 90 | +// is wired as a cobra flag on the matching leaf (static wiring; empty schema tools skip). |
| 91 | +func TestInfoEachLeafRegistersAllBaselineFlags(t *testing.T) { |
| 92 | + oldLoader := infoSchemaLoader |
| 93 | + infoSchemaLoader = func() map[string]toolschema.ToolSummary { return map[string]toolschema.ToolSummary{} } |
| 94 | + t.Cleanup(func() { infoSchemaLoader = oldLoader }) |
| 95 | + |
| 96 | + cmd := &cobra.Command{Use: "info"} |
| 97 | + orig := Cmd |
| 98 | + Cmd = cmd |
| 99 | + t.Cleanup(func() { Cmd = orig }) |
| 100 | + buildInfoAliases() |
| 101 | + |
| 102 | + for _, tool := range intelfacade.InfoToolBaseline { |
| 103 | + parts := strings.Split(tool, "_") |
| 104 | + group := parts[1] |
| 105 | + leaf := strings.Join(parts[2:], "-") |
| 106 | + leafCmd, _, err := cmd.Find([]string{group, leaf}) |
| 107 | + if err != nil || leafCmd == nil { |
| 108 | + t.Fatalf("find %s/%s for %q: %v", group, leaf, tool, err) |
| 109 | + } |
| 110 | + schema := intelfacade.InfoBaselineInputSchema(tool) |
| 111 | + if schema == nil { |
| 112 | + t.Fatalf("nil baseline schema for %q", tool) |
| 113 | + } |
| 114 | + props, ok := schema["properties"].(map[string]interface{}) |
| 115 | + if !ok { |
| 116 | + t.Fatalf("%q: missing properties", tool) |
| 117 | + } |
| 118 | + for k := range props { |
| 119 | + flagName := strings.ReplaceAll(k, "_", "-") |
| 120 | + if leafCmd.Flags().Lookup(flagName) == nil { |
| 121 | + t.Errorf("tool %q missing flag --%s (baseline key %q)", tool, flagName, k) |
| 122 | + } |
| 123 | + } |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +// TestInfoEachLeafRegistersAllSpecFields ensures embedded MCP spec fields are present as flags |
| 128 | +// (belt-and-suspenders on top of intelfacade.TestInfoBaselineCoversSpecInputFields). |
| 129 | +func TestInfoEachLeafRegistersAllSpecFields(t *testing.T) { |
| 130 | + doc, err := mcpspec.InfoInputsLogic() |
| 131 | + if err != nil { |
| 132 | + t.Fatal(err) |
| 133 | + } |
| 134 | + root := doc.(map[string]interface{}) |
| 135 | + raw := root["tools"].([]interface{}) |
| 136 | + specByTool := make(map[string][]string, len(raw)) |
| 137 | + for _, item := range raw { |
| 138 | + tm := item.(map[string]interface{}) |
| 139 | + name, _ := tm["tool_name"].(string) |
| 140 | + if name == "" { |
| 141 | + continue |
| 142 | + } |
| 143 | + fields, _ := tm["fields"].([]interface{}) |
| 144 | + for _, f := range fields { |
| 145 | + fm := f.(map[string]interface{}) |
| 146 | + if n, _ := fm["name"].(string); n != "" { |
| 147 | + specByTool[name] = append(specByTool[name], n) |
| 148 | + } |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + oldLoader := infoSchemaLoader |
| 153 | + infoSchemaLoader = func() map[string]toolschema.ToolSummary { return map[string]toolschema.ToolSummary{} } |
| 154 | + t.Cleanup(func() { infoSchemaLoader = oldLoader }) |
| 155 | + cmd := &cobra.Command{Use: "info"} |
| 156 | + orig := Cmd |
| 157 | + Cmd = cmd |
| 158 | + t.Cleanup(func() { Cmd = orig }) |
| 159 | + buildInfoAliases() |
| 160 | + |
| 161 | + for _, tool := range intelfacade.InfoToolBaseline { |
| 162 | + names := specByTool[tool] |
| 163 | + if len(names) == 0 { |
| 164 | + continue |
| 165 | + } |
| 166 | + parts := strings.Split(tool, "_") |
| 167 | + group := parts[1] |
| 168 | + leaf := strings.Join(parts[2:], "-") |
| 169 | + leafCmd, _, err := cmd.Find([]string{group, leaf}) |
| 170 | + if err != nil || leafCmd == nil { |
| 171 | + t.Fatalf("find %s/%s for %q: %v", group, leaf, tool, err) |
| 172 | + } |
| 173 | + for _, field := range names { |
| 174 | + flagName := strings.ReplaceAll(field, "_", "-") |
| 175 | + if leafCmd.Flags().Lookup(flagName) == nil { |
| 176 | + t.Errorf("tool %q missing flag for spec field %q (--%s)", tool, field, flagName) |
| 177 | + } |
| 178 | + } |
| 179 | + } |
| 180 | +} |
0 commit comments