Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/agent/autonomy/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type ExecutionEnvelope struct {
// Agent delegation — the user's own already-running, already-logged-in
// Chrome, reached through the gateway-owned broker) or BrowserEphemeral
// (a fresh, logged-out profile — explicit opt-down only). See
// docs/design/personal-agents.md "Browser broker trust boundary".
// docs/design/autonomous-agents.md "Browser broker trust boundary".
BrowserSession string
}

Expand Down
2 changes: 1 addition & 1 deletion internal/agent/autonomy/runner_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ func delegateMode(cs []ConsequenceClass) string {
// (Gmail, LinkedIn, an ATS, an internal dashboard) requires being signed in.
// "browser:ephemeral" is the explicit opt-down to a fresh, logged-out
// profile, for tasks that genuinely don't want the user's session (e.g.
// visiting a site anonymously). See docs/design/personal-agents.md "Browser
// visiting a site anonymously). See docs/design/autonomous-agents.md "Browser
// broker trust boundary".
func browserModeFor(toolsets []string) string {
for _, t := range toolsets {
Expand Down
63 changes: 34 additions & 29 deletions internal/guard/guard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,52 @@
package guard

import (
"bytes"
"os/exec"
"strings"
"testing"
)

const modulePrefix = "github.com/memcode-ai/memcode"

// deps returns the transitive import closure of pkg (including pkg itself).
// `go list` keeps the guard honest about TRANSITIVE deps, not just direct ones.
func deps(t *testing.T, pkg string) []string {
// goListLines runs `go list` and returns its STDOUT lines.
//
// Reading stdout only is load-bearing, not tidiness. `go list` writes advisory
// warnings to stderr while still exiting 0 with a complete, correct package
// list — most commonly "warning: ignoring symlink ..." when an untracked
// sibling directory (a node_modules tree from another branch, say) sits in the
// module root. CombinedOutput folds those warning lines into the results, each
// one then gets handed back to `go list` as if it were a package path, and THAT
// invocation fails. The original symptom looked like a desktop/node_modules
// problem; it was really this function laundering stderr into data.
//
// Genuine failures still fail: a non-zero exit is fatal, and so is an empty
// package list, which would otherwise let a guard pass vacuously.
func goListLines(t *testing.T, label string, args ...string) []string {
t.Helper()
out, err := exec.Command("go", "list", "-deps", pkg).CombinedOutput()
if err != nil {
t.Fatalf("go list -deps %s: %v\n%s", pkg, err, out)
cmd := exec.Command("go", args...)
var stdout, stderr bytes.Buffer
cmd.Stdout, cmd.Stderr = &stdout, &stderr
if err := cmd.Run(); err != nil {
t.Fatalf("%s: %v\n%s", label, err, stderr.String())
}
var ps []string
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
for _, line := range strings.Split(strings.TrimSpace(stdout.String()), "\n") {
if line = strings.TrimSpace(line); line != "" {
ps = append(ps, line)
}
}
return ps
}

// deps returns the transitive import closure of pkg (including pkg itself).
// `go list` keeps the guard honest about TRANSITIVE deps, not just direct ones.
func deps(t *testing.T, pkg string) []string {
t.Helper()
ps := goListLines(t, "go list -deps "+pkg, "list", "-deps", pkg)
return ps
}

// isStdlib: first path segment contains no dot.
func isStdlib(p string) bool {
seg := p
Expand Down Expand Up @@ -96,32 +118,15 @@ var vendorSDKs = map[string]string{

func directImports(t *testing.T, pkg string) []string {
t.Helper()
out, err := exec.Command("go", "list", "-f", `{{join .Imports "\n"}}`, pkg).CombinedOutput()
if err != nil {
t.Fatalf("go list %s: %v\n%s", pkg, err, out)
}
var ps []string
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
if line = strings.TrimSpace(line); line != "" {
ps = append(ps, line)
}
}
return ps
return goListLines(t, "go list "+pkg, "list", "-f", `{{join .Imports "\n"}}`, pkg)
}

func modulePackages(t *testing.T) []string {
t.Helper()
out, err := exec.Command("go", "list", modulePrefix+"/...").CombinedOutput()
if err != nil {
t.Fatalf("go list: %v\n%s", err, out)
pkgs := goListLines(t, "go list", "list", modulePrefix+"/...")
if len(pkgs) == 0 {
t.Fatal("go list returned no packages — every guard below would pass vacuously")
}
var ps []string
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
if line = strings.TrimSpace(line); line != "" {
ps = append(ps, line)
}
}
return ps
return pkgs
}

// TestVendorSDKsOnlyInTheirAdapters: a vendor client library imported outside
Expand Down
Loading