Skip to content

test: Exercise both compiled and fallback writers in schema binary tests - #3228

Open
mishablablabla wants to merge 4 commits into
mainfrom
test/compiled-io-paths
Open

mishablablabla wants to merge 4 commits into
mainfrom
test/compiled-io-paths

Conversation

@mishablablabla

Copy link
Copy Markdown
Collaborator

Summary

Add a shared test helper that verifies binary serialization produces identical results with both compiled and fallback writers.

Changes

  • Add writeWithBothWriters() to typegpu-testing-utility.
  • Verify that both writer paths are actually exercised and compare their resulting bytes.
  • Migrate serialization and roundtrip tests in arrayBufferIO, struct, array, and vector.
  • Preserve existing layout assertions and no-eval-specific coverage.
  • Restore intercepted globals and serialize helper calls to keep tests isolated.

Validation

  • Source mode: typegpu project — 2,917 tests passed.
  • Built mode (TEST_BUILT=1): typegpu project — 2,448 tests passed.
  • Migrated tests: 227 passed in both source and built modes.
  • TypeScript, oxlint, oxfmt, and git diff --check passed.

Scope

This change focuses on schema-based binary serialization tests. patch, buffer.write, other schema test files, and existing *.noEval.test.ts tests are not included.

Add `writeWithBothWriters` to typegpu-testing-utility. It encodes a value with
`writeToArrayBuffer` once with the compiled writer and once with the fallback
writer (eval blocked while a fresh TypeGPU instance loads), checks that each
path was really used, and fails if the encoded bytes differ.

Migrate the write/roundtrip tests in arrayBufferIO, struct, array and vector.
The `*.noEval.test.ts` files are left as they are.
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@609e8dc62e48082d9e6c71f06a171eb357571257
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/react@609e8dc62e48082d9e6c71f06a171eb357571257

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Resolution Time Benchmark

---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [1.09, 2.15, 4.49, 7.14, 7.93, 12.97, 26.34, 25.85]
  line [1.08, 2.19, 4.50, 7.23, 8.05, 13.34, 25.79, 26.94]
  line [1.01, 2.12, 4.83, 7.38, 8.28, 12.17, 27.08, 28.07]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.30, 0.53, 0.72, 0.85, 1.14, 1.25, 1.49, 1.69]
  line [0.32, 0.57, 0.78, 0.90, 1.27, 1.27, 1.56, 1.70]
  line [0.31, 0.52, 0.74, 0.95, 1.24, 1.27, 1.54, 1.67]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [1.00, 2.59, 4.28, 7.55, 14.26, 27.88, 58.31, 119.43]
  line [0.94, 2.17, 3.70, 7.55, 13.84, 27.20, 60.49, 119.71]
  line [1.04, 2.39, 4.53, 7.61, 13.61, 28.32, 60.38, 120.95]
Loading

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Bundle size comparison (import * as ... in PR vs import * as ... in target):

🟢 Decreased ➖ Unchanged 🔴 Increased ❔ Unknown
0 355 0 0

No notable changes.

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

This run reviewed the full PR (#3228, single commit 153c04aa) against main.

  • New test helper writeWithBothWriters — loads a fresh typegpu instance per path via vi.resetModules(), blocks globalThis.Function at load to force the eval-disallowed fallback writer, counts Function constructions during the write, captures [fallback] warnings, compares both byte outputs, and restores __TYPEGPU_* globals and console.warn.
  • Export wiring — the helper and its BothWritersCase / BothWritersResult types are re-exported from typegpu-testing-utility.
  • Serialization test migrations — array, arrayBufferIO, struct, and vector write/roundtrip tests now go through the helper while keeping their existing byte and layout assertions; the f16 struct roundtrips were split out of the layout tests.

I verified the helper exercises what it claims: the compiled run asserts a writer was generated and no fallback warning fired, the fallback run asserts eval was probed while blocked, no code was generated during the write, and exactly one fallback warning was emitted. The fresh-instance requirement and typed-array fast-path limitation are documented clearly. I ran the four changed test files (227 passed) and oxlint / oxfmt --check on the changed files (clean).

( ◦°^°◦) Arr, I read the whole diff end to end, ran the four migrated test scullies (227 passin'), checked lint and format, and found no leaks in the hull. Approvin' this one.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Copilot AI balanced review requested due to automatic review settings October 21, 2026 12:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Constructor restoration can overwrite caller-installed Function spies or stubs, breaking test isolation.

1 open issue
What changed in this PR

Adds shared test coverage comparing TypeGPU’s compiled and fallback binary writers.

Changes:

  • Adds a helper that verifies writer selection and byte equality.
  • Migrates serialization tests while preserving layout and roundtrip assertions.
  • Adds global interception, cleanup, and serialized helper calls.
File Description
packages/​typegpu/​tests/​vector.test.ts Exercises both writers for vector serialization.
packages/​typegpu/​tests/​unstruct.test.ts Migrates loose-structure roundtrip tests.
packages/​typegpu/​tests/​struct.test.ts Migrates structure serialization and f16 coverage.
packages/​typegpu/​tests/​matrix.test.ts Migrates matrix roundtrip tests.
packages/​typegpu/​tests/​disarray.test.ts Checks both writers for packed arrays.
packages/​typegpu/​tests/​arrayBufferIO.test.ts Expands dual-writer input and layout coverage.
packages/​typegpu/​tests/​array.test.ts Migrates array layout and roundtrip tests.
packages/​typegpu-testing-utility/​src/​index.ts Exports the helper and its types.
packages/​typegpu-testing-utility/​src/​bothWriters.ts Implements writer verification and byte comparison.

Review effort: Balanced

Comment thread packages/typegpu-testing-utility/src/bothWriters.ts Outdated

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

This run reviewed the delta since the prior Pullfrog review (153c04aa → 796d221), which extends the writeWithBothWriters migration to more schema serialization tests on top of a merge of main.

  • Migrated disarray, matrix, and unstruct binary serialization tests to writeWithBothWriters, keeping their size/alignment assertions in place.
  • Added arrayBufferIO cases: "handles d.vec input", "handles plain array input", "handles structs with attributes" (aligned u32 member), and "handles mat3x3f with matrix input"; migrated the read "handles vectors" / "handles structs" cases.
  • Split the f16 struct tests into dedicated roundtrip tests while preserving the layout its.
  • Migrated the remaining vector encode tests (vec2f/vec2i/vec3f/vec3i/vec4f/vec2h) and switched the f16 rounding expectation to typegpu.d.
  • Dropped now-unused imports (Infer, readFromArrayBuffer/writeToArrayBuffer) from the migrated files.

Verified locally: the 7 changed test files pass (305 tests) and pnpm --filter typegpu test:types (tsc --noEmit) is clean. Each migration follows the helper's contract — schema and value are built inside build from the fresh instance, the compiled/fallback byte comparison is unchanged, and existing byte/layout assertions are retained.

( ◦°^°◦) Arr, I charted the new commits, read the whole diff fore-to-aft, ran the seven changed test scullies (305 passin'), and typechecked the cargo — nary a leak below the waterline. Ship it!

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

This run re-reviewed the delta since the prior Pullfrog review (796d221 → 609e8dc), a single follow-up commit to the writeWithBothWriters test helper.

  • Function restore preserves a caller's spy — interceptFunctionConstructor now captures globalThis.Function at install time and restores that exact value instead of the module-level RealFunction, so a Function proxy or stub installed by a calling test survives a helper call.
  • Helper regression tests — packages/typegpu/tests/internal/bothWriters.test.ts asserts the caller's Function spy is still installed after both a successful and a throwing call, and that the original is restored (and the helper keeps working) after a queued call fails.

I verified the fix end to end: read the incremental range and the full diff, then ran the new helper tests (3 passed) and the seven migrated schema test files (305 passed) in source mode. The prior Copilot thread about constructor restoration overwriting caller spies is addressed by this commit.

( ◦°^°◦) 🏴☠️ Arr, the new commit patches the leak where the helper clobbered a caller's Function spy — I read the delta and the whole diff, ran the three new regression scullies (all passin') alongside the seven migrated ones, and found nary a loose cannon aboard. Approvin' this one.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants