The toolchain a build module reports (guard key and toolchain-reported event) names the language version alone (mesh-delivery-sdk steprun Guard); the build module's own Toolchain func keeps the installed text. Delivered with or after the sdk change. Builds: design 47 G A-471 (G-22-lead-answers-2.md)
74 lines
2.9 KiB
Go
74 lines
2.9 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// Design 47 G §492, §472, §466 (BG5, BG6): the guard says toolchain-reported on the Node build seat's subject of its node,
|
|
// with the version, the recipe and the digest of the node program, at the first write and again only when one of them
|
|
// changed; the toolchains key and a build's toolchain carry the digest.
|
|
func TestTheGuardSaysToolchainReportedOnAChangeWithTheProgramDigest(t *testing.T) {
|
|
states := newStates()
|
|
m := moduleWith(states, "v26.10.0")
|
|
prog := filepath.Join(t.TempDir(), "node")
|
|
os.WriteFile(prog, []byte("node program"), 0o755)
|
|
m.ToolchainProgram = func() (string, error) { return prog, nil }
|
|
type event struct {
|
|
subject string
|
|
body map[string]string
|
|
id string
|
|
}
|
|
var got []event
|
|
m.SayToolchain = func(subject string, body any, id string) error {
|
|
raw, _ := json.Marshal(body)
|
|
var b map[string]string
|
|
json.Unmarshal(raw, &b)
|
|
got = append(got, event{subject, b, id})
|
|
return nil
|
|
}
|
|
if err := m.Check(context.Background()); err != nil {
|
|
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" || 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"] {
|
|
t.Errorf("the toolchains key's digest is %q, the event's %q", tc.Digest, got[0].body["digest"])
|
|
}
|
|
m.Check(context.Background())
|
|
if len(got) != 1 {
|
|
t.Errorf("a second pass that changed nothing said %d events in all, want 1", len(got))
|
|
}
|
|
// A build's toolchain names the same digest (§466).
|
|
if used, err := m.askSteps(nil).Toolchain(context.Background()); err != nil || used.Digest != got[0].body["digest"] || used.Version != "v26.10.0" {
|
|
t.Errorf("a build's toolchain = %+v (%v), want the digest %s", used, err, got[0].body["digest"])
|
|
}
|
|
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" || got[1].body["digest"] == got[0].body["digest"] {
|
|
t.Errorf("a new version said %+v, want a second event with another digest", got)
|
|
}
|
|
}
|
|
|
|
// The seat's events are its definition's: the module declares no stream of its own for the toolchain (§492).
|
|
func TestTheManifestDeclaresNoToolchainStream(t *testing.T) {
|
|
raw, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var m struct {
|
|
Streams []struct {
|
|
Name string `json:"name"`
|
|
} `json:"streams"`
|
|
}
|
|
if err := json.Unmarshal(raw, &m); err != nil || len(m.Streams) != 0 {
|
|
t.Errorf("streams = %+v (%v)", m.Streams, err)
|
|
}
|
|
}
|