You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replaces generated CLI service JSON.parse(...) object argument handling with parseJsonObject(...).
Allows omitted optional JSON object flags, including functions create-execution --headers, to pass through as undefined instead of crashing on JSON.parse(undefined).
Converts malformed JSON object flag values into clear InvalidArgumentError messages like --headers must be a valid JSON object.
Adds a mock functions create-execution fixture and CLI regression coverage for invoking it without --headers.
Manual malformed flag check in the generated CLI fixture: functions create-execution --function-id fn --headers invalid exits with --headers must be a valid JSON object.
Note: the generated CLI fixture still prints an existing bun run build:types failure for "sites" resource typing during CLIBun13Test; the PHPUnit test harness continues and the test passes.
Replaces inline JSON.parse(varName) calls for object-typed CLI flags with a new parseJsonObject(value, optionName) helper that gracefully returns undefined for omitted optional flags and surfaces a clear InvalidArgumentError for malformed or non-object JSON values. The accompanying Twig template change also applies | raw to all argExpressions | join(', ') output sites, which is necessary to prevent Twig HTML-escaping the double-quoted option-name string literal introduced by the new helper signature.
Confidence Score: 5/5
Safe to merge — the fix is targeted, the helper logic is correct, and regression coverage is added across all three Bun test suites.
No P0 or P1 findings. The parseJsonObject function correctly handles all edge cases (undefined, malformed JSON, valid non-object JSON such as arrays and primitives, and valid objects including empty {}). The | raw filter addition is necessary and applied consistently across all three argExpressions | join branches. Test fixture and mock responses are properly wired in all affected test classes.
No files require special attention.
Important Files Changed
Filename
Overview
templates/cli/lib/parser.ts
Adds parseJsonObject helper that safely handles undefined (returns undefined), invalid JSON (throws InvalidArgumentError), and valid non-object JSON (throws InvalidArgumentError); logic is sound.
src/SDK/Language/CLI.php
Replaces JSON.parse(varName) with parseJsonObject(varName, "--optionName") for object-typed parameters; correctly threads the kebab-case option name through to the error message.
Adds hasObjectParam flag for conditional parseJsonObject import, and adds `
tests/resources/spec.json
Adds a functions createExecution fixture endpoint with optional object-typed headers parameter, following the existing test-spec conventions.
tests/languages/cli/test.js
Adds regression test that calls functions create-execution --function-id sample-function without --headers to verify the optional object flag no longer crashes.
tests/Base.php
Adds CLI_FUNCTION_RESPONSES mock-server constant for the new POST execution endpoint and updates the completion-list assertion to include the new functions service.
tests/CLIBun10Test.php
Adds CLI_FUNCTION_RESPONSES to the response set so the mock server handles the new execution endpoint during Bun10 test runs.
tests/CLIBun11Test.php
Same CLI_FUNCTION_RESPONSES addition as CLIBun10Test, keeping the three Bun test fixtures in sync.
tests/CLIBun13Test.php
Same CLI_FUNCTION_RESPONSES addition; primary test target for this PR's regression coverage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
JSON.parse(...)object argument handling withparseJsonObject(...).functions create-execution --headers, to pass through asundefinedinstead of crashing onJSON.parse(undefined).InvalidArgumentErrormessages like--headers must be a valid JSON object.functions create-executionfixture and CLI regression coverage for invoking it without--headers.Testing
docker run --rm -v $(pwd):/app -w /app php:8.3-cli php example.php clicomposer lint-twignpm run build:typesinexamples/clinpm run build:runtimeinexamples/clivendor/bin/phpunit tests/CLIBun13Test.phpfunctions create-execution --function-id fn --headers invalidexits with--headers must be a valid JSON object.Note: the generated CLI fixture still prints an existing
bun run build:typesfailure for"sites"resource typing duringCLIBun13Test; the PHPUnit test harness continues and the test passes.