You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Part of #4737 (parent epic — deterministic tier, REES foundation). Prerequisite
for the complexity-delta and duplication-delta sub-issues.
The problem
REES (review-enrichment/) analyzers normally see only diff hunks, not full before/after file content —
that's why complexity.ts and coverage-delta.ts both explicitly disclaim being true before/after
deltas in their own header comments. But the capability to recover real pre-PR content already exists: reconstructOldContent(newContent, patch) (review-enrichment/src/analyzers/doc-comment-drift.ts:57-93)
reverse-applies the unified-diff patch onto the fetched post-change (headSha) file content to recover
the actual pre-PR text. It's used today by exactly two analyzers (doc-comment-drift.ts, exhaustiveness-drift.ts) for narrow structural comparisons (stale @param names, enum/union
exhaustiveness) and is a one-off per-analyzer trick, not shared infrastructure — the shared AnalysisContext (review-enrichment/src/analysis-context.ts:72-104) exposes only changedFiles
(with GitHub's per-file .patch), addedLines, and patchHunks; no before-content fetch at the context
level.
Fix
Promote reconstructOldContent out of doc-comment-drift.ts into a shared module (or onto AnalysisContext itself, e.g. context.beforeContentFor(path): string | undefined), so any analyzer can
request the pre-PR text of a changed file without re-deriving the reverse-patch logic. Keep the existing
two call sites working unchanged — this is a pure extraction, not a behavior change for them.
Requirements
Preserve exact current behavior for doc-comment-drift.ts and exhaustiveness-drift.ts (byte-faithful
extraction — verify old vs. new output is identical for both, the same way Break up processors.ts mega-functions #4607's extractions were
verified this cycle).
Handle the failure/edge cases the two existing call sites already handle (patch doesn't cleanly
reverse-apply, binary file, file didn't exist before the PR / is newly added) — surface these as undefined/null, never throw, since a missing "before" is a legitimate outcome (new file) that every
downstream consumer must handle explicitly.
Document the function's real cost (it still needs the post-change file content fetched, same as today
— this doesn't add a new network call, just relocates existing reverse-patch logic).
Acceptance criteria
reconstructOldContent (or equivalent) lives once, callable from any AnalyzerDescriptor, via the
shared AnalysisContext or a co-located helper module.
doc-comment-drift.ts / exhaustiveness-drift.ts migrated to the shared version with zero output
change (regression tests pin this).
New-file / unreconstructable-patch cases return an explicit "no before content" signal, not a
thrown error or a silent wrong answer.
Context
Part of #4737 (parent epic — deterministic tier, REES foundation). Prerequisite
for the complexity-delta and duplication-delta sub-issues.
The problem
REES (
review-enrichment/) analyzers normally see only diff hunks, not full before/after file content —that's why
complexity.tsandcoverage-delta.tsboth explicitly disclaim being true before/afterdeltas in their own header comments. But the capability to recover real pre-PR content already exists:
reconstructOldContent(newContent, patch)(review-enrichment/src/analyzers/doc-comment-drift.ts:57-93)reverse-applies the unified-diff patch onto the fetched post-change (
headSha) file content to recoverthe actual pre-PR text. It's used today by exactly two analyzers (
doc-comment-drift.ts,exhaustiveness-drift.ts) for narrow structural comparisons (stale@paramnames, enum/unionexhaustiveness) and is a one-off per-analyzer trick, not shared infrastructure — the shared
AnalysisContext(review-enrichment/src/analysis-context.ts:72-104) exposes onlychangedFiles(with GitHub's per-file
.patch),addedLines, andpatchHunks; no before-content fetch at the contextlevel.
Fix
Promote
reconstructOldContentout ofdoc-comment-drift.tsinto a shared module (or ontoAnalysisContextitself, e.g.context.beforeContentFor(path): string | undefined), so any analyzer canrequest the pre-PR text of a changed file without re-deriving the reverse-patch logic. Keep the existing
two call sites working unchanged — this is a pure extraction, not a behavior change for them.
Requirements
doc-comment-drift.tsandexhaustiveness-drift.ts(byte-faithfulextraction — verify old vs. new output is identical for both, the same way Break up processors.ts mega-functions #4607's extractions were
verified this cycle).
reverse-apply, binary file, file didn't exist before the PR / is newly added) — surface these as
undefined/null, never throw, since a missing "before" is a legitimate outcome (new file) that everydownstream consumer must handle explicitly.
— this doesn't add a new network call, just relocates existing reverse-patch logic).
Acceptance criteria
reconstructOldContent(or equivalent) lives once, callable from anyAnalyzerDescriptor, via theshared
AnalysisContextor a co-located helper module.doc-comment-drift.ts/exhaustiveness-drift.tsmigrated to the shared version with zero outputchange (regression tests pin this).
thrown error or a silent wrong answer.