"use strict";
/**
 * test_workflow_condition_parser.ts — Story 10.3
 *
 * Asserts the AND / OR / NOT / == / != boolean expression parser
 * and its backward-compat with v1.2/v1.3 bare-identifier semantics.
 *
 * 10 scenarios.
 */
Object.defineProperty(exports, "__esModule", { value: true });
const ConditionParser_1 = require("./orchestrator/workflow/ConditionParser");
function assertTrue(cond, label) {
    if (!cond)
        throw new Error(`ASSERT_FAILED[${label}]`);
}
// 1. Backward-compat: bare identifier
assertTrue((0, ConditionParser_1.evaluateCondition)('user_wants_ai', { user_wants_ai: true }) === true, '1: bare identifier truthy');
assertTrue((0, ConditionParser_1.evaluateCondition)('user_wants_ai', { user_wants_ai: false }) === false, '1b: bare identifier false');
console.log('[10.3] scenario 1 (bare identifier) ✓');
// 2. AND
assertTrue((0, ConditionParser_1.evaluateCondition)('a AND b', { a: true, b: true }) === true, '2a: a=t & b=t');
assertTrue((0, ConditionParser_1.evaluateCondition)('a AND b', { a: true, b: false }) === false, '2b: a=t & b=f');
console.log('[10.3] scenario 2 (AND) ✓');
// 3. OR
assertTrue((0, ConditionParser_1.evaluateCondition)('a OR b', { a: false, b: true }) === true, '3a: a=f | b=t');
assertTrue((0, ConditionParser_1.evaluateCondition)('a OR b', { a: false, b: false }) === false, '3b: a=f | b=f');
console.log('[10.3] scenario 3 (OR) ✓');
// 4. NOT
assertTrue((0, ConditionParser_1.evaluateCondition)('NOT a', { a: false }) === true, '4a: !false');
assertTrue((0, ConditionParser_1.evaluateCondition)('NOT a', { a: true }) === false, '4b: !true');
console.log('[10.3] scenario 4 (NOT) ✓');
// 5. Equality with string literal
assertTrue((0, ConditionParser_1.evaluateCondition)('mode == "elite"', { mode: 'elite' }) === true, '5: mode == elite');
assertTrue((0, ConditionParser_1.evaluateCondition)('mode == "elite"', { mode: 'quick' }) === false, '5b: mode != elite');
console.log('[10.3] scenario 5 (== string) ✓');
// 6. Inequality with number
assertTrue((0, ConditionParser_1.evaluateCondition)('score != 0', { score: 5 }) === true, '6: score != 0');
assertTrue((0, ConditionParser_1.evaluateCondition)('score != 0', { score: 0 }) === false, '6b: score == 0');
console.log('[10.3] scenario 6 (!= number) ✓');
// 7. Parentheses + precedence
// (a OR b) AND NOT c
assertTrue((0, ConditionParser_1.evaluateCondition)('(a OR b) AND NOT c', { a: true, b: false, c: false }) === true, '7: precedence');
assertTrue((0, ConditionParser_1.evaluateCondition)('(a OR b) AND NOT c', { a: true, b: false, c: true }) === false, '7b: precedence c=t');
console.log('[10.3] scenario 7 (parentheses + precedence) ✓');
// 8. Nested object access via dot
assertTrue((0, ConditionParser_1.evaluateCondition)('user.is_admin', { user: { is_admin: true } }) === true, '8: nested truthy');
assertTrue((0, ConditionParser_1.evaluateCondition)('user.role == "owner"', { user: { role: 'owner' } }) === true, '8b: nested ==');
console.log('[10.3] scenario 8 (dotted identifier) ✓');
// 9. Unknown variable defaults to false
assertTrue((0, ConditionParser_1.evaluateCondition)('never_set', {}) === false, '9: unknown ident → false');
assertTrue((0, ConditionParser_1.evaluateCondition)('a OR never_set', { a: true }) === true, '9b: unknown in OR');
console.log('[10.3] scenario 9 (unknown var) ✓');
// 10. Empty/invalid expressions
assertTrue((0, ConditionParser_1.evaluateCondition)('', {}) === true, '10a: empty → true (no condition)');
assertTrue((0, ConditionParser_1.evaluateCondition)(undefined, {}) === true, '10b: undefined → true');
assertTrue((0, ConditionParser_1.evaluateCondition)('(((unbalanced', {}) === false, '10c: parse failure → false');
console.log('[10.3] scenario 10 (empty + invalid) ✓');
// 11. Parser direct API
const p = (0, ConditionParser_1.parseCondition)('a AND (b OR NOT c)');
assertTrue(p.ok && p.ast?.kind === 'and', '11: AST shape');
assertTrue((0, ConditionParser_1.evaluate)(p.ast, { a: true, b: false, c: false }) === true, '11b: eval');
console.log('[10.3] scenario 11 (parse API) ✓');
console.log('TEST_WORKFLOW_CONDITION_PARSER_OK');
