Download testing/nano_simulation_agents/tests/test_cli.py from yuhanqin/ut-evaluation: direct link, hf CLI and curl.
- Browser
- Download file 3.12 kB
-
https://huggingface.co/datasets/yuhanqin/ut-evaluation/resolve/main/testing/nano_simulation_agents/tests/test_cli.py
- Command line
-
hf download hf://datasets/yuhanqin/ut-evaluation/testing/nano_simulation_agents/tests/test_cli.py
-
curl -L -o test_cli.py https://huggingface.co/datasets/yuhanqin/ut-evaluation/resolve/main/testing/nano_simulation_agents/tests/test_cli.py
3.12 kB
| from __future__ import annotations | |
| from pathlib import Path | |
| from nano_python_agents import cli | |
| from nano_python_agents.providers.base import FakeProvider | |
| from nano_python_agents.types import AssistantTurn | |
| def test_listing_packaged_assets_does_not_require_api_key(tmp_path: Path, monkeypatch, capsys) -> None: | |
| monkeypatch.delenv("NANO_API_KEY", raising=False) | |
| assert cli.main(["--workspace", str(tmp_path), "--list-prompts"]) == 0 | |
| prompt_output = capsys.readouterr().out | |
| assert "system packaged" in prompt_output | |
| assert cli.main(["--workspace", str(tmp_path), "--list-skills"]) == 0 | |
| skill_output = capsys.readouterr().out | |
| assert "repo-explore v1" in skill_output | |
| def test_relative_trusted_directory_is_resolved_from_workspace( | |
| tmp_path: Path, monkeypatch, capsys | |
| ) -> None: | |
| prompt_dir = tmp_path / "trusted-prompts" | |
| prompt_dir.mkdir() | |
| (prompt_dir / "review.md").write_text("review {workspace}", encoding="utf-8") | |
| (tmp_path / "nano_agent.toml").write_text( | |
| '[prompts]\ndirectories = ["trusted-prompts"]\n', encoding="utf-8" | |
| ) | |
| monkeypatch.chdir(tmp_path.parent) | |
| assert cli.main(["--workspace", str(tmp_path), "--list-prompts"]) == 0 | |
| assert "review external" in capsys.readouterr().out | |
| def test_prompt_validation_precedes_api_key_validation(tmp_path: Path, monkeypatch, capsys) -> None: | |
| monkeypatch.delenv("NANO_API_KEY", raising=False) | |
| result = cli.main( | |
| ["--workspace", str(tmp_path), "--system-prompt", "missing", "do work"] | |
| ) | |
| captured = capsys.readouterr() | |
| assert result == 2 | |
| assert "unknown prompt identifier" in captured.err | |
| assert "API key" not in captured.err | |
| def test_cli_injects_compact_skill_index_without_body(tmp_path: Path, monkeypatch) -> None: | |
| captured: dict[str, str] = {} | |
| class CapturingProvider(FakeProvider): | |
| def create_turn(self, system_prompt, messages, tools): | |
| captured["system_prompt"] = system_prompt | |
| return super().create_turn(system_prompt, messages, tools) | |
| monkeypatch.setattr( | |
| cli, | |
| "_build_provider", | |
| lambda settings: CapturingProvider([AssistantTurn("done", [], "stop")]), | |
| ) | |
| assert cli.main(["--workspace", str(tmp_path), "inspect"]) == 0 | |
| assert "## Available Skills" in captured["system_prompt"] | |
| assert "repo-explore (v1)" in captured["system_prompt"] | |
| assert "# Repo Explore" not in captured["system_prompt"] | |
| def test_list_tools_does_not_require_api_key_and_lists_native_todo(tmp_path: Path, monkeypatch, capsys) -> None: | |
| monkeypatch.delenv("NANO_API_KEY", raising=False) | |
| internal = tmp_path / ".nano_agent" | |
| internal.mkdir() | |
| from nano_python_agents.todo import build_contract, write_contract | |
| write_contract(internal / "todo_contract.json", build_contract("cli-run")) | |
| (tmp_path / "nano_agent.toml").write_text( | |
| '[todo]\nenabled = true\nrun_id = "cli-run"\nwriter_session = "A"\n', encoding="utf-8" | |
| ) | |
| assert cli.main(["--workspace", str(tmp_path), "--list-tools"]) == 0 | |
| assert "todowrite" in capsys.readouterr().out.splitlines() | |