generated from coulomb/repo-seed
Initial implementation
This commit is contained in:
59
tests/test_cli.py
Normal file
59
tests/test_cli.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def run_cli(*args: str) -> subprocess.CompletedProcess[str]:
|
||||
env = os.environ.copy()
|
||||
env["PYTHONPATH"] = "src"
|
||||
return subprocess.run(
|
||||
[sys.executable, "-m", "infospace_bench", *args],
|
||||
check=False,
|
||||
env=env,
|
||||
text=True,
|
||||
capture_output=True,
|
||||
)
|
||||
|
||||
|
||||
def test_cli_create_inspect_and_add_artifact(tmp_path: Path) -> None:
|
||||
create = run_cli(
|
||||
"create",
|
||||
str(tmp_path),
|
||||
"pilot",
|
||||
"--name",
|
||||
"Pilot Infospace",
|
||||
"--topic-domain",
|
||||
"Test Domain",
|
||||
)
|
||||
assert create.returncode == 0, create.stderr
|
||||
assert json.loads(create.stdout)["slug"] == "pilot"
|
||||
|
||||
source = tmp_path / "source.md"
|
||||
source.write_text("# Source\n", encoding="utf-8")
|
||||
add = run_cli(
|
||||
"add-artifact",
|
||||
str(tmp_path / "infospaces" / "pilot"),
|
||||
str(source),
|
||||
"--kind",
|
||||
"source",
|
||||
"--title",
|
||||
"Source",
|
||||
)
|
||||
assert add.returncode == 0, add.stderr
|
||||
assert json.loads(add.stdout)["artifact"]["id"] == "source/source.md"
|
||||
|
||||
inspect = run_cli("inspect", str(tmp_path / "infospaces" / "pilot"))
|
||||
assert inspect.returncode == 0, inspect.stderr
|
||||
payload = json.loads(inspect.stdout)
|
||||
assert payload["config"]["topic"]["domain"] == "Test Domain"
|
||||
assert payload["artifacts"][0]["title"] == "Source"
|
||||
|
||||
|
||||
def test_cli_returns_structured_error(tmp_path: Path) -> None:
|
||||
result = run_cli("inspect", str(tmp_path / "missing"))
|
||||
|
||||
assert result.returncode == 2
|
||||
payload = json.loads(result.stderr)
|
||||
assert payload["error"]["code"] == "missing_infospace"
|
||||
Reference in New Issue
Block a user