Replace resource hot-path source pins with native cache checks

Containing CI correctly rejected stale string assertions that required the removed full-fleet copy and repeated summary work. Exercise list and stats HTTP responses and generation-summary reuse in the existing native cache test instead; retain page/live-health/concurrency and PMG ownership coverage. Lower only the retired source-read baseline entry.

Contract-Neutral: Test-only replacement of obsolete implementation-shape pins with executable endpoint/cache assertions; runtime source, wire contracts, rendered state and performance budgets are unchanged.
Change-source: pulse-maintainer
This commit is contained in:
pulse-triage[bot]
2026-11-10 06:26:34 +00:00
parent bfe226212b
commit e340fbbade
3 changed files with 42 additions and 23 deletions

View File

@@ -4,7 +4,6 @@
"cmd/pulse-mcp/main_test.go": 3,
"frontend-modern/src/__tests__/App.architecture.test.ts": 9,
"frontend-modern/src/api/__tests__/recoveryTransport.test.ts": 1,
"frontend-modern/src/api/__tests__/resourcesHotPath.guardrails.test.ts": 1,
"frontend-modern/src/components/__tests__/GitHubStarBanner.test.tsx": 1,
"frontend-modern/src/components/__tests__/whatsNewModel.test.ts": 3,
"frontend-modern/src/components/AI/__tests__/FindingsPanel.test.ts": 3,

View File

@@ -1,22 +0,0 @@
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { describe, expect, it } from 'vitest';
const resourcesHandlerSource = readFileSync(
resolve(process.cwd(), '../internal/api/resourceapi/resources.go'),
'utf8',
);
describe('resource API hot-path guardrails', () => {
it('reuses the per-generation presentation snapshot across list and stats requests', () => {
expect(
resourcesHandlerSource.match(/sharedPresentationResources\(orgID\)/g) ?? [],
).toHaveLength(2);
expect(resourcesHandlerSource).toContain('allResources := flatCopyResources(sharedResources)');
expect(
resourcesHandlerSource.match(/computeResourceContractStats\(allResources\)/g) ?? [],
).toHaveLength(2);
expect(resourcesHandlerSource).not.toContain('allResources := registry.List()');
expect(resourcesHandlerSource).not.toContain('computeResourceContractByType(registry.List())');
});
});

View File

@@ -2,8 +2,10 @@ package resourceapi
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"reflect"
"testing"
"time"
@@ -37,6 +39,7 @@ func TestPruneResourceForListResponseDoesNotMutateSharedPMG(t *testing.T) {
func TestSharedResourceListsCachedPerGenerationAndImmuneToRequestDecoration(t *testing.T) {
now := time.Date(2026, 8, 5, 12, 0, 0, 0, time.UTC)
h := NewQueryService(&config.Config{DataPath: t.TempDir()})
defer h.CloseStores()
h.SetStateProvider(resourceUnifiedSeedProvider{
snapshot: models.StateSnapshot{LastUpdate: now},
resources: []unifiedresources.Resource{
@@ -88,6 +91,45 @@ func TestSharedResourceListsCachedPerGenerationAndImmuneToRequestDecoration(t *t
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, body=%s", rec.Code, rec.Body.String())
}
var listResponse ResourcesResponse
if err := json.Unmarshal(rec.Body.Bytes(), &listResponse); err != nil {
t.Fatal(err)
}
cachedStats := h.registryCache[cacheKey(orgID)].contractStats
if cachedStats == nil {
t.Fatal("list request did not retain its generation-owned structural summary")
}
// Exercise both consumers, not their source spelling: stats and a later
// list must reuse this generation's summary and return the same counts.
for _, path := range []string{"/api/resources/stats", "/api/resources?limit=1"} {
req := httptest.NewRequest(http.MethodGet, path, nil)
req = req.WithContext(context.WithValue(req.Context(), apicontext.OrgIDContextKey, orgID))
rec := httptest.NewRecorder()
var stats unifiedresources.ResourceStats
if path == "/api/resources/stats" {
h.HandleStats(rec, req)
if err := json.Unmarshal(rec.Body.Bytes(), &stats); err != nil {
t.Fatal(err)
}
} else {
h.HandleListResources(rec, req)
var page ResourcesResponse
if err := json.Unmarshal(rec.Body.Bytes(), &page); err != nil {
t.Fatal(err)
}
stats = page.Aggregations
if len(page.Data) != 1 || page.Meta.Total != listResponse.Meta.Total {
t.Fatal("paginated response lost its row limit or full-fleet total")
}
}
if rec.Code != http.StatusOK || !reflect.DeepEqual(stats, listResponse.Aggregations) {
t.Fatalf("list and stats disagree for %s: status=%d", path, rec.Code)
}
if h.registryCache[cacheKey(orgID)].contractStats != cachedStats {
t.Fatalf("%s replaced the unchanged generation's summary", path)
}
}
after, _, err := h.sharedPresentationResources(orgID)
if err != nil {