Skip to content

Commit 036d919

Browse files
refactor: github pr context.
1 parent 9f5dbad commit 036d919

31 files changed

Lines changed: 3926 additions & 3375 deletions

playwright/github-byot-ai.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from '@playwright/test'
2-
import { defaultGitHubChatModel } from '../src/modules/github/github-api.js'
2+
import { defaultGitHubChatModel } from '../src/modules/github/api/chat.js'
33
import type { ChatRequestBody, ChatRequestMessage } from './helpers/app-test-helpers.js'
44
import {
55
appEntryPath,

playwright/workspace-tabs.spec.ts

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,62 @@ const seedSyncedComponentTab = async (page: import('@playwright/test').Page) =>
108108
})
109109
}
110110

111+
const waitForWorkspaceTabOrderPersistence = async (
112+
page: import('@playwright/test').Page,
113+
expectedLeadingTabNames: string[],
114+
) => {
115+
await expect
116+
.poll(async () => {
117+
return page.evaluate(async expectedTabNames => {
118+
const request = indexedDB.open('knighted-develop-workspaces')
119+
120+
const db = await new Promise<IDBDatabase>((resolve, reject) => {
121+
request.onsuccess = () => resolve(request.result)
122+
request.onerror = () => reject(request.error)
123+
request.onblocked = () => reject(new Error('Could not open IndexedDB.'))
124+
})
125+
126+
try {
127+
const tx = db.transaction('prWorkspaces', 'readonly')
128+
const store = tx.objectStore('prWorkspaces')
129+
const getAllRequest = store.getAll()
130+
131+
const records = await new Promise<Array<Record<string, unknown>>>(
132+
(resolve, reject) => {
133+
getAllRequest.onsuccess = () => {
134+
const value = Array.isArray(getAllRequest.result)
135+
? getAllRequest.result
136+
: []
137+
resolve(value as Array<Record<string, unknown>>)
138+
}
139+
getAllRequest.onerror = () => reject(getAllRequest.error)
140+
},
141+
)
142+
143+
return records.some(record => {
144+
const tabs = Array.isArray(record.tabs) ? record.tabs : []
145+
const tabNames = tabs
146+
.map(tab => {
147+
if (!tab || typeof tab !== 'object') {
148+
return ''
149+
}
150+
151+
return typeof (tab as { name?: unknown }).name === 'string'
152+
? ((tab as { name: string }).name ?? '')
153+
: ''
154+
})
155+
.filter(name => name.length > 0)
156+
157+
return expectedTabNames.every((name, index) => tabNames[index] === name)
158+
})
159+
} finally {
160+
db.close()
161+
}
162+
}, expectedLeadingTabNames)
163+
})
164+
.toBe(true)
165+
}
166+
111167
test('removing active tab selects deterministic adjacent tab', async ({ page }) => {
112168
await waitForInitialRender(page)
113169

@@ -320,8 +376,8 @@ test('workspace tab drag reorder persists across reload', async ({ page }) => {
320376
await expect(orderedTabs.nth(0)).toHaveAccessibleName('Workspace tab module-2.tsx')
321377
await expect(orderedTabs.nth(1)).toHaveAccessibleName('Workspace tab App.tsx')
322378

323-
/* Reorder persistence is debounced; wait for normal save rather than unload flush. */
324-
await page.waitForTimeout(1000)
379+
/* Reorder persistence is debounced; wait until IndexedDB reflects the new order. */
380+
await waitForWorkspaceTabOrderPersistence(page, ['module-2.tsx', 'App.tsx'])
325381

326382
await page.reload()
327383
await waitForInitialRender(page)

src/app.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ import { createWorkspaceSyncController } from './modules/app-core/workspace-sync
4141
import { createWorkspaceTabAddMenuUiController } from './modules/app-core/workspace-tab-add-menu-ui.js'
4242
import { createDiagnosticsUiController } from './modules/diagnostics/diagnostics-ui.js'
4343
import { createGitHubChatDrawer } from './modules/github/chat-drawer/drawer.js'
44-
import { createGitHubByotControls } from './modules/github/github-byot-controls.js'
44+
import { createGitHubByotControls } from './modules/github/byot-controls.js'
4545
import {
4646
formatActivePrReference,
4747
getActivePrContextSyncKey,
4848
parsePullRequestNumberFromUrl,
49-
} from './modules/github/github-pr-context.js'
50-
import { createGitHubPrEditorSyncController } from './modules/github/github-pr-editor-sync.js'
51-
import { createGitHubPrDrawer } from './modules/github/github-pr-drawer.js'
49+
} from './modules/github/pr/context.js'
50+
import { createGitHubPrEditorSyncController } from './modules/github/pr/editor-sync.js'
51+
import { createGitHubPrDrawer } from './modules/github/pr/drawer/controller/create-controller.js'
5252
import { createLayoutThemeController } from './modules/ui/layout-theme.js'
5353
import { createLintDiagnosticsController } from './modules/diagnostics/lint-diagnostics.js'
5454
import { createPreviewBackgroundController } from './modules/preview/preview-background.js'

0 commit comments

Comments
 (0)