resolveRunSpillsConfig function

SpillsConfig? resolveRunSpillsConfig(
  1. SpillsConfig? section,
  2. Map<String, String> env
)

Resolves the run's spills config from the yaml section (null when the config files carry no spills:) plus the env knob (spillThresholdEnvVar). Pure:

  • section absent + env unset → null — the hook is never attached, the byte-identical legacy shape (issue #678 AC1);
  • env set to a positive int → enabled with THAT threshold (env wins over the configured threshold; preview bounds stay the defaults). The section's SpillsConfig.notes survive the composition — the tolerant-parse diagnostics a bench run debugging its config needs;
  • env 0 → explicitly disabled for this run;
  • env junk → ignored (the section applies untouched; junk never breaks a boot).

Implementation

SpillsConfig? resolveRunSpillsConfig(
  SpillsConfig? section,
  Map<String, String> env,
) {
  final value = int.tryParse(env[spillThresholdEnvVar]?.trim() ?? '');
  if (value == null) return section;
  if (value <= 0) return const SpillsConfig(enabled: false);
  final base = section ?? const SpillsConfig();
  return SpillsConfig(
    enabled: true,
    threshold: value,
    headChars: base.headChars,
    tailChars: base.tailChars,
    notes: base.notes,
  );
}