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

Do not go beyond the root when searching for a previously installed tool Fixes #40655 #40800

Merged
merged 7 commits into from
Jul 23, 2024

Conversation

Forgind
Copy link
Member

@Forgind Forgind commented May 10, 2024

Fixes #40655

dotnet tool install currently looks for a previously installed tools manifest. It reads manifests it finds in looking for one that has the manifest it's trying to install but does not check whether that manifest 'isRoot', which means it keeps going outside the root.

We don't use a tool beyond the root, which means we can't install then use a tool as would be expected.

@nagilson, can you take a look at this? I don't know all that much about dotnet tool.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Tools untriaged Request triage from a team member labels May 10, 2024
@dsplaisted
Copy link
Member

@Forgind Could you add a test that covers this behavior? The issue has some repro steps which could probably be adapted to a test.

@Forgind Forgind marked this pull request as ready for review May 29, 2024 17:57
@Forgind Forgind requested a review from a team as a code owner May 29, 2024 17:57
Copy link
Member

@baronfel baronfel left a comment

Choose a reason for hiding this comment

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

LGTM from the containers perspective.

Copy link
Member

@nagilson nagilson left a comment

Choose a reason for hiding this comment

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

I have some thoughts I've labelled below, apologies for my delay in looking at this!

src/Tests/Microsoft.NET.TestFramework/TestContext.cs Outdated Show resolved Hide resolved
src/Cli/Microsoft.DotNet.Cli.Utils/Command.cs Show resolved Hide resolved
var parseResult = Parser.Instance.Parse("tool install dotnetsay");
new ToolInstallLocalCommand(parseResult, runtimeJsonPathForTests: ridGraphPath).Execute().Should().Be(0);

Directory.SetCurrentDirectory("/tmp/folder/sub");
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I fully understand this test/bug, may you please expand upon how this tests that the tool gets installed if a tools-manifest sets isRoot to true? Based on what I read, I think the bug is that the tool does not get installed locally because the tool is already installed in a parent directory. But we don't want to search the parent directory if there's a tools-manifest with isRoot is true, so it should get installed a 2nd time.

How does tools-manifest gets created within this test/is it mimicking this behavior somehow?

Copy link
Member Author

Choose a reason for hiding this comment

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

I mimicked the bug in this case:

  1. Create a tool-manifest (line 49)
  2. Install dotnetsay (line 50-51)
  3. Create another tool-manifest, in the subfolder this time (line 54)
  4. Install dotnetsay again (it should be in the subdirectory this time if it succeeds) (line 55-56)
  5. Run dotnetsay (line 58)

You're correct about what the bug is—more specifically that it doesn't install the tool if it's installed in a parent directory even if there's a tools-manifest specifying isRoot between them. So this test creates a tools manifest via dotnet new tools-manifest in the parent directory and installs dotnetsay there. When we make another tool-manifest in the subdirectory, it should no longer be able to find dotnetsay from the subdirectory, but we install it again, and it works.

Does that make sense?

Copy link
Member

Choose a reason for hiding this comment

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

Thank you, that was well written. I am not sure if that's the desired behavior or not. My guess is that this wouldn't work in 8.0.100 if you did not set isRoot, because it probably shouldn't replicate the install if isRoot is not set to true? In this case, I think the test is testing that this works regardless of whether or not isRoot is set, but I would expect it to only work if it was set even before the 8.0.200 change. I could be wrong!

Copy link
Member Author

Choose a reason for hiding this comment

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

Does 8.0.100 default isRoot to false? If so, then you're correct: it wouldn't (and shouldn't) replicate the install, and this test wouldn't be too useful. I wasn't aware that the default changed so recently, but that's good to keep in mind. I don't think this is likely to be backported to 8.0.100, but if it is, we should definitely make sure to update the test to explicitly set isRoot to true partway through. Thanks for noticing that!

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about the 8.0.100 behavior. Based on what #40655 @havranek1024 said it sounds like it defaults to false. May you try it out please and see?

Copy link
Member Author

Choose a reason for hiding this comment

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

I just tried out 8.0.107-dev (i.e., the current tip of the release/8.0.1xx branch), and it defaulted isRoot to true.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for trying that out, apologies for my delay.

@Forgind
Copy link
Member Author

Forgind commented Jul 18, 2024

Ping @nagilson

@Forgind Forgind changed the base branch from release/8.0.4xx to main July 23, 2024 20:42
Copy link
Member

@nagilson nagilson left a comment

Choose a reason for hiding this comment

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

I looked over this change again and it looks good to me! Thanks for fixing this as well as for the reminder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Tools untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dotnet tool install doesn't respect isRoot property in manifest
4 participants