/**
 * ============================================================
 *  src/workflows/stepExecutors/assert.ts —— assert step 执行
 * ------------------------------------------------------------
 *  evalExpr(condition) → 真值通过；假值抛错（带 onFail 自定义信息）。
 * ============================================================
 */
import { evalExpr, interpolate } from '../expressions.js';
export function execAssertStep(step, vars) {
    if (typeof step.condition !== 'string') {
        throw new Error(`step ${step.id}: assert 缺少 condition`);
    }
    let ok;
    try {
        // P2：表达式上下文直接 evalExpr（${} 由引擎原生处理），不再"先插值再 eval"。
        ok = Boolean(evalExpr(step.condition, vars));
    }
    catch (e) {
        throw new Error(`assert 表达式求值失败: ${e.message}`);
    }
    if (!ok) {
        const msg = step.onFail
            ? interpolate(step.onFail, vars)
            : `assertion failed: ${step.condition}`;
        throw new Error(msg);
    }
    return { raw: { ok: true }, preview: 'assert passed' };
}
