fix wrong herdr response parse + add labels and branch names to delegations
CI / verify (pull_request) Failing after 8s

This commit is contained in:
2026-09-17 21:32:26 +02:00
parent 5cf0beb74b
commit 9494936160
9 changed files with 291 additions and 38 deletions
+105 -8
View File
@@ -38,6 +38,12 @@ async function fixture() {
let linked = false;
let duplicate = false;
let branch = "";
let label: string | undefined;
let sourceWorkspaceIDOverride: string | undefined;
let sourcePathOverride: string | undefined;
let childWorkspaceIDOverride: string | undefined;
let childPathOverride: string | undefined;
let repoOverride: string | undefined;
const run = async (args: string[], cwd: string, signal: AbortSignal) => {
calls.push(args);
if (args[0] !== "herdr") return command(args, cwd, signal);
@@ -52,21 +58,33 @@ async function fixture() {
if (args[2] === "list") {
const id = args[4]!;
const path = id === "w2" ? destination : root;
const sourceWorkspaceID = sourceWorkspaceIDOverride ?? (id === "w2" ? "w1" : id);
const sourcePath = sourcePathOverride ?? root;
return JSON.stringify({
result: {
source: {
repo_key: join(root, ".git"),
repo_key: repoOverride ?? join(root, ".git"),
repo_root: root,
source_checkout_path: path,
source_workspace_id: id,
source_checkout_path: sourcePath,
source_workspace_id: sourceWorkspaceID,
},
worktrees: [
{
path,
is_linked_worktree: id === "w2" || linked,
path: sourcePath,
is_linked_worktree: linked,
is_bare: false,
open_workspace_id: id,
open_workspace_id: sourceWorkspaceID,
},
...(id === "w2"
? [
{
path: childPathOverride ?? path,
is_linked_worktree: true,
is_bare: false,
open_workspace_id: childWorkspaceIDOverride ?? id,
},
]
: []),
],
},
});
@@ -75,6 +93,8 @@ async function fixture() {
expect(args.slice(3, 5)).toEqual(["--cwd", root]);
expect(args.at(-1)).toBe("--no-focus");
branch = args[args.indexOf("--branch") + 1]!;
const labelIndex = args.indexOf("--label");
label = labelIndex === -1 ? undefined : args[labelIndex + 1];
const base = args[args.indexOf("--base") + 1]!;
// Real Git worktree behavior, but only in an isolated temporary repository.
await command(["git", "worktree", "add", "-b", branch, destination, base], root, signal);
@@ -90,6 +110,9 @@ async function fixture() {
destination,
signal,
calls,
get label() {
return label;
},
herdr: new Herdr(run),
close() {
open = false;
@@ -100,10 +123,23 @@ async function fixture() {
duplicate() {
duplicate = true;
},
changeInventory(change: {
sourceWorkspaceID?: string | undefined;
sourcePath?: string | undefined;
childWorkspaceID?: string | undefined;
childPath?: string | undefined;
repo?: string | undefined;
}) {
sourceWorkspaceIDOverride = change.sourceWorkspaceID;
sourcePathOverride = change.sourcePath;
childWorkspaceIDOverride = change.childWorkspaceID;
childPathOverride = change.childPath;
repoOverride = change.repo;
},
};
}
test("live inventory recognizes an unannotated root and creates a unique branch from another local branch", async () => {
test("create verifies a linked workspace whose inventory source remains the parent workspace", async () => {
const f = await fixture();
const root = await f.herdr.root(f.root, f.signal);
expect(root?.workspaceID).toBe("w1");
@@ -114,12 +150,73 @@ test("live inventory recognizes an unannotated root and creates a unique branch
await f.herdr.verify(
destination.directory,
destination.workspaceID,
root!.repo,
root!,
destination.branch,
f.signal,
);
});
test("create passes an optional workspace label to Herdr", async () => {
const f = await fixture();
const root = (await f.herdr.root(f.root, f.signal))!;
const destination = await f.herdr.create(
root,
"main",
"fix/login-timeout",
f.signal,
"Fix login timeout",
);
expect(destination.branch).toBe("fix/login-timeout");
expect(f.label).toBe("Fix login timeout");
const creation = f.calls.find((args) => args[0] === "herdr" && args[2] === "create")!;
expect(creation.slice(creation.indexOf("--label"), creation.indexOf("--label") + 2)).toEqual([
"--label",
"Fix login timeout",
]);
});
test("create rejects an existing destination branch before invoking Herdr", async () => {
const f = await fixture();
const root = (await f.herdr.root(f.root, f.signal))!;
await expect(
f.herdr.create(root, "main", "invalid branch", f.signal, "Invalid"),
).rejects.toThrow();
await expect(f.herdr.create(root, "main", "other", f.signal, "Other")).rejects.toThrow(
"Destination branch already exists: other",
);
expect(f.calls.filter((args) => args[0] === "herdr" && args[2] === "create")).toHaveLength(0);
});
test("verify rejects changed parent, child and repository identities", async () => {
for (const change of [
{ sourceWorkspaceID: "w9" },
{ sourcePath: "child" },
{ childWorkspaceID: "w9" },
{ childPath: "root" },
{ repo: "child" },
]) {
const f = await fixture();
const root = (await f.herdr.root(f.root, f.signal))!;
const destination = await f.herdr.create(root, "main", "multi-work/fixture", f.signal);
f.changeInventory({
sourceWorkspaceID: change.sourceWorkspaceID,
sourcePath: change.sourcePath === "child" ? f.destination : undefined,
childWorkspaceID: change.childWorkspaceID,
childPath: change.childPath === "root" ? f.root : undefined,
repo: change.repo === "child" ? f.destination : undefined,
});
await expect(
f.herdr.verify(
destination.directory,
destination.workspaceID,
root,
destination.branch,
f.signal,
),
).rejects.toThrow("Bound Herdr checkout is no longer available");
}
});
test("closed, linked and ambiguous workspaces fail root gating", async () => {
for (const mode of ["close", "link", "duplicate"] as const) {
const f = await fixture();