Skip to content

Commit d0c8f02

Browse files
authored
test(e2e): preserve offline upgrade fixtures and restart proof (#134442)
* fix: align release fixtures with migration and baseline contracts * fix: bootstrap survivor services before seeding legacy state * fix: keep survivor bootstrap state owned by the baseline Use the managed service token rather than synthetic legacy device files, and keep fixture reload disabled until the updater owns restart. * fix: report survivor service load state through its unit owner * test(e2e): include service manager in diagnostics fixture Keep the isolated systemctl observation fixture complete and use its own HOME with a parseable unit while retaining child-exit and redaction checks. * test(e2e): keep survivor migration setup offline Stop the authenticated baseline through its service owner before seeding legacy migration specimens. Start the repaired installed unit and verify strict readiness and authenticated RPC before the candidate updater captures the live service that its restart must replace.
1 parent 508858d commit d0c8f02

16 files changed

Lines changed: 367 additions & 128 deletions

‎scripts/e2e/lib/upgrade-survivor/assertions.mjs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ function seedState() {
376376
if (scenario === "meeting-transcripts-sqlite") {
377377
seedLegacyMeetingTranscripts(stateDir);
378378
}
379+
if (scenario === "cron-scheduled-authority") {
380+
seedLegacyCronScheduledAuthority(stateDir);
381+
}
379382
if (scenario === "auth-profile-v2026-7-2-beta-5") {
380383
const fixture = readJson(
381384
path.join(
@@ -1530,9 +1533,6 @@ if (command === "list-scenarios") {
15301533
process.stdout.write(`${JSON.stringify([...SCENARIOS])}\n`);
15311534
} else if (command === "seed") {
15321535
seedState();
1533-
} else if (command === "seed-cron") {
1534-
assert(getScenario() === "cron-scheduled-authority", "seed-cron requires the cron scenario");
1535-
seedLegacyCronScheduledAuthority(requireEnv("OPENCLAW_STATE_DIR"));
15361536
} else if (command === "seed-volume") {
15371537
assert(getScenario() === "sqlite-volume", "seed-volume requires the sqlite-volume scenario");
15381538
const stateDir = requireEnv("OPENCLAW_STATE_DIR");

‎scripts/e2e/lib/upgrade-survivor/config-recipe/gateway.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"mode": "local",
33
"port": 18789,
44
"bind": "loopback",
5+
"reload": {
6+
"mode": "off"
7+
},
58
"auth": {
69
"mode": "token",
710
"token": {

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

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ SYSTEMCTL_SHIM_LOG="$ARTIFACT_ROOT/systemctl-shim.log"
128128
SYSTEMCTL_SHIM_PID_FILE="$ARTIFACT_ROOT/systemctl-shim.pid"
129129
SYSTEMCTL_SHIM_DAEMON_LOG="$ARTIFACT_ROOT/systemctl-shim-gateway.log"
130130
CONFIG_COVERAGE_JSON="$ARTIFACT_ROOT/config-recipe.json"
131-
RESTART_AUTHORED_CONFIG="$RUNTIME_ROOT/restart-authored-openclaw.json"
132131
export OPENCLAW_UPGRADE_SURVIVOR_CONFIG_COVERAGE_JSON="$CONFIG_COVERAGE_JSON"
133132
rm -f "$SUMMARY_JSON" "$CONFIG_COVERAGE_JSON"
134133
: >"$PHASE_LOG"
@@ -483,24 +482,12 @@ configure_clawhub_fixture() {
483482
export OPENCLAW_CLAWHUB_URL="http://127.0.0.1:$(cat "$port_file")"
484483
}
485484

486-
park_update_restart_authored_config() {
487-
# Establish only the authenticated service target. The candidate update must
488-
# receive the untouched migration specimen and own plugin consent/convergence.
489-
node "${OPENCLAW_UPGRADE_SURVIVOR_CONFIG_PARKING_HELPER:-scripts/e2e/lib/upgrade-survivor/config-parking.mjs}" \
490-
park-restart-probe "$OPENCLAW_CONFIG_PATH" "$RESTART_AUTHORED_CONFIG" 18789
491-
}
492-
493485
assert_prepublish_fixture_idle() {
494486
[ -n "${OPENCLAW_PREPUBLISH_PLUGIN_REGISTRY_DIR:-}" ] || return 0
495487
node "${OPENCLAW_UPGRADE_SURVIVOR_CLAWHUB_FIXTURE_SERVER:-scripts/e2e/lib/clawhub-fixture-server.cjs}" \
496488
assert-no-requests "$OPENCLAW_CLAWHUB_URL"
497489
}
498490

499-
restore_update_restart_authored_config() {
500-
node "${OPENCLAW_UPGRADE_SURVIVOR_CONFIG_PARKING_HELPER:-scripts/e2e/lib/upgrade-survivor/config-parking.mjs}" \
501-
restore "$OPENCLAW_CONFIG_PATH" "$RESTART_AUTHORED_CONFIG"
502-
}
503-
504491
configure_plugin_registry() {
505492
local fixture_root="$ARTIFACT_ROOT/plugin-registry"
506493
local package_dir="$fixture_root/package"
@@ -846,6 +833,10 @@ initialize_state() {
846833
export OPENCLAW_UPGRADE_SURVIVOR_BASELINE_VERSION="$baseline_version"
847834
}
848835

836+
seed_state() {
837+
node scripts/e2e/lib/upgrade-survivor/assertions.mjs seed
838+
}
839+
849840
apply_baseline_config_recipe() {
850841
local tsx_import="${OPENCLAW_UPGRADE_SURVIVOR_TSX_IMPORT:-tsx}"
851842
local recipe_runner=(
@@ -898,37 +889,37 @@ prepare_update_restart_probe() {
898889
fi
899890
echo "Preparing configured-auth gateway for automatic update restart."
900891
install_update_restart_systemctl_shim
901-
seed_update_restart_probe_device_auth
902-
local probe_status=0
903-
local doctor_log="${SYSTEMCTL_SHIM_DAEMON_LOG}.doctor"
904-
park_update_restart_authored_config || probe_status=$?
905-
if [ "$probe_status" -eq 0 ]; then
906-
migrate_update_restart_probe_device_auth "$doctor_log" "$COMMAND_TIMEOUT" || {
907-
probe_status=$?
908-
echo "baseline probe device identity migration failed" >&2
909-
openclaw_e2e_print_log "$doctor_log" >&2
910-
}
911-
fi
892+
local probe_status=0 restore_status=0
893+
local authored_config="$RUNTIME_ROOT/baseline-authored-openclaw.json"
894+
local parking_helper="${OPENCLAW_UPGRADE_SURVIVOR_CONFIG_PARKING_HELPER:-scripts/e2e/lib/upgrade-survivor/config-parking.mjs}"
895+
# Bootstrap only service auth; authored plugins must reach the actual updater unchanged.
896+
# The canonical path stays installed in the unit, with reload off until update owns restart.
897+
node "$parking_helper" \
898+
park-restart-probe "$OPENCLAW_CONFIG_PATH" "$authored_config" 18789 || probe_status=$?
912899
if [ "$probe_status" -eq 0 ]; then
913900
write_update_restart_service_env || probe_status=$?
914901
fi
915902
if [ "$probe_status" -eq 0 ]; then
916903
run_update_restart_probe_gateway install 18789 "$COMMAND_TIMEOUT" legacy-ready-log-ok || probe_status=$?
917904
fi
905+
if [ "$probe_status" -eq 0 ]; then
906+
local STATUS_JSON="$ARTIFACT_ROOT/baseline-status.json" STATUS_ERR="$ARTIFACT_ROOT/baseline-status.err"
907+
check_gateway_status || probe_status=$?
908+
fi
918909
if [ "$probe_status" -eq 0 ]; then
919910
assert_prepublish_fixture_idle || probe_status=$?
920911
fi
921-
# Restoring authored reload settings can restart the baseline immediately.
922-
# Keep it offline through specimen seeding, migration, and explicit plugin consent.
912+
# The installed baseline must be offline before restoring authored config or seeding state.
923913
stop_update_restart_probe_gateway "$COMMAND_TIMEOUT" || return "$?"
924-
local restore_status=0
925-
restore_update_restart_authored_config || restore_status=$?
926-
if [ "$probe_status" -ne 0 ]; then
927-
return "$probe_status"
914+
if [ -e "$authored_config" ]; then
915+
node "$parking_helper" restore "$OPENCLAW_CONFIG_PATH" "$authored_config" || restore_status=$?
928916
fi
929917
if [ "$restore_status" -ne 0 ]; then
930918
return "$restore_status"
931919
fi
920+
if [ "$probe_status" -ne 0 ]; then
921+
return "$probe_status"
922+
fi
932923
}
933924

934925
assert_baseline_state() {
@@ -1124,6 +1115,10 @@ repair_fixture_plugin_consent() {
11241115
phase prepare-recovery-service run_update_restart_probe_gateway start 18789 "$COMMAND_TIMEOUT"
11251116
local preparation_status=$?
11261117
[ "$preparation_status" -eq 0 ] || return "$preparation_status"
1118+
local STATUS_JSON="$ARTIFACT_ROOT/prepared-status.json" STATUS_ERR="$ARTIFACT_ROOT/prepared-status.err"
1119+
phase prepared-gateway-auth check_gateway_status
1120+
local auth_status=$?
1121+
[ "$auth_status" -eq 0 ] || return "$auth_status"
11271122
phase recovery-update-restart update_candidate 1
11281123
local recovery_status=$?
11291124
[ "$recovery_status" -eq 0 ] || return "$recovery_status"
@@ -1308,12 +1303,7 @@ phase configure-clawhub-fixture configure_clawhub_fixture
13081303
phase prepare-update-restart-probe prepare_update_restart_probe
13091304
# Start the published baseline before adding migration specimens: its startup
13101305
# guards correctly reject them, and baseline Doctor would consume candidate proof.
1311-
phase seed-migration-state node scripts/e2e/lib/upgrade-survivor/assertions.mjs seed
1312-
if [ "$SCENARIO" = "cron-scheduled-authority" ]; then
1313-
# Baseline roster writes must precede ownerless migration specimens: the
1314-
# published CLI correctly refuses topology changes while those jobs exist.
1315-
phase seed-cron-state node scripts/e2e/lib/upgrade-survivor/assertions.mjs seed-cron
1316-
fi
1306+
phase seed-state seed_state
13171307
phase install-baseline-plugin-dependencies install_baseline_plugin_dependencies
13181308
phase seed-legacy-plugin-dependency-debris seed_legacy_plugin_dependency_debris
13191309
phase assert-legacy-plugin-dependency-debris assert_legacy_plugin_dependency_debris_present

‎scripts/e2e/lib/upgrade-survivor/update-restart-auth.sh‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,10 @@ stop_update_restart_probe_gateway() {
506506
if [ "$stop_status" -eq 0 ]; then
507507
assert_update_restart_probe_inactive >>"$stop_log" 2>&1 || stop_status=$?
508508
fi
509+
if [ "$stop_status" -eq 0 ] && openclaw_e2e_probe_tcp 127.0.0.1 18789 400; then
510+
echo "Baseline gateway listener is still open after service stop." >>"$stop_log"
511+
stop_status=1
512+
fi
509513
if [ "$stop_status" -ne 0 ]; then
510514
echo "gateway service shutdown could not be verified; preserving authored config snapshot" >&2
511515
openclaw_e2e_print_log "$stop_log" >&2

‎scripts/e2e/session-runtime-context-docker-client.ts‎

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ type TranscriptEntry = {
2424
};
2525
};
2626

27+
type MigrationManifest = {
28+
completedAt?: string;
29+
failedAt?: string;
30+
targets: {
31+
completedMoves: { kind: string; sourcePath: string; archivePath: string }[];
32+
}[];
33+
};
34+
2735
function assert(condition: unknown, message: string): asserts condition {
2836
if (!condition) {
2937
throw new Error(message);
@@ -180,7 +188,8 @@ async function verifyDoctorRepair(root: string) {
180188
const stateDir = path.join(root, ".openclaw");
181189
const configPath = path.join(stateDir, "openclaw.json");
182190
const sessionFile = await seedBrokenSession(stateDir);
183-
const originalTranscript = await fs.readFile(sessionFile);
191+
const originalSessionPath = await fs.realpath(sessionFile);
192+
const originalSessionBytes = await fs.readFile(sessionFile);
184193
await fs.mkdir(path.dirname(configPath), { recursive: true });
185194
await fs.writeFile(configPath, JSON.stringify({ plugins: { enabled: false } }, null, 2));
186195

@@ -241,17 +250,41 @@ async function verifyDoctorRepair(root: string) {
241250
),
242251
"doctor repair left runtime context in active transcript",
243252
);
244-
const archiveDir = path.join(stateDir, "agents", "main", "session-sqlite-import-archive");
245-
const archives = (await fs.readdir(archiveDir)).filter((name) =>
246-
name.includes(`.${path.basename(sessionFile)}.imported-`),
253+
const migrationRunsDir = path.join(stateDir, "session-sqlite-migration-runs");
254+
const manifests = await Promise.all(
255+
(await fs.readdir(migrationRunsDir))
256+
.filter((name) => name.endsWith(".json") && !name.endsWith(".failure.json"))
257+
.map(async (name) => {
258+
const manifest = JSON.parse(
259+
await fs.readFile(path.join(migrationRunsDir, name), "utf-8"),
260+
) as MigrationManifest;
261+
assert(manifest.completedAt && !manifest.failedAt, "doctor migration did not complete");
262+
return manifest;
263+
}),
247264
);
248-
const [archiveName] = archives;
265+
const archivedTranscripts = manifests.flatMap((manifest) =>
266+
manifest.targets.flatMap((target) =>
267+
target.completedMoves.filter(
268+
(move) => move.kind === "transcript" && move.sourcePath === originalSessionPath,
269+
),
270+
),
271+
);
272+
const [archivedTranscript] = archivedTranscripts;
249273
assert(
250-
archives.length === 1 && archiveName,
251-
`expected one doctor transcript archive, got ${archives.length}`,
274+
archivedTranscripts.length === 1 && archivedTranscript,
275+
`expected one archived original transcript, got ${archivedTranscripts.length}`,
276+
);
277+
assert(
278+
(await fs.readFile(archivedTranscript.archivePath)).equals(originalSessionBytes),
279+
"doctor archive did not preserve the original transcript bytes",
280+
);
281+
assert(
282+
await fs.lstat(sessionFile).then(
283+
() => false,
284+
(error: unknown) => error instanceof Error && "code" in error && error.code === "ENOENT",
285+
),
286+
"doctor did not retire the imported transcript source",
252287
);
253-
const archivedTranscript = await fs.readFile(path.join(archiveDir, archiveName));
254-
assert(archivedTranscript.equals(originalTranscript), "doctor changed the archived original");
255288
}
256289

257290
async function main() {

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,6 @@ else
581581
openclaw_test_state_create upgrade-survivor upgrade-survivor
582582
fi
583583
node scripts/e2e/lib/upgrade-survivor/assertions.mjs seed
584-
if [ "${OPENCLAW_UPGRADE_SURVIVOR_SCENARIO:-base}" = "cron-scheduled-authority" ]; then
585-
node scripts/e2e/lib/upgrade-survivor/assertions.mjs seed-cron
586-
fi
587584
588585
CURRENT_PHASE="install-candidate"
589586
openclaw_e2e_install_package "$OPENCLAW_UPGRADE_SURVIVOR_ARTIFACT_ROOT/install.log" "upgrade survivor package" "$npm_config_prefix"

‎scripts/lib/openclaw-test-state.mts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ function scenarioConfig(scenario: string, options: TestStateOptions = {}) {
108108
mode: "local",
109109
port: Number(options.port || 18789),
110110
bind: "loopback",
111+
// Only the updater or test service manager may restart the survivor Gateway.
112+
reload: { mode: "off" },
111113
auth: {
112114
mode: "token",
113115
token: { source: "env", provider: "default", id: "GATEWAY_AUTH_TOKEN_REF" },
@@ -445,6 +447,9 @@ OPENCLAW_TEST_STATE_JSON
445447
"mode": "local",
446448
"port": 18789,
447449
"bind": "loopback",
450+
"reload": {
451+
"mode": "off"
452+
},
448453
"auth": {
449454
"mode": "token",
450455
"token": {

‎test/scripts/docker-build-helper.test.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,21 +2833,13 @@ docker_e2e_docker_run_cmd run demo
28332833
expect(script).not.toContain('\nexport FEISHU_APP_SECRET="upgrade-survivor-feishu-secret"\n');
28342834
}
28352835
expectTextToIncludeAll(publishedRunner, [
2836-
"park_update_restart_authored_config",
28372836
"park-restart-probe",
28382837
"assert_prepublish_fixture_idle",
28392838
"assert-no-requests",
2840-
"restore_update_restart_authored_config",
28412839
"config-parking.mjs",
28422840
"'^(GATEWAY_AUTH_TOKEN_REF|OPENCLAW_CLAWHUB_URL)='",
28432841
"OPENCLAW_CLAWHUB_URL=%s",
28442842
]);
2845-
expect(publishedRunner.indexOf("park_update_restart_authored_config")).toBeLessThan(
2846-
publishedRunner.lastIndexOf("assert_prepublish_fixture_idle"),
2847-
);
2848-
expect(publishedRunner.lastIndexOf("assert_prepublish_fixture_idle")).toBeLessThan(
2849-
publishedRunner.lastIndexOf("restore_update_restart_authored_config"),
2850-
);
28512843
for (const script of [runner, updateRestartAuth]) {
28522844
expect(script).not.toContain("assert-no-requests");
28532845
}
@@ -3484,6 +3476,7 @@ trap - EXIT ERR INT TERM
34843476
seed_update_restart_probe_device_auth() { :; }
34853477
assert_prepublish_fixture_idle() { :; }
34863478
assert_baseline_state() { :; }
3479+
check_gateway_status() { :; }
34873480
# This fixture chooses an ephemeral port; retain the actual readiness implementation.
34883481
eval "$(declare -f openclaw_e2e_wait_gateway_ready | sed '1s/openclaw_e2e_wait_gateway_ready/fixture_wait_gateway_ready/')"
34893482
openclaw_e2e_wait_gateway_ready() {
@@ -4523,7 +4516,7 @@ ${storage === "wal" ? 'process.kill(process.pid, "SIGKILL");' : ""}`,
45234516
writeFileSync(join(state, "logs", "gateway-restart.log"), `restart: token=${secret}\n`);
45244517
writeFileSync(
45254518
join(unitDir, "openclaw-gateway.service"),
4526-
`ExecStart=node gateway --token ${secret}\nWorkingDirectory=/safe/service\nEnvironment="API_KEY=${secret}"\n`,
4519+
`[Service]\nExecStart=${process.execPath} gateway --token ${secret}\nWorkingDirectory=/safe/service\nEnvironment="API_KEY=${secret}"\n`,
45274520
);
45284521
writeFileSync(join(artifacts, "doctor.log"), `doctor: token=${secret}\n`);
45294522
writeFileSync(join(artifacts, "update.err"), `post-core failure: token=${secret}\n`);
@@ -4559,10 +4552,15 @@ ${storage === "wal" ? 'process.kill(process.pid, "SIGKILL");' : ""}`,
45594552
readFileSync(UPGRADE_SURVIVOR_UPDATE_RESTART_AUTH_PATH, "utf8"),
45604553
),
45614554
);
4555+
writeFileSync(
4556+
join(workDir, "systemd-fixture.mjs"),
4557+
readFileSync("scripts/e2e/lib/upgrade-survivor/systemd-fixture.mjs"),
4558+
);
45624559
const shown = spawnSync("bash", [shimPath, ...SURVIVOR_SERVICE_SHOW_ARGS], {
45634560
encoding: "utf8",
45644561
env: {
45654562
...process.env,
4563+
HOME: join(workDir, "home"),
45664564
OPENCLAW_UPGRADE_SURVIVOR_SYSTEMCTL_SHIM_DAEMON_LOG: logPath,
45674565
OPENCLAW_UPGRADE_SURVIVOR_SYSTEMCTL_SHIM_LOG: join(artifacts, "systemctl-shim.log"),
45684566
OPENCLAW_UPGRADE_SURVIVOR_SYSTEMCTL_SHIM_PID_FILE: join(workDir, "missing.pid"),

‎test/scripts/openclaw-test-state.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ describe("scripts/lib/openclaw-test-state", () => {
225225
try {
226226
expect(payload.scenario).toBe("upgrade-survivor");
227227
expect(payload.config.update).toStrictEqual({ channel: "stable" });
228+
expect(payload.config.gateway.reload).toStrictEqual({ mode: "off" });
228229
expect(payload.config.gateway.auth).toStrictEqual({
229230
mode: "token",
230231
token: {
@@ -240,6 +241,18 @@ describe("scripts/lib/openclaw-test-state", () => {
240241
});
241242
expect(payload.config.channels.telegram.enabled).toBe(true);
242243
expect(payload.config.channels.whatsapp.enabled).toBe(true);
244+
const renderedFunction = await execFileAsync(process.execPath, [
245+
scriptPath,
246+
"shell-function",
247+
]);
248+
const snippetFile = path.join(payload.root, "state-function.sh");
249+
await fs.writeFile(snippetFile, renderedFunction.stdout, "utf8");
250+
const shellHome = path.join(payload.root, "shell-home");
251+
const shellProbe = await execFileAsync("bash", [
252+
"-c",
253+
`source ${shellQuote(snippetFile)}; openclaw_test_state_create ${shellQuote(shellHome)} upgrade-survivor; cat "$OPENCLAW_CONFIG_PATH"`,
254+
]);
255+
expect(JSON.parse(shellProbe.stdout).gateway).toStrictEqual(payload.config.gateway);
243256
} finally {
244257
await fs.rm(payload.root, { recursive: true, force: true });
245258
}

‎test/scripts/package-acceptance-workflow.test.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4091,10 +4091,6 @@ describe("package artifact reuse", () => {
40914091
expect(packageJson).toContain("OPENCLAW_UPGRADE_SURVIVOR_UPDATE_RESTART_MODE=auto-auth");
40924092
expect(publishedUpgradeSurvivor).toContain("validate_baseline_package_spec");
40934093
expect(publishedUpgradeSurvivor).toContain("OPENCLAW_UPGRADE_SURVIVOR_UPDATE_RESTART_MODE");
4094-
expect(publishedUpgradeSurvivor).toContain("seed_update_restart_probe_device_auth");
4095-
expect(
4096-
readFileSync("scripts/e2e/lib/upgrade-survivor/update-restart-auth.sh", "utf8"),
4097-
).toContain("upgrade survivor restart probe");
40984094
expect(publishedUpgradeSurvivor).toContain("write_update_restart_service_env");
40994095
expect(publishedUpgradeSurvivor).toContain("GATEWAY_AUTH_TOKEN_REF=%s");
41004096
expect(publishedUpgradeSurvivor).toContain("OPENCLAW_CLAWHUB_URL=%s");

0 commit comments

Comments
 (0)