Files
mesh-delivery/sdk/tryevent/tryevent.go
T
jschoubben 45386212da A group try's candidate follows the checker's try events, judged in one locked pass (issue 1921)
The checker says try.started (members at their commits) and try.ended for a whole try; the indexer writes and
deletes the candidate from them and finds the open tries again at its start through checker_tries, never reading
the checker's state. The try's digests are judged inside the one pass that takes the seats; the definitions of every
contracts module of each member are read; the config declarations leave a try's candidate alone.

Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
2026-11-05 18:28:52 +01:00

58 lines
1.9 KiB
Go

// Package tryevent is what the checker says on its stream checks when a whole try (a try of a delivery group, not narrowed
// to a level or to some tests) starts and ends (issue 1921), and what the indexer, which hears it, reads: a try has no pull
// request, so the indexer writes the candidate of its group from the members at their commits, and deletes it at the end.
// The events carry the members, so no part reads the checker's state.
package tryevent
import (
"encoding/json"
"fmt"
"regexp"
)
// The events of the checker's stream checks.
const (
Started = "try.started"
Ended = "try.ended"
)
// IDOK is the shape of a try's id, which is also the name of its group (the key of its candidate).
var IDOK = regexp.MustCompile(`^try-[0-9]{1,20}$`)
// Member is one repository of the try: the exact commit and the trunk commit it is merged onto.
type Member struct {
Repository string `json:"repository"`
Head string `json:"head"`
Trunk string `json:"trunk"`
}
// Event is the body of both events: the try, and for Started its members; for Ended the state it ended in.
type Event struct {
ID string `json:"id"`
Members []Member `json:"members,omitempty"`
State string `json:"state,omitempty"`
}
// Decode reads an event body; a started event names its members.
func Decode(event string, body []byte) (Event, error) {
var e Event
if err := json.Unmarshal(body, &e); err != nil {
return e, err
}
if !IDOK.MatchString(e.ID) {
return e, fmt.Errorf("%q is not a try's id, try-<digits>", e.ID)
}
if event == Started && len(e.Members) == 0 {
return e, fmt.Errorf("the try %s starts with no member", e.ID)
}
return e, nil
}
// Open is one try that waits or runs, as the checker's tool checker_tries answers it.
type Open struct {
ID string `json:"id"`
State string `json:"state"`
Whole bool `json:"whole"`
Members []Member `json:"members"`
}