// 已读取AGENTS.md import * as fs from 'fs'; import * as path from 'path'; /** * 第七十九批:大神关键词搜索(服务端)。 */ describe('第七十九批大神搜索闸门', () => { const root = path.resolve(__dirname, '../../'); const indexCode = fs.readFileSync(path.join(root, 'server/src/index.ts'), 'utf-8'); const repo = fs.readFileSync(path.join(root, 'server/src/db/repository.ts'), 'utf-8'); const api = fs.readFileSync(path.join(root, 'pwuniapp/common/api.js'), 'utf-8'); const home = fs.readFileSync(path.join(root, 'pwuniapp/pages/index/index.vue'), 'utf-8'); it('后端支持关键词搜索(参数化,避免注入)', () => { expect(indexCode).toContain('req.query.keyword'); expect(repo).toContain('async getCompanions(keyword?: string)'); expect(repo).toContain('WHERE name LIKE ? OR track LIKE ? OR rank_name LIKE ?'); }); it('小程序搜索走服务端并做防抖', () => { expect(api).toContain('export async function getCompanions(keyword)'); expect(api).toContain('encodeURIComponent(kw)'); expect(home).toContain('watch(searchKeyword'); expect(home).toContain('fetchLiveCompanions'); }); });