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
43 changes: 43 additions & 0 deletions apps/web/e2e/QUARANTINE.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,46 @@ owner: unassigned, review by: 2026-12-03 for every entry.
published translation's live text changes at once. Fix: either set
`status: 'draft'` on that save, or label the button "Save" when the
translation is published.
- `help-center/public-pages.spec.ts` › HC-P-33 reading the canonical article
page counts a view (HC-B1). `view_count` is incremented only in
`getPublicArticleBySlug` (`domains/help-center/help-center.article.service.ts`),
which serves the legacy URLs, the widget's slug opens, embed cards and the
admin View button. The canonical `/hc/<locale>/articles/<urlId>-<slug>` page
uses `getPublicArticleByUrlId`, which never counts, so the list "N views",
the performance table and Popular articles miss real reads. Fix: count in
the canonical page's loader (and decide whether previews/embeds count).
- `help-center/feedback.spec.ts` › HC-F-05 a signed-out visitor who flips Yes
to No is counted once (HC-B2). `recordArticleFeedback`
(`domains/help-center/help-center.article-feedback.service.ts`) looks up an
existing vote only when there is a principal; with none it always inserts
(null principals never collide on the unique index), so Yes then No adds
one helpful and one not-helpful vote, and every request adds another. Fix:
have the portal mint an anonymous session before voting (as the widget
does), or accept the previous `feedbackId` from the client and flip that
row; add a rate limit either way.
- `help-center/public-access.spec.ts` › HC-P-04 the landing card counts only
articles the visitor can open (HC-B14). `listPublicCategories`
(`domains/help-center/help-center.category.service.ts`) rolls
`recursivePublishedArticleCount` up through every descendant without
checking that the descendant category is public or that article audiences
admit the viewer, so a card shows "5 articles" where one can be opened (and
a category with only hidden content is listed at all). Fix: compute the
roll-up with the same visibility predicate the collection page uses
(`helpCenterVisibilityConditions` for the viewer).
- `help-center/widget.spec.ts` › HC-W-10 the first widget vote of a fresh
visitor confirms it (new bug, `@isolated`). The vote is stored against the
freshly minted session, but the footer
(`components/widget/widget-article-footer.tsx`) still says "Was this
helpful?" and no button is pressed. `cast` calls `ensureSession()` before
the write; minting the session changes the widget identity, which appears
to remount the article view (session-keyed queries) and drop the local
`vote` state. Root cause unconfirmed. Fix: keep the vote state above the
remount (or key it by article), or mint the session without remounting.
- `help-center/public-locales.spec.ts` › HC-P-27 an untranslated article has
no French page, and related links on a French page work (HC-B26;
`@isolated`). `getPublicArticlePageFn` (`lib/server/functions/help-center.ts`)
loads related articles without the page language, so a French article page
lists English titles linking to `/hc/fr/articles/<id>-<slug>`, which 404
when that article has no published French translation. Fix: load related
articles for the locale (translated only), or link untranslated ones to the
default-language URL.
160 changes: 160 additions & 0 deletions apps/web/e2e/tests/help-center/ask-ai.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/**
* Ask AI on the public help center (/api/widget/kb-ask): grounded answers,
* misses that never reach the model, and what the model is shown.
*
* Journeys: HC-S-10, HC-S-11, HC-S-12, HC-S-17.
*
* Current code skips the model when retrieval finds no article (HC-S-11);
* these tests pin that. Rules for the fake AI are keyed on the marker, which
* reaches the prompt through the retrieved article's body.
*/
import type { APIRequestContext } from '@playwright/test'
import { test, expect } from '../../support/fixtures'
import { clientIp } from '../../support/api-client'
import { fakeAi } from '../../support/fake-ai-client'
import { waitForHydration } from '../../utils/helpers'
import { articlePath, hcApi, hcArticle, hcCategory, searchWord } from '../../product/help-center'

const MISS = "I couldn't find a reliable answer to that in the help articles"

/** Ask kb-ask one question as a signed-out visitor; returns the raw stream text. */
async function ask(request: APIRequestContext, question: string): Promise<string> {
const res = await request.post('/api/widget/kb-ask', {
headers: { 'x-e2e-client-ip': clientIp() },
data: {
threadId: `t-${Date.now()}`,
runId: `r-${Date.now()}`,
messages: [{ id: 'm1', role: 'user', content: question }],
tools: [],
context: [],
state: {},
forwardedProps: {},
},
})
const text = await res.text()
expect(res.status(), text.slice(0, 300)).toBe(200)
return text
}

test.afterEach(async ({ marker }) => {
await fakeAi.clear(marker)
})

test(
'HC-S-10 Ask AI on /hc streams a grounded answer citing the article',
{ tag: '@core' },
async ({ page, marker, playwright }) => {
const hc = await hcApi(playwright)
const word = searchWord()
const category = await hcCategory(hc, `Ask ${marker}`)
const article = await hcArticle(hc, {
categoryId: category.id,
title: `Pairing the ${word} remote`,
content: `To pair the ${word} remote, hold the blue button for five seconds. ${marker}`,
publish: true,
})
const answer = `${marker} hold the blue button for five seconds`
await fakeAi.script({
marker,
json: { kind: 'grounded', answer: `${answer} [1].`, sources: [{ articleId: '1' }] },
})
await page.context().setExtraHTTPHeaders({ 'x-e2e-client-ip': clientIp() })
await page.goto('/hc')
const box = page.locator('#hc-search')
await waitForHydration(box)
await expect(box).toHaveAttribute('placeholder', /Ask AI/)
await box.fill(`How do I pair the ${word} remote?`)
await page.getByRole('button', { name: 'Use AI to answer your question in seconds' }).click()
await expect(page.getByText(answer, { exact: false })).toBeVisible({ timeout: 20_000 })
const source = page.getByRole('button', { name: `1. ${article.title}` })
await expect(source).toBeVisible()
await source.click()
await expect(page).toHaveURL(new RegExp(`${articlePath(article)}$`))
}
)

test(
'HC-S-11 a question nothing in the help center matches never reaches the model',
{ tag: '@core' },
async ({ request }) => {
const nonsense = `${searchWord()} ${searchWord()}`
const text = await ask(request, nonsense)
expect(text).toContain(MISS)
expect(await fakeAi.requests({ contains: nonsense, endpoint: 'chat' })).toEqual([])
}
)

test(
'HC-S-12 a declared miss keeps its words; a grounded answer citing nothing valid becomes the miss',
{ tag: '@core' },
async ({ request, marker, playwright }) => {
const hc = await hcApi(playwright)
const word = searchWord()
const category = await hcCategory(hc, `No answer ${marker}`)
await hcArticle(hc, {
categoryId: category.id,
title: `Billing ${word} cycles`,
content: `Invoices go out monthly. ${marker}`,
publish: true,
})
await fakeAi.script({
marker,
json: { kind: 'no_answer', answer: `Nothing on that ${marker}`, sources: [] },
})
const declined = await ask(request, `Billing ${word} cycles`)
// A declared miss keeps the model's own words and cites nothing.
expect(declined).toContain(`Nothing on that ${marker}`)
expect(declined).toContain('no_answer')
expect(await fakeAi.requests({ contains: marker, endpoint: 'chat' })).not.toEqual([])

await fakeAi.clear(marker)
await fakeAi.script({
marker,
json: { kind: 'grounded', answer: `Made up ${marker} [7].`, sources: [{ articleId: '7' }] },
})
const uncited = await ask(request, `Billing ${word} cycles`)
expect(uncited).toContain(MISS)
}
)

test(
'HC-S-17 the model is shown only articles the visitor may read',
{ tag: '@core' },
async ({ request, marker, playwright }) => {
const hc = await hcApi(playwright)
const word = searchWord()
const secret = searchWord()
const open = await hcCategory(hc, `Readable ${marker}`)
const closed = await hcCategory(hc, `Unreadable ${marker}`, { isPublic: false })
await hcArticle(hc, {
categoryId: open.id,
title: `Resetting the ${word} hub`,
content: `Press reset on the ${word} hub. ${marker}`,
publish: true,
})
await hcArticle(hc, {
categoryId: closed.id,
title: `Resetting the ${word} hub internally`,
content: `Internal only ${secret}. ${marker}`,
publish: true,
})
await hcArticle(hc, {
categoryId: open.id,
title: `Resetting the ${word} hub draft`,
content: `Draft only ${secret}. ${marker}`,
})
await fakeAi.script({
marker,
json: {
kind: 'grounded',
answer: `Press reset ${marker} [1].`,
sources: [{ articleId: '1' }],
},
})
const text = await ask(request, `How do I reset the ${word} hub?`)
expect(text).toContain(`Press reset ${marker}`)
const prompts = await fakeAi.requests({ contains: marker, endpoint: 'chat' })
expect(prompts.length).toBeGreaterThan(0)
expect(await fakeAi.requests({ contains: secret, endpoint: 'chat' })).toEqual([])
}
)
186 changes: 186 additions & 0 deletions apps/web/e2e/tests/help-center/feedback.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/**
* Article feedback on the public help center: helpful and unhelpful votes,
* reasons, signed-in vote changes and signed-out de-duplication.
*
* Journeys: HC-F-01, HC-F-02, HC-F-03, HC-F-04, HC-F-05.
*/
import type { Page } from '@playwright/test'
import { generateId } from '@quackback/ids'
import { test, expect } from '../../support/fixtures'
import { supportDb } from '../../support/db'
import { supportEnv } from '../../support/env'
import { callServerFn } from '../../support/server-fns'
import { mintCustomer, portalContext } from '../../support/widget-portal'
import { waitForHydration } from '../../utils/helpers'
import {
articlePath,
articleRow,
hcApi,
hcArticle,
hcCategory,
type HcArticle,
} from '../../product/help-center'

async function seed(playwright: Parameters<typeof hcApi>[0], marker: string): Promise<HcArticle> {
const hc = await hcApi(playwright)
const category = await hcCategory(hc, `Feedback ${marker}`)
return hcArticle(hc, { categoryId: category.id, title: `Rated ${marker}`, publish: true })
}

async function counts(article: HcArticle) {
const row = await articleRow(article.uuid)
return { helpful: row?.helpful_count, notHelpful: row?.not_helpful_count }
}

async function feedbackRows(article: HcArticle) {
return supportDb()`SELECT id, principal_id, helpful, reason FROM kb_article_feedback
WHERE article_id = ${article.uuid} ORDER BY created_at`
}

/** The feedback card's Yes/No, once the page has hydrated. */
async function vote(page: Page, answer: 'Yes' | 'No') {
const button = page.getByRole('button', { name: answer, exact: true })
await waitForHydration(button)
await button.click()
}

test(
'HC-F-01 a visitor marks an article helpful once',
{ tag: '@smoke' },
async ({ page, marker, playwright }) => {
const article = await seed(playwright, marker)
await page.goto(articlePath(article))
await expect(page.getByText('Your feedback shapes what we write next.')).toBeVisible()
const recorded = page.waitForResponse((r) => r.url().includes('/_serverFn/'))
await vote(page, 'Yes')
await recorded
await expect(page.getByText('Thanks, glad it landed.')).toBeVisible()
await expect.poll(() => counts(article)).toEqual({ helpful: 1, notHelpful: 0 })
const rows = await feedbackRows(article)
expect(rows).toHaveLength(1)
expect(rows[0]).toMatchObject({ helpful: true, principal_id: null })

// Pressing Yes again sends nothing.
await page.getByRole('button', { name: 'Yes', exact: true }).click()
await page.waitForTimeout(500)
expect(await feedbackRows(article)).toHaveLength(1)
}
)

test(
'HC-F-02 Not helpful asks for an optional reason and sends it once',
{ tag: '@core' },
async ({ page, marker, playwright }) => {
const article = await seed(playwright, marker)
await page.goto(articlePath(article))
await vote(page, 'No')
await expect(page.getByText("Noted. We'll revisit this article.")).toBeVisible()
await expect.poll(() => counts(article)).toEqual({ helpful: 0, notHelpful: 1 })

const box = page.getByPlaceholder('Optional, but it tells us what to fix.')
const send = page.getByRole('button', { name: 'Send' })
await expect(send).toBeDisabled()
await box.fill(' ')
await expect(send).toBeDisabled()
await expect(box).toHaveAttribute('maxlength', '1000')
await box.fill(`Missing the export steps ${marker}`)
await send.click()
await expect(
page.getByText('Thanks. That goes to whoever maintains this article.')
).toBeVisible()
await expect(box).toBeHidden()
await expect
.poll(async () => (await feedbackRows(article))[0]?.reason)
.toBe(`Missing the export steps ${marker}`)
}
)

test(
'HC-F-03 a reason is refused when blank, too long, second, on a helpful vote or unknown',
{ tag: '@core' },
async ({ marker, playwright }) => {
const article = await seed(playwright, marker)
const anon = await playwright.request.newContext({ baseURL: supportEnv().baseUrl })
const voteFn = (helpful: boolean) =>
callServerFn<{ feedbackId: string }>(anon, 'recordArticleFeedbackFn', {
articleId: article.id,
helpful,
})
const reason = (feedbackId: string, text: string) =>
callServerFn(anon, 'submitArticleFeedbackReasonFn', { feedbackId, reason: text })

const no = await voteFn(false)
expect(no.ok, no.error).toBe(true)
const yes = await voteFn(true)
expect(yes.ok, yes.error).toBe(true)

expect((await reason(no.data.feedbackId, ' ')).ok).toBe(false)
expect((await reason(no.data.feedbackId, 'x'.repeat(1001))).ok).toBe(false)
const first = await reason(no.data.feedbackId, `First ${marker}`)
expect(first.ok, first.error).toBe(true)
const second = await reason(no.data.feedbackId, `Second ${marker}`)
expect(second.code).toBe('FEEDBACK_REASON_UNAVAILABLE')
expect((await reason(yes.data.feedbackId, `On yes ${marker}`)).code).toBe(
'FEEDBACK_REASON_UNAVAILABLE'
)
expect((await reason(generateId('kb_article_feedback'), 'x')).code).toBe(
'FEEDBACK_REASON_UNAVAILABLE'
)
const reasons = (await feedbackRows(article)).map((r) => r.reason).filter(Boolean)
expect(reasons).toEqual([`First ${marker}`])
}
)

test(
'HC-F-04 a signed-in user has one vote that moves between the counters',
{ tag: '@core' },
async ({ browser, marker, playwright, customerEmail }) => {
const article = await seed(playwright, marker)
const customer = await mintCustomer({ email: customerEmail })
const context = await portalContext(browser, customer)
const page = await context.newPage()
await page.goto(articlePath(article))
await vote(page, 'Yes')
await expect.poll(() => counts(article)).toEqual({ helpful: 1, notHelpful: 0 })
await page.getByRole('button', { name: 'No', exact: true }).click()
await expect.poll(() => counts(article)).toEqual({ helpful: 0, notHelpful: 1 })

// After a reload the page forgets the vote, but the server still keeps one.
await page.reload()
await vote(page, 'No')
await expect(page.getByText("Noted. We'll revisit this article.")).toBeVisible()
const again = await callServerFn(context.request, 'recordArticleFeedbackFn', {
articleId: article.id,
helpful: true,
})
expect(again.ok, again.error).toBe(true)
await expect.poll(() => counts(article)).toEqual({ helpful: 1, notHelpful: 0 })
const rows = await feedbackRows(article)
expect(rows).toHaveLength(1)
expect(rows[0]).toMatchObject({ helpful: true, principal_id: customer.principalUuid })
await context.close()
}
)

test(
'HC-F-05 a signed-out visitor who flips Yes to No is counted once',
{
tag: ['@core', '@quarantine'],
annotation: {
type: 'quarantine',
description:
'HC-B2: recordArticleFeedback skips the existing-vote lookup when there is no principal and always inserts, so a flip adds one helpful and one not-helpful vote',
},
},
async ({ page, marker, playwright }) => {
const article = await seed(playwright, marker)
await page.goto(articlePath(article))
await vote(page, 'Yes')
await expect.poll(() => counts(article)).toEqual({ helpful: 1, notHelpful: 0 })
await page.getByRole('button', { name: 'No', exact: true }).click()
await expect(page.getByText("Noted. We'll revisit this article.")).toBeVisible()
await page.waitForTimeout(1_000)
const c = await counts(article)
expect((c.helpful as number) + (c.notHelpful as number)).toBe(1)
}
)
Loading
Loading