Merge pull request 'The checker reads mesh-sdk's list-form level digest, so kept verdicts hold for a check naming a package like token (issue 1930, with mesh-sdk and mesh-catalog)' (#31) from fix/1930-digest-shape into main
Reviewed-on: #31
This commit was merged in pull request #31.
This commit is contained in:
@@ -3,7 +3,7 @@ module mesh-delivery-checker
|
|||||||
go 1.26.0
|
go 1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261023150321-a2c813a6b468
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261023213200-403a5d72ab93
|
||||||
github.com/nats-io/nats-server/v2 v2.11.17
|
github.com/nats-io/nats-server/v2 v2.11.17
|
||||||
github.com/nats-io/nats.go v1.54.0
|
github.com/nats-io/nats.go v1.54.0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261023150321-a2c813a6b468 h1:UcMee+IV2ii5E4dRZdQUaSaeh9IedTFYumuQbBiB0k0=
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261023213200-403a5d72ab93 h1:FAiFY2KBKEoZSH49OZTt7/zRBIQxyl5g/KhYrpggbN4=
|
||||||
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261023150321-a2c813a6b468/go.mod h1:ouERNpZizzwZ0HLEtAypsY9FR20FyUgUYRni6J7kVCY=
|
git.novox.be/novox/mesh-sdk/go v0.1.14-0.20261023213200-403a5d72ab93/go.mod h1:ouERNpZizzwZ0HLEtAypsY9FR20FyUgUYRni6J7kVCY=
|
||||||
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op h1:Z/MZK75wC/NSrkgqeNIa7jexam9uWzhLmFTSCPI/kn0=
|
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op h1:Z/MZK75wC/NSrkgqeNIa7jexam9uWzhLmFTSCPI/kn0=
|
||||||
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op/go.mod h1:FQyySiasQQM8735Ddel3MRojmy4dA1IqCeyJ5jmPMbI=
|
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op/go.mod h1:FQyySiasQQM8735Ddel3MRojmy4dA1IqCeyJ5jmPMbI=
|
||||||
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
|
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package check
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.novox.be/novox/mesh-sdk/go/delivery"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 1930/AC3: given a check ask whose stored end keeps the digest's packages as a list of {package, digest} (issue 1930),
|
||||||
|
// or one stored before it with the packages a map keyed by package path, when the same heads are checked a second time,
|
||||||
|
// then the kept verdicts the first check wrote are read from it: every package it passed is kept, none run again.
|
||||||
|
func TestKeptVerdictsAreReadFromTheDigestsListForm(t *testing.T) {
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
old bool
|
||||||
|
}{{"the list form", false}, {"a map stored before issue 1930", true}} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
b := newBench(t)
|
||||||
|
var stored []string
|
||||||
|
b.asks.Answer = func(a delivery.StepAsk) delivery.Step {
|
||||||
|
s := b.answer(a)
|
||||||
|
if tc.old && s.State == delivery.StepPassed {
|
||||||
|
s.Result = oldDigestForm(t, s.Result)
|
||||||
|
}
|
||||||
|
stored = append(stored, string(s.Result))
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
first := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))).Verdict
|
||||||
|
u := first.Levels[delivery.LevelUnit]
|
||||||
|
if first.State != delivery.VerdictPass || u.Run == 0 || u.Kept != 0 {
|
||||||
|
t.Fatalf("the first check = %+v", first)
|
||||||
|
}
|
||||||
|
if len(stored) == 0 {
|
||||||
|
t.Fatal("no ask's end was stored")
|
||||||
|
}
|
||||||
|
list := strings.Contains(stored[0], `"packages":[{"package":"fixture/slow"`)
|
||||||
|
if list == tc.old || strings.Contains(stored[0], `"fixture/slow":"`) != tc.old {
|
||||||
|
t.Fatalf("the stored end is not in the form under test: %s", stored[0])
|
||||||
|
}
|
||||||
|
b.steps.calls = nil
|
||||||
|
second := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))).Verdict
|
||||||
|
if s := second.Levels[delivery.LevelUnit]; second.State != delivery.VerdictPass || s.Kept != u.Run || s.Run != 0 {
|
||||||
|
t.Fatalf("the second check's unit level = %+v, want %d kept and none run", s, u.Run)
|
||||||
|
}
|
||||||
|
if n := len(b.steps.tool("test")); n != 0 {
|
||||||
|
t.Errorf("%d test steps ran on the second check", n)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// oldDigestForm rewrites a check answer's level digests to the form stored before issue 1930: packages as a map keyed by
|
||||||
|
// package path.
|
||||||
|
func oldDigestForm(t *testing.T, result json.RawMessage) json.RawMessage {
|
||||||
|
t.Helper()
|
||||||
|
var a struct {
|
||||||
|
Fetch json.RawMessage `json:"fetch"`
|
||||||
|
Levels []map[string]any `json:"levels"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(result, &a); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, l := range a.Levels {
|
||||||
|
d, ok := l["digest"].(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
m := map[string]any{}
|
||||||
|
list, _ := d["packages"].([]any)
|
||||||
|
for _, p := range list {
|
||||||
|
pd := p.(map[string]any)
|
||||||
|
m[pd["package"].(string)] = pd["digest"]
|
||||||
|
}
|
||||||
|
d["packages"] = m
|
||||||
|
}
|
||||||
|
raw, err := json.Marshal(a)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return raw
|
||||||
|
}
|
||||||
@@ -447,13 +447,11 @@ func (st *state) level(ctx context.Context, t *target, la delivery.LevelAnswer)
|
|||||||
return fail(t.node, fmt.Sprintf("the check of %s#%d answered the level %q, which is no level", t.pull.Repository, t.pull.Number, level)), 0
|
return fail(t.node, fmt.Sprintf("the check of %s#%d answered the level %q, which is no level", t.pull.Repository, t.pull.Number, level)), 0
|
||||||
}
|
}
|
||||||
var digests map[string]string
|
var digests map[string]string
|
||||||
if t.module == buildrun.GoBuildModule && len(la.Digest) > 0 {
|
if t.module == buildrun.GoBuildModule && la.Digest != nil {
|
||||||
var d Digested
|
// The packages come as a list, never keyed by a package path (issue 1930); an answer stored before reads too.
|
||||||
if err := json.Unmarshal(la.Digest, &d); err == nil {
|
digests = la.Digest.Map()
|
||||||
digests = d.Packages
|
if t.runner != "" {
|
||||||
if t.runner != "" {
|
t.judgedBy(la.Digest.JudgedBy) // the installed module judged it: the runner is not used again
|
||||||
t.judgedBy(d.JudgedBy) // the installed module judged it: the runner is not used again
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if t.runner != "" && la.Judged != "" {
|
if t.runner != "" && la.Judged != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user