ARTEX-English/db/tool_usage_test.go
Sean Kilfoy edaf7e323a Package BaaRai v0.7.0 as the operator distribution.
The application tree is BaaRai/ARTEX v0.7.0 (22ae88af), imported as one commit because that history is not in this repository. This commit adds the cloud installer, a defender pack for the console and the known-bad image names, and a supply-chain check. The opt-in update banner points at this fork and stays off in the cloud compose file.
2026-11-26 07:33:09 +00:00

44 lines
1 KiB
Go

package db
import "testing"
func TestToolUsageLedger(t *testing.T) {
d, err := Open(testDSN(t))
if err != nil {
SkipPGUnavailable(t, err)
}
defer d.Close()
const (
toolA = "zz_test_tool_usage_a"
toolB = "zz_test_tool_usage_b"
)
cleanup := func() {
_, _ = d.Exec(`DELETE FROM tool_usage WHERE tool_key IN ($1,$2)`, toolA, toolB)
}
cleanup()
defer cleanup()
rows := []*ToolUsage{
{ToolKey: toolA, AgentKey: "worker", TaskID: 991, ExplorationID: 5, IntentID: 7},
{ToolKey: toolA, AgentKey: "planner", TaskID: 992, ExplorationID: 6},
{ToolKey: toolA, AgentKey: "chatbot", SessionID: "conv-1"},
{ToolKey: toolB, AgentKey: "worker", TaskID: 991},
}
for _, row := range rows {
if err := d.InsertToolUsage(row); err != nil {
t.Fatalf("insert %s: %v", row.ToolKey, err)
}
}
counts, err := d.ToolUsageCounts()
if err != nil {
t.Fatal(err)
}
if got := counts[toolA]; got != 3 {
t.Errorf("%s calls: want 3, got %d", toolA, got)
}
if got := counts[toolB]; got != 1 {
t.Errorf("%s calls: want 1, got %d", toolB, got)
}
}