mirror of
https://github.com/mudler/LocalAI.git
synced 2026-11-08 05:23:28 -05:00
* refactor(addons): one name and one verb pair in the add-ons UI The sidebar, the page and the tabs now say Add-ons. The tabs are My add-ons, Find add-ons and Sources. Turn on and Turn off replace Enable, Start, Disable and Stop wherever they label a button, and the state words read On and Off. The subtitle no longer names the owner. Other locales get the new keys; the main labels are translated and the rest carry the English text until a translator refines them. A unit test checks that every locale has the keys of English. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): show what an add-on does on its card and move actions to a menu A card now shows the add-on description, an "Adds a page" line and the number of chat tools when they apply. The pin button and the bare arrows are replaced by one overflow menu with Show in sidebar, Details and Remove. Reordering a pinned add-on stays in the same menu. Remove asks first and runs the typed uninstall action; only administrators see it. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): add a preview pane for the selected add-on Selecting a card, or choosing Details in its menu, opens a pane beside the list. It shows the name and state, the description, what the add-on adds, Turn on or Turn off and Remove, and its version and source. The pane replaces the modal sheet and uses the data the list already has. The source comes from the installed list that the host already serves to administrators. Screenshot slots show only when the host lists images for the add-on; today it lists none, so no slot is drawn. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): clear first-run and empty states for My add-ons With nothing installed, an administrator now sees three add-ons from the sources, each with Install and turn on, and a link to Find add-ons. A search that finds nothing says that no add-on matches and offers to clear the search, instead of saying that nothing is installed. Install and turn on is one action of the user: it installs, then turns the add-on on, with a separate operation identity for each step and the progress or the reason for a failure shown on the card. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): one button and folded details on Find add-ons entries Each entry shows its description, an "Adds a page" label when the library entry declares a main page, and one button: Install and turn on. An add-on that is installed but off offers Turn on. Details is folded into the entry and shows the trust and build facts the entry already carries, so the separate details sheet is gone. A backend keeps a plain Install, because a backend has no on or off. The library entry carries no tool count, so the entry cannot say how many chat tools an add-on adds. That label appears on My add-ons, where the list knows it. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): install and turn on in one dialog with inline progress Install and turn on now asks once. The dialog then stays open and shows two steps, the install and the turn on, and ends on the result or on the reason a step failed with a way to try again. A failed turn on keeps the install and the retry only turns the add-on on. Each step is its own action with its own operation identity, so an unknown outcome still blocks further actions on the add-on until it is read or dismissed. The first-run cards use the same dialog. The two-step flow is a plain function with unit tests. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactor(addons): fold the Installed tab into My add-ons The page now has three tabs: My add-ons, Find add-ons and Sources. What the Installed tab showed is in the preview pane of each add-on, under More details for administrators: health, trust, compatibility, storage, data recovery and updates, with Check for updates and Upgrade. Remove and Turn on or Turn off are on the card and in the pane. An old ?tab=installed address opens My add-ons, and the management link ?manage=ID opens the details of that add-on. A card shows an update mark when the host reports one. Closing the pane returns focus to its card. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * docs(addons): describe the new add-ons page labels Update the add-ons feature page and the pages that point at it: the sidebar item and the page are called Add-ons, the tabs are My add-ons, Find add-ons and Sources, Turn on and Turn off replace Start and Stop, the card menu replaces the pin control, and the preview pane holds what the Installed tab showed. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): say what is wrong on the page of an add-on that cannot open The page of an add-on that cannot open now depends on the add-on. One that is installed but off says "<name> is off" and offers Turn on to an administrator. One that is not installed says so and sends an administrator to Find add-ons. One that failed shows the reason and a link to its details. A reader gets a line that says who can fix it, and no button. The page title is the name of the add-on, with a capital first letter when the host lists no title, and no longer the bare identifier. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(chat): put the add-on tools control next to MCP and say what off means The add-on tools control moves from the chat header to the composer, right after the MCP control, because both decide what the model may call in this chat. Its menu starts with one line: an add-on that is off here does nothing in this chat. Only add-ons that ship tools appear in it, as before. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore(addons): clear lint warnings of the new components Add the lint header the add-on components use for JSX-only imports, drop an unneeded directive, stop exporting a helper from a component file and extract the dependencies of an effect. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * test(addons): update the backend library specs for the folded entry details A backend says its kind on the entry, an add-on says it under Details, Details is a fold of the entry and an installed backend has no Install button. Assisted-by: Claude:claude-sonnet-5-5 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
263 lines
14 KiB
JavaScript
263 lines
14 KiB
JavaScript
import { test, expect, request as playwrightRequest } from '@playwright/test'
|
|
import fs from 'node:fs'
|
|
import { randomUUID } from 'node:crypto'
|
|
|
|
// Data recovery of the Tables add-on, seen from the administrator's browser.
|
|
// One UI test server runs the real add-on owner, the real Tables executable
|
|
// and the real built UI package with named accounts and real sessions. The
|
|
// page asks, the owner decides: nothing here mocks a route, except the one
|
|
// banner screenshot that is marked as such. The specs change the owner's
|
|
// state and run in order on one worker.
|
|
|
|
const creds = JSON.parse(fs.readFileSync(process.env.ADDONS_FIXTURE, 'utf8'))
|
|
const BASE = process.env.ADDONS_UI_URL
|
|
const shots = process.env.ADDONS_SHOTS
|
|
const MANAGE = '/app/addons?manage=tables'
|
|
|
|
async function shoot(page, name, target = 'recovery-panel') {
|
|
if (!shots) return
|
|
// The panel is far down the sheet: bring what the shot is about into view.
|
|
const el = page.getByTestId(target).first()
|
|
if (await el.count()) await el.scrollIntoViewIfNeeded()
|
|
await page.emulateMedia({ reducedMotion: 'reduce' })
|
|
await page.waitForTimeout(350)
|
|
await page.screenshot({ path: `${shots}/${name}.png`, fullPage: false })
|
|
}
|
|
|
|
async function browserAs(browser, who, extra = {}) {
|
|
const context = await browser.newContext({ baseURL: BASE, ...extra })
|
|
await context.addCookies([{ name: 'session', value: creds.users[who].session, url: BASE }])
|
|
const page = await context.newPage()
|
|
return { context, page }
|
|
}
|
|
|
|
async function apiAs(who) {
|
|
return playwrightRequest.newContext({ baseURL: BASE, extraHTTPHeaders: { Authorization: `Bearer ${creds.users[who].token}` } })
|
|
}
|
|
|
|
// A fetch made by the page itself: a real same-origin request with the session
|
|
// cookie and the browser's own Sec-Fetch metadata.
|
|
async function pageFetch(page, path, { method = 'GET', body, headers = {} } = {}) {
|
|
return page.evaluate(async ({ path, method, body, headers }) => {
|
|
const r = await fetch(path, {
|
|
method, credentials: 'same-origin',
|
|
headers: { Accept: 'application/json', ...(body === undefined ? {} : { 'Content-Type': 'application/json' }), ...headers },
|
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
})
|
|
let json = null
|
|
try { json = await r.json() } catch { json = null }
|
|
return { status: r.status, json }
|
|
}, { path, method, body, headers })
|
|
}
|
|
|
|
async function generation(api) {
|
|
const r = await api.get('/api/addons/apps')
|
|
expect(r.status()).toBe(200)
|
|
return (await r.json()).apps.find(a => a.id === 'tables').generation
|
|
}
|
|
|
|
async function listIds(api) {
|
|
const r = await api.get('/api/addons/resources?addonId=tables')
|
|
expect(r.status()).toBe(200)
|
|
return (await r.json()).resources.map(x => x.id)
|
|
}
|
|
|
|
async function openManage(page) {
|
|
await page.goto(MANAGE)
|
|
await expect(page.getByTestId('addon-manage')).toBeVisible({ timeout: 25_000 })
|
|
await expect(page.getByTestId('recovery-panel')).toBeVisible({ timeout: 25_000 })
|
|
}
|
|
|
|
// The pane's own Turn on and Turn off buttons: the real lifecycle.
|
|
async function setEnabled(page, enabled) {
|
|
const sheet = page.getByTestId('addon-detail')
|
|
await sheet.getByRole('button', { name: enabled ? 'Turn on' : 'Turn off' }).click()
|
|
await expect(sheet.getByRole('button', { name: enabled ? 'Turn off' : 'Turn on' })).toBeVisible({ timeout: 30_000 })
|
|
}
|
|
|
|
test.describe.configure({ mode: 'serial' })
|
|
|
|
const state = {}
|
|
|
|
test.describe('Add-on data recovery through the real owner', () => {
|
|
test('recovery: an administrator backs up from the manage sheet and the backup is listed as verified', async ({ browser }) => {
|
|
const member = await browserAs(browser, 'member')
|
|
await member.page.goto('/app/addons')
|
|
const api = await apiAs('admin')
|
|
const gen = await generation(api)
|
|
const op = `op-${randomUUID()}`
|
|
const made = await pageFetch(member.page, '/api/addons/resources', { method: 'POST', body: { addonId: 'tables', operationId: op, generation: gen, arguments: { name: 'Ledger' } }, headers: { 'X-LocalAI-Confirm': op } })
|
|
expect(made.status, JSON.stringify(made.json)).toBe(200)
|
|
state.db = made.json.id
|
|
const shared = await pageFetch(member.page, `/api/addons/resources/${state.db}/grants/${creds.users.editor.id}`, { method: 'PUT', body: { role: 'editor', operationId: `op-${randomUUID()}` }, headers: { 'X-LocalAI-Confirm': state.db } })
|
|
expect(shared.status, JSON.stringify(shared.json)).toBe(200)
|
|
state.memberPage = member.page
|
|
|
|
const admin = await browserAs(browser, 'admin')
|
|
await openManage(admin.page)
|
|
await expect(admin.page.getByTestId('recovery-empty')).toBeVisible()
|
|
await shoot(admin.page, 'recovery-empty-1280')
|
|
await admin.page.getByTestId('recovery-backup').click()
|
|
const item = admin.page.getByTestId('recovery-list').locator('li').first()
|
|
await expect(item).toBeVisible({ timeout: 60_000 })
|
|
await expect(item).toContainText('Verified')
|
|
await expect(item).toContainText('Made by you')
|
|
await expect(admin.page.getByTestId('recovery-notice')).toContainText('was made and verified')
|
|
state.backup = await item.getAttribute('data-backup')
|
|
expect(state.backup).toMatch(/^b[0-9a-z-]+$/)
|
|
// The add-on is running again and its database still answers.
|
|
expect(await listIds(await apiAs('member'))).toContain(state.db)
|
|
await shoot(admin.page, 'recovery-backup-1280')
|
|
await admin.context.close()
|
|
})
|
|
|
|
test('recovery: a person and a key cannot back up, restore or purge, and only the owner session of an administrator can', async ({ browser }) => {
|
|
const member = await browserAs(browser, 'member')
|
|
await member.page.goto('/app/addons')
|
|
const op = `op-${randomUUID()}`
|
|
for (const [method, path, body] of [
|
|
['GET', '/api/addons/tables/recovery'],
|
|
['POST', '/api/addons/tables/recovery/backup', { operationId: op }],
|
|
['POST', '/api/addons/tables/recovery/restore', { operationId: op, backupId: state.backup, confirm: 'tables' }],
|
|
['POST', '/api/addons/tables/purge', { operationId: op, scope: { data: true }, confirm: 'tables' }],
|
|
]) {
|
|
const r = await pageFetch(member.page, path, { method, body, headers: { 'X-LocalAI-Confirm': op } })
|
|
expect(r.status, `${method} ${path}`).toBe(403)
|
|
}
|
|
// An administrator's key is not the administrator's own browser session.
|
|
const key = await apiAs('admin')
|
|
for (const [path, body] of [
|
|
['/api/addons/tables/recovery/backup', { operationId: op }],
|
|
['/api/addons/tables/recovery/restore', { operationId: op, backupId: state.backup, confirm: 'tables' }],
|
|
['/api/addons/tables/purge', { operationId: op, scope: { data: true }, confirm: 'tables' }],
|
|
]) {
|
|
const r = await key.post(path, { data: body, headers: { 'X-LocalAI-Confirm': op } })
|
|
expect(r.status(), path).toBe(403)
|
|
}
|
|
// The read is for administrators, from a key too.
|
|
expect((await key.get('/api/addons/tables/recovery')).status()).toBe(200)
|
|
await member.context.close()
|
|
})
|
|
|
|
test('recovery: the restore dialog warns, asks for the typed ID and a restore does not give back a revoked share', async ({ browser }) => {
|
|
const admin = await browserAs(browser, 'admin')
|
|
const memberApi = await apiAs('member')
|
|
// After the backup the owner of the database takes the editor's access away.
|
|
const rv = await pageFetch(state.memberPage, `/api/addons/resources/${state.db}/grants/${creds.users.editor.id}`, { method: 'DELETE', headers: { 'X-LocalAI-Confirm': state.db } })
|
|
expect(rv.status, JSON.stringify(rv.json)).toBe(200)
|
|
expect(await listIds(await apiAs('editor'))).not.toContain(state.db)
|
|
|
|
await openManage(admin.page)
|
|
// A running add-on cannot be restored: the dialog says so.
|
|
await admin.page.getByTestId('recovery-restore').first().click()
|
|
const dialog = admin.page.getByTestId('recovery-restore-dialog')
|
|
await expect(dialog).toBeVisible()
|
|
await expect(dialog).toContainText('Changes made after the backup are lost')
|
|
await expect(dialog).toContainText('nobody gets back access that was taken away')
|
|
await expect(dialog).toContainText('Turn the add-on off first')
|
|
await shoot(admin.page, 'recovery-restore-running-1280', 'recovery-restore-dialog')
|
|
// Escape closes the dialog and gives the focus back.
|
|
await admin.page.keyboard.press('Escape')
|
|
await expect(dialog).toBeHidden()
|
|
await setEnabled(admin.page, false)
|
|
|
|
await admin.page.getByTestId('recovery-restore').first().click()
|
|
await expect(dialog).toBeVisible()
|
|
const confirm = admin.page.getByRole('alertdialog').getByRole('button', { name: 'Restore' })
|
|
await expect(confirm).toBeDisabled()
|
|
const typed = dialog.getByTestId('recovery-confirm-input')
|
|
await expect(typed).toBeFocused()
|
|
await typed.fill('Tables')
|
|
await expect(confirm).toBeDisabled()
|
|
await typed.fill('tables')
|
|
await expect(confirm).toBeEnabled()
|
|
await shoot(admin.page, 'recovery-restore-dialog-1280', 'recovery-restore-dialog')
|
|
await confirm.click()
|
|
await expect(dialog).toBeHidden()
|
|
const notice = admin.page.getByTestId('recovery-notice')
|
|
await expect(notice).toContainText('The backup was restored', { timeout: 60_000 })
|
|
const warnings = admin.page.getByTestId('recovery-warnings')
|
|
await expect(warnings).toContainText('Changes made after that time are not in it')
|
|
await expect(warnings).toContainText('kept as a recovery copy until you purge it')
|
|
await expect(admin.page.getByTestId('recovery-last-restore')).toBeVisible()
|
|
await shoot(admin.page, 'recovery-restored-1280', 'recovery-last-restore')
|
|
|
|
await setEnabled(admin.page, true)
|
|
// The database is back for its owner. The editor, who lost access after
|
|
// the backup, is still out: the restore never resurrects a grant.
|
|
expect(await listIds(memberApi)).toContain(state.db)
|
|
expect(await listIds(await apiAs('editor'))).not.toContain(state.db)
|
|
await admin.context.close()
|
|
})
|
|
|
|
test('recovery: a second backup, the sole recovery copy is kept and the keyboard reaches every action', async ({ browser }) => {
|
|
const admin = await browserAs(browser, 'admin', { viewport: { width: 400, height: 800 } })
|
|
await openManage(admin.page)
|
|
// Keyboard: the backup button is reachable by Tab and runs on Enter.
|
|
const backup = admin.page.getByTestId('recovery-backup')
|
|
await backup.focus()
|
|
await expect(backup).toBeFocused()
|
|
await admin.page.keyboard.press('Enter')
|
|
await expect(admin.page.getByTestId('recovery-list').locator('li')).toHaveCount(2, { timeout: 60_000 })
|
|
// Narrow layout: nothing overflows the sheet.
|
|
const overflow = await admin.page.evaluate(() => {
|
|
const sheet = document.querySelector('[data-testid="addon-manage"]')
|
|
return sheet ? sheet.scrollWidth - sheet.clientWidth : -1
|
|
})
|
|
expect(overflow).toBeLessThanOrEqual(0)
|
|
await shoot(admin.page, 'recovery-list-400')
|
|
await admin.context.close()
|
|
})
|
|
|
|
test('recovery: the page shows a needs-recovery banner with restore and purge as the actions (status mocked)', async ({ browser }) => {
|
|
const admin = await browserAs(browser, 'admin', { viewport: { width: 400, height: 800 } })
|
|
const real = await (await apiAs('admin')).get('/api/addons/tables/recovery')
|
|
const body = await real.json()
|
|
await admin.page.route('**/api/addons/tables/recovery', async route => {
|
|
if (route.request().method() !== 'GET') return route.continue()
|
|
await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({
|
|
...body, state: 'needs-recovery', recoveryBackup: body.backups[0].id,
|
|
reason: 'the migration to a new data format did not complete',
|
|
}) })
|
|
})
|
|
await openManage(admin.page)
|
|
const banner = admin.page.getByTestId('recovery-banner')
|
|
await expect(banner).toBeVisible()
|
|
await expect(banner).toContainText('needs recovery')
|
|
await expect(banner).toContainText('Restore the verified recovery copy below, or purge the data')
|
|
await expect(admin.page.getByTestId('recovery-restore').first()).toBeEnabled()
|
|
await expect(admin.page.getByTestId('recovery-purge')).toBeEnabled()
|
|
await shoot(admin.page, 'recovery-needs-recovery-400', 'recovery-banner')
|
|
await admin.context.close()
|
|
})
|
|
|
|
test('recovery: a purge needs a scope, the typed ID and a stopped add-on, and removes the data and its shares', async ({ browser }) => {
|
|
const admin = await browserAs(browser, 'admin')
|
|
await openManage(admin.page)
|
|
await admin.page.getByTestId('recovery-purge').click()
|
|
const dialog = admin.page.getByTestId('recovery-purge-dialog')
|
|
await expect(dialog).toBeVisible()
|
|
await expect(dialog).toContainText('Turn the add-on off first')
|
|
await admin.page.keyboard.press('Escape')
|
|
await setEnabled(admin.page, false)
|
|
await admin.page.getByTestId('recovery-purge').click()
|
|
const confirm = admin.page.getByRole('alertdialog').getByRole('button', { name: 'Purge…' })
|
|
await expect(confirm).toBeDisabled()
|
|
await dialog.getByTestId('recovery-confirm-input').fill('tables')
|
|
await expect(confirm).toBeEnabled()
|
|
// An empty scope cannot be confirmed.
|
|
await dialog.getByTestId('scope-data').uncheck()
|
|
await expect(confirm).toBeDisabled()
|
|
await expect(dialog).toContainText('Select what to remove')
|
|
await dialog.getByTestId('scope-data').check()
|
|
await shoot(admin.page, 'recovery-purge-dialog-1280', 'recovery-purge-dialog')
|
|
await confirm.click()
|
|
await expect(admin.page.getByTestId('recovery-notice')).toContainText('The retained data was purged', { timeout: 60_000 })
|
|
await setEnabled(admin.page, true)
|
|
expect(await listIds(await apiAs('member'))).not.toContain(state.db)
|
|
// The backups were not in the scope.
|
|
await expect(admin.page.getByTestId('recovery-list').locator('li')).toHaveCount(2)
|
|
await admin.context.close()
|
|
})
|
|
})
|