Files
archived-orca/tests/e2e/new-workspace-linked-item-project-switch.spec.ts
Neil 2ceaff4869 refactor(renderer): group workspace creation and launch owners (#40688)
* refactor(renderer): group workspace creation and launch owners

* refactor(renderer): combine concrete workspace naming imports
2026-11-10 00:31:11 -08:00

167 lines
5.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Project switches must retain workspace-scoped Jira/Linear issues and clear repo-scoped GitHub/GitLab sources.
// Drive the real ProjectCombobox → handleProjectChange → pill render path, including main’s repo resolution.
import { execFileSync } from 'node:child_process'
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import type { Page } from '@stablyai/playwright-test'
import { test, expect } from './helpers/orca-app'
import { waitForActiveWorktree, waitForSessionReady } from './helpers/store'
import type { LinkedWorkItemSummary } from '../../src/renderer/src/lib/workspace/creation/new-workspace'
import type { TaskSourceContext } from '../../src/shared/work-items/task-source-context'
const SECOND_PROJECT_NAME = 'linked-item-second-project'
function runGit(repoPath: string, args: string[]): void {
execFileSync('git', args, { cwd: repoPath, stdio: 'pipe' })
}
function createGitRepo(repoPath: string): void {
mkdirSync(repoPath, { recursive: true })
runGit(repoPath, ['init'])
runGit(repoPath, ['config', 'user.email', 'e2e@test.local'])
runGit(repoPath, ['config', 'user.name', 'E2E Test'])
writeFileSync(path.join(repoPath, 'README.md'), '# Linked item project switch E2E\n')
runGit(repoPath, ['add', '-A'])
runGit(repoPath, ['commit', '-m', 'Initial commit'])
}
async function addSecondProject(page: Page, repoPath: string): Promise<void> {
await page.evaluate(async (targetRepoPath) => {
const store = window.__store
if (!store) {
throw new Error('window.__store is not available')
}
const addedRepo = await store.getState().addRepoPath(targetRepoPath)
if (!addedRepo) {
throw new Error(`Failed to add repo at ${targetRepoPath}`)
}
}, repoPath)
}
async function openComposerWithLinkedWorkItem(
page: Page,
linkedWorkItem: LinkedWorkItemSummary,
prefilledName: string,
taskSourceContext: TaskSourceContext | null = null
): Promise<void> {
await page.evaluate(
({ linkedWorkItem, prefilledName, taskSourceContext }) => {
const store = window.__store
if (!store) {
throw new Error('window.__store is not available')
}
store.getState().openModal('new-workspace-composer', {
linkedWorkItem,
prefilledName,
taskSourceContext
})
},
{ linkedWorkItem, prefilledName, taskSourceContext }
)
}
async function getJiraSourceContext(page: Page): Promise<TaskSourceContext> {
return page.evaluate(() => {
const state = window.__store?.getState()
const activeWorktreeId = state?.activeWorktreeId
const setup = state?.projectHostSetups.find((candidate) =>
state.worktreesByRepo[candidate.repoId]?.some((worktree) => worktree.id === activeWorktreeId)
)
if (!setup) {
throw new Error('Active project host setup is unavailable')
}
return {
kind: 'task-source',
provider: 'jira',
projectId: setup.projectId,
hostId: setup.hostId,
projectHostSetupId: setup.id,
repoId: setup.repoId,
providerIdentity: {
provider: 'jira',
siteId: 'e2e-jira-site',
siteUrl: 'https://example.atlassian.net',
projectKey: 'RDG'
}
}
})
}
async function switchComposerProject(page: Page, projectName: string): Promise<void> {
const composer = page.getByRole('dialog')
const combobox = composer.getByRole('combobox', { name: 'Project' })
const comboboxRoot = composer.locator('div[data-project-combobox-root="true"]')
await combobox.click()
await page.getByRole('option', { name: new RegExp(projectName) }).click()
await expect(comboboxRoot).toContainText(projectName)
}
test.describe('New workspace composer linked item across project switches', () => {
let tempRoot: string
let secondRepoPath: string
test.beforeEach(async ({ orcaPage }) => {
await waitForSessionReady(orcaPage)
await waitForActiveWorktree(orcaPage)
tempRoot = mkdtempSync(path.join(os.tmpdir(), 'orca-e2e-linked-item-'))
secondRepoPath = path.join(tempRoot, SECOND_PROJECT_NAME)
createGitRepo(secondRepoPath)
await addSecondProject(orcaPage, secondRepoPath)
})
test.afterEach(() => {
rmSync(tempRoot, { recursive: true, force: true })
})
test('keeps a Jira issue linked when the project changes', async ({ orcaPage }) => {
const jiraSourceContext = await getJiraSourceContext(orcaPage)
await openComposerWithLinkedWorkItem(
orcaPage,
{
type: 'issue',
provider: 'jira',
number: 0,
title: 'RDG-344 Migrate homepage from NuxtJS to NextJS',
url: 'https://example.atlassian.net/browse/RDG-344',
jiraIdentifier: 'RDG-344'
},
'rdg-344-nuxtjs-nextjs',
jiraSourceContext
)
const composer = orcaPage.getByRole('dialog')
await expect(composer).toBeVisible()
const sourcePill = composer.locator('[data-workspace-source-pill="true"]')
await expect(sourcePill).toContainText('RDG-344 Migrate homepage from NuxtJS to NextJS')
await switchComposerProject(orcaPage, SECOND_PROJECT_NAME)
await expect(sourcePill).toContainText('RDG-344 Migrate homepage from NuxtJS to NextJS')
})
test('clears a repo-scoped GitHub issue when the project changes', async ({ orcaPage }) => {
await openComposerWithLinkedWorkItem(
orcaPage,
{
type: 'issue',
provider: 'github',
number: 41,
title: 'Fix crash on launch',
url: 'https://github.com/acme/app/issues/41'
},
'fix-crash-on-launch'
)
const composer = orcaPage.getByRole('dialog')
await expect(composer).toBeVisible()
const sourcePill = composer.locator('[data-workspace-source-pill="true"]')
await expect(sourcePill).toContainText('#41 Fix crash on launch')
await switchComposerProject(orcaPage, SECOND_PROJECT_NAME)
await expect(sourcePill).toHaveCount(0)
})
})