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.

11.3 KB
Raw Blame
/**
 * The rules of the store guard, held against examples. The guard that
 * renders every page (e2e/mobile/store-waechter.mobile.ts) and the one that
 * reads every text (store-woerter.test.ts) both judge with these rules, so a
 * rule that finds nothing would make both of them green for nothing.
 */
import { readFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { CONTACT_PLACE, FULL_NAME, FULL_NAME_SPELLINGS, LEGAL_LINKS, PLAY_SENTENCE, SUPPORT_EMAIL, linkAllowed, storeFindings } from '../../../e2e/mobile/store-rules'
import { LEGAL_LINKS as APP_LEGAL_LINKS, SUPPORT_EMAIL as APP_SUPPORT_EMAIL } from '../policy/links'
import { POLICY } from '../strings/policy'
import { UNFILTERED_SPELLINGS } from '../policy/unfiltered-names'

const rulesHit = (text: string, preset: 'appstore' | 'play', picker = false) => storeFindings(text, preset, { picker }).map((f) => f.split(':')[0])

describe('the rules of the store guard', () => {
  it('know the same sentence, address and links as the app', () => {
    expect(PLAY_SENTENCE).toBe(POLICY.plansOnWebsite)
    expect(SUPPORT_EMAIL).toBe(APP_SUPPORT_EMAIL)
    expect([...LEGAL_LINKS].sort()).toEqual(Object.values(APP_LEGAL_LINKS).sort())
  })

  it('find every word of the list in both presets', () => {
    const samples: Array<[string, string]> = [
      ['Choose a plan to go on.', 'plan'],
      ['Upgrade to send more.', 'upgrade'],
      ['Buy more time.', 'buy'],
      ['Subscribe now.', 'subscribe'],
      ['Your subscription ended.', 'subscribe'],
      ['See pricing.', 'pricing'],
      ['Price of this answer', 'price'],
      ['Open lu-labs.ai to go on.', 'lu-labs.ai'],
      ['Uncensored chat on your phone.', 'uncensored'],
      ['NSFW allowed.', 'nsfw'],
      ['Add credits to go on.', 'credits as something to get'],
      ['Your credits renew on the first.', 'credits as something to get'],
    ]
    for (const [text, rule] of samples) {
      expect(rulesHit(text, 'appstore'), text).toContain(rule)
      expect(rulesHit(text, 'play'), text).toContain(rule)
    }
  })

  it('appstore also finds the hub, the technical word, the website and the promise, wherever they stand', () => {
    expect(rulesHit('View on Hugging Face', 'appstore')).toContain('hugging face')
    expect(rulesHit('huggingface.co/some/model', 'appstore')).toContain('hugging face')
    expect(rulesHit('Abliterated', 'appstore', true)).toContain('abliterated')
    expect(rulesHit('No refusals', 'appstore', true)).toContain('no refusals')
    expect(rulesHit('No Filter', 'appstore', true)).toContain('no filter')
    expect(rulesHit('Unfiltered answers.', 'appstore')).toContain('unfiltered')
    expect(rulesHit('No Filter', 'appstore')).toContain('no filter')
    expect(rulesHit('Manage it on the website.', 'appstore')).toContain('website')
  })

  it('find the long name of the product in every spelling, in both presets', () => {
    const spellings = ['Locally Uncensored', 'LocallyUncensored', 'locally uncensored', 'locally-uncensored', 'locallyuncensored', 'locally_uncensored', 'LOCALLY UNCENSORED', 'Generated by Locally Uncensored.', 'locally-uncensored-chats-3.json', 'LocallyUncensored/2.0', 'github.com/purpledoubled/locally-uncensored', 'com.purpledoubled.locallyuncensored']
    for (const text of spellings) {
      expect(FULL_NAME_SPELLINGS.test(text), text).toBe(true)
      for (const preset of ['appstore', 'play'] as const) expect(rulesHit(text, preset), `${preset}: ${text}`).toContain('product name')
    }
    // The short name is the name.
    for (const preset of ['appstore', 'play'] as const) expect(storeFindings('LU could not start. Welcome to LU.', preset)).toEqual([])
  })

  it('find the words of buying that round 15 added, and leave the balance and what an action uses alone', () => {
    const samples: Array<[string, string]> = [
      ['Get more credits today.', 'get more'],
      ['Go Premium.', 'premium'],
      ['Start your free trial.', 'premium'],
      ['Only $9 to go on.', 'money'],
      ['9.99 EUR', 'money'],
      ['Chat with the monthly credit budget.', 'per month'],
      ['Credits for each month.', 'per month'],
      ['A failed run is refunded.', 'offer'],
      ['Redeem a code.', 'offer'],
      ['Nothing was charged.', 'charge'],
      ['Until your renewal date.', 'renewal'],
    ]
    for (const [text, rule] of samples) for (const preset of ['appstore', 'play'] as const) expect(rulesHit(text, preset), `${preset}: ${text}`).toContain(rule)
    // What an App Store build may say (Apple 3.1.3(f)): how many credits the account has, what an action uses,
    // and a plain sentence when none are left. No way to more of them.
    const allowed = ['1,240 credits left this period.', 'This run uses 12 credits.', 'Credits for this answer', 'This account has no credits left.', 'Not enough credits', 'You have 40 credits', 'No credits were used.', 'This model runs on this phone. Answers use no credits.']
    for (const text of allowed) for (const preset of ['appstore', 'play'] as const) expect(storeFindings(text, preset), `${preset}: ${text}`).toEqual([])
  })

  it('find the routed id of a model, which a person must never read', () => {
    for (const preset of ['appstore', 'play'] as const) {
      expect(rulesHit('Model: openai::Qwen3.5-0.8B-Q4_K_M', preset)).toContain('raw model id')
      expect(rulesHit('lu-cloud::e2e-lab/Atlas-8B could not answer.', preset)).toContain('raw model id')
      expect(storeFindings('Model: Qwen 3.5 0.8B', preset)).toEqual([])
      expect(storeFindings('Note: the answer is short.', preset)).toEqual([])
    }
  })

  it('play is weaker in exactly three places, one of them only with the switch unfilteredWords', () => {
    // The one sentence, the tag of a model where a model is picked, and the hub.
    expect(storeFindings(PLAY_SENTENCE, 'play')).toEqual([])
    expect(storeFindings(PLAY_SENTENCE, 'appstore')).not.toEqual([])
    // The long name is no such place any more: decided 10.10.2026, the app is called "LU" in both stores.
    expect(rulesHit(`Welcome to ${FULL_NAME}.`, 'play')).toContain('product name')
    expect(rulesHit(`Welcome to ${FULL_NAME}.`, 'appstore')).toContain('product name')
    // The mark and the promise are a finding in a Play build too, also where a model is picked (acceptance Android, B3).
    expect(rulesHit('No Filter', 'play', true)).toContain('no filter')
    expect(rulesHit('Qwen3 1.7B without refusals.', 'play', true)).toContain('no refusals')
    expect(rulesHit('Models with no filter.', 'play')).toContain('no filter')
    // The two words as a designation: only where a model is picked, and only with the switch of the build.
    for (const word of ['Unfiltered', 'Qwen3 1.7B Abliterated']) {
      expect(storeFindings(word, 'play', { picker: true, designation: true }), word).toEqual([])
      expect(storeFindings(word, 'play', { picker: true }), word).not.toEqual([])
      expect(storeFindings(word, 'play', { picker: true, designation: false }), word).not.toEqual([])
      expect(storeFindings(word, 'play', { designation: true }), word).not.toEqual([])
      expect(storeFindings(word, 'appstore', { picker: true, designation: true }), word).not.toEqual([])
    }
    expect(rulesHit('Models with no refusals.', 'play')).toContain('no refusals')
    // The word of the statement mark is no such tag: not even where a model is picked.
    expect(rulesHit('Uncensored', 'play', true)).toContain('uncensored')
    expect(rulesHit('Uncensored', 'appstore', true)).toContain('uncensored')
    expect(storeFindings('View on Hugging Face', 'play')).toEqual([])
    // A second sentence next to the allowed one is still a finding.
    expect(rulesHit(`${PLAY_SENTENCE} Upgrade there.`, 'play')).toEqual(['upgrade'])
  })

  it('leaves alone what only sounds like buying', () => {
    for (const text of [
      '1,240 credits left.',
      'This answer used 3 credits.',
      'Add Sample to see the credits.',
      'Update the plan',
      'Plan, 2 of 5 done',
      'Uses your data plan.',
      `Write to ${SUPPORT_EMAIL}.`,
      'On device models stay free.',
    ]) {
      expect(storeFindings(text, 'appstore'), text).toEqual([])
    }
  })

  it('the support address: fine in a loose text, a pointer to the website for a reader that knows the place', () => {
    // Decided 10.10.2026: the address is the wanted contact, shown in the contact row of About and allowed there only.
    expect(CONTACT_PLACE).toEqual({ where: 'route /settings/about', testid: 'm-settings-about-contact' })
    // The row that shows it is the one the app draws.
    const aboutPage = readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'screens', 'settings', 'AboutPage.tsx'), 'utf8')
    expect(aboutPage.match(/subtitle=\{SUPPORT_EMAIL\}/g)).toHaveLength(1)
    expect(aboutPage).toMatch(new RegExp(`subtitle=\\{SUPPORT_EMAIL\\}[^\\n]*testid="${CONTACT_PLACE.testid}"`))
    for (const preset of ['appstore', 'play'] as const) {
      expect(storeFindings(`Write to ${SUPPORT_EMAIL}.`, preset)).toEqual([])
      // The guard over the pages asks this way, after taking the address out of the contact row.
      expect(storeFindings(`Write to ${SUPPORT_EMAIL}.`, preset, { supportAddress: false })).toHaveLength(1)
      expect(storeFindings('Contact support', preset, { supportAddress: false })).toEqual([])
      // Never a pass for the domain: the website and any other address of it are findings either way.
      expect(storeFindings(`${SUPPORT_EMAIL} or [email protected]`, preset)).toHaveLength(1)
      expect(storeFindings('Visit lu-labs.ai/account.', preset)).not.toEqual([])
    }
  })

  it('a link is fine inside the app and for the four legal addresses only', () => {
    for (const href of ['', '#top', '/settings', 'blob:abc', 'http://localhost:5937/x', ...LEGAL_LINKS, `${LEGAL_LINKS[0]}/`]) expect(linkAllowed(href), href).toBe(true)
    for (const href of ['https://lu-labs.ai', 'https://lu-labs.ai/pricing', 'https://huggingface.co/x', 'https://github.com/x', 'mailto:[email protected]', 'http://localhost.evil.example/']) {
      expect(linkAllowed(href), href).toBe(false)
    }
  })

  // Second check on Android, F10: "lorablated" stood in the search hits of a store build, and no rule knew the word.
  it('find every spelling of the list of the app in a model name, except the everyday words and proper names', () => {
    const shown = (sample: string) => sample.split('/').pop()!.replace(/[-_]?GGUF$/i, '')
    for (const spelling of UNFILTERED_SPELLINGS) {
      if (spelling.everyday) continue
      expect(storeFindings(shown(spelling.sample), 'appstore', { picker: true }), spelling.sample).not.toEqual([])
    }
    expect(rulesHit('Hermes-3-Llama-3.1-8B-lorablated', 'appstore', true)).toContain('abliterated, other spellings')
    // What says it is adult content or uncensored is a finding in a Play build too, also where a model is picked.
    expect(rulesHit('Llama-3-8B-ERP', 'play', true)).toContain('adult content')
    expect(rulesHit('gemma-3-4b-it-decensored', 'play', true)).toContain('uncensored, other spellings')
    // The same names without the word, and words that only contain one.
    for (const text of ['Hermes-3-Llama-3.1-8B', 'Serpent 7B', 'A table of your chats', 'Enable collaboration', 'Orthography', 'The report was sent.']) {
      expect(storeFindings(text, 'appstore', { picker: true }), text).toEqual([])
    }
  })
})