freepdfeditor/spike/common/SpikeRunner.h

38 lines
1.4 KiB
C++

// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2025 ai-ad4 and the FreePDFEditor contributors
//
// SpikeRunner — tiny helper that each Spike A/E main() uses to emit a
// machine-readable JSON report and a process exit code matching the spike's
// acceptance gate. Keeping this in one place means CI just parses one format.
#ifndef FREEPDFEDITOR_SPIKE_COMMON_SPIKERUNNER_H
#define FREEPDFEDITOR_SPIKE_COMMON_SPIKERUNNER_H
#include <cstdint>
#include <string>
#include <vector>
namespace freepdfeditor::spike {
struct SpikeResult {
std::string spike; // "A", "B", ...
std::string name; // human-readable
std::size_t total = 0; // files/pages examined
std::size_t passed = 0; // met the gate
std::size_t failed = 0;
std::size_t errored = 0; // crashed / could not process
std::vector<std::string> failed_samples; // up to N sample ids for triage
std::string metric_name; // e.g. "byte_identical_rate", "F1"
double metric_value = 0.0; // aggregate metric
double target = 0.0; // gate threshold
bool gate_met = false;
std::string notes;
};
// Serialise `result` as a single-line JSON document on stdout, then return the
// process exit code (0 if gate_met, 1 otherwise). CI parses this line.
int emit_json_report(const SpikeResult& result);
} // namespace freepdfeditor::spike
#endif // FREEPDFEDITOR_SPIKE_COMMON_SPIKERUNNER_H