Files
multica/server/pkg/agent/worktree_capability_contract_test.go
T
Bohan Jiang 4040345e09 perf(ci): path-filter the backend jobs to skip irrelevant PRs (MUL-6389) (#7198)
Adds a `backend` path filter to the `changes` job and gates backend-tests, go-vulnerability-scan and windows-execenv on it, so a PR that never touches server/ no longer pays for a `go test -race` run, govulncheck and a Windows runner.

The filter is deliberately wider than `server/**`: four Go tests read three files outside the module (packages/core/runtimes/cli-version.ts, scripts/agent-cli-command-names.txt, scripts/go-test-with-agent-cli-guard.sh), and each must be listed or the PR that breaks such a contract is exactly the PR that skips the test.

Steps are gated rather than jobs, matching the existing frontend/sqlc-check pattern: the aggregate check reports a genuine green instead of staying pending, and still fails when a job goes missing for a reason other than the path filter.
2026-08-19 14:39:33 +08:00

45 lines
1.9 KiB
Go

package agent
import (
"os"
"path/filepath"
"regexp"
"testing"
"github.com/multica-ai/multica/server/pkg/protocol"
)
// What the two sides must agree on is the capability TOKEN, not a version.
//
// This replaces a test that pinned MinLocalWorktreeCLIVersion against a
// frontend twin. That twin is gone: since MUL-5707 nothing on either side gates
// on the version, and the frontend no longer even quotes it (#7113), so the old
// contract was pinning a number the UI does not show. The server constant stays
// because the 422 payload still carries it, but it has no counterpart to match.
//
// The token does have one, and it is load-bearing in a way a version never was:
// the daemon advertises this exact string, the server stores it, and the UI
// looks for it. A typo on either side silently disables worktree mode for
// everyone, with no error anywhere — which is precisely the failure this whole
// area keeps producing.
// This test reads OUT of the Go module, so CI's backend path filter has to
// list the frontend file explicitly (`backend` in .github/workflows/ci.yml).
// Without it, a PR that only edits the frontend token skips the very test
// that would catch the mismatch. Move or rename the path below and the
// filter must move with it.
func TestWorktreeCapabilityTokenMatchesFrontend(t *testing.T) {
path := filepath.Join("..", "..", "..", "packages", "core", "runtimes", "cli-version.ts")
src, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read %s: %v", path, err)
}
m := regexp.MustCompile(`LOCAL_WORKTREE_CAPABILITY\s*=\s*"([^"]+)"`).FindSubmatch(src)
if m == nil {
t.Fatal("LOCAL_WORKTREE_CAPABILITY not found in packages/core/runtimes/cli-version.ts")
}
if got := string(m[1]); got != protocol.DaemonCapabilityLocalWorktreeV1 {
t.Errorf("frontend looks for %q but the daemon advertises %q; worktree mode would be invisible to the UI",
got, protocol.DaemonCapabilityLocalWorktreeV1)
}
}