Files
FabledGrimoire/frontend/src/components/TestGuardReview.vue
T
bvandeusenandClaude Opus 5.5 7c7a1a7ab9
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 2m14s
CI & Build / integration (push) Successful in 2m28s
CI & Build / Build & push image (push) Successful in 35s
fix(8249): test groups come smallest first, and a big one is read as a feature area
A group is the set of tests reaching the same code from different files. A
test that drives a feature through its one entry point reaches exactly that
entry point whatever it checks, so the largest groups are a feature tested
from many files, not copies. Listing them first buried the two- and
three-test groups where one-for-one duplicates are. The readout, the tool and
the panel now list smallest first; each group says copies or area and how
many files it spans, and the panel tells an area to fold its scattered cases
into one file. Plugin 2026.12.01.0748.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 02:49:06 -05:00

251 lines
8.6 KiB
Vue

<script setup lang="ts">
/**
* Tests that guard the same thing from different files — the coverage card's
* merge-or-remove queue. Each group lists what its tests exercise and, per
* test, weak-test signals read from its body. A group is a candidate, not a
* verdict: the reviewer either marks one test redundant (naming the test in
* the group that covers it) or keeps them all, with a reason either way.
*/
import { ref, onMounted, watch } from "vue";
import { apiGet, apiPost, apiErrorMessage } from "@/api/client";
import { useToastStore } from "@/stores/toast";
interface ShapeRef {
id: number;
path: string;
symbol: string;
}
interface GroupTest extends ShapeRef {
status: string;
signals: string[];
}
interface Group {
key: string;
kind: "copies" | "area";
files: number;
guards: ShapeRef[];
tests: GroupTest[];
}
const props = defineProps<{ projectId: number; canWrite: boolean }>();
const emit = defineEmits<{ (e: "changed"): void }>();
const toast = useToastStore();
const groups = ref<Group[]>([]);
const count = ref(0);
const loading = ref(false);
const error = ref<string | null>(null);
const open = ref(false);
// One form at a time: keeping a whole group, or marking one test redundant.
const activeKey = ref<string | null>(null);
const mode = ref<"keep" | "redundant">("keep");
const testId = ref<number | null>(null);
const coverId = ref<number | null>(null);
const reason = ref("");
const saving = ref(false);
const SIGNAL_HELP: Record<string, string> = {
signature: "Checks how the code is declared (its parameters), not what it does",
"mock-only": "Asserts only that mocks were called",
"source-text": "Reads source code as text",
};
async function load() {
loading.value = true;
error.value = null;
try {
const res = await apiGet<{ count: number; groups: Group[] }>(
`/api/projects/${props.projectId}/test-guards`,
);
groups.value = res.groups;
count.value = res.count;
} catch (e) {
error.value = apiErrorMessage(e, "Could not load the test groups");
} finally {
loading.value = false;
}
}
function startKeep(g: Group) {
activeKey.value = g.key;
mode.value = "keep";
reason.value = "";
}
function startRedundant(g: Group, t: GroupTest) {
activeKey.value = g.key;
mode.value = "redundant";
testId.value = t.id;
coverId.value = g.tests.find((x) => x.id !== t.id)?.id ?? null;
reason.value = "";
}
function cancel() {
activeKey.value = null;
reason.value = "";
}
async function submit(g: Group) {
if (!reason.value.trim() || saving.value) return;
saving.value = true;
try {
if (mode.value === "keep") {
await apiPost(`/api/projects/${props.projectId}/test-guards/review`, {
test_ids: g.tests.map((t) => t.id),
reason: reason.value.trim(),
});
toast.show("Group kept — it leaves the list until a test joins or leaves it");
} else {
await apiPost(`/api/projects/${props.projectId}/test-guards/redundant`, {
test_id: testId.value,
covered_by_id: coverId.value,
reason: reason.value.trim(),
});
toast.show("Marked redundant — delete the test, and the next refresh retires its row");
}
cancel();
await load();
emit("changed");
} catch (e) {
toast.show(apiErrorMessage(e, "Could not record the verdict"), "error");
} finally {
saving.value = false;
}
}
function label(s: ShapeRef): string {
return `${s.path.split("/").pop()} · ${s.symbol}`;
}
onMounted(load);
watch(() => props.projectId, load);
</script>
<template>
<div class="tg">
<button
type="button"
class="btn-ghost btn-inline tg-toggle"
:aria-expanded="open"
aria-controls="tg-groups"
@click="open = !open"
>
{{ open ? "▾" : "▸" }} Tests guarding the same thing
<span class="tg-count">{{ count }}</span>
</button>
<div v-if="open" id="tg-groups" class="tg-body">
<p class="tg-intro">
Tests in different files that exercise exactly the same code. Read them:
if one checks nothing the other doesn't, mark it redundant and delete it;
if each checks something of its own, keep them all and say what.
</p>
<p v-if="loading" class="tg-note">Loading…</p>
<p v-else-if="error" class="tg-error" role="alert">{{ error }}</p>
<p v-else-if="!groups.length" class="tg-note">
No tests guard the same thing from different files.
</p>
<ul v-else class="tg-list">
<li v-for="g in groups" :key="g.key" class="tg-group">
<p v-if="g.kind === 'area'" class="tg-kind">
One feature tested from {{ g.files }} files: fold the scattered
cases into its own test file, and remove only what another test covers.
</p>
<div class="tg-guards">
<span class="tg-label">Guard</span>
<code v-for="s in g.guards" :key="s.id" :title="s.path">{{ s.symbol }}</code>
</div>
<ul class="tg-tests">
<li v-for="t in g.tests" :key="t.id" class="tg-test">
<code :title="t.path">{{ label(t) }}</code>
<span
v-for="sig in t.signals"
:key="sig"
class="tg-signal"
:title="SIGNAL_HELP[sig] || sig"
>{{ sig }}</span>
<button
v-if="canWrite"
type="button"
class="btn-ghost btn-inline"
@click="startRedundant(g, t)"
>Redundant…</button>
</li>
</ul>
<button
v-if="canWrite && activeKey !== g.key"
type="button"
class="btn-ghost btn-inline"
@click="startKeep(g)"
>Keep all…</button>
<form v-if="activeKey === g.key" class="tg-form" @submit.prevent="submit(g)">
<label v-if="mode === 'redundant'" class="tg-field">
<span>Covered by</span>
<select v-model="coverId">
<option
v-for="t in g.tests.filter((x) => x.id !== testId)"
:key="t.id"
:value="t.id"
>{{ label(t) }}</option>
</select>
</label>
<label class="tg-field">
<span>{{ mode === "keep"
? "What each test checks that the others don't"
: "What the covering test checks that this one also checked" }}</span>
<textarea v-model="reason" rows="2" required></textarea>
</label>
<div class="tg-actions">
<button type="submit" class="btn-primary btn-compact" :disabled="!reason.trim() || saving">
{{ mode === "keep" ? "Keep all" : "Mark redundant" }}
</button>
<button type="button" class="btn-ghost btn-compact" @click="cancel">Cancel</button>
</div>
</form>
</li>
</ul>
<p v-if="count > groups.length" class="tg-note">
Showing {{ groups.length }} of {{ count }}, smallest first: the
smallest groups are the likeliest copies.
</p>
</div>
</div>
</template>
<style scoped>
.tg { display: flex; flex-direction: column; gap: var(--fs-space-2); }
.tg-toggle { align-self: flex-start; }
.tg-count {
margin-left: var(--fs-space-1);
padding: 0 var(--fs-space-2);
border-radius: var(--fs-radius-pill);
border: 1px solid var(--fs-border-color);
color: var(--fs-text-secondary);
}
.tg-body { display: flex; flex-direction: column; gap: var(--fs-space-2); }
.tg-intro, .tg-note { color: var(--fs-text-tertiary); margin: 0; }
.tg-error { color: var(--fs-status-cancelled-fg); margin: 0; }
.tg-list, .tg-tests { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--fs-space-2); }
.tg-group {
border: 1px solid var(--fs-border-color);
border-radius: var(--fs-radius-md);
padding: var(--fs-space-2) var(--fs-space-3);
display: flex;
flex-direction: column;
gap: var(--fs-space-2);
}
.tg-guards, .tg-test { display: flex; flex-wrap: wrap; align-items: center; gap: var(--fs-space-2); }
.tg-label { color: var(--fs-text-tertiary); }
.tg-kind { margin: 0; color: var(--fs-text-secondary); }
code { font-family: var(--fs-font-mono); color: var(--fs-text-primary); }
.tg-signal {
padding: 0 var(--fs-space-2);
border-radius: var(--fs-radius-pill);
background: var(--fs-status-todo-bg);
color: var(--fs-status-todo-fg);
}
.tg-form { display: flex; flex-direction: column; gap: var(--fs-space-2); }
.tg-field { display: flex; flex-direction: column; gap: var(--fs-space-1); color: var(--fs-text-secondary); }
.tg-actions { display: flex; gap: var(--fs-space-2); }
</style>