diff --git a/CHANGELOG.md b/CHANGELOG.md index b0e2dfe5b..605f318f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f ## [Unreleased] +### Fixed + +- **An idle 0.6.0–0.7.1 host takes its normal update again.** Once the v0.7.2 release (and with it the recovery helper for these daemons) was published, the server marked every such host as needing recovery and refused its plain update with "This host requires explicitly approved recovery", so only Force worked. A plain update now runs the daemon's own updater, as before; recovery is used only for an explicit Force (or an approved release pin or phase these daemons cannot enforce). Host update tests no longer depend on what GitHub currently publishes. + ## [v0.7.2] - 2026-11-18 ### Upgrading from 0.7.1 or older diff --git a/lib/hosts/host-updates-route.test.mjs b/lib/hosts/host-updates-route.test.mjs index c075ff408..39c29c28a 100644 --- a/lib/hosts/host-updates-route.test.mjs +++ b/lib/hosts/host-updates-route.test.mjs @@ -3,14 +3,17 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { delimiter, join } from "node:path"; import test, { after } from "node:test"; +import { stubRecoveryRelease } from "./recovery-release.test-helper.mjs"; const dir = mkdtempSync(join(tmpdir(), "ompweb-host-updates-route-")); const previous = process.env.PI_CODING_AGENT_DIR; process.env.PI_CODING_AGENT_DIR = dir; const hub = await import("./hub.ts"); -const { linkHost, linkLocalHost } = await import("./link-driver.test-helper.mjs"); +const { linkHost, linkLocalHost, until } = await import("./link-driver.test-helper.mjs"); const { HostOpError, MIN_LINK_PROTOCOL_VERSION, LINK_PROTOCOL_VERSION } = await import("./link-protocol.ts"); +const restoreFetch = stubRecoveryRelease(); after(() => { + restoreFetch(); hub.flushLinkSamples(); if (previous === undefined) delete process.env.PI_CODING_AGENT_DIR; else process.env.PI_CODING_AGENT_DIR = previous; @@ -60,6 +63,28 @@ for (const local of [false, true]) test(`software checks and updates target only for (const [, args] of seen) assert.deepEqual(args.compatibility, { min: MIN_LINK_PROTOCOL_VERSION, max: LINK_PROTOCOL_VERSION }); }); +test("with the recovery helper published, a plain update of an old daemon uses its own updater and only Force uses the recovery", async (t) => { + const r = await route(); + const link = await linkHost("Old daemon", { hello: { ompwebVersion: "0.6.0" } }); + const asked = []; + const serving = link.serve({ + checkUpdates: () => info(), + updateSoftware: () => { asked.push("updateSoftware"); return { accepted: true, operation }; }, + open: () => { asked.push("open"); return { ch: "recovery", joined: true, pending: [], streaming: null, cwd: "/home/u", fellBack: false, launchAdvisor: false, advisorSpawned: false, autoApproveExtension: false }; }, + close: () => ({}), + }); + t.after(async () => { hub.closeHostLink(link.id); await serving; }); + const checked = await (await r.GET(new Request(`http://main.test/api/hosts/${link.id}/updates?force=1`), context(link.id))).json(); + assert.deepEqual([checked.ompweb.canUpdate, checked.ompweb.canForceUpdate, checked.ompweb.forceMethod], [true, true, "recovery"]); + const plain = await post(r, link.id); + assert.equal(plain.status, 202); + assert.deepEqual(asked, ["updateSoftware"], "a plain update never opens the recovery"); + const forced = await post(r, link.id, { ...body, force: true }); + assert.equal(forced.status, 202); + await until(() => asked.includes("open"), "the forced update to open the recovery channel"); + assert.deepEqual(asked, ["updateSoftware", "open"], "Force bypasses the old updater"); +}); + for (const state of ["running", "succeeded", "failed"]) test(`retry returns the existing ${state} operation even when no update is eligible`, async (t) => { const link = await linkHost("Retry host"); t.after(() => link.drop()); diff --git a/lib/hosts/hub.ts b/lib/hosts/hub.ts index e5d488e9d..e660ae3fa 100644 --- a/lib/hosts/hub.ts +++ b/lib/hosts/hub.ts @@ -1823,7 +1823,8 @@ export async function updateHostSoftware(id: string, target: HostUpdateTarget, v } const candidate = checked[target]; const link = linkFor(id); - const recovery = candidate.forceMethod === "recovery" || options.phase !== undefined && candidate.supportsTwoPhaseUpdate !== true; + // A plain update of an old daemon runs its own updater: Force and a pin or phase it cannot enforce are what recovery is for. + const recovery = (options.force || options.releasePin !== undefined) && candidate.forceMethod === "recovery" || options.phase !== undefined && candidate.supportsTwoPhaseUpdate !== true; const pinnedRecovery = options.releasePin !== undefined && recovery; if (!matching && (!candidate.updateAvailable || !(options.force ? candidate.canForceUpdate || candidate.canUpdate : candidate.canUpdate) || candidate.availableVersion !== version && !pinnedRecovery)) { // An omp update names its blocker (ompweb_update_active, omp_install_active...) for a caller that must not read English. diff --git a/lib/hosts/recovery-release.test-helper.mjs b/lib/hosts/recovery-release.test-helper.mjs new file mode 100644 index 000000000..5ff608d9c --- /dev/null +++ b/lib/hosts/recovery-release.test-helper.mjs @@ -0,0 +1,17 @@ +// Not a test file itself. Tests that route a legacy daemon's update must not depend on what GitHub serves today. +// Before this build's release is published its lookup fails; afterwards it succeeds and an old daemon gains a Force +// (recovery) route. Stubbing the lookup pins the production state: the recovery helper is published and available. + +/** Answer the release lookup of this build with a published release; every other request goes to the real fetch. + * Returns the function that restores `fetch`. */ +export function stubRecoveryRelease() { + const real = globalThis.fetch; + globalThis.fetch = async (input, init) => { + const url = String(input instanceof Request ? input.url : input); + if (!/^https:\/\/api\.github\.com\/repos\/[^/]+\/[^/]+\/releases\/tags\//.test(url)) return real(input, init); + const { installedRecoveryTag } = await import("../recovery-release.ts"); + const assets = ["linux-x64.tar.gz", "darwin-arm64.tar.gz", "windows-x64.zip"].map((name) => ({ name: `ompweb-${name}`, digest: `sha256:${"a".repeat(64)}` })); + return Response.json({ tag_name: installedRecoveryTag(), assets }); + }; + return () => { globalThis.fetch = real; }; +} diff --git a/lib/hosts/upgrade-shim.test.mjs b/lib/hosts/upgrade-shim.test.mjs index 0c2891142..f5c960500 100644 --- a/lib/hosts/upgrade-shim.test.mjs +++ b/lib/hosts/upgrade-shim.test.mjs @@ -3,6 +3,7 @@ import { mkdtempSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import test, { after } from "node:test"; +import { stubRecoveryRelease } from "./recovery-release.test-helper.mjs"; const dir = mkdtempSync(join(tmpdir(), "ompweb-upgrade-shim-")); const previous = process.env.PI_CODING_AGENT_DIR; @@ -11,7 +12,9 @@ const hub = await import("./hub.ts"); const { linkHost, upgradeSocket, until } = await import("./link-driver.test-helper.mjs"); const { LINK_PROTOCOL_VERSION } = await import("./link-protocol.ts"); const { getRpcSession } = await import("../rpc-manager.ts"); +const restoreFetch = stubRecoveryRelease(); after(() => { + restoreFetch(); hub.flushLinkSamples(); if (previous === undefined) delete process.env.PI_CODING_AGENT_DIR; else process.env.PI_CODING_AGENT_DIR = previous; diff --git a/lib/hosts/v10-upgrade.integration.test.mjs b/lib/hosts/v10-upgrade.integration.test.mjs index daf77be95..3c4862ac5 100644 --- a/lib/hosts/v10-upgrade.integration.test.mjs +++ b/lib/hosts/v10-upgrade.integration.test.mjs @@ -35,6 +35,7 @@ import { chmodSync, cpSync, existsSync, mkdirSync, mkdtempSync, readdirSync, rea import { tmpdir } from "node:os"; import { delimiter, dirname, join } from "node:path"; import { pathToFileURL } from "node:url"; +import { stubRecoveryRelease } from "./recovery-release.test-helper.mjs"; import { nodeBinary, repo, repoVersion, spawnNodeOutsideService } from "./update-fixture.test-helper.mjs"; const LEGACY = { @@ -125,7 +126,9 @@ async function stopAll(dir) { assert.deepEqual(processesUnder(dir), [], "every process this test started must exit before its directory is removed"); } +const restoreFetch = stubRecoveryRelease(); after(async () => { + restoreFetch(); if (process.platform !== "win32") await stopAll(base); await server.stop(true); closeNotificationStore();