Editing asset cache output when using x-script (#1541)

* improve messaging for x-script

* add newlines @ EOF

* format

* respond to Billy feedback

* test order of messaging

---------

Co-authored-by: Javier Matos <javiermatos@Javiers-Laptop.local>
This commit is contained in:
Javier Matos Denizac 2024-11-19 10:34:51 -05:00 коммит произвёл GitHub
Родитель d176cbeeb0
Коммит 99de266b62
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 33 добавлений и 3 удалений

Просмотреть файл

@ -0,0 +1 @@
throw "Script download error"

Просмотреть файл

@ -197,3 +197,31 @@ $actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$d
if (-not ($actual.Contains("Asset cache hit for example3.html; downloaded from: file://$AssetCache"))) {
throw "Failure: azurl (yes), x-block-origin (yes), asset-cache (hit), download (n/a)"
}
# Testing x-download failure with asset cache (x-script) and x-block-origin settings
$env:X_VCPKG_ASSET_SOURCES = "clear;x-script,pwsh $PSScriptRoot/../e2e-assets/asset-caching/failing-script.ps1 {url} {sha512} {dst};x-block-origin"
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--url", "https://example.com", "--sha512", "d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73a"))
# Check for the expected messages in order
$expectedOrder = @(
"error: <mirror-script> failed with exit code: (1).",
"error: Missing example3.html and downloads are blocked by x-block-origin."
)
# Verify order
$index = 0
foreach ($message in $expectedOrder) {
$index = $actual.IndexOf($message, $index)
if ($index -lt 0) {
throw "Failure: Expected message '$message' not found in the correct order."
}
$index += $message.Length
}
# Testing x-download success with asset cache (x-script) and x-block-origin settings
Refresh-TestRoot
$env:X_VCPKG_ASSET_SOURCES = "clear;x-script,$TestScriptAssetCacheExe {url} {sha512} {dst};x-block-origin"
$actual = Run-VcpkgAndCaptureOutput -TestArgs ($commonArgs + @("x-download", "$downloadsRoot/example3.html", "--url", "https://example.com/hello-world.txt", "--sha512", "09e1e2a84c92b56c8280f4a1203c7cffd61b162cfe987278d4d6be9afbf38c0e8934cdadf83751f4e99d111352bffefc958e5a4852c8a7a29c95742ce59288a8"))
if (-not ($actual.Contains("Successfully downloaded example3.html."))) {
throw "Failure: x-script download success message"
}

Просмотреть файл

@ -974,6 +974,7 @@ namespace vcpkg
RedirectedProcessLaunchSettings settings;
settings.environment = get_clean_environment();
settings.echo_in_debug = EchoInDebug::Show;
auto maybe_res = flatten(cmd_execute_and_capture_output(cmd, settings), "<mirror-script>");
if (maybe_res)
{
@ -982,14 +983,14 @@ namespace vcpkg
if (maybe_success)
{
fs.rename(download_path_part_path, download_path, VCPKG_LINE_INFO);
msg::println(msgDownloadSuccesful, msg::path = download_path.filename());
return urls[0];
}
errors.push_back(std::move(maybe_success).error());
msg::println_error(maybe_success.error());
}
else
{
errors.push_back(std::move(maybe_res).error());
msg::println_error(maybe_res.error());
}
}
}