Record the inputs of a build's source fingerprint in its build record (issue 1215)

This commit is contained in:
2026-10-19 11:54:21 +02:00
parent 8da2619920
commit 68088ec782
13 changed files with 204 additions and 16 deletions
+42
View File
@@ -1,6 +1,7 @@
package builder
import (
"encoding/json"
"testing"
"git.novox.be/novox/mesh-sdk/go/delivery"
@@ -81,3 +82,44 @@ func TestTheBuilderFingerprintsWithTheSDKFunction(t *testing.T) {
t.Errorf("the SDK function was given %+v", got)
}
}
// 1215/AC1: the inputs a result records, read back, give the fingerprint the build recorded (the live builds of
// 1214/AC1), through encoding/json as the build record keeps them.
func TestTheInputsAResultRecordsGiveItsFingerprintAgain(t *testing.T) {
s := &sourceInputs{module: "build-agent", tree: "11c0b4f90cae0d6e4ef9cc48cbfdf9f6dbe52bca",
bases: []string{
"sha256:d9e853e87e55526f6b2917df91a2115c36dd7c696a35be12163d44e6e2a4b6bc",
"sha256:8ac98ca534ac3f51e1f420a1dd2c15e74c75cfa0f23f3ad27eb5d7236c349a0c",
},
contexts: map[string]string{"server": "narrow:d51ca744fd11af59d616c858f76c27b3e58e16e11fbdc0c720eb9d7d19d55fac"}}
raw, err := json.Marshal(resultInputs(s))
if err != nil {
t.Fatal(err)
}
var back delivery.SourceInputs
if err := json.Unmarshal(raw, &back); err != nil {
t.Fatal(err)
}
want := "src1:e846efe73716b78e80860baaac96153de2cb76551325753838ca245d2160a3d7"
if fp, none := delivery.SourceFingerprint(back); fp != want || none != "" {
t.Errorf("the inputs read back give %q (%q), want %q", fp, none, want)
}
}
// 1215/AC3: a build that gets no fingerprint still has its inputs recorded, so the reason is visible.
func TestABuildWithNoFingerprintStillSaysItsInputs(t *testing.T) {
s := newSourceInputs("app")
s.tree = "aaaa"
s.notPinned("it resolves packages from the mesh's registry at build time")
in := resultInputs(s)
if in == nil || in.Module != "app" || in.Tree != "aaaa" || in.Unpinned == "" {
t.Fatalf("the inputs of an unpinned build: %+v", in)
}
if fp, none := delivery.SourceFingerprint(*in); fp != "" || none != in.Unpinned {
t.Errorf("the inputs give %q (%q)", fp, none)
}
noTree := resultInputs(newSourceInputs("app"))
if noTree == nil || noTree.Module != "app" || noTree.Tree != "" {
t.Errorf("the inputs of a build with no tree: %+v", noTree)
}
}