import 'package:flutter_test/flutter_test.dart'; import 'package:miler/data/geofence.dart'; /// ───────────────────────────────────────────────────────────────────────── /// THE SWITCH, AND THE FOUR SHAPES THAT MUST NOT COME BACK /// /// This file used to assert the opposite of what it asserts now, and that is /// the point of keeping it rather than deleting it. /// /// It read: /// /// expect(kGeofenceEnforced, isFalse); // "recorded decision", 2026-08-25 /// expect(kGeofenceRadiusMeters, 10); /// /// So the test suite was **enforcing the release blocker**: a developer who /// turned the fence on to fix it would be met with a red test telling him the /// off state was deliberate. Between them those two lines meant every shipped /// build let a rider mark a stop picked up from anywhere on earth, and the /// suite agreed that was correct. /// /// Reversed 2026-09-16 as part of the Play Store release audit. The fence now /// lives in `lib/data/geofence.dart` and the behaviour is exercised properly in /// `geofence_test.dart` — 41 cases, the full distance table, every failure /// mode, and an HTTP client that fails the test if a blocked rung posts /// anything. /// /// What is left here is the short list of *specific past mistakes*, each of /// which shipped, so that none of them can return quietly. /// ───────────────────────────────────────────────────────────────────────── void main() { test('MISTAKE 1 — the fence must not default to off', () { // `bool.fromEnvironment('ENFORCE_GEOFENCE', defaultValue: false)`. Every // `flutter build appbundle --release` passes no dart-define, so the default // *is* the shipped behaviour. It had been `kDebugMode` before that — off in // exactly the builds anyone tested with — and a hard `false` before that. // Three spellings, one effect. expect( kGeofenceEnforced, isTrue, reason: 'The release build must enforce proximity. If this run passed ' '--dart-define=ENFORCE_GEOFENCE=false, this failure is correct.', ); }); test('MISTAKE 2 — the radius must not be smaller than the GPS', () { // 10 m is at or inside the error radius of consumer GPS, so the fence // stopped measuring proximity and started measuring whether the satellites // were kind. It refused riders standing at doors, which is what got the // whole control switched off twice. expect(kGeofenceRadiusMetres, 100); expect( kGeofenceRadiusMetres, greaterThan(kGeofenceMaxAccuracyMetres), reason: 'a fence smaller than the fix that measures it cannot be met', ); }); test('MISTAKE 3 — there must be exactly one radius', () { // The app once held three at the same time: a per-tenant `pickupradius` // from prefs defaulting to 100, a hardcoded 500 in Home's bulk gate, and 10 // in the controller. Which fence a rider met depended on whether he ticked // boxes on Home or slid the sheet on a stop. // // Both gates call `Geofence.check` now and neither holds arithmetic, so // this asserts the constant is the only knob there is to turn. expect(kGeofenceRadiusMetres, isA()); expect(kGeofenceRadiusMetres, greaterThan(0)); }); test('MISTAKE 4 — a cached fix must have a shelf life', () { // A last-known position is instant, free, and can be an hour old. On a // round it is reliably the *previous* stop, which is how a rider marks a // delivery arrived from the last street he was on. expect(kGeofenceFixMaxAge, const Duration(seconds: 30)); }); test('the fence still has a way to be switched off in an emergency', () { // Deliberately kept, and deliberately not the default. If the fence starts // refusing real work at real doors, `--dart-define=ENFORCE_GEOFENCE=false` // gets the fleet moving inside one release rather than one sprint — and // every bypassed check logs in every build mode, so a build's own log says // which way it was compiled. // // Raise `kGeofenceRadiusMetres` before reaching for it. expect( const bool.fromEnvironment('ENFORCE_GEOFENCE', defaultValue: true), kGeofenceEnforced, ); }); }