nearle admin agent

This commit is contained in:
2026-09-28 11:26:18 +05:30
parent 090e9c0c2f
commit b18080d429
8 changed files with 271 additions and 3 deletions

View File

@@ -262,3 +262,43 @@ func TestAgentNamesAreSortedSoTwoDeploymentsLogTheSameLine(t *testing.T) {
t.Fatalf("not sorted: %v", names)
}
}
// The platform agent may only hold tools a caller with no tenant can run.
//
// Nearle's own staff are `issuperadmin`: they read across every merchant and
// belong to none, so `tools.Caller.Tenantid` is zero and `satisfies` refuses
// anything declaring RequiresTenant or RequiresBranch. An agent holding those
// would accept every question and answer "pick a shop first" to all of them,
// which reads as a broken assistant rather than a scoped one.
//
// Asserted rather than trusted, because adding a tool to a YAML file is one
// line and the failure it produces is invisible until somebody in the platform
// workspace asks a question.
func TestThePlatformAgentOnlyHoldsToolsThatNeedNoTenant(t *testing.T) {
registry := realRegistry(t)
agents, err := LoadAgents("", registry.Has)
if err != nil {
t.Fatalf("agents: %v", err)
}
platform, ok := agents["platform"]
if !ok {
t.Fatal("no platform agent — Nearle Admin has no assistant at all")
}
if len(platform.Tools) == 0 {
t.Fatal("the platform agent holds no tools")
}
for _, name := range platform.Tools {
tool, ok := registry.Tool(name)
if !ok {
t.Fatalf("platform names %q, which is not in the registry", name)
}
if tool.Needs != tools.RequiresNothing {
t.Fatalf(
"platform holds %q, which needs a shop — a platform account has none, so every "+
"question using it is refused", name)
}
}
}