File size: 7,286 Bytes
123559e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import os
import unittest
from types import SimpleNamespace
from unittest.mock import patch

from app.routers.calls import _evaluation_summary, _pipeline_progress


def _job(status, stage):
    return SimpleNamespace(status=status, stage=stage)


class PipelineProgressTests(unittest.TestCase):
    def test_active_stage_completes_every_prior_enabled_step(self):
        with patch.dict(
            os.environ,
            {
                "ENABLE_ACOUSTIC": "1",
                "EVALUATOR_V2_SHADOW": "1",
            },
        ):
            progress = _pipeline_progress(
                _job("processing", "evaluating_v2_requirements")
            )

        states = {
            stage["id"]: stage["state"]
            for stage in progress["stages"]
        }
        self.assertEqual(states["evaluation"], "completed")
        self.assertEqual(states["evidence"], "completed")
        self.assertEqual(states["requirements"], "active")
        self.assertEqual(states["findings"], "pending")
        self.assertEqual(states["publish"], "pending")
        self.assertEqual(
            progress["current_stage_label"],
            "Assess requirements",
        )

    def test_forced_transcription_starts_in_the_queue(self):
        progress = _pipeline_progress(
            _job("queued", "force_uploaded")
        )

        self.assertEqual(progress["current_stage_id"], "queued")
        self.assertEqual(progress["percent"], 0)
        self.assertEqual(progress["stages"][0]["state"], "active")

    def test_disabled_optional_stages_are_marked_skipped(self):
        with patch.dict(
            os.environ,
            {
                "ENABLE_ACOUSTIC": "0",
                "EVALUATOR_V2_SHADOW": "0",
            },
        ):
            progress = _pipeline_progress(
                _job("processing", "evaluating")
            )

        states = {
            stage["id"]: stage["state"]
            for stage in progress["stages"]
        }
        self.assertEqual(states["acoustic"], "completed")
        self.assertEqual(states["evidence"], "skipped")
        self.assertEqual(states["requirements"], "skipped")
        self.assertEqual(states["findings"], "skipped")
        self.assertEqual(states["decision"], "skipped")
        self.assertEqual(states["presentation"], "skipped")
        self.assertEqual(states["evaluation"], "active")

    def test_success_marks_enabled_pipeline_complete(self):
        with patch.dict(
            os.environ,
            {
                "ENABLE_ACOUSTIC": "1",
                "EVALUATOR_V2_SHADOW": "0",
            },
        ):
            progress = _pipeline_progress(_job("succeeded", "done"))

        enabled_states = [
            stage["state"]
            for stage in progress["stages"]
            if stage["state"] != "skipped"
        ]
        self.assertEqual(set(enabled_states), {"completed"})
        self.assertEqual(progress["percent"], 100)

    def test_failure_marks_current_stage(self):
        with patch.dict(
            os.environ,
            {
                "ENABLE_ACOUSTIC": "1",
                "EVALUATOR_V2_SHADOW": "0",
            },
        ):
            progress = _pipeline_progress(
                _job("failed", "segmenting")
            )

        current = next(
            stage
            for stage in progress["stages"]
            if stage["id"] == "segments"
        )
        self.assertEqual(current["state"], "failed")


class EvaluationSummaryTests(unittest.TestCase):
    def test_success_uses_evaluator_presentation_not_legacy_scores(self):
        run = SimpleNamespace(
            status="succeeded",
            created_at=None,
            payload={
                "status": "succeeded",
                "evaluator_version": "v2-policy-test",
                "decision": {
                    "decision_status": "complete",
                    "attention_required": True,
                },
                "presentation": {
                    "state": "needs_attention",
                    "evaluation_status": "complete",
                    "attention_required": True,
                    "manager_questions": [
                        {
                            "question_id": "call.request",
                            "answer": "yes",
                            "summary": "Request confirmed.",
                            "evidence_ids": ["evidence-request"],
                        },
                        {
                            "question_id": "call.process",
                            "answer": "partly",
                            "summary": "One process concern.",
                            "evidence_ids": ["evidence-process"],
                        },
                        {
                            "question_id": "call.experience",
                            "answer": "yes",
                            "summary": "Experience handled.",
                            "evidence_ids": [],
                        },
                        {
                            "question_id": "call.outcome",
                            "answer": "yes",
                            "summary": "Outcome confirmed.",
                            "evidence_ids": ["evidence-outcome"],
                        },
                    ],
                    "primary_reasons": [{"finding_id": "finding-a"}],
                    "additional_reason_count": 1,
                    "checklist": [
                        {"status": "demonstrated"},
                        {"status": "incorrect"},
                        {"status": "not_demonstrated"},
                    ],
                    "acoustic_context": {
                        "status": "limited",
                        "coverage_label": "Audio support on 2 of 3 segments",
                    },
                },
            },
        )

        summary = _evaluation_summary("call-a", "banking", run)

        self.assertTrue(summary["evaluation_available"])
        self.assertTrue(summary["attention_required"])
        self.assertEqual(summary["evaluation_state"], "needs_attention")
        self.assertEqual(summary["result"], "review")
        self.assertEqual(summary["aspects"]["request"]["state"], "ok")
        self.assertEqual(summary["aspects"]["process"]["state"], "concern")
        self.assertEqual(summary["concern_count"], 2)
        self.assertEqual(summary["checklist_counts"]["demonstrated"], 1)
        self.assertEqual(summary["checklist_counts"]["incorrect"], 1)
        self.assertEqual(
            summary["checklist_counts"]["not_demonstrated"],
            1,
        )
        self.assertEqual(summary["acoustic_status"], "limited")

    def test_domain_without_profile_is_not_reported_as_evaluated(self):
        summary = _evaluation_summary(
            "call-b",
            "health",
            SimpleNamespace(
                status="unsupported_domain",
                created_at=None,
                payload={"status": "unsupported_domain"},
            ),
        )

        self.assertFalse(summary["evaluation_available"])
        self.assertTrue(summary["evaluation_supported"])
        self.assertEqual(summary["evaluation_state"], "unsupported")


if __name__ == "__main__":
    unittest.main()