You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement end-to-end formal verification of core safety properties using TLA+ model checking, property-based testing, and runtime assertion monitoring #250
10/10 — Expert. Estimated effort: 8–12 days for a senior engineer.
Context
The gateway handles safety-critical operations: geofence enforcement (preventing unauthorized entry to hazardous zones), collision avoidance (proximity alerts), and regulatory compliance (ELD mandates). A single correctness bug — message reordering, duplicate processing, state machine violation — can cause a vessel to enter a restricted zone undetected, a collision warning to be suppressed, or an audit trail to be corrupted. The current test suite (166+ tests) covers functional behavior but cannot prove absence of race conditions, liveness violations, or invariant violations under all possible interleavings.
Problem statement
Establish a formal verification framework that:
TLA+ specification of core protocols: Write a TLA+ spec (spec/gateway.tla) modeling:
Room membership state machine (join, leave, disconnect, crash).
Message sequencing and replay (issue 6).
Exactly-once delivery with ACKs (issue 16).
Geofence entry/exit state transitions (issue 12).
Session resumption (issue 18).
Distributed CRDT convergence (issue 24).
Model check with TLC for: Safety (no duplicate deliveries, no lost messages, geofence state consistency), Liveness (every message eventually delivered or nacked, every client eventually reconnects), Invariants (sequence numbers monotonic, room membership matches broadcast targets).
Property-based testing with fast-check: For each TypeScript module, define generators and properties:
Violations log structured error + increment metric assertion_violation_total{component, invariant} — do NOT crash (fail-open for availability).
Contract testing for cross-module boundaries:
server.js ↔ room-manager.js: contract test that every broadcast call matches expected signature and side effects.
geofence-engine ↔ storage: contract that upsertFence persists all vertices.
Use pact or custom contract runner.
Mutation testing: Run stryker or custom mutator on core modules (room-manager, validator, rate-limiter, geofence-engine, predictor, crdt). Target: ≥ 90% mutation score. Mutants that survive must be documented as false positives or added as regression tests.
Chaos engineering integration:
ChaosMonkey class injects faults in test environment: network partition (drop messages), clock skew (±5s), process crash (kill -9), Redis failover.
Verify safety properties hold under chaos: no duplicate geofence alerts, no message loss beyond acknowledged window.
CI/CD integration:
npm run verify:tla — runs TLC model checker (must pass).
npm run verify:property — runs fast-check (must pass).
npm run verify:mutation — runs stryker (must meet threshold).
npm run verify:chaos — runs chaos tests (must pass).
Difficulty
10/10 — Expert. Estimated effort: 8–12 days for a senior engineer.
Context
The gateway handles safety-critical operations: geofence enforcement (preventing unauthorized entry to hazardous zones), collision avoidance (proximity alerts), and regulatory compliance (ELD mandates). A single correctness bug — message reordering, duplicate processing, state machine violation — can cause a vessel to enter a restricted zone undetected, a collision warning to be suppressed, or an audit trail to be corrupted. The current test suite (166+ tests) covers functional behavior but cannot prove absence of race conditions, liveness violations, or invariant violations under all possible interleavings.
Problem statement
Establish a formal verification framework that:
TLA+ specification of core protocols: Write a TLA+ spec (
spec/gateway.tla) modeling:Property-based testing with fast-check: For each TypeScript module, define generators and properties:
RoomManager:join/leave/disconnectpreserves∀c,r: c∈r.members ⇔ r∈c.rooms.RateLimiter:checknever allows > limit in window;cleanupremoves only expired.Predictor: Kalman filter covariancePremains positive semi-definite.CRDTs:merge(a, merge(b, c)) = merge(merge(a, b), c)(associativity),merge(a, b) = merge(b, a)(commutativity),merge(a, a) = a(idempotence).Runtime assertion monitoring: Instrument production code with
assert()checks for critical invariants (enabled viaNODE_ENV=production):roomManager.broadcast:assert(message.seq === roomSeq + 1).sessionManager.load:assert(decrypted.clientId === authenticatedClientId).geofenceEngine.processLocationUpdate:assert(newInsideSet ⊆ allFences ∪ oldInsideSet)(no spontaneous entries).predictor.update:assert(P.isPositiveSemiDefinite()).assertion_violation_total{component, invariant}— do NOT crash (fail-open for availability).Contract testing for cross-module boundaries:
server.js↔room-manager.js: contract test that everybroadcastcall matches expected signature and side effects.geofence-engine↔storage: contract thatupsertFencepersists all vertices.pactor custom contract runner.Mutation testing: Run
strykeror custom mutator on core modules (room-manager,validator,rate-limiter,geofence-engine,predictor,crdt). Target: ≥ 90% mutation score. Mutants that survive must be documented as false positives or added as regression tests.Chaos engineering integration:
ChaosMonkeyclass injects faults in test environment: network partition (drop messages), clock skew (±5s), process crash (kill -9), Redis failover.CI/CD integration:
npm run verify:tla— runs TLC model checker (must pass).npm run verify:property— runs fast-check (must pass).npm run verify:mutation— runs stryker (must meet threshold).npm run verify:chaos— runs chaos tests (must pass).Current behavior
tests/*.test.js: example-based unit/integration tests only.Required behavior
spec/gateway.tla— TLA+ specification of core protocols.spec/README.md— how to run TLC, interpret results.tests/property/*.test.js— fast-check properties for each module.src/assertions.js— runtime assertion helpers, enabled viaASSERTIONS_ENABLED=true.tests/contract/*.test.js— contract tests for module boundaries.tests/chaos/*.test.js— chaos monkey tests.package.jsonscripts:verify:tla,verify:property,verify:mutation,verify:chaos,verify:all..github/workflows/verify.ymlrunning all verification steps.Constraints
auth.js,validator.js,rate-limiter.js,conn-rate-limiter.js,logger.js,errors.js,room-manager.js,geofence-engine.js,protocol-registry.js,distributed-room-manager.js,tls-manager.js,admin-server.js,session-manager.js,compression.js,topology-manager.js,event-sourcing.js,collaborative-editor.js,predictor.js,multi-region.js.fast-check,stryker(ormutation-testing),tla2tools(TLC) to devDependencies.Acceptance criteria
room-manager,validator,rate-limiter,geofence-engine,predictor,crdtnpm run verify:allpasses in CInpm run lintpassesspec/,tests/property/,tests/contract/,tests/chaos/Out of scope
Hints and references
npx stryker run --mutate "src/room-manager.js,src/validator.js,..."ws.sendcalls, delaysetTimeout, kill process mid-test.