From 3a29fce0619eef88bd3d46fb9bee7027cdc37183 Mon Sep 17 00:00:00 2001 From: cflmy Date: Sat, 21 Nov 2026 18:22:22 +0800 Subject: [PATCH] fix(foreign): resolve Windows PATH executables with PATHEXT The built-in Python provider scanned PATH for the extension-less token python3; a Windows PATH contains python3.exe, so a working interpreter was reported as kernel.unavailable and the semantic golden suite failed on windows-latest. Expand candidates with PATHEXT (conservative default) and use the same platform-aware resolver in the conformance test's availability probe. Also make native failures diagnosable: strip ANSI before matching and emit the panic/build context as public check annotations, and run Linux tests through the same annotator. This fixes the Windows native lane and gives the macOS failure the context needed to diagnose it. --- .github/workflows/ci.yml | 25 +++++---- crates/cli/tests/conformance_semantics.rs | 10 ++-- crates/marqdo-foreign/src/lib.rs | 49 ++++++++++++++++-- tools/ci/annotate_workspace_tests.py | 63 +++++++++++++++++++++++ tools/ci/test_annotate_workspace_tests.py | 24 +++++++++ 5 files changed, 151 insertions(+), 20 deletions(-) create mode 100755 tools/ci/annotate_workspace_tests.py create mode 100644 tools/ci/test_annotate_workspace_tests.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1565810..b9cf922 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,17 @@ jobs: - name: Clippy run: cargo clippy --workspace --all-targets -- -D warnings - name: Tests - run: cargo test --workspace + shell: bash + run: | + set +e + CARGO_TERM_COLOR=never cargo test --workspace 2>&1 | tee workspace-tests.log + status=${PIPESTATUS[0]} + set -e + if [ "$status" -ne 0 ]; then + python3 tools/ci/annotate_workspace_tests.py \ + workspace-tests.log "Linux workspace tests" + fi + exit "$status" - name: Documentation consistency run: cargo test -p marqdo-cli --test docs_consistency - name: Architecture boundaries @@ -127,19 +137,12 @@ jobs: shell: bash run: | set +e - cargo test --workspace 2>&1 | tee workspace-tests.log + CARGO_TERM_COLOR=never cargo test --workspace 2>&1 | tee workspace-tests.log status=${PIPESTATUS[0]} set -e if [ "$status" -ne 0 ]; then - # Surface the failing test/build context as check annotations so a - # native-matrix failure is diagnosable without admin log access. - { - grep -n -A 18 -B 2 "panicked at" workspace-tests.log || true - grep -n -A 6 -B 2 "^error" workspace-tests.log || true - grep -n "test .* FAILED" workspace-tests.log || true - } | head -80 | while IFS= read -r line; do - echo "::error title=Workspace tests on ${{ matrix.os }}::$line" - done + python3 tools/ci/annotate_workspace_tests.py \ + workspace-tests.log "Workspace tests on ${{ matrix.os }}" fi exit "$status" - name: Portable CLI, analysis and trace smoke diff --git a/crates/cli/tests/conformance_semantics.rs b/crates/cli/tests/conformance_semantics.rs index 4de294b..16daef3 100644 --- a/crates/cli/tests/conformance_semantics.rs +++ b/crates/cli/tests/conformance_semantics.rs @@ -21,7 +21,6 @@ use std::fs; use std::path::{Path, PathBuf}; -use std::process::Command; use marqdo_host::{Capabilities, Host, StdHost}; use marqdo_ir::{ModuleId, Program, ResolvedImport}; @@ -68,11 +67,10 @@ fn expected_path(fixture: &Path) -> PathBuf { } fn python_available() -> bool { - Command::new("python3") - .arg("--version") - .output() - .map(|output| output.status.success()) - .unwrap_or(false) + // Ask the same platform-aware resolver the runtime uses. On Windows a + // PATH entry is `python3.exe`, not the extension-less `python3` token, so a + // raw `Command::new("python3")` probe can disagree with execution. + marqdo_foreign::detect("python").is_some() } /// Unique scratch directory for the host project root. Program fixtures are diff --git a/crates/marqdo-foreign/src/lib.rs b/crates/marqdo-foreign/src/lib.rs index f5d348c..6bebc32 100644 --- a/crates/marqdo-foreign/src/lib.rs +++ b/crates/marqdo-foreign/src/lib.rs @@ -864,6 +864,27 @@ fn execute(request: &RunRequest, registry: &KernelRegistry) -> Result Vec { + // Only the Windows branch appends suffixes, so `mut` is unused on Unix. + #[allow(unused_mut)] + let mut names = vec![std::ffi::OsString::from(name)]; + #[cfg(windows)] + { + if Path::new(name).extension().is_none() { + let extensions = + std::env::var("PATHEXT").unwrap_or_else(|_| ".COM;.EXE;.BAT;.CMD".to_string()); + for extension in extensions.split(';').filter(|value| !value.is_empty()) { + names.push(std::ffi::OsString::from(format!("{name}{extension}"))); + } + } + } + names +} + fn program_candidates(language: &str) -> &'static [&'static str] { match language { "python" => &["python3", "python"], @@ -973,9 +994,14 @@ fn resolve_program(descriptor: &KernelDescriptor) -> Result str: + return text.replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A") + + +def interesting_lines(lines: list[str]) -> list[tuple[int, str]]: + selected: list[tuple[int, str]] = [] + seen: set[int] = set() + + def add(index: int) -> None: + if 0 <= index < len(lines) and index not in seen: + seen.add(index) + selected.append((index, lines[index])) + + for index, line in enumerate(lines): + if "panicked at" in line: + for offset in range(-2, 19): + add(index + offset) + elif line.startswith("failures:") or line.startswith("---- "): + for offset in range(0, 6): + add(index + offset) + elif re.match(r"^error(\[|:)", line): + for offset in range(-1, 7): + add(index + offset) + elif "test " in line and line.endswith("FAILED"): + add(index) + return sorted(selected) + + +def main(argv: list[str]) -> int: + if len(argv) < 2: + print("usage: annotate_workspace_tests.py [title]", file=sys.stderr) + return 2 + log = sys.argv[1] + title = sys.argv[2] if len(argv) > 2 else "Workspace tests" + try: + text = open(log, encoding="utf-8", errors="replace").read() + except OSError as error: + print(f"::error title={title}::cannot read test log: {error}") + return 0 + lines = ANSI.sub("", text).splitlines() + for _, line in interesting_lines(lines)[:MAX_ANNOTATIONS]: + print(f"::error title={title}::{escape(line)}") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main(sys.argv)) diff --git a/tools/ci/test_annotate_workspace_tests.py b/tools/ci/test_annotate_workspace_tests.py new file mode 100644 index 0000000..d10754c --- /dev/null +++ b/tools/ci/test_annotate_workspace_tests.py @@ -0,0 +1,24 @@ +import importlib.util +import unittest +from pathlib import Path + +MODULE = Path(__file__).with_name("annotate_workspace_tests.py") +spec = importlib.util.spec_from_file_location("annotate", MODULE) +annotate = importlib.util.module_from_spec(spec) +spec.loader.exec_module(annotate) + + +class AnnotateTests(unittest.TestCase): + def test_strips_ansi_and_keeps_panic_context(self) -> None: + text = "\x1b[31mthread 'x' panicked at file.rs:1\x1b[0m\nvalue mismatch\nexpected 1\nactual 2\n" + lines = annotate.ANSI.sub("", text).splitlines() + selected = [line for _, line in annotate.interesting_lines(lines)] + self.assertIn("thread 'x' panicked at file.rs:1", selected) + self.assertIn("value mismatch", selected) + + def test_escapes_github_commands(self) -> None: + self.assertEqual(annotate.escape("a%b\r\nc"), "a%25b%0D%0Ac") + + +if __name__ == "__main__": + unittest.main()