Skip to content

Fix: Hash detection affects all Search results - #107

Merged
kubouch merged 6 commits into
nushell:mainfrom
mrxiaozhuox:main
Apr 9, 2025
Merged

kubouch merged 6 commits into
nushell:mainfrom
mrxiaozhuox:main

Conversation

@mrxiaozhuox

Copy link
Copy Markdown
Contributor

Description

The current Hash check in the code will directly cause the program to throw an error. When using Search, if there is even one Hash check failure, no information can be displayed.

I have fixed this issue and retained the error throw in the Install section. However, I don't think it's necessary to make the program fail to run specifically because of this issue.

The possible useful solutions I have thought of, which I can modify if you are willing to accept, are:

  1. Automatically ignore all packages with Hash check failures.
  2. Give users the right to choose, informing them that the content does not match, but they can still install it.

@mrxiaozhuox

Copy link
Copy Markdown
Contributor Author

It seems that directly adding a dirty field in the pkgs is not a good idea, so we can only wrap a layer of status or directly filter out the data that failed the hash verification.

@mrxiaozhuox

Copy link
Copy Markdown
Contributor Author

or add a new flag to decide how to control hash check failed.

@mrxiaozhuox

mrxiaozhuox commented Nov 21, 2024 •

Copy link
Copy Markdown
Contributor Author

I pushed a new update to fix the issue without affecting the structure.

  • for nupm search: hidden hash check failed package.
  • for nupm install: throw hash check failed error.

@amtoine

amtoine commented Nov 25, 2024

Copy link
Copy Markdown
Member

hopefully superseded by #111

@mrxiaozhuox

Copy link
Copy Markdown
Contributor Author

hopefully superseded by #111

I believe there is a substantial difference between these two PRs. Your PR seems to fix the Hash operation, but what this PR does is: if there is a Hash check failure, it does not affect the results of nupm search, because a hash check failure would directly terminate the entire program, and if there is one failure in the registry, none of the search results can be displayed.

Do you intend to fix this issue in your PR?

Thank you.

@amtoine

amtoine commented Nov 27, 2024

Copy link
Copy Markdown
Member

aah okok my bad.

well yeah, maybe once the fix lands, we can think about what should happen if a hash fails 😉

@kubouch

kubouch commented Nov 27, 2024

Copy link
Copy Markdown
Contributor

Thanks for the PR, sorry for the late reply.

I think the logic could be simplified: Inside search-package, don't throw an error at all, but just add a new column “hash_mismatch” (instead of “dirty”, I think it's more descriptive) with true/false depending on whether the hash failed or not. Then, applications that want to throw an error (nupm publish, nupm install) can do so afterward, and nupm search can just filter it out. nupm search could return the search result, but if there are some mismatches, it could print a warning, for example.

@kubouch

kubouch commented Jan 27, 2025

Copy link
Copy Markdown
Contributor

Again, sorry for the late reply, I don't have much time to consistently work on nupm.

There are still test failures. There are some hash mismatches and nupm publish seems to be looking for the hash-mismatch column in the test registry package file of spam_script: https://github.com/nushell/nupm/blob/main/tests/packages/registry/spam_script.nuon . So I think these need to be addressed, but otherwise the PR seems good.

@kubouch

kubouch commented Jan 27, 2025

Copy link
Copy Markdown
Contributor

Btw, you might experience some type-related errors due to the last Nushell update. I fixed those on the main branch.

@mrxiaozhuox

Copy link
Copy Markdown
Contributor Author

Again, sorry for the late reply, I don't have much time to consistently work on nupm.

There are still test failures. There are some hash mismatches and nupm publish seems to be looking for the hash-mismatch column in the test registry package file of spam_script: https://github.com/nushell/nupm/blob/main/tests/packages/registry/spam_script.nuon . So I think these need to be addressed, but otherwise the PR seems good.

do I need edit tests/nu.nu or just https://github.com/nushell/nupm/blob/main/tests/packages/registry/spam_script.nuon this file?

@kubouch

kubouch commented Jan 28, 2025

Copy link
Copy Markdown
Contributor

I haven't looked closely, but the hash-mismatch shouldn't be a part of the registry package files (like the spam_script.nuon). So nupm publish (and other relevant commands) should be modified to not require this column in those files.

@mrxiaozhuox

Copy link
Copy Markdown
Contributor Author

Only this part used search-package, but only take type field, so I don't know why test will check hash-mismatch:

nupm/nupm/publish.nu

Lines 50 to 61 in e9f39ea

let res = search-package $pkg.name --registry $reg_path --exact-match
| first # there will be only one result because we passed local path
| get pkgs
| sort-by-version
if ($res | is-empty) {
throw-error ($"Cannot guess package type because pacakge"
+ $" ($pkg.name) was not found in registry ($registry). Specify"
+ " the type manually with --git or --local flag.")
}
$res | last | get type

Maybe because this?

export const REG_PKG_COLS = [ name version path type info hash_mismatch ]

did test will check this var?

@mrxiaozhuox

Copy link
Copy Markdown
Contributor Author

I haven't looked closely, but the hash-mismatch shouldn't be a part of the registry package files (like the spam_script.nuon). So nupm publish (and other relevant commands) should be modified to not require this column in those files.

I found a cols check at here:

nupm/nupm/publish.nu

Lines 234 to 240 in e9f39ea

let exp_cols = $REG_PKG_COLS
if (($pkg_content | is-not-empty)
and ($pkg_content | columns) != $exp_cols) {
throw-error ($"Unexpected columns of package file ($pkg_path)."
+ $" Got ($pkg_content | columns), needs ($exp_cols).")
}

I want delete hash-mismatch at REG_PKG_COLS, because I think this only a temp field. how do u think?

@kubouch

kubouch commented Jan 29, 2025

Copy link
Copy Markdown
Contributor

I want delete hash-mismatch at REG_PKG_COLS, because I think this only a temp field. how do u think?

Yeah, this sounds reasonable.

@mrxiaozhuox

Copy link
Copy Markdown
Contributor Author

I want delete hash-mismatch at REG_PKG_COLS, because I think this only a temp field. how do u think?

Yeah, this sounds reasonable.

I deleted hash_mismatch field.

@kubouch

kubouch commented Feb 6, 2025

Copy link
Copy Markdown
Contributor

Good, there are still some test failures, can you fix those?

@mrxiaozhuox

Copy link
Copy Markdown
Contributor Author

Good, there are still some test failures, can you fix those?

sorry for late, I don't know how to fix this error, look's like test package and registry's hash not match.

@kubouch

kubouch commented Mar 6, 2025

Copy link
Copy Markdown
Contributor

You can update the hash in the registry to match the package hash.

@mrxiaozhuox

Copy link
Copy Markdown
Contributor Author

You can update the hash in the registry to match the package hash.

OMG, I fixed it.

I checked the MD5-related content many times and finally found that it was actually a conditional statement error. 😢

@kubouch

kubouch commented Apr 9, 2025

Copy link
Copy Markdown
Contributor

That happens :D Thanks!

@kubouch
kubouch merged commit 0c14c5f into nushell:main Apr 9, 2025
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.

3 participants