diff --git a/.agent/rules/testing.md b/.agent/rules/testing.md index 986e4a2a2..7eaaed412 100644 --- a/.agent/rules/testing.md +++ b/.agent/rules/testing.md @@ -3121,10 +3121,3 @@ rewrote. does not judge whether a phrase is the right tripwire. Marked `untriaged:` and not `none:`, and `ctest -R rulebook-tripwires` prints the count against this issue on every run. - -- **[#1735](https://github.com/LASTRADA-Software/pace/issues/1735)** — a test that uses a link must - verify a link can be followed here, and SKIP otherwise (Windows error 448). -- **[#1733](https://github.com/LASTRADA-Software/pace/issues/1733)** — the FileTrust test hard-codes - the English LOCAL SERVICE account name. -- **[#1734](https://github.com/LASTRADA-Software/pace/issues/1734)** — `python3` resolves to the - Windows Store stub on this host. diff --git a/scripts/check-mkdocs-validation.sh b/scripts/check-mkdocs-validation.sh index 9fef6659b..3194a4a8f 100755 --- a/scripts/check-mkdocs-validation.sh +++ b/scripts/check-mkdocs-validation.sh @@ -28,7 +28,14 @@ set -euo pipefail root="$(cd "$(dirname "$0")/.." && pwd)" [ "${1:-}" != "--root" ] || root="${2:?--root needs a tree}" -python3 - "$root" <<'PY' +# A Python that RUNS, never a name on PATH: on Windows `python3` is the Store's stub (#1734). +. "$(cd "$(dirname "$0")" && pwd)/lib/python.sh" +if ! pace_python_resolve; then + echo "SKIP: $PACE_PYTHON_REFUSAL" + exit 0 +fi + +pace_python - "$root" <<'PY' import sys, os try: import yaml diff --git a/scripts/check-tracked-files-selftest.cmake b/scripts/check-tracked-files-selftest.cmake index 3b3f477ad..cc5a15f51 100644 --- a/scripts/check-tracked-files-selftest.cmake +++ b/scripts/check-tracked-files-selftest.cmake @@ -452,7 +452,12 @@ MakeRepository("${missingTree}" TRUE) file(REMOVE "${missingTree}/gone.txt") execute_process(COMMAND "${GIT_EXECUTABLE}" -C "${missingTree}" ls-files -s -- ./link-to-kept OUTPUT_VARIABLE missingStaged) -if(linkResult STREQUAL "0" AND danglingResult STREQUAL "0" AND missingStaged MATCHES "120000 [^\t]*\tlink-to-kept") +# EXISTS too, which FOLLOWS the link (#1735): on a host that lets a user create a link it then +# refuses to open (error 448, "untrusted mount point"), a created and recorded link reads as +# unreadable, and a run that assumed otherwise ended in FATAL_ERROR rather than in the branches +# below that already say the link cases did not run. +if(linkResult STREQUAL "0" AND danglingResult STREQUAL "0" AND missingStaged MATCHES "120000 [^\t]*\tlink-to-kept" + AND EXISTS "${missingTree}/link-to-kept") set(linksReachable TRUE) endif() diff --git a/scripts/lib/python.sh b/scripts/lib/python.sh new file mode 100644 index 000000000..11aef5d24 --- /dev/null +++ b/scripts/lib/python.sh @@ -0,0 +1,61 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The one way a script finds a Python interpreter that RUNS (#1734). +# +# `python3` on PATH is not evidence of a Python. On Windows it is, by default, the Microsoft +# Store's app-execution alias (`%LOCALAPPDATA%\Microsoft\WindowsApps\python3.exe`): a stub that +# prints "Python was not found" and exits 49 -- even on a host with a real interpreter installed, +# which then reads as a missing prerequisite or, worse, as the script's own check failing. +# `command -v python3` answers yes to the stub. +# +# So a candidate is ASKED, never trusted for its name: it must print a token the probe chose. +# Order: `PACE_PYTHON` when set (the operator's answer wins), then `py -3` (the Windows launcher, +# which no stub shadows), then `python3`, then `python`. +# +# bash 3.2: an array and a function, nothing newer. +# +# Usage: +# . "/lib/python.sh" +# if pace_python_resolve; then pace_python -c '...'; else echo "SKIP: $PACE_PYTHON_REFUSAL"; fi + +PACE_PYTHON_CMD=() +PACE_PYTHON_REFUSAL="" + +# Whether the command in "$@" is a Python that runs: it must print the probe's own token. +pace_python_answers() { + local answer + answer="$("$@" -c 'print("pace-python-probe-7c1e")' 2> /dev/null)" || return 1 + [ "${answer%$'\r'}" = "pace-python-probe-7c1e" ] +} + +# Fill PACE_PYTHON_CMD with the first candidate that runs. Returns 1, with PACE_PYTHON_REFUSAL +# saying what was tried, when none does. +pace_python_resolve() { + PACE_PYTHON_CMD=() + if [ -n "${PACE_PYTHON:-}" ]; then + if pace_python_answers "$PACE_PYTHON"; then + PACE_PYTHON_CMD=("$PACE_PYTHON") + return 0 + fi + PACE_PYTHON_REFUSAL="PACE_PYTHON=$PACE_PYTHON does not run a Python" + return 1 + fi + if command -v py > /dev/null 2>&1 && pace_python_answers py -3; then + PACE_PYTHON_CMD=(py -3) + return 0 + fi + local candidate + for candidate in python3 python; do + if command -v "$candidate" > /dev/null 2>&1 && pace_python_answers "$candidate"; then + PACE_PYTHON_CMD=("$candidate") + return 0 + fi + done + PACE_PYTHON_REFUSAL="no usable Python (tried py -3, python3, python; a Windows Store alias is not one)" + return 1 +} + +# Run the resolved interpreter. Call pace_python_resolve first. +pace_python() { + "${PACE_PYTHON_CMD[@]}" "$@" +} diff --git a/scripts/node-mcp-enrollment-e2e.sh b/scripts/node-mcp-enrollment-e2e.sh index dc83dd38e..19d3c42b3 100755 --- a/scripts/node-mcp-enrollment-e2e.sh +++ b/scripts/node-mcp-enrollment-e2e.sh @@ -206,6 +206,18 @@ approved_body="$(call_tool "$leader_mcp_port" enrollment_approve "{\"node_id\":\ json_check "enrollment_approve" "$approved_body" \ "${OK} and ${SC}['node_id'] == '${approved_id}' and ${SC}['decision'] == 'approved' and ${SC}['enrollment'] == 'manual' and 'the leader\\'s row now reads approved' in d['result']['content'][0]['text']" wait_for_log "it is a learner" "$approved_pid" "the approved joiner" "${workdir}/approved.log" +# Admission CHANGES THE JOINER'S SHAPE, and a shape change stops every body and starts them again +# from the record -- its MCP surface included. "it is a learner" is logged by the restarted +# consensus tier BEFORE that surface is back, so section 4 dialling the learner's MCP port on the +# strength of it raced the restart and lost under ASan: `curl could not complete`. The restarted +# body announces readiness again once its surfaces are up, and the first start already wrote one +# marker, so the fact is the SECOND marker. Counted rather than matched: a match would find the +# first start's line at once. +learner_ready_again() { + [ "$(grep -c "$E2eNodeReadyMarker" "${workdir}/approved.log" || true)" -ge 2 ] +} +wait_until learner_ready_again "the approved joiner's restarted body to log a second ${E2eNodeReadyMarker}" \ + "$approved_pid" "${workdir}/approved.log" 120 e2e_note "enrollment_approve answered decision approved, and the joiner counts itself a learner" # ------------------------------------------------------------------- 3. reject diff --git a/scripts/pacectl-e2e.sh b/scripts/pacectl-e2e.sh index d643a84fd..c19a28ed0 100755 --- a/scripts/pacectl-e2e.sh +++ b/scripts/pacectl-e2e.sh @@ -266,12 +266,14 @@ refute_stdout '"value":"-"' "json must not render an absence as a dash" # Validated with a real parser where one is available. Absent is reported as its own # outcome rather than silently passing, because "no parser here" and "the document # parsed" are different things. -if command -v python3 > /dev/null 2>&1; then - python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); assert isinstance(d,list) and d[1]["value"] is None, d' \ +# A Python that RUNS, never a name on PATH: on Windows `python3` is the Store's stub (#1734). +. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/python.sh" +if pace_python_resolve; then + pace_python -c 'import json,sys; d=json.load(open(sys.argv[1])); assert isinstance(d,list) and d[1]["value"] is None, d' \ "$WORK/out" || fail "the json output is not a parseable document with a null" - e2e_note "json validated with python3" + e2e_note "json validated with ${PACE_PYTHON_CMD[*]}" else - e2e_note "python3 absent: the json document was matched textually and not parsed" + e2e_note "$PACE_PYTHON_REFUSAL: the json document was matched textually and not parsed" fi # --------------------------------------------------------------------------------- diff --git a/src/Pace/Platform/FileTrust_test.cpp b/src/Pace/Platform/FileTrust_test.cpp index 371569dfb..90d7e0573 100644 --- a/src/Pace/Platform/FileTrust_test.cpp +++ b/src/Pace/Platform/FileTrust_test.cpp @@ -801,6 +801,27 @@ using LocalBlock = std::unique_ptr; return std::format("{}\\{}", domain.data(), name.data()); } +/// The account a well-known SID names, spelled `DOMAIN\name` as THIS host localizes it. +/// +/// Never an English literal (#1733, #1683): Windows translates its well-known accounts, so +/// `NT AUTHORITY\LOCAL SERVICE` is `NT-AUTORITÄT\Lokaler Dienst` on a German host and the +/// English spelling fails to resolve there (error 1332). +/// @param sidText The SID, e.g. `S-1-5-19`. +/// @return The account name. +[[nodiscard]] std::string AccountNameOfSid(char const* sidText) +{ + PSID sid = nullptr; + REQUIRE(::ConvertStringSidToSidA(sidText, &sid) != FALSE); + LocalBlock const owned { sid }; + std::array name {}; + auto nameSize = static_cast(name.size()); + std::array domain {}; + auto domainSize = static_cast(domain.size()); + SID_NAME_USE use = SidTypeUnknown; + REQUIRE(::LookupAccountSidA(nullptr, sid, name.data(), &nameSize, domain.data(), &domainSize, &use) != FALSE); + return std::format("{}\\{}", domain.data(), name.data()); +} + /// Grant `BUILTIN\Users` read on @p path, the way `%ProgramData%` does. /// @param path The entry. /// @param inheritance `SUB_CONTAINERS_AND_OBJECTS_INHERIT` for the directory the installer @@ -1175,7 +1196,8 @@ TEST_CASE("FileTrust: a foreign-owned entry is refused with the deletion remedy" } std::array const credentialLeaves { std::filesystem::path { "node-key" } }; - auto const secured = Pace::SecureDirectoryForService(directory, "NT AUTHORITY\\LOCAL SERVICE", credentialLeaves); + // LOCAL SERVICE by its well-known SID, in this host's language (#1733). + auto const secured = Pace::SecureDirectoryForService(directory, AccountNameOfSid("S-1-5-19"), credentialLeaves); REQUIRE_FALSE(secured.has_value()); INFO(secured.error()); CHECK(secured.error().contains(key.string())); diff --git a/src/apps/pace-cc/CmdLine_test.cpp b/src/apps/pace-cc/CmdLine_test.cpp index 1ce6e8f38..6e5919c38 100644 --- a/src/apps/pace-cc/CmdLine_test.cpp +++ b/src/apps/pace-cc/CmdLine_test.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -2211,9 +2212,10 @@ TEST_CASE("CompilerWorkingDirectory reads PWD from the environment through its o auto const& base = scratch.Path(); std::filesystem::create_directories(base / "real" / "build"); - std::error_code ec; - std::filesystem::create_directory_symlink(base / "real", base / "link", ec); - if (ec) + auto const unfollowable = Pace::Testing::MakeFollowableLink(base / "real", base / "link"); + // Created AND followable, or skipped with the reason (#1735). + INFO(unfollowable.value_or(std::string {})); + if (unfollowable) { std::filesystem::remove_all(base); SKIP("symlinks unavailable on this host, so PWD cannot be made to differ from the resolved path"); @@ -2261,9 +2263,10 @@ TEST_CASE("CompilerWorkingDirectory keeps the symlinked spelling a driver report auto const& base = scratch.Path(); std::filesystem::create_directories(base / "real" / "build"); - std::error_code ec; - std::filesystem::create_directory_symlink(base / "real", base / "link", ec); - if (ec) + auto const unfollowable = Pace::Testing::MakeFollowableLink(base / "real", base / "link"); + // Created AND followable, or skipped with the reason (#1735). + INFO(unfollowable.value_or(std::string {})); + if (unfollowable) { // Symlinks need a privilege or developer mode on Windows. The rule is // unconditional; only this way of demonstrating it is not -- so this is SKIPPED diff --git a/src/apps/pace-cc/DirectManifest_test.cpp b/src/apps/pace-cc/DirectManifest_test.cpp index 44b85e097..693d74abe 100644 --- a/src/apps/pace-cc/DirectManifest_test.cpp +++ b/src/apps/pace-cc/DirectManifest_test.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -1266,9 +1267,10 @@ TEST_CASE("AnchorWorkingDirectory re-spells a symlinked cwd in the layout's voca auto const& base = scratch.Path(); std::filesystem::create_directories(base / "real" / "sub"); - std::error_code ec; - std::filesystem::create_directory_symlink(base / "real", base / "link", ec); - if (ec) + auto const unfollowable = Pace::Testing::MakeFollowableLink(base / "real", base / "link"); + // Created AND followable, or skipped with the reason (#1735). + INFO(unfollowable.value_or(std::string {})); + if (unfollowable) { // Symlink creation needs a privilege or developer mode on Windows. The rule // is unconditional; only this way of demonstrating it is not -- which is diff --git a/src/apps/pace-cc/InputFiles_test.cpp b/src/apps/pace-cc/InputFiles_test.cpp index 501f4c160..947b01daf 100644 --- a/src/apps/pace-cc/InputFiles_test.cpp +++ b/src/apps/pace-cc/InputFiles_test.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -370,11 +371,13 @@ TEST_CASE("Retargeting a symlink changes the identity read through it", "[input- scratch.Write("a.hpp", "same\n"); scratch.Write("b.hpp", "same\n"); auto const link = scratch / "h.hpp"; - std::filesystem::create_symlink(scratch / "a.hpp", link); + if (auto const unfollowable = Pace::Testing::MakeFollowableLink(scratch / "a.hpp", link)) + SKIP(*unfollowable); auto const files = MakeDiskInputFiles(); auto const first = files->Identify(link.string()); std::filesystem::remove(link); - std::filesystem::create_symlink(scratch / "b.hpp", link); + if (auto const unfollowable = Pace::Testing::MakeFollowableLink(scratch / "b.hpp", link)) + SKIP(*unfollowable); auto const second = files->Identify(link.string()); auto const target = files->Identify((scratch / "b.hpp").string()); REQUIRE(first.has_value()); diff --git a/src/apps/pace-cc/PathResolve_test.cpp b/src/apps/pace-cc/PathResolve_test.cpp index a27cbe3ec..8a9bb6a35 100644 --- a/src/apps/pace-cc/PathResolve_test.cpp +++ b/src/apps/pace-cc/PathResolve_test.cpp @@ -10,6 +10,7 @@ #include #include +#include #include using namespace Pace; @@ -86,10 +87,11 @@ TEST_CASE("Two spellings of one directory resolve to the same answer") auto const real = scratch / "real"; auto const file = MakeFile(scratch, "real/inc/h1.h"); - std::error_code ec; auto const link = scratch / "link"; - std::filesystem::create_directory_symlink(real, link, ec); - if (ec) + auto const unfollowable = Pace::Testing::MakeFollowableLink(real, link); + // Created AND followable, or skipped with the reason (#1735). + INFO(unfollowable.value_or(std::string {})); + if (unfollowable) SKIP("this host does not permit creating symlinks; nothing to compare"); auto const resolver = MakePathResolver(); @@ -111,8 +113,10 @@ TEST_CASE("A root's own final component is resolved, unlike a file's") std::error_code ec; std::filesystem::create_directories(real, ec); auto const link = scratch / "link"; - std::filesystem::create_directory_symlink(real, link, ec); - if (ec) + auto const unfollowable = Pace::Testing::MakeFollowableLink(real, link); + // Created AND followable, or skipped with the reason (#1735). + INFO(unfollowable.value_or(std::string {})); + if (unfollowable) SKIP("this host does not permit creating symlinks; nothing to compare"); auto const resolver = MakePathResolver(); diff --git a/src/apps/pace-cc/run-launcher-e2e.ps1 b/src/apps/pace-cc/run-launcher-e2e.ps1 index bb6536085..ac591cad8 100644 --- a/src/apps/pace-cc/run-launcher-e2e.ps1 +++ b/src/apps/pace-cc/run-launcher-e2e.ps1 @@ -1980,7 +1980,32 @@ try { # `...\jx\L1\genlink\g.h`. The flat leg is the one a recorder that records nothing # turns red -- the 8.3 leg above passes on the seeded short forms alone. Junctions, # because `mklink /J` needs no elevation; removed as links before the tree is. + # Created is not followable (#1735): on at least one Windows 11 build a non-administrator + # makes junctions freely and every Win32 open through one then fails with error 448 + # ("untrusted mount point") -- `cl` itself cannot read an include through it, so every case + # below failed for a property of the host. Probed once, by READING a file through a junction; + # an unfollowable host skips the cases and says why. + $junctionProbe = Join-Path ([System.IO.Path]::GetTempPath()) ("pace-cc-jxprobe-" + [guid]::NewGuid().ToString('N').Substring(0, 12)) + $junctionsFollowable = $false + $junctionWhy = "" + try { + New-Item -ItemType Directory -Force -Path (Join-Path $junctionProbe "real") | Out-Null + Set-Content -Path (Join-Path $junctionProbe "real\probe.txt") -Value "followed" + New-Item -ItemType Junction -Path (Join-Path $junctionProbe "link") -Target (Join-Path $junctionProbe "real") | Out-Null + $junctionsFollowable = (Get-Content -Raw -ErrorAction Stop (Join-Path $junctionProbe "link\probe.txt")).Trim() -eq "followed" + } catch { + $junctionWhy = $_.Exception.Message + } finally { + $probeLink = Join-Path $junctionProbe "link" + if (Test-Path $probeLink) { [System.IO.Directory]::Delete($probeLink) } + Remove-Item -Recurse -Force $junctionProbe -ErrorAction SilentlyContinue + } + if (-not $junctionsFollowable) { + Write-Host "=== a junction alias of the build tree: SKIPPED -- this host cannot follow a junction this user created ($junctionWhy) ===" + } + foreach ($cc in @("cl","clang-cl")) { + if (-not $junctionsFollowable) { break } if (-not (Get-Command $cc -ErrorAction SilentlyContinue)) { continue } Write-Host "=== a junction alias of the build tree ($cc) ===" foreach ($shape in 'flat', 'nested', 'through', 'subthrough', 'selfbuild', 'selfthrough', 'srcself', 'revthrough', diff --git a/src/apps/pace-node/NodeStateFiles_test.cpp b/src/apps/pace-node/NodeStateFiles_test.cpp index a1c81d5c1..fc7749f04 100644 --- a/src/apps/pace-node/NodeStateFiles_test.cpp +++ b/src/apps/pace-node/NodeStateFiles_test.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -1063,11 +1064,11 @@ TEST_CASE("A link named like the replace probe is no leftover of it, whatever it auto const target = elsewhere.Path() / "a-regular-file"; WriteText(target, "a regular file somewhere"); ScratchDirectory const scratch { "replace-probe-link" }; - auto made = std::error_code {}; - std::filesystem::create_symlink( - target, scratch.Path() / std::filesystem::path { std::string { Consensus::ReplaceProbeFileName } }, made); - if (made) - SKIP("this host lets this process create no symbolic link: " << made.message()); + // Created AND followable, or skipped with the reason (#1735): the assertion below reads + // THROUGH the link. + if (auto const unfollowable = Pace::Testing::MakeFollowableLink( + target, scratch.Path() / std::filesystem::path { std::string { Consensus::ReplaceProbeFileName } })) + SKIP(*unfollowable); REQUIRE(std::filesystem::is_regular_file(scratch.Path() / std::filesystem::path { std::string { Consensus::ReplaceProbeFileName } })); auto guard = ScriptedNodeKeyGuard::OwnerOnly(); diff --git a/src/tests/FollowableLink.hpp b/src/tests/FollowableLink.hpp new file mode 100644 index 000000000..66e3c0be4 --- /dev/null +++ b/src/tests/FollowableLink.hpp @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace Pace::Testing +{ + +/// Create a symbolic link and prove THIS process can open through it, or say why not (#1735). +/// +/// Creating a link is not the same fact as following one. On at least one Windows 11 build a +/// non-administrator creates links freely -- `create_symlink`, `mklink /D`, `mklink /J` all +/// succeed -- and every Win32 open through them then fails with error 448, "untrusted mount +/// point". A case that checked only the creation then failed DETERMINISTICALLY, on a clean +/// master, for a property of the host rather than of the code. So the caller gets one answer +/// for both questions: nothing when the link exists and opens, else the reason to SKIP with. +/// +/// @param target What the link points at; a directory gets a directory link. +/// @param link Where the link goes. +/// @return Nothing when the link was made and a read through it works; otherwise the reason, +/// worded for `SKIP`. +[[nodiscard]] inline std::optional MakeFollowableLink(std::filesystem::path const& target, + std::filesystem::path const& link) +{ + std::error_code error; + bool const directory = std::filesystem::is_directory(target, error); + if (directory) + std::filesystem::create_directory_symlink(target, link, error); + else + std::filesystem::create_symlink(target, link, error); + if (error) + return std::format("this host lets this process create no symbolic link ({})", error.message()); + + // FOLLOWED, never `symlink_status`: the question is whether an open through the link reaches + // the target, and both reads below go through it. + if (directory) + { + std::filesystem::directory_iterator const entries { link, error }; + if (error) + return std::format("this host cannot follow a link this process created ({})", error.message()); + return std::nullopt; + } + std::ifstream const opened { link, std::ios::binary }; + if (!opened) + return std::string { "this host cannot follow a link this process created (it would not open)" }; + return std::nullopt; +} + +} // namespace Pace::Testing