Files
orca/tests/e2e/diff-note-edit.spec.ts
T
Brennan BensonandClaude Opus 5.5 e59b843336 Keep review note changes on the workspace copy they came from (#37204)
* Keep review note changes on their captured workspace owner

* Keep review note actions on the copy whose notes are shown

Review notes now read their owner and their notes together, so an action
always changes the copy the user is looking at:

- A paired SSH copy saves through its server even when its row does not
  name the server, instead of saving on this computer.
- The Markdown preview shows and edits the selected copy's notes, not the
  first copy listed with the same workspace id.
- While the selected copy is not listed yet, no other copy's notes are
  shown; a note started then saves to that copy once it lists.
- A listing that stamps the same copy's host no longer looks like a new
  copy: a pending Send stays held and unsaved note edits are kept.
- Clear all / Clear file confirmations stay on the copy they opened on
  when the selected host changes.
- A copy removed since the user acted reports the existing save or clear
  failure once instead of failing silently.
- Mounted note views skip ownership work on store updates that cannot
  change it, and do not re-render for another copy's changes.

* Keep review notes on the exact workspace copy each surface shows

Notes, their owner and every note action now come from one copy identity.
Previews and editors of a server's copy read and save that copy, paired
SSH copies keep working through their server, an SSH draft never lands on
a local row, and controls stay disabled instead of claiming "All notes
sent" while a copy's notes are unknown. Open Clear confirmations share the
cached read, so unrelated store writes do no row work.

* Resolve review-note copies through the shared workspace ownership rules

Every listed row now gets its copy from the same rules the app routes
writes with, including server provenance from detected listings and the
SSH place behind a paired server for older rows without host stamps.
Previews, editors and diffs read notes from their own tab's provenance
instead of the selected copy, folders honor their source's host, and a
note composer's shortcut captures the copy its surface shows when it
opens.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Keep folder review notes on the folder copy their source names

A folder's notes now come from the same source rules as worktree notes,
so a file from this app never shows or saves to a server's folder with
the same id. Queued folder saves and rollbacks check the captured folder
copy the same way reads do, and resolving copies no longer rescans the
project list for every row.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Read review-note copies through the shared id indexes

Folder and worktree note views now read only their own workspace's
catalog entries from the shared indexes, and readers of one folder
share its qualification, so listing updates cost work proportional to
what is shown rather than catalog size times readers. Also fixes the
type errors and the end-to-end note seeds, which now pass the owner of
the worktree they seed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Share review-note copy resolution across rows and readers

Rows of one workspace on the same host now share a single ownership
answer per catalog snapshot, so duplicate listings of an SSH worktree
no longer make every note view rescan its peers. Folders that are not
listed return one shared answer instead of leaving cache entries behind.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Name the catalog snapshots review-note ownership results are shared under

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Save renamed-file drafts under the new path and encode restored SSH targets

A diff note draft opened before its file was renamed in place now saves
under the file's current path, still on the copy it was opened on. A
restored SSH file whose target id needs encoding now shows and saves its
own copy's notes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Update the diff note path ref after render instead of during it

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-02 10:32:22 -08:00

139 lines
5.0 KiB
TypeScript

import { test, expect } from './helpers/orca-app'
import { waitForSessionReady, waitForActiveWorktree } from './helpers/store'
test.describe('Diff note edit', () => {
test.beforeEach(async ({ orcaPage }) => {
await waitForSessionReady(orcaPage)
await waitForActiveWorktree(orcaPage)
})
test('editing a saved inline note updates the open diff card', async ({ orcaPage }) => {
const worktreeId = await waitForActiveWorktree(orcaPage)
const seededBody = 'edit-me note'
const editedBody = 'edited note from the inline card'
// Use a real modified-file diff so Monaco mounts the local saved-note zone.
const { relativePath } = await orcaPage.evaluate(async (wId) => {
const store = window.__store
if (!store) {
throw new Error('window.__store is not available - is the app in dev mode?')
}
const state = store.getState()
const worktree = Object.values(state.worktreesByRepo)
.flat()
.find((entry) => entry.id === wId)
if (!worktree) {
throw new Error('active worktree not found')
}
const separator = worktree.path.includes('\\') ? '\\' : '/'
const rel = `src${separator}index.ts`
const absolutePath = `${worktree.path}${separator}${rel}`
await window.api.fs.writeFile({
filePath: absolutePath,
content: 'export const hello = "note-edit-test"\n'
})
return { relativePath: rel }
}, worktreeId)
const addResult = await orcaPage.evaluate(
async ({ wId, rel, body }) => {
const store = window.__store
if (!store) {
throw new Error('window.__store is not available')
}
// The seeded worktree is this app's own (local) copy.
return store.getState().addDiffComment(
{
kind: 'worktree',
worktreeId: wId,
authority: { endpoint: { kind: 'self' }, at: 'local' }
},
{
worktreeId: wId,
filePath: rel,
source: 'diff',
lineNumber: 1,
body,
side: 'modified'
}
)
},
{ wId: worktreeId, rel: relativePath, body: seededBody }
)
expect(addResult, 'addDiffComment returned null').not.toBeNull()
const commentId = addResult!.id
await orcaPage.evaluate(
({ wId, rel }) => {
const store = window.__store
if (!store) {
throw new Error('window.__store is not available')
}
const state = store.getState()
const worktree = Object.values(state.worktreesByRepo)
.flat()
.find((entry) => entry.id === wId)
if (!worktree) {
throw new Error('active worktree not found')
}
const separator = worktree.path.includes('\\') ? '\\' : '/'
state.openDiff(wId, `${worktree.path}${separator}${rel}`, rel, 'typescript', false)
},
{ wId: worktreeId, rel: relativePath }
)
const card = orcaPage.locator('.orca-diff-comment-card').first()
await expect(card, 'seeded inline note did not render').toBeVisible({ timeout: 15_000 })
await expect(card.locator('.orca-diff-comment-body')).toHaveText(seededBody)
await card.getByTitle('Edit note').click()
const textarea = card.locator('.orca-diff-comment-popover-textarea')
await expect(textarea).toBeVisible()
await expect(textarea).toHaveValue(seededBody)
const saveButton = card
.locator('.orca-diff-comment-popover-footer button')
.filter({ hasText: 'Save' })
await expect(saveButton, 'Save should be disabled before the body changes').toBeDisabled()
await textarea.fill(editedBody)
await expect(saveButton, 'Save should be enabled for a non-empty changed body').toBeEnabled()
await saveButton.click()
await expect(textarea, 'edit controls did not close after saving').toHaveCount(0, {
timeout: 5_000
})
await expect
.poll(
async () =>
orcaPage.evaluate((id: string) => {
const store = window.__store
if (!store) {
return null
}
const all = Object.values(store.getState().worktreesByRepo)
.flat()
.flatMap((w) => w.diffComments ?? [])
const comment = all.find((c) => c.id === id)
return comment?.body ?? null
}, commentId),
{
timeout: 5_000,
message: 'updateDiffComment did not persist the edited body in the store'
}
)
.toBe(editedBody)
const updatedCard = orcaPage
.locator('.orca-diff-comment-card')
.filter({ has: orcaPage.locator('.orca-diff-comment-body', { hasText: editedBody }) })
.first()
await expect(updatedCard, 'inline card did not update in the open diff').toBeVisible()
await expect(updatedCard.locator('.orca-diff-comment-body')).toHaveText(editedBody)
await expect(updatedCard.locator('.orca-diff-comment-body')).not.toHaveText(seededBody)
await expect(updatedCard.getByTitle('Edit note')).toBeVisible()
})
})