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

feat: Added Semver Version and Versionreq support for plugin versions #942

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

devin-b-lake
Copy link
Contributor

No description provided.

@devin-b-lake devin-b-lake self-assigned this Feb 20, 2025
@devin-b-lake devin-b-lake force-pushed the plugin-semver-version-update branch from 8295e71 to d50cc25 Compare February 20, 2025 15:34
@devin-b-lake
Copy link
Contributor Author

The pre_process_plugin_version_req() function to prepend a = to a version if necessary is written in two places: one in policy_file.rs and one in plugin_manifest.rs. This may be worth putting in the util directory. However, I didn't see a file in there where this function would be a good fit and could be added. Should I create a new file for it in util?

@devin-b-lake
Copy link
Contributor Author

The policy-file.md documentation file where I updated the plugin version information includes the line 'For an example of the manifest field, see
[@todo - link to For-Developers section].'

I looked for the 'For-Developers' section and references to manifest field in the docs and did not see an example/explanation for the manifest field within the policy file to link to. I did see a reference to the manifest field within the plugin manifest in the Packing and Release a Plugin section. Should I link this TODO to that section?

@j-lanson
Copy link
Collaborator

The policy-file.md documentation file where I updated the plugin version information includes the line 'For an example of the manifest field, see [@todo - link to For-Developers section].'

I looked for the 'For-Developers' section and references to manifest field in the docs and did not see an example/explanation for the manifest field within the policy file to link to. I did see a reference to the manifest field within the plugin manifest in the Packing and Release a Plugin section. Should I link this TODO to that section?

Sure Devin that would be helpful.

Copy link
Collaborator

@j-lanson j-lanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few changes to make, but overall looking very clean.

Comment on lines +108 to +123
// If exact plugin version was provided, use existing cache entry if not force
if plugin_id
.version()
.version_req
.comparators
.first()
.is_some_and(|comp| comp.op == semver::Op::Exact)
{
let version_req_syntax_string = plugin_id.version().version_req.to_string();
let version_syntax_string = version_req_syntax_string
.chars()
.skip(1)
.collect::<String>();
let plugin_version = PluginVersion::new(version_syntax_string.as_str())?;
let plugin_id_for_cache = PluginId::new(
plugin_id.publisher().clone(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really clean, I like this. Might want to check though if this code stands up to a version req like =0.3.1,>4.0.1. If VersionReq::parse doesn't catch a string like that as being nonsense, the code here might not get a proper concrete version number

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a nonsense version req is passed in, e.g., =0.3.1, >4.0.1, how do we want to handle it? Should it error or should we assign a version? If we assign a version, should we make it the latest available plugin version?

It looks like the SemVer VersionReq doesn't detect =0.3.1,>4.0.1 is nonsense; it creates a VersionReq object with that version range. I'll have to rethink this logic.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nonsense reqs should be rejected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy that thanks. Currently, the program errors when a nonsense version req is passed into the version field because it cannot find a version in the download manifest within the nonsense range.

If we want the nonsense version req to be rejected when the PluginVersionReq object is instantiated (PluginVersionReq is a wrapper for VersionReq), I can try to write a validation function into the PluginVersionReq struct.

Which approach should we go with?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think erroring as early as possible is better, and means we can give clear error messages when a constraint is not satisfiable inherently because it's expressing incompatible bounds

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, the point of my original comment was not to get into discussion about how to detect nonsense versions. The point is that a version req could have multiple parts, in which case if the first comparator is =, we can't necessarily assume that the rest of the string can be parsed as a Version.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, if I do this:

plugins {
    plugin "mitre/activity" version="=0.4.0,>0.2.0" manifest="https://hipcheck.mitre.org/dl/plugin/mitre/activity.kdl"
}

Hipcheck errors with: unexpected character ',' after patch version number

Copy link
Collaborator

@alilleybrinker alilleybrinker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the work on this @devin-b-lake! I added my comments under points Julian had made already. I'd say the biggest thing is to be clear in our documentation and naming in the code itself where we're dealing with versions (as specified by SemVer) vs. version requirements.

@devin-b-lake devin-b-lake force-pushed the plugin-semver-version-update branch from e38c5c0 to 53d85ad Compare February 25, 2025 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants