Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions doc/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Nothing yet.

## Bug Fixes

* Fixed an issue where `winget search --id <msstoreId>` could fail to return a Microsoft Store package unless `--exact` was also provided.
* Fixed a crash (`0x8000ffff`) when using `--disable-interactivity` with the Resume experimental feature enabled during install operations.
88 changes: 88 additions & 0 deletions src/AppInstallerCLITests/RestInterface_1_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,94 @@ TEST_CASE("Search_Optimized_NoResponse_NotFoundCode", "[RestSource][Interface_1_
REQUIRE_THROWS_HR(v1.Search(request), APPINSTALLER_CLI_ERROR_RESTAPI_ENDPOINT_NOT_FOUND);
}

TEST_CASE("Search_SubstringIdFallback_ManifestResponse", "[RestSource][Interface_1_0]")
{
utility::string_t emptySearchResponse = _XPLATSTR(R"delimiter({ "Data" : [] })delimiter");

auto handler = std::make_shared<TestRestRequestHandler>(
[emptySearchResponse](web::http::http_request request) -> pplx::task<web::http::http_response>
{
web::http::http_response response;
response.headers().set_content_type(web::http::details::mime_types::application_json);
response.headers().set_cache_control(L"no-store");

if (request.method() == web::http::methods::POST)
{
response.set_status_code(web::http::status_codes::OK);
response.set_body(web::json::value::parse(emptySearchResponse));
}
else if (request.method() == web::http::methods::GET)
{
response.set_status_code(web::http::status_codes::OK);
response.set_body(web::json::value::parse(GetGoodManifest_RequiredFields()));
}
else
{
response.set_status_code(web::http::status_codes::BadRequest);
}

return pplx::task_from_result(response);
});

HttpClientHelper helper{ std::move(handler) };
AppInstaller::Repository::SearchRequest request;
request.Filters.emplace_back(PackageMatchFilter{ PackageMatchField::Id, MatchType::Substring, "Foo.Bar" });
Interface v1{ TestRestUriString, std::move(helper) };
Schema::IRestClient::SearchResult result = v1.Search(request);

REQUIRE(result.Matches.size() == 1);
REQUIRE(result.Matches[0].PackageInformation.PackageIdentifier == "Foo.Bar");
REQUIRE(result.Matches[0].Versions.size() == 1);
REQUIRE(result.Matches[0].Versions[0].VersionAndChannel.GetVersion().ToString() == "5.0.0");
REQUIRE(result.Matches[0].Versions[0].Manifest.has_value());
}

TEST_CASE("Search_SubstringId_NoFallbackWhenSearchMatches", "[RestSource][Interface_1_0]")
{
utility::string_t searchResponse = _XPLATSTR(
R"delimiter({
"Data" : [
{
"PackageIdentifier": "Foo.Bar.Baz",
"PackageName": "Foo Package",
"Publisher": "Foo",
"Versions": [
{ "PackageVersion": "1.0.0" }
]
}
]
})delimiter");

auto handler = std::make_shared<TestRestRequestHandler>(
[searchResponse](web::http::http_request request) -> pplx::task<web::http::http_response>
{
web::http::http_response response;
response.headers().set_content_type(web::http::details::mime_types::application_json);
response.headers().set_cache_control(L"no-store");

if (request.method() == web::http::methods::POST)
{
response.set_status_code(web::http::status_codes::OK);
response.set_body(web::json::value::parse(searchResponse));
}
else
{
response.set_status_code(web::http::status_codes::NotFound);
}

return pplx::task_from_result(response);
});

HttpClientHelper helper{ std::move(handler) };
AppInstaller::Repository::SearchRequest request;
request.Filters.emplace_back(PackageMatchFilter{ PackageMatchField::Id, MatchType::Substring, "Foo.Bar" });
Interface v1{ TestRestUriString, std::move(helper) };
Schema::IRestClient::SearchResult result = v1.Search(request);

REQUIRE(result.Matches.size() == 1);
REQUIRE(result.Matches[0].PackageInformation.PackageIdentifier == "Foo.Bar.Baz");
}

TEST_CASE("GetManifests_GoodResponse", "[RestSource][Interface_1_0]")
{
GoodManifest_AllFields sampleManifest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace AppInstaller::Repository::Rest::Schema::V1_0
std::vector<Manifest::Manifest> GetManifests(const std::string& packageId, const std::map<std::string_view, std::string>& params = {}) const override;

protected:
bool MeetsOptimizedSearchCriteria(const SearchRequest& request) const;
bool MeetsOptimizedSearchCriteria(const SearchRequest& request, bool allowSubstringMatch = false) const;
IRestClient::SearchResult OptimizedSearch(const SearchRequest& request) const;
IRestClient::SearchResult SearchInternal(const SearchRequest& request) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace AppInstaller::Repository::Rest::Schema::V1_0

return result;
}

}

Interface::Interface(const std::string& restApi, const Http::HttpClientHelper& httpClientHelper) : m_restApiUri(restApi), m_httpClientHelper(httpClientHelper)
Expand Down Expand Up @@ -98,7 +99,20 @@ namespace AppInstaller::Repository::Rest::Schema::V1_0
return OptimizedSearch(request);
}

return SearchInternal(request);
SearchResult result = SearchInternal(request);

// Some sources (including msstore) may not return exact package identifier matches for substring ID requests.
// Preserve substring semantics, but if no match was found for a single-ID request, retry through optimized exact lookup.
if (result.Matches.empty() && MeetsOptimizedSearchCriteria(request, true))
{
SearchRequest optimizedRequest = request;
optimizedRequest.Filters[0].Type = MatchType::CaseInsensitive;

AICLI_LOG(Repo, Verbose, << "No search results for ID substring request; retrying with optimized exact ID lookup.");
return OptimizedSearch(optimizedRequest);
}

return result;
}

IRestClient::SearchResult Interface::SearchInternal(const SearchRequest& request) const
Expand Down Expand Up @@ -180,16 +194,21 @@ namespace AppInstaller::Repository::Rest::Schema::V1_0
return {};
}

bool Interface::MeetsOptimizedSearchCriteria(const SearchRequest& request) const
bool Interface::MeetsOptimizedSearchCriteria(const SearchRequest& request, bool allowSubstringMatch) const
{
// Optimization: If the user wants to install a certain package with an exact match on package id and a particular rest source, we will
// call the package manifest endpoint to get the manifest directly instead of running a search for it.
if (!request.Query && request.Inclusions.size() == 0 &&
request.Filters.size() == 1 && request.Filters[0].Field == PackageMatchField::Id &&
(request.Filters[0].Type == MatchType::Exact || request.Filters[0].Type == MatchType::CaseInsensitive))
request.Filters.size() == 1 && request.Filters[0].Field == PackageMatchField::Id)
{
AICLI_LOG(Repo, Verbose, << "Search request meets optimized search criteria.");
return true;
MatchType matchType = request.Filters[0].Type;

if (matchType == MatchType::Exact || matchType == MatchType::CaseInsensitive ||
(allowSubstringMatch && matchType == MatchType::Substring))
{
AICLI_LOG(Repo, Verbose, << "Search request meets optimized search criteria.");
return true;
}
}

return false;
Expand Down
Loading