node-engine client: compose-candidate takes three key forms, built by the client and read by one parser (A-226b)

Builds: design 47 G (G-22 lead answers 2) A-226b; ADR 0593 §7
This commit is contained in:
2026-11-16 13:57:04 +01:00
parent c93229f23a
commit 2db6e5df49
5 changed files with 132 additions and 5 deletions
@@ -113,3 +113,47 @@ func TestCompositionKeyRoundTripsAndRefuses(t *testing.T) {
t.Error("a key with no group was made")
}
}
// A-226b: the three forms of a compose-candidate key are built by the client and read by one parser; a check's key reads as it
// did, a revision's number is never mistaken for a heads hash, and what is none of them is refused naming it.
func TestCandidateKeysOfTheThreeFormsRoundTripAndRefuse(t *testing.T) {
check, _ := CompositionKey("fix/1.2", "0123456789ab")
revision, err := RevisionKey("fix/1", 362)
if err != nil {
t.Fatal(err)
}
run, err := RunKey("r1")
if err != nil {
t.Fatal(err)
}
for key, want := range map[string]Candidate{
check: {Kind: CandidateCheck, Group: "fix/1.2", HeadsHash: "0123456789ab"},
revision: {Kind: CandidateRevision, Branch: "fix/1", Revision: 362},
run: {Kind: CandidateRun, Run: "r1"},
"main.1": {Kind: CandidateRevision, Branch: "main", Revision: 1},
} {
if got, err := ParseCandidateKey(key); err != nil || got != want {
t.Errorf("%q parsed as %+v (%v), want %+v", key, got, err, want)
}
}
for _, bad := range []string{"", "nogroup", "run-", "g.0123456789AB", ".362", "a.b.362", "main.0", "main.-3", "main.0362", "main.123456789012x"} {
if _, err := ParseCandidateKey(bad); err == nil {
t.Errorf("%q was taken for a candidate key", bad)
}
}
for _, bad := range []int64{0, -1, 100000000000} {
if _, err := RevisionKey("main", bad); err == nil {
t.Errorf("a key for revision %d was made", bad)
}
}
if _, err := RevisionKey("", 1); err == nil {
t.Error("a key with no branch was made")
}
if _, err := RunKey("a.b"); err == nil {
t.Error("a run key with a dot was made")
}
// The ask and the answer accept all three.
if _, err := EncodeAsk(seat.ComposeCandidateInput{Candidate: revision}); err != nil {
t.Errorf("an ask naming a revision: %v", err)
}
}