Handle empty public API baseline snapshots - #4609
Conversation
|
Warning Review limit reachedNext included review available in 27 minutes. View limit detailsLimit details: You’ve used all 4 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe merge script now filters empty baseline lines and uses typed collections for deduplication, sorting, comparison, and output. Tests now validate case-sensitive line matching and empty input baselines. ChangesBaseline merge handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to Baseline snapshot merging now treats empty valid input files as empty collections and verifies empty outputs without changing the intended populated-file behavior. The change is ready to merge with no identified current risk. Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code review
Reviewed the changes to Merge-PublicApiBaselineSnapshot.ps1 and its test script for issue #4608 (empty public API baseline handling).
Verification performed:
- Checked out both the base commit (
f592a963) and the PR head (8ab0fbdd) and ran the merge script directly against four empty input files.- Base commit: reproduces the exact crash from #4608 —
Where-Object: You cannot call a method on a null-valued expressionat theStartsWithcall inGet-ApiEntries. This confirms the classic PowerShell gotcha where a function thatreturn @(pipeline)s zero elements collapses to$nullfor the caller, so$Linesbecomes$nullinstead of an empty array, and piping$nullinvokes theWhere-Objectpredicate once with$_ = $null. - PR head: no longer crashes. The
-not [string]::IsNullOrEmpty($_) -and ...guard added toGet-Headers/Get-ApiEntriescorrectly short-circuits beforeStartsWithis reached when$_is$null.
- Base commit: reproduces the exact crash from #4608 —
- Ran
Test-MergePublicApiBaselineSnapshot.ps1from the PR branch: passes, including the new fully-empty-inputs case, and the pre-existing additive/removal/idempotency assertions still pass unchanged, so populated-file behavior is preserved. - Traced the
Write-Baselinerewrite: switching from@($Headers) + $sortedEntries/@(if(...) {Get-Content...})to explicitforeachloops withIsNullOrEmptyfiltering avoids the same null/array-collapse hazard that previously existed there too (e.g.,@($null)producing a one-element array containing$null), and theHashSetis now built by iterating rather than passed a possibly-null collection to the constructor, avoiding a potentialArgumentNullException.
Assessment: the fix directly addresses the root cause described in #4608 rather than papering over a symptom, ordering/idempotency (via the existing-vs-lines comparison before writing) is preserved, and the added test meaningfully exercises the regression (all four empty inputs, verified against actual empty output). No CLAUDE.md concerns apply to this change (PowerShell tooling scripts, no dotnet build/test pipeline involved). No actionable issues found.
CodeFactor flagged PSAvoidAssignmentToAutomaticVariable for `$matches` in Test-MergePublicApiBaselineSnapshot.ps1. Rename to `$isMatch`. Refs #4608 Claude-Session: https://claude.ai/code/session_01MGEyXW2HYJpJ47tqnpjWMa
Code reviewThis PR was previously reviewed at commit What changed in the new commit: in Re-verified for this delta:
No CLAUDE.md concerns apply (PowerShell tooling scripts, not part of the dotnet build/test pipeline or generated-options code). No actionable issues found on this new commit. |
|
Synced current |
Review: #4609 — Handle empty public API baseline snapshotsThis PR hardens Finding: the new "empty inputs" test doesn't exercise the case it claims to cover
$existing = [System.Collections.Generic.List[string]]::new()
if (Test-Path -LiteralPath $Path -PathType Leaf) {
foreach ($line in Get-Content -LiteralPath $Path) { $existing.Add($line) }
}
if ([System.Linq.Enumerable]::SequenceEqual($existing, $lines, $comparer)) {
return # <-- also hit when $Path doesn't exist yet and $lines is empty
}If The PR's summary says it now covers "fully empty shipped, unshipped, snapshot, and confirmed-removal files," and In practice this is currently unreachable: the sole production caller, Suggested fix: in Not a regression introduced by this PR (the same early-return-on-SequenceEqual structure existed in the prior version too) and not currently reachable in the real pipeline, so this is a robustness/test-coverage gap rather than a live bug — but worth closing given the PR explicitly calls out empty-file handling as its purpose. |
Write-Baseline only skips writing when the target already holds the same content; a missing target is always created, so empty inputs no longer leave the caller without an output file. The empty-input test now uses fresh output paths so it covers that case. Claude-Session: https://claude.ai/code/session_01EHe9J8SumuZb2NBZxpGBzc
|
Addressed the review finding at exact head |
|
Synced current |
Review: #4609 — Handle empty public API baseline snapshotsThis is a follow-up revision after two prior review rounds on this PR. Both previously flagged issues have been addressed:
I traced the dedup/sort/promotion logic in the main script body (shipped ↔ unshipped promotion, `REMOVED` handling, reintroduction) against the new empty-input test case and the pre-existing populated-file test case — both check out, and this logic itself is unchanged by this PR (only the header/entry filtering and the write helper were touched). No actionable issues found. Nice, tight fix scoped to the actual defect, and the new test now genuinely covers the create-vs-truncate distinction that was missing before. |
Keeps both sides of Test-MergePublicApiBaselineSnapshot.ps1: the no-confirmed-removals case from this branch runs on the original inputs first, then the empty-input cases from #4609. Claude-Session: https://claude.ai/code/session_01PkLNTUfwGXjqXZrYrHaDGC
Summary
Validation
Test-MergePublicApiBaselineSnapshot.ps1Test-SyncPublicApiBaselines.ps1Closes #4608
Summary by CodeRabbit
Bug Fixes
Tests