From 8a142dccf2b5e6d023fcdc1871de688bb3c184b6 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 8 Oct 2026 22:41:01 +0200 Subject: [PATCH] Reevaluate automatic coverage on time tag events --- app/workflows/engine.py | 4 +++- tests/test_workflow_automatic_coverage.py | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/workflows/engine.py b/app/workflows/engine.py index 552d360..2769e17 100644 --- a/app/workflows/engine.py +++ b/app/workflows/engine.py @@ -153,7 +153,9 @@ def evaluate(workflows, context, trigger): break 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} - 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) trace.append({'source': 'resource_coverage', 'matched': bool(automatic), 'choices': automatic}) if len(automatic) > 1: diff --git a/tests/test_workflow_automatic_coverage.py b/tests/test_workflow_automatic_coverage.py index 7a05c52..84d01cf 100644 --- a/tests/test_workflow_automatic_coverage.py +++ b/tests/test_workflow_automatic_coverage.py @@ -125,3 +125,10 @@ def test_automatic_evaluation_does_not_mutate_resources_or_context(): before = deepcopy(supplied) evaluate([], supplied, 'time.created') 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'