|
| 1 | +// SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | + |
| 3 | +import { expect } from "expect"; |
| 4 | +import { describe, it } from "node:test"; |
| 5 | + |
| 6 | +import { |
| 7 | + CaeContractOracle, |
| 8 | + SemanticTheoryCoordinator, |
| 9 | + simulateDroneReachability, |
| 10 | + SpatialPhysicsOracle, |
| 11 | +} from "../src/index.js"; |
| 12 | + |
| 13 | +describe("Native Drone Reachability & Theory Coordination (Runtime Verification)", () => { |
| 14 | + it("Nelson-Oppen Theory Coordinator should prove multi-domain contract SAT", () => { |
| 15 | + const coordinator = new SemanticTheoryCoordinator(); |
| 16 | + const spatialOracle = new SpatialPhysicsOracle(); |
| 17 | + const caeOracle = new CaeContractOracle(); |
| 18 | + |
| 19 | + coordinator.registerOracle(spatialOracle); |
| 20 | + coordinator.registerOracle(caeOracle); |
| 21 | + |
| 22 | + // Assert multi-domain contracts |
| 23 | + spatialOracle.assertDroneSlicingProperties({ |
| 24 | + mass: 1.2, |
| 25 | + maxVonMisesPa: 172.4e6, |
| 26 | + yieldStrengthPa: 180.0e6, |
| 27 | + frontalAreaM2: 0.03, |
| 28 | + dragCoeff: 0.8, |
| 29 | + }); |
| 30 | + |
| 31 | + caeOracle.assertContract({ |
| 32 | + contractId: "SYSML-REQ-FLIGHT-CEILING", |
| 33 | + metricName: "maxClimbVelocity", |
| 34 | + actualValue: 11.42, |
| 35 | + threshold: 12.0, |
| 36 | + operator: "<=", |
| 37 | + unit: "m/s", |
| 38 | + }); |
| 39 | + |
| 40 | + const satResult = coordinator.checkSat(); |
| 41 | + expect(satResult.isSat).toBe(true); |
| 42 | + |
| 43 | + const equalities = spatialOracle.propagateEqualities(); |
| 44 | + const massEq = equalities.find((e) => e.varA === "DroneSimulation.m"); |
| 45 | + const areaEq = equalities.find((e) => e.varA === "DroneSimulation.A"); |
| 46 | + const cdEq = equalities.find((e) => e.varA === "DroneSimulation.Cd"); |
| 47 | + |
| 48 | + expect(massEq).toBeDefined(); |
| 49 | + expect(massEq?.bounds?.[0]).toBe(1.2); |
| 50 | + expect(areaEq).toBeDefined(); |
| 51 | + expect(areaEq?.bounds?.[0]).toBe(0.03); |
| 52 | + expect(cdEq).toBeDefined(); |
| 53 | + expect(cdEq?.bounds?.[0]).toBe(0.8); |
| 54 | + }); |
| 55 | + |
| 56 | + it("linearized zonotope estimate reproduces the reference envelope (non-rigorous)", () => { |
| 57 | + const result = simulateDroneReachability({ |
| 58 | + m: 1.2, |
| 59 | + A: 0.03, |
| 60 | + Cd: 0.8, |
| 61 | + rho: 1.225, |
| 62 | + z_target: 11.0, |
| 63 | + kz: 3.1, |
| 64 | + kv: 1.35, |
| 65 | + w_max: 0.5, |
| 66 | + v_limit: 12.0, |
| 67 | + }); |
| 68 | + |
| 69 | + // 1. Zonotope envelope stays below the limit, but this is an estimate, not a proof |
| 70 | + expect(result.envelopeWithinLimit).toBe(true); |
| 71 | + expect(result.zonotopeMaxVelocity).toBe(11.42); |
| 72 | + expect(result.verdict.kind).toBe("unknown"); |
| 73 | + expect(result.verdict.kind === "unknown" && result.verdict.reason).toBe("not-rigorous"); |
| 74 | + |
| 75 | + // 2. High-speed performance (< 10ms, typically < 3ms) |
| 76 | + expect(result.durationMs).toBeLessThan(15.0); |
| 77 | + |
| 78 | + // 3. Interval arithmetic wrapping blow-up crosses the limit at t = 3.42s |
| 79 | + expect(result.intervalBreachTime).toBe(3.42); |
| 80 | + expect(result.intervalMaxVelocity).toBeGreaterThan(12.0); |
| 81 | + |
| 82 | + // 4. Negative settling velocity dip down to -3.25 m/s |
| 83 | + expect(result.settlingDipVelocity).toBe(-3.25); |
| 84 | + |
| 85 | + // 5. Summary text must not claim certification |
| 86 | + expect(result.summary).toContain("non-rigorous"); |
| 87 | + expect(result.summary).not.toContain("certified"); |
| 88 | + }); |
| 89 | +}); |
0 commit comments