Skip to content
quarry Artifact [f0be191cbb]
Login

Artifact [f0be191cbb]

Artifact f0be191cbbd2c5d80b3dcfe28eede614135348b4c1406884e288a5ba724ebe18:


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)
	}
	for _, name := range []string{"ticket.new", "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.
	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")
	}
}