Skip to content

Commit 0e1e077

Browse files
authored
feat(control-ui): show build identity chip in sidebar footer (#104350)
1 parent 8e2ddd6 commit 0e1e077

73 files changed

Lines changed: 528 additions & 113 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎ui/src/app/vite-config.node.test.ts‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ describe("Control UI Vite config", () => {
3131
OPENCLAW_BUILD_TIMESTAMP: "2026-07-10T12:34:56Z",
3232
},
3333
readGitCommit,
34+
readGitBranch: () => null,
35+
readGitDirty: () => null,
3436
readPackageVersion: () => "2026.7.10",
3537
}),
3638
).toEqual({
3739
version: "2026.7.10",
3840
commit: "0123456789abcdef0123456789abcdef01234567",
3941
builtAt: "2026-07-10T12:34:56.000Z",
42+
branch: null,
43+
dirty: null,
4044
buildId: "2026.7.10-0123456789ab-2026-07-10T12-34-56.000Z",
4145
});
4246
expect(readGitCommit).not.toHaveBeenCalled();
@@ -48,12 +52,16 @@ describe("Control UI Vite config", () => {
4852
env: {},
4953
now: () => new Date("2026-07-10T13:14:15.000Z"),
5054
readGitCommit: () => "a".repeat(40),
55+
readGitBranch: () => null,
56+
readGitDirty: () => null,
5157
readPackageVersion: () => null,
5258
}),
5359
).toEqual({
5460
version: null,
5561
commit: "a".repeat(40),
5662
builtAt: "2026-07-10T13:14:15.000Z",
63+
branch: null,
64+
dirty: null,
5765
buildId: "aaaaaaaaaaaa-2026-07-10T13-14-15.000Z",
5866
});
5967
});
@@ -99,6 +107,84 @@ describe("Control UI Vite config", () => {
99107
expect(readGitCommit).not.toHaveBeenCalled();
100108
});
101109

110+
it("prefers GIT_BRANCH over GitHub and checked-out Git branch identity", () => {
111+
const readGitBranch = vi.fn(() => "git-fallback");
112+
expect(
113+
resolveControlUiBuildInfo({
114+
env: {
115+
GIT_BRANCH: " feature/from-env ",
116+
GITHUB_REF_NAME: "feature/from-github",
117+
GITHUB_REF_TYPE: "branch",
118+
},
119+
readGitBranch,
120+
readGitCommit: () => null,
121+
readGitDirty: () => null,
122+
readPackageVersion: () => null,
123+
}).branch,
124+
).toBe("feature/from-env");
125+
expect(readGitBranch).not.toHaveBeenCalled();
126+
});
127+
128+
it("uses GITHUB_REF_NAME only for branch refs", () => {
129+
const readGitBranch = vi.fn(() => "git-fallback");
130+
expect(
131+
resolveControlUiBuildInfo({
132+
env: { GITHUB_REF_NAME: "feature/github", GITHUB_REF_TYPE: "branch" },
133+
readGitBranch,
134+
readGitCommit: () => null,
135+
readGitDirty: () => null,
136+
readPackageVersion: () => null,
137+
}).branch,
138+
).toBe("feature/github");
139+
expect(readGitBranch).not.toHaveBeenCalled();
140+
141+
expect(
142+
resolveControlUiBuildInfo({
143+
env: { GITHUB_REF_NAME: "v2026.7.10", GITHUB_REF_TYPE: "tag" },
144+
readGitBranch,
145+
readGitCommit: () => null,
146+
readGitDirty: () => null,
147+
readPackageVersion: () => null,
148+
}).branch,
149+
).toBe("git-fallback");
150+
});
151+
152+
it("falls back to checked-out Git and treats detached HEAD as unknown", () => {
153+
expect(
154+
resolveControlUiBuildInfo({
155+
env: {},
156+
readGitBranch: () => "feature/from-git",
157+
readGitCommit: () => null,
158+
readGitDirty: () => null,
159+
readPackageVersion: () => null,
160+
}).branch,
161+
).toBe("feature/from-git");
162+
expect(
163+
resolveControlUiBuildInfo({
164+
env: {},
165+
readGitBranch: () => "HEAD",
166+
readGitCommit: () => null,
167+
readGitDirty: () => null,
168+
readPackageVersion: () => null,
169+
}).branch,
170+
).toBeNull();
171+
});
172+
173+
it("captures clean, dirty, and unavailable Git worktree state", () => {
174+
const resolveDirty = (readGitDirty: () => boolean | null) =>
175+
resolveControlUiBuildInfo({
176+
env: {},
177+
readGitBranch: () => null,
178+
readGitCommit: () => null,
179+
readGitDirty,
180+
readPackageVersion: () => null,
181+
}).dirty;
182+
183+
expect(resolveDirty(() => true)).toBe(true);
184+
expect(resolveDirty(() => false)).toBe(false);
185+
expect(resolveDirty(() => null)).toBeNull();
186+
});
187+
102188
it("does not let a generic release selector replace the artifact build identity", () => {
103189
expect(
104190
resolveControlUiBuildInfo({

‎ui/src/build-info.test.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
22
import {
33
deriveControlUiBuildId,
44
normalizeControlUiBuildInfo,
5+
normalizeControlUiBranch,
56
normalizeControlUiBuildTimestamp,
67
normalizeControlUiCommit,
78
} from "./build-info.ts";
@@ -15,6 +16,13 @@ describe("Control UI build info", () => {
1516
expect(normalizeControlUiCommit("not-a-sha")).toBeNull();
1617
});
1718

19+
it("normalizes advisory branch identity", () => {
20+
expect(normalizeControlUiBranch(" feature/build-chip ")).toBe("feature/build-chip");
21+
expect(normalizeControlUiBranch("HEAD")).toBeNull();
22+
expect(normalizeControlUiBranch(" ")).toBeNull();
23+
expect(normalizeControlUiBranch("x".repeat(101))).toBe("x".repeat(100));
24+
});
25+
1826
it("canonicalizes only valid UTC build timestamps", () => {
1927
expect(normalizeControlUiBuildTimestamp("2026-07-10T12:34:56Z")).toBe(
2028
"2026-07-10T12:34:56.000Z",
@@ -38,9 +46,25 @@ describe("Control UI build info", () => {
3846
version: " ",
3947
commit: "deadbeef",
4048
builtAt: "later",
49+
branch: "HEAD",
50+
dirty: "yes",
4151
buildId: "",
4252
}),
43-
).toEqual({ version: null, commit: null, builtAt: null, buildId: "dev" });
53+
).toEqual({
54+
version: null,
55+
commit: null,
56+
builtAt: null,
57+
branch: null,
58+
dirty: null,
59+
buildId: "dev",
60+
});
61+
});
62+
63+
it("passes through normalized branch and boolean dirty state", () => {
64+
expect(normalizeControlUiBuildInfo({ branch: " feature/x ", dirty: false })).toMatchObject({
65+
branch: "feature/x",
66+
dirty: false,
67+
});
4468
});
4569

4670
it("derives a stable service-worker id from the same artifact metadata", () => {

‎ui/src/build-info.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export type ControlUiBuildInfo = Readonly<{
44
version: string | null;
55
commit: string | null;
66
builtAt: string | null;
7+
branch: string | null;
8+
dirty: boolean | null;
79
buildId: string;
810
}>;
911

@@ -28,6 +30,11 @@ export function normalizeControlUiCommit(value: unknown): string | null {
2830
return commit && FULL_GIT_SHA.test(commit) ? commit : null;
2931
}
3032

33+
export function normalizeControlUiBranch(value: unknown): string | null {
34+
const branch = normalizeOptionalString(value);
35+
return branch && branch !== "HEAD" ? branch.slice(0, 100) : null;
36+
}
37+
3138
export function normalizeControlUiBuildTimestamp(value: unknown): string | null {
3239
const timestamp = normalizeOptionalString(value);
3340
if (!timestamp || !UTC_BUILD_TIMESTAMP.test(timestamp)) {
@@ -63,6 +70,8 @@ export function normalizeControlUiBuildInfo(value: unknown): ControlUiBuildInfo
6370
const metadata = { version, commit, builtAt };
6471
return {
6572
...metadata,
73+
branch: normalizeControlUiBranch(record.branch),
74+
dirty: typeof record.dirty === "boolean" ? record.dirty : null,
6675
buildId: normalizeControlUiBuildId(record.buildId ?? deriveControlUiBuildId(metadata)),
6776
};
6877
}

‎ui/src/components/app-sidebar.ts‎

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ import {
2323
type ApplicationNavigationOptions,
2424
} from "../app/context.ts";
2525
import { controlUiPublicAssetPath } from "../app/public-assets.ts";
26-
import { isViteDevPage } from "../app/settings.ts";
2726
import type { ThemeMode } from "../app/theme.ts";
2827
import "./session-menu.ts";
28+
import "./sidebar-build-chip.ts";
2929
import "./sidebar-update-card.ts";
3030
import "./theme-mode-toggle.ts";
3131
import "./tooltip.ts";
32-
import { CONTROL_UI_BUILD_INFO } from "../build-info.ts";
3332
import { t } from "../i18n/index.ts";
3433
import { editorOpenUrl } from "../lib/editor-links.ts";
3534
import { buildExternalLinkRel, EXTERNAL_LINK_TARGET } from "../lib/external-link.ts";
@@ -128,24 +127,6 @@ const PALETTE_SHORTCUT = /Mac|iP(hone|ad|od)/i.test(globalThis.navigator?.platfo
128127
? "⌘K"
129128
: "Ctrl K";
130129

131-
// Dev-server pages get the artifact identity in the status tooltip so devs can
132-
// tell which checkout built the UI they are looking at; release builds keep the
133-
// plain status line (About/Settings already expose build details there).
134-
const DEV_BUILD_TOOLTIP_LINE = isViteDevPage()
135-
? [
136-
[
137-
CONTROL_UI_BUILD_INFO.version ? `v${CONTROL_UI_BUILD_INFO.version}` : null,
138-
CONTROL_UI_BUILD_INFO.commit?.slice(0, 12) ?? null,
139-
]
140-
.filter((part): part is string => part !== null)
141-
.join(" · "),
142-
// Trim to minutes so the timestamp stays one tooltip line.
143-
CONTROL_UI_BUILD_INFO.builtAt ? `${CONTROL_UI_BUILD_INFO.builtAt.slice(0, 16)}Z` : "",
144-
]
145-
.filter(Boolean)
146-
.join("\n")
147-
: "";
148-
149130
function loadStoredSidebarSessionsGrouping(): SidebarSessionsGrouping {
150131
return normalizeSidebarSessionsGrouping(
151132
getSafeLocalStorage()?.getItem(SIDEBAR_SESSION_GROUPING_STORAGE_KEY),
@@ -1908,9 +1889,6 @@ class AppSidebar extends OpenClawLightDomContentsElement {
19081889
const gatewayStatus = t("chat.gatewayStatus", {
19091890
status: this.connected ? t("common.online") : t("common.offline"),
19101891
});
1911-
const gatewayStatusTooltip = DEV_BUILD_TOOLTIP_LINE
1912-
? `${gatewayStatus}\n${DEV_BUILD_TOOLTIP_LINE}`
1913-
: gatewayStatus;
19141892
const settingsActive =
19151893
this.activeRouteId !== undefined && isSettingsNavigationRoute(this.activeRouteId);
19161894
const settingsTooltip = `${titleForRoute("config")} (⇧⌘,)`;
@@ -1950,7 +1928,7 @@ class AppSidebar extends OpenClawLightDomContentsElement {
19501928
</div>`
19511929
: nothing}
19521930
<div class="sidebar-footer-bar">
1953-
<openclaw-tooltip .content=${gatewayStatusTooltip}>
1931+
<openclaw-tooltip .content=${gatewayStatus}>
19541932
<span
19551933
class="sidebar-status__dot ${this.connected
19561934
? "sidebar-connection-status--online"
@@ -1960,6 +1938,11 @@ class AppSidebar extends OpenClawLightDomContentsElement {
19601938
aria-label=${gatewayStatus}
19611939
></span>
19621940
</openclaw-tooltip>
1941+
<openclaw-sidebar-build-chip
1942+
.basePath=${this.basePath}
1943+
.gatewayVersion=${this.gatewayVersion}
1944+
.onNavigate=${(routeId: "about") => this.onNavigate?.(routeId)}
1945+
></openclaw-sidebar-build-chip>
19631946
<span class="sidebar-footer-bar__spacer"></span>
19641947
<openclaw-tooltip .content=${settingsTooltip}>
19651948
<a
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { describe, expect, it } from "vitest";
2+
import type { ControlUiBuildInfo } from "../build-info.ts";
3+
import { formatBuildChipText } from "./sidebar-build-chip.ts";
4+
5+
const COMMIT = "e8cbc62f0123456789abcdef0123456789abcdef";
6+
const BUILT_AT = "2026-07-10T12:00:00.000Z";
7+
8+
function buildInfo(overrides: Partial<ControlUiBuildInfo> = {}): ControlUiBuildInfo {
9+
return {
10+
version: "2026.7.10",
11+
commit: COMMIT,
12+
builtAt: BUILT_AT,
13+
branch: "main",
14+
dirty: false,
15+
buildId: "test",
16+
...overrides,
17+
};
18+
}
19+
20+
describe("formatBuildChipText", () => {
21+
const nowMs = Date.parse(BUILT_AT) + 24 * 60_000;
22+
const cases: Array<{
23+
name: string;
24+
info: ControlUiBuildInfo;
25+
nowMs?: number;
26+
expected: string | null;
27+
}> = [
28+
{
29+
name: "main clean build",
30+
info: buildInfo(),
31+
expected: "e8cbc62 · 24m",
32+
},
33+
{
34+
name: "non-main branch",
35+
info: buildInfo({ branch: "feat/x", builtAt: "2026-07-10T12:19:00.000Z" }),
36+
expected: "feat/x@e8cbc62 · 5m",
37+
},
38+
{
39+
name: "dirty worktree",
40+
info: buildInfo({ dirty: true, builtAt: "2026-07-10T09:00:00.000Z" }),
41+
expected: "e8cbc62* · 3h",
42+
},
43+
{
44+
name: "missing build timestamp",
45+
info: buildInfo({ builtAt: null }),
46+
expected: "e8cbc62",
47+
},
48+
{
49+
name: "missing commit",
50+
info: buildInfo({ commit: null }),
51+
expected: null,
52+
},
53+
{
54+
name: "long branch",
55+
info: buildInfo({ branch: "abcdefghijklmnop", builtAt: null }),
56+
expected: "abcdefghijklmn…@e8cbc62",
57+
},
58+
{
59+
name: "future build timestamp",
60+
info: buildInfo({ builtAt: "2026-07-10T12:25:00.000Z" }),
61+
expected: "e8cbc62 · 0s",
62+
},
63+
];
64+
65+
for (const testCase of cases) {
66+
it(testCase.name, () => {
67+
expect(formatBuildChipText(testCase.info, testCase.nowMs ?? nowMs)).toBe(testCase.expected);
68+
});
69+
}
70+
});

0 commit comments

Comments
 (0)