Skip to content

feat: improve version checking#799

Open
mbevc1 wants to merge 15 commits intomainfrom
20260417_update_check
Open

feat: improve version checking#799
mbevc1 wants to merge 15 commits intomainfrom
20260417_update_check

Conversation

@mbevc1
Copy link
Copy Markdown
Contributor

@mbevc1 mbevc1 commented Apr 17, 2026

  • properly handle sync version checking when using --version
  • don't check latest version when using JSON output (avoid polluting outputs in GHA pipelines)
  • add testing for JSON output scenario
  • lower the async timeout to 1 sec (prevent long waits on slower connections)
  • local builds use dev as version

@mbevc1 mbevc1 added enhancement New feature or request go Pull requests that update go code labels Apr 17, 2026
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Apr 17, 2026

Claude finished @mbevc1's task in 3m 51s —— View job


PR Review: feat: improve version checking

  • Run static analysis (build, vet, mod tidy)
  • Read changed files
  • Review code quality, bugs, edge cases, tests
  • Post inline comments and summary

Static Analysis

All three checks pass clean — go build ./..., go vet ./..., and go mod tidy produce no errors or diffs.


Summary

This is a well-structured PR that addresses several real pain points:

  1. Synchronous version check on --version and kosli version — correct approach since Cobra's --version flag bypasses all hooks (PersistentPreRunE/PersistentPostRun)
  2. Skip update check for non-table output — prevents polluting JSON in CI/CD pipelines
  3. sync.RWMutex-protected test override — properly addresses the double-read race flagged in earlier reviews
  4. Lower async timeout to 1s — sensible default for a background check
  5. dev as local build version — consistent sentinel that cleanly skips HTTP calls via HasPrefix("dev")

What's done well

  • Thread-safe override pattern: SetCheckForUpdateOverride returning a cleanup func with sync.RWMutex protection and a single-read-then-use in CheckForUpdate (lines 47-55 of update_check.go) is idiomatic and safe. The race stress test at line 104 locks this invariant in.
  • Test coverage is thorough: New tests cover the --version notice path (TestVersionFlagPrintsNotice with called bool verification), JSON output skip, empty version, dev builds with metadata, network errors, bad JSON, non-200 responses, and concurrent access.
  • Buffered channel + non-blocking select in root.go:311,367-376 is a clean async pattern — the goroutine never blocks, and slow checks are silently dropped.
  • version subcommand (version.go:50) correctly does its own synchronous check, consistent with the --version flag path.

Issues

I left two minor inline comments (nits only — no bugs found):

  1. root.go:337 — The comment could be slightly more descriptive about why non-table output is skipped
  2. update_check.go:69 — Noting that HasPrefix("dev") implicitly covers "dev+metadata" from GetVersion()

Previous review items — status

The earlier rounds flagged several issues that have all been addressed in the current state:

  • ✅ Dev-build skip condition updated from "main" to "dev" with tests matching
  • +unreleased narrowing confirmed intentional by PR author
  • ✅ Double-read race fixed with sync.RWMutex
  • --version test coverage added via TestVersionFlagPrintsNotice
  • SetArgs fix applied per mbevc1's correction
  • ✅ Redundant first override removed from TestVersionFlagPrintsNotice
  • ✅ Empty version test added
  • ✅ Race stress test added

Overall: Clean, well-tested, and addresses all prior review feedback. The two inline nits are non-blocking. LGTM.

Comment thread internal/version/update_check.go
Comment thread internal/version/update_check.go Outdated
Comment thread cmd/kosli/main.go
Comment thread internal/version/update_check.go Outdated
Comment thread cmd/kosli/root_test.go Outdated
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Comment thread internal/version/update_check.go
Comment thread cmd/kosli/main.go
Comment thread internal/version/update_check.go Outdated
Comment thread cmd/kosli/root.go
Comment thread internal/version/update_check.go Outdated
Comment thread cmd/kosli/root.go Outdated
Comment thread cmd/kosli/main.go
Comment thread internal/version/update_check.go
Comment thread internal/version/update_check_test.go Outdated
Comment thread cmd/kosli/root.go
Comment thread cmd/kosli/root_test.go
Copy link
Copy Markdown
Contributor Author

@mbevc1 mbevc1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goroutine-safety nit on SetCheckForUpdateOverride — inline with a sync.RWMutex suggestion and a race test. Current call site is fine by happens-before; the mutex is cheap insurance against future callers / flaky timings.


Generated by Claude Code

Comment thread internal/version/update_check.go
Comment thread cmd/kosli/main.go
Comment thread internal/version/update_check.go
Comment thread internal/version/update_check.go
Comment thread cmd/kosli/root.go Outdated
Copy link
Copy Markdown
Contributor Author

@mbevc1 mbevc1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage gap: executeCommandC bypasses innerMain, so the new --version sync-notice branch in main.go has no test coverage. Inline with a sketch calling innerMain directly via the existing SetCheckForUpdateOverride helper.


Generated by Claude Code

Comment thread cmd/kosli/main.go
Comment thread internal/version/update_check.go Outdated
Comment thread internal/version/update_check.go
Comment thread cmd/kosli/root.go Outdated
Comment thread cmd/kosli/root_test.go
Comment thread internal/version/update_check.go Outdated
Comment thread internal/version/update_check.go
Comment thread cmd/kosli/root.go Outdated
future prof machine formatting

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Comment thread cmd/kosli/root.go
update the comment as well

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Comment thread cmd/kosli/root.go
Comment thread cmd/kosli/root_test.go
Comment thread cmd/kosli/root_test.go
Comment thread cmd/kosli/main.go
Comment thread internal/version/update_check.go
Comment thread cmd/kosli/root_test.go
Comment thread internal/version/update_check.go
Comment thread internal/version/update_check.go
Comment thread cmd/kosli/root.go
Comment thread cmd/kosli/main.go
Comment thread cmd/kosli/root.go
Comment thread internal/version/update_check.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant