also looking at this
feat: add shared-clock scoped vehicle simulation sessions
#98
42 files
+2764
-127
| @@ -0,0 +1,59 @@ | ||
| 1 | import { expect, test } from 'bun:test' | |
| 2 | import { cargoDeliverySummary, simulateCargoDelivery } from '../../resources/functions/drone/cargo/delivery' | |
| 3 | ||
| 4 | test('host loss after observed separation leaves uncertain custody while the independent parcel and board keep evolving', () => { | |
| 5 | const run = simulateCargoDelivery({ scenario: 'after-release-host-loss' }) | |
| 6 | expect(run.status).toBe('host-lost') | |
| 7 | expect(run.release?.outcome).toBe('separated') | |
| 8 | expect(run.finalLoad.properties.totalMassKg).toBe(1.5) | |
| 9 | expect(run.delivery.outcome).toBe('uncertain') | |
| 10 | expect(run.delivery.receiptCapturedAtMs).toBeNull() | |
| 11 | expect(run.parcel?.onSurface).toBe(true) | |
| 12 | expect(run.runtime.board.fault).toBe('output-lease-expired') | |
| 13 | expect(run.runtime.board.actuators).toEqual([0, 0, 0, 0]) | |
| 14 | expect(run.runtime.authority.state).toBe('autonomous') | |
| 15 | expect(run.runtime.mission.state).toBe('running') | |
| 16 | expect(run.runtime.trace.rows.some(row => row.result.reason === 'payload-confirmed')).toBe(false) | |
| 17 | const firstOpen = run.runtime.path.find(row => row.measurement?.values.mechanismOpen === true)! | |
| 18 | expect(run.faultInjection).toMatchObject({ phase: 'after-release', anchoredAtMs: firstOpen.atMs, sourceCapturedAtMs: firstOpen.measurement!.capturedAtMs, eventId: run.release!.eventId, triggeredAtMs: firstOpen.atMs + 20, independentTailMs: 1000 }) | |
| 19 | expect(run.faultInjection!.finalPhysicalAtMs).toBeGreaterThan(run.runtime.authority.lastCheckedAtMs! + 1000) | |
| 20 | const summary = cargoDeliverySummary(run) | |
| 21 | expect(summary.authority.hostAvailable).toBe(false) | |
| 22 | expect(summary.demonstrationMatched).toBe(true) | |
| 23 | expect(summary.landingContact).toBe(false) | |
| 24 | }, 30000) | |
| 25 | ||
| 26 | for (const fault of ['position-loss', 'imu-loss', 'vehicle-sensor-loss', 'rc-override', 'kill', 'both-links-loss']) test(`a post-separation ${fault} preserves uncertain custody and independent parcel motion`, () => { | |
| 27 | const run = simulateCargoDelivery({ scenario: 'after-release-' + fault }) | |
| 28 | expect(run.status).toBe('blocked') | |
| 29 | expect(run.release?.outcome).toBe('separated') | |
| 30 | expect(run.delivery.outcome).toBe('uncertain') | |
| 31 | expect(run.delivery.receiptCapturedAtMs).toBeNull() | |
| 32 | expect(run.parcel?.onSurface).toBe(true) | |
| 33 | expect(run.parcel!.capturedAtMs).toBeGreaterThan(run.runtime.trace.rows.at(-1)!.observation.nowMs) | |
| 34 | expect(run.runtime.board.actuators).toEqual([0, 0, 0, 0]) | |
| 35 | expect(run.runtime.mission.state).not.toBe('completed') | |
| 36 | expect(run.runtime.trace.rows.some(row => row.result.reason === 'payload-confirmed')).toBe(false) | |
| 37 | const firstOpen = run.runtime.path.find(row => row.measurement?.values.mechanismOpen === true)! | |
| 38 | expect(run.faultInjection).toMatchObject({ anchoredAtMs: firstOpen.atMs, sourceCapturedAtMs: firstOpen.measurement!.capturedAtMs, eventId: run.release!.eventId, triggeredAtMs: firstOpen.atMs + 20 }) | |
| 39 | const observed = run.runtime.authority.events | |
| 40 | expect(observed.some(event => fault === 'kill' ? event.to === 'killed' : fault === 'rc-override' ? event.to === 'manual' : fault === 'both-links-loss' ? event.reason === 'link-loss' : fault === 'position-loss' ? ['estimator-loss', 'stale-estimator'].includes(event.reason) : event.reason === 'stale-interlocks')).toBe(true) | |
| 41 | expect(cargoDeliverySummary(run).demonstrationMatched).toBe(true) | |
| 42 | }, 30000) | |
| 43 | ||
| 44 | for (const fault of ['host-loss', 'kill', 'position-loss']) test(`a post-receipt ${fault} preserves received custody without inventing carrier completion`, () => { | |
| 45 | const run = simulateCargoDelivery({ scenario: 'after-receipt-' + fault }) | |
| 46 | expect(run.status).toBe(fault === 'host-loss' ? 'host-lost' : 'blocked') | |
| 47 | expect(run.delivery.outcome).toBe('received') | |
| 48 | expect(run.delivery.receiptCapturedAtMs).not.toBeNull() | |
| 49 | expect(run.release?.outcome).toBe('separated') | |
| 50 | expect(run.parcel?.onSurface).toBe(true) | |
| 51 | expect(run.runtime.trace.rows.filter(row => row.observation.payloadAck?.outcome === 'confirmed')).toHaveLength(1) | |
| 52 | const acknowledged = run.runtime.trace.rows.find(row => row.observation.payloadAck?.outcome === 'confirmed')! | |
| 53 | expect(run.faultInjection).toMatchObject({ phase: 'after-receipt', anchoredAtMs: acknowledged.observation.nowMs, sourceCapturedAtMs: acknowledged.observation.payloadAck!.capturedAtMs, eventId: acknowledged.observation.payloadAck!.eventId, triggeredAtMs: acknowledged.observation.nowMs + 20 }) | |
| 54 | expect(run.delivery.receiptCapturedAtMs!).toBeGreaterThan(run.parcel!.capturedAtMs) | |
| 55 | expect(run.runtime.mission.state).not.toBe('completed') | |
| 56 | expect(run.runtime.board.actuators).toEqual([0, 0, 0, 0]) | |
| 57 | expect(cargoDeliverySummary(run).landingContact).toBe(false) | |
| 58 | expect(cargoDeliverySummary(run).demonstrationMatched).toBe(true) | |
| 59 | }, 30000) | |