@moondeck/station 1.0.2 → 1.0.3
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.
- package/images/standard/container/uai-create-node-data +15 -1
- package/images/standard/container/uai-repair-node-data.py +188 -74
- package/images/standard/container/uai-write-node-data +71 -0
- package/lib/browser-testing.ts +31 -26
- package/lib/codex-auth.ts +89 -92
- package/lib/docker-exec.ts +1 -1
- package/lib/engine-accounts.ts +102 -64
- package/lib/git-identity.ts +49 -20
- package/lib/node-home.fixture.ts +155 -0
- package/lib/node-state.ts +68 -0
- package/lib/orchestrator.ts +12 -12
- package/lib/runtime-archive.ts +1 -0
- package/lib/runtime-authority.ts +97 -1
- package/lib/task-container-cli.ts +1 -1
- package/lib/task-environment/self.ts +59 -16
- package/package.json +1 -1
- package/scripts/agent/task-up.sh +132 -76
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
#!/bin/sh
|
|
2
|
-
# Run only as node.
|
|
2
|
+
# Run only as node. Root never transfers ownership of a directory it finds
|
|
3
|
+
# here (uai-repair-node-data.py): its provenance cannot be proven. A share,
|
|
4
|
+
# OpenCode or state directory an older root-run step left owned by someone
|
|
5
|
+
# else is moved aside by node within its node-owned parent, keeping its owner
|
|
6
|
+
# and mode (nothing inside becomes readable), then recreated node-owned.
|
|
7
|
+
# ~/.local itself holds installed tools and is never moved.
|
|
3
8
|
umask 077
|
|
9
|
+
node_owns() { [ -O "$1" ]; }
|
|
4
10
|
for path in /home/node/.local /home/node/.local/share /home/node/.local/share/opencode /home/node/.local/state; do
|
|
11
|
+
if [ "$path" != /home/node/.local ] && [ -d "$path" ] && [ ! -L "$path" ] && ! node_owns "$path"; then
|
|
12
|
+
aside=$path.uai-not-node-owned.$$.$(/bin/date +%s)
|
|
13
|
+
if /bin/mv -T -- "$path" "$aside"; then
|
|
14
|
+
printf 'node data setup: moved %s aside to %s (not owned by node; root never transfers ownership)\n' "$path" "$aside" >&2
|
|
15
|
+
else
|
|
16
|
+
printf 'node data setup: %s is not owned by node and could not be moved aside; operator inspection required\n' "$path" >&2
|
|
17
|
+
fi
|
|
18
|
+
fi
|
|
5
19
|
/bin/mkdir -p -m 0700 -- "$path" || printf 'node data setup: could not create %s; checking existing directory metadata\n' "$path" >&2
|
|
6
20
|
done
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Root only: never create directories or follow a task-controlled symlink.
|
|
2
|
-
|
|
2
|
+
#
|
|
3
|
+
# With no arguments: the fixed ~/.local application-data targets (LEGACY_TARGETS).
|
|
4
|
+
# With "<path>:<mode>:<walk>" arguments (path relative to /home/node, mode in
|
|
5
|
+
# octal or "-" to keep, walk "r" to recurse or "-"): normalize node's own
|
|
6
|
+
# entries. Both modes log every skip and always exit 0.
|
|
3
7
|
import os
|
|
4
8
|
import pwd
|
|
5
9
|
import stat
|
|
@@ -7,87 +11,197 @@ import sys
|
|
|
7
11
|
|
|
8
12
|
flags = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW | os.O_CLOEXEC
|
|
9
13
|
node = pwd.getpwnam("node")
|
|
14
|
+
home_chain = ("home", "node")
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
# Targets mode. Root acts only through descriptors opened relative to the
|
|
17
|
+
# pinned / -> home -> node chain: directories with O_DIRECTORY|O_NOFOLLOW,
|
|
18
|
+
# files with O_NOFOLLOW|O_NONBLOCK, then fchown/fchmod on that descriptor.
|
|
19
|
+
# Root never transfers ownership: a directory or regular file is touched only
|
|
20
|
+
# when node ALREADY owns it, so root's fchown can at most reset node's own
|
|
21
|
+
# group and its fchmod only does what node could do itself. Provenance cannot
|
|
22
|
+
# be proven from inside node's home: a link count read after open cannot show
|
|
23
|
+
# that a hardlink to a system file was not just removed, and node can rename a
|
|
24
|
+
# root-owned directory it holds the parent of into a target name. Root-owned
|
|
25
|
+
# leftovers of older root-run steps are instead moved aside by node itself
|
|
26
|
+
# (uai-create-node-data, uai-write-node-data) and recreated. Regular files must
|
|
27
|
+
# also have a single link. Symlinks, sockets, FIFOs, devices, other owners and
|
|
28
|
+
# other filesystems are skipped with a log line.
|
|
29
|
+
file_flags = os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK | os.O_NOCTTY | os.O_CLOEXEC
|
|
30
|
+
max_depth = 64
|
|
31
|
+
name_chars = frozenset("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-")
|
|
32
|
+
|
|
33
|
+
def skip(display, reason):
|
|
34
|
+
print("node data repair: skipped " + display + " (" + reason + ")", file=sys.stderr)
|
|
35
|
+
|
|
36
|
+
def parse_target(spec):
|
|
37
|
+
parts = spec.split(":")
|
|
38
|
+
if len(parts) != 3 or parts[2] not in ("r", "-"):
|
|
39
|
+
return None
|
|
40
|
+
names = parts[0].split("/")
|
|
41
|
+
for name in names:
|
|
42
|
+
if name in ("", ".", "..") or not set(name) <= name_chars:
|
|
43
|
+
return None
|
|
44
|
+
mode = None
|
|
45
|
+
if parts[1] != "-":
|
|
46
|
+
if not parts[1] or not set(parts[1]) <= set("01234567") or int(parts[1], 8) > 0o777:
|
|
47
|
+
return None
|
|
48
|
+
mode = int(parts[1], 8)
|
|
49
|
+
return names, mode, parts[2] == "r"
|
|
50
|
+
|
|
51
|
+
def open_entry(parent, name, display, quiet_missing):
|
|
52
|
+
"""Open one entry of a pinned directory without following it."""
|
|
12
53
|
try:
|
|
13
|
-
|
|
54
|
+
before = os.stat(name, dir_fd=parent, follow_symlinks=False)
|
|
55
|
+
except FileNotFoundError:
|
|
56
|
+
if not quiet_missing:
|
|
57
|
+
skip(display, "removed during repair")
|
|
58
|
+
return None, None
|
|
14
59
|
except OSError as error:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
60
|
+
skip(display, os.strerror(error.errno))
|
|
61
|
+
return None, None
|
|
62
|
+
if stat.S_ISLNK(before.st_mode):
|
|
63
|
+
skip(display, "symlink")
|
|
64
|
+
return None, None
|
|
65
|
+
if stat.S_ISDIR(before.st_mode):
|
|
66
|
+
open_flags = flags
|
|
67
|
+
elif stat.S_ISREG(before.st_mode):
|
|
68
|
+
open_flags = file_flags
|
|
69
|
+
else:
|
|
70
|
+
skip(display, "not a regular file or directory")
|
|
71
|
+
return None, None
|
|
72
|
+
try:
|
|
73
|
+
fd = os.open(name, open_flags, dir_fd=parent)
|
|
74
|
+
except OSError as error:
|
|
75
|
+
# ELOOP/ENOTDIR: swapped for a symlink or file; EAGAIN: a lease.
|
|
76
|
+
skip(display, "changed during repair: " + os.strerror(error.errno))
|
|
77
|
+
return None, None
|
|
19
78
|
try:
|
|
20
79
|
current = os.fstat(fd)
|
|
80
|
+
except OSError as error:
|
|
81
|
+
os.close(fd)
|
|
82
|
+
skip(display, os.strerror(error.errno))
|
|
83
|
+
return None, None
|
|
84
|
+
if stat.S_IFMT(current.st_mode) != stat.S_IFMT(before.st_mode):
|
|
85
|
+
os.close(fd)
|
|
86
|
+
skip(display, "changed during repair")
|
|
87
|
+
return None, None
|
|
88
|
+
return fd, current
|
|
89
|
+
|
|
90
|
+
def fix(fd, current, display, mode, home_dev):
|
|
91
|
+
"""fchown/fchmod one pinned entry; False when it was skipped."""
|
|
92
|
+
if current.st_dev != home_dev:
|
|
93
|
+
skip(display, "on another filesystem")
|
|
94
|
+
return False
|
|
95
|
+
if stat.S_ISDIR(current.st_mode):
|
|
21
96
|
if current.st_uid != node.pw_uid:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
35
|
-
if not legacy:
|
|
36
|
-
print("node data repair: skipped " + display + " (directory ownership or filesystem is not eligible; operator inspection required)", file=sys.stderr)
|
|
37
|
-
os.close(fd)
|
|
38
|
-
return None
|
|
97
|
+
skip(display, "directory not owned by node; root never transfers ownership")
|
|
98
|
+
return False
|
|
99
|
+
elif not stat.S_ISREG(current.st_mode):
|
|
100
|
+
skip(display, "not a regular file")
|
|
101
|
+
return False
|
|
102
|
+
elif current.st_nlink != 1:
|
|
103
|
+
skip(display, "hardlinked file")
|
|
104
|
+
return False
|
|
105
|
+
elif current.st_uid != node.pw_uid:
|
|
106
|
+
skip(display, "file not owned by node")
|
|
107
|
+
return False
|
|
108
|
+
if current.st_uid != node.pw_uid or current.st_gid != node.pw_gid:
|
|
39
109
|
os.fchown(fd, node.pw_uid, node.pw_gid)
|
|
110
|
+
if mode is not None and stat.S_IMODE(current.st_mode) != mode:
|
|
40
111
|
os.fchmod(fd, mode)
|
|
41
|
-
|
|
42
|
-
os.close(fd)
|
|
43
|
-
raise
|
|
44
|
-
return fd
|
|
112
|
+
return True
|
|
45
113
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
114
|
+
def walk(directory, display, home_dev, depth):
|
|
115
|
+
if depth > max_depth:
|
|
116
|
+
skip(display, "nested too deeply")
|
|
117
|
+
return
|
|
118
|
+
try:
|
|
119
|
+
names = sorted(os.listdir(directory))
|
|
120
|
+
except OSError as error:
|
|
121
|
+
skip(display, os.strerror(error.errno))
|
|
122
|
+
return
|
|
123
|
+
for name in names:
|
|
124
|
+
child_display = display + "/" + name
|
|
125
|
+
fd, current = open_entry(directory, name, child_display, False)
|
|
126
|
+
if fd is None:
|
|
127
|
+
continue
|
|
53
128
|
try:
|
|
54
|
-
|
|
129
|
+
if fix(fd, current, child_display, None, home_dev) and stat.S_ISDIR(current.st_mode):
|
|
130
|
+
walk(fd, child_display, home_dev, depth + 1)
|
|
55
131
|
except OSError as error:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
132
|
+
skip(child_display, os.strerror(error.errno))
|
|
133
|
+
finally:
|
|
134
|
+
os.close(fd)
|
|
135
|
+
|
|
136
|
+
def repair_target(home, home_dev, names, mode, recursive):
|
|
137
|
+
display = "/home/node/" + "/".join(names)
|
|
138
|
+
opened = []
|
|
139
|
+
try:
|
|
140
|
+
parent = home
|
|
141
|
+
for name in names[:-1]:
|
|
142
|
+
try:
|
|
143
|
+
parent = os.open(name, flags, dir_fd=parent)
|
|
144
|
+
except FileNotFoundError:
|
|
145
|
+
return
|
|
146
|
+
except OSError as error:
|
|
147
|
+
skip(display, "parent is a symlink or not a directory: " + os.strerror(error.errno))
|
|
148
|
+
return
|
|
149
|
+
opened.append(parent)
|
|
150
|
+
if os.fstat(parent).st_dev != home_dev:
|
|
151
|
+
skip(display, "parent on another filesystem")
|
|
152
|
+
return
|
|
153
|
+
fd, current = open_entry(parent, names[-1], display, True)
|
|
154
|
+
if fd is None:
|
|
155
|
+
return
|
|
156
|
+
opened.append(fd)
|
|
157
|
+
if fix(fd, current, display, mode, home_dev) and recursive and stat.S_ISDIR(current.st_mode):
|
|
158
|
+
walk(fd, display, home_dev, 1)
|
|
159
|
+
except OSError as error:
|
|
160
|
+
skip(display, os.strerror(error.errno))
|
|
161
|
+
finally:
|
|
162
|
+
for fd in reversed(opened):
|
|
163
|
+
os.close(fd)
|
|
164
|
+
|
|
165
|
+
def repair_targets(specs):
|
|
166
|
+
targets = []
|
|
167
|
+
for spec in specs:
|
|
168
|
+
target = parse_target(spec)
|
|
169
|
+
if target is None:
|
|
170
|
+
skip(repr(spec), "invalid target")
|
|
171
|
+
else:
|
|
172
|
+
targets.append(target)
|
|
173
|
+
pinned = []
|
|
174
|
+
try:
|
|
175
|
+
parent = os.open("/", flags)
|
|
176
|
+
pinned.append(parent)
|
|
177
|
+
for component in home_chain:
|
|
178
|
+
parent = os.open(component, flags, dir_fd=parent)
|
|
179
|
+
pinned.append(parent)
|
|
180
|
+
home = os.fstat(parent)
|
|
181
|
+
if home.st_uid != node.pw_uid:
|
|
182
|
+
skip("/home/node", "home is not owned by node")
|
|
183
|
+
return
|
|
184
|
+
for names, mode, recursive in targets:
|
|
185
|
+
repair_target(parent, home.st_dev, names, mode, recursive)
|
|
186
|
+
except OSError as error:
|
|
187
|
+
skip("home anchor", "missing or redirected: " + os.strerror(error.errno))
|
|
188
|
+
finally:
|
|
189
|
+
for fd in reversed(pinned):
|
|
190
|
+
os.close(fd)
|
|
191
|
+
|
|
192
|
+
# The no-argument targets: shared application data that task startup creates
|
|
193
|
+
# as node (uai-create-node-data) and the OpenCode credentials it copies in.
|
|
194
|
+
LEGACY_TARGETS = (
|
|
195
|
+
".local:0755:-",
|
|
196
|
+
".local/share:0755:-",
|
|
197
|
+
".local/share/opencode:0755:-",
|
|
198
|
+
".local/share/opencode/auth.json:0600:-",
|
|
199
|
+
".local/share/opencode/config.json:0600:-",
|
|
200
|
+
".local/state:0700:-",
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
try:
|
|
204
|
+
repair_targets(sys.argv[1:] or LEGACY_TARGETS)
|
|
205
|
+
except Exception as error:
|
|
206
|
+
print("node data repair: stopped early (" + type(error).__name__ + ")", file=sys.stderr)
|
|
207
|
+
sys.exit(0)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Run only as node. Root must never create or write a path inside /home/node:
|
|
3
|
+
# node can plant a symlink or hardlink there in advance, or swap one in while
|
|
4
|
+
# root works. Host copies therefore arrive on stdin and land with node's own
|
|
5
|
+
# authority; root afterwards only repairs metadata through pinned descriptors
|
|
6
|
+
# (uai-repair-node-data.py), and only on entries node already owns.
|
|
7
|
+
#
|
|
8
|
+
# A directory on the destination path that node does not own (an older
|
|
9
|
+
# root-run mkdir or docker cp whose chown never ran) is not handed over by
|
|
10
|
+
# root: its provenance cannot be proven. Node moves it aside within its own
|
|
11
|
+
# parent, keeping its owner and mode, and recreates it; the caller then
|
|
12
|
+
# delivers the content again. ~/.local itself holds installed tools and is
|
|
13
|
+
# never moved.
|
|
14
|
+
#
|
|
15
|
+
# file <dest> <mode> [<parent-mode>] stdin bytes, written atomically
|
|
16
|
+
# tar <dest-dir> [<dir-mode>] a tar stream, extracted into dest-dir
|
|
17
|
+
umask 022
|
|
18
|
+
op=${1-}
|
|
19
|
+
dest=${2-}
|
|
20
|
+
case $dest in
|
|
21
|
+
/home/node/*) ;;
|
|
22
|
+
*) printf 'node data write: refusing %s (outside /home/node)\n' "$dest" >&2; exit 64 ;;
|
|
23
|
+
esac
|
|
24
|
+
case $dest/ in
|
|
25
|
+
*/../* | */./* | *//*) printf 'node data write: refusing %s (not a normalized path)\n' "$dest" >&2; exit 64 ;;
|
|
26
|
+
esac
|
|
27
|
+
node_owns() { [ -O "$1" ]; }
|
|
28
|
+
set_aside() {
|
|
29
|
+
path=/home/node
|
|
30
|
+
case $1 in /home/node/*) rest=${1#/home/node/} ;; *) return 0 ;; esac
|
|
31
|
+
while [ -n "$rest" ]; do
|
|
32
|
+
part=${rest%%/*}
|
|
33
|
+
case $rest in */*) rest=${rest#*/} ;; *) rest= ;; esac
|
|
34
|
+
path=$path/$part
|
|
35
|
+
if [ -L "$path" ] || [ ! -d "$path" ]; then return 0; fi
|
|
36
|
+
node_owns "$path" && continue
|
|
37
|
+
if [ "$path" = /home/node/.local ]; then
|
|
38
|
+
printf 'node data write: %s is not owned by node; operator inspection required\n' "$path" >&2
|
|
39
|
+
return 1
|
|
40
|
+
fi
|
|
41
|
+
aside=$path.uai-not-node-owned.$$.$(/bin/date +%s)
|
|
42
|
+
/bin/mv -T -- "$path" "$aside" || return 1
|
|
43
|
+
printf 'node data write: moved %s aside to %s (not owned by node; root never transfers ownership)\n' "$path" "$aside" >&2
|
|
44
|
+
return 0
|
|
45
|
+
done
|
|
46
|
+
}
|
|
47
|
+
case $op in
|
|
48
|
+
file)
|
|
49
|
+
mode=${3-}
|
|
50
|
+
dir=${dest%/*}
|
|
51
|
+
set_aside "$dir" || exit 1
|
|
52
|
+
/bin/mkdir -p -- "$dir" || exit 1
|
|
53
|
+
if [ -n "${4-}" ]; then /bin/chmod "$4" -- "$dir" || exit 1; fi
|
|
54
|
+
tmp=$(/bin/mktemp -- "$dir/.uai-write.XXXXXX") || exit 1
|
|
55
|
+
if /usr/bin/tee -- "$tmp" >/dev/null && /bin/chmod "$mode" -- "$tmp" && /bin/mv -f -T -- "$tmp" "$dest"; then
|
|
56
|
+
exit 0
|
|
57
|
+
fi
|
|
58
|
+
/bin/rm -f -- "$tmp"
|
|
59
|
+
exit 1
|
|
60
|
+
;;
|
|
61
|
+
tar)
|
|
62
|
+
set_aside "$dest" || exit 1
|
|
63
|
+
/bin/mkdir -p -- "$dest" || exit 1
|
|
64
|
+
if [ -n "${3-}" ]; then /bin/chmod "$3" -- "$dest" || exit 1; fi
|
|
65
|
+
exec /bin/tar -C "$dest" --no-same-owner -xpf -
|
|
66
|
+
;;
|
|
67
|
+
*)
|
|
68
|
+
printf 'node data write: unknown operation %s\n' "$op" >&2
|
|
69
|
+
exit 64
|
|
70
|
+
;;
|
|
71
|
+
esac
|
package/lib/browser-testing.ts
CHANGED
|
@@ -49,9 +49,14 @@ import {
|
|
|
49
49
|
taskContainerCli,
|
|
50
50
|
} from "./task-container-cli";
|
|
51
51
|
import { MCP_CONFIG_LOCK_PATH } from "./mcp-config-lock";
|
|
52
|
+
import { nodeHomeRepairArgv } from "./node-state";
|
|
52
53
|
import {
|
|
53
54
|
MACHINE_RUNTIME_AUTHORITY_ENV,
|
|
55
|
+
ROOT_NPM_STATE_DIR,
|
|
54
56
|
RUNTIME_AUTHORITY_ENV,
|
|
57
|
+
rootAuthorityEnv,
|
|
58
|
+
rootNpmStateGuardCommand,
|
|
59
|
+
rootRuntimeAuthorityDockerExecArgs,
|
|
55
60
|
runtimeAuthorityDockerExecArgs,
|
|
56
61
|
} from "./runtime-authority";
|
|
57
62
|
import { STANDARD_DEFAULT_NODE_VERSION } from "./standard-image";
|
|
@@ -1063,9 +1068,12 @@ const ROOT_RUNTIME_PATH =
|
|
|
1063
1068
|
// absolute path made this worker exit 127 on every task machine, so its
|
|
1064
1069
|
// done-marker was never written and each ensure re-ran it (live 2026-09-09).
|
|
1065
1070
|
// The path lists the asdf bin first and never the shims, so a container
|
|
1066
|
-
// resolves exactly what it did before.
|
|
1071
|
+
// resolves exactly what it did before. The absolute node bin also means no
|
|
1072
|
+
// asdf lookup depends on the working directory, so root's npx runs from its
|
|
1073
|
+
// own root-only state directory: npm then finds no project `.npmrc` that node
|
|
1074
|
+
// could write (as it could in /workspace).
|
|
1067
1075
|
const APT_DEPS_CMD =
|
|
1068
|
-
`PATH=${ROOT_RUNTIME_PATH} npx ` +
|
|
1076
|
+
`cd ${ROOT_NPM_STATE_DIR} && PATH=${ROOT_RUNTIME_PATH} npx ` +
|
|
1069
1077
|
"-y playwright@latest install-deps chromium";
|
|
1070
1078
|
const APT_VIEWER_CMD =
|
|
1071
1079
|
"/usr/bin/apt-get install -y --no-install-recommends xvfb x11vnc novnc websockify";
|
|
@@ -1198,7 +1206,7 @@ export async function setupBrowserTesting(
|
|
|
1198
1206
|
projectEnvProfile: "maintenance",
|
|
1199
1207
|
argv: ["/usr/bin/chown", "node:node", "/opt/pw-browsers"],
|
|
1200
1208
|
user: "root",
|
|
1201
|
-
env: authorityEnv,
|
|
1209
|
+
env: rootAuthorityEnv(authorityEnv),
|
|
1202
1210
|
timeoutMs: 5_000,
|
|
1203
1211
|
maxOutputBytes: 64 * 1024,
|
|
1204
1212
|
});
|
|
@@ -1223,7 +1231,7 @@ export async function setupBrowserTesting(
|
|
|
1223
1231
|
"exec",
|
|
1224
1232
|
"-u",
|
|
1225
1233
|
"root",
|
|
1226
|
-
...
|
|
1234
|
+
...rootRuntimeAuthorityDockerExecArgs(),
|
|
1227
1235
|
container,
|
|
1228
1236
|
"/usr/bin/chown",
|
|
1229
1237
|
"node:node",
|
|
@@ -1451,12 +1459,20 @@ export async function setupBrowserTesting(
|
|
|
1451
1459
|
const viewerSetup = VIEWER_STEPS.map((step) => `( ${step} )`).join("; ");
|
|
1452
1460
|
const aptWorker = [
|
|
1453
1461
|
"set -e",
|
|
1454
|
-
|
|
1462
|
+
// Root's npm state must be proved root-controlled first. If it is not,
|
|
1463
|
+
// skip only the npx step (logged); never run root npm from a location
|
|
1464
|
+
// node could have prepared, and never fail the rest of the worker.
|
|
1465
|
+
// A failing npx still ends the worker (set -e), so the next ensure
|
|
1466
|
+
// retries, exactly as before.
|
|
1467
|
+
`if ( ${rootNpmStateGuardCommand()} ); then ( ${APT_DEPS_CMD} ); ` +
|
|
1468
|
+
`else echo "uai: skipped playwright install-deps (root npm state unproved)" >&2; fi`,
|
|
1455
1469
|
APT_VIEWER_CMD,
|
|
1456
1470
|
// Close lock fd 9 before starting long-lived viewer grandchildren, or
|
|
1457
1471
|
// they inherit it and keep the apt lock forever after this worker exits.
|
|
1458
1472
|
`/usr/bin/su -s /bin/sh node -c ${shellQuote(viewerSetup)} 9>&-`,
|
|
1459
|
-
|
|
1473
|
+
// Hand back entries an older root npx left in node's ~/.npm — through
|
|
1474
|
+
// pinned no-follow descriptors only; never a path-based chown -R there.
|
|
1475
|
+
`${nodeHomeRepairArgv([{ path: "/home/node/.npm", recursive: true }]).map(shellQuote).join(" ")} || true`,
|
|
1460
1476
|
`/usr/bin/touch ${aptGuard.done}`,
|
|
1461
1477
|
].join("; ");
|
|
1462
1478
|
const guardedAptStart = [
|
|
@@ -1470,15 +1486,13 @@ export async function setupBrowserTesting(
|
|
|
1470
1486
|
">/tmp/uai-pw-deps.log 2>&1 &",
|
|
1471
1487
|
].join("; ");
|
|
1472
1488
|
|
|
1489
|
+
// Root form of the authority: npm prefix/cache/logs under /root, no
|
|
1490
|
+
// user/global npmrc (node writes ~/.npmrc), no PATH entry in node's home.
|
|
1491
|
+
// HOME remains node's; root-run tools must keep their XDG state out of
|
|
1492
|
+
// the task user's home.
|
|
1473
1493
|
const rootWorkerEnv = {
|
|
1474
|
-
...authorityEnv,
|
|
1475
|
-
// HOME remains node's for asdf resolution; root-run tools must keep
|
|
1476
|
-
// their XDG state out of the task user's home.
|
|
1494
|
+
...rootAuthorityEnv(authorityEnv),
|
|
1477
1495
|
XDG_STATE_HOME: "/root/.local/state",
|
|
1478
|
-
NPM_CONFIG_CACHE: "/tmp/uai-root-npm-cache",
|
|
1479
|
-
npm_config_cache: "/tmp/uai-root-npm-cache",
|
|
1480
|
-
NPM_CONFIG_LOGS_DIR: "/tmp/uai-root-npm-cache/_logs",
|
|
1481
|
-
npm_config_logs_dir: "/tmp/uai-root-npm-cache/_logs",
|
|
1482
1496
|
};
|
|
1483
1497
|
if (environment) {
|
|
1484
1498
|
await environment.exec({
|
|
@@ -1502,21 +1516,12 @@ export async function setupBrowserTesting(
|
|
|
1502
1516
|
// the MCP server). Found live 2026-07-08.
|
|
1503
1517
|
"-w",
|
|
1504
1518
|
"/workspace",
|
|
1505
|
-
|
|
1506
|
-
//
|
|
1507
|
-
//
|
|
1508
|
-
|
|
1509
|
-
// fall back to node's private cache or logs directory.
|
|
1519
|
+
// The root authority carries root-only npm settings in both
|
|
1520
|
+
// spellings, so npm's case-insensitive lookup cannot fall back to
|
|
1521
|
+
// node's cache, logs, prefix or npmrc.
|
|
1522
|
+
...rootRuntimeAuthorityDockerExecArgs(),
|
|
1510
1523
|
"-e",
|
|
1511
1524
|
"XDG_STATE_HOME=/root/.local/state",
|
|
1512
|
-
"-e",
|
|
1513
|
-
"NPM_CONFIG_CACHE=/tmp/uai-root-npm-cache",
|
|
1514
|
-
"-e",
|
|
1515
|
-
"npm_config_cache=/tmp/uai-root-npm-cache",
|
|
1516
|
-
"-e",
|
|
1517
|
-
"NPM_CONFIG_LOGS_DIR=/tmp/uai-root-npm-cache/_logs",
|
|
1518
|
-
"-e",
|
|
1519
|
-
"npm_config_logs_dir=/tmp/uai-root-npm-cache/_logs",
|
|
1520
1525
|
container,
|
|
1521
1526
|
"/bin/sh",
|
|
1522
1527
|
"-c",
|