From f1400091ff0eed4f490085f2fb5ab5c0903fa96f Mon Sep 17 00:00:00 2001 From: Iwo Plaza Date: Wed, 7 Jan 2026 17:54:26 +0100 Subject: [PATCH 1/2] Update bufferUsage.test.ts --- packages/typegpu/tests/bufferUsage.test.ts | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/packages/typegpu/tests/bufferUsage.test.ts b/packages/typegpu/tests/bufferUsage.test.ts index 224d4c877c..46a611bc36 100644 --- a/packages/typegpu/tests/bufferUsage.test.ts +++ b/packages/typegpu/tests/bufferUsage.test.ts @@ -145,6 +145,40 @@ describe('TgpuBufferMutable', () => { `); }); + it('cannot be mutated (primitive)', ({ root }) => { + const foo = root.createUniform(d.f32); + + const main = () => { + 'use gpu'; + foo.$ += 1; + }; + + expect(tgpu.resolve([main])).toMatchInlineSnapshot(` + "@group(0) @binding(0) var foo: f32; + + fn main() { + foo += 1f; + }" + `); + }); + + it('cannot be mutated (non-primitive)', ({ root }) => { + const foo = root.createUniform(d.vec3f); + + const main = () => { + 'use gpu'; + foo.$.x += 1; + }; + + expect(tgpu.resolve([main])).toMatchInlineSnapshot(` + "@group(0) @binding(0) var foo: vec3f; + + fn main() { + foo.x += 1f; + }" + `); + }); + describe('simulate mode', () => { it('allows accessing .$ in simulate mode', ({ root }) => { const buffer = root.createBuffer(d.u32, 0).$usage('storage'); @@ -260,6 +294,40 @@ describe('TgpuBufferReadonly', () => { `); }); + it('cannot be mutated (primitive)', ({ root }) => { + const foo = root.createReadonly(d.f32); + + const main = () => { + 'use gpu'; + foo.$ += 1; + }; + + expect(tgpu.resolve([main])).toMatchInlineSnapshot(` + "@group(0) @binding(0) var foo: f32; + + fn main() { + foo += 1f; + }" + `); + }); + + it('cannot be mutated (non-primitive)', ({ root }) => { + const foo = root.createReadonly(d.vec3f); + + const main = () => { + 'use gpu'; + foo.$.x += 1; + }; + + expect(tgpu.resolve([main])).toMatchInlineSnapshot(` + "@group(0) @binding(0) var foo: vec3f; + + fn main() { + foo.x += 1f; + }" + `); + }); + describe('simulate mode', () => { it('allows accessing .$ in simulate mode', ({ root }) => { const buffer = root.createBuffer(d.f32, 123).$usage('storage'); From 5c950498d793c6a7ea5ba37c0b9625f9c8163e66 Mon Sep 17 00:00:00 2001 From: Iwo Plaza Date: Wed, 7 Jan 2026 17:58:26 +0100 Subject: [PATCH 2/2] Failing tests --- packages/typegpu/tests/bufferUsage.test.ts | 34 ++++------------------ 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/packages/typegpu/tests/bufferUsage.test.ts b/packages/typegpu/tests/bufferUsage.test.ts index 46a611bc36..ab7c537854 100644 --- a/packages/typegpu/tests/bufferUsage.test.ts +++ b/packages/typegpu/tests/bufferUsage.test.ts @@ -150,16 +150,11 @@ describe('TgpuBufferMutable', () => { const main = () => { 'use gpu'; + // @ts-expect-error foo.$ += 1; }; - expect(tgpu.resolve([main])).toMatchInlineSnapshot(` - "@group(0) @binding(0) var foo: f32; - - fn main() { - foo += 1f; - }" - `); + expect(() => tgpu.resolve([main])).toThrowErrorMatchingInlineSnapshot(); }); it('cannot be mutated (non-primitive)', ({ root }) => { @@ -170,13 +165,7 @@ describe('TgpuBufferMutable', () => { foo.$.x += 1; }; - expect(tgpu.resolve([main])).toMatchInlineSnapshot(` - "@group(0) @binding(0) var foo: vec3f; - - fn main() { - foo.x += 1f; - }" - `); + expect(() => tgpu.resolve([main])).toThrowErrorMatchingInlineSnapshot(); }); describe('simulate mode', () => { @@ -299,16 +288,11 @@ describe('TgpuBufferReadonly', () => { const main = () => { 'use gpu'; + // @ts-expect-error foo.$ += 1; }; - expect(tgpu.resolve([main])).toMatchInlineSnapshot(` - "@group(0) @binding(0) var foo: f32; - - fn main() { - foo += 1f; - }" - `); + expect(() => tgpu.resolve([main])).toThrowErrorMatchingInlineSnapshot(); }); it('cannot be mutated (non-primitive)', ({ root }) => { @@ -319,13 +303,7 @@ describe('TgpuBufferReadonly', () => { foo.$.x += 1; }; - expect(tgpu.resolve([main])).toMatchInlineSnapshot(` - "@group(0) @binding(0) var foo: vec3f; - - fn main() { - foo.x += 1f; - }" - `); + expect(() => tgpu.resolve([main])).toThrowErrorMatchingInlineSnapshot(); }); describe('simulate mode', () => {