Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

3.5 KB
Raw Blame
import { expect, test, type Page } from '@playwright/test'
import { appModules, type AppWindow } from './support/ui'

async function signIn(page: Page, id: string) {
  await appModules(page, ['/src/stores/cloudAuthStore.ts'])
  await page.evaluate(owner => {
    const { useCloudAuthStore } = (window as unknown as AppWindow).__APP__['/src/stores/cloudAuthStore.ts'] as typeof import('../src/stores/cloudAuthStore')
    useCloudAuthStore.getState().setSignedIn({ id: owner }, { licenseActive: false, tier: null, access: true, quota: null })
  }, id)
}
async function add(page: Page, title: string) {
  await page.getByRole('button', { name: 'Add Memory', exact: true }).click()
  await page.getByPlaceholder('What should I remember?').fill(title)
  await page.getByPlaceholder('Details… (required)').fill(`Private ${title}`)
  await page.getByRole('button', { name: 'Save', exact: true }).click()
}
test('actual collection controls isolate two owners and retain local data through reload', async ({ page }, testInfo) => {
  await page.goto('/e2e/memory-sensitive-proof.html')
  await add(page, 'Local original')
  await signIn(page, 'owner-a')
  await page.getByRole('button', { name: 'Use account memories', exact: true }).click()
  await expect(page.getByText('Local original', { exact: true })).toHaveCount(0)
  await add(page, 'Owner A original')
  await signIn(page, 'owner-b')
  await expect(page.getByText('Local original', { exact: true })).toBeVisible()
  await page.getByRole('button', { name: 'Use account memories', exact: true }).click()
  await expect(page.getByText('Owner A original', { exact: true })).toHaveCount(0)
  await add(page, 'Owner B original')
  await signIn(page, 'owner-a')
  await page.getByRole('button', { name: 'Use account memories', exact: true }).click()
  await expect(page.getByText('Owner A original', { exact: true })).toBeVisible()
  await expect(page.getByText('Owner B original', { exact: true })).toHaveCount(0)
  await page.getByRole('button', { name: 'Preview AI memory context' }).click()
  await expect(page.locator('#result')).toContainText('Owner A original')
  await expect(page.locator('#result')).not.toContainText('Owner B original')
  await page.getByRole('button', { name: 'Use local memories', exact: true }).click()
  await expect(page.getByText('Local original', { exact: true })).toBeVisible()
  await appModules(page, ['/src/lib/idbStorage.ts'])
  await expect.poll(() => page.evaluate(async () => {
    const { idbStorage } = (window as unknown as AppWindow).__APP__['/src/lib/idbStorage.ts'] as typeof import('../src/lib/idbStorage')
    const raw = await idbStorage.getItem('locally-uncensored-memory')
    return raw?.includes('Owner A original') && raw.includes('Owner B original') && raw.includes('Local original')
  })).toBe(true)
  await page.reload()
  await expect(page.getByText('Local original', { exact: true })).toBeVisible()
  await expect(page.getByText('Owner A original', { exact: true })).toHaveCount(0)
  await signIn(page, 'owner-a')
  await page.getByRole('button', { name: 'Use account memories', exact: true }).click()
  await expect(page.getByText('Owner A original', { exact: true })).toBeVisible()
  await signIn(page, 'owner-b')
  await page.getByRole('button', { name: 'Use account memories', exact: true }).click()
  await expect(page.getByText('Owner B original', { exact: true })).toBeVisible()
  await expect(page.getByText('Owner A original', { exact: true })).toHaveCount(0)
  await page.setViewportSize({ width: 390, height: 844 })
  await page.screenshot({ path: testInfo.outputPath('memory-collections.png'), fullPage: true })
})