Skip to content
quarry Artifact [5d18395807]
Login

Artifact [5d18395807]

Artifact 5d18395807cd88dfab91b64da48d9bdf42bbacbe86d959a68f6284d6f62e063d:


package ingest

import (
	"path/filepath"
	"testing"

	"craftdesign.group/quarry/internal/index"
	"craftdesign.group/quarry/internal/zitcli"
)

// A sync can bring nothing but a content blob — exactly the blob a
// mirror's attachment card was waiting for — and a content blob is not
// folded. The index must still hear that bytes arrived, or a blob
// attachment.head remembered as missing stays hidden until some
// unrelated artifact happens to fold.
func TestAContentOnlyArtifactForgetsTheAbsentSet(t *testing.T) {
	ix, err := index.Open(filepath.Join(t.TempDir(), "i.db"))
	if err != nil {
		t.Fatal(err)
	}
	t.Cleanup(func() { ix.Close() })
	_, gen := ix.AttachmentAbsent("dddd")
	ix.RememberAttachmentAbsent("dddd", gen)
	if absent, _ := ix.AttachmentAbsent("dddd"); !absent {
		t.Fatal("FAIL: setup: the blob was not remembered absent")
	}
	p := &Pipeline{ix: ix}
	if art := p.offered(zitcli.Artifact{Hash: "dddd", Bytes: []byte("just the bytes of a file\n")}); art != nil {
		t.Fatalf("FAIL: plain content parsed as %v", art.Type)
	}
	if absent, _ := ix.AttachmentAbsent("dddd"); absent {
		t.Fatal("FAIL: a content-only artifact left a blob remembered as absent")
	}
	t.Log("ok: a content blob arriving without a fold forgets the absent set")
}