No shims, one marker system. The full mechanical sweep:
- 165 test files converted: every @pytest.mark.<os>_only decorator and
pytestmark assignment is now platforms("<os>"). Docstring/comment
prose mentioning the trio rewritten to the platforms() vocabulary.
- conftest: _OS_MARKS, the legacy skip loop, the double-mark reject for
the trio, and the selector-tagging shim are deleted. The single
platforms() gate does all host gating; _reject_contradictory_platform_
marks replaces the old reject (one platforms() marker per test — a
module-level pytestmark stacked on a per-test marker is the historic
skipped-everywhere-green-everywhere failure and stays a hard error).
- pyproject: only the platforms marker is registered.
- list_os_marked_tests.py: rewritten for the single vocabulary — takes
a platform name (linux/macos/windows), matches quoted platforms(...)
specs including negated and any-of forms, exits nonzero on empty
selection. Its test file rewritten to match (bare identifiers must
not match; the spec must appear inside the string literal).
- tests.yml macOS lane: marker: macos feeds the lister; the pytest
selection is -m "platforms and not integration" — the marker name is
the selector, the conftest's per-test host skips are the gate.
- test_os_marker_gating.py rewritten for the new reject (the old file
tested deleted machinery).
- AGENTS.md / CONTRIBUTING.md updated to the single vocabulary.
Verified: full-tree compile; marker unit tests (36); lister tests;
macOS-lane simulation (21 files, 180 collected / 429 deselected on a
windows host); broad xdist slices through scripts/run_tests.sh
(367 + 1674 passed, zero refactor-attributable failures — the 6 red
tests in the second slice fail identically with the changes stashed).
107 lines
4.0 KiB
Python
107 lines
4.0 KiB
Python
"""Tests for the skill_view path boundary check.
|
|
|
|
Regression test: the original check used a hardcoded "/" separator which
|
|
fails on Windows where Path.resolve() returns backslash-separated paths.
|
|
Now uses Path.is_relative_to() which handles all platforms correctly.
|
|
"""
|
|
|
|
import pytest
|
|
from pathlib import Path
|
|
|
|
|
|
def _path_escapes_skill_dir(resolved: Path, skill_dir_resolved: Path) -> bool:
|
|
"""Reproduce the boundary check from tools/skills_tool.py.
|
|
|
|
Returns True when the resolved path is OUTSIDE the skill directory.
|
|
"""
|
|
return not resolved.is_relative_to(skill_dir_resolved)
|
|
|
|
|
|
class TestSkillViewPathBoundaryCheck:
|
|
"""Verify the path boundary check works on all platforms."""
|
|
|
|
def test_valid_subpath_allowed(self, tmp_path):
|
|
"""A file inside the skill directory must NOT be flagged."""
|
|
skill_dir = tmp_path / "skills" / "axolotl"
|
|
ref_file = skill_dir / "references" / "api.md"
|
|
skill_dir.mkdir(parents=True)
|
|
ref_file.parent.mkdir()
|
|
ref_file.write_text("content")
|
|
|
|
resolved = ref_file.resolve()
|
|
skill_dir_resolved = skill_dir.resolve()
|
|
|
|
assert _path_escapes_skill_dir(resolved, skill_dir_resolved) is False
|
|
|
|
|
|
def test_outside_path_blocked(self, tmp_path):
|
|
"""A file outside the skill directory must be flagged."""
|
|
skill_dir = tmp_path / "skills" / "axolotl"
|
|
skill_dir.mkdir(parents=True)
|
|
outside_file = tmp_path / "secret.env"
|
|
outside_file.write_text("SECRET=123")
|
|
|
|
resolved = outside_file.resolve()
|
|
skill_dir_resolved = skill_dir.resolve()
|
|
|
|
assert _path_escapes_skill_dir(resolved, skill_dir_resolved) is True
|
|
|
|
def test_sibling_skill_dir_blocked(self, tmp_path):
|
|
"""A file in a sibling skill directory must be flagged.
|
|
|
|
This catches prefix confusion: 'axolotl-v2' starts with 'axolotl'
|
|
as a string but is a different directory.
|
|
"""
|
|
skill_dir = tmp_path / "skills" / "axolotl"
|
|
sibling_dir = tmp_path / "skills" / "axolotl-v2"
|
|
skill_dir.mkdir(parents=True)
|
|
sibling_dir.mkdir(parents=True)
|
|
sibling_file = sibling_dir / "SKILL.md"
|
|
sibling_file.write_text("other skill")
|
|
|
|
resolved = sibling_file.resolve()
|
|
skill_dir_resolved = skill_dir.resolve()
|
|
|
|
assert _path_escapes_skill_dir(resolved, skill_dir_resolved) is True
|
|
|
|
def test_skill_dir_itself_allowed(self, tmp_path):
|
|
"""Requesting the skill directory itself must be allowed."""
|
|
skill_dir = tmp_path / "skills" / "axolotl"
|
|
skill_dir.mkdir(parents=True)
|
|
|
|
resolved = skill_dir.resolve()
|
|
skill_dir_resolved = skill_dir.resolve()
|
|
|
|
assert _path_escapes_skill_dir(resolved, skill_dir_resolved) is False
|
|
|
|
|
|
class TestOldCheckWouldFail:
|
|
"""Demonstrate the bug: the old hardcoded '/' check fails on Windows."""
|
|
|
|
def _old_path_escapes(self, resolved: Path, skill_dir_resolved: Path) -> bool:
|
|
"""The BROKEN check that used hardcoded '/'."""
|
|
return (
|
|
not str(resolved).startswith(str(skill_dir_resolved) + "/")
|
|
and resolved != skill_dir_resolved
|
|
)
|
|
|
|
# ``platforms("windows")`` rather than ``skipif(os.sep == "/")``: the Windows CI
|
|
# job greps for the marker to decide which files to import, so a bare
|
|
# skipif leaves this running on no host at all.
|
|
@pytest.mark.platforms("windows")
|
|
def test_old_check_false_positive_on_windows(self, tmp_path):
|
|
"""On Windows, the old check incorrectly blocks valid subpaths."""
|
|
skill_dir = tmp_path / "skills" / "axolotl"
|
|
ref_file = skill_dir / "references" / "api.md"
|
|
skill_dir.mkdir(parents=True)
|
|
ref_file.parent.mkdir()
|
|
ref_file.write_text("content")
|
|
|
|
resolved = ref_file.resolve()
|
|
skill_dir_resolved = skill_dir.resolve()
|
|
|
|
# Old check says it escapes (WRONG on Windows)
|
|
assert self._old_path_escapes(resolved, skill_dir_resolved) is True
|
|
# New check correctly allows it
|
|
assert _path_escapes_skill_dir(resolved, skill_dir_resolved) is False
|