|
622 | 622 | assert_eq "test_error_sweep_header_references_step_2_9" "found" "$has_step_29_ref" |
623 | 623 | assert_pass_if_clean "test_error_sweep_header_references_step_2_9" |
624 | 624 |
|
| 625 | +# --------------------------------------------------------------------------- |
| 626 | +# test_ticket_deduplicates_error_details |
| 627 | +# Counter with 50 errors, mostly duplicates. Assert ticket description contains |
| 628 | +# deduplicated entries (unique by tool_name + error_message), not raw duplicates. |
| 629 | +# --------------------------------------------------------------------------- |
| 630 | +_snapshot_fail |
| 631 | +_setup_test |
| 632 | +trap '_teardown_test' EXIT |
| 633 | +# Build counter with 50 permission_denied errors: 45 identical + 3 different + 2 more identical |
| 634 | +_DEDUP_ERRORS='[]' |
| 635 | +_DEDUP_ERRORS=$(python3 -c " |
| 636 | +import json |
| 637 | +errors = [] |
| 638 | +# 45 identical errors |
| 639 | +for i in range(45): |
| 640 | + errors.append({'category':'permission_denied','timestamp':f'2026-03-15T10:{i:02d}:00Z','tool_name':'Bash','input_summary':'Bash: rm /protected/file.txt','error_message':'permission denied: /protected/file.txt','session_id':f's{i}'}) |
| 641 | +# 3 different errors |
| 642 | +errors.append({'category':'permission_denied','timestamp':'2026-03-15T11:00:00Z','tool_name':'Read','input_summary':'Read: /etc/shadow','error_message':'permission denied: /etc/shadow','session_id':'s45'}) |
| 643 | +errors.append({'category':'permission_denied','timestamp':'2026-03-15T11:01:00Z','tool_name':'Bash','input_summary':'Bash: chmod 777 /root','error_message':'permission denied: /root','session_id':'s46'}) |
| 644 | +errors.append({'category':'permission_denied','timestamp':'2026-03-15T11:02:00Z','tool_name':'Write','input_summary':'Write: /usr/bin/test','error_message':'permission denied: /usr/bin/test','session_id':'s47'}) |
| 645 | +# 2 more duplicates of the first pattern |
| 646 | +for i in range(2): |
| 647 | + errors.append({'category':'permission_denied','timestamp':f'2026-03-15T12:{i:02d}:00Z','tool_name':'Bash','input_summary':'Bash: rm /protected/file.txt','error_message':'permission denied: /protected/file.txt','session_id':f's{48+i}'}) |
| 648 | +print(json.dumps({'index':{'permission_denied':50},'errors':errors})) |
| 649 | +") |
| 650 | +_write_counter_with_errors "$_DEDUP_ERRORS" |
| 651 | +_mock_tk_list_empty |
| 652 | +_run_sweep |
| 653 | +# Ticket should be created |
| 654 | +create_calls=$(_count_tk_create_calls) |
| 655 | +assert_eq "test_ticket_deduplicates_created" "1" "$create_calls" |
| 656 | +# Get the full tk log to check description content |
| 657 | +tk_log_content=$(cat "$TK_LOG" 2>/dev/null || true) |
| 658 | +# Should contain all 4 unique error signatures (not 20 raw duplicates) |
| 659 | +assert_contains "test_ticket_dedup_has_protected_file" "/protected/file.txt" "$tk_log_content" |
| 660 | +assert_contains "test_ticket_dedup_has_etc_shadow" "/etc/shadow" "$tk_log_content" |
| 661 | +assert_contains "test_ticket_dedup_has_root" "/root" "$tk_log_content" |
| 662 | +assert_contains "test_ticket_dedup_has_usr_bin" "/usr/bin/test" "$tk_log_content" |
| 663 | +# Should show occurrence counts — the 47 identical errors should show count |
| 664 | +assert_contains "test_ticket_dedup_has_occurrence_count" "47" "$tk_log_content" |
| 665 | +# Should NOT have 20 rows of the same error — check that "Bash" tool appears |
| 666 | +# a reasonable number of times (deduplicated, not raw). In raw mode, "Bash" would |
| 667 | +# appear 20 times in the table. Deduplicated, it should appear much fewer times. |
| 668 | +_bash_row_count=$(echo "$tk_log_content" | grep -c "| Bash |" 2>/dev/null || echo "0") |
| 669 | +# With dedup: 2 unique Bash signatures. Without dedup: 20 rows showing Bash. |
| 670 | +# Assert <= 5 to allow some formatting flexibility but catch raw dump. |
| 671 | +if [[ "$_bash_row_count" -le 5 ]]; then |
| 672 | + _dedup_ok="yes" |
| 673 | +else |
| 674 | + _dedup_ok="no" |
| 675 | +fi |
| 676 | +assert_eq "test_ticket_dedup_not_raw_dump" "yes" "$_dedup_ok" |
| 677 | +assert_pass_if_clean "test_ticket_deduplicates_error_details" |
| 678 | +trap - EXIT |
| 679 | +_teardown_test |
| 680 | + |
625 | 681 | print_summary |
0 commit comments