Skip to content
quarry Artifact [01434c80cc]
Login

Artifact [01434c80cc]

Artifact 01434c80cc7a0dd3edb7122b3cce0c0c4e7219e6bbdafd22b779300e9b2a9346:


package api

import (
	"strings"
	"testing"

	"craftdesign.group/quarry/internal/ops"
)

// The artifact log has ONE gate, and every door into it carries the
// same letter.
//
// ticket.promote and ticket.discard have always taken `a`: the forge
// says in its own vocabulary that putting something into the permanent
// record — or taking it back out — is an administrator's act.
// ticket.new writes the same log and took `n`, which every Reader
// holds. So the sanctioned route in needed admin and the unsanctioned
// one did not.
//
// Found by dmestas asking why a Reader's eleven tickets were in the
// repository at all: jva holds bcghjoprz2378BC on quarry (no i, no w)
// and could still write artifacts that clone with it forever.
func TestEveryDoorIntoTheArtifactLogTakesTheSameLetter(t *testing.T) {
	r := ops.NewRegistry()
	if err := RegisterAll(r, Deps{Version: "v", Repos: testRepos(wikiIndex(t))}); err != nil {
		t.Fatal(err)
	}
	// ticket.new is NOT in this list any more. It writes the artifact
	// log only when the REPOSITORY says its tickets live there, and
	// dmestas's call is that permanence is a repository policy rather
	// than a per-caller privilege — so the letter it takes is `n` and
	// the tier decides the destination (see
	// TestANewTicketFollowsTheRepositorysTier). What still takes `a` is
	// every act that moves something INTO or OUT OF the permanent
	// record by hand.
	for _, name := range []string{"ticket.promote", "ticket.discard"} {
		op, ok := r.Lookup(name)
		if !ok {
			t.Errorf("FAIL: %s is not registered", name)
			continue
		}
		if !strings.Contains(op.Caps, "a") {
			t.Errorf("FAIL: %s writes or unwrites the artifact log with caps %q, not a", name, op.Caps)
		} else {
			t.Logf("ok: %s takes a", name)
		}
	}
	// And the intake door stays open to everybody who may file at all,
	// or raising the other gate would have closed the tracker.
	newOp, ok := r.Lookup("ticket.new")
	if !ok {
		t.Fatal("FAIL: ticket.new is not registered")
	}
	if newOp.Caps != "n" {
		t.Errorf("FAIL: ticket.new takes %q — filing must stay an ordinary act", newOp.Caps)
	} else {
		t.Log("ok: ticket.new takes n; the repository's tier decides where it lands")
	}
	intake, ok := r.Lookup("ticket.intake")
	if !ok {
		t.Fatal("FAIL: ticket.intake is not registered")
	}
	if intake.Caps != "n" {
		t.Errorf("FAIL: ticket.intake takes %q — filing a ticket must stay an ordinary act", intake.Caps)
	} else {
		t.Log("ok: ticket.intake still takes n, so a Reader can still file")
	}
}