Skip to content

add caib status#221

Merged
bennyz merged 1 commit into
centos-automotive-suite:mainfrom
bennyz:worktree-caib-status-cmd
Apr 12, 2026
Merged

add caib status#221
bennyz merged 1 commit into
centos-automotive-suite:mainfrom
bennyz:worktree-caib-status-cmd

Conversation

@bennyz

@bennyz bennyz commented Apr 12, 2026

Copy link
Copy Markdown
Contributor
$ caib status
Server  https://ado-build-api-automotive-dev-operator-system.apps.openshiftapps.com
Source  saved config (~/.config/caib/cli.json)
Status  reachable

Summary

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • CI/CD improvement
  • Refactoring

Testing

  • Unit tests pass (make test)
  • Linter passes (make lint)
  • Manifests are up to date (make manifests generate)
  • Tested on OpenShift cluster (if applicable)

@coderabbitai

coderabbitai Bot commented Apr 12, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds a new caib status CLI command that resolves the Build API server URL from environment variables, saved config, or Jumpstarter configuration, performs an HTTPS health check to /v1/healthz, and reports the server status in table, JSON, or YAML format.

Changes

Cohort / File(s) Summary
Status Command Registration
cmd/caib/root.go
Registers the new status subcommand with the root Cobra command.
Status Command Implementation
cmd/caib/status.go
Implements the status command with server URL resolution (from environment, config file, or Jumpstarter), health check via HTTPS GET to /v1/healthz, and formatted output (table with color-coding, JSON, YAML).
Status Command Tests
cmd/caib/status_test.go
Comprehensive test suite covering server resolution from multiple sources, health check responses (200, 503, unreachable), and output serialization (JSON, YAML).

Sequence Diagram(s)

sequenceDiagram
    participant User as User/CLI
    participant Root as Root Command
    participant Status as Status Command
    participant Config as Config System
    participant Health as Health Check (HTTPS)
    participant Output as Output Formatter

    User->>Root: caib status [--output format]
    Root->>Status: Execute status command
    
    Status->>Config: Check CAIB_SERVER env var
    Config-->>Status: URL or empty
    
    alt CAIB_SERVER not set
        Status->>Config: Read config file (~/.config/caib/cli.json)
        Config-->>Status: URL or empty
        
        alt Config file not found
            Status->>Config: Derive URL from Jumpstarter
            Config-->>Status: URL or empty
        end
    end
    
    alt Server URL resolved
        Status->>Health: GET /v1/healthz (5s timeout, TLS 1.2+)
        alt HTTP 200 response
            Health-->>Status: Reachable
        else Non-200 response
            Health-->>Status: Unhealthy (HTTP code)
        else Request fails
            Health-->>Status: Unreachable (error)
        end
    else No server URL
        Status->>Status: Set status to "not configured"
    end
    
    Status->>Output: Format output (table/json/yaml)
    Output-->>Status: Formatted result
    Status-->>User: Display result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • bkhizgiy

Poem

🐰 A status command hops into view,
Checking server health—green, red, or blue!
From config to Jumpstarter it springs,
Health checks and colors—oh, what it brings!
Table or JSON, YAML's there too,
A fluffy new feature, fresh and brand new! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'add caib status' is concise and directly describes the main change: adding a new subcommand to the CLI.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

To show used cluster information

Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
Assisted-by: claude-sonnet-4.6
@bennyz bennyz force-pushed the worktree-caib-status-cmd branch from 02ec385 to 9cc98a9 Compare April 12, 2026 14:37

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
cmd/caib/status_test.go (1)

41-87: Add a malformed cli.json test to lock error behavior.

The resolve tests cover env/present/absent config, but not invalid config content. Add a case with broken JSON (or unreadable file) and assert the expected surfaced behavior, so config-read error handling doesn’t regress.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/caib/status_test.go` around lines 41 - 87, Add a new test (e.g.,
TestResolveServerWithSource_MalformedConfig) that uses t.TempDir and isolateEnv
similar to the existing tests, writes a malformed JSON (or makes cli.json
unreadable) into the same config path used by resolveServerWithSource
(xdg/caib/cli.json), then call resolveServerWithSource() and assert the expected
behavior (either empty URL and empty source or a specific error-surface behavior
your code should enforce). Reference resolveServerWithSource,
TestResolveServerWithSource_SavedConfig, and isolateEnv to mirror setup; ensure
the test explicitly writes invalid content to the config file and asserts the
resulting url and source values to lock in the desired error-handling contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/caib/status.go`:
- Around line 101-106: The code currently swallows errors from config.Read(), so
change the status-command code that calls config.Read() to surface failures
instead of ignoring them: after calling config.Read(), if err != nil
return/propagate a descriptive error (or include it in the status output) such
as "failed to read saved config: <err>" rather than continuing; keep the
existing branch that returns cfg.ServerURL when cfg != nil and cfg.ServerURL is
non-empty, but ensure config.Read() errors are handled up-front (reference
config.Read(), the cfg variable and cfg.ServerURL in the status command where
this snippet lives).

---

Nitpick comments:
In `@cmd/caib/status_test.go`:
- Around line 41-87: Add a new test (e.g.,
TestResolveServerWithSource_MalformedConfig) that uses t.TempDir and isolateEnv
similar to the existing tests, writes a malformed JSON (or makes cli.json
unreadable) into the same config path used by resolveServerWithSource
(xdg/caib/cli.json), then call resolveServerWithSource() and assert the expected
behavior (either empty URL and empty source or a specific error-surface behavior
your code should enforce). Reference resolveServerWithSource,
TestResolveServerWithSource_SavedConfig, and isolateEnv to mirror setup; ensure
the test explicitly writes invalid content to the config file and asserts the
resulting url and source values to lock in the desired error-handling contract.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1e6ed743-2bbc-411f-af68-26148badab00

📥 Commits

Reviewing files that changed from the base of the PR and between fbeed0c and 9cc98a9.

📒 Files selected for processing (3)
  • cmd/caib/root.go
  • cmd/caib/status.go
  • cmd/caib/status_test.go

Comment thread cmd/caib/status.go
@bennyz bennyz requested a review from bkhizgiy April 12, 2026 14:50
@bennyz bennyz merged commit 77da6dd into centos-automotive-suite:main Apr 12, 2026
4 checks passed
@bennyz bennyz deleted the worktree-caib-status-cmd branch April 12, 2026 15:31
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.

2 participants