feat: establish reproducible FreeCAD web compatibility baseline
This commit is contained in:
12
tests/scriptSandbox.test.ts
Normal file
12
tests/scriptSandbox.test.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { describe, it } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { createScriptSandbox } from '../src/facade/scriptSandbox'
|
||||
|
||||
describe('script sandbox', () => {
|
||||
it('records and replays only approved Facade commands', () => {
|
||||
const sandbox = createScriptSandbox({ allowedCommands: ['project.list', 'geometry.createBox'], maxCommands: 3 }); sandbox.record('project.list'); sandbox.record('geometry.createBox', { width: 2, height: 3 }); const macro = sandbox.exportMacro(); assert.equal(sandbox.importMacro(macro).length, 2); assert.deepEqual(sandbox.replay(), { status: 'replayed', executed: 2, rejected: [] }); assert.equal(sandbox.snapshot().policy.maxCommands, 3); for (const capability of ['file', 'network', 'time', 'resource'] as const) assert.equal(sandbox.requestCapability(capability).granted, false)
|
||||
})
|
||||
it('rejects disallowed commands and enforces argument and command quotas', () => {
|
||||
const sandbox = createScriptSandbox({ allowedCommands: ['project.list'], maxCommands: 1, maxArgumentBytes: 10 }); assert.throws(() => sandbox.record('geometry.boolean'), /not allowed/); assert.throws(() => sandbox.record('project.list', 'this argument is too long'), /quota/); sandbox.record('project.list'); assert.throws(() => sandbox.record('project.list'), /quota/); assert.equal(sandbox.replay([{ sequence: 1, command: 'geometry.boolean', arguments: null }]).status, 'rejected')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user