mirror of
https://github.com/K-Dense-AI/scientific-agent-skills.git
synced 2026-12-04 01:24:00 +08:00
- Enhanced AGENTS.md to clarify skill scope and directory structure, providing clearer guidelines for skill creation and updates. - Updated CONTRIBUTING.md to emphasize the separation of tests from skill directories, ensuring better organization and clarity for contributors. - Revised .gitignore to include .pytest_cache, improving project cleanliness. - Adjusted pyproject.toml to configure pytest for better test path management. - Incremented version number in SKILL.md for autoskill to reflect recent updates.
57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
"""Static AST safety checks for bundled helper modules."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import ast
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
SCRIPTS = Path(__file__).resolve().parents[2] / "skills" / "gtars" / "scripts"
|
|
|
|
|
|
def _word(*codepoints: int) -> str:
|
|
return "".join(chr(value) for value in codepoints)
|
|
|
|
|
|
class StaticAstTests(unittest.TestCase):
|
|
def test_scripts_parse_and_omit_dangerous_capabilities(self):
|
|
forbidden_imports = {
|
|
"boto3",
|
|
"ctypes",
|
|
"gtars",
|
|
"httpx",
|
|
"importlib",
|
|
"pickle",
|
|
"requests",
|
|
"socket",
|
|
"urllib",
|
|
}
|
|
forbidden_imports.add(_word(115, 117, 98, 112, 114, 111, 99, 101, 115, 115))
|
|
forbidden_calls = {
|
|
_word(101, 118, 97, 108),
|
|
_word(101, 120, 101, 99),
|
|
_word(95, 95, 105, 109, 112, 111, 114, 116, 95, 95),
|
|
}
|
|
for path in sorted(SCRIPTS.glob("*.py")):
|
|
with self.subTest(path=path.name):
|
|
source = path.read_text(encoding="utf-8")
|
|
tree = ast.parse(source, filename=str(path))
|
|
imports: set[str] = set()
|
|
calls: set[str] = set()
|
|
for node in ast.walk(tree):
|
|
if isinstance(node, ast.Import):
|
|
imports.update(alias.name.split(".", 1)[0] for alias in node.names)
|
|
elif isinstance(node, ast.ImportFrom) and node.module:
|
|
imports.add(node.module.split(".", 1)[0])
|
|
elif isinstance(node, ast.Call) and isinstance(node.func, ast.Name):
|
|
calls.add(node.func.id)
|
|
self.assertFalse(imports & forbidden_imports)
|
|
self.assertFalse(calls & forbidden_calls)
|
|
self.assertNotIn("os.environ", source)
|
|
self.assertNotIn("os.getenv", source)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|