dart-decimate 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,691 @@
1
+ use std::fmt::Write as _;
2
+
3
+ use crate::decision_surface::{
4
+ DecisionSurfaceCategory, DecisionSurfaceDecision, DecisionSurfaceReport,
5
+ };
6
+
7
+ use super::{
8
+ human_details::{
9
+ best_text, fallback_best, kind_label, omitted_findings_message, summary_groups, why_text,
10
+ },
11
+ types::{Finding, FindingEdge, FindingKind, JsonReport, Severity, Verdict},
12
+ };
13
+
14
+ const MAX_RELATED_FILES: usize = 12;
15
+
16
+ /// Render a browser-ready static report for humans.
17
+ #[must_use]
18
+ pub fn render_html_report(report: &JsonReport) -> String {
19
+ let mut html = String::new();
20
+ render_document_start(&mut html, report);
21
+ render_summary(&mut html, report);
22
+ render_findings(&mut html, report);
23
+ render_next_steps(&mut html, report);
24
+ render_document_end(&mut html);
25
+ html
26
+ }
27
+
28
+ /// Render a browser-ready static decision-surface report for humans.
29
+ #[must_use]
30
+ pub fn render_decision_surface_html_report(report: &DecisionSurfaceReport) -> String {
31
+ let mut html = String::new();
32
+ render_decision_surface_document_start(&mut html, report);
33
+ render_decision_surface_summary(&mut html, report);
34
+ render_decision_surface_decisions(&mut html, report);
35
+ render_document_end(&mut html);
36
+ html
37
+ }
38
+
39
+ fn render_document_start(html: &mut String, report: &JsonReport) {
40
+ let _ = writeln!(html, "<!doctype html>");
41
+ let _ = writeln!(html, "<html lang=\"en\">");
42
+ let _ = writeln!(html, "<head>");
43
+ let _ = writeln!(html, "<meta charset=\"utf-8\">");
44
+ let _ = writeln!(
45
+ html,
46
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"
47
+ );
48
+ let _ = writeln!(
49
+ html,
50
+ "<title>Dart Decimate {} report</title>",
51
+ escape(report.command.as_str())
52
+ );
53
+ render_style(html);
54
+ let _ = writeln!(html, "</head>");
55
+ let _ = writeln!(html, "<body>");
56
+ }
57
+
58
+ fn render_decision_surface_document_start(html: &mut String, report: &DecisionSurfaceReport) {
59
+ let _ = writeln!(html, "<!doctype html>");
60
+ let _ = writeln!(html, "<html lang=\"en\">");
61
+ let _ = writeln!(html, "<head>");
62
+ let _ = writeln!(html, "<meta charset=\"utf-8\">");
63
+ let _ = writeln!(
64
+ html,
65
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"
66
+ );
67
+ let _ = writeln!(
68
+ html,
69
+ "<title>Dart Decimate {} decision surface</title>",
70
+ escape(report.command.as_str())
71
+ );
72
+ render_style(html);
73
+ let _ = writeln!(html, "</head>");
74
+ let _ = writeln!(html, "<body>");
75
+ }
76
+
77
+ fn render_style(html: &mut String) {
78
+ let _ = writeln!(
79
+ html,
80
+ "<style>
81
+ :root {{
82
+ color-scheme: dark;
83
+ --bg: #070707;
84
+ --panel: #111111;
85
+ --line: #2b2b2b;
86
+ --text: #f1f1f1;
87
+ --muted: #a6a6a6;
88
+ --accent: #8fdcff;
89
+ --error: #ff5c5c;
90
+ --warn: #ffd166;
91
+ --pass: #5ee091;
92
+ }}
93
+ * {{ box-sizing: border-box; }}
94
+ body {{
95
+ margin: 0;
96
+ background: var(--bg);
97
+ color: var(--text);
98
+ font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;
99
+ }}
100
+ main {{ max-width: 1180px; margin: 0 auto; padding: 40px 24px 56px; }}
101
+ h1, h2, h3, p {{ margin: 0; }}
102
+ h1 {{ font-size: clamp(32px, 5vw, 60px); letter-spacing: 0; line-height: 1; }}
103
+ h2 {{ margin-top: 36px; font-size: 22px; }}
104
+ .topline {{ color: var(--muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .08em; font-size: 12px; }}
105
+ .hero {{ border-bottom: 1px solid var(--line); padding-bottom: 28px; }}
106
+ .verdict {{ display: inline-flex; align-items: center; gap: 8px; margin-top: 18px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; }}
107
+ .pass {{ color: var(--pass); }}
108
+ .fail, .error {{ color: var(--error); }}
109
+ .warning {{ color: var(--warn); }}
110
+ .metrics, .groups {{ display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-top: 24px; }}
111
+ .metric, .group, .finding, .step {{ background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }}
112
+ .metric span, .group span, .label {{ color: var(--muted); display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }}
113
+ .metric strong, .group strong {{ display: block; margin-top: 4px; font-size: 24px; }}
114
+ .group p {{ margin-top: 8px; color: var(--text); }}
115
+ .findings {{ display: grid; gap: 14px; margin-top: 14px; }}
116
+ .finding header {{ display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 14px; }}
117
+ .finding h3 {{ font-size: 18px; }}
118
+ .rule, .location, .mono {{ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }}
119
+ .rule {{ color: var(--muted); font-size: 13px; }}
120
+ .section {{ margin-top: 12px; }}
121
+ .section p {{ margin-top: 3px; }}
122
+ .evidence {{ margin: 8px 0 0; padding-left: 18px; color: var(--text); }}
123
+ .evidence li {{ margin: 3px 0; }}
124
+ .command {{ overflow-wrap: anywhere; color: var(--accent); }}
125
+ a {{ color: var(--accent); text-decoration: none; }}
126
+ a:hover {{ text-decoration: underline; }}
127
+ </style>"
128
+ );
129
+ }
130
+
131
+ fn render_summary(html: &mut String, report: &JsonReport) {
132
+ let verdict_class = match report.verdict {
133
+ Verdict::Pass => "pass",
134
+ Verdict::Fail => "fail",
135
+ };
136
+ let verdict = match report.verdict {
137
+ Verdict::Pass => "PASS",
138
+ Verdict::Fail => "FAIL",
139
+ };
140
+
141
+ let _ = writeln!(html, "<main>");
142
+ let _ = writeln!(html, "<section class=\"hero\">");
143
+ let _ = writeln!(html, "<p class=\"topline\">Dart Decimate</p>");
144
+ let _ = writeln!(html, "<h1>{} report</h1>", escape(report.command.as_str()));
145
+ let _ = writeln!(
146
+ html,
147
+ "<p class=\"verdict {verdict_class}\">Verdict: <strong>{verdict}</strong></p>"
148
+ );
149
+ let _ = writeln!(html, "<div class=\"metrics\">");
150
+ metric(html, "Files", report.summary.files);
151
+ metric(html, "Edges", report.summary.edges);
152
+ metric(html, "Findings", report.summary.findings);
153
+ if report.summary.functions > 0 || report.summary.quality_score > 0 {
154
+ metric(html, "Quality", report.summary.quality_score);
155
+ metric(html, "Functions", report.summary.functions);
156
+ metric(
157
+ html,
158
+ "Max cyclomatic",
159
+ report.summary.max_cyclomatic_complexity,
160
+ );
161
+ }
162
+ let _ = writeln!(html, "</div>");
163
+ let _ = writeln!(html, "</section>");
164
+
165
+ let groups = summary_groups(&report.summary);
166
+ if groups.iter().any(|(_, items)| !items.is_empty()) {
167
+ let _ = writeln!(html, "<section>");
168
+ let _ = writeln!(html, "<h2>Issue Summary</h2>");
169
+ let _ = writeln!(html, "<div class=\"groups\">");
170
+ for (name, items) in groups.iter().filter(|(_, items)| !items.is_empty()) {
171
+ let _ = writeln!(
172
+ html,
173
+ "<article class=\"group\"><span>{}</span><p>{}</p></article>",
174
+ escape(name),
175
+ escape(&items.join(", "))
176
+ );
177
+ }
178
+ let _ = writeln!(html, "</div>");
179
+ let _ = writeln!(html, "</section>");
180
+ }
181
+ }
182
+
183
+ fn render_decision_surface_summary(html: &mut String, report: &DecisionSurfaceReport) {
184
+ let _ = writeln!(html, "<main>");
185
+ let _ = writeln!(html, "<section class=\"hero\">");
186
+ let _ = writeln!(html, "<p class=\"topline\">Dart Decimate</p>");
187
+ let _ = writeln!(
188
+ html,
189
+ "<h1>{} decision surface</h1>",
190
+ escape(report.command.as_str())
191
+ );
192
+ let _ = writeln!(html, "<div class=\"metrics\">");
193
+ metric_text(html, "Base", &report.base);
194
+ metric(html, "Changed files", report.summary.changed_files);
195
+ metric(html, "Decisions", report.summary.decisions);
196
+ let _ = writeln!(html, "</div>");
197
+ let _ = writeln!(html, "</section>");
198
+ }
199
+
200
+ fn render_decision_surface_decisions(html: &mut String, report: &DecisionSurfaceReport) {
201
+ let _ = writeln!(html, "<section>");
202
+ let _ = writeln!(html, "<h2>Decisions</h2>");
203
+ if report.decisions.is_empty() {
204
+ let _ = writeln!(
205
+ html,
206
+ "<article class=\"finding\"><p>No structural decisions surfaced for the selected changes.</p></article>"
207
+ );
208
+ let _ = writeln!(html, "</section>");
209
+ return;
210
+ }
211
+
212
+ let _ = writeln!(html, "<div class=\"findings\">");
213
+ for (index, decision) in report.decisions.iter().enumerate() {
214
+ render_decision_surface_decision(html, index + 1, decision);
215
+ }
216
+ let _ = writeln!(html, "</div>");
217
+ let _ = writeln!(html, "</section>");
218
+ }
219
+
220
+ fn render_decision_surface_decision(
221
+ html: &mut String,
222
+ index: usize,
223
+ decision: &DecisionSurfaceDecision,
224
+ ) {
225
+ let _ = writeln!(html, "<article class=\"finding\">");
226
+ let _ = writeln!(html, "<header>");
227
+ let _ = writeln!(
228
+ html,
229
+ "<div><h3>{}. {}</h3><p class=\"rule\">{}</p></div>",
230
+ index,
231
+ escape(&decision.question),
232
+ decision_category_value(decision.category)
233
+ );
234
+ let _ = writeln!(html, "<p class=\"location\">{}</p>", escape(&decision.path));
235
+ let _ = writeln!(html, "</header>");
236
+ section(html, "Expert", &decision.recommended_expert, "");
237
+ render_string_list(html, "Evidence", &decision.evidence);
238
+ render_string_list(html, "Files", &decision.files);
239
+ for command in &decision.suggested_commands {
240
+ section(html, "Command", command, "command mono");
241
+ }
242
+ let _ = writeln!(html, "</article>");
243
+ }
244
+
245
+ fn render_string_list(html: &mut String, label: &str, values: &[String]) {
246
+ if values.is_empty() {
247
+ return;
248
+ }
249
+ let _ = writeln!(
250
+ html,
251
+ "<div class=\"section\"><span class=\"label\">{}</span><ul class=\"evidence\">",
252
+ escape(label)
253
+ );
254
+ for value in values {
255
+ let _ = writeln!(html, "<li>{}</li>", escape(value));
256
+ }
257
+ let _ = writeln!(html, "</ul></div>");
258
+ }
259
+
260
+ const fn decision_category_value(category: DecisionSurfaceCategory) -> &'static str {
261
+ match category {
262
+ DecisionSurfaceCategory::CouplingBoundary => "coupling-boundary",
263
+ DecisionSurfaceCategory::PublicApiContract => "public-api-contract",
264
+ DecisionSurfaceCategory::Dependency => "dependency",
265
+ }
266
+ }
267
+
268
+ fn render_findings(html: &mut String, report: &JsonReport) {
269
+ let _ = writeln!(html, "<section>");
270
+ let _ = writeln!(html, "<h2>Findings</h2>");
271
+ if report.findings.is_empty() {
272
+ if report.summary.findings == 0 && report.verdict == Verdict::Pass {
273
+ let _ = writeln!(
274
+ html,
275
+ "<article class=\"finding\"><p>No findings. The selected Dart graph checks passed.</p></article>"
276
+ );
277
+ } else {
278
+ let message = omitted_findings_message(&report.summary, report.verdict);
279
+ let _ = writeln!(
280
+ html,
281
+ "<article class=\"finding\"><p>{}</p></article>",
282
+ escape(&message)
283
+ );
284
+ }
285
+ let _ = writeln!(html, "</section>");
286
+ return;
287
+ }
288
+
289
+ let _ = writeln!(html, "<div class=\"findings\">");
290
+ for (index, finding) in report.findings.iter().enumerate() {
291
+ render_finding(html, index + 1, finding);
292
+ }
293
+ let _ = writeln!(html, "</div>");
294
+ let _ = writeln!(html, "</section>");
295
+ }
296
+
297
+ fn render_finding(html: &mut String, index: usize, finding: &Finding) {
298
+ let severity_class = severity_class(finding.severity);
299
+ let _ = writeln!(html, "<article class=\"finding\">");
300
+ let _ = writeln!(html, "<header>");
301
+ let _ = writeln!(
302
+ html,
303
+ "<div><h3>{}. {}</h3><p class=\"rule\">{}</p></div>",
304
+ index,
305
+ escape(kind_label(finding.kind)),
306
+ escape(&finding.rule_id)
307
+ );
308
+ let _ = writeln!(
309
+ html,
310
+ "<p class=\"{severity_class}\">{}</p>",
311
+ escape(severity_label(finding.severity))
312
+ );
313
+ let _ = writeln!(html, "</header>");
314
+ section(html, "Location", &location(finding), "location");
315
+ section(html, "What", &finding.message, "");
316
+ section(html, "Why", why_text(finding.kind), "");
317
+ render_evidence(html, finding);
318
+ section(html, "Best", &best_for(finding), "");
319
+ if let Some(command) = finding
320
+ .actions
321
+ .iter()
322
+ .find_map(|action| action.command.as_ref())
323
+ {
324
+ section(html, "Inspect", command, "command mono");
325
+ }
326
+ let _ = writeln!(html, "</article>");
327
+ }
328
+
329
+ fn render_evidence(html: &mut String, finding: &Finding) {
330
+ let _ = writeln!(
331
+ html,
332
+ "<div class=\"section\"><span class=\"label\">Evidence</span><ul class=\"evidence\">"
333
+ );
334
+ let _ = writeln!(html, "<li>Location: {}</li>", escape(&location(finding)));
335
+ if let Some(fingerprint) = &finding.fingerprint {
336
+ let _ = writeln!(html, "<li>Fingerprint: {}</li>", escape(fingerprint));
337
+ }
338
+ if let Some(edge) = &finding.edge {
339
+ render_edge(html, edge);
340
+ }
341
+ if !finding.files.is_empty() {
342
+ let label = if matches!(
343
+ finding.kind,
344
+ FindingKind::CircularDependency | FindingKind::ReExportCycle
345
+ ) {
346
+ "Cycle preview"
347
+ } else {
348
+ "Related files"
349
+ };
350
+ let value = if matches!(
351
+ finding.kind,
352
+ FindingKind::CircularDependency | FindingKind::ReExportCycle
353
+ ) {
354
+ cycle_preview(&finding.files)
355
+ } else {
356
+ related_files_preview(&finding.files)
357
+ };
358
+ let _ = writeln!(html, "<li>{label}: {}</li>", escape(&value));
359
+ let _ = writeln!(html, "<li>Files: {} total</li>", finding.files.len());
360
+ }
361
+ let safe = if finding.safe_to_delete {
362
+ "yes, after reviewing generated/dynamic usage"
363
+ } else {
364
+ "no; review or refactor before deleting"
365
+ };
366
+ let _ = writeln!(html, "<li>Safe to delete: {safe}</li>");
367
+ let _ = writeln!(html, "</ul></div>");
368
+ }
369
+
370
+ fn render_edge(html: &mut String, edge: &FindingEdge) {
371
+ let text = format!(
372
+ "{} {} -> {} ({})",
373
+ edge.kind, edge.from, edge.to, edge.specifier
374
+ );
375
+ let _ = writeln!(html, "<li>Edge: {}</li>", escape(&text));
376
+ }
377
+
378
+ fn render_next_steps(html: &mut String, report: &JsonReport) {
379
+ if report.next_steps.is_empty() {
380
+ return;
381
+ }
382
+ let _ = writeln!(html, "<section>");
383
+ let _ = writeln!(html, "<h2>Next Steps</h2>");
384
+ for step in &report.next_steps {
385
+ let _ = writeln!(
386
+ html,
387
+ "<article class=\"step\"><p class=\"command mono\">{}</p><p>{}</p></article>",
388
+ escape(&step.command),
389
+ escape(&step.reason)
390
+ );
391
+ }
392
+ let _ = writeln!(html, "</section>");
393
+ }
394
+
395
+ fn render_document_end(html: &mut String) {
396
+ let _ = writeln!(html, "</main>");
397
+ let _ = writeln!(html, "</body>");
398
+ let _ = writeln!(html, "</html>");
399
+ }
400
+
401
+ fn metric(html: &mut String, label: &str, value: usize) {
402
+ metric_text(html, label, &value.to_string());
403
+ }
404
+
405
+ fn metric_text(html: &mut String, label: &str, value: &str) {
406
+ let _ = writeln!(
407
+ html,
408
+ "<div class=\"metric\"><span>{}</span><strong>{}</strong></div>",
409
+ escape(label),
410
+ escape(value)
411
+ );
412
+ }
413
+
414
+ fn section(html: &mut String, label: &str, value: &str, class_name: &str) {
415
+ let class_attr = if class_name.is_empty() {
416
+ String::new()
417
+ } else {
418
+ format!(" class=\"{class_name}\"")
419
+ };
420
+ let _ = writeln!(
421
+ html,
422
+ "<div class=\"section\"><span class=\"label\">{}</span><p{}>{}</p></div>",
423
+ escape(label),
424
+ class_attr,
425
+ escape(value)
426
+ );
427
+ }
428
+
429
+ fn best_for(finding: &Finding) -> String {
430
+ finding.actions.first().map_or_else(
431
+ || fallback_best(finding.kind),
432
+ |action| best_text(finding, action),
433
+ )
434
+ }
435
+
436
+ fn location(finding: &Finding) -> String {
437
+ let path = if finding.path.is_empty() {
438
+ "<project>"
439
+ } else {
440
+ finding.path.as_str()
441
+ };
442
+ format!("{path}:{}:{}", finding.line, finding.column)
443
+ }
444
+
445
+ const fn severity_label(severity: Severity) -> &'static str {
446
+ match severity {
447
+ Severity::Error => "error",
448
+ Severity::Warning => "warning",
449
+ }
450
+ }
451
+
452
+ const fn severity_class(severity: Severity) -> &'static str {
453
+ match severity {
454
+ Severity::Error => "error",
455
+ Severity::Warning => "warning",
456
+ }
457
+ }
458
+
459
+ fn cycle_preview(files: &[String]) -> String {
460
+ let mut visible = files
461
+ .iter()
462
+ .take(MAX_RELATED_FILES)
463
+ .cloned()
464
+ .collect::<Vec<_>>();
465
+ if files.len() > MAX_RELATED_FILES {
466
+ visible.push(format!(
467
+ "... {} more files ...",
468
+ files.len() - MAX_RELATED_FILES
469
+ ));
470
+ }
471
+ if let Some(first) = files.first() {
472
+ visible.push(first.clone());
473
+ }
474
+ visible.join(" -> ")
475
+ }
476
+
477
+ fn related_files_preview(files: &[String]) -> String {
478
+ let mut visible = files
479
+ .iter()
480
+ .take(MAX_RELATED_FILES)
481
+ .cloned()
482
+ .collect::<Vec<_>>();
483
+ if files.len() > MAX_RELATED_FILES {
484
+ visible.push(format!(
485
+ "... {} more files",
486
+ files.len() - MAX_RELATED_FILES
487
+ ));
488
+ }
489
+ visible.join(", ")
490
+ }
491
+
492
+ fn escape(value: &str) -> String {
493
+ let mut escaped = String::with_capacity(value.len());
494
+ for character in value.chars() {
495
+ match character {
496
+ '&' => escaped.push_str("&amp;"),
497
+ '<' => escaped.push_str("&lt;"),
498
+ '>' => escaped.push_str("&gt;"),
499
+ '"' => escaped.push_str("&quot;"),
500
+ '\'' => escaped.push_str("&#39;"),
501
+ character if character.is_control() => {
502
+ let _ = write!(escaped, "&#x{:X};", character as u32);
503
+ }
504
+ _ => escaped.push(character),
505
+ }
506
+ }
507
+ escaped
508
+ }
509
+
510
+ #[cfg(test)]
511
+ mod tests {
512
+ use super::*;
513
+ use crate::output::{FindingAction, FindingEdge, NextStep, ReportCommand, ReportSummary};
514
+
515
+ #[test]
516
+ fn renders_browser_ready_report_with_escaped_evidence() {
517
+ let report = JsonReport {
518
+ schema_version: "dart-decimate.report.v1".to_owned(),
519
+ kind: "combined".to_owned(),
520
+ tool: "dart-decimate".to_owned(),
521
+ command: ReportCommand::Check,
522
+ verdict: Verdict::Fail,
523
+ summary: ReportSummary {
524
+ files: 3,
525
+ edges: 2,
526
+ findings: 1,
527
+ cycles: 1,
528
+ ..ReportSummary::default()
529
+ },
530
+ findings: vec![Finding {
531
+ rule_id: "dart-decimate/circular-dependency".to_owned(),
532
+ fingerprint: Some("cycle:<unsafe>".to_owned()),
533
+ kind: FindingKind::CircularDependency,
534
+ severity: Severity::Error,
535
+ message: "Circular dependency spans 3 Dart files".to_owned(),
536
+ path: "lib/a.dart".to_owned(),
537
+ line: 1,
538
+ column: 0,
539
+ safe_to_delete: false,
540
+ files: vec![
541
+ "lib/a.dart".to_owned(),
542
+ "lib/b.dart".to_owned(),
543
+ "lib/c.dart".to_owned(),
544
+ ],
545
+ edge: None,
546
+ actions: vec![
547
+ FindingAction::new(
548
+ "break-cycle",
549
+ "Move shared dependencies inward or invert one import edge",
550
+ false,
551
+ )
552
+ .with_dart_decimate_args([
553
+ "inspect",
554
+ "--format",
555
+ "json",
556
+ "--file",
557
+ "lib/a.dart",
558
+ ]),
559
+ ],
560
+ }],
561
+ clone_groups: Vec::new(),
562
+ complexity: Vec::new(),
563
+ file_scores: Vec::new(),
564
+ hotspots: Vec::new(),
565
+ refactoring_targets: Vec::new(),
566
+ threshold_overrides: Vec::new(),
567
+ feature_flags: Vec::new(),
568
+ security_candidates: Vec::new(),
569
+ attack_surface: Vec::new(),
570
+ runtime_coverage: None,
571
+ next_steps: Vec::new(),
572
+ };
573
+
574
+ let rendered = render_html_report(&report);
575
+
576
+ assert!(rendered.starts_with("<!doctype html>"));
577
+ assert!(rendered.contains("<h1>check report</h1>"));
578
+ assert!(rendered.contains("Architecture"));
579
+ assert!(rendered.contains("1 circular dependency"));
580
+ assert!(rendered.contains("Why"));
581
+ assert!(rendered.contains("cycle:&lt;unsafe&gt;"));
582
+ assert!(rendered.contains("lib/a.dart -&gt; lib/b.dart -&gt; lib/c.dart -&gt; lib/a.dart"));
583
+ }
584
+
585
+ #[test]
586
+ fn escapes_control_characters_from_user_values() {
587
+ let report = JsonReport {
588
+ schema_version: "dart-decimate.report.v1".to_owned(),
589
+ kind: "combined".to_owned(),
590
+ tool: "dart-decimate".to_owned(),
591
+ command: ReportCommand::Check,
592
+ verdict: Verdict::Fail,
593
+ summary: ReportSummary {
594
+ files: 2,
595
+ edges: 1,
596
+ findings: 1,
597
+ cycles: 1,
598
+ ..ReportSummary::default()
599
+ },
600
+ findings: vec![Finding {
601
+ rule_id: "dart-decimate/circular-dependency".to_owned(),
602
+ fingerprint: Some("cycle:\x1bunsafe".to_owned()),
603
+ kind: FindingKind::CircularDependency,
604
+ severity: Severity::Error,
605
+ message: "Circular dependency includes \x07bell".to_owned(),
606
+ path: "lib/\x1b[31mbad.dart".to_owned(),
607
+ line: 1,
608
+ column: 0,
609
+ safe_to_delete: false,
610
+ files: vec![
611
+ "lib/\x1b[31mbad.dart".to_owned(),
612
+ "lib/\x07bell.dart".to_owned(),
613
+ ],
614
+ edge: Some(FindingEdge {
615
+ from: "lib/\x1b[31mbad.dart".to_owned(),
616
+ to: "lib/\x07bell.dart".to_owned(),
617
+ specifier: "package:app/\x1bbad.dart".to_owned(),
618
+ kind: "import".to_owned(),
619
+ }),
620
+ actions: vec![
621
+ FindingAction::new("inspect-control", "Inspect \x07bell", false)
622
+ .with_dart_decimate_args([
623
+ "inspect",
624
+ "--format",
625
+ "json",
626
+ "--file",
627
+ "lib/\x1b[31mbad.dart",
628
+ ]),
629
+ ],
630
+ }],
631
+ clone_groups: Vec::new(),
632
+ complexity: Vec::new(),
633
+ file_scores: Vec::new(),
634
+ hotspots: Vec::new(),
635
+ refactoring_targets: Vec::new(),
636
+ threshold_overrides: Vec::new(),
637
+ feature_flags: Vec::new(),
638
+ security_candidates: Vec::new(),
639
+ attack_surface: Vec::new(),
640
+ runtime_coverage: None,
641
+ next_steps: vec![NextStep {
642
+ id: "inspect-control".to_owned(),
643
+ command: "dart-decimate inspect --file lib/\x1b[31mbad.dart".to_owned(),
644
+ reason: "Review \x07bell evidence".to_owned(),
645
+ }],
646
+ };
647
+
648
+ let rendered = render_html_report(&report);
649
+
650
+ assert!(!rendered.contains('\x1b'));
651
+ assert!(!rendered.contains('\x07'));
652
+ assert!(rendered.contains("lib/&#x1B;[31mbad.dart"));
653
+ assert!(rendered.contains("&#x7;bell"));
654
+ }
655
+
656
+ #[test]
657
+ fn renders_omitted_details_for_summary_only_failures() {
658
+ let mut report = JsonReport {
659
+ schema_version: "dart-decimate.report.v1".to_owned(),
660
+ kind: "combined".to_owned(),
661
+ tool: "dart-decimate".to_owned(),
662
+ command: ReportCommand::Security,
663
+ verdict: Verdict::Fail,
664
+ summary: ReportSummary {
665
+ files: 1,
666
+ findings: 2,
667
+ security_candidates: 2,
668
+ ..ReportSummary::default()
669
+ },
670
+ findings: Vec::new(),
671
+ clone_groups: Vec::new(),
672
+ complexity: Vec::new(),
673
+ file_scores: Vec::new(),
674
+ hotspots: Vec::new(),
675
+ refactoring_targets: Vec::new(),
676
+ threshold_overrides: Vec::new(),
677
+ feature_flags: Vec::new(),
678
+ security_candidates: Vec::new(),
679
+ attack_surface: Vec::new(),
680
+ runtime_coverage: None,
681
+ next_steps: Vec::new(),
682
+ };
683
+ report.findings.clear();
684
+
685
+ let rendered = render_html_report(&report);
686
+
687
+ assert!(rendered.contains("<h1>security report</h1>"));
688
+ assert!(rendered.contains("2 findings were omitted from this summary output."));
689
+ assert!(!rendered.contains("No findings. The selected Dart graph checks passed."));
690
+ }
691
+ }