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

Allow upgrade for unknown version packages #2747

Merged
merged 3 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/AppInstallerCLICore/Commands/UpgradeCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ namespace AppInstaller::CLI
// either for upgrading or for listing available upgrades.
bool HasArgumentsForMultiplePackages(Execution::Args& execArgs)
{
return execArgs.Contains(Args::Type::All) ||
execArgs.Contains(Args::Type::IncludeUnknown);
return execArgs.Contains(Args::Type::All);
}

// Determines whether there are any arguments only used as options during an upgrade,
Expand Down
3 changes: 3 additions & 0 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@
<CopyFileToFolders Include="TestData\InstallFlowTest_Portable_WithCommand.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\InstallFlowTest_UnknownVersion.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\InstallFlowTest_UnsupportedArguments.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@
<CopyFileToFolders Include="TestData\InstallFlowTest_Portable_WithCommand.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\InstallFlowTest_UnknownVersion.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\InstallFlowTest_UnsupportedArguments.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Same content with InstallFlowTest_Exe.yaml but with higher version
PackageIdentifier: AppInstallerCliTest.TestExeUnknownVersion
PackageVersion: 1.0.0.0
PackageLocale: en-US
PackageName: AppInstaller Test Exe Unknown Version
Publisher: Microsoft Corporation
AppMoniker: AICLITestExe
License: Test
Switches:
SilentWithProgress: /silentwithprogress
Silent: /silence
Update: /update
Installers:
- Architecture: x64
InstallerUrl: https://ThisIsNotUsed
InstallerType: exe
InstallerSha256: 65DB2F2AC2686C7F2FD69D4A4C6683B888DC55BFA20A0E32CA9F838B51689A3B
ManifestType: singleton
ManifestVersion: 1.3.0
144 changes: 142 additions & 2 deletions src/AppInstallerCLITests/WorkFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,23 @@ namespace
PackageMatchFilter(PackageMatchField::Id, MatchType::Exact, "AppInstallerCliTest.TestMSStoreInstaller")));
}

if (input.empty() || input == "TestExeInstallerWithUnknownVersion")
{
auto installed = YamlParser::CreateFromPath(TestDataFile("InstallFlowTest_UnknownVersion.yaml"));
auto available = installed;
// Override the installed version to be unknown.
installed.Version = "unknown";
result.Matches.emplace_back(
ResultMatch(
TestPackage::Make(
installed,
TestPackage::MetadataMap{ { PackageVersionMetadata::InstalledType, "Exe" } },
std::vector<Manifest>{ available },
shared_from_this()
),
PackageMatchFilter(PackageMatchField::Id, MatchType::Exact, "AppInstallerCliTest.TestExeUnknownVersion")));
}

if (input == "TestExeInstallerWithLatestInstalled")
{
auto manifest = YamlParser::CreateFromPath(TestDataFile("InstallFlowTest_Exe.yaml"));
Expand Down Expand Up @@ -2191,6 +2208,84 @@ TEST_CASE("UpdateFlow_UpdateExeWithUnsupportedArgs", "[UpdateFlow][workflow]")
REQUIRE(updateOutput.str().find("-l,--location") != std::string::npos);
}

TEST_CASE("UpdateFlow_UnknownVersion", "[UpdateFlow][workflow]")
{
TestCommon::TempFile updateResultPath("TestExeInstalled.txt");
TestCommon::TempDirectory tempDirectory("TempDirectory", false);

std::ostringstream updateOutput;
TestContext context{ updateOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context);
context.Args.AddArg(Execution::Args::Type::Query, "TestExeInstallerWithUnknownVersion"sv);
context.Args.AddArg(Execution::Args::Type::InstallLocation, tempDirectory);

UpgradeCommand update({});
context.SetExecutingCommand(&update);
update.Execute(context);
INFO(updateOutput.str());

// Verify help message is shown the user to use --include-unknown
REQUIRE(context.GetTerminationHR() == APPINSTALLER_CLI_ERROR_UPDATE_NOT_APPLICABLE);
REQUIRE(!std::filesystem::exists(updateResultPath.GetPath()));
REQUIRE(updateOutput.str().find(Resource::LocString(Resource::String::UpgradeUnknownVersionExplanation).get()) != std::string::npos);
}

TEST_CASE("UpdateFlow_UnknownVersion_IncludeUnknownArg", "[UpdateFlow][workflow]")
{
TestCommon::TempFile updateResultPath("TestExeInstalled.txt");
TestCommon::TempDirectory tempDirectory("TempDirectory", false);

std::ostringstream updateOutput;
TestContext context{ updateOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context);
OverrideForShellExecute(context);
context.Args.AddArg(Execution::Args::Type::Query, "TestExeInstallerWithUnknownVersion"sv);
context.Args.AddArg(Execution::Args::Type::InstallLocation, tempDirectory);
context.Args.AddArg(Execution::Args::Type::IncludeUnknown);

UpgradeCommand update({});
context.SetExecutingCommand(&update);
update.Execute(context);
INFO(updateOutput.str());
REQUIRE(std::filesystem::exists(updateResultPath.GetPath()));
}

TEST_CASE("UpdateFlow_NoArgs_UnknownVersion", "[UpdateFlow][workflow]")
{
std::ostringstream updateOutput;
TestContext context{ updateOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context);

UpgradeCommand update({});
context.SetExecutingCommand(&update);
update.Execute(context);
INFO(updateOutput.str());

// Verify --include-unknown help text is displayed if update is executed with no args and an unknown version package is available for upgrade.
REQUIRE(updateOutput.str().find(Resource::LocString(Resource::String::UpgradeUnknownVersionCount).get()) != std::string::npos);
}

TEST_CASE("UpdateFlow_IncludeUnknown", "[UpdateFlow][workflow]")
{
std::ostringstream updateOutput;
TestContext context{ updateOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context);
context.Args.AddArg(Execution::Args::Type::IncludeUnknown);

UpgradeCommand update({});
context.SetExecutingCommand(&update);
update.Execute(context);
INFO(updateOutput.str());

// Verify unknown version package is displayed available for upgrade.
REQUIRE(updateOutput.str().find(Resource::LocString(Resource::String::UpgradeUnknownVersionCount).get()) == std::string::npos);
REQUIRE(updateOutput.str().find("unknown") != std::string::npos);
}

TEST_CASE("UpdateFlow_UpdatePortableWithManifest", "[UpdateFlow][workflow]")
{
TestCommon::TempFile updateResultPath("TestPortableInstalled.txt");
Expand Down Expand Up @@ -2396,6 +2491,43 @@ TEST_CASE("UpdateFlow_UpdateAllApplicable", "[UpdateFlow][workflow]")
update.Execute(context);
INFO(updateOutput.str());

// Verify that --include-unknown help message is displayed.
REQUIRE(updateOutput.str().find(Resource::LocString(Resource::String::UpgradeUnknownVersionCount).get()) != std::string::npos);
REQUIRE(updateOutput.str().find("AppInstallerCliTest.TestExeUnknownVersion") == std::string::npos);

// Verify installers are called.
REQUIRE(std::filesystem::exists(updateExeResultPath.GetPath()));
REQUIRE(std::filesystem::exists(updateMsixResultPath.GetPath()));
REQUIRE(std::filesystem::exists(updateMSStoreResultPath.GetPath()));
REQUIRE(std::filesystem::exists(updatePortableResultPath.GetPath()));
}

TEST_CASE("UpdateFlow_UpdateAll_IncludeUnknown", "[UpdateFlow][workflow]")
{
TestCommon::TempFile updateExeResultPath("TestExeInstalled.txt");
TestCommon::TempFile updateMsixResultPath("TestMsixInstalled.txt");
TestCommon::TempFile updateMSStoreResultPath("TestMSStoreUpdated.txt");
TestCommon::TempFile updatePortableResultPath("TestPortableInstalled.txt");

std::ostringstream updateOutput;
TestContext context{ updateOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
OverrideForCompositeInstalledSource(context);
OverrideForShellExecute(context);
OverrideForMSIX(context);
OverrideForMSStore(context, true);
OverrideForPortableInstall(context);
context.Args.AddArg(Execution::Args::Type::All);
context.Args.AddArg(Execution::Args::Type::IncludeUnknown);

UpgradeCommand update({});
update.Execute(context);
INFO(updateOutput.str());

// Verify that --include-unknown help message is NOT displayed and unknown version package is upgraded.
REQUIRE(updateOutput.str().find(Resource::LocString(Resource::String::UpgradeUnknownVersionCount).get()) == std::string::npos);
REQUIRE(updateOutput.str().find("AppInstallerCliTest.TestExeUnknownVersion") != std::string::npos);

// Verify installers are called.
REQUIRE(std::filesystem::exists(updateExeResultPath.GetPath()));
REQUIRE(std::filesystem::exists(updateMsixResultPath.GetPath()));
Expand Down Expand Up @@ -2767,7 +2899,7 @@ TEST_CASE("ExportFlow_ExportAll", "[ExportFlow][workflow]")
REQUIRE(exportedCollection.Sources[0].Details.Identifier == "*TestSource");

const auto& exportedPackages = exportedCollection.Sources[0].Packages;
REQUIRE(exportedPackages.size() == 5);
REQUIRE(exportedPackages.size() == 6);
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestExeInstaller" && p.VersionAndChannel.GetVersion().ToString().empty();
Expand All @@ -2788,6 +2920,10 @@ TEST_CASE("ExportFlow_ExportAll", "[ExportFlow][workflow]")
{
return p.Id == "AppInstallerCliTest.TestZipInstaller" && p.VersionAndChannel.GetVersion().ToString().empty();
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestExeUnknownVersion" && p.VersionAndChannel.GetVersion().ToString().empty();
}));
}

TEST_CASE("ExportFlow_ExportAll_WithVersions", "[ExportFlow][workflow]")
Expand All @@ -2811,7 +2947,7 @@ TEST_CASE("ExportFlow_ExportAll_WithVersions", "[ExportFlow][workflow]")
REQUIRE(exportedCollection.Sources[0].Details.Identifier == "*TestSource");

const auto& exportedPackages = exportedCollection.Sources[0].Packages;
REQUIRE(exportedPackages.size() == 5);
REQUIRE(exportedPackages.size() == 6);
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestExeInstaller" && p.VersionAndChannel.GetVersion().ToString() == "1.0.0.0";
Expand All @@ -2832,6 +2968,10 @@ TEST_CASE("ExportFlow_ExportAll_WithVersions", "[ExportFlow][workflow]")
{
return p.Id == "AppInstallerCliTest.TestZipInstaller" && p.VersionAndChannel.GetVersion().ToString() == "1.0.0.0";
}));
REQUIRE(exportedPackages.end() != std::find_if(exportedPackages.begin(), exportedPackages.end(), [](const auto& p)
{
return p.Id == "AppInstallerCliTest.TestExeUnknownVersion" && p.VersionAndChannel.GetVersion().ToString() == "unknown";
}));
}

TEST_CASE("ImportFlow_Successful", "[ImportFlow][workflow]")
Expand Down