Skip to content

Commit 126ee77

Browse files
refactor: address pr comments.
1 parent 9854485 commit 126ee77

3 files changed

Lines changed: 71 additions & 7 deletions

File tree

playwright/github-byot-ai.spec.ts

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
openStoredWorkspaceContextById,
1919
seedLocalWorkspaceContexts,
2020
} from './github-pr-drawer/github-pr-drawer.helpers.js'
21+
import { selectWorkspacesRepositoryFilter } from './github-pr-drawer/github-pr-drawer.helpers.js'
2122

2223
test('PR/BYOT controls are visible and chat stays hidden until token connect', async ({
2324
page,
@@ -492,7 +493,7 @@ test('Active Local non-PR workspace can be renamed from Workspaces drawer', asyn
492493
await expect(page.locator('#workspace-context-status')).toContainText(renamedTitle)
493494
})
494495

495-
test('Active Local PR-associated workspace cannot be renamed from Workspaces drawer', async ({
496+
test('Active Local workspace with active PR context and null PR number cannot be renamed from Workspaces drawer', async ({
496497
page,
497498
}) => {
498499
const activeWorkspaceId = 'active_local_workspace_rename_blocked_pr_associated'
@@ -507,7 +508,7 @@ test('Active Local PR-associated workspace cannot be renamed from Workspaces dra
507508
head: 'feat/active-local-rename-blocked',
508509
prTitle: 'PR-associated local workspace',
509510
prContextState: 'active',
510-
prNumber: 97,
511+
prNumber: null,
511512
tabs: [
512513
{
513514
id: 'component',
@@ -541,6 +542,68 @@ test('Active Local PR-associated workspace cannot be renamed from Workspaces dra
541542
await expect(renameButton).toBeDisabled()
542543
})
543544

545+
test('Repository-scoped workspace cannot be renamed from Workspaces drawer', async ({
546+
page,
547+
}) => {
548+
const repositoryFullName = 'knightedcodemonkey/develop'
549+
const repositoryWorkspaceId = 'repository_workspace_rename_blocked'
550+
551+
await waitForAppReady(page)
552+
553+
await seedLocalWorkspaceContexts(page, [
554+
{
555+
id: repositoryWorkspaceId,
556+
repo: repositoryFullName,
557+
workspaceScope: 'repository',
558+
head: 'feat/repository-rename-blocked',
559+
prTitle: 'Repository scoped workspace',
560+
prContextState: 'inactive',
561+
prNumber: null,
562+
tabs: [
563+
{
564+
id: 'component',
565+
path: 'src/component.tsx',
566+
language: 'tsx',
567+
role: 'component',
568+
content: 'export const App = () => <main>repository rename blocked</main>',
569+
order: 0,
570+
source: 'workspace',
571+
dirty: false,
572+
},
573+
],
574+
activeTabId: 'component',
575+
},
576+
])
577+
578+
await page.route('https://api.github.com/user/repos**', async route => {
579+
await route.fulfill({
580+
status: 200,
581+
contentType: 'application/json',
582+
body: JSON.stringify([
583+
{
584+
id: 11,
585+
owner: { login: 'knightedcodemonkey' },
586+
name: 'develop',
587+
full_name: repositoryFullName,
588+
default_branch: 'main',
589+
permissions: { push: true },
590+
},
591+
]),
592+
})
593+
})
594+
595+
await page.reload()
596+
await waitForAppReady(page)
597+
await connectByotWithSingleRepo(page)
598+
await selectWorkspacesRepositoryFilter(page, repositoryFullName)
599+
600+
const workspaceSelect = page.getByLabel('Stored workspace')
601+
const renameButton = page.getByRole('button', { name: 'Rename', exact: true })
602+
603+
await expect(workspaceSelect).toHaveValue(repositoryWorkspaceId)
604+
await expect(renameButton).toBeHidden()
605+
})
606+
544607
test('chat stays usable after opening a Local workspace with PAT connected', async ({
545608
page,
546609
}) => {

src/modules/app-core/github-workflows.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,12 @@ const initializeGitHubWorkflows = ({
561561
return false
562562
}
563563

564+
const workspacePrContextState =
565+
toSafeWorkspaceText(record.prContextState).toLowerCase() || 'inactive'
564566
const hasWorkspacePrNumber =
565567
typeof record.prNumber === 'number' && Number.isFinite(record.prNumber)
566-
const isPrAssociatedWorkspace = hasWorkspacePrNumber
568+
const isPrAssociatedWorkspace =
569+
workspacePrContextState !== 'inactive' || hasWorkspacePrNumber
567570
if (isPrAssociatedWorkspace) {
568571
workspacesDrawerController?.setStatus(
569572
'Use Pull Request controls to rename PR-associated workspaces.',

src/modules/workspace/workspaces-drawer/drawer.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ export const createWorkspacesDrawer = ({
8484
return state === 'inactive' && !hasPrNumber
8585
}
8686

87-
const hasFinitePrNumber = workspace =>
88-
typeof workspace?.prNumber === 'number' && Number.isFinite(workspace.prNumber)
89-
9087
const shouldRenderAsLocalEntry = workspace => {
9188
if (toSafeWorkspaceScope(workspace) === localWorkspaceScopeValue) {
9289
return true
@@ -160,7 +157,8 @@ export const createWorkspacesDrawer = ({
160157
const selectedWorkspaceScope = toSafeWorkspaceScope(selectedEntry)
161158
const isSelectedLocalWorkspace =
162159
hasSelection && selectedWorkspaceScope === localWorkspaceScopeValue
163-
const isSelectedWorkspaceNonPr = hasSelection && !hasFinitePrNumber(selectedEntry)
160+
const isSelectedWorkspaceNonPr =
161+
hasSelection && isInactiveWithoutPrNumber(selectedEntry)
164162
const isSelectedWorkspaceActive =
165163
hasSelection &&
166164
Boolean(activeWorkspaceId) &&

0 commit comments

Comments
 (0)