Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (claude): stop the coverage gate contradicting itself on unbuilt parts
[._.]/ Adam Eivy1ed26d4b01c6
diff --git a/client/src/pages/ThreejsModelDetail.jsx b/client/src/pages/ThreejsModelDetail.jsxindex ceccd52c56..dccb307bc1 100644--- a/client/src/pages/ThreejsModelDetail.jsx+++ b/client/src/pages/ThreejsModelDetail.jsx@@ -146,6 +146,13 @@ export default function ThreejsModelDetail() {const generating = record.status === 'generating' || starting;const latestRun = Array.isArray(record.runs) ? record.runs[record.runs.length - 1] : null;const coverageFindings = Array.isArray(record.coverage?.findings) ? record.coverage.findings : null;+ // Counted from the findings actually rendered rather than read off the stored+ // tallies, so the header can never disagree with the list below it — or print+ // "undefined error" for a record whose coverage arrived without its counts.+ const coverageCounts = (coverageFindings || []).reduce((counts, finding) => {+ if (counts[finding.severity] !== undefined) counts[finding.severity] += 1;+ return counts;+ }, { error: 0, warning: 0, note: 0 });return (<div className="mx-auto max-w-7xl space-y-4">@@ -293,8 +300,8 @@ export default function ThreejsModelDetail() {<h2 className="text-xs font-medium uppercase tracking-wide text-gray-400">Assembly coverage</h2><span className="text-xs text-gray-600">{coverageFindings.length === 0- ? 'Every promised feature has its own geometry'- : `${record.coverage.errorCount} error · ${record.coverage.warningCount} warning · ${record.coverage.noteCount} note`}+ ? 'Nothing promised was left unbuilt'+ : `${coverageCounts.error} error · ${coverageCounts.warning} warning · ${coverageCounts.note} note`}</span></div>{coverageFindings.length > 0 && (@@ -314,7 +321,7 @@ export default function ThreejsModelDetail() {<Info className="mt-0.5 h-3 w-3 shrink-0" /><span>This check proves the model built what its own spec promised — never that the spec promised enough.- {record.coverage.errorCount > 0+ {coverageCounts.error > 0&& ' Refining without your own feedback will target the errors above.'}</span></p>diff --git a/client/src/pages/ThreejsModelDetail.test.jsx b/client/src/pages/ThreejsModelDetail.test.jsxnew file mode 100644index 0000000000..1cf0cdfbae--- /dev/null+++ b/client/src/pages/ThreejsModelDetail.test.jsx@@ -0,0 +1,119 @@+import { render, screen, waitFor } from '@testing-library/react';+import { MemoryRouter, Route, Routes } from 'react-router';+import { beforeEach, describe, expect, it, vi } from 'vitest';+import ThreejsModelDetail from './ThreejsModelDetail';++vi.mock('../services/api', () => ({+ deleteThreejsModel: vi.fn(),+ generateThreejsModel: vi.fn(),+ getThreejsModel: vi.fn(),+ getThreejsModelSource: vi.fn(),+ threejsModelSourceUrl: (id) => `/api/threejs-models/${id}/source`,+}));++vi.mock('../hooks/useProviderModels', () => ({+ default: () => ({+ providers: [{ id: 'vision-api', name: 'Vision API', type: 'api', enabled: true }],+ selectedProviderId: 'vision-api',+ selectedModel: '',+ availableModels: [],+ setSelectedProviderId: vi.fn(),+ setSelectedModel: vi.fn(),+ loading: false,+ }),+}));++vi.mock('../components/ProviderModelSelector', () => ({+ default: () => <div>Vision API</div>,+}));++// The preview mounts a react-three-fiber Canvas, which cannot render in jsdom.+vi.mock('../components/threejsModels/ThreejsModelPreview', () => ({+ default: () => <div>Model preview</div>,+}));++import { getThreejsModel } from '../services/api';++const baseRecord = {+ id: 'threejs-example',+ name: 'Example Beacon',+ status: 'ready',+ providerId: 'vision-api',+ model: null,+ prompt: '',+ updatedAt: new Date().toISOString(),+ sourceImage: { filename: 'example-beacon.png', path: '/data/images/example-beacon.png' },+ spec: { name: 'Example Beacon', summary: 'A beacon.', detailInventory: [] },+ runs: [],+};++const renderDetail = () => render(+ <MemoryRouter initialEntries={['/media/threejs/threejs-example']}>+ <Routes>+ <Route path="/media/threejs/:id" element={<ThreejsModelDetail />} />+ </Routes>+ </MemoryRouter>,+);++describe('ThreejsModelDetail assembly coverage', () => {+ beforeEach(() => vi.clearAllMocks());++ it('lists the findings, tallies them, and states the gate is not a completeness proof', async () => {+ getThreejsModel.mockResolvedValue({+ ...baseRecord,+ coverage: {+ errorCount: 1,+ warningCount: 1,+ noteCount: 0,+ findings: [+ { code: 'fused-parts', severity: 'error', message: 'Two promised features collapsed onto "Hull".' },+ { code: 'orphan-geometry', severity: 'warning', count: 1, message: '1 geometry part is claimed by no entry.' },+ ],+ },+ });+ renderDetail();++ await waitFor(() => expect(screen.getByText('Assembly coverage')).toBeInTheDocument());+ expect(screen.getByText('Two promised features collapsed onto "Hull".')).toBeInTheDocument();+ expect(screen.getByText('1 geometry part is claimed by no entry.')).toBeInTheDocument();+ expect(screen.getByText('1 error · 1 warning · 0 note')).toBeInTheDocument();+ expect(screen.getByText(/never that the spec promised enough/)).toBeInTheDocument();+ // An error-severity finding is what the unsteered refinement will aim at.+ expect(screen.getByText(/will target the errors above/)).toBeInTheDocument();+ });++ it('counts from the findings it rendered rather than the stored tallies', async () => {+ // A record that reached this install without its counts (an older or newer+ // peer, a hand-repaired row) must not print "undefined error".+ getThreejsModel.mockResolvedValue({+ ...baseRecord,+ coverage: {+ findings: [{ code: 'folded-detail', severity: 'note', message: 'Minor relief rides on "Hull".' }],+ },+ });+ renderDetail();++ await waitFor(() => expect(screen.getByText('Assembly coverage')).toBeInTheDocument());+ expect(screen.getByText('0 error · 0 warning · 1 note')).toBeInTheDocument();+ expect(screen.queryByText(/undefined/)).not.toBeInTheDocument();+ // Notes are not defects, so no refinement is suggested.+ expect(screen.queryByText(/will target the errors above/)).not.toBeInTheDocument();+ });++ it('says nothing went unbuilt on a clean pass, without claiming the spec was complete', async () => {+ getThreejsModel.mockResolvedValue({ ...baseRecord, coverage: { errorCount: 0, warningCount: 0, noteCount: 0, findings: [] } });+ renderDetail();++ await waitFor(() => expect(screen.getByText('Assembly coverage')).toBeInTheDocument());+ expect(screen.getByText('Nothing promised was left unbuilt')).toBeInTheDocument();+ expect(screen.getByText(/never that the spec promised enough/)).toBeInTheDocument();+ });++ it('hides the section entirely for a record generated before the gate existed', async () => {+ getThreejsModel.mockResolvedValue({ ...baseRecord, coverage: null });+ renderDetail();++ await waitFor(() => expect(screen.getByText('Example Beacon')).toBeInTheDocument());+ expect(screen.queryByText('Assembly coverage')).not.toBeInTheDocument();+ });+});diff --git a/server/lib/threejsModelCoverage.js b/server/lib/threejsModelCoverage.jsindex ae176ce9fb..d1190cb585 100644--- a/server/lib/threejsModelCoverage.js+++ b/server/lib/threejsModelCoverage.js@@ -60,9 +60,16 @@ export function evaluateThreejsPartCoverage(spec) {const findings = [];// 1. Fusion — details whose ONLY implementing part is the same single part.+ // `detailSchema` does not constrain `implementationPartIds` to be unique, so+ // `['hull','hull']` validates; without the dedupe the arity test below reads+ // it as a two-part detail and the fusion gate silently stops looking at the+ // most fused spec there is. Deliberate scope limit: a group of details that+ // all name the SAME multi-part set is not reported — the issue defines fusion+ // as collapsing onto one part, and two parts is already an assembly.+ const partIdsOf = (detail) => [...new Set(detail.implementationPartIds || [])];const soleImplementers = new Map();for (const detail of details) {- const ids = detail.implementationPartIds || [];+ const ids = partIdsOf(detail);if (ids.length !== 1) continue;const group = soleImplementers.get(ids[0]) || [];group.push(detail);@@ -73,17 +80,30 @@ export function evaluateThreejsPartCoverage(spec) {// pass below cannot report the same detail a second time.const groupedDetails = new Set();for (const [partId, group] of soleImplementers) {- if (group.length < 2) continue;+ const sharedPart = byId.get(partId);+ // Nothing was built on this part or anywhere beneath it, so the details did+ // not fuse onto it — they went unbuilt. Leaving the group to the folded and+ // unbuilt passes below keeps the gate from reporting a fusion that never+ // happened alongside the "nothing was built" finding that describes the same+ // details, which would hand the next refinement pass two opposite orders.+ if (group.length < 2 || !sharedPart?.subtreeHasGeometry) continue;for (const detail of group) groupedDetails.add(detail);const ranked = group.filter((detail) => RANKED_PRIORITIES.has(detail.priority));if (ranked.length >= 2) {const features = ranked.map((detail) => detail.feature);+ // A bare group whose children carry the geometry is an attribution+ // problem, not a fused mesh — the parts already exist separately, the+ // inventory just points above them. Telling the provider to "build each+ // as its own part" there would have it rebuild geometry it got right.+ const remedy = sharedPart.hasGeometry+ ? 'Build each as its own part instead of one fused mesh.'+ : 'Point each detail at the specific child part that implements it.';findings.push({code: 'fused-parts',severity: 'error',partIds: [partId],features,- message: `${features.length} promised features collapsed onto the single part "${label(partId)}" (${listNames(features)}). Build each as its own part instead of one fused mesh.`,+ message: `${features.length} promised features collapsed onto the single part "${label(partId)}" (${listNames(features)}). ${remedy}`,});continue;}@@ -124,7 +144,7 @@ export function evaluateThreejsPartCoverage(spec) {const foldedDetails = new Set();for (const detail of details) {if (detail.priority !== 'minor' || groupedDetails.has(detail)) continue;- const ids = detail.implementationPartIds || [];+ const ids = partIdsOf(detail);if (ids.length !== 1) continue;const part = byId.get(ids[0]);const parentId = part?.ancestorIds.findLast((id) => implementedIds.has(id) && byId.get(id)?.hasGeometry);@@ -144,7 +164,7 @@ export function evaluateThreejsPartCoverage(spec) {// nothing was ever built for it.for (const detail of details) {if (foldedDetails.has(detail)) continue;- const resolved = (detail.implementationPartIds || []).map((id) => byId.get(id)).filter(Boolean);+ const resolved = partIdsOf(detail).map((id) => byId.get(id)).filter(Boolean);if (resolved.length === 0 || resolved.some((part) => part.subtreeHasGeometry)) continue;findings.push({code: 'unbuilt-detail',diff --git a/server/lib/threejsModelCoverage.test.js b/server/lib/threejsModelCoverage.test.jsindex 6df59fe6dd..63dc1bbe56 100644--- a/server/lib/threejsModelCoverage.test.js+++ b/server/lib/threejsModelCoverage.test.js@@ -125,6 +125,86 @@ describe('evaluateThreejsPartCoverage', () => {expect(coverage.findings[0].message).toContain('Hull');});+ it('sees through a part id repeated inside one detail', () => {+ // `detailSchema` does not require implementationPartIds to be unique, so a+ // maximally fused spec can hide from the arity test by naming its one part+ // twice.+ const coverage = evaluateThreejsPartCoverage(makeSpec({+ parts: [{ id: 'hull', name: 'Hull', geometry: box(2), material: 'shell' }],+ detailInventory: [+ detail('Boxy hull', ['hull', 'hull'], 'identity'),+ detail('Recessed lens', ['hull', 'hull'], 'identity'),+ ],+ }));++ expect(codes(coverage)).toEqual(['fused-parts']);+ expect(coverage.errorCount).toBe(1);+ });++ it('does not report a fusion onto a part nothing was built on', () => {+ // Two details sharing a locator that carries no geometry anywhere did not+ // fuse — they went unbuilt. Reporting both would tell the next refinement+ // pass to split a mesh that does not exist AND to build one that does not.+ const coverage = evaluateThreejsPartCoverage(makeSpec({+ parts: [+ { id: 'hull', name: 'Hull', geometry: box(2), material: 'shell' },+ { id: 'anchor', name: 'Anchor' },+ ],+ detailInventory: [+ detail('Boxy hull', ['hull'], 'identity'),+ detail('Recessed lens', ['anchor'], 'identity'),+ detail('Sensor ring', ['anchor'], 'identity'),+ ],+ }));++ expect(codes(coverage)).toEqual(['unbuilt-detail', 'unbuilt-detail']);+ expect(coverage.errorCount).toBe(2);+ });++ it('does not call two minor details on a geometry-less locator unbuilt', () => {+ const coverage = evaluateThreejsPartCoverage(makeSpec({+ parts: [{+ id: 'hull',+ name: 'Hull',+ geometry: box(2),+ material: 'shell',+ children: [{ id: 'anchor', name: 'Anchor' }],+ }],+ detailInventory: [+ detail('Boxy hull', ['hull'], 'identity'),+ detail('Fine stria', ['anchor'], 'minor'),+ detail('Faint scuffing', ['anchor'], 'minor'),+ ],+ }));++ expect(codes(coverage)).toEqual(['folded-detail', 'folded-detail']);+ expect(coverage).toMatchObject({ errorCount: 0, warningCount: 0, noteCount: 2 });+ });++ it('tells a bare group to re-attribute rather than rebuild what its children already are', () => {+ const coverage = evaluateThreejsPartCoverage(makeSpec({+ parts: [{+ id: 'head',+ name: 'Head',+ children: [+ { id: 'skull', name: 'Skull', geometry: box(0.8), material: 'shell' },+ { id: 'jaw', name: 'Jaw', geometry: box(0.4), material: 'shell' },+ ],+ }],+ detailInventory: [+ detail('Domed skull', ['head'], 'identity'),+ detail('Hinged jaw', ['head'], 'identity'),+ ],+ }));++ const fused = coverage.findings.find((finding) => finding.code === 'fused-parts');+ expect(fused.message).toContain('Point each detail at the specific child part');+ expect(fused.message).not.toContain('one fused mesh');+ // The children exist as separate meshes — the inventory just points above+ // them, which the orphan warning says in the other direction.+ expect(codes(coverage)).toContain('orphan-geometry');+ });+it('does not also call folded minor relief unbuilt when its locator part carries no geometry', () => {// The child part is a pure locator — the relief itself lives in the parent// mesh. Reporting "nothing was built for it" alongside "folding it in is