feat(FN-4044): restore github tracking patch persistence

Restored GitHub tracking patch persistence in the core store with matching test coverage in the task detail and routes tasks ops suites, plus documentation for the repaired flow.

Fusion-Task-Id: FN-4044
This commit is contained in:
Fusion
2026-05-11 17:50:30 -07:00
committed by gsxdsm
parent 55bcf045eb
commit 1d6c85e900
6 changed files with 100 additions and 7 deletions

View File

@@ -2225,7 +2225,23 @@ describe("TaskDetailModal", () => {
it("shows create tracking issue action for enabled but unlinked tasks outside editable columns", async () => {
const { updateTask } = await import("../../api");
const mockUpdate = vi.mocked(updateTask);
mockUpdate.mockResolvedValueOnce({ id: "FN-001" } as Task);
const onTaskUpdated = vi.fn();
const addToast = vi.fn();
const updatedTask = makeTask({
id: "FN-001",
column: "done",
githubTracking: {
enabled: true,
issue: {
owner: "runfusion",
repo: "fusion",
number: 77,
url: "https://github.com/runfusion/fusion/issues/77",
createdAt: "2026-01-01T00:00:00Z",
},
},
});
mockUpdate.mockResolvedValueOnce(updatedTask as Task);
render(
<TaskDetailModal
@@ -2235,7 +2251,8 @@ describe("TaskDetailModal", () => {
onMoveTask={noopMove}
onDeleteTask={noopDelete}
onMergeTask={noopMerge}
addToast={noop}
onTaskUpdated={onTaskUpdated}
addToast={addToast}
/>,
);
@@ -2245,6 +2262,8 @@ describe("TaskDetailModal", () => {
await waitFor(() => {
expect(mockUpdate).toHaveBeenCalledWith("FN-001", { githubTracking: { enabled: true } }, undefined);
});
expect(onTaskUpdated).toHaveBeenCalledWith(updatedTask);
expect(addToast).toHaveBeenCalledWith("Requested GitHub tracking issue creation", "info");
expect(screen.queryByLabelText("Enable GitHub tracking")).toBeNull();
});

View File

@@ -16,8 +16,8 @@ describe("github tracking documentation contract", () => {
expect(taskManagement).toContain("## GitHub Tracking Issues");
expect(taskManagement).toContain("They are **not** the same as imported source issues (`issueInfo` / `sourceIssue`)");
expect(taskManagement).toContain("task creation flows (including quick create, planning output, and subtask creation paths that create tasks)");
expect(taskManagement).toContain("Fusion also attempts issue creation on existing-task edits that update `githubTracking`");
expect(taskManagement).toContain("task creation flows (including quick create, planning output, automation `create-task` workflow steps, and subtask creation paths that create tasks)");
expect(taskManagement).toContain("For existing tasks, PATCH first persists any `githubTracking` mutation");
expect(taskManagement).toContain("task.githubTracking.enabled");
expect(taskManagement).toContain("task.githubTracking.repoOverride");
expect(taskManagement).toContain("Repository resolution order");

View File

@@ -153,7 +153,7 @@ vi.mock("@fusion/engine", async () => {
});
});
import { AgentStore, Database, RoutineStore, isGhAvailable, isGhAuthenticated } from "@fusion/core";
import { AgentStore, Database, RoutineStore, TaskStore as CoreTaskStore, isGhAvailable, isGhAuthenticated } from "@fusion/core";
import { createFnAgent } from "@fusion/engine";
const mockIsGhAvailable = vi.mocked(isGhAvailable);
@@ -1819,6 +1819,58 @@ describe("PATCH /tasks/:id", () => {
createIssueSpy.mockRestore();
});
it("PATCH persists githubTracking for existing tasks and links created issue with a real store", async () => {
const rootDir = mkdtempSync(join(tmpdir(), "kb-routes-patch-github-tracking-"));
const globalDir = mkdtempSync(join(tmpdir(), "kb-routes-patch-github-tracking-global-"));
const realStore = new CoreTaskStore(rootDir, globalDir, { inMemoryDb: true });
await realStore.init();
const createIssueSpy = vi.spyOn(GitHubClient.prototype, "createIssue").mockResolvedValue({
owner: "runfusion",
repo: "fusion",
number: 74,
htmlUrl: "https://github.com/runfusion/fusion/issues/74",
createdAt: "2026-01-01T00:00:00.000Z",
});
try {
await realStore.updateSettings({
githubAuthMode: "token",
githubAuthToken: "tok",
githubTrackingDefaultRepo: "runfusion/fusion",
});
const created = await realStore.createTask({ description: "route patch flow", column: "todo" });
const app = express();
app.use(express.json());
app.use("/api", createApiRoutes(realStore));
const res = await REQUEST(app, "PATCH", `/api/tasks/${created.id}`, JSON.stringify({
githubTracking: { enabled: true },
}), {
"Content-Type": "application/json",
});
expect(res.status).toBe(200);
expect(createIssueSpy).toHaveBeenCalledWith(expect.objectContaining({ owner: "runfusion", repo: "fusion" }));
expect(res.body.githubTracking?.enabled).toBe(true);
expect(res.body.githubTracking?.issue).toMatchObject({
owner: "runfusion",
repo: "fusion",
number: 74,
});
const persisted = await realStore.getTask(created.id);
expect(persisted.githubTracking?.enabled).toBe(true);
expect(persisted.githubTracking?.issue?.number).toBe(74);
} finally {
createIssueSpy.mockRestore();
realStore.close();
rmSync(rootDir, { recursive: true, force: true });
rmSync(globalDir, { recursive: true, force: true });
}
});
it("does not recreate tracking issue during explicit manual unlink patch", async () => {
const createIssueSpy = vi.spyOn(GitHubClient.prototype, "createIssue").mockResolvedValue({
owner: "runfusion",