feat(8246): the code index links each test to what it guards, and can say redundant or unused
CI & Build / Plugin hooks (push) Successful in 20s
CI & Build / Python lint (push) Successful in 3s
CI & Build / TypeScript typecheck (push) Successful in 41s
CI & Build / Python tests (push) Failing after 2m8s
CI & Build / integration (push) Successful in 2m24s
CI & Build / Build & push image (push) Skipped
CI & Build / Plugin hooks (push) Successful in 20s
CI & Build / Python lint (push) Successful in 3s
CI & Build / TypeScript typecheck (push) Successful in 41s
CI & Build / Python tests (push) Failing after 2m8s
CI & Build / integration (push) Successful in 2m24s
CI & Build / Build & push image (push) Skipped
Every coverage refresh now reads, for each test in a bound repo, which product shapes its body exercises: through module aliases and imports, following test helpers, with mocked names left out and shapes most test files reach dropped as hubs. Tests in different files that guard exactly the same set form a group. The project page lists the groups and a person can mark one test redundant, naming the test that covers it, or keep them all with a reason. Agents get test_guard_groups and review_test_group, and classify_shapes takes the two new removal verdicts, redundant (with covered_by) and unused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,242 @@
|
||||
<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;
|
||||
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">
|
||||
<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 }}, largest first.
|
||||
</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); }
|
||||
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>
|
||||
Reference in New Issue
Block a user