-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli_toolkit.py
More file actions
105 lines (88 loc) · 3.46 KB
/
Copy pathtest_cli_toolkit.py
File metadata and controls
105 lines (88 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""CLI integration tests for the new toolkit subcommands: scaffold-shim / scan / manifest.
These drive `nilscript.cli.main` the way a developer would, asserting the commands wire the cores
(scaffold generator, inference engine, manifest validator) together correctly end to end.
"""
from __future__ import annotations
import json
from pathlib import Path
from nilscript.cli import main
def test_scaffold_shim_command_creates_a_project(tmp_path: Path, capsys) -> None:
rc = main(["scaffold-shim", "--name", "acme-nil-adapter", "--dest", str(tmp_path)])
assert rc == 0
assert (tmp_path / "acme-nil-adapter" / "src" / "acme_nil_adapter" / "edge.py").exists()
def test_scan_replay_reproduces_erpnext_manifest(tmp_path: Path, capsys) -> None:
replay = tmp_path / "samples.json"
replay.write_text(
json.dumps(
{
"system": "erpnext",
"samples": [
{
"verb": "services.create_invoice",
"native_target": "Sales Invoice",
"errors": [
"Income Account None does not belong to company abc",
"HTTP 417 EXPECTATION FAILED",
],
}
],
}
),
encoding="utf-8",
)
out = tmp_path / "requirements-manifest.json"
rc = main(["scan", "--replay", str(replay), "-o", str(out)])
assert rc == 0
manifest = json.loads(out.read_text(encoding="utf-8"))
fields = {r["field"] for r in manifest["verbs"]["services.create_invoice"]["hidden_requirements"]}
assert {"company", "income_account"} <= fields
assert manifest["transport_quirks"][0]["quirk"] == "no_expect_100_continue"
def test_manifest_validate_passes_a_shareable_manifest(tmp_path: Path, capsys) -> None:
good = tmp_path / "m.json"
good.write_text(
json.dumps(
{
"manifest_version": "0.1",
"system": "erpnext",
"nil_spec": "0.1",
"verbs": {
"services.create_invoice": {
"hidden_requirements": [{"field": "company", "kind": "required_scalar"}]
}
},
}
),
encoding="utf-8",
)
assert main(["manifest", "validate", str(good)]) == 0
def test_manifest_validate_flags_a_leak(tmp_path: Path, capsys) -> None:
leaky = tmp_path / "m.json"
leaky.write_text(
json.dumps(
{
"manifest_version": "0.1",
"system": "erpnext",
"nil_spec": "0.1",
"verbs": {
"services.create_invoice": {
"instance_values": {"company": "abc"} # concrete value = leak
}
},
}
),
encoding="utf-8",
)
rc = main(["manifest", "validate", str(leaky)])
assert rc == 1
assert "LEAK" in capsys.readouterr().err
def test_bare_invocation_shows_banner_and_commands(capsys) -> None:
rc = main([])
assert rc == 0
out = capsys.readouterr().out
assert "Welcome to NILScript" in out
assert "TRUST NO AGENT" in out
assert "scaffold-shim" in out # the command list is shown too
def test_scan_without_replay_explains_itself(capsys) -> None:
rc = main(["scan", "--url", "https://x.example", "--safe"])
assert rc == 2
assert "replay" in capsys.readouterr().err