From 9feac7738f5dbe9f2f32cfa297582d3b520cb049 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Fri, 3 Apr 2026 20:33:59 +0900 Subject: internal/pkg: optionally suppress via assumed checksum This is quite error-prone and causes cache inconsistency similar to the store inconsistency seen on nix when a similar condition happens. Keep this behind a flag in case it is ever beneficial. Signed-off-by: Ophestra --- internal/pkg/pkg_test.go | 51 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'internal/pkg/pkg_test.go') diff --git a/internal/pkg/pkg_test.go b/internal/pkg/pkg_test.go index 82f260e7..50e2a584 100644 --- a/internal/pkg/pkg_test.go +++ b/internal/pkg/pkg_test.go @@ -469,7 +469,7 @@ func TestCache(t *testing.T) { }() testCases := []cacheTestCase{ - {"file", pkg.CValidateKnown, nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) { + {"file", pkg.CValidateKnown | pkg.CAssumeChecksum, nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) { identifier := (pkg.ID)(bytes.Repeat([]byte{ 0x75, 0xe6, 0x9d, 0x6d, 0xe7, 0x9f, }, 8)) @@ -626,7 +626,7 @@ func TestCache(t *testing.T) { } }, pkg.MustDecode("St9rlE-mGZ5gXwiv_hzQ_B8bZP-UUvSNmf4nHUZzCMOumb6hKnheZSe0dmnuc4Q2")}, - {"directory", 0, nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) { + {"directory", pkg.CAssumeChecksum, nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) { id := pkg.MustDecode( "HnySzeLQvSBZuTUcvfmLEX_OmH4yJWWH788NxuLuv7kVn8_uPM6Ks4rqFWM2NZJY", ) @@ -873,6 +873,53 @@ func TestCache(t *testing.T) { <-wCureDone }, pkg.MustDecode("E4vEZKhCcL2gPZ2Tt59FS3lDng-d_2SKa2i5G_RbDfwGn6EemptFaGLPUDiOa94C")}, + {"no assume checksum", 0, nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) { + makeGarbage := func(work *check.Absolute, wantErr error) error { + if err := os.Mkdir(work.String(), 0700); err != nil { + return err + } + + if err := os.WriteFile(work.Append( + "check", + ).String(), nil, 0400); err != nil { + return err + } + + return wantErr + } + + wantChecksum := pkg.MustDecode("Aubi5EG4_Y8DhL9bQ3Q4HFBhLRF7X5gt9D3CNCQfT-TeBtlRXc7Zi_JYZEMoCC7M") + + cureMany(t, c, []cureStep{ + {"create", overrideChecksum{wantChecksum, overrideIdent{pkg.ID{0xff, 0}, &stubArtifact{ + kind: pkg.KindTar, + cure: func(t *pkg.TContext) error { + return makeGarbage(t.GetWorkDir(), nil) + }, + }}}, base.Append( + "identifier", + pkg.Encode(pkg.ID{0xff, 0}), + ), wantChecksum, nil}, + + {"reject", overrideChecksum{wantChecksum, overrideIdent{pkg.ID{0xfe, 1}, &stubArtifact{ + kind: pkg.KindTar, + cure: func(t *pkg.TContext) error { + return makeGarbage(t.GetWorkDir(), stub.UniqueError(0xbad)) + }, + }}}, nil, pkg.Checksum{}, stub.UniqueError(0xbad)}, + + {"match", overrideChecksum{wantChecksum, overrideIdent{pkg.ID{0xff, 1}, &stubArtifact{ + kind: pkg.KindTar, + cure: func(t *pkg.TContext) error { + return makeGarbage(t.GetWorkDir(), nil) + }, + }}}, base.Append( + "identifier", + pkg.Encode(pkg.ID{0xff, 1}), + ), wantChecksum, nil}, + }) + }, pkg.MustDecode("OC290t23aimNo2Rp2pPwan5GI2KRLRdOwYxXQMD9jw0QROgHnNXWodoWdV0hwu2w")}, + {"scrub", 0, nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) { cureMany(t, c, []cureStep{ {"bad measured file", newStubFile( -- cgit v1.3.1