Reevaluate automatic coverage on time tag events

This commit is contained in:
Christian 2026-10-08 22:41:01 +02:00
parent b499b2dfea
commit 8a142dccf2
2 changed files with 10 additions and 1 deletions

View File

@ -153,7 +153,9 @@ def evaluate(workflows, context, trigger):
break break
if context.get('pending_billing_tag_suggestions') or any(action['type']=='suggest_tag' for action in actions): if context.get('pending_billing_tag_suggestions') or any(action['type']=='suggest_tag' for action in actions):
return {'status': 'manual_review', 'method': None, 'reason': 'pending_tag_approval', 'actions': actions, 'trace': trace} return {'status': 'manual_review', 'method': None, 'reason': 'pending_tag_approval', 'actions': actions, 'trace': trace}
if selected is None and not stopped and not context.get('target_workflow_id') and trigger in ('time.created', 'time.updated'): time_coverage_trigger = trigger in ('time.created', 'time.updated') or (
context.get('entity_type') in ('time', 'time_entry') and trigger in ('tags.added', 'tags.removed', 'tags.changed'))
if selected is None and not stopped and not context.get('target_workflow_id') and time_coverage_trigger:
automatic = automatic_coverage_choices(context) automatic = automatic_coverage_choices(context)
trace.append({'source': 'resource_coverage', 'matched': bool(automatic), 'choices': automatic}) trace.append({'source': 'resource_coverage', 'matched': bool(automatic), 'choices': automatic})
if len(automatic) > 1: if len(automatic) > 1:

View File

@ -125,3 +125,10 @@ def test_automatic_evaluation_does_not_mutate_resources_or_context():
before = deepcopy(supplied) before = deepcopy(supplied)
evaluate([], supplied, 'time.created') evaluate([], supplied, 'time.created')
assert supplied == before assert supplied == before
@pytest.mark.parametrize('trigger', ['tags.added', 'tags.removed', 'tags.changed'])
def test_time_tag_events_retain_automatic_coverage(trigger):
context = {'entity_type': 'time_entry', 'tag_ids': [7], 'agreements': [{'id': 2, 'workflow_coverage': {'tag_ids': [7]}}]}
assert evaluate([], context, trigger)['method'] == 'subscription'
context['tag_ids'] = []
assert evaluate([], context, trigger)['status'] == 'manual_review'