mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-07-10 00:14:38 +00:00
Add discovery freshness to the local/full context formatter
formatSingleDiscovery (the local/full path, FormatForAIContext) reported a resource's service, access, paths, and ports but not how old the discovery was — so Ollama/local users lacked the recency signal cloud users just got. Emit a "Last Discovered: <age>" header fact when the timestamp is known, completing freshness parity across the cloud-safe and full paths. Omitted when unknown. Test: TestFormatSingleDiscovery_IncludesFreshness (present when set, absent when zero).
This commit is contained in:
parent
55dfdcb1d3
commit
e2f82f8b17
2 changed files with 24 additions and 0 deletions
|
|
@ -118,6 +118,12 @@ func formatSingleDiscovery(d *ResourceDiscovery) string {
|
|||
sb.WriteString(fmt.Sprintf("- **Type:** %s\n", d.ResourceType))
|
||||
sb.WriteString(fmt.Sprintf("- **Target:** %s\n", firstNonEmpty(d.Hostname, d.TargetID)))
|
||||
|
||||
// Freshness so the model (local/full path) can caveat staleness rather than
|
||||
// presenting a cached scan as current — parity with the cloud-safe path.
|
||||
if !d.UpdatedAt.IsZero() {
|
||||
sb.WriteString(fmt.Sprintf("- **Last Discovered:** %s\n", FormatDiscoveryAge(d)))
|
||||
}
|
||||
|
||||
if d.ServiceVersion != "" {
|
||||
sb.WriteString(fmt.Sprintf("- **Version:** %s\n", d.ServiceVersion))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -329,3 +329,21 @@ func TestFormatCloudSafeContext(t *testing.T) {
|
|||
t.Errorf("cloud-safe context must report discovery age\n--- output ---\n%s", freshOut)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatSingleDiscovery_IncludesFreshness(t *testing.T) {
|
||||
d := &ResourceDiscovery{
|
||||
ID: MakeResourceID(ResourceTypeSystemContainer, "node1", "101"),
|
||||
ResourceType: ResourceTypeSystemContainer,
|
||||
ServiceName: "Home Assistant",
|
||||
}
|
||||
// No timestamp -> no freshness line (parity with the cloud-safe path).
|
||||
if strings.Contains(formatSingleDiscovery(d), "Last Discovered:") {
|
||||
t.Fatalf("expected no freshness line when UpdatedAt is zero")
|
||||
}
|
||||
// Known timestamp -> the local/full path reports discovery age.
|
||||
d.UpdatedAt = time.Now().Add(-3 * time.Hour)
|
||||
out := formatSingleDiscovery(d)
|
||||
if !strings.Contains(out, "**Last Discovered:** 3 hours ago") {
|
||||
t.Fatalf("expected freshness line in single-discovery output, got:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue