38 lines
2.2 KiB
TypeScript
38 lines
2.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { serializeAnalysisJob } from "../src/repositories/analysisJobRepository.js";
|
|
import { buildProjectContextResume } from "../src/services/contextResolver.js";
|
|
|
|
describe("MCP efficiency hints", () => {
|
|
it("finishes open PRs before starting newer delivery branches", () => {
|
|
const resume = buildProjectContextResume(
|
|
[{ id: "repo", owner: "Jens", repository: "app", accessMode: "read_write", defaultBranch: "main" }],
|
|
[{ id: "new", title: "New plan", status: "approved", approvalState: "approved" }, { id: "existing", title: "Finish me", status: "pull_request_open", approvalState: "approved", runs: [{ pullRequestNumber: 7 }] }], [],
|
|
);
|
|
expect(resume.nextAction).toMatchObject({ type: "review-and-merge", deliveryId: "existing", pullRequestNumber: 7 });
|
|
});
|
|
it("returns one durable resume action for an active delivery", () => {
|
|
const resume = buildProjectContextResume(
|
|
[{ id: "repo-1", owner: "Jens", repository: "app", accessMode: "read_write", defaultBranch: "main" }],
|
|
[{ id: "delivery-1", title: "Improve MCP", status: "executing", approvalState: "approved", runs: [{ branch: "chatgpt/mcp", headSha: "abc" }] }],
|
|
[],
|
|
"2026-08-27T00:00:00.000Z",
|
|
);
|
|
|
|
expect(resume).toMatchObject({
|
|
repositoryCount: 1,
|
|
activeDelivery: { id: "delivery-1", branch: "chatgpt/mcp" },
|
|
nextAction: { type: "continue-implementation", deliveryId: "delivery-1" },
|
|
});
|
|
expect(resume.stateVersion).toMatch(/^[0-9a-f]{24}$/);
|
|
});
|
|
|
|
it("tells clients when and whether to poll analysis state", () => {
|
|
const running = serializeAnalysisJob({ id: "job-1", status: "running", progressCurrent: 1, progressTotal: 4, updatedAt: new Date("2026-08-27T00:00:00.000Z") });
|
|
const succeeded = serializeAnalysisJob({ id: "job-1", status: "succeeded", progressCurrent: 4, progressTotal: 4, updatedAt: new Date("2026-08-27T00:01:00.000Z") });
|
|
|
|
expect(running).toMatchObject({ terminal: false, pollAfterMs: 4_000, nextAction: "wait-for-change" });
|
|
expect(succeeded).toMatchObject({ terminal: true, pollAfterMs: 0, nextAction: "read-results" });
|
|
expect(running.stateVersion).not.toBe(succeeded.stateVersion);
|
|
});
|
|
});
|