import { readFileSync } from 'fs' import { resolve } from 'path' // 契约:recipe.noFallback(生成失败必须明确报错,不再静默降级为规则兜底菜单) const SVC = resolve(__dirname, '../../../cfc-backend/src/main/java/com/etotem/cfc/service/DietRecommendationService.java') const VUE = resolve(__dirname, '../../pages/diet/recommendation.vue') const svc = readFileSync(SVC, 'utf8') const vue = readFileSync(VUE, 'utf8') describe('食谱生成失败显式报错(无兜底)', () => { test('生成主链路不再调用 buildFallbackMenu', () => { // 主链路(generateRecommendation 方法体内)不得出现兜底调用 const start = svc.indexOf('public Map generateRecommendation') const end = svc.indexOf('public Map regenerateRecommendation') expect(start).toBeGreaterThan(-1) expect(end).toBeGreaterThan(start) const body = svc.slice(start, end) expect(body).not.toMatch(/buildFallbackMenu/) }) test('AI 空结果 / 结构不完整时抛出明确错误', () => { expect(svc).toMatch(/throw new IllegalArgumentException\([^\n]*生成失败/) expect(svc).toMatch(/throw new IllegalArgumentException\([^\n]*AI/) }) test('前端生成失败 toast 显示后端原因而非固定文案', () => { const i = vue.indexOf('generateRecipe: function') expect(i).toBeGreaterThan(-1) const body = vue.slice(i, i + 1600) expect(body).toMatch(/var reason[^\n]*message/) }) })