Skip to content

Commit 18f1263

Browse files
authored
test(onboarding): remove formatter bridges (#122120)
1 parent 1dcac5b commit 18f1263

6 files changed

Lines changed: 39 additions & 85 deletions

‎src/commands/onboard-skills.test-support.ts‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎src/commands/onboard-skills.test.ts‎

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@ vi.mock("./onboard-helpers.js", () => ({
3333
}));
3434

3535
import { setupSkills } from "./onboard-skills.js";
36-
import { testing } from "./onboard-skills.test-support.js";
37-
38-
describe("skill onboarding text bounds", () => {
39-
it("keeps install failures and hints UTF-16 well-formed", () => {
40-
expect(testing.summarizeInstallFailure(`${"x".repeat(138)}🚀tail`)).toBe(`${"x".repeat(138)}…`);
41-
expect(testing.formatSkillHint({ description: `${"x".repeat(88)}🚀tail`, install: [] })).toBe(
42-
`${"x".repeat(88)}…`,
43-
);
44-
});
45-
});
4636

4737
function createBundledSkill(params: {
4838
name: string;
@@ -205,6 +195,36 @@ describe("setupSkills", () => {
205195
mocks.resolveInstallerKindReadiness.mockResolvedValue({ ready: true });
206196
});
207197

198+
it("bounds skill hints and install failures through the onboarding flow", async () => {
199+
const hintPrefix = "x".repeat(88);
200+
const failurePrefix = "y".repeat(138);
201+
mockMissingBrewStatus([
202+
createBundledSkill({
203+
name: "node-helper",
204+
description: `${hintPrefix}🚀tail`,
205+
bins: ["node-helper"],
206+
installLabel: "",
207+
installKind: "node",
208+
}),
209+
]);
210+
mocks.installSkill.mockResolvedValueOnce({
211+
ok: false,
212+
message: `Install failed: ${failurePrefix}🚀tail`,
213+
stdout: "",
214+
stderr: "",
215+
code: 1,
216+
});
217+
const stop = vi.fn();
218+
const { prompter } = createPrompter({ multiselect: ["node-helper"] });
219+
vi.mocked(prompter.progress).mockReturnValue({ update: vi.fn(), stop });
220+
221+
await setupSkills({} as OpenClawConfig, "/tmp/ws", runtime, prompter);
222+
223+
const options = vi.mocked(prompter.multiselect).mock.calls[0]?.[0].options ?? [];
224+
expect(options.find((option) => option.value === "node-helper")?.hint).toBe(`${hintPrefix}…`);
225+
expect(stop).toHaveBeenCalledWith(expect.stringContaining(`${failurePrefix}…`));
226+
});
227+
208228
it("hides brew-only installs in Linux containers when brew is missing", async () => {
209229
await withPlatform("linux", async () => {
210230
mockMissingBrewStatus([

‎src/commands/onboard-skills.ts‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ function formatSkillHint(skill: {
6565
return combined.length > maxLen ? `${truncateUtf16Safe(combined, maxLen - 1)}…` : combined;
6666
}
6767

68-
const testing = { formatSkillHint, summarizeInstallFailure };
69-
70-
if (process.env.VITEST || process.env.NODE_ENV === "test") {
71-
(globalThis as Record<PropertyKey, unknown>)[Symbol.for("openclaw.onboardSkillsTestApi")] =
72-
testing;
73-
}
74-
7568
const SKIP_REASON_LABELS = {
7669
brew: "Homebrew",
7770
go: `Go toolchain (${MIN_AUTO_GO_VERSION}+)`,

‎src/commands/onboarding-plugin-install.test-support.ts‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎src/commands/onboarding-plugin-install.test.ts‎

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,6 @@ vi.mock("../utils/with-timeout.js", () => ({
125125
}));
126126

127127
import { ensureOnboardingPluginInstalled } from "./onboarding-plugin-install.js";
128-
import { testing } from "./onboarding-plugin-install.test-support.js";
129-
130-
describe("plugin install error summaries", () => {
131-
it("keeps bounded terminal text UTF-16 well-formed", () => {
132-
expect(testing.summarizeInstallError(`${"x".repeat(178)}🚀tail`)).toBe(`${"x".repeat(178)}…`);
133-
});
134-
135-
it("keeps copyable line breaks while bounding detailed installer output", () => {
136-
expect(testing.formatInstallErrorDetail("first\nsecond\tvalue")).toBe("first\nsecond\\tvalue");
137-
const detailed = testing.formatInstallErrorDetail(`start\n${"x".repeat(20_000)}`);
138-
expect(detailed).toContain("start\n");
139-
expect(detailed).toHaveLength(12_000);
140-
expect(detailed.endsWith("… (installer output truncated)")).toBe(true);
141-
});
142-
});
143128

144129
function requireCapturedPrompt<T>(captured: T | undefined): T {
145130
if (!captured) {
@@ -1215,10 +1200,11 @@ describe("ensureOnboardingPluginInstalled", () => {
12151200

12161201
it("returns bounded multiline ClawHub failure detail to non-interactive callers", async () => {
12171202
const runtimeError = vi.fn();
1203+
const summaryPrefix = "x".repeat(178);
12181204
installPluginFromClawHub.mockResolvedValueOnce({
12191205
ok: false,
12201206
code: "archive_integrity_mismatch",
1221-
error: `first line\n${"x".repeat(20_000)}`,
1207+
error: `Install failed: ${summaryPrefix}🚀tail\tvalue[31m\nsecond\tline\n${"y".repeat(20_000)}`,
12221208
});
12231209

12241210
const result = await ensureOnboardingPluginInstalled({
@@ -1242,10 +1228,15 @@ describe("ensureOnboardingPluginInstalled", () => {
12421228
promptInstall: false,
12431229
});
12441230

1245-
expect(result.error).toMatch(/^first line\n/);
1231+
expect(result.error).toMatch(/^Install failed: x{178}🚀tail/);
1232+
expect(result.error).toContain("\\tvalue");
1233+
expect(result.error).toContain("\nsecond\\tline\n");
1234+
expect(result.error).not.toContain("");
12461235
expect(result.error?.endsWith("\n… (installer output truncated)")).toBe(true);
12471236
expect(result.error?.length).toBe(12_000);
1248-
expect(readFirstMockCall(runtimeError, "runtime.error")[0]).toHaveLength(203);
1237+
const runtimeMessage = String(readFirstMockCall(runtimeError, "runtime.error")[0]);
1238+
expect(runtimeMessage).toContain(`${summaryPrefix}…`);
1239+
expect(runtimeMessage).not.toContain("");
12491240
});
12501241

12511242
it("does not offer local installs when the workspace only has a spoofed .git marker", async () => {

‎src/commands/onboarding-plugin-install.ts‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -580,14 +580,6 @@ async function notePluginInstallFailure(
580580
);
581581
}
582582

583-
const testing = { formatInstallErrorDetail, summarizeInstallError };
584-
585-
if (process.env.VITEST || process.env.NODE_ENV === "test") {
586-
(globalThis as Record<PropertyKey, unknown>)[
587-
Symbol.for("openclaw.onboardingPluginInstallTestApi")
588-
] = testing;
589-
}
590-
591583
function isTimeoutError(error: unknown): boolean {
592584
return error instanceof Error && error.message === "timeout";
593585
}

0 commit comments

Comments
 (0)