package main import ( "os" "path/filepath" "strings" "testing" ) func TestAccessDiscoveryUniqueAndDuplicatePaths(t *testing.T) { path := filepath.Join(t.TempDir(), "access.json") writeFixture(t, path, `{"workspaceRoots":[],"taskRules":[]}`) got, e := discoverAccessFile([]string{filepath.Join(t.TempDir(), "missing.json"), path, path}) if e != nil || got != path { t.Fatal(got, e) } } func TestAccessDiscoveryDoesNotGuessOrFallBackToWorkingDirectory(t *testing.T) { one := filepath.Join(t.TempDir(), "access.json") two := filepath.Join(t.TempDir(), "access.json") for _, path := range []string{one, two} { writeFixture(t, path, `{"workspaceRoots":[],"taskRules":[]}`) } if _, e := discoverAccessFile([]string{one, two}); e == nil || !strings.Contains(e.Error(), "--data") { t.Fatal("ambiguous services were silently selected", e) } if _, e := discoverAccessFile([]string{filepath.Join(t.TempDir(), "missing.json")}); e == nil || !strings.Contains(e.Error(), "当前目录") { t.Fatal("missing service not explained", e) } } func TestAccessCandidateInstalledAndPortableLayout(t *testing.T) { base := t.TempDir() exe := filepath.Join(base, "bin", "remotecompile.exe") candidates := accessCandidates(exe, "windows", filepath.Join(base, "programdata")) want := filepath.Join(base, "data", "access.json") found := false for _, path := range candidates { if path == want { found = true } } if !found { t.Fatal("bin layout not detected", candidates) } if candidates[0] != filepath.Join(base, "programdata", "VibeCodingRemoteCompilation", "data", "access.json") { t.Fatal(candidates) } linux := accessCandidates("/opt/remotecompile/bin/remotecompile", "linux", "") if linux[0] != "/var/lib/remotecompile/data/access.json" { t.Fatal(linux) } // Invalid configuration targets must not be treated as a missing installation. directory := t.TempDir() if _, e := discoverAccessFile([]string{directory}); e == nil { t.Fatal("directory accepted as policy file") } if e := os.Chmod(directory, 0700); e != nil { t.Fatal(e) } }