add caib status#221
Conversation
📝 WalkthroughWalkthroughAdds a new Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
To show used cluster information Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com> Assisted-by: claude-sonnet-4.6
02ec385 to
9cc98a9
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
cmd/caib/status_test.go (1)
41-87: Add a malformedcli.jsontest 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
📒 Files selected for processing (3)
cmd/caib/root.gocmd/caib/status.gocmd/caib/status_test.go
Summary
Related Issues
Type of Change
Testing
make test)make lint)make manifests generate)