mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 18:07:00 +01:00
test(hermes): cover early steering ownership and timeout
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
01ad83057b
commit
9794f657b7
1 file changed
+59
@@ -29,6 +29,65 @@ const HANDLE: AcpRuntimeHandle = {
|
||||
};
|
||||
|
||||
describe("Codex ACPX runtime adapter", () => {
|
||||
async function pendingHermesSteering() {
|
||||
const pending = pendingExtensionTurn("turn-1");
|
||||
const runtime = Object.assign(fakeRuntime(), { requestExtension: vi.fn(async ({ params }) => ({
|
||||
accepted: true, turnToken: params.turnToken,
|
||||
})) });
|
||||
vi.mocked(runtime.startTurn).mockReturnValue(pending.turn);
|
||||
let created!: AcpRuntimeOptions & { onAgentInitialize?: (result: unknown) => void };
|
||||
const options = openOptions(fakeCommand()); options.profile = { ...options.profile, agent: "hermes" };
|
||||
const port = await openCodexAcpxRuntime(options, {
|
||||
createRegistry: () => registry(), createStore: () => store(), createRuntime: value => { created = value; return runtime; },
|
||||
});
|
||||
created.onAgentInitialize!({ agentCapabilities: { _meta: { paperclipHermes: { version: 1, steering: true } } } });
|
||||
const turn = port.startTurn({ text: "Work", requestId: "turn-1" });
|
||||
await turn.promptStarted;
|
||||
const delivery = port.steerActiveTurn!("Correction", "turn-1").then(() => null, error => error);
|
||||
await Promise.resolve(); await Promise.resolve();
|
||||
return { pending, runtime, created, port, turn, delivery };
|
||||
}
|
||||
|
||||
it("holds early Hermes steering until the owning native turn is acknowledged", async () => {
|
||||
const fixture = await pendingHermesSteering();
|
||||
const { pending, runtime, created, port, turn, delivery } = fixture;
|
||||
expect(runtime.requestExtension).not.toHaveBeenCalled();
|
||||
const identity = { version: 1, sessionId: "backend-1", turnToken: "00000000-0000-0000-0000-000000000001" };
|
||||
expect(() => created.onExtensionNotification!("_hermes/turn_started", { ...identity, sessionId: "foreign" })).toThrow("binding");
|
||||
expect(runtime.requestExtension).not.toHaveBeenCalled();
|
||||
created.onExtensionNotification!("_hermes/turn_started", identity);
|
||||
await expect(delivery).resolves.toBeNull();
|
||||
expect(runtime.requestExtension).toHaveBeenCalledExactlyOnceWith({ handle: HANDLE, method: "_hermes/steer",
|
||||
params: { sessionId: "backend-1", version: 1, turnToken: identity.turnToken, message: "Correction" }, sessionMode: "persistent" });
|
||||
expect(runtime.startTurn).toHaveBeenCalledTimes(1);
|
||||
pending.settle(); await turn.result; await port.close({ reason: "early steering acknowledged" });
|
||||
});
|
||||
|
||||
it.each(["cancel", "closeStream", "settle"] as const)("expires early Hermes steering when the owning turn ends by %s", async ending => {
|
||||
const { pending, runtime, port, turn, delivery } = await pendingHermesSteering();
|
||||
if (ending === "settle") { pending.settle(); await turn.result; }
|
||||
else await turn[ending]();
|
||||
const failure = await delivery;
|
||||
expect(failure).toBeInstanceOf(Error);
|
||||
expect(failure.message).toMatch(ending === "cancel" ? /cancelled/ : ending === "closeStream" ? /stream closed/ : /expired/);
|
||||
expect(runtime.requestExtension).not.toHaveBeenCalled();
|
||||
if (ending !== "settle") { pending.settle(); await turn.result; }
|
||||
await port.close({ reason: "early control owner ended" });
|
||||
});
|
||||
|
||||
it("bounds the native turn acknowledgement wait for early Hermes steering", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const { pending, runtime, port, turn, delivery } = await pendingHermesSteering();
|
||||
await vi.advanceTimersByTimeAsync(5_000);
|
||||
const failure = await delivery;
|
||||
expect(failure).toBeInstanceOf(Error);
|
||||
expect(failure.message).toContain("native turn acknowledgement timed out");
|
||||
expect(runtime.requestExtension).not.toHaveBeenCalled();
|
||||
pending.settle(); await turn.result; await port.close({ reason: "native acknowledgement absent" });
|
||||
} finally { vi.useRealTimers(); }
|
||||
});
|
||||
|
||||
it("accepts only the owning Hermes terminal usage after Stop and before prompt settlement", async () => {
|
||||
const pending = pendingExtensionTurn("turn-1");
|
||||
const runtime = fakeRuntime(); vi.mocked(runtime.startTurn).mockReturnValue(pending.turn);
|
||||
|
||||
Reference in new issue
Block a user