import 'dart:convert'; import 'package:pipe/pipe.dart'; import 'package:test/test.dart'; /// The state-map seam: rules read only the model, so a model that went through /// JSON - as one written by a separate front end would - must produce exactly /// the same report as the in-process model. If a rule quietly depended on /// something the JSON does not carry, this is where it shows. void main() { late ProjectAnalysis analysis; setUpAll(() async { analysis = await analyzeProject( await loadProject('test/fixtures/stuck_loading'), concurrency: 1, ); }); tearDownAll(() async { await analysis.dispose(); }); StateFlow throughJson(StateFlow flow) => stateFlowFromJson( jsonDecode(jsonEncode(flow.toJson())) as Map, ); test('the model survives JSON unchanged', () { final once = jsonEncode(analysis.flow.toJson()); final twice = jsonEncode(throughJson(analysis.flow).toJson()); expect(twice, once); }); test('rules on the decoded model report exactly the same findings', () { final direct = jsonEncode(runChecks(flow: analysis.flow).toJson()); final decoded = jsonEncode( runChecks(flow: throughJson(analysis.flow)).toJson(), ); expect(decoded, direct); // Not vacuous: every rule fires somewhere on the fixture. final rules = runChecks(flow: analysis.flow).findings.map((f) => f.rule); expect(rules.toSet(), containsAll(allRules)); }); }