Skip to content

Commit 2d3f4b6

Browse files
committed
fix(qa-coverage): only write the coverage file when material content changed
The script was bumping generated.at on every run, which left qa-coverage.json dirty in the working tree after every pre-commit hook fire. Each subsequent commit then started with an immediately-modified file even when nothing in coverage actually changed. Fix: compare the new summary to the existing one before writing. When items_total / items_covered / items_uncovered / items_skipped are all identical, skip the write and carry the existing timestamp + drift entry forward. The working tree settles after the first run.
1 parent b35f631 commit 2d3f4b6

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

bin/qa-coverage-check.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,37 @@
137137
// 5. Persist + report.
138138
// ─────────────────────────────────────────────────────────
139139

140-
file_put_contents(
141-
$coverage,
142-
json_encode( $result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) . "\n"
143-
);
140+
// Only write when something other than `generated.at` changed.
141+
// Otherwise every commit dirties qa-coverage.json with a fresh timestamp
142+
// and the working tree never settles.
143+
$should_write = true;
144+
if ( is_file( $coverage ) ) {
145+
$existing = json_decode( (string) file_get_contents( $coverage ), true );
146+
if ( is_array( $existing ) ) {
147+
$existing_summary = $existing['summary'] ?? array();
148+
$current_summary = $result['summary'];
149+
$material_unchanged = (
150+
( $existing_summary['items_total'] ?? null ) === $current_summary['items_total']
151+
&& ( $existing_summary['items_covered'] ?? null ) === $current_summary['items_covered']
152+
&& ( $existing_summary['items_uncovered'] ?? null ) === $current_summary['items_uncovered']
153+
&& ( $existing_summary['items_skipped'] ?? null ) === $current_summary['items_skipped']
154+
);
155+
if ( $material_unchanged ) {
156+
$should_write = false;
157+
// Carry the existing generated.at + drift forward so subsequent
158+
// runs still see a stable baseline.
159+
$result['generated']['at'] = $existing['generated']['at'] ?? $result['generated']['at'];
160+
$result['drift'] = $existing['drift'] ?? $result['drift'];
161+
}
162+
}
163+
}
164+
165+
if ( $should_write ) {
166+
file_put_contents(
167+
$coverage,
168+
json_encode( $result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) . "\n"
169+
);
170+
}
144171

145172
print_human_summary( $result, $opts );
146173

0 commit comments

Comments
 (0)