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. - Self
Update Report - Result of a
self_updaterun.
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,.zipfor Windows).tagincludes the leadingv(it is$GITHUB_REF_NAMEin the workflow). - cache_
dir - Cache directory for the passive-check timestamp:
$CTX_CACHE_DIR(test hook) ordirs::cache_dir()/ctx. - check_
is_ due - True when the 24h interval since the last recorded check has elapsed
(or no valid timestamp is recorded).
nowis 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
SHA256SUMSfile: one<hex> <name>entry per line (thesha256sum/shasum -a 256format; a leading*on the name marks binary mode and is stripped). Returns file name -> lowercase hex digest. - passive_
check - Passive update check, called from
mainafter the command has finished (ctx self-updateandctx --versioninvocations skip it entirely). - passive_
check_ allowed - The passive-check suppression predicate (H3). Pure so the whole gate
matrix is unit-testable;
envabstractsstd::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
Nonewhen 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.