also looking at this
feat: model one point-load intake with conserved momentum
#99
45 files
+3133
-169
| @@ -0,0 +1,92 @@ | ||
| 1 | import { expect, test } from 'bun:test' | |
| 2 | import { createMultirotorProfile } from '../../resources/functions/drone/vehicles/multirotor/profile' | |
| 3 | import { runVehicleSimulation } from '../../resources/functions/drone/vehicles/runtime' | |
| 4 | import { replayVehicleMission } from '../../resources/functions/drone/missions/vehicle' | |
| 5 | ||
| 6 | // Existing public owned-runtime seam: actual raw sensors, estimator, mission, | |
| 7 | // controls and board. This verifies modeled execution, not firmware or flight. | |
| 8 | test('a four-motor profile executes the shared mission and lands with replayable observations', () => { | |
| 9 | const run = runVehicleSimulation(createMultirotorProfile(), { seconds: 100 }) | |
| 10 | expect(run.vehicle).toBe('quadcopter') | |
| 11 | expect(run.status).toBe('completed') | |
| 12 | expect(run.fault).toBeNull() | |
| 13 | expect(run.navigationEvidence.observedSensors.imu).toBeGreaterThan(100) | |
| 14 | expect(run.navigationEvidence.observedSensors.gnss).toBeGreaterThan(20) | |
| 15 | expect(run.path.some(row => row.positionM && Math.hypot(row.positionM[0] - 2, row.positionM[1] - 1, row.positionM[2] + 1) < .25)).toBe(true) | |
| 16 | expect(run.path.some(row => row.actuators.some(n => n > 0))).toBe(true) | |
| 17 | expect(run.trace.rows.at(-1)!.observation.onGround).toBe(true) | |
| 18 | expect(run.board.actuators).toEqual([0, 0, 0, 0]) | |
| 19 | expect(run.board.expiresAtMs).toBeNull() | |
| 20 | expect(run.authority.state).toBe('disarmed') | |
| 21 | expect(replayVehicleMission(run.trace).snapshot()).toEqual(run.mission) | |
| 22 | expect(run.physicalFlightEnabled).toBe(false) | |
| 23 | expect(run.board.physicalActuationEnabled).toBe(false) | |
| 24 | }, 30000) | |
| 25 | ||
| 26 | for (const scenario of ['imu-loss', 'position-loss', 'vehicle-sensor-loss', 'rc-override', 'kill', 'host-loss', 'link-loss'] as const) { | |
| 27 | test('the shared four-motor mission preserves independent authority under ' + scenario, () => { | |
| 28 | const run = runVehicleSimulation(createMultirotorProfile(scenario), { seconds: 100 }) | |
| 29 | expect(run.status).toBe(scenario === 'host-loss' ? 'host-lost' : 'blocked') | |
| 30 | expect(run.mission.state).not.toBe('completed') | |
| 31 | expect(run.board.actuators).toEqual([0, 0, 0, 0]) | |
| 32 | expect(run.board.expiresAtMs).toBeNull() | |
| 33 | expect(run.fault).not.toBeNull() | |
| 34 | expect(run.board.physicalActuationEnabled).toBe(false) | |
| 35 | if (scenario === 'host-loss') { | |
| 36 | expect(run.board.fault).toBe('output-lease-expired') | |
| 37 | expect(run.authority.state).toBe('autonomous') | |
| 38 | } | |
| 39 | else expect(run.authority.state).not.toBe('autonomous') | |
| 40 | }, 30000) | |
| 41 | } | |
| 42 | ||
| 43 | test('a four-motor controller rejects rate evidence from a different estimator reference', () => { | |
| 44 | const profile = createMultirotorProfile(), createSession = profile.createSession | |
| 45 | let changed = false | |
| 46 | profile.createSession = () => { | |
| 47 | const session = createSession(), controller = session.createController() | |
| 48 | return { ...session, createController: () => ({ step(context) { | |
| 49 | if (context.enabled && context.nowMs === 2000 && context.controlRate) { | |
| 50 | context.controlRate.reference = '55:99,99,99,99,99' | |
| 51 | changed = true | |
| 52 | } | |
| 53 | return controller.step(context) | |
| 54 | } }) } | |
| 55 | } | |
| 56 | const run = runVehicleSimulation(profile, { seconds: 100 }) | |
| 57 | expect(changed).toBe(true) | |
| 58 | expect(run.status).toBe('blocked') | |
| 59 | expect(run.fault).toBe('quad-rate-unqualified') | |
| 60 | expect(run.board.actuators).toEqual([0, 0, 0, 0]) | |
| 61 | }, 30000) | |
| 62 | ||
| 63 | test('an installed link adapter cannot become a fabricated healthy link when its result fails', () => { | |
| 64 | let getterRead = false | |
| 65 | const badResults: (() => unknown)[] = [() => null, () => undefined, () => { throw new Error('private-radio-detail') }, | |
| 66 | () => ({ capturedAtMs: 2001, connected: true }), () => ({ capturedAtMs: 2000, connected: 'yes' }), | |
| 67 | () => ({ capturedAtMs: 2000, get connected() { getterRead = true; return true } })] | |
| 68 | for (const badResult of badResults) { | |
| 69 | const profile = createMultirotorProfile(), createSession = profile.createSession | |
| 70 | profile.createSession = () => ({ ...createSession(), linkObservation(nowMs) { | |
| 71 | return (nowMs < 2000 ? { capturedAtMs: nowMs, connected: true } : badResult()) as { capturedAtMs: number, connected: boolean } | |
| 72 | } }) | |
| 73 | const run = runVehicleSimulation(profile, { seconds: 100 }) | |
| 74 | expect(run.status).toBe('blocked') | |
| 75 | expect(run.authority.events.some(event => event.reason === 'link-loss')).toBe(true) | |
| 76 | expect(run.board.actuators).toEqual([0, 0, 0, 0]) | |
| 77 | expect(run.board.expiresAtMs).toBeNull() | |
| 78 | } | |
| 79 | expect(getterRead).toBe(false) | |
| 80 | }, 30000) | |
| 81 | ||
| 82 | test('an installed link adapter preserves source age and cannot override declared link loss', () => { | |
| 83 | for (const scenario of ['nominal', 'link-loss'] as const) { | |
| 84 | const profile = createMultirotorProfile(scenario), createSession = profile.createSession | |
| 85 | profile.createSession = () => ({ ...createSession(), linkObservation: nowMs => ({ capturedAtMs: scenario === 'nominal' ? Math.min(nowMs, 2000) : nowMs, connected: true }) }) | |
| 86 | const run = runVehicleSimulation(profile, { seconds: 100 }) | |
| 87 | expect(run.status).toBe('blocked') | |
| 88 | expect(run.authority.events.some(event => event.reason === 'link-loss')).toBe(true) | |
| 89 | expect(run.path.at(-1)!.atMs).toBe(scenario === 'nominal' ? 2160 : 5000) | |
| 90 | expect(run.board.actuators).toEqual([0, 0, 0, 0]) | |
| 91 | } | |
| 92 | }, 30000) | |