Skip to content

Commit f2ec9d1

Browse files
author
Peter Steinberger
committed
fix(doctor): inspect packaged and full protocol UI freshness
1 parent 36b80ad commit f2ec9d1

2 files changed

Lines changed: 132 additions & 10 deletions

File tree

‎src/commands/doctor-ui.test.ts‎

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { execFileSync } from "node:child_process";
12
// Doctor UI tests cover control UI asset checks, repair hints, and filesystem diagnostics.
23
import fs from "node:fs/promises";
34
import os from "node:os";
@@ -88,12 +89,132 @@ describe("UI protocol freshness health mapping", () => {
8889
expect(uiProtocolFreshnessIssueToRepairEffects(issue({ canBuild: false }))).toEqual([]);
8990
});
9091

92+
it("reports missing packaged UI assets without requiring unpublished protocol sources", async () => {
93+
const root = await createOpenClawRoot();
94+
await fs.rm(path.join(root, "packages"), { recursive: true });
95+
96+
await expect(detectUiProtocolFreshnessIssues({ root })).resolves.toEqual([
97+
{
98+
kind: "missing-assets",
99+
root,
100+
uiIndexPath: path.join(root, "dist/control-ui/index.html"),
101+
canBuild: false,
102+
},
103+
]);
104+
});
105+
106+
it("gives packaged installs an actionable recovery hint instead of a missing build command", () => {
107+
const finding = uiProtocolFreshnessIssueToHealthFinding(issue({ canBuild: false }));
108+
109+
expect(finding.message).not.toContain("pnpm ui:build");
110+
expect(finding.fixHint).toContain("Reinstall OpenClaw");
111+
});
112+
113+
it("keeps healthy packaged UI assets quiet without probing unpublished protocol history", async () => {
114+
const root = await createOpenClawRoot();
115+
await fs.rm(path.join(root, "packages"), { recursive: true });
116+
await touch(path.join(root, "dist/control-ui/index.html"), new Date("2026-01-02"));
117+
let checkedHistory = false;
118+
119+
await expect(
120+
detectUiProtocolFreshnessIssues({
121+
root,
122+
async collectChangesSinceBuild() {
123+
checkedHistory = true;
124+
return ["abc123 unavailable packaged source"];
125+
},
126+
}),
127+
).resolves.toEqual([]);
128+
expect(checkedHistory).toBe(false);
129+
});
130+
131+
it.each([
132+
["a nested schema module", "schema/sessions.ts"],
133+
["the protocol package entrypoint", "index.ts"],
134+
])("reports stale assets after changes to %s", async (_description, changedProtocolFile) => {
135+
const root = await createOpenClawRoot();
136+
const uiIndexPath = path.join(root, "dist/control-ui/index.html");
137+
const schemaBarrelPath = path.join(root, "packages/gateway-protocol/src/schema.ts");
138+
await touch(schemaBarrelPath, new Date("2026-01-01T00:00:00.000Z"));
139+
await touch(uiIndexPath, new Date("2026-01-02T00:00:00.000Z"));
140+
await touch(path.join(root, "ui/package.json"), new Date("2026-01-02T00:00:00.000Z"));
141+
await touch(
142+
path.join(root, "packages/gateway-protocol/src", changedProtocolFile),
143+
new Date("2026-01-03T00:00:00.000Z"),
144+
);
145+
146+
await expect(
147+
detectUiProtocolFreshnessIssues({
148+
root,
149+
async collectChangesSinceBuild() {
150+
return [`abc123 changed ${changedProtocolFile}`];
151+
},
152+
}),
153+
).resolves.toEqual([
154+
{
155+
kind: "stale-assets",
156+
root,
157+
uiIndexPath,
158+
canBuild: true,
159+
changesSinceBuild: [`abc123 changed ${changedProtocolFile}`],
160+
},
161+
]);
162+
});
163+
164+
it("reads committed nested protocol changes from the real complete-package git pathspec", async () => {
165+
const root = await createOpenClawRoot();
166+
const uiIndexPath = path.join(root, "dist/control-ui/index.html");
167+
await touch(path.join(root, "packages/gateway-protocol/src/schema.ts"), new Date("2026-01-01"));
168+
await touch(uiIndexPath, new Date("2026-01-02"));
169+
await touch(path.join(root, "ui/package.json"), new Date("2026-01-02"));
170+
await touch(
171+
path.join(root, "packages/gateway-protocol/src/schema/sessions.ts"),
172+
new Date("2026-01-03"),
173+
);
174+
execFileSync("git", ["init", "--quiet", root]);
175+
execFileSync("git", ["-C", root, "add", "packages/gateway-protocol/src/schema/sessions.ts"]);
176+
execFileSync(
177+
"git",
178+
[
179+
"-C",
180+
root,
181+
"-c",
182+
"core.hooksPath=/dev/null",
183+
"-c",
184+
"commit.gpgSign=false",
185+
"-c",
186+
"user.name=Doctor UI Test",
187+
"-c",
188+
189+
"commit",
190+
"--quiet",
191+
"-m",
192+
"update nested protocol schema",
193+
],
194+
{
195+
env: {
196+
...process.env,
197+
GIT_AUTHOR_DATE: "2026-01-03T00:00:00Z",
198+
GIT_COMMITTER_DATE: "2026-01-03T00:00:00Z",
199+
},
200+
},
201+
);
202+
203+
await expect(detectUiProtocolFreshnessIssues({ root })).resolves.toEqual([
204+
expect.objectContaining({
205+
kind: "stale-assets",
206+
changesSinceBuild: [expect.stringMatching(/update nested protocol schema$/)],
207+
}),
208+
]);
209+
});
210+
91211
it("does not report stale assets when git finds no schema changes", async () => {
92212
const root = await createOpenClawRoot();
93213
const schemaPath = path.join(root, "packages/gateway-protocol/src/schema.ts");
94214
const uiIndexPath = path.join(root, "dist/control-ui/index.html");
95215
await touch(uiIndexPath, new Date("2026-01-01T00:00:00.000Z"));
96216
await touch(schemaPath, new Date("2026-01-02T00:00:00.000Z"));
217+
await touch(path.join(root, "ui/package.json"), new Date("2026-01-01T00:00:00.000Z"));
97218

98219
await expect(
99220
detectUiProtocolFreshnessIssues({
@@ -111,6 +232,7 @@ describe("UI protocol freshness health mapping", () => {
111232
const uiIndexPath = path.join(root, "dist/control-ui/index.html");
112233
await touch(uiIndexPath, new Date("2026-01-01T00:00:00.000Z"));
113234
await touch(schemaPath, new Date("2026-01-02T00:00:00.000Z"));
235+
await touch(path.join(root, "ui/package.json"), new Date("2026-01-01T00:00:00.000Z"));
114236

115237
await expect(
116238
detectUiProtocolFreshnessIssues({

‎src/commands/doctor-ui.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export async function detectUiProtocolFreshnessIssues(
5050
return [];
5151
}
5252

53-
const schemaPath = path.join(root, "packages/gateway-protocol/src/schema.ts");
5453
const uiHealth = await resolveControlUiDistIndexHealth({
5554
root,
5655
argv1: opts.argv1 ?? process.argv[1],
@@ -59,19 +58,15 @@ export async function detectUiProtocolFreshnessIssues(
5958
const uiSourcesPath = path.join(root, "ui/package.json");
6059

6160
try {
62-
const [schemaStats, uiStats, uiSourcesStats] = await Promise.all([
63-
fs.stat(schemaPath).catch(() => null),
61+
const [uiStats, uiSourcesStats] = await Promise.all([
6462
fs.stat(uiIndexPath).catch(() => null),
6563
fs.stat(uiSourcesPath).catch(() => null),
6664
]);
67-
if (!schemaStats) {
68-
return [];
69-
}
7065
const canBuild = uiSourcesStats !== null;
7166
if (!uiStats) {
7267
return [{ kind: "missing-assets", root, uiIndexPath, canBuild }];
7368
}
74-
if (schemaStats.mtime <= uiStats.mtime) {
69+
if (!canBuild) {
7570
return [];
7671
}
7772
const changesSinceBuild = await (
@@ -106,7 +101,7 @@ async function collectProtocolSchemaChangesSince(
106101
"log",
107102
`--since=${uiMtime.toISOString()}`,
108103
"--format=%h %s",
109-
"packages/gateway-protocol/src/schema.ts",
104+
"packages/gateway-protocol/src",
110105
],
111106
{ timeoutMs: 5000 },
112107
).catch(() => null);
@@ -132,7 +127,7 @@ export function uiProtocolFreshnessIssueToHealthFinding(
132127
? issue.kind === "missing-assets"
133128
? "Run `openclaw doctor --fix` to build Control UI assets."
134129
: "Run `openclaw doctor --fix --force` to rebuild Control UI assets, or run `pnpm ui:build`."
135-
: "Install from a source checkout with ui/ sources, then run `pnpm ui:build`.",
130+
: "Reinstall OpenClaw to restore bundled Control UI assets.",
136131
};
137132
}
138133

@@ -156,7 +151,12 @@ export function uiProtocolFreshnessIssueToRepairEffects(
156151

157152
function formatUiProtocolFreshnessIssue(issue: UiProtocolFreshnessIssue): string {
158153
if (issue.kind === "missing-assets") {
159-
return ["- Control UI assets are missing.", "- Run: pnpm ui:build"].join("\n");
154+
return [
155+
"- Control UI assets are missing.",
156+
issue.canBuild
157+
? "- Run: pnpm ui:build"
158+
: "- Reinstall OpenClaw to restore bundled Control UI assets.",
159+
].join("\n");
160160
}
161161
if (issue.changesSinceBuild.length === 0) {
162162
return "UI assets are older than the protocol schema.";

0 commit comments

Comments
 (0)