File size: 2,047 Bytes
5a5899d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { test, expect } from '@playwright/test'
import { API_KEY_HEADER } from './helpers'

test.describe('Docs Knowledge API', () => {
  test('tree/search/content flows for markdown knowledge docs', async ({ request }) => {
    const stamp = Date.now()
    const path = `knowledge-base/e2e-kb-${stamp}.md`
    const content = `# E2E Knowledge ${stamp}\n\nDeployment runbook token: kb-search-${stamp}`

    const create = await request.post('/api/memory', {
      headers: API_KEY_HEADER,
      data: {
        action: 'create',
        path,
        content,
      },
    })
    expect(create.status()).toBe(200)

    const tree = await request.get('/api/docs/tree', { headers: API_KEY_HEADER })
    expect(tree.status()).toBe(200)
    const treeBody = await tree.json()
    expect(Array.isArray(treeBody.tree)).toBe(true)

    const search = await request.get(`/api/docs/search?q=${encodeURIComponent(`kb-search-${stamp}`)}`, {
      headers: API_KEY_HEADER,
    })
    expect(search.status()).toBe(200)
    const searchBody = await search.json()
    const found = searchBody.results.find((r: any) => r.path === path)
    expect(found).toBeTruthy()

    const doc = await request.get(`/api/docs/content?path=${encodeURIComponent(path)}`, {
      headers: API_KEY_HEADER,
    })
    expect(doc.status()).toBe(200)
    const docBody = await doc.json()
    expect(docBody.path).toBe(path)
    expect(docBody.content).toContain(`kb-search-${stamp}`)

    const cleanup = await request.delete('/api/memory', {
      headers: API_KEY_HEADER,
      data: {
        action: 'delete',
        path,
      },
    })
    expect(cleanup.status()).toBe(200)
  })

  test('docs APIs require auth', async ({ request }) => {
    const tree = await request.get('/api/docs/tree')
    expect(tree.status()).toBe(401)

    const search = await request.get('/api/docs/search?q=deployment')
    expect(search.status()).toBe(401)

    const content = await request.get('/api/docs/content?path=knowledge-base/example.md')
    expect(content.status()).toBe(401)
  })
})