Skip to content

Commit 3f749b9

Browse files
fix(update): route stored dev channel to the git update flow [AI-assisted] (#123083)
* fix(update): route stored dev channel to the git update flow [AI-assisted] A package-detected launcher with a stored update.channel: dev resolved the npm "dev" dist-tag (which does not exist -> ETARGET) because switchToGit only honored an explicitly requested --channel dev. Base the decision on the effective channel and collapse the duplicated selectedChannel/channel computation, which is provably identical in every reachable case. Refs #123073 * docs(update): state the dev-channel git contract in the routing comment Review finding: "dev" can exist as a rare npm dist-tag, so the comment must not claim it never does; the routing rationale is the documented dev-channel git-checkout contract. * fix(update): keep one-off --tag on the package path for stored-dev installs --tag is documented as a one-run package-target override, so a stored dev channel must not divert a tagged update into the git flow (where the tag is ignored). An explicitly requested --channel dev still outranks the tag, matching existing explicit-channel behavior. * test(update): scope the package-to-git clone to a per-case OPENCLAW_GIT_DIR The stored-dev routing case performs a real transactional clone. On the default <home>/openclaw that directory outlived the case and made a later test fail with "OPENCLAW_GIT_DIR appeared while cloning". Test Plan: node --import tsx scripts/test-projects.mts src/cli/update-cli.test.ts Failing set now matches clean origin/main exactly (3 pre-existing macOS $TMPDIR symlink failures, unrelated to this change). Assisted by an AI coding assistant; reviewed before submitting. * test(update): verify stored dev routing on installed packages Temporary expected-failure verification for #123073. Restore only the routing owner to its pre-fix bytes while retaining the original contributor commits and adding installed-package regression coverage. This head must not merge; restore the reviewed fix and require hosted green proof after capturing the intended failure. * fix(update): restore stored dev routing after regression proof Restore the contributor's canonical effective-channel fix after the installed-package regression lane reproduced package routing for stored dev. Keep one-off tags on the package path and explicit dev precedence. Remove the obsolete source-text assertion now covered by installed CLI behavior and format the CI documentation table. Preserve all original contributor commits. Fresh hosted GREEN validation remains required. Co-authored-by: Chinmayrawat15 <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Chinmayrawat15 <[email protected]>
1 parent 4d9187a commit 3f749b9

9 files changed

Lines changed: 111 additions & 26 deletions

File tree

‎docs/ci.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ dispatch.
4343
| `checks-fast-contracts-plugins-*` | Two weighted plugin contract shards | Node-relevant changes |
4444
| `checks-fast-contracts-channels-*` | Two weighted channel contract shards | Node-relevant changes |
4545
| `checks-node-*` | Changed-target Node tests on pull requests; compact integration shards on `main`; metadata-complete compact fallback on broad PRs; full named shards on manual and release runs | Node-relevant changes |
46-
| `docker-seed-e2e` | One Docker scheduler job for the executable `mcp-channels`, `cron-mcp-cleanup`, and `mcp-code-mode-gateway` owner lanes | PR changes to their seed helpers or CI gate owners |
46+
| `docker-seed-e2e` | One Docker scheduler job for the executable `mcp-channels`, `cron-mcp-cleanup`, `mcp-code-mode-gateway`, and `update-channel-switch` owner lanes | PR changes to their E2E helpers or CI gate owners |
4747
| `check-*` | Sharded main local gate equivalent: guards, transient npm-lock validation, bundled-channel config metadata, prod types, lint, dependencies, test types | Node-relevant changes |
4848
| `check-additional-*` | Boundary check stripes (including prompt snapshot drift), session accessor/transcript reader/SQLite transaction boundaries, extension lint groups, package boundary compile/canary, and runtime topology architecture; the pure-reporting plugin SDK API diff runs on manual and release dispatches only | Node-relevant changes |
4949
| `checks-node-compat-node22` | Node 22 compatibility build and smoke lane | Full Release Validation and manual dispatches only |
@@ -61,7 +61,7 @@ dispatch.
6161
| `openclaw-performance` | Separate workflow: daily/on-demand Kova runtime performance reports with mock-provider, deep-profile, and GPT 5.6 live lanes | Scheduled and manual dispatch |
6262

6363
The rare path-triggered `docker-seed-e2e` job selects only the executable
64-
owners of changed seed helpers and runs them through one scheduler invocation.
64+
owners of changed E2E helpers and runs them through one scheduler invocation.
6565
Trusted same-repository pull requests use one 16-vCPU Blacksmith runner with
6666
main and tail parallelism set to 3; GitHub-hosted, fork, and retry paths run the
6767
same selected lanes serially. The job is part of `openclaw/ci-gate`. It adds at

‎docs/install/development-channels.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ OpenClaw ships four update channels:
1818
applies automatically.
1919
- **beta**: npm dist-tag `beta`. Falls back to `latest` when `beta` is missing
2020
or older than the current stable release.
21-
- **dev**: moving head of `main` (git). npm dist-tag `dev` when published. `main`
21+
- **dev**: moving head of `main` (git), including when switching from a package install. `main`
2222
is for experimentation and active development; it may contain incomplete
2323
features or breaking changes. Do not run it for production gateways.
2424

@@ -43,7 +43,7 @@ install paths:
4343
| `stable` | dist-tag `latest` | latest stable git tag (excludes `-alpha.N`, `-beta.N`, `-rc.N`, `-dev.N`, `-next.N`, `-preview.N`, `-canary.N`, `-nightly.N`, and other named prerelease suffixes) |
4444
| `extended-stable` | resolves the public npm `extended-stable` selector, verifies the exact selected package, and installs that exact version. Fails closed with no fallback to `latest`, `beta`, or `dev`. | unsupported: OpenClaw leaves the checkout unchanged and asks you to use a package installation |
4545
| `beta` | dist-tag `beta`, falling back to `latest` when `beta` is missing or older | latest beta git tag, falling back to the latest stable git tag when beta is missing or older |
46-
| `dev` | dist-tag `dev` (rare; most dev users run git installs) | fetches, rebases the checkout on the upstream `main` branch, builds, and reinstalls the global CLI |
46+
| `dev` | switches to a Git checkout, builds it, and reinstalls the global CLI | fetches, rebases the checkout on the upstream `main` branch, builds, and reinstalls the global CLI |
4747

4848
For `dev` git installs, the default checkout is `~/openclaw` (or
4949
`$OPENCLAW_HOME/openclaw` when `OPENCLAW_HOME` is set); override with
@@ -82,6 +82,9 @@ Notes:
8282
- `--tag` applies to **package (npm) installs only**; git installs ignore it.
8383
- The tag is not persisted; the next `openclaw update` uses the configured
8484
channel.
85+
- A package install with stored `update.channel: "dev"` still honors a one-off
86+
`--tag` without switching to Git. An explicit `--channel dev` takes precedence
87+
over `--tag` and selects the Git checkout flow.
8588
- The `--tag main` shorthand is rejected for package installs because the
8689
workspace checkout is not a self-contained package artifact. Use
8790
`openclaw update --channel dev` (package installs switch to a git checkout)

‎scripts/e2e/lib/update-channel-switch/assertions.mjs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Assertions for update-channel switch E2E scenarios.
2+
import assert from "node:assert/strict";
23
import fs from "node:fs";
34
import path from "node:path";
45
import { legacyPackageAcceptanceCompat } from "../package-compat.mjs";
@@ -8,7 +9,7 @@ const controlUiHtml = "<!doctype html><title>fixture</title>\n";
89

910
function usage() {
1011
console.error(
11-
"usage: assertions.mjs <prepare-git-fixture|write-control-ui|assert-update|assert-config-channel|assert-status-kind|assert-installed-version> [...]",
12+
"usage: assertions.mjs <prepare-git-fixture|write-control-ui|assert-update|assert-dry-run|assert-config-channel|assert-status-kind|assert-installed-version> [...]",
1213
);
1314
process.exit(2);
1415
}
@@ -189,6 +190,18 @@ function assertConfigChannel(channel) {
189190
);
190191
}
191192

193+
function assertDryRun(kind, channel) {
194+
const preview = JSON.parse(process.env.UPDATE_JSON ?? "");
195+
assert.equal(preview.dryRun, true);
196+
assert.equal(preview.installKind, "package");
197+
assert.equal(preview.storedChannel, "dev");
198+
assert.equal(preview.effectiveChannel, channel);
199+
assert.equal(preview.updateInstallKind, kind);
200+
assert.equal(preview.mode, kind === "git" ? "git" : "npm");
201+
assert.equal(preview.switchToGit, kind === "git");
202+
assert.equal(preview.switchToPackage, false);
203+
}
204+
192205
function assertStatusKind(kind) {
193206
const payload = JSON.parse(process.env.STATUS_JSON ?? "");
194207
if (payload.update?.installKind !== kind) {
@@ -218,6 +231,9 @@ switch (command) {
218231
case "assert-config-channel":
219232
assertConfigChannel(args[0]);
220233
break;
234+
case "assert-dry-run":
235+
assertDryRun(args[0], args[1]);
236+
break;
221237
case "assert-status-kind":
222238
assertStatusKind(args[0]);
223239
break;

‎scripts/e2e/update-channel-switch-docker.sh‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,32 @@ status_json="$(openclaw update status --json)"
157157
printf "%s\n" "$status_json"
158158
STATUS_JSON="$status_json" node scripts/e2e/lib/update-channel-switch/assertions.mjs assert-status-kind package
159159
160+
assert_package_dry_run() {
161+
local expected_kind="$1" expected_channel="$2"
162+
shift 2
163+
local preview
164+
preview="$(openclaw update --dry-run --json --no-restart "$@")"
165+
printf "%s\n" "$preview"
166+
UPDATE_JSON="$preview" node scripts/e2e/lib/update-channel-switch/assertions.mjs \
167+
assert-dry-run "$expected_kind" "$expected_channel"
168+
node scripts/e2e/lib/update-channel-switch/assertions.mjs assert-config-channel dev
169+
}
170+
dev_channel_args=(--channel dev)
171+
# Legacy package acceptance permits missing channel persistence; keep its explicit switch.
172+
if [ "$OPENCLAW_PACKAGE_ACCEPTANCE_LEGACY_COMPAT" != "1" ]; then
173+
echo "==> package dry-run channel and one-off tag precedence"
174+
openclaw config set update.channel dev
175+
assert_package_dry_run git dev
176+
assert_package_dry_run git dev --channel dev
177+
assert_package_dry_run git dev --channel dev --tag beta
178+
assert_package_dry_run package dev --tag beta
179+
assert_package_dry_run package stable --channel stable
180+
dev_channel_args=()
181+
fi
182+
160183
echo "==> package -> git dev channel"
161184
set +e
162-
dev_json="$(openclaw update --channel dev --yes --json --no-restart)"
185+
dev_json="$(openclaw update "${dev_channel_args[@]}" --yes --json --no-restart)"
163186
dev_status=$?
164187
set -e
165188
printf "%s\n" "$dev_json"

‎scripts/lib/ci-changed-node-test-plan.mts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,23 @@ const CHANGED_NODE_TEST_TARGETS_PER_JOB = 12;
5050
// integration tests past the global timeout.
5151
const SERIAL_CHANGED_TARGET_RE = /^extensions\/memory-core\//u;
5252
const BOUNDARY_NODE_TEST_CONFIG = "test/vitest/vitest.boundary.config.ts";
53-
const DOCKER_SEED_LANE_ORDER = [
53+
const MCP_DOCKER_SEED_LANES = [
5454
"mcp-channels",
5555
"cron-mcp-cleanup",
5656
"mcp-code-mode-gateway",
5757
] as const;
58+
const DOCKER_SEED_LANE_ORDER = [...MCP_DOCKER_SEED_LANES, "update-channel-switch"] as const;
5859
type DockerSeedLane = (typeof DOCKER_SEED_LANE_ORDER)[number];
5960
const DOCKER_SEED_LANES_BY_PATH: Readonly<Record<string, readonly DockerSeedLane[]>> = {
60-
".github/workflows/ci.yml": DOCKER_SEED_LANE_ORDER,
61+
".github/workflows/ci.yml": MCP_DOCKER_SEED_LANES,
6162
"scripts/e2e/cron-mcp-cleanup-seed.ts": ["cron-mcp-cleanup"],
62-
"scripts/e2e/docker-openai-seed.ts": DOCKER_SEED_LANE_ORDER,
63+
"scripts/e2e/docker-openai-seed.ts": MCP_DOCKER_SEED_LANES,
6364
"scripts/e2e/lib/mcp-code-mode-probe-server.ts": ["mcp-code-mode-gateway"],
65+
"scripts/e2e/lib/update-channel-switch/assertions.mjs": ["update-channel-switch"],
6466
"scripts/e2e/mcp-channels-seed.ts": ["mcp-channels"],
6567
"scripts/e2e/mcp-code-mode-gateway-seed.ts": ["mcp-code-mode-gateway"],
66-
"scripts/lib/ci-changed-node-test-plan.mts": DOCKER_SEED_LANE_ORDER,
68+
"scripts/e2e/update-channel-switch-docker.sh": ["update-channel-switch"],
69+
"scripts/lib/ci-changed-node-test-plan.mts": MCP_DOCKER_SEED_LANES,
6770
};
6871
const publicPluginSdkEntrySources = Object.values(
6972
buildPluginSdkEntrySources(publicPluginSdkEntrypoints),

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3835,6 +3835,30 @@ describe("update-cli", () => {
38353835
expectedChannel: "beta" as const,
38363836
expectedPersistedChannel: undefined,
38373837
},
3838+
{
3839+
name: "routes a stored dev channel on package installs to the git update flow",
3840+
installKind: "package" as const,
3841+
options: { yes: true },
3842+
storedChannel: "dev" as const,
3843+
expectedChannel: "dev" as const,
3844+
expectedPersistedChannel: undefined,
3845+
},
3846+
{
3847+
name: "keeps a stored-dev package install on the package path for a one-off --tag",
3848+
installKind: "package" as const,
3849+
options: { tag: "latest", yes: true },
3850+
storedChannel: "dev" as const,
3851+
expectedChannel: undefined,
3852+
expectedPersistedChannel: undefined,
3853+
},
3854+
{
3855+
name: "keeps explicit dev channel precedence over a one-off --tag",
3856+
installKind: "package" as const,
3857+
options: { channel: "dev", tag: "latest", yes: true },
3858+
storedChannel: "dev" as const,
3859+
expectedChannel: "dev" as const,
3860+
expectedPersistedChannel: undefined,
3861+
},
38383862
{
38393863
name: "switches git installs to package mode for explicit beta and persists it",
38403864
installKind: "git" as const,
@@ -3848,7 +3872,8 @@ describe("update-cli", () => {
38483872
async ({ installKind, options, storedChannel, expectedChannel, expectedPersistedChannel }) => {
38493873
if (installKind === "package") {
38503874
mockPackageInstallStatus(createCaseDir("openclaw-update"));
3851-
} else {
3875+
}
3876+
if (installKind === "git" || expectedChannel !== undefined) {
38523877
vi.mocked(runGatewayUpdate).mockResolvedValue(makeOkUpdateResult({ mode: "git" }));
38533878
}
38543879
if (storedChannel) {
@@ -3858,7 +3883,16 @@ describe("update-cli", () => {
38583883
});
38593884
}
38603885

3861-
await updateCommand(options);
3886+
if (installKind === "package" && expectedChannel !== undefined) {
3887+
// Git commands are mocked, but package-to-git routing stages real directories.
3888+
// Left on the default <home>/openclaw they outlive this case and make
3889+
// a later test fail with "OPENCLAW_GIT_DIR appeared while cloning".
3890+
await withEnvAsync({ OPENCLAW_GIT_DIR: createCaseDir("openclaw-update-git") }, async () => {
3891+
await updateCommand(options);
3892+
});
3893+
} else {
3894+
await updateCommand(options);
3895+
}
38623896

38633897
if (expectedChannel !== undefined) {
38643898
expectUpdateCallChannel(expectedChannel);

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ async function updateCommandInternal(
248248
}
249249

250250
const installKind = updateStatus.installKind;
251-
const selectedChannel =
251+
const channel =
252252
requestedChannel ??
253253
storedChannel ??
254254
(installKind === "git"
@@ -257,7 +257,7 @@ async function updateCommandInternal(
257257
currentVersion: VERSION,
258258
installKind,
259259
}).channel);
260-
if (selectedChannel === "extended-stable" && installKind === "git") {
260+
if (channel === "extended-stable" && installKind === "git") {
261261
await reportPreMutationUpdateFailure({
262262
root,
263263
installKind,
@@ -267,19 +267,17 @@ async function updateCommandInternal(
267267
});
268268
return;
269269
}
270-
const switchToGit = requestedChannel === "dev" && installKind !== "git";
270+
// An effective dev channel (stored or explicit) selects the git flow — the
271+
// documented dev contract is a git checkout. Exception: --tag is a one-run
272+
// package-target override, so it keeps a stored-dev package install on the
273+
// package path; only an explicitly requested dev channel outranks it.
274+
const explicitTag = normalizeTag(opts.tag);
275+
const switchToGit =
276+
installKind !== "git" &&
277+
(requestedChannel === "dev" || (channel === "dev" && explicitTag === null));
271278
const switchToPackage =
272279
requestedChannel !== null && requestedChannel !== "dev" && installKind === "git";
273280
const updateInstallKind = switchToGit ? "git" : switchToPackage ? "package" : installKind;
274-
const channel =
275-
requestedChannel ??
276-
storedChannel ??
277-
(updateInstallKind === "git"
278-
? DEFAULT_GIT_CHANNEL
279-
: resolveEffectiveUpdateChannel({
280-
currentVersion: VERSION,
281-
installKind: updateInstallKind,
282-
}).channel);
283281
if (channel === "dev" && requestedChannel !== "dev") {
284282
const resolvedDevTarget = readDevUpdateTargetOrExit();
285283
if (!resolvedDevTarget.ok) {
@@ -288,7 +286,6 @@ async function updateCommandInternal(
288286
devTarget = resolvedDevTarget.target;
289287
}
290288

291-
const explicitTag = normalizeTag(opts.tag);
292289
const unsupportedMainTag = updateInstallKind === "package" && explicitTag === "main";
293290
if ((channel === "extended-stable" && explicitTag) || unsupportedMainTag) {
294291
await reportPreMutationUpdateFailure({

‎test/scripts/ci-changed-node-test-plan.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ it.each([
6565
[["scripts/e2e/cron-mcp-cleanup-seed.ts"], ["cron-mcp-cleanup"]],
6666
[["scripts/e2e/mcp-code-mode-gateway-seed.ts"], ["mcp-code-mode-gateway"]],
6767
[["scripts/e2e/lib/mcp-code-mode-probe-server.ts"], ["mcp-code-mode-gateway"]],
68+
[["scripts/e2e/update-channel-switch-docker.sh"], ["update-channel-switch"]],
69+
[["scripts/e2e/lib/update-channel-switch/assertions.mjs"], ["update-channel-switch"]],
70+
[
71+
[
72+
"scripts/e2e/update-channel-switch-docker.sh",
73+
"scripts/e2e/lib/update-channel-switch/assertions.mjs",
74+
"scripts/e2e/mcp-channels-seed.ts",
75+
],
76+
["mcp-channels", "update-channel-switch"],
77+
],
6878
[["scripts/e2e/docker-openai-seed.ts"], allDockerSeedLanes],
6979
[
7080
[

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4895,7 +4895,6 @@ source "$ROOT_DIR/scripts/lib/docker-e2e-logs.sh"
48954895
"assert-config-channel beta",
48964896
"assert-installed-version",
48974897
"assert-status-kind package",
4898-
"openclaw update --channel dev",
48994898
"openclaw update --channel stable",
49004899
]);
49014900
expect(updateRunner).toContain("openclaw update --channel beta --yes --json --no-restart");

0 commit comments

Comments
 (0)