Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions scripts/lib/bootstrap-maintenance.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { readFileSync } from "node:fs";
import { homedir } from "node:os";
import { join, resolve } from "node:path";
import { pathToFileURL } from "node:url";
Expand Down Expand Up @@ -30,6 +31,14 @@ function fail(code) {
throw new Error(code);
}

function currentPackageVersion() {
try {
return String(JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"))?.version || "").trim() || null;
} catch {
return null;
}
}

function defaultCodexHome() {
return resolve(process.env.CODEX_HOME || join(homedir(), ".codex"));
}
Expand Down Expand Up @@ -258,6 +267,9 @@ export async function runBootstrapDoctor({
const readAuthority = dependencies.readInstalledAuthorityHost || readInstalledAuthorityHost;
const readReceipt = dependencies.readActivationReceipt || readActivationReceipt;
const latestRelease = dependencies.latestRelease || (() => createGitHubReleaseClient().latestRelease());
const runtimeVersion = typeof dependencies.runtimeVersion === "function"
? dependencies.runtimeVersion()
: currentPackageVersion();

const environment = checkEnvironment();
const found = discover(target ? { explicitTarget: target } : {});
Expand All @@ -269,6 +281,7 @@ export async function runBootstrapDoctor({

const report = {
action: "doctor",
runtime: { packageVersion: runtimeVersion, relationToLatest: null },
environment,
target: selected?.target || (target ? resolve(target) : null),
installations: found,
Expand Down Expand Up @@ -355,6 +368,7 @@ export async function runBootstrapDoctor({
const match = /^v(\d+\.\d+\.\d+)$/.exec(tag);
if (!match) fail("stable_release_tag_invalid");
report.latest.version = match[1];
if (runtimeVersion) report.runtime.relationToLatest = relation(runtimeVersion, match[1]);
if (selected?.version) report.latest.relation = relation(selected.version, match[1]);
if (
report.authorityHost.ok &&
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/bootstrap-maintenance.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ test("doctor is read-only and reports integrity, activation, config, authority h
codexHome: CODEX_HOME,
dependencies: {
checkBootstrapEnvironment: () => ({ ok: true, node: { ok: true }, git: { ok: true }, gh: { ok: true }, ghAuth: { ok: true } }),
runtimeVersion: () => "9.9.9",
discoverInstallations: () => validInstallation(),
readInstalledManifest: () => manifest,
compareInstalledManifest: () => ({ clean: false, modifications: [{ path: "SKILL.md", reason: "changed" }] }),
Expand All @@ -314,6 +315,7 @@ test("doctor is read-only and reports integrity, activation, config, authority h

assert.deepEqual(mutations, []);
assert.equal(report.target, TARGET);
assert.deepEqual(report.runtime, { packageVersion: "9.9.9", relationToLatest: "already_ahead" });
assert.equal(report.installed.version, "0.4.0");
assert.equal(report.integrity.clean, false);
assert.equal(report.config.ok, true);
Expand Down
Loading