Add local dev binary override and Git-aware versioning
This commit is contained in:
1 parent
83ade4dbf9
commit
883690e128
9 files changed
+585
-24
No files matched your search
@@ -37,6 +37,25 @@ describe("CLI version & help handling", () => {
|
||||
const parsed = JSON.parse(result.stdout.trim());
|
||||
expect(parsed.name).toBe("seal-use");
|
||||
expect(parsed.version).toBe(VERSION);
|
||||
expect(parsed).toHaveProperty("channel");
|
||||
expect(parsed).toHaveProperty("isRelease");
|
||||
});
|
||||
|
||||
test("version output includes structured dev channel and git information", () => {
|
||||
const result = runCli(["v"]);
|
||||
expect(result.status).toBe(0);
|
||||
const parsed = JSON.parse(result.stdout.trim());
|
||||
expect(parsed.name).toBe("seal-use");
|
||||
expect(typeof parsed.channel).toBe("string");
|
||||
expect(typeof parsed.isRelease).toBe("boolean");
|
||||
if (!parsed.isRelease) {
|
||||
expect(parsed.channel).toBe("dev");
|
||||
if (parsed.git) {
|
||||
expect(parsed.git).toHaveProperty("baseVersion");
|
||||
expect(parsed.git).toHaveProperty("commitsAhead");
|
||||
expect(parsed.git).toHaveProperty("commit");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("help command prints standard help banner", () => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { dirname, join } from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { isCompiledBinary } from "../../core/runtime.js";
|
||||
import { syncGlobalSkillIfPresent } from "../../core/embedded-skill.js";
|
||||
import { VERSION } from "../../version.js";
|
||||
import { VERSION, IS_RELEASE } from "../../version.js";
|
||||
import { runServiceCommand, serviceStatus } from "../service.js";
|
||||
import { printJson } from "../printer.js";
|
||||
import { STATE_DIR } from "./service.js";
|
||||
@@ -46,14 +46,20 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
|
||||
const cleanTarget = targetVersion.replace(/^v/, "");
|
||||
const cmp = compareSemVer(cleanTarget, VERSION);
|
||||
if (cmp < 0) {
|
||||
printJson({
|
||||
updated: false,
|
||||
currentVersion: VERSION,
|
||||
targetVersion: cleanTarget,
|
||||
mode: isCompiledBinary() ? "binary" : "source",
|
||||
message: `Cannot downgrade seal-use from v${VERSION} to older version v${cleanTarget}. Updates must be forward-only.`
|
||||
});
|
||||
return;
|
||||
if (!IS_RELEASE && options.force) {
|
||||
// Allow force reinstall/switch from dev build to target release
|
||||
} else {
|
||||
printJson({
|
||||
updated: false,
|
||||
currentVersion: VERSION,
|
||||
targetVersion: cleanTarget,
|
||||
mode: isCompiledBinary() ? "binary" : "source",
|
||||
message: !IS_RELEASE
|
||||
? `Cannot downgrade seal-use from dev build v${VERSION} to release v${cleanTarget}. Use --force to overwrite.`
|
||||
: `Cannot downgrade seal-use from v${VERSION} to older version v${cleanTarget}. Updates must be forward-only.`
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (cmp === 0 && !options.force) {
|
||||
printJson({
|
||||
|
||||
+2
-5
@@ -4,7 +4,7 @@ import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { createSealClient } from "../core/http/factory.js";
|
||||
import type { CorpConfig } from "../core/config/types.js";
|
||||
import { VERSION } from "../version.js";
|
||||
import { VERSION, VERSION_INFO } from "../version.js";
|
||||
import { handleApprovalRunsCommand } from "./commands/approval-runs.js";
|
||||
import { handleAnalyticsCommand } from "./commands/analytics.js";
|
||||
import { handleAuthCommand } from "./commands/auth.js";
|
||||
@@ -174,10 +174,7 @@ async function dispatch(argv: string[], runtime: CliRuntime) {
|
||||
Boolean(args.options.v) ||
|
||||
Boolean(args.options.V)
|
||||
) {
|
||||
printJson({
|
||||
name: "seal-use",
|
||||
version: VERSION
|
||||
});
|
||||
printJson(VERSION_INFO);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { formatDevVersion, parseGitDescribe, resolveVersionInfo } from "./version.js";
|
||||
import { compareSemVer, isNewerVersion } from "./cli/commands/update.js";
|
||||
|
||||
describe("Git version parsing and formatting", () => {
|
||||
test("parses full git describe string with commits ahead and dirty state", () => {
|
||||
const parsed = parseGitDescribe("v0.10.15-2-ga521a24-dirty");
|
||||
expect(parsed).toEqual({
|
||||
baseVersion: "0.10.15",
|
||||
commitsAhead: 2,
|
||||
commit: "a521a24",
|
||||
dirty: true,
|
||||
describe: "v0.10.15-2-ga521a24-dirty"
|
||||
});
|
||||
});
|
||||
|
||||
test("parses clean git describe string without dirty suffix", () => {
|
||||
const parsed = parseGitDescribe("v0.10.15-0-g83ade4d");
|
||||
expect(parsed).toEqual({
|
||||
baseVersion: "0.10.15",
|
||||
commitsAhead: 0,
|
||||
commit: "83ade4d",
|
||||
dirty: false,
|
||||
describe: "v0.10.15-0-g83ade4d"
|
||||
});
|
||||
});
|
||||
|
||||
test("parses tag-only git describe with dirty status", () => {
|
||||
const parsed = parseGitDescribe("v0.10.15-dirty");
|
||||
expect(parsed).toEqual({
|
||||
baseVersion: "0.10.15",
|
||||
commitsAhead: 0,
|
||||
commit: "",
|
||||
dirty: true,
|
||||
describe: "v0.10.15-dirty"
|
||||
});
|
||||
});
|
||||
|
||||
test("parses raw commit hash fallback", () => {
|
||||
const parsed = parseGitDescribe("83ade4d-dirty", "0.10.15");
|
||||
expect(parsed).toEqual({
|
||||
baseVersion: "0.10.15",
|
||||
commitsAhead: 0,
|
||||
commit: "83ade4d",
|
||||
dirty: true,
|
||||
describe: "83ade4d-dirty"
|
||||
});
|
||||
});
|
||||
|
||||
test("returns null for empty or invalid describe strings", () => {
|
||||
expect(parseGitDescribe("")).toBeNull();
|
||||
expect(parseGitDescribe(" ")).toBeNull();
|
||||
expect(parseGitDescribe("invalid/string/without/semver")).toBeNull();
|
||||
});
|
||||
|
||||
test("formats dev version according to standard SemVer 2.0 rules", () => {
|
||||
expect(formatDevVersion("0.10.15", 2, "a521a24", false)).toBe("0.10.15-dev.2+ga521a24");
|
||||
expect(formatDevVersion("0.10.15", 2, "a521a24", true)).toBe("0.10.15-dev.2+ga521a24.dirty");
|
||||
expect(formatDevVersion("0.10.15", 0, "83ade4d", false)).toBe("0.10.15-dev.0+g83ade4d");
|
||||
expect(formatDevVersion("0.10.15", 0, "83ade4d", true)).toBe("0.10.15-dev.0+g83ade4d.dirty");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveVersionInfo configuration modes", () => {
|
||||
test("resolves inlined environment variables when preset", () => {
|
||||
const info = resolveVersionInfo({
|
||||
env: {
|
||||
SEAL_BUILD_VERSION: "0.10.15-dev.3+g9a7be16",
|
||||
SEAL_BUILD_CHANNEL: "dev",
|
||||
SEAL_BUILD_IS_RELEASE: "false",
|
||||
SEAL_BUILD_GIT_BASE: "0.10.15",
|
||||
SEAL_BUILD_GIT_COMMITS_AHEAD: "3",
|
||||
SEAL_BUILD_GIT_COMMIT: "9a7be16",
|
||||
SEAL_BUILD_GIT_DIRTY: "false",
|
||||
SEAL_BUILD_GIT_DESCRIBE: "v0.10.15-3-g9a7be16"
|
||||
}
|
||||
});
|
||||
|
||||
expect(info.name).toBe("seal-use");
|
||||
expect(info.version).toBe("0.10.15-dev.3+g9a7be16");
|
||||
expect(info.channel).toBe("dev");
|
||||
expect(info.isRelease).toBe(false);
|
||||
expect(info.git).toBeDefined();
|
||||
expect(info.git?.baseVersion).toBe("0.10.15");
|
||||
expect(info.git?.commitsAhead).toBe(3);
|
||||
expect(info.git?.commit).toBe("9a7be16");
|
||||
expect(info.git?.dirty).toBe(false);
|
||||
});
|
||||
|
||||
test("resolves release mode when SEAL_FORCE_RELEASE is set", () => {
|
||||
const info = resolveVersionInfo({
|
||||
env: {
|
||||
SEAL_FORCE_RELEASE: "1"
|
||||
}
|
||||
});
|
||||
|
||||
expect(info.name).toBe("seal-use");
|
||||
expect(info.channel).toBe("release");
|
||||
expect(info.isRelease).toBe(true);
|
||||
expect(info.git).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("compareSemVer dev version handling", () => {
|
||||
test("recognizes future release as newer than dev build", () => {
|
||||
expect(isNewerVersion("0.10.16", "0.10.15-dev.2+ga521a24")).toBe(true);
|
||||
expect(isNewerVersion("0.11.0", "0.10.15-dev.2+ga521a24")).toBe(true);
|
||||
expect(isNewerVersion("1.0.0", "0.10.15-dev.2+ga521a24")).toBe(true);
|
||||
});
|
||||
|
||||
test("recognizes base release as older than ahead dev build", () => {
|
||||
expect(compareSemVer("0.10.15", "0.10.15-dev.2+ga521a24")).toBe(-1);
|
||||
expect(isNewerVersion("0.10.15", "0.10.15-dev.2+ga521a24")).toBe(false);
|
||||
});
|
||||
|
||||
test("correctly compares dev builds by commits ahead", () => {
|
||||
expect(compareSemVer("0.10.15-dev.3", "0.10.15-dev.2")).toBe(1);
|
||||
expect(compareSemVer("0.10.15-dev.1", "0.10.15-dev.2")).toBe(-1);
|
||||
});
|
||||
|
||||
test("identifies older legacy release as downgrade", () => {
|
||||
expect(compareSemVer("0.3.3", "0.10.15-dev.2+ga521a24")).toBe(-1);
|
||||
});
|
||||
});
|
||||
+173
-1
@@ -1,3 +1,175 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import packageJson from "../package.json" with { type: "json" };
|
||||
|
||||
export const VERSION = packageJson.version;
|
||||
export interface GitBuildInfo {
|
||||
baseVersion: string;
|
||||
commitsAhead: number;
|
||||
commit: string;
|
||||
dirty: boolean;
|
||||
describe: string;
|
||||
}
|
||||
|
||||
export interface VersionInfo {
|
||||
name: "seal-use";
|
||||
version: string;
|
||||
channel: "release" | "dev";
|
||||
isRelease: boolean;
|
||||
git?: GitBuildInfo;
|
||||
}
|
||||
|
||||
export function parseGitDescribe(output: string, fallbackVersion = packageJson.version): GitBuildInfo | null {
|
||||
const trimmed = output.trim();
|
||||
if (!trimmed) return null;
|
||||
|
||||
const dirty = trimmed.endsWith("-dirty");
|
||||
const clean = dirty ? trimmed.slice(0, -6) : trimmed;
|
||||
|
||||
// Format 1: v0.10.15-2-ga521a24
|
||||
const longMatch = clean.match(/^v?(\d+\.\d+\.\d+(?:-[a-zA-Z0-9.]+)?)-(\d+)-g([0-9a-f]+)$/);
|
||||
if (longMatch && longMatch[1] && longMatch[2] && longMatch[3]) {
|
||||
return {
|
||||
baseVersion: longMatch[1],
|
||||
commitsAhead: Number.parseInt(longMatch[2], 10),
|
||||
commit: longMatch[3],
|
||||
dirty,
|
||||
describe: trimmed
|
||||
};
|
||||
}
|
||||
|
||||
// Format 2: v0.10.15
|
||||
const tagMatch = clean.match(/^v?(\d+\.\d+\.\d+(?:-[a-zA-Z0-9.]+)?)$/);
|
||||
if (tagMatch && tagMatch[1]) {
|
||||
return {
|
||||
baseVersion: tagMatch[1],
|
||||
commitsAhead: 0,
|
||||
commit: "",
|
||||
dirty,
|
||||
describe: trimmed
|
||||
};
|
||||
}
|
||||
|
||||
// Format 3: 83ade4d
|
||||
const commitMatch = clean.match(/^([0-9a-f]{7,40})$/);
|
||||
if (commitMatch && commitMatch[1]) {
|
||||
return {
|
||||
baseVersion: fallbackVersion,
|
||||
commitsAhead: 0,
|
||||
commit: commitMatch[1],
|
||||
dirty,
|
||||
describe: trimmed
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function formatDevVersion(baseVersion: string, commitsAhead: number, commit: string, dirty: boolean): string {
|
||||
const dirtySuffix = dirty ? ".dirty" : "";
|
||||
const commitSuffix = commit ? `+g${commit}${dirtySuffix}` : dirty ? "+dirty" : "";
|
||||
return `${baseVersion}-dev.${commitsAhead}${commitSuffix}`;
|
||||
}
|
||||
|
||||
export function resolveVersionInfo(options?: {
|
||||
env?: Record<string, string | undefined>;
|
||||
cwd?: string;
|
||||
}): VersionInfo {
|
||||
const customEnv = options?.env;
|
||||
const buildVersion = customEnv?.SEAL_BUILD_VERSION ?? process.env.SEAL_BUILD_VERSION;
|
||||
const buildIsRelease = customEnv?.SEAL_BUILD_IS_RELEASE ?? process.env.SEAL_BUILD_IS_RELEASE;
|
||||
const buildChannel = customEnv?.SEAL_BUILD_CHANNEL ?? process.env.SEAL_BUILD_CHANNEL;
|
||||
const buildGitBase = customEnv?.SEAL_BUILD_GIT_BASE ?? process.env.SEAL_BUILD_GIT_BASE;
|
||||
const buildGitCommitsAhead = customEnv?.SEAL_BUILD_GIT_COMMITS_AHEAD ?? process.env.SEAL_BUILD_GIT_COMMITS_AHEAD;
|
||||
const buildGitCommit = customEnv?.SEAL_BUILD_GIT_COMMIT ?? process.env.SEAL_BUILD_GIT_COMMIT;
|
||||
const buildGitDirty = customEnv?.SEAL_BUILD_GIT_DIRTY ?? process.env.SEAL_BUILD_GIT_DIRTY;
|
||||
const buildGitDescribe = customEnv?.SEAL_BUILD_GIT_DESCRIBE ?? process.env.SEAL_BUILD_GIT_DESCRIBE;
|
||||
const forceRelease = customEnv?.SEAL_FORCE_RELEASE ?? process.env.SEAL_FORCE_RELEASE;
|
||||
const cwd = options?.cwd;
|
||||
|
||||
// 1. Check compile-time inlined environment variables
|
||||
if (buildVersion) {
|
||||
const isRelease = buildIsRelease === "true";
|
||||
const channel = (buildChannel as "release" | "dev") || (isRelease ? "release" : "dev");
|
||||
const result: VersionInfo = {
|
||||
name: "seal-use",
|
||||
version: buildVersion,
|
||||
channel,
|
||||
isRelease
|
||||
};
|
||||
|
||||
if (buildGitBase) {
|
||||
result.git = {
|
||||
baseVersion: buildGitBase,
|
||||
commitsAhead: Number.parseInt(buildGitCommitsAhead || "0", 10),
|
||||
commit: buildGitCommit || "",
|
||||
dirty: buildGitDirty === "true",
|
||||
describe: buildGitDescribe || buildVersion
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 2. Explicit force release via environment
|
||||
if (buildIsRelease === "true" || forceRelease === "1") {
|
||||
return {
|
||||
name: "seal-use",
|
||||
version: packageJson.version,
|
||||
channel: "release",
|
||||
isRelease: true
|
||||
};
|
||||
}
|
||||
|
||||
// 3. Dynamic resolution from git repository in dev mode
|
||||
try {
|
||||
const res = spawnSync("git", ["describe", "--tags", "--long", "--dirty", "--always"], {
|
||||
cwd,
|
||||
encoding: "utf8",
|
||||
stdio: ["ignore", "pipe", "ignore"]
|
||||
});
|
||||
|
||||
if (res.status === 0 && res.stdout) {
|
||||
const gitInfo = parseGitDescribe(res.stdout.trim(), packageJson.version);
|
||||
if (gitInfo) {
|
||||
if (!gitInfo.commit) {
|
||||
const revRes = spawnSync("git", ["rev-parse", "--short", "HEAD"], {
|
||||
cwd,
|
||||
encoding: "utf8",
|
||||
stdio: ["ignore", "pipe", "ignore"]
|
||||
});
|
||||
if (revRes.status === 0 && revRes.stdout) {
|
||||
gitInfo.commit = revRes.stdout.trim();
|
||||
}
|
||||
}
|
||||
|
||||
const devVersion = formatDevVersion(
|
||||
gitInfo.baseVersion,
|
||||
gitInfo.commitsAhead,
|
||||
gitInfo.commit,
|
||||
gitInfo.dirty
|
||||
);
|
||||
|
||||
return {
|
||||
name: "seal-use",
|
||||
version: devVersion,
|
||||
channel: "dev",
|
||||
isRelease: false,
|
||||
git: gitInfo
|
||||
};
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Fall back below if git is not installed or error occurs
|
||||
}
|
||||
|
||||
// 4. Default fallback when git is not available
|
||||
return {
|
||||
name: "seal-use",
|
||||
version: `${packageJson.version}-dev.0+local`,
|
||||
channel: "dev",
|
||||
isRelease: false
|
||||
};
|
||||
}
|
||||
|
||||
export const VERSION_INFO = resolveVersionInfo();
|
||||
export const VERSION = VERSION_INFO.version;
|
||||
export const IS_RELEASE = VERSION_INFO.isRelease;
|
||||
export const CHANNEL = VERSION_INFO.channel;
|
||||
Reference in new issue
Block a user