vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Let a release change until a channel names it
214e7ea67ccb37d356a52097f8ce838bdf4c1731 · Keenan Nemetz · 17d ago · parent 502119f4
Let a release change until a channel names it A release is mutable again. Notes can be edited and files added, replaced, or removed after publication, because a mistyped note or a rebuilt binary is not a reason to cut a new version. Editing the notes re-tags the same commit, which the old rule refused from the first attached file. The one thing that stays frozen is a release a channel names. A channel records the tag name and the tag object, so a re-tag would dangle it and a changed pointer would serve different bytes under a URL a package manager already cached. Pre-receive reads the channel table from the instance database and refuses every change to a channeled release — tag moves and deletes, and added, replaced, or removed pointers alike — naming the channel and how to move it. The browser applies the same rule: the edit form, the attach form, and the list link are all drawn from it. Attaching also works from the browser now, at parity with the CLI. The Artifacts card takes files, or a directory, and an optional directory to publish under; the handler streams each part to a temp file while hashing it, checks the object-store quota before storing anything, writes bytes first and pointers second, and calls the same metadata writer the CLI does. A directory upload keeps its paths, which is why the body is read as a multipart stream rather than through ParseForm.
server/releases_test.go +104−31
| @@ -18,6 +18,7 @@ import ( | |||
| 18 | 18 | "time" | |
| 19 | 19 | ||
| 20 | 20 | "rodent.software/vole/forge" | |
| 21 | "rodent.software/vole/forge/channel" | ||
| 21 | 22 | ) | |
| 22 | 23 | ||
| 23 | 24 | // releaseFixture builds a repository with one commit tagged v0.9.0 and a second | |
| @@ -573,11 +574,32 @@ func pointerFor(t *testing.T, f *fixture, data []byte) string { | |||
| 573 | 574 | return fmt.Sprintf("version https://git-lfs.github.com/spec/v1\noid sha256:%s\nsize %d\n", oid, len(data)) | |
| 574 | 575 | } | |
| 575 | 576 | ||
| 576 | // TestPublishedReleaseIsImmutable covers the rule from four directions: the tag | ||
| 577 | // cannot move, the tag cannot be deleted, a pointer cannot be removed, and a | ||
| 578 | // pointer cannot be re-pointed. A link that can change bytes is worse than no | ||
| 579 | // link, and a writer is the person most likely to do it by accident. | ||
| 580 | func TestPublishedReleaseIsImmutable(t *testing.T) { | ||
| 577 | // setChannel points a channel at the tag as the server currently sees it. The | ||
| 578 | // recorded object is the tag object, which is what makes a re-tag visible. | ||
| 579 | func setChannel(t *testing.T, f *fixture, name, tag string) { | ||
| 580 | t.Helper() | ||
| 581 | m := mustRepo(t, f) | ||
| 582 | tg, err := m.Git().Tag(tag) | ||
| 583 | if err != nil { | ||
| 584 | t.Fatalf("tag %s: %v", tag, err) | ||
| 585 | } | ||
| 586 | if err := f.srv.Channels.Set(m.ID, channel.Channel{ | ||
| 587 | Name: name, | ||
| 588 | Release: tag, | ||
| 589 | ReleaseObject: tg.OID, | ||
| 590 | UpdatedBy: "keenan", | ||
| 591 | UpdatedAt: time.Now().UTC(), | ||
| 592 | }); err != nil { | ||
| 593 | t.Fatalf("set channel %s: %v", name, err) | ||
| 594 | } | ||
| 595 | } | ||
| 596 | |||
| 597 | // TestReleaseCanBeEditedAfterPublication is the mutability rule: notes, added | ||
| 598 | // files, replaced files, and removed files all change a published release, and | ||
| 599 | // none of them needs a new tag. The notes are the tag message, so editing them | ||
| 600 | // re-tags the same commit, which is exactly what the old blanket refusal existed | ||
| 601 | // to forbid. | ||
| 602 | func TestReleaseCanBeEditedAfterPublication(t *testing.T) { | ||
| 581 | 603 | t.Parallel() | |
| 582 | 604 | f := newFixture(t) | |
| 583 | 605 | f.publish(f.repo) | |
| @@ -595,57 +617,107 @@ func TestPublishedReleaseIsImmutable(t *testing.T) { | |||
| 595 | 617 | ||
| 596 | 618 | writerKey := f.addWriter(t) | |
| 597 | 619 | ||
| 598 | // A second commit for the tag to be moved onto. | ||
| 599 | if err := os.WriteFile(filepath.Join(work, "a.txt"), []byte("two\n"), 0o644); err != nil { | ||
| 600 | t.Fatal(err) | ||
| 620 | // Edit the notes: a new tag object at the same commit. | ||
| 621 | if _, errs, err := runGit(t, work, "tag", "-f", "-a", "v1.0.0", "-m", "corrected notes\n"); err != nil { | ||
| 622 | t.Fatalf("re-tag: %s", errs) | ||
| 601 | 623 | } | |
| 602 | if _, errs, err := runGit(t, work, "add", "-A"); err != nil { | ||
| 603 | t.Fatal(errs) | ||
| 624 | if _, errs, err := fgit(t, writerKey, work, "push", "--force", f.sshURL(f.repo), | ||
| 625 | "refs/tags/v1.0.0:refs/tags/v1.0.0"); err != nil { | ||
| 626 | t.Fatalf("editing the notes was refused: %s", errs) | ||
| 604 | 627 | } | |
| 605 | if _, errs, err := runGit(t, work, "commit", "-qm", "second"); err != nil { | ||
| 606 | t.Fatal(errs) | ||
| 628 | m := mustRepo(t, f) | ||
| 629 | if tg, err := m.Git().Tag("v1.0.0"); err != nil || !strings.Contains(tg.Message, "corrected notes") { | ||
| 630 | t.Fatalf("the edited notes were not stored: %+v %v", tg, err) | ||
| 631 | } | ||
| 632 | |||
| 633 | // Replace the artifact's bytes under the same path. | ||
| 634 | newPointer := pointerFor(t, f, []byte("the rebuilt bytes")) | ||
| 635 | if _, err := pushMetaAs(t, f, writerKey, | ||
| 636 | map[string]string{"releases/v1.0.0/tool": newPointer}, nil, "replace the artifact"); err != nil { | ||
| 637 | t.Fatalf("replacing an artifact was refused: %v", err) | ||
| 638 | } | ||
| 639 | // Remove it. | ||
| 640 | if _, err := pushMetaAs(t, f, writerKey, nil, | ||
| 641 | []string{"releases/v1.0.0/tool"}, "remove the artifact"); err != nil { | ||
| 642 | t.Fatalf("removing an artifact was refused: %v", err) | ||
| 643 | } | ||
| 644 | // Add another. | ||
| 645 | if _, err := pushMetaAs(t, f, writerKey, | ||
| 646 | map[string]string{"releases/v1.0.0/tool2": pointerFor(t, f, []byte("second artifact"))}, nil, | ||
| 647 | "add an artifact"); err != nil { | ||
| 648 | t.Fatalf("adding an artifact was refused: %v", err) | ||
| 607 | 649 | } | |
| 650 | } | ||
| 651 | |||
| 652 | // TestChanneledReleaseIsFrozen covers the one rule mutability keeps: a channel is | ||
| 653 | // the promise that a URL keeps serving one release, so the release it names stops | ||
| 654 | // changing — notes, additions, replacements and removals alike — until the | ||
| 655 | // channel names something else. | ||
| 656 | func TestChanneledReleaseIsFrozen(t *testing.T) { | ||
| 657 | t.Parallel() | ||
| 658 | f := newFixture(t) | ||
| 659 | f.publish(f.repo) | ||
| 660 | work := workRepo(t, map[string]string{"a.txt": "one\n"}) | ||
| 608 | 661 | if _, errs, err := f.git(work, "push", f.sshURL(f.repo), "main:refs/heads/main"); err != nil { | |
| 609 | 662 | t.Fatalf("push: %s", errs) | |
| 610 | 663 | } | |
| 664 | for _, tag := range []string{"v0.9.0", "v1.0.0"} { | ||
| 665 | if _, errs, err := runGit(t, work, "tag", "-a", tag, "-m", tag+" notes\n"); err != nil { | ||
| 666 | t.Fatalf("tag %s: %s", tag, errs) | ||
| 667 | } | ||
| 668 | if _, errs, err := f.git(work, "push", f.sshURL(f.repo), "refs/tags/"+tag+":refs/tags/"+tag); err != nil { | ||
| 669 | t.Fatalf("push tag %s: %s", tag, errs) | ||
| 670 | } | ||
| 671 | } | ||
| 672 | attachArtifact(t, f, "v1.0.0", "tool", []byte("the published bytes")) | ||
| 673 | writerKey := f.addWriter(t) | ||
| 674 | setChannel(t, f, "stable", "v1.0.0") | ||
| 611 | 675 | ||
| 612 | if _, errs, err := runGit(t, work, "tag", "-f", "-a", "v1.0.0", "-m", "moved\n"); err != nil { | ||
| 676 | // The notes cannot move, even at the same commit. | ||
| 677 | if _, errs, err := runGit(t, work, "tag", "-f", "-a", "v1.0.0", "-m", "rewritten\n"); err != nil { | ||
| 613 | 678 | t.Fatalf("re-tag: %s", errs) | |
| 614 | 679 | } | |
| 615 | 680 | if _, errs, err := fgit(t, writerKey, work, "push", "--force", f.sshURL(f.repo), | |
| 616 | 681 | "refs/tags/v1.0.0:refs/tags/v1.0.0"); err == nil { | |
| 617 | t.Fatalf("moving a released tag was accepted: %s", errs) | ||
| 618 | } else if !strings.Contains(errs, "release artifacts attached") { | ||
| 619 | t.Fatalf("refusal does not explain itself: %s", errs) | ||
| 682 | t.Fatalf("editing a channeled release was accepted: %s", errs) | ||
| 683 | } else if !strings.Contains(errs, "channel stable") { | ||
| 684 | t.Fatalf("refusal does not name the channel: %s", errs) | ||
| 620 | 685 | } | |
| 621 | |||
| 686 | // Nor can the tag go away. | ||
| 622 | 687 | if _, errs, err := fgit(t, writerKey, work, "push", f.sshURL(f.repo), | |
| 623 | 688 | ":refs/tags/v1.0.0"); err == nil { | |
| 624 | t.Fatalf("deleting a released tag was accepted: %s", errs) | ||
| 689 | t.Fatalf("deleting a channeled release was accepted: %s", errs) | ||
| 625 | 690 | } | |
| 626 | |||
| 627 | // A pointer cannot be removed... | ||
| 628 | if _, err := pushMetaAs(t, f, writerKey, nil, []string{"releases/v1.0.0/tool"}, "drop the artifact"); err == nil { | ||
| 629 | t.Fatal("removing a published artifact was accepted") | ||
| 691 | // Nor can the files: removed, replaced, or added. | ||
| 692 | if out, err := pushMetaAs(t, f, writerKey, nil, | ||
| 693 | []string{"releases/v1.0.0/tool"}, "drop the artifact"); err == nil { | ||
| 694 | t.Fatal("removing an artifact of a channeled release was accepted") | ||
| 695 | } else if !strings.Contains(out, "channel stable") { | ||
| 696 | t.Fatalf("refusal does not name the channel: %s", out) | ||
| 630 | 697 | } | |
| 631 | // ...and cannot be re-pointed at different bytes under the same name. | ||
| 632 | 698 | if _, err := pushMetaAs(t, f, writerKey, | |
| 633 | 699 | map[string]string{"releases/v1.0.0/tool": pointerFor(t, f, []byte("different bytes"))}, nil, | |
| 634 | 700 | "swap the artifact"); err == nil { | |
| 635 | t.Fatal("re-pointing a published artifact was accepted") | ||
| 701 | t.Fatal("replacing an artifact of a channeled release was accepted") | ||
| 636 | 702 | } | |
| 637 | // Adding another artifact is not a rewrite: it invalidates nothing. | ||
| 638 | 703 | if _, err := pushMetaAs(t, f, writerKey, | |
| 639 | 704 | map[string]string{"releases/v1.0.0/tool2": pointerFor(t, f, []byte("second artifact"))}, nil, | |
| 640 | "add an artifact"); err != nil { | ||
| 641 | t.Fatalf("adding an artifact was refused: %v", err) | ||
| 705 | "add an artifact"); err == nil { | ||
| 706 | t.Fatal("adding a file to a channeled release was accepted") | ||
| 707 | } | ||
| 708 | |||
| 709 | // Moving the channel out of the way releases the rule. | ||
| 710 | setChannel(t, f, "stable", "v0.9.0") | ||
| 711 | if _, err := pushMetaAs(t, f, writerKey, nil, | ||
| 712 | []string{"releases/v1.0.0/tool"}, "drop the artifact"); err != nil { | ||
| 713 | t.Fatalf("editing after the channel moved was refused: %v", err) | ||
| 642 | 714 | } | |
| 643 | 715 | } | |
| 644 | 716 | ||
| 645 | // TestAdminCanRepairARelease, audited: refusing an admin outright leaves a | ||
| 646 | // mistyped tag unrepairable, and an unaudited override leaves no trace of the | ||
| 647 | // bytes that changed under somebody's link. | ||
| 648 | func TestAdminCanRepairARelease(t *testing.T) { | ||
| 717 | // TestAdminCanRepairAChanneledRelease, audited: refusing an admin outright leaves | ||
| 718 | // a release that a forgotten channel freezes unrepairable, and an unaudited | ||
| 719 | // override leaves no trace of the bytes that changed under somebody's link. | ||
| 720 | func TestAdminCanRepairAChanneledRelease(t *testing.T) { | ||
| 649 | 721 | t.Parallel() | |
| 650 | 722 | f := newFixture(t) | |
| 651 | 723 | f.publish(f.repo) | |
| @@ -660,6 +732,7 @@ func TestAdminCanRepairARelease(t *testing.T) { | |||
| 660 | 732 | t.Fatalf("push tag: %s", errs) | |
| 661 | 733 | } | |
| 662 | 734 | attachArtifact(t, f, "v1.0.0", "tool", []byte("bytes")) | |
| 735 | setChannel(t, f, "stable", "v1.0.0") | ||
| 663 | 736 | ||
| 664 | 737 | if _, err := pushMetaAs(t, f, f.keyPath, nil, []string{"releases/v1.0.0/tool"}, "remove a bad artifact"); err != nil { | |
| 665 | 738 | t.Fatalf("an admin could not repair the release: %v", err) | |