diff --git a/web/standalone/src/components/VersionBadge.test.ts b/web/standalone/src/components/VersionBadge.test.ts new file mode 100644 index 0000000..803263d --- /dev/null +++ b/web/standalone/src/components/VersionBadge.test.ts @@ -0,0 +1,22 @@ +import { describe, expect, it } from "vitest"; +import { shortBuildTag } from "./VersionBadge"; + +describe("shortBuildTag (version badge display)", () => { + it("shortens a staging tag's full sha to 7 chars", () => { + expect(shortBuildTag("staging-75bb0d7e4f2a9c1b8d3e6f0a2b4c6d8e0f1a2b3c")).toBe( + "staging-75bb0d7", + ); + }); + + it("shortens a bare full sha", () => { + expect(shortBuildTag("75bb0d7e4f2a9c1b8d3e6f0a2b4c6d8e0f1a2b3c")).toBe("75bb0d7"); + }); + + it("leaves release tags and dev untouched", () => { + expect(shortBuildTag("2.7.7")).toBe("2.7.7"); + expect(shortBuildTag("dev")).toBe("dev"); + // Short hex-ish fragments (< 12 chars) are not treated as hashes. + expect(shortBuildTag("demo-local")).toBe("demo-local"); + expect(shortBuildTag("beta-abc123")).toBe("beta-abc123"); + }); +}); diff --git a/web/standalone/src/components/VersionBadge.tsx b/web/standalone/src/components/VersionBadge.tsx index d3d0ead..d2fb04c 100644 --- a/web/standalone/src/components/VersionBadge.tsx +++ b/web/standalone/src/components/VersionBadge.tsx @@ -10,8 +10,15 @@ import { APP_GIT_SHA, APP_TAG, LANDING_URL, REPO_URL } from "@/lib/config"; * loaded editor. `fixed` keeps it viewport-anchored on every route; z-20 sits * under the editor's boot overlay (z-30) so it's hidden until the tool is up. */ +/** Display form of a build tag: any embedded full commit hash shortens to the + * GitHub-style 7 chars ("staging-<40 hex>" → "staging-abc1234"); release tags + * ("2.7.7") pass through untouched. Display only — links keep the full sha. */ +export function shortBuildTag(tag: string): string { + return tag.replace(/\b[0-9a-f]{12,40}\b/i, (h) => h.slice(0, 7)); +} + export function VersionBadge() { - const tag = APP_TAG ?? "dev"; + const tag = shortBuildTag(APP_TAG ?? "dev"); const versionUrl = APP_GIT_SHA ? `${REPO_URL}/commit/${APP_GIT_SHA}` : APP_TAG