verulla-manifest 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. verulla_manifest-0.0.2/.gitignore +7 -0
  2. verulla_manifest-0.0.2/PKG-INFO +6 -0
  3. verulla_manifest-0.0.2/pyproject.toml +13 -0
  4. verulla_manifest-0.0.2/tests/golden/fastapi.Dockerfile +7 -0
  5. verulla_manifest-0.0.2/tests/golden/node.Dockerfile +7 -0
  6. verulla_manifest-0.0.2/tests/golden/static.Dockerfile +5 -0
  7. verulla_manifest-0.0.2/tests/test_adapters_registry.py +127 -0
  8. verulla_manifest-0.0.2/tests/test_container_hardening.py +55 -0
  9. verulla_manifest-0.0.2/tests/test_dockerfile.py +73 -0
  10. verulla_manifest-0.0.2/tests/test_fastapi_adapter.py +79 -0
  11. verulla_manifest-0.0.2/tests/test_manifest_import.py +4 -0
  12. verulla_manifest-0.0.2/tests/test_manifest_model.py +193 -0
  13. verulla_manifest-0.0.2/tests/test_node_adapter.py +68 -0
  14. verulla_manifest-0.0.2/tests/test_static_adapter.py +41 -0
  15. verulla_manifest-0.0.2/tests/test_translate.py +156 -0
  16. verulla_manifest-0.0.2/verulla_manifest/__init__.py +34 -0
  17. verulla_manifest-0.0.2/verulla_manifest/adapters/__init__.py +18 -0
  18. verulla_manifest-0.0.2/verulla_manifest/adapters/base.py +25 -0
  19. verulla_manifest-0.0.2/verulla_manifest/adapters/dockerfile.py +21 -0
  20. verulla_manifest-0.0.2/verulla_manifest/adapters/fastapi_adapter.py +51 -0
  21. verulla_manifest-0.0.2/verulla_manifest/adapters/node.py +54 -0
  22. verulla_manifest-0.0.2/verulla_manifest/adapters/registry.py +39 -0
  23. verulla_manifest-0.0.2/verulla_manifest/adapters/static.py +29 -0
  24. verulla_manifest-0.0.2/verulla_manifest/build_plan.py +47 -0
  25. verulla_manifest-0.0.2/verulla_manifest/dockerfile.py +24 -0
  26. verulla_manifest-0.0.2/verulla_manifest/model.py +142 -0
  27. verulla_manifest-0.0.2/verulla_manifest/sketch_events.py +39 -0
  28. verulla_manifest-0.0.2/verulla_manifest/translate.py +65 -0
@@ -0,0 +1,7 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ data/
5
+ *.db
6
+ .DS_Store
7
+ output.txt
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.5
2
+ Name: verulla-manifest
3
+ Version: 0.0.2
4
+ Requires-Python: >=3.12
5
+ Requires-Dist: pydantic>=2.7
6
+ Requires-Dist: pyyaml>=6
@@ -0,0 +1,13 @@
1
+ [project]
2
+ name = "verulla-manifest"
3
+ version = "0.0.2"
4
+ requires-python = ">=3.12"
5
+ dependencies = ["pydantic>=2.7", "pyyaml>=6"]
6
+
7
+ [build-system]
8
+ requires = ["hatchling"]
9
+ build-backend = "hatchling.build"
10
+
11
+ [tool.deptry]
12
+ known_first_party = ["verulla_manifest"]
13
+ extend_exclude = ["tests"]
@@ -0,0 +1,7 @@
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY . .
4
+ RUN pip install -r requirements.txt
5
+ USER 10001:10001
6
+ EXPOSE 8080
7
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
@@ -0,0 +1,7 @@
1
+ FROM node:20-alpine
2
+ WORKDIR /app
3
+ COPY . .
4
+ RUN npm ci
5
+ USER 10001:10001
6
+ EXPOSE 3000
7
+ CMD ["npm", "start"]
@@ -0,0 +1,5 @@
1
+ FROM nginxinc/nginx-unprivileged:alpine
2
+ WORKDIR /usr/share/nginx/html
3
+ COPY . .
4
+ USER 101:101
5
+ EXPOSE 8080
@@ -0,0 +1,127 @@
1
+ """Tests for the adapter registry and BuildPlan model (M3 T3.2)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ import pytest
8
+ from pydantic import ValidationError
9
+
10
+ from verulla_manifest.adapters import (
11
+ DockerfileAdapter,
12
+ FastAPIAdapter,
13
+ NodeAdapter,
14
+ StaticAdapter,
15
+ select_adapter,
16
+ )
17
+ from verulla_manifest.build_plan import BuildPlan
18
+ from verulla_manifest.model import FunctionSpec
19
+
20
+
21
+ def _function() -> FunctionSpec:
22
+ return FunctionSpec(name="my-func")
23
+
24
+
25
+ class TestSelectAdapter:
26
+ def test_dockerfile_only(self, tmp_path: Path) -> None:
27
+ (tmp_path / "Dockerfile").write_text("FROM scratch\n")
28
+ assert select_adapter(tmp_path) is DockerfileAdapter
29
+
30
+ def test_dockerfile_and_package_json_prefers_dockerfile(self, tmp_path: Path) -> None:
31
+ (tmp_path / "Dockerfile").write_text("FROM scratch\n")
32
+ (tmp_path / "package.json").write_text("{}\n")
33
+ assert select_adapter(tmp_path) is DockerfileAdapter
34
+
35
+ def test_package_json_only(self, tmp_path: Path) -> None:
36
+ (tmp_path / "package.json").write_text("{}\n")
37
+ assert select_adapter(tmp_path) is NodeAdapter
38
+
39
+ def test_requirements_txt_only(self, tmp_path: Path) -> None:
40
+ (tmp_path / "requirements.txt").write_text("fastapi\n")
41
+ assert select_adapter(tmp_path) is FastAPIAdapter
42
+
43
+ def test_pyproject_toml_only(self, tmp_path: Path) -> None:
44
+ (tmp_path / "pyproject.toml").write_text("[project]\nname='x'\n")
45
+ assert select_adapter(tmp_path) is FastAPIAdapter
46
+
47
+ def test_empty_dir_falls_back_to_static(self, tmp_path: Path) -> None:
48
+ assert select_adapter(tmp_path) is StaticAdapter
49
+
50
+ def test_explicit_static_hint_bypasses_detection(self, tmp_path: Path) -> None:
51
+ (tmp_path / "package.json").write_text("{}\n")
52
+ assert select_adapter(tmp_path, runtime="static") is StaticAdapter
53
+
54
+ def test_bogus_runtime_raises(self, tmp_path: Path) -> None:
55
+ with pytest.raises(ValueError):
56
+ select_adapter(tmp_path, runtime="bogus")
57
+
58
+
59
+ class TestAdapterPlan:
60
+ def test_dockerfile_adapter_plan(self, tmp_path: Path) -> None:
61
+ plan = DockerfileAdapter.plan(_function(), tmp_path)
62
+ assert isinstance(plan, BuildPlan)
63
+ assert plan.dockerfile_path == "Dockerfile"
64
+ assert plan.base_image is None
65
+
66
+ # NodeAdapter.plan() is now implemented (M3 T3.4); its dedicated
67
+ # coverage moved to test_node_adapter.py.
68
+ def test_node_adapter_plan_returns_build_plan(self, tmp_path: Path) -> None:
69
+ (tmp_path / "package.json").write_text('{"scripts": {"start": "node server.js"}}\n')
70
+
71
+ plan = NodeAdapter.plan(_function(), tmp_path)
72
+
73
+ assert isinstance(plan, BuildPlan)
74
+ assert plan.base_image == "node:20-slim"
75
+ assert plan.run_cmd == ["npm", "start"]
76
+
77
+ # FastAPIAdapter.plan() is now implemented (M3 T3.3); its dedicated
78
+ # coverage moved to test_fastapi_adapter.py.
79
+ def test_fastapi_adapter_plan_returns_build_plan(self, tmp_path: Path) -> None:
80
+ (tmp_path / "requirements.txt").write_text("fastapi\n")
81
+ (tmp_path / "main.py").write_text("app = None\n")
82
+
83
+ plan = FastAPIAdapter.plan(_function(), tmp_path)
84
+
85
+ assert isinstance(plan, BuildPlan)
86
+ assert plan.base_image == "python:3.12-slim"
87
+ assert plan.run_cmd == [
88
+ "uvicorn",
89
+ "main:app",
90
+ "--host",
91
+ "0.0.0.0",
92
+ "--port",
93
+ "8080",
94
+ ]
95
+
96
+ # StaticAdapter.plan() is now implemented (M3 T3.4); its dedicated
97
+ # coverage moved to test_static_adapter.py.
98
+ def test_static_adapter_plan_returns_build_plan(self, tmp_path: Path) -> None:
99
+ plan = StaticAdapter.plan(_function(), tmp_path)
100
+
101
+ assert isinstance(plan, BuildPlan)
102
+ assert plan.base_image == "nginxinc/nginx-unprivileged:alpine"
103
+ assert plan.port == 8080
104
+
105
+
106
+ class TestBuildPlanValidation:
107
+ def test_both_base_image_and_dockerfile_path_raises(self) -> None:
108
+ with pytest.raises(ValidationError):
109
+ BuildPlan(base_image="python:3.12-slim", dockerfile_path="Dockerfile")
110
+
111
+ def test_neither_base_image_nor_dockerfile_path_raises(self) -> None:
112
+ with pytest.raises(ValidationError):
113
+ BuildPlan()
114
+
115
+ def test_dockerfile_path_with_build_steps_raises(self) -> None:
116
+ with pytest.raises(ValidationError):
117
+ BuildPlan(dockerfile_path="Dockerfile", build_steps=["pip install -r requirements.txt"])
118
+
119
+ def test_base_image_valid(self) -> None:
120
+ plan = BuildPlan(base_image="python:3.12-slim", run_cmd=["python", "app.py"])
121
+ assert plan.dockerfile_path is None
122
+ assert plan.port == 8080
123
+
124
+ def test_dockerfile_path_valid(self) -> None:
125
+ plan = BuildPlan(dockerfile_path="Dockerfile")
126
+ assert plan.base_image is None
127
+ assert plan.build_steps == []
@@ -0,0 +1,55 @@
1
+ from pathlib import Path
2
+
3
+ import yaml
4
+
5
+ ROOT = Path(__file__).parents[2]
6
+
7
+
8
+ def test_first_party_python_images_run_as_non_root() -> None:
9
+ for name in ("Dockerfile.admin", "Dockerfile.account", "Dockerfile.control", "Dockerfile"):
10
+ text = (ROOT / name).read_text()
11
+ assert "USER " in text, f"{name} must select a non-root runtime user"
12
+
13
+
14
+ def test_generated_dockerfile_uses_dependency_first_copy_and_non_root_user() -> None:
15
+ from verulla_manifest import BuildPlan, generate_dockerfile
16
+
17
+ dockerfile = generate_dockerfile(
18
+ BuildPlan(base_image="python:3.12-slim", build_steps=["pip install -r requirements.txt"])
19
+ )
20
+ assert "COPY . ." in dockerfile
21
+ assert dockerfile.index("COPY . .") < dockerfile.index("USER ")
22
+
23
+
24
+ def test_deployments_have_distinct_probes_and_restrictive_security_contexts() -> None:
25
+ control = yaml.safe_load((ROOT / "deploy/control/release.yaml").read_text())
26
+ values = control["spec"]["values"]
27
+ container = values["controllers"]["control"]["containers"]["app"]
28
+ probes = container["probes"]
29
+ assert probes["startup"]["enabled"]
30
+ assert probes["liveness"]["spec"] != probes["readiness"]["spec"]
31
+ pod_sc = values["defaultPodOptions"]["securityContext"]
32
+ assert pod_sc["seccompProfile"]["type"] == "RuntimeDefault"
33
+ security = container["securityContext"]
34
+ assert security["allowPrivilegeEscalation"] is False
35
+ assert security["capabilities"]["drop"] == ["ALL"]
36
+
37
+ postgres = yaml.safe_load_all((ROOT / "deploy/control/postgres.yaml").read_text())
38
+ stateful = list(postgres)[1]
39
+ spec = stateful["spec"]["template"]["spec"]
40
+ pg = spec["containers"][0]
41
+ assert "startupProbe" in pg
42
+ assert pg["securityContext"]["allowPrivilegeEscalation"] is False
43
+
44
+ zot = list(yaml.safe_load_all((ROOT / "deploy/registry/zot.yaml").read_text()))
45
+ zot_container = next(doc for doc in zot if doc.get("kind") == "Deployment")["spec"]["template"]["spec"]["containers"][0]
46
+ assert zot_container["startupProbe"]["httpGet"]["path"] == "/livez"
47
+ assert zot_container["livenessProbe"]["httpGet"]["path"] == "/livez"
48
+ assert zot_container["readinessProbe"]["httpGet"]["path"] == "/readyz"
49
+
50
+
51
+ def test_migration_container_has_bounded_resources() -> None:
52
+ release = yaml.safe_load((ROOT / "deploy/control/release.yaml").read_text())
53
+ migrate = release["spec"]["values"]["controllers"]["control"]["initContainers"]["migrate"]
54
+ assert migrate["resources"]["requests"]["memory"]
55
+ assert migrate["resources"]["limits"]["memory"]
@@ -0,0 +1,73 @@
1
+ from pathlib import Path
2
+
3
+ import pytest
4
+
5
+ from verulla_manifest import BuildPlan, generate_dockerfile
6
+ from verulla_cli.emulate import generate_dockerfile as cli_generate_dockerfile
7
+
8
+
9
+ GOLDEN_DIR = Path(__file__).parent / "golden"
10
+
11
+
12
+ @pytest.mark.parametrize(
13
+ ("name", "plan"),
14
+ [
15
+ ("static", BuildPlan(base_image="nginxinc/nginx-unprivileged:alpine", port=8080, copy_dest="/usr/share/nginx/html")),
16
+ # The official unprivileged image listens on 8080 and runs as UID/GID 101.
17
+ (
18
+ "fastapi",
19
+ BuildPlan(
20
+ base_image="python:3.12-slim",
21
+ build_steps=["pip install -r requirements.txt"],
22
+ run_cmd=["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"],
23
+ port=8080,
24
+ ),
25
+ ),
26
+ (
27
+ "node",
28
+ BuildPlan(
29
+ base_image="node:20-alpine",
30
+ build_steps=["npm ci"],
31
+ run_cmd=["npm", "start"],
32
+ port=3000,
33
+ ),
34
+ ),
35
+ ],
36
+ )
37
+ def test_generated_dockerfile_matches_golden(name: str, plan: BuildPlan) -> None:
38
+ assert generate_dockerfile(plan).encode() == (GOLDEN_DIR / f"{name}.Dockerfile").read_bytes()
39
+
40
+
41
+ def test_cli_and_manifest_import_paths_have_byte_identical_output() -> None:
42
+ plan = BuildPlan(
43
+ base_image="python:3.12-slim",
44
+ build_steps=["pip install -r requirements.txt"],
45
+ run_cmd=["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"],
46
+ port=8080,
47
+ )
48
+ assert generate_dockerfile(plan).encode() == cli_generate_dockerfile(plan).encode()
49
+
50
+
51
+ def test_dockerfile_path_plan_is_rejected() -> None:
52
+ with pytest.raises(ValueError):
53
+ generate_dockerfile(BuildPlan(dockerfile_path="Dockerfile"))
54
+
55
+
56
+ def test_plan_copy_destination_is_preserved() -> None:
57
+ text = generate_dockerfile(
58
+ BuildPlan(base_image="nginx:alpine", port=80, copy_dest="/usr/share/nginx/html")
59
+ )
60
+ assert "WORKDIR /usr/share/nginx/html" in text
61
+ assert "WORKDIR /app" not in text
62
+
63
+
64
+ def test_static_image_uses_unprivileged_nginx_user_and_port() -> None:
65
+ text = generate_dockerfile(
66
+ BuildPlan(
67
+ base_image="nginxinc/nginx-unprivileged:alpine",
68
+ port=8080,
69
+ copy_dest="/usr/share/nginx/html",
70
+ )
71
+ )
72
+ assert "USER 101:101" in text
73
+ assert "EXPOSE 8080" in text
@@ -0,0 +1,79 @@
1
+ """Tests for FastAPIAdapter.plan() (M3 T3.3)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ import pytest
8
+
9
+ from verulla_manifest.adapters.fastapi_adapter import FastAPIAdapter
10
+ from verulla_manifest.build_plan import BuildPlan
11
+ from verulla_manifest.model import FunctionSpec
12
+
13
+
14
+ def _function() -> FunctionSpec:
15
+ return FunctionSpec(name="web", src="./")
16
+
17
+
18
+ class TestFastAPIAdapterPlan:
19
+ def test_requirements_txt_and_main_py(self, tmp_path: Path) -> None:
20
+ (tmp_path / "requirements.txt").write_text("fastapi\n")
21
+ (tmp_path / "main.py").write_text("app = None\n")
22
+
23
+ plan = FastAPIAdapter.plan(_function(), tmp_path)
24
+
25
+ assert isinstance(plan, BuildPlan)
26
+ assert plan.base_image == "python:3.12-slim"
27
+ assert plan.build_steps == ["pip install --no-cache-dir -r requirements.txt"]
28
+ assert plan.run_cmd == [
29
+ "uvicorn",
30
+ "main:app",
31
+ "--host",
32
+ "0.0.0.0",
33
+ "--port",
34
+ "8080",
35
+ ]
36
+ assert plan.port == 8080
37
+ assert plan.dockerfile_path is None
38
+
39
+ def test_pyproject_only_and_app_py(self, tmp_path: Path) -> None:
40
+ (tmp_path / "pyproject.toml").write_text("[project]\nname='x'\n")
41
+ (tmp_path / "app.py").write_text("app = None\n")
42
+
43
+ plan = FastAPIAdapter.plan(_function(), tmp_path)
44
+
45
+ assert plan.build_steps == ["pip install --no-cache-dir ."]
46
+ assert plan.run_cmd == [
47
+ "uvicorn",
48
+ "app:app",
49
+ "--host",
50
+ "0.0.0.0",
51
+ "--port",
52
+ "8080",
53
+ ]
54
+
55
+ def test_entrypoint_priority_main_over_app(self, tmp_path: Path) -> None:
56
+ (tmp_path / "requirements.txt").write_text("fastapi\n")
57
+ (tmp_path / "main.py").write_text("app = None\n")
58
+ (tmp_path / "app.py").write_text("app = None\n")
59
+
60
+ plan = FastAPIAdapter.plan(_function(), tmp_path)
61
+
62
+ assert plan.run_cmd[1] == "main:app"
63
+ assert "app:app" not in plan.run_cmd
64
+
65
+ def test_entrypoint_priority_app_over_server(self, tmp_path: Path) -> None:
66
+ (tmp_path / "requirements.txt").write_text("fastapi\n")
67
+ (tmp_path / "app.py").write_text("app = None\n")
68
+ (tmp_path / "server.py").write_text("app = None\n")
69
+
70
+ plan = FastAPIAdapter.plan(_function(), tmp_path)
71
+
72
+ assert plan.run_cmd[1] == "app:app"
73
+ assert "server:app" not in plan.run_cmd
74
+
75
+ def test_no_entrypoint_raises_value_error(self, tmp_path: Path) -> None:
76
+ (tmp_path / "requirements.txt").write_text("fastapi\n")
77
+
78
+ with pytest.raises(ValueError, match="entrypoint"):
79
+ FastAPIAdapter.plan(_function(), tmp_path)
@@ -0,0 +1,4 @@
1
+ def test_import():
2
+ import verulla_manifest
3
+
4
+ assert verulla_manifest.__version__
@@ -0,0 +1,193 @@
1
+ """Tests for the verulla.yml manifest model (Task 3.1)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import pytest
6
+ from pydantic import ValidationError
7
+
8
+ from verulla_manifest import (
9
+ FunctionSpec,
10
+ Limits,
11
+ Manifest,
12
+ RouteSpec,
13
+ load_manifest,
14
+ parse_yaml,
15
+ )
16
+
17
+ VALID_YAML = """
18
+ version: 1
19
+ app: mysite
20
+ functions:
21
+ - name: web
22
+ src: ./
23
+ runtime: auto
24
+ limits: {cpu: 250m, memory: 256Mi, timeout_s: 30}
25
+ routes:
26
+ - path: /
27
+ function: web
28
+ """
29
+
30
+
31
+ def test_valid_example_parses():
32
+ m = parse_yaml(VALID_YAML)
33
+ assert isinstance(m, Manifest)
34
+ assert m.version == 1
35
+ assert m.app == "mysite"
36
+ assert [f.name for f in m.functions] == ["web"]
37
+ assert m.functions[0].src == "./"
38
+ assert m.functions[0].runtime == "auto"
39
+ assert m.functions[0].limits.cpu == "250m"
40
+ assert m.functions[0].limits.memory == "256Mi"
41
+ assert m.functions[0].limits.timeout_s == 30
42
+ assert m.routes[0].path == "/"
43
+ assert m.routes[0].function == "web"
44
+
45
+
46
+ def test_defaults_are_sane():
47
+ f = FunctionSpec(name="web")
48
+ assert f.src == "./"
49
+ assert f.runtime == "auto"
50
+ assert f.limits.cpu == "250m"
51
+ assert f.limits.memory == "256Mi"
52
+ assert f.limits.timeout_s == 60
53
+
54
+
55
+ @pytest.mark.parametrize(
56
+ "src",
57
+ [
58
+ "/etc",
59
+ "C:\\outside",
60
+ "\\rooted",
61
+ "../outside",
62
+ "nested/../outside",
63
+ "nested\\..\\outside",
64
+ "./nested/../../outside",
65
+ ],
66
+ )
67
+ def test_function_src_rejects_absolute_and_parent_components(src):
68
+ with pytest.raises(ValidationError):
69
+ FunctionSpec(name="web", src=src)
70
+
71
+
72
+ def test_function_src_accepts_nested_relative_path():
73
+ assert FunctionSpec(name="web", src="packages/web").src == "packages/web"
74
+
75
+
76
+ def test_minimal_yaml_uses_defaults():
77
+ text = (
78
+ "version: 1\n"
79
+ "app: mysite\n"
80
+ "functions:\n"
81
+ " - name: web\n"
82
+ "routes:\n"
83
+ " - path: /\n"
84
+ " function: web\n"
85
+ )
86
+ m = parse_yaml(text)
87
+ assert m.functions[0].src == "./"
88
+ assert m.functions[0].limits.timeout_s == 60
89
+
90
+
91
+ def test_unknown_top_level_key_rejected():
92
+ with pytest.raises(ValidationError):
93
+ parse_yaml(VALID_YAML + "extra: nope\n")
94
+
95
+
96
+ def test_unknown_function_key_rejected():
97
+ text = VALID_YAML.replace("runtime: auto", "runtime: auto\n bogus: 1")
98
+ with pytest.raises(ValidationError):
99
+ parse_yaml(text)
100
+
101
+
102
+ def test_route_referencing_missing_function_rejected():
103
+ text = VALID_YAML.replace("function: web", "function: ghost")
104
+ with pytest.raises(ValidationError) as exc:
105
+ parse_yaml(text)
106
+ assert "ghost" in str(exc.value)
107
+
108
+
109
+ def test_route_path_must_start_with_slash():
110
+ text = VALID_YAML.replace("path: /", "path: index")
111
+ with pytest.raises(ValidationError):
112
+ parse_yaml(text)
113
+
114
+
115
+ def test_parse_yaml_non_mapping_string_raises():
116
+ with pytest.raises(ValueError):
117
+ parse_yaml("just a string")
118
+
119
+
120
+ def test_parse_yaml_top_level_list_raises():
121
+ with pytest.raises(ValueError):
122
+ parse_yaml("- a\n- b\n")
123
+
124
+
125
+ def test_load_manifest_reads_file(tmp_path):
126
+ p = tmp_path / "verulla.yml"
127
+ p.write_text(VALID_YAML, encoding="utf-8")
128
+ m = load_manifest(p)
129
+ assert m.app == "mysite"
130
+ assert m.functions[0].name == "web"
131
+
132
+
133
+ def test_bad_function_name_rejected():
134
+ with pytest.raises(ValidationError):
135
+ FunctionSpec(name="Bad Name")
136
+
137
+
138
+ def test_limits_timeout_bounds():
139
+ # Manifest-level bounds are 1..3600; tier caps live in control/runtime/timeouts.py.
140
+ assert Limits(timeout_s=1).timeout_s == 1
141
+ assert Limits(timeout_s=3600).timeout_s == 3600
142
+ with pytest.raises(ValidationError):
143
+ Limits(timeout_s=0)
144
+ with pytest.raises(ValidationError):
145
+ Limits(timeout_s=3601)
146
+
147
+
148
+ def test_empty_functions_rejected():
149
+ text = VALID_YAML.replace(
150
+ "functions:\n - name: web\n src: ./\n runtime: auto\n limits: {cpu: 250m, memory: 256Mi, timeout_s: 30}",
151
+ "functions: []",
152
+ )
153
+ with pytest.raises(ValidationError):
154
+ parse_yaml(text)
155
+
156
+
157
+ def test_function_route_and_env_limits_are_bounded():
158
+ too_many_functions = VALID_YAML.replace(
159
+ " - name: web\n src: ./\n runtime: auto\n limits: {cpu: 250m, memory: 256Mi, timeout_s: 30}",
160
+ "\n".join(f" - name: {'web' if i == 0 else f'fn-{i}'}" for i in range(21)),
161
+ )
162
+ with pytest.raises(ValidationError):
163
+ parse_yaml(too_many_functions)
164
+
165
+ too_many_routes = VALID_YAML.replace(
166
+ " - path: /\n function: web",
167
+ "\n".join(f" - path: /{i}\n function: web" for i in range(101)),
168
+ )
169
+ with pytest.raises(ValidationError, match="at most 100"):
170
+ parse_yaml(too_many_routes)
171
+
172
+ too_many_env = VALID_YAML + "env:\n" + "".join(f" KEY_{i}: value\n" for i in range(65))
173
+ with pytest.raises(ValidationError, match="at most 64"):
174
+ parse_yaml(too_many_env)
175
+
176
+
177
+ def test_bad_app_name_rejected():
178
+ text = VALID_YAML.replace("app: mysite", "app: AB")
179
+ with pytest.raises(ValidationError):
180
+ parse_yaml(text)
181
+
182
+
183
+ def test_version_must_be_one():
184
+ text = VALID_YAML.replace("version: 1", "version: 2")
185
+ with pytest.raises(ValidationError):
186
+ parse_yaml(text)
187
+
188
+
189
+ def test_route_spec_shape():
190
+ r = RouteSpec(path="/api", function="web")
191
+ assert r.path == "/api"
192
+ with pytest.raises(ValidationError):
193
+ RouteSpec(path="api", function="web")
@@ -0,0 +1,68 @@
1
+ """Tests for NodeAdapter.plan() (M3 T3.4)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from pathlib import Path
7
+
8
+ import pytest
9
+
10
+ from verulla_manifest.adapters.node import NodeAdapter
11
+ from verulla_manifest.build_plan import BuildPlan
12
+ from verulla_manifest.model import FunctionSpec
13
+
14
+
15
+ def _function() -> FunctionSpec:
16
+ return FunctionSpec(name="web", src="./")
17
+
18
+
19
+ class TestNodeAdapterPlan:
20
+ def test_scripts_start_no_lock_file(self, tmp_path: Path) -> None:
21
+ (tmp_path / "package.json").write_text(
22
+ json.dumps({"scripts": {"start": "node server.js"}})
23
+ )
24
+
25
+ plan = NodeAdapter.plan(_function(), tmp_path)
26
+
27
+ assert isinstance(plan, BuildPlan)
28
+ assert plan.base_image == "node:20-slim"
29
+ assert plan.build_steps == ["npm install --omit=dev"]
30
+ assert plan.run_cmd == ["npm", "start"]
31
+ assert plan.port == 8080
32
+
33
+ def test_scripts_start_with_lock_file_uses_npm_ci(self, tmp_path: Path) -> None:
34
+ (tmp_path / "package.json").write_text(
35
+ json.dumps({"scripts": {"start": "node server.js"}})
36
+ )
37
+ (tmp_path / "package-lock.json").write_text("{}\n")
38
+
39
+ plan = NodeAdapter.plan(_function(), tmp_path)
40
+
41
+ assert plan.build_steps == ["npm ci --omit=dev"]
42
+
43
+ def test_main_field_no_start_script(self, tmp_path: Path) -> None:
44
+ (tmp_path / "package.json").write_text(json.dumps({"main": "server.js"}))
45
+
46
+ plan = NodeAdapter.plan(_function(), tmp_path)
47
+
48
+ assert plan.run_cmd == ["node", "server.js"]
49
+
50
+ def test_index_js_fallback(self, tmp_path: Path) -> None:
51
+ (tmp_path / "package.json").write_text(json.dumps({}))
52
+ (tmp_path / "index.js").write_text("console.log('hi');\n")
53
+
54
+ plan = NodeAdapter.plan(_function(), tmp_path)
55
+
56
+ assert plan.run_cmd == ["node", "index.js"]
57
+
58
+ def test_no_start_command_found_raises_value_error(self, tmp_path: Path) -> None:
59
+ (tmp_path / "package.json").write_text(json.dumps({}))
60
+
61
+ with pytest.raises(ValueError, match="start command"):
62
+ NodeAdapter.plan(_function(), tmp_path)
63
+
64
+ def test_invalid_json_raises_value_error(self, tmp_path: Path) -> None:
65
+ (tmp_path / "package.json").write_text("{not valid json")
66
+
67
+ with pytest.raises(ValueError, match="JSON"):
68
+ NodeAdapter.plan(_function(), tmp_path)