carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package console
2
3import (
4 "context"
5 "crypto/sha256"
6 "encoding/hex"
7 "net/http"
8 "testing"
9
10 "github.com/carlosframework/platform/internal/release"
11)
12
13// Issue #316: system status compares bootstrap/carlos, the binary a new box
14// boots, with stable's signed linux-arm64 artifact.
15func TestSystemStatusReportsWhetherBootstrapIsStablesBuild(t *testing.T) {
16 fx := newConsoleFixture(t)
17 owner := cliToken(t, fx, "paul@keymail.dev", "code-sys-bootstrap")
18 seedBox(t, fx, "ie", "linux-arm64", "stable", "v0.28.0")
19 ctx := context.Background()
20 build := []byte("stable build")
21 sum := sha256.Sum256(build)
22 if _, err := release.PromoteSystem(ctx, fx.rel, release.RootSigner(fx.priv), "router", "stable", release.SystemRelease{
23 Version: "v0.28.0", Artifacts: map[string]release.SystemArtifact{"linux-arm64": {
24 Key: release.SystemArtifactKey("v0.28.0", "linux-arm64"), SHA256: hex.EncodeToString(sum[:])}},
25 }, release.SystemPromoteOptions{}); err != nil {
26 t.Fatal(err)
27 }
28 bootstrap := func() any {
29 t.Helper()
30 st, out := getJSON(t, fx.ts.URL+"/api/cli/system/status", owner)
31 if st != http.StatusOK {
32 t.Fatalf("status = %d %v", st, out)
33 }
34 v, ok := out["bootstrap"]
35 if !ok {
36 t.Fatalf("no bootstrap field in %v", out)
37 }
38 return v
39 }
40 if got := bootstrap(); got != nil {
41 t.Fatalf("absent bootstrap object: bootstrap = %v, want null", got)
42 }
43 put := func(data []byte) {
44 t.Helper()
45 _, etag, err := fx.rel.Get(ctx, bootstrapKey)
46 if err != nil {
47 etag = ""
48 }
49 if _, err := fx.rel.Put(ctx, bootstrapKey, data, etag); err != nil {
50 t.Fatal(err)
51 }
52 }
53 put([]byte("an older build"))
54 row, _ := bootstrap().(map[string]any)
55 if row["state"] != "behind" || row["version"] != "v0.28.0" || row["key"] != "bootstrap/router/v0.28.0/carlos-linux-arm64" {
56 t.Fatalf("stale bootstrap: row = %v, want behind v0.28.0 with the mirror key", row)
57 }
58 put(build)
59 if row, _ := bootstrap().(map[string]any); row["state"] != "current" {
60 t.Fatalf("matching bootstrap: row = %v, want current", row)
61 }
62 // Past its budget the comparison reads unreadable, and the status read
63 // still answers (Astra review: a slow store must not time the CLI out).
64 was := bootstrapReadBudget
65 bootstrapReadBudget = 0
66 t.Cleanup(func() { bootstrapReadBudget = was })
67 if row, _ := bootstrap().(map[string]any); row["state"] != "unreadable" || row["error"] == "" {
68 t.Fatalf("over budget: row = %v, want unreadable with the error", row)
69 }
70}
71