mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-11 17:23:48 +08:00
- 基于 TypeScript AST 精确识别 readFileSync 派生变量及其断言,仅删除不改写保留代码 - 断言全为源码文本的 it() 块整块移除,混合块中只剔除单条源码断言 - 清理随之失效的变量声明、空 it()/describe() 与无用 import,6 个文件因无用例残留而删除 - 累计移除 1283 处代码区间、8270 行,守卫基线由 130 条收敛至 12 条 - 全量测试失败集合无新增,TabManager 悬浮信息用例的 CRLF 误报一并消除 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
48 lines
2.4 KiB
TypeScript
48 lines
2.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { buildEditableTriggerSql } from './triggerEditSql';
|
|
|
|
describe('triggerEditSql', () => {
|
|
it('builds a replace-style trigger edit script with drop and create statements', () => {
|
|
const sql = buildEditableTriggerSql(
|
|
'bit_check',
|
|
'CREATE TRIGGER `bit_check`\nBEFORE INSERT ON `c_check`\nFOR EACH ROW\nBEGIN\n SET NEW.flag = 1;\nEND',
|
|
{ dropSql: 'DROP TRIGGER IF EXISTS `bit_check`' },
|
|
);
|
|
|
|
expect(sql).toContain('-- Edit trigger: bit_check');
|
|
expect(sql).toContain('The table design change will drop the original trigger before creating a new one');
|
|
expect(sql).toContain('DROP TRIGGER IF EXISTS `bit_check`;');
|
|
expect(sql).toContain('CREATE TRIGGER `bit_check`');
|
|
expect(sql.trim().endsWith(';')).toBe(true);
|
|
});
|
|
|
|
it('localizes editable trigger SQL comments while keeping SQL and names raw', () => {
|
|
const translate = (key: string, params?: Record<string, unknown>): string => {
|
|
const values: Record<string, string> = {
|
|
'trigger_viewer.edit_sql.header': 'Edit trigger: {{name}}',
|
|
'trigger_viewer.edit_sql.replace_hint': 'The original trigger will be dropped before recreating it.',
|
|
'trigger_viewer.edit_sql.compatibility_hint': 'Review compatibility with the current database before running.',
|
|
'trigger_viewer.edit_sql.empty_definition': 'The trigger definition is empty. Complete the CREATE TRIGGER statement before running.',
|
|
'trigger_viewer.edit_sql.fragment_definition': 'Only a trigger definition fragment was returned. Complete the CREATE TRIGGER statement before running.',
|
|
};
|
|
return (values[key] || key).replace(/\{\{(\w+)\}\}/g, (_, name) => String(params?.[name] ?? ''));
|
|
};
|
|
|
|
const sql = buildEditableTriggerSql(
|
|
'bit_check',
|
|
'BEGIN\n SET NEW.flag = 1;\nEND',
|
|
{ dropSql: 'DROP TRIGGER IF EXISTS `bit_check`', translate },
|
|
);
|
|
|
|
expect(sql).toContain('-- Edit trigger: bit_check');
|
|
expect(sql).toContain('-- The original trigger will be dropped before recreating it.');
|
|
expect(sql).toContain('-- Only a trigger definition fragment was returned. Complete the CREATE TRIGGER statement before running.');
|
|
expect(sql).toContain('DROP TRIGGER IF EXISTS `bit_check`;');
|
|
expect(sql).toContain('bit_check');
|
|
expect(sql).toContain('CREATE TRIGGER');
|
|
expect(sql).not.toContain('修改触发器');
|
|
expect(sql).not.toContain('请补全 CREATE TRIGGER 语句');
|
|
});
|
|
});
|