fix(FN-2107): normalize task ID handling for task creation tools
- Return the created task ID directly from runTaskPlan and propagate it through fn_task_plan - Remove hardcoded FN-### log parsing so CLI extension supports structured IDs like PROJ-042 - Add heartbeat fallback parsing from task_create text output when details.taskId is absent - Expand engine and CLI tests to cover structured task IDs and updated task-plan return behavior
This commit is contained in:
@@ -10,9 +10,14 @@ vi.mock("@fusion/core/gh-cli", () => ({
|
||||
getGhErrorMessage: vi.fn((error: unknown) => (error instanceof Error ? error.message : String(error))),
|
||||
}));
|
||||
|
||||
vi.mock("../commands/task.js", () => ({
|
||||
runTaskPlan: vi.fn(),
|
||||
}));
|
||||
|
||||
import kbExtension from "../extension.js";
|
||||
import { TaskStore } from "@fusion/core";
|
||||
import { isGhAvailable, isGhAuthenticated, runGhJsonAsync } from "@fusion/core/gh-cli";
|
||||
import { runTaskPlan } from "../commands/task.js";
|
||||
|
||||
// ── Mock ExtensionAPI that captures registrations ──────────────────
|
||||
|
||||
@@ -73,6 +78,7 @@ describe("fn pi extension", () => {
|
||||
vi.mocked(isGhAvailable).mockReturnValue(true);
|
||||
vi.mocked(isGhAuthenticated).mockReturnValue(true);
|
||||
vi.mocked(runGhJsonAsync).mockReset();
|
||||
vi.mocked(runTaskPlan).mockReset();
|
||||
|
||||
tmpDir = await mkdtemp(join(tmpdir(), "kb-ext-test-"));
|
||||
api = createMockAPI();
|
||||
@@ -144,6 +150,25 @@ describe("fn pi extension", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("fn_task_plan", () => {
|
||||
it("uses runTaskPlan return value for taskId regardless of prefix", async () => {
|
||||
vi.mocked(runTaskPlan).mockResolvedValueOnce("PROJ-042");
|
||||
const tool = api.tools.get("fn_task_plan")!;
|
||||
|
||||
const result = await tool.execute(
|
||||
"plan-1",
|
||||
{ description: "Plan a project task" },
|
||||
undefined,
|
||||
undefined,
|
||||
makeCtx(tmpDir),
|
||||
);
|
||||
|
||||
expect(runTaskPlan).toHaveBeenCalledWith("Plan a project task", true);
|
||||
expect(result.details.taskId).toBe("PROJ-042");
|
||||
expect(result.content[0].text).toContain("Task PROJ-042");
|
||||
});
|
||||
});
|
||||
|
||||
describe("fn_task_create", () => {
|
||||
it("creates a task and returns its ID", async () => {
|
||||
const tool = api.tools.get("fn_task_create")!;
|
||||
|
||||
@@ -405,24 +405,15 @@ describe("runTaskPlan", () => {
|
||||
|
||||
mockQuestion.mockResolvedValueOnce("y");
|
||||
|
||||
const exitSpy = vi.spyOn(process, "exit").mockImplementation(() => {
|
||||
throw new Error("Process.exit called");
|
||||
});
|
||||
|
||||
try {
|
||||
await runTaskPlan("Build something", true);
|
||||
} catch {
|
||||
// expected
|
||||
}
|
||||
const taskId = await runTaskPlan("Build something", true);
|
||||
|
||||
expect(taskId).toBe("FN-042");
|
||||
expect(mockCreateTask).toHaveBeenCalledWith({
|
||||
title: "Planned Task",
|
||||
description: "A well-planned task",
|
||||
column: "triage",
|
||||
dependencies: ["FN-001"],
|
||||
});
|
||||
|
||||
exitSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("prompts for confirmation without --yes flag", async () => {
|
||||
@@ -575,22 +566,13 @@ describe("runTaskPlan", () => {
|
||||
.mockResolvedValueOnce("y")
|
||||
.mockResolvedValueOnce("n");
|
||||
|
||||
const exitSpy = vi.spyOn(process, "exit").mockImplementation(() => {
|
||||
throw new Error("Process.exit called");
|
||||
});
|
||||
|
||||
try {
|
||||
await runTaskPlan("Build something", false);
|
||||
} catch {
|
||||
// expected
|
||||
}
|
||||
const taskId = await runTaskPlan("Build something", false);
|
||||
|
||||
expect(taskId).toBeUndefined();
|
||||
expect(mockCreateTask).not.toHaveBeenCalled();
|
||||
expect(mockConsoleLog).toHaveBeenCalledWith(
|
||||
expect.stringContaining("Task creation cancelled")
|
||||
);
|
||||
|
||||
exitSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("validates single_select input and retries on invalid", async () => {
|
||||
|
||||
Reference in New Issue
Block a user