Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions website/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export default [
// 'error', not 'warn': like the native-<select> gate above this is a gate
// on a set that only shrinks, so it stays out of the --max-warnings budget
// where a real regression would be indistinguishable from unrelated noise.
// The 32 modules that still call these globals are exempted by name in the
// The modules that still call these globals are exempted by name in the
// allowlist block below (see issue #15662); every other renderer file is
// refused a new call. Electron main-process dialogs live outside src/ and
// are untouched. Tests drive these globals through the harness and are
Expand Down Expand Up @@ -220,7 +220,7 @@ export default [
// Allowlist for no-restricted-globals / no-restricted-properties: the
// renderer modules that still call a browser-native confirm/alert/prompt
// today (issue #15662). The gate above is 'error' for every OTHER renderer
// file, so a NEW native dialog anywhere else is refused; these 32 are the
// file, so a NEW native dialog anywhere else is refused; these are the
// standing inventory, migrated to useConfirm() / in-app surfaces in later
// PRs. This list only SHRINKS: delete a path the moment its last native
// dialog is gone, never add one. Keep it sorted.
Expand Down Expand Up @@ -252,10 +252,7 @@ export default [
'src/pages/overview/AgentTemplatesTab.tsx',
'src/pages/overview/KiroCrewCfgTab.tsx',
'src/pages/overview/MemoryTab.tsx',
'src/pages/overview/PortabilityTab.tsx',
'src/pages/overview/PromptsTab.tsx',
'src/pages/overview/SkillsTab.tsx',
'src/pages/overview/SteeringTab.tsx',
'src/utils/popoutController.ts',
],
rules: {
Expand Down
20 changes: 11 additions & 9 deletions website/integration/SkillsTab.integration.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,12 @@ vi.mock('framer-motion', async () => {
}
})

// Mock window.confirm for delete operations
const mockConfirm = vi.fn()
Object.defineProperty(window, 'confirm', {
writable: true,
value: mockConfirm,
})

/** The skills list is a master-detail layout: a list of skill rows on the
* left, a directory browser + edit affordances on the right. The first
* skill is auto-selected on load. */
describe('SkillsTab Integration Tests', () => {
beforeEach(() => {
vi.clearAllMocks()
mockConfirm.mockReturnValue(true)
})

// ── Loading & Display ──────────────────────────────────────────────
Expand Down Expand Up @@ -199,6 +191,11 @@ describe('SkillsTab Integration Tests', () => {
// ── Delete Skill ───────────────────────────────────────────────────

it('deletes a skill with confirmation', async () => {
const deleted = vi.fn()
server.use(http.delete('/api/skills/:name', ({ params }) => {
deleted(params.name)
return HttpResponse.json({ ok: true })
}))
const user = userEvent.setup()
renderWithProviders(<SkillsTab />)

Expand All @@ -209,7 +206,12 @@ describe('SkillsTab Integration Tests', () => {
const delBtn = await screen.findByRole('button', { name: /delete/i }, { timeout: 3000 })
await user.click(delBtn)

expect(mockConfirm).toHaveBeenCalledWith(expect.stringContaining('code-search'))
const dialog = await screen.findByRole('dialog')
expect(dialog).toHaveTextContent('code-search')
expect(deleted).not.toHaveBeenCalled()
await user.click(within(dialog).getByRole('button', { name: 'Delete' }))
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
await waitFor(() => expect(deleted).toHaveBeenCalledWith('code-search'))
})

// ── Create Skill ───────────────────────────────────────────────────
Expand Down
72 changes: 71 additions & 1 deletion website/src/pages/overview/PortabilityTab.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'

import PortabilityTab, { IMPORT_RESULT_KEY, chatImportLines, importedItemCount, keptSettingsFiles, refusalText, settingsFileLabel, refusedItems, unbundledTemplates } from './PortabilityTab'
import { __resetUiPrefsSyncForTests, resumeUiPrefsSync } from '../../lib/uiPrefs'
import { i18nT } from '../../i18n/t'
import { confirmAction } from '../../test/confirmAction'

// Spied, not replaced: the tab must hand the sync back exactly when it does not
// reload, and the real pause/adopt behaviour still runs underneath.
Expand Down Expand Up @@ -528,3 +530,71 @@ describe('PortabilityTab chat history', () => {
expect(line.textContent).toBe('Chats added: 2. Already on this install: 1.')
})
})

describe('PortabilityTab replace-import confirmation', () => {
afterEach(() => {
cleanup()
vi.unstubAllGlobals()
__resetUiPrefsSyncForTests()
})

async function askToReplace() {
const fetchMock = vi.fn(async (url: string) => new Response(JSON.stringify(
url.includes('preview')
? { ok: true, manifest: { version: 1, created_at: 't', hostname: 'h', user: 'u', contents: {} } }
: { ok: true, summary: { items: ['full replace'] } },
), { status: 200 }))
vi.stubGlobal('fetch', fetchMock)
const view = render(<PortabilityTab />)
const input = screen.getByLabelText(/choose import file/i)
const file = new File(['PK'], 'original.zip')
fireEvent.change(input, { target: { files: [file] } })
const importButton = screen.getByRole('button', { name: /^import$/i })
await waitFor(() => expect(importButton).toBeEnabled())
fireEvent.keyDown(screen.getByRole('combobox', { name: 'Mode' }), { key: 'ArrowDown' })
fireEvent.click(await screen.findByRole('option', { name: 'Replace', exact: true }))
fireEvent.click(importButton)
const dialog = await screen.findByRole('dialog')
expect(dialog).toHaveAccessibleName('Import')
const body = within(dialog).getByText(i18nT('pages.overview.portabilityTab.replace_mode_will_overwrite_existing_data_contin'), { selector: 'p' })
expect(body).toHaveStyle({ overflowWrap: 'anywhere' })
return { fetchMock, dialog, input, file, view }
}

it('does not import after cancellation', async () => {
const { fetchMock } = await askToReplace()
await confirmAction('Cancel')
expect(fetchMock.mock.calls.some(([url]) => url.includes('/import'))).toBe(false)
})

it('imports the original file after the chosen file changes during confirmation', async () => {
const { fetchMock, input, file } = await askToReplace()
fireEvent.change(input, { target: { files: [new File(['NEW'], 'replacement.zip')] } })
await waitFor(() => expect(fetchMock.mock.calls.filter(([url]) => url.includes('/preview'))).toHaveLength(2))
await confirmAction('Import')
await screen.findByText(/Import complete/)
const request = fetchMock.mock.calls.find(([url]) => url.includes('/import'))
expect(request?.[0]).toBe('/api/portability/import?mode=replace')
const options = (request as unknown as [string, RequestInit])[1]
expect((options.body as FormData).get('file')).toBe(file)
})

it('imports with the mode and memory selection captured before confirmation', async () => {
const { fetchMock } = await askToReplace()
fireEvent.keyDown(screen.getByRole('combobox', { name: 'Mode' }), { key: 'ArrowDown' })
fireEvent.click(await screen.findByRole('option', { name: 'Merge', exact: true }))
const memoryOnly = screen.getByRole('checkbox', { name: i18nT('pages.overview.portabilityTab.import_memory_only') })
await waitFor(() => expect(memoryOnly).toBeEnabled())
fireEvent.click(memoryOnly)
expect(memoryOnly).toBeChecked()
await confirmAction('Import')
await screen.findByText(/Import complete/)
expect(fetchMock.mock.calls.find(([url]) => url.includes('/import'))?.[0]).toBe('/api/portability/import?mode=replace')
})

it('cancels a pending replace import when its owner unmounts', async () => {
const { fetchMock, view } = await askToReplace()
view.unmount()
expect(fetchMock.mock.calls.some(([url]) => url.includes('/import'))).toBe(false)
})
})
13 changes: 10 additions & 3 deletions website/src/pages/overview/PortabilityTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export default function PortabilityTab() {
const [importMemoryOnly, setImportMemoryOnly] = useState(false)
const [chatLines, setChatLines] = useState<string[]>(carried?.chats ?? [])
const fileRef = useRef<HTMLInputElement>(null)
const { confirm: confirmShare, confirmDialog } = useConfirm()
const { confirm, confirmDialog } = useConfirm()
// A memory bundle carries nothing else, so it only ever imports with Merge.
const previewMemoryOnly = isMemoryOnlyManifest(preview)
const memoryImport = importMemoryOnly || previewMemoryOnly
Expand All @@ -332,7 +332,7 @@ export default function PortabilityTab() {
// A memory-only export exists to be handed to someone else, and nothing in it
// is redacted: the user sees what it holds and says yes before it is built.
if (memoryOnly) {
const ok = await confirmShare({
const ok = await confirm({
title: i18nT('pages.overview.portabilityTab.share_memory_title'),
body: (
<span data-testid="portability-share-memory-body">
Expand Down Expand Up @@ -417,7 +417,14 @@ export default function PortabilityTab() {
const handleImport = async () => {
const file = fileRef.current?.files?.[0]
if (!file) return
if (effectiveMode === 'replace' && !confirm(i18nT('pages.overview.portabilityTab.replace_mode_will_overwrite_existing_data_contin'))) return
if (effectiveMode === 'replace') {
const ok = await confirm({
title: i18nT('pages.overview.portabilityTab.import'),
body: <p className="m-0" style={{ overflowWrap: 'anywhere' }}>{i18nT('pages.overview.portabilityTab.replace_mode_will_overwrite_existing_data_contin')}</p>,
confirmLabel: i18nT('pages.overview.portabilityTab.import'),
})
if (!ok) return
}

setImportStatus({ type: 'loading', msg: i18nT('pages.overview.portabilityTab.importing') })
setImportWarnings([])
Expand Down
Loading
Loading