Files
Agent-System-Backend/internal/server/command_pairs_test.go
weichen e0b1c27f1f
ci / vet-and-test (pull_request) Successful in 42s
Scope command audit storage and queries to the requesting owner
Why: GET /api/commands/audit leaked every tenant's audit rows (command ids, entrances, conversation ids, param digests) to any authenticated user; owner was never recorded nor filtered.
Evidence: Red run at a7cc69b FAIL (alice sees bob's row); after fix go test ./... 32/32 packages ok, including TestCommandAuditOwnerScoping and the v18 backfill test (rows recorded on the task card).
Impact: v18 migration adds command_audit.owner with actor-based backfill (empty-actor rows stay invisible via API, kept in-table); AppendAudit/ListAudits gain owner params; cmdbus port and fakes updated; handler passes authenticated owner. No public extension surface change.
Refs: Task card R1; U0 proposal section 5 C7 finding.
2026-10-08 14:02:19 +00:00

47 lines
1.1 KiB
Go

package server
import (
"encoding/json"
"os"
"path/filepath"
"testing"
agentcommand "agent-command"
"agent-system-backend/internal/cmdbus"
)
type pair struct {
ID string `json:"id"`
Button bool `json:"button"`
Chat bool `json:"chat"`
}
type nopAudit struct{}
func (nopAudit) AppendAudit(string, agentcommand.AuditEnvelope) error { return nil }
// 每个内置命令都必须在 command-pairs.json 里同时声明按钮入口与对话入口。
// 新命令漏登记则本测试失败,合入被挡住。
func TestBuiltinCommandsHaveDualEntryPairs(t *testing.T) {
raw, err := os.ReadFile(filepath.Join("testdata", "command-pairs.json"))
if err != nil {
t.Fatal(err)
}
var pairs []pair
if err := json.Unmarshal(raw, &pairs); err != nil {
t.Fatal(err)
}
byID := map[string]pair{}
for _, p := range pairs {
byID[p.ID] = p
}
s := &Server{Bus: cmdbus.New(nopAudit{}, nil, nil)}
s.WireBuiltinCommands()
for _, cmd := range s.Bus.List() {
p, ok := byID[cmd.Spec.ID]
if !ok || !p.Button || !p.Chat {
t.Errorf("command %s missing dual-entry pair (button and chat)", cmd.Spec.ID)
}
}
}