fix assistant custom widget creation
This commit is contained in:
1 parent
474d9968b5
commit
ceed0979a1
21 files changed
+513
-47
No files matched your search
@@ -2,7 +2,7 @@
|
||||
|
||||
import { act, createElement, Fragment } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { afterEach, describe, expect, test } from "vitest";
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
|
||||
import {
|
||||
AssistantAutoApprovalProvider,
|
||||
@@ -67,6 +67,19 @@ describe("assistant automatic approval tracker", () => {
|
||||
expect(tracker.claim("app-create-1")).toBe(true);
|
||||
});
|
||||
|
||||
test("bounds automatic retries and permits a fresh claim after completion", () => {
|
||||
const tracker = createAssistantAutoApprovalTracker(2);
|
||||
|
||||
expect(tracker.claim("custom-widget-create-1")).toBe(true);
|
||||
tracker.release("custom-widget-create-1");
|
||||
expect(tracker.claim("custom-widget-create-1")).toBe(true);
|
||||
tracker.release("custom-widget-create-1");
|
||||
expect(tracker.claim("custom-widget-create-1")).toBe(false);
|
||||
|
||||
tracker.complete("custom-widget-create-1");
|
||||
expect(tracker.claim("custom-widget-create-1")).toBe(true);
|
||||
});
|
||||
|
||||
test("keeps the setting for the same local conversation and resets it on a real switch", async () => {
|
||||
const container = document.createElement("div");
|
||||
containers.push(container);
|
||||
@@ -185,4 +198,48 @@ describe("assistant automatic approval tracker", () => {
|
||||
|
||||
await act(async () => root.unmount());
|
||||
});
|
||||
|
||||
test("retries an approval response that never settles and restores manual controls after two attempts", async () => {
|
||||
vi.useFakeTimers();
|
||||
const container = document.createElement("div");
|
||||
containers.push(container);
|
||||
document.body.append(container);
|
||||
const root = createRoot(container);
|
||||
let confirmationCount = 0;
|
||||
|
||||
await act(async () => {
|
||||
root.render(
|
||||
createElement(
|
||||
AssistantAutoApprovalProvider,
|
||||
{ conversationId: "local-thread-1" },
|
||||
createElement(
|
||||
Fragment,
|
||||
null,
|
||||
createElement(AutoApprovalProbe),
|
||||
createElement(AutomaticActionProbe, {
|
||||
ready: true,
|
||||
completed: false,
|
||||
confirm: () => {
|
||||
confirmationCount += 1;
|
||||
},
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
act(() => currentAutoApproval?.setEnabled(true));
|
||||
expect(confirmationCount).toBe(1);
|
||||
expect(automaticActionInProgress).toBe(true);
|
||||
|
||||
await act(async () => vi.advanceTimersByTime(5_000));
|
||||
expect(confirmationCount).toBe(2);
|
||||
expect(automaticActionInProgress).toBe(true);
|
||||
|
||||
await act(async () => vi.advanceTimersByTime(5_000));
|
||||
expect(confirmationCount).toBe(2);
|
||||
expect(automaticActionInProgress).toBe(false);
|
||||
|
||||
await act(async () => root.unmount());
|
||||
vi.useRealTimers();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user