This document contains guidelines and rules for Claude when working on the Guix codebase.
Before committing any changes, Claude must ensure the following checks pass.
The easiest way to run all pre-commit checks is using Mage:
# Run all pre-commit checks (format, vet, test, build)
go run github.com/magefile/mage@latest
# Or if mage is installed locally
mageThis will automatically run all the checks below in the correct order.
If you prefer to run checks manually:
All Go files must be formatted with gofmt:
gofmt -w .This ensures consistent code style across the entire codebase.
Run go vet to catch common Go mistakes:
go vet ./...Run all tests to ensure no regressions:
go test ./...All tests must pass before committing.
Verify the code compiles for both native and WASM targets:
# Native build
go build ./...
# WASM build (for runtime package)
GOOS=js GOARCH=wasm go build ./pkg/runtime/...The following Mage targets are available:
mageormage preCommit- Run all pre-commit checks (default)mage format- Format all Go filesmage vet- Run go vetmage test- Run all testsmage build- Build all packagesmage buildWasm- Build WASM runtimemage generate- Regenerate all example codemage clean- Remove build artifactsmage ci- Run all CI checks
If not using Mage, run these commands before every commit:
# Format all Go files
gofmt -w .
# Check for common mistakes
go vet ./...
# Run tests
go test ./...
# Verify native build
go build ./...
# Verify WASM build
GOOS=js GOARCH=wasm go build ./pkg/runtime/...Commit messages should follow this format:
<type>: <subject>
<body>
<footer>
Types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changes (formatting, missing semicolons, etc.)refactor: Code refactoringtest: Adding or updating testschore: Maintenance tasks
Example:
feat: Add WebGPU support for 3D graphics
Implement comprehensive WebGPU runtime with scene graphs,
PBR materials, and lighting system.
- Add 8 new runtime modules for GPU operations
- Create rotating cube example
- Add detailed documentation in docs/WEBGPU.md
Feature branches should follow the pattern: claude/<feature-name>-<session-id>
Example: claude/add-webgpu-support-01BWtA2VBNZfg7Y29aanCzJG
Always verify the build passes on CI/CD before pushing:
- Format code:
gofmt -w . - Run linter:
go vet ./... - Run tests:
go test ./... - Build all targets:
go build ./... - Commit changes
- Push to remote
Follow the Effective Go guidelines:
- Use
gofmtfor formatting (enforced pre-commit) - Keep functions small and focused
- Use meaningful variable names
- Comment exported functions and types
- Avoid global mutable state
For code in pkg/runtime/:
- Always use build tags:
//go:build js && wasm - Handle
js.Valuecarefully - checkTruthy()before use - Clean up
js.FuncwithRelease()to prevent memory leaks - Use lowercase function names for internal helpers (e.g.,
logError, notLogError)
For WebGPU-related code:
- Validate GPU context before operations
- Handle async promises with proper error checking
- Log errors using
logError()fromdom.go - Clean up GPU resources in cleanup/unmount methods
- Test in WebGPU-enabled browsers (Chrome 113+, Edge 113+)
- Place tests in
*_test.gofiles - Use table-driven tests where appropriate
- Mock external dependencies
- Test error cases, not just happy paths
- Test WASM builds with browser automation (when available)
- Verify WebGPU functionality in supported browsers
- Test example applications end-to-end
End-to-end tests use Playwright to test examples in real browsers:
# Navigate to example directory
cd examples/webgpu-cube
# Install dependencies
npm install
# Install Playwright browsers
npx playwright install --with-deps chromium
# Run tests
npx playwright test
# Run tests in headed mode (visible browser)
npx playwright test --headed
# Run tests in debug mode
npx playwright test --debugWebGPU E2E Testing Requirements:
For WebGPU tests to run in CI environments (GitHub Actions), Chrome must be launched with specific flags:
--enable-unsafe-webgpu- Enable WebGPU API--use-angle=swiftshader- Use software rendering (no GPU required)--disable-vulkan-surface- Disable Vulkan for CI compatibility--no-sandbox- Required for containerized environments
These flags are configured in playwright.config.ts for each example.
Writing E2E Tests:
import { test, expect } from '@playwright/test';
test('should render canvas', async ({ page }) => {
await page.goto('http://localhost:8080');
// Wait for canvas to be created
await page.waitForSelector('canvas', { timeout: 5000 });
// Check canvas is visible
const canvas = await page.locator('canvas');
await expect(canvas).toBeVisible();
});Test Coverage:
E2E tests should verify:
- Page loads without errors
- WebGPU initialization succeeds
- Canvas element is created and visible
- Controls respond to user interaction
- Keyboard shortcuts work correctly
- No error messages are displayed
- Add godoc comments to all exported types and functions
- Include examples in documentation where helpful
- Keep comments up-to-date with code changes
- Update README.md for user-facing changes
- Add detailed guides to
docs/for major features - Include working examples in
examples/ - Document browser compatibility requirements
- Unused imports: Remove all unused imports (build will fail)
- Name conflicts: Can't have type and function with same name in package
- Case sensitivity: Exported names start with uppercase, internal with lowercase
- js.Value lifecycle: Always check
Truthy()and releasejs.Func
- Async initialization: WebGPU requires async setup via promises
- Context configuration: Canvas context must be configured before use
- Resource cleanup: Always destroy GPU resources (buffers, textures, etc.)
- Browser support: Check WebGPU availability before use
The continuous integration system will run:
gofmt -d .(check formatting)go vet ./...(linting)go test ./...(unit tests)go build ./...(build verification)GOOS=js GOARCH=wasm go build ./pkg/runtime/...(WASM build)- Playwright E2E tests for all examples (counter, calculator, webgpu-cube)
All checks must pass for the build to succeed.
WebGPU E2E Tests in CI:
The WebGPU cube example runs E2E tests with:
- Headless Chrome with software rendering (SwiftShader)
- WebGPU enabled via
--enable-unsafe-webgpuflag - Tests verify initialization, rendering, and user interactions
- Screenshots are captured for visual regression testing
If the build fails:
- Read the error message carefully
- Fix the specific issue (formatting, imports, syntax)
- Re-run the pre-commit checklist
- Commit the fix with a descriptive message
- Push the corrected code
- Go Documentation
- Effective Go
- Go Code Review Comments
- WebGPU Specification
- syscall/js Package
- Playwright Documentation
- Playwright for E2E Testing
Last Updated: 2025-11-28 Version: 1.0