Skip to content

Commit 762eb4f

Browse files
fix: prevent workspace overwrites.
1 parent 5c916c9 commit 762eb4f

30 files changed

Lines changed: 2691 additions & 578 deletions

docs/pr-context-storage-matrix.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,22 @@ Use this matrix as the source of truth when debugging UI/storage mismatch.
4343

4444
## Current Workspace Selection On Load
4545

46-
When the app loads or the selected repository changes, the app selects a workspace from IndexedDB using repository-scoped records only.
46+
When the app loads, workspace restore scope depends on whether a repository is selected.
47+
48+
- If a repository is selected: use repository-scoped records only (`repo` match).
49+
- If no repository is selected: evaluate all stored workspace records.
4750

4851
Selection order:
4952

50-
1. Load records for the currently selected repository (`repo` match).
51-
2. Compute a preferred id from in-memory state:
53+
1. Load candidate records using the scope above.
54+
2. Compute preferred candidates from in-memory state:
5255

53-
- Existing in-memory active record id when available.
54-
- Otherwise canonical id derived from current repository + head.
56+
- Preferred by id: existing in-memory active record id when available.
57+
- Preferred by workspace key: current repository + head (`workspaceKey`).
5558

56-
3. If the preferred record exists and is `active`, select it.
57-
4. Otherwise select the first `active` record in that repository.
58-
5. Otherwise select the preferred record if present.
59+
3. If preferred-by-id or preferred-by-key exists and is `active`, select it.
60+
4. Otherwise select the first `active` record in candidates.
61+
5. Otherwise select preferred-by-id or preferred-by-key if present.
5962
6. Otherwise fall back to the first record returned by IDB ordering.
6063

6164
Notes:

playwright/github-byot-ai.spec.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -760,15 +760,20 @@ test('BYOT remembers selected repository across reloads', async ({ page }) => {
760760
.fill('github_pat_fake_1234567890')
761761
await page.getByRole('button', { name: 'Add GitHub token' }).click()
762762

763-
await ensureOpenPrDrawerOpen(page)
764-
765763
const repoSelect = page.getByLabel('Pull request repository')
766-
await expect(repoSelect).toBeEnabled()
764+
await expect(repoSelect).toBeDisabled()
767765
await expect(page.getByRole('status', { name: 'App status' })).toHaveText(
768766
'Loaded 2 writable repositories',
769767
)
770768

771-
await repoSelect.selectOption('knightedcodemonkey/develop')
769+
await page.getByRole('button', { name: 'Workspaces' }).click()
770+
const workspaceRepositoryFilter = page.getByLabel('Workspace repository filter')
771+
await expect(workspaceRepositoryFilter).toBeVisible()
772+
await workspaceRepositoryFilter.selectOption('knightedcodemonkey/develop')
773+
await expect(workspaceRepositoryFilter).toHaveValue('knightedcodemonkey/develop')
774+
await page.getByRole('button', { name: 'Close workspaces drawer' }).click()
775+
776+
await ensureOpenPrDrawerOpen(page)
772777
await expect(repoSelect).toHaveValue('knightedcodemonkey/develop')
773778

774779
await page.reload()
@@ -783,4 +788,5 @@ test('BYOT remembers selected repository across reloads', async ({ page }) => {
783788
await expect(page.getByRole('button', { name: 'Delete GitHub token' })).toBeVisible()
784789
await ensureOpenPrDrawerOpen(page)
785790
await expect(repoSelect).toHaveValue('knightedcodemonkey/develop')
791+
await expect(repoSelect).toBeDisabled()
786792
})

0 commit comments

Comments
 (0)