Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/web/src/components/BranchToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ interface BranchToolbarProps {
options?: { readonly fromSetting?: boolean },
) => void;
envLocked: boolean;
/** The branch can't be changed now (a message or goal is on its way). */
branchLocked?: boolean;
onCheckoutPullRequestRequest?: (reference: string) => void;
onComposerFocusRequest?: () => void;
availableEnvironments?: readonly EnvironmentOption[];
Expand Down Expand Up @@ -268,6 +270,7 @@ export const BranchToolbar = memo(function BranchToolbar({
activeThreadBranchOverrideFromSetting,
onActiveThreadBranchOverrideChange,
envLocked,
branchLocked = false,
onCheckoutPullRequestRequest,
onComposerFocusRequest,
availableEnvironments,
Expand Down Expand Up @@ -448,6 +451,7 @@ export const BranchToolbar = memo(function BranchToolbar({
threadId={threadId}
{...(draftId ? { draftId } : {})}
envLocked={envLocked}
locked={branchLocked}
{...(effectiveEnvModeOverride ? { effectiveEnvModeOverride } : {})}
{...(activeThreadBranchOverride !== undefined ? { activeThreadBranchOverride } : {})}
{...(activeThreadBranchOverrideFromSetting
Expand Down Expand Up @@ -526,6 +530,7 @@ export const BranchToolbar = memo(function BranchToolbar({
threadId={threadId}
{...(draftId ? { draftId } : {})}
envLocked={envLocked}
locked={branchLocked}
{...(effectiveEnvModeOverride ? { effectiveEnvModeOverride } : {})}
{...(activeThreadBranchOverride !== undefined ? { activeThreadBranchOverride } : {})}
{...(activeThreadBranchOverrideFromSetting
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/components/BranchToolbarBranchSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ interface BranchToolbarBranchSelectorProps {
threadId: ThreadId;
draftId?: DraftId;
envLocked: boolean;
/** The picker is off: a message or goal on its way has its branch. */
locked?: boolean;
effectiveEnvModeOverride?: "local" | "worktree";
activeThreadBranchOverride?: string | null;
/** The override is the base the "New worktrees from" setting gave, not a pick. */
Expand Down Expand Up @@ -126,6 +128,7 @@ export function BranchToolbarBranchSelector({
threadId,
draftId,
envLocked,
locked = false,
effectiveEnvModeOverride,
activeThreadBranchOverride,
activeThreadBranchOverrideFromSetting,
Expand Down Expand Up @@ -670,7 +673,8 @@ export function BranchToolbarBranchSelector({
}),
selectedCheckoutMissing,
);
const triggerDisabled = (isBranchesSearchPending && refs.length === 0) || isBranchActionPending;
const triggerDisabled =
locked || (isBranchesSearchPending && refs.length === 0) || isBranchActionPending;

function renderPickerItem(itemValue: string, index: number) {
if (checkoutPullRequestItemValue && itemValue === checkoutPullRequestItemValue) {
Expand Down
12 changes: 12 additions & 0 deletions apps/web/src/components/ChatView.agents.browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,18 @@ describe("ChatView (full app): agent browser tabs and rooms", () => {
).toMatchObject({ requestId, choice: "review" }),
{ timeout: 8_000, interval: 16 },
);
// The server took the answer, but the thread has not caught up yet, so
// the card is still there. Its buttons stay off: a second answer in
// that gap would be refused as an invite already answered.
await new Promise((resolve) => setTimeout(resolve, 300));
expect(document.querySelector('[data-testid="agent-invite-panel"]')).toBe(panel);
expect(
[...panel.querySelectorAll<HTMLButtonElement>("button")]
.filter((button) =>
["Not now", "Add to thread", "Review only"].includes(button.textContent ?? ""),
)
.map((button) => button.disabled),
).toEqual([true, true, true]);
} finally {
await mounted.cleanup();
}
Expand Down
221 changes: 221 additions & 0 deletions apps/web/src/components/ChatView.sending.browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,227 @@ describe("ChatView (full app): first sends and worktree setup", () => {
}
});

it("waits for a slow branch list instead of failing a New worktree send", async () => {
const snapshot = addThreadToSnapshot(createDraftOnlySnapshot(), THREAD_ID);
// The branch list on a busy repository can take seconds. It answers only
// once the message has been sent.
let releaseRefs: () => void = () => {};
const refsReleased = new Promise<void>((resolve) => {
releaseRefs = resolve;
});
const mounted = await mountChatView({
viewport: DEFAULT_VIEWPORT,
snapshot: {
...snapshot,
threads: snapshot.threads.map((thread) =>
thread.id === THREAD_ID ? Object.assign({}, thread, { session: null }) : thread,
),
},
resolveRpc: (body) => {
if (body._tag === WS_METHODS.vcsListRefs) {
return refsReleased.then(() => ({
isRepo: true,
hasPrimaryRemote: true,
nextCursor: null,
totalCount: 2,
refs: [
{ name: "feature/current", current: true, isDefault: false, worktreePath: null },
{ name: "main", current: false, isDefault: true, worktreePath: null },
],
}));
}
if (body._tag === ORCHESTRATION_WS_METHODS.dispatchCommand) {
return { sequence: fixture.snapshot.snapshotSequence + 1 };
}
return undefined;
},
});

const turnStart = () =>
wsRequests.find(
(request) =>
request._tag === ORCHESTRATION_WS_METHODS.dispatchCommand &&
request.type === "thread.turn.start",
) as { bootstrap?: { prepareWorktree?: { baseBranch?: string } } } | undefined;

try {
(await waitForButtonByText("Current checkout")).click();
await clickSelectItemContainingText("New worktree");
useComposerDraftStore.getState().setPrompt(THREAD_REF, "Ship it");
await waitForLayout();
(await waitForSendButton()).click();
await waitForLayout();

expect(document.body.textContent).not.toContain("Select a base branch");
expect(turnStart()).toBeUndefined();

releaseRefs();
// The "New worktrees from" setting's default: the default branch, not
// the branch the project's checkout is on.
await vi.waitFor(
() => expect(turnStart()?.bootstrap?.prepareWorktree?.baseBranch).toBe("main"),
{ timeout: 8_000, interval: 16 },
);
} finally {
releaseRefs();
await mounted.cleanup();
}
});

it("takes back a New worktree send whose branch isn't found, keeping what was typed since", async () => {
const snapshot = addThreadToSnapshot(createDraftOnlySnapshot(), THREAD_ID);
let releaseRefs: () => void = () => {};
const refsReleased = new Promise<void>((resolve) => {
releaseRefs = resolve;
});
const mounted = await mountChatView({
viewport: DEFAULT_VIEWPORT,
snapshot: {
...snapshot,
threads: snapshot.threads.map((thread) =>
thread.id === THREAD_ID ? Object.assign({}, thread, { session: null }) : thread,
),
},
resolveRpc: (body) => {
if (body._tag === WS_METHODS.vcsListRefs) {
// No branches at all: nothing for a new worktree to start from.
return refsReleased.then(() => ({
isRepo: true,
hasPrimaryRemote: true,
nextCursor: null,
totalCount: 0,
refs: [],
}));
}
if (body._tag === ORCHESTRATION_WS_METHODS.dispatchCommand) {
return { sequence: fixture.snapshot.snapshotSequence + 1 };
}
return undefined;
},
});
const userMessages = () =>
[...document.querySelectorAll('[data-message-role="user"]')].map(
(row) => row.textContent ?? "",
);

try {
(await waitForButtonByText("Current checkout")).click();
await clickSelectItemContainingText("New worktree");
useComposerDraftStore.getState().setPrompt(THREAD_REF, "Ship it");
await waitForLayout();
(await waitForSendButton()).click();
await vi.waitFor(
() => expect(userMessages().some((text) => text.includes("Ship it"))).toBe(true),
{
timeout: 8_000,
interval: 16,
},
);
// The user starts the next message while the first one waits.
useComposerDraftStore.getState().setPrompt(THREAD_REF, "Next idea");
releaseRefs();

await vi.waitFor(
() =>
expect(useComposerDraftStore.getState().getComposerDraft(THREAD_REF)?.prompt).toBe(
"Ship it\n\nNext idea",
),
{ timeout: 8_000, interval: 16 },
);
expect(userMessages().some((text) => text.includes("Ship it"))).toBe(false);
expect(
wsRequests.some(
(request) =>
request._tag === ORCHESTRATION_WS_METHODS.dispatchCommand &&
request.type === "thread.turn.start",
),
).toBe(false);
} finally {
releaseRefs();
await mounted.cleanup();
}
});

it("keeps a waiting New worktree send's branch picker off until it goes", async () => {
const snapshot = addThreadToSnapshot(createDraftOnlySnapshot(), THREAD_ID);
// The setting names `develop`, whose search is slow; the plain list is not.
let releaseSearch: () => void = () => {};
const searchReleased = new Promise<void>((resolve) => {
releaseSearch = resolve;
});
const refsPage = (refs: ReadonlyArray<Record<string, unknown>>) => ({
isRepo: true,
hasPrimaryRemote: true,
nextCursor: null,
totalCount: refs.length,
refs,
});
const mounted = await mountChatView({
viewport: DEFAULT_VIEWPORT,
snapshot: {
...snapshot,
threads: snapshot.threads.map((thread) =>
thread.id === THREAD_ID ? Object.assign({}, thread, { session: null }) : thread,
),
},
configureFixture: (nextFixture) => {
nextFixture.serverConfig = {
...nextFixture.serverConfig,
settings: {
...nextFixture.serverConfig.settings,
newWorktreeBase: { from: "named", branch: "develop" },
},
};
},
resolveRpc: (body) => {
if (body._tag === WS_METHODS.vcsListRefs) {
return body.query === "develop"
? searchReleased.then(() =>
refsPage([
{ name: "develop", current: false, isDefault: false, worktreePath: null },
]),
)
: refsPage([
{ name: "main", current: true, isDefault: true, worktreePath: null },
{ name: "release/next", current: false, isDefault: false, worktreePath: null },
]);
}
if (body._tag === ORCHESTRATION_WS_METHODS.dispatchCommand) {
return { sequence: fixture.snapshot.snapshotSequence + 1 };
}
return undefined;
},
});

try {
(await waitForButtonByText("Current checkout")).click();
await clickSelectItemContainingText("New worktree");
useComposerDraftStore.getState().setPrompt(THREAD_REF, "Ship it");
await waitForLayout();
(await waitForSendButton()).click();
await waitForLayout();

// The send has its place while it waits for the setting's branch.
expect((await waitForButtonByText("From main")).disabled).toBe(true);
releaseSearch();

await vi.waitFor(
() => {
const turnStartRequest = wsRequests.find(
(request) =>
request._tag === ORCHESTRATION_WS_METHODS.dispatchCommand &&
request.type === "thread.turn.start",
) as { bootstrap?: { prepareWorktree?: { baseBranch?: string } } } | undefined;
expect(turnStartRequest?.bootstrap?.prepareWorktree?.baseBranch).toBe("develop");
},
{ timeout: 8_000, interval: 16 },
);
} finally {
releaseSearch();
await mounted.cleanup();
}
});

it("clears pending worktree overrides when switching empty server threads", async () => {
const secondThreadId = "thread-browser-test-second" as ThreadId;
const snapshot = addThreadToSnapshot(createDraftOnlySnapshot(), THREAD_ID);
Expand Down
Loading
Loading