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
+15 -5
View File
@@ -59,16 +59,26 @@ const scenario = async () => {
source: {
repo_key: join(root, ".git"),
repo_root: root,
source_checkout_path: path,
source_workspace_id: id,
source_checkout_path: root,
source_workspace_id: "w1",
},
worktrees: [
{
path,
is_linked_worktree: path !== root,
path: root,
is_linked_worktree: false,
is_bare: false,
open_workspace_id: id,
open_workspace_id: "w1",
},
...(path === root
? []
: [
{
path,
is_linked_worktree: true,
is_bare: false,
open_workspace_id: id,
},
]),
],
},
});
+7 -1
View File
@@ -76,7 +76,13 @@ export default Plugin.define({
background: input.background,
...(input.child
? { sessionID: input.child }
: { worktree: { base: "main" } }),
: {
worktree: {
base: "main",
branch: "fix/native-host",
label: "Fix native host",
},
}),
},
{
sessionID: Session.ID.make(input.parent),
+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();
+97 -2
View File
@@ -18,14 +18,26 @@ class FixtureHerdr extends Herdr {
verified = 0;
delayCreation = false;
creationAborted = false;
createdBase: string | undefined;
createdBranch: string | undefined;
createdLabel: string | undefined;
creationStarted = Promise.withResolvers<void>();
override async root(directory: string) {
return this.eligible && directory === "/root"
? { directory, workspaceID: "w1", repo: "/root/.git" }
: undefined;
}
override async create(_root: HerdrRoot, _base: string, branch: string, signal: AbortSignal) {
override async create(
_root: HerdrRoot,
base: string,
branch: string,
signal: AbortSignal,
label?: string,
) {
this.creations++;
this.createdBase = base;
this.createdBranch = branch;
this.createdLabel = label;
if (!this.eligible) throw new Error("root closed");
if (this.delayCreation) {
this.creationStarted.resolve();
@@ -295,7 +307,13 @@ const request = z.object({
agent: z.string(),
description: z.string(),
prompt: z.string(),
worktree: z.object({ base: z.string() }).optional(),
worktree: z
.object({
base: z.string(),
branch: z.string().optional(),
label: z.string().optional(),
})
.optional(),
sessionID: z.string().optional(),
background: z.boolean().optional(),
});
@@ -348,6 +366,83 @@ test("local fast-lo uses native delegation without a worktree", async () => {
);
});
test("custom branch and workspace label pass through delegation", async () => {
const f = fixture();
await Effect.runPromise(
Effect.scoped(
Effect.gen(function* () {
yield* f.install;
const result = yield* f.execute({
agent: "coordinate",
description: "Fix login timeout",
prompt: "work",
worktree: {
base: "main",
branch: "fix/login-timeout",
label: "Fix login timeout",
},
});
expect(f.herdr.createdBase).toBe("main");
expect(f.herdr.createdBranch).toBe("fix/login-timeout");
expect(f.herdr.createdLabel).toBe("Fix login timeout");
expect(result.metadata?.branch).toBe("fix/login-timeout");
}),
),
);
});
test("omitted naming retains generated branch and no explicit label", async () => {
const f = fixture();
await Effect.runPromise(
Effect.scoped(
Effect.gen(function* () {
yield* f.install;
yield* f.invoke();
expect(f.herdr.createdBranch).toMatch(/^multi-work\/[0-9a-f-]{36}$/);
expect(f.herdr.createdLabel).toBeUndefined();
}),
),
);
});
test("rejects empty naming fields and naming on resume", async () => {
const f = fixture();
await Effect.runPromise(
Effect.scoped(
Effect.gen(function* () {
yield* f.install;
for (const worktree of [
{ base: "main", branch: " " },
{ base: "main", label: " " },
])
expect(
(yield* Effect.exit(
f.execute({
agent: "coordinate",
description: "invalid",
prompt: "work",
worktree,
}),
))._tag,
).toBe("Failure");
yield* f.invoke();
expect(
(yield* Effect.exit(
f.execute({
agent: "coordinate",
description: "resume",
prompt: "work",
sessionID: "ses_child1",
worktree: { base: "main", branch: "fix/other" },
}),
))._tag,
).toBe("Failure");
expect(f.herdr.creations).toBe(1);
}),
),
);
});
test("root loss, session permission denial and missing destination fail before prompting", async () => {
for (const failure of ["root", "permission", "ask", "destination", "project"] as const) {
const f = fixture();