import { describe, expect, it } from 'vitest'; import { LANGUAGE_VERSION, resolveTarget } from './LanguageScene'; import { validateRobotCommand } from './RobotCommand'; describe('语言任务目标', () => { it('命名区与连续坐标使用同一支撑面,不修改场景', () => { expect(resolveTarget('B')).toEqual({ position: [0.257, 0.75, 0.128], supportId: 'table' }); expect(resolveTarget('coordinates', [0.25, 0.5])).toEqual({ position: [0.25, 0.5, 0.128], supportId: 'table', }); expect(resolveTarget('coordinates', [0.257, 0.015, 0.128]).supportId).toBe('source'); }); it.each([ [0.2, 0.5], [0.25, 0.9], [0.25, 0.5, 0.3], [NaN, 0.5], [Infinity, 0.5], ])('rejects unsafe %s', (...p) => { expect(() => resolveTarget('coordinates', p)).toThrow(); }); it('拒绝模型覆盖命名区、未知目标与不匹配支撑', () => { const c = { version: LANGUAGE_VERSION, action: 'pick_place', value: 0, summary: '搬运', objectId: 'block', targetId: 'B', position: [], supportId: 'table', }; expect(validateRobotCommand(c).targetId).toBe('B'); for (const invalid of [ { position: [0.25, 0.5] }, { targetId: 'C' }, { supportId: 'source' }, { code: 'run()' }, ]) expect(() => validateRobotCommand({ ...c, ...invalid })).toThrow(); }); });