Jelajahi Sumber

WIP: 兼容未读接口 405 并保护会话切换

[gstack-context]
Decisions: 未读 GET/PATCH 的 404/405 均视为上游不支持;标记已读失败不阻断会话加载
Remaining: 全量测试、生产构建、重载 8800、真实会话切换复验
Skill: /investigate
[/gstack-context]
samien 2 bulan lalu
induk
melakukan
6453970269

+ 1 - 1
src/client/views/ChatView.vue

@@ -132,7 +132,7 @@ async function chooseSession(id: string) {
   await ensureRouteProfile(profile)
   if (chat.activeProfileName !== profile) await chat.loadSessions(profile)
   await chat.selectSession(id, profile)
-  await chat.markRead(id, profile)
+  await chat.markRead(id, profile).catch(() => undefined)
   quoted.value = null
 }
 

+ 1 - 1
src/server/routes.ts

@@ -182,7 +182,7 @@ async function proxyOptionalUnread(
       search: options.search,
       body: options.requestBody,
     })
-    if (response.status === 404) {
+    if (response.status === 404 || response.status === 405) {
       json(ctx, 200, fallback)
       return
     }

+ 13 - 0
tests/e2e/workspace.spec.ts

@@ -82,6 +82,19 @@ test('restores a routed conversation even when unread-count refresh fails', asyn
   await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
 })
 
+test('opens a conversation even when marking it read is unsupported', async ({ page }) => {
+  const pageErrors: string[] = []
+  page.on('pageerror', error => pageErrors.push(error.message))
+  await page.route('**/api/app/sessions/unread/*', async route => {
+    await route.fulfill({ status: 405, contentType: 'application/json', body: JSON.stringify({ error: 'Method Not Allowed' }) })
+  })
+
+  await page.getByRole('option').filter({ hasText: '第二个会话' }).click()
+  await expect(page).toHaveURL(/\/chat\/session-second\?profile=yaoyao/)
+  await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
+  expect(pageErrors).toEqual([])
+})
+
 test('restores a legacy session link under its owning Agent profile', async ({ page }) => {
   await page.goto('/chat/session-yaoer')
   await expect(page.getByText('瑶儿历史消息', { exact: true })).toBeVisible()

+ 2 - 1
tests/server/app.test.ts

@@ -168,7 +168,8 @@ describe('8800 BFF', () => {
           search: url.searchParams,
           headers: new Headers(init?.headers),
         })
-        return jsonResponse({ detail: 'Not Found' }, { status: 404 })
+        const status = (init?.method ?? 'GET') === 'PATCH' ? 405 : 404
+        return jsonResponse({ detail: status === 405 ? 'Method Not Allowed' : 'Not Found' }, { status })
       }
       return baseGateway(input, init)
     }) as typeof fetch