Browser Verification steps now explicitly request and log agent-browser usage. - Mark the built-in browser verification workflow step as browser-required and document that it runs through agent-browser. - Add executor helpers to inject the agent-browser skill, probe CLI availability, and log start/finish outcomes. - Cover workflow metadata, browser verification execution logging, availability probing, and skill augmentation with tests. - Add a patch changeset for the published Fusion package. Files changed: .../fn-7130-browser-verification-agent-browser.md | 7 + docs/workflow-steps.md | 4 +- .../__tests__/builtin-coding-workflow-ir.test.ts | 23 ++ .../core/src/__tests__/builtin-workflows.test.ts | 12 + .../core/src/builtin-browser-verification-group.ts | 4 + packages/core/src/types.ts | 7 + ...iltin-coding-browser-verification-group.test.ts | 8 +- .../executor-browser-verification.test.ts | 267 +++++++++++++++++++++ packages/engine/src/executor.ts | 118 +++++++++ 9 files changed, 447 insertions(+), 3 deletions(-) Fusion-Task-Id: FN-7130 Fusion-Task-Lineage: 3a76522e-70e1-4445-ad18-b9e1b9b355fc Co-authored-by: Fusion (runfusion.ai) <noreply@runfusion.ai>
268 lines
9.6 KiB
TypeScript
268 lines
9.6 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import "./executor-test-helpers.js";
|
|
import type { WorkflowIrNode } from "@fusion/core";
|
|
import {
|
|
AGENT_BROWSER_NAVIGATION_SKILL_ID,
|
|
augmentSessionSkillsForBrowserStep,
|
|
formatAgentBrowserAvailabilityLog,
|
|
probeAgentBrowserAvailability,
|
|
TaskExecutor,
|
|
} from "../executor.js";
|
|
import { summarizeToolArgs } from "../agent-logger.js";
|
|
import {
|
|
createMockStore,
|
|
mockedCreateFnAgent,
|
|
mockedExecSync,
|
|
resetExecutorMocks,
|
|
} from "./executor-test-helpers.js";
|
|
|
|
type CapturedSession = {
|
|
skillSelection?: { requestedSkillNames?: string[]; projectRootDir?: string; sessionPurpose?: string };
|
|
};
|
|
|
|
function captureSession(output = '{"verdict":"APPROVE","notes":""}') {
|
|
const holder: { last?: CapturedSession } = {};
|
|
mockedCreateFnAgent.mockImplementation(async (opts: any) => {
|
|
holder.last = { skillSelection: opts.skillSelection };
|
|
const listeners: Array<(event: any) => void> = [];
|
|
return {
|
|
session: {
|
|
state: {},
|
|
subscribe: (fn: (event: any) => void) => {
|
|
listeners.push(fn);
|
|
return () => {};
|
|
},
|
|
prompt: vi.fn(async () => {
|
|
for (const fn of listeners) {
|
|
fn({
|
|
type: "message_update",
|
|
assistantMessageEvent: {
|
|
type: "text_delta",
|
|
partial: output,
|
|
contentIndex: 0,
|
|
delta: output,
|
|
},
|
|
});
|
|
}
|
|
}),
|
|
dispose: vi.fn(),
|
|
},
|
|
};
|
|
});
|
|
return holder;
|
|
}
|
|
|
|
function baseTask(overrides: Record<string, unknown> = {}) {
|
|
return {
|
|
id: "FN-7130",
|
|
title: "Browser verification",
|
|
description: "exercise browser verification",
|
|
column: "in-progress" as const,
|
|
worktree: "/tmp/wt",
|
|
branch: "fusion/fn-7130",
|
|
baseCommitSha: "abc123",
|
|
dependencies: [],
|
|
steps: [{ name: "s", status: "in-progress" as const }],
|
|
currentStep: 0,
|
|
log: [],
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function makeExecutor(store: ReturnType<typeof createMockStore>) {
|
|
return new TaskExecutor(store as any, "/tmp/test", {
|
|
agentStore: { getAgent: vi.fn().mockResolvedValue(null), createAgent: vi.fn() },
|
|
} as any);
|
|
}
|
|
|
|
function browserVerificationStep(overrides: Record<string, unknown> = {}) {
|
|
return {
|
|
id: "graph:browser-verification-step",
|
|
name: "Browser Verification",
|
|
description: "",
|
|
mode: "prompt",
|
|
phase: "pre-merge",
|
|
gateMode: "advisory",
|
|
prompt: "Verify in browser.",
|
|
toolMode: "coding",
|
|
requiresBrowser: true,
|
|
enabled: true,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("browser-verification workflow-step browser capability", () => {
|
|
beforeEach(() => {
|
|
resetExecutorMocks();
|
|
});
|
|
|
|
it("probes agent-browser availability as a bounded non-fatal helper", async () => {
|
|
await expect(probeAgentBrowserAvailability(async (command, options) => {
|
|
expect(command).toBe("agent-browser --version");
|
|
expect(options.timeout).toBeLessThanOrEqual(10_000);
|
|
return { stdout: "agent-browser 1.2.3\n", stderr: "" };
|
|
})).resolves.toEqual({ available: true, version: "agent-browser 1.2.3" });
|
|
|
|
await expect(probeAgentBrowserAvailability(async () => {
|
|
const err = new Error("spawn agent-browser ENOENT") as Error & { code: string };
|
|
err.code = "ENOENT";
|
|
throw err;
|
|
})).resolves.toEqual({ available: false, reason: "not installed" });
|
|
|
|
await expect(probeAgentBrowserAvailability(async () => {
|
|
const err = new Error("Command timed out") as Error & { code: string; killed: boolean };
|
|
err.code = "ETIMEDOUT";
|
|
err.killed = true;
|
|
throw err;
|
|
})).resolves.toEqual({ available: false, reason: "probe timed out" });
|
|
});
|
|
|
|
it("merges the agent-browser navigation skill idempotently", () => {
|
|
expect(augmentSessionSkillsForBrowserStep(undefined, "/repo")).toEqual({
|
|
projectRootDir: "/repo",
|
|
sessionPurpose: "executor",
|
|
requestedSkillNames: [AGENT_BROWSER_NAVIGATION_SKILL_ID],
|
|
});
|
|
|
|
expect(augmentSessionSkillsForBrowserStep({
|
|
projectRootDir: "/repo",
|
|
sessionPurpose: "executor",
|
|
requestedSkillNames: ["existing", AGENT_BROWSER_NAVIGATION_SKILL_ID],
|
|
}, "/fallback").requestedSkillNames).toEqual(["existing", AGENT_BROWSER_NAVIGATION_SKILL_ID]);
|
|
});
|
|
|
|
it("materializes requiresBrowser from graph prompt config and omits it when absent", async () => {
|
|
const store = createMockStore();
|
|
store.getTask.mockImplementation(async (id: string) => baseTask({ id }));
|
|
const executor = makeExecutor(store);
|
|
const captured: Array<Record<string, unknown>> = [];
|
|
vi.spyOn(executor as any, "executeWorkflowStep").mockImplementation(async (_task: unknown, step: Record<string, unknown>) => {
|
|
captured.push(step);
|
|
return { success: true, output: "ok" };
|
|
});
|
|
|
|
const browserNode: WorkflowIrNode = {
|
|
id: "custom-browser-step",
|
|
kind: "prompt",
|
|
config: { prompt: "Verify", toolMode: "coding", requiresBrowser: true },
|
|
};
|
|
const plainNode: WorkflowIrNode = { id: "plain-step", kind: "prompt", config: { prompt: "Review" } };
|
|
|
|
await (executor as any).runGraphCustomNode(browserNode, baseTask(), {}, undefined);
|
|
await (executor as any).runGraphCustomNode(plainNode, baseTask(), {}, undefined);
|
|
|
|
expect(captured[0]).toMatchObject({ id: "graph:custom-browser-step", requiresBrowser: true, toolMode: "coding" });
|
|
expect(captured[1]).not.toHaveProperty("requiresBrowser");
|
|
});
|
|
|
|
it("summarizes bash agent-browser commands for agent-log tool entries", () => {
|
|
expect(summarizeToolArgs("bash", { command: "agent-browser open http://localhost:5173" })).toBe(
|
|
"agent-browser open http://localhost:5173",
|
|
);
|
|
});
|
|
|
|
it("logs browser verification start, availability, and finish while augmenting session skills", async () => {
|
|
const store = createMockStore();
|
|
const executor = makeExecutor(store);
|
|
const cap = captureSession();
|
|
mockedExecSync.mockImplementation((command: string) => {
|
|
if (command === "agent-browser --version") return Buffer.from("agent-browser 9.9.9\n");
|
|
return Buffer.from("");
|
|
});
|
|
|
|
const result = await (executor as any).executeWorkflowStep(
|
|
baseTask(),
|
|
browserVerificationStep(),
|
|
"/tmp/wt",
|
|
{},
|
|
undefined,
|
|
undefined,
|
|
);
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(cap.last?.skillSelection?.requestedSkillNames).toContain(AGENT_BROWSER_NAVIGATION_SKILL_ID);
|
|
expect(store.logEntry).toHaveBeenCalledWith(
|
|
"FN-7130",
|
|
"[browser-verification] agent-browser available — version agent-browser 9.9.9",
|
|
);
|
|
expect(store.appendAgentLog).toHaveBeenCalledWith(
|
|
"FN-7130",
|
|
expect.stringContaining("[browser-verification] starting browser verification"),
|
|
"text",
|
|
undefined,
|
|
"reviewer",
|
|
);
|
|
expect(store.appendAgentLog).toHaveBeenCalledWith(
|
|
"FN-7130",
|
|
"[browser-verification] agent-browser available — version agent-browser 9.9.9",
|
|
"text",
|
|
undefined,
|
|
"reviewer",
|
|
);
|
|
expect(store.appendAgentLog).toHaveBeenCalledWith(
|
|
"FN-7130",
|
|
"[browser-verification] finished browser verification for task FN-7130: verdict APPROVE",
|
|
"text",
|
|
undefined,
|
|
"reviewer",
|
|
);
|
|
});
|
|
|
|
it("logs an actionable warning and continues when agent-browser is missing", async () => {
|
|
const store = createMockStore();
|
|
const executor = makeExecutor(store);
|
|
captureSession();
|
|
mockedExecSync.mockImplementation((command: string) => {
|
|
if (command === "agent-browser --version") {
|
|
const err = new Error("spawn agent-browser ENOENT") as Error & { code: string };
|
|
err.code = "ENOENT";
|
|
throw err;
|
|
}
|
|
return Buffer.from("");
|
|
});
|
|
|
|
const result = await (executor as any).executeWorkflowStep(
|
|
baseTask(),
|
|
browserVerificationStep(),
|
|
"/tmp/wt",
|
|
{},
|
|
undefined,
|
|
undefined,
|
|
);
|
|
|
|
const warning = "[browser-verification] agent-browser not found on PATH — the step relies on the agent-browser CLI; install the agent-browser plugin/binary. Continuing; the step may fast-bail or fail.";
|
|
expect(result.success).toBe(true);
|
|
expect(formatAgentBrowserAvailabilityLog({ available: false, reason: "not installed" })).toBe(warning);
|
|
expect(store.logEntry).toHaveBeenCalledWith("FN-7130", warning);
|
|
expect(store.appendAgentLog).toHaveBeenCalledWith("FN-7130", warning, "text", undefined, "reviewer");
|
|
});
|
|
|
|
it("keeps flag-absent prompt steps byte-inert for browser logging and skills", async () => {
|
|
const store = createMockStore();
|
|
const executor = makeExecutor(store);
|
|
const cap = captureSession();
|
|
mockedExecSync.mockImplementation((command: string) => {
|
|
if (command === "agent-browser --version") throw new Error("should not probe agent-browser");
|
|
return Buffer.from("");
|
|
});
|
|
|
|
const result = await (executor as any).executeWorkflowStep(
|
|
baseTask(),
|
|
browserVerificationStep({ id: "graph:plain", name: "Plain", toolMode: "readonly", requiresBrowser: undefined }),
|
|
"/tmp/wt",
|
|
{},
|
|
undefined,
|
|
undefined,
|
|
);
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(cap.last?.skillSelection?.requestedSkillNames ?? []).not.toContain(AGENT_BROWSER_NAVIGATION_SKILL_ID);
|
|
expect(store.logEntry.mock.calls.some(([, message]: [string, string]) => message.includes("[browser-verification]"))).toBe(false);
|
|
expect(store.appendAgentLog.mock.calls.some(([, message]: [string, string]) => message.includes("[browser-verification]"))).toBe(false);
|
|
});
|
|
});
|