B2: on every branch-moved of a watched branch, and at its start for every watched branch's head, the bridge reads the head through the seat git's verb branch, as a kept call that waits on the holder's return while the branch is watched, and writes one head-moved (repository, branch, head, before the head held in its state heads, start) on its stream forge; a head equal to the one held writes nothing. It reads no pull request, no tree, no file and no protection: the merged and pushed messages, their inputs and the state inputs, the call of git.pull, the finding branch-unprotected with its held finding writer, and the ten-second redelivery go. A move whose head cannot be read is left unacknowledged for the bus to deliver again. B3: the pull-message path (Convert, the open pull requests at start and reconnect, the forge-delete message), the groups (internal/groups' group part, forge.group.merged, end-asks, bridge_groups, bridge_group_end_again), bridge_merged_message with the forge-made reader, the checker's owed and the merge act of a switched key (with the switch's bookkeeping read) go, with their consumes, invokes, states and requires. The gate's owed path stays (H-A-71), its catch-up from the gate's verb groups gone with that verb. The two meet in main.go and the package compiles only with both, as it did not since B1. The unit suites pass; the whole test (integration) is rewritten in B4. Builds: design 47 H §739, §764 (the forge bridge; the branch protection); lead answers H-A-23, H-A-27, H-A-48, H-A-71 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
76 lines
2.8 KiB
Go
76 lines
2.8 KiB
Go
package forgemsg
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"slices"
|
|
"time"
|
|
)
|
|
|
|
// OwedEndedEvent is the name of an owed act's outcome on the forge bridge's stream `forge` (design 47 G §164): the
|
|
// bridge says it for each act the gate or the checker said as the event `owed`. Its two parts are no repository's
|
|
// forge event (`forge.<owner>.<name>.<kind>`).
|
|
const OwedEndedEvent = "owed.ended"
|
|
|
|
// The outcomes of an owed act (design 47 G §164, §168): performed, refused (the forge's own words), could not be
|
|
// performed (the forge did not answer within the call's bound, with the error), undecodable (an act the bridge cannot
|
|
// read, with why) and, from the tool `bridge_owed_drop`, dropped.
|
|
const (
|
|
OwedPerformed = "performed"
|
|
OwedRefused = "refused"
|
|
OwedCouldNotBePerformed = "could not be performed"
|
|
OwedUndecodable = "undecodable"
|
|
OwedDropped = "dropped"
|
|
)
|
|
|
|
// OwedOutcomes are the outcomes an owed.ended says, one of them.
|
|
var OwedOutcomes = []string{OwedPerformed, OwedRefused, OwedCouldNotBePerformed, OwedUndecodable, OwedDropped}
|
|
|
|
// OwedEnded is an owed act's outcome (design 47 G §164): the act's id and one outcome, with the words of any outcome
|
|
// but performed. Of is the seat that said the act (mesh-delivery for the gate's), so it hears its own ids (§164). An act the bridge cannot decode may name no id.
|
|
type OwedEnded struct {
|
|
V int `json:"v"`
|
|
Of string `json:"of"`
|
|
ID string `json:"id,omitempty"`
|
|
Outcome string `json:"outcome"`
|
|
Words string `json:"words,omitempty"`
|
|
At time.Time `json:"at"`
|
|
}
|
|
|
|
func (e OwedEnded) check() error {
|
|
switch {
|
|
case e.Of == "":
|
|
return fmt.Errorf("an owed act's outcome names no seat that said it")
|
|
case !slices.Contains(OwedOutcomes, e.Outcome):
|
|
return fmt.Errorf("the outcome %q of an owed act is none of %v", e.Outcome, OwedOutcomes)
|
|
case e.ID == "" && e.Outcome != OwedUndecodable:
|
|
return fmt.Errorf("the outcome %s of an owed act names no id", e.Outcome)
|
|
case e.Outcome != OwedPerformed && e.Words == "":
|
|
return fmt.Errorf("the outcome %s of the owed act %s says no words", e.Outcome, e.ID)
|
|
case e.At.IsZero():
|
|
return fmt.Errorf("the outcome of the owed act %s says no time", e.ID)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EncodeOwedEnded is e as JSON at Version; it refuses what check refuses.
|
|
func EncodeOwedEnded(e OwedEnded) ([]byte, error) {
|
|
if err := e.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
e.V = Version
|
|
return json.Marshal(e)
|
|
}
|
|
|
|
// DecodeOwedEnded reads an owed act's outcome; it refuses an unknown version and what EncodeOwedEnded refuses.
|
|
func DecodeOwedEnded(data []byte) (OwedEnded, error) {
|
|
var e OwedEnded
|
|
if err := decode(data, &e); err != nil {
|
|
return OwedEnded{}, err
|
|
}
|
|
if err := e.check(); err != nil {
|
|
return OwedEnded{}, err
|
|
}
|
|
return e, nil
|
|
}
|