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
5 changes: 2 additions & 3 deletions packages/gittensory-miner/bin/gittensory-miner.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node
import { createRequire } from "node:module";
import { printHelp, printVersion, runCli } from "../lib/cli.js";
import { runDenyCheck } from "../lib/deny-check.js";
import { runGovernorCli } from "../lib/governor-ledger-cli.js";
Expand All @@ -16,6 +15,7 @@ import {
resolveUpgradeCommand,
startUpdateCheck,
} from "../lib/update-check.js";
import { resolveMinerVersion } from "../lib/version.js";

const cliArgs = process.argv.slice(2);

Expand Down Expand Up @@ -54,9 +54,8 @@ if (cliArgs[0] === "governor") {
process.exit(await runGovernorCli(cliArgs[1], cliArgs.slice(2)));
}

const require = createRequire(import.meta.url);
const packageName = "@jsonbored/gittensory-miner";
const packageVersion = require("../package.json").version;
const packageVersion = resolveMinerVersion(process.env);
const upgradeCommand = resolveUpgradeCommand(packageName);

const updateCheck = startUpdateCheck(cliArgs, {
Expand Down
11 changes: 2 additions & 9 deletions packages/gittensory-miner/lib/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createRequire } from "node:module";
import { homedir } from "node:os";
import { join } from "node:path";
import { checkDockerPresent, checkLaptopStateSqlite } from "./laptop-init.js";
import { resolveMinerVersion } from "./version.js";

// Slim laptop-mode CLI commands (#2288): `status` (what's installed + where local state lives) and `doctor` (is
// this laptop set up correctly). Both are read-only and 100% local — no repo-scanning, no coding-agent invocation,
Expand Down Expand Up @@ -33,14 +34,6 @@ export function resolveMinerStateDir(env = process.env) {
return join(configHome, "gittensory-miner");
}

function readOwnVersion() {
try {
return require("../package.json").version ?? null;
} catch {
return null;
}
}

// The pinned @jsonbored/gittensory-engine version this miner is built against, read from the miner's own declared
// dependency. (The engine package's `exports` map blocks `require("<pkg>/package.json")`, and its built `dist` may
// be absent depending on build order, so the declared-dependency version is the reliable, always-available source.)
Expand Down Expand Up @@ -71,7 +64,7 @@ function discoverConfigFile(cwd) {
export function collectStatus(env = process.env, cwd = process.cwd()) {
const stateDir = resolveMinerStateDir(env);
return {
package: { name: PACKAGE_NAME, version: readOwnVersion() },
package: { name: PACKAGE_NAME, version: resolveMinerVersion(env) },
engine: { name: ENGINE_PACKAGE, version: readEngineVersion() },
node: process.version,
stateDir,
Expand Down
3 changes: 3 additions & 0 deletions packages/gittensory-miner/lib/version.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const MINER_PACKAGE_VERSION: string;

export function resolveMinerVersion(env?: Record<string, string | undefined>): string;
10 changes: 10 additions & 0 deletions packages/gittensory-miner/lib/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ownPackageJson from "../package.json" with { type: "json" };

/** Package.json semver at import time — the laptop npm-install default. */
export const MINER_PACKAGE_VERSION = ownPackageJson.version;

/** Resolved miner release id: `GITTENSORY_MINER_VERSION` wins when set (fleet Docker image builds). */
export function resolveMinerVersion(env = process.env) {
const override = typeof env.GITTENSORY_MINER_VERSION === "string" ? env.GITTENSORY_MINER_VERSION.trim() : "";
return override || MINER_PACKAGE_VERSION;
}
2 changes: 1 addition & 1 deletion packages/gittensory-miner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"lib"
],
"scripts": {
"build": "node --check bin/gittensory-miner.js && node --check lib/cli.js && node --check lib/deny-check.js && node --check lib/run-state-cli.js && node --check lib/update-check.js && node --check lib/opportunity-fanout.js && node --check lib/ci-poller.js && node --check lib/run-state.js && node --check lib/deny-hooks.js && node --check lib/event-ledger.js && node --check lib/event-ledger-cli.js && node --check lib/claim-ledger.js && node --check lib/claim-ledger-expiry.js && node --check lib/portfolio-queue.js && node --check lib/portfolio-queue-cli.js && node --check lib/portfolio-discovery.js && node --check lib/opportunity-ranker.js && node --check lib/plan-store.js && node --check lib/plan-store-cli.js && node --check lib/rejection-templates.js && node --check lib/governor-ledger.js && node --check lib/governor-ledger-cli.js && node --check lib/manage-status.js && node --check lib/manage-poll.js && node --check lib/status.js && node --check lib/laptop-init.js && node --check lib/replay-objective-anchor.js && node --check lib/replay-task-generation.js && node --check lib/calibration-types.js && node --check lib/calibration.js"
"build": "node --check bin/gittensory-miner.js && node --check lib/version.js && node --check lib/cli.js && node --check lib/deny-check.js && node --check lib/run-state-cli.js && node --check lib/update-check.js && node --check lib/opportunity-fanout.js && node --check lib/ci-poller.js && node --check lib/run-state.js && node --check lib/deny-hooks.js && node --check lib/event-ledger.js && node --check lib/event-ledger-cli.js && node --check lib/claim-ledger.js && node --check lib/claim-ledger-expiry.js && node --check lib/portfolio-queue.js && node --check lib/portfolio-queue-cli.js && node --check lib/portfolio-discovery.js && node --check lib/opportunity-ranker.js && node --check lib/plan-store.js && node --check lib/plan-store-cli.js && node --check lib/rejection-templates.js && node --check lib/governor-ledger.js && node --check lib/governor-ledger-cli.js && node --check lib/manage-status.js && node --check lib/manage-poll.js && node --check lib/status.js && node --check lib/laptop-init.js && node --check lib/replay-objective-anchor.js && node --check lib/replay-task-generation.js && node --check lib/calibration-types.js && node --check lib/calibration.js"
},
"dependencies": {
"@jsonbored/gittensory-engine": ">=0.1.0 <1.0.0"
Expand Down
5 changes: 5 additions & 0 deletions test/unit/miner-package-skeleton.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ describe("gittensory-miner package skeleton (#2287)", () => {
it("serves --help and --version from the bin entry", () => {
expect(runCapture(["--help", "--no-update-check"])).toContain("gittensory-miner --help");
expect(runCapture(["--version", "--no-update-check"])).toContain("@jsonbored/gittensory-miner/");
expect(
runCapture(["--version", "--no-update-check"], {
GITTENSORY_MINER_VERSION: "gittensory-miner-fleet@abc1234",
}),
).toContain("gittensory-miner-fleet@abc1234");
});

it("documents foundation scope and local checkout install paths in the README", () => {
Expand Down
11 changes: 11 additions & 0 deletions test/unit/miner-status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ describe("gittensory-miner status/doctor (#2288)", () => {
expect(status.configFile).toBe(join(root, ".gittensory-miner.yml")); // discovered
});

it("collectStatus prefers GITTENSORY_MINER_VERSION over package.json (#4310)", () => {
const status = collectStatus(
{
GITTENSORY_MINER_CONFIG_DIR: "/s",
GITTENSORY_MINER_VERSION: "gittensory-miner-fleet@deadbeef",
},
tempRoot(),
);
expect(status.package.version).toBe("gittensory-miner-fleet@deadbeef");
});

it("runStatus prints human-readable text (0) and machine JSON with --json", () => {
const log = vi.spyOn(console, "log").mockImplementation(() => {});
expect(runStatus([], { GITTENSORY_MINER_CONFIG_DIR: "/s" }, tempRoot())).toBe(0);
Expand Down
23 changes: 23 additions & 0 deletions test/unit/miner-version.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expect, it } from "vitest";
import {
MINER_PACKAGE_VERSION,
resolveMinerVersion,
} from "../../packages/gittensory-miner/lib/version.js";

describe("gittensory-miner version resolution (#4310)", () => {
it("defaults to the package.json semver when GITTENSORY_MINER_VERSION is unset", () => {
expect(MINER_PACKAGE_VERSION).toMatch(/^\d+\.\d+\.\d+$/);
expect(resolveMinerVersion({})).toBe(MINER_PACKAGE_VERSION);
expect(resolveMinerVersion({ GITTENSORY_MINER_VERSION: "" })).toBe(MINER_PACKAGE_VERSION);
expect(resolveMinerVersion({ GITTENSORY_MINER_VERSION: " " })).toBe(MINER_PACKAGE_VERSION);
});

it("prefers a nonblank GITTENSORY_MINER_VERSION override (fleet Docker build ref)", () => {
expect(
resolveMinerVersion({ GITTENSORY_MINER_VERSION: "gittensory-miner-fleet@abc1234" }),
).toBe("gittensory-miner-fleet@abc1234");
expect(
resolveMinerVersion({ GITTENSORY_MINER_VERSION: " 0.9.0-beta.1 " }),
).toBe("0.9.0-beta.1");
});
});