mirror of
https://github.com/getpaseo/paseo.git
synced 2026-12-05 22:55:33 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e09abaf59d | ||
|
|
9d08b583d9 | ||
|
|
86ae1c7a83 | ||
|
|
4c00134303 |
@@ -29,8 +29,6 @@ import {
|
||||
expectWorkspaceAgentConfiguration,
|
||||
openCommandCenterForAgent,
|
||||
} from "../support/helpers/command-center-agent-controls";
|
||||
import { openSettingsWithShortcut } from "../support/helpers/app";
|
||||
import { clickSettingsBackToWorkspace } from "../support/helpers/settings";
|
||||
import { expectComposerVisible } from "../support/helpers/composer";
|
||||
import { openAgentRoute, seedMockAgentWorkspace } from "../support/helpers/mock-agent";
|
||||
|
||||
@@ -299,34 +297,6 @@ test.describe("Agent profiles in the model picker", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("the composer profile editor reopens after visiting Settings", async ({ page }) => {
|
||||
const seed = await seedAgentProfiles([PROFILE]);
|
||||
const workspace = await seedMockAgentWorkspace({
|
||||
repoPrefix: "agent-profiles-settings-return-",
|
||||
title: "Agent profiles Settings return",
|
||||
model: "ten-second-stream",
|
||||
modeId: "load-test",
|
||||
});
|
||||
const model = { provider: PROFILE.provider, modelId: PROFILE.model };
|
||||
|
||||
try {
|
||||
await openAgentRoute(page, workspace);
|
||||
await expectComposerVisible(page);
|
||||
await openModelPicker(page);
|
||||
await openEditProfileFromModelRow(page, model);
|
||||
|
||||
await openSettingsWithShortcut(page);
|
||||
await clickSettingsBackToWorkspace(page);
|
||||
await expectComposerVisible(page);
|
||||
await openModelPicker(page);
|
||||
await openEditProfileFromModelRow(page, model);
|
||||
await expectAgentProfileNameDraft(page, PROFILE.name);
|
||||
} finally {
|
||||
await workspace.cleanup();
|
||||
await seed.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test("canceling Remove in the composer profile editor keeps the editor and draft open", async ({
|
||||
page,
|
||||
}) => {
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
withPluginFocusingAnAgentWithContextUsage,
|
||||
withPluginHoldingNewWorkspaceComposer,
|
||||
withPluginWritingToAnotherWorkspace,
|
||||
withPluginSettingsFromComposer,
|
||||
} from "../support/helpers/plugin-composers-by-reference";
|
||||
|
||||
test("a panel in the Explorer inserts at the cursor of the focused agent's composer", async ({
|
||||
@@ -222,26 +221,3 @@ test("focus reaches an agent kept in the Explorer on a compact screen", async ({
|
||||
await author.expectParentReadyToType();
|
||||
});
|
||||
});
|
||||
|
||||
test("Settings accepts clicks after a composer plugin closes its dialog and navigates", async ({
|
||||
page,
|
||||
}) => {
|
||||
test.setTimeout(120_000);
|
||||
await withPluginSettingsFromComposer(page, { width: 1280, height: 800 }, async (flow) => {
|
||||
await flow.openPluginDialog();
|
||||
await flow.openSettingsFromPlugin();
|
||||
await flow.changeSetting();
|
||||
await flow.returnToChat();
|
||||
});
|
||||
});
|
||||
|
||||
test("Settings accepts clicks after navigation from the compact model sheet", async ({ page }) => {
|
||||
test.setTimeout(120_000);
|
||||
await withPluginSettingsFromComposer(page, { width: 430, height: 900 }, async (flow) => {
|
||||
await flow.openModelSheet();
|
||||
await flow.openPluginDialog();
|
||||
await flow.openSettingsFromPlugin();
|
||||
await flow.changeSetting();
|
||||
await flow.returnToChat();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import { clickNewTerminal } from "../support/helpers/launcher";
|
||||
import { expectTerminalSurfaceVisible } from "../support/helpers/terminal-perf";
|
||||
import {
|
||||
connectWorkspaceSetupClient,
|
||||
createWorkspaceThroughDaemon,
|
||||
findWorktreeWorkspaceForProject,
|
||||
navigateToWorkspaceViaSidebar,
|
||||
openHomeWithProject,
|
||||
@@ -14,7 +15,34 @@ import {
|
||||
test.describe("Workspace setup runtime authority", () => {
|
||||
test.describe.configure({ retries: 1 });
|
||||
|
||||
test("opens a new worktree and starts its first terminal there", async ({ page }) => {
|
||||
test("worktree workspace is created in its own directory", async ({ page }) => {
|
||||
test.setTimeout(90_000);
|
||||
|
||||
const client = await connectWorkspaceSetupClient();
|
||||
const repo = await createTempGitRepo("workspace-setup-chat-");
|
||||
|
||||
try {
|
||||
await seedProjectForWorkspaceSetup(client, repo.path);
|
||||
const workspace = await createWorkspaceThroughDaemon(client, {
|
||||
cwd: repo.path,
|
||||
worktreeSlug: `setup-chat-${Date.now()}`,
|
||||
});
|
||||
const workspaceId = workspace.id;
|
||||
|
||||
const wsInfo = await findWorktreeWorkspaceForProject(client, repo.path);
|
||||
expect(wsInfo.workspaceDirectory).not.toBe(repo.path);
|
||||
expect(existsSync(wsInfo.workspaceDirectory)).toBe(true);
|
||||
|
||||
await openHomeWithProject(page, repo.path);
|
||||
await navigateToWorkspaceViaSidebar(page, workspaceId);
|
||||
await expect(page).toHaveURL(/\/workspace\//, { timeout: 30_000 });
|
||||
} finally {
|
||||
await client.close();
|
||||
await repo.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("first terminal opens in the created workspace directory", async ({ page }) => {
|
||||
test.setTimeout(90_000);
|
||||
|
||||
const client = await connectWorkspaceSetupClient();
|
||||
@@ -23,37 +51,35 @@ test.describe("Workspace setup runtime authority", () => {
|
||||
try {
|
||||
await seedProjectForWorkspaceSetup(client, repo.path);
|
||||
|
||||
const workspace = await test.step("creates a worktree in its own directory", async () => {
|
||||
const result = await client.createPaseoWorktree({
|
||||
cwd: repo.path,
|
||||
worktreeSlug: `setup-terminal-${Date.now()}`,
|
||||
});
|
||||
if (!result.workspace || result.error) {
|
||||
throw new Error(result.error ?? "Failed to create workspace");
|
||||
}
|
||||
|
||||
const listedWorkspace = await findWorktreeWorkspaceForProject(client, repo.path);
|
||||
expect(listedWorkspace.workspaceDirectory).toBe(result.workspace.workspaceDirectory);
|
||||
expect(listedWorkspace.workspaceDirectory).not.toBe(repo.path);
|
||||
expect(existsSync(listedWorkspace.workspaceDirectory)).toBe(true);
|
||||
return result.workspace;
|
||||
// Create workspace via daemon API since the new workspace screen
|
||||
// no longer has a standalone terminal button
|
||||
const worktreeSlug = `setup-terminal-${Date.now()}`;
|
||||
const result = await client.createPaseoWorktree({
|
||||
cwd: repo.path,
|
||||
worktreeSlug,
|
||||
});
|
||||
if (!result.workspace || result.error) {
|
||||
throw new Error(result.error ?? "Failed to create workspace");
|
||||
}
|
||||
const workspaceDir = result.workspace.workspaceDirectory;
|
||||
const workspaceId = result.workspace.id;
|
||||
|
||||
await test.step("opens the worktree from the sidebar", async () => {
|
||||
await openHomeWithProject(page, repo.path);
|
||||
await navigateToWorkspaceViaSidebar(page, workspace.id);
|
||||
await expect(page).toHaveURL(/\/workspace\//, { timeout: 30_000 });
|
||||
});
|
||||
// Navigate to the worktree workspace via sidebar click (direct URL
|
||||
// navigation for freshly created worktree workspaces can race with
|
||||
// Expo Router hydration, so we use the sidebar which is authoritative).
|
||||
await openHomeWithProject(page, repo.path);
|
||||
await navigateToWorkspaceViaSidebar(page, workspaceId);
|
||||
|
||||
const countWorktreeTerminals = async () =>
|
||||
(await client.listTerminals(workspace.workspaceDirectory)).terminals.length;
|
||||
await test.step("registers the first terminal under the worktree directory", async () => {
|
||||
await clickNewTerminal(page);
|
||||
await expectTerminalSurfaceVisible(page);
|
||||
await clickNewTerminal(page);
|
||||
await expectTerminalSurfaceVisible(page);
|
||||
|
||||
await expect.poll(countWorktreeTerminals, { timeout: 30_000 }).toBeGreaterThan(0);
|
||||
expect((await client.listTerminals(repo.path)).terminals.length).toBe(0);
|
||||
});
|
||||
// Verify terminal is listed under the worktree directory, not the original repo
|
||||
await expect
|
||||
.poll(async () => (await client.listTerminals(workspaceDir)).terminals.length > 0, {
|
||||
timeout: 30_000,
|
||||
})
|
||||
.toBe(true);
|
||||
expect((await client.listTerminals(repo.path)).terminals.length).toBe(0);
|
||||
} finally {
|
||||
await client.close();
|
||||
await repo.cleanup();
|
||||
|
||||
@@ -38,11 +38,6 @@ export const openSettings = async (page: Page) => {
|
||||
await expect(page).toHaveURL(/\/settings\/general$/);
|
||||
};
|
||||
|
||||
export async function openSettingsWithShortcut(page: Page): Promise<void> {
|
||||
await page.keyboard.press("ControlOrMeta+,");
|
||||
await expect(page).toHaveURL(/\/settings\/general$/);
|
||||
}
|
||||
|
||||
export const setWorkingDirectory = async (page: Page, directory: string) => {
|
||||
const workingDirectorySelect = page
|
||||
.locator('[data-testid="working-directory-select"]:visible')
|
||||
|
||||
@@ -766,108 +766,3 @@ export async function withPluginFocusingAnAgentWithContextUsage(
|
||||
await agent.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
export async function withPluginSettingsFromComposer(
|
||||
page: Page,
|
||||
viewport: typeof WIDE,
|
||||
run: (flow: {
|
||||
openModelSheet(): Promise<void>;
|
||||
openPluginDialog(): Promise<void>;
|
||||
openSettingsFromPlugin(): Promise<void>;
|
||||
changeSetting(): Promise<void>;
|
||||
returnToChat(): Promise<void>;
|
||||
}) => Promise<void>,
|
||||
) {
|
||||
const workspace = await seedWorkspace({ repoPrefix: "composer-settings-" });
|
||||
const agent = await createMockAgent(workspace, "Composer settings agent");
|
||||
const directory = await mkdtemp(path.join(tmpdir(), "paseo-composer-settings-"));
|
||||
await writeFile(
|
||||
path.join(directory, "paseo-plugin.json"),
|
||||
JSON.stringify({ id: "composer-settings", requirements: pluginRequirements }),
|
||||
);
|
||||
await writeFile(
|
||||
path.join(directory, "index.client.tsx"),
|
||||
`import { useState } from "react";
|
||||
import { Pressable, Text } from "react-native";
|
||||
import { Action, Modal } from "@getpaseo/plugin/client/ui";
|
||||
|
||||
function Button({ title, onPress }) {
|
||||
return <Pressable accessibilityRole="button" onPress={onPress}><Text>{title}</Text></Pressable>;
|
||||
}
|
||||
|
||||
export default function contribute(client) {
|
||||
client.addSettingsScreen({
|
||||
id: "preferences",
|
||||
title: "Composer preferences",
|
||||
icon: "SlidersHorizontal",
|
||||
Component() {
|
||||
const [saved, setSaved] = useState(false);
|
||||
return <Button title={saved ? "Preference saved" : "Save preference"} onPress={() => setSaved(true)} />;
|
||||
},
|
||||
});
|
||||
client.addComposerItem({
|
||||
id: "preferences",
|
||||
Component() {
|
||||
const [open, setOpen] = useState(false);
|
||||
return <>
|
||||
<Action title="Composer preferences" icon="ListChecks" onPress={() => setOpen(true)} />
|
||||
<Modal title="Composer preferences" open={open} onOpenChange={setOpen}>
|
||||
<Modal.Content>
|
||||
<Button title="Open plugin settings" onPress={() => {
|
||||
setOpen(false);
|
||||
client.openSettings("preferences");
|
||||
}} />
|
||||
</Modal.Content>
|
||||
</Modal>
|
||||
</>;
|
||||
},
|
||||
});
|
||||
return () => {};
|
||||
}`,
|
||||
);
|
||||
const client = await connectNewWorkspaceDaemonClient({ ownProjects: false });
|
||||
const previous = await client.getDaemonConfig();
|
||||
const settingsButton = page.getByRole("button", { name: "Open plugin settings", exact: true });
|
||||
try {
|
||||
await client.patchDaemonConfig({ pluginsEnabled: true });
|
||||
await client.installDirectoryPlugin(directory);
|
||||
await page.setViewportSize(viewport);
|
||||
await gotoAppShell(page);
|
||||
await approveClientPluginsInUi(page, ["composer-settings"]);
|
||||
await openAgentRoute(page, { workspaceId: workspace.workspaceId, agentId: agent.id });
|
||||
await run({
|
||||
openModelSheet: () =>
|
||||
test.step("open Agent settings from the model button", () =>
|
||||
page.getByRole("button", { name: /^Select model/ }).click()),
|
||||
openPluginDialog: () =>
|
||||
test.step("open the composer plugin's preferences dialog", async () => {
|
||||
await page.getByRole("button", { name: "Composer preferences", exact: true }).click();
|
||||
await expect(settingsButton).toBeVisible();
|
||||
}),
|
||||
openSettingsFromPlugin: () =>
|
||||
test.step("navigate to Settings from the plugin dialog", () => settingsButton.click()),
|
||||
changeSetting: () =>
|
||||
test.step("save a preference in Settings", async () => {
|
||||
await page
|
||||
.getByRole("button", { name: "Save preference", exact: true })
|
||||
.click({ timeout: 10_000 });
|
||||
await expect(
|
||||
page.getByRole("button", { name: "Preference saved", exact: true }),
|
||||
).toBeVisible();
|
||||
}),
|
||||
returnToChat: () =>
|
||||
test.step("return to chat with the dialog and model sheet closed", async () => {
|
||||
await page.goBack();
|
||||
await expect(prompt(page)).toBeVisible();
|
||||
await expect(settingsButton).toBeHidden();
|
||||
await expect(page.getByText("Agent settings", { exact: true })).toBeHidden();
|
||||
}),
|
||||
});
|
||||
} finally {
|
||||
await client.removePlugin("composer-settings");
|
||||
await client.patchDaemonConfig({ pluginsEnabled: previous.config.pluginsEnabled });
|
||||
await client.close();
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
await workspace.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useOverlayRegistration, type KeyboardInputEvent } from "@/keyboard";
|
||||
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import type { ComponentProps, ReactNode } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -23,7 +23,6 @@ import {
|
||||
useBottomSheetSafeAreaPaddingStyle,
|
||||
useIsolatedBottomSheetVisibility,
|
||||
} from "@/components/ui/isolated-bottom-sheet-modal";
|
||||
import { useRetainedPanelActive } from "@/components/retained-panel";
|
||||
import { ScrollView } from "@/components/ui/scroll-view";
|
||||
import { isWeb } from "@/constants/platform";
|
||||
import { BottomSafeAreaInset } from "@/components/ui/bottom-safe-area-inset";
|
||||
@@ -694,36 +693,7 @@ function CompactSheetBody({
|
||||
);
|
||||
}
|
||||
|
||||
export function AdaptiveModalSheet(props: AdaptiveModalSheetProps) {
|
||||
const panelActive = useRetainedPanelActive();
|
||||
const { visible, onClose, onDismiss } = props;
|
||||
const dismissalPending = useRef(false);
|
||||
|
||||
const finishDismissal = useCallback(() => {
|
||||
if (!dismissalPending.current) return;
|
||||
dismissalPending.current = false;
|
||||
onDismiss?.();
|
||||
}, [onDismiss]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!isWeb) return;
|
||||
if (visible) dismissalPending.current = true;
|
||||
if (panelActive) return;
|
||||
|
||||
// Complete dismissal when the inactive commit removes the portal, including when
|
||||
// a close animation was already running. Compact portal cleanup can also report dismissal.
|
||||
if (visible) onClose();
|
||||
finishDismissal();
|
||||
}, [panelActive, visible, onClose, finishDismissal]);
|
||||
|
||||
// A web portal escapes its hidden panel. Unmount its presentation in the inactive commit
|
||||
// so a chat that freezes on the next commit cannot strand the overlay above another screen.
|
||||
return !isWeb || panelActive ? (
|
||||
<AdaptiveModalSheetPresentation {...props} onDismiss={isWeb ? finishDismissal : onDismiss} />
|
||||
) : null;
|
||||
}
|
||||
|
||||
function AdaptiveModalSheetPresentation({
|
||||
export function AdaptiveModalSheet({
|
||||
header,
|
||||
showCloseButton = true,
|
||||
visible,
|
||||
|
||||
@@ -92,6 +92,21 @@ describe("passthrough CLI", () => {
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("opens the development app when Electron switches precede its entrypoint", () => {
|
||||
expect(
|
||||
parsePassthroughCliArgs({
|
||||
argv: [
|
||||
"/usr/bin/electron",
|
||||
"--no-sandbox",
|
||||
"--inspect=127.0.0.1:0",
|
||||
"/checkout/packages/desktop",
|
||||
],
|
||||
isDefaultApp: true,
|
||||
forceCli: false,
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("preserves CLI flags for direct app invocations", () => {
|
||||
expect(
|
||||
parsePassthroughCliArgs({
|
||||
@@ -102,6 +117,19 @@ describe("passthrough CLI", () => {
|
||||
).toEqual(["--version"]);
|
||||
});
|
||||
|
||||
it("preserves Electron-like values in a CLI command", () => {
|
||||
const command = ["terminal", "send-keys", "terminal-id", "--literal", "--"];
|
||||
const keys = ["--disable-gpu", "--inspect=0", "Enter"];
|
||||
|
||||
expect(
|
||||
parsePassthroughCliArgs({
|
||||
argv: ["/usr/bin/Paseo", "--no-sandbox", ...command, ...keys],
|
||||
isDefaultApp: false,
|
||||
forceCli: false,
|
||||
}),
|
||||
).toEqual([...command, ...keys]);
|
||||
});
|
||||
|
||||
it("passes --open-project through as a normal CLI arg", () => {
|
||||
expect(
|
||||
parsePassthroughCliArgs({
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { getDesktopLaunchArgs } from "../../desktop-launch-args.js";
|
||||
import { resolvePassthroughCliEntrypoint } from "./entrypoints.js";
|
||||
|
||||
const DESKTOP_CLI_ENV = "PASEO_DESKTOP_CLI";
|
||||
const IGNORED_ARG_PREFIXES = ["-psn_", "--class=", "--no-sandbox", "--remote-debugging-port="];
|
||||
|
||||
export type PassthroughCliRunner = (argv: string[]) => Promise<number>;
|
||||
|
||||
@@ -11,15 +11,7 @@ export function parsePassthroughCliArgs(input: {
|
||||
isDefaultApp: boolean;
|
||||
forceCli: boolean;
|
||||
}): string[] | null {
|
||||
const startIndex = input.isDefaultApp ? 2 : 1;
|
||||
const effective: string[] = [];
|
||||
|
||||
for (const arg of input.argv.slice(startIndex)) {
|
||||
if (IGNORED_ARG_PREFIXES.some((prefix) => arg.startsWith(prefix))) {
|
||||
continue;
|
||||
}
|
||||
effective.push(arg);
|
||||
}
|
||||
const effective = getDesktopLaunchArgs(input);
|
||||
|
||||
if (input.forceCli) {
|
||||
return effective;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
const ELECTRON_ARG_PREFIXES = [
|
||||
"-psn_",
|
||||
"--class=",
|
||||
"--force-device-scale-factor=",
|
||||
"--inspect=",
|
||||
"--ozone-platform=",
|
||||
"--remote-debugging-address=",
|
||||
"--remote-debugging-port=",
|
||||
];
|
||||
const ELECTRON_ARGS = new Set(["--allow-file-access-from-files", "--disable-gpu", "--no-sandbox"]);
|
||||
|
||||
function skipElectronSwitches(args: string[], start: number): number {
|
||||
let index = start;
|
||||
while (index < args.length) {
|
||||
const arg = args[index]!;
|
||||
if (
|
||||
!ELECTRON_ARGS.has(arg) &&
|
||||
!ELECTRON_ARG_PREFIXES.some((prefix) => arg.startsWith(prefix))
|
||||
) {
|
||||
break;
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
export function getDesktopLaunchArgs(input: { argv: string[]; isDefaultApp: boolean }): string[] {
|
||||
const firstArg = skipElectronSwitches(input.argv, 1);
|
||||
// Electron retains switches before the development entrypoint. Wrappers can also add them after it.
|
||||
const start = input.isDefaultApp ? skipElectronSwitches(input.argv, firstArg + 1) : firstArg;
|
||||
return input.argv.slice(start);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mkdtempSync, mkdirSync } from "node:fs";
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
@@ -23,6 +23,8 @@ describe("open-project-routing", () => {
|
||||
parseOpenProjectPathFromArgv({
|
||||
argv: [
|
||||
"/Applications/Paseo.app/Contents/MacOS/Paseo",
|
||||
"--disable-gpu",
|
||||
"--ozone-platform=x11",
|
||||
"--allow-file-access-from-files",
|
||||
"--no-sandbox",
|
||||
projectPath,
|
||||
@@ -32,32 +34,57 @@ describe("open-project-routing", () => {
|
||||
).toBe(projectPath);
|
||||
});
|
||||
|
||||
it("does not treat flags as project paths", () => {
|
||||
const projectPath = mkdtempSync(path.join(tmpdir(), "paseo-open-project-"));
|
||||
const flagLikeDirectory = path.join(projectPath, "--version");
|
||||
mkdirSync(flagLikeDirectory);
|
||||
it("leaves an existing daemon home directory in the CLI arguments", () => {
|
||||
const home = mkdtempSync(path.join(tmpdir(), "paseo-daemon-home-"));
|
||||
try {
|
||||
expect(
|
||||
parseOpenProjectPathFromArgv({
|
||||
argv: ["/usr/bin/Paseo", "--no-sandbox", "daemon", "start", "--home", home],
|
||||
isDefaultApp: false,
|
||||
}),
|
||||
).toBeNull();
|
||||
} finally {
|
||||
rmSync(home, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("leaves a path after a CLI flag in the CLI arguments", () => {
|
||||
expect(
|
||||
parseOpenProjectPathFromArgv({
|
||||
argv: ["/Applications/Paseo.app/Contents/MacOS/Paseo", "--version", flagLikeDirectory],
|
||||
isDefaultApp: false,
|
||||
}),
|
||||
).toBe(flagLikeDirectory);
|
||||
|
||||
expect(
|
||||
parseOpenProjectPathFromArgv({
|
||||
argv: ["/Applications/Paseo.app/Contents/MacOS/Paseo", "--version"],
|
||||
argv: ["/usr/bin/Paseo", "--version", tmpdir()],
|
||||
isDefaultApp: false,
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it.each([{ selector: [] }, { selector: ["--open-project"] }])(
|
||||
"opens a project after the Electron display scale switch with selector $selector",
|
||||
({ selector }) => {
|
||||
const projectPath = mkdtempSync(path.join(tmpdir(), "paseo-open-project-"));
|
||||
try {
|
||||
expect(
|
||||
parseOpenProjectPathFromArgv({
|
||||
argv: ["/usr/bin/Paseo", "--force-device-scale-factor=1.5", ...selector, projectPath],
|
||||
isDefaultApp: false,
|
||||
}),
|
||||
).toBe(projectPath);
|
||||
} finally {
|
||||
rmSync(projectPath, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("returns the path from an explicit --open-project flag for backward compatibility", () => {
|
||||
const projectPath = mkdtempSync(path.join(tmpdir(), "paseo-open-project-"));
|
||||
|
||||
expect(
|
||||
parseOpenProjectPathFromArgv({
|
||||
argv: ["/Applications/Paseo.app/Contents/MacOS/Paseo", "--open-project", projectPath],
|
||||
argv: [
|
||||
"/Applications/Paseo.app/Contents/MacOS/Paseo",
|
||||
"--disable-gpu",
|
||||
"--open-project",
|
||||
projectPath,
|
||||
],
|
||||
isDefaultApp: false,
|
||||
}),
|
||||
).toBe(projectPath);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { existsSync, statSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { getDesktopLaunchArgs } from "./desktop-launch-args.js";
|
||||
|
||||
const OPEN_PROJECT_FLAG = "--open-project";
|
||||
const OPEN_PROJECT_IGNORED_ARG_PREFIXES = ["-psn_", "--no-sandbox"];
|
||||
|
||||
function isExistingDirectoryAbsolutePath(candidate: string): boolean {
|
||||
if (!path.isAbsolute(candidate) || !existsSync(candidate)) {
|
||||
@@ -20,24 +20,7 @@ export function parseOpenProjectPathFromArgv(input: {
|
||||
argv: string[];
|
||||
isDefaultApp: boolean;
|
||||
}): string | null {
|
||||
const effectiveArgs = input.argv
|
||||
.slice(input.isDefaultApp ? 2 : 1)
|
||||
.filter((arg) => !OPEN_PROJECT_IGNORED_ARG_PREFIXES.some((prefix) => arg.startsWith(prefix)));
|
||||
|
||||
const positionalProjectPath = effectiveArgs.find(
|
||||
(arg) => !arg.startsWith("-") && isExistingDirectoryAbsolutePath(arg),
|
||||
);
|
||||
if (positionalProjectPath) {
|
||||
return positionalProjectPath;
|
||||
}
|
||||
|
||||
const openProjectIndex = effectiveArgs.indexOf(OPEN_PROJECT_FLAG);
|
||||
if (openProjectIndex === -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const flaggedProjectPath = effectiveArgs[openProjectIndex + 1];
|
||||
return flaggedProjectPath && isExistingDirectoryAbsolutePath(flaggedProjectPath)
|
||||
? flaggedProjectPath
|
||||
: null;
|
||||
const [firstArg, secondArg] = getDesktopLaunchArgs(input);
|
||||
const projectPath = firstArg === OPEN_PROJECT_FLAG ? secondArg : firstArg;
|
||||
return projectPath && isExistingDirectoryAbsolutePath(projectPath) ? projectPath : null;
|
||||
}
|
||||
|
||||
@@ -3954,7 +3954,6 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
|
||||
private readonly usageSessionKey = randomUUID();
|
||||
private readonly harnessEnvironment: Record<string, string>;
|
||||
private readImportedSettings: boolean;
|
||||
|
||||
usageSession() {
|
||||
if (this.closed) return null;
|
||||
@@ -3978,9 +3977,7 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
private readonly autoReviewEnabled: boolean = false,
|
||||
private readonly agentId?: string,
|
||||
private readonly initialResumePurpose: "interactive" | "history" = "interactive",
|
||||
importOptions?: { readImportedSettings: boolean },
|
||||
) {
|
||||
this.readImportedSettings = importOptions?.readImportedSettings ?? false;
|
||||
this.logger = logger.child({
|
||||
module: "agent",
|
||||
provider: CODEX_PROVIDER,
|
||||
@@ -4101,7 +4098,7 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
|
||||
this.speedModels =
|
||||
CodexModelListResponseSchema.parse(await client.request("model/list", {})).data ?? [];
|
||||
if (!this.readImportedSettings) this.normalizeSpeed();
|
||||
this.normalizeSpeed();
|
||||
await this.loadResolvedConfig();
|
||||
await this.loadCollaborationModes();
|
||||
await this.loadSkills();
|
||||
@@ -4109,10 +4106,6 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
if (this.currentThreadId) {
|
||||
await this.ensureThreadLoaded();
|
||||
await this.applyDefaultModelAndThinking();
|
||||
if (this.readImportedSettings) {
|
||||
this.normalizeSpeed();
|
||||
this.readImportedSettings = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.closed) {
|
||||
@@ -4361,7 +4354,7 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
const runs = resolved ?? "default";
|
||||
this.providerOptions = { ...this.providerOptions, service_tier: runs };
|
||||
this.requestedServiceTier = runs;
|
||||
this.openOptionsPatch = { ...this.openOptionsPatch, service_tier: runs };
|
||||
this.openOptionsPatch = { service_tier: runs };
|
||||
}
|
||||
|
||||
private get serviceTier(): string | null {
|
||||
@@ -4649,7 +4642,6 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
const response = await this.client.request("thread/resume", params);
|
||||
this.rememberResolvedSandboxPolicy(response);
|
||||
this.rememberRestoredCollaborationMode(response);
|
||||
this.applyImportedThreadSettings(response);
|
||||
}
|
||||
} catch (error) {
|
||||
const threadId = this.currentThreadId;
|
||||
@@ -4665,7 +4657,6 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
const response = await this.client.request("thread/resume", params);
|
||||
this.rememberResolvedSandboxPolicy(response);
|
||||
this.rememberRestoredCollaborationMode(response);
|
||||
this.applyImportedThreadSettings(response);
|
||||
this.logger.info({ threadId }, "Unarchived Codex thread to restore active Paseo agent");
|
||||
} else {
|
||||
this.logger.warn({ error, threadId }, "Failed to resume persisted Codex thread");
|
||||
@@ -4695,26 +4686,6 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
this.refreshResolvedCollaborationMode();
|
||||
}
|
||||
|
||||
private applyImportedThreadSettings(response: unknown): void {
|
||||
if (!this.readImportedSettings) return;
|
||||
|
||||
const thread = toObjectRecord(response);
|
||||
if (!this.config.model && typeof thread?.model === "string" && thread.model) {
|
||||
this.config.model = thread.model;
|
||||
}
|
||||
if (typeof thread?.reasoningEffort === "string") {
|
||||
this.config.thinkingOptionId ??= normalizeCodexThinkingOptionId(thread.reasoningEffort);
|
||||
}
|
||||
|
||||
const mode = this.restoredCollaborationMode?.mode;
|
||||
if (mode === "plan" || mode === "default") {
|
||||
const planMode = mode === "plan";
|
||||
this.providerOptions = { ...this.providerOptions, plan_mode: planMode };
|
||||
this.openOptionsPatch = { ...this.openOptionsPatch, plan_mode: planMode };
|
||||
this.setPlanMode(planMode);
|
||||
}
|
||||
}
|
||||
|
||||
private parseSlashCommandInput(text: string): { commandName: string; args?: string } | null {
|
||||
const trimmed = text.trim();
|
||||
if (!trimmed.startsWith("/") || trimmed.length <= 1) {
|
||||
@@ -8639,22 +8610,6 @@ export class CodexAppServerAgentClient implements AgentClient {
|
||||
launchContext?: AgentLaunchContext,
|
||||
options?: AgentResumeSessionOptions,
|
||||
): Promise<AgentSession> {
|
||||
return this.openResumedSession({ handle, overrides, launchContext, options });
|
||||
}
|
||||
|
||||
private async openResumedSession({
|
||||
handle,
|
||||
overrides,
|
||||
launchContext,
|
||||
options,
|
||||
readImportedSettings = false,
|
||||
}: {
|
||||
handle: { sessionId: string; metadata?: Record<string, unknown> };
|
||||
overrides?: Partial<AgentSessionConfig>;
|
||||
launchContext?: AgentLaunchContext;
|
||||
options?: AgentResumeSessionOptions;
|
||||
readImportedSettings?: boolean;
|
||||
}): Promise<AgentSession> {
|
||||
const storedConfig = (handle.metadata ?? {}) as Partial<AgentSessionConfig>;
|
||||
const merged: AgentSessionConfig = {
|
||||
...storedConfig,
|
||||
@@ -8686,7 +8641,6 @@ export class CodexAppServerAgentClient implements AgentClient {
|
||||
autoReviewEnabled,
|
||||
launchContext?.agentId,
|
||||
options?.purpose ?? "interactive",
|
||||
{ readImportedSettings },
|
||||
);
|
||||
await session.connect();
|
||||
return session;
|
||||
@@ -8752,32 +8706,12 @@ export class CodexAppServerAgentClient implements AgentClient {
|
||||
}
|
||||
|
||||
async importSession(input: ImportProviderSessionInput, context: ImportProviderSessionContext) {
|
||||
const imported = await importSessionFromPersistence({
|
||||
return importSessionFromPersistence({
|
||||
provider: CODEX_PROVIDER,
|
||||
request: input,
|
||||
context,
|
||||
resumeSession: (handle, config, launchContext) =>
|
||||
this.openResumedSession({
|
||||
handle,
|
||||
overrides: config,
|
||||
launchContext,
|
||||
readImportedSettings: true,
|
||||
}),
|
||||
resumeSession: this.resumeSession.bind(this),
|
||||
});
|
||||
try {
|
||||
const runtime = await imported.session.getRuntimeInfo();
|
||||
return {
|
||||
...imported,
|
||||
config: {
|
||||
...imported.config,
|
||||
model: runtime.model ?? imported.config.model,
|
||||
thinkingOptionId: runtime.thinkingOptionId ?? imported.config.thinkingOptionId,
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
await imported.session.close();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async getCatalogCacheKey(_options: FetchCatalogOptions): Promise<string> {
|
||||
|
||||
+2
-111
@@ -1,20 +1,14 @@
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import { once } from "node:events";
|
||||
import { createServer, type Server } from "node:http";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { z } from "zod";
|
||||
import { afterEach, describe, expect, test } from "vitest";
|
||||
|
||||
import { createTestLogger } from "../../../test-utils/test-logger.js";
|
||||
import { spawnProcess } from "../../../utils/spawn.js";
|
||||
import { withTimeout } from "../../../utils/promise-timeout.js";
|
||||
import { CodexAppServerAgentClient, CodexAppServerAgentSession } from "./codex-app-server-agent.js";
|
||||
import { CodexAppServerClient } from "./codex/app-server-transport.js";
|
||||
import { DaemonClient } from "../../test-utils/daemon-client.js";
|
||||
import { createTestPaseoDaemon } from "../../test-utils/paseo-daemon.js";
|
||||
|
||||
// Runs the real `codex` binary against a local Responses endpoint standing in
|
||||
// for a custom provider's OPENAI_BASE_URL, so no login is needed.
|
||||
@@ -57,13 +51,10 @@ async function startResponsesEndpoint(): Promise<{
|
||||
baseUrl: string;
|
||||
server: Server;
|
||||
requestCount: () => number;
|
||||
lastRequest: () => unknown;
|
||||
}> {
|
||||
let requests = 0;
|
||||
let lastRequest: unknown;
|
||||
const server = createServer((req, res) => {
|
||||
const chunks: Buffer[] = [];
|
||||
req.on("data", (chunk: Buffer) => chunks.push(chunk));
|
||||
req.resume();
|
||||
req.on("end", () => {
|
||||
if (req.method !== "POST" || req.url !== "/v1/responses") {
|
||||
res.statusCode = 404;
|
||||
@@ -71,7 +62,6 @@ async function startResponsesEndpoint(): Promise<{
|
||||
return;
|
||||
}
|
||||
requests += 1;
|
||||
lastRequest = JSON.parse(Buffer.concat(chunks).toString());
|
||||
res.setHeader("content-type", "text/event-stream");
|
||||
res.end(finalAnswer());
|
||||
});
|
||||
@@ -84,7 +74,6 @@ async function startResponsesEndpoint(): Promise<{
|
||||
baseUrl: `http://127.0.0.1:${address.port}/v1`,
|
||||
server,
|
||||
requestCount: () => requests,
|
||||
lastRequest: () => lastRequest,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -203,101 +192,3 @@ describe("Codex custom provider import list", () => {
|
||||
120_000,
|
||||
);
|
||||
});
|
||||
|
||||
async function seedNativePlanThread(cwd: string, env: NodeJS.ProcessEnv): Promise<string> {
|
||||
const child = await spawnProcess("codex", ["app-server"], { cwd, env, stdio: "pipe" });
|
||||
const seed = new CodexAppServerClient(child, createTestLogger());
|
||||
try {
|
||||
await seed.request("initialize", {
|
||||
clientInfo: { name: "import-test", version: "1" },
|
||||
capabilities: { experimentalApi: true },
|
||||
});
|
||||
seed.notify("initialized");
|
||||
const { thread } = z.object({ thread: z.object({ id: z.string() }) }).parse(
|
||||
await seed.request("thread/start", {
|
||||
cwd,
|
||||
model: "gpt-5.4",
|
||||
config: { model_reasoning_effort: "high" },
|
||||
}),
|
||||
);
|
||||
const completed = Promise.withResolvers<unknown>();
|
||||
seed.setNotificationHandler((method, params) => {
|
||||
if (method === "turn/completed") completed.resolve(params);
|
||||
});
|
||||
await seed.request("turn/start", {
|
||||
threadId: thread.id,
|
||||
input: [{ type: "text", text: "Reply done." }],
|
||||
collaborationMode: {
|
||||
mode: "plan",
|
||||
settings: { model: "gpt-5.4", reasoning_effort: "high", developer_instructions: null },
|
||||
},
|
||||
});
|
||||
expect(
|
||||
await withTimeout(completed.promise, 15_000, "Native Codex turn did not finish"),
|
||||
).toMatchObject({ turn: { status: "completed" } });
|
||||
return thread.id;
|
||||
} finally {
|
||||
await seed.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
test("import preserves the Codex thread model, reasoning effort, and Plan mode", async () => {
|
||||
const artifacts = fileURLToPath(new URL("../../../../../../.artifacts/", import.meta.url));
|
||||
mkdirSync(artifacts, { recursive: true });
|
||||
const cwd = mkdtempSync(path.join(artifacts, "codex-import-settings-"));
|
||||
const endpoint = await startResponsesEndpoint();
|
||||
try {
|
||||
writeFileSync(
|
||||
path.join(cwd, "config.toml"),
|
||||
[
|
||||
'model = "gpt-5.4-mini"',
|
||||
'model_reasoning_effort = "low"',
|
||||
'model_provider = "fixture"',
|
||||
"[model_providers.fixture]",
|
||||
'name = "Fixture"',
|
||||
'wire_api = "responses"',
|
||||
'base_url = "' + endpoint.baseUrl + '"',
|
||||
].join("\n"),
|
||||
);
|
||||
const env = { ...process.env, CODEX_HOME: cwd };
|
||||
const sessionId = await seedNativePlanThread(cwd, env);
|
||||
const expectedRequest = { model: "gpt-5.4", reasoning: { effort: "high" } };
|
||||
expect(endpoint.lastRequest()).toMatchObject(expectedRequest);
|
||||
const daemon = await createTestPaseoDaemon({
|
||||
agentClients: {},
|
||||
providerOverrides: { codex: { env: { CODEX_HOME: cwd }, options: { service_tier: "fast" } } },
|
||||
paseoHomeRoot: cwd,
|
||||
});
|
||||
const client = new DaemonClient({ url: `ws://127.0.0.1:${daemon.port}/ws` });
|
||||
try {
|
||||
await client.connect();
|
||||
const agent = await client.importAgent({ provider: "codex", sessionId, cwd });
|
||||
const previousRequests = endpoint.requestCount();
|
||||
await client.sendAgentMessage(agent.id, "Reply done again.");
|
||||
expect(await client.waitForFinish(agent.id, 30_000)).toMatchObject({ status: "idle" });
|
||||
expect(endpoint.requestCount()).toBeGreaterThan(previousRequests);
|
||||
expect(endpoint.lastRequest()).toMatchObject(expectedRequest);
|
||||
expect(agent).toMatchObject({
|
||||
model: "gpt-5.4",
|
||||
thinkingOptionId: "high",
|
||||
runtimeInfo: { extra: { collaborationMode: "Plan" } },
|
||||
options: { plan_mode: true, service_tier: "default" },
|
||||
});
|
||||
await client.setAgentOptions(agent.id, { plan_mode: false });
|
||||
expect(await client.fetchAgent(agent.id)).toMatchObject({
|
||||
agent: {
|
||||
model: "gpt-5.4",
|
||||
thinkingOptionId: "high",
|
||||
runtimeInfo: { extra: { collaborationMode: "Default" } },
|
||||
options: { plan_mode: false, service_tier: "default" },
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
await client.close();
|
||||
await daemon.close();
|
||||
}
|
||||
} finally {
|
||||
await closeServer(endpoint.server);
|
||||
rmSync(cwd, { recursive: true, force: true });
|
||||
}
|
||||
}, 60_000);
|
||||
|
||||
Reference in New Issue
Block a user