Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions packages/core/src/architecture.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { describe, expect, test } from 'bun:test'
import { readdirSync, readFileSync } from 'node:fs'
import { join, relative, resolve } from 'node:path'

/**
* Layer rule (AGENTS.md): core is pure logic — no Three.js, no rendering.
* A runtime `three`/`@react-three/*` import in core evaluates R3F (and thus
* React client context) in every consumer of the barrel, which crashes
* Next.js route handlers under the RSC server condition (capture uploads
* 500'd this way once). Type-only imports are erased at build and allowed.
*/
const SRC = resolve(import.meta.dir)

function sourceFiles(dir: string): string[] {
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
const full = join(dir, entry.name)
if (entry.isDirectory()) return sourceFiles(full)
if (/\.test\.tsx?$/.test(entry.name)) return []
return /\.tsx?$/.test(entry.name) ? [full] : []
})
}

const BANNED_SPEC = String.raw`(?:three(?:\/[^'"]*)?|@react-three\/[^'"]*)`
// `import`/`export … from 'three…'` — group 1 captures a whole-clause `type`
// qualifier, the only form guaranteed to be erased by the compiler.
const FROM_RE = new RegExp(
String.raw`(?:import|export)\s+(type\s)?[\w*{}\s,$]*?from\s*['"]${BANNED_SPEC}['"]`,
'g',
)
// Bare side-effect form: `import 'three…'` — always a runtime import.
const SIDE_EFFECT_RE = new RegExp(String.raw`import\s*['"]${BANNED_SPEC}['"]`, 'g')

describe('architecture', () => {
test('core has no runtime three/@react-three imports', () => {
const files = sourceFiles(SRC)
const offenders: string[] = []

for (const file of files) {
const src = readFileSync(file, 'utf8')
for (const match of src.matchAll(FROM_RE)) {
if (!match[1]) offenders.push(`${relative(SRC, file)}: ${match[0].replaceAll('\n', ' ')}`)
}
for (const match of src.matchAll(SIDE_EFFECT_RE)) {
offenders.push(`${relative(SRC, file)}: ${match[0]}`)
}
}

expect(offenders).toEqual([])
// Guard against the walk passing vacuously.
expect(files.length).toBeGreaterThan(100)
})
})
5 changes: 4 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ export type {
FloorPlacedFootprintsResolver,
} from './registry'
export * from './registry'
// Exported here rather than from the registry barrel: that barrel is
// reachable from server-safe graphs (schema → spatial grid → registry)
// and must stay free of React imports.
export { useRegistryVersion } from './registry/use-registry-version'
export * from './schema'
export * from './services'
export { isMovable, movePlanToward, moveToward, resolveMovable } from './services/movement'
Expand Down Expand Up @@ -361,7 +365,6 @@ export {
stepElevatorRuntimeState,
stepElevatorRuntimes,
} from './systems/elevator/elevator-runtime'
export { ElevatorRuntimeSystem } from './systems/elevator/elevator-runtime-system'
export {
type ElevatorLevelEntry,
resolveElevatorBuildingLevels,
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,3 @@ export type {
ToolHintChip,
Vec2,
} from './types'
export { useRegistryVersion } from './use-registry-version'
10 changes: 0 additions & 10 deletions packages/core/src/systems/elevator/elevator-runtime-system.tsx

This file was deleted.

13 changes: 12 additions & 1 deletion packages/nodes/src/elevator/system.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
'use client'

import { ElevatorOpeningSystem, ElevatorRuntimeSystem } from '@pascal-app/core'
import { ElevatorOpeningSystem, stepElevatorRuntimes } from '@pascal-app/core'
import { ElevatorInteractionSystem } from '@pascal-app/viewer'
import { useFrame } from '@react-three/fiber'

/** Cab travel + door state machine, stepped once per frame. Lives here rather
* than in core so the core barrel stays free of runtime R3F imports. */
function ElevatorRuntimeSystem() {
useFrame(({ clock }, delta) => {
stepElevatorRuntimes(clock.getElapsedTime() * 1000, delta)
}, 2)

return null
}

/**
* Composite system for elevator — bundles three per-frame systems:
Expand Down
Loading