feat(FN-3876): add GitHub tracking test coverage across settings, issues, s
Adds comprehensive test coverage for GitHub tracking across four areas: settings inheritance, issue creation, status sync transitions, and unlink sync regression — spanning 280 lines of new tests across four test files with minimal store.ts adjustment. Fusion-Task-Id: FN-3876
This commit is contained in:
@@ -124,8 +124,8 @@ describe("GitHubTrackingCommentService", () => {
|
||||
it("ignores non-target columns", async () => {
|
||||
service.start();
|
||||
|
||||
for (const to of ["triage", "todo", "in-review", "archived"]) {
|
||||
store.emit("task:moved", { task: createTask(), from: "todo", to });
|
||||
for (const [from, to] of [["triage", "todo"], ["todo", "triage"], ["todo", "in-review"], ["in-review", "archived"]] as const) {
|
||||
store.emit("task:moved", { task: createTask(), from, to });
|
||||
}
|
||||
await flushAsync();
|
||||
|
||||
|
||||
@@ -151,7 +151,9 @@ describe("GitHubTrackingStateService", () => {
|
||||
it("does nothing for non-done transitions", async () => {
|
||||
service.start();
|
||||
|
||||
store.emit("task:moved", { task: createTask(), from: "todo", to: "in-progress" });
|
||||
for (const [from, to] of [["triage", "todo"], ["todo", "in-progress"], ["in-review", "in-review"]] as const) {
|
||||
store.emit("task:moved", { task: createTask(), from, to });
|
||||
}
|
||||
await flushAsync();
|
||||
|
||||
expect(mockSetIssueState).not.toHaveBeenCalled();
|
||||
|
||||
127
packages/dashboard/src/__tests__/github-tracking-unlink.test.ts
Normal file
127
packages/dashboard/src/__tests__/github-tracking-unlink.test.ts
Normal file
@@ -0,0 +1,127 @@
|
||||
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 { TaskStore } from "@fusion/core";
|
||||
import { GitHubTrackingCommentService } from "../github-tracking-comments.js";
|
||||
import { GitHubTrackingStateService } from "../github-tracking-state.js";
|
||||
|
||||
const { mockCommentOnIssue, mockSetIssueState, mockResolveGithubTrackingAuth } = vi.hoisted(() => ({
|
||||
mockCommentOnIssue: vi.fn(),
|
||||
mockSetIssueState: vi.fn(),
|
||||
mockResolveGithubTrackingAuth: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../github.js", () => ({
|
||||
GitHubClient: vi.fn().mockImplementation(() => ({
|
||||
commentOnIssue: (...args: unknown[]) => mockCommentOnIssue(...args),
|
||||
setIssueState: (...args: unknown[]) => mockSetIssueState(...args),
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock("../github-auth.js", () => ({
|
||||
resolveGithubTrackingAuth: (...args: unknown[]) => mockResolveGithubTrackingAuth(...args),
|
||||
}));
|
||||
|
||||
function makeTmpDir(): string {
|
||||
return mkdtempSync(join(tmpdir(), "kb-dashboard-github-tracking-unlink-test-"));
|
||||
}
|
||||
|
||||
async function flushAsync(): Promise<void> {
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
}
|
||||
|
||||
describe("github tracking unlink flow", () => {
|
||||
let rootDir: string;
|
||||
let globalDir: string;
|
||||
let store: TaskStore;
|
||||
let commentService: GitHubTrackingCommentService;
|
||||
let stateService: GitHubTrackingStateService;
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks();
|
||||
mockResolveGithubTrackingAuth.mockReturnValue({ ok: true, auth: { mode: "token", token: "token" } });
|
||||
rootDir = makeTmpDir();
|
||||
globalDir = makeTmpDir();
|
||||
store = new TaskStore(rootDir, globalDir, { inMemoryDb: true });
|
||||
await store.init();
|
||||
commentService = new GitHubTrackingCommentService(store);
|
||||
stateService = new GitHubTrackingStateService(store);
|
||||
commentService.start();
|
||||
stateService.start();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
commentService.stop();
|
||||
stateService.stop();
|
||||
await flushAsync();
|
||||
store.close();
|
||||
await rm(rootDir, { recursive: true, force: true });
|
||||
await rm(globalDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("clears linked issue metadata on unlink while preserving toggle semantics", async () => {
|
||||
const task = await store.createTask({
|
||||
description: "unlink",
|
||||
githubTracking: {
|
||||
enabled: true,
|
||||
repoOverride: "octocat/hello-world",
|
||||
},
|
||||
});
|
||||
|
||||
await store.linkGithubIssue(task.id, {
|
||||
owner: "octocat",
|
||||
repo: "hello-world",
|
||||
number: 7,
|
||||
url: "https://github.com/octocat/hello-world/issues/7",
|
||||
createdAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const unlinked = await store.unlinkGithubIssue(task.id);
|
||||
expect(unlinked.githubTracking?.issue).toBeUndefined();
|
||||
expect(unlinked.githubTracking?.unlinkedAt).toBeTruthy();
|
||||
expect(unlinked.githubTracking?.enabled).toBe(true);
|
||||
});
|
||||
|
||||
it("stops all status-sync calls after unlink and does not mutate remote issue during unlink", async () => {
|
||||
const task = await store.createTask({
|
||||
description: "unlink sync",
|
||||
githubTracking: { enabled: true },
|
||||
});
|
||||
|
||||
await store.linkGithubIssue(task.id, {
|
||||
owner: "octocat",
|
||||
repo: "hello-world",
|
||||
number: 9,
|
||||
url: "https://github.com/octocat/hello-world/issues/9",
|
||||
createdAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
await store.moveTask(task.id, "todo");
|
||||
await store.moveTask(task.id, "in-progress");
|
||||
await store.moveTask(task.id, "done");
|
||||
await flushAsync();
|
||||
|
||||
expect(mockCommentOnIssue).toHaveBeenCalled();
|
||||
expect(mockSetIssueState).toHaveBeenCalled();
|
||||
|
||||
mockCommentOnIssue.mockClear();
|
||||
mockSetIssueState.mockClear();
|
||||
|
||||
await store.unlinkGithubIssue(task.id);
|
||||
await flushAsync();
|
||||
|
||||
// unlink is local-only: should not close/reopen/comment as a side-effect
|
||||
expect(mockCommentOnIssue).not.toHaveBeenCalled();
|
||||
expect(mockSetIssueState).not.toHaveBeenCalled();
|
||||
|
||||
await store.moveTask(task.id, "todo");
|
||||
await store.moveTask(task.id, "in-progress");
|
||||
await store.moveTask(task.id, "done");
|
||||
await flushAsync();
|
||||
|
||||
expect(mockCommentOnIssue).not.toHaveBeenCalled();
|
||||
expect(mockSetIssueState).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -57,6 +57,19 @@ describe("formatTrackingIssueBody", () => {
|
||||
summary: "Summary paragraph",
|
||||
})).toBe("Fusion task: FN-X\n\nPrimary paragraph");
|
||||
});
|
||||
|
||||
it("does not include full prompt content or fusion hyperlinks", () => {
|
||||
const body = formatTrackingIssueBody({
|
||||
id: "FN-X",
|
||||
description: "Short summary only",
|
||||
prompt: "# PROMPT\nhttp://localhost:4040/tasks/FN-X\nFull private prompt",
|
||||
});
|
||||
|
||||
expect(body).toContain("Fusion task: FN-X");
|
||||
expect(body).toContain("Short summary only");
|
||||
expect(body).not.toContain("localhost:4040/tasks/FN-X");
|
||||
expect(body).not.toContain("Full private prompt");
|
||||
});
|
||||
});
|
||||
|
||||
describe("maybeCreateTrackingIssue", () => {
|
||||
@@ -108,12 +121,45 @@ describe("maybeCreateTrackingIssue", () => {
|
||||
|
||||
expect(result.created).toBe(true);
|
||||
expect(createIssueMock).toHaveBeenCalledTimes(1);
|
||||
expect(createIssueMock).toHaveBeenCalledWith(expect.objectContaining({
|
||||
title: expect.stringContaining("[FN-1]"),
|
||||
body: expect.stringContaining("Fusion task: FN-1"),
|
||||
}));
|
||||
expect(linkGithubIssue).toHaveBeenCalledWith("FN-1", expect.objectContaining({ owner: "o", repo: "r", number: 12 }));
|
||||
expect(recordActivity).toHaveBeenCalledWith(expect.objectContaining({
|
||||
metadata: expect.objectContaining({ type: "github-issue-created", repo: "o/r", number: 12 }),
|
||||
}));
|
||||
});
|
||||
|
||||
it.each([
|
||||
["task override", { enabled: true, repoOverride: "task/repo" }, { githubTrackingDefaultRepo: "project/repo" }, { githubTrackingDefaultRepo: "global/repo" }, "task", "repo"],
|
||||
["project default", { enabled: true }, { githubTrackingDefaultRepo: "project/repo" }, { githubTrackingDefaultRepo: "global/repo" }, "project", "repo"],
|
||||
["global default", { enabled: true }, {}, { githubTrackingDefaultRepo: "global/repo" }, "global", "repo"],
|
||||
] as const)("resolves repo from %s", async (_label, tracking, projectSettings, globalSettings, owner, repo) => {
|
||||
const linkGithubIssue = vi.fn();
|
||||
|
||||
await maybeCreateTrackingIssue(buildTask({ githubTracking: tracking }), {
|
||||
taskStore: { linkGithubIssue, recordActivity: vi.fn() } as any,
|
||||
projectSettings: projectSettings as any,
|
||||
globalSettings: globalSettings as any,
|
||||
logger: console,
|
||||
});
|
||||
|
||||
expect(createIssueMock).toHaveBeenCalledWith(expect.objectContaining({ owner, repo }));
|
||||
});
|
||||
|
||||
it("skips creation when tracking is on but no repo is configured", async () => {
|
||||
const result = await maybeCreateTrackingIssue(buildTask({ githubTracking: { enabled: true } }), {
|
||||
taskStore: { recordActivity: vi.fn() } as any,
|
||||
projectSettings: {},
|
||||
globalSettings: {},
|
||||
logger: { warn: vi.fn(), info: vi.fn() },
|
||||
});
|
||||
|
||||
expect(result).toEqual({ created: false, reason: "no_repo_configured" });
|
||||
expect(createIssueMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns auth reason when resolver fails", async () => {
|
||||
resolveAuthMock.mockReturnValue({
|
||||
ok: false,
|
||||
|
||||
Reference in New Issue
Block a user