Files
kandev/apps/web/components/task-create-dialog-helpers.multi-repo.test.ts
T
Kandev Agent 9e8079de69 feat(multi-repo): per-repo git ops, unified branch endpoint, chip-style task create
Bundles a string of multi-repo fixes and refactors that came up while
testing the feature end-to-end:

- workspace_path stored on multi-repo TaskEnvironment was one level too
  high, so agentctl booted with the wrong WorkDir on cold start; fixed
  in resolveTaskEnvWorkspacePath + GetWorkspaceInfoForSession.
- Stage/Unstage/Discard/Commit/Revert/Reset/Amend now thread `repo`
  through agentctl client → WS handler → frontend hook → SessionGit
  fan-out, so the right git repo is targeted (was running at the task
  root, which isn't a git repo for multi-repo tasks).
- agentctl GitLog is multi-repo aware: when no `repo` is specified and
  per-repo trackers exist, fans out one log per repo and merges sorted
  newest-first with RepositoryName stamped on each commit.
- Per-repo grouping for files (Changes panel) and commits, with
  collapsible group headers; commits section defaults to collapsed.
  Algorithm extracted into one generic groupByRepositoryName helper
  (was copy-pasted three times).
- Task creation dialog rewritten around a unified `fs.repositories[]`
  list — no more "primary vs extras" split. Chip-style row with one
  pill per repo + branch, "+" to add, x to remove, GitHub URL toggle
  inline. Discovered (on-machine) repos appear in any chip's dropdown.
  Removes ~6 fields and 3 helpers from the dialog state.
- Branch listing endpoints collapsed to one:
  GET /workspaces/:id/branches?repository_id=X | path=Y
  Frontend collapses to a single useBranches hook with a tagged-union
  source. Drops two HTTP routes, two service methods, two API client
  funcs, and one whole hook file.

Tests added across the chain: workspace_path resolver, sort-commits-
by-date, manager poll-mode propagation, RepoSubpaths, chip grouping
+ collapse + per-repo isLatest, group-by-repo helper, dialog payload
builder + chip wiring + discovered-repo flow.
2026-04-26 21:23:48 +01:00

83 lines
2.8 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { buildRepositoriesPayload } from "./task-create-dialog-helpers";
describe("buildRepositoriesPayload — unified rows", () => {
it("maps each row in order, dropping empty ones silently", () => {
const payload = buildRepositoriesPayload({
useGitHubUrl: false,
githubUrl: "",
githubBranch: "",
githubPrHeadBranch: null,
repositories: [
{ key: "r0", repositoryId: "repo-front", branch: "main" },
{ key: "r1", repositoryId: "repo-back", branch: "develop" },
{ key: "r2", branch: "" }, // no repo picked yet — dropped
{ key: "r3", repositoryId: "repo-shared", branch: "" },
],
discoveredRepositories: [],
});
expect(payload).toEqual([
{ repository_id: "repo-front", base_branch: "main" },
{ repository_id: "repo-back", base_branch: "develop" },
{ repository_id: "repo-shared", base_branch: undefined },
]);
});
it("emits local_path + default_branch for discovered (on-machine) rows", () => {
const payload = buildRepositoriesPayload({
useGitHubUrl: false,
githubUrl: "",
githubBranch: "",
githubPrHeadBranch: null,
repositories: [
{ key: "r0", localPath: "/home/me/projects/local-project", branch: "trunk" },
{ key: "r1", repositoryId: "repo-back", branch: "main" },
],
discoveredRepositories: [
{ path: "/home/me/projects/local-project", default_branch: "trunk" },
// eslint-disable-next-line @typescript-eslint/no-explicit-any
] as any,
});
expect(payload).toEqual([
{
repository_id: "",
base_branch: "trunk",
local_path: "/home/me/projects/local-project",
default_branch: "trunk",
},
{ repository_id: "repo-back", base_branch: "main" },
]);
});
it("URL mode produces a single github_url entry and ignores the rows", () => {
const payload = buildRepositoriesPayload({
useGitHubUrl: true,
githubUrl: "github.com/owner/repo",
githubBranch: "feature-x",
githubPrHeadBranch: null,
repositories: [{ key: "r0", repositoryId: "ignored", branch: "ignored" }],
discoveredRepositories: [],
});
expect(payload).toEqual([
{
repository_id: "",
base_branch: "feature-x",
checkout_branch: undefined,
github_url: "github.com/owner/repo",
},
]);
});
it("single-row workspace repo: payload mirrors the row", () => {
const payload = buildRepositoriesPayload({
useGitHubUrl: false,
githubUrl: "",
githubBranch: "",
githubPrHeadBranch: null,
repositories: [{ key: "r0", repositoryId: "repo-only", branch: "main" }],
discoveredRepositories: [],
});
expect(payload).toEqual([{ repository_id: "repo-only", base_branch: "main" }]);
});
});