@stll/oxlint-config 0.10.0 → 0.12.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.
- package/README.md +248 -0
- package/dist/cloud-setup-cli.cjs +63 -0
- package/dist/cloud-setup-cli.cjs.map +1 -0
- package/dist/cloud-setup-cli.d.cts +1 -0
- package/dist/cloud-setup-cli.d.mts +1 -0
- package/dist/cloud-setup-cli.mjs +63 -0
- package/dist/cloud-setup-cli.mjs.map +1 -0
- package/dist/toolchain-check-cli.cjs +10 -197
- package/dist/toolchain-check-cli.cjs.map +1 -1
- package/dist/toolchain-check-cli.mjs +9 -173
- package/dist/toolchain-check-cli.mjs.map +1 -1
- package/dist/toolchain-guard.cjs +3302 -0
- package/dist/toolchain-guard.cjs.map +1 -0
- package/dist/toolchain-guard.mjs +3243 -0
- package/dist/toolchain-guard.mjs.map +1 -0
- package/dist/typecheck-parity-cli.cjs +77 -16
- package/dist/typecheck-parity-cli.cjs.map +1 -1
- package/dist/typecheck-parity-cli.mjs +77 -16
- package/dist/typecheck-parity-cli.mjs.map +1 -1
- package/package.json +11 -1
- package/toolchain.json +91 -1
|
@@ -0,0 +1,3243 @@
|
|
|
1
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { minVersion, satisfies, subset, valid, validRange } from "semver";
|
|
5
|
+
import picomatch from "picomatch";
|
|
6
|
+
import { parse } from "smol-toml";
|
|
7
|
+
import { LineCounter, isAlias, isMap, isNode, isScalar, isSeq, parseAllDocuments, parseDocument } from "yaml";
|
|
8
|
+
//#region src/cloud-setup-install.ts
|
|
9
|
+
const packageInstall = String.raw`
|
|
10
|
+
# Prevent package maintainer scripts from starting unmanaged system services.
|
|
11
|
+
apt_install() (
|
|
12
|
+
# EXIT runs after function locals expire; this subshell owns the trap state.
|
|
13
|
+
backup=''
|
|
14
|
+
policy_state=untouched
|
|
15
|
+
[[ ! -L /var/lock/stll-cloud-apt.lock ]] || fail 'Invalid package install lock'
|
|
16
|
+
exec 8>/var/lock/stll-cloud-apt.lock
|
|
17
|
+
flock -x -w 120 8 || fail 'Another package installation is active'
|
|
18
|
+
[[ ! -L /usr/sbin/policy-rc.d ]] || fail 'Unsupported service-start policy symlink'
|
|
19
|
+
[[ ! -e /usr/sbin/policy-rc.d || -f /usr/sbin/policy-rc.d ]] || fail 'Unsupported service-start policy file'
|
|
20
|
+
backup="$(mktemp -d)"
|
|
21
|
+
cleanup_package_policy() {
|
|
22
|
+
local status=$?
|
|
23
|
+
trap - EXIT HUP INT TERM
|
|
24
|
+
if [[ "$policy_state" == installed ]]; then
|
|
25
|
+
if [[ -f "$backup/original" ]]; then
|
|
26
|
+
if ! cp -p "$backup/original" /usr/sbin/policy-rc.d; then status=1; fi
|
|
27
|
+
else
|
|
28
|
+
if ! rm -f /usr/sbin/policy-rc.d; then status=1; fi
|
|
29
|
+
fi
|
|
30
|
+
fi
|
|
31
|
+
rm -rf -- "$backup"
|
|
32
|
+
exit "$status"
|
|
33
|
+
}
|
|
34
|
+
trap cleanup_package_policy EXIT
|
|
35
|
+
trap 'exit 129' HUP
|
|
36
|
+
trap 'exit 130' INT
|
|
37
|
+
trap 'exit 143' TERM
|
|
38
|
+
if [[ -e /usr/sbin/policy-rc.d ]]; then cp -p /usr/sbin/policy-rc.d "$backup/original"; fi
|
|
39
|
+
policy_state=installed
|
|
40
|
+
printf '%s\n' '#!/bin/sh' 'exit 101' > /usr/sbin/policy-rc.d
|
|
41
|
+
chmod 755 /usr/sbin/policy-rc.d
|
|
42
|
+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends "$@"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
`;
|
|
46
|
+
const postgresSourceLine = "deb [signed-by=/usr/share/keyrings/stll-pgdg.asc] https://apt.postgresql.org/pub/repos/apt noble-pgdg main";
|
|
47
|
+
const postgresSigningFingerprint = "B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8";
|
|
48
|
+
const postgresSources = String.raw`
|
|
49
|
+
pgdg_key_fingerprint() {
|
|
50
|
+
gpg --batch --show-keys --with-colons "$1" | awk -F: '$1 == "pub" { primary = 1 } $1 == "sub" { primary = 0 } $1 == "fpr" && primary { print toupper($10); primary = 0 }'
|
|
51
|
+
}
|
|
52
|
+
pgdg_sources_ready() {
|
|
53
|
+
local managed="$1" file mode records suite keyring override fingerprint selected_keyring=''
|
|
54
|
+
shift
|
|
55
|
+
PGDG_SOURCE_STATE=missing
|
|
56
|
+
[[ ! -L "$managed" ]] || fail "Managed PGDG source must not be a symlink: $managed"
|
|
57
|
+
for file in "$@"; do
|
|
58
|
+
[[ -e "$file" ]] || continue
|
|
59
|
+
[[ -f "$file" ]] || fail "APT source must be a regular file: $file"
|
|
60
|
+
case "$file" in *.sources) mode=sources ;; *) mode=list ;; esac
|
|
61
|
+
records="$(awk -v mode="$mode" '
|
|
62
|
+
function trim(value) { gsub(/^[[:space:]]+|[[:space:]]+$/, "", value); return value }
|
|
63
|
+
function pgdg_uri(uri) {
|
|
64
|
+
uri = tolower(uri)
|
|
65
|
+
if (uri !~ /^[a-z][a-z0-9+.-]*:\/\//) return 0
|
|
66
|
+
sub(/^[a-z][a-z0-9+.-]*:\/\//, "", uri)
|
|
67
|
+
sub(/[\/?#].*$/, "", uri)
|
|
68
|
+
sub(/^.*@/, "", uri)
|
|
69
|
+
sub(/:.*$/, "", uri)
|
|
70
|
+
return uri == "apt.postgresql.org" || uri == "apt.postgresql.org."
|
|
71
|
+
}
|
|
72
|
+
function contains_pgdg(value, tokens, count, token_index) {
|
|
73
|
+
count = split(value, tokens, /[[:space:]]+/)
|
|
74
|
+
for (token_index = 1; token_index <= count; token_index++) if (pgdg_uri(tokens[token_index])) return 1
|
|
75
|
+
return 0
|
|
76
|
+
}
|
|
77
|
+
function unsafe_field(name) {
|
|
78
|
+
return name ~ /^(trusted|allow-insecure|allow-weak|allow-downgrade-to-insecure)$/
|
|
79
|
+
}
|
|
80
|
+
function disabled_override(value) {
|
|
81
|
+
value = tolower(trim(value))
|
|
82
|
+
gsub(/^["\047]|["\047]$/, "", value)
|
|
83
|
+
return value ~ /^(no|false|without|off|disable|0)$/
|
|
84
|
+
}
|
|
85
|
+
function stanza(override_index) {
|
|
86
|
+
override = 0
|
|
87
|
+
for (override_index = 1; override_index <= override_count; override_index++) {
|
|
88
|
+
if (!disabled_override(override_values[override_index])) override = 1
|
|
89
|
+
delete override_values[override_index]
|
|
90
|
+
}
|
|
91
|
+
if (tolower(trim(enabled)) != "no" && pgdg) print (trim(suites) == "" ? "-" : trim(suites)) "\t" (trim(keyring) == "" ? "-" : trim(keyring)) "\t" (override ? "unsafe" : "safe")
|
|
92
|
+
enabled = ""; pgdg = 0; field = ""; suites = ""; keyring = ""; override = 0; override_count = 0
|
|
93
|
+
}
|
|
94
|
+
/^[[:space:]]*#/ { if (mode == "list" || $0 ~ /^#/) next }
|
|
95
|
+
{
|
|
96
|
+
line = $0
|
|
97
|
+
if (mode == "list") {
|
|
98
|
+
sub(/[[:space:]]*#.*$/, "", line)
|
|
99
|
+
if (line !~ /^[[:space:]]*deb(-src)?[[:space:]]/ || !contains_pgdg(line)) next
|
|
100
|
+
keyring = ""; override = 0
|
|
101
|
+
if (match(line, /\[[^]]*\]/)) {
|
|
102
|
+
options = substr(line, RSTART + 1, RLENGTH - 2)
|
|
103
|
+
count = split(options, tokens, /[[:space:]]+/)
|
|
104
|
+
for (token_index = 1; token_index <= count; token_index++) {
|
|
105
|
+
if (tolower(tokens[token_index]) ~ /^signed-by=/) { keyring = tokens[token_index]; sub(/^[^=]*=/, "", keyring) }
|
|
106
|
+
option_name = tolower(tokens[token_index]); sub(/=.*/, "", option_name)
|
|
107
|
+
option_value = tokens[token_index]; sub(/^[^=]*=/, "", option_value)
|
|
108
|
+
if (unsafe_field(option_name) && !disabled_override(option_value)) override = 1
|
|
109
|
+
}
|
|
110
|
+
sub(/\[[^]]*\]/, "", line)
|
|
111
|
+
}
|
|
112
|
+
count = split(line, tokens, /[[:space:]]+/)
|
|
113
|
+
for (token_index = 1; token_index <= count; token_index++) if (pgdg_uri(tokens[token_index])) print (tokens[token_index + 1] == "" ? "-" : tokens[token_index + 1]) "\t" (keyring == "" ? "-" : keyring) "\t" (override ? "unsafe" : "safe")
|
|
114
|
+
next
|
|
115
|
+
}
|
|
116
|
+
if (line ~ /^[[:space:]]*$/) { stanza(); next }
|
|
117
|
+
if (line ~ /^[[:space:]]/) {
|
|
118
|
+
if (field == "uris" && contains_pgdg(line)) pgdg = 1
|
|
119
|
+
if (field == "enabled") enabled = enabled " " line
|
|
120
|
+
if (field == "suites") suites = suites " " line
|
|
121
|
+
if (field == "signed-by") keyring = keyring " " line
|
|
122
|
+
if (unsafe_field(field)) override_values[override_count] = override_values[override_count] " " line
|
|
123
|
+
next
|
|
124
|
+
}
|
|
125
|
+
field = tolower(line)
|
|
126
|
+
sub(/:.*/, "", field)
|
|
127
|
+
value = line
|
|
128
|
+
sub(/^[^:]*:[[:space:]]*/, "", value)
|
|
129
|
+
if (field == "uris" && contains_pgdg(value)) pgdg = 1
|
|
130
|
+
if (field == "enabled") enabled = value
|
|
131
|
+
if (field == "suites") suites = value
|
|
132
|
+
if (field == "signed-by") keyring = value
|
|
133
|
+
if (unsafe_field(field)) override_values[++override_count] = value
|
|
134
|
+
}
|
|
135
|
+
END { if (mode == "sources") stanza() }
|
|
136
|
+
' "$file")" || fail "Cannot inspect APT source: $file"
|
|
137
|
+
if [[ "$file" == "$managed" && -z "$records" ]]; then
|
|
138
|
+
fail "Managed PGDG source has no active PGDG entry: $file"
|
|
139
|
+
fi
|
|
140
|
+
while IFS=$'\t' read -r suite keyring override; do
|
|
141
|
+
[[ -n "$suite" ]] || continue
|
|
142
|
+
[[ "$override" == safe ]] || fail "PGDG source enables an unsafe trust override: $file"
|
|
143
|
+
[[ "$suite" == noble-pgdg && "$keyring" == /* && ! "$keyring" =~ [[:space:],] ]] || fail "PGDG source requires noble-pgdg and one Signed-By keyring: $file"
|
|
144
|
+
[[ -z "$selected_keyring" || "$selected_keyring" == "$keyring" ]] || fail "Conflicting PGDG Signed-By keyrings: $file"
|
|
145
|
+
fingerprint="$(pgdg_key_fingerprint "$keyring")" || fail "Cannot verify PGDG Signed-By keyring: $file"
|
|
146
|
+
[[ "$fingerprint" == @PGDG_FINGERPRINT@ ]] || fail "PGDG Signed-By fingerprint mismatch: $file"
|
|
147
|
+
selected_keyring="$keyring"
|
|
148
|
+
PGDG_SOURCE_STATE=reuse
|
|
149
|
+
done <<< "$records"
|
|
150
|
+
done
|
|
151
|
+
}
|
|
152
|
+
`;
|
|
153
|
+
const postgresInstall = String.raw`
|
|
154
|
+
postgres_ready() {
|
|
155
|
+
local binary
|
|
156
|
+
for binary in postgres initdb pg_ctl psql createdb; do
|
|
157
|
+
[[ -x "/usr/lib/postgresql/@POSTGRES@/bin/$binary" ]] || return 1
|
|
158
|
+
done
|
|
159
|
+
/usr/lib/postgresql/@POSTGRES@/bin/postgres --version | grep -Eq '^postgres \(PostgreSQL\) @POSTGRES@\.'
|
|
160
|
+
}
|
|
161
|
+
if ! postgres_ready; then
|
|
162
|
+
pgdg_sources_ready /etc/apt/sources.list.d/stll-pgdg.list /etc/apt/sources.list /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources
|
|
163
|
+
if [[ "$PGDG_SOURCE_STATE" == missing ]]; then
|
|
164
|
+
local key key_fingerprint
|
|
165
|
+
key="$(mktemp)"
|
|
166
|
+
curl --fail --silent --show-error --location --proto '=https' --proto-redir '=https' --tlsv1.2 https://www.postgresql.org/media/keys/ACCC4CF8.asc -o "$key"
|
|
167
|
+
key_fingerprint="$(pgdg_key_fingerprint "$key")"
|
|
168
|
+
[[ "$key_fingerprint" == @PGDG_FINGERPRINT@ ]] || fail 'PostgreSQL signing key mismatch'
|
|
169
|
+
install -d -m 755 /usr/share/keyrings
|
|
170
|
+
install -m 644 "$key" /usr/share/keyrings/stll-pgdg.asc
|
|
171
|
+
rm -- "$key"
|
|
172
|
+
printf '%s\n' '@PGDG_SOURCE@' > /etc/apt/sources.list.d/stll-pgdg.list
|
|
173
|
+
fi
|
|
174
|
+
apt-get update
|
|
175
|
+
apt_install postgresql-@POSTGRES@ postgresql-client-@POSTGRES@
|
|
176
|
+
fi
|
|
177
|
+
postgres_ready || fail 'PostgreSQL toolchain is incomplete or differs from the policy major'
|
|
178
|
+
`;
|
|
179
|
+
const valkeyInstall = String.raw`
|
|
180
|
+
if ! command -v valkey-server >/dev/null || [[ "$(valkey-server --version | sed -nE 's/.*v=([0-9.]+).*/\1/p')" != '@VALKEY@' ]] || ! command -v valkey-cli >/dev/null || [[ "$(valkey-cli --version)" != 'valkey-cli @VALKEY@' ]]; then
|
|
181
|
+
local scratch server_url server_sha tools_url tools_sha package
|
|
182
|
+
scratch="$(mktemp -d)"
|
|
183
|
+
chmod 755 "$scratch"
|
|
184
|
+
case "$ARCH" in
|
|
185
|
+
amd64) server_url='@AMD64_SERVER_URL@'; server_sha='@AMD64_SERVER_SHA@'; tools_url='@AMD64_TOOLS_URL@'; tools_sha='@AMD64_TOOLS_SHA@' ;;
|
|
186
|
+
arm64) server_url='@ARM64_SERVER_URL@'; server_sha='@ARM64_SERVER_SHA@'; tools_url='@ARM64_TOOLS_URL@'; tools_sha='@ARM64_TOOLS_SHA@' ;;
|
|
187
|
+
*) fail 'Unsupported Valkey architecture' ;;
|
|
188
|
+
esac
|
|
189
|
+
curl --fail --silent --show-error --location --proto '=https' --proto-redir '=https' --tlsv1.2 "$server_url" -o "$scratch/valkey-server.deb"
|
|
190
|
+
curl --fail --silent --show-error --location --proto '=https' --proto-redir '=https' --tlsv1.2 "$tools_url" -o "$scratch/valkey-tools.deb"
|
|
191
|
+
(cd "$scratch"; printf '%s %s\n' "$server_sha" valkey-server.deb "$tools_sha" valkey-tools.deb | sha256sum --strict -c -)
|
|
192
|
+
for package in valkey-server valkey-tools; do
|
|
193
|
+
[[ "$(dpkg-deb -f "$scratch/$package.deb" Package)" == "$package" ]] || fail 'Valkey artifact package mismatch'
|
|
194
|
+
[[ "$(dpkg-deb -f "$scratch/$package.deb" Version)" == '@VALKEY@-1.noble' ]] || fail 'Valkey artifact version mismatch'
|
|
195
|
+
[[ "$(dpkg-deb -f "$scratch/$package.deb" Architecture)" == "$ARCH" ]] || fail 'Valkey artifact architecture mismatch'
|
|
196
|
+
done
|
|
197
|
+
apt-get update
|
|
198
|
+
apt_install "$scratch/valkey-server.deb" "$scratch/valkey-tools.deb"
|
|
199
|
+
rm -rf -- "$scratch"
|
|
200
|
+
fi
|
|
201
|
+
[[ "$(valkey-server --version | sed -nE 's/.*v=([0-9.]+).*/\1/p')" == '@VALKEY@' ]] || fail 'Valkey version differs from policy'
|
|
202
|
+
[[ "$(valkey-cli --version)" == 'valkey-cli @VALKEY@' ]] || fail 'Valkey client version differs from policy'
|
|
203
|
+
`;
|
|
204
|
+
const state = String.raw`
|
|
205
|
+
service_account_ready() {
|
|
206
|
+
local uid gid shell
|
|
207
|
+
uid="$(id -u stll-cloud)" || fail 'Service user is unavailable; run install'
|
|
208
|
+
gid="$(id -g stll-cloud)"
|
|
209
|
+
shell="$(getent passwd stll-cloud | cut -d: -f7)"
|
|
210
|
+
[[ "$uid" =~ ^[1-9][0-9]*$ && "$gid" =~ ^[1-9][0-9]*$ && "$shell" == /usr/sbin/nologin ]] || fail 'Service user must be unprivileged with no login shell'
|
|
211
|
+
}
|
|
212
|
+
prepare_state() {
|
|
213
|
+
service_account_ready
|
|
214
|
+
[[ ! -L /var/lib/stll-cloud ]] || fail 'Service state root must not be a symlink'
|
|
215
|
+
if [[ -e /var/lib/stll-cloud ]]; then
|
|
216
|
+
[[ -d /var/lib/stll-cloud && "$(stat -c '%u:%a' /var/lib/stll-cloud)" == 0:755 ]] || fail 'Invalid service state root'
|
|
217
|
+
else
|
|
218
|
+
install -d -m 755 -o root -g root /var/lib/stll-cloud
|
|
219
|
+
fi
|
|
220
|
+
STATE="/var/lib/stll-cloud/$(printf '%s' "$REPO_ROOT" | sha256sum | cut -d' ' -f1)"
|
|
221
|
+
[[ ! -L "$STATE" ]] || fail 'Service state must not be a symlink'
|
|
222
|
+
if [[ -e "$STATE" ]]; then
|
|
223
|
+
[[ -d "$STATE" && "$(stat -c '%u:%a' "$STATE")" == 0:710 && "$(stat -c '%g' "$STATE")" == "$(id -g stll-cloud)" ]] || fail 'Invalid service state ownership'
|
|
224
|
+
else
|
|
225
|
+
install -d -m 710 -o root -g stll-cloud "$STATE"
|
|
226
|
+
fi
|
|
227
|
+
[[ ! -L "$STATE/lock" ]] || fail 'Service lock must not be a symlink'
|
|
228
|
+
exec 9>"$STATE/lock"
|
|
229
|
+
flock -x -w 10 9 || fail 'Another setup process owns the service state'
|
|
230
|
+
}
|
|
231
|
+
`;
|
|
232
|
+
const renderCloudServiceInstall = ({ services, postgres, valkey, valkeyArtifacts }) => {
|
|
233
|
+
const parts = services.map((service) => {
|
|
234
|
+
switch (service) {
|
|
235
|
+
case "postgres": return postgresInstall.replaceAll("@POSTGRES@", postgres).replaceAll("@PGDG_SOURCE@", postgresSourceLine).replaceAll("@PGDG_FINGERPRINT@", postgresSigningFingerprint);
|
|
236
|
+
case "valkey": {
|
|
237
|
+
const replacements = /* @__PURE__ */ new Map([
|
|
238
|
+
["@VALKEY@", valkey],
|
|
239
|
+
["@AMD64_SERVER_URL@", valkeyArtifacts.amd64.server.url],
|
|
240
|
+
["@AMD64_SERVER_SHA@", valkeyArtifacts.amd64.server.sha256],
|
|
241
|
+
["@AMD64_TOOLS_URL@", valkeyArtifacts.amd64.tools.url],
|
|
242
|
+
["@AMD64_TOOLS_SHA@", valkeyArtifacts.amd64.tools.sha256],
|
|
243
|
+
["@ARM64_SERVER_URL@", valkeyArtifacts.arm64.server.url],
|
|
244
|
+
["@ARM64_SERVER_SHA@", valkeyArtifacts.arm64.server.sha256],
|
|
245
|
+
["@ARM64_TOOLS_URL@", valkeyArtifacts.arm64.tools.url],
|
|
246
|
+
["@ARM64_TOOLS_SHA@", valkeyArtifacts.arm64.tools.sha256]
|
|
247
|
+
]);
|
|
248
|
+
return valkeyInstall.replace(/@[A-Z0-9_]+@/g, (token) => {
|
|
249
|
+
const value = replacements.get(token);
|
|
250
|
+
if (value === void 0) throw new Error(`Missing Valkey artifact field: ${token}`);
|
|
251
|
+
return value;
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
default: throw new Error(`Unsupported service: ${String(service)}`);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
const user = services.length === 0 ? "" : " if ! id stll-cloud >/dev/null 2>&1; then useradd --system --user-group --no-create-home --shell /usr/sbin/nologin stll-cloud; fi\n service_account_ready\n";
|
|
258
|
+
return `${packageInstall}\n${services.includes("postgres") ? postgresSources.replaceAll("@PGDG_FINGERPRINT@", postgresSigningFingerprint) : ""}\n${services.length === 0 ? "prepare_state() { :; }\n" : state}\ninstall_services() {\n${user}${parts.join("")}\n :\n}\n`;
|
|
259
|
+
};
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/cloud-setup-schema.ts
|
|
262
|
+
const cloudServices = ["postgres", "valkey"];
|
|
263
|
+
const cloudInstallCommand = "bun install --frozen-lockfile";
|
|
264
|
+
const cloudService = (value) => cloudServices.some((service) => value === service);
|
|
265
|
+
/** Parse an explicit declaration without assuming services for undeclared repositories. */
|
|
266
|
+
const parseCloudSetup = (input) => {
|
|
267
|
+
if (input === void 0) return void 0;
|
|
268
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) throw new Error("cloud must be an object");
|
|
269
|
+
for (const key of Object.keys(input)) if (key !== "services" && key !== "install" && key !== "envFile") throw new Error(`unsupported cloud key: ${key}`);
|
|
270
|
+
if (!("services" in input) || !Array.isArray(input.services)) throw new Error("cloud.services must be an explicit array");
|
|
271
|
+
if (!("install" in input) || input.install !== "bun install --frozen-lockfile") throw new Error(`cloud.install must be exactly ${cloudInstallCommand}`);
|
|
272
|
+
if (!("envFile" in input) || typeof input.envFile !== "string") throw new Error("cloud.envFile must be a canonical repository-relative path");
|
|
273
|
+
const envFile = input.envFile;
|
|
274
|
+
if (envFile.startsWith("/") || /^[A-Za-z]:/.test(envFile) || envFile.includes("\\") || /\p{Cc}/u.test(envFile) || envFile.split("/").some((part) => part === "" || part === "." || part === "..")) throw new Error("cloud.envFile must be a canonical repository-relative path");
|
|
275
|
+
const seen = /* @__PURE__ */ new Set();
|
|
276
|
+
return {
|
|
277
|
+
services: Array.from(input.services, (service) => {
|
|
278
|
+
if (!cloudService(service)) throw new Error("cloud.services contains an unsupported service");
|
|
279
|
+
if (seen.has(service)) throw new Error(`cloud.services contains duplicate service: ${service}`);
|
|
280
|
+
seen.add(service);
|
|
281
|
+
return service;
|
|
282
|
+
}),
|
|
283
|
+
install: cloudInstallCommand,
|
|
284
|
+
envFile
|
|
285
|
+
};
|
|
286
|
+
};
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/cloud-setup-services.ts
|
|
289
|
+
const common = String.raw`
|
|
290
|
+
service_file() {
|
|
291
|
+
local file="$1" owner="$2"
|
|
292
|
+
[[ ! -L "$file" ]] || fail "Service state must not contain symbolic links"
|
|
293
|
+
if [[ -e "$file" ]]; then
|
|
294
|
+
[[ -f "$file" && "$(stat -c '%u:%a' "$file")" == "$owner:600" ]] || fail "Invalid service state file"
|
|
295
|
+
fi
|
|
296
|
+
}
|
|
297
|
+
service_directory() {
|
|
298
|
+
local directory="$1"
|
|
299
|
+
[[ ! -L "$directory" ]] || fail "Service directory must not be a symbolic link"
|
|
300
|
+
if [[ -e "$directory" ]]; then
|
|
301
|
+
[[ -d "$directory" && "$(stat -c '%u:%a' "$directory")" == "$SERVICE_UID:700" ]] || fail "Invalid service directory"
|
|
302
|
+
else
|
|
303
|
+
root install -d -m 700 -o stll-cloud -g stll-cloud "$directory"
|
|
304
|
+
fi
|
|
305
|
+
}
|
|
306
|
+
service_password() {
|
|
307
|
+
local file="$1"
|
|
308
|
+
service_file "$file" 0
|
|
309
|
+
if [[ ! -e "$file" ]]; then
|
|
310
|
+
(umask 077; openssl rand -hex 32 > "$file")
|
|
311
|
+
root chown root:root "$file"
|
|
312
|
+
fi
|
|
313
|
+
[[ "$(cat "$file")" =~ ^[0-9a-f]{64}$ ]] || fail "Invalid service credential state"
|
|
314
|
+
}
|
|
315
|
+
service_process_matches() {
|
|
316
|
+
local pid="$1" executable="$2" owner actual expected
|
|
317
|
+
[[ "$pid" =~ ^[1-9][0-9]*$ && -d "/proc/$pid" ]] || return 1
|
|
318
|
+
owner="$(stat -c '%u' "/proc/$pid" 2>/dev/null)" || return 2
|
|
319
|
+
[[ "$owner" =~ ^[0-9]+$ ]] || return 2
|
|
320
|
+
[[ "$owner" == "$SERVICE_UID" ]] || return 1
|
|
321
|
+
actual="$(readlink -f "/proc/$pid/exe" 2>/dev/null)" || return 2
|
|
322
|
+
expected="$(readlink -f "$executable")" || return 2
|
|
323
|
+
[[ -n "$actual" && -n "$expected" && "$actual" != *' (deleted)' ]] || return 2
|
|
324
|
+
[[ "$actual" == "$expected" ]]
|
|
325
|
+
}
|
|
326
|
+
service_process() {
|
|
327
|
+
service_process_matches "$1" "$2" || fail "Managed service process identity differs from the recorded state"
|
|
328
|
+
}
|
|
329
|
+
service_prune_pid() {
|
|
330
|
+
local file="$1" executable="$2" service="$3" pid identity
|
|
331
|
+
[[ -e "$file" ]] || return 0
|
|
332
|
+
pid="$(head -n 1 "$file")"
|
|
333
|
+
# PostgreSQL encodes a standalone backend with a negative PID.
|
|
334
|
+
if [[ "$service" == postgres ]]; then pid="$(printf '%s' "$pid" | sed 's/^-//')"; fi
|
|
335
|
+
if service_process_matches "$pid" "$executable"; then return 0; else identity=$?; fi
|
|
336
|
+
[[ "$identity" != 2 ]] || fail "Cannot verify recorded live service process; retaining its PID file"
|
|
337
|
+
# Let PostgreSQL check orphan shared memory before removing a dead-PID lock.
|
|
338
|
+
if [[ "$service" == postgres && "$pid" =~ ^[1-9][0-9]*$ && ! -d "/proc/$pid" ]]; then return 0; fi
|
|
339
|
+
if [[ "$service" == postgres ]]; then
|
|
340
|
+
[[ "$pid" =~ ^[1-9][0-9]*$ && "$SERVICE_UID" != 0 ]] || fail "Cannot safely recover PostgreSQL PID state"
|
|
341
|
+
# The root controller is not our nonroot postgres. Preserve the remaining
|
|
342
|
+
# lock rows so PostgreSQL's EPERM/ancestor path still checks orphan memory.
|
|
343
|
+
root sed -i "1s/.*/$$/" "$file"
|
|
344
|
+
return 0
|
|
345
|
+
fi
|
|
346
|
+
# Restored state can name an unrelated live process; never signal that PID.
|
|
347
|
+
root rm -- "$file"
|
|
348
|
+
}
|
|
349
|
+
`;
|
|
350
|
+
const postgresStart = String.raw`
|
|
351
|
+
local pg_bin='/usr/lib/postgresql/@POSTGRES@/bin' pg_data="$STATE/postgres" pg_password pg_details pg_pid pg_version
|
|
352
|
+
service_password "$STATE/postgres.password"
|
|
353
|
+
pg_password="$(cat "$STATE/postgres.password")"
|
|
354
|
+
service_directory "$pg_data"
|
|
355
|
+
for file in PG_VERSION postmaster.pid postgresql.conf pg_hba.conf pg_ident.conf postgresql.auto.conf; do
|
|
356
|
+
service_file "$pg_data/$file" "$SERVICE_UID"
|
|
357
|
+
done
|
|
358
|
+
if [[ ! -e "$pg_data/PG_VERSION" ]]; then
|
|
359
|
+
[[ -z "$(ls -A "$pg_data")" ]] || fail "PostgreSQL data directory is not initialized"
|
|
360
|
+
service_file "$STATE/postgres.init-password" "$SERVICE_UID"
|
|
361
|
+
(umask 077; printf '%s\n' "$pg_password" > "$STATE/postgres.init-password")
|
|
362
|
+
root chown stll-cloud:stll-cloud "$STATE/postgres.init-password"
|
|
363
|
+
service_run env PGHOST=127.0.0.1 PGHOSTADDR=127.0.0.1 "$pg_bin/initdb" -D "$pg_data" --username=stll_cloud --auth-host=scram-sha-256 --auth-local=scram-sha-256 --pwfile="$STATE/postgres.init-password" --encoding=UTF8 --locale=C --set=unix_socket_directories= >/dev/null || fail "PostgreSQL initialization failed"
|
|
364
|
+
root rm "$STATE/postgres.init-password"
|
|
365
|
+
fi
|
|
366
|
+
[[ -f "$pg_data/PG_VERSION" && "$(cat "$pg_data/PG_VERSION")" == '@POSTGRES@' ]] || fail "PostgreSQL data has a different major version"
|
|
367
|
+
service_prune_pid "$pg_data/postmaster.pid" "$pg_bin/postgres" postgres
|
|
368
|
+
if ! service_run env PGHOST=127.0.0.1 PGHOSTADDR=127.0.0.1 "$pg_bin/pg_ctl" -D "$pg_data" status >/dev/null 2>&1; then
|
|
369
|
+
service_run env PGHOST=127.0.0.1 PGHOSTADDR=127.0.0.1 "$pg_bin/pg_ctl" -D "$pg_data" -l "$pg_data/cloud.log" -o "-h 127.0.0.1 -p 55432 -c unix_socket_directories=" -t 10 -w start >/dev/null || fail "PostgreSQL start failed; port 55432 must be available"
|
|
370
|
+
fi
|
|
371
|
+
pg_details="$(env -u PGSERVICE -u PGSERVICEFILE -u PGOPTIONS PGHOSTADDR=127.0.0.1 PGPASSWORD="$pg_password" PGCONNECT_TIMEOUT=2 "$pg_bin/psql" -X -h 127.0.0.1 -p 55432 -U stll_cloud -d postgres -At -v ON_ERROR_STOP=1 -c "SELECT current_setting('data_directory'), current_setting('listen_addresses'), current_setting('port'), current_setting('server_version_num'), current_setting('unix_socket_directories')")" || fail "PostgreSQL authenticated readiness failed"
|
|
372
|
+
pg_version="$(printf '%s\n' "$pg_details" | cut -d '|' -f4)"
|
|
373
|
+
[[ "$pg_details" == "$pg_data|127.0.0.1|55432|$pg_version|" && "$pg_version" =~ ^[0-9]{6}$ ]] || fail "PostgreSQL endpoint does not match managed data and listener"
|
|
374
|
+
(( pg_version / 10000 == @POSTGRES@ )) || fail "PostgreSQL endpoint has a different major version"
|
|
375
|
+
pg_pid="$(head -n 1 "$pg_data/postmaster.pid")"
|
|
376
|
+
service_process "$pg_pid" "$pg_bin/postgres"
|
|
377
|
+
[[ "$(env -u PGSERVICE -u PGSERVICEFILE -u PGOPTIONS PGHOSTADDR=127.0.0.1 PGPASSWORD="$pg_password" PGCONNECT_TIMEOUT=2 "$pg_bin/psql" -X -h 127.0.0.1 -p 55432 -U stll_cloud -d postgres -At -v ON_ERROR_STOP=1 -c "SELECT count(*) FROM pg_database WHERE datname = 'cloud_test'")" == 1 ]] || env -u PGSERVICE -u PGSERVICEFILE -u PGOPTIONS PGHOSTADDR=127.0.0.1 PGPASSWORD="$pg_password" PGCONNECT_TIMEOUT=2 "$pg_bin/createdb" -h 127.0.0.1 -p 55432 -U stll_cloud cloud_test || fail "PostgreSQL test database creation failed"
|
|
378
|
+
DATABASE_URL="postgresql://stll_cloud:$pg_password@127.0.0.1:55432/cloud_test"
|
|
379
|
+
`;
|
|
380
|
+
const valkeyStart = String.raw`
|
|
381
|
+
local vk_data="$STATE/valkey" vk_password vk_config vk_info vk_pid vk_expected ready=0
|
|
382
|
+
service_password "$STATE/valkey.password"
|
|
383
|
+
vk_password="$(cat "$STATE/valkey.password")"
|
|
384
|
+
service_directory "$vk_data"
|
|
385
|
+
vk_config="$vk_data/valkey.conf"
|
|
386
|
+
service_file "$vk_config" "$SERVICE_UID"
|
|
387
|
+
for file in valkey.pid valkey.log dump.rdb; do
|
|
388
|
+
[[ ! -L "$vk_data/$file" ]] || fail "Valkey state must not contain symbolic links"
|
|
389
|
+
if [[ -e "$vk_data/$file" ]]; then
|
|
390
|
+
[[ -f "$vk_data/$file" && "$(stat -c '%u' "$vk_data/$file")" == "$SERVICE_UID" ]] || fail "Invalid Valkey state file"
|
|
391
|
+
fi
|
|
392
|
+
done
|
|
393
|
+
vk_expected="$(printf '%s\n' 'bind 127.0.0.1' 'port 56379' 'protected-mode yes' 'daemonize yes' "requirepass $vk_password" "dir $vk_data" "pidfile $vk_data/valkey.pid" "logfile $vk_data/valkey.log" 'save ""' 'appendonly no')"
|
|
394
|
+
if [[ ! -e "$vk_config" ]]; then
|
|
395
|
+
(umask 077; printf '%s\n' "$vk_expected" > "$vk_config")
|
|
396
|
+
root chown stll-cloud:stll-cloud "$vk_config"
|
|
397
|
+
fi
|
|
398
|
+
[[ "$(cat "$vk_config")" == "$vk_expected" ]] || fail "Valkey configuration differs from managed settings"
|
|
399
|
+
service_prune_pid "$vk_data/valkey.pid" "$(command -v valkey-server)" valkey
|
|
400
|
+
if [[ ! -e "$vk_data/valkey.pid" ]]; then
|
|
401
|
+
service_run valkey-server "$vk_config" || fail "Valkey start failed; port 56379 must be available"
|
|
402
|
+
fi
|
|
403
|
+
for ((attempt=0; attempt<20; attempt++)); do
|
|
404
|
+
if vk_info="$(VALKEYCLI_AUTH="$vk_password" timeout 0.2 valkey-cli -h 127.0.0.1 -p 56379 --raw INFO server 2>/dev/null)"; then
|
|
405
|
+
if [[ "$vk_info" == *$'valkey_version:@VALKEY@\r\n'* && "$vk_info" == *"config_file:$vk_config"$'\r\n'* ]]; then ready=1; break; fi
|
|
406
|
+
fi
|
|
407
|
+
sleep 0.25
|
|
408
|
+
done
|
|
409
|
+
[[ "$ready" == 1 ]] || fail "Valkey authenticated readiness or managed version/configuration check failed"
|
|
410
|
+
[[ -f "$vk_data/valkey.pid" ]] || fail "Valkey managed process identifier is unavailable"
|
|
411
|
+
vk_pid="$(cat "$vk_data/valkey.pid")"
|
|
412
|
+
service_process "$vk_pid" "$(command -v valkey-server)"
|
|
413
|
+
[[ "$vk_info" == *"process_id:$vk_pid"$'\r\n'* ]] || fail "Valkey endpoint has a different process identifier"
|
|
414
|
+
[[ "$(VALKEYCLI_AUTH="$vk_password" timeout 2 valkey-cli -h 127.0.0.1 -p 56379 --raw CONFIG GET bind)" == $'bind\n127.0.0.1' ]] || fail "Valkey endpoint must bind only loopback"
|
|
415
|
+
[[ "$(VALKEYCLI_AUTH="$vk_password" timeout 2 valkey-cli -h 127.0.0.1 -p 56379 --raw CONFIG GET dir)" == "$(printf 'dir\n%s' "$vk_data")" ]] || fail "Valkey endpoint has a different data directory"
|
|
416
|
+
REDIS_URL="redis://:$vk_password@127.0.0.1:56379/0"
|
|
417
|
+
`;
|
|
418
|
+
/** Render only declared services; installation and environment-file ownership stay with the caller. */
|
|
419
|
+
const renderCloudServiceStart = ({ services, postgres, valkey }) => {
|
|
420
|
+
if (!/^[1-9][0-9]*$/.test(postgres) || !/^\d+\.\d+\.\d+$/.test(valkey)) throw new Error("Invalid cloud service runtime policy");
|
|
421
|
+
if (services.length === 0) return "start_services() { :; }\n";
|
|
422
|
+
const bodies = services.map((service) => {
|
|
423
|
+
switch (service) {
|
|
424
|
+
case "postgres": return postgresStart.replaceAll("@POSTGRES@", postgres);
|
|
425
|
+
case "valkey": return valkeyStart.replaceAll("@VALKEY@", valkey);
|
|
426
|
+
default: throw new Error(`Unsupported cloud service: ${String(service)}`);
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
return `${common}\nstart_services() {\n local SERVICE_UID file attempt\n SERVICE_UID="$(id -u stll-cloud)"\n [[ -d "$STATE" && ! -L "$STATE" && "$(stat -c '%u' "$STATE")" == 0 ]] || fail "Invalid cloud service state directory"\n${bodies.join("")}\n}\n`;
|
|
430
|
+
};
|
|
431
|
+
//#endregion
|
|
432
|
+
//#region src/toolchain-node.ts
|
|
433
|
+
const numericComponent = "(?:0|[1-9]\\d*)";
|
|
434
|
+
const policyPattern = new RegExp(`^${numericComponent}\\.x$`);
|
|
435
|
+
const selectorPattern = new RegExp(`^(${numericComponent})(?:\\.(?:x|${numericComponent}(?:\\.${numericComponent})?))?$`);
|
|
436
|
+
/** A Node policy selects the complete stable release series of one major. */
|
|
437
|
+
const nodePolicyValid = (value) => policyPattern.test(value) && validRange(value) !== null;
|
|
438
|
+
/** Static selectors may narrow that series, but cannot float across majors. */
|
|
439
|
+
const nodeSelectorMatches = (value, policy) => {
|
|
440
|
+
if (!nodePolicyValid(policy) || typeof value !== "string") return false;
|
|
441
|
+
const major = selectorPattern.exec(value)?.[1];
|
|
442
|
+
return major !== void 0 && major === policy.slice(0, -2) && validRange(value) !== null;
|
|
443
|
+
};
|
|
444
|
+
/** Engines must support every stable release in the approved major series. */
|
|
445
|
+
const nodeSupportRangeMatches = (policy, range) => {
|
|
446
|
+
if (!nodePolicyValid(policy)) return false;
|
|
447
|
+
try {
|
|
448
|
+
return subset(policy, range);
|
|
449
|
+
} catch {
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region src/cloud-setup.ts
|
|
455
|
+
const cloudSetupPath = ".agents/cloud-setup.sh";
|
|
456
|
+
const cloudEnvironmentMarker = "# Generated by stll-cloud-setup; disposable local test services.";
|
|
457
|
+
const script = String.raw`#!/usr/bin/env bash
|
|
458
|
+
# Generated by stll-cloud-setup. Regenerate with stll-cloud-setup.
|
|
459
|
+
# Networked installation and offline service startup are separate lifecycle steps.
|
|
460
|
+
# Cached filesystems may not preserve processes; run start at every session start.
|
|
461
|
+
# Supported platform: Ubuntu 24.04 (noble), amd64/arm64, root or passwordless sudo.
|
|
462
|
+
set -euo pipefail
|
|
463
|
+
|
|
464
|
+
usage() { echo 'Usage: cloud-setup.sh install|start' >&2; exit 2; }
|
|
465
|
+
[[ "$#" == 1 ]] || usage
|
|
466
|
+
case "$1" in install|start) MODE="$1" ;; *) usage ;; esac
|
|
467
|
+
fail() { echo "cloud-setup: $*" >&2; exit 1; }
|
|
468
|
+
trap 'echo "cloud-setup: command failed at line $LINENO" >&2' ERR
|
|
469
|
+
[[ -f /etc/os-release ]] || fail 'Ubuntu 24.04 is required'
|
|
470
|
+
. /etc/os-release
|
|
471
|
+
[[ "$ID" == ubuntu && "$VERSION_ID" == 24.04 && "$VERSION_CODENAME" == noble ]] || fail 'Only Ubuntu 24.04 (noble) is supported'
|
|
472
|
+
SCRIPT="$(realpath -- "$0")"
|
|
473
|
+
REPO_ROOT="$(cd -- "$(dirname -- "$SCRIPT")/.." && pwd -P)"
|
|
474
|
+
[[ "$SCRIPT" == "$REPO_ROOT/.agents/cloud-setup.sh" ]] || fail 'Run the generated repository script'
|
|
475
|
+
if [[ "$(id -u)" != 0 ]]; then
|
|
476
|
+
command -v sudo >/dev/null && sudo -n true || fail 'Root or passwordless sudo is required'
|
|
477
|
+
exec sudo -n -- bash "$SCRIPT" "$MODE"
|
|
478
|
+
fi
|
|
479
|
+
OUTPUT_UID="$(printenv SUDO_UID || id -u)"
|
|
480
|
+
[[ "$OUTPUT_UID" =~ ^[0-9]+$ ]] || fail 'Invalid invoking user'
|
|
481
|
+
OUTPUT_GID="$(getent passwd "$OUTPUT_UID" | cut -d: -f4)"
|
|
482
|
+
[[ "$OUTPUT_GID" =~ ^[0-9]+$ ]] || fail 'Invoking user is unavailable'
|
|
483
|
+
OUTPUT_USER="$(getent passwd "$OUTPUT_UID" | cut -d: -f1)"
|
|
484
|
+
OUTPUT_HOME="$(getent passwd "$OUTPUT_UID" | cut -d: -f6)"
|
|
485
|
+
[[ -n "$OUTPUT_USER" && "$OUTPUT_HOME" == /* && -d "$OUTPUT_HOME" ]] || fail 'Invoking user requires an existing home directory'
|
|
486
|
+
root() { "$@"; }
|
|
487
|
+
service_run() { runuser -u stll-cloud -- "$@" 9>&-; }
|
|
488
|
+
BUN_VERSION='@BUN@'
|
|
489
|
+
NODE_VERSION='@NODE@'
|
|
490
|
+
NODE_DIR="/opt/stll-cloud/node/$NODE_VERSION"
|
|
491
|
+
BUN_DIR="/opt/stll-cloud/bun/$BUN_VERSION"
|
|
492
|
+
export PATH="$NODE_DIR/bin:$BUN_DIR:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
493
|
+
BUN_CACHE="/var/cache/stll-cloud/bun/$OUTPUT_UID"
|
|
494
|
+
ENV_FILE=@ENV_FILE@
|
|
495
|
+
ENV_MARKER='@ENV_MARKER@'
|
|
496
|
+
[[ -f "$REPO_ROOT/.node-version" && ! -L "$REPO_ROOT/.node-version" ]] || fail 'A regular root .node-version is required'
|
|
497
|
+
[[ "$(awk 'NF { if (++count > 1 || NF != 1) exit 1; value=$1 } END { if (count != 1) exit 1; print value }' "$REPO_ROOT/.node-version")" == "$NODE_VERSION" ]] || fail 'Node selector changed; regenerate cloud-setup.sh'
|
|
498
|
+
cd -- "$REPO_ROOT"
|
|
499
|
+
case "$(uname -m)" in
|
|
500
|
+
x86_64) ARCH=amd64; NODE_ARCH=x64; BUN_ARCH=x64 ;;
|
|
501
|
+
aarch64|arm64) ARCH=arm64; NODE_ARCH=arm64; BUN_ARCH=aarch64 ;;
|
|
502
|
+
*) fail 'Only amd64 and arm64 are supported' ;;
|
|
503
|
+
esac
|
|
504
|
+
|
|
505
|
+
runtime_ready() {
|
|
506
|
+
[[ -x "$NODE_DIR/bin/node" && "$($NODE_DIR/bin/node --version)" == "v$NODE_VERSION" ]] || fail 'Pinned Node is unavailable; run install'
|
|
507
|
+
[[ -x "$BUN_DIR/bun" && "$($BUN_DIR/bun --version)" == "$BUN_VERSION" ]] || fail 'Pinned Bun is unavailable; run install'
|
|
508
|
+
}
|
|
509
|
+
install_runtimes() {
|
|
510
|
+
if ! command -v curl >/dev/null || ! command -v unzip >/dev/null || ! command -v xz >/dev/null || ! command -v openssl >/dev/null || ! command -v gpg >/dev/null; then
|
|
511
|
+
apt-get update
|
|
512
|
+
DEBIAN_FRONTEND=noninteractive apt_install ca-certificates curl unzip xz-utils openssl gnupg util-linux
|
|
513
|
+
fi
|
|
514
|
+
local scratch node_archive bun_archive bun_folder
|
|
515
|
+
scratch="$(mktemp -d)"
|
|
516
|
+
trap 'rm -rf -- "$scratch"' RETURN
|
|
517
|
+
if [[ ! -x "$NODE_DIR/bin/node" ]] || [[ "$($NODE_DIR/bin/node --version)" != "v$NODE_VERSION" ]]; then
|
|
518
|
+
node_archive="node-v$NODE_VERSION-linux-$NODE_ARCH.tar.xz"
|
|
519
|
+
curl --fail --silent --show-error --location --proto '=https' --proto-redir '=https' --tlsv1.2 "https://nodejs.org/dist/v$NODE_VERSION/$node_archive" -o "$scratch/$node_archive"
|
|
520
|
+
curl --fail --silent --show-error --location --proto '=https' --proto-redir '=https' --tlsv1.2 "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt" -o "$scratch/node-sums"
|
|
521
|
+
(cd "$scratch"; awk -v name="$node_archive" '$2 == name { print; count++ } END { if (count != 1) exit 1 }' node-sums | sha256sum --strict -c -)
|
|
522
|
+
install -d -m 755 "$NODE_DIR"
|
|
523
|
+
tar -xJf "$scratch/$node_archive" --strip-components=1 -C "$NODE_DIR"
|
|
524
|
+
fi
|
|
525
|
+
if [[ ! -x "$BUN_DIR/bun" ]] || [[ "$($BUN_DIR/bun --version)" != "$BUN_VERSION" ]]; then
|
|
526
|
+
bun_folder="bun-linux-$BUN_ARCH"
|
|
527
|
+
bun_archive="$bun_folder.zip"
|
|
528
|
+
curl --fail --silent --show-error --location --proto '=https' --proto-redir '=https' --tlsv1.2 "https://github.com/oven-sh/bun/releases/download/bun-v$BUN_VERSION/$bun_archive" -o "$scratch/$bun_archive"
|
|
529
|
+
curl --fail --silent --show-error --location --proto '=https' --proto-redir '=https' --tlsv1.2 "https://github.com/oven-sh/bun/releases/download/bun-v$BUN_VERSION/SHASUMS256.txt" -o "$scratch/bun-sums"
|
|
530
|
+
(cd "$scratch"; awk -v name="$bun_archive" '$2 == name || $2 == "*" name { print $1 " " name; count++ } END { if (count != 1) exit 1 }' bun-sums | sha256sum --strict -c -)
|
|
531
|
+
unzip -q "$scratch/$bun_archive" -d "$scratch/bun"
|
|
532
|
+
install -d -m 755 "$BUN_DIR"
|
|
533
|
+
install -m 755 "$scratch/bun/$bun_folder/bun" "$BUN_DIR/bun"
|
|
534
|
+
fi
|
|
535
|
+
runtime_ready
|
|
536
|
+
ln -sfnT -- "$NODE_DIR/bin/node" /usr/local/bin/node
|
|
537
|
+
ln -sfnT -- "$NODE_DIR/bin/npm" /usr/local/bin/npm
|
|
538
|
+
ln -sfnT -- "$NODE_DIR/bin/npx" /usr/local/bin/npx
|
|
539
|
+
ln -sfnT -- "$BUN_DIR/bun" /usr/local/bin/bun
|
|
540
|
+
rm -rf -- "$scratch"
|
|
541
|
+
trap - RETURN
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
dependency_install() {
|
|
545
|
+
local directory
|
|
546
|
+
for directory in /var/cache/stll-cloud /var/cache/stll-cloud/bun; do
|
|
547
|
+
[[ ! -L "$directory" ]] || fail 'Dependency cache parent must not be a symlink'
|
|
548
|
+
if [[ -e "$directory" ]]; then
|
|
549
|
+
[[ -d "$directory" && "$(stat -c '%u' "$directory")" == 0 ]] || fail 'Dependency cache parent must be root-owned'
|
|
550
|
+
fi
|
|
551
|
+
install -d -m 755 -o root -g root "$directory"
|
|
552
|
+
done
|
|
553
|
+
[[ ! -L "$BUN_CACHE" ]] || fail 'Dependency cache must not be a symlink'
|
|
554
|
+
if [[ -e "$BUN_CACHE" ]]; then
|
|
555
|
+
[[ -d "$BUN_CACHE" && "$(stat -c '%u' "$BUN_CACHE")" == "$OUTPUT_UID" ]] || fail 'Dependency cache ownership differs from the invoking user'
|
|
556
|
+
fi
|
|
557
|
+
install -d -m 700 -o "$OUTPUT_UID" -g "$OUTPUT_GID" "$BUN_CACHE"
|
|
558
|
+
runuser -u "$OUTPUT_USER" -- env HOME="$OUTPUT_HOME" BUN_INSTALL_CACHE_DIR="$BUN_CACHE" PATH="$PATH" "$BUN_DIR/bun" install --frozen-lockfile
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
@SERVICE_INSTALL@
|
|
562
|
+
@SERVICE_START@
|
|
563
|
+
|
|
564
|
+
validate_environment() {
|
|
565
|
+
local part target="$REPO_ROOT" env_path="$REPO_ROOT/$ENV_FILE" first_line temporary
|
|
566
|
+
while IFS= read -r part; do
|
|
567
|
+
target="$target/$part"
|
|
568
|
+
[[ ! -L "$target" ]] || fail 'Environment path must not contain symbolic links'
|
|
569
|
+
done < <(printf '%s\n' "$ENV_FILE" | tr '/' '\n')
|
|
570
|
+
[[ -d "$(dirname -- "$env_path")" ]] || fail 'Environment parent directory is missing'
|
|
571
|
+
if [[ -e "$env_path" ]]; then
|
|
572
|
+
[[ -f "$env_path" ]] || fail 'Environment target must be a regular file'
|
|
573
|
+
IFS= read -r first_line < "$env_path" || fail 'Refusing to overwrite an unowned environment file'
|
|
574
|
+
[[ "$first_line" == "$ENV_MARKER" ]] || fail 'Refusing to overwrite an unowned environment file'
|
|
575
|
+
fi
|
|
576
|
+
}
|
|
577
|
+
write_environment() {
|
|
578
|
+
validate_environment
|
|
579
|
+
local env_path="$REPO_ROOT/$ENV_FILE" temporary
|
|
580
|
+
temporary="$(mktemp "$(dirname -- "$env_path")/.stll-cloud-env.XXXXXX")"
|
|
581
|
+
chmod 600 "$temporary"
|
|
582
|
+
{
|
|
583
|
+
printf '%s\n' "$ENV_MARKER" 'NODE_ENV=test'
|
|
584
|
+
if [[ -n "$DATABASE_URL" ]]; then printf 'DATABASE_URL=%s\n' "$DATABASE_URL"; fi
|
|
585
|
+
if [[ -n "$REDIS_URL" ]]; then printf 'REDIS_URL=%s\n' "$REDIS_URL"; fi
|
|
586
|
+
} > "$temporary"
|
|
587
|
+
chown "$OUTPUT_UID:$OUTPUT_GID" "$temporary"
|
|
588
|
+
mv -f -- "$temporary" "$env_path"
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
if [[ "$MODE" == install ]]; then
|
|
592
|
+
install_runtimes
|
|
593
|
+
install_services
|
|
594
|
+
dependency_install
|
|
595
|
+
exit 0
|
|
596
|
+
fi
|
|
597
|
+
runtime_ready
|
|
598
|
+
DATABASE_URL=''
|
|
599
|
+
REDIS_URL=''
|
|
600
|
+
validate_environment
|
|
601
|
+
prepare_state
|
|
602
|
+
start_services
|
|
603
|
+
write_environment
|
|
604
|
+
`;
|
|
605
|
+
const shellQuote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
606
|
+
const generateCloudSetup = ({ policy, cloud, nodeVersion }) => {
|
|
607
|
+
const selected = parseCloudSetup(cloud);
|
|
608
|
+
if (selected === void 0) throw new Error("cloud declaration is required");
|
|
609
|
+
const exactNode = nodeVersion.trim();
|
|
610
|
+
if (valid(exactNode) !== exactNode || !nodeSelectorMatches(exactNode, policy.node)) throw new Error("cloud requires a tracked exact .node-version within the shared Node series");
|
|
611
|
+
const services = cloudServices.filter((service) => selected.services.includes(service));
|
|
612
|
+
const replacements = /* @__PURE__ */ new Map([
|
|
613
|
+
["@BUN@", policy.bun],
|
|
614
|
+
["@NODE@", exactNode],
|
|
615
|
+
["@ENV_FILE@", shellQuote(selected.envFile)],
|
|
616
|
+
["@ENV_MARKER@", cloudEnvironmentMarker],
|
|
617
|
+
["@SERVICE_INSTALL@", renderCloudServiceInstall({
|
|
618
|
+
services,
|
|
619
|
+
postgres: policy.postgres,
|
|
620
|
+
valkey: policy.valkey,
|
|
621
|
+
valkeyArtifacts: policy.valkeyArtifacts
|
|
622
|
+
})],
|
|
623
|
+
["@SERVICE_START@", renderCloudServiceStart({
|
|
624
|
+
services,
|
|
625
|
+
postgres: policy.postgres,
|
|
626
|
+
valkey: policy.valkey
|
|
627
|
+
})]
|
|
628
|
+
]);
|
|
629
|
+
return script.replace(/@[A-Z0-9_]+@/g, (token) => {
|
|
630
|
+
const value = replacements.get(token);
|
|
631
|
+
if (value === void 0) throw new Error(`Missing cloud setup field: ${token}`);
|
|
632
|
+
return value;
|
|
633
|
+
});
|
|
634
|
+
};
|
|
635
|
+
//#endregion
|
|
636
|
+
//#region src/toolchain-container-inputs.ts
|
|
637
|
+
const record$6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
638
|
+
/** Filename class recognized by Dependabot's Docker Compose fetcher. */
|
|
639
|
+
const isComposeDefinitionPath = (file) => /^\.?(?:docker-)?compose(?:-[\w]+)?(?:\.[\w-]+)?\.ya?ml$/i.test(file.split("/").at(-1) ?? "");
|
|
640
|
+
/** Candidate YAML files are classified by their document shape after reading. */
|
|
641
|
+
const isKubernetesDefinitionPath = (file) => /^[^.].*\.ya?ml$/i.test(file.split("/").at(-1) ?? "");
|
|
642
|
+
const kubernetesPodSpecPaths = {
|
|
643
|
+
Pod: ["spec"],
|
|
644
|
+
Deployment: [
|
|
645
|
+
"spec",
|
|
646
|
+
"template",
|
|
647
|
+
"spec"
|
|
648
|
+
],
|
|
649
|
+
DaemonSet: [
|
|
650
|
+
"spec",
|
|
651
|
+
"template",
|
|
652
|
+
"spec"
|
|
653
|
+
],
|
|
654
|
+
StatefulSet: [
|
|
655
|
+
"spec",
|
|
656
|
+
"template",
|
|
657
|
+
"spec"
|
|
658
|
+
],
|
|
659
|
+
ReplicaSet: [
|
|
660
|
+
"spec",
|
|
661
|
+
"template",
|
|
662
|
+
"spec"
|
|
663
|
+
],
|
|
664
|
+
ReplicationController: [
|
|
665
|
+
"spec",
|
|
666
|
+
"template",
|
|
667
|
+
"spec"
|
|
668
|
+
],
|
|
669
|
+
Job: [
|
|
670
|
+
"spec",
|
|
671
|
+
"template",
|
|
672
|
+
"spec"
|
|
673
|
+
],
|
|
674
|
+
CronJob: [
|
|
675
|
+
"spec",
|
|
676
|
+
"jobTemplate",
|
|
677
|
+
"spec",
|
|
678
|
+
"template",
|
|
679
|
+
"spec"
|
|
680
|
+
]
|
|
681
|
+
};
|
|
682
|
+
/** Shared semantic image enumeration for runtime checks and update-root generation. */
|
|
683
|
+
const containerDocumentImages = (document, file) => {
|
|
684
|
+
if (!record$6(document)) return void 0;
|
|
685
|
+
const services = document["services"];
|
|
686
|
+
if (isComposeDefinitionPath(file) && record$6(services)) {
|
|
687
|
+
const images = [];
|
|
688
|
+
for (const [name, service] of Object.entries(services)) if (record$6(service) && service["image"] !== void 0) images.push({
|
|
689
|
+
image: service["image"],
|
|
690
|
+
path: [
|
|
691
|
+
"services",
|
|
692
|
+
name,
|
|
693
|
+
"image"
|
|
694
|
+
]
|
|
695
|
+
});
|
|
696
|
+
return {
|
|
697
|
+
ecosystem: "docker-compose",
|
|
698
|
+
images
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
if (typeof document["apiVersion"] !== "string" || typeof document["kind"] !== "string") return void 0;
|
|
702
|
+
const images = [];
|
|
703
|
+
const visited = /* @__PURE__ */ new Set();
|
|
704
|
+
const walkResource = (resource, prefix) => {
|
|
705
|
+
if (visited.has(resource)) return;
|
|
706
|
+
visited.add(resource);
|
|
707
|
+
if (typeof resource["apiVersion"] !== "string" || typeof resource["kind"] !== "string") return;
|
|
708
|
+
if (resource["kind"] === "List" && Array.isArray(resource["items"])) {
|
|
709
|
+
for (const [index, item] of resource["items"].entries()) if (record$6(item)) walkResource(item, [
|
|
710
|
+
...prefix,
|
|
711
|
+
"items",
|
|
712
|
+
index
|
|
713
|
+
]);
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
const specPath = Object.entries(kubernetesPodSpecPaths).find(([kind]) => kind === resource["kind"])?.[1];
|
|
717
|
+
if (specPath === void 0) return;
|
|
718
|
+
let spec = resource;
|
|
719
|
+
for (const key of specPath) spec = record$6(spec) ? spec[key] : void 0;
|
|
720
|
+
if (!record$6(spec)) return;
|
|
721
|
+
for (const key of [
|
|
722
|
+
"containers",
|
|
723
|
+
"initContainers",
|
|
724
|
+
"ephemeralContainers"
|
|
725
|
+
]) {
|
|
726
|
+
const containers = spec[key];
|
|
727
|
+
if (!Array.isArray(containers)) continue;
|
|
728
|
+
for (const [index, container] of containers.entries()) if (record$6(container) && container["image"] !== void 0) images.push({
|
|
729
|
+
image: container["image"],
|
|
730
|
+
path: [
|
|
731
|
+
...prefix,
|
|
732
|
+
...specPath,
|
|
733
|
+
key,
|
|
734
|
+
index,
|
|
735
|
+
"image"
|
|
736
|
+
]
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
walkResource(document, []);
|
|
741
|
+
return images.length === 0 ? void 0 : {
|
|
742
|
+
ecosystem: "docker",
|
|
743
|
+
images
|
|
744
|
+
};
|
|
745
|
+
};
|
|
746
|
+
//#endregion
|
|
747
|
+
//#region src/toolchain-images.ts
|
|
748
|
+
/** Docker Hub spellings accepted by the shared runtime policy. */
|
|
749
|
+
const dockerHubRegistries = [
|
|
750
|
+
"docker.io",
|
|
751
|
+
"index.docker.io",
|
|
752
|
+
"registry-1.docker.io"
|
|
753
|
+
];
|
|
754
|
+
/** Expand the full accepted repository alias class without parsing Dockerfile instructions. */
|
|
755
|
+
const ownedDockerImageAliases = (images) => {
|
|
756
|
+
const aliases = /* @__PURE__ */ new Set();
|
|
757
|
+
for (const image of images) for (const repository of [image, `library/${image}`]) {
|
|
758
|
+
aliases.add(repository);
|
|
759
|
+
for (const registry of dockerHubRegistries) aliases.add(`${registry}/${repository}`);
|
|
760
|
+
}
|
|
761
|
+
return [...aliases].sort();
|
|
762
|
+
};
|
|
763
|
+
/** Preserve tag/digest spelling while normalizing registry and namespace aliases. */
|
|
764
|
+
const canonicalDockerRuntime = (image) => {
|
|
765
|
+
const registry = dockerHubRegistries.find((entry) => image.toLowerCase().startsWith(`${entry}/`));
|
|
766
|
+
return (registry === void 0 ? image : image.slice(registry.length + 1)).replace(/^library\//i, "");
|
|
767
|
+
};
|
|
768
|
+
//#endregion
|
|
769
|
+
//#region src/toolchain-inputs.ts
|
|
770
|
+
const excludedInputPath = (file) => file === "" || file.split("/").some((part) => part === "node_modules" || part === "vendor");
|
|
771
|
+
const javascriptDependencyLockfiles = [
|
|
772
|
+
"bun.lock",
|
|
773
|
+
"package-lock.json",
|
|
774
|
+
"yarn.lock",
|
|
775
|
+
"pnpm-lock.yaml"
|
|
776
|
+
];
|
|
777
|
+
/** Match project, environment, local, and fragment filenames recognized by mise. */
|
|
778
|
+
const isMiseConfigPath = (file) => !excludedInputPath(file) && (/(?:^|\/)\.?mise(?:\.[^./][^/]*)?\.toml$/.test(file) || /(?:^|\/)(?:\.?mise|\.config\/mise)\/config(?:\.[^./][^/]*)?\.toml$/.test(file) || /(?:^|\/)(?:\.?mise|\.config\/mise)\/conf\.d\/[^./][^/]*\.toml$/.test(file));
|
|
779
|
+
/** GitHub action metadata may live at the repository root or in any directory. */
|
|
780
|
+
const githubAutomationFileKind = (file) => {
|
|
781
|
+
if (file === "") return void 0;
|
|
782
|
+
if (/^\.github\/workflows\/[^/]+\.ya?ml$/.test(file)) return "workflow";
|
|
783
|
+
if (/(?:^|\/)action\.ya?ml$/.test(file)) return "action";
|
|
784
|
+
};
|
|
785
|
+
/** Dependabot updates workflows and repository-root action metadata. */
|
|
786
|
+
const isDependabotGithubActionsPath = (file) => {
|
|
787
|
+
const kind = githubAutomationFileKind(file);
|
|
788
|
+
return kind === "workflow" || kind === "action" && !file.includes("/");
|
|
789
|
+
};
|
|
790
|
+
/** Use one filename discriminator for reader selection and Python ecosystem decisions. */
|
|
791
|
+
const pythonDependencyManifestKind = (file) => {
|
|
792
|
+
if (excludedInputPath(file)) return void 0;
|
|
793
|
+
const name = file.split("/").at(-1);
|
|
794
|
+
if (name === "pyproject.toml") return "project";
|
|
795
|
+
if (name === "Pipfile") return "pipfile";
|
|
796
|
+
if (name === "Pipfile.lock") return "pipfile-lock";
|
|
797
|
+
if (name === "setup.py" || name === "setup.cfg") return "setup";
|
|
798
|
+
if (name !== void 0 && /^requirements[^/]*\.(?:txt|in)$/.test(name)) return "requirements";
|
|
799
|
+
};
|
|
800
|
+
const isPythonDependencyManifest = (file) => pythonDependencyManifestKind(file) !== void 0;
|
|
801
|
+
/** Docker definition names use dot-delimited variants, excluding source and documentation. */
|
|
802
|
+
const isDockerDefinitionPath = (file) => {
|
|
803
|
+
if (excludedInputPath(file)) return false;
|
|
804
|
+
const name = file.split("/").at(-1) ?? "";
|
|
805
|
+
if (/\.(?:[cm]?[jt]sx?|mdx?|rst|txt|html?|py|rs|go|java|sh|c|cc|cpp|cxx|h|hpp|cs|rb|php|swift|kt|css|scss)$/i.test(name)) return false;
|
|
806
|
+
return /^(?:[^./]+\.)*(?:dockerfile|containerfile)(?:\.[^./]+)*$/i.test(name);
|
|
807
|
+
};
|
|
808
|
+
/** Lockfiles establish ecosystem presence without reading their dependency graphs. */
|
|
809
|
+
const toolchainInputKind = (file) => {
|
|
810
|
+
if (file === ".agents/cloud-setup.sh") return "config";
|
|
811
|
+
if (githubAutomationFileKind(file) !== void 0) return "config";
|
|
812
|
+
if (excludedInputPath(file)) return void 0;
|
|
813
|
+
if (pythonDependencyManifestKind(file) === "pipfile-lock" || javascriptDependencyLockfiles.some((name) => file.split("/").at(-1) === name) || /(?:^|\/)uv\.lock$/.test(file)) return "presence";
|
|
814
|
+
if (githubAutomationFileKind(file) !== void 0 || isMiseConfigPath(file) || isPythonDependencyManifest(file) || isDockerDefinitionPath(file) || isComposeDefinitionPath(file) || isKubernetesDefinitionPath(file) || /(?:^|\/)(?:package\.json|pnpm-workspace\.yaml|stll-toolchain\.json|\.bun-version|\.node-version|\.nvmrc|\.python-version|rust-toolchain(?:\.toml)?|\.tool-versions|\.?mise\.toml|uv\.toml|\.uv\.toml|\.github\/dependabot\.ya?ml|Cargo\.toml)$/.test(file)) return "config";
|
|
815
|
+
};
|
|
816
|
+
//#endregion
|
|
817
|
+
//#region src/toolchain-workspaces.ts
|
|
818
|
+
/** Match manifest directories with the same positive and negative workspace patterns. */
|
|
819
|
+
const workspaceContains = ({ directory, file, patterns, rootMembership }) => {
|
|
820
|
+
const relative = path.posix.relative(directory, path.posix.dirname(file));
|
|
821
|
+
if (relative === "" && rootMembership === "implicit") return true;
|
|
822
|
+
if (relative === ".." || relative.startsWith("../")) return false;
|
|
823
|
+
if (!Array.isArray(patterns)) return false;
|
|
824
|
+
const normalize = (pattern) => path.posix.normalize(pattern);
|
|
825
|
+
const selected = patterns.filter((value) => typeof value === "string");
|
|
826
|
+
return picomatch(selected.filter((pattern) => !pattern.startsWith("!")).map(normalize))(relative) && !picomatch(selected.filter((pattern) => pattern.startsWith("!")).map((pattern) => normalize(pattern.slice(1))))(relative);
|
|
827
|
+
};
|
|
828
|
+
//#endregion
|
|
829
|
+
//#region src/toolchain-dependabot.ts
|
|
830
|
+
const dependabotRules = ["dependabot-policy"];
|
|
831
|
+
const record$5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
832
|
+
const strings = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
833
|
+
const sameStrings = (value, expected) => {
|
|
834
|
+
if (!strings(value) || value.length !== expected.length) return false;
|
|
835
|
+
const sortedExpected = [...expected].sort();
|
|
836
|
+
return [...value].sort().every((entry, index) => entry === sortedExpected[index]);
|
|
837
|
+
};
|
|
838
|
+
const directoryOf = (file) => {
|
|
839
|
+
const directory = path.posix.dirname(file);
|
|
840
|
+
return directory === "." ? "/" : `/${directory}`;
|
|
841
|
+
};
|
|
842
|
+
const workspaceManifests = {
|
|
843
|
+
npm: "package.json",
|
|
844
|
+
cargo: "Cargo.toml",
|
|
845
|
+
uv: "pyproject.toml"
|
|
846
|
+
};
|
|
847
|
+
const workspaceTable = (parsed, ecosystem) => {
|
|
848
|
+
switch (ecosystem) {
|
|
849
|
+
case "npm": return parsed["workspaces"];
|
|
850
|
+
case "cargo": return parsed["workspace"];
|
|
851
|
+
case "uv": {
|
|
852
|
+
const tool = parsed["tool"];
|
|
853
|
+
const uv = record$5(tool) ? tool["uv"] : void 0;
|
|
854
|
+
return record$5(uv) ? uv["workspace"] : void 0;
|
|
855
|
+
}
|
|
856
|
+
default: throw new Error("unknown workspace ecosystem", { cause: ecosystem });
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
/** Installable workspace members share their update root; own-lock projects stay discoverable. */
|
|
860
|
+
const workspaceRoots = (files, ecosystem) => {
|
|
861
|
+
const manifests = Object.keys(files).filter((file) => path.posix.basename(file) === workspaceManifests[ecosystem] || ecosystem === "npm" && path.posix.basename(file) === "pnpm-workspace.yaml");
|
|
862
|
+
const workspaces = /* @__PURE__ */ new Map();
|
|
863
|
+
const npmWorkspaceErrors = /* @__PURE__ */ new Map();
|
|
864
|
+
for (const file of manifests) {
|
|
865
|
+
if (ecosystem === "npm") {
|
|
866
|
+
const directory = path.posix.dirname(file);
|
|
867
|
+
const workspaceFile = path.posix.join(directory, "pnpm-workspace.yaml");
|
|
868
|
+
const text = files[workspaceFile];
|
|
869
|
+
if (text !== void 0) {
|
|
870
|
+
try {
|
|
871
|
+
const document = parseDocument(text);
|
|
872
|
+
if (document.errors.length > 0) throw new Error(`${workspaceFile}:1: invalid pnpm workspace YAML`);
|
|
873
|
+
const parsed = document.toJS({ maxAliasCount: 100 });
|
|
874
|
+
if (!record$5(parsed)) throw new Error(`${workspaceFile}:1: pnpm workspace must contain an object`);
|
|
875
|
+
const patterns = parsed["packages"] ?? [];
|
|
876
|
+
if (!strings(patterns)) throw new Error(`${workspaceFile}:1: pnpm packages must be a string array`);
|
|
877
|
+
workspaces.set(directory, patterns.map((pattern) => pattern.startsWith("!") ? `!${path.posix.normalize(pattern.slice(1))}` : path.posix.normalize(pattern)));
|
|
878
|
+
} catch (error) {
|
|
879
|
+
npmWorkspaceErrors.set(directory, error instanceof Error ? error : new Error(String(error)));
|
|
880
|
+
}
|
|
881
|
+
continue;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
try {
|
|
885
|
+
const parsed = ecosystem === "npm" ? JSON.parse(files[file] ?? "") : parse(files[file] ?? "");
|
|
886
|
+
if (!record$5(parsed)) continue;
|
|
887
|
+
if (ecosystem === "npm" && typeof parsed["packageManager"] === "string" && parsed["packageManager"].startsWith("pnpm@")) continue;
|
|
888
|
+
const value = workspaceTable(parsed, ecosystem);
|
|
889
|
+
const patterns = record$5(value) ? value[ecosystem === "npm" ? "packages" : "members"] : value;
|
|
890
|
+
const members = ecosystem === "cargo" && record$5(value) && patterns === void 0 ? [] : patterns;
|
|
891
|
+
if (strings(members)) {
|
|
892
|
+
const excluded = ecosystem !== "npm" && record$5(value) && strings(value["exclude"]) ? value["exclude"].map((pattern) => `!${pattern}`) : [];
|
|
893
|
+
workspaces.set(path.posix.dirname(file), [...members, ...excluded]);
|
|
894
|
+
}
|
|
895
|
+
} catch {}
|
|
896
|
+
}
|
|
897
|
+
const implicitCargoMembers = /* @__PURE__ */ new Map();
|
|
898
|
+
const declaredMember = (root, patterns, directory) => {
|
|
899
|
+
const relative = path.posix.relative(root, directory);
|
|
900
|
+
if (relative === "" || relative === ".." || relative.startsWith("../")) return false;
|
|
901
|
+
return workspaceContains({
|
|
902
|
+
directory: root,
|
|
903
|
+
file: path.posix.join(directory, "package.json"),
|
|
904
|
+
patterns,
|
|
905
|
+
rootMembership: "patterns"
|
|
906
|
+
});
|
|
907
|
+
};
|
|
908
|
+
const installable = /* @__PURE__ */ new Set(["."]);
|
|
909
|
+
if (ecosystem === "npm") {
|
|
910
|
+
for (const file of manifests) {
|
|
911
|
+
const directory = path.posix.dirname(file);
|
|
912
|
+
if (javascriptDependencyLockfiles.some((name) => files[path.posix.join(directory, name)] !== void 0)) installable.add(directory);
|
|
913
|
+
}
|
|
914
|
+
let changed = true;
|
|
915
|
+
while (changed) {
|
|
916
|
+
changed = false;
|
|
917
|
+
for (const [root, patterns] of workspaces) {
|
|
918
|
+
if (!installable.has(root)) continue;
|
|
919
|
+
for (const file of manifests) {
|
|
920
|
+
const directory = path.posix.dirname(file);
|
|
921
|
+
if (installable.has(directory) || !declaredMember(root, patterns, directory)) continue;
|
|
922
|
+
installable.add(directory);
|
|
923
|
+
changed = true;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
if (ecosystem === "npm") {
|
|
929
|
+
for (const [directory, error] of npmWorkspaceErrors) if (installable.has(directory)) throw error;
|
|
930
|
+
}
|
|
931
|
+
if (ecosystem === "cargo") for (const [root, patterns] of workspaces) {
|
|
932
|
+
const includes = patterns.filter((pattern) => !pattern.startsWith("!"));
|
|
933
|
+
const excludes = patterns.filter((pattern) => pattern.startsWith("!"));
|
|
934
|
+
const memberDirectories = /* @__PURE__ */ new Set([root]);
|
|
935
|
+
for (const file of manifests) {
|
|
936
|
+
const directory = path.posix.dirname(file);
|
|
937
|
+
const relative = path.posix.relative(root, directory);
|
|
938
|
+
if (includes.some((pattern) => picomatch.isMatch(relative, pattern)) && !excludes.some((pattern) => picomatch.isMatch(relative, pattern.slice(1)))) memberDirectories.add(directory);
|
|
939
|
+
}
|
|
940
|
+
for (const directory of memberDirectories) try {
|
|
941
|
+
const parsed = parse(files[path.posix.join(directory, "Cargo.toml")] ?? "");
|
|
942
|
+
const workspace = parse(files[path.posix.join(root, "Cargo.toml")] ?? "")["workspace"];
|
|
943
|
+
const inherited = record$5(workspace) ? workspace["dependencies"] : void 0;
|
|
944
|
+
const dependencyOwners = [parsed];
|
|
945
|
+
const targets = parsed["target"];
|
|
946
|
+
if (record$5(targets)) {
|
|
947
|
+
for (const target of Object.values(targets)) if (record$5(target)) dependencyOwners.push(target);
|
|
948
|
+
}
|
|
949
|
+
for (const owner of dependencyOwners) for (const key of [
|
|
950
|
+
"dependencies",
|
|
951
|
+
"dev-dependencies",
|
|
952
|
+
"build-dependencies"
|
|
953
|
+
]) {
|
|
954
|
+
const dependencies = owner[key];
|
|
955
|
+
if (!record$5(dependencies)) continue;
|
|
956
|
+
for (const [name, dependency] of Object.entries(dependencies)) {
|
|
957
|
+
if (!record$5(dependency)) continue;
|
|
958
|
+
const isInherited = dependency["workspace"] === true;
|
|
959
|
+
const resolved = isInherited && record$5(inherited) ? inherited[name] : dependency;
|
|
960
|
+
if (!record$5(resolved) || typeof resolved["path"] !== "string") continue;
|
|
961
|
+
if (path.posix.isAbsolute(resolved["path"]) || /\\|\$|^[A-Za-z]:/.test(resolved["path"])) continue;
|
|
962
|
+
const target = path.posix.normalize(path.posix.join(isInherited ? root : directory, resolved["path"]));
|
|
963
|
+
const relative = path.posix.relative(root, target);
|
|
964
|
+
if (relative.startsWith("../") || relative === ".." || files[path.posix.join(target, "Cargo.toml")] === void 0 || excludes.some((pattern) => picomatch.isMatch(relative, pattern.slice(1)))) continue;
|
|
965
|
+
memberDirectories.add(target);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
} catch {}
|
|
969
|
+
implicitCargoMembers.set(root, memberDirectories);
|
|
970
|
+
}
|
|
971
|
+
return manifests.filter((file) => ecosystem !== "npm" || installable.has(path.posix.dirname(file))).filter((file) => {
|
|
972
|
+
const directory = path.posix.dirname(file);
|
|
973
|
+
return ![...workspaces].some(([root, patterns]) => {
|
|
974
|
+
if (ecosystem === "npm" && !installable.has(root)) return false;
|
|
975
|
+
const relative = path.posix.relative(root, directory);
|
|
976
|
+
if (relative === "" || relative.startsWith("../")) return false;
|
|
977
|
+
const includes = patterns.filter((pattern) => !pattern.startsWith("!"));
|
|
978
|
+
const excludes = patterns.filter((pattern) => pattern.startsWith("!"));
|
|
979
|
+
return (implicitCargoMembers.get(root)?.has(directory) === true || (ecosystem === "npm" ? declaredMember(root, patterns, directory) : includes.some((pattern) => picomatch.isMatch(relative, pattern)))) && !excludes.some((pattern) => picomatch.isMatch(relative, pattern.slice(1)));
|
|
980
|
+
});
|
|
981
|
+
}).map(directoryOf).filter((directory, index, values) => values.indexOf(directory) === index);
|
|
982
|
+
};
|
|
983
|
+
const javascriptEcosystem = (directory, files) => {
|
|
984
|
+
const root = directory === "/" ? "." : directory.slice(1);
|
|
985
|
+
if (files[path.posix.join(root, "bun.lock")] !== void 0) return "bun";
|
|
986
|
+
try {
|
|
987
|
+
const manifest = JSON.parse(files[path.posix.join(root, "package.json")] ?? "{}");
|
|
988
|
+
if (record$5(manifest) && typeof manifest["packageManager"] === "string" && manifest["packageManager"].startsWith("bun@")) return "bun";
|
|
989
|
+
} catch {}
|
|
990
|
+
return "npm";
|
|
991
|
+
};
|
|
992
|
+
const pythonEcosystem = (file, files) => {
|
|
993
|
+
const manifestKind = pythonDependencyManifestKind(file);
|
|
994
|
+
if (manifestKind === "pipfile" || manifestKind === "pipfile-lock" || manifestKind === "setup") return "pip";
|
|
995
|
+
const root = path.posix.dirname(file);
|
|
996
|
+
if (files[path.posix.join(root, "uv.lock")] !== void 0 || files[path.posix.join(root, "uv.toml")] !== void 0) return "uv";
|
|
997
|
+
const pyproject = files[path.posix.join(root, "pyproject.toml")];
|
|
998
|
+
if (pyproject !== void 0) try {
|
|
999
|
+
const tool = parse(pyproject)["tool"];
|
|
1000
|
+
if (record$5(tool) && record$5(tool["uv"])) return "uv";
|
|
1001
|
+
} catch {}
|
|
1002
|
+
return "pip";
|
|
1003
|
+
};
|
|
1004
|
+
const ecosystemRoots = (files) => {
|
|
1005
|
+
const roots = /* @__PURE__ */ new Map();
|
|
1006
|
+
const requireRoot = (ecosystem, directory) => {
|
|
1007
|
+
const directories = roots.get(ecosystem) ?? /* @__PURE__ */ new Set();
|
|
1008
|
+
directories.add(directory);
|
|
1009
|
+
roots.set(ecosystem, directories);
|
|
1010
|
+
};
|
|
1011
|
+
for (const directory of workspaceRoots(files, "npm")) requireRoot(javascriptEcosystem(directory, files), directory);
|
|
1012
|
+
for (const directory of workspaceRoots(files, "cargo")) requireRoot("cargo", directory);
|
|
1013
|
+
for (const directory of workspaceRoots(files, "uv")) {
|
|
1014
|
+
const root = directory === "/" ? "." : directory.slice(1);
|
|
1015
|
+
requireRoot(pythonEcosystem(path.posix.join(root, "pyproject.toml"), files), directory);
|
|
1016
|
+
}
|
|
1017
|
+
for (const file of Object.keys(files)) {
|
|
1018
|
+
if (isDependabotGithubActionsPath(file)) requireRoot("github-actions", "/");
|
|
1019
|
+
const name = path.posix.basename(file);
|
|
1020
|
+
if (isDockerDefinitionPath(file)) requireRoot("docker", directoryOf(file));
|
|
1021
|
+
if (isComposeDefinitionPath(file) || isKubernetesDefinitionPath(file)) for (const document of parseAllDocuments(files[file] ?? "", { merge: true })) {
|
|
1022
|
+
if (document.errors.length > 0) continue;
|
|
1023
|
+
try {
|
|
1024
|
+
const classified = containerDocumentImages(document.toJS({ maxAliasCount: 100 }), file);
|
|
1025
|
+
if (classified !== void 0) requireRoot(classified.ecosystem, directoryOf(file));
|
|
1026
|
+
} catch {}
|
|
1027
|
+
}
|
|
1028
|
+
if (name === "uv.lock" || name === "uv.toml" || name !== "pyproject.toml" && isPythonDependencyManifest(file)) requireRoot(pythonEcosystem(file, files), directoryOf(file));
|
|
1029
|
+
}
|
|
1030
|
+
return roots;
|
|
1031
|
+
};
|
|
1032
|
+
const ignoredFor = (ecosystem, policy) => {
|
|
1033
|
+
if (ecosystem === "npm" || ecosystem === "bun") return policy.ignoredPackages;
|
|
1034
|
+
if (ecosystem === "github-actions") return policy.ignoredActions;
|
|
1035
|
+
if (ecosystem === "docker" || ecosystem === "docker-compose") return ownedDockerImageAliases(policy.ignoredImages);
|
|
1036
|
+
return [];
|
|
1037
|
+
};
|
|
1038
|
+
/** Validate the shared update policy against a hermetic tracked-file snapshot. */
|
|
1039
|
+
const checkDependabot = ({ files, policy }) => {
|
|
1040
|
+
const roots = ecosystemRoots(files);
|
|
1041
|
+
const paths = [".github/dependabot.yml", ".github/dependabot.yaml"].filter((file) => files[file] !== void 0);
|
|
1042
|
+
if (roots.size === 0 && paths.length === 0) return [];
|
|
1043
|
+
const file = paths.at(0) ?? ".github/dependabot.yml";
|
|
1044
|
+
const diagnostics = [];
|
|
1045
|
+
const add = (message, line = 1) => {
|
|
1046
|
+
diagnostics.push({
|
|
1047
|
+
rule: "dependabot-policy",
|
|
1048
|
+
path: file,
|
|
1049
|
+
line,
|
|
1050
|
+
message
|
|
1051
|
+
});
|
|
1052
|
+
};
|
|
1053
|
+
if (paths.length === 0) {
|
|
1054
|
+
add("add a Dependabot configuration for the repository's package ecosystems");
|
|
1055
|
+
return diagnostics;
|
|
1056
|
+
}
|
|
1057
|
+
if (paths.length > 1) add("keep one Dependabot configuration file");
|
|
1058
|
+
const lineCounter = new LineCounter();
|
|
1059
|
+
const document = parseDocument(files[file] ?? "", { lineCounter });
|
|
1060
|
+
if (document.errors.length > 0) {
|
|
1061
|
+
for (const error of document.errors) add(`invalid Dependabot YAML: ${error.message}`, lineCounter.linePos(error.pos[0]).line);
|
|
1062
|
+
return diagnostics;
|
|
1063
|
+
}
|
|
1064
|
+
let parsed;
|
|
1065
|
+
try {
|
|
1066
|
+
parsed = document.toJS({ maxAliasCount: 100 });
|
|
1067
|
+
} catch {
|
|
1068
|
+
add("cannot resolve Dependabot YAML aliases");
|
|
1069
|
+
return diagnostics;
|
|
1070
|
+
}
|
|
1071
|
+
if (!record$5(parsed) || parsed["version"] !== 2 || !Array.isArray(parsed["updates"])) {
|
|
1072
|
+
add("Dependabot must declare version: 2 and an updates array");
|
|
1073
|
+
return diagnostics;
|
|
1074
|
+
}
|
|
1075
|
+
const covered = /* @__PURE__ */ new Map();
|
|
1076
|
+
let legacy;
|
|
1077
|
+
try {
|
|
1078
|
+
const legacyDocument = parseDocument(files[file] ?? "", {
|
|
1079
|
+
version: "1.1",
|
|
1080
|
+
schema: "yaml-1.1"
|
|
1081
|
+
});
|
|
1082
|
+
if (legacyDocument.errors.length === 0) legacy = legacyDocument.toJS({ maxAliasCount: 100 });
|
|
1083
|
+
} catch {}
|
|
1084
|
+
const legacyUpdates = record$5(legacy) && Array.isArray(legacy["updates"]) ? legacy["updates"] : [];
|
|
1085
|
+
const rootClaims = /* @__PURE__ */ new Map();
|
|
1086
|
+
const directoryClaims = /* @__PURE__ */ new Map();
|
|
1087
|
+
for (const [index, update] of parsed["updates"].entries()) {
|
|
1088
|
+
const lineOf = (key) => {
|
|
1089
|
+
const node = document.getIn([
|
|
1090
|
+
"updates",
|
|
1091
|
+
index,
|
|
1092
|
+
key
|
|
1093
|
+
], true);
|
|
1094
|
+
const offset = isNode(node) ? node.range?.[0] : void 0;
|
|
1095
|
+
return offset === void 0 ? 1 : lineCounter.linePos(offset).line;
|
|
1096
|
+
};
|
|
1097
|
+
const report = (key, message) => add(message, lineOf(key));
|
|
1098
|
+
if (!record$5(update) || typeof update["package-ecosystem"] !== "string") {
|
|
1099
|
+
report("package-ecosystem", "each Dependabot update must declare a package ecosystem");
|
|
1100
|
+
continue;
|
|
1101
|
+
}
|
|
1102
|
+
const ecosystem = update["package-ecosystem"];
|
|
1103
|
+
if (update["target-branch"] !== void 0) report("target-branch", `${ecosystem}: shared updates must target the default branch`);
|
|
1104
|
+
if (update["open-pull-requests-limit"] === 0) report("open-pull-requests-limit", `${ecosystem}: version updates must remain enabled`);
|
|
1105
|
+
const single = update["directory"];
|
|
1106
|
+
const multiple = update["directories"];
|
|
1107
|
+
let directories = [];
|
|
1108
|
+
if (typeof single === "string" && multiple === void 0) directories = [single];
|
|
1109
|
+
else if (single === void 0 && strings(multiple)) directories = multiple;
|
|
1110
|
+
const validDirectories = directories.filter((directory) => directory.startsWith("/") && !directory.split("/").includes(".."));
|
|
1111
|
+
if (directories.length === 0 || validDirectories.length !== directories.length) report("directory", `${ecosystem}: declare directory or nonempty directories with absolute repository paths`);
|
|
1112
|
+
const normalizedDirectories = Array.from(new Set(validDirectories.map((value) => path.posix.normalize(value).replace(/\/+$/, "") || "/")));
|
|
1113
|
+
const matches = covered.get(ecosystem) ?? /* @__PURE__ */ new Set();
|
|
1114
|
+
const claimedDirectories = directoryClaims.get(ecosystem) ?? /* @__PURE__ */ new Map();
|
|
1115
|
+
for (const directory of normalizedDirectories) {
|
|
1116
|
+
const previous = claimedDirectories.get(directory);
|
|
1117
|
+
if (previous !== void 0) report(multiple === void 0 ? "directory" : "directories", `${ecosystem}: directory ${directory} overlaps update entry ${previous + 1}`);
|
|
1118
|
+
else claimedDirectories.set(directory, index);
|
|
1119
|
+
}
|
|
1120
|
+
directoryClaims.set(ecosystem, claimedDirectories);
|
|
1121
|
+
const claimedRoots = rootClaims.get(ecosystem) ?? /* @__PURE__ */ new Map();
|
|
1122
|
+
for (const root of roots.get(ecosystem) ?? []) if (normalizedDirectories.some((directory) => directory === root || multiple !== void 0 && picomatch.isMatch(root, directory))) {
|
|
1123
|
+
const previous = claimedRoots.get(root);
|
|
1124
|
+
if (previous !== void 0) report(multiple === void 0 ? "directory" : "directories", `${ecosystem}: update root ${root} overlaps update entry ${previous + 1}`);
|
|
1125
|
+
else claimedRoots.set(root, index);
|
|
1126
|
+
matches.add(root);
|
|
1127
|
+
}
|
|
1128
|
+
rootClaims.set(ecosystem, claimedRoots);
|
|
1129
|
+
covered.set(ecosystem, matches);
|
|
1130
|
+
const schedule = update["schedule"];
|
|
1131
|
+
const legacyUpdate = legacyUpdates.at(index);
|
|
1132
|
+
const legacySchedule = record$5(legacyUpdate) ? legacyUpdate["schedule"] : void 0;
|
|
1133
|
+
if (record$5(schedule) && schedule["time"] === policy.schedule.time && (!record$5(legacySchedule) || legacySchedule["time"] !== policy.schedule.time)) report("schedule", `${ecosystem}: quote schedule time to preserve its string value in YAML 1.1`);
|
|
1134
|
+
if (!record$5(schedule) || Object.keys(schedule).length !== Object.keys(policy.schedule).length || Object.entries(policy.schedule).some(([key, value]) => schedule[key] !== value)) report("schedule", `${ecosystem}: schedule must match the shared policy`);
|
|
1135
|
+
const cooldown = update["cooldown"];
|
|
1136
|
+
if (!record$5(cooldown) || Object.keys(cooldown).length !== 1 || cooldown["default-days"] !== policy.cooldown.defaultDays) report("cooldown", `${ecosystem}: cooldown must contain only default-days: ${policy.cooldown.defaultDays}`);
|
|
1137
|
+
const groups = update["groups"];
|
|
1138
|
+
if (!record$5(groups) || Object.keys(groups).length !== Object.keys(policy.groups).length || Object.entries(policy.groups).some(([name, expected]) => {
|
|
1139
|
+
const group = groups[name];
|
|
1140
|
+
return !record$5(group) || Object.keys(group).length !== 2 || !sameStrings(group["patterns"], expected.patterns) || !sameStrings(group["update-types"], expected.updateTypes);
|
|
1141
|
+
})) report("groups", `${ecosystem}: groups must match the shared policy`);
|
|
1142
|
+
const ignored = ignoredFor(ecosystem, policy);
|
|
1143
|
+
const ignore = update["ignore"];
|
|
1144
|
+
if (ignore !== void 0 && (!Array.isArray(ignore) || ignore.length === 0)) report("ignore", `${ecosystem}: omit ignore or provide a nonempty array`);
|
|
1145
|
+
if (Array.isArray(ignore) && ignore.some((entry) => !record$5(entry) || typeof entry["dependency-name"] !== "string" || !ignored.includes(entry["dependency-name"]))) report("ignore", `${ecosystem}: ignore only packages owned by the shared policy`);
|
|
1146
|
+
for (const name of ignored) if (!Array.isArray(ignore) || !ignore.some((entry) => record$5(entry) && entry["dependency-name"] === name && Object.keys(entry).length === 1)) report("ignore", `${ecosystem}: ignore all updates for shared pin ${name}`);
|
|
1147
|
+
}
|
|
1148
|
+
for (const [ecosystem, directories] of roots) for (const directory of directories) if (!covered.get(ecosystem)?.has(directory)) add(`add a ${ecosystem} update entry covering ${directory}`);
|
|
1149
|
+
return diagnostics;
|
|
1150
|
+
};
|
|
1151
|
+
//#endregion
|
|
1152
|
+
//#region src/toolchain-engine-floors.ts
|
|
1153
|
+
const record$4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1154
|
+
const repositoryPath = (value) => typeof value === "string" && value !== "" && !/^[A-Za-z]:/.test(value) && !/[\\\s]/.test(value) && !Array.from(value).some((character) => character.charCodeAt(0) < 32) && value.split("/").every((part) => part !== "" && part !== "." && part !== "..");
|
|
1155
|
+
const parseEngineFloors = (input) => {
|
|
1156
|
+
if (input === void 0) return [];
|
|
1157
|
+
if (!Array.isArray(input)) throw new Error("engineFloors must be an array");
|
|
1158
|
+
const result = [];
|
|
1159
|
+
const jobs = /* @__PURE__ */ new Set();
|
|
1160
|
+
for (const entry of input) {
|
|
1161
|
+
if (!record$4(entry) || Object.keys(entry).some((key) => ![
|
|
1162
|
+
"package",
|
|
1163
|
+
"workflow",
|
|
1164
|
+
"job"
|
|
1165
|
+
].includes(key)) || entry["package"] !== "." && !repositoryPath(entry["package"]) || !repositoryPath(entry["workflow"]) || !/^\.github\/workflows\/[^/]+\.ya?ml$/.test(entry["workflow"]) || typeof entry["job"] !== "string" || entry["job"].trim() === "") throw new Error("each engine floor requires a repository package directory, workflow path and job");
|
|
1166
|
+
const key = `${entry["workflow"]}:${entry["job"]}`;
|
|
1167
|
+
if (jobs.has(key)) throw new Error("engine floor workflow jobs must be unique");
|
|
1168
|
+
jobs.add(key);
|
|
1169
|
+
result.push({
|
|
1170
|
+
package: entry["package"],
|
|
1171
|
+
workflow: entry["workflow"],
|
|
1172
|
+
job: entry["job"]
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
return result;
|
|
1176
|
+
};
|
|
1177
|
+
const resolveEngineFloor = (entry, files) => {
|
|
1178
|
+
const manifestText = files[path.posix.join(entry.package, "package.json")];
|
|
1179
|
+
const workflowText = files[entry.workflow];
|
|
1180
|
+
if (manifestText === void 0 || workflowText === void 0) throw new Error("engine floor package and workflow must be tracked");
|
|
1181
|
+
const manifest = JSON.parse(manifestText);
|
|
1182
|
+
if (!record$4(manifest) || manifest["private"] === true || typeof manifest["name"] !== "string" || manifest["name"].trim() === "" || !record$4(manifest["engines"]) || typeof manifest["engines"]["node"] !== "string") throw new Error("engine floor package must be published and declare engines.node");
|
|
1183
|
+
const range = manifest["engines"]["node"];
|
|
1184
|
+
const minimum = validRange(range) === null ? null : minVersion(range);
|
|
1185
|
+
if (minimum === null || minimum.prerelease.length !== 0) throw new Error("engine floor engines.node must declare a stable minimum");
|
|
1186
|
+
const document = parseDocument(workflowText, { merge: true });
|
|
1187
|
+
if (document.errors.length !== 0) throw new Error("engine floor workflow must be valid YAML");
|
|
1188
|
+
const workflow = document.toJS({ maxAliasCount: 100 });
|
|
1189
|
+
if (!record$4(workflow) || !record$4(workflow["jobs"])) throw new Error("engine floor job must exist in its tracked workflow");
|
|
1190
|
+
const job = workflow["jobs"][entry.job];
|
|
1191
|
+
if (!record$4(job)) throw new Error("engine floor job must exist in its tracked workflow");
|
|
1192
|
+
if (!Array.isArray(job["steps"]) || Object.hasOwn(job, "uses")) throw new Error("engine floor job must declare steps and cannot reuse a workflow");
|
|
1193
|
+
return {
|
|
1194
|
+
...entry,
|
|
1195
|
+
range,
|
|
1196
|
+
major: minimum.major
|
|
1197
|
+
};
|
|
1198
|
+
};
|
|
1199
|
+
const engineFloorSelectorMatches = (value, floor) => {
|
|
1200
|
+
if (typeof value !== "string" || !/^\d+\.\d+\.\d+$/.test(value) || valid(value) !== value) return false;
|
|
1201
|
+
return Number(value.split(".").at(0)) === floor.major && satisfies(value, floor.range);
|
|
1202
|
+
};
|
|
1203
|
+
//#endregion
|
|
1204
|
+
//#region src/toolchain-packages.ts
|
|
1205
|
+
const packageRules = [
|
|
1206
|
+
"bun-pins",
|
|
1207
|
+
"package-pins",
|
|
1208
|
+
"typescript-layout",
|
|
1209
|
+
"node-engine"
|
|
1210
|
+
];
|
|
1211
|
+
const record$3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1212
|
+
const shellSubstitutions = (command) => {
|
|
1213
|
+
const frames = [{
|
|
1214
|
+
kind: "root",
|
|
1215
|
+
start: 0,
|
|
1216
|
+
depth: 0,
|
|
1217
|
+
quote: void 0
|
|
1218
|
+
}];
|
|
1219
|
+
const bodies = [];
|
|
1220
|
+
for (let index = 0; index < command.length; index += 1) {
|
|
1221
|
+
const frame = frames.at(-1);
|
|
1222
|
+
if (frame === void 0) break;
|
|
1223
|
+
const character = command.at(index);
|
|
1224
|
+
if (character === "\\" && frame.quote !== "'") {
|
|
1225
|
+
index += 1;
|
|
1226
|
+
continue;
|
|
1227
|
+
}
|
|
1228
|
+
if (character === "`" && frame.kind === "backticks") {
|
|
1229
|
+
bodies.push(command.slice(frame.start, index));
|
|
1230
|
+
frames.pop();
|
|
1231
|
+
continue;
|
|
1232
|
+
}
|
|
1233
|
+
if (character === frame.quote) {
|
|
1234
|
+
frame.quote = void 0;
|
|
1235
|
+
continue;
|
|
1236
|
+
}
|
|
1237
|
+
if (frame.quote === "'") continue;
|
|
1238
|
+
if (character === "$" && command.at(index + 1) === "(") {
|
|
1239
|
+
frames.push({
|
|
1240
|
+
kind: "parentheses",
|
|
1241
|
+
start: index + 2,
|
|
1242
|
+
depth: 1,
|
|
1243
|
+
quote: void 0
|
|
1244
|
+
});
|
|
1245
|
+
index += 1;
|
|
1246
|
+
continue;
|
|
1247
|
+
}
|
|
1248
|
+
if (character === "`") {
|
|
1249
|
+
frames.push({
|
|
1250
|
+
kind: "backticks",
|
|
1251
|
+
start: index + 1,
|
|
1252
|
+
depth: 0,
|
|
1253
|
+
quote: void 0
|
|
1254
|
+
});
|
|
1255
|
+
continue;
|
|
1256
|
+
}
|
|
1257
|
+
if (frame.quote !== void 0) continue;
|
|
1258
|
+
if (character === "'" || character === "\"") {
|
|
1259
|
+
frame.quote = character;
|
|
1260
|
+
continue;
|
|
1261
|
+
}
|
|
1262
|
+
if (frame.kind !== "parentheses") continue;
|
|
1263
|
+
if (character === "(") frame.depth += 1;
|
|
1264
|
+
if (character === ")" && --frame.depth === 0) {
|
|
1265
|
+
bodies.push(command.slice(frame.start, index));
|
|
1266
|
+
frames.pop();
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
for (const frame of frames.slice(1)) bodies.push(command.slice(frame.start));
|
|
1270
|
+
return bodies;
|
|
1271
|
+
};
|
|
1272
|
+
const compilerCommandSegments = (command) => {
|
|
1273
|
+
const segments = [[]];
|
|
1274
|
+
for (const source of [command, ...shellSubstitutions(command)]) {
|
|
1275
|
+
segments.push([]);
|
|
1276
|
+
const shellWords = source.match(/(?:[^\s"'\\;&|()]|\\[^\n]|"(?:[^"\\]|\\.)*"|'[^']*')+|&&|\|\||[();&|\n]/g);
|
|
1277
|
+
for (const word of shellWords ?? []) if (/^(?:&&|\|\||[;&|\n])$/.test(word)) segments.push([]);
|
|
1278
|
+
else segments.at(-1)?.push(word);
|
|
1279
|
+
}
|
|
1280
|
+
return segments.map((words) => {
|
|
1281
|
+
let start = 0;
|
|
1282
|
+
const skipAssignments = () => {
|
|
1283
|
+
while (/^[A-Za-z_][A-Za-z\d_]*=/.test(words.at(start) ?? "")) start += 1;
|
|
1284
|
+
};
|
|
1285
|
+
skipAssignments();
|
|
1286
|
+
while (/^(?:\/usr\/bin\/|\/bin\/)?env$/.test(words.at(start) ?? "")) {
|
|
1287
|
+
start += 1;
|
|
1288
|
+
while (start < words.length) {
|
|
1289
|
+
const option = words.at(start);
|
|
1290
|
+
if (option === "--") {
|
|
1291
|
+
start += 1;
|
|
1292
|
+
break;
|
|
1293
|
+
}
|
|
1294
|
+
if (option === "-u" || option === "--unset") {
|
|
1295
|
+
start += 2;
|
|
1296
|
+
continue;
|
|
1297
|
+
}
|
|
1298
|
+
if (option === "-" || option === "-i" || option === "--ignore-environment" || /^--unset=.+|^-u.+/.test(option ?? "")) {
|
|
1299
|
+
start += 1;
|
|
1300
|
+
continue;
|
|
1301
|
+
}
|
|
1302
|
+
break;
|
|
1303
|
+
}
|
|
1304
|
+
skipAssignments();
|
|
1305
|
+
}
|
|
1306
|
+
return words.slice(start);
|
|
1307
|
+
});
|
|
1308
|
+
};
|
|
1309
|
+
const launcherValueOptions = new Map(Object.entries({
|
|
1310
|
+
npx: [
|
|
1311
|
+
"-p",
|
|
1312
|
+
"--package",
|
|
1313
|
+
"-c",
|
|
1314
|
+
"--call",
|
|
1315
|
+
"--cache",
|
|
1316
|
+
"--registry",
|
|
1317
|
+
"--userconfig"
|
|
1318
|
+
],
|
|
1319
|
+
bunx: ["-p", "--package"],
|
|
1320
|
+
pnpm: [
|
|
1321
|
+
"--filter",
|
|
1322
|
+
"-F",
|
|
1323
|
+
"--dir",
|
|
1324
|
+
"-C",
|
|
1325
|
+
"--package"
|
|
1326
|
+
],
|
|
1327
|
+
yarn: [
|
|
1328
|
+
"--cwd",
|
|
1329
|
+
"--cache-folder",
|
|
1330
|
+
"--mutex",
|
|
1331
|
+
"--use-yarnrc",
|
|
1332
|
+
"--modules-folder",
|
|
1333
|
+
"--registry"
|
|
1334
|
+
],
|
|
1335
|
+
bun: [
|
|
1336
|
+
"--cwd",
|
|
1337
|
+
"--filter",
|
|
1338
|
+
"-F",
|
|
1339
|
+
"--config",
|
|
1340
|
+
"-c",
|
|
1341
|
+
"--env-file",
|
|
1342
|
+
"-e",
|
|
1343
|
+
"--eval",
|
|
1344
|
+
"-p",
|
|
1345
|
+
"--print"
|
|
1346
|
+
],
|
|
1347
|
+
node: [
|
|
1348
|
+
"-e",
|
|
1349
|
+
"--eval",
|
|
1350
|
+
"-p",
|
|
1351
|
+
"--print",
|
|
1352
|
+
"--conditions",
|
|
1353
|
+
"-C",
|
|
1354
|
+
"--inspect-port",
|
|
1355
|
+
"--max-old-space-size",
|
|
1356
|
+
"--stack-size",
|
|
1357
|
+
"--title",
|
|
1358
|
+
"--icu-data-dir",
|
|
1359
|
+
"--openssl-config",
|
|
1360
|
+
"--input-type"
|
|
1361
|
+
]
|
|
1362
|
+
}).map(([launcher, options]) => [launcher, new Set(options)]));
|
|
1363
|
+
const invokesCompiler = (words) => {
|
|
1364
|
+
const literal = (word) => {
|
|
1365
|
+
let result = "";
|
|
1366
|
+
let quote;
|
|
1367
|
+
for (let index = 0; index < word.length; index += 1) {
|
|
1368
|
+
const character = word.at(index);
|
|
1369
|
+
if (character === quote) {
|
|
1370
|
+
quote = void 0;
|
|
1371
|
+
continue;
|
|
1372
|
+
}
|
|
1373
|
+
if (quote === void 0 && (character === "'" || character === "\"")) {
|
|
1374
|
+
quote = character;
|
|
1375
|
+
continue;
|
|
1376
|
+
}
|
|
1377
|
+
const next = word.at(index + 1);
|
|
1378
|
+
if (character === "\\" && next !== void 0 && quote !== "'" && (quote === void 0 || /[$`"\\\n]/.test(next))) {
|
|
1379
|
+
result += next;
|
|
1380
|
+
index += 1;
|
|
1381
|
+
} else result += character;
|
|
1382
|
+
}
|
|
1383
|
+
return result;
|
|
1384
|
+
};
|
|
1385
|
+
const tokens = words.map(literal);
|
|
1386
|
+
const compiler = (word) => /(?:^|\/)(?:tsc|tsgo)(?:\.js)?$/.test(word);
|
|
1387
|
+
let start = 0;
|
|
1388
|
+
const skipOptions = (index, launcher) => {
|
|
1389
|
+
while (tokens.at(index)?.startsWith("-")) {
|
|
1390
|
+
const option = tokens.at(index);
|
|
1391
|
+
index += 1;
|
|
1392
|
+
if (option === "--") break;
|
|
1393
|
+
if (option !== void 0 && launcherValueOptions.get(launcher)?.has(option)) index += 1;
|
|
1394
|
+
}
|
|
1395
|
+
return index;
|
|
1396
|
+
};
|
|
1397
|
+
while (start < tokens.length) {
|
|
1398
|
+
const launcher = tokens.at(start);
|
|
1399
|
+
if (launcher === void 0 || !launcherValueOptions.has(launcher)) break;
|
|
1400
|
+
start = skipOptions(start + 1, launcher);
|
|
1401
|
+
if (launcher === "bun" && tokens.at(start) === "check") return true;
|
|
1402
|
+
const subcommand = tokens.at(start);
|
|
1403
|
+
if (launcher === "bun" && (subcommand === "x" || subcommand === "run") || launcher === "pnpm" && (subcommand === "exec" || subcommand === "dlx") || launcher === "yarn" && (subcommand === "exec" || subcommand === "dlx" || subcommand === "run")) start = skipOptions(start + 1, launcher);
|
|
1404
|
+
}
|
|
1405
|
+
return tokens.slice(start).some((word, index) => compiler(word) || word === "bun" && tokens.at(skipOptions(start + index + 1, "bun")) === "check");
|
|
1406
|
+
};
|
|
1407
|
+
/** Validate manifests and catalog resolutions from a tracked-file snapshot. */
|
|
1408
|
+
const checkPackageFiles = ({ files, policy }) => {
|
|
1409
|
+
const sources = new Map(Object.entries(files));
|
|
1410
|
+
const diagnostics = [];
|
|
1411
|
+
const pins = new Map(Object.entries({
|
|
1412
|
+
...policy.packages,
|
|
1413
|
+
"bun-types": policy.bun
|
|
1414
|
+
}));
|
|
1415
|
+
const manifests = /* @__PURE__ */ new Map();
|
|
1416
|
+
const yamlLocations = /* @__PURE__ */ new Map();
|
|
1417
|
+
const reportedLines = /* @__PURE__ */ new Map();
|
|
1418
|
+
const add = ({ file, rule, key, value, message }) => {
|
|
1419
|
+
const source = sources.get(file);
|
|
1420
|
+
if (source === void 0) throw new Error(`Missing package diagnostic source: ${file}`);
|
|
1421
|
+
const serialized = value === void 0 ? void 0 : JSON.stringify(value);
|
|
1422
|
+
const locationKey = `${file}:${key}:${serialized ?? ""}`;
|
|
1423
|
+
const previous = reportedLines.get(locationKey) ?? -1;
|
|
1424
|
+
const yamlLine = yamlLocations.get(locationKey)?.shift();
|
|
1425
|
+
const index = source.split(/\r?\n/).findIndex((line, lineIndex) => lineIndex > previous && line.includes(JSON.stringify(key)) && (serialized === void 0 || line.includes(serialized)));
|
|
1426
|
+
if (index >= 0) reportedLines.set(locationKey, index);
|
|
1427
|
+
diagnostics.push({
|
|
1428
|
+
rule,
|
|
1429
|
+
path: file,
|
|
1430
|
+
line: yamlLine ?? Math.max(1, index + 1),
|
|
1431
|
+
message
|
|
1432
|
+
});
|
|
1433
|
+
};
|
|
1434
|
+
for (const [file, text] of sources) {
|
|
1435
|
+
const pnpm = path.posix.basename(file) === "pnpm-workspace.yaml";
|
|
1436
|
+
if (!pnpm && path.posix.basename(file) !== "package.json") continue;
|
|
1437
|
+
try {
|
|
1438
|
+
const lineCounter = new LineCounter();
|
|
1439
|
+
const document = pnpm ? parseDocument(text, { lineCounter }) : void 0;
|
|
1440
|
+
if (document !== void 0 && document.errors.length > 0) throw new Error("invalid YAML");
|
|
1441
|
+
const json = document === void 0 ? JSON.parse(text) : document.toJS();
|
|
1442
|
+
if (!record$3(json)) throw new Error("manifest must be an object");
|
|
1443
|
+
if (pnpm) {
|
|
1444
|
+
if (json["catalog"] !== void 0 && !record$3(json["catalog"])) throw new Error("catalog must be a mapping");
|
|
1445
|
+
if (json["catalogs"] !== void 0 && (!record$3(json["catalogs"]) || Object.values(json["catalogs"]).some((catalog) => !record$3(catalog)))) throw new Error("named catalogs must be mappings");
|
|
1446
|
+
if (json["packages"] !== void 0 && (!Array.isArray(json["packages"]) || !json["packages"].every((pattern) => typeof pattern === "string"))) throw new Error("workspace packages must be patterns");
|
|
1447
|
+
}
|
|
1448
|
+
manifests.set(file, json);
|
|
1449
|
+
if (document === void 0) continue;
|
|
1450
|
+
const catalogEntries = [
|
|
1451
|
+
{
|
|
1452
|
+
catalog: json["catalog"],
|
|
1453
|
+
prefix: ["catalog"]
|
|
1454
|
+
},
|
|
1455
|
+
{
|
|
1456
|
+
catalog: json["overrides"],
|
|
1457
|
+
prefix: ["overrides"]
|
|
1458
|
+
},
|
|
1459
|
+
...record$3(json["catalogs"]) ? Object.entries(json["catalogs"]).map(([name, catalog]) => ({
|
|
1460
|
+
catalog,
|
|
1461
|
+
prefix: ["catalogs", name]
|
|
1462
|
+
})) : []
|
|
1463
|
+
];
|
|
1464
|
+
for (const { catalog, prefix } of catalogEntries) {
|
|
1465
|
+
if (!record$3(catalog)) continue;
|
|
1466
|
+
for (const [name, value] of Object.entries(catalog)) {
|
|
1467
|
+
const node = document.getIn([...prefix, name], true);
|
|
1468
|
+
if (!isNode(node) || node.range === void 0 || node.range === null) continue;
|
|
1469
|
+
const key = `${file}:${name}:${JSON.stringify(value)}`;
|
|
1470
|
+
const lines = yamlLocations.get(key) ?? [];
|
|
1471
|
+
lines.push(lineCounter.linePos(node.range[0]).line);
|
|
1472
|
+
yamlLocations.set(key, lines);
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
} catch {
|
|
1476
|
+
add({
|
|
1477
|
+
file,
|
|
1478
|
+
rule: "package-pins",
|
|
1479
|
+
key: "",
|
|
1480
|
+
message: pnpm ? "invalid pnpm-workspace.yaml object" : "invalid package.json object"
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
const catalogSources = (json) => [json, ...record$3(json["workspaces"]) ? [json["workspaces"]] : []];
|
|
1485
|
+
const pnpmWorkspaceFor = (file) => {
|
|
1486
|
+
let directory = path.posix.dirname(file);
|
|
1487
|
+
while (true) {
|
|
1488
|
+
const workspace = manifests.get(path.posix.join(directory, "pnpm-workspace.yaml"));
|
|
1489
|
+
if (workspace !== void 0) return {
|
|
1490
|
+
directory,
|
|
1491
|
+
workspace
|
|
1492
|
+
};
|
|
1493
|
+
if (directory === ".") return void 0;
|
|
1494
|
+
directory = path.posix.dirname(directory);
|
|
1495
|
+
}
|
|
1496
|
+
};
|
|
1497
|
+
const catalogFor = (file, name) => {
|
|
1498
|
+
const owner = pnpmWorkspaceFor(file);
|
|
1499
|
+
if (owner !== void 0) {
|
|
1500
|
+
const { directory, workspace } = owner;
|
|
1501
|
+
if (path.posix.basename(file) === "package.json" && !workspaceContains({
|
|
1502
|
+
directory,
|
|
1503
|
+
file,
|
|
1504
|
+
patterns: workspace["packages"],
|
|
1505
|
+
rootMembership: "implicit"
|
|
1506
|
+
})) return void 0;
|
|
1507
|
+
if (name === "" || name === "default") return workspace["catalog"] ?? (record$3(workspace["catalogs"]) ? workspace["catalogs"]["default"] : void 0);
|
|
1508
|
+
return record$3(workspace["catalogs"]) ? workspace["catalogs"][name] : void 0;
|
|
1509
|
+
}
|
|
1510
|
+
let directory = path.posix.dirname(file);
|
|
1511
|
+
while (true) {
|
|
1512
|
+
const manifest = manifests.get(path.posix.join(directory, "package.json"));
|
|
1513
|
+
if (manifest !== void 0) {
|
|
1514
|
+
for (const source of catalogSources(manifest)) {
|
|
1515
|
+
if (name === "" && source["catalog"] !== void 0) return source["catalog"];
|
|
1516
|
+
if (record$3(source["catalogs"]) && source["catalogs"][name] !== void 0) return source["catalogs"][name];
|
|
1517
|
+
}
|
|
1518
|
+
if (manifest["workspaces"] !== void 0) return void 0;
|
|
1519
|
+
}
|
|
1520
|
+
if (directory === ".") return void 0;
|
|
1521
|
+
directory = path.posix.dirname(directory);
|
|
1522
|
+
}
|
|
1523
|
+
};
|
|
1524
|
+
const resolve = (file, name, value) => {
|
|
1525
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1526
|
+
while (typeof value === "string" && value.startsWith("catalog:")) {
|
|
1527
|
+
if (visited.has(value)) return void 0;
|
|
1528
|
+
visited.add(value);
|
|
1529
|
+
const catalog = catalogFor(file, value.slice(8));
|
|
1530
|
+
value = record$3(catalog) ? catalog[name] : void 0;
|
|
1531
|
+
}
|
|
1532
|
+
return value;
|
|
1533
|
+
};
|
|
1534
|
+
const workspaceOwnerFor = (file) => {
|
|
1535
|
+
const pnpm = pnpmWorkspaceFor(file);
|
|
1536
|
+
if (pnpm !== void 0) return {
|
|
1537
|
+
directory: pnpm.directory,
|
|
1538
|
+
patterns: pnpm.workspace["packages"],
|
|
1539
|
+
source: "pnpm"
|
|
1540
|
+
};
|
|
1541
|
+
let directory = path.posix.dirname(file);
|
|
1542
|
+
while (true) {
|
|
1543
|
+
const workspaces = manifests.get(path.posix.join(directory, "package.json"))?.["workspaces"];
|
|
1544
|
+
if (workspaces !== void 0) return {
|
|
1545
|
+
directory,
|
|
1546
|
+
patterns: record$3(workspaces) ? workspaces["packages"] : workspaces,
|
|
1547
|
+
source: "json"
|
|
1548
|
+
};
|
|
1549
|
+
if (directory === ".") return void 0;
|
|
1550
|
+
directory = path.posix.dirname(directory);
|
|
1551
|
+
}
|
|
1552
|
+
};
|
|
1553
|
+
const workspaceResolution = ({ file, name, pin }) => {
|
|
1554
|
+
const owner = workspaceOwnerFor(file);
|
|
1555
|
+
if (owner === void 0) return "nonmember";
|
|
1556
|
+
const { directory, patterns, source } = owner;
|
|
1557
|
+
if (source === "json" && !Array.isArray(patterns)) return "mismatch";
|
|
1558
|
+
if (!workspaceContains({
|
|
1559
|
+
directory,
|
|
1560
|
+
file,
|
|
1561
|
+
patterns,
|
|
1562
|
+
rootMembership: "implicit"
|
|
1563
|
+
})) return "nonmember";
|
|
1564
|
+
const candidates = [...manifests.entries()].filter(([candidate, json]) => path.posix.basename(candidate) === "package.json" && json["name"] === name && workspaceContains({
|
|
1565
|
+
directory,
|
|
1566
|
+
file: candidate,
|
|
1567
|
+
patterns,
|
|
1568
|
+
rootMembership: source === "json" ? "patterns" : "implicit"
|
|
1569
|
+
}));
|
|
1570
|
+
return candidates.length === 1 && candidates.every(([, json]) => json["version"] === pin) ? "matched" : "mismatch";
|
|
1571
|
+
};
|
|
1572
|
+
const tsSpecifiers = /* @__PURE__ */ new Map();
|
|
1573
|
+
for (const layout of policy.typescriptInstallLayouts) {
|
|
1574
|
+
const values = tsSpecifiers.get(layout.compilerPackage) ?? /* @__PURE__ */ new Set();
|
|
1575
|
+
values.add(layout.compilerSpecifier);
|
|
1576
|
+
tsSpecifiers.set(layout.compilerPackage, values);
|
|
1577
|
+
if (layout.type !== "split-compatibility") continue;
|
|
1578
|
+
const compatibility = tsSpecifiers.get(layout.compatibilityPackage) ?? /* @__PURE__ */ new Set();
|
|
1579
|
+
compatibility.add(layout.compatibilitySpecifier);
|
|
1580
|
+
tsSpecifiers.set(layout.compatibilityPackage, compatibility);
|
|
1581
|
+
}
|
|
1582
|
+
tsSpecifiers.set(policy.typescript6Compatibility.packageAlias, /* @__PURE__ */ new Set([`npm:typescript@${policy.typescript6Compatibility.version}`]));
|
|
1583
|
+
const layoutFor = (specifiers) => policy.typescriptInstallLayouts.find((layout) => {
|
|
1584
|
+
const compiler = specifiers.get(layout.compilerPackage);
|
|
1585
|
+
if (compiler?.size !== 1 || !compiler.has(layout.compilerSpecifier)) return false;
|
|
1586
|
+
if (layout.type === "split-compatibility") {
|
|
1587
|
+
const compatibility = specifiers.get(layout.compatibilityPackage);
|
|
1588
|
+
return compatibility?.size === 1 && compatibility.has(layout.compatibilitySpecifier);
|
|
1589
|
+
}
|
|
1590
|
+
return policy.typescriptInstallLayouts.every((other) => other.compilerPackage === layout.compilerPackage || !specifiers.has(other.compilerPackage));
|
|
1591
|
+
});
|
|
1592
|
+
const peerRange = (value) => typeof value === "string" && valid(value) === null && validRange(value) !== null;
|
|
1593
|
+
const toolchainEntries = (file, json) => {
|
|
1594
|
+
const entries = [];
|
|
1595
|
+
for (const section of [
|
|
1596
|
+
"dependencies",
|
|
1597
|
+
"devDependencies",
|
|
1598
|
+
"optionalDependencies",
|
|
1599
|
+
"peerDependencies"
|
|
1600
|
+
]) {
|
|
1601
|
+
const dependencies = json[section];
|
|
1602
|
+
if (!record$3(dependencies)) continue;
|
|
1603
|
+
for (const [name, value] of Object.entries(dependencies)) {
|
|
1604
|
+
if (!tsSpecifiers.has(name)) continue;
|
|
1605
|
+
const resolved = resolve(file, name, value);
|
|
1606
|
+
if (section === "peerDependencies" && peerRange(resolved)) continue;
|
|
1607
|
+
entries.push({
|
|
1608
|
+
section,
|
|
1609
|
+
name,
|
|
1610
|
+
value: resolved
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
return entries;
|
|
1615
|
+
};
|
|
1616
|
+
const specifierMap = (entries) => {
|
|
1617
|
+
const specifiers = /* @__PURE__ */ new Map();
|
|
1618
|
+
for (const { name, value } of entries) {
|
|
1619
|
+
const values = specifiers.get(name) ?? /* @__PURE__ */ new Set();
|
|
1620
|
+
values.add(value);
|
|
1621
|
+
specifiers.set(name, values);
|
|
1622
|
+
}
|
|
1623
|
+
return specifiers;
|
|
1624
|
+
};
|
|
1625
|
+
const workspaceLayouts = /* @__PURE__ */ new Map();
|
|
1626
|
+
const workspaceLayoutFor = (file) => {
|
|
1627
|
+
const owner = workspaceOwnerFor(file);
|
|
1628
|
+
if (owner === void 0 || !workspaceContains({
|
|
1629
|
+
...owner,
|
|
1630
|
+
file,
|
|
1631
|
+
rootMembership: "implicit"
|
|
1632
|
+
})) return void 0;
|
|
1633
|
+
const key = `${owner.source}:${owner.directory}`;
|
|
1634
|
+
const cached = workspaceLayouts.get(key);
|
|
1635
|
+
if (cached !== void 0) return cached;
|
|
1636
|
+
const entries = [];
|
|
1637
|
+
for (const [candidate, member] of manifests) {
|
|
1638
|
+
if (path.posix.basename(candidate) !== "package.json") continue;
|
|
1639
|
+
const memberOwner = workspaceOwnerFor(candidate);
|
|
1640
|
+
if (memberOwner?.directory !== owner.directory || memberOwner.source !== owner.source || !workspaceContains({
|
|
1641
|
+
...owner,
|
|
1642
|
+
file: candidate,
|
|
1643
|
+
rootMembership: "implicit"
|
|
1644
|
+
})) continue;
|
|
1645
|
+
entries.push(...toolchainEntries(candidate, member).filter(({ section }) => section === "devDependencies"));
|
|
1646
|
+
}
|
|
1647
|
+
const result = {
|
|
1648
|
+
layout: layoutFor(specifierMap(entries)),
|
|
1649
|
+
directory: owner.directory
|
|
1650
|
+
};
|
|
1651
|
+
workspaceLayouts.set(key, result);
|
|
1652
|
+
return result;
|
|
1653
|
+
};
|
|
1654
|
+
for (const [file, json] of manifests) {
|
|
1655
|
+
const manager = json["packageManager"];
|
|
1656
|
+
if (manager !== void 0 && manager !== `bun@${policy.bun}`) add({
|
|
1657
|
+
file,
|
|
1658
|
+
rule: "bun-pins",
|
|
1659
|
+
key: "packageManager",
|
|
1660
|
+
value: manager,
|
|
1661
|
+
message: `packageManager Bun version must be ${policy.bun}, found ${JSON.stringify(manager)}`
|
|
1662
|
+
});
|
|
1663
|
+
const checkEntries = (entries, location) => {
|
|
1664
|
+
if (!record$3(entries)) return;
|
|
1665
|
+
for (const [name, raw] of Object.entries(entries)) {
|
|
1666
|
+
const value = resolve(file, name, raw);
|
|
1667
|
+
const tsAllowed = tsSpecifiers.get(name);
|
|
1668
|
+
if (tsAllowed !== void 0) {
|
|
1669
|
+
if (typeof value !== "string" || !tsAllowed.has(value)) add({
|
|
1670
|
+
file,
|
|
1671
|
+
rule: "typescript-layout",
|
|
1672
|
+
key: location?.key ?? name,
|
|
1673
|
+
value: location === void 0 ? raw : location.value,
|
|
1674
|
+
message: `${name} must use a declared TypeScript specifier, found ${String(value)}`
|
|
1675
|
+
});
|
|
1676
|
+
continue;
|
|
1677
|
+
}
|
|
1678
|
+
const pin = pins.get(name);
|
|
1679
|
+
if (pin === void 0) continue;
|
|
1680
|
+
if (value === pin) continue;
|
|
1681
|
+
const workspace = value === "workspace:*" ? workspaceResolution({
|
|
1682
|
+
file,
|
|
1683
|
+
name,
|
|
1684
|
+
pin
|
|
1685
|
+
}) : void 0;
|
|
1686
|
+
if (workspace === "matched") continue;
|
|
1687
|
+
add({
|
|
1688
|
+
file,
|
|
1689
|
+
rule: name === "bun-types" ? "bun-pins" : "package-pins",
|
|
1690
|
+
key: location?.key ?? name,
|
|
1691
|
+
value: location === void 0 ? raw : location.value,
|
|
1692
|
+
message: workspace === "nonmember" ? `${name} workspace:* consumer is not a member of its nearest workspace` : `${name} must be ${pin}, found ${String(value)}`
|
|
1693
|
+
});
|
|
1694
|
+
}
|
|
1695
|
+
};
|
|
1696
|
+
for (const key of [
|
|
1697
|
+
"dependencies",
|
|
1698
|
+
"devDependencies",
|
|
1699
|
+
"optionalDependencies"
|
|
1700
|
+
]) checkEntries(json[key]);
|
|
1701
|
+
if (record$3(json["peerDependencies"])) {
|
|
1702
|
+
for (const [name, value] of Object.entries(json["peerDependencies"])) if (tsSpecifiers.has(name) && !peerRange(resolve(file, name, value))) checkEntries({ [name]: value });
|
|
1703
|
+
}
|
|
1704
|
+
for (const source of catalogSources(json)) {
|
|
1705
|
+
checkEntries(source["catalog"]);
|
|
1706
|
+
if (!record$3(source["catalogs"])) continue;
|
|
1707
|
+
for (const catalog of Object.values(source["catalogs"])) checkEntries(catalog);
|
|
1708
|
+
}
|
|
1709
|
+
const ownedNames = /* @__PURE__ */ new Set([...pins.keys(), ...tsSpecifiers.keys()]);
|
|
1710
|
+
const resolutionDependencies = {};
|
|
1711
|
+
const resolutionRoot = manifests.get(path.posix.join(path.posix.dirname(file), "package.json"));
|
|
1712
|
+
if (resolutionRoot !== void 0) for (const section of [
|
|
1713
|
+
"dependencies",
|
|
1714
|
+
"devDependencies",
|
|
1715
|
+
"optionalDependencies"
|
|
1716
|
+
]) {
|
|
1717
|
+
const entries = resolutionRoot[section];
|
|
1718
|
+
if (!record$3(entries)) continue;
|
|
1719
|
+
for (const [name, value] of Object.entries(entries)) resolutionDependencies[name] = resolve(file, name, value);
|
|
1720
|
+
}
|
|
1721
|
+
const affectedSpecifiers = /* @__PURE__ */ new Map();
|
|
1722
|
+
const owner = workspaceOwnerFor(file);
|
|
1723
|
+
for (const [candidate, member] of manifests) {
|
|
1724
|
+
if (path.posix.basename(candidate) !== "package.json") continue;
|
|
1725
|
+
const memberOwner = workspaceOwnerFor(candidate);
|
|
1726
|
+
if (!(candidate === path.posix.join(path.posix.dirname(file), "package.json")) && !(owner !== void 0 && owner.directory === path.posix.dirname(file) && memberOwner?.directory === owner.directory && memberOwner.source === owner.source && workspaceContains({
|
|
1727
|
+
directory: owner.directory,
|
|
1728
|
+
file: candidate,
|
|
1729
|
+
patterns: owner.patterns,
|
|
1730
|
+
rootMembership: "implicit"
|
|
1731
|
+
}))) continue;
|
|
1732
|
+
for (const section of [
|
|
1733
|
+
"dependencies",
|
|
1734
|
+
"devDependencies",
|
|
1735
|
+
"optionalDependencies"
|
|
1736
|
+
]) {
|
|
1737
|
+
const entries = member[section];
|
|
1738
|
+
if (!record$3(entries)) continue;
|
|
1739
|
+
for (const [name, value] of Object.entries(entries)) {
|
|
1740
|
+
if (!tsSpecifiers.has(name)) continue;
|
|
1741
|
+
const values = affectedSpecifiers.get(name) ?? /* @__PURE__ */ new Set();
|
|
1742
|
+
values.add(resolve(candidate, name, value));
|
|
1743
|
+
affectedSpecifiers.set(name, values);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
const checkResolutionMap = (entries, parent) => {
|
|
1748
|
+
if (!record$3(entries)) return;
|
|
1749
|
+
for (const [selector, replacement] of Object.entries(entries)) {
|
|
1750
|
+
const target = selector === "." ? parent : selector;
|
|
1751
|
+
if (target === void 0) continue;
|
|
1752
|
+
let pattern = target.split(/>\s*(?=[@A-Za-z_*]|$)/).at(-1)?.trim() ?? "";
|
|
1753
|
+
const version = pattern.lastIndexOf("@");
|
|
1754
|
+
let qualifier;
|
|
1755
|
+
if (version > pattern.lastIndexOf("/")) {
|
|
1756
|
+
qualifier = pattern.slice(version + 1).replace(/^npm:/, "");
|
|
1757
|
+
pattern = pattern.slice(0, version);
|
|
1758
|
+
}
|
|
1759
|
+
const parts = pattern.split("/");
|
|
1760
|
+
pattern = parts.at(-2)?.startsWith("@") ? parts.slice(-2).join("/") : parts.at(-1) ?? "";
|
|
1761
|
+
if (pattern === "") {
|
|
1762
|
+
add({
|
|
1763
|
+
file,
|
|
1764
|
+
rule: "package-pins",
|
|
1765
|
+
key: selector,
|
|
1766
|
+
value: replacement,
|
|
1767
|
+
message: "resolution selector must name a package"
|
|
1768
|
+
});
|
|
1769
|
+
continue;
|
|
1770
|
+
}
|
|
1771
|
+
if (record$3(replacement)) {
|
|
1772
|
+
checkResolutionMap(replacement, target);
|
|
1773
|
+
continue;
|
|
1774
|
+
}
|
|
1775
|
+
for (const name of ownedNames) {
|
|
1776
|
+
if (!picomatch(pattern)(name)) continue;
|
|
1777
|
+
let value = replacement;
|
|
1778
|
+
if (typeof replacement === "string" && replacement.startsWith("$")) {
|
|
1779
|
+
const reference = replacement.slice(1);
|
|
1780
|
+
value = resolutionDependencies[reference];
|
|
1781
|
+
}
|
|
1782
|
+
const resolved = resolve(file, name, value);
|
|
1783
|
+
checkEntries({ [name]: value }, {
|
|
1784
|
+
key: selector,
|
|
1785
|
+
value: replacement
|
|
1786
|
+
});
|
|
1787
|
+
if (tsSpecifiers.has(name) && [...affectedSpecifiers.get(name) ?? []].some((specifier) => {
|
|
1788
|
+
if (resolved === specifier) return false;
|
|
1789
|
+
if (qualifier === void 0 || validRange(qualifier) === null) return true;
|
|
1790
|
+
if (typeof specifier !== "string") return false;
|
|
1791
|
+
const release = valid(specifier.startsWith("npm:") ? specifier.slice(specifier.lastIndexOf("@") + 1) : specifier);
|
|
1792
|
+
return release !== null && satisfies(release, qualifier);
|
|
1793
|
+
}) && typeof resolved === "string" && tsSpecifiers.get(name)?.has(resolved)) add({
|
|
1794
|
+
file,
|
|
1795
|
+
rule: "typescript-layout",
|
|
1796
|
+
key: selector,
|
|
1797
|
+
value: replacement,
|
|
1798
|
+
message: `${name} resolution must preserve its declared TypeScript install specifier`
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
};
|
|
1803
|
+
checkResolutionMap(json["overrides"]);
|
|
1804
|
+
checkResolutionMap(json["resolutions"]);
|
|
1805
|
+
if (record$3(json["pnpm"])) checkResolutionMap(json["pnpm"]["overrides"]);
|
|
1806
|
+
const localEntries = toolchainEntries(file, json);
|
|
1807
|
+
const usesCompiler = policy.typescriptInstallLayouts.some((layout) => localEntries.some(({ name }) => name === layout.compilerPackage));
|
|
1808
|
+
let selectedLayout = layoutFor(specifierMap(localEntries));
|
|
1809
|
+
if (usesCompiler) {
|
|
1810
|
+
if (layoutFor(specifierMap(localEntries.filter(({ section }) => section !== "peerDependencies"))) === void 0) selectedLayout = void 0;
|
|
1811
|
+
if (selectedLayout === void 0) {
|
|
1812
|
+
const workspace = workspaceLayoutFor(file);
|
|
1813
|
+
const layout = workspace?.layout;
|
|
1814
|
+
if (workspace !== void 0 && layout !== void 0) {
|
|
1815
|
+
const expected = /* @__PURE__ */ new Map([[layout.compilerPackage, layout.compilerSpecifier]]);
|
|
1816
|
+
if (layout.type === "split-compatibility") expected.set(layout.compatibilityPackage, layout.compatibilitySpecifier);
|
|
1817
|
+
expected.set(policy.typescript6Compatibility.packageAlias, `npm:typescript@${policy.typescript6Compatibility.version}`);
|
|
1818
|
+
const developmentOnly = localEntries.every(({ section, name, value }) => section === "devDependencies" && expected.get(name) === value);
|
|
1819
|
+
const runtimeCompatibilityOnly = layout.type === "split-compatibility" && path.posix.dirname(file) !== workspace.directory && localEntries.every(({ section, name, value }) => (section === "dependencies" || section === "devDependencies" || section === "peerDependencies") && name === layout.compatibilityPackage && value === layout.compatibilitySpecifier);
|
|
1820
|
+
if (developmentOnly || runtimeCompatibilityOnly) selectedLayout = layout;
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
if (selectedLayout === void 0) add({
|
|
1824
|
+
file,
|
|
1825
|
+
rule: "typescript-layout",
|
|
1826
|
+
key: "dependencies",
|
|
1827
|
+
message: "TypeScript compiler and compatibility packages must match one complete declared install layout"
|
|
1828
|
+
});
|
|
1829
|
+
const command = record$3(json["scripts"]) ? json["scripts"]["typecheck"] : void 0;
|
|
1830
|
+
if (selectedLayout !== void 0 && typeof command === "string") {
|
|
1831
|
+
const normalizedExpected = selectedLayout.typecheckCommand.replace(/\s+/g, " ").trim();
|
|
1832
|
+
for (const words of compilerCommandSegments(command)) {
|
|
1833
|
+
if (!invokesCompiler(words)) continue;
|
|
1834
|
+
const normalized = words.join(" ");
|
|
1835
|
+
if (!words.some((word) => word === "(" || word === ")") && shellSubstitutions(normalized).length === 0 && (normalized === normalizedExpected || normalized.startsWith(`${normalizedExpected} `))) continue;
|
|
1836
|
+
add({
|
|
1837
|
+
file,
|
|
1838
|
+
rule: "typescript-layout",
|
|
1839
|
+
key: "typecheck",
|
|
1840
|
+
value: command,
|
|
1841
|
+
message: `typecheck compiler invocation must use ${selectedLayout.typecheckCommand}`
|
|
1842
|
+
});
|
|
1843
|
+
break;
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
if (record$3(json["peerDependencies"])) {
|
|
1848
|
+
const peerLayout = selectedLayout ?? workspaceLayoutFor(file)?.layout;
|
|
1849
|
+
for (const [name, raw] of Object.entries(json["peerDependencies"])) {
|
|
1850
|
+
if (!tsSpecifiers.has(name)) continue;
|
|
1851
|
+
const range = resolve(file, name, raw);
|
|
1852
|
+
if (!peerRange(range)) continue;
|
|
1853
|
+
const releases = /* @__PURE__ */ new Set();
|
|
1854
|
+
for (const layout of policy.typescriptInstallLayouts) {
|
|
1855
|
+
if (layout.compilerPackage !== name && !(layout.type === "split-compatibility" && layout.compatibilityPackage === name)) continue;
|
|
1856
|
+
const specifier = layout.compilerSpecifier;
|
|
1857
|
+
releases.add(specifier.startsWith("npm:") ? specifier.slice(specifier.lastIndexOf("@") + 1) : specifier);
|
|
1858
|
+
}
|
|
1859
|
+
if (name === policy.typescript6Compatibility.packageAlias) releases.add(policy.typescript6Compatibility.version);
|
|
1860
|
+
if (peerLayout?.type === "split-compatibility" && name === peerLayout.compatibilityPackage) releases.add(peerLayout.compatibilitySpecifier);
|
|
1861
|
+
if ([...releases].every((release) => satisfies(release, range))) continue;
|
|
1862
|
+
add({
|
|
1863
|
+
file,
|
|
1864
|
+
rule: "typescript-layout",
|
|
1865
|
+
key: name,
|
|
1866
|
+
value: raw,
|
|
1867
|
+
message: `${name} peer support range must include ${[...releases].join(" and ")}, found ${range}`
|
|
1868
|
+
});
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
if (record$3(json["engines"]) && json["engines"]["node"] !== void 0 && (typeof json["engines"]["node"] !== "string" || !nodeSupportRangeMatches(policy.node, json["engines"]["node"]))) add({
|
|
1872
|
+
file,
|
|
1873
|
+
rule: "node-engine",
|
|
1874
|
+
key: "node",
|
|
1875
|
+
value: json["engines"]["node"],
|
|
1876
|
+
message: `engines.node must support ${policy.node}, found ${JSON.stringify(json["engines"]["node"])}`
|
|
1877
|
+
});
|
|
1878
|
+
}
|
|
1879
|
+
return diagnostics;
|
|
1880
|
+
};
|
|
1881
|
+
//#endregion
|
|
1882
|
+
//#region src/toolchain-runtime.ts
|
|
1883
|
+
const runtimeRules = [
|
|
1884
|
+
"bun-pins",
|
|
1885
|
+
"node-version",
|
|
1886
|
+
"python-version",
|
|
1887
|
+
"rust-version",
|
|
1888
|
+
"runtime-manager",
|
|
1889
|
+
"runtime-docker",
|
|
1890
|
+
"runtime-workflow",
|
|
1891
|
+
"action-pins"
|
|
1892
|
+
];
|
|
1893
|
+
const record$2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1894
|
+
const pythonSelectorMatches = (value, expected) => value === expected || typeof value === "string" && /^\d+\.\d+$/.test(expected) && value.startsWith(`${expected}.`) && /^\d+\.\d+\.\d+$/.test(value);
|
|
1895
|
+
const compareRelease = (left, right) => {
|
|
1896
|
+
for (let index = 0; index < Math.max(left.length, right.length); index++) {
|
|
1897
|
+
const difference = (left.at(index) ?? 0) - (right.at(index) ?? 0);
|
|
1898
|
+
if (difference !== 0) return Math.sign(difference);
|
|
1899
|
+
}
|
|
1900
|
+
return 0;
|
|
1901
|
+
};
|
|
1902
|
+
const pythonSeriesRequirementMatches = ({ current, operator, target, wildcard }) => {
|
|
1903
|
+
const prefixCovers = (prefix) => prefix.length <= 2 && prefix.every((part, index) => current.at(index) === part);
|
|
1904
|
+
const prefixOverlaps = target.slice(0, 2).every((part, index) => current.at(index) === part) && target.slice(3).every((part) => part === 0);
|
|
1905
|
+
if (wildcard) {
|
|
1906
|
+
if (operator === "==") return prefixCovers(target);
|
|
1907
|
+
if (operator === "!=") return !prefixOverlaps;
|
|
1908
|
+
return false;
|
|
1909
|
+
}
|
|
1910
|
+
const minimumComparison = compareRelease(current, target);
|
|
1911
|
+
const seriesComparison = compareRelease(current.slice(0, 2), target.slice(0, 2));
|
|
1912
|
+
switch (operator) {
|
|
1913
|
+
case "==": return false;
|
|
1914
|
+
case "!=": return !(seriesComparison === 0 && target.slice(3).every((part) => part === 0));
|
|
1915
|
+
case ">=": return minimumComparison >= 0;
|
|
1916
|
+
case ">": return minimumComparison > 0;
|
|
1917
|
+
case "<=":
|
|
1918
|
+
case "<": return seriesComparison < 0;
|
|
1919
|
+
case "~=": return target.length >= 2 && minimumComparison >= 0 && prefixCovers(target.slice(0, -1));
|
|
1920
|
+
default: return false;
|
|
1921
|
+
}
|
|
1922
|
+
};
|
|
1923
|
+
/** Evaluate final-release Python constraints against the complete selected version set. */
|
|
1924
|
+
const pythonRequirementMatches = (requirement, version) => {
|
|
1925
|
+
if (typeof requirement !== "string" || requirement.trim() === "") return false;
|
|
1926
|
+
const current = version.split(".").map(Number);
|
|
1927
|
+
return requirement.split(",").every((clause) => {
|
|
1928
|
+
const match = /^(~=|==|!=|<=|>=|<|>)\s*(\d+(?:\.\d+)*)(\.\*)?$/.exec(clause.trim());
|
|
1929
|
+
if (match === null) return false;
|
|
1930
|
+
const operator = match[1];
|
|
1931
|
+
const release = match[2];
|
|
1932
|
+
if (release === void 0 || operator === void 0) return false;
|
|
1933
|
+
const target = release.split(".").map(Number);
|
|
1934
|
+
if (current.length === 2) return pythonSeriesRequirementMatches({
|
|
1935
|
+
current,
|
|
1936
|
+
operator,
|
|
1937
|
+
target,
|
|
1938
|
+
wildcard: match[3] !== void 0
|
|
1939
|
+
});
|
|
1940
|
+
const comparison = compareRelease(current, target);
|
|
1941
|
+
if (match[3] !== void 0) {
|
|
1942
|
+
if (operator !== "==" && operator !== "!=") return false;
|
|
1943
|
+
const prefix = target.every((part, index) => (current.at(index) ?? 0) === part);
|
|
1944
|
+
return operator === "==" ? prefix : !prefix;
|
|
1945
|
+
}
|
|
1946
|
+
switch (operator) {
|
|
1947
|
+
case "==": return comparison === 0;
|
|
1948
|
+
case "!=": return comparison !== 0;
|
|
1949
|
+
case "<=": return comparison <= 0;
|
|
1950
|
+
case ">=": return comparison >= 0;
|
|
1951
|
+
case "<": return comparison < 0;
|
|
1952
|
+
case ">": return comparison > 0;
|
|
1953
|
+
case "~=": {
|
|
1954
|
+
if (target.length < 2) return false;
|
|
1955
|
+
const prefix = target.slice(0, -1);
|
|
1956
|
+
return comparison >= 0 && prefix.every((part, index) => (current.at(index) ?? 0) === part);
|
|
1957
|
+
}
|
|
1958
|
+
default: return false;
|
|
1959
|
+
}
|
|
1960
|
+
});
|
|
1961
|
+
};
|
|
1962
|
+
/** Check runtime declarations only in the files that declare or configure them. */
|
|
1963
|
+
const checkRuntimeFile = ({ file, text, policy, trackedFiles, readFile, repository, onDelegated, engineFloors = [], onEngineFloor }) => {
|
|
1964
|
+
const diagnostics = [];
|
|
1965
|
+
const name = path.posix.basename(file);
|
|
1966
|
+
const lines = text.split(/\r?\n/);
|
|
1967
|
+
const add = ({ rule, line, message }) => {
|
|
1968
|
+
diagnostics.push({
|
|
1969
|
+
rule,
|
|
1970
|
+
path: file,
|
|
1971
|
+
line,
|
|
1972
|
+
message
|
|
1973
|
+
});
|
|
1974
|
+
};
|
|
1975
|
+
const lineOf = (key) => Math.max(1, lines.findIndex((line) => line.includes(key)) + 1);
|
|
1976
|
+
const pin = ({ rule, value, expected, label, line = 1, selector }) => {
|
|
1977
|
+
let matches = value === expected;
|
|
1978
|
+
if (selector === "node") matches = nodeSelectorMatches(value, expected);
|
|
1979
|
+
else if (label.includes("python")) matches = pythonSelectorMatches(value, expected);
|
|
1980
|
+
if (!matches) add({
|
|
1981
|
+
rule,
|
|
1982
|
+
line,
|
|
1983
|
+
message: `${label} must be ${expected}, found ${String(value)}`
|
|
1984
|
+
});
|
|
1985
|
+
};
|
|
1986
|
+
const toml = (rule) => {
|
|
1987
|
+
try {
|
|
1988
|
+
return parse(text);
|
|
1989
|
+
} catch {
|
|
1990
|
+
add({
|
|
1991
|
+
rule,
|
|
1992
|
+
line: 1,
|
|
1993
|
+
message: "invalid TOML"
|
|
1994
|
+
});
|
|
1995
|
+
return;
|
|
1996
|
+
}
|
|
1997
|
+
};
|
|
1998
|
+
const versions = {
|
|
1999
|
+
...policy.packages,
|
|
2000
|
+
...Object.fromEntries(Object.entries(policy.packages).map(([tool, version]) => [`npm:${tool}`, version])),
|
|
2001
|
+
bun: policy.bun,
|
|
2002
|
+
node: policy.node,
|
|
2003
|
+
nodejs: policy.node,
|
|
2004
|
+
python: policy.python,
|
|
2005
|
+
rust: policy.rust,
|
|
2006
|
+
"core:node": policy.node,
|
|
2007
|
+
"core:python": policy.python,
|
|
2008
|
+
"core:rust": policy.rust,
|
|
2009
|
+
"core:bun": policy.bun
|
|
2010
|
+
};
|
|
2011
|
+
const nodeTools = /* @__PURE__ */ new Set([
|
|
2012
|
+
"node",
|
|
2013
|
+
"nodejs",
|
|
2014
|
+
"core:node"
|
|
2015
|
+
]);
|
|
2016
|
+
if (name === ".bun-version") pin({
|
|
2017
|
+
rule: "bun-pins",
|
|
2018
|
+
value: text.trim(),
|
|
2019
|
+
expected: policy.bun,
|
|
2020
|
+
label: name
|
|
2021
|
+
});
|
|
2022
|
+
if (name === ".node-version" || name === ".nvmrc") pin({
|
|
2023
|
+
rule: "node-version",
|
|
2024
|
+
selector: "node",
|
|
2025
|
+
value: text.trim(),
|
|
2026
|
+
expected: policy.node,
|
|
2027
|
+
label: name
|
|
2028
|
+
});
|
|
2029
|
+
if (name === ".python-version") pin({
|
|
2030
|
+
rule: "python-version",
|
|
2031
|
+
value: text.trim(),
|
|
2032
|
+
expected: policy.python,
|
|
2033
|
+
label: name
|
|
2034
|
+
});
|
|
2035
|
+
const firstContent = lines.find((line) => line.trim() !== "" && !line.trimStart().startsWith("#"));
|
|
2036
|
+
const rustToml = name === "rust-toolchain.toml" || name === "rust-toolchain" && firstContent?.trimStart().startsWith("[");
|
|
2037
|
+
if (name === "rust-toolchain" && !rustToml) pin({
|
|
2038
|
+
rule: "rust-version",
|
|
2039
|
+
value: text.trim(),
|
|
2040
|
+
expected: policy.rust,
|
|
2041
|
+
label: name
|
|
2042
|
+
});
|
|
2043
|
+
if (rustToml) {
|
|
2044
|
+
const parsed = toml("rust-version");
|
|
2045
|
+
if (parsed !== void 0) {
|
|
2046
|
+
const toolchain = parsed["toolchain"];
|
|
2047
|
+
const components = record$2(toolchain) ? toolchain["components"] : void 0;
|
|
2048
|
+
const expected = Array.isArray(components) && components.includes("rustc-dev") ? policy.rustCompilerDevelopment : policy.rust;
|
|
2049
|
+
pin({
|
|
2050
|
+
rule: "rust-version",
|
|
2051
|
+
value: record$2(toolchain) ? toolchain["channel"] : void 0,
|
|
2052
|
+
expected,
|
|
2053
|
+
label: "Rust channel",
|
|
2054
|
+
line: lineOf("channel")
|
|
2055
|
+
});
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
if (name === "Cargo.toml") {
|
|
2059
|
+
const parsed = toml("rust-version");
|
|
2060
|
+
const rustFloor = (value) => {
|
|
2061
|
+
const parts = typeof value === "string" && /^(?:0|[1-9]\d*)(?:\.(?:0|[1-9]\d*)){0,2}$/.test(value) ? value.split(".").map(Number) : void 0;
|
|
2062
|
+
if (parts === void 0 || !parts.every(Number.isSafeInteger) || compareRelease(parts, policy.rust.split(".").map(Number)) > 0) add({
|
|
2063
|
+
rule: "rust-version",
|
|
2064
|
+
line: lineOf("rust-version"),
|
|
2065
|
+
message: `Cargo rust-version must be a bare support floor at or below Rust ${policy.rust}`
|
|
2066
|
+
});
|
|
2067
|
+
};
|
|
2068
|
+
const readManifest = (candidate) => {
|
|
2069
|
+
if (candidate === file) return parsed;
|
|
2070
|
+
if (!trackedFiles.has(candidate)) return void 0;
|
|
2071
|
+
try {
|
|
2072
|
+
return parse(readFile(candidate) ?? "");
|
|
2073
|
+
} catch {
|
|
2074
|
+
return;
|
|
2075
|
+
}
|
|
2076
|
+
};
|
|
2077
|
+
if (parsed !== void 0) {
|
|
2078
|
+
const workspace = parsed["workspace"];
|
|
2079
|
+
const defaults = record$2(workspace) ? workspace["package"] : void 0;
|
|
2080
|
+
if (record$2(defaults) && defaults["rust-version"] !== void 0) rustFloor(defaults["rust-version"]);
|
|
2081
|
+
const pkg = parsed["package"];
|
|
2082
|
+
const version = record$2(pkg) ? pkg["rust-version"] : void 0;
|
|
2083
|
+
if (version !== void 0) if (!record$2(version)) rustFloor(version);
|
|
2084
|
+
else {
|
|
2085
|
+
let inherited;
|
|
2086
|
+
if (version["workspace"] === true && record$2(pkg)) {
|
|
2087
|
+
const explicit = pkg["workspace"];
|
|
2088
|
+
let directory = path.posix.dirname(file);
|
|
2089
|
+
const explicitPath = typeof explicit === "string" && !explicit.includes("\\") && !explicit.includes(":") && !explicit.includes("${{") && !path.posix.isAbsolute(explicit) ? path.posix.normalize(path.posix.join(directory, explicit)) : void 0;
|
|
2090
|
+
if (explicit === void 0 || explicitPath !== void 0 && explicitPath !== ".." && !explicitPath.startsWith("../")) {
|
|
2091
|
+
if (explicitPath !== void 0) directory = explicitPath;
|
|
2092
|
+
while (true) {
|
|
2093
|
+
const table = readManifest(path.posix.join(directory, "Cargo.toml"))?.["workspace"];
|
|
2094
|
+
if (record$2(table)) {
|
|
2095
|
+
const fields = table["package"];
|
|
2096
|
+
inherited = record$2(fields) ? fields["rust-version"] : void 0;
|
|
2097
|
+
break;
|
|
2098
|
+
}
|
|
2099
|
+
if (explicit !== void 0 || directory === ".") break;
|
|
2100
|
+
directory = path.posix.dirname(directory);
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
rustFloor(inherited);
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
if (name === "Pipfile") {
|
|
2109
|
+
const requires = toml("python-version")?.["requires"];
|
|
2110
|
+
if (record$2(requires)) {
|
|
2111
|
+
const minor = requires["python_version"];
|
|
2112
|
+
if (minor !== void 0 && minor !== policy.python.split(".").slice(0, 2).join(".")) add({
|
|
2113
|
+
rule: "python-version",
|
|
2114
|
+
line: lineOf("python_version"),
|
|
2115
|
+
message: `Pipfile python_version must select Python ${policy.python}`
|
|
2116
|
+
});
|
|
2117
|
+
const full = requires["python_full_version"];
|
|
2118
|
+
if (full !== void 0 && !(typeof full === "string" && /^\d+\.\d+\.\d+$/.test(full) && pythonSelectorMatches(full, policy.python))) add({
|
|
2119
|
+
rule: "python-version",
|
|
2120
|
+
line: lineOf("python_full_version"),
|
|
2121
|
+
message: `Pipfile python_full_version must select Python ${policy.python}`
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
if (name === "pyproject.toml" || name === "uv.toml") {
|
|
2126
|
+
const parsed = toml("python-version");
|
|
2127
|
+
if (parsed !== void 0) {
|
|
2128
|
+
const project = parsed["project"];
|
|
2129
|
+
if (record$2(project) && project["requires-python"] !== void 0) {
|
|
2130
|
+
if (!pythonRequirementMatches(project["requires-python"], policy.python)) add({
|
|
2131
|
+
rule: "python-version",
|
|
2132
|
+
line: lineOf("requires-python"),
|
|
2133
|
+
message: `requires-python must include Python ${policy.python}; unsupported constraints must use final-release version specifiers`
|
|
2134
|
+
});
|
|
2135
|
+
}
|
|
2136
|
+
const tool = parsed["tool"];
|
|
2137
|
+
const configuredUv = record$2(tool) ? tool["uv"] : void 0;
|
|
2138
|
+
const uv = name === "uv.toml" ? parsed : configuredUv;
|
|
2139
|
+
if (record$2(uv) && uv["python"] !== void 0) pin({
|
|
2140
|
+
rule: "python-version",
|
|
2141
|
+
value: uv["python"],
|
|
2142
|
+
expected: policy.python,
|
|
2143
|
+
label: "uv python",
|
|
2144
|
+
line: lineOf("python")
|
|
2145
|
+
});
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
if (isMiseConfigPath(file)) {
|
|
2149
|
+
const tools = toml("runtime-manager")?.["tools"];
|
|
2150
|
+
if (record$2(tools)) for (const [tool, expected] of Object.entries(versions)) {
|
|
2151
|
+
const configured = tools[tool];
|
|
2152
|
+
if (configured !== void 0) pin({
|
|
2153
|
+
rule: "runtime-manager",
|
|
2154
|
+
value: record$2(configured) ? configured["version"] : configured,
|
|
2155
|
+
expected,
|
|
2156
|
+
selector: nodeTools.has(tool) ? "node" : void 0,
|
|
2157
|
+
label: `mise ${tool}`,
|
|
2158
|
+
line: lineOf(tool)
|
|
2159
|
+
});
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
if (name === ".tool-versions") lines.forEach((line, index) => {
|
|
2163
|
+
const fields = line.replace(/#.*$/, "").trim().split(/\s+/);
|
|
2164
|
+
const tool = fields.at(0);
|
|
2165
|
+
if (tool === void 0 || !(tool in versions)) return;
|
|
2166
|
+
const expected = Object.entries(versions).find(([key]) => key === tool)?.[1];
|
|
2167
|
+
if (expected !== void 0) pin({
|
|
2168
|
+
rule: "runtime-manager",
|
|
2169
|
+
value: fields.slice(1).join(" "),
|
|
2170
|
+
expected,
|
|
2171
|
+
selector: nodeTools.has(tool) ? "node" : void 0,
|
|
2172
|
+
label: `.tool-versions ${tool}`,
|
|
2173
|
+
line: index + 1
|
|
2174
|
+
});
|
|
2175
|
+
});
|
|
2176
|
+
const checkRuntimeImage = ({ image, line, label }) => {
|
|
2177
|
+
if (typeof image !== "string" || image.includes("$")) {
|
|
2178
|
+
add({
|
|
2179
|
+
rule: "runtime-docker",
|
|
2180
|
+
line,
|
|
2181
|
+
message: `cannot determine ${label} runtime; use a static image or a reasoned runtime-docker opt-out`
|
|
2182
|
+
});
|
|
2183
|
+
return;
|
|
2184
|
+
}
|
|
2185
|
+
const runtime = /^(node|python|oven\/bun)(?::([^@]+))?(?:@.*)?$/i.exec(canonicalDockerRuntime(image));
|
|
2186
|
+
if (runtime === null) return;
|
|
2187
|
+
const tool = runtime[1]?.toLowerCase();
|
|
2188
|
+
if (image.includes("@")) {
|
|
2189
|
+
add({
|
|
2190
|
+
rule: tool === "oven/bun" ? "bun-pins" : "runtime-docker",
|
|
2191
|
+
line,
|
|
2192
|
+
message: `${label} ${tool} digest requires an approved digest policy; use a tag-only runtime image`
|
|
2193
|
+
});
|
|
2194
|
+
return;
|
|
2195
|
+
}
|
|
2196
|
+
const tag = runtime[2];
|
|
2197
|
+
const variantSuffix = tool === "oven/bun" ? /-(?:alpine|slim|debian)$/ : /-(?:alpine(?:\d+(?:\.\d+)*)?|(?:bookworm|bullseye|trixie|buster)(?:-slim)?|slim)$/;
|
|
2198
|
+
const version = tag?.replace(variantSuffix, "");
|
|
2199
|
+
let expected = policy.bun;
|
|
2200
|
+
if (tool === "node") expected = policy.node;
|
|
2201
|
+
else if (tool === "python") expected = policy.python;
|
|
2202
|
+
pin({
|
|
2203
|
+
rule: tool === "oven/bun" ? "bun-pins" : "runtime-docker",
|
|
2204
|
+
value: version,
|
|
2205
|
+
expected,
|
|
2206
|
+
selector: tool === "node" ? "node" : void 0,
|
|
2207
|
+
label: `${label} ${tool}`,
|
|
2208
|
+
line
|
|
2209
|
+
});
|
|
2210
|
+
};
|
|
2211
|
+
if (isDockerDefinitionPath(file)) {
|
|
2212
|
+
const variables = /* @__PURE__ */ new Map();
|
|
2213
|
+
const escape = /^\s*#\s*escape\s*=\s*([\\`])\s*$/m.exec(text)?.[1] ?? "\\";
|
|
2214
|
+
const continuation = new RegExp(`${escape === "`" ? "`" : "\\\\"}\\s*$`);
|
|
2215
|
+
const stages = /* @__PURE__ */ new Set();
|
|
2216
|
+
let argumentScope = "global";
|
|
2217
|
+
const heredocs = [];
|
|
2218
|
+
let instruction = "";
|
|
2219
|
+
let startLine = 1;
|
|
2220
|
+
const expand = (value) => {
|
|
2221
|
+
for (let count = 0; count <= variables.size; count++) {
|
|
2222
|
+
const next = value.replace(/\$(?:\{([A-Za-z_][A-Za-z_\d]*)\}|([A-Za-z_][A-Za-z_\d]*))/g, (reference, braced, plain) => variables.get(braced ?? plain ?? "") ?? reference);
|
|
2223
|
+
if (next === value) return next;
|
|
2224
|
+
value = next;
|
|
2225
|
+
}
|
|
2226
|
+
return value;
|
|
2227
|
+
};
|
|
2228
|
+
const collectHeredocs = (content, line) => {
|
|
2229
|
+
let quote;
|
|
2230
|
+
for (let index = 0; index < content.length; index++) {
|
|
2231
|
+
const character = content.at(index);
|
|
2232
|
+
if (quote !== void 0) {
|
|
2233
|
+
if (character === quote) quote = void 0;
|
|
2234
|
+
else if (quote === "\"" && character === "\\") index++;
|
|
2235
|
+
continue;
|
|
2236
|
+
}
|
|
2237
|
+
if (character === "\\") {
|
|
2238
|
+
index++;
|
|
2239
|
+
continue;
|
|
2240
|
+
}
|
|
2241
|
+
if (character === "'" || character === "\"") {
|
|
2242
|
+
quote = character;
|
|
2243
|
+
continue;
|
|
2244
|
+
}
|
|
2245
|
+
if (character === "#" && (index === 0 || /[\s;&|()]/.test(content.at(index - 1) ?? ""))) break;
|
|
2246
|
+
if (character !== "<" || content.at(index + 1) !== "<") continue;
|
|
2247
|
+
if (content.at(index + 2) === "<") {
|
|
2248
|
+
index += 2;
|
|
2249
|
+
continue;
|
|
2250
|
+
}
|
|
2251
|
+
index += 2;
|
|
2252
|
+
const stripTabs = content.at(index) === "-";
|
|
2253
|
+
if (stripTabs) index++;
|
|
2254
|
+
while (/\s/.test(content.at(index) ?? "")) index++;
|
|
2255
|
+
if (content.at(index) === "#") {
|
|
2256
|
+
add({
|
|
2257
|
+
rule: "runtime-docker",
|
|
2258
|
+
line,
|
|
2259
|
+
message: "invalid Docker heredoc delimiter"
|
|
2260
|
+
});
|
|
2261
|
+
break;
|
|
2262
|
+
}
|
|
2263
|
+
let delimiter = "";
|
|
2264
|
+
let delimiterQuote;
|
|
2265
|
+
for (; index < content.length; index++) {
|
|
2266
|
+
const part = content.at(index);
|
|
2267
|
+
if (delimiterQuote !== void 0) {
|
|
2268
|
+
if (part === delimiterQuote) delimiterQuote = void 0;
|
|
2269
|
+
else if (delimiterQuote === "\"" && part === "\\" && /[$"\\]/.test(content.at(index + 1) ?? "")) delimiter += content.at(++index);
|
|
2270
|
+
else delimiter += part;
|
|
2271
|
+
continue;
|
|
2272
|
+
}
|
|
2273
|
+
if (part === "'" || part === "\"") {
|
|
2274
|
+
delimiterQuote = part;
|
|
2275
|
+
continue;
|
|
2276
|
+
}
|
|
2277
|
+
if (part === "\\" && content.at(index + 1) !== void 0) {
|
|
2278
|
+
delimiter += content.at(++index);
|
|
2279
|
+
continue;
|
|
2280
|
+
}
|
|
2281
|
+
if (/[\s;&|<>()]/.test(part ?? "")) break;
|
|
2282
|
+
delimiter += part;
|
|
2283
|
+
}
|
|
2284
|
+
if (delimiter !== "" && delimiterQuote === void 0) heredocs.push({
|
|
2285
|
+
delimiter,
|
|
2286
|
+
stripTabs,
|
|
2287
|
+
line
|
|
2288
|
+
});
|
|
2289
|
+
else add({
|
|
2290
|
+
rule: "runtime-docker",
|
|
2291
|
+
line,
|
|
2292
|
+
message: "invalid Docker heredoc delimiter"
|
|
2293
|
+
});
|
|
2294
|
+
index--;
|
|
2295
|
+
}
|
|
2296
|
+
};
|
|
2297
|
+
const checkInstruction = (content, line) => {
|
|
2298
|
+
const argument = /^\s*ARG\s+([A-Za-z_][A-Za-z_\d]*)(?:=(.*))?$/i.exec(content);
|
|
2299
|
+
if (argument !== null) {
|
|
2300
|
+
if (argumentScope === "stage") return;
|
|
2301
|
+
const key = argument[1];
|
|
2302
|
+
const value = argument[2];
|
|
2303
|
+
if (key !== void 0 && value !== void 0) variables.set(key, expand(value.replace(/^(["'])(.*)\1$/, "$2")));
|
|
2304
|
+
return;
|
|
2305
|
+
}
|
|
2306
|
+
if (/^\s*(?:RUN|COPY)\s+/i.test(content)) {
|
|
2307
|
+
collectHeredocs(content, line);
|
|
2308
|
+
return;
|
|
2309
|
+
}
|
|
2310
|
+
const from = /^\s*FROM\s+(?:--platform=\S+\s+)?(\S+)(?:\s+AS\s+(\S+))?/i.exec(content);
|
|
2311
|
+
if (from === null || from[1] === void 0) return;
|
|
2312
|
+
argumentScope = "stage";
|
|
2313
|
+
const image = expand(from[1]);
|
|
2314
|
+
if (image.includes("$")) {
|
|
2315
|
+
add({
|
|
2316
|
+
rule: "runtime-docker",
|
|
2317
|
+
line,
|
|
2318
|
+
message: "cannot determine FROM runtime; declare an image ARG default or a reasoned runtime-docker opt-out"
|
|
2319
|
+
});
|
|
2320
|
+
return;
|
|
2321
|
+
}
|
|
2322
|
+
const stage = from[2]?.toLowerCase();
|
|
2323
|
+
const previousStage = stages.has(image.toLowerCase());
|
|
2324
|
+
if (stage !== void 0) stages.add(stage);
|
|
2325
|
+
if (previousStage) return;
|
|
2326
|
+
checkRuntimeImage({
|
|
2327
|
+
image,
|
|
2328
|
+
line,
|
|
2329
|
+
label: "FROM"
|
|
2330
|
+
});
|
|
2331
|
+
};
|
|
2332
|
+
lines.forEach((line, index) => {
|
|
2333
|
+
const heredoc = heredocs.at(0);
|
|
2334
|
+
if (heredoc !== void 0) {
|
|
2335
|
+
if ((heredoc.stripTabs ? line.replace(/^\t+/, "") : line) === heredoc.delimiter) heredocs.shift();
|
|
2336
|
+
return;
|
|
2337
|
+
}
|
|
2338
|
+
if (line.trimStart().startsWith("#")) return;
|
|
2339
|
+
if (instruction === "") startLine = index + 1;
|
|
2340
|
+
instruction += line.replace(continuation, " ");
|
|
2341
|
+
if (continuation.test(line)) return;
|
|
2342
|
+
checkInstruction(instruction, startLine);
|
|
2343
|
+
instruction = "";
|
|
2344
|
+
});
|
|
2345
|
+
if (instruction !== "") checkInstruction(instruction, startLine);
|
|
2346
|
+
for (const heredoc of heredocs) add({
|
|
2347
|
+
rule: "runtime-docker",
|
|
2348
|
+
line: heredoc.line,
|
|
2349
|
+
message: `unterminated Docker heredoc ${heredoc.delimiter}`
|
|
2350
|
+
});
|
|
2351
|
+
}
|
|
2352
|
+
if (isComposeDefinitionPath(file) || isKubernetesDefinitionPath(file)) {
|
|
2353
|
+
const lineCounter = new LineCounter();
|
|
2354
|
+
for (const containerDocument of parseAllDocuments(text, {
|
|
2355
|
+
lineCounter,
|
|
2356
|
+
merge: true,
|
|
2357
|
+
uniqueKeys: true
|
|
2358
|
+
})) {
|
|
2359
|
+
const contents = containerDocument.contents;
|
|
2360
|
+
const declaredResource = isMap(contents) && isScalar(contents.get("apiVersion", true)) && isScalar(contents.get("kind", true));
|
|
2361
|
+
const recognizedContainer = isComposeDefinitionPath(file) || declaredResource;
|
|
2362
|
+
if (containerDocument.errors.length > 0) {
|
|
2363
|
+
if (recognizedContainer) add({
|
|
2364
|
+
rule: "runtime-docker",
|
|
2365
|
+
line: 1,
|
|
2366
|
+
message: "invalid container YAML"
|
|
2367
|
+
});
|
|
2368
|
+
continue;
|
|
2369
|
+
}
|
|
2370
|
+
try {
|
|
2371
|
+
const classified = containerDocumentImages(containerDocument.toJS({ maxAliasCount: 100 }), file);
|
|
2372
|
+
for (const entry of classified?.images ?? []) {
|
|
2373
|
+
const node = containerDocument.getIn(entry.path, true);
|
|
2374
|
+
const line = (isMap(node) || isScalar(node) || isSeq(node) || isAlias(node)) && node.range !== void 0 && node.range !== null ? lineCounter.linePos(node.range[0]).line : 1;
|
|
2375
|
+
checkRuntimeImage({
|
|
2376
|
+
image: entry.image,
|
|
2377
|
+
line,
|
|
2378
|
+
label: classified?.ecosystem === "docker-compose" ? "Compose image" : "Kubernetes image"
|
|
2379
|
+
});
|
|
2380
|
+
}
|
|
2381
|
+
} catch {
|
|
2382
|
+
if (recognizedContainer) add({
|
|
2383
|
+
rule: "runtime-docker",
|
|
2384
|
+
line: 1,
|
|
2385
|
+
message: "invalid container YAML aliases"
|
|
2386
|
+
});
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
const automationKind = githubAutomationFileKind(file);
|
|
2391
|
+
if (automationKind === void 0) return diagnostics;
|
|
2392
|
+
const document = parseDocument(text, {
|
|
2393
|
+
uniqueKeys: true,
|
|
2394
|
+
merge: true
|
|
2395
|
+
});
|
|
2396
|
+
if (document.errors.length > 0) {
|
|
2397
|
+
add({
|
|
2398
|
+
rule: "runtime-workflow",
|
|
2399
|
+
line: 1,
|
|
2400
|
+
message: "invalid workflow YAML"
|
|
2401
|
+
});
|
|
2402
|
+
return diagnostics;
|
|
2403
|
+
}
|
|
2404
|
+
const nodeLine = (node) => {
|
|
2405
|
+
if (!record$2(node) || !Array.isArray(node["range"])) return 1;
|
|
2406
|
+
const offset = node["range"].at(0);
|
|
2407
|
+
return typeof offset === "number" ? text.slice(0, offset).split("\n").length : 1;
|
|
2408
|
+
};
|
|
2409
|
+
let checkoutBindings = [];
|
|
2410
|
+
let checkoutDestinations = /* @__PURE__ */ new Map();
|
|
2411
|
+
let unknownCheckoutDestination = false;
|
|
2412
|
+
const staticRepositoryPath = (value) => typeof value === "string" && value !== "" && !value.includes("${{") && !value.includes("\\") && !value.includes(":") && !path.posix.isAbsolute(value) && !value.split("/").includes("..");
|
|
2413
|
+
const normalizeCheckoutPath = (prefix) => path.posix.normalize(prefix).replace(/\/$/, "") || ".";
|
|
2414
|
+
const checkReference = ({ value, tool, line }) => {
|
|
2415
|
+
const allowed = {
|
|
2416
|
+
node: [".node-version", ".nvmrc"],
|
|
2417
|
+
python: [".python-version"],
|
|
2418
|
+
bun: ["package.json"]
|
|
2419
|
+
}[tool];
|
|
2420
|
+
const rule = tool === "bun" ? "bun-pins" : "runtime-workflow";
|
|
2421
|
+
const selector = staticRepositoryPath(value) ? path.posix.normalize(value) : void 0;
|
|
2422
|
+
const binding = selector === void 0 ? void 0 : checkoutBindings.findLast((entry) => entry.path === "." || selector === entry.path || selector.startsWith(`${entry.path}/`));
|
|
2423
|
+
if (selector === void 0) {
|
|
2424
|
+
add({
|
|
2425
|
+
rule,
|
|
2426
|
+
line,
|
|
2427
|
+
message: `setup-${tool} must reference a tracked ${allowed.join(" or ")}`
|
|
2428
|
+
});
|
|
2429
|
+
return;
|
|
2430
|
+
}
|
|
2431
|
+
if (unknownCheckoutDestination || [...checkoutDestinations].some(([prefix, count]) => count > 1 && (prefix === "." || selector === prefix || selector.startsWith(`${prefix}/`)))) {
|
|
2432
|
+
add({
|
|
2433
|
+
rule,
|
|
2434
|
+
line,
|
|
2435
|
+
message: `setup-${tool} version-file selector has untrusted checkout provenance: checkout destinations must be static and have exactly one writer`
|
|
2436
|
+
});
|
|
2437
|
+
return;
|
|
2438
|
+
}
|
|
2439
|
+
if (binding?.source === "untrusted") {
|
|
2440
|
+
add({
|
|
2441
|
+
rule,
|
|
2442
|
+
line: binding.line,
|
|
2443
|
+
message: `setup-${tool} version-file selector cannot use this checkout: ${binding.reason}`
|
|
2444
|
+
});
|
|
2445
|
+
return;
|
|
2446
|
+
}
|
|
2447
|
+
const target = binding === void 0 || binding.path === "." ? selector : path.posix.relative(binding.path, selector);
|
|
2448
|
+
if (!allowed.includes(path.posix.basename(target)) || binding?.source !== "delegated" && !trackedFiles.has(target)) {
|
|
2449
|
+
add({
|
|
2450
|
+
rule,
|
|
2451
|
+
line,
|
|
2452
|
+
message: `setup-${tool} must reference a tracked ${allowed.join(" or ")}`
|
|
2453
|
+
});
|
|
2454
|
+
return;
|
|
2455
|
+
}
|
|
2456
|
+
if (binding !== void 0 && (binding.sparse.mode === "invalid" || binding.sparse.mode === "files" && !binding.sparse.paths.has(target))) {
|
|
2457
|
+
add({
|
|
2458
|
+
rule,
|
|
2459
|
+
line,
|
|
2460
|
+
message: `checkout sparse-checkout must explicitly list ${target} without dynamic, glob, or negation patterns`
|
|
2461
|
+
});
|
|
2462
|
+
return;
|
|
2463
|
+
}
|
|
2464
|
+
if (binding?.source === "delegated") {
|
|
2465
|
+
onDelegated?.({
|
|
2466
|
+
path: file,
|
|
2467
|
+
line,
|
|
2468
|
+
tool,
|
|
2469
|
+
selector,
|
|
2470
|
+
checkoutPath: binding.path,
|
|
2471
|
+
ref: binding.ref
|
|
2472
|
+
});
|
|
2473
|
+
return;
|
|
2474
|
+
}
|
|
2475
|
+
const content = readFile(target);
|
|
2476
|
+
if (tool === "bun") {
|
|
2477
|
+
try {
|
|
2478
|
+
const manifest = JSON.parse(content ?? "");
|
|
2479
|
+
pin({
|
|
2480
|
+
rule,
|
|
2481
|
+
value: record$2(manifest) ? manifest["packageManager"] : void 0,
|
|
2482
|
+
expected: `bun@${policy.bun}`,
|
|
2483
|
+
label: "setup-bun version file packageManager",
|
|
2484
|
+
line
|
|
2485
|
+
});
|
|
2486
|
+
} catch {
|
|
2487
|
+
add({
|
|
2488
|
+
rule,
|
|
2489
|
+
line,
|
|
2490
|
+
message: "bun-version-file must reference a readable package.json object"
|
|
2491
|
+
});
|
|
2492
|
+
}
|
|
2493
|
+
return;
|
|
2494
|
+
}
|
|
2495
|
+
pin({
|
|
2496
|
+
rule,
|
|
2497
|
+
value: content?.trim(),
|
|
2498
|
+
expected: policy[tool],
|
|
2499
|
+
selector: tool === "node" ? "node" : void 0,
|
|
2500
|
+
label: `setup-${tool} version file`,
|
|
2501
|
+
line
|
|
2502
|
+
});
|
|
2503
|
+
};
|
|
2504
|
+
const resolveNode = (node) => {
|
|
2505
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2506
|
+
while (isAlias(node)) {
|
|
2507
|
+
if (visited.has(node)) throw new Error("cyclic YAML alias");
|
|
2508
|
+
visited.add(node);
|
|
2509
|
+
node = node.resolve(document);
|
|
2510
|
+
}
|
|
2511
|
+
return node;
|
|
2512
|
+
};
|
|
2513
|
+
const approvedActions = new Map(Object.entries(policy.actions).map(([action, approved]) => [action.toLowerCase(), approved]));
|
|
2514
|
+
const mergedMaps = (node) => {
|
|
2515
|
+
node = resolveNode(node);
|
|
2516
|
+
if (!isMap(node)) return [];
|
|
2517
|
+
const maps = [];
|
|
2518
|
+
for (const pair of node.items) {
|
|
2519
|
+
if (!isScalar(pair.key) || typeof pair.key.value !== "symbol" || pair.key.source !== "<<") continue;
|
|
2520
|
+
const merge = resolveNode(pair.value);
|
|
2521
|
+
maps.push(...isSeq(merge) ? merge.items : [merge]);
|
|
2522
|
+
}
|
|
2523
|
+
return maps;
|
|
2524
|
+
};
|
|
2525
|
+
const keysOf = (node, visited = /* @__PURE__ */ new Set()) => {
|
|
2526
|
+
node = resolveNode(node);
|
|
2527
|
+
if (!isMap(node)) return /* @__PURE__ */ new Set();
|
|
2528
|
+
if (visited.has(node)) throw new Error("cyclic YAML merge");
|
|
2529
|
+
const next = new Set(visited);
|
|
2530
|
+
next.add(node);
|
|
2531
|
+
const keys = new Set(node.items.flatMap((pair) => isScalar(pair.key) && typeof pair.key.value === "string" ? [pair.key.value] : []));
|
|
2532
|
+
for (const merged of mergedMaps(node)) for (const key of keysOf(merged, next)) keys.add(key);
|
|
2533
|
+
return keys;
|
|
2534
|
+
};
|
|
2535
|
+
const sourceMap = ({ node, key, visited = /* @__PURE__ */ new Set() }) => {
|
|
2536
|
+
node = resolveNode(node);
|
|
2537
|
+
if (!isMap(node)) return void 0;
|
|
2538
|
+
if (node.has(key)) return node;
|
|
2539
|
+
if (visited.has(node)) throw new Error("cyclic YAML merge");
|
|
2540
|
+
const next = new Set(visited);
|
|
2541
|
+
next.add(node);
|
|
2542
|
+
for (const merged of mergedMaps(node)) {
|
|
2543
|
+
const source = sourceMap({
|
|
2544
|
+
node: merged,
|
|
2545
|
+
key,
|
|
2546
|
+
visited: next
|
|
2547
|
+
});
|
|
2548
|
+
if (source !== void 0) return source;
|
|
2549
|
+
}
|
|
2550
|
+
};
|
|
2551
|
+
const getNode = (node, key) => {
|
|
2552
|
+
const source = sourceMap({
|
|
2553
|
+
node,
|
|
2554
|
+
key
|
|
2555
|
+
});
|
|
2556
|
+
return isMap(source) ? resolveNode(source.get(key, true)) : void 0;
|
|
2557
|
+
};
|
|
2558
|
+
const actionInputs = /* @__PURE__ */ new Map();
|
|
2559
|
+
const inputsOf = (node) => {
|
|
2560
|
+
node = resolveNode(node);
|
|
2561
|
+
const cached = actionInputs.get(node);
|
|
2562
|
+
if (cached !== void 0) return cached;
|
|
2563
|
+
const options = getNode(node, "with");
|
|
2564
|
+
const inputs = /* @__PURE__ */ new Map();
|
|
2565
|
+
for (const key of keysOf(options)) {
|
|
2566
|
+
const folded = key.toUpperCase();
|
|
2567
|
+
const value = getNode(options, key);
|
|
2568
|
+
if (inputs.has(folded)) add({
|
|
2569
|
+
rule: "action-pins",
|
|
2570
|
+
line: nodeLine(value),
|
|
2571
|
+
message: `action input ${key} collides after case-folding`
|
|
2572
|
+
});
|
|
2573
|
+
if (/(?:^|-)VERSION(?:-FILE)?$/.test(folded) && key !== folded.toLowerCase()) add({
|
|
2574
|
+
rule: "action-pins",
|
|
2575
|
+
line: nodeLine(value),
|
|
2576
|
+
message: `selector input ${key} must use canonical lowercase casing`
|
|
2577
|
+
});
|
|
2578
|
+
inputs.set(folded, value);
|
|
2579
|
+
}
|
|
2580
|
+
actionInputs.set(node, inputs);
|
|
2581
|
+
return inputs;
|
|
2582
|
+
};
|
|
2583
|
+
const getInput = (node, key) => inputsOf(node).get(key.toUpperCase());
|
|
2584
|
+
const dynamicRefBody = (value) => {
|
|
2585
|
+
if (typeof value !== "string" || !value.startsWith("${{")) return void 0;
|
|
2586
|
+
let quote;
|
|
2587
|
+
for (let index = 3; index < value.length; index++) {
|
|
2588
|
+
const character = value.at(index);
|
|
2589
|
+
if (quote !== void 0) {
|
|
2590
|
+
if (character === quote) if (quote === "'" && value.at(index + 1) === "'") index++;
|
|
2591
|
+
else quote = void 0;
|
|
2592
|
+
else if (quote === "\"" && character === "\\") index++;
|
|
2593
|
+
continue;
|
|
2594
|
+
}
|
|
2595
|
+
if (character === "'" || character === "\"") quote = character;
|
|
2596
|
+
else if (value.startsWith("${{", index)) return void 0;
|
|
2597
|
+
else if (character === "}" && value.at(index + 1) === "}") return index === value.length - 2 ? value.slice(3, index).trim() : void 0;
|
|
2598
|
+
}
|
|
2599
|
+
};
|
|
2600
|
+
const checkoutPrefixOf = (node) => {
|
|
2601
|
+
const destination = getInput(node, "path");
|
|
2602
|
+
if (destination === void 0) return ".";
|
|
2603
|
+
return isScalar(destination) ? destination.value : void 0;
|
|
2604
|
+
};
|
|
2605
|
+
const sparseCheckoutOf = (node) => {
|
|
2606
|
+
const sparseKeys = [...inputsOf(node).keys()].filter((key) => key.startsWith("SPARSE-CHECKOUT"));
|
|
2607
|
+
if (sparseKeys.length === 0) return { mode: "all" };
|
|
2608
|
+
if (sparseKeys.some((key) => key !== "SPARSE-CHECKOUT" && key !== "SPARSE-CHECKOUT-CONE-MODE")) return { mode: "invalid" };
|
|
2609
|
+
const value = getInput(node, "sparse-checkout");
|
|
2610
|
+
const cone = getInput(node, "sparse-checkout-cone-mode");
|
|
2611
|
+
if (!isScalar(value) || typeof value.value !== "string" || cone !== void 0 && (!isScalar(cone) || cone.value !== true && cone.value !== false && cone.value !== "true" && cone.value !== "false")) return { mode: "invalid" };
|
|
2612
|
+
const paths = value.value.split(/\r?\n/).map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
2613
|
+
if (paths.length === 0 || paths.some((entry) => !staticRepositoryPath(entry) || entry.startsWith("!") || /[*?[\]]/.test(entry))) return { mode: "invalid" };
|
|
2614
|
+
return {
|
|
2615
|
+
mode: "files",
|
|
2616
|
+
paths: new Set(paths)
|
|
2617
|
+
};
|
|
2618
|
+
};
|
|
2619
|
+
let currentEngineFloor;
|
|
2620
|
+
const checkAction = (node) => {
|
|
2621
|
+
node = resolveNode(node);
|
|
2622
|
+
if (!isMap(node)) return;
|
|
2623
|
+
inputsOf(node);
|
|
2624
|
+
const uses = getNode(node, "uses");
|
|
2625
|
+
if (uses === void 0) return;
|
|
2626
|
+
const line = nodeLine(uses);
|
|
2627
|
+
if (!isScalar(uses) || typeof uses.value !== "string") {
|
|
2628
|
+
add({
|
|
2629
|
+
rule: "action-pins",
|
|
2630
|
+
line,
|
|
2631
|
+
message: "action uses must be a string containing a full commit SHA"
|
|
2632
|
+
});
|
|
2633
|
+
return;
|
|
2634
|
+
}
|
|
2635
|
+
const value = uses.value;
|
|
2636
|
+
if (value.startsWith("$/")) {
|
|
2637
|
+
if (value.length === 2 || /\s/.test(value) || value.includes("@") || value.includes("${{") || value.includes("\\") || value.split("/").includes("..")) add({
|
|
2638
|
+
rule: "action-pins",
|
|
2639
|
+
line,
|
|
2640
|
+
message: "self-repository actions must use a static repository path without a ref suffix"
|
|
2641
|
+
});
|
|
2642
|
+
return;
|
|
2643
|
+
}
|
|
2644
|
+
if (value.startsWith("./")) {
|
|
2645
|
+
const selector = staticRepositoryPath(value) ? path.posix.normalize(value) : void 0;
|
|
2646
|
+
const binding = selector === void 0 ? void 0 : checkoutBindings.findLast((entry) => entry.path === "." || selector === entry.path || selector.startsWith(`${entry.path}/`));
|
|
2647
|
+
if (selector === void 0 || unknownCheckoutDestination || binding !== void 0 && binding.source !== "tracked" || [...checkoutDestinations].some(([prefix, count]) => count > 1 && (prefix === "." || selector === prefix || selector.startsWith(`${prefix}/`)))) add({
|
|
2648
|
+
rule: "action-pins",
|
|
2649
|
+
line,
|
|
2650
|
+
message: "local actions require an unambiguous checkout of the current source snapshot"
|
|
2651
|
+
});
|
|
2652
|
+
return;
|
|
2653
|
+
}
|
|
2654
|
+
if (value.startsWith("docker://")) {
|
|
2655
|
+
add({
|
|
2656
|
+
rule: "action-pins",
|
|
2657
|
+
line,
|
|
2658
|
+
message: "Docker image actions require a reasoned action-pins opt-out"
|
|
2659
|
+
});
|
|
2660
|
+
checkRuntimeImage({
|
|
2661
|
+
image: value.slice(9),
|
|
2662
|
+
line,
|
|
2663
|
+
label: "Docker action image"
|
|
2664
|
+
});
|
|
2665
|
+
return;
|
|
2666
|
+
}
|
|
2667
|
+
const remote = /^([^./][^\s@]*\/[^\s@]+)@([^\s]+)$/.exec(value);
|
|
2668
|
+
if (remote === null) {
|
|
2669
|
+
add({
|
|
2670
|
+
rule: "action-pins",
|
|
2671
|
+
line,
|
|
2672
|
+
message: "remote actions must use a full commit SHA"
|
|
2673
|
+
});
|
|
2674
|
+
return;
|
|
2675
|
+
}
|
|
2676
|
+
const action = remote[1]?.toLowerCase();
|
|
2677
|
+
const ref = remote[2];
|
|
2678
|
+
const approved = action === void 0 ? void 0 : approvedActions.get(action) ?? approvedActions.get(action.split("/").slice(0, 2).join("/"));
|
|
2679
|
+
if (ref === void 0 || !/^[a-f0-9]{40}$/.test(ref)) add({
|
|
2680
|
+
rule: "action-pins",
|
|
2681
|
+
line,
|
|
2682
|
+
message: "remote actions must use a full commit SHA"
|
|
2683
|
+
});
|
|
2684
|
+
else if (approved !== void 0 && ref !== approved.sha) add({
|
|
2685
|
+
rule: "action-pins",
|
|
2686
|
+
line,
|
|
2687
|
+
message: `${action} must use ${approved.sha}`
|
|
2688
|
+
});
|
|
2689
|
+
const declaration = sourceMap({
|
|
2690
|
+
node,
|
|
2691
|
+
key: "uses"
|
|
2692
|
+
});
|
|
2693
|
+
const comment = uses.comment ?? (isMap(declaration) ? declaration.comment : void 0) ?? "";
|
|
2694
|
+
if (approved !== void 0 && !comment.trim().split(/\s+/).includes(approved.version)) add({
|
|
2695
|
+
rule: "action-pins",
|
|
2696
|
+
line,
|
|
2697
|
+
message: `${action} requires a # ${approved.version} version comment`
|
|
2698
|
+
});
|
|
2699
|
+
if (action === "actions/checkout") {
|
|
2700
|
+
const checkoutRepository = getInput(node, "repository");
|
|
2701
|
+
const checkoutRef = getInput(node, "ref");
|
|
2702
|
+
const prefix = checkoutPrefixOf(node);
|
|
2703
|
+
let repo;
|
|
2704
|
+
if (checkoutRepository !== void 0) repo = isScalar(checkoutRepository) ? checkoutRepository.value : null;
|
|
2705
|
+
const self = repo === void 0 || repo === "${{ github.repository }}" || typeof repo === "string" && repository !== void 0 && repo.toLowerCase() === repository.toLowerCase();
|
|
2706
|
+
const workflowSource = repo === "${{ job.workflow_repository }}" && isScalar(checkoutRef) && checkoutRef.value === "${{ job.workflow_sha }}";
|
|
2707
|
+
const currentSource = self && checkoutRef === void 0;
|
|
2708
|
+
const refValue = isScalar(checkoutRef) ? checkoutRef.value : void 0;
|
|
2709
|
+
const dynamicRef = dynamicRefBody(refValue);
|
|
2710
|
+
const delegatedSource = (self || repo === "${{ job.workflow_repository }}") && dynamicRef !== void 0 && dynamicRef !== "" && !/^(?:'(?:[^']|'')*'|"(?:[^"\\]|\\.)*"|(?:true|false|null)|-?(?:0x[\da-f]+|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?))$/i.test(dynamicRef) && !/^(?:github\s*(?:\.\s*sha|\[\s*['"]sha['"]\s*\])|job\s*(?:\.\s*workflow_sha|\[\s*['"]workflow_sha['"]\s*\]))$/i.test(dynamicRef);
|
|
2711
|
+
if (!staticRepositoryPath(prefix)) checkoutBindings.push({
|
|
2712
|
+
path: ".",
|
|
2713
|
+
source: "untrusted",
|
|
2714
|
+
reason: "checkout destination must be a static repository path",
|
|
2715
|
+
line,
|
|
2716
|
+
sparse: { mode: "invalid" }
|
|
2717
|
+
});
|
|
2718
|
+
else {
|
|
2719
|
+
const destination = normalizeCheckoutPath(prefix);
|
|
2720
|
+
const trustedWriter = ref === approved?.sha && sourceMap({
|
|
2721
|
+
node,
|
|
2722
|
+
key: "if"
|
|
2723
|
+
}) === void 0 && sourceMap({
|
|
2724
|
+
node,
|
|
2725
|
+
key: "continue-on-error"
|
|
2726
|
+
}) === void 0 && checkoutDestinations.get(destination) === 1 && !unknownCheckoutDestination;
|
|
2727
|
+
if (trustedWriter && delegatedSource && typeof refValue === "string") checkoutBindings.push({
|
|
2728
|
+
path: destination,
|
|
2729
|
+
sparse: sparseCheckoutOf(node),
|
|
2730
|
+
source: "delegated",
|
|
2731
|
+
ref: refValue
|
|
2732
|
+
});
|
|
2733
|
+
else if (trustedWriter && (workflowSource || currentSource)) checkoutBindings.push({
|
|
2734
|
+
path: destination,
|
|
2735
|
+
sparse: sparseCheckoutOf(node),
|
|
2736
|
+
source: "tracked"
|
|
2737
|
+
});
|
|
2738
|
+
else {
|
|
2739
|
+
let reason = "checkout does not select a trusted repository source snapshot";
|
|
2740
|
+
if (ref !== approved?.sha) reason = "actions/checkout must use the approved action SHA";
|
|
2741
|
+
else if (sourceMap({
|
|
2742
|
+
node,
|
|
2743
|
+
key: "if"
|
|
2744
|
+
}) !== void 0 || sourceMap({
|
|
2745
|
+
node,
|
|
2746
|
+
key: "continue-on-error"
|
|
2747
|
+
}) !== void 0) reason = "checkout must be unconditional and omit continue-on-error";
|
|
2748
|
+
else if (checkoutDestinations.get(destination) !== 1 || unknownCheckoutDestination) reason = "checkout destination must have exactly one static writer";
|
|
2749
|
+
checkoutBindings.push({
|
|
2750
|
+
path: destination,
|
|
2751
|
+
sparse: sparseCheckoutOf(node),
|
|
2752
|
+
source: "untrusted",
|
|
2753
|
+
reason,
|
|
2754
|
+
line
|
|
2755
|
+
});
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
}
|
|
2759
|
+
let tool;
|
|
2760
|
+
switch (action) {
|
|
2761
|
+
case "actions/setup-node":
|
|
2762
|
+
tool = "node";
|
|
2763
|
+
break;
|
|
2764
|
+
case "actions/setup-python":
|
|
2765
|
+
tool = "python";
|
|
2766
|
+
break;
|
|
2767
|
+
case "oven-sh/setup-bun":
|
|
2768
|
+
tool = "bun";
|
|
2769
|
+
break;
|
|
2770
|
+
default: return;
|
|
2771
|
+
}
|
|
2772
|
+
const literal = getInput(node, `${tool}-version`);
|
|
2773
|
+
if (tool === "node" && currentEngineFloor !== void 0) {
|
|
2774
|
+
const reference = getInput(node, "node-version-file");
|
|
2775
|
+
if (reference === void 0 && isScalar(literal) && engineFloorSelectorMatches(literal.value, currentEngineFloor)) {
|
|
2776
|
+
onEngineFloor?.(currentEngineFloor, "matched");
|
|
2777
|
+
return;
|
|
2778
|
+
}
|
|
2779
|
+
onEngineFloor?.(currentEngineFloor, "mismatch");
|
|
2780
|
+
add({
|
|
2781
|
+
rule: "runtime-workflow",
|
|
2782
|
+
line: nodeLine(literal ?? reference ?? uses),
|
|
2783
|
+
message: `engine floor job must select an exact Node patch satisfying ${currentEngineFloor.range} with minimum major ${currentEngineFloor.major}`
|
|
2784
|
+
});
|
|
2785
|
+
return;
|
|
2786
|
+
}
|
|
2787
|
+
if (literal !== void 0) add({
|
|
2788
|
+
rule: tool === "bun" ? "bun-pins" : "runtime-workflow",
|
|
2789
|
+
line: nodeLine(literal),
|
|
2790
|
+
message: `setup-${tool} must use ${tool}-version-file`
|
|
2791
|
+
});
|
|
2792
|
+
const reference = getInput(node, `${tool}-version-file`);
|
|
2793
|
+
checkReference({
|
|
2794
|
+
value: isScalar(reference) ? reference.value : void 0,
|
|
2795
|
+
tool,
|
|
2796
|
+
line: reference === void 0 ? line : nodeLine(reference)
|
|
2797
|
+
});
|
|
2798
|
+
};
|
|
2799
|
+
const checkContainer = (node) => {
|
|
2800
|
+
node = resolveNode(node);
|
|
2801
|
+
if (node === void 0) return;
|
|
2802
|
+
const image = isMap(node) ? getNode(node, "image") : node;
|
|
2803
|
+
checkRuntimeImage({
|
|
2804
|
+
image: isScalar(image) ? image.value : void 0,
|
|
2805
|
+
line: nodeLine(image ?? node),
|
|
2806
|
+
label: "container image"
|
|
2807
|
+
});
|
|
2808
|
+
};
|
|
2809
|
+
const checkSteps = (node, floor) => {
|
|
2810
|
+
currentEngineFloor = void 0;
|
|
2811
|
+
checkoutBindings = [];
|
|
2812
|
+
checkoutDestinations = /* @__PURE__ */ new Map();
|
|
2813
|
+
unknownCheckoutDestination = false;
|
|
2814
|
+
node = resolveNode(node);
|
|
2815
|
+
if (!isSeq(node)) return;
|
|
2816
|
+
for (const step of node.items) {
|
|
2817
|
+
const uses = getNode(step, "uses");
|
|
2818
|
+
if (!isScalar(uses) || typeof uses.value !== "string" || !uses.value.toLowerCase().startsWith("actions/checkout@")) continue;
|
|
2819
|
+
const prefix = checkoutPrefixOf(step);
|
|
2820
|
+
if (!staticRepositoryPath(prefix)) {
|
|
2821
|
+
unknownCheckoutDestination = true;
|
|
2822
|
+
continue;
|
|
2823
|
+
}
|
|
2824
|
+
const destination = normalizeCheckoutPath(prefix);
|
|
2825
|
+
checkoutDestinations.set(destination, (checkoutDestinations.get(destination) ?? 0) + 1);
|
|
2826
|
+
}
|
|
2827
|
+
currentEngineFloor = floor;
|
|
2828
|
+
try {
|
|
2829
|
+
for (const step of node.items) checkAction(step);
|
|
2830
|
+
} finally {
|
|
2831
|
+
currentEngineFloor = void 0;
|
|
2832
|
+
}
|
|
2833
|
+
};
|
|
2834
|
+
try {
|
|
2835
|
+
document.toJS({ maxAliasCount: 100 });
|
|
2836
|
+
if (automationKind === "workflow") {
|
|
2837
|
+
const jobs = getNode(document.contents, "jobs");
|
|
2838
|
+
if (isMap(jobs)) for (const key of keysOf(jobs)) {
|
|
2839
|
+
checkoutBindings = [];
|
|
2840
|
+
checkoutDestinations = /* @__PURE__ */ new Map();
|
|
2841
|
+
unknownCheckoutDestination = false;
|
|
2842
|
+
currentEngineFloor = void 0;
|
|
2843
|
+
const job = getNode(jobs, key);
|
|
2844
|
+
checkAction(job);
|
|
2845
|
+
checkContainer(getNode(job, "container"));
|
|
2846
|
+
const services = getNode(job, "services");
|
|
2847
|
+
if (isMap(services)) for (const service of keysOf(services)) checkContainer(getNode(services, service));
|
|
2848
|
+
checkSteps(getNode(job, "steps"), engineFloors.find((entry) => entry.job === key));
|
|
2849
|
+
}
|
|
2850
|
+
} else {
|
|
2851
|
+
const runs = getNode(document.contents, "runs");
|
|
2852
|
+
const using = getNode(runs, "using");
|
|
2853
|
+
if (isScalar(using) && using.value === "composite") checkSteps(getNode(runs, "steps"));
|
|
2854
|
+
if (isScalar(using) && using.value === "docker") {
|
|
2855
|
+
const image = getNode(runs, "image");
|
|
2856
|
+
const value = isScalar(image) ? image.value : void 0;
|
|
2857
|
+
if (typeof value === "string" && value.startsWith("docker://")) {
|
|
2858
|
+
add({
|
|
2859
|
+
rule: "action-pins",
|
|
2860
|
+
line: nodeLine(image),
|
|
2861
|
+
message: "Docker image actions require a reasoned action-pins opt-out"
|
|
2862
|
+
});
|
|
2863
|
+
checkRuntimeImage({
|
|
2864
|
+
image: value.slice(9),
|
|
2865
|
+
line: nodeLine(image),
|
|
2866
|
+
label: "Docker action image"
|
|
2867
|
+
});
|
|
2868
|
+
} else if (typeof value !== "string" || value.includes("${{") || value.includes("\\") || value.includes(":") || path.posix.isAbsolute(value) || path.posix.normalize(path.posix.join(path.posix.dirname(file), value)).split("/").at(0) === ".." || path.posix.basename(value) !== "Dockerfile") add({
|
|
2869
|
+
rule: "action-pins",
|
|
2870
|
+
line: nodeLine(image),
|
|
2871
|
+
message: "Docker actions must reference a local Dockerfile or declare a reasoned action-pins opt-out for an external image"
|
|
2872
|
+
});
|
|
2873
|
+
}
|
|
2874
|
+
}
|
|
2875
|
+
} catch {
|
|
2876
|
+
add({
|
|
2877
|
+
rule: "runtime-workflow",
|
|
2878
|
+
line: 1,
|
|
2879
|
+
message: "cannot resolve workflow YAML aliases"
|
|
2880
|
+
});
|
|
2881
|
+
}
|
|
2882
|
+
return diagnostics;
|
|
2883
|
+
};
|
|
2884
|
+
//#endregion
|
|
2885
|
+
//#region src/toolchain-schema.ts
|
|
2886
|
+
const packagePinKeys = [
|
|
2887
|
+
"oxlint",
|
|
2888
|
+
"oxlint-tsgolint",
|
|
2889
|
+
"@oxlint/plugins",
|
|
2890
|
+
"@stll/oxlint-plugin",
|
|
2891
|
+
"oxfmt",
|
|
2892
|
+
"lefthook"
|
|
2893
|
+
];
|
|
2894
|
+
const valkeyArchitectures = ["amd64", "arm64"];
|
|
2895
|
+
const valkeyArtifactPackages = {
|
|
2896
|
+
server: "valkey-server",
|
|
2897
|
+
tools: "valkey-tools"
|
|
2898
|
+
};
|
|
2899
|
+
const record$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2900
|
+
const artifactRecord = (value, keys) => {
|
|
2901
|
+
if (!record$1(value) || Object.keys(value).some((key) => !keys.includes(key)) || keys.some((key) => !Object.hasOwn(value, key))) throw new Error("valkeyArtifacts requires complete, closed artifact objects");
|
|
2902
|
+
return value;
|
|
2903
|
+
};
|
|
2904
|
+
const parseValkeyArtifacts = (input, version) => {
|
|
2905
|
+
const architectures = artifactRecord(input, valkeyArchitectures);
|
|
2906
|
+
const line = version.split(".").slice(0, 2).join(".");
|
|
2907
|
+
const parseArchitecture = (architecture) => {
|
|
2908
|
+
const packages = artifactRecord(architectures[architecture], Object.keys(valkeyArtifactPackages));
|
|
2909
|
+
const parseArtifact = (kind) => {
|
|
2910
|
+
const artifact = artifactRecord(packages[kind], ["url", "sha256"]);
|
|
2911
|
+
const url = artifact["url"];
|
|
2912
|
+
const sha256 = artifact["sha256"];
|
|
2913
|
+
const expected = `https://download.valkey.io/packaging/valkey-${line}/deb/ubuntu2404/${architecture}/${valkeyArtifactPackages[kind]}_${version}-1.noble_${architecture}.deb`;
|
|
2914
|
+
if (typeof url !== "string" || url !== expected) throw new Error("valkeyArtifacts URL must select the exact official versioned Ubuntu artifact");
|
|
2915
|
+
if (typeof sha256 !== "string" || !/^[a-f0-9]{64}$/.test(sha256)) throw new Error("valkeyArtifacts requires a lowercase SHA256 pin");
|
|
2916
|
+
return {
|
|
2917
|
+
url,
|
|
2918
|
+
sha256
|
|
2919
|
+
};
|
|
2920
|
+
};
|
|
2921
|
+
return {
|
|
2922
|
+
server: parseArtifact("server"),
|
|
2923
|
+
tools: parseArtifact("tools")
|
|
2924
|
+
};
|
|
2925
|
+
};
|
|
2926
|
+
return {
|
|
2927
|
+
amd64: parseArchitecture("amd64"),
|
|
2928
|
+
arm64: parseArchitecture("arm64")
|
|
2929
|
+
};
|
|
2930
|
+
};
|
|
2931
|
+
/** Reject unsupported or incomplete installed policies before inspecting a consumer. */
|
|
2932
|
+
const parseToolchainPolicy = (input) => {
|
|
2933
|
+
if (!record$1(input) || input["schemaVersion"] !== 1) throw new Error("toolchain.json must use schemaVersion 1");
|
|
2934
|
+
const string = (object, key) => {
|
|
2935
|
+
const value = object[key];
|
|
2936
|
+
if (typeof value !== "string" || value.trim() === "") throw new Error(`toolchain.json requires a nonempty ${key}`);
|
|
2937
|
+
return value;
|
|
2938
|
+
};
|
|
2939
|
+
const packages = {};
|
|
2940
|
+
for (const key of packagePinKeys) packages[key] = string(input, key);
|
|
2941
|
+
const bun = string(input, "bun");
|
|
2942
|
+
const typescript = string(input, "typescript");
|
|
2943
|
+
const node = string(input, "node");
|
|
2944
|
+
const python = string(input, "python");
|
|
2945
|
+
const postgres = string(input, "postgres");
|
|
2946
|
+
const valkey = string(input, "valkey");
|
|
2947
|
+
const rust = string(input, "rust");
|
|
2948
|
+
const rustCompilerDevelopment = string(input, "rustCompilerDevelopment");
|
|
2949
|
+
for (const [name, value] of Object.entries({
|
|
2950
|
+
...packages,
|
|
2951
|
+
bun,
|
|
2952
|
+
typescript
|
|
2953
|
+
})) if (valid(value) !== value) throw new Error(`toolchain.json ${name} must be an exact release`);
|
|
2954
|
+
if (!/^[1-9]\d*$/.test(postgres) || !Number.isSafeInteger(Number(postgres))) throw new Error("PostgreSQL must be a canonical positive major");
|
|
2955
|
+
if (valid(valkey) !== valkey || !/^\d+\.\d+\.\d+$/.test(valkey)) throw new Error("Valkey must be an exact stable release");
|
|
2956
|
+
const valkeyArtifacts = parseValkeyArtifacts(input["valkeyArtifacts"], valkey);
|
|
2957
|
+
if (!nodePolicyValid(node)) throw new Error("Node must be a canonical major N.x series");
|
|
2958
|
+
if (!/^\d+\.\d+(?:\.\d+)?$/.test(python)) throw new Error("Python must be an exact minor or patch release");
|
|
2959
|
+
if (!/^\d+\.\d+\.\d+$/.test(rust)) throw new Error("Rust must be an exact stable release");
|
|
2960
|
+
if (!/^nightly-\d{4}-\d{2}-\d{2}$/.test(rustCompilerDevelopment)) throw new Error("Rust compiler development must be a dated nightly");
|
|
2961
|
+
const compatibility = input["typescript6Compatibility"];
|
|
2962
|
+
if (!record$1(compatibility)) throw new Error("missing TypeScript compatibility policy");
|
|
2963
|
+
const version = string(compatibility, "version");
|
|
2964
|
+
const packageAlias = string(compatibility, "packageAlias");
|
|
2965
|
+
if (valid(version) !== version) throw new Error("TypeScript compatibility must be an exact release");
|
|
2966
|
+
const layouts = input["typescriptInstallLayouts"];
|
|
2967
|
+
if (!Array.isArray(layouts) || layouts.length === 0) throw new Error("missing TypeScript install layouts");
|
|
2968
|
+
const typescriptInstallLayouts = layouts.map((layout) => {
|
|
2969
|
+
if (!record$1(layout)) throw new Error("invalid TypeScript install layout");
|
|
2970
|
+
const compilerPackage = string(layout, "compilerPackage");
|
|
2971
|
+
const compilerSpecifier = string(layout, "compilerSpecifier");
|
|
2972
|
+
const typecheckCommand = string(layout, "typecheckCommand");
|
|
2973
|
+
switch (layout["type"]) {
|
|
2974
|
+
case "direct":
|
|
2975
|
+
if (compilerSpecifier !== typescript || compilerPackage !== "typescript") throw new Error("direct TypeScript layout differs from shared version");
|
|
2976
|
+
return {
|
|
2977
|
+
type: "direct",
|
|
2978
|
+
compilerPackage,
|
|
2979
|
+
compilerSpecifier,
|
|
2980
|
+
typecheckCommand
|
|
2981
|
+
};
|
|
2982
|
+
case "split-compatibility": {
|
|
2983
|
+
const compatibilityPackage = string(layout, "compatibilityPackage");
|
|
2984
|
+
const compatibilitySpecifier = string(layout, "compatibilitySpecifier");
|
|
2985
|
+
if (compilerSpecifier !== `npm:typescript@${typescript}` || compatibilitySpecifier !== version) throw new Error("split TypeScript layout differs from shared versions");
|
|
2986
|
+
return {
|
|
2987
|
+
type: "split-compatibility",
|
|
2988
|
+
compilerPackage,
|
|
2989
|
+
compilerSpecifier,
|
|
2990
|
+
compatibilityPackage,
|
|
2991
|
+
compatibilitySpecifier,
|
|
2992
|
+
typecheckCommand
|
|
2993
|
+
};
|
|
2994
|
+
}
|
|
2995
|
+
default: throw new Error("unsupported TypeScript install layout");
|
|
2996
|
+
}
|
|
2997
|
+
});
|
|
2998
|
+
const actionsInput = input["actions"];
|
|
2999
|
+
if (!record$1(actionsInput) || Object.keys(actionsInput).length === 0) throw new Error("missing approved actions");
|
|
3000
|
+
const actions = {};
|
|
3001
|
+
for (const [name, action] of Object.entries(actionsInput)) {
|
|
3002
|
+
if (!record$1(action)) throw new Error(`invalid action policy: ${name}`);
|
|
3003
|
+
const sha = string(action, "sha");
|
|
3004
|
+
const actionVersion = string(action, "version");
|
|
3005
|
+
if (!/^[a-f0-9]{40}$/.test(sha) || !/^v\d+(?:\.\d+)*$/.test(actionVersion)) throw new Error(`invalid action SHA/version: ${name}`);
|
|
3006
|
+
actions[name] = {
|
|
3007
|
+
sha,
|
|
3008
|
+
version: actionVersion
|
|
3009
|
+
};
|
|
3010
|
+
}
|
|
3011
|
+
const dependabotInput = input["dependabot"];
|
|
3012
|
+
if (!record$1(dependabotInput) || !record$1(dependabotInput["schedule"]) || !record$1(dependabotInput["cooldown"]) || !record$1(dependabotInput["groups"])) throw new Error("missing Dependabot policy");
|
|
3013
|
+
const scheduleInput = dependabotInput["schedule"];
|
|
3014
|
+
const schedule = {
|
|
3015
|
+
interval: string(scheduleInput, "interval"),
|
|
3016
|
+
day: string(scheduleInput, "day"),
|
|
3017
|
+
time: string(scheduleInput, "time"),
|
|
3018
|
+
timezone: string(scheduleInput, "timezone")
|
|
3019
|
+
};
|
|
3020
|
+
const defaultDays = dependabotInput["cooldown"]["defaultDays"];
|
|
3021
|
+
if (typeof defaultDays !== "number" || !Number.isInteger(defaultDays) || defaultDays < 5) throw new Error("Dependabot cooldown must be at least five days");
|
|
3022
|
+
const strings = (value) => {
|
|
3023
|
+
if (!Array.isArray(value) || !value.every((entry) => typeof entry === "string")) throw new Error("Dependabot group values must be string arrays");
|
|
3024
|
+
return value;
|
|
3025
|
+
};
|
|
3026
|
+
const groups = {};
|
|
3027
|
+
for (const [name, group] of Object.entries(dependabotInput["groups"])) {
|
|
3028
|
+
if (!record$1(group)) throw new Error(`invalid Dependabot group: ${name}`);
|
|
3029
|
+
groups[name] = {
|
|
3030
|
+
patterns: strings(group["patterns"]),
|
|
3031
|
+
updateTypes: strings(group["updateTypes"])
|
|
3032
|
+
};
|
|
3033
|
+
}
|
|
3034
|
+
return {
|
|
3035
|
+
bun,
|
|
3036
|
+
typescript,
|
|
3037
|
+
node,
|
|
3038
|
+
postgres,
|
|
3039
|
+
valkey,
|
|
3040
|
+
valkeyArtifacts,
|
|
3041
|
+
python,
|
|
3042
|
+
rust,
|
|
3043
|
+
rustCompilerDevelopment,
|
|
3044
|
+
packages,
|
|
3045
|
+
actions,
|
|
3046
|
+
typescriptInstallLayouts,
|
|
3047
|
+
typescript6Compatibility: {
|
|
3048
|
+
version,
|
|
3049
|
+
packageAlias
|
|
3050
|
+
},
|
|
3051
|
+
dependabot: {
|
|
3052
|
+
schedule,
|
|
3053
|
+
cooldown: { defaultDays },
|
|
3054
|
+
groups,
|
|
3055
|
+
ignoredPackages: [.../* @__PURE__ */ new Set([
|
|
3056
|
+
...Object.keys(packages),
|
|
3057
|
+
...typescriptInstallLayouts.flatMap((layout) => layout.type === "direct" ? [layout.compilerPackage] : [layout.compilerPackage, layout.compatibilityPackage]),
|
|
3058
|
+
packageAlias,
|
|
3059
|
+
"bun-types"
|
|
3060
|
+
])],
|
|
3061
|
+
ignoredActions: Object.keys(actions),
|
|
3062
|
+
ignoredImages: [
|
|
3063
|
+
"node",
|
|
3064
|
+
"python",
|
|
3065
|
+
"oven/bun"
|
|
3066
|
+
]
|
|
3067
|
+
}
|
|
3068
|
+
};
|
|
3069
|
+
};
|
|
3070
|
+
//#endregion
|
|
3071
|
+
//#region src/toolchain-guard.ts
|
|
3072
|
+
const toolchainRules = [.../* @__PURE__ */ new Set([
|
|
3073
|
+
...packageRules,
|
|
3074
|
+
...runtimeRules,
|
|
3075
|
+
...dependabotRules,
|
|
3076
|
+
"cloud-setup-drift"
|
|
3077
|
+
])];
|
|
3078
|
+
const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3079
|
+
const array = (value) => Array.isArray(value);
|
|
3080
|
+
/** Repository-owned declarations are explicit; malformed decisions fail closed. */
|
|
3081
|
+
const parseToolchainConfiguration = (input) => {
|
|
3082
|
+
if (!record(input) || Object.keys(input).some((key) => key !== "optOuts" && key !== "cloud" && key !== "engineFloors") || input["optOuts"] !== void 0 && !array(input["optOuts"])) throw new Error("stll-toolchain.json accepts only optOuts, cloud and engineFloors declarations");
|
|
3083
|
+
const disabled = /* @__PURE__ */ new Set();
|
|
3084
|
+
const optOuts = input["optOuts"] ?? [];
|
|
3085
|
+
if (!array(optOuts)) throw new Error("optOuts must be an array");
|
|
3086
|
+
for (const entry of optOuts) {
|
|
3087
|
+
if (!record(entry) || Object.keys(entry).some((key) => key !== "rule" && key !== "reason") || typeof entry["rule"] !== "string" || !toolchainRules.some((rule) => rule === entry["rule"]) || typeof entry["reason"] !== "string" || entry["reason"].trim() === "" || disabled.has(entry["rule"])) throw new Error("each opt-out requires a unique known rule and a nonempty reason");
|
|
3088
|
+
if (entry["rule"] === "node-engine") throw new Error("node-engine cannot be opted out; engines.node must support the shared Node series");
|
|
3089
|
+
if (entry["rule"] === "cloud-setup-drift") throw new Error("cloud-setup-drift cannot be opted out; generated setup must match shared policy");
|
|
3090
|
+
disabled.add(entry["rule"]);
|
|
3091
|
+
}
|
|
3092
|
+
return {
|
|
3093
|
+
disabled,
|
|
3094
|
+
cloud: parseCloudSetup(input["cloud"]),
|
|
3095
|
+
engineFloors: parseEngineFloors(input["engineFloors"])
|
|
3096
|
+
};
|
|
3097
|
+
};
|
|
3098
|
+
/** Read one tracked configuration snapshot for guards and policy generation. */
|
|
3099
|
+
const readToolchainInputs = (root) => {
|
|
3100
|
+
const diagnostics = [];
|
|
3101
|
+
const tracked = execFileSync("git", [
|
|
3102
|
+
"ls-files",
|
|
3103
|
+
"-z",
|
|
3104
|
+
"--cached"
|
|
3105
|
+
], {
|
|
3106
|
+
cwd: root,
|
|
3107
|
+
encoding: "utf8"
|
|
3108
|
+
}).split("\0").filter((file) => file !== "");
|
|
3109
|
+
const files = {};
|
|
3110
|
+
const trackedFiles = new Set(tracked);
|
|
3111
|
+
const resolvedRoot = realpathSync(root);
|
|
3112
|
+
for (const file of tracked) {
|
|
3113
|
+
const kind = toolchainInputKind(file);
|
|
3114
|
+
if (kind === void 0) continue;
|
|
3115
|
+
if (kind === "presence") {
|
|
3116
|
+
files[file] = "";
|
|
3117
|
+
continue;
|
|
3118
|
+
}
|
|
3119
|
+
try {
|
|
3120
|
+
const resolvedFile = realpathSync(path.join(resolvedRoot, file));
|
|
3121
|
+
const relative = path.relative(resolvedRoot, resolvedFile);
|
|
3122
|
+
if (path.isAbsolute(relative) || relative.split(path.sep).at(0) === ".." || !trackedFiles.has(relative.split(path.sep).join("/"))) throw new Error("Configuration target is outside the tracked tree");
|
|
3123
|
+
files[file] = readFileSync(resolvedFile, "utf8");
|
|
3124
|
+
} catch {
|
|
3125
|
+
diagnostics.push({
|
|
3126
|
+
rule: "configuration",
|
|
3127
|
+
path: file,
|
|
3128
|
+
line: 1,
|
|
3129
|
+
message: "cannot read tracked configuration file"
|
|
3130
|
+
});
|
|
3131
|
+
}
|
|
3132
|
+
}
|
|
3133
|
+
return {
|
|
3134
|
+
files,
|
|
3135
|
+
trackedFiles,
|
|
3136
|
+
diagnostics
|
|
3137
|
+
};
|
|
3138
|
+
};
|
|
3139
|
+
const checkToolchain = ({ root, policy, onDelegated }) => {
|
|
3140
|
+
const { files, trackedFiles, diagnostics } = readToolchainInputs(root);
|
|
3141
|
+
let repository;
|
|
3142
|
+
try {
|
|
3143
|
+
const origin = execFileSync("git", [
|
|
3144
|
+
"remote",
|
|
3145
|
+
"get-url",
|
|
3146
|
+
"origin"
|
|
3147
|
+
], {
|
|
3148
|
+
cwd: root,
|
|
3149
|
+
encoding: "utf8",
|
|
3150
|
+
stdio: [
|
|
3151
|
+
"ignore",
|
|
3152
|
+
"pipe",
|
|
3153
|
+
"ignore"
|
|
3154
|
+
]
|
|
3155
|
+
}).trim();
|
|
3156
|
+
repository = /^(?:https?:\/\/github\.com\/|git@github\.com:|ssh:\/\/git@github\.com\/)([^/]+\/[^/]+?)(?:\.git)?\/?$/.exec(origin)?.[1];
|
|
3157
|
+
} catch {}
|
|
3158
|
+
let disabled = /* @__PURE__ */ new Set();
|
|
3159
|
+
let cloud;
|
|
3160
|
+
const engineFloors = [];
|
|
3161
|
+
if (files["stll-toolchain.json"] !== void 0) try {
|
|
3162
|
+
const configuration = parseToolchainConfiguration(JSON.parse(files["stll-toolchain.json"]));
|
|
3163
|
+
disabled = configuration.disabled;
|
|
3164
|
+
cloud = configuration.cloud;
|
|
3165
|
+
for (const entry of configuration.engineFloors) engineFloors.push(resolveEngineFloor(entry, files));
|
|
3166
|
+
} catch (error) {
|
|
3167
|
+
diagnostics.push({
|
|
3168
|
+
rule: "configuration",
|
|
3169
|
+
path: "stll-toolchain.json",
|
|
3170
|
+
line: 1,
|
|
3171
|
+
message: error instanceof Error ? error.message : String(error)
|
|
3172
|
+
});
|
|
3173
|
+
}
|
|
3174
|
+
const script = files[cloudSetupPath];
|
|
3175
|
+
if (cloud === void 0 && trackedFiles.has(".agents/cloud-setup.sh")) diagnostics.push({
|
|
3176
|
+
rule: "cloud-setup-drift",
|
|
3177
|
+
path: cloudSetupPath,
|
|
3178
|
+
line: 1,
|
|
3179
|
+
message: "cloud setup script requires an explicit cloud declaration in stll-toolchain.json"
|
|
3180
|
+
});
|
|
3181
|
+
if (cloud !== void 0) try {
|
|
3182
|
+
const nodeVersion = files[".node-version"];
|
|
3183
|
+
if (nodeVersion === void 0) throw new Error("cloud setup requires a tracked root .node-version with an exact stable release");
|
|
3184
|
+
if (script !== generateCloudSetup({
|
|
3185
|
+
policy,
|
|
3186
|
+
cloud,
|
|
3187
|
+
nodeVersion: nodeVersion.trim()
|
|
3188
|
+
})) diagnostics.push({
|
|
3189
|
+
rule: "cloud-setup-drift",
|
|
3190
|
+
path: cloudSetupPath,
|
|
3191
|
+
line: 1,
|
|
3192
|
+
message: "cloud setup script is missing or differs from shared policy; run stll-cloud-setup"
|
|
3193
|
+
});
|
|
3194
|
+
} catch (error) {
|
|
3195
|
+
diagnostics.push({
|
|
3196
|
+
rule: "cloud-setup-drift",
|
|
3197
|
+
path: cloudSetupPath,
|
|
3198
|
+
line: 1,
|
|
3199
|
+
message: error instanceof Error ? error.message : String(error)
|
|
3200
|
+
});
|
|
3201
|
+
}
|
|
3202
|
+
const exercisedFloors = /* @__PURE__ */ new Set();
|
|
3203
|
+
const mismatchedFloors = /* @__PURE__ */ new Set();
|
|
3204
|
+
diagnostics.push(...checkPackageFiles({
|
|
3205
|
+
files,
|
|
3206
|
+
policy
|
|
3207
|
+
}));
|
|
3208
|
+
for (const [file, text] of Object.entries(files)) diagnostics.push(...checkRuntimeFile({
|
|
3209
|
+
file,
|
|
3210
|
+
text,
|
|
3211
|
+
policy: {
|
|
3212
|
+
...policy,
|
|
3213
|
+
packages: {
|
|
3214
|
+
...policy.packages,
|
|
3215
|
+
typescript: policy.typescript
|
|
3216
|
+
}
|
|
3217
|
+
},
|
|
3218
|
+
trackedFiles,
|
|
3219
|
+
repository,
|
|
3220
|
+
onDelegated,
|
|
3221
|
+
engineFloors: engineFloors.filter((entry) => entry.workflow === file),
|
|
3222
|
+
onEngineFloor: (entry, status) => {
|
|
3223
|
+
if (status === "mismatch") mismatchedFloors.add(entry);
|
|
3224
|
+
else exercisedFloors.add(entry);
|
|
3225
|
+
},
|
|
3226
|
+
readFile: (target) => files[target]
|
|
3227
|
+
}));
|
|
3228
|
+
for (const entry of engineFloors) if (!exercisedFloors.has(entry) || mismatchedFloors.has(entry)) diagnostics.push({
|
|
3229
|
+
rule: "configuration",
|
|
3230
|
+
path: "stll-toolchain.json",
|
|
3231
|
+
line: 1,
|
|
3232
|
+
message: `engine floor ${entry.workflow}:${entry.job} requires a setup-node exact patch satisfying ${entry.package} engines.node minimum major ${entry.major}`
|
|
3233
|
+
});
|
|
3234
|
+
diagnostics.push(...checkDependabot({
|
|
3235
|
+
files,
|
|
3236
|
+
policy: policy.dependabot
|
|
3237
|
+
}));
|
|
3238
|
+
return diagnostics.filter((diagnostic) => !disabled.has(diagnostic.rule));
|
|
3239
|
+
};
|
|
3240
|
+
//#endregion
|
|
3241
|
+
export { cloudSetupPath as a, parseToolchainPolicy as i, parseToolchainConfiguration as n, generateCloudSetup as o, readToolchainInputs as r, checkToolchain as t };
|
|
3242
|
+
|
|
3243
|
+
//# sourceMappingURL=toolchain-guard.mjs.map
|