//! The audit recorder, for checking a new contract against every caller the tests have: in a
//! build with the `param-audit` feature, when `SOLIDCRAFT_PARAM_AUDIT` names a directory, every
//! call to a command with a contract that breaks it is recorded, with what the command did, so a
//! test run shows which callers the contracts would warn about or refuse. Without the feature it
//! is compiled (so it is linted and tested) but never on.
//!
//! ```text
//! SOLIDCRAFT_PARAM_AUDIT=$PWD/audit cargo test --workspace --no-fail-fast --features solidcraft-engine/param-audit
//! python3 scripts/param_audit.py audit
//! ```
//!
//! A line whose outcome is `ok` is a call that works today and that strict would refuse: a form
//! the contract is missing, or a mistake the handler silently ignores.
//!
//! Records are aggregated per process by signature (command, issues, outcome, test thread) and
//! written to `
/audit-.jsonl` when a signature is first seen and again each time its
//! count reaches a power of two; readers keep the highest `count` per signature in each file
//! and add the files up. A process keeps at most 4096 signatures and counts later new ones
//! under one `dropped` line. Writing never fails a command.
use std::collections::HashMap;
use std::io::Write;
use std::path::PathBuf;
use std::sync::{Mutex, OnceLock};
use serde_json::{Value, json};
use super::check::{Issue, truncate};
use crate::Result;
static DIR: OnceLock