Skip to content

Commit d653ad1

Browse files
test(mcp): group worktree inventory coverage
1 parent a19a6f4 commit d653ad1

1 file changed

Lines changed: 131 additions & 225 deletions

File tree

‎apps/server/src/mcp/WorktreeMcpService.test.ts‎

Lines changed: 131 additions & 225 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,6 +2017,137 @@ describe("t3_worktree_list", () => {
20172017
expect(harness.listWorktrees).toHaveBeenCalledTimes(2);
20182018
});
20192019
});
2020+
it.effect("bounds nested binding identity reads by the requested page", () => {
2021+
const nestedOne = `${workspaceRoot}/packages/one`;
2022+
const nestedTwo = `${workspaceRoot}/packages/two`;
2023+
const nestedThree = `${workspaceRoot}/packages/three`;
2024+
const harness = makeHarness({
2025+
worktrees: [{ path: workspaceRoot, refName: "dev" }],
2026+
projectThreads: [
2027+
{ id: threadId, title: "Caller", branch: "dev", worktreePath: null },
2028+
{
2029+
id: ThreadId.make("thread-nested-binding-one"),
2030+
title: "Nested one",
2031+
branch: "dev",
2032+
worktreePath: nestedOne,
2033+
},
2034+
{
2035+
id: ThreadId.make("thread-nested-binding-two"),
2036+
title: "Nested two",
2037+
branch: "dev",
2038+
worktreePath: nestedTwo,
2039+
},
2040+
{
2041+
id: ThreadId.make("thread-nested-binding-three"),
2042+
title: "Nested three",
2043+
branch: "dev",
2044+
worktreePath: nestedThree,
2045+
},
2046+
],
2047+
});
2048+
return Effect.gen(function* () {
2049+
const result = yield* runList(harness, { limit: 1, bindingLimit: 1 });
2050+
2051+
expect(result.bindingPathResolution).toEqual({
2052+
totalCandidates: 3,
2053+
attemptedCandidates: 1,
2054+
truncated: true,
2055+
complete: false,
2056+
});
2057+
expect(result.worktrees[0]?.bindingCount).toBe(2);
2058+
expect(harness.listWorktrees).toHaveBeenCalledTimes(2);
2059+
});
2060+
});
2061+
2062+
it.effect("resolves only nested binding candidates for the selected worktree page", () => {
2063+
const firstWorktree = "/worktrees/project-a";
2064+
const secondWorktree = "/worktrees/project-b";
2065+
const firstNestedPath = `${firstWorktree}/packages/app`;
2066+
const secondNestedPath = `${secondWorktree}/packages/app`;
2067+
const listedWorktrees = [
2068+
{ path: workspaceRoot, refName: "dev" },
2069+
{ path: firstWorktree, refName: "feature/a" },
2070+
{ path: secondWorktree, refName: "feature/b" },
2071+
];
2072+
const harness = makeHarness({
2073+
worktrees: listedWorktrees,
2074+
projectThreads: [
2075+
{
2076+
id: ThreadId.make("thread-off-page-nested-binding"),
2077+
title: "Off-page nested binding",
2078+
branch: "feature/a",
2079+
worktreePath: firstNestedPath,
2080+
},
2081+
{
2082+
id: threadId,
2083+
title: "Selected-page nested binding",
2084+
branch: "feature/b",
2085+
worktreePath: secondNestedPath,
2086+
},
2087+
],
2088+
worktreeInventories: {
2089+
[firstNestedPath]: {
2090+
repositoryCommonDir: "/repo/.git",
2091+
currentWorktreeRoot: firstWorktree,
2092+
worktrees: listedWorktrees,
2093+
},
2094+
[secondNestedPath]: {
2095+
repositoryCommonDir: "/repo/.git",
2096+
currentWorktreeRoot: secondWorktree,
2097+
worktrees: listedWorktrees,
2098+
},
2099+
},
2100+
});
2101+
return Effect.gen(function* () {
2102+
const result = yield* runList(harness, { cursor: 2, limit: 1, bindingLimit: 1 });
2103+
2104+
expect(result.bindingPathResolution).toEqual({
2105+
totalCandidates: 1,
2106+
attemptedCandidates: 1,
2107+
truncated: false,
2108+
complete: true,
2109+
});
2110+
expect(result.worktrees[0]).toMatchObject({
2111+
path: secondWorktree,
2112+
bindingCount: 1,
2113+
bindings: [expect.objectContaining({ threadId })],
2114+
});
2115+
expect(harness.listWorktrees).toHaveBeenCalledTimes(2);
2116+
expect(harness.listWorktrees).not.toHaveBeenCalledWith(firstNestedPath);
2117+
expect(harness.listWorktrees).toHaveBeenCalledWith(secondNestedPath);
2118+
});
2119+
});
2120+
2121+
it.effect("reports incomplete binding counts when a candidate inventory read fails", () => {
2122+
const nestedPath = `${workspaceRoot}/packages/unreadable`;
2123+
const harness = makeHarness({
2124+
worktrees: [{ path: workspaceRoot, refName: "dev" }],
2125+
projectThreads: [
2126+
{
2127+
id: threadId,
2128+
title: "Unreadable nested binding",
2129+
branch: "dev",
2130+
worktreePath: nestedPath,
2131+
},
2132+
],
2133+
worktreeInventoryFailsFor: new Set([nestedPath]),
2134+
});
2135+
return Effect.gen(function* () {
2136+
const result = yield* runList(harness, { limit: 1 });
2137+
2138+
expect(result.bindingPathResolution).toEqual({
2139+
totalCandidates: 1,
2140+
attemptedCandidates: 1,
2141+
truncated: false,
2142+
complete: false,
2143+
});
2144+
expect(result.worktrees[0]).toMatchObject({
2145+
path: workspaceRoot,
2146+
bindingCount: 0,
2147+
bindings: [],
2148+
});
2149+
});
2150+
});
20202151
});
20212152

20222153
describe("t3_thread_checkout", () => {
@@ -2655,231 +2786,6 @@ describe("t3_thread_checkout", () => {
26552786
});
26562787
});
26572788

2658-
it.effect("bounds nested binding identity reads by the requested page", () => {
2659-
const nestedOne = `${workspaceRoot}/packages/one`;
2660-
const nestedTwo = `${workspaceRoot}/packages/two`;
2661-
const nestedThree = `${workspaceRoot}/packages/three`;
2662-
const harness = makeHarness({
2663-
worktrees: [{ path: workspaceRoot, refName: "dev" }],
2664-
projectThreads: [
2665-
{ id: threadId, title: "Caller", branch: "dev", worktreePath: null },
2666-
{
2667-
id: ThreadId.make("thread-nested-binding-one"),
2668-
title: "Nested one",
2669-
branch: "dev",
2670-
worktreePath: nestedOne,
2671-
},
2672-
{
2673-
id: ThreadId.make("thread-nested-binding-two"),
2674-
title: "Nested two",
2675-
branch: "dev",
2676-
worktreePath: nestedTwo,
2677-
},
2678-
{
2679-
id: ThreadId.make("thread-nested-binding-three"),
2680-
title: "Nested three",
2681-
branch: "dev",
2682-
worktreePath: nestedThree,
2683-
},
2684-
],
2685-
});
2686-
return Effect.gen(function* () {
2687-
const result = yield* runList(harness, { limit: 1, bindingLimit: 1 });
2688-
2689-
expect(result.bindingPathResolution).toEqual({
2690-
totalCandidates: 3,
2691-
attemptedCandidates: 1,
2692-
truncated: true,
2693-
complete: false,
2694-
});
2695-
expect(result.worktrees[0]?.bindingCount).toBe(2);
2696-
expect(harness.listWorktrees).toHaveBeenCalledTimes(2);
2697-
});
2698-
});
2699-
2700-
it.effect("resolves only nested binding candidates for the selected worktree page", () => {
2701-
const firstWorktree = "/worktrees/project-a";
2702-
const secondWorktree = "/worktrees/project-b";
2703-
const firstNestedPath = `${firstWorktree}/packages/app`;
2704-
const secondNestedPath = `${secondWorktree}/packages/app`;
2705-
const listedWorktrees = [
2706-
{ path: workspaceRoot, refName: "dev" },
2707-
{ path: firstWorktree, refName: "feature/a" },
2708-
{ path: secondWorktree, refName: "feature/b" },
2709-
];
2710-
const harness = makeHarness({
2711-
worktrees: listedWorktrees,
2712-
projectThreads: [
2713-
{
2714-
id: ThreadId.make("thread-off-page-nested-binding"),
2715-
title: "Off-page nested binding",
2716-
branch: "feature/a",
2717-
worktreePath: firstNestedPath,
2718-
},
2719-
{
2720-
id: threadId,
2721-
title: "Selected-page nested binding",
2722-
branch: "feature/b",
2723-
worktreePath: secondNestedPath,
2724-
},
2725-
],
2726-
worktreeInventories: {
2727-
[firstNestedPath]: {
2728-
repositoryCommonDir: "/repo/.git",
2729-
currentWorktreeRoot: firstWorktree,
2730-
worktrees: listedWorktrees,
2731-
},
2732-
[secondNestedPath]: {
2733-
repositoryCommonDir: "/repo/.git",
2734-
currentWorktreeRoot: secondWorktree,
2735-
worktrees: listedWorktrees,
2736-
},
2737-
},
2738-
});
2739-
return Effect.gen(function* () {
2740-
const result = yield* runList(harness, { cursor: 2, limit: 1, bindingLimit: 1 });
2741-
2742-
expect(result.bindingPathResolution).toEqual({
2743-
totalCandidates: 1,
2744-
attemptedCandidates: 1,
2745-
truncated: false,
2746-
complete: true,
2747-
});
2748-
expect(result.worktrees[0]).toMatchObject({
2749-
path: secondWorktree,
2750-
bindingCount: 1,
2751-
bindings: [expect.objectContaining({ threadId })],
2752-
});
2753-
expect(harness.listWorktrees).toHaveBeenCalledTimes(2);
2754-
expect(harness.listWorktrees).not.toHaveBeenCalledWith(firstNestedPath);
2755-
expect(harness.listWorktrees).toHaveBeenCalledWith(secondNestedPath);
2756-
});
2757-
});
2758-
2759-
it.effect("reports incomplete binding counts when a candidate inventory read fails", () => {
2760-
const nestedPath = `${workspaceRoot}/packages/unreadable`;
2761-
const harness = makeHarness({
2762-
worktrees: [{ path: workspaceRoot, refName: "dev" }],
2763-
projectThreads: [
2764-
{
2765-
id: threadId,
2766-
title: "Unreadable nested binding",
2767-
branch: "dev",
2768-
worktreePath: nestedPath,
2769-
},
2770-
],
2771-
worktreeInventoryFailsFor: new Set([nestedPath]),
2772-
});
2773-
return Effect.gen(function* () {
2774-
const result = yield* runList(harness, { limit: 1 });
2775-
2776-
expect(result.bindingPathResolution).toEqual({
2777-
totalCandidates: 1,
2778-
attemptedCandidates: 1,
2779-
truncated: false,
2780-
complete: false,
2781-
});
2782-
expect(result.worktrees[0]).toMatchObject({
2783-
path: workspaceRoot,
2784-
bindingCount: 0,
2785-
bindings: [],
2786-
});
2787-
});
2788-
});
2789-
2790-
it.effect("includes archived thread bindings retained on a physical checkout", () => {
2791-
const archivedThreadId = ThreadId.make("thread-archived-list-owner");
2792-
const harness = makeHarness({
2793-
worktrees: [{ path: workspaceRoot, refName: "dev" }],
2794-
archivedProjectThread: {
2795-
id: archivedThreadId,
2796-
title: "Archived checkout owner",
2797-
branch: "dev",
2798-
worktreePath: workspaceRoot,
2799-
},
2800-
});
2801-
return Effect.gen(function* () {
2802-
const result = yield* runList(harness, { limit: 1 });
2803-
2804-
expect(result.worktrees[0]).toMatchObject({
2805-
path: workspaceRoot,
2806-
bindingCount: 2,
2807-
bindings: expect.arrayContaining([
2808-
expect.objectContaining({
2809-
threadId: archivedThreadId,
2810-
recordedWorktreePath: workspaceRoot,
2811-
active: false,
2812-
}),
2813-
]),
2814-
});
2815-
});
2816-
});
2817-
2818-
it.effect("attributes a nested recorded cwd to its physical worktree root", () => {
2819-
const nestedPath = `${workspaceRoot}/packages/app`;
2820-
const harness = makeHarness({
2821-
worktrees: [{ path: workspaceRoot, refName: "dev" }],
2822-
projectThreads: [
2823-
{
2824-
id: threadId,
2825-
title: "Nested caller",
2826-
branch: "dev",
2827-
worktreePath: nestedPath,
2828-
},
2829-
],
2830-
});
2831-
return Effect.gen(function* () {
2832-
const result = yield* runList(harness, { limit: 1 });
2833-
2834-
expect(result.worktrees[0]).toMatchObject({
2835-
path: workspaceRoot,
2836-
bindingCount: 1,
2837-
bindings: [
2838-
{
2839-
threadId,
2840-
recordedWorktreePath: nestedPath,
2841-
callingThread: true,
2842-
},
2843-
],
2844-
});
2845-
expect(harness.localStatus).toHaveBeenCalledTimes(1);
2846-
expect(harness.listWorktrees).toHaveBeenCalledTimes(2);
2847-
});
2848-
});
2849-
2850-
it.effect("does not attribute a nested independent repository to the project worktree", () => {
2851-
const nestedPath = `${workspaceRoot}/vendor/independent`;
2852-
const harness = makeHarness({
2853-
worktrees: [{ path: workspaceRoot, refName: "dev" }],
2854-
projectThreads: [
2855-
{
2856-
id: threadId,
2857-
title: "Nested independent repository",
2858-
branch: "main",
2859-
worktreePath: nestedPath,
2860-
},
2861-
],
2862-
worktreeInventories: {
2863-
[nestedPath]: {
2864-
repositoryCommonDir: `${nestedPath}/.git`,
2865-
currentWorktreeRoot: nestedPath,
2866-
worktrees: [{ path: nestedPath, refName: "main" }],
2867-
},
2868-
},
2869-
});
2870-
return Effect.gen(function* () {
2871-
const result = yield* runList(harness, { limit: 1 });
2872-
2873-
expect(result.worktrees[0]).toMatchObject({
2874-
path: workspaceRoot,
2875-
bindingCount: 0,
2876-
bindings: [],
2877-
});
2878-
expect(harness.localStatus).toHaveBeenCalledTimes(1);
2879-
expect(harness.listWorktrees).toHaveBeenCalledTimes(2);
2880-
});
2881-
});
2882-
28832789
it.effect("rejects a physical worktree bound through another project alias", () => {
28842790
const targetPath = "/worktrees/project/cross-project";
28852791
const otherProjectRoot = "/aliases/other-project";

0 commit comments

Comments
 (0)