-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Do not update {major}.json
if an older version was published
#483
Conversation
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.
please add a test demonstrating the behaviour(s)
We currently do not have any tests in place. How would you envision these tests to look like? |
there's tests for other targets here -- can follow those as an example https://github.com/getsentry/craft/tree/master/src/targets/__tests__ |
Could you please provide a bit more specific guidance? How would you like these tests to be structured? Should we mock the symlinks in any way, etc. |
I don't particularly care beyond that there are tests for the functionality -- use your judgement to pick what makes sense for you |
I don't think this is quite right consider this scenario:
I expect the symlink structure to be:
before this patch it would do that I believe but after this patch the 1 symlink will be untouched because it was "older" I think the actual fix needs to understand the current set of symlinks and make the symlink based on that |
@asottile-sentry yep, you're right 👍 |
Talked with @tonyo (writing down for future reference): The missing check is if |
I'm not sure that's sufficient either -- the same problem will exist for minor revisions:
|
+ adjust tests
Ok, so I rewrote this logic to take existing |
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.
new tests look useful! thanks for those!
src/utils/symlink.ts
Outdated
logger.debug( | ||
`${ | ||
newVersionMajorSymlinkedVersion ? 'Updating' : 'Adding' | ||
} symlink for "${majorVersionLink}" ${ | ||
newVersionMajorSymlinkedVersion | ||
? `from version "${semVerToString(newVersionMajorSymlinkedVersion)}" ` | ||
: '' | ||
}to "${newVersion}"` | ||
); |
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.
there's way too much going on in this line -- if it's just for a debug line I'd just put the raw data in here instead of trying to make it end-user readable. should eliminate all the logic here as well since this seems error prone / more likely to break than the actual logic
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.
I guess we can simplify it a little but while working on this, having some readable debug output was immensly helpful. (Fwiw, what we had before showed the wrong "from version" on many occasions).
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.
I think logger.debug('symlinking', {before, after})
would probably be sufficient
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.
updated it again
src/utils/symlink.ts
Outdated
try { | ||
// using lstat instead of exists because broken symlinks return false for exists | ||
fs.lstatSync(symlinkPath); | ||
const linkedFile = fs.readlinkSync(symlinkPath); | ||
return parseVersion(path.basename(linkedFile)); | ||
} catch { |
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.
this try catch is overly broad -- each of these 3 statements could raise errors but I think (?) you only intend to catch errors from the first one? this could hide a programming error especially after future maintenance
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.
good catch!
src/utils/symlink.ts
Outdated
const majorVersionLink = `${parsedNewVersion.major}.json`; | ||
forceSymlink(baseVersionName, path.join(packageDir, majorVersionLink)); | ||
// Read possibly existing symlinks for major and minor versions of the new version | ||
const newVersionMajorSymlinkedVersion = getExistingSymlinkedVersion( |
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.
this variable name seems overly verbose and also incorrect -- maybe existingMajorSymlink
instead ? (same for the other one right below this)
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.
I replaced it with existingLinkedMajorVersion
which hopefully clarifies what this variable is holding (i.e. not the symlink but the already parsed version that this link is linking to).
src/utils/__tests__/symlink.test.ts
Outdated
describe('correctly handles already existing symlinks', () => { | ||
it('when updating an old major version', async () => |
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.
the describe
/ it
s read backwards here -- I think they're supposed to be the other way around so the code "reads"?
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.
I tried to "group" the three tests that cover multiple link calls and hence handle actually existing files/symlinks.
I'll just remove the describe block here to clear up the confusion.
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.
This should resolve an issue where craft wrongly updates the
{major}.json
if an older version is released. See getsentry/sentry-release-registry@6db6af4Update (@Lms24): This PR not only resolves the issue mentioned above but it rewrites the linking cases to take previously existing symlinks into account. This way, we can more safely bump the respective symlinks. Added tests to cover the most important + edge case paths.