Skip to content

Commit 2d3fa48

Browse files
authored
feat(doctor): expose UI freshness health findings
Expose UI freshness doctor findings through the structured health contribution path so lint JSON and dry-run repair output include stale UI asset guidance. Keep legacy positional repair filtering stable while excluding health checks that already own their structured repair output. Maintainer fixups also avoid stale UI warnings when git history cannot prove changed sources, and make the foreground timeout regression test deterministic. Verification: - Local: `git diff --check origin/main...HEAD` - Local: `node_modules/.bin/oxfmt --check --threads=1 src/agents/bash-tools.exec-foreground-failures.test.ts src/commands/doctor-ui.test.ts src/commands/doctor-ui.ts src/flows/doctor-core-checks.ts src/flows/doctor-health-contributions.test.ts src/flows/doctor-health-contributions.ts src/flows/doctor-health-conversion-plan.ts` - Local: `node_modules/.bin/oxlint --tsconfig config/tsconfig/oxlint.core.json src/agents/bash-tools.exec-foreground-failures.test.ts src/commands/doctor-ui.test.ts src/commands/doctor-ui.ts src/flows/doctor-core-checks.ts src/flows/doctor-health-contributions.test.ts src/flows/doctor-health-contributions.ts src/flows/doctor-health-conversion-plan.ts` - Local: `node scripts/run-vitest.mjs src/commands/doctor-ui.test.ts src/flows/doctor-health-contributions.test.ts src/commands/doctor-lint.test.ts src/agents/bash-tools.exec-foreground-failures.test.ts --reporter=dot --pool=forks --testTimeout=30000 --hookTimeout=30000` - Local: `GOMAXPROCS=4 node scripts/run-tsgo.mjs -p tsconfig.core.json --noEmit --incremental false --pretty false` - Local: `GOMAXPROCS=4 node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --noEmit --incremental false --pretty false` - Local: `GOMAXPROCS=4 node scripts/run-tsgo.mjs -p tsconfig.extensions.json --noEmit --incremental false --pretty false` - Autoreview: `.agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main` - GitHub Actions: CI `26708647282`, Real behavior proof `26708646476`, CodeQL `26708647258`, CodeQL Critical Quality `26708647230`, OpenGrep PR Diff `26708647214`, Workflow Sanity `26708647232`, Dependency Guard `26708646489`, ClawSweeper Dispatch `26708646475`, Labeler `26708646480` Co-authored-by: Gio Della-Libera <[email protected]>
1 parent 7606e1d commit 2d3fa48

7 files changed

Lines changed: 391 additions & 104 deletions

‎src/agents/bash-tools.exec-foreground-failures.test.ts‎

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2+
import type { SpawnInput } from "../process/supervisor/index.js";
23
import { captureEnv } from "../test-utils/env.js";
34
import { resetProcessRegistryForTests } from "./bash-process-registry.js";
45
import { createExecTool } from "./bash-tools.exec.js";
56
import { resolveShellFromPath } from "./shell-utils.js";
67

8+
const supervisorMock = vi.hoisted(() => ({
9+
spawn: vi.fn(),
10+
cancel: vi.fn(),
11+
cancelScope: vi.fn(),
12+
reconcileOrphans: vi.fn(),
13+
getRecord: vi.fn(),
14+
}));
15+
16+
vi.mock("../process/supervisor/index.js", () => ({
17+
getProcessSupervisor: () => supervisorMock,
18+
}));
19+
720
const isWin = process.platform === "win32";
821
const defaultShell = isWin
922
? undefined
1023
: process.env.OPENCLAW_TEST_SHELL || resolveShellFromPath("bash") || process.env.SHELL || "sh";
11-
const longDelayCmd = isWin ? "Start-Sleep -Seconds 5" : "sleep 5";
1224

1325
describe("exec foreground failures", () => {
1426
let envSnapshot: ReturnType<typeof captureEnv>;
@@ -19,6 +31,11 @@ describe("exec foreground failures", () => {
1931
if (!isWin && defaultShell) {
2032
process.env.SHELL = defaultShell;
2133
}
34+
supervisorMock.spawn.mockReset();
35+
supervisorMock.cancel.mockReset();
36+
supervisorMock.cancelScope.mockReset();
37+
supervisorMock.reconcileOrphans.mockReset();
38+
supervisorMock.getRecord.mockReset();
2239
resetProcessRegistryForTests();
2340
});
2441

@@ -35,11 +52,35 @@ describe("exec foreground failures", () => {
3552
backgroundMs: 10,
3653
allowBackground: false,
3754
});
55+
supervisorMock.spawn.mockImplementationOnce(async (input: SpawnInput) => ({
56+
runId: input.runId ?? "call-timeout",
57+
pid: 1234,
58+
startedAtMs: Date.now(),
59+
stdin: {
60+
write: vi.fn(),
61+
end: vi.fn(),
62+
destroy: vi.fn(),
63+
},
64+
wait: vi.fn(async () => ({
65+
reason: "overall-timeout" as const,
66+
exitCode: null,
67+
exitSignal: null,
68+
durationMs: input.timeoutMs ?? 50,
69+
stdout: "",
70+
stderr: "",
71+
timedOut: true,
72+
noOutputTimedOut: false,
73+
})),
74+
cancel: vi.fn(),
75+
}));
3876

3977
const result = await tool.execute("call-timeout", {
40-
command: longDelayCmd,
78+
command: "echo never-runs",
79+
host: "gateway",
4180
});
4281

82+
expect(supervisorMock.spawn).toHaveBeenCalledOnce();
83+
expect((supervisorMock.spawn.mock.calls[0]?.[0] as SpawnInput | undefined)?.timeoutMs).toBe(50);
4384
expect(result.content[0]?.type).toBe("text");
4485
expect((result.content[0] as { text?: string }).text).toMatch(/timed out/i);
4586
expect((result.content[0] as { text?: string }).text).toMatch(/re-run with a higher timeout/i);

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

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import fs from "node:fs/promises";
2+
import os from "node:os";
3+
import path from "node:path";
4+
import { afterEach, describe, expect, it } from "vitest";
5+
import {
6+
detectUiProtocolFreshnessIssues,
7+
uiProtocolFreshnessIssueToHealthFinding,
8+
uiProtocolFreshnessIssueToRepairEffects,
9+
type UiProtocolFreshnessIssue,
10+
} from "./doctor-ui.js";
11+
12+
const tempRoots: string[] = [];
13+
14+
function issue(overrides: Partial<UiProtocolFreshnessIssue> = {}): UiProtocolFreshnessIssue {
15+
return {
16+
kind: "missing-assets",
17+
root: "/repo/openclaw",
18+
uiIndexPath: "/repo/openclaw/dist/control-ui/index.html",
19+
canBuild: true,
20+
...overrides,
21+
} as UiProtocolFreshnessIssue;
22+
}
23+
24+
async function createOpenClawRoot(): Promise<string> {
25+
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-doctor-ui-"));
26+
tempRoots.push(root);
27+
await fs.writeFile(path.join(root, "package.json"), JSON.stringify({ name: "openclaw" }));
28+
await fs.mkdir(path.join(root, "packages/gateway-protocol/src"), { recursive: true });
29+
await fs.writeFile(path.join(root, "packages/gateway-protocol/src/schema.ts"), "export {};\n");
30+
return root;
31+
}
32+
33+
async function touch(filePath: string, date: Date): Promise<void> {
34+
await fs.mkdir(path.dirname(filePath), { recursive: true });
35+
await fs.writeFile(filePath, "");
36+
await fs.utimes(filePath, date, date);
37+
}
38+
39+
describe("UI protocol freshness health mapping", () => {
40+
afterEach(async () => {
41+
await Promise.all(
42+
tempRoots.splice(0).map((root) => fs.rm(root, { recursive: true, force: true })),
43+
);
44+
});
45+
46+
it("maps missing UI assets to a structured finding and dry-run effect", () => {
47+
const current = issue();
48+
49+
expect(uiProtocolFreshnessIssueToHealthFinding(current)).toEqual(
50+
expect.objectContaining({
51+
checkId: "core/doctor/ui-protocol-freshness",
52+
severity: "warning",
53+
path: "/repo/openclaw/dist/control-ui/index.html",
54+
fixHint: expect.stringContaining("openclaw doctor --fix"),
55+
}),
56+
);
57+
expect(uiProtocolFreshnessIssueToRepairEffects(current)).toEqual([
58+
{
59+
kind: "process",
60+
action: "would-build-control-ui",
61+
target: "/repo/openclaw",
62+
dryRunSafe: false,
63+
},
64+
]);
65+
});
66+
67+
it("maps stale UI assets to rebuild effects without file diffs", () => {
68+
const current = issue({
69+
kind: "stale-assets",
70+
changesSinceBuild: ["abc123 schema change"],
71+
});
72+
const finding = uiProtocolFreshnessIssueToHealthFinding(current);
73+
74+
expect(finding.message).toContain("abc123 schema change");
75+
expect(finding.fixHint).toContain("openclaw doctor --fix --force");
76+
expect(uiProtocolFreshnessIssueToRepairEffects(current)).toEqual([
77+
{
78+
kind: "process",
79+
action: "would-rebuild-control-ui",
80+
target: "/repo/openclaw",
81+
dryRunSafe: false,
82+
},
83+
]);
84+
});
85+
86+
it("does not report dry-run effects when UI sources are unavailable", () => {
87+
expect(uiProtocolFreshnessIssueToRepairEffects(issue({ canBuild: false }))).toEqual([]);
88+
});
89+
90+
it("does not report stale assets when git finds no schema changes", async () => {
91+
const root = await createOpenClawRoot();
92+
const schemaPath = path.join(root, "packages/gateway-protocol/src/schema.ts");
93+
const uiIndexPath = path.join(root, "dist/control-ui/index.html");
94+
await touch(uiIndexPath, new Date("2026-01-01T00:00:00.000Z"));
95+
await touch(schemaPath, new Date("2026-01-02T00:00:00.000Z"));
96+
97+
await expect(
98+
detectUiProtocolFreshnessIssues({
99+
root,
100+
async collectChangesSinceBuild() {
101+
return [];
102+
},
103+
}),
104+
).resolves.toEqual([]);
105+
});
106+
107+
it("does not report stale assets when git history is unavailable", async () => {
108+
const root = await createOpenClawRoot();
109+
const schemaPath = path.join(root, "packages/gateway-protocol/src/schema.ts");
110+
const uiIndexPath = path.join(root, "dist/control-ui/index.html");
111+
await touch(uiIndexPath, new Date("2026-01-01T00:00:00.000Z"));
112+
await touch(schemaPath, new Date("2026-01-02T00:00:00.000Z"));
113+
114+
await expect(
115+
detectUiProtocolFreshnessIssues({
116+
root,
117+
async collectChangesSinceBuild() {
118+
return null;
119+
},
120+
}),
121+
).resolves.toEqual([]);
122+
});
123+
});

0 commit comments

Comments
 (0)