mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-18 16:08:55 +00:00
fix(run): runs started together get their own tabs (#3595)
Rerun Failed Tests for several Go packages and compound configurations start runs concurrently. Each run picked a finished tab before awaiting the editor save and took it only afterwards, so two runs could pick the same tab: one replaced the other and its process never started. A tab a starting run is about to take, or was asked to reuse, is now held until it is taken. Also fixes the agent model e2e helper: a model row's name now includes its Configure button, so the option is matched by its leading name.
This commit is contained in:
@@ -255,7 +255,8 @@ async function selectDraft(page: Page) {
|
||||
}
|
||||
async function chooseModel(page: Page, name: string) {
|
||||
await modelButton(page).click();
|
||||
await page.getByRole("option", { name, exact: true }).click();
|
||||
// A model row also holds its Configure button, whose label joins the option's name.
|
||||
await page.getByRole("option", { name: new RegExp(`^${name}\\b`) }).click();
|
||||
await page.keyboard.press("Escape");
|
||||
await box(page).focus();
|
||||
}
|
||||
|
||||
@@ -69,3 +69,14 @@ it("keeps an agent's commands out of other tabs", async () => {
|
||||
await startRun(agent, undefined, undefined, { prepared: true });
|
||||
expect(useRun.getState().sessions).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("gives runs started together their own tabs", async () => {
|
||||
useRun.setState({ sessions: [finished("a"), finished("b")], activeSession: "a" });
|
||||
await Promise.all([
|
||||
startRun(config("x"), "a", undefined, { prepared: true }),
|
||||
startRun(config("y"), undefined, undefined, { prepared: true }),
|
||||
startRun(config("z"), undefined, undefined, { prepared: true }),
|
||||
]);
|
||||
expect(tabs()).toEqual(["a:x", "b:y", expect.stringMatching(/^run\d+:z$/)]);
|
||||
expect(ipc.runStart).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
+41
-17
@@ -760,38 +760,58 @@ export function sessionsOf(config: RunConfig, sessions = useRun.getState().sessi
|
||||
* Agents' commands keep to their own tabs.
|
||||
*/
|
||||
function reusableTab(sessions: readonly RunSession[], active: string | null, config: RunConfig) {
|
||||
const free = sessions.filter((s) => !isLive(s) && !s.pinned);
|
||||
const free = sessions.filter((s) => !isLive(s) && !s.pinned && !claimedTabs.has(s.id));
|
||||
const same = free.find((s) => s.config.id === config.id);
|
||||
if (same || agentName(config) !== null) return same;
|
||||
const others = free.filter((s) => agentName(s.config) === null);
|
||||
return others.find((s) => s.id === active) ?? others[0];
|
||||
}
|
||||
|
||||
/** Tabs a starting run is about to take: runs started together (compounds, reruns of several packages) must not take the same one. */
|
||||
const claimedTabs = new Set<string>();
|
||||
|
||||
/** Pins or unpins a session's tab. */
|
||||
export function pinSession(id: string, pinned: boolean) {
|
||||
patchSession(id, { pinned });
|
||||
}
|
||||
|
||||
interface StartRunOptions {
|
||||
show?: boolean;
|
||||
/** Launch this instead of `config` (e.g. with a debug agent); the tab still shows `config`. Skips before launch tasks. */
|
||||
launch?: RunConfig;
|
||||
/** Every output line of this run. */
|
||||
onLine?: (text: string) => void;
|
||||
/** The process exited. */
|
||||
onExit?: (exitCode: number | null, stopped: boolean) => void;
|
||||
/** Before launch tasks already ran (or must not run). */
|
||||
prepared?: boolean;
|
||||
/** Configurations whose launch led to this one (before launch tasks, compounds): breaks cycles. */
|
||||
chain?: readonly string[];
|
||||
/** Runs before the stop signal when the user stops this run (run executors). */
|
||||
beforeStop?: (runId: RunId) => Promise<void>;
|
||||
}
|
||||
|
||||
/** Starts `config`, reusing the tab of a finished (or the given) session (see `reusableTab`). */
|
||||
export async function startRun(
|
||||
config: RunConfig,
|
||||
reuse?: string,
|
||||
baseConfig?: RunConfig,
|
||||
options: {
|
||||
show?: boolean;
|
||||
/** Launch this instead of `config` (e.g. with a debug agent); the tab still shows `config`. Skips before launch tasks. */
|
||||
launch?: RunConfig;
|
||||
/** Every output line of this run. */
|
||||
onLine?: (text: string) => void;
|
||||
/** The process exited. */
|
||||
onExit?: (exitCode: number | null, stopped: boolean) => void;
|
||||
/** Before launch tasks already ran (or must not run). */
|
||||
prepared?: boolean;
|
||||
/** Configurations whose launch led to this one (before launch tasks, compounds): breaks cycles. */
|
||||
chain?: readonly string[];
|
||||
/** Runs before the stop signal when the user stops this run (run executors). */
|
||||
beforeStop?: (runId: RunId) => Promise<void>;
|
||||
} = {},
|
||||
options: StartRunOptions = {},
|
||||
): Promise<RunSession | null> {
|
||||
if (!reuse || claimedTabs.has(reuse)) return startRunIn(config, reuse, baseConfig, options);
|
||||
claimedTabs.add(reuse);
|
||||
try {
|
||||
return await startRunIn(config, reuse, baseConfig, options);
|
||||
} finally {
|
||||
claimedTabs.delete(reuse);
|
||||
}
|
||||
}
|
||||
|
||||
async function startRunIn(
|
||||
config: RunConfig,
|
||||
reuse: string | undefined,
|
||||
baseConfig: RunConfig | undefined,
|
||||
options: StartRunOptions,
|
||||
): Promise<RunSession | null> {
|
||||
config = withRunTarget(config);
|
||||
if (!options.launch && isCMakeBuild(config)) {
|
||||
@@ -841,12 +861,16 @@ export async function startRun(
|
||||
// IDEA there is no time limit: a first Stop waits for the shutdown, a second one kills it.
|
||||
await waitForExit(stopping, null);
|
||||
const now = useRun.getState();
|
||||
session ??= reusableTab(now.sessions, now.activeSession, config);
|
||||
const picked = session ? undefined : reusableTab(now.sessions, now.activeSession, config);
|
||||
session ??= picked;
|
||||
|
||||
if (picked) claimedTabs.add(picked.id);
|
||||
try {
|
||||
await maybeEditorService()?.saveAll();
|
||||
} catch {
|
||||
/* saving is best effort */
|
||||
} finally {
|
||||
if (picked) claimedTabs.delete(picked.id);
|
||||
}
|
||||
|
||||
const startedAt = Date.now();
|
||||
|
||||
Reference in New Issue
Block a user