Skip to content

Commit b40f846

Browse files
authored
fix(release): keep survivor plugin repair hermetic (#120677)
1 parent 5ebbc3c commit b40f846

7 files changed

Lines changed: 318 additions & 46 deletions

File tree

‎scripts/e2e/lib/clawhub-fixture-server.cjs‎

Lines changed: 144 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// CommonJS fixture server for ClawHub package/install E2E scenarios.
2+
const { execFileSync } = require("node:child_process");
23
const crypto = require("node:crypto");
34
const fs = require("node:fs");
45
const http = require("node:http");
@@ -8,12 +9,150 @@ const { createRequire } = require("node:module");
89

910
const profile = process.argv[2];
1011
const portFile = process.argv[3];
12+
const artifactManifestFile = process.argv[4];
1113
const requireFromApp = createRequire(path.join(process.cwd(), "package.json"));
1214
const JSZip = requireFromApp("jszip");
1315
const tar = requireFromApp("tar");
1416
const packageName = "@openclaw/kitchen-sink";
1517
const pluginId = "openclaw-kitchen-sink-fixture";
1618

19+
function startPrepublishArtifactServer() {
20+
const manifest = JSON.parse(fs.readFileSync(artifactManifestFile, "utf8"));
21+
if (!Array.isArray(manifest.packages) || manifest.packages.length === 0) {
22+
throw new Error("prepublish artifact manifest must contain packages");
23+
}
24+
const artifacts = new Map(
25+
manifest.packages.map((entry) => {
26+
if (
27+
typeof entry.name !== "string" ||
28+
typeof entry.version !== "string" ||
29+
typeof entry.tarball !== "string" ||
30+
path.basename(entry.tarball) !== entry.tarball
31+
) {
32+
throw new Error("invalid prepublish artifact manifest entry");
33+
}
34+
const tarballPath = path.join(path.dirname(artifactManifestFile), entry.tarball);
35+
const archive = fs.readFileSync(tarballPath);
36+
const sha256 = crypto.createHash("sha256").update(archive).digest("hex");
37+
const packedPackage = JSON.parse(
38+
execFileSync("tar", ["-xOf", tarballPath, "package/package.json"], {
39+
encoding: "utf8",
40+
}),
41+
);
42+
const packedPlugin = JSON.parse(
43+
execFileSync("tar", ["-xOf", tarballPath, "package/openclaw.plugin.json"], {
44+
encoding: "utf8",
45+
}),
46+
);
47+
if (
48+
sha256 !== entry.sha256 ||
49+
packedPackage.name !== entry.name ||
50+
packedPackage.version !== entry.version ||
51+
typeof packedPlugin.id !== "string" ||
52+
packedPlugin.id.length === 0
53+
) {
54+
throw new Error(`prepublish artifact metadata mismatch for ${entry.name}`);
55+
}
56+
return [
57+
entry.name,
58+
{
59+
...entry,
60+
archive,
61+
runtimeId: packedPlugin.id,
62+
npmIntegrity: `sha512-${crypto.createHash("sha512").update(archive).digest("base64")}`,
63+
npmShasum: crypto.createHash("sha1").update(archive).digest("hex"),
64+
},
65+
];
66+
}),
67+
);
68+
const requestLog = [];
69+
const json = (response, value, status = 200) => {
70+
response.writeHead(status, { "content-type": "application/json" });
71+
response.end(`${JSON.stringify(value)}\n`);
72+
};
73+
const server = http.createServer((request, response) => {
74+
const url = new URL(request.url, "http://127.0.0.1");
75+
if (url.pathname === "/__fixture__/requests") {
76+
json(response, { requests: requestLog });
77+
return;
78+
}
79+
requestLog.push(`${request.method} ${url.pathname}${url.search}`);
80+
const match =
81+
/^\/api\/v1\/packages\/([^/]+)(?:\/versions\/([^/]+)(?:\/(artifact(?:\/download)?|security))?)?$/u.exec(
82+
url.pathname,
83+
);
84+
const entry = match ? artifacts.get(decodeURIComponent(match[1])) : undefined;
85+
if (request.method !== "GET" || !entry) {
86+
response.writeHead(request.method === "GET" ? 404 : 405);
87+
response.end(request.method === "GET" ? "not found" : "method not allowed");
88+
return;
89+
}
90+
const version = match[2] ? decodeURIComponent(match[2]) : undefined;
91+
if (version && version !== entry.version) {
92+
json(response, { error: "version not found" }, 404);
93+
return;
94+
}
95+
const packageRecord = {
96+
name: entry.name,
97+
family: "code-plugin",
98+
runtimeId: entry.runtimeId,
99+
};
100+
const artifact = {
101+
kind: "npm-pack",
102+
sha256: entry.sha256,
103+
npmIntegrity: entry.npmIntegrity,
104+
npmShasum: entry.npmShasum,
105+
};
106+
const versionRecord = {
107+
version: entry.version,
108+
artifact,
109+
};
110+
if (!version) {
111+
json(response, {
112+
package: {
113+
...packageRecord,
114+
channel: "official",
115+
isOfficial: true,
116+
latestVersion: entry.version,
117+
tags: { latest: entry.version, beta: entry.version },
118+
},
119+
});
120+
} else if (!match[3]) {
121+
json(response, { package: packageRecord, version: versionRecord });
122+
} else if (match[3] === "security") {
123+
json(response, {
124+
trust: {
125+
blockedFromDownload: false,
126+
reasons: [],
127+
pending: false,
128+
stale: false,
129+
},
130+
});
131+
} else if (match[3] === "artifact") {
132+
json(response, {
133+
version: versionRecord,
134+
artifact: {
135+
artifactKind: "npm-pack",
136+
artifactSha256: entry.sha256,
137+
npmIntegrity: entry.npmIntegrity,
138+
},
139+
});
140+
} else {
141+
response.writeHead(200, {
142+
"content-type": "application/octet-stream",
143+
"X-ClawHub-Artifact-Sha256": entry.sha256,
144+
"X-ClawHub-Npm-Integrity": entry.npmIntegrity,
145+
"X-ClawHub-Npm-Shasum": entry.npmShasum,
146+
"X-ClawHub-Npm-Tarball-Name": entry.tarball,
147+
});
148+
response.end(entry.archive);
149+
}
150+
});
151+
server.listen(0, "127.0.0.1", () => {
152+
fs.writeFileSync(portFile, String(server.address().port));
153+
});
154+
}
155+
17156
const buildArtifactSummary = ({
18157
clawpackSha256,
19158
clawpackSize,
@@ -440,8 +579,12 @@ profiles["catalog-search"] = {
440579

441580
const fixture = profiles[profile];
442581
if (!fixture || !portFile) {
582+
if (profile === "prepublish-artifacts" && portFile && artifactManifestFile) {
583+
startPrepublishArtifactServer();
584+
return;
585+
}
443586
console.error(
444-
"usage: clawhub-fixture-server.cjs <catalog-search|kitchen-sink-plugin|plugins> <port-file>",
587+
"usage: clawhub-fixture-server.cjs <catalog-search|kitchen-sink-plugin|plugins|prepublish-artifacts> <port-file> [manifest-file]",
445588
);
446589
process.exit(1);
447590
}

‎scripts/e2e/lib/upgrade-survivor/run.sh‎

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ FAILURE_PHASE=""
5757
FAILURE_MESSAGE=""
5858
gateway_pid=""
5959
plugin_registry_pid=""
60+
clawhub_fixture_pid=""
6061
baseline_spec=""
6162
baseline_version=""
6263
baseline_version_expected="0"
@@ -229,9 +230,6 @@ NODE
229230
}
230231

231232
cleanup() {
232-
if [ -n "${plugin_registry_pid:-}" ]; then
233-
kill "$plugin_registry_pid" >/dev/null 2>&1 || true
234-
fi
235233
if [ -s "$SYSTEMCTL_SHIM_PID_FILE" ]; then
236234
systemctl --user stop openclaw-gateway.service >/dev/null 2>&1 || true
237235
fi
@@ -243,6 +241,8 @@ cleanup() {
243241
openclaw_e2e_terminate_gateways "$shim_pid"
244242
fi
245243
fi
244+
openclaw_e2e_stop_process "${plugin_registry_pid:-}"
245+
openclaw_e2e_stop_process "${clawhub_fixture_pid:-}"
246246
}
247247

248248
on_error() {
@@ -373,6 +373,33 @@ TS
373373
echo "Seeded source-only plugin shadow: $shadow_root"
374374
}
375375

376+
wait_for_fixture_port() {
377+
local pid="$1" port_file="$2" log_file="$3" label="$4"
378+
for _ in $(seq 1 100); do
379+
[ -s "$port_file" ] && return 0
380+
openclaw_e2e_process_alive "$pid" || break
381+
sleep 0.1
382+
done
383+
openclaw_e2e_print_log "$log_file" >&2
384+
echo "Timed out waiting for upgrade survivor $label." >&2
385+
return 1
386+
}
387+
388+
configure_clawhub_fixture() {
389+
unset OPENCLAW_CLAWHUB_URL CLAWHUB_URL
390+
[ -z "${OPENCLAW_PREPUBLISH_PLUGIN_REGISTRY_DIR:-}" ] && return 0
391+
local fixture_root="$ARTIFACT_ROOT/clawhub-fixture" port_file log_file
392+
port_file="$fixture_root/port"
393+
log_file="$fixture_root/server.log"
394+
mkdir -p "$fixture_root"
395+
node "${OPENCLAW_UPGRADE_SURVIVOR_CLAWHUB_FIXTURE_SERVER:-scripts/e2e/lib/clawhub-fixture-server.cjs}" \
396+
prepublish-artifacts "$port_file" \
397+
"$OPENCLAW_PREPUBLISH_PLUGIN_REGISTRY_DIR/prepublish-plugin-registry.json" >"$log_file" 2>&1 &
398+
clawhub_fixture_pid="$!"
399+
wait_for_fixture_port "$clawhub_fixture_pid" "$port_file" "$log_file" "ClawHub fixture"
400+
export OPENCLAW_CLAWHUB_URL="http://127.0.0.1:$(cat "$port_file")"
401+
}
402+
376403
configure_plugin_registry() {
377404
local fixture_root="$ARTIFACT_ROOT/plugin-registry"
378405
local package_dir="$fixture_root/package"
@@ -482,22 +509,9 @@ NODE
482509
>"$log_file" 2>&1 &
483510
plugin_registry_pid="$!"
484511

485-
for _ in $(seq 1 100); do
486-
if [ -s "$port_file" ]; then
487-
export NPM_CONFIG_REGISTRY="http://127.0.0.1:$(cat "$port_file")"
488-
export npm_config_registry="$NPM_CONFIG_REGISTRY"
489-
return 0
490-
fi
491-
if ! kill -0 "$plugin_registry_pid" 2>/dev/null; then
492-
openclaw_e2e_print_log "$log_file" >&2
493-
return 1
494-
fi
495-
sleep 0.1
496-
done
497-
498-
openclaw_e2e_print_log "$log_file" >&2
499-
echo "Timed out waiting for upgrade survivor npm registry." >&2
500-
return 1
512+
wait_for_fixture_port "$plugin_registry_pid" "$port_file" "$log_file" "npm registry"
513+
export NPM_CONFIG_REGISTRY="http://127.0.0.1:$(cat "$port_file")"
514+
export npm_config_registry="$NPM_CONFIG_REGISTRY"
501515
}
502516

503517
legacy_plugin_dependency_probe_paths() {
@@ -1462,8 +1476,11 @@ phase assert-baseline assert_baseline_state
14621476
phase seed-legacy-runtime-deps-symlink seed_legacy_runtime_deps_symlink
14631477
phase resolve-candidate resolve_candidate_version
14641478
phase prepare-update-restart-probe prepare_update_restart_probe
1479+
phase configure-clawhub-fixture configure_clawhub_fixture
14651480
phase configure-plugin-registry configure_plugin_registry
14661481
phase update-candidate update_candidate
1482+
[ -z "${OPENCLAW_CLAWHUB_URL:-}" ] || CLAWHUB_EXPECTED_VERSION="$candidate_version" \
1483+
node -e 'const n="@openclaw/whatsapp",v=encodeURIComponent(process.env.CLAWHUB_EXPECTED_VERSION),p=`/api/v1/packages/${encodeURIComponent(n)}`,expected=[`GET ${p}`,`GET ${p}/versions/${v}/artifact`,`GET ${p}/versions/${v}/security`,`GET ${p}/versions/${v}/artifact/download`];fetch(`${process.env.OPENCLAW_CLAWHUB_URL}/__fixture__/requests`).then((response)=>response.json()).then(({requests})=>{if(JSON.stringify(requests)!==JSON.stringify(expected))throw new Error(`unexpected ClawHub fixture requests: ${JSON.stringify(requests)}`)})'
14671484
phase root-managed-vps-cli-usable assert_root_managed_vps_cli_usable
14681485
phase assert-legacy-plugin-dependency-debris-before-doctor assert_legacy_plugin_dependency_debris_before_doctor
14691486
phase doctor run_doctor

‎scripts/e2e/upgrade-survivor-docker.sh‎

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ if [ "${OPENCLAW_UPGRADE_SURVIVOR_PUBLISHED_BASELINE:-0}" = "1" ]; then
176176
-e OPENCLAW_UPGRADE_SURVIVOR_SUMMARY_JSON=/tmp/openclaw-upgrade-survivor-artifacts/summary.json \
177177
-e OPENCLAW_UPGRADE_SURVIVOR_START_BUDGET_SECONDS="$START_BUDGET_SECONDS" \
178178
-e OPENCLAW_UPGRADE_SURVIVOR_STATUS_BUDGET_SECONDS="$STATUS_BUDGET_SECONDS" \
179+
-e OPENCLAW_UPGRADE_SURVIVOR_CLAWHUB_FIXTURE_SERVER=/tmp/openclaw-clawhub-fixture-server.cjs \
179180
"${PROBE_ENV_ARGS[@]}" \
180181
-v "$ARTIFACT_DIR:/tmp/openclaw-upgrade-survivor-artifacts" \
182+
-v "$HARNESS_ROOT_DIR/scripts/e2e/lib/clawhub-fixture-server.cjs:/tmp/openclaw-clawhub-fixture-server.cjs:ro" \
181183
-v "$HARNESS_ROOT_DIR/scripts/e2e/lib/upgrade-survivor/run.sh:/tmp/openclaw-upgrade-survivor-run.sh:ro" \
182184
"${PREPUBLISH_PLUGIN_REGISTRY_ARGS[@]}" \
183185
"${DOCKER_E2E_PACKAGE_ARGS[@]}" \
@@ -206,8 +208,10 @@ docker_e2e_run_with_harness \
206208
-e OPENCLAW_UPGRADE_SURVIVOR_COMMAND_TIMEOUT="$COMMAND_TIMEOUT" \
207209
-e OPENCLAW_UPGRADE_SURVIVOR_START_BUDGET_SECONDS="$START_BUDGET_SECONDS" \
208210
-e OPENCLAW_UPGRADE_SURVIVOR_STATUS_BUDGET_SECONDS="$STATUS_BUDGET_SECONDS" \
211+
-e OPENCLAW_UPGRADE_SURVIVOR_CLAWHUB_FIXTURE_SERVER=/tmp/openclaw-clawhub-fixture-server.cjs \
209212
"${PROBE_ENV_ARGS[@]}" \
210213
-v "$ARTIFACT_DIR:/tmp/openclaw-upgrade-survivor-artifacts" \
214+
-v "$HARNESS_ROOT_DIR/scripts/e2e/lib/clawhub-fixture-server.cjs:/tmp/openclaw-clawhub-fixture-server.cjs:ro" \
211215
"${PREPUBLISH_PLUGIN_REGISTRY_ARGS[@]}" \
212216
"${DOCKER_E2E_PACKAGE_ARGS[@]}" \
213217
"${DOCKER_RUN_USER_ARGS[@]}" \
@@ -265,20 +269,47 @@ export OPENCLAW_UPGRADE_SURVIVOR_BASELINE_SERVICE_INSTALL_ERR="$BASELINE_SERVICE
265269
266270
gateway_pid=""
267271
plugin_registry_pid=""
272+
clawhub_fixture_pid=""
268273
cleanup() {
269-
if [ -n "${plugin_registry_pid:-}" ]; then
270-
kill "$plugin_registry_pid" >/dev/null 2>&1 || true
271-
fi
272274
if [ -s "$SYSTEMCTL_SHIM_PID_FILE" ]; then
273275
systemctl --user stop openclaw-gateway.service >/dev/null 2>&1 || true
274276
fi
275277
openclaw_e2e_terminate_gateways "${gateway_pid:-}"
276278
if [ -s "$SYSTEMCTL_SHIM_PID_FILE" ]; then
277279
openclaw_e2e_terminate_gateways "$(cat "$SYSTEMCTL_SHIM_PID_FILE" 2>/dev/null || true)"
278280
fi
281+
openclaw_e2e_stop_process "${plugin_registry_pid:-}"
282+
openclaw_e2e_stop_process "${clawhub_fixture_pid:-}"
279283
}
280284
trap cleanup EXIT
281285
286+
wait_for_fixture_port() {
287+
local pid="$1" port_file="$2" log_file="$3" label="$4"
288+
for _ in $(seq 1 100); do
289+
[ -s "$port_file" ] && return 0
290+
openclaw_e2e_process_alive "$pid" || break
291+
sleep 0.1
292+
done
293+
openclaw_e2e_print_log "$log_file" >&2
294+
echo "Timed out waiting for upgrade survivor $label." >&2
295+
return 1
296+
}
297+
298+
configure_clawhub_fixture() {
299+
unset OPENCLAW_CLAWHUB_URL CLAWHUB_URL
300+
[ -z "${OPENCLAW_PREPUBLISH_PLUGIN_REGISTRY_DIR:-}" ] && return 0
301+
local fixture_root="$OPENCLAW_UPGRADE_SURVIVOR_ARTIFACT_ROOT/clawhub-fixture" port_file log_file
302+
port_file="$fixture_root/port"
303+
log_file="$fixture_root/server.log"
304+
mkdir -p "$fixture_root"
305+
node "$OPENCLAW_UPGRADE_SURVIVOR_CLAWHUB_FIXTURE_SERVER" \
306+
prepublish-artifacts "$port_file" \
307+
"$OPENCLAW_PREPUBLISH_PLUGIN_REGISTRY_DIR/prepublish-plugin-registry.json" >"$log_file" 2>&1 &
308+
clawhub_fixture_pid="$!"
309+
wait_for_fixture_port "$clawhub_fixture_pid" "$port_file" "$log_file" "ClawHub fixture"
310+
export OPENCLAW_CLAWHUB_URL="http://127.0.0.1:$(cat "$port_file")"
311+
}
312+
282313
configure_plugin_registry() {
283314
local fixture_root="$OPENCLAW_UPGRADE_SURVIVOR_ARTIFACT_ROOT/plugin-registry"
284315
local package_dir="$fixture_root/package"
@@ -388,22 +419,9 @@ NODE
388419
>"$log_file" 2>&1 &
389420
plugin_registry_pid="$!"
390421
391-
for _ in $(seq 1 100); do
392-
if [ -s "$port_file" ]; then
393-
export NPM_CONFIG_REGISTRY="http://127.0.0.1:$(cat "$port_file")"
394-
export npm_config_registry="$NPM_CONFIG_REGISTRY"
395-
return 0
396-
fi
397-
if ! kill -0 "$plugin_registry_pid" 2>/dev/null; then
398-
openclaw_e2e_print_log "$log_file" >&2
399-
return 1
400-
fi
401-
sleep 0.1
402-
done
403-
404-
openclaw_e2e_print_log "$log_file" >&2
405-
echo "Timed out waiting for upgrade survivor npm registry." >&2
406-
return 1
422+
wait_for_fixture_port "$plugin_registry_pid" "$port_file" "$log_file" "npm registry"
423+
export NPM_CONFIG_REGISTRY="http://127.0.0.1:$(cat "$port_file")"
424+
export npm_config_registry="$NPM_CONFIG_REGISTRY"
407425
}
408426
409427
openclaw_e2e_eval_test_state_from_b64 "${OPENCLAW_TEST_STATE_SCRIPT_B64:?missing OPENCLAW_TEST_STATE_SCRIPT_B64}"
@@ -426,6 +444,7 @@ if [ "$UPDATE_RESTART_MODE" = "auto-auth" ]; then
426444
prepare_update_restart_probe_current_install "$PORT" "$GATEWAY_LOG"
427445
fi
428446
447+
configure_clawhub_fixture
429448
configure_plugin_registry
430449
echo "Running package update against the mounted tarball..."
431450
update_args=(update --tag "${OPENCLAW_CURRENT_PACKAGE_TGZ:?missing OPENCLAW_CURRENT_PACKAGE_TGZ}" --yes --json)
@@ -442,6 +461,8 @@ if [ "$update_status" -ne 0 ]; then
442461
openclaw_e2e_print_log /tmp/openclaw-upgrade-survivor-update.json >&2
443462
exit "$update_status"
444463
fi
464+
[ -z "${OPENCLAW_CLAWHUB_URL:-}" ] || CLAWHUB_EXPECTED_VERSION="$package_version" \
465+
node -e 'const n="@openclaw/whatsapp",v=encodeURIComponent(process.env.CLAWHUB_EXPECTED_VERSION),p=`/api/v1/packages/${encodeURIComponent(n)}`,expected=[`GET ${p}`,`GET ${p}/versions/${v}/artifact`,`GET ${p}/versions/${v}/security`,`GET ${p}/versions/${v}/artifact/download`];fetch(`${process.env.OPENCLAW_CLAWHUB_URL}/__fixture__/requests`).then((response)=>response.json()).then(({requests})=>{if(JSON.stringify(requests)!==JSON.stringify(expected))throw new Error(`unexpected ClawHub fixture requests: ${JSON.stringify(requests)}`)})'
445466
446467
if [ "$UPDATE_RESTART_MODE" = "auto-auth" ]; then
447468
echo "Skipping doctor repair until after restart proof."

‎scripts/lib/docker-e2e-plan.mjs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,6 @@ export function requiredPrepublishPluginPackagesForLanes(poolLanes) {
698698
return (
699699
typeof entry.name === "string" &&
700700
configuredChannelIds.has(channelId) &&
701-
install?.defaultChoice === "npm" &&
702701
install?.npmSpec === entry.name
703702
);
704703
})

0 commit comments

Comments
 (0)