Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix(ai): use canonical app-container mentions

rcourtman861ac9ab4d59
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 90ce48cdaa..8de5d0438d 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -282,6 +282,12 @@ label as `label` through the structured mention payload, and the insertion
path uses that same label for prompt text and cursor placement, so mention
search, selection, and submission do not depend on a raw `displayName` field
fork.
+Structured `app-container` mentions must now use canonical unified-resource
+identity (`app-container:<host>:<provider_uid>`) instead of a Docker-transport
+ID. Frontend mention pickers should emit that canonical ID for every
+app-container, including API-backed platforms such as TrueNAS, while backend
+structured-mention resolution may continue to accept legacy `docker:...`
+mentions only as a compatibility path.
The same governed-context rule also applies to the main unified AI resource
overview: infrastructure, workload, alert-label, and top-consumer summaries
must not leak raw resource names, cluster labels, IP addresses, or unresolved
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
index 13fe83baba..c45ce81f52 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
@@ -127,14 +127,15 @@ vi.mock('../MentionAutocomplete', () => ({
MentionAutocomplete: (props: {
visible: boolean;
query: string;
- resources: Array<{ id: string; label: string }>;
- onSelect: (resource: { id: string; label: string }) => void;
+ resources: Array<{ id: string; label: string; node?: string }>;
+ onSelect: (resource: { id: string; label: string; node?: string }) => void;
}) => (
<div
data-testid="mention-autocomplete"
data-visible={String(props.visible)}
data-query={props.query}
data-resource-count={String(props.resources.length)}
+ data-resource-ids={props.resources.map((resource) => resource.id).join('|')}
data-resource-labels={props.resources.map((resource) => resource.label).join('|')}
>
<button
@@ -562,6 +563,53 @@ describe('AIChat', () => {
);
});
+ it('surfaces TrueNAS app containers through canonical app-container mention IDs', async () => {
+ const nextcloud = {
+ id: 'app-container:truenas-main:nextcloud',
+ type: 'app-container' as const,
+ name: 'nextcloud',
+ displayName: 'Nextcloud',
+ status: 'running',
+ parentId: 'agent:truenas-main',
+ parentName: 'truenas-main',
+ platformType: 'truenas',
+ sourceType: 'truenas',
+ tags: ['truenas', 'app'],
+ };
+ mockByType.mockImplementation((type: string) => (type === 'app-container' ? [nextcloud] : []));
+ mockResources.mockReturnValue([nextcloud]);
+
+ renderChat();
+ const textarea = screen.getByPlaceholderText(
+ 'Ask about your infrastructure...',
+ ) as HTMLTextAreaElement;
+ Object.defineProperty(textarea, 'selectionStart', { value: 5, writable: true });
+ fireEvent.input(textarea, { target: { value: '@next' } });
+
+ await waitFor(() => {
+ expect(screen.getByTestId('mention-autocomplete')).toHaveAttribute(
+ 'data-resource-ids',
+ 'app-container:truenas-main:nextcloud',
+ );
+ });
+
+ fireEvent.click(screen.getByTestId('mention-select-first'));
+ fireEvent.keyDown(textarea, { key: 'Enter' });
+
+ expect(mockChat.sendMessage).toHaveBeenCalledWith(
+ '@Nextcloud',
+ [
+ expect.objectContaining({
+ id: 'app-container:truenas-main:nextcloud',
+ name: 'Nextcloud',
+ type: 'app-container',
+ node: 'truenas-main',
+ }),
+ ],
+ undefined,
+ );
+ });
+
it('inserts the governed display label into the prompt when a mention is selected', async () => {
const governedPolicy = {
sensitivity: 'restricted' as const,
diff --git a/frontend-modern/src/components/AI/Chat/index.tsx b/frontend-modern/src/components/AI/Chat/index.tsx
index 3e3668b18b..5e4d9586e7 100644
--- a/frontend-modern/src/components/AI/Chat/index.tsx
+++ b/frontend-modern/src/components/AI/Chat/index.tsx
@@ -399,6 +399,39 @@ export const AIChat: Component<AIChatProps> = (props) => {
resource.id
);
};
+ const getAppContainerMentionHost = (resource: Resource): string => {
+ const platformData = readPlatformData(resource);
+ const platformDocker = asRecord(platformData?.docker);
+ const platformTrueNAS = asRecord(platformData?.truenas);
+ return (
+ resource.parentName ||
+ asString(platformDocker?.hostname) ||
+ asString(platformTrueNAS?.hostname) ||
+ getPreferredResourceHostname(resource) ||
+ ''
+ );
+ };
+ const getAppContainerMentionId = (resource: Resource): string => {
+ if (resource.id.startsWith('app-container:')) {
+ return resource.id;
+ }
+
+ const host = getAppContainerMentionHost(resource);
+ const platformData = readPlatformData(resource);
+ const platformDocker = asRecord(platformData?.docker);
+ const containerID =
+ asString(platformDocker?.containerId) ||
+ asString(platformDocker?.name) ||
+ asString(resource.canonicalIdentity?.primaryId) ||
+ asString(resource.name) ||
+ asString(resource.id);
+
+ if (host && containerID) {
+ return `app-container:${host}:${containerID}`;
+ }
+
+ return resource.id;
+ };
const parseLegacyVmid = (
resource: Resource,
@@ -419,7 +452,7 @@ export const AIChat: Component<AIChatProps> = (props) => {
const vms = byType('vm');
const containers = [...byType('system-container'), ...byType('oci-container')];
const dockerHosts = byType('docker-host');
- const dockerContainers = byType('app-container');
+ const appContainers = byType('app-container');
const agentResources = allResources().filter(
(resource) =>
(resource.type === 'agent' ||
@@ -460,18 +493,7 @@ export const AIChat: Component<AIChatProps> = (props) => {
});
}
- // Add Docker runtimes
- const dockerContainersByRuntimeId = new Map<string, Resource[]>();
- for (const dockerContainer of dockerContainers) {
- if (!dockerContainer.parentId) continue;
- const existing = dockerContainersByRuntimeId.get(dockerContainer.parentId);
- if (existing) {
- existing.push(dockerContainer);
- } else {
- dockerContainersByRuntimeId.set(dockerContainer.parentId, [dockerContainer]);
- }
- }
-
+ // Add container runtimes
for (const runtime of dockerHosts) {
const dockerActionId = getDockerActionId(runtime);
const label = getPreferredResourceDisplayName(runtime);
@@ -486,20 +508,19 @@ export const AIChat: Component<AIChatProps> = (props) => {
type: 'agent',
status: runtimeStatus,
});
+ }
- // Add Docker containers
- for (const container of dockerContainersByRuntimeId.get(runtime.id) || []) {
- const originalContainerId = container.id.includes('/')
- ? container.id.split('/').pop() || container.id
- : container.id;
- mentionCandidates.push({
- id: `docker:${dockerActionId}:${originalContainerId}`,
- label: getPreferredResourceDisplayName(container),
- type: 'app-container',
- status: container.status === 'running' ? 'running' : 'exited',
- node: hostnameOrId,
- });
- }
+ // Add app containers through canonical unified resource identity rather than
+ // a Docker-only transport shape, so API-backed platforms such as TrueNAS use
+ // the same mention contract as Docker-backed workloads.
+ for (const container of appContainers) {
+ mentionCandidates.push({
+ id: getAppContainerMentionId(container),
+ label: getPreferredResourceDisplayName(container),
+ type: 'app-container',
+ status: container.status === 'running' ? 'running' : 'exited',
+ node: getAppContainerMentionHost(container),
+ });
}
// Add nodes
diff --git a/frontend-modern/src/components/AI/__tests__/aiChatUtils.test.ts b/frontend-modern/src/components/AI/__tests__/aiChatUtils.test.ts
index bd6c0a5618..e96e89ae66 100644
--- a/frontend-modern/src/components/AI/__tests__/aiChatUtils.test.ts
+++ b/frontend-modern/src/components/AI/__tests__/aiChatUtils.test.ts
@@ -118,9 +118,9 @@ describe('aiChatUtils', () => {
expect(id).toMatch(/^lxc:[^:]+:\d+$/);
});
- it('docker mention IDs follow docker:agentId:containerId format', () => {
- const id = 'docker:agent-1:abc123';
- expect(id).toMatch(/^docker:[^:]+:[^:]+$/);
+ it('app-container mention IDs follow app-container:host:providerUid format', () => {
+ const id = 'app-container:truenas-main:nextcloud';
+ expect(id).toMatch(/^app-container:[^:]+:[^:]+$/);
});
it('node mention IDs follow node:instance:name format', () => {
diff --git a/internal/ai/chat/context_prefetch.go b/internal/ai/chat/context_prefetch.go
index 6622f264d5..fd5fa135b6 100644
--- a/internal/ai/chat/context_prefetch.go
+++ b/internal/ai/chat/context_prefetch.go
@@ -466,7 +466,8 @@ func (p *ContextPrefetcher) resolveStructuredMentions(structured []StructuredMen
for _, sm := range structured {
// Parse the structured ID to extract resource details.
// Frontend ID formats: "vm:node:vmid", "system-container:node:vmid",
- // "docker:hostId:containerId", "agent:id", "node:instance:name"
+ // "app-container:host:providerUid" (canonical), legacy "docker:hostId:containerId",
+ // "agent:id", "node:instance:name"
parts := strings.Split(sm.ID, ":")
// Enforce canonical v6 frontend mention types only.
@@ -523,7 +524,7 @@ func (p *ContextPrefetcher) resolveStructuredMentions(structured []StructuredMen
})
case "app-container":
- hostID, containerID := parseStructuredDockerMentionID(sm.ID, rs)
+ hostID, containerID := parseStructuredAppContainerMentionID(sm.ID, rs)
// Gather bind mounts via ReadState
var mounts []MountInfo
@@ -618,6 +619,101 @@ func (p *ContextPrefetcher) resolveStructuredMentions(structured []StructuredMen
return mentions
}
+type appContainerResourceGetter interface {
+ GetByType(unifiedresources.ResourceType) []unifiedresources.Resource
+}
+
+type appContainerResourceLister interface {
+ ListByType(unifiedresources.ResourceType) []unifiedresources.Resource
+}
+
+func appContainerResourcesFromReadState(rs unifiedresources.ReadState) []unifiedresources.Resource {
+ if rs == nil {
+ return nil
+ }
+ if getter, ok := any(rs).(appContainerResourceGetter); ok {
+ return getter.GetByType(unifiedresources.ResourceTypeAppContainer)
+ }
+ if lister, ok := any(rs).(appContainerResourceLister); ok {
+ return lister.ListByType(unifiedresources.ResourceTypeAppContainer)
+ }
+ return nil
+}
+
+func appContainerResourceHost(resource unifiedresources.Resource) string {
+ if host := strings.TrimSpace(resource.ParentName); host != "" {
+ return host
+ }
+ if resource.Docker != nil {
+ if host := strings.TrimSpace(resource.Docker.Hostname); host != "" {
+ return host
+ }
+ }
+ if resource.TrueNAS != nil {
+ if host := strings.TrimSpace(resource.TrueNAS.Hostname); host != "" {
+ return host
+ }
+ }
+ for _, host := range resource.Identity.Hostnames {
+ if host = strings.TrimSpace(host); host != "" {
+ return host
+ }
+ }
+ return ""
+}
+
+func parseStructuredAppContainerMentionID(mentionID string, rs unifiedresources.ReadState) (hostID string, containerID string) {
+ const canonicalPrefix = "app-container:"
+ if strings.HasPrefix(mentionID, canonicalPrefix) {
+ if rs != nil {
+ for _, resource := range appContainerResourcesFromReadState(rs) {
+ if !strings.EqualFold(strings.TrimSpace(resource.ID), mentionID) {
+ continue
+ }
+ host := appContainerResourceHost(resource)
+ if host == "" {
+ continue
+ }
+ if providerUID := appContainerProviderUID(resource, host); providerUID != "" {
+ return host, providerUID
+ }
+ }
+ }
+
+ raw := strings.TrimPrefix(mentionID, canonicalPrefix)
+ parts := strings.SplitN(raw, ":", 2)
+ if len(parts) == 2 && strings.TrimSpace(parts[0]) != "" && strings.TrimSpace(parts[1]) != "" {
+ return strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])
+ }
+ return "", ""
+ }
+
+ return parseStructuredDockerMentionID(mentionID, rs)
+}
+
+func appContainerProviderUID(resource unifiedresources.Resource, host string) string {
+ prefix := "app-container:" + strings.TrimSpace(host) + ":"
+ if strings.HasPrefix(resource.ID, prefix) {
+ if providerUID := strings.TrimSpace(strings.TrimPrefix(resource.ID, prefix)); providerUID != "" {
+ return providerUID
+ }
+ }
+ if resource.Docker != nil {
+ if containerID := strings.TrimSpace(resource.Docker.ContainerID); containerID != "" {
+ return containerID
+ }
+ }
+ if resource.Canonical != nil {
+ if primaryID := strings.TrimSpace(resource.Canonical.PrimaryID); primaryID != "" {
+ return primaryID
+ }
+ }
+ if name := strings.TrimSpace(resource.Name); name != "" {
+ return name
+ }
+ return ""
+}
+
func parseStructuredDockerMentionID(mentionID string, rs unifiedresources.ReadState) (hostID string, containerID string) {
const prefix = "docker:"
if !strings.HasPrefix(mentionID, prefix) {
diff --git a/internal/ai/chat/context_prefetch_additional_test.go b/internal/ai/chat/context_prefetch_additional_test.go
index 2956508e74..e543a7b1cb 100644
--- a/internal/ai/chat/context_prefetch_additional_test.go
+++ b/internal/ai/chat/context_prefetch_additional_test.go
@@ -4,6 +4,7 @@ import (
"context"
"strings"
"testing"
+ "time"
"github.com/rcourtman/pulse-go-rewrite/internal/ai/tools"
"github.com/rcourtman/pulse-go-rewrite/internal/models"
@@ -163,6 +164,7 @@ func TestContextPrefetcher_ResolveStructuredMentions(t *testing.T) {
structured := []StructuredMention{
{ID: "docker:dock1:cid:part", Name: "homepage", Type: "app-container"},
+ {ID: "app-container:dock1:cid:part", Name: "homepage", Type: "app-container"},
{ID: "agent:host1", Name: "host1", Type: "agent"},
{ID: "system-container:node1:201", Name: "beta", Type: "system-container", Node: "node1"},
{ID: "docker:resource:docker:abc:cid-simple", Name: "homepage2", Type: "app-container"},
@@ -181,8 +183,8 @@ func TestContextPrefetcher_ResolveStructuredMentions(t *testing.T) {
prefetcher := NewContextPrefetcher(rs, nil)
mentions := prefetcher.resolveStructuredMentions(structured)
- if len(mentions) != 4 {
- t.Fatalf("expected 4 mentions, got %d", len(mentions))
+ if len(mentions) != 5 {
+ t.Fatalf("expected 5 mentions, got %d", len(mentions))
}
if mentions[0].ResourceID != "cid:part" {
@@ -191,17 +193,20 @@ func TestContextPrefetcher_ResolveStructuredMentions(t *testing.T) {
if len(mentions[0].BindMounts) == 0 {
t.Fatalf("expected bind mounts on docker mention")
}
- if mentions[1].ResourceType != "agent" {
- t.Fatalf("expected agent mention, got %q", mentions[1].ResourceType)
+ if mentions[1].TargetID != "dock1" || mentions[1].ResourceID != "cid:part" {
+ t.Fatalf("expected canonical app-container mention to resolve through docker host, got %+v", mentions[1])
}
- if mentions[2].ResourceType != "system-container" {
- t.Fatalf("expected system-container mention type, got %q", mentions[2].ResourceType)
+ if mentions[2].ResourceType != "agent" {
+ t.Fatalf("expected agent mention, got %q", mentions[2].ResourceType)
}
- if mentions[3].TargetID != "resource:docker:abc" {
- t.Fatalf("expected docker target ID with colons preserved, got %q", mentions[3].TargetID)
+ if mentions[3].ResourceType != "system-container" {
+ t.Fatalf("expected system-container mention type, got %q", mentions[3].ResourceType)
}
- if mentions[3].ResourceID != "cid-simple" {
- t.Fatalf("expected docker container ID parsed correctly, got %q", mentions[3].ResourceID)
+ if mentions[4].TargetID != "resource:docker:abc" {
+ t.Fatalf("expected docker target ID with colons preserved, got %q", mentions[4].TargetID)
+ }
+ if mentions[4].ResourceID != "cid-simple" {
+ t.Fatalf("expected docker container ID parsed correctly, got %q", mentions[4].ResourceID)
}
unknown := prefetcher.resolveStructuredMentions([]StructuredMention{{ID: "weird:1", Name: "mystery", Type: "weird"}})
@@ -215,6 +220,74 @@ func TestContextPrefetcher_ResolveStructuredMentions(t *testing.T) {
}
}
+func TestContextPrefetcher_ResolveStructuredMentions_TrueNASCanonicalAppContainer(t *testing.T) {
+ rr := unifiedresources.NewRegistry(nil)
+ now := time.Now().UTC()
+ hostID := "agent:truenas-main"
+ hostSourceID := "truenas-system:truenas-main"
+ rr.IngestRecords(unifiedresources.SourceTrueNAS, []unifiedresources.IngestRecord{
+ {
+ SourceID: hostSourceID,
+ Resource: unifiedresources.Resource{
+ ID: hostID,
+ Type: unifiedresources.ResourceTypeAgent,
+ Name: "truenas-main",
+ Status: unifiedresources.StatusOnline,
+ LastSeen: now,
+ UpdatedAt: now,
+ Agent: &unifiedresources.AgentData{
+ Hostname: "truenas-main",
+ Platform: "truenas",
+ },
+ TrueNAS: &unifiedresources.TrueNASData{Hostname: "truenas-main"},
+ },
+ Identity: unifiedresources.ResourceIdentity{Hostnames: []string{"truenas-main"}},
+ },
+ {
+ SourceID: "app:nextcloud",
+ ParentSourceID: hostSourceID,
+ Resource: unifiedresources.Resource{
+ ID: "app-container:truenas-main:nextcloud",
+ Type: unifiedresources.ResourceTypeAppContainer,
+ Name: "Nextcloud",
+ Status: unifiedresources.StatusOnline,
+ LastSeen: now,
+ UpdatedAt: now,
+ ParentID: &hostID,
+ ParentName: "truenas-main",
+ TrueNAS: &unifiedresources.TrueNASData{Hostname: "truenas-main"},
+ Canonical: &unifiedresources.CanonicalIdentity{
+ DisplayName: "Nextcloud",
+ Hostname: "truenas-main",
+ PrimaryID: "nextcloud",
+ Aliases: []string{"Nextcloud", "nextcloud"},
+ },
+ Tags: []string{"truenas", "app"},
+ },
+ Identity: unifiedresources.ResourceIdentity{Hostnames: []string{"truenas-main"}},
+ },
+ })
+
+ prefetcher := NewContextPrefetcher(rr, nil)
+ mentions := prefetcher.resolveStructuredMentions([]StructuredMention{{
+ ID: "app-container:truenas-main:nextcloud",
+ Name: "Nextcloud",
+ Type: "app-container",
+ }})
+ if len(mentions) != 1 {
+ t.Fatalf("expected one mention, got %#v", mentions)
+ }
+ if mentions[0].ResourceType != "app-container" {
+ t.Fatalf("expected app-container mention type, got %q", mentions[0].ResourceType)
+ }
+ if mentions[0].TargetID != "truenas-main" || mentions[0].TargetHost != "truenas-main" {
+ t.Fatalf("expected TrueNAS host routing, got %+v", mentions[0])
+ }
+ if mentions[0].ResourceID != "nextcloud" {
+ t.Fatalf("expected canonical provider uid, got %+v", mentions[0])
+ }
+}
+
func TestContextPrefetcher_ResolveStructuredMentions_IgnoresLegacyContainerAliases(t *testing.T) {
rs := newTestReadState(models.StateSnapshot{})
prefetcher := NewContextPrefetcher(rs, nil)
diff --git a/internal/ai/chat/types.go b/internal/ai/chat/types.go
index 587f54e9e1..4b516a2d8c 100644
--- a/internal/ai/chat/types.go
+++ b/internal/ai/chat/types.go
@@ -84,7 +84,7 @@ type StreamCallback func(event StreamEvent)
// The frontend resolves these from the autocomplete and sends them alongside the prompt,
// so the backend doesn't need to re-derive resource identity from text.
type StructuredMention struct {
- ID string `json:"id"` // e.g. "system-container:pve-node:123", "docker:docker-host-1:container", "agent:host-1"
+ ID string `json:"id"` // e.g. "system-container:pve-node:123", "app-container:truenas-main:nextcloud", legacy "docker:docker-host-1:container", "agent:host-1"
Name string `json:"name"` // Display name, e.g. "ntfy"
Type string `json:"type"` // "vm", "system-container", "app-container", "node", "agent"
Node string `json:"node,omitempty"` // Proxmox node or parent host
diff --git a/tests/integration/tests/31-truenas-ai-chat-mentions.spec.ts b/tests/integration/tests/31-truenas-ai-chat-mentions.spec.ts
new file mode 100644
index 0000000000..708bf34648
--- /dev/null
+++ b/tests/integration/tests/31-truenas-ai-chat-mentions.spec.ts
@@ -0,0 +1,191 @@
+import fs from 'node:fs';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { test as base, expect } from '@playwright/test';
+import { createAuthenticatedStorageState } from './helpers';
+
+const __dirname = path.dirname(fileURLToPath(import.meta.url));
+
+type WorkerFixtures = {
+ authStorageStatePath: string;
+};
+
+const SCREENSHOT_PATH = '/tmp/truenas-ai-chat-mentions.png';
+
+const test = base.extend<{}, WorkerFixtures>({
+ storageState: async ({ authStorageStatePath }, use) => {
+ await use(authStorageStatePath);
+ },
+ authStorageStatePath: [async ({ browser }, use, workerInfo) => {
+ const storageStatePath = path.resolve(
+ __dirname,
+ '..',
+ '..',
+ 'tmp',
+ 'playwright-auth',
+ `truenas-ai-chat-mentions-${workerInfo.project.name}.json`,
+ );
+ fs.mkdirSync(path.dirname(storageStatePath), { recursive: true });
+ await createAuthenticatedStorageState(browser, storageStatePath);
+ try {
+ await use(storageStatePath);
+ } finally {
+ fs.rmSync(storageStatePath, { force: true });
+ }
+ }, { scope: 'worker' }],
+});
+
+test.describe('TrueNAS AI chat mentions', () => {
+ test.setTimeout(180_000);
+
+ test('surfaces TrueNAS apps as canonical assistant mention targets', async ({ page }) => {
+ await page.route('**/api/truenas/connections', async (route) => {
+ if (route.request().method() !== 'GET') {
+ await route.continue();
+ return;
+ }
+
+ await route.fulfill({
+ status: 200,
+ contentType: 'application/json',
+ body: JSON.stringify([]),
+ });
+ });
+
+ await page.route('**/api/ai/status', async (route) => {
+ await route.fulfill({
+ status: 200,
+ contentType: 'application/json',
+ body: JSON.stringify({ running: true, engine: 'test' }),
+ });
+ });
+
+ await page.route('**/api/ai/sessions', async (route) => {
+ if (route.request().method() !== 'GET') {
+ await route.continue();
+ return;
+ }
+
+ await route.fulfill({
+ status: 200,
+ contentType: 'application/json',
+ body: JSON.stringify([]),
+ });
+ });
+
+ await page.route('**/api/ai/settings', async (route) => {
+ await route.fulfill({
+ status: 200,
+ contentType: 'application/json',
+ body: JSON.stringify({
+ model: 'openai:gpt-4o-mini',
+ chat_model: '',
+ control_level: 'read_only',
+ discovery_enabled: true,
+ }),
+ });
+ });
+
+ await page.route('**/api/ai/models', async (route) => {
+ await route.fulfill({
+ status: 200,
+ contentType: 'application/json',
+ body: JSON.stringify({
+ models: [{ id: 'openai:gpt-4o-mini', name: 'GPT-4o mini' }],
+ }),
+ });
+ });
+
+ await page.route('**/api/resources**', async (route) => {
+ const requestUrl = new URL(route.request().url());
+ if (requestUrl.pathname !== '/api/resources') {
+ await route.continue();
+ return;
+ }
+
+ await route.fulfill({
+ status: 200,
+ contentType: 'application/json',
+ body: JSON.stringify({
+ data: [
+ {
+ id: 'agent:truenas-main',
+ type: 'agent',
+ name: 'truenas-main',
+ status: 'online',
+ lastSeen: '2026-03-30T09:00:00Z',
+ sources: ['agent', 'truenas'],
+ canonicalIdentity: {
+ displayName: 'TrueNAS Main',
+ hostname: 'truenas-main',
+ platformId: 'truenas-main',
+ },
+ agent: {
+ agentId: 'truenas-main',
+ hostname: 'truenas-main',
+ platform: 'truenas',
+ },
+ },
+ {
+ id: 'app-container:truenas-main:nextcloud',
+ type: 'app-container',
+ name: 'nextcloud',
+ status: 'running',
+ lastSeen: '2026-03-30T09:00:00Z',
+ parentId: 'agent:truenas-main',
+ parentName: 'truenas-main',
+ sources: ['truenas'],
+ tags: ['truenas', 'app'],
+ canonicalIdentity: {
+ displayName: 'Nextcloud',
+ hostname: 'truenas-main',
+ primaryId: 'nextcloud',
+ platformId: 'truenas-main',
+ },
+ docker: {
+ containerId: 'nextcloud',
+ hostname: 'truenas-main',
+ },
+ },
+ ],
+ meta: {
+ page: 1,
+ limit: 100,
+ total: 2,
+ totalPages: 1,
+ },
+ }),
+ });
+ });
+
+ await page.goto('/settings/infrastructure/platforms/truenas', {
+ waitUntil: 'domcontentloaded',
+ });
+ await page.waitForURL(/\/settings\/infrastructure\/platforms\/truenas/, {
+ timeout: 15_000,
+ });
+
+ const resourcesLoaded = page.waitForResponse((response) => {
+ const url = new URL(response.url());
+ return url.pathname === '/api/resources' && response.request().method() === 'GET';
+ });
+ await page.getByRole('button', { name: 'Expand Pulse Assistant' }).click();
+ await expect(page.getByRole('heading', { name: 'Pulse Assistant', exact: true })).toBeVisible();
+ await resourcesLoaded;
+
+ const textarea = page.getByPlaceholder('Ask about your infrastructure...');
+ await textarea.click();
+ await textarea.pressSequentially('@next');
+
+ const mentionSurface = page.locator('[data-mention-autocomplete]');
+ await expect(mentionSurface.getByText('Resources')).toBeVisible();
+ await expect(mentionSurface.getByRole('button', { name: /Nextcloud/ })).toBeVisible();
+ await expect(mentionSurface).toContainText('app-container');
+ await expect(mentionSurface).toContainText('truenas-main');
+
+ await mentionSurface.getByRole('button', { name: /Nextcloud/ }).click();
+ await expect(textarea).toHaveValue('@Nextcloud ');
+
+ await page.screenshot({ path: SCREENSHOT_PATH, fullPage: true });
+ });
+});