unity-devkit 0.3.4.dev252__tar.gz → 0.3.5__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 (26) hide show
  1. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/PKG-INFO +1 -1
  2. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/pyproject.toml +2 -1
  3. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/src/unity_devkit/build_unity.py +1 -11
  4. unity_devkit-0.3.5/src/unity_devkit/check_unity_lock.py +68 -0
  5. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/src/unity_devkit/matrix.py +10 -4
  6. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/src/unity_devkit/player_build.py +58 -36
  7. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/src/unity_devkit/projects.py +28 -8
  8. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/tests/test_build_player.py +65 -17
  9. unity_devkit-0.3.5/tests/test_check_unity_lock.py +144 -0
  10. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/tests/test_matrix.py +20 -5
  11. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/tests/test_projects.py +37 -7
  12. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/.gitignore +0 -0
  13. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/src/unity_devkit/__init__.py +0 -0
  14. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/src/unity_devkit/compile_check_unity.py +0 -0
  15. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/src/unity_devkit/identity.py +0 -0
  16. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/src/unity_devkit/install.py +0 -0
  17. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/src/unity_devkit/license.py +0 -0
  18. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/src/unity_devkit/license_restore.py +0 -0
  19. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/src/unity_devkit/lock_unity.py +0 -0
  20. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/src/unity_devkit/py.typed +0 -0
  21. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/src/unity_devkit/test_unity.py +0 -0
  22. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/src/unity_devkit/upm_cache.py +0 -0
  23. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/tests/test_identity.py +0 -0
  24. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/tests/test_prepare.py +0 -0
  25. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/tests/test_run_unity_batchmode.py +0 -0
  26. {unity_devkit-0.3.4.dev252 → unity_devkit-0.3.5}/tests/test_upm_cache.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: unity-devkit
3
- Version: 0.3.4.dev252
3
+ Version: 0.3.5
4
4
  Summary: Unity build, license, and CI tooling
5
5
  Requires-Python: >=3.13
6
6
  Requires-Dist: bashrun>=0.1.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "unity-devkit"
3
- version = "0.3.4.dev252"
3
+ version = "0.3.5"
4
4
  description = "Unity build, license, and CI tooling"
5
5
  requires-python = ">=3.13"
6
6
  dependencies = [
@@ -15,6 +15,7 @@ dependencies = [
15
15
  activate-unity-license = "unity_devkit.license:activate_app"
16
16
  build-unity = "unity_devkit.build_unity:app"
17
17
  build-unity-matrix = "unity_devkit.matrix:build_app"
18
+ check-unity-lock = "unity_devkit.check_unity_lock:app"
18
19
  compile-check-unity = "unity_devkit.compile_check_unity:app"
19
20
  compile-check-unity-matrix = "unity_devkit.matrix:compile_check_app"
20
21
  install = "unity_devkit.install:app"
@@ -12,7 +12,7 @@ from build_artifact_registry.cache import restore, save
12
12
  from build_artifact_registry.setup_oras import install_oras
13
13
  from .identity import builds_registry, cache_key, cache_registry
14
14
  from .license_restore import restore_or_activate_license
15
- from .player_build import build_player, parse_environment_fields, resolve_unity_project
15
+ from .player_build import build_player, resolve_unity_project
16
16
  from .upm_cache import restore_upm_cache, save_upm_cache
17
17
 
18
18
  app = typer.Typer(add_completion=False, pretty_exceptions_show_locals=False)
@@ -47,15 +47,7 @@ def build_unity(
47
47
  ),
48
48
  ] = "",
49
49
  development: Annotated[bool, typer.Option("--development", help="Development build column")] = False,
50
- environment_preset: Annotated[
51
- str, typer.Option(help="Environment preset name; empty leaves the workspace untouched")
52
- ] = "",
53
- environment_field: Annotated[
54
- list[str] | None,
55
- typer.Option("--environment-field", help="Environment field override as path=value (repeatable)"),
56
- ] = None,
57
50
  ) -> None:
58
- fields = parse_environment_fields(environment_field or [])
59
51
  parsed_pr_number = int(pr_number) if pr_number else None
60
52
  derived_cache_key = cache_key(project, platform, parsed_pr_number)
61
53
  library_cache_registry = cache_registry(registry)
@@ -80,8 +72,6 @@ def build_unity(
80
72
  version=version,
81
73
  commit_count=commit_count,
82
74
  development=development,
83
- environment_preset=environment_preset,
84
- environment_fields=fields,
85
75
  )
86
76
  for artifact in artifacts:
87
77
  print(f"Built: {artifact}")
@@ -0,0 +1,68 @@
1
+ import json
2
+ from pathlib import Path
3
+ from typing import Annotated, Any
4
+
5
+ import typer
6
+
7
+ from .projects import discover_projects
8
+
9
+ app = typer.Typer(add_completion=False, pretty_exceptions_show_locals=False)
10
+
11
+
12
+ @app.command()
13
+ def check_unity_lock(project: Annotated[str | None, typer.Option(help="Limit to a specific project.")] = None) -> None:
14
+ config = discover_projects()
15
+
16
+ if project is not None and project not in config:
17
+ raise typer.BadParameter(f"Unknown project '{project}'. Valid: {', '.join(config)}")
18
+
19
+ projects = {project: config[project]} if project else config
20
+ failures: list[str] = []
21
+
22
+ for name, project_config in projects.items():
23
+ print(f"Checking {name} ({project_config.path / 'Packages' / 'packages-lock.json'})...")
24
+ failures.extend(check_project_lock(name, project_config.path))
25
+
26
+ if failures:
27
+ for failure in failures:
28
+ print(f" {failure}")
29
+
30
+ raise SystemExit(
31
+ "packages-lock.json disagrees with Packages/manifest.json — run 'uv run lock-unity' "
32
+ "to regenerate the lock, then commit it."
33
+ )
34
+
35
+ print("Every packages-lock.json agrees with its manifest.")
36
+
37
+
38
+ def check_project_lock(name: str, project_path: Path) -> list[str]:
39
+ packages_directory = project_path / "Packages"
40
+ manifest_path = packages_directory / "manifest.json"
41
+ lock_path = packages_directory / "packages-lock.json"
42
+
43
+ if not manifest_path.is_file():
44
+ return [f"{name}: {manifest_path} does not exist"]
45
+
46
+ if not lock_path.is_file():
47
+ return [f"{name}: {lock_path} does not exist — run 'uv run lock-unity' to generate it."]
48
+
49
+ try:
50
+ manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
51
+ lock = json.loads(lock_path.read_text(encoding="utf-8"))
52
+ except json.JSONDecodeError as error:
53
+ return [f"{name}: unparseable manifest/lock JSON: {error.msg} at line {error.lineno}"]
54
+
55
+ requirements: dict[str, Any] = manifest.get("dependencies", {})
56
+ locked: dict[str, Any] = lock.get("dependencies", {})
57
+
58
+ failures: list[str] = []
59
+
60
+ for package, requirement in sorted(requirements.items()):
61
+ entry = locked.get(package)
62
+
63
+ if entry is None:
64
+ failures.append(f"{name}: '{package}' ({requirement}) is absent from packages-lock.json")
65
+ elif entry.get("version") != requirement:
66
+ failures.append(f"{name}: '{package}' manifest wants {requirement}, lock recorded {entry.get('version')}")
67
+
68
+ return failures
@@ -5,7 +5,13 @@ from typing import Annotated
5
5
 
6
6
  import typer
7
7
 
8
- from .player_build import LICENSE_IMAGE_MODULE, PLATFORM_CONFIGS, UNITYCI_IMAGE_REVISION, read_editor_version
8
+ from .player_build import (
9
+ LICENSE_IMAGE_MODULE,
10
+ UNITYCI_IMAGE_REVISION,
11
+ platform_build_target,
12
+ read_editor_version,
13
+ unityci_image_module,
14
+ )
9
15
  from .projects import ProjectEntry, discover_projects
10
16
 
11
17
  build_app = typer.Typer(add_completion=False, pretty_exceptions_show_locals=False)
@@ -22,11 +28,11 @@ def build_matrix(
22
28
  matrix: list[dict[str, str]] = []
23
29
 
24
30
  for name, entry in projects.items():
25
- if not entry.builds:
31
+ if not entry.platforms:
26
32
  continue
27
33
  version = read_editor_version(entry.path)
28
- for platform in entry.builds:
29
- image_module = PLATFORM_CONFIGS[platform]["unityci_image_module"]
34
+ for platform in entry.platforms:
35
+ image_module = unityci_image_module(platform_build_target(platform))
30
36
  matrix.append({
31
37
  "project": name,
32
38
  "platform": platform,
@@ -6,28 +6,36 @@ import sys
6
6
  import tempfile
7
7
  from collections.abc import Sequence
8
8
  from pathlib import Path
9
- from typing import TypedDict
10
9
 
11
10
  from bashrun.bash import CalledProcessError, bash, bash_pipe
12
11
 
13
12
  from .projects import ProjectEntry, discover_projects
14
13
 
15
14
 
16
- class PlatformConfig(TypedDict):
17
- build_target: str
18
- unityci_image_module: str
19
-
15
+ UNITYCI_IMAGE_MODULES: dict[str, str] = {
16
+ "Android": "android",
17
+ "StandaloneLinux64": "linux-il2cpp",
18
+ "Win64": "windows-mono",
19
+ }
20
20
 
21
- PLATFORM_CONFIGS: dict[str, PlatformConfig] = {
22
- "AndroidMobile": {"build_target": "Android", "unityci_image_module": "android"},
23
- "MagicLeap2": {"build_target": "Android", "unityci_image_module": "android"},
24
- "Linux": {"build_target": "StandaloneLinux64", "unityci_image_module": "linux-il2cpp"},
25
- "Windows": {"build_target": "Win64", "unityci_image_module": "windows-mono"},
21
+ PLATFORM_BUILD_TARGETS: dict[str, str] = {
22
+ "AndroidMobile": "Android",
23
+ "MagicLeap2": "Android",
26
24
  }
27
25
 
28
26
  UNITYCI_IMAGE_REVISION = "3"
29
27
  LICENSE_IMAGE_MODULE = "linux-il2cpp"
30
- PLAYERBUILD_ENTRY = "Outernet.PlayerBuild.Entry"
28
+
29
+
30
+ def platform_build_target(platform: str) -> str:
31
+ build_target = PLATFORM_BUILD_TARGETS.get(platform)
32
+ if build_target is None:
33
+ raise SystemExit(
34
+ f"No build target known for platform '{platform}' — add it to PLATFORM_BUILD_TARGETS "
35
+ "beside the matching SharedSpecs factory"
36
+ )
37
+ return build_target
38
+
31
39
 
32
40
  # Pinned to the v2026.07.21 tag of dotnet/install-scripts (raw at the commit SHA, which
33
41
  # is immutable, unlike the moving https://dot.net/v1/dotnet-install.sh redirect).
@@ -222,17 +230,13 @@ def prepare_unity_project(project_path: Path) -> None:
222
230
  bash(f"dotnet nugetforunity restore {project_path}", env=env)
223
231
 
224
232
 
225
- def parse_environment_fields(entries: Sequence[str]) -> dict[str, str]:
226
- fields: dict[str, str] = {}
227
- for entry in entries:
228
- line = entry.strip()
229
- if not line:
230
- continue
231
- path, separator, value = line.partition("=")
232
- if not separator or not path:
233
- raise SystemExit(f"Invalid environment field entry (expected path=value): {entry!r}")
234
- fields[path] = value
235
- return fields
233
+ def unityci_image_module(build_target: str) -> str:
234
+ module = UNITYCI_IMAGE_MODULES.get(build_target)
235
+ if module is None:
236
+ raise SystemExit(
237
+ f"Unknown build target '{build_target}' — supported: {', '.join(sorted(UNITYCI_IMAGE_MODULES))}"
238
+ )
239
+ return module
236
240
 
237
241
 
238
242
  def build_player(
@@ -242,22 +246,23 @@ def build_player(
242
246
  version: str = "",
243
247
  commit_count: int = 0,
244
248
  development: bool = False,
245
- environment_preset: str = "",
246
- environment_fields: dict[str, str] | None = None,
247
249
  ) -> list[Path]:
248
250
  project_config = resolve_unity_project(project)
249
- valid_builds = project_config.builds or []
250
- if not valid_builds:
251
+ platforms = project_config.platforms
252
+ if not platforms:
251
253
  raise SystemExit(
252
254
  f"Project '{project}' declares no builds — add platform keys to its unity-devkit.json 'platforms' map"
253
255
  )
254
- if build not in valid_builds:
255
- raise SystemExit(f"Unknown build '{build}' for project '{project}'. Valid: {', '.join(valid_builds)}")
256
- if build not in PLATFORM_CONFIGS:
257
- raise SystemExit(f"No platform config for build '{build}'. Valid: {', '.join(PLATFORM_CONFIGS)}")
256
+ if build not in platforms:
257
+ raise SystemExit(f"Unknown build '{build}' for project '{project}'. Valid: {', '.join(sorted(platforms))}")
258
258
 
259
259
  project_path = project_config.path
260
- build_target = PLATFORM_CONFIGS[build]["build_target"]
260
+ build_target = platform_build_target(build)
261
+ entry = project_config.entry
262
+ if not entry:
263
+ raise SystemExit(
264
+ f"Project '{project}' declares platforms but no 'entry' executeMethod in its unity-devkit.json"
265
+ )
261
266
  prepare_unity_project(project_path)
262
267
 
263
268
  if version:
@@ -273,17 +278,15 @@ def build_player(
273
278
  before = snapshot_artifacts(build_directory)
274
279
 
275
280
  env: dict[str, str] = {"PLATFORM": build, "DEVELOPMENT": "true" if development else "false"}
276
- if environment_preset:
277
- env["ENVIRONMENT"] = environment_preset
278
- if environment_fields:
279
- env["ENVIRONMENT_FIELDS"] = json.dumps(environment_fields)
280
281
  run_unity_batchmode(
281
282
  project_path,
282
- f"-buildTarget {build_target} -executeMethod {PLAYERBUILD_ENTRY}",
283
+ f"-buildTarget {build_target} -executeMethod {entry}",
283
284
  nographics=False,
284
285
  env=env,
285
286
  )
286
287
 
288
+ verify_platform_record(project_path, build, development)
289
+
287
290
  after = snapshot_artifacts(build_directory)
288
291
  produced = sorted(path for path, modification_time in after.items() if before.get(path) != modification_time)
289
292
  if not produced:
@@ -295,6 +298,25 @@ def build_player(
295
298
  return produced
296
299
 
297
300
 
301
+ def verify_platform_record(project_path: Path, build: str, development: bool) -> None:
302
+ record_path = project_path / "Assets" / "_LocalWorkspace" / "platform.json"
303
+ if not record_path.is_file():
304
+ raise SystemExit(
305
+ f"No platform record at {record_path} — the project entry never ran the playerbuild Apply step"
306
+ )
307
+ record = json.loads(record_path.read_text(encoding="utf-8"))
308
+ if record.get("platform") != build:
309
+ raise SystemExit(
310
+ f"Platform record says '{record.get('platform')}' but '{build}' was requested — "
311
+ "the entry applied the wrong spec"
312
+ )
313
+ if record.get("development") != development:
314
+ raise SystemExit(
315
+ f"Platform record says development={record.get('development')} but the build ran "
316
+ f"with development={development}"
317
+ )
318
+
319
+
298
320
  def replace_serialized_field(text: str, field_name: str, value: str) -> str:
299
321
  pattern = re.compile(rf"^(?P<indent>[ \t]*){field_name}:.*$", re.MULTILINE)
300
322
  rewritten, count = pattern.subn(lambda match: f"{match.group('indent')}{field_name}: {value}", text)
@@ -1,20 +1,27 @@
1
1
  import os
2
2
  from collections.abc import Iterator
3
3
  from pathlib import Path
4
- from typing import Any
4
+ from typing import Self
5
5
 
6
- from pydantic import BaseModel, ConfigDict, field_validator
6
+ from pydantic import BaseModel, ConfigDict, field_validator, model_validator
7
7
 
8
8
  BUILD_CONFIG_FILENAME = "unity-devkit.json"
9
9
  PROJECT_MARKER = Path("ProjectSettings") / "ProjectVersion.txt"
10
10
  PRUNE_DIRECTORIES = {".git", "Library", "Temp", "obj", "Build", "node_modules", "__pycache__"}
11
11
 
12
12
 
13
+ class PlatformConfig(BaseModel):
14
+ model_config = ConfigDict(extra="forbid")
15
+
16
+ render_pipeline: str = ""
17
+
18
+
13
19
  class BuildConfigFile(BaseModel):
14
- model_config = ConfigDict(extra="ignore")
20
+ model_config = ConfigDict(extra="forbid")
15
21
 
16
22
  name: str
17
- platforms: dict[str, Any] | None = None
23
+ entry: str | None = None
24
+ platforms: dict[str, PlatformConfig] | None = None
18
25
 
19
26
  @field_validator("name")
20
27
  @classmethod
@@ -23,10 +30,24 @@ class BuildConfigFile(BaseModel):
23
30
  raise ValueError("unity-devkit.json 'name' must be a non-empty string")
24
31
  return value
25
32
 
33
+ @model_validator(mode="after")
34
+ def entry_required_with_platforms(self) -> Self:
35
+ if self.platforms and not self.entry:
36
+ raise ValueError(
37
+ "unity-devkit.json declares 'platforms' — an 'entry' executeMethod is required "
38
+ "(a public static parameterless method the build invokes)"
39
+ )
40
+ return self
41
+
26
42
 
27
43
  class ProjectEntry(BaseModel):
28
44
  path: Path
29
- builds: list[str] | None = None
45
+ entry: str | None = None
46
+ platforms: dict[str, PlatformConfig] | None = None
47
+
48
+ @property
49
+ def builds(self) -> list[str] | None:
50
+ return list(self.platforms) if self.platforms else None
30
51
 
31
52
 
32
53
  def discover_projects() -> dict[str, ProjectEntry]:
@@ -49,14 +70,13 @@ def discover_projects() -> dict[str, ProjectEntry]:
49
70
  f"and previously at {first_seen[parsed.name]}"
50
71
  )
51
72
  first_seen[parsed.name] = config_path
52
- builds = list(parsed.platforms.keys()) if parsed.platforms else None
53
- discovered[parsed.name] = ProjectEntry(path=directory, builds=builds)
73
+ discovered[parsed.name] = ProjectEntry(path=directory, entry=parsed.entry, platforms=parsed.platforms)
54
74
 
55
75
  if not discovered:
56
76
  raise SystemExit(
57
77
  f"No {BUILD_CONFIG_FILENAME} found under {root} — declare Unity projects with a "
58
78
  f"{BUILD_CONFIG_FILENAME} per project root (carrying a 'name' field; 'platforms' "
59
- f"keys are the build targets)"
79
+ "keys are the build targets)"
60
80
  )
61
81
  return discovered
62
82
 
@@ -2,6 +2,7 @@ import json
2
2
  from pathlib import Path
3
3
 
4
4
  import pytest
5
+ from pydantic import ValidationError
5
6
 
6
7
  from unity_devkit import player_build
7
8
 
@@ -23,6 +24,7 @@ def write_repository(tmp_path: Path, project_settings: str, *, builds: list[str]
23
24
  (project / "ProjectSettings" / "ProjectVersion.txt").write_text("m_EditorVersion: 6000.0.66f1\n")
24
25
  config: dict[str, object] = {"name": "tool"}
25
26
  if builds is not None:
27
+ config["entry"] = "Outernet.Tool.Entry"
26
28
  config["platforms"] = {platform: {} for platform in builds}
27
29
  (project / "unity-devkit.json").write_text(json.dumps(config))
28
30
  return project
@@ -33,10 +35,20 @@ def fake_unity_build_producing(project_path: Path, extra_flags: str, *, nographi
33
35
  build_directory = project_path / "Build"
34
36
  build_directory.mkdir(exist_ok=True)
35
37
  (build_directory / "Tool.apk").write_bytes(b"apk")
38
+ record_directory = project_path / "Assets" / "_LocalWorkspace"
39
+ record_directory.mkdir(parents=True, exist_ok=True)
40
+ (record_directory / "platform.json").write_text(
41
+ json.dumps({"platform": env["PLATFORM"], "development": env["DEVELOPMENT"] == "true"})
42
+ )
36
43
  return Path("unused-editor.log")
37
44
 
38
45
 
39
46
  def fake_unity_build_silent(project_path: Path, extra_flags: str, *, nographics: bool, env: dict[str, str]) -> Path:
47
+ record_directory = project_path / "Assets" / "_LocalWorkspace"
48
+ record_directory.mkdir(parents=True, exist_ok=True)
49
+ (record_directory / "platform.json").write_text(
50
+ json.dumps({"platform": env["PLATFORM"], "development": env["DEVELOPMENT"] == "true"})
51
+ )
40
52
  return Path("unused-editor.log")
41
53
 
42
54
 
@@ -53,7 +65,7 @@ def test_build_player_stamps_version_and_returns_artifacts(tmp_path: Path, monke
53
65
  assert " bundleVersion: 0.2.7-dev+42\n" in rewritten
54
66
  assert "0.1.0" not in rewritten
55
67
  assert produced == [project / "Build" / "Tool.apk"]
56
- assert RECEIVED_SESSIONS[0][0] == "-buildTarget Android -executeMethod Outernet.PlayerBuild.Entry"
68
+ assert RECEIVED_SESSIONS[0][0] == "-buildTarget Android -executeMethod Outernet.Tool.Entry"
57
69
 
58
70
 
59
71
  def test_build_player_appends_the_commit_count_to_an_opaque_version_base(
@@ -115,11 +127,58 @@ def test_unknown_build_fails(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) ->
115
127
  player_build.build_player("tool", "win64")
116
128
 
117
129
 
118
- def test_build_without_platform_config_fails(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
119
- write_repository(tmp_path, PROJECT_SETTINGS, builds=["AndroidMobile", "SteamDeck"])
130
+ def test_platform_record_mismatch_fails(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
131
+ write_repository(tmp_path, PROJECT_SETTINGS, builds=["AndroidMobile"])
132
+
133
+ def fake_wrong_platform(project_path: Path, extra_flags: str, *, nographics: bool, env: dict[str, str]) -> Path:
134
+ build_directory = project_path / "Build"
135
+ build_directory.mkdir(exist_ok=True)
136
+ (build_directory / "Tool.apk").write_bytes(b"apk")
137
+ record_directory = project_path / "Assets" / "_LocalWorkspace"
138
+ record_directory.mkdir(parents=True, exist_ok=True)
139
+ (record_directory / "platform.json").write_text(json.dumps({"platform": "MagicLeap2", "development": False}))
140
+ return Path("unused-editor.log")
141
+
142
+ monkeypatch.chdir(tmp_path)
143
+ monkeypatch.setattr(player_build, "run_unity_batchmode", fake_wrong_platform)
144
+
145
+ with pytest.raises(SystemExit, match="wrong spec"):
146
+ player_build.build_player("tool", "AndroidMobile")
147
+
148
+
149
+ def test_missing_platform_record_fails(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
150
+ write_repository(tmp_path, PROJECT_SETTINGS, builds=["AndroidMobile"])
120
151
  monkeypatch.chdir(tmp_path)
121
152
 
122
- with pytest.raises(SystemExit, match="No platform config for build 'SteamDeck'"):
153
+ def fake_no_record(project_path: Path, extra_flags: str, *, nographics: bool, env: dict[str, str]) -> Path:
154
+ build_directory = project_path / "Build"
155
+ build_directory.mkdir(exist_ok=True)
156
+ (build_directory / "Tool.apk").write_bytes(b"apk")
157
+ return Path("unused-editor.log")
158
+
159
+ monkeypatch.setattr(player_build, "run_unity_batchmode", fake_no_record)
160
+
161
+ with pytest.raises(SystemExit, match="platform record"):
162
+ player_build.build_player("tool", "AndroidMobile")
163
+
164
+
165
+ def test_build_without_entry_fails(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
166
+ project = tmp_path / "apps" / "Tool"
167
+ (project / "ProjectSettings").mkdir(parents=True)
168
+ (project / "ProjectSettings" / "ProjectSettings.asset").write_text(PROJECT_SETTINGS)
169
+ (project / "ProjectSettings" / "ProjectVersion.txt").write_text("m_EditorVersion: 6000.0.66f1\n")
170
+ (project / "unity-devkit.json").write_text(json.dumps({"name": "tool", "platforms": {"AndroidMobile": {}}}))
171
+ monkeypatch.chdir(tmp_path)
172
+
173
+ with pytest.raises(ValidationError, match="entry"):
174
+ player_build.build_player("tool", "AndroidMobile")
175
+
176
+
177
+ def test_platform_without_known_build_target_fails(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
178
+ write_repository(tmp_path, PROJECT_SETTINGS, builds=["SteamDeck"])
179
+ monkeypatch.chdir(tmp_path)
180
+
181
+ with pytest.raises(SystemExit, match="No build target known for platform 'SteamDeck'"):
123
182
  player_build.build_player("tool", "SteamDeck")
124
183
 
125
184
 
@@ -129,20 +188,9 @@ def test_build_player_environment_carries_the_entry_contract(tmp_path: Path, mon
129
188
  monkeypatch.chdir(tmp_path)
130
189
  monkeypatch.setattr(player_build, "run_unity_batchmode", fake_unity_build_producing)
131
190
 
132
- player_build.build_player(
133
- "tool",
134
- "AndroidMobile",
135
- development=True,
136
- environment_preset="airgapped",
137
- environment_fields={"localConfig.apiUrl": "http://tool.local"},
138
- )
191
+ player_build.build_player("tool", "AndroidMobile", development=True)
139
192
 
140
- assert RECEIVED_SESSIONS[0][1] == {
141
- "PLATFORM": "AndroidMobile",
142
- "DEVELOPMENT": "true",
143
- "ENVIRONMENT": "airgapped",
144
- "ENVIRONMENT_FIELDS": '{"localConfig.apiUrl": "http://tool.local"}',
145
- }
193
+ assert RECEIVED_SESSIONS[0][1] == {"PLATFORM": "AndroidMobile", "DEVELOPMENT": "true"}
146
194
 
147
195
 
148
196
  def test_build_player_without_environment_sends_platform_and_development_only(
@@ -0,0 +1,144 @@
1
+ import json
2
+ from pathlib import Path
3
+
4
+ import pytest
5
+ import typer
6
+
7
+ from unity_devkit.check_unity_lock import check_project_lock, check_unity_lock
8
+
9
+ MANIFEST = {
10
+ "dependencies": {
11
+ "com.unity.xr.management": "4.5.3",
12
+ "org.outernet.lbetoolkit": "https://github.com/outernet-foundation/lbe-toolkit.git?path=/Core#3783af528365f8dfc98d3fff0f0717fa5e7019",
13
+ }
14
+ }
15
+
16
+ MATCHING_LOCK = {
17
+ "dependencies": {
18
+ "com.unity.xr.management": {"version": "4.5.3", "depth": 0, "source": "registry"},
19
+ "com.unity.mathematics": {"version": "1.3.2", "depth": 1, "source": "registry"},
20
+ "org.outernet.lbetoolkit": {
21
+ "version": "https://github.com/outernet-foundation/lbe-toolkit.git?path=/Core#3783af528365f8dfc98d3fff0f0717fa5e7019",
22
+ "depth": 0,
23
+ "source": "git",
24
+ "hash": "3783af528365f8dfc98d3fff0f0717fa5e7019",
25
+ },
26
+ }
27
+ }
28
+
29
+
30
+ def write_packages(
31
+ tmp_path: Path,
32
+ manifest: str = json.dumps(MANIFEST),
33
+ lock: str | None = json.dumps(MATCHING_LOCK),
34
+ ) -> Path:
35
+ packages = tmp_path / "Packages"
36
+ packages.mkdir(parents=True)
37
+ (packages / "manifest.json").write_text(manifest, encoding="utf-8")
38
+
39
+ if lock is not None:
40
+ (packages / "packages-lock.json").write_text(lock, encoding="utf-8")
41
+
42
+ return tmp_path
43
+
44
+
45
+ def test_matching_lock_reports_nothing(tmp_path: Path) -> None:
46
+ write_packages(tmp_path)
47
+
48
+ assert check_project_lock("tool", tmp_path) == []
49
+
50
+
51
+ def test_ignores_lock_entries_without_manifest_dependencies(tmp_path: Path) -> None:
52
+ assert check_project_lock("tool", write_packages(tmp_path, manifest=json.dumps({"dependencies": {}}))) == []
53
+
54
+
55
+ def test_version_mismatch_is_reported(tmp_path: Path) -> None:
56
+ stale = json.loads(json.dumps(MATCHING_LOCK))
57
+ stale["dependencies"]["org.outernet.lbetoolkit"] = {"version": "1.1.0-dev.39", "depth": 0, "source": "registry"}
58
+ write_packages(tmp_path, lock=json.dumps(stale))
59
+
60
+ failures = check_project_lock("tool", tmp_path)
61
+
62
+ assert len(failures) == 1
63
+ assert "org.outernet.lbetoolkit" in failures[0]
64
+ assert "1.1.0-dev.39" in failures[0]
65
+ assert "3783af528365f8dfc98d3fff0f0717fa5e7019" in failures[0]
66
+
67
+
68
+ def test_manifest_dependency_absent_from_lock_is_reported(tmp_path: Path) -> None:
69
+ stale = json.loads(json.dumps(MATCHING_LOCK))
70
+ del stale["dependencies"]["com.unity.xr.management"]
71
+ write_packages(tmp_path, lock=json.dumps(stale))
72
+
73
+ failures = check_project_lock("tool", tmp_path)
74
+
75
+ assert len(failures) == 1
76
+ assert "com.unity.xr.management" in failures[0]
77
+ assert "4.5.3" in failures[0]
78
+
79
+
80
+ def test_missing_lock_file_is_reported(tmp_path: Path) -> None:
81
+ write_packages(tmp_path, lock=None)
82
+
83
+ failures = check_project_lock("tool", tmp_path)
84
+
85
+ assert len(failures) == 1
86
+ assert "lock-unity" in failures[0]
87
+
88
+
89
+ def test_missing_manifest_is_reported(tmp_path: Path) -> None:
90
+ project = write_packages(tmp_path)
91
+ (project / "Packages" / "manifest.json").unlink()
92
+
93
+ assert check_project_lock("tool", tmp_path) == [f"tool: {project / 'Packages' / 'manifest.json'} does not exist"]
94
+
95
+
96
+ def test_unparseable_lock_is_reported(tmp_path: Path) -> None:
97
+ write_packages(tmp_path, lock="{")
98
+
99
+ failures = check_project_lock("tool", tmp_path)
100
+
101
+ assert len(failures) == 1
102
+ assert "unparseable" in failures[0]
103
+
104
+
105
+ def test_cli_passes_when_every_project_agrees(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
106
+ project = tmp_path / "Tool"
107
+ (project / "ProjectSettings").mkdir(parents=True)
108
+ (project / "ProjectSettings" / "ProjectVersion.txt").write_text("m_EditorVersion: 6000.0.66f1\n")
109
+ (project / "unity-devkit.json").write_text(
110
+ json.dumps({"name": "Tool", "entry": "Outernet.Tool.Entry", "platforms": {"Linux": {}}})
111
+ )
112
+ packages = project / "Packages"
113
+ packages.mkdir()
114
+ (packages / "manifest.json").write_text(json.dumps(MANIFEST), encoding="utf-8")
115
+ (packages / "packages-lock.json").write_text(json.dumps(MATCHING_LOCK), encoding="utf-8")
116
+ monkeypatch.chdir(tmp_path)
117
+
118
+ check_unity_lock(project=None)
119
+
120
+
121
+ def test_cli_exits_non_zero_on_drift(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
122
+ project = tmp_path / "Tool"
123
+ (project / "ProjectSettings").mkdir(parents=True)
124
+ (project / "ProjectSettings" / "ProjectVersion.txt").write_text("m_EditorVersion: 6000.0.66f1\n")
125
+ (project / "unity-devkit.json").write_text(
126
+ json.dumps({"name": "Tool", "entry": "Outernet.Tool.Entry", "platforms": {"Linux": {}}})
127
+ )
128
+ packages = project / "Packages"
129
+ packages.mkdir()
130
+ (packages / "manifest.json").write_text(json.dumps(MANIFEST), encoding="utf-8")
131
+ monkeypatch.chdir(tmp_path)
132
+
133
+ with pytest.raises(SystemExit, match="lock-unity"):
134
+ check_unity_lock(project=None)
135
+
136
+
137
+ def test_cli_rejects_unknown_project(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
138
+ monkeypatch.chdir(tmp_path)
139
+ (tmp_path / "ProjectSettings").mkdir()
140
+ (tmp_path / "ProjectSettings" / "ProjectVersion.txt").write_text("m_EditorVersion: 6000.0.66f1\n")
141
+ (tmp_path / "unity-devkit.json").write_text(json.dumps({"name": "Tool"}))
142
+
143
+ with pytest.raises(typer.BadParameter):
144
+ check_unity_lock(project="other")
@@ -10,7 +10,7 @@ def write_repository(tmp_path: Path, builds: list[str] | None = None) -> None:
10
10
  project = tmp_path / "apps" / "Tool"
11
11
  (project / "ProjectSettings").mkdir(parents=True)
12
12
  (project / "ProjectSettings" / "ProjectVersion.txt").write_text("m_EditorVersion: 6000.0.66f1\n")
13
- config: dict[str, object] = {"name": "tool"}
13
+ config: dict[str, object] = {"name": "tool", "entry": "Outernet.Tool.Entry"}
14
14
  if builds is not None:
15
15
  config["platforms"] = {platform: {} for platform in builds}
16
16
  (project / "unity-devkit.json").write_text(json.dumps(config))
@@ -19,7 +19,7 @@ def write_repository(tmp_path: Path, builds: list[str] | None = None) -> None:
19
19
  def test_matrix_emits_entries_from_catalog(
20
20
  tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
21
21
  ) -> None:
22
- write_repository(tmp_path, builds=["Linux"])
22
+ write_repository(tmp_path, builds=["AndroidMobile"])
23
23
  monkeypatch.chdir(tmp_path)
24
24
 
25
25
  matrix.build_matrix()
@@ -28,8 +28,8 @@ def test_matrix_emits_entries_from_catalog(
28
28
  assert legs == [
29
29
  {
30
30
  "project": "tool",
31
- "platform": "Linux",
32
- "editor-image": "unityci/editor:6000.0.66f1-linux-il2cpp-3",
31
+ "platform": "AndroidMobile",
32
+ "editor-image": "unityci/editor:6000.0.66f1-android-3",
33
33
  }
34
34
  ]
35
35
 
@@ -42,6 +42,19 @@ def test_matrix_fails_without_builds(tmp_path: Path, monkeypatch: pytest.MonkeyP
42
42
  matrix.build_matrix()
43
43
 
44
44
 
45
+ def test_matrix_fails_on_unknown_build_target(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
46
+ project = tmp_path / "apps" / "Tool"
47
+ (project / "ProjectSettings").mkdir(parents=True)
48
+ (project / "ProjectSettings" / "ProjectVersion.txt").write_text("m_EditorVersion: 6000.0.66f1\n")
49
+ (project / "unity-devkit.json").write_text(
50
+ json.dumps({"name": "tool", "entry": "Outernet.Tool.Entry", "platforms": {"SteamDeck": {}}})
51
+ )
52
+ monkeypatch.chdir(tmp_path)
53
+
54
+ with pytest.raises(SystemExit, match="No build target known for platform 'SteamDeck'"):
55
+ matrix.build_matrix()
56
+
57
+
45
58
  def test_matrix_project_filter_scopes_to_one_project(
46
59
  tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
47
60
  ) -> None:
@@ -49,7 +62,9 @@ def test_matrix_project_filter_scopes_to_one_project(
49
62
  other = tmp_path / "apps" / "Other"
50
63
  (other / "ProjectSettings").mkdir(parents=True)
51
64
  (other / "ProjectSettings" / "ProjectVersion.txt").write_text("m_EditorVersion: 6000.0.66f1\n")
52
- (other / "unity-devkit.json").write_text(json.dumps({"name": "other", "platforms": {"Linux": {}}}))
65
+ (other / "unity-devkit.json").write_text(
66
+ json.dumps({"name": "other", "entry": "Outernet.Other.Entry", "platforms": {"AndroidMobile": {}}})
67
+ )
53
68
  monkeypatch.chdir(tmp_path)
54
69
 
55
70
  matrix.build_matrix(project="other")
@@ -22,7 +22,14 @@ def write_build_config(project_dir: Path, config: dict[str, object]) -> Path:
22
22
 
23
23
  def test_discovers_project_with_platforms_keys_as_builds(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
24
24
  project = create_unity_project(tmp_path, "Alpha")
25
- write_build_config(project, {"name": "Alpha", "platforms": {"Linux": {}, "AndroidMobile": {}}})
25
+ write_build_config(
26
+ project,
27
+ {
28
+ "name": "Alpha",
29
+ "entry": "Outernet.Alpha.Entry",
30
+ "platforms": {"Linux": {}, "AndroidMobile": {"render_pipeline": "Assets/Settings/Android.asset"}},
31
+ },
32
+ )
26
33
  monkeypatch.chdir(tmp_path)
27
34
 
28
35
  projects = discover_projects()
@@ -30,6 +37,7 @@ def test_discovers_project_with_platforms_keys_as_builds(tmp_path: Path, monkeyp
30
37
  assert set(projects) == {"Alpha"}
31
38
  assert projects["Alpha"].path == project
32
39
  assert projects["Alpha"].builds == ["Linux", "AndroidMobile"]
40
+ assert projects["Alpha"].entry == "Outernet.Alpha.Entry"
33
41
 
34
42
 
35
43
  def test_name_is_decoupled_from_directory_name(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
@@ -52,6 +60,8 @@ def test_path_only_project_has_no_builds(tmp_path: Path, monkeypatch: pytest.Mon
52
60
 
53
61
  assert set(projects) == {"Harness"}
54
62
  assert projects["Harness"].builds is None
63
+ assert projects["Harness"].entry is None
64
+ assert projects["Harness"].platforms is None
55
65
 
56
66
 
57
67
  def test_no_build_config_found_fails(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
@@ -82,21 +92,41 @@ def test_duplicate_project_name_fails(tmp_path: Path, monkeypatch: pytest.Monkey
82
92
  discover_projects()
83
93
 
84
94
 
85
- def test_ignores_csharp_owned_fields(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
95
+ def test_platforms_without_entry_fails(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
96
+ project = create_unity_project(tmp_path, "App")
97
+ write_build_config(
98
+ project,
99
+ {"name": "App", "platforms": {"AndroidMobile": {"render_pipeline": "Assets/P.asset"}}},
100
+ )
101
+ monkeypatch.chdir(tmp_path)
102
+
103
+ with pytest.raises(ValidationError, match="entry"):
104
+ discover_projects()
105
+
106
+
107
+ def test_unknown_root_field_fails(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
108
+ project = create_unity_project(tmp_path, "App")
109
+ write_build_config(project, {"name": "App", "environment_config": "Assets/App/UnityEnv.cs"})
110
+ monkeypatch.chdir(tmp_path)
111
+
112
+ with pytest.raises(ValidationError, match="environment_config"):
113
+ discover_projects()
114
+
115
+
116
+ def test_unknown_platform_field_fails(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
86
117
  project = create_unity_project(tmp_path, "App")
87
118
  write_build_config(
88
119
  project,
89
120
  {
90
121
  "name": "App",
91
- "environment_config": "Assets/App/UnityEnv.cs",
92
- "platforms": {"AndroidMobile": {"render_pipeline": "Assets/Settings/Android.asset"}},
122
+ "entry": "Outernet.App.Entry",
123
+ "platforms": {"AndroidMobile": {"render_pipeline": "Assets/P.asset", "environment_preset": "airgapped"}},
93
124
  },
94
125
  )
95
126
  monkeypatch.chdir(tmp_path)
96
127
 
97
- projects = discover_projects()
98
-
99
- assert projects["App"].builds == ["AndroidMobile"]
128
+ with pytest.raises(ValidationError, match="environment_preset"):
129
+ discover_projects()
100
130
 
101
131
 
102
132
  def test_missing_name_field_fails(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: