Repository navigation
fix(features): convert non-string option values like the reference CLI - #155
Conversation
A string-typed (or untyped) feature option given a non-string JSON
value failed with `option "packages" expects string, got
[]interface {}`. The reference CLI never type-checks option values: it
writes each one into devcontainer-features.env through a JavaScript
template literal, so ["jq","tree"] installs as jq,tree.
MergeOptions now converts such values as JavaScript's String() does:
arrays join with "," (null elements empty, nested arrays flattened),
numbers use JavaScript's formatting (1e6 -> 1000000, 1e21 -> 1e+21),
booleans and null take their literal form. Objects are still rejected
and boolean options stay strict. Enums are checked against the
converted string, and a WarnFeatureOptionCoerced warning reports each
conversion. Non-string defaults and undeclared options are converted
too, so feature.env never carries Go formatting such as [jq tree].
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M1zV4YDcDbkxa8xkQS5dMA
ghost
left a comment
There was a problem hiding this comment.
Code Review — 9bb0314 · CLEAN
No concrete defect introduced by this change was substantiated. The changed option path matches the intended JavaScript-style coercion for the supported JSON value shapes, while preserving boolean validation; feature values are serialized into the generated feature environment consumed by install scripts.
What I reviewed
Coverage: Reviewed the exact head 9bb031472f367369aa305a8bb3854e897697ccaa (one commit, five changed files), covering correctness, interface-contract, untrusted-input, test-coverage, operability, and R5 reference-CLI divergence. Confirmed the devcontainer.json feature parser produces float64/[]any/map[string]any, MergeOptions flows through layerFeatures into SerializeEnvFile, and warning events are surfaced through Up and Build. Read the repository engineering review standard at the governing base SHA, README, CONTRIBUTING, feature design record, and the pinned reference CLI v0.90.0 implementation. .dap/code-review.yml and AGENTS.md are absent at the governing SHA, so the engineering record and core prompt governed this review. State-integrity, concurrency, redelivery, and version-compatibility were not applicable to these edits; backend-specific behavior and the real Docker integration path were not independently exercised, consistent with the no-execution review constraint.
CLEAN — this round found nothing. Reply in a finding's own thread to argue it. On the pull request I answer @dap-code-review-by-crunchloop review, pause and resume.
ghost
left a comment
There was a problem hiding this comment.
No open findings on 9bb0314.
The DAP Code Review check run remains the verdict of record. This approval is dismissed if a finding reopens or a later head is not clean.
….Number like JavaScript The reference CLI never type-checks option values and writes "true" and true identically, so a boolean option given the string "true" or "false" now takes that boolean with a feature_option_coerced warning. Other non-boolean values still error. A json.Number is formatted through its float64 value, as JavaScript parses every JSON number as a double: "1e6" is 1000000, "1.50" is 1.5. Adds edge-case tests checked against node 22's String() (nested empty arrays, null elements, subnormal and max doubles, -0, precision loss) and a test that a second merge of merged options is a no-op, which SameOptions relies on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M1zV4YDcDbkxa8xkQS5dMA
Dismissed by DAP code review: bf2071e has not been reviewed clean (the pull request was pushed to).
|
I reviewed this PR against
Differences from the reference CLI that this PR leaves as they were:
These are all rare, and none was in scope here. |
ghost
left a comment
There was a problem hiding this comment.
Code Review — bf2071e · CLEAN
The feature option coercion changes align the declared value handling with the reference CLI on the supported JSON value shapes; I found no concrete defect introduced by this PR.
What I reviewed
Coverage: Reviewed the exact head bf2071e53292f180faf6592b9e7b1bc3395e8704 (2 commits, 5 changed files), including option coercion, enum and boolean validation, env serialization, runtime consumers, and warning delivery. Checked R5 in .dap/review/engineering.md at governing base a4e72d2a108d81ab72539c17fcd8483acb384d7e; .dap/code-review.yml is absent, and AGENTS.md is absent, so repository guidance is the engineering directives plus CONTRIBUTING.md and design/features.md. Verified feature options flow from JSON parsing to MergeOptions, into feature.env, and warnings are propagated through Up. Build-time warnings are accumulated on the resolved config; I did not pursue event delivery for Build because the examined change’s primary coercion path and tested Up warning propagation were intact. R8 coverage: the new unit and feature build-context tests pin coercion and serialization; no real backend behavior was changed. Access-control, untrusted-input, and secret-exposure mechanisms were not implicated by this change. Conditional state-integrity, redelivery, version-compatibility, operability, and concurrency checks do not apply.
CLEAN — this round found nothing. Reply in a finding's own thread to argue it. On the pull request I answer @dap-code-review-by-crunchloop review, pause and resume.
ghost
left a comment
There was a problem hiding this comment.
No open findings on bf2071e.
The DAP Code Review check run remains the verdict of record. This approval is dismissed if a finding reopens or a later head is not clean.
Problem
A feature option declared as
"type": "string"(or with no type) fails when the user gives it a non-string JSON value:DAP hit this in session 19146: a
devcontainer.jsonusingghcr.io/devcontainers-extra/features/apt-packages:1with"packages": ["jq", "tree"]. The workspace builds with@devcontainers/clibut not with this library (DAP pins v0.5.3).What the reference CLI and the spec do
devcontainer-features.envthrough a JavaScript template literal (src/spec-node/containerFeatures.ts:414), so it is converted with JavaScript'sString(). We confirmed this with a real build ofghcr.io/devcontainers-extra/features/apt-packages:1:["jq","tree"]was installed asjq,tree. The other conversions are[]→ ``,[["a","b"],"c"]→ `a,b,c`, `5` → `5`, `1.5` → `1.5`, `true` → `true`, `null` → `null` and `{"a":1}` → `[object Object]`.docs/specs/devcontainer-features.md(l.97-99, 423-425) declares option types (string/boolean) but does not require tools to enforce them on user input.Change
feature/options.go:coerceOptionStringfollows JavaScript'sString():,. Anullelement becomes empty and nested arrays flatten.1e6→1000000,1e21→1e+21,1e-7→1e-7.true/false, andnullbecomesnull.json.Numberis formatted through its float64 value, as JavaScript parses every JSON number as a double ("1e6"→1000000). Go integers become decimal.[object Object]would never be what the user meant.MergeOptions/validateOptionValue:stringor untyped option, the value is converted and the converted string is stored. Each conversion adds a warning with the new codeconfig.WarnFeatureOptionCoerced(feature_option_coerced), which reachescfg.Warningsthe same wayWarnUnknownFeatureOptiondoes."true"and"false"as the booleans, with the same warning. The reference CLI writes"true"andtruethe same way (INSTALLZSH="true"). Any other non-boolean, such as"yes","True",1ornull, still errors.SerializeEnvFile'sfmt.Sprintwould write Go formatting such as[jq tree]or1e+06.Tests
feature/options_test.gocovers:nilelement (a,b,,c);5,1.5,1e6,1e21,-1.5e22,1e-7,json.Number,int);trueandnil;SerializeEnvFileafterMergeOptionswritingPACKAGES='jq,tree'.TestMergeOptions_TypeValidationstill checks that"yes"for a boolean option errors.String()covers nested empty arrays,nullelements at depth, mixed arrays, the subnormal and maximum doubles,-0, integer precision loss andjson.Numberexponent forms."true"/"false"(converted, with a warning) and"True","yes","",1,nulland["true"](rejected).MergeOptionsof already merged options changes nothing and warns nothing.SameOptionsrelies on that.feature_options_test.gois an end to end test. It resolves adevcontainer.jsonwith"packages": ["jq","tree"]and runslayerFeatureswith a fake store. It checks that the generated build context'sfeature.envcontainsPACKAGES='jq,tree'and that the warning is reported. Without this change, the same test fails with the error above.Validation run locally
go vet ./...passed.go test -race -count=1 ./...passed.golangci-lint run ./...(v2.5.0) reported 0 issues.TestImageSource*,TestOCIFeature*,TestDependsOn*,TestFeatureMount*andTestBuild*(9 tests,-tags=integration) passed against Docker 29.1.3.All runs used Go 1.26.11.
🤖 Generated with Claude Code
https://claude.ai/code/session_01M1zV4YDcDbkxa8xkQS5dMA