feat(cmd): add workspace start and stop commands (#70)#74
feat(cmd): add workspace start and stop commands (#70)#74feloy merged 1 commit intokortex-hub:mainfrom
Conversation
Implements start and stop commands to manage workspace runtime state. Both commands support JSON output and include alias shortcuts. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: Philippe Martin <phmartin@redhat.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
📝 WalkthroughWalkthroughAdds workspace start and stop commands to the CLI with manager-based control, including root-level aliases, JSON and text output formats, and comprehensive test coverage across start/stop workflows and error handling paths. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📝 Coding Plan
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 |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (4)
pkg/cmd/workspace_stop.go (1)
132-136: Add at least one more help example.The command help currently shows only two scenarios. Adding a third common case here keeps the help aligned with the repo convention, and the alias will inherit it automatically. As per coding guidelines, "All Cobra commands must include an
Examplefield with usage examples showing the most common use cases (typically 3-5 examples) with comments describing what each example does)".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/cmd/workspace_stop.go` around lines 132 - 136, The Example field for the workspace stop Cobra command in workspace_stop.go only lists two examples; add at least one more common usage example (e.g., stopping by workspace name or using a force/quiet flag) to bring the examples to 3+ as per convention; locate the Example string on the workspace stop command (the Example field in the NewWorkspaceStopCmd / workspace stop command declaration) and append a third commented example line showing usage and a short comment describing it so the alias inherits it too.pkg/cmd/workspace_start.go (1)
132-136: Broaden the command examples.This
Exampleblock only covers two flows. Please add at least one more common start scenario so the generated help meets the 3-5 example guideline. As per coding guidelines, "All Cobra commands must include anExamplefield with usage examples showing the most common use cases (typically 3-5 examples) with comments describing what each example does)".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/cmd/workspace_start.go` around lines 132 - 136, The Example block for the Cobra command (the Example field in the workspace start command) only shows two usages; add at least one more common usage example (3–5 total) to satisfy the guideline. Update the Example string for the workspace start command to include a third example such as starting by workspace name (e.g., "kortex-cli workspace start my-workspace" with a short comment "Start workspace by name") while keeping the existing ID and JSON-output examples; ensure each example has a brief comment explaining what it does.pkg/cmd/workspace_stop_test.go (2)
449-516: Add a JSON-path alias E2E.This alias case only exercises plain output, so it will not catch regressions where
stopstill delegates correctly but drops--output jsonhandling. I’d add onestop <id> --output jsonvariant here to cover the full alias surface.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/cmd/workspace_stop_test.go` around lines 449 - 516, Add a second sub-case exercising the alias with JSON output: after the existing alias invocation using rootCmd.SetArgs([]string{"stop", instanceID, "--storage", storageDir}), add a variant that calls rootCmd.SetArgs([]string{"stop", instanceID, "--storage", storageDir, "--output", "json"}), execute the command, parse the JSON from output.String(), and assert it contains the expected fields (id equals instanceID and runtime.state equals "stopped"); reuse the same manager and instanceID setup and verify that manager.Get(instanceID) still reports stopped to ensure both plain and JSON outputs are covered.
769-773: Avoid locking the examples test to exactly two commands.Parsing plus
ValidateCommandExamplesalready proves the examples are usable. KeepingexpectedCount == 2here will create busywork as soon as we expand the command examples.Suggested simplification
- // Verify we have the expected number of examples - expectedCount := 2 - if len(commands) != expectedCount { - t.Errorf("Expected %d example commands, got %d", expectedCount, len(commands)) - } + if len(commands) == 0 { + t.Fatal("Expected at least one example command") + }As per coding guidelines: All Cobra commands must include an
Examplefield with usage examples showing the most common use cases (typically 3-5 examples) with comments describing what each example does.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/cmd/workspace_stop_test.go` around lines 769 - 773, The test currently enforces an exact count by setting expectedCount := 2 and checking len(commands) == expectedCount; remove that strict check (or replace it with a len(commands) > 0 assertion) so the test doesn't fail when examples are expanded — locate the lines that define expectedCount and the if len(commands) != expectedCount check in the workspace_stop_test.go test and either delete them or change the assertion to ensure there is at least one example (e.g., assert len(commands) > 0) while keeping the existing ValidateCommandExamples usage.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/cmd/workspace_start.go`:
- Around line 74-77: The code registers only a fake runtime (fake.New()) via
manager.RegisterRuntime before calling Start, so real workspace runtimes are
never available; update the workspace start path to register the
actual/configured runtimes before starting the manager by invoking
manager.RegisterRuntime for each real runtime implementation your app supports
(e.g., the concrete runtime constructors used elsewhere) or by iterating the
runtime factory/registry used in production, keeping fake.New() only for test
modes, and ensure all registrations occur prior to manager.Start() so workspaces
using real runtimes can be started.
In `@pkg/cmd/workspace_stop.go`:
- Around line 74-77: The current startup path in workspace_stop.go always
registers only the fake runtime via manager.RegisterRuntime(fake.New()), causing
workspace stop to fail for non-fake runtimes; update the initialization to
register real/configured runtimes instead of (or in addition to) fake.New():
locate the code around manager.RegisterRuntime and replace the unconditional
fake.New() registration with the proper runtime discovery/registration logic
used elsewhere (e.g., register runtimes from the same config/registry used by
the rest of the app or conditionally register fake.New() only under a test
flag), ensuring the manager used by the stop command supports the workspace's
actual runtime types.
In `@README.md`:
- Around line 123-149: Remove the leading shell prompt from the two command code
blocks that run "kortex-cli workspace start 2c5f1604..." and "kortex-cli
workspace stop 2c5f1604..." so the blocks contain just the commands (no "$ "
prefix); this removes the inline prompt that triggers MD014 and matches the rest
of the README examples.
---
Nitpick comments:
In `@pkg/cmd/workspace_start.go`:
- Around line 132-136: The Example block for the Cobra command (the Example
field in the workspace start command) only shows two usages; add at least one
more common usage example (3–5 total) to satisfy the guideline. Update the
Example string for the workspace start command to include a third example such
as starting by workspace name (e.g., "kortex-cli workspace start my-workspace"
with a short comment "Start workspace by name") while keeping the existing ID
and JSON-output examples; ensure each example has a brief comment explaining
what it does.
In `@pkg/cmd/workspace_stop_test.go`:
- Around line 449-516: Add a second sub-case exercising the alias with JSON
output: after the existing alias invocation using
rootCmd.SetArgs([]string{"stop", instanceID, "--storage", storageDir}), add a
variant that calls rootCmd.SetArgs([]string{"stop", instanceID, "--storage",
storageDir, "--output", "json"}), execute the command, parse the JSON from
output.String(), and assert it contains the expected fields (id equals
instanceID and runtime.state equals "stopped"); reuse the same manager and
instanceID setup and verify that manager.Get(instanceID) still reports stopped
to ensure both plain and JSON outputs are covered.
- Around line 769-773: The test currently enforces an exact count by setting
expectedCount := 2 and checking len(commands) == expectedCount; remove that
strict check (or replace it with a len(commands) > 0 assertion) so the test
doesn't fail when examples are expanded — locate the lines that define
expectedCount and the if len(commands) != expectedCount check in the
workspace_stop_test.go test and either delete them or change the assertion to
ensure there is at least one example (e.g., assert len(commands) > 0) while
keeping the existing ValidateCommandExamples usage.
In `@pkg/cmd/workspace_stop.go`:
- Around line 132-136: The Example field for the workspace stop Cobra command in
workspace_stop.go only lists two examples; add at least one more common usage
example (e.g., stopping by workspace name or using a force/quiet flag) to bring
the examples to 3+ as per convention; locate the Example string on the workspace
stop command (the Example field in the NewWorkspaceStopCmd / workspace stop
command declaration) and append a third commented example line showing usage and
a short comment describing it so the alias inherits it too.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c6d62e89-b9c2-48c0-8d39-6698b85077b2
📒 Files selected for processing (9)
README.mdpkg/cmd/root.gopkg/cmd/start.gopkg/cmd/stop.gopkg/cmd/workspace.gopkg/cmd/workspace_start.gopkg/cmd/workspace_start_test.gopkg/cmd/workspace_stop.gopkg/cmd/workspace_stop_test.go
Implements start and stop commands to manage workspace runtime state. Both commands support JSON output and include alias shortcuts.
Fixes #70