GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: add unit tests for version-check comparison and skip logic by Montana · Pull Request #1339 · sourcegraph/src-cli

Conversation

@Montana

@Montana Montana commented Jun 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Hey Sourcegraph,

This change adds cmd/src/version_check_test.go, covering both pieces of thenew logic with table-driven unit tests. The functions under test are pure and have no network or filesystem dependencies, so the suite runs fast and
deterministically.

isOutdated

Verifies the version comparison that decides whether a warning should fire:

  • Major / minor / patch comparison — confirms an older patch (4.3.0 vs
    4.3.1), older minor (4.3.0 vs 4.4.0), and older major (3.43.0 vs
    4.0.0) are each reported as outdated, while equal (4.4.0 vs 4.4.0) and
    newer (4.5.0 vs 4.4.0) versions are not.
  • v-prefixes — checks that a leading v (v4.3.0) parses correctly and
    compares the same as its bare form, so the result doesn't depend on how the
    version string is formatted.
  • Prereleases — ensures comparison is limited to the major/minor/patch
    components: a prerelease on the same base (4.4.0-rc.1 vs 4.4.0) is not
    flagged as outdated, while a prerelease on an older base (4.3.0-rc.1 vs
    4.4.0) still is. This guards against spurious warnings for users running
    release candidates.
  • Unparseable input — confirms the function returns ok = false (rather
    than guessing) when the current version can't be parsed (dev) or the
    recommended version is empty, so callers know to stay silent instead of
    warning on bad data.

shouldSkipVersionCheck

Verifies the guard that decides when to run the check at all:

  • No-op subcommands — confirms the check is skipped for version, help,
    an empty subcommand, and flag-only invocations like -h / --help, where a
    warning would be noise (and where version already reports this information
    itself).
  • Normal subcommands — confirms the check does run for representative
    real commands (search, batch, api), so the feature isn't accidentally
    disabled.
  • SRC_SKIP_VERSION_CHECK opt-out — confirms setting the environment
    variable suppresses the check, covering the documented escape hatch for CI
    and scripts.
  • Dev builds — confirms the check is skipped when version.BuildTag is the
    default dev value, so local and development builds don't warn on every
    invocation.

Because shouldSkipVersionCheck reads the package-level version.BuildTag, the test temporarily overrides it to a real release value (4.3.0) and restores it via t.Cleanup, keeping the cases isolated from the build-time version.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Montana
test: add unit tests for version-check comparison and skip logic
d692b63
@keegancsmith
keegancsmith requested review from burmudar and keegancsmith July 1, 2026 11:12
@burmudar

burmudar commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

@Montana This test should be part of #1338. Please update that PR as I am closing this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@burmudar burmudar closed this Jul 1, 2026
@Montana

Montana commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Hi @burmudar,

You're right. I'd added the comparison and skip helpers but never invoked them, so the check was dead code. Fixed by calling maybeWarnVersion(os.Args[1:]) from main() before maybeRunMigratedCommand(). It reuses the existing getRecommendedVersion against .api/src-cli/version instead of duplicating the request.

Behavior matches the PR description: fail-open on any error, 3s timeout, stderr only so --json is untouched, and the skip rules (dev build via version.BuildTag == version.DefaultBuildTag, SRC_SKIP_VERSION_CHECK, and version/help/no-arg) are all applied at the call site. Comparison is major/minor/patch only, so prereleases don't warn. I've folded your #1339 tests in here so the comparison and skip logic are covered.

One thing to flag, because this runs before flag parsing, -endpoint/-config passed as flags aren't picked up by the early config read — it resolves the endpoint from SRC_ENDPOINT, the config file, or the default. Happy to move the call after config resolution if you'd rather flags be honored; I kept it simple to preserve the fail-open guarantees, but your call.

I've reopened another 2 PR's that should address this, you can fold them together if you want.

Cheers,
Michael

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Montana added a commit to Montana/src-cli that referenced this pull request Jul 1, 2026
@Montana
feat: warn when src-cli is older than the instance's recommended version
3d167f6
Before running a command, src does a best-effort check of the running version against the version recommended by the configured instance (/.api/src-cli/version) and prints a single stderr warning when behind. Fail-open, 3s timeout, stderr only so --json is unaffected. Skips version/help/no-arg, dev builds, and SRC_SKIP_VERSION_CHECK. Compares major/minor/patch only. Adds unit tests. Closes sourcegraph#930. Supersedes sourcegraph#1339, sourcegraph#1343.
@Montana Montana mentioned this pull request Jul 1, 2026
feat: warn when src-cli is older than the instance's recommended version #1347
Closed
marcleblanc2 added a commit that referenced this pull request Nov 10, 2026
@marcleblanc2 @Montana @ampagent
feat: warn when src-cli is older than the instance's recommended vers…
61d7456
…ion (#1403)

* feat: warn when src-cli is older than the instance's recommended version

Before running a command, src does a best-effort check of the running version against the version recommended by the configured instance (/.api/src-cli/version) and prints a single stderr warning when behind. Fail-open, 3s timeout, stderr only so --json is unaffected. Skips version/help/no-arg, dev builds, and SRC_SKIP_VERSION_CHECK. Compares major/minor/patch only. Adds unit tests. Closes #930. Supersedes #1339, #1343.

* fix: make the outdated-version warning safe to ship

- Fix a nil pointer panic on every command in release builds: the check
  built its API client from a zero-value api.Flags.
- Run the check after flags and config are resolved, so -endpoint and
  -config are honored and the right instance is asked.
- Ask the instance at most once every 24 hours per endpoint, caching the
  answer, including a failed lookup, under the user cache directory, so
  an instance that does not answer cannot delay every command.
- Compare versions with Masterminds/semver, which is already linked into
  the binary, instead of a hand-written parser.
- Skip 'src version' by its parsed subcommand instead of scanning every
  argument for the word.
- Test the check end to end against a fake instance.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1c29c-9f51-7761-a4ba-4d4f46dcd4ef
Co-authored-by: Amp <[email protected]>

* fix: run the version check with the command's own API client

The check ran before the subcommand's flags were parsed, so it ignored
-insecure-skip-verify and never warned on instances with an untrusted
certificate. It also ran twice for nested legacy commands such as
'src repos list', which printed the warning twice.

Run it once per process from config.apiClient instead, using the client
the command asked for. Commands that never talk to the instance, such as
'src search -h', no longer trigger a lookup.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1c29c-9f51-7761-a4ba-4d4f46dcd4ef
Co-authored-by: Amp <[email protected]>

* docs: document the outdated-version warning and SRC_SKIP_VERSION_CHECK

* feat: make 'src version' warn too, and refresh the cached version

'src version' was the one command that never warned. It now prints the
warning from the answer it just got from the instance, and caches that
answer, so the commands that follow warn about the same version.

It still makes a single request, and 'src version -client-only' still
makes none: the check that other commands get from config.apiClient
keeps skipping 'src version'.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1c29c-9f51-7761-a4ba-4d4f46dcd4ef
Co-authored-by: Amp <[email protected]>

* docs: remove the README section on the version check

The warning already names SRC_SKIP_VERSION_CHECK and links to the
upgrade instructions, and CHANGELOG.md describes the feature.

This reverts commit 71363c8.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1c29c-9f51-7761-a4ba-4d4f46dcd4ef
Co-authored-by: Amp <[email protected]>

---------

Co-authored-by: Montana <[email protected]>
Co-authored-by: Amp <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@keegancsmith keegancsmith Awaiting requested review from keegancsmith
@burmudar burmudar Awaiting requested review from burmudar

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Montana @burmudar
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.