Files
mesh-catalog/modules/mesh-vault/cmd/mesh-vault/own_issue_test.go
T

85 lines
3.5 KiB
Go

package main
import (
"fmt"
"strings"
"testing"
)
// Issue 928 (ADR 0349 clause 10): the vault takes a software-issued value by itself. With claude-code's need
// recorded on two machines and the forge's tool answering, one pass asks the tool for both holders and keeps a
// value for each; the next pass leaves them be, and a holder bound later is the only one asked.
func TestThePassAsksAnIssuingProvidersToolForTheHoldersItHoldsNothingFor(t *testing.T) {
mirror := assignments{
"novox.gitea": handedWith("novox", "gitea"),
"anchor.claude-code": handedWith("anchor", "claude-code", "gitea-read@novox/gitea=gitea-read+issued~gitea_agent_token"),
}
v := pairVault(t, mirror)
var asked []map[string]any
v.Ask = forgeMesh(perHolderProvider(agentTokens, &asked)).ask
o := pass(t, v, "provision/novox/gitea-read")
if o.Outcome != PairPerHolder {
t.Fatalf("outcome %+v", o)
}
if len(asked) != 1 || !strings.Contains(toString(asked[0]["holders"]), "anchor") {
t.Fatalf("the tool was asked %v, want once for anchor", asked)
}
if _, held, _ := v.Store.Read(anchorsToken); !held {
t.Fatal("the vault took no value for claude-code on anchor by itself")
}
if got := handedTo(t, v, "provisioner.anchor", anchorsToken); got != agentTokens["anchor/claude-code"] {
t.Errorf("anchor got %q", got)
}
// Held is left untouched: no second ask, so the forge does not mint anew (rotation is the software's).
pass(t, v, "provision/novox/gitea-read")
if len(asked) != 1 {
t.Errorf("the tool was asked again for a holder that holds its value (%d asks)", len(asked))
}
// A holder bound since is the only one asked.
mirror["laptop.claude-code"] = handedWith("laptop", "claude-code", "gitea-read@novox/gitea=gitea-read+issued~gitea_agent_token")
pass(t, v, "provision/novox/gitea-read")
if len(asked) != 2 || strings.Contains(toString(asked[1]["holders"]), "anchor") {
t.Fatalf("asks %v, want a second naming laptop alone", asked)
}
if _, held, _ := v.Store.Read(laptopsToken); !held {
t.Error("no value for the holder bound later")
}
}
// A failed ask keeps nothing, is said as a held outcome, and is asked again at the next pass; a plan naming no
// tool is said, not guessed.
func TestAFailedAskOfTheToolIsAskedAgainAndNoToolIsSaid(t *testing.T) {
mirror := assignments{
"novox.gitea": handedWith("novox", "gitea"),
"anchor.claude-code": handedWith("anchor", "claude-code", "gitea-read@novox/gitea=gitea-read+issued~gitea_agent_token"),
}
v := pairVault(t, mirror)
v.Ask = forgeMesh(func(string, map[string]any) (map[string]any, error) { return nil, errTest }).ask
o := pass(t, v, "provision/novox/gitea-read")
if o.Outcome != PairHeld || !strings.Contains(o.Why, "could not be asked") {
t.Fatalf("a failed ask is %+v", o)
}
var asked []map[string]any
v.Ask = forgeMesh(perHolderProvider(agentTokens, &asked)).ask
pass(t, v, "provision/novox/gitea-read")
if _, held, _ := v.Store.Read(anchorsToken); !held || len(asked) != 1 {
t.Fatal("the next pass did not ask again and keep the value")
}
noTool := pairVault(t, assignments{
"novox.gitea": handedWith("novox", "gitea"),
"anchor.claude-code": handedWith("anchor", "claude-code", "gitea-read@novox/gitea=gitea-read+issued"),
})
noTool.Ask = v.Ask
if o := pass(t, noTool, "provision/novox/gitea-read"); o.Outcome != PairHeld || !strings.Contains(o.Why, "name no tool") {
t.Errorf("a plan with no tool is %+v", o)
}
}
var errTest = errString("nats: no responders available for request")
func toString(v any) string { return strings.TrimSpace(strings.ReplaceAll(fmt.Sprint(v), "map", "")) }