mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-09 07:08:59 +00:00
55eb7135be
Closes five 2026-04-24 audit findings (all P2, all category cat-f /
diff-05x06-*) by reconciling the TypeScript interfaces in
web/src/api/types.ts with the on-wire JSON shape Go's
internal/domain/*.go structs actually emit. D-1 closed the same pattern
for one entity (Certificate / ManagedCertificate); D-2 covers the
remaining five.
Per-entity verdicts (audit's "stricter side is the contract"):
Agent — TRIM 5 phantoms (last_heartbeat, capabilities, tags,
created_at, updated_at). Go emits last_heartbeat_at only.
Target — ADD 2 (retired_at?, retired_reason?) — I-004 fields.
DiscCert — ADD pem_data? — real field, real Go emit, omitempty.
Issuer — TRIM phantom status. Go has Enabled bool only.
Notif — TRIM phantom subject. Go has Message string only.
Certificate — verify-only; D-1 closure confirmed clean at recon.
Consumer fixes (same commit as the trim):
- AgentDetailPage.tsx — remove dead Capabilities + Tags sections (always
rendered empty); replace agent.created_at/updated_at row with the
Go-emitted registered_at; widen heartbeatStatus() to accept undefined.
- AgentsPage.tsx — same heartbeatStatus widening.
- IssuersPage.tsx + IssuerDetailPage.tsx — issuerStatus() now derives
from `enabled` exclusively; the dead `issuer.status || 'Unknown'`
fallback is gone.
- NotificationsPage.tsx — drop dead `|| n.subject` fallback.
- NotificationsPage.test.tsx — drop dead `subject:` from mocks.
- api/utils.ts::timeAgo widened to accept string | undefined | null.
- api/types.test.ts — Agent (I-004) fixture trimmed of the 5 phantoms.
Tests (Vitest):
- 5 new describe blocks in web/src/api/types.test.ts:
- Agent interface (D-2 phantom-fields trim) — 2 it blocks
- Target interface (D-2 retirement fields) — 2 it blocks
- DiscoveredCertificate interface (D-2 pem_data ADD) — 2 it blocks
- Issuer interface (D-2 status phantom trim) — 1 it block
- Notification interface (D-2 subject phantom trim) — 1 it block
- Each block uses the literal-construction pattern from D-1; trimmed
fields are pinned via excess-property comments that compile-fail when
uncommented if a phantom is reintroduced.
CI regression guardrail:
- .github/workflows/ci.yml — existing D-1 step renamed to "Forbidden
StatusBadge dead-key + TS phantom-field regression guard (D-1 + D-2)".
Three new awk-windowed greps over Agent / Issuer / Notification
interfaces in types.ts. The Agent grep includes a `grep -v
'last_heartbeat_at'` filter to avoid false positives on the
legitimate Go-emitted heartbeat field.
Documentation:
- CHANGELOG.md — new D-2 section above B-1 under [unreleased] with full
Added/Removed/Audit findings closed/Known follow-ups breakdown.
- docs/architecture.md — Web Dashboard section gains a new "TS ↔ Go
type contract rule (D-1 + D-2 closure)" paragraph capturing the
stricter-side-wins rule and the CI guardrail it's anchored by.
- coverage-gap-audit-2026-04-24-v5/unified-audit.md — Live Tracker score
20/47 → 25/47 (P2: 6/27 → 11/27). Per-finding ✅ RESOLVED Status
blocks added to all 5 diff-05x06-* entries plus the verify-only
Certificate entry. Closed-bundle index gets D-2 row.
Verification (all gates green):
- cd web && tsc --noEmit → clean
- cd web && vitest run --reporter=dot → 9 files, 302 tests passing
(was 294 → +8 D-2 cases)
- cd web && vite build → clean
- go vet ./internal/... ./cmd/... → clean (no Go touched)
- golangci-lint v2.11.4 run ./... → 0 issues
- D-2 Agent guardrail dry-run → empty (good)
- D-2 Issuer guardrail dry-run → empty (good)
- D-2 Notification guardrail dry-run → empty (good)
- D-2 Target ADD-shape sanity → 2 retirement fields present
- D-2 DiscCert ADD-shape sanity → pem_data present
- D-1 Certificate guardrail still clean → empty (good)
- OpenAPI YAML parses → 89 paths
Audit findings closed:
- diff-05x06-7cdf4e78ae24 (P2, Agent TS↔Go drift)
- diff-05x06-2044a46f4dd0 (P2, Target TS↔DeploymentTarget Go drift)
- diff-05x06-85ab6b98a2f7 (P2, DiscoveredCertificate TS↔Go drift)
- diff-05x06-97fab8783a5c (P2, Issuer TS↔Go drift)
- diff-05x06-caba9eb3620e (P2, Notification TS↔NotificationEvent drift)
- diff-05x06-af18a8d7ef41 (P2) — verified clean since D-1; no edit
Deferred follow-ups:
- Issuer richer status view (enabled × test_status) — UX scope, not drift.
- Real Agent metadata (capabilities, tags) — backend feature, not drift.
- DiscoveredCertificate pem_data list-response perf — separate backend change.
174 lines
7.5 KiB
TypeScript
174 lines
7.5 KiB
TypeScript
import { useParams, useNavigate } from 'react-router-dom';
|
|
import { useQuery } from '@tanstack/react-query';
|
|
import { getAgent, getJobs } from '../api/client';
|
|
import PageHeader from '../components/PageHeader';
|
|
import StatusBadge from '../components/StatusBadge';
|
|
import ErrorState from '../components/ErrorState';
|
|
import { formatDateTime, timeAgo } from '../api/utils';
|
|
|
|
function InfoRow({ label, value }: { label: string; value: React.ReactNode }) {
|
|
return (
|
|
<div className="flex justify-between py-2 border-b border-surface-border/50">
|
|
<span className="text-sm text-ink-muted">{label}</span>
|
|
<span className="text-sm text-ink">{value}</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// D-2 (master): the `lastHeartbeat` parameter accepts undefined because
|
|
// the Go-side struct emits `last_heartbeat_at` as `omitempty` (a never-
|
|
// heartbeated agent omits the field entirely). Pre-D-2 the TS interface
|
|
// declared the field as required, masking this case. Post-D-2 the empty
|
|
// case is explicit at both the type level and the function signature.
|
|
function heartbeatStatus(lastHeartbeat: string | undefined): string {
|
|
if (!lastHeartbeat) return 'Offline';
|
|
const ago = Date.now() - new Date(lastHeartbeat).getTime();
|
|
if (ago < 5 * 60 * 1000) return 'Online';
|
|
if (ago < 15 * 60 * 1000) return 'Stale';
|
|
return 'Offline';
|
|
}
|
|
|
|
export default function AgentDetailPage() {
|
|
const { id } = useParams<{ id: string }>();
|
|
const navigate = useNavigate();
|
|
|
|
const { data: agent, isLoading, error, refetch } = useQuery({
|
|
queryKey: ['agent', id],
|
|
queryFn: () => getAgent(id!),
|
|
enabled: !!id,
|
|
refetchInterval: 10000,
|
|
});
|
|
|
|
const { data: jobs } = useQuery({
|
|
queryKey: ['agent-jobs', id],
|
|
queryFn: () => getJobs({ per_page: '10' }),
|
|
enabled: !!id,
|
|
});
|
|
|
|
// Filter jobs related to this agent (deployment jobs)
|
|
const agentJobs = jobs?.data?.slice(0, 10) || [];
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<>
|
|
<PageHeader title="Agent" />
|
|
<div className="flex items-center justify-center flex-1 text-ink-muted">Loading...</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
if (error || !agent) {
|
|
return (
|
|
<>
|
|
<PageHeader title="Agent" />
|
|
<ErrorState error={error as Error || new Error('Not found')} onRetry={() => refetch()} />
|
|
</>
|
|
);
|
|
}
|
|
|
|
const health = agent.status || heartbeatStatus(agent.last_heartbeat_at);
|
|
|
|
return (
|
|
<>
|
|
<PageHeader
|
|
title={agent.name}
|
|
subtitle={agent.id}
|
|
action={
|
|
<button onClick={() => navigate('/agents')} className="btn btn-ghost text-xs">Back</button>
|
|
}
|
|
/>
|
|
<div className="flex-1 overflow-y-auto p-6 space-y-6">
|
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
|
{/* Agent Info */}
|
|
<div className="bg-surface border border-surface-border rounded p-5 shadow-sm">
|
|
<h3 className="text-sm font-semibold text-ink-muted mb-4">Agent Details</h3>
|
|
<InfoRow label="Health" value={<StatusBadge status={health} />} />
|
|
<InfoRow label="Hostname" value={<span className="font-mono text-xs">{agent.hostname || '—'}</span>} />
|
|
<InfoRow label="IP Address" value={<span className="font-mono text-xs">{agent.ip_address || '—'}</span>} />
|
|
<InfoRow label="Version" value={agent.version || '—'} />
|
|
<InfoRow label="Last Heartbeat" value={
|
|
agent.last_heartbeat_at ? (
|
|
<span>
|
|
{timeAgo(agent.last_heartbeat_at)}
|
|
<span className="text-ink-faint ml-2 text-xs">{formatDateTime(agent.last_heartbeat_at)}</span>
|
|
</span>
|
|
) : '—'
|
|
} />
|
|
{/* D-2 (master): pre-D-2 these rows used `agent.created_at`
|
|
+ `agent.updated_at` — TS phantoms that the Go-side
|
|
struct (`internal/domain/connector.go::Agent`) never
|
|
emitted. The "Registered" row now reads from the real
|
|
Go-emitted `registered_at` field; the "Updated" row is
|
|
dropped because the Go struct has no equivalent
|
|
update-timestamp on Agent (heartbeats are tracked via
|
|
`last_heartbeat_at` above). */}
|
|
<InfoRow label="Registered" value={formatDateTime(agent.registered_at)} />
|
|
</div>
|
|
|
|
{/* System Info */}
|
|
<div className="bg-surface border border-surface-border rounded p-5 shadow-sm">
|
|
<h3 className="text-sm font-semibold text-ink-muted mb-4">System Information</h3>
|
|
<InfoRow label="Operating System" value={agent.os || '—'} />
|
|
<InfoRow label="Architecture" value={agent.architecture || '—'} />
|
|
<InfoRow label="IP Address" value={<span className="font-mono text-xs">{agent.ip_address || '—'}</span>} />
|
|
<InfoRow label="Agent Version" value={agent.version || '—'} />
|
|
{/* D-2 (master): the previous "Capabilities" + "Tags" sections
|
|
rendered `agent.capabilities` and `agent.tags`, both of
|
|
which were TS phantom fields the Go-side struct
|
|
(`internal/domain/connector.go::Agent`) never emitted.
|
|
Both sections always rendered as the empty-state fallback
|
|
(the `?.length ?` and `Object.keys(...).length > 0`
|
|
guards always evaluated false). Removed in D-2 master.
|
|
If/when the backend grows real Agent metadata fields
|
|
(capabilities advertised at heartbeat time, operator-
|
|
applied tags), re-introduce here in the same commit that
|
|
ships the Go-side change. */}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Recent Jobs */}
|
|
<div className="bg-surface border border-surface-border rounded p-5 shadow-sm">
|
|
<h3 className="text-sm font-semibold text-ink-muted mb-4">Recent Jobs</h3>
|
|
{!agentJobs.length ? (
|
|
<p className="text-sm text-ink-faint">No recent jobs</p>
|
|
) : (
|
|
<div className="space-y-2">
|
|
{agentJobs.map(j => (
|
|
<div key={j.id} className="flex items-center justify-between py-2 px-3 rounded hover:bg-surface-muted transition-colors">
|
|
<div>
|
|
<div className="text-sm text-ink">{j.type}</div>
|
|
<div className="text-xs text-ink-faint font-mono">{j.id}</div>
|
|
</div>
|
|
<div className="flex items-center gap-3">
|
|
<span className="text-xs text-ink-muted font-mono">{j.certificate_id}</span>
|
|
<StatusBadge status={j.status} />
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Heartbeat Timeline */}
|
|
<div className="bg-surface border border-surface-border rounded p-5 shadow-sm">
|
|
<h3 className="text-sm font-semibold text-ink-muted mb-4">Heartbeat Status</h3>
|
|
<div className="flex items-center gap-4">
|
|
<div className={`w-3 h-3 rounded-full ${
|
|
health === 'Online' ? 'bg-emerald-500 animate-pulse' :
|
|
health === 'Stale' ? 'bg-amber-500' : 'bg-red-500'
|
|
}`} />
|
|
<div>
|
|
<p className="text-sm text-ink">{health}</p>
|
|
<p className="text-xs text-ink-muted">
|
|
{health === 'Online' && 'Agent is responding to heartbeat checks'}
|
|
{health === 'Stale' && 'Agent has not sent a heartbeat recently'}
|
|
{health === 'Offline' && 'Agent is not responding'}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|