Files
archie/deploy_workflow_test.go
T
sam 50693cf030 fix(release): package and update archie-messaging on a host install
The v1.30.0 extraction moved Telegram, email and webhook out of archied and into
cmd/archie-messaging, and nothing packaged it. dist-zip built and copied only the
five older binaries, and scripts/archie-update-install omitted it from both its
service and binary lists. A host upgraded across v1.30.0 therefore ran on with no
messaging process at all: archied logged that it stopped serving the telegram
gateway at the extraction, nothing replaced it, and the bot was dead for two days
with no error anywhere -- the daemon looked healthy throughout (archie-core-1c01).

Fixed in all four places the host component set was enumerated: the zip's build
loop, the zip's copy list, the installer's GATEWAY_SERVICES (messaging is a
service, so it is installed AND restarted) and its GATEWAY_BINARIES. The comment
claiming every process in the documented deployment ships in the zip is now true,
and says what makes it true.

The duplication was the actual defect, so the sets are pinned to cmd/ instead:
TestHostCommandListsCannotDrift derives the host-run commands from cmd/ and
asserts all four lists, plus the reference runbook's units, agree with it. Adding
a command or extracting one fails the test until it is packaged -- the check that
would have caught this on the day. The installer's own test grew the same
coverage, and the reason it passed while the bug was live is worth recording: its
fixture created only the stale cmd/ set, so the script's `[ -d ./cmd/$cmd ]` guard
silently skipped messaging.

Documentation, because the installer now refuses an update when a service unit is
missing and sends the operator to the runbook -- so a service the runbook omits is
a dead end: a messaging unit in deployments/systemd-user-service.md, the component
list and start sequence in deployments/INSTRUCTIONS.md (which ships inside the
zip), and the packaged-binary list in RELEASING.md.

Verified: task check exit 0, including test:tools and test:ui. Both new guards
were made to fail on purpose: reintroducing each omission produces "missing
archie-messaging" and "no call with fragments [./cmd/archie-messaging]".
2026-09-22 05:42:17 +10:00

257 lines
8.6 KiB
Go

package configtemplate
import (
"os"
"path/filepath"
"sort"
"strings"
"testing"
)
func TestDeployWorkflowOnlyPublishesRuntimeImageForRuntimeTag(t *testing.T) {
source := readDeploymentFile(t, ".github/workflows/deploy.yml")
// The fallback remains necessary because Dockerfile.archied accepts a
// runtime version, but it must not be used as the image-publish selector.
for _, required := range []string{
`RUNTIME_TAG="$(git tag --points-at HEAD --list 'archie/v*' | sort -V | tail -1)"`,
`echo "runtime_tag=$RUNTIME_TAG" >> "$GITHUB_OUTPUT"`,
"if: steps.versions.outputs.runtime_tag != ''",
} {
if !strings.Contains(source, required) {
t.Errorf("deploy workflow is missing runtime-image guard %q", required)
}
}
// The gateway build remains unconditional, while the runtime build is
// guarded. This verifies both sides of the gateway-only/dual-tag contract.
agentMarker := " - name: Build and push archie-agent\n"
agentStart := strings.Index(source, agentMarker)
if agentStart < 0 {
t.Fatal("deploy workflow has no archie-agent build step")
}
if !strings.Contains(source[agentStart:], agentMarker+" if: steps.versions.outputs.runtime_tag != ''\n") {
t.Fatal("archie-agent build step is not conditionally enabled")
}
gatewayMarker := " - name: Build and push archied\n"
gatewayStart := strings.Index(source, gatewayMarker)
if gatewayStart < 0 {
t.Fatal("deploy workflow has no archied build step")
}
if strings.Contains(source[gatewayStart:agentStart], "\n if:") {
t.Fatal("archied build step is unexpectedly conditional")
}
}
func TestDeployWorkflowUsesConfiguredFormatters(t *testing.T) {
source := readDeploymentFile(t, ".github/workflows/deploy.yml")
for _, required := range []string{
"github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.13.2",
"golangci-lint fmt",
"git diff --exit-code",
"golangci-lint run ./...",
} {
if !strings.Contains(source, required) {
t.Errorf("deploy workflow is missing formatter gate %q", required)
}
}
if strings.Contains(source, "gofumpt -w .") {
t.Error("deploy workflow bypasses the configured formatter set")
}
}
func TestPullRequestsRunTheDefinitiveGateWithoutPublishAccess(t *testing.T) {
source := readDeploymentFile(t, ".github/workflows/quality.yml")
for _, required := range []string{
"pull_request:",
"contents: read",
"task check",
"git diff --exit-code",
} {
if !strings.Contains(source, required) {
t.Errorf("quality workflow is missing %q", required)
}
}
for _, forbidden := range []string{
"packages: write",
"docker/login-action",
"docker/build-push-action",
} {
if strings.Contains(source, forbidden) {
t.Errorf("quality workflow has publishing capability %q", forbidden)
}
}
}
// unpackagedCommands are commands that deliberately never ship as a host binary.
// Naming each one with its reason keeps an omission a decision rather than an
// oversight -- which is exactly how archied's channels were lost.
var unpackagedCommands = map[string]string{
"archie-agent": "runs only inside the Docker image build-and-push publishes, never as a host binary",
}
// cliOnlyCommands ship in the zip but must never be restarted by the updater:
// they are not services.
var cliOnlyCommands = map[string]bool{"archie-playbooks": true}
// TestHostCommandListsCannotDrift is why archie-core-1c01 went unnoticed for two
// days. The v1.30.0 extraction moved Telegram, email and webhook out of archied
// into a new cmd/archie-messaging that nothing packaged: the release zip omitted
// it, and scripts/archie-update-install omitted it from both of its lists, so a
// host install ran on with a dead Telegram bot and no error logged anywhere. The
// daemon looked healthy throughout.
//
// The host component set was enumerated independently in three places (the zip's
// build loop, the zip's copy list, and the installer's two lists), so two
// coordinated edits would have drifted again. Every list is pinned to cmd/ here
// instead: adding a command fails this test until it is packaged, and extracting
// one fails it until the previous command is removed.
func TestHostCommandListsCannotDrift(t *testing.T) {
workflow := readDeploymentFile(t, ".github/workflows/deploy.yml")
installer := readDeploymentFile(t, filepath.Join("scripts", "archie-update-install"))
want := hostRunCommands(t)
wantBinaries := want
wantServices := withoutCLIOnly(want)
built := wordsAfter(t, workflow, "for cmd in ", "; do", nil)
// The marker consumes the prefix of the first word only, so restore it for
// whichever word the marker ended inside.
var shipped []string
for _, word := range wordsAfter(t, workflow, "cp dist/", ` "$name/"`, nil) {
if !strings.HasPrefix(word, "dist/") {
word = "dist/" + word
}
shipped = append(shipped, strings.TrimPrefix(word, "dist/"))
}
services := wordsAfter(t, installer, `GATEWAY_SERVICES="`, `"`, nil)
binaries := wordsAfter(t, installer, `GATEWAY_BINARIES="`, `"`, map[string][]string{"$GATEWAY_SERVICES": services})
for _, list := range []struct {
name string
got []string
want []string
}{
{"deploy.yml dist-zip build loop", built, wantBinaries},
{"deploy.yml dist-zip copy list", shipped, wantBinaries},
{"archie-update-install GATEWAY_BINARIES", binaries, wantBinaries},
{"archie-update-install GATEWAY_SERVICES", services, wantServices},
} {
if diff := setDifference(list.want, list.got); diff != "" {
t.Errorf("%s does not match the host-run commands in cmd/: %s", list.name, diff)
}
}
// The installer now REFUSES an update when a service unit is missing and
// tells the operator to create it from this runbook, so a service the
// runbook never shows is a dead end rather than a documentation gap.
runbook := readDeploymentFile(t, filepath.Join("deployments", "systemd-user-service.md"))
var undocumented []string
for _, service := range wantServices {
if !strings.Contains(runbook, "/bin/"+service+" ") {
undocumented = append(undocumented, service)
}
}
if len(undocumented) > 0 {
t.Errorf("deployments/systemd-user-service.md documents no unit for: %s", strings.Join(undocumented, " "))
}
}
// hostRunCommands is every command under cmd/, minus the deliberately
// unpackaged ones. Deriving it is the point: a list written out here would drift
// from cmd/ exactly as the packaged lists did.
func hostRunCommands(t *testing.T) []string {
t.Helper()
entries, err := os.ReadDir("cmd")
if err != nil {
t.Fatalf("read cmd/: %v", err)
}
var commands []string
for _, entry := range entries {
if !entry.IsDir() {
continue
}
if _, skip := unpackagedCommands[entry.Name()]; skip {
continue
}
commands = append(commands, entry.Name())
}
if len(commands) == 0 {
t.Fatal("cmd/ holds no commands: this guard would assert nothing")
}
sort.Strings(commands)
return commands
}
func withoutCLIOnly(commands []string) []string {
out := make([]string, 0, len(commands))
for _, command := range commands {
if cliOnlyCommands[command] {
continue
}
out = append(out, command)
}
return out
}
// wordsAfter returns the whitespace-separated words between two markers on the
// same line. expand maps a word to the words it stands for, which is how the
// installer's "$GATEWAY_SERVICES" reference is followed to what it names.
func wordsAfter(t *testing.T, source, marker, terminator string, expand map[string][]string) []string {
t.Helper()
start := strings.Index(source, marker)
if start < 0 {
t.Fatalf("no %q in the file under test", marker)
}
rest := source[start+len(marker):]
end := strings.Index(rest, terminator)
if end < 0 {
t.Fatalf("no %q after %q", terminator, marker)
}
var words []string
for word := range strings.FieldsSeq(rest[:end]) {
if replacement, ok := expand[word]; ok {
words = append(words, replacement...)
continue
}
words = append(words, word)
}
return words
}
// setDifference names what is missing from and extra in got, so a failure says
// which side moved rather than that two lists differ.
func setDifference(want, got []string) string {
present := make(map[string]bool, len(got))
for _, item := range got {
present[item] = true
}
var missing []string
for _, item := range want {
if !present[item] {
missing = append(missing, item)
}
}
expected := make(map[string]bool, len(want))
for _, item := range want {
expected[item] = true
}
var extra []string
for _, item := range got {
if !expected[item] {
extra = append(extra, item)
}
}
sort.Strings(missing)
sort.Strings(extra)
var problems []string
if len(missing) > 0 {
problems = append(problems, "missing "+strings.Join(missing, " "))
}
if len(extra) > 0 {
problems = append(problems, "unexpected "+strings.Join(extra, " "))
}
return strings.Join(problems, "; ")
}