Skip to main content

Module update

Module update 

Source
Expand description

Release and update mechanism: ctx self-update, ctx --version --check, and the passive update notice.

§Determinism rule

ctx never updates itself automatically. The passive check only prints a one-line notice to stderr; replacing the binary always requires an explicit ctx self-update invocation.

§How updates work

Releases are published by .github/workflows/release.yml: one archive per platform named ctx-<tag>-<target>.tar.gz (.zip on Windows), plus an aggregated SHA256SUMS file. self_update queries the GitHub Releases API, downloads the artifact for the compile-time target, verifies its sha256 against SHA256SUMS, extracts the ctx binary member, and atomically renames it over the running executable. On checksum mismatch the update aborts with an error (exit code 2) and the installed binary is left untouched.

§Test hooks (undocumented environment variables)

  • CTX_UPDATE_BASE_URL: overrides the GitHub API base URL so integration tests can point at a local mock server (asset download URLs come from the release JSON itself, so the mock controls those too).
  • CTX_CACHE_DIR: overrides the passive-check cache directory (default: dirs::cache_dir()/ctx).
  • CTX_UPDATE_FORCE_TTY=1: makes the passive check treat stderr as a terminal, so the end-to-end notice path can be exercised from a test where stderr is a pipe.

Structs§

Asset
One downloadable asset attached to a release.
Release
A GitHub release: tag (e.g. v0.3.0) plus its assets.
SelfUpdateReport
Result of a self_update run.

Constants§

PASSIVE_CHECK_INTERVAL_SECS
How often the passive check may touch the network (24 hours).

Functions§

artifact_name
Release artifact file name for a tag and target, mirroring the packaging steps in .github/workflows/release.yml (ctx-<tag>-<target>.tar.gz, .zip for Windows). tag includes the leading v (it is $GITHUB_REF_NAME in the workflow).
cache_dir
Cache directory for the passive-check timestamp: $CTX_CACHE_DIR (test hook) or dirs::cache_dir()/ctx.
check_is_due
True when the 24h interval since the last recorded check has elapsed (or no valid timestamp is recorded). now is unix seconds, injected so tests control the clock.
current_version
The version this binary was built as.
explicit_check
Query the latest release and compare against the running binary.
latest_release
Fetch the latest (non-prerelease, non-draft) release.
parse_release
Parse the GitHub Releases API JSON for one release.
parse_sha256sums
Parse a SHA256SUMS file: one <hex> <name> entry per line (the sha256sum / shasum -a 256 format; a leading * on the name marks binary mode and is stripped). Returns file name -> lowercase hex digest.
passive_check
Passive update check, called from main after the command has finished (ctx self-update and ctx --version invocations skip it entirely).
passive_check_allowed
The passive-check suppression predicate (H3). Pure so the whole gate matrix is unit-testable; env abstracts std::env::var.
record_check
Record now (unix seconds) as the last check attempt.
release_by_tag
Fetch a specific release by tag (e.g. v0.3.0).
release_target
The release target triple this binary was compiled for, or None when the release workflow publishes no artifact for this platform.
self_update
Update the running executable from the GitHub release feed.
update_notice
The stderr notice printed by the passive check, also reused by ctx --version --check.