executable-stories-formatters 0.8.0 → 0.9.0

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.
package/dist/index.js CHANGED
@@ -281,7 +281,8 @@ function canonicalizeTestCase(raw, options, projectRoot) {
281
281
  projectName: raw.projectName,
282
282
  retry: raw.retry ?? 0,
283
283
  retries: raw.retries ?? 0,
284
- tags
284
+ tags,
285
+ ...raw.evidence ? { evidence: raw.evidence } : {}
285
286
  };
286
287
  }
287
288
  function normalizeTags(story) {
@@ -13814,7 +13815,7 @@ function renderDocEntry(entry, deps) {
13814
13815
  // src/formatters/html/renderers/steps.ts
13815
13816
  var CONTINUATION_KEYWORDS = ["And", "But", "*"];
13816
13817
  function renderStep(step, stepResult, index, deps) {
13817
- const statusIcon2 = stepResult ? deps.getStatusIcon(stepResult.status) : "\u25CB";
13818
+ const statusIcon4 = stepResult ? deps.getStatusIcon(stepResult.status) : "\u25CB";
13818
13819
  const statusClass = stepResult ? `status-${stepResult.status}` : "";
13819
13820
  const duration = stepResult && stepResult.durationMs > 0 ? `${stepResult.durationMs}ms` : "";
13820
13821
  const keywordTrimmed = step.keyword.trim();
@@ -13823,7 +13824,7 @@ function renderStep(step, stepResult, index, deps) {
13823
13824
  const stepDocs = deps.renderDocs(step.docs, "step-docs");
13824
13825
  const textHtml = deps.highlightStepParams ? deps.highlightStepParams(step.text) : deps.escapeHtml(step.text);
13825
13826
  return `<div class="${stepClass}" data-keyword="${deps.escapeHtml(keywordTrimmed)}" data-text="${deps.escapeHtml(step.text)}">
13826
- <span class="step-status ${statusClass}">${statusIcon2}</span>
13827
+ <span class="step-status ${statusClass}">${statusIcon4}</span>
13827
13828
  <span class="step-keyword">${deps.escapeHtml(step.keyword)}</span>
13828
13829
  <span class="step-text">${textHtml}</span>
13829
13830
  <span class="step-duration">${duration}</span>
@@ -13873,16 +13874,16 @@ function hasSufficientHistory(entries, min) {
13873
13874
  }
13874
13875
 
13875
13876
  // src/formatters/html/renderers/scenario.ts
13876
- function renderTicket(ticket, template, escapeHtml3) {
13877
+ function renderTicket(ticket, template, escapeHtml4) {
13877
13878
  const url = ticket.url ?? (template ? template.replace("{ticket}", ticket.id) : void 0);
13878
13879
  if (url) {
13879
- return `<a class="tag ticket-tag" href="${escapeHtml3(url)}" target="_blank" rel="noopener noreferrer">${escapeHtml3(ticket.id)}</a>`;
13880
+ return `<a class="tag ticket-tag" href="${escapeHtml4(url)}" target="_blank" rel="noopener noreferrer">${escapeHtml4(ticket.id)}</a>`;
13880
13881
  }
13881
- return `<span class="tag ticket-tag">${escapeHtml3(ticket.id)}</span>`;
13882
+ return `<span class="tag ticket-tag">${escapeHtml4(ticket.id)}</span>`;
13882
13883
  }
13883
13884
  function renderScenario(args, deps) {
13884
13885
  const { tc } = args;
13885
- const statusIcon2 = deps.getStatusIcon(tc.status);
13886
+ const statusIcon4 = deps.getStatusIcon(tc.status);
13886
13887
  const statusClass = `status-${tc.status}`;
13887
13888
  const duration = tc.durationMs > 0 ? `${(tc.durationMs / 1e3).toFixed(2)}s` : "";
13888
13889
  const tags = tc.tags.map((t) => `<span class="tag">${deps.escapeHtml(t)}</span>`).join("");
@@ -13952,7 +13953,7 @@ function renderScenario(args, deps) {
13952
13953
  <div class="scenario-header" role="button" tabindex="0" aria-expanded="${ariaExpanded}">
13953
13954
  <div class="scenario-info">
13954
13955
  <div class="scenario-title">
13955
- <span class="status-icon ${statusClass}">${statusIcon2}</span>
13956
+ <span class="status-icon ${statusClass}">${statusIcon4}</span>
13956
13957
  <span class="scenario-name">${deps.escapeHtml(tc.story.scenario)}</span>
13957
13958
  </div>
13958
13959
  <div class="scenario-meta">${tags}${tickets}${outcomeBadge}${sourceLink}${traceBadge}${metricBadges}</div>
@@ -14078,7 +14079,7 @@ function flattenTree(roots) {
14078
14079
  }
14079
14080
  return result;
14080
14081
  }
14081
- function buildTooltip(span, escapeHtml3) {
14082
+ function buildTooltip(span, escapeHtml4) {
14082
14083
  const parts = [];
14083
14084
  parts.push(`${span.name} (${formatDuration(span.durationMs)})`);
14084
14085
  if (span.statusMessage) {
@@ -14096,7 +14097,7 @@ function buildTooltip(span, escapeHtml3) {
14096
14097
  if (text2.length > TOOLTIP_MAX_LENGTH) {
14097
14098
  text2 = text2.slice(0, TOOLTIP_MAX_LENGTH - 3) + "...";
14098
14099
  }
14099
- return escapeHtml3(text2);
14100
+ return escapeHtml4(text2);
14100
14101
  }
14101
14102
  function renderTraceView(args, deps) {
14102
14103
  if (!args.spans || args.spans.length === 0) return "";
@@ -14319,11 +14320,11 @@ function renderToc(args, deps) {
14319
14320
  const featureName = suitePaths.length > 0 && suitePaths[0].length > 0 ? suitePaths[0][0] : file.split("/").pop()?.replace(/\.[^.]+$/, "") ?? file;
14320
14321
  const featureSlug = `feature-${slugify(file)}`;
14321
14322
  const scenarios = testCases.map((tc) => {
14322
- const statusIcon2 = deps.getStatusIcon(tc.status);
14323
+ const statusIcon4 = deps.getStatusIcon(tc.status);
14323
14324
  const statusClass = `status-${tc.status}`;
14324
14325
  const failedClass = tc.status === "failed" ? " toc-failed" : "";
14325
14326
  return `<a class="toc-scenario${failedClass}" href="#scenario-${tc.id}">
14326
- <span class="toc-status ${statusClass}">${statusIcon2}</span>
14327
+ <span class="toc-status ${statusClass}">${statusIcon4}</span>
14327
14328
  ${deps.escapeHtml(tc.story.scenario)}
14328
14329
  </a>`;
14329
14330
  }).join("\n");
@@ -19634,6 +19635,697 @@ function listScenarios(args, _deps) {
19634
19635
  return lines.join("\n");
19635
19636
  }
19636
19637
 
19638
+ // src/review/conventions.ts
19639
+ var CHANGE_TAG_PREFIX = "change:";
19640
+ var AUDIENCE_TAG_PREFIX = "audience:";
19641
+ var VALID_CHANGE_TYPES = /* @__PURE__ */ new Set([
19642
+ "feature",
19643
+ "bugfix",
19644
+ "refactor",
19645
+ "perf",
19646
+ "deps"
19647
+ ]);
19648
+ var STAKEHOLDER_FILE = /(?:\.e2e\.)|(?:^|\/)e2e\/|(?:\.spec\.)/i;
19649
+ var CODE_EXTENSIONS = /* @__PURE__ */ new Set([
19650
+ "ts",
19651
+ "tsx",
19652
+ "js",
19653
+ "jsx",
19654
+ "mjs",
19655
+ "cjs",
19656
+ "py",
19657
+ "go",
19658
+ "rs",
19659
+ "kt",
19660
+ "kts",
19661
+ "java",
19662
+ "cs",
19663
+ "rb"
19664
+ ]);
19665
+ var TEST_INFIX = /\.(?:story\.)?(?:int\.|e2e\.|unit\.)?(?:test|spec|cy)\.[a-z]+$/i;
19666
+ function deriveAudience(sourceFile, tags) {
19667
+ const override = tags.map((t) => t.toLowerCase()).find((t) => t.startsWith(AUDIENCE_TAG_PREFIX));
19668
+ if (override) {
19669
+ const value = override.slice(AUDIENCE_TAG_PREFIX.length);
19670
+ if (value === "stakeholder" || value === "engineer") return value;
19671
+ }
19672
+ return STAKEHOLDER_FILE.test(sourceFile) ? "stakeholder" : "engineer";
19673
+ }
19674
+ function deriveChangeType(tags) {
19675
+ for (const tag of tags) {
19676
+ const lower = tag.toLowerCase();
19677
+ if (lower.startsWith(CHANGE_TAG_PREFIX)) {
19678
+ const value = lower.slice(CHANGE_TAG_PREFIX.length);
19679
+ if (VALID_CHANGE_TYPES.has(value)) return value;
19680
+ }
19681
+ }
19682
+ return "unknown";
19683
+ }
19684
+ function extensionOf(path10) {
19685
+ const base = path10.split("/").pop() ?? path10;
19686
+ const dot = base.lastIndexOf(".");
19687
+ return dot === -1 ? "" : base.slice(dot + 1).toLowerCase();
19688
+ }
19689
+ function isTestFile(path10) {
19690
+ return TEST_INFIX.test(path10);
19691
+ }
19692
+ function isReviewableSource(path10) {
19693
+ if (isTestFile(path10)) return false;
19694
+ if (path10.endsWith(".d.ts")) return false;
19695
+ return CODE_EXTENSIONS.has(extensionOf(path10));
19696
+ }
19697
+ function testBaseKey(testFile) {
19698
+ return testFile.replace(TEST_INFIX, "");
19699
+ }
19700
+ function sourceBaseKey(sourceFile) {
19701
+ const dot = sourceFile.lastIndexOf(".");
19702
+ const slash = sourceFile.lastIndexOf("/");
19703
+ return dot > slash ? sourceFile.slice(0, dot) : sourceFile;
19704
+ }
19705
+
19706
+ // src/review/build-review.ts
19707
+ var STRENGTH_RANK = {
19708
+ none: 0,
19709
+ weak: 1,
19710
+ moderate: 2,
19711
+ strong: 3
19712
+ };
19713
+ var INTENT_SECTION_TITLE = /\b(why|intent|approach|rationale|reasoning)\b/i;
19714
+ function findDoc(docs, predicate) {
19715
+ if (!docs) return void 0;
19716
+ for (const doc of docs) {
19717
+ if (predicate(doc)) return doc;
19718
+ const nested = findDoc(doc.children, predicate);
19719
+ if (nested) return nested;
19720
+ }
19721
+ return void 0;
19722
+ }
19723
+ function anyDoc(docs, predicate) {
19724
+ return findDoc(docs, predicate) !== void 0;
19725
+ }
19726
+ function extractIntent(testCase) {
19727
+ const docs = testCase.story.docs;
19728
+ const section = findDoc(
19729
+ docs,
19730
+ (d) => d.kind === "section" && INTENT_SECTION_TITLE.test(d.title)
19731
+ );
19732
+ if (section && section.kind === "section") return section.markdown;
19733
+ const note = findDoc(docs, (d) => d.kind === "note");
19734
+ if (note && note.kind === "note") return note.text;
19735
+ return void 0;
19736
+ }
19737
+ function hasScreenshot(testCase) {
19738
+ if (testCase.attachments.some((a) => a.mediaType.startsWith("image/"))) {
19739
+ return true;
19740
+ }
19741
+ if (anyDoc(testCase.story.docs, (d) => d.kind === "screenshot")) return true;
19742
+ return testCase.story.steps.some(
19743
+ (step) => anyDoc(step.docs, (d) => d.kind === "screenshot")
19744
+ );
19745
+ }
19746
+ function hasOtelTrace(testCase) {
19747
+ return (testCase.story.otelSpans?.length ?? 0) > 0;
19748
+ }
19749
+ function gradeEvidence(testCase, audience) {
19750
+ if (testCase.status !== "passed") {
19751
+ return {
19752
+ strength: "none",
19753
+ reasons: [`test is ${testCase.status} \u2014 the proof does not hold`]
19754
+ };
19755
+ }
19756
+ const ev = testCase.evidence;
19757
+ const screenshot = hasScreenshot(testCase);
19758
+ const otel = hasOtelTrace(testCase);
19759
+ const isIntegration = /\.int\.test\./i.test(testCase.sourceFile);
19760
+ const mutation = ev?.mutationScorePct;
19761
+ const changedCov = ev?.changedLineCoveragePct;
19762
+ const strong2 = [];
19763
+ if (ev?.failingFirstVerified) {
19764
+ strong2.push("failing-first verified (red on base ref, green on head)");
19765
+ }
19766
+ if (typeof mutation === "number" && mutation >= 80) {
19767
+ strong2.push(`mutation score ${mutation}% (\u226580%)`);
19768
+ }
19769
+ if (screenshot && otel) {
19770
+ strong2.push("backed by screenshot + OTEL trace");
19771
+ } else if (audience === "stakeholder" && (screenshot || otel)) {
19772
+ strong2.push(`stakeholder proof: ${screenshot ? "screenshot" : "OTEL trace"}`);
19773
+ }
19774
+ if (strong2.length > 0) return { strength: "strong", reasons: strong2 };
19775
+ const moderate = [];
19776
+ if (screenshot) moderate.push("screenshot attached");
19777
+ if (otel) moderate.push("OTEL trace attached");
19778
+ if (typeof mutation === "number" && mutation >= 50) {
19779
+ moderate.push(`mutation score ${mutation}%`);
19780
+ }
19781
+ if (typeof changedCov === "number" && changedCov >= 80) {
19782
+ moderate.push(`changed-line coverage ${changedCov}%`);
19783
+ }
19784
+ if (isIntegration) moderate.push("integration-level test");
19785
+ if (moderate.length > 0) return { strength: "moderate", reasons: moderate };
19786
+ return {
19787
+ strength: "weak",
19788
+ reasons: [
19789
+ "passing test only \u2014 no corroborating evidence (add e2e proof, mutation score, or failing-first)"
19790
+ ]
19791
+ };
19792
+ }
19793
+ function toClaim(testCase, changedSourcePaths) {
19794
+ const audience = deriveAudience(testCase.sourceFile, testCase.tags);
19795
+ const changeType = deriveChangeType(testCase.tags);
19796
+ const { strength, reasons } = gradeEvidence(testCase, audience);
19797
+ const key = testBaseKey(testCase.sourceFile);
19798
+ const coversFiles = changedSourcePaths.filter(
19799
+ (path10) => sourceBaseKey(path10) === key
19800
+ );
19801
+ return {
19802
+ id: testCase.id,
19803
+ scenario: testCase.story.scenario,
19804
+ sourceFile: testCase.sourceFile,
19805
+ sourceLine: testCase.sourceLine,
19806
+ status: testCase.status,
19807
+ audience,
19808
+ changeType,
19809
+ strength,
19810
+ strengthReasons: reasons,
19811
+ intent: extractIntent(testCase),
19812
+ coversFiles,
19813
+ testCase
19814
+ };
19815
+ }
19816
+ function bandFor(claims) {
19817
+ if (claims.length === 0) return "uncovered";
19818
+ const maxRank = Math.max(...claims.map((c) => STRENGTH_RANK[c.strength]));
19819
+ return maxRank >= STRENGTH_RANK.moderate ? "covered" : "weak";
19820
+ }
19821
+ var AUDIENCE_ORDER = {
19822
+ stakeholder: 0,
19823
+ engineer: 1
19824
+ };
19825
+ function buildReview(run, context = { changedFiles: [] }) {
19826
+ const changedSource = context.changedFiles.filter(
19827
+ (f) => isReviewableSource(f.path)
19828
+ );
19829
+ const changedSourcePaths = changedSource.map((f) => f.path);
19830
+ const claims = run.testCases.map((tc) => toClaim(tc, changedSourcePaths));
19831
+ const changedFiles = changedSource.map((file) => {
19832
+ const covering = claims.filter((c) => c.coversFiles.includes(file.path));
19833
+ return {
19834
+ path: file.path,
19835
+ changeKind: file.changeKind,
19836
+ band: bandFor(covering),
19837
+ claims: covering.map((c) => ({
19838
+ id: c.id,
19839
+ scenario: c.scenario,
19840
+ strength: c.strength
19841
+ }))
19842
+ };
19843
+ });
19844
+ const sortedClaims = [...claims].sort((a, b) => {
19845
+ if (AUDIENCE_ORDER[a.audience] !== AUDIENCE_ORDER[b.audience]) {
19846
+ return AUDIENCE_ORDER[a.audience] - AUDIENCE_ORDER[b.audience];
19847
+ }
19848
+ if (STRENGTH_RANK[a.strength] !== STRENGTH_RANK[b.strength]) {
19849
+ return STRENGTH_RANK[a.strength] - STRENGTH_RANK[b.strength];
19850
+ }
19851
+ if (a.sourceFile !== b.sourceFile) {
19852
+ return a.sourceFile.localeCompare(b.sourceFile);
19853
+ }
19854
+ return a.scenario.localeCompare(b.scenario);
19855
+ });
19856
+ const bandRank = { uncovered: 0, weak: 1, covered: 2 };
19857
+ const sortedFiles = [...changedFiles].sort((a, b) => {
19858
+ if (bandRank[a.band] !== bandRank[b.band]) {
19859
+ return bandRank[a.band] - bandRank[b.band];
19860
+ }
19861
+ return a.path.localeCompare(b.path);
19862
+ });
19863
+ const summary = buildSummary2(sortedClaims, sortedFiles);
19864
+ return {
19865
+ run,
19866
+ context,
19867
+ summary,
19868
+ claims: sortedClaims,
19869
+ changedFiles: sortedFiles
19870
+ };
19871
+ }
19872
+ function buildSummary2(claims, changedFiles) {
19873
+ const byAudience = {
19874
+ stakeholder: 0,
19875
+ engineer: 0
19876
+ };
19877
+ const byStrength = {
19878
+ none: 0,
19879
+ weak: 0,
19880
+ moderate: 0,
19881
+ strong: 0
19882
+ };
19883
+ for (const claim of claims) {
19884
+ byAudience[claim.audience] += 1;
19885
+ byStrength[claim.strength] += 1;
19886
+ }
19887
+ return {
19888
+ totalClaims: claims.length,
19889
+ byAudience,
19890
+ byStrength,
19891
+ changedSourceFiles: changedFiles.length,
19892
+ uncovered: changedFiles.filter((f) => f.band === "uncovered").length,
19893
+ weaklyCovered: changedFiles.filter((f) => f.band === "weak").length,
19894
+ covered: changedFiles.filter((f) => f.band === "covered").length
19895
+ };
19896
+ }
19897
+
19898
+ // src/formatters/review-markdown.ts
19899
+ var STRENGTH_BADGE = {
19900
+ strong: "\u{1F7E2} strong",
19901
+ moderate: "\u{1F7E1} moderate",
19902
+ weak: "\u{1F7E0} weak",
19903
+ none: "\u{1F534} none"
19904
+ };
19905
+ function statusIcon2(status) {
19906
+ switch (status) {
19907
+ case "passed":
19908
+ return "\u2705";
19909
+ case "failed":
19910
+ return "\u274C";
19911
+ case "skipped":
19912
+ return "\u2298";
19913
+ default:
19914
+ return "\u2022";
19915
+ }
19916
+ }
19917
+ function escapeCell2(value) {
19918
+ return value.replace(/\|/g, "\\|").replace(/\n/g, " ");
19919
+ }
19920
+ function intentSummary(intent) {
19921
+ const firstLine = intent.split("\n").find((l) => l.trim().length > 0) ?? "";
19922
+ const trimmed = firstLine.trim();
19923
+ return trimmed.length > 200 ? `${trimmed.slice(0, 197)}\u2026` : trimmed;
19924
+ }
19925
+ function renderTicket2(ticket) {
19926
+ return ticket.url ? `[${ticket.id}](${ticket.url})` : `\`${ticket.id}\``;
19927
+ }
19928
+ function renderUncoveredBand(lines, files) {
19929
+ const uncovered = files.filter((f) => f.band === "uncovered");
19930
+ if (uncovered.length === 0) return;
19931
+ lines.push(`## \u{1F534} Changed code with no evidence (${uncovered.length})`);
19932
+ lines.push("");
19933
+ lines.push("Start here \u2014 these changed source files have no claim or test behind them.");
19934
+ lines.push("");
19935
+ for (const file of uncovered) {
19936
+ lines.push(`- \`${file.path}\` _(${file.changeKind})_`);
19937
+ }
19938
+ lines.push("");
19939
+ }
19940
+ function renderWeakBand(lines, files) {
19941
+ const weak = files.filter((f) => f.band === "weak");
19942
+ if (weak.length === 0) return;
19943
+ lines.push(`## \u{1F7E1} Changed code with weak evidence (${weak.length})`);
19944
+ lines.push("");
19945
+ for (const file of weak) {
19946
+ const covered = file.claims.map((c) => `${escapeCell2(c.scenario)} (${c.strength})`).join(", ");
19947
+ lines.push(`- \`${file.path}\` _(${file.changeKind})_ \u2014 only: ${covered}`);
19948
+ }
19949
+ lines.push("");
19950
+ }
19951
+ function renderClaim(lines, claim) {
19952
+ lines.push(`### ${statusIcon2(claim.status)} ${claim.scenario}`);
19953
+ lines.push("");
19954
+ lines.push(`- File: \`${claim.sourceFile}:${claim.sourceLine}\``);
19955
+ if (claim.changeType !== "unknown") {
19956
+ lines.push(`- Change: \`${claim.changeType}\``);
19957
+ }
19958
+ const tickets = claim.testCase.story.tickets ?? [];
19959
+ if (tickets.length > 0) {
19960
+ lines.push(`- Tickets: ${tickets.map(renderTicket2).join(", ")}`);
19961
+ }
19962
+ lines.push(
19963
+ `- Evidence: ${STRENGTH_BADGE[claim.strength]} \u2014 ${claim.strengthReasons.join("; ")}`
19964
+ );
19965
+ if (claim.coversFiles.length > 0) {
19966
+ lines.push(
19967
+ `- Covers: ${claim.coversFiles.map((f) => `\`${f}\``).join(", ")}`
19968
+ );
19969
+ }
19970
+ if (claim.intent) {
19971
+ lines.push(`- Why: ${escapeCell2(intentSummary(claim.intent))}`);
19972
+ }
19973
+ lines.push("");
19974
+ }
19975
+ function renderAudienceSection(lines, title, claims) {
19976
+ if (claims.length === 0) return;
19977
+ lines.push(`## ${title} (${claims.length})`);
19978
+ lines.push("");
19979
+ for (const claim of claims) {
19980
+ renderClaim(lines, claim);
19981
+ }
19982
+ }
19983
+ var ReviewMarkdownFormatter = class {
19984
+ title;
19985
+ constructor(options = {}) {
19986
+ this.title = options.title ?? "Evidence Review";
19987
+ }
19988
+ format(review) {
19989
+ const lines = [];
19990
+ const { summary, context } = review;
19991
+ lines.push(`# ${this.title}`);
19992
+ lines.push("");
19993
+ if (context.baseRef || context.headRef) {
19994
+ lines.push(
19995
+ `Comparing \`${context.baseRef ?? "base"}\` \u2192 \`${context.headRef ?? "head"}\`.`
19996
+ );
19997
+ lines.push("");
19998
+ }
19999
+ lines.push("## Review priority");
20000
+ lines.push("");
20001
+ if (summary.changedSourceFiles === 0) {
20002
+ lines.push(
20003
+ "No changed source files supplied \u2014 showing claims and evidence only."
20004
+ );
20005
+ } else if (summary.uncovered > 0) {
20006
+ lines.push(
20007
+ `Review the ${summary.uncovered} unaccounted-for file(s) first: changed code with no evidence behind it.`
20008
+ );
20009
+ } else if (summary.weaklyCovered > 0) {
20010
+ lines.push(
20011
+ `No unaccounted-for changes. Review ${summary.weaklyCovered} weakly-covered file(s) next.`
20012
+ );
20013
+ } else {
20014
+ lines.push("Every changed source file is backed by at least moderate evidence.");
20015
+ }
20016
+ lines.push("");
20017
+ if (summary.changedSourceFiles > 0) {
20018
+ lines.push("| \u{1F534} Uncovered | \u{1F7E1} Weak | \u{1F7E2} Covered | Changed files |");
20019
+ lines.push("| ---: | ---: | ---: | ---: |");
20020
+ lines.push(
20021
+ `| ${summary.uncovered} | ${summary.weaklyCovered} | ${summary.covered} | ${summary.changedSourceFiles} |`
20022
+ );
20023
+ lines.push("");
20024
+ }
20025
+ lines.push("| Claims | Stakeholder | Engineer | Strong | Moderate | Weak | None |");
20026
+ lines.push("| ---: | ---: | ---: | ---: | ---: | ---: | ---: |");
20027
+ lines.push(
20028
+ `| ${summary.totalClaims} | ${summary.byAudience.stakeholder} | ${summary.byAudience.engineer} | ${summary.byStrength.strong} | ${summary.byStrength.moderate} | ${summary.byStrength.weak} | ${summary.byStrength.none} |`
20029
+ );
20030
+ lines.push("");
20031
+ renderUncoveredBand(lines, review.changedFiles);
20032
+ renderWeakBand(lines, review.changedFiles);
20033
+ renderAudienceSection(
20034
+ lines,
20035
+ "Stakeholder behaviour",
20036
+ review.claims.filter((c) => c.audience === "stakeholder")
20037
+ );
20038
+ renderAudienceSection(
20039
+ lines,
20040
+ "Engineer changes",
20041
+ review.claims.filter((c) => c.audience === "engineer")
20042
+ );
20043
+ return lines.join("\n").trimEnd();
20044
+ }
20045
+ };
20046
+
20047
+ // src/formatters/review-html.ts
20048
+ function escapeHtml3(value) {
20049
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
20050
+ }
20051
+ var STRENGTH_LABEL = {
20052
+ strong: "Strong",
20053
+ moderate: "Moderate",
20054
+ weak: "Weak",
20055
+ none: "None"
20056
+ };
20057
+ function statusIcon3(status) {
20058
+ switch (status) {
20059
+ case "passed":
20060
+ return "\u2705";
20061
+ case "failed":
20062
+ return "\u274C";
20063
+ case "skipped":
20064
+ return "\u2298";
20065
+ default:
20066
+ return "\u2022";
20067
+ }
20068
+ }
20069
+ function formatStep3(step) {
20070
+ return `<li><strong>${escapeHtml3(step.keyword)}</strong> ${escapeHtml3(step.text)}</li>`;
20071
+ }
20072
+ function inlineDoc(doc) {
20073
+ switch (doc.kind) {
20074
+ case "note":
20075
+ return escapeHtml3(doc.text);
20076
+ case "section":
20077
+ return `<strong>${escapeHtml3(doc.title)}</strong>: ${escapeHtml3(doc.markdown)}`;
20078
+ case "kv":
20079
+ return `${escapeHtml3(doc.label)}: ${escapeHtml3(String(doc.value))}`;
20080
+ case "code":
20081
+ return `${escapeHtml3(doc.label)}: <code>${escapeHtml3(doc.content)}</code>`;
20082
+ case "link":
20083
+ return `${escapeHtml3(doc.label)}: ${escapeHtml3(doc.url)}`;
20084
+ default:
20085
+ return escapeHtml3(doc.kind);
20086
+ }
20087
+ }
20088
+ function renderEvidenceArtifacts(testCase) {
20089
+ const parts = [];
20090
+ for (const att of testCase.attachments) {
20091
+ if (att.mediaType.startsWith("image/") && att.contentEncoding === "BASE64") {
20092
+ parts.push(
20093
+ `<img class="shot" alt="${escapeHtml3(att.name)}" src="data:${escapeHtml3(att.mediaType)};base64,${att.body}" />`
20094
+ );
20095
+ }
20096
+ }
20097
+ if ((testCase.story.otelSpans?.length ?? 0) > 0) {
20098
+ parts.push(
20099
+ `<p class="trace-note">\u{1F4E1} ${testCase.story.otelSpans.length} OTEL span(s) captured</p>`
20100
+ );
20101
+ }
20102
+ return parts.length > 0 ? `<div class="artifacts">${parts.join("")}</div>` : "";
20103
+ }
20104
+ function renderTicketPills(claim) {
20105
+ const tickets = claim.testCase.story.tickets ?? [];
20106
+ if (tickets.length === 0) return "";
20107
+ return `<div class="ticket-row">${tickets.map((ticket) => {
20108
+ const label = escapeHtml3(ticket.id);
20109
+ if (ticket.url) {
20110
+ return `<a class="ticket-pill" href="${escapeHtml3(ticket.url)}" target="_blank" rel="noopener noreferrer">${label}</a>`;
20111
+ }
20112
+ return `<span class="ticket-pill">${label}</span>`;
20113
+ }).join("")}</div>`;
20114
+ }
20115
+ function renderClaimCard(claim) {
20116
+ const ticketSearch = (claim.testCase.story.tickets ?? []).map((ticket) => ticket.id).join(" ");
20117
+ const search = escapeHtml3(
20118
+ `${claim.scenario} ${claim.sourceFile} ${claim.changeType} ${claim.audience} ${claim.strength} ${ticketSearch}`
20119
+ ).toLowerCase();
20120
+ const steps = claim.testCase.story.steps.length > 0 ? `<ul class="step-list">${claim.testCase.story.steps.map(formatStep3).join("")}</ul>` : "";
20121
+ const reasons = `<ul class="reasons">${claim.strengthReasons.map((r) => `<li>${escapeHtml3(r)}</li>`).join("")}</ul>`;
20122
+ const intent = claim.intent !== void 0 ? `<div class="intent"><span class="intent-label">Why</span> ${escapeHtml3(claim.intent)}</div>` : "";
20123
+ const covers = claim.coversFiles.length > 0 ? `<p class="covers">Covers ${claim.coversFiles.map((f) => `<code>${escapeHtml3(f)}</code>`).join(", ")}</p>` : "";
20124
+ const docs = (claim.testCase.story.docs ?? []).filter(
20125
+ (d) => d.kind === "section" || d.kind === "note"
20126
+ );
20127
+ const extraDocs = docs.length > 0 && claim.intent === void 0 ? `<div class="intent">${docs.map(inlineDoc).join("<br>")}</div>` : "";
20128
+ return `
20129
+ <article class="claim-card" data-audience="${claim.audience}" data-strength="${claim.strength}" data-search="${search}">
20130
+ <header class="claim-header">
20131
+ <div>
20132
+ <span class="strength-badge strength-${claim.strength}">${STRENGTH_LABEL[claim.strength]}</span>
20133
+ ${claim.changeType !== "unknown" ? `<span class="change-pill">${escapeHtml3(claim.changeType)}</span>` : ""}
20134
+ <h3>${statusIcon3(claim.status)} ${escapeHtml3(claim.scenario)}</h3>
20135
+ <p class="source">${escapeHtml3(`${claim.sourceFile}:${claim.sourceLine}`)}</p>
20136
+ ${renderTicketPills(claim)}
20137
+ </div>
20138
+ </header>
20139
+ ${intent}${extraDocs}
20140
+ <div class="evidence-block">
20141
+ <span class="evidence-label">Evidence</span>
20142
+ ${reasons}
20143
+ </div>
20144
+ ${covers}
20145
+ ${renderEvidenceArtifacts(claim.testCase)}
20146
+ ${steps}
20147
+ </article>`;
20148
+ }
20149
+ function renderChangedFileRow(file) {
20150
+ const claims = file.claims.length > 0 ? file.claims.map((c) => `${escapeHtml3(c.scenario)} <em>(${c.strength})</em>`).join(", ") : "\u2014";
20151
+ return `<tr data-band="${file.band}">
20152
+ <td><span class="band-dot band-${file.band}"></span></td>
20153
+ <td><code>${escapeHtml3(file.path)}</code></td>
20154
+ <td>${escapeHtml3(file.changeKind)}</td>
20155
+ <td>${claims}</td>
20156
+ </tr>`;
20157
+ }
20158
+ function renderAudienceSection2(title, claims) {
20159
+ if (claims.length === 0) return "";
20160
+ return `<section class="audience-section">
20161
+ <h2>${escapeHtml3(title)} <span class="count">${claims.length}</span></h2>
20162
+ <div class="claim-list">${claims.map(renderClaimCard).join("\n")}</div>
20163
+ </section>`;
20164
+ }
20165
+ var REVIEW_CSS = `
20166
+ * { box-sizing: border-box; }
20167
+ body { margin: 0; font-family: var(--font-sans, system-ui, sans-serif); background: var(--background); color: var(--foreground); }
20168
+ main { max-width: 1100px; margin: 0 auto; padding: 32px 20px 80px; }
20169
+ h1, h2, h3, p { margin: 0; }
20170
+ .review-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
20171
+ .subtle { color: var(--muted-foreground); margin-top: 6px; }
20172
+ .theme-toggle { background: var(--secondary); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; cursor: pointer; font-size: 1.1rem; color: var(--foreground); }
20173
+ .card, .claim-card, .summary-card, .panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius, 16px); }
20174
+ .hero-card { padding: 24px; margin-bottom: 20px; }
20175
+ .summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-bottom: 20px; }
20176
+ .summary-card { padding: 14px 16px; }
20177
+ .summary-card strong { display: block; font-size: 1.8rem; }
20178
+ .priority-banner { padding: 18px 20px; margin-bottom: 20px; background: linear-gradient(135deg, color-mix(in srgb, var(--destructive) 10%, transparent), var(--card)); }
20179
+ .panel { padding: 18px; margin-bottom: 24px; }
20180
+ table { width: 100%; border-collapse: collapse; }
20181
+ th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
20182
+ th { color: var(--muted-foreground); font-weight: 600; }
20183
+ .band-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }
20184
+ .band-uncovered { background: var(--destructive); }
20185
+ .band-weak { background: var(--warning, #b58900); }
20186
+ .band-covered { background: var(--success, #2e7d32); }
20187
+ .toolbar { position: sticky; top: 12px; z-index: 2; display: flex; flex-wrap: wrap; gap: 10px; padding: 14px; margin-bottom: 20px; }
20188
+ .toolbar input { flex: 1 1 240px; border: 1px solid var(--border); border-radius: 999px; padding: 10px 14px; font: inherit; background: var(--background); color: var(--foreground); }
20189
+ .toolbar button { border: 1px solid var(--border); background: var(--secondary); border-radius: 999px; padding: 10px 14px; font: inherit; cursor: pointer; color: var(--foreground); }
20190
+ .toolbar button.active { background: var(--foreground); color: var(--background); }
20191
+ .audience-section { margin-bottom: 28px; }
20192
+ .audience-section h2 { margin-bottom: 12px; }
20193
+ .count { color: var(--muted-foreground); font-weight: 400; }
20194
+ .claim-list { display: grid; gap: 14px; }
20195
+ .claim-card { padding: 18px; }
20196
+ .claim-header h3 { margin-top: 8px; }
20197
+ .source { color: var(--muted-foreground); font-family: var(--font-mono, ui-monospace, monospace); font-size: 0.85rem; margin-top: 4px; }
20198
+ .ticket-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
20199
+ .ticket-pill { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 999px; padding: 3px 9px; color: var(--muted-foreground); background: var(--background); font-size: 0.78rem; text-decoration: none; }
20200
+ .ticket-pill:hover { color: var(--foreground); border-color: var(--muted-foreground); }
20201
+ .strength-badge, .change-pill { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: 0.8rem; margin-right: 6px; }
20202
+ .change-pill { background: var(--secondary); }
20203
+ .strength-strong { background: color-mix(in srgb, var(--success, #2e7d32) 18%, transparent); color: var(--success, #2e7d32); }
20204
+ .strength-moderate { background: color-mix(in srgb, var(--warning, #b58900) 20%, transparent); color: var(--warning, #b58900); }
20205
+ .strength-weak { background: color-mix(in srgb, #d2691e 20%, transparent); color: #b5530a; }
20206
+ .strength-none { background: color-mix(in srgb, var(--destructive) 16%, transparent); color: var(--destructive); }
20207
+ .intent { margin: 12px 0; padding: 10px 12px; border-left: 3px solid var(--border); background: color-mix(in srgb, var(--card) 60%, var(--background)); border-radius: 6px; }
20208
+ .intent-label { font-weight: 700; margin-right: 6px; }
20209
+ .evidence-block { margin-top: 10px; }
20210
+ .evidence-label { font-weight: 600; color: var(--muted-foreground); }
20211
+ .reasons { margin: 6px 0 0; padding-left: 18px; }
20212
+ .covers { color: var(--muted-foreground); margin-top: 8px; font-size: 0.9rem; }
20213
+ .artifacts { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; }
20214
+ .shot { max-width: 280px; max-height: 200px; border: 1px solid var(--border); border-radius: 8px; }
20215
+ .trace-note { color: var(--muted-foreground); }
20216
+ .step-list { margin: 12px 0 0; padding-left: 18px; color: var(--muted-foreground); }
20217
+ `;
20218
+ var JS_THEME_TOGGLE2 = `
20219
+ function getSystemTheme() { return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; }
20220
+ function getEffectiveTheme() { var s = localStorage.getItem('review-theme'); return (s === 'dark' || s === 'light') ? s : getSystemTheme(); }
20221
+ function toggleTheme() { var n = getEffectiveTheme() === 'dark' ? 'light' : 'dark'; localStorage.setItem('review-theme', n); applyTheme(n); }
20222
+ function applyTheme(t) {
20223
+ document.documentElement.setAttribute('data-theme', t);
20224
+ var b = document.querySelector('.theme-toggle');
20225
+ if (b) { b.textContent = t === 'dark' ? '\\u2600\\ufe0f' : '\\ud83c\\udf19'; }
20226
+ }
20227
+ `;
20228
+ var ReviewHtmlFormatter = class {
20229
+ title;
20230
+ theme;
20231
+ darkMode;
20232
+ constructor(options = {}) {
20233
+ this.title = options.title ?? "Evidence Review";
20234
+ this.theme = resolveTheme(options.theme ?? "default");
20235
+ this.darkMode = options.darkMode ?? true;
20236
+ }
20237
+ format(review) {
20238
+ const { summary, context } = review;
20239
+ const priority = summary.changedSourceFiles === 0 ? "No changed source files supplied \u2014 showing claims and evidence only." : summary.uncovered > 0 ? `${summary.uncovered} changed file(s) have no evidence. Review them first.` : summary.weaklyCovered > 0 ? `No unaccounted-for changes. ${summary.weaklyCovered} file(s) are weakly covered.` : "Every changed source file is backed by at least moderate evidence.";
20240
+ const changedFilesPanel = summary.changedSourceFiles > 0 ? `<section class="panel">
20241
+ <h2>Changed files</h2>
20242
+ <table>
20243
+ <thead><tr><th></th><th>File</th><th>Change</th><th>Evidence</th></tr></thead>
20244
+ <tbody>${review.changedFiles.map(renderChangedFileRow).join("")}</tbody>
20245
+ </table>
20246
+ </section>` : "";
20247
+ const themeToggleHtml = this.darkMode ? `<button type="button" class="theme-toggle" onclick="toggleTheme()" aria-label="Toggle theme"></button>` : "";
20248
+ const themeInitJs = this.darkMode ? `${JS_THEME_TOGGLE2}
20249
+ applyTheme(getEffectiveTheme());` : "";
20250
+ const themeAttr = this.darkMode ? ' data-theme="light"' : "";
20251
+ const refsLine = context.baseRef || context.headRef ? `<p class="subtle">Comparing ${escapeHtml3(context.baseRef ?? "base")} \u2192 ${escapeHtml3(context.headRef ?? "head")}</p>` : "";
20252
+ return `<!doctype html>
20253
+ <html lang="en"${themeAttr}>
20254
+ <head>
20255
+ <meta charset="utf-8" />
20256
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
20257
+ <title>${escapeHtml3(this.title)}</title>
20258
+ <style>
20259
+ ${this.theme.css}
20260
+ ${REVIEW_CSS}
20261
+ </style>
20262
+ </head>
20263
+ <body>
20264
+ <main>
20265
+ <div class="hero-card card">
20266
+ <div class="review-header">
20267
+ <h1>${escapeHtml3(this.title)}</h1>
20268
+ ${themeToggleHtml}
20269
+ </div>
20270
+ ${refsLine}
20271
+ </div>
20272
+ <section class="summary-grid">
20273
+ <div class="summary-card"><strong>${summary.uncovered}</strong><span>\u{1F534} Uncovered</span></div>
20274
+ <div class="summary-card"><strong>${summary.weaklyCovered}</strong><span>\u{1F7E1} Weak</span></div>
20275
+ <div class="summary-card"><strong>${summary.covered}</strong><span>\u{1F7E2} Covered</span></div>
20276
+ <div class="summary-card"><strong>${summary.totalClaims}</strong><span>Claims</span></div>
20277
+ <div class="summary-card"><strong>${summary.byStrength.strong}</strong><span>Strong</span></div>
20278
+ <div class="summary-card"><strong>${summary.byStrength.weak + summary.byStrength.none}</strong><span>Weak/None</span></div>
20279
+ </section>
20280
+ <section class="card priority-banner">
20281
+ <h2>Review priority</h2>
20282
+ <p class="subtle">${escapeHtml3(priority)}</p>
20283
+ </section>
20284
+ ${changedFilesPanel}
20285
+ <section class="toolbar">
20286
+ <input type="search" placeholder="Filter claims by scenario, file, change-type" aria-label="Filter claims" />
20287
+ <button type="button" class="active" data-filter="all">All</button>
20288
+ <button type="button" data-filter="stakeholder">Stakeholder</button>
20289
+ <button type="button" data-filter="engineer">Engineer</button>
20290
+ <button type="button" data-filter="weak">Weak/None</button>
20291
+ </section>
20292
+ ${renderAudienceSection2("Stakeholder behaviour", review.claims.filter((c) => c.audience === "stakeholder"))}
20293
+ ${renderAudienceSection2("Engineer changes", review.claims.filter((c) => c.audience === "engineer"))}
20294
+ </main>
20295
+ <script>
20296
+ ${themeInitJs}
20297
+ const input = document.querySelector('input[type="search"]');
20298
+ const buttons = Array.from(document.querySelectorAll('[data-filter]'));
20299
+ const cards = Array.from(document.querySelectorAll('.claim-card'));
20300
+ let activeFilter = 'all';
20301
+ function applyFilters() {
20302
+ const query = (input.value || '').trim().toLowerCase();
20303
+ cards.forEach((card) => {
20304
+ const audience = card.getAttribute('data-audience');
20305
+ const strength = card.getAttribute('data-strength');
20306
+ const haystack = card.getAttribute('data-search') || '';
20307
+ let matchesFilter = activeFilter === 'all'
20308
+ || audience === activeFilter
20309
+ || (activeFilter === 'weak' && (strength === 'weak' || strength === 'none'));
20310
+ const matchesSearch = !query || haystack.includes(query);
20311
+ card.style.display = matchesFilter && matchesSearch ? '' : 'none';
20312
+ });
20313
+ }
20314
+ input.addEventListener('input', applyFilters);
20315
+ buttons.forEach((button) => {
20316
+ button.addEventListener('click', () => {
20317
+ activeFilter = button.getAttribute('data-filter');
20318
+ buttons.forEach((b) => b.classList.toggle('active', b === button));
20319
+ applyFilters();
20320
+ });
20321
+ });
20322
+ applyFilters();
20323
+ </script>
20324
+ </body>
20325
+ </html>`;
20326
+ }
20327
+ };
20328
+
19637
20329
  // src/index.ts
19638
20330
  var FORMAT_EXTENSIONS = {
19639
20331
  astro: ".md",
@@ -20096,6 +20788,8 @@ export {
20096
20788
  MIN_PERF_SAMPLES,
20097
20789
  MarkdownFormatter,
20098
20790
  ReportGenerator,
20791
+ ReviewHtmlFormatter,
20792
+ ReviewMarkdownFormatter,
20099
20793
  RunDiffHtmlFormatter,
20100
20794
  RunDiffMarkdownFormatter,
20101
20795
  STORY_META_KEY,
@@ -20106,6 +20800,7 @@ export {
20106
20800
  adaptPlaywrightRun,
20107
20801
  adaptVitestRun,
20108
20802
  assertValidRun,
20803
+ buildReview,
20109
20804
  bundleAssets,
20110
20805
  calculateFlakiness,
20111
20806
  calculateStability,
@@ -20115,6 +20810,8 @@ export {
20115
20810
  copyMarkdownAssets,
20116
20811
  createPrCommentSummary,
20117
20812
  createReportGenerator,
20813
+ deriveAudience,
20814
+ deriveChangeType,
20118
20815
  deriveStepResults,
20119
20816
  detectCI4 as detectCI,
20120
20817
  detectPerformanceTrend,
@@ -20126,7 +20823,10 @@ export {
20126
20823
  generateTestCaseId,
20127
20824
  getAvailableThemes,
20128
20825
  getCssOnlyThemes,
20826
+ gradeEvidence,
20129
20827
  hasSufficientHistory,
20828
+ isReviewableSource,
20829
+ isTestFile,
20130
20830
  listScenarios,
20131
20831
  loadHistory,
20132
20832
  mergeStepResults,