import 'package:pipelines_app/core/api_gateway.dart'; /// Opt-in (`?usage=1`) size and reported token usage for the capture /// fixture's runs, shaped exactly as the server sends them: a run-level /// `usage` total (list and detail) and a per-step `usage`. Without the /// parameter the fixture keeps the old-server shape with neither. bool probeUsage = false; /// Per-step usage of run 7, by recorded sequence. The build visit is mostly /// cache reads, as a caching harness reports; plan 1 predates the cache split. const _stepUsage = { 5: { 'tokens_total': 1200000, 'tokens_known': true, 'split_known': true, 'tokens_in': 300000, 'tokens_out': 60000, 'tokens_reasoning': 40000, 'cache_read': 780000, 'cache_write': 20000, 'cache_known': true, 'cost_known': true, }, 2: { 'tokens_total': 20100000, 'tokens_known': true, 'split_known': true, 'tokens_in': 500000, 'tokens_out': 80000, 'tokens_reasoning': 20000, 'cache_read': 19480000, 'cache_write': 20000, 'cache_known': true, 'cost_usd': 1.42, 'cost_known': true, }, 1: { 'tokens_total': 1100000, 'tokens_known': true, 'split_known': true, 'tokens_in': 1000000, 'tokens_out': 100000, 'cache_known': true, 'cache_read': 0, 'cost_known': true, }, }; /// Run 7's total over [_stepUsage], as the server's aggregate sums it. const _run7Usage = { 'stages': 3, 'tokens_total': 22400000, 'tokens_known_stages': 3, 'split_known': true, 'tokens_in': 1800000, 'tokens_out': 240000, 'tokens_reasoning': 60000, 'cache_read': 20260000, 'cache_write': 40000, 'cache_known': true, 'cache_known_stages': 3, 'cost_usd': 1.42, 'cost_known_stages': 3, }; /// Run 6: one of its two stages reported no token count, so its total is a /// lower bound; no stage reported a positive cost. const _run6Usage = { 'stages': 2, 'tokens_total': 9100000, 'tokens_known_stages': 1, 'split_known': false, 'split_unknown_stages': 1, 'cost_known_stages': 1, 'cost_unknown_stages': 1, }; /// Adds the run's size and usage to a list row or detail when enabled. JsonMap withProbeUsage(JsonMap run) { if (!probeUsage) return run; return switch (run['id']) { 7 => {...run, 'size_bytes': 340 * 1024 * 1024, 'usage': _run7Usage}, 6 => {...run, 'size_bytes': 4404019, 'usage': _run6Usage}, _ => run, }; } /// Adds the recorded per-step usage to run 7's steps when enabled. JsonMap withProbeStepUsage(JsonMap step) { final usage = _stepUsage[step['sequence']]; return probeUsage && usage != null ? {...step, 'usage': usage} : step; }