harness: validate actual result shape against declared arity - #236
Merged
Conversation
assert_return with an empty expected list never inspected the actual value: compareValues short-circuited to a vacuous pass, and invoke collapsed the raw return by declared arity, discarding it for arity 0 and casting unchecked for 2+. A spurious result from an arity-0 export passed silently. Extract the collapse into collapseResultsByArity (value-mapping.ts), which validates the observed shape against the declared arity per the runtime's convention (resultsToHost, runtime/src/exec/boundary.ts): arity 0 requires undefined, arity 1 requires non-undefined (a ComponentValue is never undefined; arrays stay legal — a single list<T> result IS an array, the deliberate deviation from the issue text), and arity n>=2 requires an array of exactly n. compareValues now rejects a non-undefined actual when nothing is expected. Error messages use a bigint-safe describe helper (JSON.stringify throws on lifted i64s). Unit coverage in harness/tests/value_mapping_test.ts; the arity-0 spurious-result path is untestable end-to-end (it requires a broken runtime), which is why the collapse is a pure exported function. Fixes #188
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.
Fixes #188.
assert_returnwith an empty expected list never inspected the actual value: two stacked layers discarded it independently —compareValuesshort-circuited to a vacuous pass whenexpectedwas empty, andinvokecollapsed the raw return by declared arity, discarding it for arity 0 and castingraw as unknown[]unchecked for 2+.Changes
collapseResultsByArity(new,harness/src/value-mapping.ts): pure collapse+validate of the raw invoke return against the declared arity, per the runtime's convention (resultsToHost,runtime/src/exec/boundary.ts):rawmust beundefinedrawmust not beundefined(aComponentValueis neverundefined—runtime/src/cabi/types.ts). Deliberate deviation from the issue's suggested fix: arrays stay legal at arity 1, because a singlelist<T>/tuple result IS a JS array — disambiguating that from N results is exactly whycomputeExportAritiesexists.rawmust be an array of exactly that lengthRuntimeExecutor.invokeuses it; a shape mismatch now fails the command loudly.compareValueswith emptyexpectednow requiresactual === undefinedinstead of passing vacuously.JSON.stringifythrows on lifted i64 bigints).harness/tests/value_mapping_test.ts(14 tests), including pins for the bigint-safe messages and the arity-1-array non-throw.The collapse is a pure exported function because the arity-0 spurious-result path cannot be exercised end-to-end — producing one requires a broken runtime.
Gates
just conformance— pass (1257 passed, 0 failed, 112 pre-existing xfail; all 88 harness tests green). No latent runtime bug surfaced by the stricter checks.just sched-seeds— pass (seeds 1 and 4242).