This commit is contained in:
+151
-1
@@ -14,6 +14,8 @@ import { bindingKey, bindingSchema, installMultiWork } from "../src/multi-work.j
|
||||
|
||||
class FixtureHerdr extends Herdr {
|
||||
eligible = true;
|
||||
rootWorkspaceID = "w1";
|
||||
rootRepo = "/root/.git";
|
||||
creations = 0;
|
||||
verified = 0;
|
||||
delayCreation = false;
|
||||
@@ -24,7 +26,7 @@ class FixtureHerdr extends Herdr {
|
||||
creationStarted = Promise.withResolvers<void>();
|
||||
override async root(directory: string) {
|
||||
return this.eligible && directory === "/root"
|
||||
? { directory, workspaceID: "w1", repo: "/root/.git" }
|
||||
? { directory, workspaceID: this.rootWorkspaceID, repo: this.rootRepo }
|
||||
: undefined;
|
||||
}
|
||||
override async create(
|
||||
@@ -366,6 +368,128 @@ test("local fast-lo uses native delegation without a worktree", async () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("coordinate can create and resume a root-local background child without Herdr creation or movement", async () => {
|
||||
const f = fixture();
|
||||
f.parent.permissions = [{ action: "herdr_worktree", resource: "*", effect: "deny" }];
|
||||
await Effect.runPromise(
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
yield* f.install;
|
||||
const created = yield* f.execute({
|
||||
agent: "coordinate",
|
||||
description: "local edit",
|
||||
prompt: "edit assigned files",
|
||||
background: true,
|
||||
});
|
||||
expect(created.metadata).toMatchObject({
|
||||
sessionID: "ses_child1",
|
||||
status: "running",
|
||||
directory: "/root",
|
||||
workspaceID: "w1",
|
||||
branch: "root",
|
||||
});
|
||||
expect(f.herdr.creations).toBe(0);
|
||||
expect(f.order).toEqual(["create", "prompt:/root"]);
|
||||
expect(bindingSchema.parse(f.storage.get(bindingKey("ses_child1")))).toMatchObject({
|
||||
owner: "ses_parent",
|
||||
directory: "/root",
|
||||
workspaceID: "w1",
|
||||
branch: "root",
|
||||
ready: true,
|
||||
});
|
||||
yield* f.execute({
|
||||
agent: "coordinate",
|
||||
description: "resume local",
|
||||
prompt: "continue",
|
||||
sessionID: "ses_child1",
|
||||
});
|
||||
expect(f.herdr.creations).toBe(0);
|
||||
expect(f.herdr.verified).toBe(0);
|
||||
}),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test("root-local resume rejects location, binding, and live-root changes", async () => {
|
||||
for (const tamper of ["session", "workspace", "root", "branch", "live-root"] as const) {
|
||||
const f = fixture();
|
||||
await Effect.runPromise(
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
yield* f.install;
|
||||
yield* f.execute({
|
||||
agent: "coordinate",
|
||||
description: "local edit",
|
||||
prompt: "work",
|
||||
});
|
||||
if (tamper === "session")
|
||||
f.sessions.get("ses_child1")!.location.directory = "/other";
|
||||
else if (tamper === "live-root") f.herdr.rootWorkspaceID = "foreign";
|
||||
else {
|
||||
const binding = bindingSchema.parse(
|
||||
f.storage.get(bindingKey("ses_child1")),
|
||||
);
|
||||
const changed = { ...binding };
|
||||
if (tamper === "workspace") changed.workspaceID = "foreign";
|
||||
if (tamper === "root") {
|
||||
changed.root = { ...binding.root, workspaceID: "foreign" };
|
||||
changed.workspaceID = "foreign";
|
||||
}
|
||||
if (tamper === "branch") changed.branch = "main";
|
||||
f.storage.set(bindingKey("ses_child1"), changed);
|
||||
}
|
||||
expect(
|
||||
(yield* Effect.exit(
|
||||
f.execute({
|
||||
agent: "coordinate",
|
||||
description: "resume",
|
||||
prompt: "continue",
|
||||
sessionID: "ses_child1",
|
||||
}),
|
||||
))._tag,
|
||||
).toBe("Failure");
|
||||
expect(f.prompts).toBe(1);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("interrupted root-local creation retains its binding and cannot be blindly replayed", async () => {
|
||||
const f = fixture();
|
||||
f.hold();
|
||||
const controller = new AbortController();
|
||||
const running = Effect.runPromise(
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
yield* f.install;
|
||||
return yield* f.execute({
|
||||
agent: "coordinate",
|
||||
description: "local edit",
|
||||
prompt: "work",
|
||||
});
|
||||
}),
|
||||
),
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
await f.entered.promise;
|
||||
controller.abort();
|
||||
await expect(running).rejects.toBeDefined();
|
||||
expect(bindingSchema.parse(f.storage.get(bindingKey("ses_child1"))).ready).toBe(true);
|
||||
expect(f.storage.has(`multi-work-call:${f.call.sessionID}:${f.call.id}`)).toBe(true);
|
||||
const replay = await Effect.runPromise(
|
||||
Effect.exit(
|
||||
f.execute({
|
||||
agent: "coordinate",
|
||||
description: "local edit",
|
||||
prompt: "work",
|
||||
}),
|
||||
),
|
||||
);
|
||||
expect(replay._tag).toBe("Failure");
|
||||
expect(f.prompts).toBe(1);
|
||||
});
|
||||
|
||||
test("custom branch and workspace label pass through delegation", async () => {
|
||||
const f = fixture();
|
||||
await Effect.runPromise(
|
||||
@@ -623,6 +747,32 @@ test("configured build restrictions remain effective for worktree preparation",
|
||||
);
|
||||
});
|
||||
|
||||
test("worktree resumes retain the herdr_worktree permission guard", async () => {
|
||||
const f = fixture();
|
||||
await Effect.runPromise(
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
yield* f.install;
|
||||
yield* f.invoke();
|
||||
f.parent.permissions = [
|
||||
{ action: "herdr_worktree", resource: "*", effect: "deny" },
|
||||
];
|
||||
const resumed = yield* Effect.exit(
|
||||
f.execute({
|
||||
agent: "coordinate",
|
||||
description: "resume",
|
||||
prompt: "continue",
|
||||
sessionID: "ses_child1",
|
||||
}),
|
||||
);
|
||||
expect(resumed._tag).toBe("Failure");
|
||||
expect(f.herdr.verified).toBe(0);
|
||||
expect(f.prompts).toBe(1);
|
||||
}),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test("failed initialization records the attempt and never blindly recreates on replay", async () => {
|
||||
const f = fixture();
|
||||
f.missingDestination();
|
||||
|
||||
+13
-10
@@ -306,17 +306,17 @@ async function host(
|
||||
child = target;
|
||||
for (const hook of sessionHooks.prompt ?? []) await hook({ sessionID: "child" });
|
||||
},
|
||||
bindCoordinate(ready: boolean, moved = true) {
|
||||
childDirectory = moved ? `${directory}/worktree` : directory;
|
||||
bindCoordinate(ready: boolean, moved = true, local = false) {
|
||||
childDirectory = local ? directory : moved ? `${directory}/worktree` : directory;
|
||||
storage.set(bindingKey("child"), {
|
||||
owner: "parent",
|
||||
child: "child",
|
||||
projectID: "project-fixture",
|
||||
ready,
|
||||
root: { directory, workspaceID: "w1", repo: `${directory}/.git` },
|
||||
directory: `${directory}/worktree`,
|
||||
workspaceID: "w2",
|
||||
branch: "multi-work/test",
|
||||
directory: local ? directory : `${directory}/worktree`,
|
||||
workspaceID: local ? "w1" : "w2",
|
||||
branch: local ? "root" : "multi-work/test",
|
||||
});
|
||||
},
|
||||
async tools(caller: string) {
|
||||
@@ -663,22 +663,25 @@ test("manual calls and command-created child sessions cannot bypass delegation r
|
||||
expect((await result.tools("build")).subagent?.description).toBe("Native subagents");
|
||||
});
|
||||
|
||||
test("coordinate prompt admission requires both owned provenance and a completed move; multi-work cannot be a child", async () => {
|
||||
test("coordinate prompt admission requires owned ready placement; local and moved bindings work", async () => {
|
||||
const result = await host();
|
||||
await expect(result.command("multi-work", "coordinate")).rejects.toThrow(
|
||||
"ready worktree binding",
|
||||
"ready multi-work binding",
|
||||
);
|
||||
result.bindCoordinate(false);
|
||||
await expect(result.command("multi-work", "coordinate")).rejects.toThrow(
|
||||
"ready worktree binding",
|
||||
"ready multi-work binding",
|
||||
);
|
||||
result.bindCoordinate(true, false);
|
||||
await expect(result.command("multi-work", "coordinate")).rejects.toThrow(
|
||||
"ready worktree binding",
|
||||
"ready multi-work binding",
|
||||
);
|
||||
result.bindCoordinate(true);
|
||||
await result.command("multi-work", "coordinate");
|
||||
await expect(result.command("build", "coordinate")).rejects.toThrow("ready worktree binding");
|
||||
result.bindCoordinate(true, true, true);
|
||||
await result.command("multi-work", "coordinate");
|
||||
await expect(result.command("build", "coordinate")).rejects.toThrow("ready multi-work binding");
|
||||
result.bindCoordinate(true);
|
||||
await expect(result.command("multi-work", "fast-lo")).rejects.toThrow("local fast-lo");
|
||||
for (const invoke of [result.delegate, result.command])
|
||||
await expect(invoke("build", "multi-work")).rejects.toThrow("primary only");
|
||||
|
||||
+74
-3
@@ -2,6 +2,7 @@ import { expect, test } from "bun:test";
|
||||
import type { Plugin } from "@opencode/plugin/tui";
|
||||
import type { Route, SlotMap } from "@opencode/plugin/tui/context";
|
||||
import { testRender, type JSX } from "@opentui/solid";
|
||||
import { jsx } from "@opentui/solid/jsx-runtime";
|
||||
import { createSignal } from "solid-js";
|
||||
import { build } from "../scripts/build.js";
|
||||
import type { QuotaStatus } from "../src/quota.js";
|
||||
@@ -87,12 +88,19 @@ test("built quota slot stays reactive across pending, empty, failure, update, an
|
||||
const renderHome = homeRender;
|
||||
const home = await testRender(() => renderHome({ mode: "normal", showDetails: false }), {
|
||||
width: 40,
|
||||
height: 5,
|
||||
height: 6,
|
||||
});
|
||||
await home.waitForFrame((frame) => frame.includes("ChatGPT quota (home)"));
|
||||
const homeFrame = home.captureCharFrame();
|
||||
expect(homeFrame).toContain(" ChatGPT quota (home)");
|
||||
expect(homeFrame).toContain(" 5h: 90% · due");
|
||||
expect(homeFrame.split("\n")).toEqual([
|
||||
" ",
|
||||
" ",
|
||||
" ChatGPT quota (home) ",
|
||||
" 5h: 90% · due ",
|
||||
" ",
|
||||
" ",
|
||||
"",
|
||||
]);
|
||||
expect(statusCalls).toBe(1);
|
||||
home.renderer.destroy();
|
||||
|
||||
@@ -152,3 +160,66 @@ test("built quota slot stays reactive across pending, empty, failure, update, an
|
||||
if (cleanup) await cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("home quota stays out of the host footer row at wide and narrow widths", async () => {
|
||||
await build();
|
||||
const { default: plugin } = await import(new URL("../dist/tui.js", import.meta.url).href);
|
||||
let homeRender: HomeSlotRender | undefined;
|
||||
const contextFixture = {
|
||||
client: {
|
||||
rpc: () => ({
|
||||
status: async () => status("home", 90),
|
||||
events: { on: () => () => undefined },
|
||||
}),
|
||||
},
|
||||
ui: {
|
||||
slot(claim: { after?: "prompt.footer"; render: HomeSlotRender }) {
|
||||
if (claim.after === "prompt.footer") homeRender = claim.render;
|
||||
return () => undefined;
|
||||
},
|
||||
router: { current: () => ({ type: "home" as const }) },
|
||||
},
|
||||
theme: { text: { default: "#ffffff", muted: "#888888" } },
|
||||
};
|
||||
// SAFETY: This focused fixture implements every context member read by slot setup/rendering.
|
||||
const cleanup = await plugin.setup(Object.assign({} as Plugin.Context, contextFixture));
|
||||
if (!homeRender) throw new Error("Plugin did not register the home slot");
|
||||
const renderHome = homeRender;
|
||||
try {
|
||||
for (const width of [75, 40]) {
|
||||
const footer = (quota: boolean) =>
|
||||
jsx("box", {
|
||||
flexDirection: "row",
|
||||
children: [
|
||||
jsx("text", { children: "/project" }),
|
||||
jsx("box", { flexGrow: 1 }),
|
||||
jsx("text", { children: "NORMAL" }),
|
||||
jsx("text", { children: " ctrl+k commands" }),
|
||||
quota ? renderHome({ mode: "normal", showDetails: false }) : undefined,
|
||||
],
|
||||
});
|
||||
const baseline = await testRender(() => footer(false), { width, height: 6 });
|
||||
const rendered = await testRender(() => footer(true), { width, height: 6 });
|
||||
try {
|
||||
await baseline.renderOnce();
|
||||
await rendered.waitForFrame((frame) => frame.includes("ChatGPT quota (home)"));
|
||||
const baselineRows = baseline.captureCharFrame().split("\n");
|
||||
const quotaRows = rendered.captureCharFrame().split("\n");
|
||||
expect(quotaRows[0]).toBe(baselineRows[0]);
|
||||
expect(quotaRows[0]).toContain("/project");
|
||||
expect(quotaRows[0]).toContain("NORMAL ctrl+k commands");
|
||||
expect(quotaRows[1]?.trim()).toBe("");
|
||||
expect(quotaRows[2]?.trim()).toBe("ChatGPT quota (home)");
|
||||
expect(quotaRows[3]?.trim()).toBe("5h: 90% · due");
|
||||
expect(quotaRows[2]?.indexOf("ChatGPT quota (home)")).toBe(
|
||||
Math.ceil((width - "ChatGPT quota (home)".length) / 2),
|
||||
);
|
||||
} finally {
|
||||
baseline.renderer.destroy();
|
||||
rendered.renderer.destroy();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (cleanup) await cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user