#!/usr/bin/env python3 """Canonical Manual QA Excel Workbook Generator for AI-Native Unified Process. Standardized per UP-AI v1.0 Quality Standard. Compiles a 21-sheet, 30-column Excel workbook under: 04_generated_documentation/07_test_design/manual_qa/workbooks/IterationNN__Complete_Manual_Testcases.xlsx """ import argparse import os import sys from pathlib import Path try: import openpyxl from openpyxl.styles import Alignment, Border, Font, PatternFill, Side from openpyxl.utils import get_column_letter except ImportError: print("Error: openpyxl is required. Run via 'uv run --with openpyxl python3 scripts/generate_manual_qa_workbook.py'") sys.exit(1) COLUMNS = [ "Test Case ID", "Test Case Name", "Test Objective / Description", "Scope Status", "Related BRD Requirement ID(s)", "Related Use Case ID(s)", "Related FR ID(s)", "Related SRS / NFR ID(s)", "Related Story ID(s)", "Related Business Rule / Acceptance Criterion", "Related HLD / LLD / Contract Reference", "Related Screen / Route / API / Data / Integration Surface", "Actor / Role / Portal", "Test Category", "Test Level", "Priority", "Preconditions", "Test Steps", "Test Data", "Expected Result", "Prohibited Side Effects", "Postconditions / Cleanup", "Result (Dev)", "Result (Staging)", "Result (Production)", "Actual Result / Evidence", "Defect Reference", "Comment", "Source References", "Execution Type" ] TEST_CATEGORIES = [ ("Functional_Testcase", "Functional"), ("Validation_Testcase", "Validation"), ("Boundary-Value_Testcase", "Boundary-Value"), ("Negative_Testcase", "Negative"), ("Security_Testcase", "Security"), ("Database_Testcase", "Database"), ("API_Testcase", "API"), ("Performance_Testcase", "Performance"), ("UAT_Testcase", "UAT"), ("Integration_Testcase", "Integration"), ("CrossBrowser_Testcase", "CrossBrowser"), ("Accessibility_Testcase", "Accessibility"), ("Mobile-Responsive_Testcase", "Mobile-Responsive"), ("AI-ML_Testcase", "AI-ML"), ("Regression_Testcase", "Regression"), ("Automation_Testcase", "Automation"), ] def build_workbook(iteration: str, name: str, output_path: str, cases_by_category: dict = None, manifest_rows: list = None, summary_metadata: list = None, notes: list = None, traceability_rows: list = None): wb = openpyxl.Workbook() wb.remove(wb.active) navy_fill = PatternFill(start_color="001F4E78", end_color="001F4E78", fill_type="solid") header_font = Font(name="Calibri", size=11, bold=True, color="FFFFFF") bold_font = Font(name="Calibri", size=11, bold=True) regular_font = Font(name="Calibri", size=10) thin_border = Border( left=Side(style="thin", color="D9D9D9"), right=Side(style="thin", color="D9D9D9"), top=Side(style="thin", color="D9D9D9"), bottom=Side(style="thin", color="D9D9D9"), ) # 1. Coverage_Summary ws_cov = wb.create_sheet(title="Coverage_Summary") ws_cov.append(["Field", "Value"]) for cell in ws_cov[1]: cell.fill = navy_fill cell.font = header_font if not summary_metadata: summary_metadata = [ ("Scope Name", f"Iteration {iteration} Complete Manual QA — {name}"), ("Process Baseline", "AI_Native_Unified_Process_v1.md (UP-AI v1.0)"), ("Status", "Approved / Verified via Stage 12 & Gate 14.1"), ] for k, v in summary_metadata: ws_cov.append([k, v]) for row in ws_cov.iter_rows(min_row=2): row[0].font = bold_font row[1].font = regular_font for cell in row: cell.border = thin_border ws_cov.column_dimensions["A"].width = 30 ws_cov.column_dimensions["B"].width = 80 # 2. Scope_Manifest ws_scope = wb.create_sheet(title="Scope_Manifest") ws_scope.append(["Selector", "Resolved ID / Path", "Item Type", "Parent Chain", "Iteration", "Status", "Disposition"]) for cell in ws_scope[1]: cell.fill = navy_fill cell.font = header_font cell.alignment = Alignment(horizontal="center", vertical="center", wrap_text=True) if manifest_rows: for r in manifest_rows: ws_scope.append(r) for row in ws_scope.iter_rows(min_row=2): for cell in row: cell.font = regular_font cell.border = thin_border for col in ws_scope.columns: max_len = max(len(str(cell.value or '')) for cell in col) col_letter = get_column_letter(col[0].column) ws_scope.column_dimensions[col_letter].width = max(max_len + 2, 14) # 3. 16 Test Category Sheets cat_summary = [] cases_by_category = cases_by_category or {} for sheet_name, cat_title in TEST_CATEGORIES: ws = wb.create_sheet(title=sheet_name) ws.append(COLUMNS) for cell in ws[1]: cell.fill = navy_fill cell.font = header_font cell.alignment = Alignment(horizontal="center", vertical="center", wrap_text=True) cat_cases = cases_by_category.get(sheet_name, []) for c in cat_cases: if isinstance(c, list): row_val = c + [""] * (30 - len(c)) if len(c) < 30 else c[:30] ws.append(row_val) elif isinstance(c, dict): row_val = [c.get(col, "") for col in COLUMNS] ws.append(row_val) for row in ws.iter_rows(min_row=2): for cell in row: cell.font = regular_font cell.border = thin_border for col in ws.columns: max_len = max(len(str(cell.value or '')) for cell in col) col_letter = get_column_letter(col[0].column) ws.column_dimensions[col_letter].width = min(max(max_len + 2, 12), 40) tot_c = len(cat_cases) auto_c = sum(1 for c in cat_cases if (c[29] if isinstance(c, list) else c.get("Execution Type")) == "Automated") man_c = sum(1 for c in cat_cases if (c[29] if isinstance(c, list) else c.get("Execution Type")) == "Manual") both_c = sum(1 for c in cat_cases if (c[29] if isinstance(c, list) else c.get("Execution Type")) == "Both" or (c[29] if isinstance(c, list) else "").startswith("Automated +")) pct = f"{(auto_c + both_c) / tot_c * 100:.1f}%" if tot_c > 0 else "0.0%" cat_summary.append((sheet_name, tot_c, auto_c, man_c, both_c, pct)) # 4. Execution Summary ws_exec = wb.create_sheet(title="Execution Summary", index=1) ws_exec.append([f"Execution Summary - Iteration {iteration} {name}", "", "", "", "", ""]) ws_exec.append([]) ws_exec.append(["Test Category", "Total Test Cases", "Automation", "Manual", "Both", "Automation Percentage"]) for cell in ws_exec[3]: cell.fill = navy_fill cell.font = header_font tot_tc = sum(x[1] for x in cat_summary) tot_auto = sum(x[2] for x in cat_summary) tot_man = sum(x[3] for x in cat_summary) tot_both = sum(x[4] for x in cat_summary) overall_pct = f"{(tot_auto + tot_both) / tot_tc * 100:.1f}%" if tot_tc > 0 else "0.0%" for r in cat_summary: ws_exec.append(list(r)) ws_exec.append([]) ws_exec.append(["TOTAL", tot_tc, tot_auto, tot_man, tot_both, overall_pct]) for cell in ws_exec[ws_exec.max_row]: cell.font = bold_font for row in ws_exec.iter_rows(min_row=3): for cell in row: cell.border = thin_border for col in ws_exec.columns: max_len = max(len(str(cell.value or '')) for cell in col) col_letter = get_column_letter(col[0].column) ws_exec.column_dimensions[col_letter].width = max(max_len + 2, 16) # 5. Traceability_Matrix ws_tm = wb.create_sheet(title="Traceability_Matrix") ws_tm.append(["Use Case ID", "FR ID", "Story ID", "Test Case ID", "Test Category", "Portal / Surface", "Automation Status"]) for cell in ws_tm[1]: cell.fill = navy_fill cell.font = header_font cell.alignment = Alignment(horizontal="center", vertical="center", wrap_text=True) t_rows = traceability_rows if traceability_rows is not None else manifest_rows if t_rows: for r in t_rows: ws_tm.append(r) for row in ws_tm.iter_rows(min_row=2): for cell in row: cell.font = regular_font cell.border = thin_border for col in ws_tm.columns: max_len = max(len(str(cell.value or '')) for cell in col) col_letter = get_column_letter(col[0].column) ws_tm.column_dimensions[col_letter].width = max(max_len + 2, 14) # 6. Generation_Notes ws_notes = wb.create_sheet(title="Generation_Notes") ws_notes.append(["Note ID", "Section", "Detail"]) for cell in ws_notes[1]: cell.fill = navy_fill cell.font = header_font if notes: for n in notes: ws_notes.append(n) for row in ws_notes.iter_rows(min_row=2): for cell in row: cell.font = regular_font cell.border = thin_border for col in ws_notes.columns: max_len = max(len(str(cell.value or '')) for cell in col) col_letter = get_column_letter(col[0].column) ws_notes.column_dimensions[col_letter].width = max(max_len + 2, 16) out_file = Path(output_path) out_file.parent.mkdir(parents=True, exist_ok=True) wb.save(str(out_file)) print(f"Successfully compiled 21-sheet QA workbook at: {out_file} (Total Cases: {tot_tc})") def main(): parser = argparse.ArgumentParser(description="Compile 21-sheet Manual QA Excel Workbook") parser.add_argument("--iteration", required=True, help="Iteration number (e.g. 02, 03)") parser.add_argument("--name", required=True, help="Iteration Name (e.g. Customer_Vendor_Onboarding)") parser.add_argument("--output", help="Optional output path") args = parser.parse_args() default_out = f"04_generated_documentation/07_test_design/manual_qa/workbooks/Iteration{args.iteration}_{args.name}_Complete_Manual_Testcases.xlsx" out_path = args.output or default_out build_workbook(iteration=args.iteration, name=args.name, output_path=out_path) if __name__ == "__main__": main()