Skip to content

Commit c82b18f

Browse files
committed
fix(e2e): probe stored dev update routing
1 parent e339ce2 commit c82b18f

3 files changed

Lines changed: 89 additions & 3 deletions

File tree

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const controlUiHtml = "<!doctype html><title>fixture</title>\n";
99

1010
function usage() {
1111
console.error(
12-
"usage: assertions.mjs <prepare-git-fixture|write-control-ui|assert-update|assert-dry-run|assert-config-channel|assert-status-kind|assert-installed-version> [...]",
12+
"usage: assertions.mjs <prepare-git-fixture|write-control-ui|assert-update|assert-dry-run|resolve-stored-dev-route|assert-config-channel|assert-status-kind|assert-installed-version> [...]",
1313
);
1414
process.exit(2);
1515
}
@@ -214,6 +214,28 @@ function assertDryRun(kind, channel) {
214214
assert.equal(preview.switchToPackage, false);
215215
}
216216

217+
function resolveStoredDevRoute() {
218+
const preview = JSON.parse(process.env.UPDATE_JSON ?? "");
219+
assert.equal(preview.dryRun, true);
220+
assert.equal(preview.installKind, "package");
221+
assert.equal(preview.storedChannel, "dev");
222+
assert.equal(preview.effectiveChannel, "dev");
223+
assert.equal(preview.switchToPackage, false);
224+
if (preview.updateInstallKind === "git") {
225+
assert.equal(preview.mode, "git");
226+
assert.equal(preview.switchToGit, true);
227+
return "git";
228+
}
229+
if (preview.updateInstallKind === "package") {
230+
assert.equal(preview.mode, "npm");
231+
assert.equal(preview.switchToGit, false);
232+
return "package";
233+
}
234+
throw new Error(
235+
`expected stored dev dry run to advertise git or package routing, got ${String(preview.updateInstallKind)}`,
236+
);
237+
}
238+
217239
function assertStatusKind(kind) {
218240
const payload = JSON.parse(process.env.STATUS_JSON ?? "");
219241
if (payload.update?.installKind !== kind) {
@@ -246,6 +268,9 @@ switch (command) {
246268
case "assert-dry-run":
247269
assertDryRun(args[0], args[1]);
248270
break;
271+
case "resolve-stored-dev-route":
272+
console.log(resolveStoredDevRoute());
273+
break;
249274
case "assert-status-kind":
250275
assertStatusKind(args[0]);
251276
break;

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,23 @@ assert_package_dry_run() {
170170
dev_channel_args=(--channel dev)
171171
# Legacy package acceptance permits missing channel persistence; keep its explicit switch.
172172
if [ "$OPENCLAW_PACKAGE_ACCEPTANCE_LEGACY_COMPAT" != "1" ]; then
173-
echo "==> package dry-run channel and one-off tag precedence"
173+
echo "==> package dry-run channel capability and one-off tag precedence"
174174
openclaw config set update.channel dev
175-
assert_package_dry_run git dev
175+
stored_dev_preview="$(openclaw update --dry-run --json --no-restart)"
176+
printf "%s\n" "$stored_dev_preview"
177+
stored_dev_route="$(UPDATE_JSON="$stored_dev_preview" node scripts/e2e/lib/update-channel-switch/assertions.mjs resolve-stored-dev-route)"
178+
case "$stored_dev_route" in
179+
git)
180+
dev_channel_args=()
181+
;;
182+
package)
183+
# Frozen packages before stored-channel git routing still support explicit dev.
184+
;;
185+
*)
186+
echo "unknown stored dev route: $stored_dev_route" >&2
187+
exit 1
188+
;;
189+
esac
176190
assert_package_dry_run git dev --channel dev
177191
assert_package_dry_run git dev --channel dev --tag beta
178192
assert_package_dry_run package dev --tag beta
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Update-channel switch Docker assertions accept the candidate's advertised dry-run route.
2+
import { spawnSync } from "node:child_process";
3+
import { describe, expect, it } from "vitest";
4+
5+
const ASSERTIONS_SCRIPT = "scripts/e2e/lib/update-channel-switch/assertions.mjs";
6+
7+
function resolveStoredDevRoute(preview: Record<string, unknown>) {
8+
return spawnSync(process.execPath, [ASSERTIONS_SCRIPT, "resolve-stored-dev-route"], {
9+
encoding: "utf8",
10+
env: { ...process.env, UPDATE_JSON: JSON.stringify(preview) },
11+
});
12+
}
13+
14+
describe("update-channel switch Docker assertions", () => {
15+
it.each([
16+
["git", { mode: "git", switchToGit: true, updateInstallKind: "git" }],
17+
["package", { mode: "npm", switchToGit: false, updateInstallKind: "package" }],
18+
])("uses the advertised stored dev %s route", (expectedRoute, route) => {
19+
const result = resolveStoredDevRoute({
20+
dryRun: true,
21+
installKind: "package",
22+
storedChannel: "dev",
23+
effectiveChannel: "dev",
24+
switchToPackage: false,
25+
...route,
26+
});
27+
28+
expect(result.status, result.stderr).toBe(0);
29+
expect(result.stdout.trim()).toBe(expectedRoute);
30+
});
31+
32+
it("rejects an inconsistent advertised route", () => {
33+
const result = resolveStoredDevRoute({
34+
dryRun: true,
35+
installKind: "package",
36+
storedChannel: "dev",
37+
effectiveChannel: "dev",
38+
mode: "npm",
39+
switchToGit: false,
40+
switchToPackage: false,
41+
updateInstallKind: "git",
42+
});
43+
44+
expect(result.status).not.toBe(0);
45+
expect(result.stderr).toContain("Expected values to be strictly equal");
46+
});
47+
});

0 commit comments

Comments
 (0)