mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-03 10:33:40 +01:00
Per maintainer decision: the cloud-context-privacy feature was bloat. The real fix for the "useless Assistant on cloud" problem was the earlier sensitivity recalibration (ordinary workloads = Internal, not redacted); the dial layered a configurable knob on top of an already-solved problem, guarding mostly-non-secret data on a destination the operator opted into, and demanded every model-bound path stay dial-aware (a standing leak surface). The privacy control users actually understand is the choice of model — cloud provider vs. local Ollama. Removed entirely: - AIConfig.CloudContextPrivacy dial + constants + GetCloudContextPrivacy / NormalizeCloudContextPrivacy, AND the now-dead legacy ShareOperationalContextWithCloud boolean + ShouldShareOperationalContextWithCloud (internal/config/ai.go); the config-load migration (persistence.go). - Both fields from the /api/settings/ai request/response, validation, and sync (ai_handlers.go) + the JSON contract snapshots. - The "Cloud model privacy" 3-option UI control, form field, presentation copy, and CloudContextPrivacy type (frontend), plus their tests. - The dial branching in the seam: chat/service.go cloudPrivacyLevel, CloudContextPolicy.Level + local_only suppression + the localOnly directive (context_prefetch.go), the inventory resourceLabel dial logic (resource_context*), and the modelboundary RedactLocalOnlyResourcesOnly option. Fixed lean posture (no setting): a cloud-routed model receives real infrastructure context, with two always-on invariants enforced by the model-boundary sanitizer — credentials are always stripped, and local-only/Restricted resources (the floor) never leave the local trust boundary. Local (Ollama) always full. The sanitizer's default is now the local-only floor; it remains the universal backstop installed on EVERY model-bound path (chat, session compaction, discovery/report/analysis via the shared helper). Kept the two standalone fixes from this effort: compaction now routes through the sanitizer, and directives no longer inject the "redacted by policy" placeholder. Governance: ai-runtime contract rewritten to a fixed-posture rule; api-contracts / frontend-primitives / agent-lifecycle / storage-recovery dial references removed. Tests updated to the floor-only behavior (local-only redacted, Sensitive flows, secrets stripped). Full internal/ai/..., config, api suites green; frontend type-check + tests + lint green.
135 lines
4.6 KiB
Go
135 lines
4.6 KiB
Go
package ai
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
|
|
unifiedresources "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
|
|
)
|
|
|
|
func TestBuildUnifiedResourcePolicyContext(t *testing.T) {
|
|
resources := unifiedresources.RefreshCanonicalMetadataSlice([]unifiedresources.Resource{
|
|
{
|
|
ID: "public-1",
|
|
Name: "public-vm",
|
|
Type: unifiedresources.ResourceTypeVM,
|
|
Tags: []string{"public"},
|
|
},
|
|
{
|
|
ID: "sensitive-1",
|
|
Name: "db-1",
|
|
Type: unifiedresources.ResourceTypeVM,
|
|
Tags: []string{"database"},
|
|
Status: unifiedresources.StatusOnline,
|
|
Identity: unifiedresources.ResourceIdentity{
|
|
Hostnames: []string{"db.internal"},
|
|
IPAddresses: []string{"10.0.0.10"},
|
|
},
|
|
Canonical: &unifiedresources.CanonicalIdentity{
|
|
PlatformID: "db.internal",
|
|
Aliases: []string{"db-1"},
|
|
},
|
|
},
|
|
{
|
|
ID: "restricted-1",
|
|
Name: "mail-gw",
|
|
Type: unifiedresources.ResourceTypePMG,
|
|
Status: unifiedresources.StatusWarning,
|
|
PMG: &unifiedresources.PMGData{Hostname: "mail.internal"},
|
|
},
|
|
{
|
|
ID: "storage-1",
|
|
Name: "backup-volume",
|
|
Type: unifiedresources.ResourceTypeStorage,
|
|
Status: unifiedresources.StatusOnline,
|
|
Storage: &unifiedresources.StorageMeta{
|
|
Path: "/mnt/pve/backups",
|
|
},
|
|
},
|
|
})
|
|
|
|
context := buildUnifiedResourcePolicyContext(unifiedresources.SummarizePolicyPosture(resources), "")
|
|
|
|
if !context.hasGovernedResources() {
|
|
t.Fatal("expected governed posture")
|
|
}
|
|
if context.localOnlyCount != 1 {
|
|
t.Fatalf("localOnlyCount = %d, want 1", context.localOnlyCount)
|
|
}
|
|
|
|
wantHints := []unifiedresources.ResourceRedactionHint{
|
|
unifiedresources.ResourceRedactionHostname,
|
|
unifiedresources.ResourceRedactionIPAddress,
|
|
unifiedresources.ResourceRedactionPlatformID,
|
|
unifiedresources.ResourceRedactionAlias,
|
|
unifiedresources.ResourceRedactionPath,
|
|
}
|
|
if !reflect.DeepEqual(context.redactionHints, wantHints) {
|
|
t.Fatalf("redactionHints = %#v, want %#v", context.redactionHints, wantHints)
|
|
}
|
|
|
|
joined := strings.Join(context.appendSummarySections(nil), "\n")
|
|
if !strings.Contains(joined, "### Data Governance") {
|
|
t.Fatalf("expected data governance section, got %q", joined)
|
|
}
|
|
if !strings.Contains(joined, "Sensitivity: 1 Public, 0 Internal, 2 Sensitive, 1 Restricted") {
|
|
t.Fatalf("expected canonical sensitivity summary, got %q", joined)
|
|
}
|
|
if !strings.Contains(joined, "Routing: 1 Cloud Summary, 2 Local First, 1 Local Only") {
|
|
t.Fatalf("expected canonical routing summary, got %q", joined)
|
|
}
|
|
if count := strings.Count(joined, "### Policy Redaction Hints"); count != 1 {
|
|
t.Fatalf("policy redaction hints count = %d, want 1 in %q", count, joined)
|
|
}
|
|
if !strings.Contains(joined, "Redactions in use: Hostname, IP Address, Platform ID, Alias, Path") {
|
|
t.Fatalf("expected canonical redaction labels, got %q", joined)
|
|
}
|
|
}
|
|
|
|
func TestBuildUnifiedResourcePolicyContextExternalModel(t *testing.T) {
|
|
localOnly := unifiedresources.Resource{
|
|
ID: "mail-1",
|
|
Name: "customer-mail",
|
|
Type: unifiedresources.ResourceTypePMG,
|
|
Status: unifiedresources.StatusWarning,
|
|
PMG: &unifiedresources.PMGData{Hostname: "mail.internal"},
|
|
}
|
|
cloudSummary := unifiedresources.Resource{
|
|
ID: "public-1",
|
|
Name: "public-node",
|
|
Type: unifiedresources.ResourceTypeAgent,
|
|
Status: unifiedresources.StatusOnline,
|
|
Tags: []string{"public"},
|
|
}
|
|
resources := unifiedresources.RefreshCanonicalMetadataSlice([]unifiedresources.Resource{localOnly, cloudSummary})
|
|
|
|
context := buildUnifiedResourcePolicyContext(unifiedresources.SummarizePolicyPosture(resources), "openai:gpt-4o")
|
|
|
|
if !context.externalModel {
|
|
t.Fatal("expected external model handling")
|
|
}
|
|
if context.includeResourceDetails(resources[0]) {
|
|
t.Fatal("expected local-only resource details to be omitted")
|
|
}
|
|
if !context.includeResourceDetails(resources[1]) {
|
|
t.Fatal("expected cloud-summary resource details to remain available")
|
|
}
|
|
if filtered := context.filterDetailedResources(resources); len(filtered) != 1 || filtered[0].ID != "public-1" {
|
|
t.Fatalf("filtered resources = %#v, want only public-1", filtered)
|
|
}
|
|
|
|
joined := strings.Join(context.appendSummarySections(nil), "\n")
|
|
if !strings.Contains(joined, "External model handling: 1 local-only resources are represented only in aggregate and omitted from detailed context.") {
|
|
t.Fatalf("expected external handling summary, got %q", joined)
|
|
}
|
|
|
|
localContext := buildUnifiedResourcePolicyContext(unifiedresources.SummarizePolicyPosture(resources), "ollama:llama3")
|
|
if localContext.externalModel {
|
|
t.Fatal("expected ollama destination to stay local")
|
|
}
|
|
if !localContext.includeResourceDetails(resources[0]) {
|
|
t.Fatal("expected local model context to include local-only resource details")
|
|
}
|
|
}
|