fix: band-level windowed refine_layout + programmatic map_fields to prevent 91.5% content loss
Root cause: LLM receiving full 34k-char JRXML would regenerate from scratch
instead of modifying coordinates in-place, shrinking output to ~3k chars.
Solution (programmatic node control, not prompt engineering):
- New agent/jrxml_windower.py: decompose JRXML into header (never sent to
LLM) + individual bands. Split bands >4000 chars at element boundaries.
Reassemble with element count validation (>10% change = rollback).
- Rewrite refine_layout: per-band windowed LLM processing (~2-4k chars
each). LLM cannot "reimagine" the entire report.
- Rewrite map_fields: 100% programmatic regex $F{field_N} -> real name
replacement. Zero LLM calls, zero content loss.
- _sanitize_field_name: non-ASCII chars escaped to _uXXXX_ format for
valid JRXML identifiers.
- Tests: 48 new unit tests (windower 28 + map_fields 20). All passing.
Full suite 385 tests, zero regressions.
This commit is contained in:
+50
-3
@@ -1,5 +1,52 @@
|
||||
# Vue 3 + TypeScript + Vite
|
||||
# JRXML Agent 前端
|
||||
|
||||
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||
Vue 3 + TypeScript + Vite + Pinia — JRXML 报表生成代理的 Web UI。
|
||||
|
||||
Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).
|
||||
## 技术栈
|
||||
|
||||
- **Vue 3** (Composition API + `<script setup>`)
|
||||
- **TypeScript** 6.x
|
||||
- **Vite** 8.x
|
||||
- **Pinia** 3.x (状态管理)
|
||||
- **SSE** (Server-Sent Events) 流式响应
|
||||
|
||||
## 组件结构
|
||||
|
||||
```
|
||||
src/
|
||||
├── api/client.ts SSE 客户端 + fetch 封装
|
||||
├── stores/
|
||||
│ ├── chat.ts Pinia: 消息/流式/节点进度/文件
|
||||
│ ├── session.ts Pinia: 会话 CRUD
|
||||
│ └── kb.ts Pinia: 多租户知识库管理
|
||||
├── components/
|
||||
│ ├── Sidebar.vue 会话列表 + 下载 + 历史版本
|
||||
│ ├── ChatMessages.vue 消息列表渲染
|
||||
│ ├── ProcessSection.vue 处理过程折叠区
|
||||
│ ├── UnifiedInput.vue 统一输入框(文本+文件拖拽/粘贴)
|
||||
│ ├── SummaryCard.vue 结果摘要卡片
|
||||
│ ├── KbSelector.vue KB 下拉选择器
|
||||
│ └── KbManager.vue KB 管理面板(创建/上传/构建/删除)
|
||||
└── utils/format.ts 工具函数
|
||||
```
|
||||
|
||||
## 开发
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm run dev # 启动开发服务器 (localhost:5173)
|
||||
npm run build # 生产构建
|
||||
npx playwright test # E2E 测试
|
||||
```
|
||||
|
||||
## SSE 事件流
|
||||
|
||||
前端通过 `api.chat()` 发起 POST 请求,后端返回 `text/event-stream`:
|
||||
|
||||
| 事件 | 说明 |
|
||||
|------|------|
|
||||
| `node_start` | 节点开始执行(含 node/label/step_index) |
|
||||
| `node_complete` | 节点执行完成(含 detail) |
|
||||
| `stream_token` | LLM 逐字输出 |
|
||||
| `agent_complete` | 全图执行完成(含 intent/status/jrxml_length/error 等) |
|
||||
| `agent_error` | 执行异常 |
|
||||
|
||||
@@ -8,9 +8,19 @@ import ChatMessages from './components/ChatMessages.vue'
|
||||
import ProcessSection from './components/ProcessSection.vue'
|
||||
import SummaryCard from './components/SummaryCard.vue'
|
||||
import UnifiedInput from './components/UnifiedInput.vue'
|
||||
import KbSelector from './components/KbSelector.vue'
|
||||
import KbManager from './components/KbManager.vue'
|
||||
import { useKbStore } from './stores/kb'
|
||||
|
||||
const chat = useChatStore()
|
||||
const session = useSessionStore()
|
||||
const kb = useKbStore()
|
||||
|
||||
function handleKbChange(kbId: string) {
|
||||
if (session.currentId) {
|
||||
kb.bindKbToSession(session.currentId, kbId)
|
||||
}
|
||||
}
|
||||
|
||||
const chatContainer = ref<HTMLElement | null>(null)
|
||||
|
||||
@@ -128,6 +138,7 @@ async function handleSend(text: string, files: File[]) {
|
||||
<Sidebar @quickAction="(text) => handleSend(text, [])" />
|
||||
|
||||
<main class="main-area">
|
||||
<KbSelector @change="handleKbChange" />
|
||||
<div class="chat-container" ref="chatContainer">
|
||||
<ChatMessages />
|
||||
<ProcessSection />
|
||||
@@ -139,6 +150,8 @@ async function handleSend(text: string, files: File[]) {
|
||||
@send="handleSend"
|
||||
/>
|
||||
</main>
|
||||
|
||||
<KbManager />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useKbStore } from '../stores/kb'
|
||||
|
||||
const kb = useKbStore()
|
||||
|
||||
const newKbName = ref('')
|
||||
const newKbDesc = ref('')
|
||||
const creating = ref(false)
|
||||
const uploading = ref<string | null>(null)
|
||||
const building = ref<string | null>(null)
|
||||
const fileInput = ref<HTMLInputElement | null>(null)
|
||||
|
||||
onMounted(() => { kb.init() })
|
||||
|
||||
async function handleCreate() {
|
||||
if (!newKbName.value.trim()) return
|
||||
creating.value = true
|
||||
await kb.createKb(newKbName.value.trim(), newKbDesc.value.trim())
|
||||
newKbName.value = ''
|
||||
newKbDesc.value = ''
|
||||
creating.value = false
|
||||
}
|
||||
|
||||
async function handleDelete(kbId: string) {
|
||||
if (confirm('确定删除此知识库?所有文件和数据将被永久删除。')) {
|
||||
await kb.deleteKb(kbId)
|
||||
}
|
||||
}
|
||||
|
||||
function triggerUpload(kbId: string) {
|
||||
uploading.value = kbId
|
||||
fileInput.value?.click()
|
||||
}
|
||||
|
||||
async function handleFileSelect(e: Event, kbId: string) {
|
||||
const input = e.target as HTMLInputElement
|
||||
if (input.files && input.files.length > 0) {
|
||||
for (const f of input.files) {
|
||||
await kb.uploadFileToKb(kbId, f)
|
||||
}
|
||||
await kb.buildKb(kbId)
|
||||
await kb.refreshKbs()
|
||||
}
|
||||
input.value = ''
|
||||
uploading.value = null
|
||||
}
|
||||
|
||||
async function handleBuild(kbId: string) {
|
||||
building.value = kbId
|
||||
await kb.buildKb(kbId)
|
||||
building.value = null
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<div v-if="kb.showManager" class="kb-manager-overlay" @click.self="kb.showManager = false">
|
||||
<div class="kb-manager">
|
||||
<h3>知识库管理</h3>
|
||||
|
||||
<div class="create-form">
|
||||
<input v-model="newKbName" class="kb-input" placeholder="知识库名称" :disabled="creating" />
|
||||
<input v-model="newKbDesc" class="kb-input" placeholder="描述(可选)" :disabled="creating" />
|
||||
<button class="kb-btn primary" :disabled="creating || !newKbName.trim()" @click="handleCreate">
|
||||
{{ creating ? '创建中...' : '创建' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="kb.loading" class="empty">加载中...</div>
|
||||
<div v-else-if="kb.kbs.length === 0" class="empty">暂无知识库</div>
|
||||
|
||||
<div v-for="k in kb.kbs" :key="k.kb_id" class="kb-card">
|
||||
<div class="kb-card-header">
|
||||
<strong>{{ k.name }}</strong>
|
||||
<span class="kb-status" :class="k.parse_status">
|
||||
{{ k.parse_status === 'ready' ? '就绪' : k.parse_status === 'partial' ? '部分' : '空' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="kb-meta">
|
||||
{{ k.field_count }}字段 · {{ k.template_count }}模板 ·
|
||||
{{ k.file_count }}文件 · {{ k.chunk_count }}块
|
||||
</div>
|
||||
<div class="kb-actions">
|
||||
<button class="kb-btn" @click="triggerUpload(k.kb_id)" :disabled="uploading === k.kb_id">
|
||||
{{ uploading === k.kb_id ? '上传中...' : '上传文件' }}
|
||||
</button>
|
||||
<button class="kb-btn" @click="handleBuild(k.kb_id)" :disabled="building === k.kb_id || k.file_count === 0">
|
||||
{{ building === k.kb_id ? '构建中...' : '构建' }}
|
||||
</button>
|
||||
<button class="kb-btn danger" @click="handleDelete(k.kb_id)">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="kb-btn close-btn" @click="kb.showManager = false">关闭</button>
|
||||
|
||||
<input ref="fileInput" type="file" multiple
|
||||
accept=".jrxml,.md,.xlsx,.xls,.docx,.doc,.pdf,.csv,.txt,.json,.zip,.tar,.gz"
|
||||
style="display:none"
|
||||
@change="(e: Event) => { const kbId = uploading; if (kbId) handleFileSelect(e, kbId); }" />
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.kb-manager-overlay {
|
||||
position: fixed; inset: 0;
|
||||
background: rgba(0,0,0,0.6);
|
||||
z-index: 100;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
}
|
||||
.kb-manager {
|
||||
background: #1e1e2e;
|
||||
border: 1px solid #45475a;
|
||||
border-radius: 12px;
|
||||
padding: 24px;
|
||||
width: 540px;
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
color: #cdd6f4;
|
||||
}
|
||||
h3 { margin: 0 0 16px; font-size: 18px; }
|
||||
.create-form { display: flex; gap: 8px; margin-bottom: 16px; }
|
||||
.kb-input {
|
||||
flex: 1;
|
||||
background: #181825;
|
||||
border: 1px solid #45475a;
|
||||
border-radius: 6px;
|
||||
color: #cdd6f4;
|
||||
padding: 6px 10px;
|
||||
font-size: 13px;
|
||||
outline: none;
|
||||
}
|
||||
.kb-input:focus { border-color: #cba6f7; }
|
||||
.kb-btn {
|
||||
background: #313244; border: none; border-radius: 6px;
|
||||
color: #cdd6f4; padding: 6px 12px; font-size: 12px;
|
||||
cursor: pointer; white-space: nowrap;
|
||||
}
|
||||
.kb-btn:hover:not(:disabled) { background: #45475a; }
|
||||
.kb-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
.kb-btn.primary { background: #cba6f7; color: #1e1e2e; }
|
||||
.kb-btn.primary:hover:not(:disabled) { background: #b4befe; }
|
||||
.kb-btn.danger { color: #f38ba8; }
|
||||
.kb-btn.danger:hover:not(:disabled) { background: #f38ba8; color: #1e1e2e; }
|
||||
.empty { text-align: center; color: #6c7086; padding: 24px 0; }
|
||||
.kb-card {
|
||||
background: #181825; border: 1px solid #313244;
|
||||
border-radius: 8px; padding: 12px; margin-bottom: 8px;
|
||||
}
|
||||
.kb-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
|
||||
.kb-status { font-size: 11px; padding: 1px 6px; border-radius: 4px; }
|
||||
.kb-status.ready { background: #a6e3a1; color: #1e1e2e; }
|
||||
.kb-status.partial { background: #fab387; color: #1e1e2e; }
|
||||
.kb-status.empty { background: #45475a; color: #a6adc8; }
|
||||
.kb-meta { font-size: 11px; color: #6c7086; margin-bottom: 8px; }
|
||||
.kb-actions { display: flex; gap: 6px; }
|
||||
.close-btn { display: block; margin: 16px auto 0; }
|
||||
</style>
|
||||
@@ -0,0 +1,108 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue'
|
||||
import { useKbStore } from '../stores/kb'
|
||||
|
||||
const kb = useKbStore()
|
||||
|
||||
const emit = defineEmits<{
|
||||
change: [kbId: string]
|
||||
}>()
|
||||
|
||||
function handleChange(e: Event) {
|
||||
const kbId = (e.target as HTMLSelectElement).value
|
||||
kb.selectKb(kbId)
|
||||
if (kbId) {
|
||||
kb.fetchKbFields(kbId)
|
||||
}
|
||||
emit('change', kbId)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
kb.init()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="kb-selector">
|
||||
<label class="kb-label">知识库</label>
|
||||
<select
|
||||
class="kb-select"
|
||||
:value="kb.currentKbId"
|
||||
@change="handleChange"
|
||||
>
|
||||
<option value="">-- 不使用知识库 --</option>
|
||||
<option
|
||||
v-for="k in kb.kbs"
|
||||
:key="k.kb_id"
|
||||
:value="k.kb_id"
|
||||
>
|
||||
{{ k.name }} ({{ k.field_count }}字段, {{ k.template_count }}模板)
|
||||
</option>
|
||||
</select>
|
||||
<button class="kb-manage-btn" @click="kb.showManager = !kb.showManager" title="管理知识库">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<circle cx="12" cy="12" r="3"/>
|
||||
<path d="M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"/>
|
||||
</svg>
|
||||
</button>
|
||||
<span v-if="kb.currentKbName" class="kb-badge">当前: {{ kb.currentKbName }}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.kb-selector {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 16px;
|
||||
background: #181825;
|
||||
border-bottom: 1px solid #313244;
|
||||
}
|
||||
|
||||
.kb-label {
|
||||
font-size: 12px;
|
||||
color: #6c7086;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.kb-select {
|
||||
flex: 1;
|
||||
background: #1e1e2e;
|
||||
border: 1px solid #45475a;
|
||||
border-radius: 6px;
|
||||
color: #cdd6f4;
|
||||
padding: 4px 8px;
|
||||
font-size: 13px;
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.kb-select:focus {
|
||||
border-color: #cba6f7;
|
||||
}
|
||||
|
||||
.kb-manage-btn {
|
||||
background: #313244;
|
||||
border: none;
|
||||
color: #a6adc8;
|
||||
border-radius: 6px;
|
||||
padding: 4px 6px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.kb-manage-btn:hover {
|
||||
background: #45475a;
|
||||
color: #cdd6f4;
|
||||
}
|
||||
|
||||
.kb-badge {
|
||||
font-size: 11px;
|
||||
color: #a6e3a1;
|
||||
background: #1e1e2e;
|
||||
padding: 2px 8px;
|
||||
border-radius: 10px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
@@ -140,7 +140,7 @@ function handlePaste(e: ClipboardEvent) {
|
||||
ref="fileInputRef"
|
||||
type="file"
|
||||
multiple
|
||||
accept="image/*,.pdf,.docx,.doc,.xlsx,.xls,.txt,.csv"
|
||||
accept="image/*,.pdf,.docx,.doc,.xlsx,.xls,.txt,.csv,.jrxml"
|
||||
style="display:none"
|
||||
@change="handleFileSelect"
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
/** Pinia store — multi-tenant KB management. */
|
||||
|
||||
import { ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export interface KbSummary {
|
||||
kb_id: string
|
||||
name: string
|
||||
description: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
field_count: number
|
||||
template_count: number
|
||||
file_count: number
|
||||
chunk_count: number
|
||||
parse_status: string
|
||||
}
|
||||
|
||||
export interface UserInfo {
|
||||
user_id: string
|
||||
name: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface KbTemplate {
|
||||
name: string
|
||||
file: string
|
||||
}
|
||||
|
||||
export interface KbField {
|
||||
name: string
|
||||
description: string
|
||||
type: string
|
||||
required: boolean
|
||||
}
|
||||
|
||||
export const useKbStore = defineStore('kb', () => {
|
||||
const users = ref<UserInfo[]>([])
|
||||
const currentUserId = ref('')
|
||||
const kbs = ref<KbSummary[]>([])
|
||||
const currentKbId = ref('')
|
||||
const currentKbName = ref('')
|
||||
const currentKbFields = ref<KbField[]>([])
|
||||
const currentKbTemplates = ref<KbTemplate[]>([])
|
||||
const loading = ref(false)
|
||||
const showManager = ref(false)
|
||||
|
||||
function setKbs(list: KbSummary[]) { kbs.value = list }
|
||||
|
||||
function selectKb(kbId: string) {
|
||||
currentKbId.value = kbId
|
||||
const kb = kbs.value.find(k => k.kb_id === kbId)
|
||||
if (kb) currentKbName.value = kb.name
|
||||
}
|
||||
|
||||
async function refreshUsers() {
|
||||
try {
|
||||
const r = await fetch('/api/users')
|
||||
const data = await r.json()
|
||||
users.value = data.users || []
|
||||
if (users.value.length > 0 && !currentUserId.value) {
|
||||
currentUserId.value = users.value[0].user_id
|
||||
}
|
||||
} catch (e) { console.error('获取用户列表失败:', e) }
|
||||
}
|
||||
|
||||
async function refreshKbs(userId?: string) {
|
||||
const uid = userId || currentUserId.value
|
||||
if (!uid) return
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await fetch(`/api/users/${uid}/kbs`)
|
||||
const data = await r.json()
|
||||
kbs.value = data.kbs || []
|
||||
} catch (e) { console.error('获取知识库列表失败:', e) }
|
||||
finally { loading.value = false }
|
||||
}
|
||||
|
||||
async function createKb(name: string, description = ''): Promise<KbSummary | null> {
|
||||
if (!currentUserId.value) return null
|
||||
try {
|
||||
const r = await fetch(`/api/users/${currentUserId.value}/kbs`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name, description }),
|
||||
})
|
||||
if (!r.ok) throw new Error('创建失败')
|
||||
const kb = await r.json()
|
||||
await refreshKbs()
|
||||
return kb
|
||||
} catch (e) { console.error('创建知识库失败:', e); return null }
|
||||
}
|
||||
|
||||
async function deleteKb(kbId: string): Promise<boolean> {
|
||||
try {
|
||||
const r = await fetch(`/api/kbs/${kbId}`, { method: 'DELETE' })
|
||||
if (!r.ok) throw new Error('删除失败')
|
||||
if (currentKbId.value === kbId) { currentKbId.value = ''; currentKbName.value = '' }
|
||||
await refreshKbs()
|
||||
return true
|
||||
} catch (e) { console.error('删除知识库失败:', e); return false }
|
||||
}
|
||||
|
||||
async function uploadFileToKb(kbId: string, file: File): Promise<boolean> {
|
||||
try {
|
||||
const form = new FormData()
|
||||
form.append('file', file)
|
||||
const r = await fetch(`/api/kbs/${kbId}/upload`, { method: 'POST', body: form })
|
||||
return r.ok
|
||||
} catch (e) { console.error('KB文件上传失败:', e); return false }
|
||||
}
|
||||
|
||||
async function buildKb(kbId: string): Promise<boolean> {
|
||||
try {
|
||||
const r = await fetch(`/api/kbs/${kbId}/build`, { method: 'POST' })
|
||||
if (!r.ok) throw new Error('构建失败')
|
||||
await refreshKbs()
|
||||
return true
|
||||
} catch (e) { console.error('KB构建失败:', e); return false }
|
||||
}
|
||||
|
||||
async function fetchKbFields(kbId: string) {
|
||||
try {
|
||||
const r = await fetch(`/api/kbs/${kbId}/fields`)
|
||||
const data = await r.json()
|
||||
currentKbFields.value = data.fields || []
|
||||
currentKbTemplates.value = data.templates || []
|
||||
} catch (e) { console.error('获取KB字段失败:', e) }
|
||||
}
|
||||
|
||||
async function bindKbToSession(sessionId: string, kbId: string) {
|
||||
try {
|
||||
await fetch(`/api/sessions/${sessionId}/kb`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ kb_id: kbId }),
|
||||
})
|
||||
} catch (e) { console.error('绑定KB失败:', e) }
|
||||
}
|
||||
|
||||
async function init() {
|
||||
await refreshUsers()
|
||||
if (currentUserId.value) await refreshKbs()
|
||||
}
|
||||
|
||||
return {
|
||||
users, currentUserId, kbs, currentKbId, currentKbName,
|
||||
currentKbFields, currentKbTemplates, loading, showManager,
|
||||
setKbs, selectKb, refreshUsers, refreshKbs, createKb, deleteKb,
|
||||
uploadFileToKb, buildKb, fetchKbFields, bindKbToSession, init,
|
||||
}
|
||||
})
|
||||
@@ -166,3 +166,155 @@ test.describe("Input UX", () => {
|
||||
await expect(page.locator(".send-btn")).toBeEnabled();
|
||||
});
|
||||
});
|
||||
|
||||
// ── KB (Knowledge Base) API mocks ───────────────────────────────
|
||||
|
||||
function mockKbApi(page: any) {
|
||||
mockApi(page);
|
||||
|
||||
page.route("**/api/users", (route: any) => {
|
||||
if (route.request().method() === "POST") {
|
||||
return route.fulfill({
|
||||
json: { user_id: "u_e2e_test_001", name: "E2E用户", created_at: "2026-05-23T00:00:00Z" },
|
||||
});
|
||||
}
|
||||
return route.fulfill({
|
||||
json: { users: [{ user_id: "u_e2e_test_001", name: "E2E用户", created_at: "2026-05-23T00:00:00Z" }] },
|
||||
});
|
||||
});
|
||||
|
||||
page.route("**/api/users/*/kbs", (route: any) => {
|
||||
if (route.request().method() === "POST") {
|
||||
return route.fulfill({
|
||||
json: {
|
||||
kb_id: "kb_e2e_001", user_id: "u_e2e_test_001",
|
||||
name: "E2E测试库", description: "",
|
||||
created_at: "2026-05-23T00:00:00Z", updated_at: "2026-05-23T00:00:00Z",
|
||||
fields: [], templates: [], file_count: 0, chunk_count: 0, parse_status: "empty",
|
||||
},
|
||||
});
|
||||
}
|
||||
return route.fulfill({
|
||||
json: {
|
||||
kbs: [{
|
||||
kb_id: "kb_e2e_001", name: "E2E测试库", description: "",
|
||||
created_at: "2026-05-23T00:00:00Z", updated_at: "2026-05-23T00:00:00Z",
|
||||
field_count: 10, template_count: 3, file_count: 2, chunk_count: 50, parse_status: "ready",
|
||||
}],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
page.route("**/api/kbs/*/status", (route: any) =>
|
||||
route.fulfill({ json: { parse_status: "ready", file_count: 2, chunk_count: 50 } })
|
||||
);
|
||||
page.route("**/api/kbs/*/fields", (route: any) =>
|
||||
route.fulfill({ json: {
|
||||
fields: [{ name: "billNo", description: "工单号", type: "String" }],
|
||||
templates: [{ name: "结算单", file: "结算单.jrxml" }],
|
||||
}})
|
||||
);
|
||||
page.route("**/api/kbs/*", (route: any) => {
|
||||
if (route.request().method() === "DELETE") {
|
||||
return route.fulfill({ json: { status: "deleted" } });
|
||||
}
|
||||
return route.fulfill({
|
||||
json: {
|
||||
kb_id: "kb_e2e_001", user_id: "u_e2e_test_001",
|
||||
name: "E2E测试库", description: "",
|
||||
fields: [], templates: [],
|
||||
file_count: 2, chunk_count: 50, parse_status: "ready",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
page.route("**/api/kbs/*/upload", (route: any) =>
|
||||
route.fulfill({ json: { filename: "test.jrxml", type: "jrxml", error: null } })
|
||||
);
|
||||
|
||||
page.route("**/api/sessions/*/kb", (route: any) => {
|
||||
if (route.request().method() === "PUT") {
|
||||
return route.fulfill({ json: { kb_id: "kb_e2e_001", kb_name: "E2E测试库" } });
|
||||
}
|
||||
return route.fulfill({ json: { kb_id: "kb_e2e_001", kb_name: "E2E测试库" } });
|
||||
});
|
||||
}
|
||||
|
||||
// ── KB feature tests ────────────────────────────────────────────
|
||||
|
||||
test.describe("KB selector", () => {
|
||||
test("KB selector renders in chat interface", async ({ page }) => {
|
||||
await mockKbApi(page);
|
||||
await page.goto("/");
|
||||
|
||||
await expect(page.locator(".kb-selector")).toBeVisible({ timeout: 5000 });
|
||||
await expect(page.locator(".kb-label")).toContainText("知识库");
|
||||
await expect(page.locator(".kb-select")).toBeVisible();
|
||||
await expect(page.locator(".kb-manage-btn")).toBeVisible();
|
||||
});
|
||||
|
||||
test("can select a KB from dropdown", async ({ page }) => {
|
||||
await mockKbApi(page);
|
||||
await page.goto("/");
|
||||
|
||||
const select = page.locator(".kb-select");
|
||||
await expect(select).toBeVisible({ timeout: 5000 });
|
||||
await select.selectOption({ label: "E2E测试库 (10字段, 3模板)" });
|
||||
await expect(page.locator(".kb-badge")).toContainText("E2E测试库");
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("KB manager", () => {
|
||||
test("opens KB manager overlay", async ({ page }) => {
|
||||
await mockKbApi(page);
|
||||
await page.goto("/");
|
||||
|
||||
await page.locator(".kb-manage-btn").click();
|
||||
await expect(page.locator(".kb-manager")).toBeVisible({ timeout: 3000 });
|
||||
await expect(page.locator(".kb-manager h3")).toContainText("知识库管理");
|
||||
});
|
||||
|
||||
test("can close KB manager", async ({ page }) => {
|
||||
await mockKbApi(page);
|
||||
await page.goto("/");
|
||||
|
||||
await page.locator(".kb-manage-btn").click();
|
||||
await expect(page.locator(".kb-manager")).toBeVisible({ timeout: 3000 });
|
||||
await page.locator(".close-btn").click();
|
||||
await expect(page.locator(".kb-manager")).not.toBeVisible({ timeout: 3000 });
|
||||
});
|
||||
|
||||
test("create form has name input and create button", async ({ page }) => {
|
||||
await mockKbApi(page);
|
||||
await page.goto("/");
|
||||
|
||||
await page.locator(".kb-manage-btn").click();
|
||||
await expect(page.locator(".kb-manager")).toBeVisible({ timeout: 3000 });
|
||||
|
||||
await expect(page.locator('.kb-manager .create-form .kb-input').first()).toBeVisible();
|
||||
await expect(page.locator('.kb-manager .create-form button.primary')).toBeVisible();
|
||||
});
|
||||
|
||||
test("KB cards show name, status, and actions", async ({ page }) => {
|
||||
await mockKbApi(page);
|
||||
await page.goto("/");
|
||||
|
||||
await page.locator(".kb-manage-btn").click();
|
||||
await expect(page.locator(".kb-manager")).toBeVisible({ timeout: 3000 });
|
||||
|
||||
await expect(page.locator(".kb-card")).toBeVisible({ timeout: 3000 });
|
||||
await expect(page.locator(".kb-card strong")).toContainText("E2E测试库");
|
||||
await expect(page.locator(".kb-status.ready")).toContainText("就绪");
|
||||
await expect(page.locator(".kb-actions button")).toHaveCount(3);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("JRXML upload in chat", () => {
|
||||
test("file input accepts .jrxml extension", async ({ page }) => {
|
||||
await mockKbApi(page);
|
||||
await page.goto("/");
|
||||
|
||||
const input = page.locator('.unified-input input[type="file"]');
|
||||
await expect(input).toHaveAttribute("accept", /\.jrxml/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user