feat(FN-3074): sort done column by recency, preserve merge-active state, ad
This merge adds done-column sorting by most recent completion while preserving merge-active state on verification bounces, introduces a comprehensive droid runtime regression test suite covering engine delegation, auth routes, and model routing, hardens the CLI native bundle externalization, and fix Fusion-Task-Id: FN-3074
This commit is contained in:
@@ -60,6 +60,16 @@ describe("registerModelRoutes droid-cli filter", () => {
|
||||
expect(response.models.some((model) => model.provider === "droid-cli")).toBe(true);
|
||||
});
|
||||
|
||||
it("filters droid-cli models when useDroidCli setting is unset", async () => {
|
||||
const { handler } = setup(undefined);
|
||||
const json = vi.fn();
|
||||
|
||||
await handler({}, { json });
|
||||
|
||||
const response = json.mock.calls[0][0] as { models: Array<{ provider: string }> };
|
||||
expect(response.models.some((model) => model.provider === "droid-cli")).toBe(false);
|
||||
});
|
||||
|
||||
it("includes resolved planning model when settings hierarchy resolves one", async () => {
|
||||
const { handler } = setup(false, {
|
||||
planningProvider: "openai",
|
||||
|
||||
@@ -950,6 +950,37 @@ describe("Droid CLI auth routes", () => {
|
||||
id: "droid-cli",
|
||||
name: "Factory AI — via Droid CLI",
|
||||
type: "cli",
|
||||
authenticated: true,
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("GET /auth/status marks droid-cli unauthenticated when extension status is not ok", async () => {
|
||||
vi.spyOn(droidCliProbeModule, "probeDroidCli").mockResolvedValue({
|
||||
available: true,
|
||||
version: "droid 1.0.0",
|
||||
probeDurationMs: 10,
|
||||
});
|
||||
store.getGlobalSettingsStore = vi.fn().mockReturnValue({
|
||||
...createMockGlobalSettingsStore(),
|
||||
getSettings: vi.fn().mockResolvedValue({ useDroidCli: true }),
|
||||
});
|
||||
|
||||
const res = await GET(
|
||||
buildApp({ getDroidCliExtensionStatus: () => ({ status: "error", reason: "bad ext" }) } as Parameters<
|
||||
typeof createApiRoutes
|
||||
>[1]),
|
||||
"/api/auth/status",
|
||||
);
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.providers).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "droid-cli",
|
||||
authenticated: false,
|
||||
type: "cli",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
|
||||
@@ -109,6 +109,42 @@ describe("provider registration (default export)", () => {
|
||||
vi.doUnmock("../../../../plugins/fusion-plugin-droid-runtime/src/process-manager.js");
|
||||
vi.doUnmock("../../../../plugins/fusion-plugin-droid-runtime/src/mcp-config.js");
|
||||
});
|
||||
|
||||
it("delegates streamSimple execution to plugin-owned streamViaCli", async () => {
|
||||
vi.resetModules();
|
||||
const pluginStreamViaCli = vi.fn(() => ({ delegated: true }));
|
||||
vi.doMock("../../../../plugins/fusion-plugin-droid-runtime/src/provider.js", () => ({
|
||||
streamViaCli: pluginStreamViaCli,
|
||||
}));
|
||||
vi.doMock("../../../../plugins/fusion-plugin-droid-runtime/src/process-manager.js", () => ({
|
||||
validateCliPresenceAsync: vi.fn(async () => ({ ok: true })),
|
||||
validateCliAuthAsync: vi.fn(async () => true),
|
||||
killAllProcesses: vi.fn(),
|
||||
discoverDroidModels: vi.fn(async () => ["droid-pro"]),
|
||||
}));
|
||||
vi.doMock("../../../../plugins/fusion-plugin-droid-runtime/src/mcp-config.js", () => ({
|
||||
getCustomToolDefs: vi.fn(() => []),
|
||||
toolsFromContext: vi.fn(() => []),
|
||||
writeMcpConfig: vi.fn(() => undefined),
|
||||
}));
|
||||
|
||||
const registerProvider = vi.fn();
|
||||
const on = vi.fn();
|
||||
const getAllTools = vi.fn(() => []);
|
||||
const setActiveTools = vi.fn();
|
||||
|
||||
const mod = await import("../../index");
|
||||
mod.default({ registerProvider, on, getAllTools, setActiveTools } as any);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
const [, config] = registerProvider.mock.calls[0];
|
||||
config.streamSimple({ id: "droid-pro", provider: "droid-cli" }, { messages: [] }, {});
|
||||
expect(pluginStreamViaCli).toHaveBeenCalled();
|
||||
|
||||
vi.doUnmock("../../../../plugins/fusion-plugin-droid-runtime/src/provider.js");
|
||||
vi.doUnmock("../../../../plugins/fusion-plugin-droid-runtime/src/process-manager.js");
|
||||
vi.doUnmock("../../../../plugins/fusion-plugin-droid-runtime/src/mcp-config.js");
|
||||
});
|
||||
});
|
||||
|
||||
describe("streamViaCli", { timeout: 90_000 }, () => {
|
||||
|
||||
165
packages/engine/src/__tests__/droid-runtime-e2e.test.ts
Normal file
165
packages/engine/src/__tests__/droid-runtime-e2e.test.ts
Normal file
@@ -0,0 +1,165 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { mkdtempSync } from "node:fs";
|
||||
import { rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { PluginLoader, PluginStore, type TaskStore } from "@fusion/core";
|
||||
import { PluginRunner } from "../plugin-runner.js";
|
||||
import { resolveRuntime } from "../runtime-resolution.js";
|
||||
import { createResolvedAgentSession } from "../agent-session-helpers.js";
|
||||
|
||||
const { mockCreateFnAgent, mockPromptWithFallback, mockDescribeModel } = vi.hoisted(() => ({
|
||||
mockCreateFnAgent: vi.fn(),
|
||||
mockPromptWithFallback: vi.fn(),
|
||||
mockDescribeModel: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../logger.js", () => ({
|
||||
createLogger: vi.fn(() => ({
|
||||
log: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
})),
|
||||
executorLog: {
|
||||
log: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("../pi.js", () => ({
|
||||
createFnAgent: mockCreateFnAgent,
|
||||
promptWithFallback: mockPromptWithFallback,
|
||||
describeModel: mockDescribeModel,
|
||||
}));
|
||||
|
||||
function createTaskStoreMock(rootDir: string): TaskStore {
|
||||
return {
|
||||
getRootDir: () => rootDir,
|
||||
on: vi.fn(),
|
||||
off: vi.fn(),
|
||||
} as unknown as TaskStore;
|
||||
}
|
||||
|
||||
function droidPluginModulePath(): string {
|
||||
return fileURLToPath(
|
||||
new URL("../../../../plugins/fusion-plugin-droid-runtime/src/index.ts", import.meta.url),
|
||||
);
|
||||
}
|
||||
|
||||
async function preloadDroidPluginModule(): Promise<void> {
|
||||
await import(pathToFileURL(droidPluginModulePath()).href);
|
||||
}
|
||||
|
||||
describe("Droid runtime E2E pipeline", () => {
|
||||
let testRoot: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
testRoot = mkdtempSync(join(tmpdir(), "fn-droid-e2e-"));
|
||||
vi.clearAllMocks();
|
||||
|
||||
mockCreateFnAgent.mockResolvedValue({
|
||||
session: { id: "fallback-session", dispose: vi.fn() },
|
||||
sessionFile: "/tmp/fallback.session.json",
|
||||
});
|
||||
mockPromptWithFallback.mockResolvedValue(undefined);
|
||||
mockDescribeModel.mockReturnValue("pi/default");
|
||||
|
||||
await preloadDroidPluginModule();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await rm(testRoot, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("loads Droid plugin and creates sessions through Droid runtime without createFnAgent", async () => {
|
||||
const pluginStore = new PluginStore(testRoot, { inMemoryDb: true });
|
||||
await pluginStore.init();
|
||||
|
||||
await pluginStore.registerPlugin({
|
||||
manifest: {
|
||||
id: "fusion-plugin-droid-runtime",
|
||||
name: "Droid Runtime Plugin",
|
||||
version: "0.1.0",
|
||||
runtime: {
|
||||
runtimeId: "droid",
|
||||
name: "Droid Runtime",
|
||||
version: "0.1.0",
|
||||
},
|
||||
},
|
||||
path: droidPluginModulePath(),
|
||||
});
|
||||
|
||||
const taskStore = createTaskStoreMock(testRoot);
|
||||
const pluginLoader = new PluginLoader({ pluginStore, taskStore });
|
||||
const loadResult = await pluginLoader.loadAllPlugins();
|
||||
expect(loadResult).toEqual({ loaded: 1, errors: 0 });
|
||||
|
||||
const pluginRunner = new PluginRunner({
|
||||
pluginLoader,
|
||||
pluginStore,
|
||||
taskStore,
|
||||
rootDir: testRoot,
|
||||
});
|
||||
|
||||
const resolved = await resolveRuntime({
|
||||
sessionPurpose: "executor",
|
||||
runtimeHint: "droid",
|
||||
pluginRunner,
|
||||
});
|
||||
|
||||
expect(resolved.runtimeId).toBe("droid");
|
||||
expect(resolved.wasConfigured).toBe(true);
|
||||
|
||||
const created = await createResolvedAgentSession({
|
||||
sessionPurpose: "executor",
|
||||
runtimeHint: "droid",
|
||||
pluginRunner,
|
||||
cwd: testRoot,
|
||||
systemPrompt: "You are helpful",
|
||||
defaultModelId: "droid-pro",
|
||||
});
|
||||
|
||||
expect(created.runtimeId).toBe("droid");
|
||||
expect(created.wasConfigured).toBe(true);
|
||||
expect(created.session).toBeTruthy();
|
||||
expect(resolved.runtime.describeModel(created.session)).toBe("droid/droid-pro");
|
||||
|
||||
expect(
|
||||
typeof (created.session as { promptWithFallback?: unknown }).promptWithFallback,
|
||||
).toBe("function");
|
||||
expect(mockCreateFnAgent).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("falls back to default pi runtime when Droid plugin is not installed", async () => {
|
||||
const pluginStore = new PluginStore(testRoot, { inMemoryDb: true });
|
||||
await pluginStore.init();
|
||||
|
||||
const taskStore = createTaskStoreMock(testRoot);
|
||||
const pluginLoader = new PluginLoader({ pluginStore, taskStore });
|
||||
await pluginLoader.loadAllPlugins();
|
||||
|
||||
const pluginRunner = new PluginRunner({
|
||||
pluginLoader,
|
||||
pluginStore,
|
||||
taskStore,
|
||||
rootDir: testRoot,
|
||||
});
|
||||
|
||||
const result = await createResolvedAgentSession({
|
||||
sessionPurpose: "executor",
|
||||
runtimeHint: "droid",
|
||||
pluginRunner,
|
||||
cwd: testRoot,
|
||||
systemPrompt: "fallback",
|
||||
});
|
||||
|
||||
expect(result.runtimeId).toBe("pi");
|
||||
expect(result.wasConfigured).toBe(false);
|
||||
expect(mockCreateFnAgent).toHaveBeenCalledWith({
|
||||
cwd: testRoot,
|
||||
systemPrompt: "fallback",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -300,5 +300,36 @@ describe("Runtime Selection Regression Tests", () => {
|
||||
expect(result.runtimeId).toBe("openclaw");
|
||||
expect(result.wasConfigured).toBe(true);
|
||||
});
|
||||
|
||||
it("should route runtimeHint=droid to the droid runtime", async () => {
|
||||
mockResolveRuntime.mockResolvedValue({
|
||||
runtime: {
|
||||
id: "droid",
|
||||
name: "Droid Runtime",
|
||||
createSession: async () => ({
|
||||
session: {
|
||||
model: { provider: "droid-cli", id: "droid-pro" },
|
||||
},
|
||||
}),
|
||||
promptWithFallback: vi.fn(),
|
||||
describeModel: () => "droid/droid-pro",
|
||||
},
|
||||
wasConfigured: true,
|
||||
runtimeId: "droid",
|
||||
});
|
||||
|
||||
const { createResolvedAgentSession } = await import("../agent-session-helpers.js");
|
||||
|
||||
const result = await createResolvedAgentSession({
|
||||
sessionPurpose: "executor",
|
||||
pluginRunner: {} as any,
|
||||
runtimeHint: "droid",
|
||||
cwd: "/test/path",
|
||||
systemPrompt: "Test prompt",
|
||||
});
|
||||
|
||||
expect(result.runtimeId).toBe("droid");
|
||||
expect(result.wasConfigured).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user