also looking at this
feat: model one point-load intake with conserved momentum
#99
45 files
+3133
-169
| @@ -0,0 +1,73 @@ | ||
| 1 | import { expect, test } from 'bun:test' | |
| 2 | import { command } from '@stacksjs/testing' | |
| 3 | import { mkdtemp, rm, symlink, writeFile } from 'node:fs/promises' | |
| 4 | import { tmpdir } from 'node:os' | |
| 5 | import { join } from 'node:path' | |
| 6 | import { spawn } from 'node:child_process' | |
| 7 | ||
| 8 | test('native Buddy executes an explicit cargo mission file and reports the configured modeled delivery', async () => { | |
| 9 | const result = await command(['cargo:mission', 'examples/cargo-delivery.json']).withTimeout(30000) | |
| 10 | expect(result.timedOut).toBe(false) | |
| 11 | expect(result.exitCode).toBe(0) | |
| 12 | expect(result.stderr).toBe('') | |
| 13 | const report = JSON.parse(result.stdout) | |
| 14 | expect(report.status).toBe('completed') | |
| 15 | expect(report.delivery).toMatchObject({ outcome: 'received', containerId: 'parcel-150g', siteId: 'declared-site', recipientId: 'declared-recipient' }) | |
| 16 | expect(report.configuration.id).toBe('operator-cargo-route') | |
| 17 | expect(report.load.initial.totalMassKg).toBe(1.65) | |
| 18 | expect(report.load.final.totalMassKg).toBe(1.5) | |
| 19 | expect(report.landingContact).toBe(true) | |
| 20 | expect(report.board.actuators).toEqual([0, 0, 0, 0]) | |
| 21 | expect(report.physicalFlightEnabled).toBe(false) | |
| 22 | expect(report.identityAuthenticated).toBe(false) | |
| 23 | expect(result.stdout.trim().split('\n')).toHaveLength(1) | |
| 24 | expect(Buffer.byteLength(result.stdout)).toBeLessThanOrEqual(16384) | |
| 25 | }, 40000) | |
| 26 | ||
| 27 | test('native configured cargo reports alternate and post-release outcomes with exit2', async () => { | |
| 28 | for (const [scenario, status, custody] of [['site-blocked', 'diverted', 'not-released'], ['after-release-host-loss', 'host-lost', 'uncertain'], ['after-receipt-kill', 'blocked', 'received']]) { | |
| 29 | const result = await command(['cargo:mission', 'examples/cargo-delivery.json', '--scenario', scenario!]).withTimeout(30000) | |
| 30 | expect(result.timedOut).toBe(false) | |
| 31 | expect(result.exitCode).toBe(2) | |
| 32 | expect(result.stderr).toBe('') | |
| 33 | const report = JSON.parse(result.stdout) | |
| 34 | expect(report.status).toBe(status) | |
| 35 | expect(report.delivery.outcome).toBe(custody) | |
| 36 | expect(report.demonstrationMatched).toBe(true) | |
| 37 | expect(report.configuration.id).toBe('operator-cargo-route') | |
| 38 | expect(report.board.actuators).toEqual([0, 0, 0, 0]) | |
| 39 | } | |
| 40 | }, 100000) | |
| 41 | ||
| 42 | test('native configured cargo refuses malformed, oversized and symlink requests without caller details', async () => { | |
| 43 | const root = await mkdtemp(join(tmpdir(), 'drone-cargo-mission-')) | |
| 44 | try { | |
| 45 | const invalid = join(root, 'invalid.json'), oversized = join(root, 'oversized.json'), unicode = join(root, 'unicode.json'), link = join(root, 'link.json') | |
| 46 | await writeFile(invalid, '{"private-sentinel":"/operator/private"}') | |
| 47 | await writeFile(oversized, ' '.repeat(16385)) | |
| 48 | await writeFile(unicode, new Uint8Array([255])) | |
| 49 | await symlink(invalid, link) | |
| 50 | for (const path of [invalid, oversized, unicode, link, root, join(root, 'private-missing')]) { | |
| 51 | const result = await command(['cargo:mission', path]).withTimeout(30000) | |
| 52 | expect(result.timedOut).toBe(false) | |
| 53 | expect(result.exitCode).toBe(1) | |
| 54 | expect(result.stdout).toBe('') | |
| 55 | expect(result.stderr).toBe('Cargo mission simulation unavailable: invalid declaration, rejected route or output failure\n') | |
| 56 | } | |
| 57 | } | |
| 58 | finally { await rm(root, { recursive: true, force: true }) } | |
| 59 | }, 190000) | |
| 60 | ||
| 61 | test('a closed configured cargo stdout retains failure and awaits its fixed diagnostic', async () => { | |
| 62 | const child = spawn(process.execPath, ['bin/drone.ts', 'cargo:mission', 'examples/cargo-delivery.json'], { stdio: ['ignore', 'pipe', 'pipe'] }) | |
| 63 | child.stdout.destroy() | |
| 64 | let stderr = '', timedOut = false | |
| 65 | child.stderr.on('data', (chunk: Buffer) => { stderr += chunk.toString('utf8'); if (Buffer.byteLength(stderr) > 8192) child.kill('SIGKILL') }) | |
| 66 | const guard = setTimeout(() => { timedOut = true; child.kill('SIGKILL') }, 30000) | |
| 67 | let code: number | null | |
| 68 | try { code = await new Promise<number | null>((resolve, reject) => { child.once('error', reject); child.once('close', resolve) }) } | |
| 69 | finally { clearTimeout(guard) } | |
| 70 | expect(timedOut).toBe(false) | |
| 71 | expect(code).toBe(1) | |
| 72 | expect(stderr).toBe('Cargo mission simulation unavailable: invalid declaration, rejected route or output failure\n') | |
| 73 | }, 40000) | |