Skip to content

Commit dfca707

Browse files
author
ci bot
committed
Merge branch 'fix/TG-1135-mcp-qa-fixes' into 'enterprise'
fix(mcp): list_table_groups 500, profiling-run PII counts, schedule id display See merge request dkinternal/testgen/dataops-testgen!580
2 parents 676d753 + 098ded0 commit dfca707

4 files changed

Lines changed: 29 additions & 9 deletions

File tree

testgen/common/models/table_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ def _list_with_activity(
583583
latest_profile AS (
584584
SELECT pr.table_groups_id, MAX(je.started_at) AS started_at
585585
FROM profiling_runs pr
586-
LEFT JOIN job_executions je ON je.id = pr.job_execution_id
586+
LEFT JOIN job_executions je ON je.id = pr.id
587587
GROUP BY pr.table_groups_id
588588
),
589589
latest_test AS (

testgen/mcp/tools/profiling.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
DataColumnChars,
1515
)
1616
from testgen.common.models.data_table import DataTable
17+
from testgen.common.models.hygiene_issue import HygieneIssue
1718
from testgen.common.models.job_execution import JobExecution
1819
from testgen.common.models.profile_result import ProfileResult
1920
from testgen.common.models.profiling_run import ProfilingRun, ProfilingRunSummary
@@ -543,13 +544,19 @@ def get_profiling_run(job_execution_id: str) -> str:
543544
doc.field("Columns profiled", summary.column_ct or 0)
544545
if summary.record_ct is not None:
545546
doc.field("Records", summary.record_ct)
546-
doc.field(
547-
"Hygiene issues (confirmed)",
548-
f"{(summary.anomalies_definite_ct or 0) + (summary.anomalies_likely_ct or 0) + (summary.anomalies_possible_ct or 0)} total "
549-
f"— {summary.anomalies_definite_ct or 0} definite, "
550-
f"{summary.anomalies_likely_ct or 0} likely, "
551-
f"{summary.anomalies_possible_ct or 0} possible",
552-
)
547+
if summary.profiling_run_id:
548+
# Count from the canonical source so likelihood buckets and Potential PII
549+
# stay separate (matches the REST profiling-run issue_counts).
550+
counts = HygieneIssue.count_for_run(summary.profiling_run_id)
551+
hygiene = counts.hygiene_issues
552+
doc.field(
553+
"Hygiene issues (confirmed)",
554+
f"{hygiene.definite + hygiene.likely + hygiene.possible} total "
555+
f"— {hygiene.definite} definite, {hygiene.likely} likely, {hygiene.possible} possible",
556+
)
557+
pii = counts.potential_pii
558+
if pii.high or pii.moderate:
559+
doc.field("Potential PII", f"{pii.high} high, {pii.moderate} moderate")
553560
if summary.dq_score_profiling is not None:
554561
doc.field("Profiling Score", friendly_score(summary.dq_score_profiling))
555562

testgen/mcp/tools/schedules.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def create_profiling_schedule(
205205
active=active,
206206
)
207207
sched.save()
208+
get_current_session().flush() # populate the default-generated id before rendering
208209

209210
doc = MdDoc()
210211
doc.heading(1, f"Profiling schedule created for `{table_group.table_groups_name}`")
@@ -239,6 +240,7 @@ def create_test_run_schedule(
239240
active=active,
240241
)
241242
sched.save()
243+
get_current_session().flush() # populate the default-generated id before rendering
242244

243245
doc = MdDoc()
244246
doc.heading(1, f"Test run schedule created for `{suite.test_suite}`")

tests/unit/mcp/test_tools_profiling.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from testgen.common.models.data_column import ColumnProfileDetail, ColumnProfileSummary, DataColumnChars
8+
from testgen.common.models.hygiene_issue import HygieneIssueCounts, IssueCounts, PotentialPiiCounts
89
from testgen.common.pii_masking import PII_REDACTED
910
from testgen.mcp.exceptions import MCPResourceNotAccessible, MCPUserError
1011
from testgen.mcp.permissions import ProjectPermissions
@@ -635,15 +636,21 @@ def test_list_profiling_runs_malformed_schedule_raises(mock_tg_cls, mock_run_cls
635636
# ----------------------------------------------------------------------
636637

637638

639+
@patch("testgen.mcp.tools.profiling.HygieneIssue")
638640
@patch("testgen.mcp.tools.profiling.ProfilingRun")
639-
def test_get_profiling_run_returns_detail(mock_run_cls, db_session_mock):
641+
def test_get_profiling_run_returns_detail(mock_run_cls, mock_hygiene_cls, db_session_mock):
640642
summary = _mock_profiling_run()
641643
mock_run_cls.select_summary.return_value = ([summary], 1)
642644
mock_run = MagicMock(project_code="demo")
643645
mock_run_cls.get.return_value = mock_run
644646
mock_run_cls.select_table_breakdown.return_value = [
645647
MagicMock(schema_name="demo", table_name="orders", record_ct=1000, column_ct=5, anomaly_ct=2),
646648
]
649+
mock_hygiene_cls.count_for_run.return_value = IssueCounts(
650+
hygiene_issues=HygieneIssueCounts(definite=2, likely=2, possible=4),
651+
potential_pii=PotentialPiiCounts(high=0, moderate=8),
652+
dismissed=0,
653+
)
647654

648655
with patch("testgen.mcp.permissions._compute_project_permissions") as mock_compute:
649656
mock_compute.return_value = ProjectPermissions(
@@ -659,6 +666,10 @@ def test_get_profiling_run_returns_detail(mock_run_cls, db_session_mock):
659666
assert "Completed" in result
660667
assert "Per-table breakdown" in result
661668
assert "orders" in result
669+
# Hygiene breakdown comes from count_for_run, keeping Potential PII separate from "possible".
670+
mock_hygiene_cls.count_for_run.assert_called_once_with(summary.profiling_run_id)
671+
assert "8 total — 2 definite, 2 likely, 4 possible" in result
672+
assert "Potential PII:** 0 high, 8 moderate" in result
662673

663674

664675
@patch("testgen.mcp.tools.profiling.ProfilingRun")

0 commit comments

Comments
 (0)