Skip to content

feat(cmd): add workspace start and stop commands (#70)#74

Merged
feloy merged 1 commit intokortex-hub:mainfrom
feloy:start-stop-cmds
Mar 16, 2026
Merged

feat(cmd): add workspace start and stop commands (#70)#74
feloy merged 1 commit intokortex-hub:mainfrom
feloy:start-stop-cmds

Conversation

@feloy
Copy link
Contributor

@feloy feloy commented Mar 16, 2026

Implements start and stop commands to manage workspace runtime state. Both commands support JSON output and include alias shortcuts.

Fixes #70

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-commenter
Copy link

Codecov Report

❌ Patch coverage is 86.95652% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/cmd/workspace_start.go 83.63% 5 Missing and 4 partials ⚠️
pkg/cmd/workspace_stop.go 83.63% 5 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai
Copy link

coderabbitai bot commented Mar 16, 2026

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Documentation
README.md
Adds three new workflow steps: "Start a workspace" (Step 5), "Stop a workspace" (Step 6), and "Remove a workspace" (Step 7 shifted), including usage, arguments, flags, examples, JSON output structure, and error handling guidance for start/stop commands.
Command Registration
pkg/cmd/root.go, pkg/cmd/workspace.go
Registers new start and stop subcommands to the root and workspace command groups via NewStartCmd(), NewStopCmd(), NewWorkspaceStartCmd(), and NewWorkspaceStopCmd() calls.
Root-level Aliases
pkg/cmd/start.go, pkg/cmd/stop.go
Introduces alias commands that wrap workspace start/stop commands, delegating behavior through flag reuse and example adaptation for simplified CLI surface.
Workspace Command Implementations
pkg/cmd/workspace_start.go, pkg/cmd/workspace_stop.go
Implements full start/stop logic including flag validation, manager initialization, fake runtime registration, workspace state transitions, and dual output modes (plain ID or JSON) with error handling.
Test Coverage
pkg/cmd/workspace_start_test.go, pkg/cmd/workspace_stop_test.go
Comprehensive test suites (1,500+ lines) covering command construction, pre-run validation, multi-workspace scenarios, output formatting, error cases, alias equivalence, and example field validation.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding workspace start and stop commands, which is the primary focus of the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining that it implements start and stop commands with JSON output and alias shortcuts, which aligns with the code changes.
Linked Issues check ✅ Passed The PR implements all requirements from issue #70: workspace start/stop commands with JSON output [#70] and their aliases (start/stop) [#70], with comprehensive test coverage validating all specified functionality.
Out of Scope Changes check ✅ Passed All changes are scope-compliant: new start/stop commands and their aliases, JSON output support, and comprehensive tests directly address issue #70 requirements, with only minor README documentation additions.

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

📝 Coding Plan
  • Generate coding plan for human review comments

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 Example field 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 Example block 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 an Example field 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 stop still delegates correctly but drops --output json handling. I’d add one stop <id> --output json variant 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 ValidateCommandExamples already proves the examples are usable. Keeping expectedCount == 2 here 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 Example field 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

📥 Commits

Reviewing files that changed from the base of the PR and between 29bd323 and 981abea.

📒 Files selected for processing (9)
  • README.md
  • pkg/cmd/root.go
  • pkg/cmd/start.go
  • pkg/cmd/stop.go
  • pkg/cmd/workspace.go
  • pkg/cmd/workspace_start.go
  • pkg/cmd/workspace_start_test.go
  • pkg/cmd/workspace_stop.go
  • pkg/cmd/workspace_stop_test.go

@feloy feloy requested review from benoitf and jeffmaury March 16, 2026 14:21
@feloy feloy merged commit 06f2ee5 into kortex-hub:main Mar 16, 2026
6 checks passed
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.

Start/Stop commands

3 participants