feat: add source-owned combat mechanic programs

This commit is contained in:
JB
2026-07-27 13:35:00 -04:00
parent 5a67b252aa
commit 4eb754e7c8
62 changed files with 14815 additions and 905 deletions
@@ -0,0 +1,76 @@
import { describe, expect, it } from 'vitest';
import { conditionalRuleDraftFromRows } from './conditional-effects.js';
const rule = {
id: 'rule-1',
simulation_readiness: 'simulation_ready',
scenario_inputs_json: '[]'
};
const clause = {
id: 'clause-1',
rule_id: 'rule-1',
clause_key: 'hit',
label: 'Hit',
event_kind: 'weapon_hit',
conditions_json: '{"kind":"true"}',
reducer_json: '{"kind":"none"}',
mutations_json: '[]',
sort_order: 1,
active: 1
};
const outcome = {
rule_id: 'rule-1',
clause_id: 'clause-1',
effect_key: 'damage',
outcome_key: 'Damage',
application_kind: 'active_modifier',
effect_scope: 'self',
stat_attribute_id: 'weapon-damage',
value_basis: 'flat',
value_scaling: 'flat',
damage_basis: null,
application_phase: 'while_active',
combat_timing: 'current',
resource_kind: null,
state_pool_id: null,
min_state_value: null,
max_state_value: null,
description_slot: 1,
value: 3,
value_expression_json: null
};
describe('conditional mechanic persistence adapter', () => {
it('rejects divergent metadata across value variants', () => {
expect(() => conditionalRuleDraftFromRows(
rule,
[],
[clause],
[
{ ...outcome, variant_key: 'I' },
{ ...outcome, variant_key: 'II', application_phase: 'after_event', value: 5 }
],
['I', 'II']
)).toThrow(/inconsistent application_phase metadata/);
});
it('loads consistent value variants into one outcome', () => {
const draft = conditionalRuleDraftFromRows(
rule,
[],
[clause],
[
{ ...outcome, variant_key: 'I' },
{ ...outcome, variant_key: 'II', value: 5 }
],
['I', 'II']
);
expect(draft?.clauses[0].outcomes[0].variants).toEqual({
I: { value: 3 },
II: { value: 5 }
});
});
});