feat: add per-provider timeout for usage panel to prevent blocking on slow responses

fix: update scheduler filesystem path from .kb to .fusion for task validation

style: clean up TaskDetailModal styling with reusable CSS classes

test: add comprehensive tests for file-service operations with mocked filesystem
This commit is contained in:
gsxdsm
2026-04-01 22:38:18 -07:00
parent f96879380c
commit 5654d2e230
30 changed files with 1281 additions and 142 deletions

View File

@@ -0,0 +1,81 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import type { TaskStore } from "@fusion/core";
import { dirname, resolve } from "path";
// Create mock functions that can be configured in tests
const mocks = vi.hoisted(() => ({
mockReaddir: vi.fn(),
mockReadFile: vi.fn(),
mockWriteFile: vi.fn(),
mockStat: vi.fn(),
mockExistsSync: vi.fn(),
}));
// Hoist mocks alongside vi.mock
vi.mock("node:fs/promises", async () => {
const actual = await import("node:fs/promises");
return {
default: {
readdir: mocks.mockReaddir,
readFile: mocks.mockReadFile,
writeFile: mocks.mockWriteFile,
stat: mocks.mockStat,
},
readdir: mocks.mockReaddir,
readFile: mocks.mockReadFile,
writeFile: mocks.mockWriteFile,
stat: mocks.mockStat,
};
});
vi.mock("node:fs", async () => {
const actual = await import("node:fs");
return {
default: {
existsSync: mocks.mockExistsSync,
},
existsSync: mocks.mockExistsSync,
};
});
// Import AFTER mocks are set up
import { writeProjectFile } from "../file-service";
describe("debug", () => {
beforeEach(() => {
mocks.mockStat.mockReset();
});
it("test", async () => {
const mockGetRootDir = vi.fn();
const mockStore = {
getRootDir: mockGetRootDir,
} as unknown as TaskStore;
mockGetRootDir.mockReturnValue("/test/project");
let callCount = 0;
mocks.mockStat.mockImplementation(async (path: string) => {
callCount++;
console.log(`stat call #${callCount}:`, path);
// Return a simple object
const result = {
isDirectory: () => path.includes("/file.txt"),
isFile: () => !path.includes("/file.txt"),
};
console.log(`stat #${callCount} returning:`, result);
console.log(`stat #${callCount} isDirectory():`, result.isDirectory());
return result;
});
try {
await writeProjectFile(mockStore, "file.txt/sub.txt", "content");
console.log("Success!");
} catch (e: any) {
console.log("Error:", e.message);
}
});
});