ARTEX/server/assembly_test.go
BaaRai 716e484e74 feat(server,web): opt-in shared browser with isolated CDP, per-task profiles, and configurable lock (#621)
Rebased onto main (5f5ec32) and hardened per security review:
- Opt-in only (-shared-browser / ARTEX_SHARED_BROWSER=true; default false); README and CHANGELOG accurately describe hardened behavior and document the residual risk of same-UID argv token visibility alongside per-message operator-hold/lease enforcement and immediate revocation.
- Isolates CDP via --remote-debugging-pipe on Unix (no Chromium DevTools TCP port or DevToolsActivePort) fronted by a per-run 256-bit token-authenticated server CDP proxy enforcing operator hold and active lease on every HTTP request and WebSocket message.
- Removes --ignore-certificate-errors from the capture path; trusts only ARTEX's capture CA SPKI pin (--ignore-certificate-errors-spki-list) and fails closed if unreadable.
- Removes --disable-blink-features=AutomationControlled and the HeadlessChrome user-agent rewrite (policy: hand challenges off via ask_operator).
- Isolates browser profiles per task or chat session under <data>/browser-profiles/<scope> using descriptor-relative openat(O_NOFOLLOW|O_DIRECTORY) + fchown + unlinkat with root-owned parent (no filepath.Walk over executor-owned trees), tested against root/scope/child symlinks.
- Makes operator lock / ask_operator hold timeout configurable via -shared-browser-lock-timeout / ARTEX_SHARED_BROWSER_LOCK_TIMEOUT (default 15m), auto-expiring idle locks.
Co-authored-by: Pranil Acharya <Pro-Nil@users.noreply.github.com>
2026-11-28 10:00:56 +01:00

93 lines
2.8 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package server
import (
"context"
"os"
"path/filepath"
"testing"
"github.com/Autumn-27/artex/agent"
"github.com/Autumn-27/artex/db"
actool "github.com/Autumn-27/norma/tool"
)
// hasSkillTool reports whether the packed tool set contains the Skill meta-tool.
func hasSkillTool(tools []actool.CoreTool) bool {
for _, t := range tools {
if t.Name() == "Skill" {
return true
}
}
return false
}
// TestAssembleVisibleSkill verifies a filesystem skill made visible to an agent is
// packed into that agent's tool set (as the single Skill meta-tool) via the wired
// ToolAugment hook. Skills live on disk under skillDir; visibility is a per-agent
// (agent × skill_name) row keyed by the skill's directory name.
func TestAssembleVisibleSkill(t *testing.T) {
dsn, _, err := db.DSN()
if err != nil {
db.SkipPGUnavailable(t, err)
}
pg, err := db.Open(dsn)
if err != nil {
db.SkipPGUnavailable(t, err)
}
defer pg.Close()
// Filesystem skill fixture: <skillDir>/t-assemble/SKILL.md. The directory name
// (t-assemble) is the visibility key matched against AgentSkillNames.
skillDir := t.TempDir()
const skillName = "t-assemble"
if err := os.MkdirAll(filepath.Join(skillDir, skillName), 0o755); err != nil {
t.Fatal(err)
}
md := "---\nname: t-assemble\ndescription: do the thing\n---\ndo the thing"
if err := os.WriteFile(filepath.Join(skillDir, skillName, "SKILL.md"), []byte(md), 0o644); err != nil {
t.Fatal(err)
}
wireAgentAugment(pg, skillDir, nil, ExecPrivilege{}, nil)
t.Cleanup(func() { agent.SetToolAugment(nil) })
ag, _ := pg.GetAgentByKey("planner")
if ag == nil {
t.Fatal("planner agent missing")
}
// Isolate this test from whatever skill visibility the planner already has in the
// shared DB: clear it now, restore it on cleanup.
orig, _ := pg.AgentSkillNames(ag.ID)
if err := pg.SetAgentSkillVisibility(ag.ID, nil); err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = pg.SetAgentSkillVisibility(ag.ID, orig) })
// before: skill not visible → no Skill meta-tool
extra, _, cleanup := agent.ToolAugment()(context.Background(), "planner")
cleanup()
if hasSkillTool(extra) {
t.Fatalf("expected no Skill meta-tool before the skill is made visible")
}
// make the skill visible to planner
if err := pg.ToggleSkillVisibility(ag.ID, skillName, true); err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = pg.ToggleSkillVisibility(ag.ID, skillName, false) })
// after: the Skill meta-tool is packed in
extra, _, cleanup = agent.ToolAugment()(context.Background(), "planner")
defer cleanup()
if !hasSkillTool(extra) {
t.Fatalf("expected the Skill meta-tool after making the skill visible")
}
// AugmentTools appends extra to base without filtering base
combined, _, c2 := agent.AugmentTools(context.Background(), "planner", nil)
defer c2()
if !hasSkillTool(combined) {
t.Fatalf("AugmentTools should surface the Skill meta-tool")
}
}