mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-11-16 08:20:34 +00:00
* feat(hitl): add human-in-the-loop approval for high-risk tool calls * fix(hitl): address approval review findings * docs(hitl): keep agent guidance under size limit * fix(hitl): guard approval pause recovery * docs(hitl): shrink inherited guidance * fix(hitl): harden approval admission and recovery * fix(approvals): address review safety and reconciliation gaps * ci: retry approval checks after runner timeout --------- Co-authored-by: wangzeren <1004695029@qq.com>
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { expect, test } from "@rstest/core";
|
|
import { QueryClient, QueryObserver } from "@tanstack/react-query";
|
|
|
|
import {
|
|
deriveHitlApprovalState,
|
|
invalidateStoppedThreadCaches,
|
|
} from "@/core/threads/hooks";
|
|
import { approvalsKey } from "@/core/threads/tool-approvals";
|
|
|
|
test("terminal invalidation reconciles pending child approvals in the current thread", async () => {
|
|
const client = new QueryClient();
|
|
const key = approvalsKey("thread", "owner");
|
|
const other = approvalsKey("other-thread", "owner");
|
|
client.setQueryData(key, { requests: [{ request_id: "child" }] });
|
|
client.setQueryData(other, { requests: [{ request_id: "other" }] });
|
|
let fetches = 0;
|
|
const observer = new QueryObserver(client, {
|
|
queryKey: key,
|
|
staleTime: Infinity,
|
|
queryFn: async () => {
|
|
fetches += 1;
|
|
return { requests: [] };
|
|
},
|
|
});
|
|
const unsubscribe = observer.subscribe(() => undefined);
|
|
invalidateStoppedThreadCaches(client, "thread", false);
|
|
await client.refetchQueries({ queryKey: key, stale: true });
|
|
expect(client.getQueryData(key)).toEqual({ requests: [] });
|
|
expect(fetches).toBeGreaterThan(0);
|
|
expect(client.getQueryState(other)?.isInvalidated).toBe(false);
|
|
unsubscribe();
|
|
client.clear();
|
|
});
|
|
|
|
test("a server-owned pending approval run supports degraded tools-node pauses", () => {
|
|
const args = {
|
|
liveInterrupt: undefined,
|
|
historyLoading: true,
|
|
answeredRequestIds: new Set<string>(),
|
|
next: ["tools"],
|
|
};
|
|
expect(
|
|
deriveHitlApprovalState({ ...args, pendingApprovalRun: true })
|
|
.hasPendingApproval,
|
|
).toBe(true);
|
|
expect(deriveHitlApprovalState(args).hasPendingApproval).toBe(false);
|
|
});
|