Fix desktop launch, app icons and keyboard parameter editing
This commit is contained in:
1 parent
8fa52c8e5e
commit
6dd202d277
45 files changed
+5993
-272
No files matched your search
@@ -0,0 +1,93 @@
|
||||
"""Fast failure-path checks for the desktop Flatpak process probe."""
|
||||
import importlib.util
|
||||
import json
|
||||
import struct
|
||||
import zlib
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SPEC = importlib.util.spec_from_file_location("flatpak_smoke", ROOT / "packaging/linux/flatpak-smoke.py")
|
||||
SMOKE = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(SMOKE)
|
||||
|
||||
|
||||
def healthy_replies():
|
||||
return [
|
||||
{"id": 1, "ok": True, "result": {"renderer": "gpu", "viewport": [250, 126, 1000, 700]}},
|
||||
{"id": 2, "ok": True, "result": {"feature": 1, "bodies": ["Body1"]}},
|
||||
{"id": 3, "ok": True, "result": {
|
||||
"timeline": [{"error": None}],
|
||||
"bodies": [{"volume_mm3": 20 * 30 * 10, "bbox": {"min": [0, 0, 0], "max": [30, 20, 10]}}],
|
||||
}},
|
||||
]
|
||||
|
||||
|
||||
def output(replies):
|
||||
return "\n".join(json.dumps(reply) for reply in replies)
|
||||
|
||||
|
||||
def chunk(kind, data):
|
||||
return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(data, zlib.crc32(kind)))
|
||||
|
||||
|
||||
def rgba_png(width, height, rows):
|
||||
header = struct.pack(">IIBBBBB", width, height, 8, 6, 0, 0, 0)
|
||||
return (b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", header)
|
||||
+ chunk(b"IDAT", zlib.compress(rows)) + chunk(b"IEND", b""))
|
||||
|
||||
|
||||
class DesktopProbe(unittest.TestCase):
|
||||
def test_real_presented_frame_is_required_not_just_responsive_control(self):
|
||||
black = rgba_png(2, 2, b"\x00" + bytes([0, 0, 0, 255]) * 2 + b"\x00" + bytes([0, 0, 0, 255]) * 2)
|
||||
with self.assertRaisesRegex(ValueError, "blank presented frame"):
|
||||
SMOKE.frame_statistics(black)
|
||||
# Independently encoded two rows: red/green, blue/white.
|
||||
colour = rgba_png(2, 2, b"\x00" + bytes([255, 0, 0, 255, 0, 255, 0, 255])
|
||||
+ b"\x00" + bytes([0, 0, 255, 255, 255, 255, 255, 255]))
|
||||
self.assertEqual(SMOKE.frame_statistics(colour), {"width": 2, "height": 2, "nonblack": 4, "pixels": 4})
|
||||
# Same pixels encoded with PNG Sub filtering (not a second decoder).
|
||||
sub = rgba_png(2, 2, b"\x01" + bytes([255, 0, 0, 255, 1, 255, 0, 0])
|
||||
+ b"\x01" + bytes([0, 0, 255, 255, 255, 255, 0, 0]))
|
||||
self.assertEqual(SMOKE.frame_statistics(sub), SMOKE.frame_statistics(colour))
|
||||
|
||||
def test_frame_byte_dimensions_and_decompression_are_bounded(self):
|
||||
with self.assertRaisesRegex(ValueError, "dimensions"):
|
||||
SMOKE.frame_statistics(rgba_png(SMOKE.MAX_PIXELS + 1, 1, b""))
|
||||
with self.assertRaisesRegex(ValueError, "decompressed size"):
|
||||
SMOKE.frame_statistics(rgba_png(1, 1, b"\x00" * 10000))
|
||||
truncated = rgba_png(1, 1, b"\x00\xff\x00\x00\xff")[:-1]
|
||||
with self.assertRaises(ValueError):
|
||||
SMOKE.frame_statistics(truncated)
|
||||
|
||||
def test_ui_thread_and_independent_box_measurement_are_required(self):
|
||||
replies = healthy_replies()
|
||||
self.assertEqual(SMOKE.validate_replies(output(replies)), "gpu")
|
||||
replies[2]["result"]["bodies"][0]["volume_mm3"] = 5900
|
||||
with self.assertRaises(ValueError):
|
||||
SMOKE.validate_replies(output(replies))
|
||||
|
||||
def test_cli_version_or_partial_control_output_is_not_desktop_success(self):
|
||||
with self.assertRaises(ValueError):
|
||||
SMOKE.validate_replies("solvecraft-cli 0.3.0\n")
|
||||
with self.assertRaises(ValueError):
|
||||
SMOKE.validate_replies(output(healthy_replies()[:1]))
|
||||
|
||||
def test_startup_without_viewport_or_failed_feature_is_not_success(self):
|
||||
for failure in ["viewport", "feature", "control", "bounds"]:
|
||||
with self.subTest(failure=failure):
|
||||
replies = healthy_replies()
|
||||
if failure == "viewport":
|
||||
replies[0]["result"]["viewport"][2] = 0
|
||||
elif failure == "feature":
|
||||
replies[2]["result"]["timeline"][0]["error"] = "operation failed"
|
||||
elif failure == "control":
|
||||
replies[1] = {"id": 2, "ok": False, "error": "startup failure"}
|
||||
else:
|
||||
replies[2]["result"]["bodies"][0]["bbox"]["max"][0] = 29
|
||||
with self.assertRaises(ValueError):
|
||||
SMOKE.validate_replies(output(replies))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,82 @@
|
||||
"""PE icon guard: Windows PE32/PE32+ resources, and missing/broken groups."""
|
||||
import pathlib
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
SCRIPT = pathlib.Path(__file__).resolve().parents[1] / "windows/check-icon.ps1"
|
||||
|
||||
|
||||
def executable(pe64=True, icon=True, broken=False):
|
||||
data = bytearray(1024)
|
||||
def u16(at, value): struct.pack_into("<H", data, at, value)
|
||||
def u32(at, value): struct.pack_into("<I", data, at, value)
|
||||
u16(0, 0x5A4D)
|
||||
u32(0x3C, 0x80)
|
||||
u32(0x80, 0x4550)
|
||||
u16(0x86, 1)
|
||||
optional = 0x98
|
||||
size = 240 if pe64 else 224
|
||||
u16(0x94, size)
|
||||
u16(optional, 0x20B if pe64 else 0x10B)
|
||||
directories = optional + (112 if pe64 else 96)
|
||||
u32(directories + 16, 0x1000)
|
||||
u32(directories + 20, 512)
|
||||
section = optional + size
|
||||
u32(section + 12, 0x1000)
|
||||
u32(section + 16, 512)
|
||||
u32(section + 20, 512)
|
||||
base = 512
|
||||
def directory(relative, entries):
|
||||
u16(base + relative + 14, len(entries))
|
||||
for i, (name, offset) in enumerate(entries):
|
||||
u32(base + relative + 16 + 8*i, name)
|
||||
u32(base + relative + 20 + 8*i, offset)
|
||||
if icon:
|
||||
directory(0, [(3, 0x80000030), (14, 0x80000070)])
|
||||
directory(0x30, [(1, 0x80000050)])
|
||||
directory(0x50, [(1033, 0xB0)])
|
||||
directory(0x70, [(1, 0x80000090)])
|
||||
directory(0x90, [(1033, 0xC0)])
|
||||
u32(base + 0xB0, 0x1100)
|
||||
u32(base + 0xB4, 40)
|
||||
u32(base + 0xC0, 0x1140)
|
||||
u32(base + 0xC4, 20)
|
||||
u16(base + 0x142, 1)
|
||||
u16(base + 0x144, 1)
|
||||
u32(base + 0x14E, 40)
|
||||
u16(base + 0x152, 2 if broken else 1)
|
||||
return data
|
||||
|
||||
|
||||
class IconGuard(unittest.TestCase):
|
||||
def run_guard(self, data):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
path = pathlib.Path(folder) / "app.exe"
|
||||
path.write_bytes(data)
|
||||
return subprocess.run([shutil.which("pwsh") or "powershell", "-NoProfile", "-File", str(SCRIPT), "-Path", str(path)], capture_output=True, text=True)
|
||||
|
||||
def test_valid_pe32_and_pe64(self):
|
||||
for pe64 in (False, True):
|
||||
result = self.run_guard(executable(pe64))
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertIn("1 images, 1 group", result.stdout)
|
||||
|
||||
def test_generic_executable_is_rejected(self):
|
||||
result = self.run_guard(executable(icon=False))
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("RT_ICON", result.stderr)
|
||||
|
||||
def test_group_must_reference_a_real_image(self):
|
||||
result = self.run_guard(executable(broken=True))
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("missing image", result.stderr)
|
||||
|
||||
def test_truncated_executable_is_rejected(self):
|
||||
self.assertNotEqual(self.run_guard(b"MZ").returncode, 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user