"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const prompt_translator_1 = require("../prompt-translator");
(0, vitest_1.describe)('translatePrompt', () => {
    const vars = [
        { key: 'area', description: '研究领域', initialValue: null },
        { key: 'ref_fp', description: '文献存储 bibtex 格式文件的路径', initialValue: null },
        { key: 'has_error', description: '文献存在错误', initialValue: null },
    ];
    (0, vitest_1.it)('替换 @{key} 为 key(description)=\'value\'', () => {
        const r = (0, prompt_translator_1.translatePrompt)('请调研@{area}', vars, { area: '逆合成' }, []);
        (0, vitest_1.expect)(r).toContain("area(研究领域)='逆合成'");
    });
    (0, vitest_1.it)('null 值显示为 null（不带引号）', () => {
        const r = (0, prompt_translator_1.translatePrompt)('@{area}', vars, { area: null }, []);
        (0, vitest_1.expect)(r).toContain('area(研究领域)=null');
    });
    (0, vitest_1.it)('替换 ${key} 为 update-variable 英文指令（v-19-b 起 prompt 英文化）', () => {
        const r = (0, prompt_translator_1.translatePrompt)('修改 ${has_error}', vars, { has_error: null }, ['has_error']);
        (0, vitest_1.expect)(r).toContain('Update variable has_error(文献存在错误; stored at .ccweb-flow-train.json under key:has_error). Current value: null. Write the new value.');
    });
    (0, vitest_1.it)('outputs 非空时追加系统指令段', () => {
        const r = (0, prompt_translator_1.translatePrompt)('do something ${has_error}', vars, { has_error: null }, ['has_error']);
        (0, vitest_1.expect)(r).toContain('[System Instructions]');
        (0, vitest_1.expect)(r).toContain('.ccweb-flow-train.json');
        (0, vitest_1.expect)(r).toContain('has_error');
    });
    (0, vitest_1.it)('outputs 为空时仍追加系统指令段（v-j：done flag 是完成信号源）', () => {
        const r = (0, prompt_translator_1.translatePrompt)('just ask @{area}', vars, { area: '逆合成' }, []);
        (0, vitest_1.expect)(r).toContain('[System Instructions]');
        (0, vitest_1.expect)(r).toContain('run-state.json');
        (0, vitest_1.expect)(r).toContain('.done');
    });
    (0, vitest_1.it)('ctx 传入时系统指令含具体 basename + nodeId', () => {
        const r = (0, prompt_translator_1.translatePrompt)('@{area}', vars, { area: 'x' }, [], { basename: 'flow1', nodeId: 'n_llm_a' });
        (0, vitest_1.expect)(r).toContain('.ccweb/tracks/flow1.run-state.json');
        (0, vitest_1.expect)(r).toContain('nodes.n_llm_a.done');
        (0, vitest_1.expect)(r).toContain('nodes.n_llm_a.failed');
    });
    (0, vitest_1.it)('done flag 指令对 LLM 多步操作友好（明确说"可多步后标"）', () => {
        const r = (0, prompt_translator_1.translatePrompt)('@{area}', vars, { area: 'x' }, [], { basename: 'flow1', nodeId: 'n1' });
        (0, vitest_1.expect)(r).toContain('you may perform multiple steps before marking');
    });
    (0, vitest_1.it)('placeholder nodeId 不带空格（默认 <node-id>，与 <basename> 风格一致）', () => {
        const r = (0, prompt_translator_1.translatePrompt)('@{area}', vars, { area: 'x' }, []);
        (0, vitest_1.expect)(r).toContain('<node-id>');
        (0, vitest_1.expect)(r).not.toContain('<node id>');
    });
    (0, vitest_1.it)('未声明的 key 保留字面（不替换）', () => {
        const r = (0, prompt_translator_1.translatePrompt)('@{未知}', vars, {}, []);
        (0, vitest_1.expect)(r).toContain('@{未知}');
    });
    (0, vitest_1.it)('完整研究循环 prompt（spec 例子）', () => {
        const tpl = '请检查@{ref_fp}中的论文，相关性 @{area}，结果 ${has_error}';
        const r = (0, prompt_translator_1.translatePrompt)(tpl, vars, { area: '逆合成', ref_fp: './test.bibtex', has_error: null }, ['has_error']);
        (0, vitest_1.expect)(r).toContain("ref_fp(文献存储 bibtex 格式文件的路径)='./test.bibtex'");
        (0, vitest_1.expect)(r).toContain("area(研究领域)='逆合成'");
        (0, vitest_1.expect)(r).toContain('Update variable has_error(文献存在错误;');
        (0, vitest_1.expect)(r).toContain('[System Instructions]');
    });
    (0, vitest_1.it)('codex P1 顺修：所有提及 run-state.json 的句子都用完整路径插值（防 LLM 误改根目录）', () => {
        const r = (0, prompt_translator_1.translatePrompt)('@{area}', vars, { area: 'x' }, [], { basename: 'flow1', nodeId: 'n1' });
        // 完整路径在多个句子中重复出现（path + done modify + failed modify + watch sentence）
        const matches = r.match(/\.ccweb\/tracks\/flow1\.run-state\.json/g) ?? [];
        (0, vitest_1.expect)(matches.length).toBeGreaterThanOrEqual(4);
    });
    (0, vitest_1.it)('codex P2 顺修：done/failed 互斥 + 禁动其他字段', () => {
        const r = (0, prompt_translator_1.translatePrompt)('@{area}', vars, { area: 'x' }, [], { basename: 'flow1', nodeId: 'n1' });
        (0, vitest_1.expect)(r).toContain('exactly one of `done` or `failed`');
        (0, vitest_1.expect)(r).toContain('Do not modify other fields');
    });
    (0, vitest_1.it)('数字值不加引号', () => {
        const r = (0, prompt_translator_1.translatePrompt)('@{n}', [{ key: 'n', description: '次数', initialValue: 0 }], { n: 42 }, []);
        (0, vitest_1.expect)(r).toContain('n(次数)=42');
        (0, vitest_1.expect)(r).not.toContain("n(次数)='42'");
    });
    (0, vitest_1.it)('boolean 值', () => {
        const r = (0, prompt_translator_1.translatePrompt)('@{f}', [{ key: 'f', description: '标志', initialValue: false }], { f: true }, []);
        (0, vitest_1.expect)(r).toContain('f(标志)=true');
    });
    (0, vitest_1.it)('object/array 值用 JSON.stringify', () => {
        const r = (0, prompt_translator_1.translatePrompt)('@{x}', [{ key: 'x', description: '数据', initialValue: null }], { x: { a: 1 } }, []);
        (0, vitest_1.expect)(r).toContain('x(数据)=\'{"a":1}\'');
    });
});
//# sourceMappingURL=prompt-translator.test.js.map