Files
airdef/tools/test_airdef_build.py
T
chexit 11238c4a03
build / mod (push) Failing after 29s
Add dlss to the game build on Windows + NVIDIA RTX with the SDK
tools/airdef.py game always built with --features mods, so an RTX user had
to run the manual cargo line from docs/DLSS-TESTING.md. The feature string
now comes from dlss_build_features(): dlss is added only when the OS is
Windows, a Win32_VideoController name has both NVIDIA and RTX, the DLSS SDK
has include/nvngx*.h and lib/Windows_x86_64/x64 (DLSS_SDK, a repo DLSS/ dir
or %ProgramFiles%\NVIDIA\DLSS), and VULKAN_SDK has Include/vulkan/vulkan.h
(dlss_wgpu's build script needs both SDKs). Otherwise the build stays
mods-only; on Windows + RTX without the SDK it prints how to get v310.9.1
instead of failing. GPU/SDK probe errors mean "no DLSS" and never abort the
build; the HORIZON_DLSS runtime switch is untouched.

Tests: tools/test_airdef_build.py covers non-Windows, no RTX, missing DLSS
SDK, missing Vulkan SDK, the full toolchain, a failed GPU probe, the SDK
layout check and the feature string reaching cargo. python3 tools/airdef.py
game still builds mods-only on macOS (fresh target dir: 3m11s, exit 0).

Co-Authored-By: Kimi Code <noreply@moonshot.ai>
2026-11-21 14:21:20 +03:00

137 lines
6.2 KiB
Python

"""Real Git migration regression; no network, user settings or player data."""
import contextlib
import importlib.util
import io
import os
from pathlib import Path
import subprocess
import tempfile
import unittest
from unittest.mock import patch
SPEC = importlib.util.spec_from_file_location("airdef_build", Path(__file__).with_name("airdef.py"))
airdef = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(airdef)
def git(at, *args):
return subprocess.check_output(["git", "-C", str(at), *args], text=True, stderr=subprocess.STDOUT).strip()
def init(at):
at.mkdir()
git(at, "init", "-q")
git(at, "config", "user.name", "Test")
git(at, "config", "user.email", "test@example.invalid")
def commit(at, text):
(at / "engine.txt").write_text(text)
git(at, "add", "engine.txt")
git(at, "commit", "-qm", text)
return git(at, "rev-parse", "HEAD")
class ForkMigrationTests(unittest.TestCase):
def test_stale_local_url_is_synced_before_fetching_new_pin(self):
with tempfile.TemporaryDirectory(prefix="airdef-fork-test-") as tmp, patch.dict(os.environ, {"GIT_ALLOW_PROTOCOL": "file"}):
root = Path(tmp)
source, parent = root / "source", root / "airdef"
init(source)
old = commit(source, "old")
canonical = root / "canonical.git"
git(root, "clone", "--bare", str(source), str(canonical))
init(parent)
git(parent, "submodule", "add", str(canonical), "horizon")
child = parent / "horizon"
new = commit(source, "new-fork-only-pin")
git(source, "push", str(canonical), "HEAD")
git(parent, "update-index", "--cacheinfo", f"160000,{new},horizon")
stale = str(root / "missing-upstream.git")
git(parent, "config", "submodule.horizon.url", stale)
git(child, "remote", "set-url", "origin", stale)
self.assertEqual(git(child, "rev-parse", "HEAD"), old)
with patch.object(airdef, "ROOT", parent), patch.object(airdef, "FORK", child):
airdef.fork()
self.assertEqual(git(child, "rev-parse", "HEAD"), new)
self.assertEqual(git(child, "remote", "get-url", "origin"), str(canonical))
# The fast path must also repair stale configuration for the next update.
git(child, "remote", "set-url", "origin", stale)
airdef.fork()
self.assertEqual(git(child, "remote", "get-url", "origin"), str(canonical))
class DlssBuildFeatureTests(unittest.TestCase):
"""Feature-строку решает детект Windows + RTX + SDK; на Mac и при сбоях — просто mods."""
def setUp(self):
self.tmp = tempfile.TemporaryDirectory(prefix="airdef-dlss-test-")
self.root = Path(self.tmp.name)
self.sdk = self.root / "DLSS"
(self.sdk / "include").mkdir(parents=True)
(self.sdk / "include" / "nvngx_dlss.h").write_text("")
(self.sdk / "lib" / "Windows_x86_64" / "x64").mkdir(parents=True)
self.vulkan = self.root / "VulkanSDK"
(self.vulkan / "Include" / "vulkan").mkdir(parents=True)
(self.vulkan / "Include" / "vulkan" / "vulkan.h").write_text("")
def tearDown(self):
self.tmp.cleanup()
def features(self, **kwargs):
out = io.StringIO()
with patch.dict(os.environ, {"VULKAN_SDK": str(self.vulkan)}), contextlib.redirect_stdout(out):
return airdef.dlss_build_features(**kwargs), out.getvalue()
def test_non_windows_is_mods_even_with_rtx_and_sdk(self):
features, output = self.features(system="Darwin", gpus=["NVIDIA GeForce RTX 3060"], sdk=self.sdk)
self.assertEqual(features, "mods")
self.assertEqual(output, "")
def test_windows_without_rtx_is_mods_silently(self):
features, output = self.features(system="Windows", gpus=["Intel(R) UHD Graphics 770"], sdk=self.sdk)
self.assertEqual(features, "mods")
self.assertEqual(output, "")
def test_windows_rtx_without_sdk_warns_and_builds_mods(self):
features, output = self.features(system="Windows", gpus=["NVIDIA GeForce RTX 3060"],
sdk=self.root / "missing")
self.assertEqual(features, "mods")
self.assertIn("DLSS_SDK", output)
self.assertIn("RTX", output)
def test_windows_rtx_without_vulkan_sdk_warns_and_builds_mods(self):
with patch.dict(os.environ, {"VULKAN_SDK": str(self.root / "missing")}), contextlib.redirect_stdout(io.StringIO()):
features = airdef.dlss_build_features(system="Windows", gpus=["NVIDIA GeForce RTX 3060"], sdk=self.sdk)
self.assertEqual(features, "mods")
def test_windows_rtx_with_full_toolchain_enables_dlss(self):
features, output = self.features(system="Windows", gpus=["NVIDIA GeForce RTX 3060", "Intel(R) UHD"],
sdk=self.sdk)
self.assertEqual(features, "mods,dlss")
self.assertIn("mods,dlss", output)
def test_gpu_query_failure_means_no_dlss(self):
with patch.object(airdef.platform, "system", return_value="Windows"), \
patch.object(airdef.subprocess, "run", side_effect=OSError("no powershell")):
self.assertEqual(airdef.gpu_names(), [])
self.assertEqual(airdef.dlss_build_features(system="Windows", gpus=[]), "mods")
def test_sdk_path_requires_the_layout_dlss_wgpu_builds_with(self):
with patch.dict(os.environ, {"DLSS_SDK": str(self.sdk)}):
self.assertEqual(airdef.dlss_sdk_path(), self.sdk)
with patch.dict(os.environ, {"DLSS_SDK": str(self.root / "missing")}):
self.assertIsNone(airdef.dlss_sdk_path())
def test_game_builds_with_the_detected_feature_string(self):
commands = []
with patch.object(airdef, "fork"), patch.object(airdef, "cargo", return_value="cargo"), \
patch.object(airdef, "run", side_effect=lambda cmd, cwd=None, env=None: commands.append(cmd)), \
patch.object(airdef, "dlss_build_features", return_value="mods,dlss"):
airdef.game()
self.assertEqual(commands[-1][-1], "mods,dlss")
if __name__ == "__main__":
unittest.main()