From 32c00d6e72135eb367d80d014ff1a929deffae4e Mon Sep 17 00:00:00 2001 From: Aomsir Date: Sun, 25 Oct 2026 17:02:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(grok):=20=E8=AF=8A=E6=96=AD=E6=96=87?= =?UTF-8?q?=E6=A1=88=E4=B8=8D=E5=86=8D=E8=AF=BB=E5=8F=96=E7=BB=A7=E6=89=BF?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../account/GrokModelDiagnosticsPanel.vue | 11 ++-- .../GrokModelDiagnosticsPanel.spec.ts | 50 +++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/account/GrokModelDiagnosticsPanel.vue b/frontend/src/components/account/GrokModelDiagnosticsPanel.vue index f1fa64ef8a..2104c1a59d 100644 --- a/frontend/src/components/account/GrokModelDiagnosticsPanel.vue +++ b/frontend/src/components/account/GrokModelDiagnosticsPanel.vue @@ -260,6 +260,12 @@ const ERROR_LABEL_KEYS: Record = { too_large: 'admin.accounts.grokModelDiagnostics.errorTooLarge', persistence: 'admin.accounts.grokModelDiagnostics.errorPersistence' } + +function ownedLabelKey(table: Record, value: string | undefined): string | undefined { + if (!value || !Object.prototype.hasOwnProperty.call(table, value)) return undefined + return table[value] +} + let timer: ReturnType | undefined onMounted(() => { @@ -377,14 +383,13 @@ const stateClass = computed(() => { const attemptLabel = computed(() => { const status = props.diagnostics?.last_attempt?.status if (!status) return '' - return t(ATTEMPT_LABEL_KEYS[status] ?? 'admin.accounts.grokModelDiagnostics.attemptUnknown') + return t(ownedLabelKey(ATTEMPT_LABEL_KEYS, status) ?? 'admin.accounts.grokModelDiagnostics.attemptUnknown') }) const attemptErrorLabel = computed(() => { const attempt = props.diagnostics?.last_attempt if (!attempt || attempt.status !== 'failed') return '' - const key = attempt.error_code ? ERROR_LABEL_KEYS[attempt.error_code] : undefined - return t(key ?? 'admin.accounts.grokModelDiagnostics.attemptUnavailable') + return t(ownedLabelKey(ERROR_LABEL_KEYS, attempt.error_code) ?? 'admin.accounts.grokModelDiagnostics.attemptUnavailable') }) const attemptDetail = computed(() => { diff --git a/frontend/src/components/account/__tests__/GrokModelDiagnosticsPanel.spec.ts b/frontend/src/components/account/__tests__/GrokModelDiagnosticsPanel.spec.ts index 1c09591fa3..945735623a 100644 --- a/frontend/src/components/account/__tests__/GrokModelDiagnosticsPanel.spec.ts +++ b/frontend/src/components/account/__tests__/GrokModelDiagnosticsPanel.spec.ts @@ -686,6 +686,56 @@ describe('GrokModelDiagnosticsPanel', () => { expect(attempt).not.toContain('上游请求失败') }) + it.each(['__proto__', 'constructor', 'toString'] as const)( + 'treats inherited attempt status %s as unknown without showing it', + async (status) => { + const wrapper = track(mountPanel({ + diagnostics: freshDiagnostics({ + last_attempt: { + started_at: '2026-10-25T11:50:00.000Z', + finished_at: '2026-10-25T11:50:02.000Z', + status, + error_code: 'http_error' + } + }) + })) + expect(wrapper.get('[data-testid="grok-diagnostics-state"]').text()).toContain('当前有效') + await openDetails(wrapper) + const attempt = wrapper.get('[data-testid="grok-diagnostics-last-attempt"]').text() + expect(attempt).toContain('状态未知') + expect(attempt).not.toContain(status) + expect(attempt).not.toContain('http_error') + expect(attempt).not.toContain('上游请求失败') + expect(attempt).not.toContain('[object Object]') + } + ) + + it.each(['__proto__', 'constructor', 'toString'] as const)( + 'treats inherited error code %s as unavailable without showing it', + async (code) => { + const wrapper = track(mountPanel({ + diagnostics: freshDiagnostics({ + last_attempt: { + started_at: '2026-10-25T11:50:00.000Z', + finished_at: '2026-10-25T11:50:02.000Z', + status: 'failed', + error_code: code + } + }) + })) + expect(wrapper.get('[data-testid="grok-diagnostics-state"]').text()).toContain('同步失败') + expect(wrapper.text()).toContain('同步未成功,请稍后重试') + expect(wrapper.text()).not.toContain(code) + expect(wrapper.text()).not.toContain('[object Object]') + await openDetails(wrapper) + const attempt = wrapper.get('[data-testid="grok-diagnostics-last-attempt"]').text() + expect(attempt).toContain('同步失败') + expect(attempt).toContain('同步未成功,请稍后重试') + expect(attempt).not.toContain(code) + expect(attempt).not.toContain('failed') + } + ) + it('shows a fresh snapshot gap as the previous catalog when the latest attempt fell back', async () => { const attemptFinished = '2026-10-25T11:40:00.000Z' const wrapper = track(mountPanel({