* feat(app): launch a terminal from the New workspace screen
New workspace only ever started a chat agent. Empty workspaces existed but
were reachable only by submitting an empty composer, which nothing advertised,
and terminals could not be started from this screen at all. People concluded
Paseo did not support terminals.
Adds a launch chip to the meta row, shaped from the same ComboboxTrigger as
its neighbours, that chooses between Chat and a terminal. Terminal profiles
mark where a typed prompt goes with a {{{prompt}}} sentinel in their command
or args, substituted client-side before create_terminal_request, so the daemon
learns nothing new and the protocol is untouched. A profile without the
sentinel takes no input: the composer goes read-only and shows the exact
command, so there is nothing to type wrong.
Prompt forms come from each CLI's own --help. claude, codex, and pi take a
trailing positional; opencode's positional is the project directory, so it
uses --prompt=. Profiles predating the sentinel adopt the right form on read,
keyed on the command's base name rather than the profile id, because profiles
created in settings get generated ids.
* fix(app): stop existing launchers passing the prompt sentinel literally
Adoption made every caller of resolveTerminalProfiles see sentinel-bearing
args, but only New workspace substituted them. Pinned targets and the
workspace terminal menu forwarded profile.args straight through, so launching
Claude from an existing workspace ran `claude "{{{prompt}}}"` with that text as
the prompt.
Every launcher now goes through resolveTerminalProfileLaunch. Surfaces with
nowhere to type pass an empty prompt, which drops the prompt-only arg and
gives back the bare command they had before.
Also from the same review:
- Adoption skipped when args lead with a subcommand. `opencode run` takes a
positional message rather than --prompt, and `codex login` takes no prompt at
all. Only the first arg is checked, so `pi --thinking high` still adopts.
- Settings edits the persisted list again, not the adopted view. It writes the
whole list back on any change, so resolving first baked read-time adoption
into the user's config the moment they reordered a row.
- A hidden draft no longer names a workspace. Text typed for a prompt-taking
profile stayed in state after switching to a read-only one and still seeded
the generated title and branch.
- Windows .cmd escaping now has a round-trip test: a real cmd.exe runs a real
.cmd shim that echoes its argv, covering metacharacters, an injection
attempt, and newlines. The existing tests only asserted the command line we
generate.
- Fixed an ENOTEMPTY flake in the terminal suite. kill() only signals, so the
shell was still writing into $ZDOTDIR while its directory was being removed.
Cleanup waits for exit instead.
* fix(app): keep the host and isolation accessible names stable
Wiring the new tooltips also replaced these two accessible names with the
tooltip copy, which broke `sidebar-project-grouping` at the host picker: its
selector is `getByRole("button", { name: "Host", exact: true })` and the button
had become "Choose the host". It timed out on both attempts in CI.
An accessible name identifies a control; a tooltip explains it. Conflating them
renamed a control that other surfaces address by name. The names go back to
what they were and the tooltips keep the "Choose the ..." copy.
* test(server): stop temp-dir teardown failing unrelated terminal tests
The ENOTEMPTY flake survived both earlier attempts. Waiting for the session to
exit shrank the window; retrying the remove did not close it either. The writes
come from processes zsh forks on the way out, which outlive the pty and answer
to nothing the test holds.
Teardown is now best-effort and logs what it left behind. A temp directory we
cannot remove is not a defect in the terminal code under test, and failing on it
reports the race against whichever assertion ran last, which is exactly how this
surfaced: as a flake in an unrelated zsh title test. 10 consecutive runs green.
Also replaces a cast in the Windows .cmd helper with a real narrow, so a change
to ResolvedTerminalCommand fails loudly there. Test files are excluded from
typecheck (tsconfig.server.json), so a cast in one is never checked at all.
* fix(app): keep terminal launch policy in its owning workflows
Profile adoption now parses known global option values before deciding whether argv already contains a positional. Workspace naming is derived inside the terminal workflow so hidden launch-only drafts cannot affect branch or title generation.
* fix(server): preserve cmd shim arguments through both parses
npm command shims forward %*, so metacharacters lose one escape layer before the target process receives argv. Exercise the production node-pty string command line against a forwarding shim, and only tolerate the known ENOTEMPTY teardown race.
* fix(server): stabilize Windows subprocess tests
* test(server): isolate Windows argv recorder output
* test(server): allow native watcher integration to settle
194 lines
7.7 KiB
TypeScript
194 lines
7.7 KiB
TypeScript
import { expect, type Page } from "@playwright/test";
|
|
import type { TerminalProfile } from "@getpaseo/protocol/messages";
|
|
import { DEFAULT_TERMINAL_PROFILES } from "@getpaseo/protocol/terminal-profiles";
|
|
import { connectNewWorkspaceDaemonClient } from "./new-workspace";
|
|
import { waitForTerminalContent } from "./terminal-perf";
|
|
|
|
export type { TerminalProfile };
|
|
|
|
export interface TerminalProfileSeed {
|
|
/** Restores the daemon's terminalProfiles to what they were before seeding, and closes the client. */
|
|
restore(): Promise<void>;
|
|
}
|
|
|
|
/**
|
|
* Overrides the connected host's terminal profiles for the duration of a
|
|
* test. The daemon has no "unset" for a patched config field, so restoring
|
|
* writes back either the exact previous array, or the shipped defaults when
|
|
* the host had never customized profiles — functionally identical to the
|
|
* absent state `resolveTerminalProfiles` would otherwise produce.
|
|
*/
|
|
export async function seedTerminalProfiles(
|
|
profiles: TerminalProfile[],
|
|
): Promise<TerminalProfileSeed> {
|
|
const client = await connectNewWorkspaceDaemonClient();
|
|
const previous = await client.getDaemonConfig();
|
|
await client.patchDaemonConfig({ terminalProfiles: profiles });
|
|
return {
|
|
async restore() {
|
|
await client.patchDaemonConfig({
|
|
terminalProfiles: previous.config.terminalProfiles ?? [...DEFAULT_TERMINAL_PROFILES],
|
|
});
|
|
await client.close();
|
|
},
|
|
};
|
|
}
|
|
|
|
/** Mid-test profile changes (e.g. simulating a profile being removed). Does not manage restoration — pair with `seedTerminalProfiles` for that. */
|
|
export async function patchTerminalProfiles(profiles: TerminalProfile[]): Promise<void> {
|
|
const client = await connectNewWorkspaceDaemonClient();
|
|
try {
|
|
await client.patchDaemonConfig({ terminalProfiles: profiles });
|
|
} finally {
|
|
await client.close();
|
|
}
|
|
}
|
|
|
|
// ─── Locators ──────────────────────────────────────────────────────────────
|
|
|
|
/** The single meta-row chip that chooses chat or a terminal. */
|
|
export function launchTrigger(page: Page) {
|
|
return page.getByTestId("new-workspace-launch-trigger");
|
|
}
|
|
|
|
export function launchMenu(page: Page) {
|
|
return page.getByTestId("new-workspace-launch-menu");
|
|
}
|
|
|
|
export function launchOption(page: Page, optionId: string) {
|
|
return page.getByTestId(`new-workspace-launch-option-${optionId}`);
|
|
}
|
|
|
|
export function manageProfilesOption(page: Page) {
|
|
return page.getByTestId("new-workspace-launch-manage-profiles");
|
|
}
|
|
|
|
// Chat and terminal are the same composer in two modes, so they share
|
|
// `message-input-root`. What tells them apart is which affordances that mode
|
|
// renders: chat has the attachment button, terminal has the Launch button.
|
|
export function composerRoot(page: Page) {
|
|
return page.locator('[data-testid="message-input-root"]:visible');
|
|
}
|
|
|
|
// Scoped to the visible composer: a workspace opened earlier in the test keeps
|
|
// its own composer mounted but hidden in the deck, so an unscoped testid
|
|
// matches two elements and trips strict mode.
|
|
export function attachButton(page: Page) {
|
|
return composerRoot(page).getByTestId("message-input-attach-button");
|
|
}
|
|
|
|
export function terminalPromptInput(page: Page) {
|
|
return composerRoot(page).getByRole("textbox", { name: "Terminal prompt" });
|
|
}
|
|
|
|
/** The static command shown when the selected profile takes no prompt. */
|
|
export function terminalCommandPreview(page: Page) {
|
|
return composerRoot(page).getByTestId("composer-readonly-content");
|
|
}
|
|
|
|
export function terminalLaunchSubmit(page: Page) {
|
|
return composerRoot(page).getByTestId("new-workspace-launch-submit");
|
|
}
|
|
|
|
// ─── Actions ───────────────────────────────────────────────────────────────
|
|
|
|
export async function openLaunchMenu(page: Page): Promise<void> {
|
|
await launchTrigger(page).click();
|
|
await expect(launchMenu(page)).toBeVisible({ timeout: 30_000 });
|
|
}
|
|
|
|
/** `optionId` is `chat`, `blank`, or a terminal profile id. */
|
|
export async function selectLaunchOption(page: Page, optionId: string): Promise<void> {
|
|
await openLaunchMenu(page);
|
|
const option = launchOption(page, optionId);
|
|
await expect(option).toBeVisible({ timeout: 30_000 });
|
|
await option.click();
|
|
await expect(launchMenu(page)).toHaveCount(0);
|
|
}
|
|
|
|
export async function selectChatLaunch(page: Page): Promise<void> {
|
|
await selectLaunchOption(page, "chat");
|
|
}
|
|
|
|
export async function fillTerminalPrompt(page: Page, text: string): Promise<void> {
|
|
const input = terminalPromptInput(page);
|
|
await expect(input).toBeVisible({ timeout: 30_000 });
|
|
await input.fill(text);
|
|
}
|
|
|
|
export async function submitTerminalLaunch(page: Page): Promise<void> {
|
|
const submit = terminalLaunchSubmit(page);
|
|
await expect(submit).toBeEnabled({ timeout: 30_000 });
|
|
await submit.click();
|
|
}
|
|
|
|
// ─── Assertions ────────────────────────────────────────────────────────────
|
|
|
|
export async function expectChatComposerActive(page: Page): Promise<void> {
|
|
await expect(composerRoot(page)).toBeVisible({ timeout: 30_000 });
|
|
await expect(attachButton(page)).toBeVisible({ timeout: 30_000 });
|
|
await expect(terminalLaunchSubmit(page)).toHaveCount(0);
|
|
}
|
|
|
|
export async function expectTerminalComposerActive(page: Page): Promise<void> {
|
|
await expect(composerRoot(page)).toBeVisible({ timeout: 30_000 });
|
|
await expect(terminalLaunchSubmit(page)).toBeVisible({ timeout: 30_000 });
|
|
await expect(attachButton(page)).toHaveCount(0);
|
|
}
|
|
|
|
export async function expectLaunchTriggerLabel(page: Page, label: string): Promise<void> {
|
|
await expect(launchTrigger(page)).toContainText(label);
|
|
}
|
|
|
|
export async function expectChatLaunchSelected(page: Page): Promise<void> {
|
|
await expectLaunchTriggerLabel(page, "Chat");
|
|
await expectChatComposerActive(page);
|
|
}
|
|
|
|
export async function expectTerminalLaunchSelected(
|
|
page: Page,
|
|
profileLabel: string,
|
|
): Promise<void> {
|
|
await expectLaunchTriggerLabel(page, profileLabel);
|
|
await expectTerminalComposerActive(page);
|
|
}
|
|
|
|
export async function expectTerminalPreviewCommand(page: Page, command: string): Promise<void> {
|
|
const preview = terminalCommandPreview(page);
|
|
await expect(preview).toBeVisible({ timeout: 30_000 });
|
|
await expect(preview).toHaveText(command);
|
|
}
|
|
|
|
function terminalContentIncludes(expected: string) {
|
|
return (text: string) => text.includes(expected);
|
|
}
|
|
|
|
/** Waits for the spawned terminal's rendered output to contain `expected`. */
|
|
export async function expectTerminalOutputContains(
|
|
page: Page,
|
|
expected: string,
|
|
timeoutMs = 30_000,
|
|
): Promise<void> {
|
|
await waitForTerminalContent(page, terminalContentIncludes(expected), timeoutMs);
|
|
}
|
|
|
|
/**
|
|
* Waits for the New workspace submit to land on a workspace with a terminal
|
|
* tab open, and returns the terminal id. Scoped to visible elements: earlier
|
|
* workspace decks stay mounted (offscreen) for fast switching, so an
|
|
* unscoped terminal-surface locator can match more than one.
|
|
*/
|
|
export async function expectWorkspaceOpensWithTerminalTab(page: Page): Promise<string> {
|
|
const terminalTab = page.locator('[data-testid^="workspace-tab-terminal_"]:visible');
|
|
await expect(terminalTab.first()).toBeVisible({ timeout: 30_000 });
|
|
await expect(page.locator('[data-testid="terminal-surface"]:visible').first()).toBeVisible({
|
|
timeout: 30_000,
|
|
});
|
|
const testId = await terminalTab.first().getAttribute("data-testid");
|
|
const terminalId = testId?.replace("workspace-tab-terminal_", "") ?? "";
|
|
if (!terminalId) {
|
|
throw new Error(`Could not parse terminal id from tab testID: ${testId}`);
|
|
}
|
|
return terminalId;
|
|
}
|