-
Notifications
You must be signed in to change notification settings - Fork 11
fix(scripts): preserve manual NOTES block in incremental report generator #1119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3b0bf70
fix(scripts): preserve manual NOTES block in incremental report gener…
carlos-alm d1623f6
fix(scripts): preserve all NOTES blocks via matchAll (#1119)
carlos-alm 934893d
Merge branch 'main' into fix/incremental-report-preserve-notes
carlos-alm acc916f
Merge branch 'main' into fix/incremental-report-preserve-notes
carlos-alm 86e0535
Merge branch 'main' into fix/incremental-report-preserve-notes
carlos-alm 83cbc77
Merge branch 'main' into fix/incremental-report-preserve-notes
carlos-alm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { execFileSync } from 'node:child_process'; | ||
| import fs from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
| const repoRoot = path.resolve(__dirname, '..', '..'); | ||
| const scriptPath = path.join(repoRoot, 'scripts', 'update-incremental-report.ts'); | ||
|
|
||
| // --experimental-strip-types works in Node 22.6+ through current 24.x; the | ||
| // renamed --strip-types was added then removed again across 24.x minor | ||
| // versions, so prefer the experimental name for compatibility. | ||
| const stripFlag = '--experimental-strip-types'; | ||
|
|
||
| const SAMPLE_ENTRY = { | ||
| version: '9.9.9', | ||
| date: '2026-05-14', | ||
| files: 100, | ||
| wasm: { fullBuildMs: 1000, noopRebuildMs: 10, oneFileRebuildMs: 50 }, | ||
| native: { fullBuildMs: 500, noopRebuildMs: 5, oneFileRebuildMs: 25 }, | ||
| resolve: { | ||
| imports: 200, | ||
| nativeBatchMs: 2, | ||
| jsFallbackMs: 4, | ||
| perImportNativeMs: 0, | ||
| perImportJsMs: 0, | ||
| }, | ||
| }; | ||
|
|
||
| let tmpDir: string; | ||
| let reportPath: string; | ||
| let entryPath: string; | ||
|
|
||
| beforeEach(() => { | ||
| tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-incr-report-')); | ||
| reportPath = path.join(tmpDir, 'INCREMENTAL-BENCHMARKS.md'); | ||
| entryPath = path.join(tmpDir, 'entry.json'); | ||
| fs.writeFileSync(entryPath, JSON.stringify(SAMPLE_ENTRY)); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| if (tmpDir) fs.rmSync(tmpDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| function runScript() { | ||
| execFileSync('node', [stripFlag, scriptPath, entryPath], { | ||
| env: { ...process.env, CODEGRAPH_INCREMENTAL_REPORT_PATH: reportPath }, | ||
| stdio: 'pipe', | ||
| }); | ||
| } | ||
|
|
||
| describe('update-incremental-report script', () => { | ||
| it('preserves a manual NOTES_START/NOTES_END block across regeneration', () => { | ||
| const NOTES = `<!-- NOTES_START --> | ||
| **Note (9.9.8):** Workers hung past the 10-minute timeout and were SIGKILL'd. | ||
| <!-- NOTES_END -->`; | ||
| const initial = `# Codegraph Incremental Build Benchmarks | ||
|
|
||
| ${NOTES} | ||
|
|
||
| <!-- INCREMENTAL_BENCHMARK_DATA | ||
| [ | ||
| { | ||
| "version": "9.9.8", | ||
| "date": "2026-05-01", | ||
| "files": 99, | ||
| "wasm": null, | ||
| "native": null, | ||
| "resolve": { "imports": 100, "nativeBatchMs": 1, "jsFallbackMs": 2, "perImportNativeMs": 0, "perImportJsMs": 0 } | ||
| } | ||
| ] | ||
| --> | ||
| `; | ||
| fs.writeFileSync(reportPath, initial); | ||
|
|
||
| runScript(); | ||
|
|
||
| const out = fs.readFileSync(reportPath, 'utf8'); | ||
| expect(out).toContain('<!-- NOTES_START -->'); | ||
| expect(out).toContain('<!-- NOTES_END -->'); | ||
| expect(out).toContain("Workers hung past the 10-minute timeout and were SIGKILL'd"); | ||
| // Notes should appear before the data comment, after the latest summary | ||
| expect(out.indexOf('<!-- NOTES_START -->')).toBeLessThan( | ||
| out.indexOf('<!-- INCREMENTAL_BENCHMARK_DATA'), | ||
| ); | ||
| }); | ||
|
|
||
| it('does not invent a NOTES block when none was present', () => { | ||
| const initial = `# Codegraph Incremental Build Benchmarks | ||
|
|
||
| <!-- INCREMENTAL_BENCHMARK_DATA | ||
| [] | ||
| --> | ||
| `; | ||
| fs.writeFileSync(reportPath, initial); | ||
|
|
||
| runScript(); | ||
|
|
||
| const out = fs.readFileSync(reportPath, 'utf8'); | ||
| expect(out).not.toContain('NOTES_START'); | ||
| expect(out).not.toContain('NOTES_END'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in d1623f6 — switched to
matchAll()and join all matched blocks with blank lines, so any number ofNOTES_START/NOTES_ENDblocks survive regeneration. Added a regression test covering two distinct NOTES blocks (both delimiter pairs preserved, both body texts present after roundtrip).