internal/pkg: expose cure whence
Test / Create distribution (push) Successful in 58s
Test / Sandbox (push) Successful in 3m1s
Test / ShareFS (push) Successful in 3m53s
Test / Hakurei (push) Successful in 4m6s
Test / Sandbox (race detector) (push) Successful in 5m34s
Test / Hakurei (race detector) (push) Successful in 6m40s
Test / Flake checks (push) Successful in 1m5s
Test / Create distribution (push) Successful in 58s
Test / Sandbox (push) Successful in 3m1s
Test / ShareFS (push) Successful in 3m53s
Test / Hakurei (push) Successful in 4m6s
Test / Sandbox (race detector) (push) Successful in 5m34s
Test / Hakurei (race detector) (push) Successful in 6m40s
Test / Flake checks (push) Successful in 1m5s
Useful for cure determinism validation of KindExec. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
+47
-44
@@ -627,6 +627,7 @@ type cureStep struct {
|
||||
|
||||
pathname *check.Absolute
|
||||
output expectsKnown
|
||||
whence int
|
||||
err error
|
||||
}
|
||||
|
||||
@@ -646,7 +647,7 @@ func cureMany(t *testing.T, c *pkg.Cache, steps []cureStep) {
|
||||
|
||||
for _, step := range steps {
|
||||
t.Log("cure step:", step.name)
|
||||
if pathname, checksum, err := c.Cure(step.a); !reflect.DeepEqual(err, step.err) {
|
||||
if pathname, checksum, whence, err := c.CureWhence(step.a); !reflect.DeepEqual(err, step.err) {
|
||||
faults, _err := c.ReadFaults(step.a)
|
||||
if _err != nil {
|
||||
t.Errorf("ReadFaults: error = %v", _err)
|
||||
@@ -663,6 +664,8 @@ func cureMany(t *testing.T, c *pkg.Cache, steps []cureStep) {
|
||||
t.Logf("faulting cure terminated %s ago", time.Since(faults[0].Time()))
|
||||
}
|
||||
t.Fatalf("Cure: error = %v, want %v", err, step.err)
|
||||
} else if step.whence != whence {
|
||||
t.Fatalf("Cure: whence = %s, want %s", pkg.WhenceString(whence), pkg.WhenceString(step.whence))
|
||||
} else if step.pathname != ignorePathname && !pathname.Is(step.pathname) {
|
||||
t.Fatalf("Cure: pathname = %q, want %q", pathname, step.pathname)
|
||||
} else if step.output == nil || checksum != makeChecksumH(step.output.hash()) {
|
||||
@@ -774,28 +777,28 @@ func TestCache(t *testing.T) {
|
||||
identifier,
|
||||
new(testdata.hash()),
|
||||
testdata, nil,
|
||||
), wantPathname, testdata, nil},
|
||||
), wantPathname, testdata, pkg.WNew, nil},
|
||||
|
||||
{"identical content", newStubFile(
|
||||
pkg.KindHTTPGet,
|
||||
identifier0,
|
||||
new(testdata.hash()),
|
||||
testdata, nil,
|
||||
), wantPathname0, testdata, nil},
|
||||
), wantPathname0, testdata, pkg.WCache, nil},
|
||||
|
||||
{"existing entry", newStubFile(
|
||||
pkg.KindHTTPGet,
|
||||
identifier,
|
||||
new(testdata.hash()),
|
||||
testdata, nil,
|
||||
), wantPathname, testdata, nil},
|
||||
), wantPathname, testdata, pkg.WCache, nil},
|
||||
|
||||
{"checksum mismatch", newStubFile(
|
||||
pkg.KindHTTPGet,
|
||||
pkg.ID{0xff, 0},
|
||||
new(pkg.Checksum),
|
||||
testdata, nil,
|
||||
), nil, nil, &pkg.ChecksumMismatchError{
|
||||
), nil, nil, pkg.WNew, &pkg.ChecksumMismatchError{
|
||||
Got: testdata.hash(),
|
||||
}},
|
||||
|
||||
@@ -816,12 +819,12 @@ func TestCache(t *testing.T) {
|
||||
0x36, 0x65, 0x59, 0x33, 0xec, 0x2b,
|
||||
0x41, 0x34, 0x65, 0x96, 0x68, 0x17,
|
||||
0xa9, 0xc2, 0x08, 0xa1, 0x17, 0x17,
|
||||
}, nil},
|
||||
}, pkg.WNew, nil},
|
||||
|
||||
{"incomplete implementation", struct{ pkg.Artifact }{&stubArtifact{
|
||||
kind: pkg.KindExec,
|
||||
params: []byte("artifact overridden to be incomplete"),
|
||||
}}, nil, nil, pkg.InvalidArtifactError(pkg.MustDecode(
|
||||
}}, nil, nil, pkg.WNew, pkg.InvalidArtifactError(pkg.MustDecode(
|
||||
"E__uZ1sLIvb84vzSm5Uezb03RogsiaeTt1nfIVv8TKnnf4LqwtSi-smdHhlkZrUJ",
|
||||
))},
|
||||
|
||||
@@ -830,18 +833,18 @@ func TestCache(t *testing.T) {
|
||||
pkg.ID{0xff, 1},
|
||||
nil,
|
||||
nil, stub.UniqueError(0xcafe),
|
||||
), nil, nil, stub.UniqueError(0xcafe)},
|
||||
), nil, nil, pkg.WNew, stub.UniqueError(0xcafe)},
|
||||
|
||||
{"error caching", newStubFile(
|
||||
pkg.KindHTTPGet,
|
||||
pkg.ID{0xff, 1},
|
||||
nil,
|
||||
nil, nil,
|
||||
), nil, nil, stub.UniqueError(0xcafe)},
|
||||
), nil, nil, pkg.WCache, stub.UniqueError(0xcafe)},
|
||||
|
||||
{"cache hit bad type", overrideChecksum{testdata.hash(), overrideIdent{pkg.ID{0xff, 2}, &stubArtifact{
|
||||
kind: pkg.KindTar,
|
||||
}}}, nil, nil, pkg.InvalidFileModeError(
|
||||
}}}, nil, nil, pkg.WCache, pkg.InvalidFileModeError(
|
||||
0400,
|
||||
)},
|
||||
|
||||
@@ -853,7 +856,7 @@ func TestCache(t *testing.T) {
|
||||
cure: func(f *pkg.FContext) error {
|
||||
panic("attempting to cure impossible artifact")
|
||||
},
|
||||
}, nil, nil, &pkg.DependencyCureError{
|
||||
}, nil, nil, pkg.WNew, &pkg.DependencyCureError{
|
||||
{
|
||||
A: failingFile,
|
||||
Err: struct {
|
||||
@@ -875,7 +878,7 @@ func TestCache(t *testing.T) {
|
||||
cureMany(t, c0, []cureStep{
|
||||
{"cache hit ident", overrideIdent{
|
||||
id: identifier,
|
||||
}, wantPathname, testdata, nil},
|
||||
}, wantPathname, testdata, pkg.WCache, nil},
|
||||
|
||||
{"cache miss checksum match", newStubFile(
|
||||
pkg.KindHTTPGet,
|
||||
@@ -886,7 +889,7 @@ func TestCache(t *testing.T) {
|
||||
), base.Append(
|
||||
"identifier",
|
||||
pkg.Encode(testdata.hash()),
|
||||
), testdata, nil},
|
||||
), testdata, pkg.WNew, nil},
|
||||
})
|
||||
|
||||
// cure after close
|
||||
@@ -1016,30 +1019,30 @@ func TestCache(t *testing.T) {
|
||||
{"initial directory", overrideChecksum{want.hash(), overrideIdent{id, &stubArtifact{
|
||||
kind: pkg.KindTar,
|
||||
cure: makeSample,
|
||||
}}}, wantPathname, want, nil},
|
||||
}}}, wantPathname, want, pkg.WNew, nil},
|
||||
|
||||
{"identical identifier", overrideChecksum{want.hash(), overrideIdent{id, &stubArtifact{
|
||||
kind: pkg.KindTar,
|
||||
}}}, wantPathname, want, nil},
|
||||
}}}, wantPathname, want, pkg.WCache, nil},
|
||||
|
||||
{"identical checksum", overrideIdent{id0, &stubArtifact{
|
||||
kind: pkg.KindTar,
|
||||
cure: makeSample,
|
||||
}}, wantPathname0, want, nil},
|
||||
}}, wantPathname0, want, pkg.WNew, nil},
|
||||
|
||||
{"cure fault", overrideIdent{pkg.ID{0xff, 0}, &stubArtifact{
|
||||
kind: pkg.KindTar,
|
||||
cure: func(t *pkg.TContext) error {
|
||||
return makeGarbage(t.GetWorkDir(), stub.UniqueError(0xcafe))
|
||||
},
|
||||
}}, nil, nil, stub.UniqueError(0xcafe)},
|
||||
}}, nil, nil, pkg.WNew, stub.UniqueError(0xcafe)},
|
||||
|
||||
{"checksum mismatch", overrideChecksum{pkg.Checksum{}, overrideIdent{pkg.ID{0xff, 1}, &stubArtifact{
|
||||
kind: pkg.KindTar,
|
||||
cure: func(t *pkg.TContext) error {
|
||||
return makeGarbage(t.GetWorkDir(), nil)
|
||||
},
|
||||
}}}, nil, nil, &pkg.ChecksumMismatchError{
|
||||
}}}, nil, nil, pkg.WNew, &pkg.ChecksumMismatchError{
|
||||
Got: pkg.MustDecode(
|
||||
"CUx-3hSbTWPsbMfDhgalG4Ni_GmR9TnVX8F99tY_P5GtkYvczg9RrF5zO0jX9XYT",
|
||||
),
|
||||
@@ -1050,7 +1053,7 @@ func TestCache(t *testing.T) {
|
||||
pkg.ID{0xff, 2},
|
||||
new(want.hash()),
|
||||
testdata, nil,
|
||||
), nil, nil, pkg.InvalidFileModeError(
|
||||
), nil, nil, pkg.WCache, pkg.InvalidFileModeError(
|
||||
fs.ModeDir | 0500,
|
||||
)},
|
||||
|
||||
@@ -1064,7 +1067,7 @@ func TestCache(t *testing.T) {
|
||||
_, err = io.ReadAll(r)
|
||||
return err
|
||||
},
|
||||
}}, nil, nil, &os.PathError{
|
||||
}}, nil, nil, pkg.WNew, &os.PathError{
|
||||
Op: "read",
|
||||
Path: base.Append(
|
||||
"checksum",
|
||||
@@ -1078,14 +1081,14 @@ func TestCache(t *testing.T) {
|
||||
cure: func(t *pkg.TContext) error {
|
||||
return nil
|
||||
},
|
||||
}}, nil, nil, pkg.NoOutputError{}},
|
||||
}}, nil, nil, pkg.WNew, pkg.NoOutputError{}},
|
||||
|
||||
{"file output", overrideIdent{pkg.ID{0xff, 5}, &stubArtifact{
|
||||
kind: pkg.KindTar,
|
||||
cure: func(t *pkg.TContext) error {
|
||||
return os.WriteFile(t.GetWorkDir().String(), []byte{0}, 0400)
|
||||
},
|
||||
}}, nil, nil, errors.New("non-file artifact produced regular file")},
|
||||
}}, nil, nil, pkg.WNew, errors.New("non-file artifact produced regular file")},
|
||||
|
||||
{"symlink output", overrideIdent{pkg.ID{0xff, 6}, &stubArtifact{
|
||||
kind: pkg.KindTar,
|
||||
@@ -1095,7 +1098,7 @@ func TestCache(t *testing.T) {
|
||||
t.GetWorkDir().String(),
|
||||
)
|
||||
},
|
||||
}}, nil, nil, pkg.InvalidFileModeError(
|
||||
}}, nil, nil, pkg.WNew, pkg.InvalidFileModeError(
|
||||
fs.ModeSymlink | 0777,
|
||||
)},
|
||||
|
||||
@@ -1116,7 +1119,7 @@ func TestCache(t *testing.T) {
|
||||
}, base.Append(
|
||||
"identifier",
|
||||
"xMDWovje7OfyIaDy_2VnjpKxRqSOQ_LoeD946t-3WsS2V2SeMJ7nDGrNfpa4Pbc-",
|
||||
), want, nil},
|
||||
), want, pkg.WNew, nil},
|
||||
|
||||
{"substitutable", &stubArtifactF{
|
||||
kind: pkg.KindExec,
|
||||
@@ -1135,7 +1138,7 @@ func TestCache(t *testing.T) {
|
||||
}, base.Append(
|
||||
"identifier",
|
||||
"k2ilgG5KQ9NXnMoT2oB6NdwOnSPRn_H24oXQc4l6qOYIxIG9XfuEczeyrR8UEv_f",
|
||||
), want, nil},
|
||||
), want, pkg.WSubstitute, nil},
|
||||
})
|
||||
|
||||
if c0, err := unsafeOpen(
|
||||
@@ -1164,7 +1167,7 @@ func TestCache(t *testing.T) {
|
||||
}, base.Append(
|
||||
"identifier",
|
||||
"_EmV5nsYZ2UWHgRmLDMU8i-rJWDx-kv5_1pFrzQI7vMMCM5mAXivO8UZtVfOqMR_",
|
||||
), want, nil},
|
||||
), want, pkg.WSubstitute, nil},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1235,7 +1238,7 @@ func TestCache(t *testing.T) {
|
||||
pkg.ID{0xff, 1},
|
||||
nil,
|
||||
nil, stub.UniqueError(0xbad),
|
||||
), nil, nil, stub.UniqueError(0xbad)},
|
||||
), nil, nil, pkg.WNew, stub.UniqueError(0xbad)},
|
||||
|
||||
{"file output", overrideIdent{pkg.ID{0xff, 2}, &stubArtifact{
|
||||
kind: pkg.KindTar,
|
||||
@@ -1246,7 +1249,7 @@ func TestCache(t *testing.T) {
|
||||
0400,
|
||||
)
|
||||
},
|
||||
}}, nil, nil, errors.New(
|
||||
}}, nil, nil, pkg.WNew, errors.New(
|
||||
"non-file artifact produced regular file",
|
||||
)},
|
||||
})
|
||||
@@ -1363,14 +1366,14 @@ func TestCache(t *testing.T) {
|
||||
}}}, base.Append(
|
||||
"identifier",
|
||||
pkg.Encode(pkg.ID{0xff, 0}),
|
||||
), want, nil},
|
||||
), want, pkg.WNew, nil},
|
||||
|
||||
{"reject", overrideChecksum{want.hash(), overrideIdent{pkg.ID{0xfe, 1}, &stubArtifact{
|
||||
kind: pkg.KindTar,
|
||||
cure: func(t *pkg.TContext) error {
|
||||
return makeGarbage(t.GetWorkDir(), stub.UniqueError(0xbad))
|
||||
},
|
||||
}}}, nil, nil, stub.UniqueError(0xbad)},
|
||||
}}}, nil, nil, pkg.WNew, stub.UniqueError(0xbad)},
|
||||
|
||||
{"match", overrideChecksum{want.hash(), overrideIdent{pkg.ID{0xff, 1}, &stubArtifact{
|
||||
kind: pkg.KindTar,
|
||||
@@ -1380,7 +1383,7 @@ func TestCache(t *testing.T) {
|
||||
}}}, base.Append(
|
||||
"identifier",
|
||||
pkg.Encode(pkg.ID{0xff, 1}),
|
||||
), want, nil},
|
||||
), want, pkg.WNew, nil},
|
||||
})
|
||||
}, expectsFS{
|
||||
".": {Mode: fs.ModeDir | 0700},
|
||||
@@ -1408,7 +1411,7 @@ func TestCache(t *testing.T) {
|
||||
), base.Append(
|
||||
"identifier",
|
||||
pkg.Encode(pkg.Checksum{0xfe, 0}),
|
||||
), expectsChecksum{0xff, 0}, nil},
|
||||
), expectsChecksum{0xff, 0}, pkg.WNew, nil},
|
||||
})
|
||||
|
||||
for _, p := range [][]string{
|
||||
@@ -1485,7 +1488,7 @@ func TestCache(t *testing.T) {
|
||||
), expectsFS{
|
||||
".": {Mode: fs.ModeDir | 0500},
|
||||
"result": {Mode: 0444},
|
||||
}, nil},
|
||||
}, pkg.WNew, nil},
|
||||
|
||||
{"substituted", substituted, base.Append(
|
||||
"identifier",
|
||||
@@ -1493,7 +1496,7 @@ func TestCache(t *testing.T) {
|
||||
), expectsFS{
|
||||
".": {Mode: fs.ModeDir | 0500},
|
||||
"result": {Mode: 0444},
|
||||
}, nil},
|
||||
}, pkg.WSubstitute, nil},
|
||||
})
|
||||
}, expectsFS{
|
||||
".": {Mode: fs.ModeDir | 0700},
|
||||
@@ -1586,14 +1589,14 @@ func TestCache(t *testing.T) {
|
||||
{"extern", a, base.Append(
|
||||
"identifier",
|
||||
pkg.Encode(wantIdent.Value()),
|
||||
), wantOutput, nil},
|
||||
), wantOutput, pkg.WExternal, nil},
|
||||
|
||||
{"substitute", _a, base.Append(
|
||||
"identifier",
|
||||
pkg.Encode(_wantIdent.Value()),
|
||||
), _wantOutput, nil},
|
||||
), _wantOutput, pkg.WExternal, nil},
|
||||
|
||||
{"mismatch", kca, nil, nil, &pkg.ChecksumMismatchError{
|
||||
{"mismatch", kca, nil, nil, pkg.WExternal, &pkg.ChecksumMismatchError{
|
||||
Got: wantChecksum,
|
||||
}},
|
||||
})
|
||||
@@ -1717,27 +1720,27 @@ func TestCache(t *testing.T) {
|
||||
{"extern", a, base.Append(
|
||||
"identifier",
|
||||
pkg.Encode(wantIdent.Value()),
|
||||
), wantOutput, nil},
|
||||
), wantOutput, pkg.WExternal, nil},
|
||||
|
||||
{"flood shallow extern", fia, base.Append(
|
||||
"identifier",
|
||||
pkg.Encode(fiaIdent.Value()),
|
||||
), wantOutput, nil},
|
||||
), wantOutput, pkg.WExternal, nil},
|
||||
|
||||
{"substitute", _a, base.Append(
|
||||
"identifier",
|
||||
pkg.Encode(_wantIdent.Value()),
|
||||
), _wantOutput, nil},
|
||||
), _wantOutput, pkg.WExternal, nil},
|
||||
|
||||
{"flood shallow local", flia, base.Append(
|
||||
"identifier",
|
||||
pkg.Encode(fliaIdent.Value()),
|
||||
), wantOutput, nil},
|
||||
), wantOutput, pkg.WExternal, nil},
|
||||
|
||||
{"flood shallow hanging", fhia, nil, nil,
|
||||
pkg.HangingInputError(c.Ident(h))},
|
||||
pkg.WNew, pkg.HangingInputError(c.Ident(h))},
|
||||
|
||||
{"mismatch", kca, nil, nil, &pkg.ChecksumMismatchError{
|
||||
{"mismatch", kca, nil, nil, pkg.WExternal, &pkg.ChecksumMismatchError{
|
||||
Got: wantChecksum,
|
||||
}},
|
||||
})
|
||||
@@ -1781,7 +1784,7 @@ func TestErrors(t *testing.T) {
|
||||
}{
|
||||
{"InvalidLookupError", pkg.InvalidLookupError{
|
||||
0xff, 0xf0,
|
||||
}, "attempting to look up non-dependency artifact __AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"},
|
||||
}, "attempting to look up non-input artifact __AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"},
|
||||
|
||||
{"InvalidArtifactError", pkg.InvalidArtifactError{
|
||||
0xff, 0xfd,
|
||||
|
||||
Reference in New Issue
Block a user