Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

85 lines
2.0 KiB
Go

package ohmypi
import (
"os"
"path/filepath"
"testing"
"github.com/zzet/gortex/internal/agents"
"github.com/zzet/gortex/internal/agents/agentstest"
)
func TestOhMyPiCreatesAndMerges(t *testing.T) {
env, _ := agentstest.NewEnv(t)
// Create sentinel .omp directory so Detect returns true.
if err := os.MkdirAll(filepath.Join(env.Root, ".omp"), 0o755); err != nil {
t.Fatal(err)
}
a := New()
// Apply should write the MCP config to .omp/mcp.json.
res, err := a.Apply(env, agents.ApplyOpts{})
if err != nil {
t.Fatalf("apply: %v", err)
}
if !res.Detected {
t.Fatal("expected Detected=true after creating .omp/")
}
if !res.Configured {
t.Fatal("expected Configured=true after apply")
}
agentstest.AssertCountsByAction(t, res, map[agents.ActionKind]int{agents.ActionCreate: 1})
mcp := agentstest.ReadJSON(t, filepath.Join(env.Root, ".omp", "mcp.json"))
servers := mcp["mcpServers"].(map[string]any)
if _, ok := servers["gortex"]; !ok {
t.Fatalf("gortex server missing: %v", servers)
}
// Assert idempotence on re-run.
agentstest.AssertIdempotent(t, a, env)
}
func TestOhMyPiGlobalIsNoOp(t *testing.T) {
env, _ := agentstest.NewEnv(t)
env.Mode = agents.ModeGlobal
// Even if .omp directory exists, Detect should return false in ModeGlobal.
if err := os.MkdirAll(filepath.Join(env.Root, ".omp"), 0o755); err != nil {
t.Fatal(err)
}
a := New()
detected, err := a.Detect(env)
if err != nil {
t.Fatalf("detect: %v", err)
}
if detected {
t.Fatal("expected Detect to return false in ModeGlobal")
}
// Plan should be empty.
plan, err := a.Plan(env)
if err != nil {
t.Fatalf("plan: %v", err)
}
if len(plan.Files) > 0 {
t.Fatalf("expected empty plan in ModeGlobal, got: %v", plan.Files)
}
// Apply should return early and not write files.
res, err := a.Apply(env, agents.ApplyOpts{})
if err != nil {
t.Fatalf("apply: %v", err)
}
if res.Configured {
t.Fatal("expected Configured=false in ModeGlobal")
}
if len(res.Files) > 0 {
t.Fatalf("expected no files touched in ModeGlobal, got: %v", res.Files)
}
}