fix(grok): 诊断文案不再读取继承属性

This commit is contained in:
Aomsir committed 2026-10-25 17:02:27 +08:00
1 parent c68d312372
commit 32c00d6e72
2 files changed
+58 -3

No files matched your search

@@ -260,6 +260,12 @@ const ERROR_LABEL_KEYS: Record<string, string> = {
too_large: 'admin.accounts.grokModelDiagnostics.errorTooLarge',
persistence: 'admin.accounts.grokModelDiagnostics.errorPersistence'
}
function ownedLabelKey(table: Record<string, string>, value: string | undefined): string | undefined {
if (!value || !Object.prototype.hasOwnProperty.call(table, value)) return undefined
return table[value]
}
let timer: ReturnType<typeof setInterval> | 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(() => {
@@ -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({