Skip to content

LC-002: reject non-object script parameters - #3122

Merged
aiongg merged 1 commit into
storytold:mainfrom
DAnaeto:fix/cli-script-params
Oct 31, 2026
Merged

aiongg merged 1 commit into
storytold:mainfrom
DAnaeto:fix/cli-script-params

Conversation

@DAnaeto

@DAnaeto DAnaeto commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

run --script silently replaces non-object params with an empty object. A mutating command can consequently run against the current selection instead of rejecting malformed input.

Change

Validate every script line before creating a session or running a command. Objects remain valid, and omitted or null parameters still mean an empty object. Other values produce a source-and-line error.

Not in this PR: Snapshot script parsing.

How it was checked

  • The regression test failed before the fix and all 27 CLI integration tests passed afterward.
  • Direct CLI checks confirmed malformed parameters exit nonzero with no command output, while omitted and null parameters succeed.
  • cargo fmt --all -- --check and cargo clippy --locked -p lightcraft-cli --all-targets -- -D warnings passed.
  • Before rebasing, cargo xtask ci stopped on an existing clippy::if_same_then_else error in apps/lightcraft/src/native_menu.rs:492. The same code remains on current upstream main; full CI was not rerun after rebasing.

Merging

  • Overlap: No directly overlapping PR found in a targeted search.
  • Existing edits and libraries: Invalid scripts stop before opening the library or executing commands.
  • Shared numbers taken: None.
  • New dependencies, unsafe, network access or deleted files: None.

Summary by CodeRabbit

  • Bug Fixes
    • run --script now reports a line-specific error when params is an array, string, number, or boolean, instead of silently treating it as empty.
    • Missing or null params still default to an empty object, and object values remain accepted.
    • Invalid parameters are rejected for both standard input and file input, with no command output produced.

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 662df66 and b576c72.

Files selected for processing: 2
  • apps/lightcraft-cli/src/main.rs
  • apps/lightcraft-cli/tests/it/cli.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Walkthrough

The run --script parser now accepts object parameters, defaults missing or null parameters to an empty object, and reports an error for other JSON types. Integration tests cover both stdin and file input.

Changes: CLI script parameter validation

Layer / File(s) Summary
Validate script parameters
apps/lightcraft-cli/src/main.rs, apps/lightcraft-cli/tests/it/cli.rs
The parser reports the script path and line number when params is not an object, null, or absent. Integration tests check invalid types for stdin and file input, confirm no command output on failure, and verify accepted values.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: skylartaylor

Merge Risk: Minimal · up to b576c

No actionable merge-blocking risk is identified.

Security architecture risk: Minimal · up to b576c

The change rejects malformed parameters before connecting to a backend, opening a library, or executing commands. Valid object parameters and omitted or null parameters retain their existing behavior. No introduced or worsened security risk was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The tightened input gate protects both existing execution destinations: a remote control connection and a headless session with optional library opening and imports. Invalid parameter types cannot reach either destination through this run-script path.

Trust Boundaries and Controls

  • observed — User-supplied script JSON receives stricter validation before reaching command execution. Existing direct control-method routing and engine.execute routing remain unchanged; the PR narrows accepted inputs rather than adding a route or expanding command authority.

Resilience and Maintainability Implications

  • observed — Pre-execution rejection is not transactional execution: after validation succeeds, commands still execute individually, runtime failure stops subsequent commands unless keep-going is enabled, and prior effects are not rolled back. This behavior predates the PR and is not worsened by the validation change.
Pre-merge checks: Passed 4 · Failed 1

Failed 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%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: rejecting non-object script parameters.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Clippy (1.99.0)

Clippy execution timed out

Comment @coderabbitai help to get the list of available commands.

@DAnaeto
DAnaeto marked this pull request as ready for review October 27, 2026 04:00
emmertex referenced this pull request in emmertex/chromaforge Oct 27, 2026
Upstream #3165, #3124, #3122: refuse signed control indexes, non-UTF-8 arguments and non-object script params; review r5
emmertex added a commit to clydecbrown/lightcraft that referenced this pull request Oct 27, 2026
…d control indexes, non-UTF-8 CLI arguments and non-object script params

Hand ports of three open upstream PRs (their files moved in the fork:
apps/cli, crates/develop/src/controls.rs). Tests come along, adapted to
the fork's test binary.

Sources: upstream PRs storytold#3165 (Silvertree2010), storytold#3124 and storytold#3122 (DAnaeto).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aiongg
aiongg merged commit 328e423 into storytold:main Oct 31, 2026
1 check 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.

2 participants