|
| 1 | +<script setup lang="ts"> |
| 2 | +/** |
| 3 | + * The Attempts tab for a flaky test: a strip of every attempt (retry number, |
| 4 | + * status, duration, a "this one" marker on the opened execution), and below it |
| 5 | + * "what differed" between the failing attempt and the attempt that passed on |
| 6 | + * retry — the flakiness fingerprint. The diff is loaded lazily from |
| 7 | + * `/attempt-diff` when the tab is first opened (this card mounts under a `v-if`). |
| 8 | + * |
| 9 | + * Each difference cites an evidence section; the chip switches to that evidence |
| 10 | + * tab through the page's section locator — the same mechanism a clue uses. |
| 11 | + */ |
| 12 | +import type { AttemptDiffEntry } from '#shared/attempt-diff'; |
| 13 | +import type { AttemptDiffResult } from '#shared/handlers/test-cases'; |
| 14 | +import { useClusterSectionLocator } from '~/composables/useClusterSectionLocator'; |
| 15 | +
|
| 16 | +const props = defineProps<{ |
| 17 | + testRunsCaseId: number; |
| 18 | + /** Every attempt of this execution, already fetched at page level. */ |
| 19 | + attempts: Array<{ retry: number; status: string; duration: number | null; executionId: number | null }>; |
| 20 | +}>(); |
| 21 | +
|
| 22 | +const { data, status } = await useFetch<AttemptDiffResult>(`/api/test-run-cases/${props.testRunsCaseId}/attempt-diff`); |
| 23 | +
|
| 24 | +const locator = useClusterSectionLocator(); |
| 25 | +
|
| 26 | +// The endpoint's attempt list is authoritative (it unions every attempt row); |
| 27 | +// the page-level `attempts` prop is the fallback while the diff is loading. |
| 28 | +const orderedAttempts = computed(() => { |
| 29 | + const source = data.value?.attempts?.length ? data.value.attempts : (props.attempts ?? []); |
| 30 | + return [...source].sort((a, b) => (a.retry ?? 0) - (b.retry ?? 0)); |
| 31 | +}); |
| 32 | +
|
| 33 | +const differences = computed<AttemptDiffEntry[]>(() => data.value?.differences ?? []); |
| 34 | +const applicable = computed(() => data.value?.applicable === true); |
| 35 | +
|
| 36 | +// ── Per-kind presentation ────────────────────────────────────────────────── |
| 37 | +const KIND_ICON: Record<AttemptDiffEntry['kind'], string> = { |
| 38 | + error: 'i-lucide-circle-x', |
| 39 | + network: 'i-lucide-arrow-left-right', |
| 40 | + console: 'i-lucide-terminal', |
| 41 | + step: 'i-lucide-list-checks', |
| 42 | + duration: 'i-lucide-timer', |
| 43 | + 'page-state': 'i-lucide-database', |
| 44 | + aria: 'i-lucide-scan-text', |
| 45 | +}; |
| 46 | +
|
| 47 | +/** Where a difference's citation jumps — evidence section id → readable tab name. */ |
| 48 | +const SECTION_LABEL: Record<string, string> = { |
| 49 | + executionError: 'Error', |
| 50 | + networkRequests: 'Network', |
| 51 | + console: 'Console', |
| 52 | + steps: 'Timeline', |
| 53 | + appState: 'State', |
| 54 | + ariaSnapshot: 'Screen', |
| 55 | +}; |
| 56 | +
|
| 57 | +function onlyLabel(entry: AttemptDiffEntry): { text: string; class: string } { |
| 58 | + if (entry.only === 'failing') { |
| 59 | + return { text: 'only on the failing attempt', class: 'text-red-600 dark:text-red-400 bg-red-500/10' }; |
| 60 | + } |
| 61 | + if (entry.only === 'passing') { |
| 62 | + return { text: 'only on the passing attempt', class: 'text-green-600 dark:text-green-400 bg-green-500/10' }; |
| 63 | + } |
| 64 | + return { text: 'changed', class: 'text-amber-600 dark:text-amber-400 bg-amber-500/10' }; |
| 65 | +} |
| 66 | +
|
| 67 | +function citationLabel(entry: AttemptDiffEntry): string | null { |
| 68 | + const section = entry.ref?.section; |
| 69 | + if (!section || !locator.canLocate(section)) return null; |
| 70 | + return SECTION_LABEL[section] ?? null; |
| 71 | +} |
| 72 | +
|
| 73 | +function reveal(entry: AttemptDiffEntry) { |
| 74 | + const section = entry.ref?.section; |
| 75 | + if (section && locator.canLocate(section)) locator.open(section); |
| 76 | +} |
| 77 | +
|
| 78 | +function attemptLabel(retry: number): string { |
| 79 | + return retry === 0 ? 'Attempt 1' : `Retry ${retry}`; |
| 80 | +} |
| 81 | +</script> |
| 82 | + |
| 83 | +<template> |
| 84 | + <div class="space-y-4" data-shot="attempts-diff"> |
| 85 | + <!-- ── Attempt strip ──────────────────────────────────────────────────── --> |
| 86 | + <SectionCard embedded icon="i-lucide-repeat" title="Attempts" help="case.attempts"> |
| 87 | + <ul class="flex flex-col sm:flex-row sm:flex-wrap gap-2"> |
| 88 | + <li |
| 89 | + v-for="attempt in orderedAttempts" |
| 90 | + :key="attempt.retry" |
| 91 | + class="flex items-center gap-2 rounded-md border border-default px-2.5 py-1.5 text-sm" |
| 92 | + :class="attempt.executionId === testRunsCaseId ? 'bg-primary/5 border-primary/40' : ''" |
| 93 | + > |
| 94 | + <span class="font-medium whitespace-nowrap">{{ attemptLabel(attempt.retry) }}</span> |
| 95 | + <StatusChip :status="attempt.status" size="xs" /> |
| 96 | + <DurationValue :ms="attempt.duration" class="text-muted tabular-nums" /> |
| 97 | + <span v-if="attempt.executionId === testRunsCaseId" class="text-xs text-primary font-medium whitespace-nowrap" |
| 98 | + >this one</span |
| 99 | + > |
| 100 | + <ULink |
| 101 | + v-else-if="attempt.executionId" |
| 102 | + :to="`/test-run-cases/${attempt.executionId}`" |
| 103 | + class="text-xs text-primary hover:underline whitespace-nowrap" |
| 104 | + >open</ULink |
| 105 | + > |
| 106 | + </li> |
| 107 | + </ul> |
| 108 | + </SectionCard> |
| 109 | + |
| 110 | + <!-- ── What differed ──────────────────────────────────────────────────── --> |
| 111 | + <SectionCard embedded icon="i-lucide-git-compare" title="What differed" help="case.attempts"> |
| 112 | + <LoadingState v-if="status === 'pending'" text="Comparing attempts…" /> |
| 113 | + |
| 114 | + <EmptyState |
| 115 | + v-else-if="!applicable" |
| 116 | + icon="i-lucide-repeat" |
| 117 | + text="No failing-and-passing pair to compare — this needs one attempt that failed and one that passed." |
| 118 | + /> |
| 119 | + |
| 120 | + <EmptyState |
| 121 | + v-else-if="differences.length === 0" |
| 122 | + icon="i-lucide-equal" |
| 123 | + text="The failing and passing attempts left no different evidence — the flakiness is not visible in the captured signals." |
| 124 | + /> |
| 125 | + |
| 126 | + <ul v-else class="space-y-2.5"> |
| 127 | + <li |
| 128 | + v-for="(entry, i) in differences" |
| 129 | + :key="i" |
| 130 | + class="flex items-start gap-2.5 rounded-md border border-default p-2.5" |
| 131 | + > |
| 132 | + <UIcon :name="KIND_ICON[entry.kind]" class="size-4 shrink-0 mt-0.5 text-muted" /> |
| 133 | + <div class="min-w-0 flex-1 space-y-1"> |
| 134 | + <div class="flex flex-wrap items-center gap-2"> |
| 135 | + <span |
| 136 | + class="rounded px-1.5 py-0.5 text-xs font-medium whitespace-nowrap" |
| 137 | + :class="onlyLabel(entry).class" |
| 138 | + >{{ onlyLabel(entry).text }}</span |
| 139 | + > |
| 140 | + <span class="text-sm font-medium break-words">{{ entry.summary }}</span> |
| 141 | + </div> |
| 142 | + <pre |
| 143 | + v-if="entry.detail" |
| 144 | + class="text-xs text-muted font-mono whitespace-pre-wrap break-words max-h-32 overflow-y-auto" |
| 145 | + >{{ entry.detail }}</pre> |
| 146 | + <button |
| 147 | + v-if="citationLabel(entry)" |
| 148 | + type="button" |
| 149 | + class="inline-flex items-center gap-1 text-xs text-primary hover:underline" |
| 150 | + @click="reveal(entry)" |
| 151 | + > |
| 152 | + <UIcon name="i-lucide-arrow-up-right" class="size-3" /> |
| 153 | + View in {{ citationLabel(entry) }} |
| 154 | + </button> |
| 155 | + </div> |
| 156 | + </li> |
| 157 | + </ul> |
| 158 | + </SectionCard> |
| 159 | + </div> |
| 160 | +</template> |
0 commit comments