Skip to content
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

[Crates] Only use non-yanked crate versions (ready for merge) #9949

Merged
merged 10 commits into from Feb 5, 2024

Conversation

johannesvollmer
Copy link
Contributor

No description provided.

Copy link
Contributor

github-actions bot commented Feb 3, 2024

Messages
📖 ✨ Thanks for your contribution to Shields, @johannesvollmer!

Generated by 🚫 dangerJS against 65d2826

@johannesvollmer
Copy link
Contributor Author

is there a way to add tests to this, without setting up a special crate? can I test with a mocked response json? (the current json for the exrs crate)

@johannesvollmer johannesvollmer changed the title prototype fix msrv using yanked versions fix MSRV service using yanked versions Feb 3, 2024
@johannesvollmer johannesvollmer changed the title fix MSRV service using yanked versions make MSRV service not use yanked versions Feb 3, 2024
@johannesvollmer
Copy link
Contributor Author

johannesvollmer commented Feb 3, 2024

Use max version instead of newest version? What's the difference?

other code in this repo uses
json.crate.max_stable_version ? json.crate.max_stable_version : json.crate.max_version

@johannesvollmer
Copy link
Contributor Author

Same issue exists elsewhere in repo. Apply a fix in the shared base class?

const license = version ? version.license : versions[0].license

@chris48s
Copy link
Member

chris48s commented Feb 4, 2024

Thanks for picking this up.

Same issue exists elsewhere in repo. Apply a fix in the shared base class?

Yes. I think we should declare a function on BaseCratesService to get the latest non-yanked version. Then we should use that same definition of "latest" when we want to fetch any data point for the latest version, so:

  • MSRV
  • License
  • Number of downloads

should all get the "latest" version in the same way (and all exclude yanked versions).

@johannesvollmer
Copy link
Contributor Author

  • put the logic for finding the correct version info into one function and reuse it everywhere
  • use crate.max_version, as it is the only field seems to be required in the response
  • deduplicate response scheme

@johannesvollmer
Copy link
Contributor Author

johannesvollmer commented Feb 4, 2024

0204130921 Error: I've made a huge mistake

What does that mean? What exactly did go wrong? How can I make this unit test run? Please help.

@johannesvollmer johannesvollmer marked this pull request as ready for review February 4, 2024 13:11
@johannesvollmer johannesvollmer changed the title make MSRV service not use yanked versions [Crates] Only use non-yanked crate versions Feb 4, 2024
@johannesvollmer johannesvollmer changed the title [Crates] Only use non-yanked crate versions [Crates] Only use non-yanked crate versions (help required) Feb 4, 2024
@johannesvollmer johannesvollmer changed the title [Crates] Only use non-yanked crate versions (help required) [Crates] Only use non-yanked crate versions (guidance required) Feb 4, 2024
@chris48s
Copy link
Member

chris48s commented Feb 4, 2024

Thanks for making a start on this. Rather than coach you through this one, I've decided to just take what you've done as a baseline and work from there, retaining the core approach. I've pushed my proposed solution to this branch.

There are some changes I've made which are just cleanup, getting the build to pass, adding tests, etc. To summarise the key changes:

  • I think it makes sense to base everything (license, downloads, MSRV) off the latest stable version if there is one
  • I've moved the helper function(s) onto BaseCratesService
  • I've just written the tests as unit tests on base class

Does this implementation seem reasonable to you?

Just to clarify a few points where you seemed to be getting stuck:

  1. There are 2 types of this test in codebase: The ones in files called .tester.js are integration tests: We bootstrap the app and test it from the outside by making HTTP calls against it. Most of these tests touch live services, but we can also use mocks. Then the tests in files called .spec.js are unit tests that test the code. They run using 2 different test frameworks. One of the reasons you were hitting problems was because you were trying to write a unit-style test (that tests an individual function) in a .tester.js.

Error: I've made a huge mistake

What does that mean?

There are some tests in the core test suite that test some code which outputs something to the console, and we don't suppress console output under test. I guess you're seeing this when running.
https://github.com/badges/shields/blob/master/core/base-service/base.spec.js#L225-L244

  1. The purpose of validating the response we receive against a schema is so that we can write the rest of the code on the assumption we have an object that conforms to that schema. That allows us to be a bit less defensive in the code we write post-validation. If we don't have an object that conforms to the expected format, we'll throw when we validate it.

Hope some of that helps?

@johannesvollmer
Copy link
Contributor Author

johannesvollmer commented Feb 4, 2024

thanks for making it work <3 I have nothing else to add. your points sound reasonable and are a welcome addition.

@johannesvollmer
Copy link
Contributor Author

johannesvollmer commented Feb 4, 2024

Well, one bike shedding addition: As it seems difficult to decide whether to use max_version or max_stable_version, maybe a different PR might want to read this from a url parameter, allowing the user to decide. I'd not do it right now in this PR though, to keep the scope narrow. For now, max_stable indeed seems like the best default.

@johannesvollmer johannesvollmer changed the title [Crates] Only use non-yanked crate versions (guidance required) [Crates] Only use non-yanked crate versions (ready for merge) Feb 5, 2024
@chris48s
Copy link
Member

chris48s commented Feb 5, 2024

OK, cool. I'm going to merge what we've got for now.

I think this is pretty much in line with what we do for other package registries.

@chris48s chris48s added this pull request to the merge queue Feb 5, 2024
Merged via the queue into badges:master with commit e36d933 Feb 5, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants