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