feat(FN-2982): merge fusion/fn-2982
Merges FN-2982 Step 3: adds model filtering for the droid-cli settings API, fixes planning mode question display and new-session reset in the dashboard, and adds test coverage for droid-cli settings and model route registration. Fusion-Task-Id: FN-2982
This commit is contained in:
@@ -779,7 +779,7 @@ describe("Migration: pre-33 DB upgrade", () => {
|
||||
// Step 1: Create a fresh database at v33 (runs all migrations up to 33)
|
||||
const db1 = createDatabase(legacyDir);
|
||||
db1.init();
|
||||
expect(db1.getSchemaVersion()).toBe(56);
|
||||
expect(db1.getSchemaVersion()).toBe(57);
|
||||
db1.close();
|
||||
|
||||
// Step 2: Manually downgrade to version 32 and drop insight tables
|
||||
@@ -814,7 +814,7 @@ describe("Migration: pre-33 DB upgrade", () => {
|
||||
expect(tableNamesBefore).not.toContain("project_insight_runs");
|
||||
// Now run init — this triggers the v32→v33 migration
|
||||
db3.init();
|
||||
expect(db3.getSchemaVersion()).toBe(56);
|
||||
expect(db3.getSchemaVersion()).toBe(57);
|
||||
|
||||
// Step 4: Verify insight tables exist after migration
|
||||
const tablesAfter = db3.prepare(
|
||||
@@ -845,12 +845,12 @@ describe("Migration: pre-33 DB upgrade", () => {
|
||||
try {
|
||||
const db1 = createDatabase(testDir);
|
||||
db1.init();
|
||||
expect(db1.getSchemaVersion()).toBe(56);
|
||||
expect(db1.getSchemaVersion()).toBe(57);
|
||||
db1.close();
|
||||
|
||||
const db2 = createDatabase(testDir);
|
||||
expect(() => db2.init()).not.toThrow();
|
||||
expect(db2.getSchemaVersion()).toBe(56);
|
||||
expect(db2.getSchemaVersion()).toBe(57);
|
||||
db2.close();
|
||||
} finally {
|
||||
rmSync(testDir, { recursive: true, force: true });
|
||||
|
||||
@@ -2629,7 +2629,7 @@ describe("MissionStore", () => {
|
||||
|
||||
describe("Loop State & Validator Run Schema (v31)", () => {
|
||||
it("schema version is 40 after migration", () => {
|
||||
expect(db.getSchemaVersion()).toBe(56);
|
||||
expect(db.getSchemaVersion()).toBe(57);
|
||||
});
|
||||
|
||||
it("mission_features table has loop state columns", () => {
|
||||
|
||||
@@ -742,7 +742,7 @@ describe("RoadmapStore", () => {
|
||||
|
||||
describe("schema version", () => {
|
||||
it("schema version is 40 after init", () => {
|
||||
expect(db.getSchemaVersion()).toBe(56);
|
||||
expect(db.getSchemaVersion()).toBe(57);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -465,7 +465,7 @@ describe("Run Audit", () => {
|
||||
});
|
||||
|
||||
it("schema version is bumped to 40", () => {
|
||||
expect(db.getSchemaVersion()).toBe(56);
|
||||
expect(db.getSchemaVersion()).toBe(57);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -51,7 +51,7 @@ describe("TaskStore task documents", () => {
|
||||
|
||||
expect(tableNames.has("task_documents")).toBe(true);
|
||||
expect(tableNames.has("task_document_revisions")).toBe(true);
|
||||
expect(db.getSchemaVersion()).toBe(56);
|
||||
expect(db.getSchemaVersion()).toBe(57);
|
||||
|
||||
const index = db
|
||||
.prepare(
|
||||
|
||||
28
packages/core/src/__tests__/use-droid-cli-settings.test.ts
Normal file
28
packages/core/src/__tests__/use-droid-cli-settings.test.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { GlobalSettings } from "../types.js";
|
||||
import {
|
||||
DEFAULT_GLOBAL_SETTINGS,
|
||||
GLOBAL_SETTINGS_KEYS,
|
||||
isGlobalSettingsKey,
|
||||
} from "../settings-schema.js";
|
||||
|
||||
describe("useDroidCli global setting", () => {
|
||||
it("is included in GLOBAL_SETTINGS_KEYS", () => {
|
||||
expect(GLOBAL_SETTINGS_KEYS).toContain("useDroidCli");
|
||||
});
|
||||
|
||||
it("defaults to undefined", () => {
|
||||
expect(DEFAULT_GLOBAL_SETTINGS.useDroidCli).toBeUndefined();
|
||||
});
|
||||
|
||||
it("is recognized by isGlobalSettingsKey", () => {
|
||||
expect(isGlobalSettingsKey("useDroidCli")).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts boolean values in GlobalSettings", () => {
|
||||
const enabled: GlobalSettings = { useDroidCli: true };
|
||||
const disabled: GlobalSettings = { useDroidCli: false };
|
||||
expect(enabled.useDroidCli).toBe(true);
|
||||
expect(disabled.useDroidCli).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { Router } from "express";
|
||||
import { registerModelRoutes } from "../routes/register-model-routes.js";
|
||||
|
||||
function setup(useDroidCli?: boolean) {
|
||||
const getHandlers = new Map<string, (req: unknown, res: { json: (body: unknown) => void }) => Promise<void>>();
|
||||
const router = {
|
||||
get: vi.fn((path: string, handler: (req: unknown, res: { json: (body: unknown) => void }) => Promise<void>) => {
|
||||
getHandlers.set(path, handler);
|
||||
}),
|
||||
} as unknown as Router;
|
||||
|
||||
const store = {
|
||||
getGlobalSettingsStore: () => ({
|
||||
getSettings: vi.fn().mockResolvedValue({ useDroidCli }),
|
||||
}),
|
||||
};
|
||||
|
||||
const runtimeLogger = {
|
||||
child: vi.fn(() => ({ warn: vi.fn() })),
|
||||
};
|
||||
|
||||
const modelRegistry = {
|
||||
refresh: vi.fn(),
|
||||
getAvailable: vi.fn(() => [
|
||||
{ provider: "droid-cli", id: "droid/model", name: "Droid", reasoning: false, contextWindow: 0 },
|
||||
{ provider: "openai", id: "gpt-5", name: "GPT-5", reasoning: true, contextWindow: 128000 },
|
||||
]),
|
||||
};
|
||||
|
||||
registerModelRoutes({
|
||||
router,
|
||||
store: store as never,
|
||||
runtimeLogger: runtimeLogger as never,
|
||||
options: { modelRegistry } as never,
|
||||
} as never);
|
||||
|
||||
return { handler: getHandlers.get("/models")!, modelRegistry };
|
||||
}
|
||||
|
||||
describe("registerModelRoutes droid-cli filter", () => {
|
||||
it("filters droid-cli models when useDroidCli is false", async () => {
|
||||
const { handler } = setup(false);
|
||||
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 droid-cli models when useDroidCli is true", async () => {
|
||||
const { handler } = setup(true);
|
||||
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(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { Router } from "express";
|
||||
import { registerSettingsMemoryRoutes } from "../routes/register-settings-memory-routes.js";
|
||||
|
||||
function setup(initialUseDroidCli = false) {
|
||||
const putHandlers = new Map<string, (req: { body: Record<string, unknown> }, res: { json: (body: unknown) => void }) => Promise<void>>();
|
||||
const router = {
|
||||
get: vi.fn(),
|
||||
put: vi.fn((path: string, handler: (req: { body: Record<string, unknown> }, res: { json: (body: unknown) => void }) => Promise<void>) => {
|
||||
putHandlers.set(path, handler);
|
||||
}),
|
||||
post: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
} as unknown as Router;
|
||||
|
||||
let globalSettings = { useDroidCli: initialUseDroidCli } as Record<string, unknown>;
|
||||
const onUseDroidCliToggled = vi.fn();
|
||||
|
||||
const store = {
|
||||
getGlobalSettingsStore: () => ({
|
||||
getSettings: vi.fn(async () => globalSettings),
|
||||
invalidateCache: vi.fn(),
|
||||
}),
|
||||
updateGlobalSettings: vi.fn(async (patch: Record<string, unknown>) => {
|
||||
globalSettings = { ...globalSettings, ...patch };
|
||||
return globalSettings;
|
||||
}),
|
||||
};
|
||||
|
||||
registerSettingsMemoryRoutes(
|
||||
{
|
||||
router,
|
||||
store: store as never,
|
||||
options: {
|
||||
onUseDroidCliToggled,
|
||||
engineManager: { getAllEngines: () => new Map() },
|
||||
} as never,
|
||||
runtimeLogger: { warn: vi.fn() } as never,
|
||||
getProjectContext: vi.fn() as never,
|
||||
rethrowAsApiError: (err: unknown): never => {
|
||||
throw err;
|
||||
},
|
||||
} as never,
|
||||
{
|
||||
validateModelPresets: () => undefined,
|
||||
sanitizeOverlapIgnorePaths: () => undefined,
|
||||
discoverDashboardPiExtensions: async () => ({ entries: [] }) as never,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
putSettingsGlobal: putHandlers.get("/settings/global")!,
|
||||
onUseDroidCliToggled,
|
||||
};
|
||||
}
|
||||
|
||||
describe("registerSettingsMemoryRoutes useDroidCli hook", () => {
|
||||
it("fires onUseDroidCliToggled on transition", async () => {
|
||||
const { putSettingsGlobal, onUseDroidCliToggled } = setup(false);
|
||||
await putSettingsGlobal({ body: { useDroidCli: true } }, { json: vi.fn() });
|
||||
expect(onUseDroidCliToggled).toHaveBeenCalledWith(false, true);
|
||||
});
|
||||
|
||||
it("does not fire onUseDroidCliToggled when value does not change", async () => {
|
||||
const { putSettingsGlobal, onUseDroidCliToggled } = setup(true);
|
||||
await putSettingsGlobal({ body: { useDroidCli: true } }, { json: vi.fn() });
|
||||
expect(onUseDroidCliToggled).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not fire onUseDroidCliToggled for unrelated settings updates", async () => {
|
||||
const { putSettingsGlobal, onUseDroidCliToggled } = setup(false);
|
||||
await putSettingsGlobal({ body: { defaultProvider: "openai" } }, { json: vi.fn() });
|
||||
expect(onUseDroidCliToggled).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -11,6 +11,7 @@ export const registerModelRoutes: ApiRouteRegistrar = (ctx) => {
|
||||
let defaultProvider: string | undefined;
|
||||
let defaultModelId: string | undefined;
|
||||
let useClaudeCli = false;
|
||||
let useDroidCli = false;
|
||||
if (store) {
|
||||
try {
|
||||
const globalStore = store.getGlobalSettingsStore();
|
||||
@@ -20,6 +21,7 @@ export const registerModelRoutes: ApiRouteRegistrar = (ctx) => {
|
||||
defaultProvider = globalSettings.defaultProvider;
|
||||
defaultModelId = globalSettings.defaultModelId;
|
||||
useClaudeCli = globalSettings.useClaudeCli === true;
|
||||
useDroidCli = globalSettings.useDroidCli === true;
|
||||
} catch {
|
||||
// Silently ignore settings errors - just return empty favorites/default model
|
||||
}
|
||||
@@ -61,6 +63,9 @@ export const registerModelRoutes: ApiRouteRegistrar = (ctx) => {
|
||||
if (!useClaudeCli) {
|
||||
models = models.filter((m) => m.provider !== "pi-claude-cli");
|
||||
}
|
||||
if (!useDroidCli) {
|
||||
models = models.filter((m) => m.provider !== "droid-cli");
|
||||
}
|
||||
|
||||
res.json({
|
||||
models,
|
||||
|
||||
Reference in New Issue
Block a user