Files
Pulse/internal/ai/tools/current_resource_identity_test.go
rcourtman 88338e9a7c Preserve canonical resource ownership in Assistant
Keep selection on the registry ID through context, sessions and command
routing so same-name resources cannot cross provider boundaries.
Retain native executor coordinates, legacy inputs that resolve uniquely,
policy redaction and paid execution modes.

Refs #2681
2026-10-13 01:56:59 +01:00

30 lines
1.3 KiB
Go

package tools
import (
"github.com/rcourtman/pulse-go-rewrite/internal/models"
"github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
"testing"
)
func TestCurrentResourceAddressingKeepsTheSelectedCanonicalOwner(t *testing.T) {
rr := unifiedresources.NewRegistry(nil)
rr.IngestSnapshot(models.StateSnapshot{VMs: []models.VM{
{ID: "a:node1:101", Instance: "a", Node: "node1", VMID: 101, Name: "first", Type: "qemu"},
{ID: "b:node1:101", Instance: "b", Node: "node1", VMID: 101, Name: "second", Type: "qemu"},
}})
selected := unifiedresources.ProxmoxGuestCanonicalID(unifiedresources.ResourceTypeVM, "b", 101)
resource := &mockResource{resourceID: selected, providerUID: "101", kind: "vm", aliases: []string{"first"}, targetHost: "node1"}
executor := NewPulseToolExecutor(ExecutorConfig{ReadState: rr})
target, err := executor.commandTargetForResolvedResource(resource)
if err != nil || target != selected {
t.Fatalf("selected owner rebound through provider UID or alias: %q %v", target, err)
}
if got := canonicalQueryIDForResolvedResource(resource); got != selected {
t.Fatalf("selected read uses unscoped ID %s", got)
}
resource.resourceID = "vm-unknown"
if target, err := executor.commandTargetForResolvedResource(resource); err == nil {
t.Fatalf("missing owner rebound to %s", target)
}
}