@threenative/runtime-native 0.2.0 → 0.3.0

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.
@@ -3,11 +3,10 @@
3
3
  import { spawnSync } from 'node:child_process';
4
4
  import { createHash } from 'node:crypto';
5
5
  import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
6
- import { basename, join, resolve } from 'node:path';
6
+ import { basename, dirname, join, resolve } from 'node:path';
7
7
  import { fileURLToPath, pathToFileURL } from 'node:url';
8
8
  import { PNG } from 'pngjs';
9
9
 
10
- const workspaceRoot = resolve(fileURLToPath(import.meta.url), '..', '..', '..', '..');
11
10
  const READY_MARKER = 'TN_NATIVE_SMOKE_READY:webgpu';
12
11
  const ASSET_MARKER = 'TN_NATIVE_STARTER_ASSETS_LOADED:texture,glb';
13
12
 
@@ -61,9 +60,13 @@ export function verifyStarterDesktop({ frames = 300, project = process.cwd() } =
61
60
  mkdirSync(artifactDirectory, { recursive: true });
62
61
  const runtimeArgs = ['--screenshot', screenshot, '--frames', String(frames)];
63
62
  // See verify-desktop-core.mjs: `xvfb-run` hands back its own failing cleanup kill's status.
63
+ const displayHelper = join(dirname(fileURLToPath(import.meta.url)), 'xvfb.sh');
64
+ if (process.platform === 'linux' && !existsSync(displayHelper)) {
65
+ throw new Error(`TN_NATIVE_STARTER_DISPLAY_SUPPORT_MISSING: ${displayHelper}`);
66
+ }
64
67
  const command = process.platform === 'linux' ? 'sh' : artifact;
65
68
  const args = process.platform === 'linux'
66
- ? [join(workspaceRoot, 'scripts', 'xvfb.sh'), artifact, ...runtimeArgs]
69
+ ? [displayHelper, artifact, ...runtimeArgs]
67
70
  : runtimeArgs;
68
71
  const result = spawnSync(command, args, {
69
72
  cwd: projectRoot,
@@ -0,0 +1,63 @@
1
+ #!/bin/sh
2
+ # Run a command under a virtual X display and return the command's status.
3
+ #
4
+ # This copy is packaged with the installed desktop verifier. It must not resolve a helper from the
5
+ # engine checkout because the verifier is a consumer-facing command run from node_modules.
6
+ # `xvfb-run` is deliberately not used: its cleanup kill can replace a successful command status.
7
+ set -u
8
+
9
+ if [ "$#" -eq 0 ]; then
10
+ echo "scripts/xvfb.sh: usage: scripts/xvfb.sh <command> [args...]" >&2
11
+ exit 2
12
+ fi
13
+
14
+ case "$(uname -s 2>/dev/null || echo unknown)" in
15
+ Linux*) ;;
16
+ *) exec "$@" ;;
17
+ esac
18
+
19
+ if ! command -v Xvfb >/dev/null 2>&1; then
20
+ echo "scripts/xvfb.sh: Xvfb is required for headless Linux runs and is not installed." >&2
21
+ exit 2
22
+ fi
23
+
24
+ screen="${TN_XVFB_SCREEN:-1600x900x24}"
25
+ runtime="$(mktemp -d)"
26
+ display_file="$runtime/display"
27
+ : >"$display_file"
28
+
29
+ Xvfb -displayfd 3 -screen 0 "$screen" -nolisten tcp 3>"$display_file" &
30
+ xvfb_pid=$!
31
+
32
+ cleanup() {
33
+ if kill -0 "$xvfb_pid" 2>/dev/null; then
34
+ kill "$xvfb_pid" 2>/dev/null || true
35
+ wait "$xvfb_pid" 2>/dev/null || true
36
+ fi
37
+ rm -rf "$runtime"
38
+ }
39
+ trap cleanup EXIT INT TERM
40
+
41
+ display=""
42
+ waited=0
43
+ while [ "$waited" -lt 100 ]; do
44
+ display="$(tr -d '[:space:]' <"$display_file")"
45
+ [ -n "$display" ] && break
46
+ if ! kill -0 "$xvfb_pid" 2>/dev/null; then
47
+ echo "scripts/xvfb.sh: Xvfb exited before it reported a display" >&2
48
+ exit 2
49
+ fi
50
+ sleep 0.1
51
+ waited=$((waited + 1))
52
+ done
53
+
54
+ if [ -z "$display" ]; then
55
+ echo "scripts/xvfb.sh: Xvfb did not report a display within 10 seconds" >&2
56
+ exit 2
57
+ fi
58
+
59
+ DISPLAY=":$display"
60
+ export DISPLAY
61
+ "$@"
62
+ status=$?
63
+ exit "$status"