Skip to content
Open
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
94 changes: 80 additions & 14 deletions bun.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@
"urdf-loader": "^0.13.1"
},
"peerDependencies": {
"@pascal-app/core": ">=1.0.0-beta.4 <1.0.0",
"@pascal-app/editor": ">=1.0.0-beta.4 <1.0.0",
"@pascal-app/viewer": ">=1.0.0-beta.4 <1.0.0",
"@pascal-app/core": ">=1.0.0-beta.4 <2.0.0",
"@pascal-app/editor": ">=1.0.0-beta.4 <2.0.0",
"@pascal-app/viewer": ">=1.0.0-beta.4 <2.0.0",
"@react-three/fiber": "^9",
"react": "^18 || ^19",
"three": "^0.185",
"three": "^0.185 || ^0.186",
"zod": "^4",
"zustand": "^5"
},
"devDependencies": {
"@pascal-app/core": "1.0.0-beta.4",
"@pascal-app/editor": "1.0.0-beta.4",
"@pascal-app/viewer": "1.0.0-beta.4",
"@pascal-app/core": "1.0.3",
"@pascal-app/editor": "1.0.3",
"@pascal-app/viewer": "1.0.3",
"@react-three/fiber": "^9.5.0",
"@types/bun": "^1.3.5",
"@types/blob-stream": "^0.1.33",
Expand All @@ -50,10 +50,10 @@
"@types/pdfkit": "^0.17.3",
"@types/react": "^19.2.2",
"@types/react-dom": "^19.2.2",
"@types/three": "^0.185.0",
"@types/three": "0.184.1",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"three": "^0.185.0",
"three": "0.186.0",
"typescript": "6.0.3",
"zod": "^4.3.6",
"zustand": "^5.0.11"
Expand Down
22 changes: 22 additions & 0 deletions src/joint-controls.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, test } from 'bun:test'
import { runProbe } from './test-support/host-stubs'

describe('Articraft inspector', () => {
test('every slider drag commits as one undo step (restoreOnCommit left on)', () => {
const sliders = runProbe<Array<{ label: string; restoreOnCommit: unknown }>>(
new URL('./test-support/joint-controls-probe.tsx', import.meta.url).pathname,
)
expect(sliders.map((slider) => slider.label)).toEqual([
'Scale',
'Position X',
'Position Y',
'Position Z',
'Rotation X',
'Rotation Y',
'Rotation Z',
'lid',
'drawer',
])
expect(sliders.filter((slider) => slider.restoreOnCommit === false)).toEqual([])
})
})
4 changes: 0 additions & 4 deletions src/joint-controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export default function ArticraftJointControls() {
min={0.05}
onChange={setScale}
precision={2}
restoreOnCommit={false}
step={0.05}
value={node.scale}
/>
Expand All @@ -85,7 +84,6 @@ export default function ArticraftJointControls() {
min={-100}
onChange={(value) => setVector('position', index, value)}
precision={2}
restoreOnCommit={false}
step={0.05}
unit="m"
value={node.position[index]}
Expand All @@ -99,7 +97,6 @@ export default function ArticraftJointControls() {
min={-180}
onChange={(value) => setVector('rotation', index, value)}
precision={1}
restoreOnCommit={false}
step={1}
unit="°"
value={toDegrees(node.rotation[index])}
Expand All @@ -126,7 +123,6 @@ export default function ArticraftJointControls() {
min={displayRange[0]}
onChange={(value) => setJoint(joint, angular ? toRadians(value) : value)}
precision={angular ? 1 : 3}
restoreOnCommit={false}
step={angular ? 1 : 0.001}
unit={angular ? '°' : 'm'}
value={angular
Expand Down
37 changes: 37 additions & 0 deletions src/package.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { describe, expect, test } from 'bun:test'
import { readFileSync } from 'node:fs'

const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')) as {
peerDependencies: Record<string, string>
}

// The host ships Pascal 1.x on three 0.186 (@pascal-app/core 1.0.3 pins `three ^0.186`);
// strict installs refuse the plugin when a peer range excludes them.
const shippedHost = {
'@pascal-app/core': ['1.0.0-beta.4', '1.0.3', '1.9.0'],
'@pascal-app/editor': ['1.0.0-beta.4', '1.0.3', '1.9.0'],
'@pascal-app/viewer': ['1.0.0-beta.4', '1.0.3', '1.9.0'],
three: ['0.185.0', '0.186.0', '0.186.1'],
} as const

describe('peer ranges', () => {
for (const [name, versions] of Object.entries(shippedHost)) {
test(`${name} accepts ${versions.join(', ')}`, () => {
const range = manifest.peerDependencies[name]
expect(range).toBeDefined()
for (const version of versions) {
expect({ version, accepted: Bun.semver.satisfies(version, range ?? '') }).toEqual({
version,
accepted: true,
})
}
})
}

test('does not claim the next major', () => {
for (const name of ['@pascal-app/core', '@pascal-app/editor', '@pascal-app/viewer']) {
expect(Bun.semver.satisfies('2.0.0', manifest.peerDependencies[name] ?? '')).toBe(false)
}
expect(Bun.semver.satisfies('0.187.0', manifest.peerDependencies.three ?? '')).toBe(false)
})
})
26 changes: 26 additions & 0 deletions src/test-support/host-stubs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { plugin } from 'bun'

/**
* Replaces the host packages (`@pascal-app/core`, `editor`, `viewer`) with
* stubs for a probe script. Module stubs are process-global, so probes run in
* a child process (see `runProbe`) and never inside the test runner.
*/
export function stubHostModules(stubs: Record<string, Record<string, unknown>>): void {
plugin({
name: 'articraft-host-stubs',
setup(build) {
for (const [specifier, exports] of Object.entries(stubs)) {
build.module(specifier, () => ({ exports, loader: 'object' }))
}
},
})
}

/** Runs a probe script in a child process and returns the JSON it prints. */
export function runProbe<T>(probe: string): T {
const result = Bun.spawnSync([process.execPath, probe], { stderr: 'pipe', stdout: 'pipe' })
if (result.exitCode !== 0) {
throw new Error(`${probe} failed:\n${result.stderr.toString()}`)
}
return JSON.parse(result.stdout.toString()) as T
}
61 changes: 61 additions & 0 deletions src/test-support/joint-controls-probe.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { renderToStaticMarkup } from 'react-dom/server'
import { stubHostModules } from './host-stubs'

// Renders the Articraft inspector against stubbed host packages and prints
// the props every SliderControl received.
const NODE_ID = 'articraft_probe'
const node = {
id: NODE_ID,
type: 'articraft:asset',
position: [0, 0, 0],
rotation: [0, 0, 0],
scale: 1,
joints: [
{
name: 'lid',
type: 'revolute',
parent: 'base',
child: 'lid',
axis: [0, 0, 1],
origin: { xyz: [0, 0, 0], rpy: [0, 0, 0] },
limits: { lower: 0, upper: 1.5 },
},
{
name: 'drawer',
type: 'prismatic',
parent: 'base',
child: 'drawer',
axis: [1, 0, 0],
origin: { xyz: [0, 0, 0], rpy: [0, 0, 0] },
limits: { lower: 0, upper: 0.4 },
},
],
jointValues: {},
motionEnabled: false,
attribution: { creator: 'Articraft authors', license: 'CC-BY-4.0', sourceUrl: 'https://x.test' },
}
const sliders: Array<{ label: string; restoreOnCommit: unknown }> = []
const state = { nodes: { [NODE_ID]: node }, updateNode: () => undefined }

stubHostModules({
'@pascal-app/core': {
useScene: Object.assign((select: (value: typeof state) => unknown) => select(state), {
getState: () => state,
}),
},
'@pascal-app/editor': {
PanelSection: ({ children }: { children?: unknown }) => children,
SliderControl: (props: { label: string; restoreOnCommit?: boolean }) => {
sliders.push({ label: props.label, restoreOnCommit: props.restoreOnCommit ?? 'default' })
return null
},
},
'@pascal-app/viewer': {
useViewer: (select: (value: unknown) => unknown) =>
select({ selection: { selectedIds: [NODE_ID] } }),
},
})

const { default: ArticraftJointControls } = await import('../joint-controls')
renderToStaticMarkup(<ArticraftJointControls />)
console.log(JSON.stringify(sliders))
Loading