fix(scripts): preserve manual NOTES block in incremental report generator#1119
fix(scripts): preserve manual NOTES block in incremental report generator#1119carlos-alm wants to merge 2 commits into
Conversation
…ator scripts/update-incremental-report.ts regenerates the report from scratch on every release. PR #1008 added a manual <!-- NOTES_START --> ... <!-- NOTES_END --> block explaining why 3.9.5 had null build metrics, but the 3.9.6 release silently dropped it because the script had no awareness of the sentinel pair. The version-history table now jumps 3.9.4 → 3.9.6 with no explanation. Extract any NOTES block from the existing file (mirroring how INCREMENTAL_BENCHMARK_DATA is preserved) and re-emit it just before the data comment in the regenerated markdown. Restore the lost 3.9.5 note and add a regression test gated on the env-overridable report path. Closes #1042
|
Claude finished @carlos-alm's task —— View job PR Review: Incremental Report NOTES PreservationRoot Cause AnalysisProblem Being Solved: The Why This Approach: The fix properly mirrors the existing pattern used for preserving Risk Assessment: LOW RISK - This is a targeted fix to a specific data loss issue. The changes are additive and follow existing patterns. Backlog Compliance
Code Quality AssessmentChanges Analysis:
Security & Performance:
Minor Observations:
Final Recommendation
|
Greptile SummaryThis PR fixes a silent data-loss bug in
Confidence Score: 5/5This PR is safe to merge — the change is narrow, well-tested, and purely additive to an internal report-generation script. The core logic (matchAll extraction + conditional re-emit) is straightforward and directly tested by three focused regression cases. The env-var path override cleanly isolates tests from the real file. No existing behaviour is altered for the non-notes path, and the restored markdown note is a documentation-only change. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Read reportPath via CODEGRAPH_INCREMENTAL_REPORT_PATH\nor default path] --> B{File exists?}
B -- No --> D[history = empty\nnotesBlock = empty string]
B -- Yes --> C[Read file content]
C --> E[Extract INCREMENTAL_BENCHMARK_DATA JSON\ninto history array]
C --> F[matchAll NOTES_START…NOTES_END blocks\njoin with blank lines into notesBlock]
E --> G[Prepend new entry to history]
F --> G
D --> G
G --> H[Build markdown: header + version table\n+ Latest results section]
H --> I{notesBlock non-empty?}
I -- Yes --> J[Append notesBlock]
I -- No --> K[Skip]
J --> L[Append INCREMENTAL_BENCHMARK_DATA comment]
K --> L
L --> M[Write file to reportPath]
Reviews (3): Last reviewed commit: "fix(scripts): preserve all NOTES blocks ..." | Re-trigger Greptile |
| const notesMatch = content.match(/<!--\s*NOTES_START\s*-->[\s\S]*?<!--\s*NOTES_END\s*-->/); | ||
| if (notesMatch) notesBlock = notesMatch[0]; |
There was a problem hiding this comment.
Only first NOTES block is silently preserved
.match() returns the first regex match, so if a second <!-- NOTES_START --> ... <!-- NOTES_END --> block is ever added (e.g. to annotate a different anomalous release), it would be silently dropped the next time the script runs. This mirrors a real data-loss scenario: the PR itself was created specifically because a block was silently dropped once before. Consider using .matchAll() and concatenating all matched blocks, or at least documenting the single-block constraint as a comment near this code.
There was a problem hiding this comment.
Fixed in d1623f6 — switched to matchAll() and join all matched blocks with blank lines, so any number of NOTES_START/NOTES_END blocks survive regeneration. Added a regression test covering two distinct NOTES blocks (both delimiter pairs preserved, both body texts present after roundtrip).
If multiple NOTES_START/NOTES_END blocks are added to annotate different anomalous releases, .match() silently dropped all but the first — the same data-loss class this PR was created to prevent. Switch to .matchAll() and join with blank lines so every block survives regeneration. Add a test covering two distinct NOTES blocks.
Summary
scripts/update-incremental-report.tsregeneratesgenerated/benchmarks/INCREMENTAL-BENCHMARKS.mdfrom scratch on every release, which silently dropped the manual<!-- NOTES_START --> ... <!-- NOTES_END -->block PR docs: update incremental benchmarks (3.9.5) #1008 added to explain why 3.9.5 hasnullbuild metrics. After 3.9.6, the version-history table jumped 3.9.4 → 3.9.6 with no context.NOTES_START/NOTES_ENDblock from the existing file (mirroring howINCREMENTAL_BENCHMARK_DATAis preserved) and re-emit it just before the data comment in the regenerated markdown.tests/unit/update-incremental-report.test.ts, gated on a newCODEGRAPH_INCREMENTAL_REPORT_PATHenv override so the script can target a temp file from tests.Closes #1042
Test plan
npx vitest run tests/unit/update-incremental-report.test.ts— both cases pass (NOTES preserved on roundtrip, no spurious NOTES when absent)npm run lint— no new errors