Skip to content

fix: [sc-85690] Auto updater integration test#39

Merged
mlataza merged 8 commits intomainfrom
bug/sc-85690/auto-updater-integration-test
Mar 31, 2026
Merged

fix: [sc-85690] Auto updater integration test#39
mlataza merged 8 commits intomainfrom
bug/sc-85690/auto-updater-integration-test

Conversation

@mlataza
Copy link
Copy Markdown
Collaborator

@mlataza mlataza commented Mar 30, 2026

Summary

Story details: https://app.shortcut.com/rewst/story/85690

  • Adds an end-to-end auto updater integration test across all three platforms (Windows, Linux, macOS)
  • Fixes several reliability issues in the auto update flow: missing executable permissions, detached process launch, and an overridable update interval for testing

Changes

Auto updater integration test (scripts/build_integration_test.ps1, .github/workflows/integration-test.yml)

  • Added scripts/build_integration_test.ps1 — builds a special integration test binary using -ldflags to inject a fake version (v0.0.0-it, older than any real release) and a short update interval (30s) to force an auto update during the test
  • Added a build-integration-test job in the CI workflow that builds and caches the IT binary per platform using actions/cache@v5 (keyed on Go version + source hash)
  • Added three new steps in each platform's test job (before the logging level update):
    1. Install the IT binary (old version) via --update
    2. Poll the log file until "Updating agent" appears (up to 120s)
    3. Verify the agent restarted on a newer version than 0.0.0-it

Update interval override (internal/agent/updater.go)

  • Added updateIntervalStr package-level variable, injectable at build time via -ldflags
  • Added DefaultUpdateInterval() which reads updateIntervalStr if set, otherwise defaults to 48 hours
  • service.go updated to use DefaultUpdateInterval() instead of a hardcoded 48*time.Hour

Executable permission fix (internal/agent/updater.go)

  • Added os.Chmod(file.Name(), 0755) after downloading the installer binary to os.CreateTemp — without this, exec fails with permission denied on Unix since temp files are created without execute bits

Detached process launch (cmd/agent_smith/run_command_unix.go, run_command_windows.go)

  • The downloaded installer is launched via cmd.Start() (non-blocking), but it was inheriting the service's process group — causing it to be killed when the service shut down as part of the update handoff
  • Added platform-specific detachedCommand():
    • Unix (Darwin/Linux): syscall.SysProcAttr{Setsid: true} — creates a new session, fully detaching from the parent process group
    • Windows: CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP — equivalent detachment for the Windows process model
  • Installer stdout/stderr are routed to the service's log file for visibility

Test plan

  • Trigger the integration test workflow with os: all
  • Verify the build-integration-test job completes and artifacts are uploaded for all three platforms
  • Verify the "Wait for auto updater" step detects "Updating agent" within 120s on each platform
  • Verify the "Verify auto update completed" step confirms the agent restarted on a version newer than 0.0.0-it
  • Verify subsequent test steps (debug logging, syslog, uninstall) complete successfully after the auto update

@mlataza mlataza merged commit fa7ce57 into main Mar 31, 2026
51 of 57 checks passed
@mlataza mlataza deleted the bug/sc-85690/auto-updater-integration-test branch March 31, 2026 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant