Skip to content

feat(config): support workspace configuration#80

Merged
feloy merged 6 commits intokortex-hub:mainfrom
feloy:podman1
Mar 19, 2026
Merged

feat(config): support workspace configuration#80
feloy merged 6 commits intokortex-hub:mainfrom
feloy:podman1

Conversation

@feloy
Copy link
Contributor

@feloy feloy commented Mar 19, 2026

  • import WorkspaceConfiguration from kortex-cli-api
  • add config package loading and validating workspace configuration
  • change runtime.Create signature to receive WorkspaceConfiguration (instead of config path)
  • document the WorkspaceConfiguration format in README

Fixes #79

feloy and others added 5 commits March 19, 2026 08:31
Updates the kortex-cli-api/cli/go dependency to the latest commit
abc0e6182754b595b5dc3087d0a6ef5ab51fde3f.

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Philippe Martin <phmartin@redhat.com>
Imports workspace configuration model from kortex-cli-api and adds
comprehensive validation for environment variables and mount paths.
Environment variable names must be valid Unix identifiers, and exactly
one of value or secret must be defined. Mount paths must be relative
and non-empty. Validation is integrated into the init command to
catch configuration errors early.

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Philippe Martin <phmartin@redhat.com>
Documents the workspace.json configuration file format, including
environment variables, mount paths, validation rules, and practical
examples for configuring workspace runtime behavior.

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Philippe Martin <phmartin@redhat.com>
Adds detection for duplicate environment variable names in workspace
configuration and a test to verify they are properly rejected with
descriptive error messages.

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Philippe Martin <phmartin@redhat.com>
Changed runtime.CreateParams to accept WorkspaceConfiguration instead
of ConfigPath. The init command now loads the configuration and passes
it to manager.Add() via a new AddOptions struct, centralizing config
handling at the command level and removing redundant loading.

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 88.23529% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/runtime/fake/fake.go 50.00% 3 Missing and 1 partial ⚠️
pkg/config/config.go 94.54% 2 Missing and 1 partial ⚠️
pkg/cmd/init.go 84.61% 1 Missing and 1 partial ⚠️
pkg/instances/manager.go 88.88% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai
Copy link

coderabbitai bot commented Mar 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d72cffaa-28a2-4fa0-bdcc-9558b6e68a39

📥 Commits

Reviewing files that changed from the base of the PR and between 6424bd1 and e0cdcff.

📒 Files selected for processing (1)
  • pkg/config/config_test.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/config/config_test.go

📝 Walkthrough

Walkthrough

This PR adds a workspace config loader/validator (pkg/config), integrates loading into init (preRun), threads validated config through instances.Add via a new AddOptions (including WorkspaceConfig), updates runtimes to accept workspace config, and updates tests/docs and dependencies accordingly.

Changes

Cohort / File(s) Summary
Documentation
AGENTS.md, README.md
Added docs describing workspace configuration at .kortex/workspace.json, JSON schema for environment and mounts, validation rules, examples, and notes about CLI flag --workspace-configuration.
Config package
pkg/config/config.go, pkg/config/config_test.go
New Config interface and NewConfig(); Load() reads/unmarshals workspace.json and validates env entries (name rules, uniqueness, mutually exclusive value/secret, non-empty secret refs) and mount paths (non-empty, must be relative). Exported errors: ErrInvalidPath, ErrConfigNotFound, ErrInvalidConfig. Comprehensive tests.
Init command
pkg/cmd/init.go, pkg/cmd/init_test.go
Load workspace config in preRun (treat ErrConfigNotFound as OK); surface other validation errors; pass loaded config into manager via new AddOptions. Added tests for success, mutual-exclusivity failure, and missing config.
Instance manager API
pkg/instances/manager.go, pkg/instances/manager_test.go
Changed Manager.Add to Add(ctx, AddOptions) and introduced AddOptions{Instance, RuntimeType, WorkspaceConfig}; validation updated and runtime creation now receives WorkspaceConfig. Updated tests to new call shape.
Runtime changes (fake + core)
pkg/runtime/runtime.go, pkg/runtime/fake/fake.go, pkg/runtime/fake/fake_test.go
Replaced CreateParams.ConfigPath string with WorkspaceConfig *workspace.WorkspaceConfiguration; fake runtime no longer requires config path and conditionally augments returned Info with has_config and env_vars_count. Tests adjusted to new params.
Workspace command tests
pkg/cmd/..._test.go
pkg/cmd/workspace_list_test.go, pkg/cmd/workspace_remove_test.go, pkg/cmd/workspace_start_test.go, pkg/cmd/workspace_stop_test.go
Updated E2E test callsites to use manager.Add(ctx, instances.AddOptions{Instance: ..., RuntimeType: "fake"}) instead of positional args.
Dependencies
go.mod
Bumped kortex-cli-api/cli/go, added direct kortex-cli-api/workspace-configuration/go requirement, and promoted spf13/pflag from indirect to direct.

Sequence Diagram(s)

sequenceDiagram
    participant InitCmd as Init Command
    participant ConfigMgr as Config Manager
    participant InstanceMgr as Instance Manager
    participant Runtime as Runtime

    InitCmd->>ConfigMgr: NewConfig(absConfigDir)
    ConfigMgr->>ConfigMgr: ensure path absolute

    InitCmd->>ConfigMgr: Load()
    ConfigMgr->>ConfigMgr: read workspace.json
    ConfigMgr->>ConfigMgr: unmarshal JSON
    ConfigMgr->>ConfigMgr: validate env vars (name, unique, value xor secret)
    ConfigMgr->>ConfigMgr: validate mounts (non-empty, relative)
    ConfigMgr-->>InitCmd: WorkspaceConfiguration | error

    rect rgba(100, 200, 100, 0.5)
    InitCmd->>InstanceMgr: Add(ctx, AddOptions{Instance, RuntimeType, WorkspaceConfig})
    end

    InstanceMgr->>InstanceMgr: validate AddOptions
    InstanceMgr->>Runtime: Create({SourcePath, WorkspaceConfig})
    Runtime->>Runtime: augment Info if WorkspaceConfig present
    Runtime-->>InstanceMgr: RuntimeInfo
    InstanceMgr-->>InitCmd: Instance
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.57% 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 'feat(config): support workspace configuration' clearly and concisely summarizes the main change: adding support for workspace configuration.
Description check ✅ Passed The description directly relates to the changeset, outlining the key implementation steps (import API, add config package, change runtime signature, document in README) and referencing the linked issue #79.
Linked Issues check ✅ Passed The pull request fully implements the requirements from issue #79: adds a config package to load/validate workspace configuration [#79], and validates it during init command execution [#79].
Out of Scope Changes check ✅ Passed All changes align with the stated objectives: config package implementation, runtime signature updates, documentation, and test updates to support the new workspace configuration feature.

✏️ 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: 1

🧹 Nitpick comments (2)
pkg/config/config_test.go (1)

174-205: Add an unknown-key sibling to the malformed-JSON case.

This file covers syntax errors well, but it still misses the common typo case where the JSON is valid and a field name is wrong. A subtest with an unexpected or misspelled key would lock in the fail-fast behavior this PR is aiming for.

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

In `@pkg/config/config_test.go` around lines 174 - 205, Add a subtest alongside
the malformed-JSON case that writes syntactically valid JSON containing an
unexpected/misspelled key (e.g., {"unkownKey": "value"} or a misspelled expected
field) to WorkspaceConfigFile, then call NewConfig(configDir) and cfg.Load() and
assert it returns a validation/unknown-key error (not nil and not
ErrConfigNotFound); update the test to reference NewConfig, cfg.Load,
WorkspaceConfigFile and ErrConfigNotFound so it fails fast when unknown keys are
present.
pkg/instances/manager_test.go (1)

267-298: Add one WorkspaceConfig propagation case in TestManager_Add.

Every updated call here still passes only Instance and RuntimeType. Since AddOptions now also carries WorkspaceConfig, a regression that drops that payload before runtime creation would leave this suite green. A tiny spy/fake runtime that records the received config would be enough to cover it.

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

In `@pkg/instances/manager_test.go` around lines 267 - 298, Update TestManager_Add
to include a subtest that passes a non-nil WorkspaceConfig through AddOptions
and asserts the runtime factory actually received it: create a small spy fake
runtime/factory (e.g., newFakeRuntimeSpy or extend fakeInstanceFactory) that
records the WorkspaceConfig it was invoked with, call manager.Add(ctx,
AddOptions{Instance: inst, RuntimeType: "fake", WorkspaceConfig: myConfig}) and
then assert the spy saw the exact myConfig; place the assertion alongside the
existing success assertions so regressions that drop WorkspaceConfig during
Manager.Add or during runtime creation are caught.
🤖 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/config/config.go`:
- Around line 111-133: The validation currently uses filepath.IsAbs(dep) /
filepath.IsAbs(conf) which is platform-dependent; update the checks inside the
loops over cfg.Mounts.Dependencies and cfg.Mounts.Configs to treat Unix-style
leading "/" (and leading backslash) as absolute as well (e.g. consider a path
absolute if filepath.IsAbs(...) OR strings.HasPrefix(path, "/") OR
strings.HasPrefix(path, "\\") or other appropriate detection), so
ErrInvalidConfig is returned for such paths consistently across platforms; make
the change where filepath.IsAbs is called in the dependency and config
validation blocks.

---

Nitpick comments:
In `@pkg/config/config_test.go`:
- Around line 174-205: Add a subtest alongside the malformed-JSON case that
writes syntactically valid JSON containing an unexpected/misspelled key (e.g.,
{"unkownKey": "value"} or a misspelled expected field) to WorkspaceConfigFile,
then call NewConfig(configDir) and cfg.Load() and assert it returns a
validation/unknown-key error (not nil and not ErrConfigNotFound); update the
test to reference NewConfig, cfg.Load, WorkspaceConfigFile and ErrConfigNotFound
so it fails fast when unknown keys are present.

In `@pkg/instances/manager_test.go`:
- Around line 267-298: Update TestManager_Add to include a subtest that passes a
non-nil WorkspaceConfig through AddOptions and asserts the runtime factory
actually received it: create a small spy fake runtime/factory (e.g.,
newFakeRuntimeSpy or extend fakeInstanceFactory) that records the
WorkspaceConfig it was invoked with, call manager.Add(ctx, AddOptions{Instance:
inst, RuntimeType: "fake", WorkspaceConfig: myConfig}) and then assert the spy
saw the exact myConfig; place the assertion alongside the existing success
assertions so regressions that drop WorkspaceConfig during Manager.Add or during
runtime creation are caught.
🪄 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: 294498e2-f3c9-4c5d-a45b-fe1f500bd198

📥 Commits

Reviewing files that changed from the base of the PR and between 4119436 and 6424bd1.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (16)
  • AGENTS.md
  • README.md
  • go.mod
  • pkg/cmd/init.go
  • pkg/cmd/init_test.go
  • pkg/cmd/workspace_list_test.go
  • pkg/cmd/workspace_remove_test.go
  • pkg/cmd/workspace_start_test.go
  • pkg/cmd/workspace_stop_test.go
  • pkg/config/config.go
  • pkg/config/config_test.go
  • pkg/instances/manager.go
  • pkg/instances/manager_test.go
  • pkg/runtime/fake/fake.go
  • pkg/runtime/fake/fake_test.go
  • pkg/runtime/runtime.go

Use platform-appropriate absolute paths in tests instead of hardcoded
Unix-style paths. Use tempDir for absolute paths and filepath.ToSlash
for JSON representation to ensure tests work on both Unix and Windows.

Signed-off-by: Philippe Martin <phmartin@redhat.com>
@feloy feloy requested review from benoitf and jeffmaury March 19, 2026 10:03
@feloy feloy merged commit 071ae05 into kortex-hub:main Mar 19, 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.

load and validate workspace configuration

3 participants