< Summary

Information
Class: RoleRadar.Application.Tracking.Import.Report.TrackerImportReportGenerator
Assembly: RoleRadar.Application
File(s): /home/runner/work/roleradar/roleradar/src/RoleRadar.Application/Tracking/Import/Report/TrackerImportReportGenerator.cs
Line coverage
91%
Covered lines: 142
Uncovered lines: 14
Coverable lines: 156
Total lines: 273
Line coverage: 91%
Branch coverage
67%
Covered branches: 38
Total branches: 56
Branch coverage: 67.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IsInsideGitWorkTree(...)80%101090%
GenerateReportAsync()60.34%635888.57%

File(s)

/home/runner/work/roleradar/roleradar/src/RoleRadar.Application/Tracking/Import/Report/TrackerImportReportGenerator.cs

#LineLine coverage
 1using System.Globalization;
 2using System.Text;
 3using RoleRadar.Application.Tracking.Import.Commands;
 4
 5namespace RoleRadar.Application.Tracking.Import.Report;
 6
 7public static class TrackerImportReportGenerator
 8{
 9    public static bool IsInsideGitWorkTree(string path)
 10    {
 411        if (string.IsNullOrWhiteSpace(path))
 12        {
 013            return false;
 14        }
 15
 416        var fullPath = Path.GetFullPath(path);
 417        var dir = new DirectoryInfo(Path.GetDirectoryName(fullPath) ?? fullPath);
 18
 2019        while (dir is not null)
 20        {
 1821            if (Directory.Exists(Path.Combine(dir.FullName, ".git")) ||
 1822                File.Exists(Path.Combine(dir.FullName, ".git")))
 23            {
 224                return true;
 25            }
 26
 1627            dir = dir.Parent;
 28        }
 29
 230        return false;
 31    }
 32
 33    public static async Task GenerateReportAsync(
 34        string reportPath,
 35        ImportTrackerCommand command,
 36        TrackerImportSummary summary,
 37        CancellationToken cancellationToken = default)
 38    {
 439        ArgumentNullException.ThrowIfNull(reportPath);
 440        ArgumentNullException.ThrowIfNull(command);
 441        ArgumentNullException.ThrowIfNull(summary);
 42
 443        var sb = new StringBuilder();
 444        var inv = CultureInfo.InvariantCulture;
 45
 46        // 1. Header & Execution Mode
 447        sb.AppendLine("================================================================================");
 448        sb.AppendLine("                 RoleRadar Tracker Import Execution Report                      ");
 449        sb.AppendLine("================================================================================");
 450        sb.AppendLine(inv, $"Timestamp (UTC):     {DateTime.UtcNow:yyyy-MM-dd HH:mm:ss}Z");
 451        sb.AppendLine(inv, $"Execution Mode:      {(summary.IsDryRun ? "DRY_RUN" : "APPLIED")}");
 452        sb.AppendLine(inv, $"Bundle Directory:    {command.BundleDirectory}");
 453        sb.AppendLine(inv, $"Default Date Anchor: {(command.DefaultDate.HasValue ? command.DefaultDate.Value.ToString("y
 454        sb.AppendLine();
 55
 56        // 2. Aggregated Counts Summary
 457        sb.AppendLine("--------------------------------------------------------------------------------");
 458        sb.AppendLine("                          Aggregated Counts Summary                             ");
 459        sb.AppendLine("--------------------------------------------------------------------------------");
 460        sb.AppendLine(inv, $"Companies Created:                     {summary.CompaniesCreated}");
 461        sb.AppendLine(inv, $"Companies Updated:                     {summary.CompaniesUpdated}");
 462        sb.AppendLine(inv, $"Companies Unchanged/Skipped:           {summary.CompaniesUnchanged}");
 463        sb.AppendLine(inv, $"Postings Created:                      {summary.PostingsCreated}");
 464        sb.AppendLine(inv, $"Postings Updated:                      {summary.PostingsUpdated}");
 465        sb.AppendLine(inv, $"Postings Unchanged/Skipped:            {summary.PostingsUnchanged}");
 466        sb.AppendLine(inv, $"Applications Created:                  {summary.ApplicationsCreated}");
 467        sb.AppendLine(inv, $"Applications Unchanged/Skipped:        {summary.ApplicationsUnchanged}");
 468        sb.AppendLine(inv, $"Standalone Notes Created:              {summary.StandaloneNotesCreated}");
 469        sb.AppendLine(inv, $"Screening Notes Created:               {summary.ScreeningNotesCreated}");
 470        sb.AppendLine(inv, $"Criteria Registered:                   {summary.CriteriaCreated}");
 471        sb.AppendLine(inv, $"Signals Created:                       {summary.SignalsCreated}");
 472        sb.AppendLine(inv, $"Mapped to Event Notes:                 {summary.MappedToEventNotes}");
 473        sb.AppendLine(inv, $"Resume Variants Defaulted:             {summary.ResumeVariantsDefaulted}");
 474        sb.AppendLine(inv, $"Dates Defaulted:                       {summary.DatesDefaulted}");
 475        sb.AppendLine(inv, $"Dates Inferred (Rollback/SameYear):    {summary.DatesInferred}");
 476        sb.AppendLine(inv, $"Dates Flagged (or Scores Flagged):     {summary.DatesFlagged}");
 477        sb.AppendLine(inv, $"Culture Summaries Truncated (>500):    {summary.CultureTruncations}");
 478        sb.AppendLine(inv, $"Culture Levels Unmapped:               {summary.CultureUnmapped}");
 479        sb.AppendLine(inv, $"Total Field Truncations:               {summary.FieldTruncations.Values.Sum()}");
 480        sb.AppendLine(inv, $"Unclaimed Applied Roles Remaining:     {summary.UnclaimedAppliedPostings}");
 481        sb.AppendLine(inv, $"Total Row Errors Encountered:          {summary.Errors.Count}");
 482        if (summary.FieldTruncations.Count > 0)
 83        {
 084            sb.AppendLine("  Field Truncation Breakdown:");
 085            foreach (var (field, count) in summary.FieldTruncations.OrderBy(kv => kv.Key, StringComparer.OrdinalIgnoreCa
 86            {
 087                sb.AppendLine(inv, $"    - {field}: {count}");
 88            }
 89        }
 490        sb.AppendLine();
 91
 92        // 2b. File Reconciliation Summary
 493        sb.AppendLine("--------------------------------------------------------------------------------");
 494        sb.AppendLine("                     File-Level Reconciliation Summary                          ");
 495        sb.AppendLine("--------------------------------------------------------------------------------");
 496        if (summary.FileReconciliations.Count == 0)
 97        {
 298            sb.AppendLine("No files processed.");
 99        }
 100        else
 101        {
 2102            sb.AppendLine(string.Format(inv, "{0,-25} {1,8} {2,8} {3,8} {4,10} {5,8} {6,8}", "File", "Read", "Created", 
 2103            sb.AppendLine(new string('-', 81));
 34104            foreach (var f in summary.FileReconciliations.Values.OrderBy(x => x.FileName, StringComparer.OrdinalIgnoreCa
 105            {
 10106                if (f.IsAbsent)
 107                {
 0108                    sb.AppendLine(string.Format(inv, "{0,-25} {1,8} {2,8} {3,8} {4,10} {5,8} {6,8}", f.FileName, "absent
 109                }
 110                else
 111                {
 10112                    sb.AppendLine(string.Format(inv, "{0,-25} {1,8} {2,8} {3,8} {4,10} {5,8} {6,8}", f.FileName, f.Read,
 10113                    if (f.SkippedByReason.Count > 0)
 114                    {
 0115                        sb.AppendLine("    Skipped Breakdown:");
 0116                        foreach (var (reason, count) in f.SkippedByReason.OrderBy(kv => kv.Key, StringComparer.OrdinalIg
 117                        {
 0118                            sb.AppendLine(inv, $"      - {reason}: {count}");
 119                        }
 120                    }
 10121                    if (f.UnchangedByReason.Count > 0)
 122                    {
 0123                        sb.AppendLine("    Unchanged Breakdown:");
 0124                        foreach (var (reason, count) in f.UnchangedByReason.OrderBy(kv => kv.Key, StringComparer.Ordinal
 125                        {
 0126                            sb.AppendLine(inv, $"      - {reason}: {count}");
 127                        }
 128                    }
 129                }
 130            }
 131        }
 4132        sb.AppendLine();
 133
 134        // 2c. Source Field Coverage
 4135        sb.AppendLine("--------------------------------------------------------------------------------");
 4136        sb.AppendLine("                           Source Field Coverage                                ");
 4137        sb.AppendLine("--------------------------------------------------------------------------------");
 4138        sb.AppendLine(string.Format(inv, "{0,-23} {1,-20} {2,10}  {3}", "File", "Field", "Non-Empty", "Handling"));
 4139        sb.AppendLine(new string('-', 88));
 488140        foreach (var def in SourceFieldCatalog.AllFields)
 141        {
 240142            var nonNullCount = summary.GetSourceFieldNonEmptyCount(def.File, def.Field);
 240143            sb.AppendLine(string.Format(inv, "{0,-23} {1,-20} {2,10}  {3}", def.File, def.Field, nonNullCount, def.Handl
 144        }
 4145        sb.AppendLine();
 146
 4147        if (summary.DispositionHistogram.Count > 0)
 148        {
 2149            sb.AppendLine("--------------------------------------------------------------------------------");
 2150            sb.AppendLine("                       Post-Run Disposition Histogram                           ");
 2151            sb.AppendLine("--------------------------------------------------------------------------------");
 16152            foreach (var (disposition, count) in summary.DispositionHistogram.OrderBy(kv => kv.Key, StringComparer.Ordin
 153            {
 4154                sb.AppendLine(inv, $"  - {disposition}: {count}");
 155            }
 2156            sb.AppendLine();
 157        }
 158
 4159        sb.AppendLine("--------------------------------------------------------------------------------");
 4160        sb.AppendLine("                              Mapping Decisions                                 ");
 4161        sb.AppendLine("--------------------------------------------------------------------------------");
 4162        sb.AppendLine("  - Remote Type: 'remote_mentioned' is preserved as RemoteType.Unknown without storing text in");
 4163        sb.AppendLine("    culture summary (counted under Unmapped Values as 'remote_mentioned: N not stored').");
 4164        sb.AppendLine("  - Resume Variant: Domain entity requires non-nullable ResumeVariant; blank values default");
 4165        sb.AppendLine("    to ResumeVariant.AsIs with 'resume variant unspecified' appended to applied event notes");
 4166        sb.AppendLine("    (counted under Resume Variants Defaulted).");
 4167        sb.AppendLine("  - Fit & Referral: Fit values and referral=true are mapped to applied event notes");
 4168        sb.AppendLine("    (counted under Mapped to Event Notes).");
 4169        sb.AppendLine();
 170
 4171        if (summary.UnmappedValues.Count > 0)
 172        {
 4173            sb.AppendLine("--------------------------------------------------------------------------------");
 4174            sb.AppendLine("                              Unmapped Values                                   ");
 4175            sb.AppendLine("--------------------------------------------------------------------------------");
 26176            foreach (var (field, count) in summary.UnmappedValues.OrderBy(kv => kv.Key, StringComparer.OrdinalIgnoreCase
 177            {
 6178                if (string.Equals(field, "remote_mentioned", StringComparison.OrdinalIgnoreCase))
 179                {
 2180                    sb.AppendLine(inv, $"  - remote_mentioned: {count} not stored");
 2181                    continue;
 182                }
 4183                var samples = summary.UnmappedValueSamples.TryGetValue(field, out var list) && list.Count > 0
 4184                    ? $" (samples: {string.Join(", ", list.Take(5))})"
 4185                    : string.Empty;
 4186                sb.AppendLine(inv, $"  - {field}: {count}{samples}");
 187            }
 4188            sb.AppendLine();
 189        }
 190
 191        // 3. Companies Requiring Alias Review
 4192        sb.AppendLine("--------------------------------------------------------------------------------");
 4193        sb.AppendLine("                     Companies Requiring Alias Review                           ");
 4194        sb.AppendLine("--------------------------------------------------------------------------------");
 4195        if (summary.AutoCreatedCompanies.Count == 0)
 196        {
 2197            sb.AppendLine("None. All referenced companies existed or matched known aliases.");
 198        }
 199        else
 200        {
 2201            sb.AppendLine("The following companies were auto-created with status 'neutral' and a blank description.");
 2202            sb.AppendLine("Inspect for near-miss names and add canonical aliases to company-aliases.csv before --apply:"
 12203            foreach (var comp in summary.AutoCreatedCompanies.Distinct())
 204            {
 4205                sb.AppendLine(inv, $"  - {comp}");
 206            }
 207        }
 4208        sb.AppendLine();
 209
 210        // 4. Unclaimed "Applied" Postings
 4211        sb.AppendLine("--------------------------------------------------------------------------------");
 4212        sb.AppendLine("                         Unclaimed Applied Postings                             ");
 4213        sb.AppendLine("--------------------------------------------------------------------------------");
 4214        if (summary.UnclaimedAppliedPostingTitles.Count == 0)
 215        {
 2216            sb.AppendLine("None. All applied postings in postings.json had matching applications.");
 217        }
 218        else
 219        {
 2220            sb.AppendLine("The following postings had status 'applied' in postings.json but no matching record");
 2221            sb.AppendLine("in applications.csv. They have been imported in disposition 'scored':");
 8222            foreach (var title in summary.UnclaimedAppliedPostingTitles)
 223            {
 2224                sb.AppendLine(inv, $"  - {title}");
 225            }
 226        }
 4227        sb.AppendLine();
 228
 229        // 5. Contacts Detected for Manual Entry
 4230        sb.AppendLine("--------------------------------------------------------------------------------");
 4231        sb.AppendLine("                     Contacts Detected for Manual Entry                         ");
 4232        sb.AppendLine("--------------------------------------------------------------------------------");
 4233        if (summary.PeopleDetected.Count == 0)
 234        {
 2235            sb.AppendLine("None. No detected individuals or contains_people flags in applications.csv.");
 236        }
 237        else
 238        {
 2239            sb.AppendLine("Per Constitution Principle I, contact records are NEVER created automatically.");
 2240            sb.AppendLine("Use 'roleradar contact add <name>' to record interactions with the following contacts:");
 8241            foreach (var detected in summary.PeopleDetected)
 242            {
 2243                sb.AppendLine(inv, $"  - {detected}");
 244            }
 245        }
 4246        sb.AppendLine();
 247
 248        // 6. Row Validation Errors & Warnings
 4249        sb.AppendLine("--------------------------------------------------------------------------------");
 4250        sb.AppendLine("                    Row Validation Errors & Skipped Rows                        ");
 4251        sb.AppendLine("--------------------------------------------------------------------------------");
 4252        if (summary.Errors.Count == 0)
 253        {
 4254            sb.AppendLine("None. All rows processed cleanly without validation errors.");
 255        }
 256        else
 257        {
 0258            foreach (var err in summary.Errors)
 259            {
 0260                sb.AppendLine(inv, $"  - [{err.SourceFile}:{err.LineNumber}] ({err.ErrorCode}) {err.Message}");
 261            }
 262        }
 4263        sb.AppendLine();
 264
 4265        var dir = Path.GetDirectoryName(reportPath);
 4266        if (!string.IsNullOrWhiteSpace(dir) && !Directory.Exists(dir))
 267        {
 0268            Directory.CreateDirectory(dir);
 269        }
 270
 4271        await File.WriteAllTextAsync(reportPath, sb.ToString(), Encoding.UTF8, cancellationToken);
 4272    }
 273}