1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
package main
import (
"context"
"os"
"path/filepath"
"slices"
"testing"
"mm/internal/agentinit"
"mm/internal/config"
"mm/internal/detector"
"mm/internal/engine"
"github.com/firebase/genkit/go/genkit"
)
// `mm init` and `mm --init` both open the wizard; nothing else does.
func TestIsInit(t *testing.T) {
for arg, want := range map[string]bool{"init": true, "--init": true, "-init": true, "agent.yaml": false, "-p": false} {
if isInit(arg) != want {
t.Errorf("isInit(%q) = %v", arg, !want)
}
}
}
// `mm tui …` and `mm acp …` become their flags; a mode word anywhere else,
// or a path, is left alone.
func TestModeWordAsFlag(t *testing.T) {
for _, c := range []struct{ in, want []string }{
{[]string{"mm", "tui"}, []string{"mm", "-tui"}},
{[]string{"mm", "acp", "agent.yaml"}, []string{"mm", "-acp", "agent.yaml"}},
{[]string{"mm", "tui", "-config", "a.yaml"}, []string{"mm", "-tui", "-config", "a.yaml"}},
{[]string{"mm", "agent.yaml", "tui"}, []string{"mm", "agent.yaml", "tui"}},
{[]string{"mm", "./tui"}, []string{"mm", "./tui"}},
{[]string{"mm"}, []string{"mm"}},
} {
if got := modeWordAsFlag(c.in); !slices.Equal(got, c.want) {
t.Errorf("modeWordAsFlag(%q) = %q, want %q", c.in, got, c.want)
}
}
}
// A JSON agent written by `mm init` starts: structuredOutput forbids every
// tool, and the generated file turns them all off — main is where that rule
// is checked (config.StructuredOutputConflict), not config.Load.
func TestGeneratedJSONAgentDeclaresNoTool(t *testing.T) {
saved := config.Cfg
t.Cleanup(func() { config.Cfg = saved })
t.Setenv("MCP_GATEWAY_URL", "")
p, err := agentinit.LoadPresets()
if err != nil {
t.Fatal(err)
}
text := agentinit.Render(agentinit.Decide(p, agentinit.Choices{Provider: "dmr", Model: "ai/x", Usage: "json", Machine: "small", Name: "extract"}, agentinit.Facts{}))
path := filepath.Join(t.TempDir(), "agent.yaml")
if err := os.WriteFile(path, []byte(text), 0o644); err != nil {
t.Fatal(err)
}
if _, err := config.Load(path); err != nil {
t.Fatal(err)
}
config.Cfg.SkillsDir = t.TempDir()
set := assembleTools(&engine.Engine{G: genkit.Init(context.Background())}, detector.NewLoopDetector(10, 3), nil)
if err := config.StructuredOutputConflict(set.names); err != nil {
t.Errorf("the generated JSON agent would not start: %v", err)
}
}
|