🐛 Drop ReleaseNotes singleton to fix multi-pass state leak (#111)#112
Open
glandais-nickel wants to merge 2 commits into
Open
🐛 Drop ReleaseNotes singleton to fix multi-pass state leak (#111)#112glandais-nickel wants to merge 2 commits into
glandais-nickel wants to merge 2 commits into
Conversation
Demonstrate that the process-wide ReleaseNotes singleton retains `_rtype` and `_context.commits` across analyzeCommits / generateNotes calls, causing pass 2 (e.g. maintenance branch creation) to inherit pass 1 state. Marked `.failing` so the suite stays green until the singleton is fixed.
semantic-release reuses the same plugin process across analyzeCommits / generateNotes invocations. The static `ReleaseNotes.get` returned a shared instance whose `_rtype` cache and constructor-frozen `_context.commits` polluted subsequent passes (e.g. the channel-add pass run before a maintenance release evaluation). Construct a fresh `ReleaseNotes` per call from each entry point so the context (notably `context.commits`) provided by semantic-release is always reflected. The existing test stubs that bypassed the singleton are no longer needed.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #111.
Problem
ReleaseNotes.getreturned a process-wide singleton, so whensemantic-release ran
analyzeCommits/generateNotestwice within asingle run (e.g. the channel-add pass that precedes a maintenance
release evaluation), two pieces of state leaked from pass 1 into pass 2:
_rtype, memoized on the instance, short-circuited pass 2'sgetReleaseType._context.commits, parsed once in the constructor, was neverrefreshed (
updateContextdoes not touch it), sogenerateNotesrendered pass 1's commits in pass 2's notes.
Net effect on a maintenance branch with no release-worthy commit:
an unwanted release was emitted whose notes contained commits from
prior releases.
Fix
Construct a fresh
ReleaseNotesper call from each entry point(
analyze-commits.js,generate-notes.js) and drop the staticget/_instance. semantic-release's per-callcontext.commitsisnow always reflected.
updateContext()is still invoked once on theper-pass instance, so note rendering is unchanged.
This is option 2 from the issue's "Suggested fix" section — the
smaller change of the two.
Tests
test/integration/release-notes-singleton.test.jscovers bothregression scenarios (release-type inheritance and commit-list
pollution across passes).
analyze-commits.test.js/generate-notes.test.jsare removed(no longer needed, and broken without the static
get).npm test: 21 passing.