Sidebar (web/components/sidebar.tsx) reorganized to the requested structure:
Quick find at the top; a Pages group (All Pages tree with the existing
rename/reorder/pin/subpage/delete interactions, Pinned Pages, Untagged
Pages); a Bookmarks group (All Bookmarks, Calendar, and expandable carets
for Tags / Kanban / Collections / Contacts listing their entities with
deep-links /tags?tag=, /kanban?column=, /collections?id=, /contacts?open=);
Trash at the bottom. Collapsed desktop rail is a flat icon list; the mobile
drawer shows the full grouped nav.
Page tagging (new): PageTag join (migration 023 + schema.sql, db-converge
proven), POST/DELETE /api/pages/{id}/tags with owner-or-TagShare validation
(same rule as bookmark tags), tags exposed in the page list/detail
projections so the sidebar can compute the untagged subset. Tagging is
metadata (no content-version bump) and cascades on page/tag delete.
Dragging a page from Untagged Pages onto a tag assigns it (custom drag MIME
keeps it distinct from page reorder).
Kanban: only explicitly-placed cards render (no auto-populate of unassigned
bookmarks); the sidebar caret lists the existing columns and ?column=
scrolls/rings the target. e2e updated to assert no-auto-populate then place
the card explicitly.
All Bookmarks: a Group by selector (None/Calendar/Tags/Kanban/Collections/
Contacts) rendering grouped sections via shared row/card renderers; the
default None path is byte-identical to before (205-row table, same keys).
Collections grouping fetches membership once, sequence-guarded.
Calendar: Day/Week/Month/Year/List views (Month default), adaptive
prev/next + Today, date-sorted list; SSR-safe (date-fns only, post-mount
today), internal overflow containers so no page-level horizontal scroll.
Deep-link page wrappers for kanban/collections/contacts pass searchParams
into the clients' initial selection.
Test gate: the -race internal/http suite now exceeds the default 10m go
test timeout (~14m cold-cache), so the tests service and Makefile test
target use -timeout 30m; the suite passes in full.
Verified: regressions 20/20, real-stack e2e all pass, lint/SSR-lint/build
0 errors, db-converge green, full Go integration suite green; browser
checks of the grouped sidebar, drag-to-tag, bookmark group-by and every
calendar view show correct rendering with no horizontal overflow.
260 lines
16 KiB
JavaScript
260 lines
16 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { execFileSync } from 'node:child_process'
|
|
import { chromium } from 'playwright'
|
|
|
|
// Run with the Docker stack up. Only uniquely created QA accounts are cleaned
|
|
// up; existing users, bookmarks and database tables are never reset.
|
|
const base = process.env.BASE_URL || 'http://localhost:3000'
|
|
// Review TEST-03: the cleanup path deletes accounts through the LOCAL compose
|
|
// database, so the runner must prove the browser target is that same stack
|
|
// before creating anything. Non-loopback targets are refused unless the
|
|
// operator explicitly acknowledges (E2E_ALLOW_REMOTE=1) that no cleanup is
|
|
// possible and accounts will persist (E2E_KEEP_DATA=1).
|
|
const repoRoot = new URL('..', import.meta.url)
|
|
const baseUrl = new URL(base)
|
|
const loopback = ['localhost', '127.0.0.1', '::1'].includes(baseUrl.hostname)
|
|
const keepData = process.env.E2E_KEEP_DATA === '1'
|
|
const localDbRunning = () => {
|
|
try {
|
|
return execFileSync('docker', ['compose', 'ps', '--status', 'running', '-q', 'db'], { cwd: repoRoot, stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim() !== ''
|
|
} catch { return false }
|
|
}
|
|
if (!loopback) {
|
|
if (process.env.E2E_ALLOW_REMOTE !== '1') {
|
|
console.error(`Refusing to run against non-local target ${base}: cleanup is tied to the local compose database. Use the local stack, or set E2E_ALLOW_REMOTE=1 together with E2E_KEEP_DATA=1 to accept that QA accounts will persist on the remote target.`)
|
|
process.exit(1)
|
|
}
|
|
if (!keepData) {
|
|
console.error(`Remote target ${base} cannot be cleaned up through local docker; set E2E_KEEP_DATA=1 to acknowledge created accounts will persist.`)
|
|
process.exit(1)
|
|
}
|
|
}
|
|
if (!keepData && !localDbRunning()) {
|
|
console.error('Cleanup requires the local compose db service to be running (docker compose up -d db); refusing to create QA accounts that could not be removed.')
|
|
process.exit(1)
|
|
}
|
|
const browser = await chromium.launch({ executablePath: process.env.CHROMIUM_PATH || '/usr/bin/chromium', headless: true, args: ['--no-sandbox'] })
|
|
const accounts = []
|
|
const errors = []
|
|
let testFailed = false
|
|
const password = 'qa-test-long-password'
|
|
const email = `qa-${Date.now()}@superbrain.test`
|
|
const context = await browser.newContext()
|
|
const page = await context.newPage()
|
|
page.on('pageerror', error => errors.push(error.message))
|
|
|
|
async function json(response, status = 200) {
|
|
assert.equal(response.status(), status, `${response.url()}: ${await response.text()}`)
|
|
return response.json()
|
|
}
|
|
try {
|
|
// Review CR-03: every accepted registration answers with the SAME uniform
|
|
// {ok:true} body — the account id is private until authentication
|
|
// establishes ownership, so it comes from /api/me after login.
|
|
const signup = await json(await context.request.post(`${base}/api/signup`, { data: { email, password, name: 'Browser QA' } }), 201)
|
|
assert.deepEqual(signup, { ok: true })
|
|
await page.goto(`${base}/login`)
|
|
await page.getByPlaceholder('Email', { exact: true }).fill(email)
|
|
await page.getByPlaceholder('Password', { exact: true }).fill(password)
|
|
await page.getByRole('button', { name: 'Sign in with Email', exact: true }).click()
|
|
await page.waitForURL('**/pages')
|
|
await page.getByRole('heading', { name: 'No pages yet', exact: true }).waitFor()
|
|
const me = await json(await context.request.get(`${base}/api/me`))
|
|
accounts.push(me.user.id)
|
|
// Target/cleanup identity preflight (review TEST-03): the account created
|
|
// through BASE_URL must exist in the local compose database that cleanup
|
|
// deletes from. If it does not, the browser target is backed by some other
|
|
// database — abort before creating further data.
|
|
if (!keepData && loopback) {
|
|
assert.match(me.user.id, /^[a-z0-9]+$/i)
|
|
const found = execFileSync('docker', ['compose', 'exec', '-T', 'db', 'psql', '-U', 'superbrain', '-d', 'superbrain', '-Atc',
|
|
`SELECT count(*) FROM "User" WHERE id='${me.user.id}';`], { cwd: repoRoot, stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim()
|
|
if (found !== '1') {
|
|
throw new Error(`preflight failed: QA account ${me.user.id} created through ${base} is not present in the local compose database; target and cleanup environments differ (remove it on the target environment)`)
|
|
}
|
|
console.log('PASS: browser target and cleanup database are the same stack')
|
|
}
|
|
await page.getByRole('button', { name: 'New', exact: true }).first().click()
|
|
const dialog = page.getByRole('dialog')
|
|
await dialog.getByPlaceholder('https://...').fill('https://example.org/browser-qa')
|
|
await dialog.getByPlaceholder('Auto-filled from URL').fill('Browser QA bookmark')
|
|
// Wait for the create to land server-side; navigating earlier cancels the
|
|
// in-flight POST (Go fetches the preview before inserting, so a cancelled
|
|
// request context aborts creation).
|
|
const saved = page.waitForResponse(r => r.url().includes('/api/bookmarks') && r.request().method() === 'POST' && r.status() === 201)
|
|
await dialog.getByRole('button', { name: 'Save Bookmark', exact: true }).click()
|
|
await saved
|
|
await page.goto(`${base}/bookmarks`)
|
|
await page.getByText('Browser QA bookmark', { exact: true }).first().waitFor()
|
|
let bookmarks = await json(await context.request.get(`${base}/api/bookmarks`))
|
|
const bookmark = bookmarks.find(b => b.title === 'Browser QA bookmark')
|
|
assert.ok(bookmark?.id, 'UI-created bookmark was not persisted by Go')
|
|
await page.getByText('Browser QA bookmark', { exact: true }).first().click()
|
|
await page.getByRole('link', { name: 'Download Markdown', exact: true }).waitFor()
|
|
// Optimistic concurrency (review CR-04): the PUT carries the version it edited from.
|
|
const update = await json(await context.request.put(`${base}/api/bookmarks/${bookmark.id}`, { data: { notes: '# Browser verified', isPublic: true, version: bookmark.version } }))
|
|
assert.equal(update.notes, '# Browser verified')
|
|
// Notion-style Quick Find (Cmd/Ctrl+K): open, dismiss, then jump straight
|
|
// to this bookmark's detail sheet through the ?open= deep link.
|
|
await page.keyboard.press('Escape')
|
|
await page.getByRole('link', { name: 'Download Markdown', exact: true }).waitFor({ state: 'hidden' })
|
|
await page.keyboard.press('Control+k')
|
|
const quickFind = page.getByPlaceholder('Search pages, bookmarks, tags, and commands…')
|
|
await quickFind.waitFor()
|
|
await page.keyboard.press('Escape')
|
|
await quickFind.waitFor({ state: 'hidden' })
|
|
await page.keyboard.press('Control+k')
|
|
await quickFind.waitFor()
|
|
await quickFind.fill('Browser QA')
|
|
await page.getByRole('option', { name: /Browser QA bookmark/ }).first().click()
|
|
await page.waitForURL('**/bookmarks?open=*')
|
|
await page.getByRole('link', { name: 'Download Markdown', exact: true }).waitFor()
|
|
console.log('PASS: Quick Find opens with Ctrl+K and deep-links to the bookmark sheet')
|
|
const publicContext = await browser.newContext()
|
|
const publicPage = await publicContext.newPage()
|
|
publicPage.on('pageerror', error => errors.push(error.message))
|
|
await publicPage.goto(`${base}/share/bookmark/${bookmark.id}`)
|
|
await publicPage.getByText('Browser QA bookmark', { exact: true }).first().waitFor()
|
|
// Privacy field assertions (review PRIV-04): the public API response is an
|
|
// allowlist — no owner attribution, no contact/recipient/operational data.
|
|
const publicBody = await json(await publicContext.request.get(`${base}/api/public/bookmarks/${bookmark.id}`))
|
|
assert.equal(publicBody.title, 'Browser QA bookmark')
|
|
assert.equal('# Browser verified', publicBody.notes, 'public link must publish notes (documented behavior)')
|
|
for (const key of ['owner', 'ownerId', 'contact', 'contactId', 'sharedWith', 'imapQuery', 'imapWatchEnabled', 'alertAt', 'alertSent', 'kanbanColumnId', 'kanbanPosition', 'kanbanStatus', 'pageLinks']) {
|
|
assert.equal(key in publicBody, false, `public response must not include ${key}`)
|
|
}
|
|
console.log('PASS: public response matches the documented privacy policy (no owner attribution)')
|
|
await publicContext.close()
|
|
await page.goto(`${base}/kanban`)
|
|
await page.getByRole('heading', { name: 'Kanban Board' }).waitFor()
|
|
// Only explicitly-placed cards appear: a fresh bookmark is NOT auto-populated.
|
|
assert.equal(await page.getByText('Browser QA bookmark', { exact: true }).count(), 0, 'kanban must not auto-populate unplaced bookmarks')
|
|
const columns = await json(await context.request.get(`${base}/api/kanban/columns`))
|
|
assert.equal(columns.length, 4)
|
|
// Place it explicitly; now it appears on the board.
|
|
const placed = await json(await context.request.put(`${base}/api/kanban/cards/${bookmark.id}`, { data: { columnId: columns[0].id, position: 0, version: update.version } }))
|
|
await page.reload()
|
|
await page.getByText('Browser QA bookmark', { exact: true }).waitFor()
|
|
const custom = await json(await context.request.post(`${base}/api/kanban/columns`, { data: { label: 'QA done' } }), 201)
|
|
await json(await context.request.put(`${base}/api/kanban/cards/${bookmark.id}`, { data: { columnId: custom.id, position: 0, version: placed.version } }))
|
|
const moved = await json(await context.request.delete(`${base}/api/kanban/columns/${custom.id}`))
|
|
assert.equal(moved.moved, 1)
|
|
await page.goto(`${base}/pages`)
|
|
await page.getByRole('button', { name: 'New page', exact: true }).click()
|
|
await page.getByRole('textbox', { name: 'Page title' }).waitFor()
|
|
// TipTap contenteditable: drive it with keyboard.insertText (fill() does
|
|
// not work on contenteditable) and watch the workspace save badge.
|
|
const editor = page.locator('[data-page-editor]')
|
|
await editor.click()
|
|
await page.keyboard.insertText('Autosaved markdown from browser QA.')
|
|
await page.getByText('Saved', { exact: true }).waitFor()
|
|
const pages = await json(await context.request.get(`${base}/api/pages`))
|
|
let created = null
|
|
for (const p of pages) {
|
|
const detail = await json(await context.request.get(`${base}/api/pages/${p.id}`))
|
|
if (detail.content.includes('Autosaved markdown from browser QA.')) { created = detail; break }
|
|
}
|
|
assert.ok(created, 'autosaved page content never reached the API')
|
|
// Notion-style slash menu: "/h2" at the start of a line inserts a heading.
|
|
await editor.click()
|
|
await page.keyboard.press('End')
|
|
await page.keyboard.press('Enter')
|
|
await page.keyboard.type('/h2')
|
|
await page.getByRole('option', { name: /Heading 2/ }).click()
|
|
await page.keyboard.type('QA heading')
|
|
await page.getByText('Saved', { exact: true }).waitFor()
|
|
const slashed = await json(await context.request.get(`${base}/api/pages/${created.id}`))
|
|
assert.ok(slashed.content.includes('## QA heading'), `slash command did not insert heading: ${JSON.stringify(slashed.content)}`)
|
|
console.log('PASS: pages autosave and slash commands insert Markdown headings')
|
|
await json(await context.request.patch(`${base}/api/pages/${created.id}`, { data: { addBookmarkId: bookmark.id } }))
|
|
// Product invariant: a URL added to the page (paste) becomes a bookmark.
|
|
// insertText does not fire ProseMirror's paste handler, so dispatch a real
|
|
// ClipboardEvent; arm both network waits before the event.
|
|
const bookmarkPost = page.waitForResponse(r => r.url().includes('/api/bookmarks') && r.request().method() === 'POST')
|
|
const linkPatch = page.waitForResponse(r => r.request().method() === 'PATCH' && r.url().includes('/api/pages/') && Boolean(r.request().postDataJSON()?.addBookmarkId))
|
|
await editor.click()
|
|
await page.keyboard.press('Control+a')
|
|
await page.evaluate(() => {
|
|
const dt = new DataTransfer()
|
|
dt.setData('text/plain', 'https://e2e-url.test/qa-page-link')
|
|
document.querySelector('[data-page-editor]')
|
|
.dispatchEvent(new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true }))
|
|
})
|
|
const created2 = await (await bookmarkPost).json()
|
|
await linkPatch
|
|
const linked = await json(await context.request.get(`${base}/api/pages/${created.id}`))
|
|
assert.ok(created2.url === 'https://e2e-url.test/qa-page-link', 'paste created a bookmark for the wrong URL')
|
|
assert.ok(linked.bookmarks.some(b => b.bookmark.url === 'https://e2e-url.test/qa-page-link'), 'pasted URL did not become a page bookmark')
|
|
const markdown = await context.request.get(`${base}/api/pages/${created.id}/markdown`)
|
|
assert.equal(markdown.status(), 200)
|
|
assert.ok((await markdown.text()).includes('Browser QA bookmark'))
|
|
// Collections (Notion-like upgrades phase 2, validation scenario): an
|
|
// existing bookmark joins a collection without duplication, gets a
|
|
// collection-scoped status, and the same membership is driven from both
|
|
// the table view and a board view.
|
|
await page.goto(`${base}/collections`)
|
|
await page.getByRole('heading', { name: 'Collections', exact: true }).waitFor()
|
|
await page.getByLabel('New collection name').fill('Research')
|
|
await page.getByRole('button', { name: 'Create collection' }).click()
|
|
await page.getByText('Collection created').waitFor()
|
|
await page.getByRole('button', { name: 'Add bookmarks' }).click()
|
|
await page.getByLabel('Search bookmarks').fill('Browser QA')
|
|
await page.getByRole('button', { name: 'Add', exact: true }).first().click()
|
|
await page.keyboard.press('Escape')
|
|
await page.getByText('Browser QA bookmark', { exact: true }).first().waitFor()
|
|
await page.getByRole('button', { name: 'Property' }).click()
|
|
await page.getByLabel('Property name').fill('Status')
|
|
await page.getByRole('button', { name: 'Option', exact: true }).click()
|
|
await page.getByLabel('Option label').first().fill('Backlog')
|
|
await page.getByRole('button', { name: 'Option', exact: true }).click()
|
|
await page.getByLabel('Option label').nth(1).fill('Doing')
|
|
await page.getByRole('button', { name: 'Create property' }).click()
|
|
await page.getByText('Property added').waitFor()
|
|
await page.getByLabel('Status', { exact: true }).first().click()
|
|
await page.getByRole('option', { name: 'Doing' }).click()
|
|
await page.getByRole('button', { name: 'Add view' }).click()
|
|
await page.getByLabel('View name').fill('Board')
|
|
await page.getByLabel('View type').click()
|
|
await page.getByRole('option', { name: 'Board' }).click()
|
|
await page.getByRole('button', { name: 'Create view' }).click()
|
|
await page.getByText('View added').waitFor()
|
|
await page.getByLabel('Group by property').click()
|
|
await page.getByRole('option', { name: 'Status' }).click()
|
|
await page.getByLabel('Move Browser QA bookmark').getByText('Doing').waitFor()
|
|
// Moving the card on the board and reading it back in the table proves both
|
|
// views edit one membership, not copies.
|
|
const boardCard = page.locator('[data-collection-item-id]').filter({ hasText: 'Browser QA bookmark' })
|
|
const backlogColumn = page.locator('[data-board-group]').filter({ hasText: 'Backlog' })
|
|
const movedMembership = page.waitForResponse(r => r.url().includes('/items/') && r.request().method() === 'PATCH' && r.status() === 200)
|
|
await boardCard.locator('[data-drag-handle]').dragTo(backlogColumn)
|
|
await movedMembership
|
|
await page.getByRole('button', { name: 'Table', exact: true }).click()
|
|
await page.getByLabel('Status', { exact: true }).first().getByText('Backlog').waitFor()
|
|
const membership = await json(await context.request.get(`${base}/api/collections`))
|
|
assert.equal(membership[0]._count.items, 1, 'bookmark count after membership add')
|
|
console.log('PASS: collections — membership without duplication, typed properties, table+board over one membership')
|
|
for (const [path, heading] of [['bookmarks', 'All Bookmarks'], ['tags', 'Tags'], ['calendar', 'Calendar'], ['collections', 'Collections'], ['contacts', 'Contacts'], ['settings', 'Settings']]) {
|
|
await page.goto(`${base}/${path}`)
|
|
await page.getByRole('heading', { name: heading, exact: true }).first().waitFor()
|
|
}
|
|
assert.deepEqual(errors, [], 'Browser runtime errors')
|
|
await json(await context.request.delete(`${base}/api/bookmarks/${bookmark.id}`))
|
|
console.log('PASS: browser login, Go-backed bookmark create/edit/delete, public sharing, quick find deep links, kanban, collections, pages/autosave/slash-commands/export, all application screens')
|
|
} catch (error) {
|
|
testFailed = true
|
|
throw error
|
|
} finally {
|
|
await browser.close()
|
|
if (!keepData && accounts.length) {
|
|
// Cleanup failures must not mask the real test error; log them and fail
|
|
// the run only when the tests themselves passed.
|
|
try {
|
|
assert.ok(accounts.every(id => /^[a-z0-9]+$/i.test(id)))
|
|
execFileSync('docker', ['compose', 'exec', '-T', 'db', 'psql', '-U', 'superbrain', '-d', 'superbrain', '-v', 'ON_ERROR_STOP=1', '-c', `DELETE FROM "User" WHERE id IN (${accounts.map(id => `'${id}'`).join(',')});`], { cwd: repoRoot, stdio: 'inherit' })
|
|
} catch (cleanupError) {
|
|
console.error(`QA account cleanup failed (${accounts.join(',')}); delete manually.`, cleanupError.message)
|
|
if (!testFailed) process.exitCode = 1
|
|
}
|
|
}
|
|
}
|