Files
ARTEX/server/spill_test.go
T
BaaRai 7520c6e588 security(agent): command-output spills go to a root-owned per-task dir
Norma's tool.Capture writes an oversized tool output to a file in
ToolOutputDir, from the server process. ARTEX passed <run dir>/cmd-output:
the executor can write in the run directory and could turn cmd-output into
a symlink, so root wrote the spill where the link pointed.

- With the privilege drop on, ToolOutputDir is <data>/spill/tasks/<id> for
  the worker, the main agent and the planner of a task, and
  <data>/spill/sessions/<id> for a chat. The server creates it when the
  run starts (agent.SetSpillDirMaker, same style as SetRunDirMaker):
  root:<exec gid> 0750 below root:root 0755 parents, each level through a
  descriptor opened with O_NOFOLLOW. A directory that cannot be created
  leaves the run without a spill directory (output is truncated), never
  with the run directory. Without the drop the path stays
  <run dir>/cmd-output.
- Norma v0.4.11 writes the spill file 0600 (directory 0700), so the
  executor could not read it. The runs wrap their hooks (agent.SpillHooks):
  after a tool call whose result carries the spill marker, the server makes
  the files of the directory root:<exec gid> 0640. The agent reads a spill
  with Bash; the file tools do not reach outside the run directory.
- The spill directory follows the task: stageTaskFiles moves it to the
  delete staging with tasks/<id>, stageTaskArchiveFiles packs it as
  files/spill/tasks/<id>, and installTaskArchiveFiles restores it and puts
  its ownership back. Deleting a conversation removes
  spill/sessions/conv-<id>.

Tests: TestToolOutputDir (agent); TestDeleteTaskFilesRemovesSpillDir,
TestRemoveConversationSpill and the archive round trip (server); root-only
TestSpillDirAsRoot, and the spill directory in
TestTaskArchiveRestoreRunDirOwnershipAsRoot. SECURITY.md drops the spill
from the residual list.
2026-11-20 05:35:55 +01:00

35 lines
1.1 KiB
Go

package server
import (
"path/filepath"
"testing"
"github.com/Autumn-27/artex/agent"
)
// Deleting a conversation removes the spill directory of its chat session only: the
// spills of another conversation and the session's run directory stay.
func TestRemoveConversationSpill(t *testing.T) {
dataDir := t.TempDir()
s := &Server{m: &Manager{dir: dataDir}}
spill := agent.SessionSpillDir(dataDir, s.convBusyKey(5))
if spill != filepath.Join(dataDir, "spill", "sessions", "conv-5") {
t.Fatalf("session spill directory = %s", spill)
}
kept := []string{
filepath.Join("spill", "sessions", "conv-50", "output-1-2.txt"),
filepath.Join("spill", "tasks", "5", "output-1-3.txt"),
filepath.Join("sessions", "conv-5", "notes.txt"),
}
for _, path := range append([]string{filepath.Join("spill", "sessions", "conv-5", "output-1-1.txt")}, kept...) {
createDeleteFixture(t, dataDir, path, false)
}
s.removeConversationSpill(5)
assertPathMissing(t, spill)
for _, path := range kept {
assertPathExists(t, filepath.Join(dataDir, path))
}
// A conversation that never spilled has nothing to remove.
s.removeConversationSpill(6)
}