Skip to content

Commit 6a00be5

Browse files
committed
fix(update): complete channel switch follow-up work
1 parent cd8187d commit 6a00be5

9 files changed

Lines changed: 269 additions & 105 deletions

File tree

‎.github/workflows/openclaw-live-and-e2e-checks-reusable.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@ jobs:
430430
command: pnpm test:docker:doctor-switch
431431
timeout_minutes: 60
432432
release_path: true
433+
- suite_id: docker-update-channel-switch
434+
label: Update Channel Switch Docker E2E
435+
command: pnpm test:docker:update-channel-switch
436+
timeout_minutes: 60
437+
release_path: true
433438
- suite_id: docker-session-runtime-context
434439
label: Session Runtime Context Docker E2E
435440
command: pnpm test:docker:session-runtime-context

‎docs/help/testing.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ These Docker runners split into two buckets:
607607
`OPENCLAW_LIVE_GATEWAY_MODEL_TIMEOUT_MS=90000`. Override those env vars when you
608608
explicitly want the larger exhaustive scan.
609609
- `test:docker:all` builds the live Docker image once via `test:docker:live-build`, then reuses it for the live Docker lanes. It also builds one shared `scripts/e2e/Dockerfile` image via `test:docker:e2e-build` and reuses it for the E2E container smoke runners that exercise the built app. The aggregate uses a weighted local scheduler: `OPENCLAW_DOCKER_ALL_PARALLELISM` controls process slots, while resource caps keep heavy live, npm-install, and multi-service lanes from all starting at once. Defaults are 10 slots, `OPENCLAW_DOCKER_ALL_LIVE_LIMIT=6`, `OPENCLAW_DOCKER_ALL_NPM_LIMIT=8`, and `OPENCLAW_DOCKER_ALL_SERVICE_LIMIT=7`; tune `OPENCLAW_DOCKER_ALL_WEIGHT_LIMIT` or `OPENCLAW_DOCKER_ALL_DOCKER_LIMIT` only when the Docker host has more headroom. The runner performs a Docker preflight by default, removes stale OpenClaw E2E containers, prints status every 30 seconds, stores successful lane timings in `.artifacts/docker-tests/lane-timings.json`, and uses those timings to start longer lanes first on later runs. Use `OPENCLAW_DOCKER_ALL_DRY_RUN=1` to print the weighted lane manifest without building or running Docker.
610-
- Container smoke runners: `test:docker:openwebui`, `test:docker:onboard`, `test:docker:npm-onboard-channel-agent`, `test:docker:session-runtime-context`, `test:docker:agents-delete-shared-workspace`, `test:docker:gateway-network`, `test:docker:browser-cdp-snapshot`, `test:docker:mcp-channels`, `test:docker:pi-bundle-mcp-tools`, `test:docker:cron-mcp-cleanup`, `test:docker:plugins`, `test:docker:plugin-update`, and `test:docker:config-reload` boot one or more real containers and verify higher-level integration paths.
610+
- Container smoke runners: `test:docker:openwebui`, `test:docker:onboard`, `test:docker:npm-onboard-channel-agent`, `test:docker:update-channel-switch`, `test:docker:session-runtime-context`, `test:docker:agents-delete-shared-workspace`, `test:docker:gateway-network`, `test:docker:browser-cdp-snapshot`, `test:docker:mcp-channels`, `test:docker:pi-bundle-mcp-tools`, `test:docker:cron-mcp-cleanup`, `test:docker:plugins`, `test:docker:plugin-update`, and `test:docker:config-reload` boot one or more real containers and verify higher-level integration paths.
611611
612612
The live-model Docker runners also bind-mount only the needed CLI auth homes (or all supported ones when the run is not narrowed), then copy them into the container home before the run so external-CLI OAuth can refresh tokens without mutating the host auth store:
613613
@@ -619,6 +619,7 @@ The live-model Docker runners also bind-mount only the needed CLI auth homes (or
619619
- Open WebUI live smoke: `pnpm test:docker:openwebui` (script: `scripts/e2e/openwebui-docker.sh`)
620620
- Onboarding wizard (TTY, full scaffolding): `pnpm test:docker:onboard` (script: `scripts/e2e/onboard-docker.sh`)
621621
- Npm tarball onboarding/channel/agent smoke: `pnpm test:docker:npm-onboard-channel-agent` installs the packed OpenClaw tarball globally in Docker, configures OpenAI via env-ref onboarding plus Telegram by default, verifies doctor repairs activated plugin runtime deps, and runs one mocked OpenAI agent turn. Reuse a prebuilt tarball with `OPENCLAW_NPM_ONBOARD_PACKAGE_TGZ=/path/to/openclaw-*.tgz`, skip the host rebuild with `OPENCLAW_NPM_ONBOARD_HOST_BUILD=0`, or switch channel with `OPENCLAW_NPM_ONBOARD_CHANNEL=discord`.
622+
- Update channel switch smoke: `pnpm test:docker:update-channel-switch` installs the packed OpenClaw tarball globally in Docker, switches from package `stable` to git `dev`, verifies the persisted channel and plugin post-update work, then switches back to package `stable` and checks update status.
622623
- Session runtime context smoke: `pnpm test:docker:session-runtime-context` verifies hidden runtime context transcript persistence plus doctor repair of affected duplicated prompt-rewrite branches.
623624
- Bun global install smoke: `bash scripts/e2e/bun-global-install-smoke.sh` packs the current tree, installs it with `bun install -g` in an isolated home, and verifies `openclaw infer image providers --json` returns bundled image providers instead of hanging. Reuse a prebuilt tarball with `OPENCLAW_BUN_GLOBAL_SMOKE_PACKAGE_TGZ=/path/to/openclaw-*.tgz`, skip the host build with `OPENCLAW_BUN_GLOBAL_SMOKE_HOST_BUILD=0`, or copy `dist/` from a built Docker image with `OPENCLAW_BUN_GLOBAL_SMOKE_DIST_IMAGE=openclaw-dockerfile-smoke:local`.
624625
- Installer Docker smoke: `bash scripts/test-install-sh-docker.sh` shares one npm cache across its root, update, and direct-npm containers. Update smoke defaults to npm `latest` as the stable baseline before upgrading to the candidate tarball. Non-root installer checks keep an isolated npm cache so root-owned cache entries do not mask user-local install behavior. Set `OPENCLAW_INSTALL_SMOKE_NPM_CACHE_DIR=/path/to/cache` to reuse the root/update/direct-npm cache across local reruns.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,7 @@
15421542
"test:docker:plugins": "bash scripts/e2e/plugins-docker.sh",
15431543
"test:docker:qr": "bash scripts/e2e/qr-import-docker.sh",
15441544
"test:docker:session-runtime-context": "bash scripts/e2e/session-runtime-context-docker.sh",
1545+
"test:docker:update-channel-switch": "bash scripts/e2e/update-channel-switch-docker.sh",
15451546
"test:e2e": "node scripts/run-vitest.mjs run --config test/vitest/vitest.e2e.config.ts",
15461547
"test:e2e:openshell": "OPENCLAW_E2E_OPENSHELL=1 node scripts/run-vitest.mjs run --config test/vitest/vitest.e2e.config.ts extensions/openshell/src/backend.e2e.test.ts",
15471548
"test:extension": "node scripts/test-extension.mjs",

‎scripts/e2e/Dockerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ RUN --mount=type=cache,id=openclaw-pnpm-store,target=/home/appuser/.local/share/
4040

4141
FROM deps AS build
4242

43-
COPY --chown=appuser:appuser tsconfig.json tsconfig.plugin-sdk.dts.json tsdown.config.ts vitest.config.ts openclaw.mjs ./
43+
COPY --chown=appuser:appuser .oxlintrc.json tsconfig.json tsconfig.plugin-sdk.dts.json tsconfig.oxlint*.json tsdown.config.ts vitest.config.ts openclaw.mjs ./
4444
COPY --chown=appuser:appuser src ./src
4545
COPY --chown=appuser:appuser test ./test
4646
COPY --chown=appuser:appuser scripts ./scripts
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
5+
source "$ROOT_DIR/scripts/lib/docker-e2e-image.sh"
6+
7+
IMAGE_NAME="$(docker_e2e_resolve_image "openclaw-update-channel-switch-e2e" OPENCLAW_UPDATE_CHANNEL_SWITCH_E2E_IMAGE)"
8+
SKIP_BUILD="${OPENCLAW_UPDATE_CHANNEL_SWITCH_E2E_SKIP_BUILD:-0}"
9+
10+
docker_e2e_build_or_reuse "$IMAGE_NAME" update-channel-switch "$ROOT_DIR/scripts/e2e/Dockerfile" "$ROOT_DIR" "" "$SKIP_BUILD"
11+
12+
echo "Running update channel switch E2E..."
13+
docker run --rm \
14+
-e COREPACK_ENABLE_DOWNLOAD_PROMPT=0 \
15+
-e OPENCLAW_SKIP_CHANNELS=1 \
16+
-e OPENCLAW_SKIP_PROVIDERS=1 \
17+
"$IMAGE_NAME" \
18+
bash -lc 'set -euo pipefail
19+
20+
export npm_config_loglevel=error
21+
export npm_config_fund=false
22+
export npm_config_audit=false
23+
export npm_config_prefix=/tmp/npm-prefix
24+
export NPM_CONFIG_PREFIX=/tmp/npm-prefix
25+
export PNPM_HOME=/tmp/pnpm-home
26+
export PATH="/tmp/npm-prefix/bin:/tmp/pnpm-home:$PATH"
27+
export CI=true
28+
export OPENCLAW_DISABLE_BUNDLED_PLUGINS=1
29+
export OPENCLAW_NO_ONBOARD=1
30+
export OPENCLAW_NO_PROMPT=1
31+
32+
cat > /app/.gitignore <<'"'"'GITIGNORE'"'"'
33+
node_modules
34+
**/node_modules/
35+
dist
36+
dist-runtime
37+
.turbo
38+
coverage
39+
GITIGNORE
40+
41+
node --import tsx scripts/write-package-dist-inventory.ts
42+
43+
git config --global user.email "[email protected]"
44+
git config --global user.name "OpenClaw Docker E2E"
45+
git config --global gc.auto 0
46+
git -C /app init -q
47+
git -C /app config gc.auto 0
48+
git -C /app add -A
49+
git -C /app commit -qm "test fixture"
50+
fixture_sha="$(git -C /app rev-parse HEAD)"
51+
52+
pkg_tgz="$(npm pack --ignore-scripts --silent --pack-destination /tmp /app | tail -n 1 | tr -d "\r")"
53+
pkg_tgz_path="/tmp/$pkg_tgz"
54+
if [ ! -f "$pkg_tgz_path" ]; then
55+
echo "npm pack failed (expected $pkg_tgz_path)"
56+
exit 1
57+
fi
58+
59+
npm install -g --prefix /tmp/npm-prefix --omit=optional "$pkg_tgz_path"
60+
61+
home_dir="$(mktemp -d /tmp/openclaw-update-channel-switch-home.XXXXXX)"
62+
export HOME="$home_dir"
63+
mkdir -p "$HOME/.openclaw"
64+
cat > "$HOME/.openclaw/openclaw.json" <<'"'"'JSON'"'"'
65+
{
66+
"update": {
67+
"channel": "stable"
68+
},
69+
"plugins": {}
70+
}
71+
JSON
72+
73+
export OPENCLAW_GIT_DIR=/app
74+
export OPENCLAW_UPDATE_DEV_TARGET_REF="$fixture_sha"
75+
76+
echo "==> package -> git dev channel"
77+
set +e
78+
dev_json="$(openclaw update --channel dev --yes --json --no-restart)"
79+
dev_status=$?
80+
set -e
81+
printf "%s\n" "$dev_json"
82+
if [ "$dev_status" -ne 0 ]; then
83+
exit "$dev_status"
84+
fi
85+
DEV_JSON="$dev_json" node - <<'"'"'NODE'"'"'
86+
const payload = JSON.parse(process.env.DEV_JSON);
87+
if (payload.status !== "ok") {
88+
throw new Error(`expected dev update status ok, got ${payload.status}`);
89+
}
90+
if (payload.mode !== "git") {
91+
throw new Error(`expected dev update mode git, got ${payload.mode}`);
92+
}
93+
if (payload.postUpdate?.plugins?.status !== "ok") {
94+
throw new Error(`expected plugin post-update ok, got ${JSON.stringify(payload.postUpdate?.plugins)}`);
95+
}
96+
NODE
97+
98+
node - <<'"'"'NODE'"'"'
99+
const fs = require("node:fs");
100+
const path = require("node:path");
101+
const configPath = path.join(process.env.HOME, ".openclaw", "openclaw.json");
102+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
103+
if (config.update?.channel !== "dev") {
104+
throw new Error(`expected persisted update.channel dev, got ${JSON.stringify(config.update?.channel)}`);
105+
}
106+
NODE
107+
108+
status_json="$(openclaw update status --json)"
109+
printf "%s\n" "$status_json"
110+
STATUS_JSON="$status_json" node - <<'"'"'NODE'"'"'
111+
const payload = JSON.parse(process.env.STATUS_JSON);
112+
if (payload.update?.installKind !== "git") {
113+
throw new Error(`expected git install after dev switch, got ${payload.update?.installKind}`);
114+
}
115+
if (payload.channel?.value !== "dev" || payload.channel?.source !== "config") {
116+
throw new Error(`expected dev config channel after dev switch, got ${JSON.stringify(payload.channel)}`);
117+
}
118+
NODE
119+
120+
echo "==> git -> package stable channel"
121+
set +e
122+
stable_json="$(openclaw update --channel stable --tag "$pkg_tgz_path" --yes --json --no-restart)"
123+
stable_status=$?
124+
set -e
125+
printf "%s\n" "$stable_json"
126+
if [ "$stable_status" -ne 0 ]; then
127+
exit "$stable_status"
128+
fi
129+
STABLE_JSON="$stable_json" node - <<'"'"'NODE'"'"'
130+
const payload = JSON.parse(process.env.STABLE_JSON);
131+
if (payload.status !== "ok") {
132+
throw new Error(`expected stable update status ok, got ${payload.status}`);
133+
}
134+
if (!["npm", "pnpm", "bun"].includes(payload.mode)) {
135+
throw new Error(`expected package-manager mode after stable switch, got ${payload.mode}`);
136+
}
137+
if (payload.postUpdate?.plugins?.status !== "ok") {
138+
throw new Error(`expected plugin post-update ok, got ${JSON.stringify(payload.postUpdate?.plugins)}`);
139+
}
140+
NODE
141+
142+
node - <<'"'"'NODE'"'"'
143+
const fs = require("node:fs");
144+
const path = require("node:path");
145+
const configPath = path.join(process.env.HOME, ".openclaw", "openclaw.json");
146+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
147+
if (config.update?.channel !== "stable") {
148+
throw new Error(`expected persisted update.channel stable, got ${JSON.stringify(config.update?.channel)}`);
149+
}
150+
NODE
151+
152+
status_json="$(openclaw update status --json)"
153+
printf "%s\n" "$status_json"
154+
STATUS_JSON="$status_json" node - <<'"'"'NODE'"'"'
155+
const payload = JSON.parse(process.env.STATUS_JSON);
156+
if (payload.update?.installKind !== "package") {
157+
throw new Error(`expected package install after stable switch, got ${payload.update?.installKind}`);
158+
}
159+
if (payload.channel?.value !== "stable" || payload.channel?.source !== "config") {
160+
throw new Error(`expected stable config channel after stable switch, got ${JSON.stringify(payload.channel)}`);
161+
}
162+
NODE
163+
164+
echo "OK"
165+
'

‎scripts/test-docker-all.mjs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ const lanes = [
246246
npmLane("doctor-switch", "OPENCLAW_SKIP_DOCKER_BUILD=1 pnpm test:docker:doctor-switch", {
247247
weight: 3,
248248
}),
249+
npmLane(
250+
"update-channel-switch",
251+
"OPENCLAW_SKIP_DOCKER_BUILD=1 pnpm test:docker:update-channel-switch",
252+
{
253+
timeoutMs: 30 * 60 * 1000,
254+
weight: 3,
255+
},
256+
),
249257
lane("plugins", "OPENCLAW_SKIP_DOCKER_BUILD=1 pnpm test:docker:plugins", {
250258
resources: ["npm", "service"],
251259
weight: 6,

‎src/cli/update-cli.test.ts‎

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,41 +1693,68 @@ describe("update-cli", () => {
16931693
expect(syncConfig?.plugins?.entries).toBeUndefined();
16941694
});
16951695

1696-
it("skips plugin sync in the old process after switching from package to git", async () => {
1696+
it("persists channel and runs post-update work after switching from package to git", async () => {
16971697
const tempDir = createCaseDir("openclaw-update");
1698+
const gitRoot = path.join(tempDir, "..", "openclaw");
16981699
const completionCacheSpy = vi
16991700
.spyOn(updateCliShared, "tryWriteCompletionCache")
17001701
.mockResolvedValue(undefined);
17011702
mockPackageInstallStatus(tempDir);
1703+
vi.mocked(readConfigFileSnapshot).mockResolvedValue({
1704+
...baseSnapshot,
1705+
parsed: { update: { channel: "stable" } },
1706+
resolved: { update: { channel: "stable" } } as OpenClawConfig,
1707+
sourceConfig: { update: { channel: "stable" } } as OpenClawConfig,
1708+
runtimeConfig: { update: { channel: "stable" } } as OpenClawConfig,
1709+
config: { update: { channel: "stable" } } as OpenClawConfig,
1710+
});
17021711
vi.mocked(runGatewayUpdate).mockResolvedValue(
17031712
makeOkUpdateResult({
17041713
mode: "git",
1705-
root: path.join(tempDir, "..", "openclaw"),
1714+
root: gitRoot,
17061715
after: { version: "2026.4.10" },
17071716
}),
17081717
);
1709-
serviceLoaded.mockResolvedValue(true);
1710-
syncPluginsForUpdateChannel.mockRejectedValue(
1711-
new Error("Config validation failed: old host version"),
1712-
);
1718+
syncPluginsForUpdateChannel.mockImplementation(async ({ config }) => ({
1719+
changed: false,
1720+
config,
1721+
summary: {
1722+
switchedToBundled: [],
1723+
switchedToNpm: [],
1724+
warnings: [],
1725+
errors: [],
1726+
},
1727+
}));
1728+
updateNpmInstalledPlugins.mockImplementation(async ({ config }) => ({
1729+
changed: false,
1730+
config,
1731+
outcomes: [],
1732+
}));
17131733

1714-
await updateCommand({ channel: "dev", yes: true });
1734+
await updateCommand({ channel: "dev", yes: true, restart: false });
17151735

1716-
expect(syncPluginsForUpdateChannel).not.toHaveBeenCalled();
1717-
expect(replaceConfigFile).not.toHaveBeenCalled();
1718-
expect(completionCacheSpy).not.toHaveBeenCalled();
1736+
const persistedConfig = vi.mocked(replaceConfigFile).mock.calls[0]?.[0]?.nextConfig;
1737+
expect(persistedConfig?.update?.channel).toBe("dev");
1738+
expect(syncPluginsForUpdateChannel).toHaveBeenCalledWith(
1739+
expect.objectContaining({
1740+
channel: "dev",
1741+
config: expect.objectContaining({
1742+
update: expect.objectContaining({ channel: "dev" }),
1743+
}),
1744+
workspaceDir: gitRoot,
1745+
}),
1746+
);
1747+
expect(updateNpmInstalledPlugins).toHaveBeenCalledWith(
1748+
expect.objectContaining({
1749+
config: expect.objectContaining({
1750+
update: expect.objectContaining({ channel: "dev" }),
1751+
}),
1752+
}),
1753+
);
1754+
expect(completionCacheSpy).toHaveBeenCalledWith(gitRoot, false);
17191755
expect(runRestartScript).not.toHaveBeenCalled();
17201756
expect(runDaemonRestart).not.toHaveBeenCalled();
1721-
expect(defaultRuntime.exit).toHaveBeenCalledWith(0);
17221757
expect(defaultRuntime.exit).not.toHaveBeenCalledWith(1);
1723-
expect(
1724-
vi
1725-
.mocked(defaultRuntime.log)
1726-
.mock.calls.map((call) => String(call[0]))
1727-
.join("\n"),
1728-
).toContain(
1729-
"Switched from a package install to a git checkout. Skipping remaining post-update work in the old CLI process; rerun follow-up commands from the new git install if needed.",
1730-
);
17311758
});
17321759
it("explains why git updates cannot run with edited files", async () => {
17331760
vi.mocked(defaultRuntime.log).mockClear();

0 commit comments

Comments
 (0)