Phase 2 spike: spawn migration (flagged) + new shelf node

The first time registry-driven nodes actually run in the editor.

Spawn migration (under NEXT_PUBLIC_USE_REGISTRY_FOR_SPAWN flag):
- New packages/nodes/src/spawn/ folder with renderer, tool, schema
  (re-exported from core), parametrics, definition, index.
- Spawn definition appended to builtinPlugin.nodes only when the flag
  is set. With the flag off, the Phase 0 shims fall through and the
  legacy SpawnRenderer / SpawnTool keep ownership.
- New no-props SpawnTool reads activeLevelId from useViewer directly,
  matches legacy placement behavior (half-meter snap, singleton-per-
  level, replace-on-reclick).
- Structural parity test (9 cases) validates definition shape +
  schema identity. Pixel-diff defers to Phase 4 alongside more nodes.

New shelf node (no legacy — registered unconditionally):
- ShelfNode schema in core/schema/nodes/shelf.ts (hand-maintained
  AnyNode union for now; Phase 6 derives the union from the registry
  and moves the schema fully into nodes/shelf/).
- packages/nodes/src/shelf/ folder: pure geometry builder
  (buildShelfGeometry returns a Three.js Group of top board +
  brackets), R3F renderer that mounts the built group, no-props
  placement tool, parametrics descriptor (width/depth/thickness/
  height/bracketStyle/color), definition with surfaces.top stackable
  surface for future stacking, and presentation metadata for the
  palette.
- 13 unit tests across schema bounds and geometry behavior.
- Palette wiring: 'shelf' added to StructureTool union + an entry in
  the structure-tools array (placeholder icon, replaced in Phase 4
  when palette is registry-driven).

Framework changes:
- @pascal-app/viewer now exports useNodeEvents from its public barrel
  so node bundles in @pascal-app/nodes can subscribe to node-specific
  pointer events. (Used by spawn renderer; shelf renderer skips it
  for now since useNodeEvents has a hardcoded kind list — Phase 4
  generalizes it via the registry.)
- @pascal-app/nodes gains @pascal-app/viewer as a peer + dev dep so
  node bundles can import from it.

630 tests pass across 76 files (22 new this phase). Editor app
continues to ship green with both legacy spawn and the new shelf
node co-existing through the Phase 0 dispatch shims.

To validate end-to-end in dev:
- bun dev:community → open editor → click 'Shelf' in structure
  toolbar → click to place. Confirms full registry path
  (NodeRenderer dispatch + ToolManager dispatch + sceneRegistry
  byType Proxy).
- Set NEXT_PUBLIC_USE_REGISTRY_FOR_SPAWN=1, restart dev, place spawn
  → visually identical to legacy. Confirms parity.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Wassim SAMAD
2026-05-14 13:07:38 -04:00
co-authored by Claude Opus 4.7
parent e8cf85313b
commit b6d77206b4
27 changed files with 881 additions and 6 deletions
@@ -0,0 +1,69 @@
import { describe, expect, test } from 'bun:test'
import { SpawnNode as SpawnSchemaFromCore } from '@pascal-app/core'
import { spawnDefinition } from '../definition'
import { SpawnNode } from '../schema'
/**
* Structural parity for the spawn registry definition.
*
* The new renderer is a near-line-by-line port of the legacy
* `@pascal-app/viewer/components/renderers/spawn/spawn-renderer.tsx` —
* same mesh count, same primitives, same colors. The "parity" assertion
* for the spike is structural (definition is well-formed, both lazy
* modules resolve to React components) plus a manual visual eyeball check
* documented in the plan. Pixel-level Playwright parity lands in Phase 4
* when more nodes are migrated.
*/
describe('spawn definition', () => {
test('schema matches the core schema export', () => {
// Both imports must point to the same Zod schema — the registry
// definition re-exports from core.
expect(SpawnNode).toBe(SpawnSchemaFromCore)
})
test('definition has the expected shape', () => {
expect(spawnDefinition.kind).toBe('spawn')
expect(spawnDefinition.schemaVersion).toBe(1)
expect(spawnDefinition.category).toBe('site')
expect(spawnDefinition.schema).toBe(SpawnNode)
})
test('defaults() returns a value that the schema accepts', () => {
const defaults = spawnDefinition.defaults()
const parsed = SpawnNode.safeParse({ ...defaults, id: 'spawn_test1234567890ab' })
expect(parsed.success).toBe(true)
})
test('presentation declares an iconify icon for the palette', () => {
expect(spawnDefinition.presentation?.label).toBe('Spawn Point')
expect(spawnDefinition.presentation?.icon.kind).toBe('iconify')
expect(spawnDefinition.presentation?.paletteSection).toBe('structure')
})
test("movable capability restricts to X/Z (matches today's placement behavior)", () => {
expect(spawnDefinition.capabilities.movable?.axes).toEqual(['x', 'z'])
expect(spawnDefinition.capabilities.movable?.gridSnap).toBe(true)
})
test('rotatable capability declares yaw-only with diagonal-friendly snap angles', () => {
expect(spawnDefinition.capabilities.rotatable?.axes).toEqual(['y'])
const angles = spawnDefinition.capabilities.rotatable?.snapAngles ?? []
expect(angles.length).toBeGreaterThanOrEqual(3)
expect(angles).toContain(0)
})
test('renderer is a parametric lazy module reference', () => {
expect(spawnDefinition.renderer.kind).toBe('parametric')
if (spawnDefinition.renderer.kind !== 'parametric') return
expect(typeof spawnDefinition.renderer.module).toBe('function')
})
test('tool is a lazy module reference', () => {
expect(typeof spawnDefinition.tool).toBe('function')
})
test('mcp description is set so AI surfaces describe the kind', () => {
expect(spawnDefinition.mcp?.description).toBeDefined()
expect(spawnDefinition.mcp?.description?.length).toBeGreaterThan(0)
})
})