Skip to content

Commit 56adb23

Browse files
committed
fix(sc9): reject unparsed env shebangs
Signed-off-by: Efe Gökdemir <[email protected]>
1 parent cc7011a commit 56adb23

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎src/skillspector/nodes/build_context.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ def _is_conventional_skill_script(skill_dir: Path, path: str, data: bytes) -> bo
864864
".tsx": {"node", "nodejs", "bun", "deno", "tsx"},
865865
".zsh": {"zsh"},
866866
}
867-
if interpreter and interpreter not in compatible[suffix]:
867+
if not interpreter or interpreter not in compatible[suffix]:
868868
return False
869869

870870
skill_root = skill_dir.joinpath(*parts[:3])

‎tests/nodes/test_build_context.py‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,25 @@ def test_conventional_skill_scripts_are_not_concealed(
683683
assert coverage == []
684684

685685

686+
def test_conventional_skill_script_with_compatible_env_shebang_is_not_concealed(
687+
tmp_path: Path,
688+
) -> None:
689+
skill_root = tmp_path / ".claude" / "skills" / "demo"
690+
script = skill_root / "scripts" / "run.py"
691+
script.parent.mkdir(parents=True)
692+
(skill_root / "SKILL.md").write_text("# Demo\n", encoding="utf-8")
693+
script.write_bytes(b"#!/usr/bin/env python3\nprint(1)\n")
694+
695+
result = build_context({"skill_path": str(tmp_path), "use_llm": False})
696+
697+
metadata = next(
698+
item
699+
for item in result["component_metadata"]
700+
if item["path"] == ".claude/skills/demo/scripts/run.py"
701+
)
702+
assert metadata["concealed_executable"] is False
703+
704+
686705
@pytest.mark.parametrize(
687706
("relative_path", "payload", "manifest", "source_local_only"),
688707
[
@@ -697,6 +716,18 @@ def test_conventional_skill_scripts_are_not_concealed(
697716
(".claude/skills/demo/scripts/tool.py", b"MZ" + b"\0" * 20, True, False),
698717
(".claude/skills/demo/scripts/run", b"#!/bin/sh\ntrue\n", True, False),
699718
(".claude/skills/demo/scripts/run.bat", b"@echo off\r\n", True, False),
719+
(
720+
".claude/skills/demo/scripts/run.py",
721+
b"#!/usr/bin/env -Sbash\ntrue\n",
722+
True,
723+
False,
724+
),
725+
(
726+
".claude/skills/demo/scripts/run.py",
727+
b"#!/usr/bin/env --split-string=bash\ntrue\n",
728+
True,
729+
False,
730+
),
700731
(".claude/skills/.demo/scripts/run.py", b"#!/usr/bin/env python3\nprint(1)\n", True, False),
701732
(
702733
".claude/skills/demo/scripts/.cache/run.py",
@@ -725,7 +756,7 @@ def test_skill_script_exemption_fails_closed(
725756
target = tmp_path / relative_path
726757
target.parent.mkdir(parents=True)
727758
target.write_bytes(payload)
728-
skill_root = tmp_path / ".claude" / "skills" / "demo"
759+
skill_root = target.parents[1]
729760
skill_root.mkdir(parents=True, exist_ok=True)
730761
if manifest is True:
731762
(skill_root / "SKILL.md").write_text("# Demo\n", encoding="utf-8")

0 commit comments

Comments
 (0)