Compare commits
27
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f85199f624 | ||
|
|
13d43a7de0 | ||
|
|
5dfb357333 | ||
|
|
282758456c | ||
|
|
0e9f916806 | ||
|
|
daa5d3ea5f | ||
|
|
be993cb2c5 | ||
|
|
cd3b8fe8e9 | ||
|
|
f0c21ca033 | ||
|
|
c6ec42bc2e | ||
|
|
f65d789052 | ||
|
|
62b8251b99 | ||
|
|
90c88fc7b5 | ||
|
|
740c218139 | ||
|
|
1481465ec7 | ||
|
|
d2b8f64c94 | ||
|
|
eed95cd63b | ||
|
|
84106a9338 | ||
|
|
9ed13cd9dc | ||
|
|
d76c3588e3 | ||
|
|
377d42f5ea | ||
|
|
9ade421e12 | ||
|
|
46f3dc8cd7 | ||
|
|
7da6dd20a1 | ||
|
|
c87cf1ace5 | ||
|
|
3f3f6789dd | ||
|
|
7c6aed9d69 |
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
artifactref "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/containerimageregistryclient/reference"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/publishconformance"
|
||||
)
|
||||
|
||||
type memObjects map[string][]byte
|
||||
@@ -666,6 +667,22 @@ func TestTheHolderOfTheTwoImageSeats(t *testing.T) {
|
||||
}
|
||||
}
|
||||
})
|
||||
// Design 47 G A-490: the publish contract's no-parts form, as every publish holder is held to it.
|
||||
t.Run("the publish conformance cases", func(t *testing.T) {
|
||||
publishconformance.Run(t, func(t *testing.T) publishconformance.Bed {
|
||||
b := newBed(true)
|
||||
return publishconformance.Bed{
|
||||
Hold: func(d string) { b.store.has[d] = true },
|
||||
Publish: func(name, version, digest string) publishconformance.Outcome {
|
||||
got, err := b.h.Publish(ArtifactSeat, builder, PublishRequest{Name: name, Version: version, Kind: KindBundle, Digest: digest, Transfer: "t"})
|
||||
o := publishconformance.Outcome{Ended: got.Ended, Lacks: len(got.Missing), Err: err}
|
||||
if len(b.said) > 0 {
|
||||
o.Event, o.Reason = b.said[len(b.said)-1].event, b.said[len(b.said)-1].body.Reason
|
||||
}
|
||||
return o
|
||||
}}
|
||||
})
|
||||
})
|
||||
t.Run("a publish with a version and no parts tags the held digest at the store's size; one not held is not stored", func(t *testing.T) {
|
||||
// Design 47 G A-417, A-73, A-50: the build stored the bundle untagged; the builder's publish of its version with that
|
||||
// digest and no parts tags it and says published, nothing sent; a digest the store holds none of is refused as not
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
# The wallpaper (module feh, novox/hq ADR 0208). Owned by the mesh: replaced at every push. The
|
||||
# The wallpaper (module feh, novox/hq ADR 0208). Owned by the mesh: replaced at every delivery. The
|
||||
# session's start runs it, and so may anything that wants the declared wallpaper back. The image is
|
||||
# the module's own, in ~/.local/share/feh/wallpapers. feh_set changes the wallpaper for a session
|
||||
# without touching this file.
|
||||
# without touching this file (the second single-module proof, 2026-11-17).
|
||||
feh --no-fehbg --bg-fill "$HOME/.local/share/feh/wallpapers/default.jpg"
|
||||
|
||||
@@ -291,7 +291,7 @@ func verbTools[PI, PA, PPI, PPA, VI, VA, RI, RA any](seat string, holder func()
|
||||
}
|
||||
return []stdio.Tool{
|
||||
{Name: seat + "." + packageseats.VerbPublish, Input: obj,
|
||||
Description: "Open a transfer of a package's one file (ADR 0611): its name, the builder's version, kind package, its sha256 digest and the file as its one part; answers the part the forge lacks. A version held with that digest answers held and says published.",
|
||||
Description: "Open a transfer of a package's one file (ADR 0611): its name, the builder's version, kind package, its sha256 digest and the file as its one part; answers the part the forge lacks. A version held with that digest answers held and says published; with no part at all (the builder's publish again) nothing moves: held says published, else refused as not stored, naming the digest (design 47 G A-490).",
|
||||
Run: run(func(h *packageseats.Holder, args map[string]any) (any, error) {
|
||||
in, err := as[PI](args)
|
||||
if err != nil {
|
||||
|
||||
@@ -213,7 +213,9 @@ func (h *Holder) answer(transfer string, r parts.Received) Answer {
|
||||
return Answer{Transfer: transfer, Lacks: r.Lacks, Ended: r.Ended}
|
||||
}
|
||||
|
||||
// Publish is `publish` on seat for the proved caller: a package is one file, its digest the file's sha256.
|
||||
// Publish is `publish` on seat for the proved caller: a package is one file, its digest the file's sha256. With its one
|
||||
// part the file travels (design 51 *Publishing*); with none (the builder's publish again, design 47 G A-73, A-417) the
|
||||
// version is said published when the forge holds it under the digest, and refused as not stored otherwise.
|
||||
func (h *Holder) Publish(seat, caller string, p Publish) (Answer, error) {
|
||||
if err := checkPublish(seat, p); err != nil {
|
||||
return Answer{}, err
|
||||
@@ -225,12 +227,25 @@ func (h *Holder) Publish(seat, caller string, p Publish) (Answer, error) {
|
||||
} else if ok {
|
||||
if d != p.Digest {
|
||||
reason := fmt.Sprintf("%s@%s is published with %s, not %s", p.Name, p.Version, d, p.Digest)
|
||||
if len(p.Parts) == 0 {
|
||||
// The builder's publish again names nothing the forge holds under that digest: refused as not stored (A-490,
|
||||
// A-490a), the words its republish recognises.
|
||||
reason = "not stored: " + reason
|
||||
return Answer{Transfer: p.Transfer, Ended: true}, errors.Join(errors.New("publish: "+reason), h.refused(Transfer{Shape: Opening{Publish: p, Seat: seat}}, reason))
|
||||
}
|
||||
// A one-part publish of a taken version is refused with an event only, as the registry would (the builder's "version taken").
|
||||
return Answer{Transfer: p.Transfer, Ended: true}, h.refused(Transfer{Shape: Opening{Publish: p, Seat: seat}}, reason)
|
||||
}
|
||||
o := outcomeOf(p, "")
|
||||
o.Reference = Reference(p.Name, p.Version)
|
||||
return Answer{Transfer: p.Transfer, Ended: true}, h.Say(seat, EventPublished, o)
|
||||
}
|
||||
// A publish with a version, a digest and no parts (design 47 G A-73, A-417): what the forge holds under the version has
|
||||
// been said published above; nothing else travels, so the publish is refused as not stored, naming the digest.
|
||||
if len(p.Parts) == 0 {
|
||||
reason := fmt.Sprintf("not stored: the forge holds no %s of %s, so version %s names nothing", p.Digest, p.Name, p.Version)
|
||||
return Answer{Transfer: p.Transfer, Ended: true}, errors.Join(errors.New("publish: "+reason), h.refused(Transfer{Shape: Opening{Publish: p, Seat: seat}}, reason))
|
||||
}
|
||||
// The transfer's name is the caller's own (the seat's contract): none would open the seat's one nameless transfer,
|
||||
// which key() still makes a valid id.
|
||||
if strings.TrimSpace(p.Transfer) == "" {
|
||||
@@ -377,8 +392,8 @@ func checkPublish(seat string, p Publish) error {
|
||||
return fmt.Errorf("publish: %s holds packages, not a %s", seat, p.Kind)
|
||||
case !strings.HasPrefix(p.Digest, "sha256:"):
|
||||
return fmt.Errorf("publish: digest %q is no sha256 digest", p.Digest)
|
||||
case len(p.Parts) != 1 || p.Parts[0].Digest != p.Digest:
|
||||
return errors.New("publish: a package is one file, its one part the package's digest")
|
||||
case len(p.Parts) > 1 || (len(p.Parts) == 1 && p.Parts[0].Digest != p.Digest):
|
||||
return errors.New("publish: a package is one file, its one part the package's digest, or no part at all")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/parts"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/publishconformance"
|
||||
)
|
||||
|
||||
type memObjects map[string][]byte
|
||||
@@ -50,10 +51,21 @@ func (b builder) Recorded(_, _, _ string) (bool, string, error) { return b.ok, "
|
||||
// forge is the forge's package registry: seat -> name@version -> file.
|
||||
type forge struct {
|
||||
files map[string]map[string][]byte
|
||||
digests map[string]string // seat+name@version -> a digest held with no bytes kept
|
||||
removed []string
|
||||
}
|
||||
|
||||
func (f *forge) holdDigest(seat, name, version, d string) {
|
||||
if f.digests == nil {
|
||||
f.digests = map[string]string{}
|
||||
}
|
||||
f.digests[seat+" "+name+"@"+version] = d
|
||||
}
|
||||
|
||||
func (f *forge) Held(seat, name, version string) (string, bool, error) {
|
||||
if d, ok := f.digests[seat+" "+name+"@"+version]; ok {
|
||||
return d, true, nil
|
||||
}
|
||||
b, ok := f.files[seat][name+"@"+version]
|
||||
if !ok {
|
||||
return "", false, nil
|
||||
@@ -150,6 +162,50 @@ func TestTheForgeHoldsBothPackageSeats(t *testing.T) {
|
||||
}
|
||||
}
|
||||
})
|
||||
// Design 47 G A-490, A-490a: the publish contract's no-parts form, as every publish holder is held to it, per seat.
|
||||
for _, seat := range []string{GoSeat, NpmSeat} {
|
||||
t.Run("the publish conformance cases on "+seat, func(t *testing.T) {
|
||||
publishconformance.Run(t, func(t *testing.T) publishconformance.Bed {
|
||||
b := newBed(true)
|
||||
return publishconformance.Bed{
|
||||
Hold: func(d string) {
|
||||
b.forge.holdDigest(seat, publishconformance.Name, publishconformance.Version, d)
|
||||
},
|
||||
Publish: func(name, version, digest string) publishconformance.Outcome {
|
||||
a, err := b.h.Publish(seat, goBuild, Publish{Transfer: "t", Name: name, Version: version, Kind: KindPackage, Digest: digest})
|
||||
o := publishconformance.Outcome{Ended: a.Ended, Lacks: len(a.Lacks), Err: err}
|
||||
if len(b.said) > 0 {
|
||||
o.Event, o.Reason = b.said[len(b.said)-1].event, b.said[len(b.said)-1].o.Reason
|
||||
}
|
||||
return o
|
||||
}}
|
||||
})
|
||||
})
|
||||
}
|
||||
// Design 47 G A-73, A-417: the builder's publish again names the version and the digest and no parts.
|
||||
t.Run("a publish with a digest and no parts is published when held, refused as not stored when not", func(t *testing.T) {
|
||||
for _, seat := range []string{NpmSeat, GoSeat} {
|
||||
b := newBed(true)
|
||||
none := pub("mesh-sdk", "0.1.0", file)
|
||||
none.Parts = nil
|
||||
a, err := b.h.Publish(seat, goBuild, none)
|
||||
if err == nil || !strings.Contains(err.Error(), "not stored") || !strings.Contains(err.Error(), digest(file)) || !a.Ended {
|
||||
t.Fatalf("%s: a publish of a digest the forge lacks answered %+v, %v; want refused as not stored, naming the digest", seat, a, err)
|
||||
}
|
||||
if len(b.said) != 1 || b.said[0].event != EventRefused || !strings.Contains(b.said[0].o.Reason, digest(file)) || !b.findings["publish-refused mesh-sdk@0.1.0"] {
|
||||
t.Errorf("%s: said %+v, findings %v; want refused with the digest and the finding raised", seat, b.said, b.findings)
|
||||
}
|
||||
b = newBed(true)
|
||||
if _, ok := b.forge.files[seat]; !ok {
|
||||
b.forge.files[seat] = map[string][]byte{}
|
||||
}
|
||||
b.forge.files[seat]["mesh-sdk@0.1.0"] = file
|
||||
a, err = b.h.Publish(seat, goBuild, none)
|
||||
if err != nil || !a.Ended || len(a.Lacks) != 0 || len(b.said) != 1 || b.said[0].event != EventPublished || b.said[0].o.Reference != "mesh-sdk@0.1.0" {
|
||||
t.Errorf("%s: a held digest answered %+v, %v, said %+v; want published", seat, a, err, b.said)
|
||||
}
|
||||
}
|
||||
})
|
||||
// Tools review F4 and running review F2's kind: a seat's incoming is read per seat with the cap its binding
|
||||
// carries; an open transfer is armed with its idle key, re-armed for the rest when it took a chunk since, and
|
||||
// dropped with its chunks when it had none for 24 hours; a cap from the binding refuses a transfer past it.
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
// Package buildstep is kept empty as a bridge: the running pre-G indexer publishes mesh-catalog's packages only while
|
||||
// every package directory it published before is in the tree. It goes once G's indexer runs.
|
||||
package buildstep
|
||||
@@ -58,6 +58,7 @@ func main() {
|
||||
// compiles that program and runs it shut off, answers its mark judged by the candidate at the tree's commit, and the
|
||||
// program reached no key, no login, no name and no socket of the machine.
|
||||
func TestTheUnitLevelUnderTheWorkspaceRunnerRunsTheTreesProgramShutOff(t *testing.T) {
|
||||
t.Parallel()
|
||||
needTools(t, "the candidate's program shut off", "go", "git", "bwrap")
|
||||
home := t.TempDir()
|
||||
key, login := filepath.Join(home, ".ssh", "mesh_ed25519"), filepath.Join(home, "broker")
|
||||
|
||||
@@ -195,6 +195,7 @@ func TestACandidateThatDoesNotCompileFailsTheStepWithTheCompilersFirstErrorAndRu
|
||||
}
|
||||
|
||||
func TestTheInstalledProgramSaysItJudged(t *testing.T) { // 1898 K1, ADR 0535 §5
|
||||
t.Parallel()
|
||||
m, states, ws, _ := workspaceFor(t, "slow")
|
||||
for _, runner := range []any{nil, RunnerInstalled} {
|
||||
args := map[string]any{"workspace": ws, "level": LevelUnit}
|
||||
@@ -223,6 +224,7 @@ func TestAnUnknownRunnerIsRefused(t *testing.T) { // 1898 K1
|
||||
}
|
||||
|
||||
func TestTheShutOffProcessRunsTheStepItIsAsked(t *testing.T) { // 1898 K2: the candidate's side of the spec
|
||||
t.Parallel()
|
||||
m, _, ws, calls := workspaceFor(t, "slow")
|
||||
m.Inside = true
|
||||
a := m.answer(context.Background(), levelSpec{Step: stepUnit, Workspace: ws, Packages: []string{"./..."}, Bound: UnitBound})
|
||||
|
||||
@@ -24,70 +24,7 @@ import (
|
||||
"git.novox.be/novox/mesh-sdk/go/testbus"
|
||||
)
|
||||
|
||||
// nodeEngineTree is the node-engine's repository as the checker places it beside this check (MESH_CHECK_BESIDE, the
|
||||
// repository mesh-host), and with it every Go module of the other repositories placed there (mesh-sdk, mesh-contracts,
|
||||
// mesh-delivery, mesh-networking, the catalogue's trunk) and of the catalogue under check, first, as candidates: the workspace lays those the
|
||||
// node-engine's composer requires at the zero version, transitively (workspaceOf), so they resolve as the group lays
|
||||
// them, wherever the composer lives. The test
|
||||
// builds the node-engine's real composer command from that tree; it does not stand one in. With no beside directory it
|
||||
// fails, and with the node-engine beside but no composer command in it it fails: a composer test that could not build its
|
||||
// composer proves nothing. With a beside directory that holds no node-engine at all it skips aloud (NOT JUDGED), since a
|
||||
// checker from before this release places none for the catalogue.
|
||||
func nodeEngineTree(t *testing.T) (tree string, modules []string) {
|
||||
t.Helper()
|
||||
beside := os.Getenv("MESH_CHECK_BESIDE")
|
||||
if beside == "" {
|
||||
t.Fatal("NOT CHECKED: MESH_CHECK_BESIDE is not set, so the node-engine's repository (mesh-host) is not beside this check")
|
||||
}
|
||||
tree = filepath.Join(beside, "mesh-host")
|
||||
if !dirExists(tree) {
|
||||
// A checker from before novox/hq ADR 0593 places only mesh-sdk beside a catalogue check, so the node-engine's
|
||||
// repository is absent, not wrong: said aloud, since nothing here could build a composer to judge.
|
||||
t.Skipf("NOT JUDGED: the node-engine's repository (mesh-host) is not beside this check in MESH_CHECK_BESIDE=%s; the running checker places none for the catalogue, so the composer is judged only once it does", beside)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(tree, "cmd", "mesh-compose")); err != nil {
|
||||
t.Fatalf("NOT CHECKED: the node-engine's composer command is not beside this check in MESH_CHECK_BESIDE=%s: %v", beside, err)
|
||||
}
|
||||
entries, err := os.ReadDir(beside)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var roots []string
|
||||
for _, e := range entries {
|
||||
if e.Name() == "mesh-host" || !dirExists(filepath.Join(beside, e.Name())) {
|
||||
continue
|
||||
}
|
||||
root, err := filepath.EvalSymlinks(filepath.Join(beside, e.Name()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
roots = append(roots, root)
|
||||
}
|
||||
// The catalogue under check, first: beside lies its trunk (issue 1295), whose modules a head's must win over.
|
||||
catalogue, err := filepath.Abs(filepath.Join("..", "..", "..", ".."))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, root := range append([]string{catalogue}, roots...) {
|
||||
filepath.WalkDir(root, func(p string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if d.IsDir() && (d.Name() == ".git" || d.Name() == "testdata" || d.Name() == "node_modules") {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if !d.IsDir() && d.Name() == "go.mod" {
|
||||
modules = append(modules, filepath.Dir(p))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
return tree, modules
|
||||
}
|
||||
|
||||
func dirExists(p string) bool { st, err := os.Stat(p); return err == nil && st.IsDir() }
|
||||
|
||||
// copyTree copies the files of a source tree into dst, leaving out its .git.
|
||||
// copyHostTree copies the files of a source tree into dst, leaving out its .git.
|
||||
func copyHostTree(t *testing.T, src, dst string) {
|
||||
t.Helper()
|
||||
src, err := filepath.EvalSymlinks(src)
|
||||
@@ -130,7 +67,7 @@ func goEnvOf(t *testing.T, name string) string {
|
||||
}
|
||||
|
||||
// 1622/AC1, AC3 against the real bus (ADR 0593 §7, C9): a compose ask put on the Go build seat's check stream is pulled by
|
||||
// the module started whole on that bus, which fetches the commit (the node-engine's repository beside the check, its Go module at the root), builds the composer command the ask names there with nothing fetched, fills the
|
||||
// the module started whole on that bus, which fetches the commit (a stand-in composer of this module's testdata, its Go module at the root), builds the composer command the ask names there with nothing fetched, fills the
|
||||
// request's manifests from the indexer's state and runs the composer; the step key <node>.<ask id> passes with the
|
||||
// composer's verdict. A second ask of the same commit runs the kept composer: fetched and built once.
|
||||
func TestAComposeAskIsBuiltOnceAndAnsweredOnTheBus(t *testing.T) {
|
||||
@@ -157,14 +94,11 @@ func TestAComposeAskIsBuiltOnceAndAnsweredOnTheBus(t *testing.T) {
|
||||
m.Run = StepRunner(t.TempDir())
|
||||
m.GoModCache = goEnvOf(t, "GOMODCACHE") // the module cache this module's own build filled, read and not fetched
|
||||
run, gocache := m.Run, goEnvOf(t, "GOCACHE") // this machine's build cache, so the composer's packages compile once
|
||||
hostTree, beside := nodeEngineTree(t)
|
||||
workFile := ""
|
||||
// The composer is a stand-in of this module's own testdata (design 47 G A-474: a module's tests read nothing outside it, and a
|
||||
// pipeline's step places no other repository beside the tree): a program of the composer's contract that imports nothing.
|
||||
hostTree := filepath.Join("testdata", "composer")
|
||||
m.Run = func(ctx context.Context, env []string, name string, args ...string) forgekey.Ran {
|
||||
env = append(env, "GOCACHE="+gocache)
|
||||
if workFile != "" {
|
||||
env = append(env, "GOWORK="+workFile, "GOFLAGS=-mod=readonly") // a workspace takes no -mod=mod
|
||||
}
|
||||
return run(ctx, env, name, args...)
|
||||
return run(ctx, append(env, "GOCACHE="+gocache), name, args...)
|
||||
}
|
||||
read, digests := catalogHolds(t, `{"module":"demo","version":"1"}`)
|
||||
m.ReadEntry = read
|
||||
@@ -181,18 +115,6 @@ func TestAComposeAskIsBuiltOnceAndAnsweredOnTheBus(t *testing.T) {
|
||||
return nil, err
|
||||
}
|
||||
copyHostTree(t, hostTree, tree)
|
||||
if len(beside) > 0 { // the group's other repositories, laid beside the node-engine's tree as one workspace
|
||||
work, err := workspaceOf(tree, beside)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(m.Work, ws, "go.work"), []byte(work), 0o600); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
workFile = filepath.Join(m.Work, ws, "go.work")
|
||||
// Nothing is downloaded here: this level has no network. The check's own fetch downloaded this workspace's
|
||||
// graph (downloadBeside), and a module it lacks fails the build naming it.
|
||||
}
|
||||
return map[string]any{"workspace": ws}, nil
|
||||
}
|
||||
}
|
||||
@@ -203,7 +125,7 @@ func TestAComposeAskIsBuiltOnceAndAnsweredOnTheBus(t *testing.T) {
|
||||
|
||||
ask := func() sdkstep.Step {
|
||||
a := composeAskOf(t, digests[0])
|
||||
a.Compose.Fetch.Repository, a.Compose.Dir, a.Compose.Package = "novox/mesh-host", catalogclient.RootPath, "github.com/novox/mesh-host/cmd/mesh-compose"
|
||||
a.Compose.Fetch.Repository, a.Compose.Dir, a.Compose.Package = "novox/mesh-catalog", catalogclient.RootPath, "standin/cmd/mesh-compose"
|
||||
raw, err := sdkstep.EncodeStepAsk(a)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -273,6 +273,7 @@ func TestAPackageWithTheReadsOutsideMarkerIsKeptOnlyByWhatItLists(t *testing.T)
|
||||
}
|
||||
edit(t, tree, "docs/one.md", "one\n")
|
||||
edit(t, tree, "other.md", "other\n")
|
||||
// Each marker is judged in a fixture of its own, side by side: the digests are go commands, and the table is the test's longest part.
|
||||
for name, marker := range map[string]string{
|
||||
"an empty marker": "# nothing listed\n\n",
|
||||
"a sentence": "the tests read ../docs\n",
|
||||
@@ -282,19 +283,44 @@ func TestAPackageWithTheReadsOutsideMarkerIsKeptOnlyByWhatItLists(t *testing.T)
|
||||
"a path that is not clean": "docs/./one.md\n",
|
||||
"a good line and a bad line": "docs\nnope/*.md\n",
|
||||
} {
|
||||
edit(t, tree, "c/"+ReadsOutsideMarker, marker)
|
||||
first, second := digests(t, m, "unit"), digests(t, m, "unit")
|
||||
if len(first.Packages[c]) != 64 || first.Packages[c] == second.Packages[c] || first.Packages[c] == plain.Packages[c] {
|
||||
t.Errorf("%s: c's digest is stable: %s, %s, before %s", name, first.Packages[c], second.Packages[c], plain.Packages[c])
|
||||
}
|
||||
if strings.Join(first.ReadsOutside, ",") != c {
|
||||
t.Errorf("%s: the answer does not name the package that reads outside: %v", name, first.ReadsOutside)
|
||||
}
|
||||
if first.Packages[a] != plain.Packages[a] || first.Packages[a] != second.Packages[a] {
|
||||
t.Errorf("%s: a has no marker and its digest moved: %s, %s, before %s", name, first.Packages[a], second.Packages[a], plain.Packages[a])
|
||||
}
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m, tree := digestFixture(t)
|
||||
plain := digests(t, m, "unit")
|
||||
if err := os.MkdirAll(filepath.Join(tree, "docs"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
edit(t, tree, "docs/one.md", "one\n")
|
||||
edit(t, tree, "other.md", "other\n")
|
||||
edit(t, tree, "c/"+ReadsOutsideMarker, marker)
|
||||
first, second := digests(t, m, "unit"), digests(t, m, "unit")
|
||||
if len(first.Packages[c]) != 64 || first.Packages[c] == second.Packages[c] || first.Packages[c] == plain.Packages[c] {
|
||||
t.Errorf("%s: c's digest is stable: %s, %s, before %s", name, first.Packages[c], second.Packages[c], plain.Packages[c])
|
||||
}
|
||||
if strings.Join(first.ReadsOutside, ",") != c {
|
||||
t.Errorf("%s: the answer does not name the package that reads outside: %v", name, first.ReadsOutside)
|
||||
}
|
||||
if first.Packages[a] != plain.Packages[a] || first.Packages[a] != second.Packages[a] {
|
||||
t.Errorf("%s: a has no marker and its digest moved: %s, %s, before %s", name, first.Packages[a], second.Packages[a], plain.Packages[a])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// The marker that lists what the package's tests read, and the marker of what the package needs (issue 890/AC3): in a fixture of its
|
||||
// own, so it runs beside the table above.
|
||||
func TestAListedReadsOutsideMarkerKeepsTheDigestOfOnlyWhatItLists(t *testing.T) {
|
||||
t.Parallel()
|
||||
m, tree := digestFixture(t)
|
||||
plain := digests(t, m, "unit")
|
||||
c, a := "fixture/digest/c", "fixture/digest/a"
|
||||
if err := os.MkdirAll(filepath.Join(tree, "docs"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
edit(t, tree, "docs/one.md", "one\n")
|
||||
edit(t, tree, "other.md", "other\n")
|
||||
|
||||
// A list: a glob, a directory read whole, and a path whose absence is read.
|
||||
edit(t, tree, "c/"+ReadsOutsideMarker, "# what c's tests read\ndocs/*.md\ndocs\n?gone\n")
|
||||
before := digests(t, m, "unit")
|
||||
|
||||
@@ -34,7 +34,7 @@ func TestTheGuardSaysToolchainReportedOnAChangeWithTheProgramDigest(t *testing.T
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(got) != 1 || got[0].subject != "mesh.seat.node-build-go.event.toolchain-reported.ace" || got[0].body["node"] != "ace" || got[0].body["language"] != "go" ||
|
||||
got[0].body["version"] != "go1.27.1" || got[0].body["recipe"] != m.Recipe.Version() || len(got[0].body["digest"]) != len("sha256:")+64 {
|
||||
got[0].body["version"] != "go1.27" || got[0].body["recipe"] != m.Recipe.Version() || len(got[0].body["digest"]) != len("sha256:")+64 {
|
||||
t.Fatalf("events = %+v, want one toolchain-reported for ace, go with the program's digest", got)
|
||||
}
|
||||
if tc, _ := states.toolchain("ace.go"); tc.Digest != got[0].body["digest"] {
|
||||
@@ -51,7 +51,7 @@ func TestTheGuardSaysToolchainReportedOnAChangeWithTheProgramDigest(t *testing.T
|
||||
os.WriteFile(prog, []byte("another go program"), 0o755)
|
||||
m.Probe = func(context.Context) (string, error) { return "go1.27.2", nil }
|
||||
m.Check(context.Background())
|
||||
if len(got) != 2 || got[1].body["version"] != "go1.27.2" || got[1].body["digest"] == got[0].body["digest"] {
|
||||
if len(got) != 2 || got[1].body["version"] != "go1.27" || got[1].body["digest"] == got[0].body["digest"] {
|
||||
t.Errorf("a new version said %+v, want a second event with another digest", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,8 +149,8 @@ func TestAnyInstalledGoIsHealthyNamedAndReported(t *testing.T) {
|
||||
t.Errorf("health = %+v, want healthy naming %s", a, installed)
|
||||
}
|
||||
tc, ok := states.toolchain("ace.go")
|
||||
if !ok || tc.Version != installed || tc.Recipe != m.Recipe.Version() {
|
||||
t.Errorf("ace.go = %+v, %v; want version %s and recipe %s", tc, ok, installed, m.Recipe.Version())
|
||||
if !ok || tc.Version != sdkstep.LanguageVersion(installed) || tc.Recipe != m.Recipe.Version() {
|
||||
t.Errorf("ace.go = %+v, %v; want version %s and recipe %s", tc, ok, sdkstep.LanguageVersion(installed), m.Recipe.Version())
|
||||
}
|
||||
ran := false
|
||||
run := func(context.Context, map[string]any) (any, error) { ran = true; return "done", nil }
|
||||
|
||||
@@ -186,6 +186,7 @@ func TestABuildRunsShutOffAndOnlyATrunkBuildWritesTheCaches(t *testing.T) {
|
||||
|
||||
// 1309-S3: the digest's go list runs shut off.
|
||||
func TestTheDigestListsPackagesShutOff(t *testing.T) {
|
||||
t.Parallel()
|
||||
m, _ := digestFixture(t)
|
||||
var seen []shutOff
|
||||
m.Run = throughBubblewrap(t, m.Run, &seen)
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
// resolves no name, reaches no socket of the machine (a TCP port on its loopback, a unix socket) and leaves the shared
|
||||
// caches unchanged. The probe is testdata/repos/probe.
|
||||
func TestARunStepReachesNoKeyLoginNameOrSocketAndLeavesTheCachesUnchanged(t *testing.T) {
|
||||
t.Parallel()
|
||||
needTools(t, "the shut-off unit level", "go", "git", "bwrap")
|
||||
tree := repository(t, "probe")
|
||||
work, err := os.MkdirTemp("", "w")
|
||||
|
||||
@@ -195,6 +195,16 @@ func TestTheModuleInvokesTheArtifactSeatsVerbsAndWritesNoStore(t *testing.T) {
|
||||
if !slices.Contains(m.Consumes, "mesh-conditions.findings-asked") {
|
||||
t.Errorf("consumes %v lack mesh-conditions.findings-asked", m.Consumes)
|
||||
}
|
||||
// Design 47 G A-488a, A-488b: its runtime follows the seat list, so the module consumes the seat's two events (which makes its
|
||||
// durable consumer) and invokes the verb that reads the list.
|
||||
for _, ev := range []string{"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed"} {
|
||||
if !slices.Contains(m.Consumes, ev) {
|
||||
t.Errorf("consumes %v lack %s", m.Consumes, ev)
|
||||
}
|
||||
}
|
||||
if !slices.Contains(m.Invokes, "seat:mesh-catalog.seat-definitions") {
|
||||
t.Errorf("invokes %v lack seat:mesh-catalog.seat-definitions", m.Invokes)
|
||||
}
|
||||
// Not a foundation part, it asks its finding stream in requires, by the template events (design 47 G §529, A-30), and
|
||||
// declares no stream of that name.
|
||||
for _, st := range m.Streams {
|
||||
|
||||
@@ -158,6 +158,7 @@ func sleepABit() { time.Sleep(30 * time.Millisecond) }
|
||||
// The workspace is self-contained after the fetch: no alternates file, and git finds the commit with the mirror gone,
|
||||
// as a step shut off with the workspace alone needs. Real git, a local repository as the forge.
|
||||
func TestTheWorkspaceIsSelfContainedAfterAFetchThroughTheMirror(t *testing.T) {
|
||||
t.Parallel()
|
||||
if _, err := exec.LookPath("git"); err != nil {
|
||||
t.Skip("no git")
|
||||
}
|
||||
|
||||
@@ -93,8 +93,8 @@ func TestStartWritesTheToolchainAndHealthIsHealthy(t *testing.T) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if tc.Version != "go1.27.1" || tc.Recipe != m.Recipe.Version() || tc.Language != "go" {
|
||||
t.Fatalf("ace.go = %+v, want go1.27.1 and recipe %s", tc, m.Recipe.Version())
|
||||
if tc.Version != "go1.27" || tc.Recipe != m.Recipe.Version() || tc.Language != "go" {
|
||||
t.Fatalf("ace.go = %+v, want go1.27 and recipe %s", tc, m.Recipe.Version())
|
||||
}
|
||||
if a := m.Health(ctx); a.State != health.StateHealthy || !a.Healthy {
|
||||
t.Errorf("health = %+v, want healthy", a)
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
// build_go_fetch is asked that head as the package's version and build_go_build runs on the member, then both pass, the
|
||||
// build with GOPROXY=off against the head: the older commit holds no Go package at all.
|
||||
func TestRealFetchAndBuildOfAMemberAskedAPullHeadItsGoModDoesNotName(t *testing.T) {
|
||||
t.Parallel()
|
||||
// Not skipped when a tool is missing: a pass of the check must mean this test ran (the check prints no test log).
|
||||
for _, tool := range []string{"go", "git"} {
|
||||
if _, err := exec.LookPath(tool); err != nil {
|
||||
|
||||
@@ -304,6 +304,7 @@ func TestARelativeReplaceStillResolvesInTheTemporaryModfile(t *testing.T) {
|
||||
// the asked versions, else from the trunk's latest published version, and never looked for as the commit 000000000000
|
||||
// among the pull request heads.
|
||||
func TestARequirementAtTheZeroVersionIsTakenFromTheAskOrTheTrunk(t *testing.T) {
|
||||
t.Parallel()
|
||||
const sdk = "git.novox.be/novox/mesh-sdk/go"
|
||||
zeroMod := "module fixture/member\n\ngo 1.26\n\nrequire (\n\t" + sdk + " v0.0.0-00010101000000-" + zeroShort + "\n)\n"
|
||||
trunk := strings.Repeat("a", 40)
|
||||
|
||||
@@ -171,6 +171,7 @@ func TestRealFetchMergesConflictsAndPlainlyFetches(t *testing.T) {
|
||||
// sibling and passes with it; the sibling is a plain directory with no symlink in it; and a sibling that holds a
|
||||
// symlink fails the fetch naming it.
|
||||
func TestRealTestsReadTheSiblingBesideTheTree(t *testing.T) {
|
||||
t.Parallel()
|
||||
needTools(t, "the shut-off unit level", "go", "git", "bwrap") // the tests run in bubblewrap (1309)
|
||||
f := newForge(t)
|
||||
files := map[string]string{}
|
||||
|
||||
@@ -118,6 +118,7 @@ func resolve(t *testing.T, addr string, a builds.BuiltArtifact) []byte {
|
||||
// reference resolves in a real artifact store to bytes of that digest. The build is the real go's, shut off, of the
|
||||
// fixture testdata/repos/build, with an archive beside its bundle.
|
||||
func TestADoneBuildsArtifactsResolveInARealArtifactStore(t *testing.T) {
|
||||
t.Parallel()
|
||||
needTools(t, "the build", "go", "bwrap")
|
||||
work := t.TempDir()
|
||||
tree := filepath.Join(work, "ws1", "tree")
|
||||
|
||||
@@ -62,6 +62,7 @@ func repository(t *testing.T, name string) string {
|
||||
// test_test.go read the output captured from them, and this one proves the capture is what the real go says today. It
|
||||
// starts go test, so it carries the tag.
|
||||
func TestUnitLevelRunsTheRealGoOnTheFixtureRepositories(t *testing.T) {
|
||||
t.Parallel()
|
||||
needTools(t, "the unit level on fixtures", "go", "git", "bwrap")
|
||||
want := map[string]struct {
|
||||
passed, noTests bool
|
||||
@@ -104,6 +105,7 @@ func TestUnitLevelRunsTheRealGoOnTheFixtureRepositories(t *testing.T) {
|
||||
// 086 A-C3 against the real go (design 47 line 571 at b229f5c4): a tree holding an unformatted file passes its unit
|
||||
// level, its two tests run, and the lint step's body fails naming the file.
|
||||
func TestAnUnformattedFileFailsTheRealLintStepAndNotTheUnitLevel(t *testing.T) {
|
||||
t.Parallel()
|
||||
needTools(t, "the unit level's gofmt and vet", "go", "git", "bwrap")
|
||||
home := t.TempDir()
|
||||
m := &Module{Home: home, Work: t.TempDir(), Cache: t.TempDir()}
|
||||
@@ -150,7 +152,7 @@ func TestIntegrationLevelRunsAgainstARealStoreAndBusAndLeavesNothing(t *testing.
|
||||
needTools(t, "the integration level", "go", "git", "initdb", "pg_ctl", "postgres", "bwrap")
|
||||
tree := repository(t, "store")
|
||||
// A short work directory: a unix socket's path is bounded at 108 bytes.
|
||||
work, err := os.MkdirTemp("/tmp", "w")
|
||||
work, err := os.MkdirTemp(os.TempDir(), "w")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -185,6 +187,7 @@ func TestIntegrationLevelRunsAgainstARealStoreAndBusAndLeavesNothing(t *testing.
|
||||
// 1487/AC2: given a fixture Go module, when it is built twice, both digests are equal and the archive holds one
|
||||
// executable named as binaryName says. It runs the real go, so it carries the tag.
|
||||
func TestBuildTwiceGivesOneDigestAndOneExecutable(t *testing.T) {
|
||||
t.Parallel()
|
||||
needTools(t, "the build", "go", "bwrap")
|
||||
work := t.TempDir()
|
||||
tree := filepath.Join(work, "ws1", "tree")
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
// Command mesh-compose is the stand-in composer the compose ask's test builds: a program of the contract the Go build module
|
||||
// runs (`-request <file>`, the last line of its standard output a composer verdict of version 1), which judges nothing and
|
||||
// answers each case of the request by its name, with no manifest and no machine. It imports nothing of the mesh.
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
file := flag.String("request", "", "the request file")
|
||||
flag.Parse()
|
||||
raw, err := os.ReadFile(*file)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var req struct {
|
||||
Cases []struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"cases"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &req); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
type verdict struct {
|
||||
Name string `json:"name"`
|
||||
Manifests map[string]any `json:"manifests"`
|
||||
}
|
||||
out := struct {
|
||||
V int `json:"v"`
|
||||
SDK string `json:"sdk"`
|
||||
Cases []verdict `json:"cases"`
|
||||
}{V: 1, SDK: "stand-in"}
|
||||
for _, c := range req.Cases {
|
||||
out.Cases = append(out.Cases, verdict{Name: c.Name, Manifests: map[string]any{}})
|
||||
}
|
||||
line, _ := json.Marshal(out)
|
||||
fmt.Println(string(line))
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module standin
|
||||
|
||||
go 1.26
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
// group's head Go cannot fetch is placed from the forge's pull request heads; a go.mod that does not require the package
|
||||
// takes nothing.
|
||||
func TestAnAskedVersionIsWrittenIntoTheModfileWhateverGoModNames(t *testing.T) {
|
||||
t.Parallel()
|
||||
const sdk = "git.novox.be/novox/mesh-sdk/go"
|
||||
trunk := strings.Repeat("a", 40)
|
||||
offHead := strings.Repeat("b", 40) // a commit no pull request's head carries
|
||||
|
||||
@@ -33,7 +33,9 @@
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"mesh-conditions.findings-asked"
|
||||
"mesh-conditions.findings-asked",
|
||||
"mesh-catalog.seat-definition-changed",
|
||||
"mesh-catalog.seat-definition-removed"
|
||||
],
|
||||
"invokes": [
|
||||
"seat:mesh-hand-acts.hand-act",
|
||||
@@ -46,6 +48,7 @@
|
||||
"seat:mesh-wants.input",
|
||||
"seat:mesh-module-assigner.assignments",
|
||||
"seat:mesh-catalog.module",
|
||||
"seat:mesh-catalog.seat-definitions",
|
||||
"seat:mesh-catalog.entry"
|
||||
],
|
||||
"config": {
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestTheModuleInvokesTheImageSeatAndHoldsNoRegistry(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want := []string{"seat:mesh-hand-acts.hand-act", "seat:container-image-registry.publish", "seat:container-image-registry.publish-part",
|
||||
"seat:container-image-registry.mirror", "seat:mesh-module-assigner.assignments", "seat:mesh-catalog.module"}; !slices.Equal(m.Invokes, want) {
|
||||
"seat:container-image-registry.mirror", "seat:mesh-module-assigner.assignments", "seat:mesh-catalog.module", "seat:mesh-catalog.seat-definitions"}; !slices.Equal(m.Invokes, want) {
|
||||
t.Errorf("invokes = %v, want %v", m.Invokes, want)
|
||||
}
|
||||
// The seat's outcomes a copy waits on; the version comes in the ask, so version.numbered is not heard (design 47 G §413).
|
||||
@@ -32,6 +32,7 @@ func TestTheModuleInvokesTheImageSeatAndHoldsNoRegistry(t *testing.T) {
|
||||
for _, e := range OutcomeEvents {
|
||||
consumes = append(consumes, "container-image-registry."+e)
|
||||
}
|
||||
consumes = append(consumes, "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed") // the seat list, A-488a
|
||||
if !slices.Equal(m.Consumes, consumes) {
|
||||
t.Errorf("consumes = %v, want %v", m.Consumes, consumes)
|
||||
}
|
||||
|
||||
@@ -113,6 +113,16 @@ func TestWorkAndStoreDirectoriesLieOutsideTheHome(t *testing.T) {
|
||||
// and the registry's address is bound into a file of the home that the program reads.
|
||||
func TestManifestKeepsItsStatesClaimsItsBuildSeatAndDeclaresItsHealthTool(t *testing.T) {
|
||||
m := readManifest(t)
|
||||
// Design 47 G A-488a, A-488b: its runtime follows the seat list, so the module consumes the seat's two events (which makes its
|
||||
// durable consumer) and invokes the verb that reads the list.
|
||||
for _, ev := range []string{"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed"} {
|
||||
if !slices.Contains(m.Consumes, ev) {
|
||||
t.Errorf("consumes %v lack %s", m.Consumes, ev)
|
||||
}
|
||||
}
|
||||
if !slices.Contains(m.Invokes, "seat:mesh-catalog.seat-definitions") {
|
||||
t.Errorf("invokes %v lack seat:mesh-catalog.seat-definitions", m.Invokes)
|
||||
}
|
||||
states := []string{}
|
||||
for _, s := range m.State {
|
||||
states = append(states, s.Name)
|
||||
|
||||
@@ -68,11 +68,14 @@
|
||||
"seat:container-image-registry.publish-part",
|
||||
"seat:container-image-registry.mirror",
|
||||
"seat:mesh-module-assigner.assignments",
|
||||
"seat:mesh-catalog.module"
|
||||
"seat:mesh-catalog.module",
|
||||
"seat:mesh-catalog.seat-definitions"
|
||||
],
|
||||
"consumes": [
|
||||
"container-image-registry.published",
|
||||
"container-image-registry.refused"
|
||||
"container-image-registry.refused",
|
||||
"mesh-catalog.seat-definition-changed",
|
||||
"mesh-catalog.seat-definition-removed"
|
||||
],
|
||||
"own-secrets": {
|
||||
"broker": "${dir:state}/broker"
|
||||
|
||||
@@ -34,7 +34,7 @@ func TestTheGuardSaysToolchainReportedOnAChangeWithTheProgramDigest(t *testing.T
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(got) != 1 || got[0].subject != "mesh.seat.node-build-node.event.toolchain-reported.ace" || got[0].body["node"] != "ace" || got[0].body["language"] != "typescript" ||
|
||||
got[0].body["version"] != "v26.10.0" || got[0].body["recipe"] != m.Recipe.Version() || len(got[0].body["digest"]) != len("sha256:")+64 {
|
||||
got[0].body["version"] != "v26.10" || got[0].body["recipe"] != m.Recipe.Version() || len(got[0].body["digest"]) != len("sha256:")+64 {
|
||||
t.Fatalf("events = %+v, want one toolchain-reported for ace, go with the program's digest", got)
|
||||
}
|
||||
if tc, _ := states.toolchain("ace.typescript"); tc.Digest != got[0].body["digest"] {
|
||||
@@ -51,7 +51,7 @@ func TestTheGuardSaysToolchainReportedOnAChangeWithTheProgramDigest(t *testing.T
|
||||
os.WriteFile(prog, []byte("another node program"), 0o755)
|
||||
m.Probe = func(context.Context) (string, error) { return "v26.11.0", nil }
|
||||
m.Check(context.Background())
|
||||
if len(got) != 2 || got[1].body["version"] != "v26.11.0" || got[1].body["digest"] == got[0].body["digest"] {
|
||||
if len(got) != 2 || got[1].body["version"] != "v26.11" || got[1].body["digest"] == got[0].body["digest"] {
|
||||
t.Errorf("a new version said %+v, want a second event with another digest", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-sdk/go/health"
|
||||
)
|
||||
|
||||
@@ -36,8 +37,8 @@ func TestAnyInstalledNodeIsHealthyNamedAndReported(t *testing.T) {
|
||||
t.Errorf("health = %+v, want healthy naming %s", a, installed)
|
||||
}
|
||||
tc, ok := states.toolchain("ace.typescript")
|
||||
if !ok || tc.Version != installed || tc.Recipe != m.Recipe.Version() {
|
||||
t.Errorf("ace.typescript = %+v, %v; want version %s and recipe %s", tc, ok, installed, m.Recipe.Version())
|
||||
if !ok || tc.Version != sdkstep.LanguageVersion(installed) || tc.Recipe != m.Recipe.Version() {
|
||||
t.Errorf("ace.typescript = %+v, %v; want version %s and recipe %s", tc, ok, sdkstep.LanguageVersion(installed), m.Recipe.Version())
|
||||
}
|
||||
if err := m.Prepare(context.Background()); err != nil {
|
||||
t.Errorf("no step can run on node %s: %v", installed, err)
|
||||
|
||||
@@ -277,6 +277,17 @@ func TestTheModuleRequiresNodeToolsItPullsThrough(t *testing.T) {
|
||||
if !slices.Contains(m.Requires, "node-tools") {
|
||||
t.Errorf("requires %v lack node-tools", m.Requires)
|
||||
}
|
||||
// Design 47 G A-488a: its runtime follows the seat list (seatlist.Start subscribes to the seat mesh-catalog's events), so the
|
||||
// module consumes both, which makes its durable consumer <node>_mesh-build-node_tools: with none, the seat list is never
|
||||
// read and the asks of a named asker are given back for ever.
|
||||
for _, ev := range []string{"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed"} {
|
||||
if !slices.Contains(m.Consumes, ev) {
|
||||
t.Errorf("consumes %v lack %s", m.Consumes, ev)
|
||||
}
|
||||
}
|
||||
if !slices.Contains(m.Invokes, "seat:mesh-catalog.seat-definitions") {
|
||||
t.Errorf("invokes %v lack seat:mesh-catalog.seat-definitions (A-488b)", m.Invokes)
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 G A-254, A-313, A-314: the module keeps a run's answer over what step-ended carries inline in the steps state's own
|
||||
|
||||
@@ -94,8 +94,8 @@ func TestStartWritesTheToolchainAndHealthIsHealthy(t *testing.T) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if tc.Version != "v26.10.0" || tc.Recipe != m.Recipe.Version() || tc.Language != "typescript" {
|
||||
t.Fatalf("ace.typescript = %+v, want v26.10.0 and recipe %s", tc, m.Recipe.Version())
|
||||
if tc.Version != "v26.10" || tc.Recipe != m.Recipe.Version() || tc.Language != "typescript" {
|
||||
t.Fatalf("ace.typescript = %+v, want v26.10 and recipe %s", tc, m.Recipe.Version())
|
||||
}
|
||||
if a := m.Health(ctx); a.State != health.StateHealthy || !a.Healthy {
|
||||
t.Errorf("health = %+v, want healthy", a)
|
||||
|
||||
@@ -24,6 +24,10 @@
|
||||
"serves": ["current", "drop", "pause", "resume", "steps", "kept-artifact", "output"]
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"mesh-catalog.seat-definition-changed",
|
||||
"mesh-catalog.seat-definition-removed"
|
||||
],
|
||||
"config": {
|
||||
"capacity": {
|
||||
"type": "number",
|
||||
@@ -76,7 +80,8 @@
|
||||
"seat:npm-package-registry.publish",
|
||||
"seat:npm-package-registry.publish-part",
|
||||
"seat:mesh-module-assigner.assignments",
|
||||
"seat:mesh-catalog.module"
|
||||
"seat:mesh-catalog.module",
|
||||
"seat:mesh-catalog.seat-definitions"
|
||||
],
|
||||
"own-secrets": {
|
||||
"broker": "${dir:state}/broker"
|
||||
|
||||
@@ -71,6 +71,8 @@ type ForgeReads interface {
|
||||
Pull(repository string, number int64) (gitseat.PullAnswer, error)
|
||||
// Branch is a repository branch's head (the seat git's verb branch).
|
||||
Branch(repository, branch string) (gitseat.BranchAnswer, error)
|
||||
// Contains is whether commit is in (or is) the commit in (the seat git's verb contains).
|
||||
Contains(repository, commit, in string) (bool, error)
|
||||
}
|
||||
|
||||
// kvKept is the store over the runtime.
|
||||
|
||||
@@ -42,7 +42,9 @@ type fakeForge struct {
|
||||
open []gitseat.OpenPull
|
||||
pulls map[string]gitseat.Pull
|
||||
heads map[string]string // "<repository>@<branch>" -> head
|
||||
fail bool
|
||||
// contains says whether commit is in `in`; nil means every commit is in every other (a straight line forward)
|
||||
contains func(commit, in string) bool
|
||||
fail bool
|
||||
}
|
||||
|
||||
func (f *fakeForge) OpenPulls() (gitseat.OpenPullsAnswer, error) {
|
||||
@@ -61,6 +63,15 @@ func (f *fakeForge) Branch(repository, branch string) (gitseat.BranchAnswer, err
|
||||
}
|
||||
return gitseat.BranchAnswer{Branch: branch, Repository: repository, Head: head}, nil
|
||||
}
|
||||
func (f *fakeForge) Contains(repository, commit, in string) (bool, error) {
|
||||
if f.fail {
|
||||
return false, errors.New("the forge is away")
|
||||
}
|
||||
if f.contains == nil {
|
||||
return true, nil
|
||||
}
|
||||
return f.contains(commit, in), nil
|
||||
}
|
||||
func (f *fakeForge) Pull(repository string, number int64) (gitseat.PullAnswer, error) {
|
||||
p, ok := f.pulls[fmt.Sprintf("%s#%d", repository, number)]
|
||||
if !ok {
|
||||
|
||||
@@ -44,7 +44,7 @@ type FindingWriter interface {
|
||||
// generated contract of the seat that defines it (A-17). It is started once the runtime serves (A-40).
|
||||
func NewFindingWriter() (*views.HeldWriter[meshconditions.Finding, meshconditions.FindingCleared, meshconditions.FindingsStated, meshconditions.FindingsAskedEvent], error) {
|
||||
return views.NewStdioHeldWriter(views.WriterConfig[meshconditions.Finding, meshconditions.FindingCleared, meshconditions.FindingsStated, meshconditions.FindingsAskedEvent]{
|
||||
Asked: meshconditions.SubjectFindingsAsked, Module: Module, State: stdio.State("findings"), Kinds: []string{ApprovalCarriedOpen}})
|
||||
Asked: meshconditions.SubjectFindingsAsked, Module: Module, State: stdio.State("findings"), Kinds: []string{ApprovalCarriedOpen, SourceUncompared}})
|
||||
}
|
||||
|
||||
// approvalID is the id of a pull request's finding: its repository and number, each escaped as a key's name is.
|
||||
|
||||
@@ -32,7 +32,7 @@ func (l *listening) get() string { l.mu.Lock(); defer l.mu.Unlock(); return l.n
|
||||
|
||||
// The events this owner follows: the forge bridge's word on an act owed, and the step events the delivery records are built
|
||||
// from (consumer.go).
|
||||
var followed = append(append([]string{owedEndedEvent}, stepPatterns()...), pullUpdatedEvent, pullMergedEvent, pullClosedEvent, registrationChangedEvent)
|
||||
var followed = append(append([]string{owedEndedEvent}, stepPatterns()...), pullUpdatedEvent, pullMergedEvent, pullClosedEvent, registrationChangedEvent, forgeMergedEvent)
|
||||
|
||||
func main() {
|
||||
settingsFile := os.Getenv("MESH_DELIVERY_GATE_SETTINGS")
|
||||
@@ -118,7 +118,13 @@ func run(h *Holder, l *listening) {
|
||||
l.set("listening")
|
||||
logf("[mesh-delivery] listening: %s", strings.Join(followed, ", "))
|
||||
// A watched branch no source key holds starts from the forge, once at each start and at each registration change (A-401).
|
||||
go startSourcesAtStart(h)
|
||||
// then each head is compared with the forge's, and a merge made outside the gate is followed (A-464).
|
||||
go func() {
|
||||
startSourcesAtStart(h)
|
||||
if _, err := h.FollowAtStart(); err != nil {
|
||||
logf("[mesh-delivery] the sources were not all compared with the forge's heads: %v", err)
|
||||
}
|
||||
}()
|
||||
// A missed pull event is put right from the forge's own record, once at each start (§716).
|
||||
if err := h.ReadForge(); err != nil {
|
||||
logf("[mesh-delivery] the open pull requests were not read from the forge, they are read again at the next start: %v", err)
|
||||
@@ -179,6 +185,9 @@ func take(h *Holder, e stdio.Envelope) error {
|
||||
_, err := h.StartSources()
|
||||
return err
|
||||
}
|
||||
if forgeMergedEvent != "" && stdio.TopicMatches(forgeMergedEvent, e.Key) {
|
||||
return h.ForgeMerged(e.Body)
|
||||
}
|
||||
if e.Key == pullClosedEvent {
|
||||
return errors.Join(h.DeliveryClosed(e.Body), h.pullEnded(e.Body, "closed"))
|
||||
}
|
||||
|
||||
@@ -134,13 +134,16 @@ func TestItClaimsTheDeliverySeatAndFollowsWhatItHandles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// From G's delivery the gate hears neither the bridge's merged and pushed messages nor the teller's answers nor the view's
|
||||
// reach (design 47 G §592, §593): it consumes the indexer's take-in.taken and the bridge's owed.ended, and the git events that clear
|
||||
// From G's delivery the gate hears neither the bridge's pushed messages nor the teller's answers nor the view's reach
|
||||
// (design 47 G §592, §593); it hears the bridge's merged message alone, to follow every merge (A-464): it consumes the indexer's take-in.taken and the bridge's owed.ended, and the git events that clear
|
||||
// an approval carried.
|
||||
if want := append(slices.Clone(followed), meshconditions.Seat+"."+meshconditions.EventFindingsAsked); !reflect.DeepEqual(m.Consumes, want) {
|
||||
t.Fatalf("consumes %v, follows %v", m.Consumes, followed)
|
||||
}
|
||||
for _, c := range m.Consumes {
|
||||
if c == forgeMergedEvent {
|
||||
continue // A-464: the source follows every merge, so the gate hears the forge bridge's merged message, and it alone
|
||||
}
|
||||
for _, gone := range []string{".forge.", "teller", "view", "forge-pull", "forge-status"} {
|
||||
if strings.Contains(c, gone) {
|
||||
t.Errorf("the manifest still consumes %s, which G's gate does not hear (§431, §592, §593)", c)
|
||||
|
||||
@@ -0,0 +1,278 @@
|
||||
package main
|
||||
|
||||
// The gate's source of a watched branch follows every merge into that branch, whoever made it (design 47 G A-464, A-464b, amending
|
||||
// A-463): on the forge bridge's `merged` of a repository the source names, at the branch the source watches, the gate moves that
|
||||
// repository's head to the merge and says source-moved, as a take-in moves it; at its start it compares each head with the
|
||||
// forge's branch head, asked of the seat git, and moves every one behind it the same way, so a merge whose message was lost is
|
||||
// followed too; gate_source_follow does the same for one repository now. A head the source does not name, or a branch it does
|
||||
// not watch, is left: only a start or a registration change adds them (sourcestart.go).
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
)
|
||||
|
||||
// forgeMergedEvent is the forge bridge's merged message of any repository, as the manifest consumes it.
|
||||
var forgeMergedEvent = declared("forge.*.*.merged")
|
||||
|
||||
// moveHead moves the head the branch's source names for repository to head, and says source-moved with the key's revision. It
|
||||
// answers false, and writes nothing, when the branch has no source key, the key does not name the repository or names the head
|
||||
// already. group is the group that made the merge, empty for a merge no group of the gate made.
|
||||
func (h *Holder) moveHead(branch, repository, head, group string) (moved bool, err error) {
|
||||
if h.Source == nil || head == "" {
|
||||
return false, nil
|
||||
}
|
||||
held, _, err := h.Source.Read(branch)
|
||||
if err != nil || held == nil {
|
||||
return false, err
|
||||
}
|
||||
name := ""
|
||||
for r := range held.Heads {
|
||||
if trunk.SameRepository(r, repository) {
|
||||
name = r
|
||||
}
|
||||
}
|
||||
if name == "" || held.Heads[name] == head {
|
||||
return false, nil // not named, or no change: no revision and no source-moved (A-464c)
|
||||
}
|
||||
was := held.Heads[name]
|
||||
// Only forward (A-464c): the head held must be contained in the merge, asked of the seat git.
|
||||
if h.Forge == nil {
|
||||
return false, errors.New("this gate reads no forge, so it cannot tell whether the merge is ahead of the head")
|
||||
}
|
||||
ahead, err := h.Forge.Contains(name, was, head)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("whether %.12s is in %.12s of %s cannot be read, so the head stays: %w", was, head, name, err)
|
||||
}
|
||||
if !ahead {
|
||||
h.logf("[mesh-delivery] source.%s keeps %s at %.12s: the merge %.12s does not contain it (heard again, late or out of order), left without effect", branch, name, was, head)
|
||||
return false, nil
|
||||
}
|
||||
rev, err := h.Source.Set(branch, func(prev *Source) (Source, bool) {
|
||||
moved = false
|
||||
if prev == nil || prev.Heads[name] != was {
|
||||
return Source{}, false // another writer moved it first
|
||||
}
|
||||
next := Source{Group: group, Heads: map[string]string{}}
|
||||
for r, c := range prev.Heads {
|
||||
next.Heads[r] = c
|
||||
}
|
||||
next.Heads[name] = head
|
||||
moved = true
|
||||
return next, true
|
||||
})
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("source.%s cannot be moved: %w", branch, err)
|
||||
}
|
||||
if !moved || h.SaySeat == nil {
|
||||
return moved, nil
|
||||
}
|
||||
at := h.Now().UTC()
|
||||
return true, h.SaySeat(seat.SubjectSourceMoved(keys.EscapeName(branch)),
|
||||
seat.SourceMovedEvent{Branch: branch, Group: group, Revision: int64(rev), At: &at},
|
||||
"source-moved."+keys.EscapeName(branch)+"."+strconv.FormatUint(rev, 10))
|
||||
}
|
||||
|
||||
// ForgeMerged takes one merged message of the forge bridge: the head of its repository in the source of the branch it landed on
|
||||
// moves to the merge. A merge no delivery group made (the message names no group) is said so. A message that cannot be read, or
|
||||
// names no branch or merge, is said and taken: heard again it would be refused again.
|
||||
func (h *Holder) ForgeMerged(body json.RawMessage) error {
|
||||
f, err := forgemsg.DecodeForge(body)
|
||||
if err != nil {
|
||||
h.logf("[mesh-delivery] a merged message of the forge bridge is not readable, the source does not follow it: %v", err)
|
||||
return nil
|
||||
}
|
||||
if f.Kind != forgemsg.ForgeMerged {
|
||||
return nil
|
||||
}
|
||||
if f.Base == "" || f.Merge == "" {
|
||||
h.logf("[mesh-delivery] the merged message of %s names no branch or no merge, the source does not follow it", f.Repository)
|
||||
return nil
|
||||
}
|
||||
moved, err := h.moveHead(f.Base, f.Repository, f.Merge, f.Group)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if moved {
|
||||
if f.Group == "" { // A-464b: a merge whose message names no delivery group is one the gate did not make
|
||||
h.logf("[mesh-delivery] source.%s follows the merge %.12s of %s: not made by a delivery group of the gate", f.Base, f.Merge, f.Repository)
|
||||
} else {
|
||||
h.logf("[mesh-delivery] source.%s follows the merge %.12s of %s, made by the delivery group %s", f.Base, f.Merge, f.Repository, f.Group)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SourceUncompared is the finding of a start comparison that left a head uncompared (A-464e).
|
||||
const SourceUncompared = "source-uncompared"
|
||||
|
||||
// FollowAtStart compares each head of every source key with the forge's head of that branch and moves every one behind it, at
|
||||
// each start. It ends only when every head was compared (A-464e): a head the forge could not be asked for (the seat git not
|
||||
// answering yet, as when its bundle starts in the same tool runner) is compared again after a growing pause of at most a
|
||||
// minute, and the finding source-uncompared names the repositories and the last error while any stands. It answers the heads
|
||||
// moved as "<repository>@<branch>".
|
||||
func (h *Holder) FollowAtStart() ([]string, error) {
|
||||
if h.Source == nil || h.Forge == nil {
|
||||
return nil, errors.New("this gate keeps no source or reads no forge")
|
||||
}
|
||||
var moved []string
|
||||
var only map[string]bool
|
||||
for wait := 2 * time.Second; ; wait = min(wait*2, time.Minute) {
|
||||
got, left := h.followPass(only)
|
||||
moved = append(moved, got...)
|
||||
if len(left) == 0 {
|
||||
h.clearUncompared()
|
||||
h.logf("[mesh-delivery] the sources compared with the forge's heads at the start: moved %v", moved)
|
||||
return moved, nil
|
||||
}
|
||||
only = map[string]bool{}
|
||||
var names []string
|
||||
var last error
|
||||
for n, err := range left {
|
||||
only[n] = true
|
||||
names = append(names, n)
|
||||
last = err
|
||||
}
|
||||
sort.Strings(names)
|
||||
h.sayUncompared(names, last)
|
||||
h.logf("[mesh-delivery] %d heads are not compared with the forge's yet (%s; last: %v); asking again in %s", len(names), strings.Join(names, ", "), last, wait)
|
||||
startSleep(wait)
|
||||
}
|
||||
}
|
||||
|
||||
// followPass compares the heads named in only (every head when nil) once; it answers the heads moved and, by "<repository>@<branch>",
|
||||
// each head it could not compare with why. A source it cannot list or read is one entry named for itself.
|
||||
func (h *Holder) followPass(only map[string]bool) (moved []string, left map[string]error) {
|
||||
left = map[string]error{}
|
||||
branches, err := h.Source.Branches()
|
||||
if err != nil {
|
||||
left["the branches of the source"] = err
|
||||
return nil, left
|
||||
}
|
||||
for _, branch := range branches {
|
||||
held, _, err := h.Source.Read(branch)
|
||||
if err != nil {
|
||||
left["source."+branch] = err
|
||||
continue
|
||||
}
|
||||
if held == nil {
|
||||
continue
|
||||
}
|
||||
for repository, head := range held.Heads {
|
||||
name := repository + "@" + branch
|
||||
if only != nil && !only[name] {
|
||||
continue
|
||||
}
|
||||
ok, err := h.followForge(branch, repository, head)
|
||||
if err != nil {
|
||||
left[name] = err
|
||||
continue
|
||||
}
|
||||
if ok {
|
||||
moved = append(moved, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return moved, left
|
||||
}
|
||||
|
||||
func (h *Holder) sayUncompared(names []string, last error) {
|
||||
if h.Findings == nil {
|
||||
return
|
||||
}
|
||||
at := h.Now().UTC()
|
||||
err := h.Findings.Write(context.Background(), meshconditions.Finding{Scope: FindingScope, ID: SourceUncompared, Kind: SourceUncompared,
|
||||
Subject: meshconditions.Subject{Scope: FindingScope, ID: SourceUncompared},
|
||||
Severity: meshconditions.FindingSeverityWarning, Resolver: "operator",
|
||||
Summary: fmt.Sprintf("the gate's source is not compared with the forge's head for %s; the last error: %v", strings.Join(names, ", "), last),
|
||||
Headline: "The gate's source is not compared with the forge",
|
||||
Explanation: "At its start the gate compares each head of its source with the forge's head of the branch. A head it could not compare is asked again after a growing pause, and this clears once every head is compared.",
|
||||
Needs: "the seat git answering; gate_source_follow moves one repository's head by hand.",
|
||||
Source: SourceUncompared, Observer: Module, At: at, Since: at})
|
||||
if err != nil {
|
||||
h.logf("[mesh-delivery] the finding %s is not written: %v", SourceUncompared, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Holder) clearUncompared() {
|
||||
if h.Findings == nil {
|
||||
return
|
||||
}
|
||||
for _, f := range h.Findings.Held() {
|
||||
if f.Scope == FindingScope && f.ID == SourceUncompared && f.Kind == SourceUncompared {
|
||||
if err := h.Findings.Clear(context.Background(), FindingScope, SourceUncompared, SourceUncompared, "every head is compared with the forge's"); err != nil {
|
||||
h.logf("[mesh-delivery] the finding %s is not cleared: %v", SourceUncompared, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// followForge moves one repository's head in a branch's source to the forge's head of the branch when they differ.
|
||||
func (h *Holder) followForge(branch, repository, held string) (bool, error) {
|
||||
a, err := h.Forge.Branch(repository, branch)
|
||||
if err == nil && a.Error != "" {
|
||||
err = errors.New(a.Error)
|
||||
}
|
||||
if err == nil && a.Head == "" {
|
||||
err = errors.New("the forge named no head")
|
||||
}
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if sameCommit(held, a.Head) && len(held) == len(a.Head) {
|
||||
return false, nil
|
||||
}
|
||||
moved, err := h.moveHead(branch, repository, a.Head, "")
|
||||
if moved {
|
||||
h.logf("[mesh-delivery] source.%s follows the forge: %s from %.12s to %.12s", branch, repository, held, a.Head)
|
||||
}
|
||||
return moved, err
|
||||
}
|
||||
|
||||
// SourceFollow moves one repository's head to the forge's head of the branch by hand, after the hand-act log took it.
|
||||
func (h *Holder) SourceFollow(branch, repository, why, by string, acts handActs) (map[string]any, error) {
|
||||
if strings.TrimSpace(branch) == "" || strings.TrimSpace(repository) == "" || strings.TrimSpace(why) == "" {
|
||||
return nil, errors.New("say the branch, the repository and why its head follows the forge")
|
||||
}
|
||||
if h.Source == nil || h.Forge == nil {
|
||||
return nil, errors.New("this gate keeps no source or reads no forge")
|
||||
}
|
||||
if acts == nil {
|
||||
return nil, errors.New("the hand-act log cannot be reached here, so nothing was moved")
|
||||
}
|
||||
held, _, err := h.Source.Read(branch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if held == nil {
|
||||
return nil, fmt.Errorf("the gate keeps no source of the branch %s", branch)
|
||||
}
|
||||
name := ""
|
||||
for r := range held.Heads {
|
||||
if trunk.SameRepository(r, repository) {
|
||||
name = r
|
||||
}
|
||||
}
|
||||
if name == "" {
|
||||
return nil, fmt.Errorf("the source of %s names no head of %s", branch, repository)
|
||||
}
|
||||
if _, err := acts.Record(meshhandactsclient.Request{What: "moved the head of " + repository + " in the source of the branch " + branch + " to the forge's head",
|
||||
Why: why, Cause: "gate_source_follow", Verb: "source-follow"}); err != nil {
|
||||
return nil, fmt.Errorf("the hand act was not recorded through mesh-hand-acts, so nothing was moved: %w", err)
|
||||
}
|
||||
moved, err := h.followForge(branch, name, held.Heads[name])
|
||||
return map[string]any{"branch": branch, "repository": name, "moved": moved, "by": by}, err
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
)
|
||||
|
||||
// Design 47 G A-464, A-464b: the forge bridge's merged message moves the head of its repository in the source of the branch it
|
||||
// landed on and says source-moved; a merge naming no delivery group is said not made by one; a branch no source key holds, a
|
||||
// repository the key does not name, and a head the key holds already move nothing.
|
||||
func TestAMergedMessageMovesTheSourceOfItsBranchWhoeverMadeTheMerge(t *testing.T) {
|
||||
old, merge := strings.Repeat("a", 40), strings.Repeat("b", 40)
|
||||
body := func(repository, base, group string) []byte {
|
||||
f := forgemsg.Forge{V: 1, Kind: forgemsg.ForgeMerged, Repository: repository, Base: base, Merge: merge, Head: merge, Number: 14, Root: strings.Repeat("d", 40)}
|
||||
data, err := forgemsg.EncodeForge(f)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return data
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name, repository, base string
|
||||
moved bool
|
||||
}{
|
||||
{"watched branch, named repository", "novox/mesh-contracts", "main", true},
|
||||
{"a branch no source key holds", "novox/mesh-contracts", "other", false},
|
||||
{"a repository the key does not name", "novox/other", "main", false},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
src := &memSource{vals: map[string]Source{"main": {Group: "g", Heads: map[string]string{"novox/mesh-contracts": old}}}}
|
||||
var said []string
|
||||
var logged []string
|
||||
h := &Holder{Now: time.Now, Source: src, Forge: &fakeForge{},
|
||||
Logf: func(f string, a ...any) { logged = append(logged, f) },
|
||||
SaySeat: func(subject string, _ any, id string) error { said = append(said, id); return nil }}
|
||||
if err := h.ForgeMerged(body(c.repository, c.base, "")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := src.vals["main"]
|
||||
if c.moved != (got.Heads["novox/mesh-contracts"] == merge) || c.moved != (len(said) == 1) || (c.moved && got.Group != "") {
|
||||
t.Fatalf("source %+v said %v: moved wanted %v", got, said, c.moved)
|
||||
}
|
||||
if c.moved && !strings.Contains(strings.Join(logged, "\n"), "not made by a delivery group of the gate") {
|
||||
t.Errorf("a merge no group made is not said so: %v", logged)
|
||||
}
|
||||
// Heard again, the key names the head already: nothing is moved or said twice.
|
||||
if err := h.ForgeMerged(body(c.repository, c.base, "")); err != nil || len(said) > 1 {
|
||||
t.Errorf("heard twice: %v, said %v", err, said)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 G A-464: at its start the gate compares each head with the forge's branch head and moves every one behind it; a head
|
||||
// the forge cannot read is said and left; gate_source_follow does it for one repository after the hand-act log took it.
|
||||
func TestTheStartAndTheToolMoveAHeadBehindTheForge(t *testing.T) {
|
||||
old, now := strings.Repeat("a", 40), strings.Repeat("c", 40)
|
||||
mk := func() (*Holder, *branchSource, *[]string) {
|
||||
src := &branchSource{memSource{vals: map[string]Source{"main": {Heads: map[string]string{"o/f1": old, "o/f2": old, "o/f3": now}}}}}
|
||||
var said []string
|
||||
return &Holder{Now: time.Now, Source: src, Logf: func(string, ...any) {},
|
||||
Forge: &fakeForge{heads: map[string]string{"o/f1@main": now, "o/f3@main": now}}, // o/f2 cannot be read
|
||||
SaySeat: func(_ string, _ any, id string) error { said = append(said, id); return nil }}, src, &said
|
||||
}
|
||||
h, src, said := mk()
|
||||
fw := &fakeFindings{}
|
||||
h.Findings = fw
|
||||
forge := h.Forge.(*fakeForge)
|
||||
var pauses []time.Duration
|
||||
var heldWhileWaiting int
|
||||
prevSleep := startSleep
|
||||
startSleep = func(d time.Duration) {
|
||||
pauses = append(pauses, d)
|
||||
heldWhileWaiting = len(fw.held) // the finding stands while a head is uncompared
|
||||
forge.heads["o/f2@main"] = now // the seat git answers by the second pass
|
||||
}
|
||||
defer func() { startSleep = prevSleep }()
|
||||
moved, err := h.FollowAtStart()
|
||||
if err != nil || len(moved) != 2 || src.vals["main"].Heads["o/f1"] != now || src.vals["main"].Heads["o/f2"] != now || len(*said) != 2 {
|
||||
t.Fatalf("start: moved %v err %v heads %v said %v: want o/f1 and, after the second pass, o/f2 moved", moved, err, src.vals["main"].Heads, *said)
|
||||
}
|
||||
if len(pauses) != 1 || heldWhileWaiting != 1 || len(fw.held) != 0 {
|
||||
t.Fatalf("pauses %v, finding held while waiting %d and after %d: want one pause, the finding raised while a head stood uncompared and cleared after", pauses, heldWhileWaiting, len(fw.held))
|
||||
}
|
||||
h, src, said = mk()
|
||||
acts := &handActsFake{refuse: errors.New("log down")}
|
||||
if _, err := h.SourceFollow("main", "o/f1", "missed a merge", "me", acts); err == nil || src.vals["main"].Heads["o/f1"] != old {
|
||||
t.Fatalf("moved without the log: %v", err)
|
||||
}
|
||||
acts.refuse = nil
|
||||
if _, err := h.SourceFollow("main", "o/f1", "", "me", acts); err == nil {
|
||||
t.Fatal("moved with no reason")
|
||||
}
|
||||
out, err := h.SourceFollow("main", "o/f1", "missed a merge", "me", acts)
|
||||
if err != nil || out["moved"] != true || len(acts.took) != 1 || acts.took[0].Cause != "gate_source_follow" || src.vals["main"].Heads["o/f1"] != now {
|
||||
t.Fatalf("tool: %v %v log %+v heads %v", out, err, acts.took, src.vals["main"].Heads)
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 G A-464: the gate takes the forge bridge's merged event of any repository, by the manifest's own pattern.
|
||||
func TestTheGateTakesTheForgeBridgesMergedEventOfAnyRepository(t *testing.T) {
|
||||
merge := strings.Repeat("b", 40)
|
||||
data, err := forgemsg.EncodeForge(forgemsg.Forge{V: 1, Kind: forgemsg.ForgeMerged, Repository: "novox/mesh-contracts", Base: "main", Merge: merge, Head: merge, Number: 14, Root: strings.Repeat("d", 40)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
src := &memSource{vals: map[string]Source{"main": {Heads: map[string]string{"novox/mesh-contracts": strings.Repeat("a", 40)}}}}
|
||||
h := &Holder{Now: time.Now, Source: src, Forge: &fakeForge{}, Logf: func(string, ...any) {}}
|
||||
key := strings.Replace(strings.Replace(forgeMergedEvent, "*", "novox", 1), "*", "mesh-contracts", 1)
|
||||
if err := take(h, stdio.Envelope{Key: key, Body: data}); err != nil || src.vals["main"].Heads["novox/mesh-contracts"] != merge {
|
||||
t.Fatalf("event %q: %v, source %+v", key, err, src.vals["main"])
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 G A-464c: a head moves only forward and only when it changes. A merged message for a commit that does not contain
|
||||
// the held head (replayed, late, out of order) moves nothing and is said; a second message for the same head writes no
|
||||
// revision; and a take-in.taken for a head a merged already moved writes none and says no source-moved.
|
||||
func TestAHeadMovesOnlyForwardAndOnlyWhenItChanges(t *testing.T) {
|
||||
oldC, newC := strings.Repeat("a", 40), strings.Repeat("b", 40)
|
||||
msg := func(merge string) []byte {
|
||||
data, err := forgemsg.EncodeForge(forgemsg.Forge{V: 1, Kind: forgemsg.ForgeMerged, Repository: "novox/app", Base: "main", Merge: merge, Head: merge, Number: 3, Root: strings.Repeat("d", 40)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return data
|
||||
}
|
||||
src := &memSource{vals: map[string]Source{"main": {Heads: map[string]string{"novox/app": newC}}}}
|
||||
var said, logged []string
|
||||
// newC contains oldC, not the other way round.
|
||||
forge := &fakeForge{contains: func(commit, in string) bool { return commit == in || (commit == oldC && in == newC) }}
|
||||
h := &Holder{Now: time.Now, Source: src, Forge: forge, Logf: func(f string, a ...any) { logged = append(logged, f) },
|
||||
SaySeat: func(_ string, _ any, id string) error { said = append(said, id); return nil }}
|
||||
if err := h.ForgeMerged(msg(oldC)); err != nil || src.vals["main"].Heads["novox/app"] != newC || src.rev != 0 || len(said) != 0 || len(logged) == 0 {
|
||||
t.Fatalf("a replayed old merge: %v, source %+v, revisions %d, said %v, logged %v: want nothing moved and a log line", err, src.vals["main"], src.rev, said, logged)
|
||||
}
|
||||
if err := h.ForgeMerged(msg(newC)); err != nil || src.rev != 0 || len(said) != 0 {
|
||||
t.Fatalf("a second message for the same head wrote revision %d, said %v", src.rev, said)
|
||||
}
|
||||
// A take-in.taken naming the head a merged moved already writes no revision and says nothing.
|
||||
body := []byte(`{"v":1,"kind":"taken","key":"g.feat","what":"group","group":"feat","branch":"main","source":7,` +
|
||||
`"merges":[{"repository":"novox/app","number":3,"merge":"` + newC + `"}],"entries":[]}`)
|
||||
if err := h.moveSource(mustTaken(t, body)); err != nil || src.rev != 0 || len(said) != 0 {
|
||||
t.Fatalf("take-in for a head already moved: %v, revision %d, said %v", err, src.rev, said)
|
||||
}
|
||||
// A real forward move still writes one revision.
|
||||
src.vals["main"] = Source{Heads: map[string]string{"novox/app": oldC}}
|
||||
if err := h.ForgeMerged(msg(newC)); err != nil || src.rev != 1 || len(said) != 1 {
|
||||
t.Fatalf("a forward move: %v, revision %d, said %v", err, src.rev, said)
|
||||
}
|
||||
}
|
||||
|
||||
func mustTaken(t *testing.T, body []byte) meshcatalog.TakeInTaken {
|
||||
t.Helper()
|
||||
var v meshcatalog.TakeInTaken
|
||||
if err := json.Unmarshal(body, &v); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Design 47 G A-464d: a take-in.taken arriving after a later merge moved the head leaves the head where it is.
|
||||
func TestATakeInTakenAfterALaterMergeLeavesTheHead(t *testing.T) {
|
||||
oldC, newC := strings.Repeat("a", 40), strings.Repeat("b", 40)
|
||||
src := &memSource{vals: map[string]Source{"main": {Heads: map[string]string{"novox/app": newC}}}}
|
||||
var said []string
|
||||
h := &Holder{Now: time.Now, Source: src, Logf: func(string, ...any) {},
|
||||
Forge: &fakeForge{contains: func(commit, in string) bool { return commit == in || (commit == oldC && in == newC) }},
|
||||
SaySeat: func(_ string, _ any, id string) error { said = append(said, id); return nil }}
|
||||
body := []byte(`{"v":1,"kind":"taken","key":"g.feat","what":"group","group":"feat","branch":"main","source":7,` +
|
||||
`"merges":[{"repository":"novox/app","number":3,"merge":"` + oldC + `"}],"entries":[]}`)
|
||||
if err := h.moveSource(mustTaken(t, body)); err != nil || src.vals["main"].Heads["novox/app"] != newC || src.rev != 0 || len(said) != 0 {
|
||||
t.Fatalf("take-in of an older merge: %v, source %+v, revision %d, said %v: want the head left at the later merge", err, src.vals["main"], src.rev, said)
|
||||
}
|
||||
}
|
||||
|
||||
// fakeFindings is the gate's finding writer in memory.
|
||||
type fakeFindings struct{ held []meshconditions.Finding }
|
||||
|
||||
func (f *fakeFindings) Write(_ context.Context, x meshconditions.Finding) error {
|
||||
f.held = append(f.held, x)
|
||||
return nil
|
||||
}
|
||||
func (f *fakeFindings) Clear(_ context.Context, _, _, _, _ string) error { f.held = nil; return nil }
|
||||
func (f *fakeFindings) Held() []meshconditions.Finding { return f.held }
|
||||
@@ -55,6 +55,18 @@ func (s seatGit) Branch(repository, branch string) (gitseat.BranchAnswer, error)
|
||||
return a, s.call(gitseat.VerbBranch, gitseat.BranchInput{Repository: repository, Branch: branch}, &a)
|
||||
}
|
||||
|
||||
// Contains is whether commit is the commit in or an ancestor of it.
|
||||
func (s seatGit) Contains(repository, commit, in string) (bool, error) {
|
||||
var a gitseat.ContainsAnswer
|
||||
if err := s.call(gitseat.VerbContains, gitseat.ContainsInput{Repository: repository, Commit: commit, In: in}, &a); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if a.Error != "" {
|
||||
return false, errors.New(a.Error)
|
||||
}
|
||||
return a.Contains, nil
|
||||
}
|
||||
|
||||
// watchedRepositories are the repositories each watched branch is registered for, each once, sorted.
|
||||
func watchedRepositories(regs []meshcatalog.Registration) map[string][]string {
|
||||
seen := map[string]map[string]bool{}
|
||||
|
||||
@@ -89,5 +89,16 @@ func sourceTools(h *Holder, acts handActs) []stdio.Tool {
|
||||
Run: func(a map[string]any) (any, error) {
|
||||
return h.SourceStart(strArg(a, "branch"), strArg(a, "why"), stdio.CallerOf(a), acts)
|
||||
}},
|
||||
{Name: "gate_source_follow",
|
||||
Description: "Move the head one watched branch's source names for one repository to the forge's head of that branch now, as " +
|
||||
"the gate does when it hears a merge and at its start (design 47 G A-464); recorded in the hand-act log of the seat " +
|
||||
"mesh-hand-acts first. Nothing is moved when the source already names the forge's head.",
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{
|
||||
"branch": str("the watched branch"), "repository": str("the repository, owner/name"),
|
||||
"why": str("why its head follows the forge by hand, in plain words")},
|
||||
"required": []string{"branch", "repository", "why"}},
|
||||
Run: func(a map[string]any) (any, error) {
|
||||
return h.SourceFollow(strArg(a, "branch"), strArg(a, "repository"), strArg(a, "why"), stdio.CallerOf(a), acts)
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
mdc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
|
||||
meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
)
|
||||
|
||||
@@ -107,9 +108,43 @@ func (h *Holder) moveSource(t meshcatalog.TakeInTaken) error {
|
||||
for _, m := range t.Merges {
|
||||
heads[m.Repository] = m.Merge
|
||||
}
|
||||
// A head moves only forward (A-464d): a repository whose held head is not contained in the merge is left where it is.
|
||||
if held, _, err := h.Source.Read(t.Branch); err != nil {
|
||||
return err
|
||||
} else if held != nil && h.Forge != nil {
|
||||
for r, c := range heads {
|
||||
for name, was := range held.Heads {
|
||||
if !trunk.SameRepository(name, r) || was == c {
|
||||
continue
|
||||
}
|
||||
ahead, err := h.Forge.Contains(name, was, c)
|
||||
if err != nil {
|
||||
return fmt.Errorf("whether %.12s is in %.12s of %s cannot be read, so the head stays: %w", was, c, name, err)
|
||||
}
|
||||
if !ahead {
|
||||
h.logf("[mesh-delivery] source.%s keeps %s at %.12s: the take-in's merge %.12s does not contain it, left without effect", t.Branch, name, was, c)
|
||||
delete(heads, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(heads) == 0 {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
wrote := false
|
||||
rev, err := h.Source.Set(t.Branch, func(prev *Source) (Source, bool) {
|
||||
wrote = false
|
||||
next := Source{Group: t.Group, Heads: heads}
|
||||
if prev != nil {
|
||||
same := true
|
||||
for r, c := range heads {
|
||||
if prev.Heads[r] != c {
|
||||
same = false
|
||||
}
|
||||
}
|
||||
if same {
|
||||
return Source{}, false // a merged message moved these heads already: no revision (A-464c)
|
||||
}
|
||||
next.Heads = map[string]string{}
|
||||
for r, c := range prev.Heads {
|
||||
next.Heads[r] = c
|
||||
@@ -118,12 +153,13 @@ func (h *Holder) moveSource(t meshcatalog.TakeInTaken) error {
|
||||
next.Heads[r] = c
|
||||
}
|
||||
}
|
||||
wrote = true
|
||||
return next, true
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("source.%s cannot be moved: %w", t.Branch, err)
|
||||
}
|
||||
if h.SaySeat == nil {
|
||||
if h.SaySeat == nil || !wrote {
|
||||
return nil
|
||||
}
|
||||
at := h.Now().UTC()
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestATakeInTakenOpensOneRecordAndMovesItsBranchsSource(t *testing.T) {
|
||||
if s := src.vals["main"]; s.Group != "feat" || s.Heads["novox/app"] != merge {
|
||||
t.Fatalf("source.main %+v", s)
|
||||
}
|
||||
if len(events) != 2 || !strings.HasSuffix(events[0].subject, ".event.source-moved.main") {
|
||||
if len(events) != 1 || !strings.HasSuffix(events[0].subject, ".event.source-moved.main") {
|
||||
t.Fatalf("said %+v", events)
|
||||
}
|
||||
drop := json.RawMessage(`{"v":1,"kind":"taken","key":"m.00000000000000000002","what":"revision","dropped":true,"branch":"main","source":8,` +
|
||||
@@ -92,7 +92,7 @@ func TestATakeInTakenOpensOneRecordAndMovesItsBranchsSource(t *testing.T) {
|
||||
if err := c.Hear(stdio.Envelope{Key: "mesh-delivery-indexer.take-in.taken", Body: drop}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if kept, _ := h.Records.Kept(); len(kept) != 1 || len(events) != 2 {
|
||||
if kept, _ := h.Records.Kept(); len(kept) != 1 || len(events) != 1 {
|
||||
t.Fatalf("a hand drop opened %d records and said %d events", len(kept), len(events))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"git.pull-merged",
|
||||
"git.pull-closed",
|
||||
"mesh-catalog.registration-changed",
|
||||
"mesh-delivery-forge-bridge.forge.*.*.merged",
|
||||
"mesh-conditions.findings-asked"
|
||||
],
|
||||
"emits": [
|
||||
@@ -383,6 +384,7 @@
|
||||
"gate_records",
|
||||
"gate_source",
|
||||
"gate_source_again",
|
||||
"gate_source_follow",
|
||||
"gate_source_start"
|
||||
],
|
||||
"config": {
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
"backup_delete_retired",
|
||||
"backup_deleted"
|
||||
],
|
||||
"secrets-owner": "${machine:account}",
|
||||
"own-secrets": {
|
||||
"repository": "${dir:state}/repository.secret",
|
||||
"broker": "${dir:state}/broker"
|
||||
|
||||
Reference in New Issue
Block a user