mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-04 05:33:55 +08:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f544185cf |
@@ -6,6 +6,7 @@ All notable changes to this project are documented in this file. The format is b
|
||||
|
||||
### Security
|
||||
|
||||
- **Agent sessions no longer offer Norma's background-task tools.** Norma adds `Monitor`, `TaskOutput`, `TaskStop` and `TaskList` to every session that does not opt out, and only the connection test and the goal decomposer opted out. `Monitor` starts a shell command in the panel process, not through the sandbox that `Bash` uses, so in `ARTEX_SANDBOX=required` mode a worker, planner, chat or main-agent model could run commands in the panel container, outside the task's worker, and read or write other tasks' workspaces and transcripts. Every agent session is now built through one constructor. It turns these tools off while the sandbox is required, and always for a session that has neither `Bash` nor the interactive shell, so an orchestration agent cannot gain a shell through `Monitor`. Sessions that do have `Bash` or `shell_*` keep them when the sandbox is off: their background runs, PTY sessions and the pause kill switch depend on the same task manager. The constructor also turns a nil tool list into an empty one, because Norma reads nil as "use my own default tools" and installs its unconfined `Bash` and file tools; the tool catalogue resolver also returns an empty list instead of nil when the tools table cannot be read, the case of the Auto chat agent, whose base list is empty.
|
||||
- **The target gate honors operator-approved egress grants.** The gate compared every target with pins only, while the sandbox proxy allowed every port of an operator-approved CIDR grant: a host already inside a granted task or company scope still raised per-port and bare-host approval prompts (pins match `host:port`, and a request naming the host without a port is covered only by a port-0 pin). `CheckTargets` now also consults the grants the operator approved for the task (its approved, unexpanded `task_scope` rows and the entries frozen into `task_scope_egress` by approved company grants, normalized as the proxy allowlist is): a domain matching a granted domain, an address inside a granted CIDR, or a range fully inside one passes as covered by `scope_grant`, recorded once per process and target key as a system-decided allowed row with the target outcome `scope_grant`. Pins, stored exemptions, block rules and human approvals are unchanged: anything outside a grant is decided as before, and task allow rules play no role, as everywhere in the gate. Related to #830, the mirror gap on the network side.
|
||||
- **Chat-spawned tasks inherit fully operator-approved companies (#830).** Migration `0025_company_scope_approved.sql` made company scope an explicit operator decision, but `spawn_task` still stamped the whole company link `approved_by_operator=false`, so a chat-spawned task started with an empty egress allowlist and every connection was denied until an operator approved scope again per task (the trap #833 warns about). `CreateTaskWithOptions` now checks each LLM-selected company: one whose scope inventory exists and is entirely operator-approved and to which the calling task itself holds an operator-approved link carries standing consent, so its task link is inserted approved (a spawn with no task caller - chat session or direct API - inherits nothing, per review on #841) and its grant frozen into `task_scope_egress`, exactly as an operator selection does; a company holding any agent-written (unapproved) row, and one with no scope rows, stay coverage-only, so `add_company_scope`, the ScopeSentry sync and invented ids still grant nothing without a fresh operator decision. Provenance is preserved: `source` stays `agent` and the approval column records the inherited consent row by row. Related: #830, #833.
|
||||
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ import (
|
||||
// contiguous run is coalesced into a single record so the trace shows whole
|
||||
// messages, not dozens of fragments.
|
||||
func captureRun(ctx context.Context, opts agentcore.Options, input string, emit func(db.Activity)) (string, harness.TerminalReason, error) {
|
||||
s := agentcore.NewSession(opts)
|
||||
s := newSession(opts)
|
||||
defer s.Close() // release the session's background-task manager (temp dir + processes)
|
||||
return captureRunSession(ctx, s, input, emit)
|
||||
}
|
||||
|
||||
+1
-1
@@ -276,7 +276,7 @@ func (c *ChatAgent) Chat(ctx context.Context, agentKey, sessionID, message strin
|
||||
// experimental feature: when enabled, noa takes over context compression (archive centralized under <workDir>/noa/<SessionID>, persistent).
|
||||
enableNoa(&opts, c.noaEnabledFn, c.workDir, "chat-"+sessionID, noaWarn("chat-"+sessionID))
|
||||
ctx = attachSideCapture(ctx, &opts)
|
||||
s := agentcore.NewSession(opts)
|
||||
s := newSession(opts)
|
||||
defer s.Close()
|
||||
// reload prior conversation so the agent has context across turns (each Chat is
|
||||
// a fresh session). First turn: no file yet → Resume loads nothing and proceeds.
|
||||
|
||||
+1
-1
@@ -181,7 +181,7 @@ func DecomposeGoalsWithProvider(ctx context.Context, prov llm.Provider, dataDir,
|
||||
emit(r)
|
||||
}
|
||||
}
|
||||
session := agentcore.NewSession(agentcore.Options{
|
||||
session := newSession(agentcore.Options{
|
||||
Provider: prov,
|
||||
SystemPrompt: []string{sys},
|
||||
DynamicBoundary: 1, // the whole static system prompt gets a cache breakpoint across the turns
|
||||
|
||||
+1
-1
@@ -193,7 +193,7 @@ func (m *MainAgent) Chat(ctx context.Context, taskID int64, mainSeg int, as *db.
|
||||
}
|
||||
enableNoa(&opts, m.noaEnabledFn, m.workDir, noaSession, noaWarn(noaSession))
|
||||
ctx = attachSideCapture(ctx, &opts)
|
||||
s := agentcore.NewSession(opts)
|
||||
s := newSession(opts)
|
||||
defer s.Close()
|
||||
// reload the prior conversation from the transcript so the agent has context
|
||||
// across turns (each Chat is a fresh session; without this it can't see earlier
|
||||
|
||||
@@ -2,10 +2,44 @@ package agent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/Autumn-27/norma/agentcore"
|
||||
actool "github.com/Autumn-27/norma/tool"
|
||||
)
|
||||
|
||||
// newSession builds every Norma session ARTEX runs. Norma's background-task
|
||||
// tools (Monitor, TaskOutput, TaskStop, TaskList) start commands in the panel
|
||||
// process, outside the sandbox that Bash goes through, so no session gets them
|
||||
// while the sandbox is required. With the sandbox off, a session that has no
|
||||
// shell tool still must not gain one through Monitor: orchestration agents get
|
||||
// no background tools at all. A session that does have Bash or the interactive
|
||||
// shell keeps the task manager when the sandbox is off: Bash backgrounds long
|
||||
// commands, the pause kill switch ends a command's whole process group, and the
|
||||
// interactive shell keeps its PTY sessions on the same manager.
|
||||
// A nil tool list makes Norma install its own unconfined file and shell tools,
|
||||
// so nil becomes an empty list.
|
||||
func newSession(opts agentcore.Options) *agentcore.Session {
|
||||
if opts.Tools == nil {
|
||||
opts.Tools = []actool.CoreTool{}
|
||||
}
|
||||
if SandboxRequired() || !hasShellTool(opts.Tools) {
|
||||
opts.DisableBackgroundTasks = true
|
||||
}
|
||||
return agentcore.NewSession(opts)
|
||||
}
|
||||
|
||||
// hasShellTool reports whether the session offers Bash or the interactive shell
|
||||
// (shell_open and its companions), the session tools that need the task manager.
|
||||
func hasShellTool(tools []actool.CoreTool) bool {
|
||||
for _, tool := range tools {
|
||||
if name := tool.Name(); name == "Bash" || strings.HasPrefix(name, "shell_") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// resumeSession reloads the persisted conversation of session id into s. Norma's
|
||||
// transcript.Store.Load treats a missing file as a fresh session (no records, no
|
||||
// error); any other failure, such as a corrupt line or an unreadable path, is
|
||||
|
||||
@@ -0,0 +1,317 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Autumn-27/artex/db"
|
||||
"github.com/Autumn-27/artex/sandbox"
|
||||
"github.com/Autumn-27/norma/agentcore"
|
||||
actool "github.com/Autumn-27/norma/tool"
|
||||
)
|
||||
|
||||
// Norma's background-task tools run commands in the panel process, outside
|
||||
// the sandbox. While the sandbox is required, no production session may offer
|
||||
// them to the model.
|
||||
var backgroundTaskTools = []string{"Monitor", "TaskOutput", "TaskStop", "TaskList"}
|
||||
|
||||
// requireSandboxForTest puts the process in ARTEX_SANDBOX=required mode, with
|
||||
// no tool augmentation or catalogue, for the duration of the test.
|
||||
func requireSandboxForTest(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Setenv("ARTEX_SANDBOX", sandbox.ModeRequired)
|
||||
t.Setenv("AGENT_CORE_DISABLE_BACKGROUND_TASKS", "")
|
||||
oldEx, oldAug, oldRes := CurrentSandboxExecutor(), ToolAugment(), ToolResolve()
|
||||
t.Cleanup(func() {
|
||||
SetSandboxExecutor(oldEx)
|
||||
SetToolAugment(oldAug)
|
||||
SetToolResolve(oldRes)
|
||||
})
|
||||
SetSandboxExecutor(&SandboxExecutor{Mode: sandbox.ModeRequired})
|
||||
SetToolAugment(nil)
|
||||
SetToolResolve(nil)
|
||||
if !SandboxRequired() {
|
||||
t.Fatal("sandbox is not in required mode")
|
||||
}
|
||||
}
|
||||
|
||||
// requireSandboxOffForTest puts the process in ARTEX_SANDBOX=off mode, with no
|
||||
// tool augmentation or catalogue, for the duration of the test.
|
||||
func requireSandboxOffForTest(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Setenv("ARTEX_SANDBOX", sandbox.ModeOff)
|
||||
t.Setenv("AGENT_CORE_DISABLE_BACKGROUND_TASKS", "")
|
||||
oldEx, oldAug, oldRes := CurrentSandboxExecutor(), ToolAugment(), ToolResolve()
|
||||
t.Cleanup(func() {
|
||||
SetSandboxExecutor(oldEx)
|
||||
SetToolAugment(oldAug)
|
||||
SetToolResolve(oldRes)
|
||||
})
|
||||
SetSandboxExecutor(nil)
|
||||
SetToolAugment(nil)
|
||||
SetToolResolve(nil)
|
||||
if SandboxRequired() {
|
||||
t.Fatal("sandbox is still required")
|
||||
}
|
||||
}
|
||||
|
||||
// offeredTools returns the tool names of the first model request, failing the
|
||||
// test when the session never called the model.
|
||||
func offeredTools(t *testing.T, p *captureToolNamesProvider) map[string]bool {
|
||||
t.Helper()
|
||||
p.mu.Lock()
|
||||
called := p.names != nil
|
||||
p.mu.Unlock()
|
||||
if !called {
|
||||
t.Fatal("the session never sent a model request")
|
||||
}
|
||||
return p.seen()
|
||||
}
|
||||
|
||||
func assertNoBackgroundTaskTools(t *testing.T, p *captureToolNamesProvider) {
|
||||
t.Helper()
|
||||
got := offeredTools(t, p)
|
||||
for _, name := range backgroundTaskTools {
|
||||
if got[name] {
|
||||
t.Errorf("model was offered %s (offered: %v)", name, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProductionSessionsOfferNoBackgroundTaskTools(t *testing.T) {
|
||||
requireSandboxForTest(t)
|
||||
workDir := t.TempDir()
|
||||
|
||||
t.Run("chat execution agent", func(t *testing.T) {
|
||||
prov := &captureToolNamesProvider{}
|
||||
c := NewChatAgent(prov, "test-model", workDir, nil, 100000)
|
||||
if _, err := c.Chat(t.Context(), "pentest", "conv-bgtools-pentest", "hello", 1, 0, false, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertNoBackgroundTaskTools(t, prov)
|
||||
})
|
||||
|
||||
// Auto's base list is nil. Norma reads a nil list as "install my own
|
||||
// unconfined file and shell tools", so none of those may appear either.
|
||||
t.Run("chat orchestration agent", func(t *testing.T) {
|
||||
// With finding-traffic binding on, the finding workflow keeps Auto's list
|
||||
// nil (with it off, it copies the list into a new empty slice), so this is
|
||||
// the setting under which a nil list reaches the session.
|
||||
oldBinding := FindingTrafficBindingEnabled()
|
||||
t.Cleanup(func() { SetFindingTrafficBindingEnabled(oldBinding) })
|
||||
SetFindingTrafficBindingEnabled(func() bool { return true })
|
||||
prov := &captureToolNamesProvider{}
|
||||
c := NewChatAgent(prov, "test-model", workDir, nil, 100000)
|
||||
if _, err := c.Chat(t.Context(), "auto", "conv-bgtools-auto", "hello", 1, 0, false, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertNoBackgroundTaskTools(t, prov)
|
||||
got := prov.seen()
|
||||
for _, name := range []string{"Bash", "Read", "Write", "Edit", "MultiEdit", "LS", "Glob", "Grep"} {
|
||||
if got[name] {
|
||||
t.Errorf("auto was offered Norma's default tool %s", name)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("goal decomposition", func(t *testing.T) {
|
||||
prov := &captureToolNamesProvider{}
|
||||
// The fixture answers in plain text, so the decomposer reports a contract
|
||||
// error. Only the offered tools matter here.
|
||||
_, _ = DecomposeGoals(t.Context(), prov, t.TempDir(), "Audit auth on lab.local", "", nil, guardTaskStore(t), 0, nil)
|
||||
assertNoBackgroundTaskTools(t, prov)
|
||||
})
|
||||
|
||||
t.Run("planner", func(t *testing.T) {
|
||||
d := testDB(t)
|
||||
t.Cleanup(func() { _ = d.Close() })
|
||||
task, err := d.CreateTaskWithOptions("", "", db.TaskCreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = d.DeleteTask(task.ID) })
|
||||
ts := d.Exploration(task.ExplorationID)
|
||||
if _, err := ts.AddNode(db.KindGoal, map[string]any{"text": "Audit /admin"}, 0, "open", "goals", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ts.AddIntent(map[string]any{"summary": "Audit the fixture admin endpoint"}, 0, nil, "fixture"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
prov := &captureToolNamesProvider{}
|
||||
p := NewPlanner(prov, "test-model", workDir, nil, 0, 2)
|
||||
_, _, _ = p.Plan(t.Context(), task.ID, nil, ts, "", nil, nil, nil)
|
||||
assertNoBackgroundTaskTools(t, prov)
|
||||
})
|
||||
|
||||
t.Run("main agent", func(t *testing.T) {
|
||||
d := testDB(t)
|
||||
t.Cleanup(func() { _ = d.Close() })
|
||||
expID, err := d.CreateExploration("bgtools main agent", "no background-task tools")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _, _ = d.Exec(`DELETE FROM explorations WHERE id=$1`, expID) })
|
||||
prov := &captureToolNamesProvider{}
|
||||
m := NewMainAgent(prov, "test-model", workDir, nil, 0, 1)
|
||||
if _, err := m.Chat(t.Context(), expID, 0, nil, d.Exploration(expID), "verify goal", "status?", nil, nil, nil, nil, nil, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertNoBackgroundTaskTools(t, prov)
|
||||
})
|
||||
|
||||
t.Run("worker", func(t *testing.T) {
|
||||
d := testDB(t)
|
||||
t.Cleanup(func() { _ = d.Close() })
|
||||
expID, err := d.CreateExploration("bgtools worker", "no background-task tools")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _, _ = d.Exec(`DELETE FROM explorations WHERE id=$1`, expID) })
|
||||
es := d.Exploration(expID)
|
||||
payload := map[string]any{"summary": "probe"}
|
||||
intentID, err := es.AddNode("intent", payload, 0, "running", "planner", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
raw, _ := json.Marshal(payload)
|
||||
prov := &captureToolNamesProvider{}
|
||||
w := NewWorker(prov, "test-model", workDir, nil, 0, 1)
|
||||
if _, _, err := w.Execute(t.Context(), "work#1", expID, nil, es, &db.Node{ID: intentID, Payload: raw}, nil, nil, nil, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertNoBackgroundTaskTools(t, prov)
|
||||
})
|
||||
|
||||
// captureRun is the constructor the planner uses. Check it on its own too,
|
||||
// with a nil tool list: Norma reads nil as "install my own unconfined file
|
||||
// and shell tools", so the model must be offered no tools at all.
|
||||
t.Run("captureRun", func(t *testing.T) {
|
||||
prov := &captureToolNamesProvider{}
|
||||
if _, _, err := captureRun(t.Context(), agentcore.Options{Provider: prov, MaxTurns: 1}, "hello", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := offeredTools(t, prov); len(got) != 0 {
|
||||
t.Fatalf("nil tool list offered %v, want no tools", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Without the sandbox, a session that has no Bash must still not gain a shell
|
||||
// through Norma's background-task tools. The planner is excluded because it
|
||||
// does have Bash, and then the task manager is needed for pause and background
|
||||
// runs.
|
||||
func TestSessionsWithoutBashOfferNoBackgroundTaskTools(t *testing.T) {
|
||||
requireSandboxOffForTest(t)
|
||||
workDir := t.TempDir()
|
||||
|
||||
t.Run("chat orchestration agent", func(t *testing.T) {
|
||||
// With finding-traffic binding on, the finding workflow keeps Auto's list
|
||||
// nil (with it off, it copies the list into a new empty slice), so this is
|
||||
// the setting under which a nil list reaches the session.
|
||||
oldBinding := FindingTrafficBindingEnabled()
|
||||
t.Cleanup(func() { SetFindingTrafficBindingEnabled(oldBinding) })
|
||||
SetFindingTrafficBindingEnabled(func() bool { return true })
|
||||
prov := &captureToolNamesProvider{}
|
||||
c := NewChatAgent(prov, "test-model", workDir, nil, 100000)
|
||||
if _, err := c.Chat(t.Context(), "auto", "conv-bgtools-auto-off", "hello", 1, 0, false, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertNoBackgroundTaskTools(t, prov)
|
||||
got := prov.seen()
|
||||
for _, name := range []string{"Bash", "Read", "Write", "Edit", "MultiEdit", "LS", "Glob", "Grep"} {
|
||||
if got[name] {
|
||||
t.Errorf("auto was offered Norma's default tool %s", name)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("main agent", func(t *testing.T) {
|
||||
d := testDB(t)
|
||||
t.Cleanup(func() { _ = d.Close() })
|
||||
expID, err := d.CreateExploration("bgtools main agent off", "no background-task tools")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _, _ = d.Exec(`DELETE FROM explorations WHERE id=$1`, expID) })
|
||||
prov := &captureToolNamesProvider{}
|
||||
m := NewMainAgent(prov, "test-model", workDir, nil, 0, 1)
|
||||
if _, err := m.Chat(t.Context(), expID, 0, nil, d.Exploration(expID), "verify goal", "status?", nil, nil, nil, nil, nil, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertNoBackgroundTaskTools(t, prov)
|
||||
})
|
||||
}
|
||||
|
||||
func TestHasShellTool(t *testing.T) {
|
||||
if hasShellTool(nil) {
|
||||
t.Fatal("nil tool list reported a shell tool")
|
||||
}
|
||||
if hasShellTool([]actool.CoreTool{dummyTool("Read"), dummyTool("Grep")}) {
|
||||
t.Fatal("a session without a shell tool reported one")
|
||||
}
|
||||
if !hasShellTool([]actool.CoreTool{dummyTool("Read"), dummyTool("Bash")}) {
|
||||
t.Fatal("a session with Bash was not detected")
|
||||
}
|
||||
if !hasShellTool(append([]actool.CoreTool{dummyTool("Read")}, actool.ShellSessionTools()...)) {
|
||||
t.Fatal("a session with the interactive shell was not detected")
|
||||
}
|
||||
}
|
||||
|
||||
// With the sandbox off, an agent whose interactive shell is on keeps the task
|
||||
// manager its PTY sessions live on, even when Bash is not bound to it.
|
||||
func TestInteractiveShellWithoutBashKeepsTaskManager(t *testing.T) {
|
||||
requireSandboxOffForTest(t)
|
||||
prov := &captureToolNamesProvider{}
|
||||
s := newSession(agentcore.Options{Provider: prov, Tools: actool.ShellSessionTools(), NonStreaming: true, WorkingDir: t.TempDir()})
|
||||
defer s.Close()
|
||||
for _, err := range s.Prompt(t.Context(), "hello") {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if got := offeredTools(t, prov); !got["TaskList"] {
|
||||
t.Fatalf("a session with shell_open has no task manager (offered: %v)", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestNoDirectNormaSessions keeps every session behind newSession: a direct
|
||||
// agentcore.NewSession call would bring the background-task tools back. It covers
|
||||
// the server and command packages too, and keeps agentcore.Run to the connection
|
||||
// test, which sets the flag itself.
|
||||
func TestNoDirectNormaSessions(t *testing.T) {
|
||||
for _, root := range []string{".", "../server", "../cmd"} {
|
||||
err := filepath.WalkDir(root, func(path string, entry fs.DirEntry, walkErr error) error {
|
||||
if walkErr != nil {
|
||||
return walkErr
|
||||
}
|
||||
if entry.IsDir() {
|
||||
return nil
|
||||
}
|
||||
if !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") {
|
||||
return nil
|
||||
}
|
||||
if filepath.Base(path) == "session.go" && filepath.Clean(filepath.Dir(path)) == "." {
|
||||
return nil
|
||||
}
|
||||
src, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
text := string(src)
|
||||
if strings.Contains(text, "agentcore.NewSession(") {
|
||||
t.Errorf("%s calls agentcore.NewSession directly; use newSession", path)
|
||||
}
|
||||
if strings.Contains(text, "agentcore.Run(") && path != "provider.go" {
|
||||
t.Errorf("%s calls agentcore.Run directly; only the connection test may", path)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -778,7 +778,7 @@ func (w *Worker) execute(ctx context.Context, name string, taskID int64, as *db.
|
||||
noaSession := WorkerSessionID(ts.ID(), intent.ID)
|
||||
enableNoa(&opts, w.noaEnabledFn, w.workDir, noaSession, noaWarn(noaSession))
|
||||
ctx = attachSideCapture(ctx, &opts)
|
||||
s := agentcore.NewSession(opts)
|
||||
s := newSession(opts)
|
||||
defer s.Close() // release the session's background-task manager (temp dir + processes)
|
||||
|
||||
// Resume prior conversation if this intent was paused/blocked/exhausted and is
|
||||
|
||||
@@ -307,6 +307,11 @@ func wireTools(pg *db.DB, domainReg map[string]actool.CoreTool) {
|
||||
rows, err := pg.ListTools()
|
||||
if err != nil {
|
||||
log.Printf("[tools] failed to read tools table, passing through with code defaults: %v", err)
|
||||
// Auto's base list is nil, and Norma reads nil as "use its own
|
||||
// unconfined default tools". Keep it an empty list.
|
||||
if tools == nil {
|
||||
return []actool.CoreTool{}
|
||||
}
|
||||
return tools
|
||||
}
|
||||
byKey := make(map[string]*db.Tool, len(rows))
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"testing"
|
||||
|
||||
"github.com/Autumn-27/artex/agent"
|
||||
"github.com/Autumn-27/artex/db"
|
||||
)
|
||||
|
||||
// When the tools table cannot be read, Auto's nil base list must come back as
|
||||
// an empty list: Norma reads nil as "install my own unconfined default tools".
|
||||
func TestToolResolveCatalogFailureReturnsEmptyList(t *testing.T) {
|
||||
sqlDB, err := sql.Open("pgx", "postgres://127.0.0.1:1/unused?sslmode=disable")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = sqlDB.Close() // every query now fails without touching the network
|
||||
oldBinding, oldCapture := agent.FindingTrafficBindingEnabled(), agent.TrafficCaptureEnabled()
|
||||
t.Cleanup(func() {
|
||||
agent.SetToolResolve(nil)
|
||||
agent.SetFindingTrafficBindingEnabled(oldBinding)
|
||||
agent.SetTrafficCaptureEnabled(oldCapture)
|
||||
})
|
||||
wireTools(&db.DB{DB: sqlDB}, nil)
|
||||
|
||||
got := agent.ToolResolve()(context.Background(), "auto", nil)
|
||||
if got == nil || len(got) != 0 {
|
||||
t.Fatalf("catalogue failure returned %#v, want an empty non-nil list", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user