From 18bbd699c1a20e99b48ee3f38970d5c33b18643f Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 18 Sep 2026 23:14:34 +1000 Subject: [PATCH] fix(update): write the agent version sidecar with a real newline printf '%s\\n' emitted the literal characters backslash-n, which archie-update-check's release-version check rejects, so every managed-agent update left the installed agent version reported as unknown. --- internal/releaseupdate/install_script_test.go | 21 +++++++++++++++++++ scripts/archie-update-install | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/internal/releaseupdate/install_script_test.go b/internal/releaseupdate/install_script_test.go index 7ca49d194..fdae8fac4 100644 --- a/internal/releaseupdate/install_script_test.go +++ b/internal/releaseupdate/install_script_test.go @@ -830,3 +830,24 @@ func TestUpdateInstallRefusesWhenTaskDatabaseCannotBeBackedUp(t *testing.T) { } assertCallAbsent(t, calls, "arhied.prev") } + +// The sidecar is the only record of the managed agent version, and +// archie-update-check refuses anything but a bare release version, so a stray +// escape in the write leaves the installed agent reported as unknown forever. +func TestUpdateInstallWritesABareAgentVersionSidecar(t *testing.T) { + versionFile := filepath.Join(t.TempDir(), "archie-agent.version") + runUpdateInstallScript(t, map[string]string{ + "ARCHIE_UPDATE_DAEMON_PREVIOUS": "1.13.0", + "ARCHIE_UPDATE_AGENT_PREVIOUS": "1.9.9", + "ARCHIE_UPDATE_AGENT_VERSION": "1.10.0", + "ARCHIE_AGENT_VERSION_FILE": versionFile, + }) + + recorded, err := os.ReadFile(versionFile) + if err != nil { + t.Fatal(err) + } + if string(recorded) != "1.10.0\n" { + t.Fatalf("sidecar = %q, want %q", recorded, "1.10.0\n") + } +} diff --git a/scripts/archie-update-install b/scripts/archie-update-install index c13039a62..ce3635f63 100755 --- a/scripts/archie-update-install +++ b/scripts/archie-update-install @@ -248,7 +248,7 @@ if [[ ",$components," == *,agent,* ]]; then # Only record a version after the image build succeeds. Write beside the # state atomically so the check never observes a partial version. version_tmp="$(mktemp "$AGENT_VERSION_FILE.tmp.XXXXXX")" - printf '%s\\n' "$RT" > "$version_tmp" + printf '%s\n' "$RT" > "$version_tmp" chmod 600 "$version_tmp" mv -f "$version_tmp" "$AGENT_VERSION_FILE" fi