Repository navigation
Conversation
Optional record fields and variant payloads were encoded with a truthiness test, so 0, false and "" were sent as absent. Test presence with `!= null` instead. The new conversion test runs the generated wrapper against a stub actor and checks what it sends.
marc0olo
added this pull request to stack #200
September 28, 2026 15:08
This was referenced Sep 28, 2026
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Repeated wrapper calls overwrite cleanup state and leak temporary directories.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Corrects TypeScript-to-Candid conversion so falsy optional values remain present.
Changes:
- Replaces truthiness checks with nullish presence checks.
- Adds runtime conversion tests and supporting fixtures.
- Updates generated snapshots.
| File | Description |
|---|---|
src/core/generate/rs/src/bindings/typescript_native/conversion_functions_generator.rs |
Generates nullish optional checks. |
tests/conversion.test.ts |
Tests optional-value conversion. |
tests/utils/wrapper.ts |
Loads generated wrappers with stub dependencies. |
tests/assets/optional_presence.did |
Defines optional conversion fixtures. |
tests/snapshots/generate/example/example.ts.snapshot |
Updates generated output. |
tests/snapshots/wasm-generate/no-root-export/example/example.ts.snapshot |
Updates no-root-export output. |
tests/snapshots/wasm-generate/root-export/example/example.ts.snapshot |
Updates root-export output. |
tests/snapshots/wasm-generate/typescript/example/example.ts.snapshot |
Updates TypeScript output. |
tests/snapshots/wasm-generate/typescript-root-export/example/example.ts.snapshot |
Updates TypeScript root-export output. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
marc0olo
marked this pull request as ready for review
September 29, 2026 08:17
marc0olo
removed this pull request from stack #200
September 29, 2026 08:43
marc0olo
added this pull request to stack #202
September 29, 2026 08:43
This was referenced Sep 29, 2026
Closed
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Bottom of a two-PR stack (#198 builds on it) fixing conversions that are silently wrong.
Behaviour
This changes what goes on the wire. A canister that received nothing for these values now receives what the caller asked to send.
{ count: 0n }(opt nat)[], absent[0n]{ flag: false },{ name: "" }[][false],[""]undefined[][]{ __kind__: "count", count: 0n }{ count: [] }{ count: [0n] }count: null{ count: [] }{ count: [] }optargument0n[0n][0n], unchangedWhy
Optional record fields and variant payloads were encoded with a truthiness test (
value.count ? candid_some(…) : candid_none()), so0,falseand""could not be sent at all. The generated code was valid and typechecked, which is why snapshots and typechecks passed over it. The test is now!= null; bareoptarguments already compared withnull.Testing
tests/conversion.test.tsgenerates the bindings, calls the generated wrapper with a stub actor and checks what reaches it. It fails onmainwithexpected { count: [] } to deeply equal { count: [ 0n ] }.tests/utils/wrapper.tsloads the wrapper against a minimal@icp-sdk/corestub. The snapshot changes are theexamplefixture's two optional fields.🤖 Generated with Claude Code