Skip to content

fix(iii-worker): validate worker config and fix CLI help text#1450

Merged
ytallo merged 3 commits intomainfrom
ytallolayon/mot-3002-3021-worker-cli-dx-fixes
Apr 10, 2026
Merged

fix(iii-worker): validate worker config and fix CLI help text#1450
ytallo merged 3 commits intomainfrom
ytallolayon/mot-3002-3021-worker-cli-dx-fixes

Conversation

@ytallo
Copy link
Copy Markdown
Contributor

@ytallo ytallo commented Apr 10, 2026

Summary

  • MOT-3002: Fix hyphenated iii-worker display name in CLI help text → now shows iii worker
  • MOT-3021: Validate iii.worker.yaml config before sandbox startup — missing package_manager now shows a Tier 1 error with inline YAML fix instead of a misleading "permission denied"
  • Fix pnpm/yarn inference to use correct commands (pnpm install/pnpm exec tsx, yarn install/yarn exec tsx) instead of npm commands
  • Add ("typescript", _) catch-all for unrecognized package managers
  • Add ProjectInfo::validate() with language and run_cmd checks in both start_local_worker() and handle_local_add()
  • 6 new tests

Test plan

  • cargo build -p iii-worker — compiles clean
  • cargo test -p iii-worker --lib -- project — 19 tests pass (6 new)
  • cargo run -p iii-worker -- --help — verify "iii worker" (no hyphen)
  • Create iii.worker.yaml with language: typescript but no package_manager — verify Tier 1 error with YAML fix shown
  • Create iii.worker.yaml with package_manager: deno — verify "unrecognized" error

Summary by CodeRabbit

  • Bug Fixes

    • Project configs are validated early; invalid configs halt operations with clear error messages.
    • TypeScript package-manager errors now report unsupported values and stop invalid setups.
  • Improvements

    • CLI invocation name standardized to "iii worker".
    • TypeScript install/run commands differ per package manager (npm, yarn, pnpm) for more accurate behavior.
  • Tests

    • Added unit tests for validation and TypeScript package-manager scenarios.

Fix two DX bugs:

MOT-3002: Change clap display name from "iii-worker" to "iii worker"
so help text no longer shows the hyphenated binary name.

MOT-3021: Validate iii.worker.yaml config before sandbox startup.
Missing package_manager now shows a Tier 1 error with inline YAML fix
instead of a misleading "permission denied" from the sandbox. Also
split pnpm/yarn from npm inference so each uses correct commands
(pnpm install/pnpm exec tsx, yarn install/yarn exec tsx).

Additional hardening:
- Add ("typescript", _) catch-all for unrecognized package managers
- Add ProjectInfo::validate() checking language and run_cmd
- Validate in both start_local_worker() and handle_local_add()
- 6 new tests covering pnpm, yarn, missing PM, unknown PM, language
  typos, and empty run_cmd
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
iii-website Ready Ready Preview, Comment Apr 10, 2026 7:54pm
motia-docs Ready Ready Preview, Comment Apr 10, 2026 7:54pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c8d9fe04-a294-414d-959d-9a7bb0979560

📥 Commits

Reviewing files that changed from the base of the PR and between e6755ea and 09bc065.

📒 Files selected for processing (1)
  • crates/iii-worker/src/cli/app.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/iii-worker/src/cli/app.rs

📝 Walkthrough

Walkthrough

Updated CLI metadata (command/bin name changed to "iii worker"); added ProjectInfo::validate() and enforce it in local worker flows; refined TypeScript script inference for npm/yarn/pnpm; added unit tests and improved manifest error handling.

Changes

Cohort / File(s) Summary
CLI Metadata
crates/iii-worker/src/cli/app.rs
Changed Clap top-level command name and bin_name to "iii worker".
Project validation & script inference
crates/iii-worker/src/cli/project.rs
Added ProjectInfo::validate() (checks non-empty run_cmd and allowed language values); split TypeScript infer_scripts() into separate npm, yarn, pnpm branches; return clear error for unknown/missing package_manager; added unit tests.
Local worker flows
crates/iii-worker/src/cli/local_worker.rs
Invoke project.validate() in handle_local_add() and start_local_worker() and fail fast with red error: + exit code 1 on validation errors; renamed _projectproject.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • sergiofilhowz

Poem

🐰 I hop through code with nimble cheer,
"iii worker" now speaks so near.
Projects checked before they run,
Scripts split by package manager fun,
A little rabbit pats the job — well done!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely summarizes the two main changes: validating worker config and fixing CLI help text to show 'iii worker' without hyphen.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ytallolayon/mot-3002-3021-worker-cli-dx-fixes

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
Copy Markdown
Contributor

@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 (1)
crates/iii-worker/src/cli/project.rs (1)

385-450: Add regression coverage for non-TypeScript runtime manifests without package_manager.

The new tests cover TypeScript well; adding python/rust no-package_manager manifest tests would protect against this behavior drifting again.

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/iii-worker/src/cli/project.rs`:
- Around line 146-155: The current check mistakenly requires package_manager
whenever language is set (if !language.is_empty() &&
package_manager.is_empty()), which forces package_manager for non-JS runtimes;
change this to only require package_manager for JS-style runtimes. Replace the
condition with a membership test (e.g., known_js_langs.contains(&language) &&
package_manager.is_empty()) or an explicit equality check for the JS languages
you support (e.g., language == "node" || language == "javascript" || language ==
"typescript"), and keep the existing eprintln block (using manifest_path,
language, entry) only for that JS-specific branch; leave other languages to fall
through or produce a separate unknown-language message.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6970a5f8-b152-4867-a6a1-fd1d39c3b455

📥 Commits

Reviewing files that changed from the base of the PR and between a0d2891 and 4db118a.

📒 Files selected for processing (3)
  • crates/iii-worker/src/cli/app.rs
  • crates/iii-worker/src/cli/local_worker.rs
  • crates/iii-worker/src/cli/project.rs

Comment on lines +146 to +155
if !language.is_empty() && package_manager.is_empty() {
eprintln!(
"{} missing `package_manager` in {}\n\n runtime:\n language: {}\n package_manager: npm <-- add this line\n entry: {}\n\nhint: valid options are: npm, yarn, pnpm, bun",
"error:".red(),
manifest_path.display(),
language,
entry
);
return None;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

package_manager is being required too broadly here.

At Line 146, !language.is_empty() forces package_manager for all runtime languages. That breaks valid Python/Rust manifests without scripts, and can mask unknown-language errors as “missing package_manager”.

💡 Proposed fix
-        if !language.is_empty() && package_manager.is_empty() {
+        if language == "typescript" && package_manager.is_empty() {
             eprintln!(
                 "{} missing `package_manager` in {}\n\n  runtime:\n    language: {}\n    package_manager: npm    <-- add this line\n    entry: {}\n\nhint: valid options are: npm, yarn, pnpm, bun",
                 "error:".red(),
                 manifest_path.display(),
                 language,
                 entry
             );
             return None;
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/iii-worker/src/cli/project.rs` around lines 146 - 155, The current
check mistakenly requires package_manager whenever language is set (if
!language.is_empty() && package_manager.is_empty()), which forces
package_manager for non-JS runtimes; change this to only require package_manager
for JS-style runtimes. Replace the condition with a membership test (e.g.,
known_js_langs.contains(&language) && package_manager.is_empty()) or an explicit
equality check for the JS languages you support (e.g., language == "node" ||
language == "javascript" || language == "typescript"), and keep the existing
eprintln block (using manifest_path, language, entry) only for that JS-specific
branch; leave other languages to fall through or produce a separate
unknown-language message.

The clap `name` attribute controls the command identity, but the Usage
line derives from argv[0] (the binary name). Adding `bin_name` ensures
the usage line also shows "iii worker" instead of "iii-worker".
@ytallo
Copy link
Copy Markdown
Contributor Author

ytallo commented Apr 10, 2026

Evidence

MOT-3002 — Help text fix

$ iii-worker --help
iii managed worker runtime

Usage: iii worker <COMMAND>

Commands:
  add        Add one or more workers from the registry or by OCI image reference
  remove     Remove one or more workers (stops and removes containers)
  reinstall  Re-download a worker (equivalent to `add --force`; pass `--reset-config` to also clear config.yaml)
  clear      Clear downloaded worker artifacts from ~/.iii/ (local-only, no engine connection needed)
  start      Start a previously stopped managed worker container
  stop       Stop a managed worker container
  list       List all workers and their status
  logs       Show logs from a managed worker container
  help       Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

Usage line now shows iii worker (no hyphen).

MOT-3021 — Missing package_manager validation

$ cat /tmp/test-worker/iii.worker.yaml
name: test-worker
runtime:
  language: typescript
  entry: src/index.ts

$ iii-worker add /tmp/test-worker
error: missing `package_manager` in /private/tmp/test-worker/iii.worker.yaml

  runtime:
    language: typescript
    package_manager: npm    <-- add this line
    entry: src/index.ts

hint: valid options are: npm, yarn, pnpm, bun

Tier 1 (Elm-style) error with inline YAML fix. Previously this would silently proceed and crash with a misleading "permission denied" inside the sandbox.

MOT-3021 — Unrecognized package manager

$ cat /tmp/test-worker/iii.worker.yaml
name: test-worker
runtime:
  language: typescript
  package_manager: deno
  entry: src/index.ts

$ iii-worker add /tmp/test-worker
error: unrecognized package_manager 'deno' for typescript — supported: npm, yarn, pnpm, bun
error: no run command could be determined — check iii.worker.yaml for missing `scripts.start` or `runtime` section

Tests

running 19 tests
test cli::project::tests::infer_scripts_bun ... ok
test cli::project::tests::infer_scripts_npm ... ok
test cli::project::tests::infer_scripts_typescript_unknown_pm ... ok
test cli::project::tests::infer_scripts_pnpm ... ok
test cli::project::tests::infer_scripts_rust ... ok
test cli::project::tests::infer_scripts_python ... ok
test cli::project::tests::infer_scripts_yarn ... ok
test cli::project::tests::validate_empty_run_cmd ... ok
test cli::project::tests::validate_unrecognized_language ... ok
test cli::project::tests::auto_detect_project_unknown_returns_none ... ok
test cli::project::tests::auto_detect_project_node_npm ... ok
test cli::project::tests::auto_detect_project_node_bun ... ok
test cli::project::tests::auto_detect_project_rust ... ok
test cli::project::tests::auto_detect_project_python ... ok
test cli::project::tests::load_manifest_auto_detects_scripts ... ok
test cli::project::tests::load_manifest_filters_engine_url_env ... ok
test cli::project::tests::load_manifest_missing_package_manager ... ok
test cli::project::tests::load_project_info_prefers_manifest ... ok
test cli::project::tests::load_manifest_with_explicit_scripts ... ok

test result: ok. 19 passed; 0 failed; 0 ignored; 0 measured; 180 filtered out

6 new tests, all passing.

sergiofilhowz
sergiofilhowz previously approved these changes Apr 10, 2026
@ytallo ytallo merged commit 7ef7dde into main Apr 10, 2026
32 checks passed
@ytallo ytallo deleted the ytallolayon/mot-3002-3021-worker-cli-dx-fixes branch April 10, 2026 20:18
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