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
86 lines
2.7 KiB
Go
86 lines
2.7 KiB
Go
package mcp
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/zzet/gortex/internal/lint"
|
|
)
|
|
|
|
func goLinterAvailable(t *testing.T) {
|
|
t.Helper()
|
|
ls := lint.NewRegistry().ForLanguage("go")
|
|
if len(ls) == 0 || !ls[0].Available() {
|
|
t.Skip("gofmt not on PATH")
|
|
}
|
|
}
|
|
|
|
func TestLintFileReportsGoSyntaxError(t *testing.T) {
|
|
goLinterAvailable(t)
|
|
srv, dir := setupTestServer(t)
|
|
broken := filepath.Join(dir, "broken.go")
|
|
require.NoError(t, os.WriteFile(broken, []byte("package main\n\nfunc main() {\n"), 0o644))
|
|
|
|
resp := callEditHandlerJSON(t, srv.handleLintFile, map[string]any{"path": broken})
|
|
require.Equal(t, false, resp["healthy"])
|
|
require.NotEmpty(t, resp["diagnostics"].([]any))
|
|
require.Contains(t, resp["linters_ran"], "gofmt")
|
|
}
|
|
|
|
func TestLintFileCleanGo(t *testing.T) {
|
|
goLinterAvailable(t)
|
|
srv, dir := setupTestServer(t)
|
|
clean := filepath.Join(dir, "clean.go")
|
|
require.NoError(t, os.WriteFile(clean, []byte("package main\n\nfunc f() {}\n"), 0o644))
|
|
|
|
resp := callEditHandlerJSON(t, srv.handleLintFile, map[string]any{"path": clean})
|
|
require.Equal(t, true, resp["healthy"])
|
|
require.Equal(t, "go", resp["language"])
|
|
}
|
|
|
|
func TestLintFileUnknownLanguageIsHealthy(t *testing.T) {
|
|
srv, dir := setupTestServer(t)
|
|
txt := filepath.Join(dir, "notes.txt")
|
|
require.NoError(t, os.WriteFile(txt, []byte("hello\n"), 0o644))
|
|
|
|
resp := callEditHandlerJSON(t, srv.handleLintFile, map[string]any{"path": txt})
|
|
require.Equal(t, true, resp["healthy"])
|
|
require.Equal(t, "", resp["language"])
|
|
}
|
|
|
|
func TestEditFileSurfacesSyntaxHealthOnBreak(t *testing.T) {
|
|
srv, dir := setupTestServer(t)
|
|
mainGo := filepath.Join(dir, "main.go")
|
|
|
|
// Drop helper's closing brace — the file no longer parses. Bypass the
|
|
// pre-write parse gate so the edit lands and the post-write syntax_health
|
|
// warning is the signal under test.
|
|
resp := callEditHandlerJSON(t, srv.handleEditFile, map[string]any{
|
|
"path": mainGo,
|
|
"old_string": "func helper() {}",
|
|
"new_string": "func helper() {",
|
|
"allow_parse_errors": true,
|
|
})
|
|
require.Equal(t, "applied", resp["status"])
|
|
health, ok := resp["syntax_health"].(map[string]any)
|
|
require.True(t, ok, "a broken edit must surface syntax_health")
|
|
require.Equal(t, false, health["healthy"])
|
|
}
|
|
|
|
func TestEditFileCleanEditOmitsSyntaxHealth(t *testing.T) {
|
|
srv, dir := setupTestServer(t)
|
|
mainGo := filepath.Join(dir, "main.go")
|
|
|
|
resp := callEditHandlerJSON(t, srv.handleEditFile, map[string]any{
|
|
"path": mainGo,
|
|
"old_string": "Port int",
|
|
"new_string": "Port int // ok",
|
|
})
|
|
require.Equal(t, "applied", resp["status"])
|
|
_, has := resp["syntax_health"]
|
|
require.False(t, has, "a clean edit must not surface syntax_health")
|
|
}
|