Files
streamline/control-web/test/eddyUsagePanel.test.tsx
2026-11-16 17:26:44 -08:00

67 lines
6.2 KiB
TypeScript

import { expect, test } from "bun:test";
import { renderToStaticMarkup } from "react-dom/server";
import { UsageReport, type UsageMetrics } from "../src/components/EddyUsagePanel";
// The shape GET /api/eddy/admin/usage returned in an end-to-end run (Mac app → runtime → control plane → Postgres),
// plus a signed-in second Mac.
const data: UsageMetrics = {
from: 0, until: 1794477200000, timezone: "UTC", days: 7,
summary: {activeInstallations: 2, activeDevices: 2, activeAccounts: 1, anonymousDevices: 1, portalSessions: 0, shellSessions: 3,
portalActiveMs: 0, shellActiveMs: 360000, appRuntimeMs: 90000},
daily: [{day: "2026-11-12", activeInstallations: 2, activeDevices: 2, actions: 3, portalActiveMs: 0, shellActiveMs: 360000}],
operations: [
{name: "runtime.prepare", action: "first-launch", source: "shell", count: 1, activeInstallations: 1, succeeded: 1, failed: 0, cancelled: 0, successRate: 1, p50Ms: 57876, p95Ms: 57876, p95QueueMs: null},
{name: "app.launch", action: "app", source: "runtime", count: 2, activeInstallations: 2, succeeded: 1, failed: 1, cancelled: 0, successRate: .5, p50Ms: 30000, p95Ms: 30000, p95QueueMs: null},
{name: "view.opened", action: "desk", source: "shell", count: 4, activeInstallations: 1, succeeded: 0, failed: 0, cancelled: 0, successRate: null, p50Ms: null, p95Ms: null, p95QueueMs: null},
],
releases: [{release: "2026.11.12-eddy-home.35", activeInstallations: 2}],
users: [
{user: "anonymous", activeInstallations: 1, activeDevices: 1, portalSessions: 0, shellSessions: 2, actions: 2, launchesSucceeded: 1, launchesFailed: 0, operationsSucceeded: 1, operationsFailed: 1, portalActiveMs: 0, shellActiveMs: 60000, appRuntimeMs: 0, lastAt: 1794477175868},
{user: "someone@example.com", activeInstallations: 1, activeDevices: 1, portalSessions: 0, shellSessions: 1, actions: 1, launchesSucceeded: 0, launchesFailed: 1, operationsSucceeded: 0, operationsFailed: 0, portalActiveMs: 0, shellActiveMs: 300000, appRuntimeMs: 90000, lastAt: 1794477100000},
],
devices: [
{device: "89fead1d", installations: 1, accounts: 0, neverSignedIn: true, firstAt: 1794476800000, lastAt: 1794477175868, shellSessions: 2, shellActiveMs: 60000, actions: 2,
launchesSucceeded: 1, launchesFailed: 0, appRuntimeMs: 0, appVersions: ["0.9.13+15"], profile: {model: "Mac16,7", chip: "m4", memoryGB: 48, macos: "26.6", language: "zh", location: "other"}},
{device: "fedcba98", installations: 1, accounts: 1, neverSignedIn: false, firstAt: 1794470000000, lastAt: 1794477100000, shellSessions: 1, shellActiveMs: 300000, actions: 1,
launchesSucceeded: 0, launchesFailed: 1, appRuntimeMs: 90000, appVersions: [], profile: null},
],
funnel: {firstLaunch: 1, runtimeReady: 1, runtimeReadyP50Ms: 57876, homeShown: 1, homeShownP50Ms: 58255, appInstalled: 0, appInstalledP50Ms: null,
taskOpened: 0, taskOpenedP50Ms: null, firstEdit: 0, firstEditP50Ms: null, firstShare: 0, firstShareP50Ms: null},
retention: [{week: "2026-11-09", devices: 1, d1Eligible: 0, d1: 0, d7Eligible: 0, d7: 0, d28Eligible: 0, d28: 0}],
adoption: {activeDevices: 2, openedTask: 1, designDesk: 1, coldRestart: 0, agentEdit: 0, share: 0, import: 0, relay: 0},
appVersions: [{appVersion: "0.9.13+15", devices: 1, lastAt: 1794477175868}],
flows: [{name: "permission.flow", action: "screen-recording", step: "granted", count: 1, devices: 1}],
details: [
{name: "preview.change", action: "language", detail: "ar", count: 3, devices: 1, succeeded: 2, failed: 1, p50Ms: 21000, freedMB: 0},
{name: "dock.attach", action: "detached", detail: "", count: 2, devices: 1, succeeded: 0, failed: 0, p50Ms: 600000, freedMB: 0},
{name: "agent.entry", action: "app", detail: "claude", count: 4, devices: 1, succeeded: 0, failed: 0, p50Ms: null, freedMB: 0},
{name: "notice.shown", action: "failure", detail: "app", count: 1, devices: 1, succeeded: 0, failed: 0, p50Ms: null, freedMB: 0},
{name: "notice.action", action: "clean-up", detail: "space", count: 1, devices: 1, succeeded: 0, failed: 0, p50Ms: null, freedMB: 0},
{name: "operation.completed", action: "storage.clean", detail: "app-cache", count: 2, devices: 1, succeeded: 2, failed: 0, p50Ms: 900, freedMB: 1500},
{name: "app.crash", action: "app", detail: "app", count: 1, devices: 1, succeeded: 0, failed: 0, p50Ms: null, freedMB: 0},
],
};
test("the usage report shows devices, the activation funnel, retention, feature use and the Mac app", () => {
const html = renderToStaticMarkup(<UsageReport data={data} user="" onUser={() => {}} />);
for (const text of ["活跃设备", "Mac app 会话", "激活漏斗", "运行环境准备好", "57.9 s", "留存", "还没到", "功能使用", "用设计台",
"50.0%", "按设备", "<code>89fead1d</code>", "Mac16,7 · M4 · 48 GB · macOS 26.6 · 不在「应用程序」", "未登录(按设备上传)",
"屏幕录制授权", "已允许", "0.9.13+15", "准备运行环境 · first-launch", "Mac app"]) expect(html).toContain(text);
expect(html).toContain("其中 1 台设备有未登录时上传的数据");
});
test("P1 detail: previews, docking, the Agent entry, failure cards, storage cleaning and crashes", () => {
const html = renderToStaticMarkup(<UsageReport data={{...data, summary: {...data.summary, appCrashes: 1}}} user="" onUser={() => {}} />);
for (const text of ["设计台、预览与吸附", "预览 · 换语言", "العربية", "66.7%", "21.0 s", "吸附 · 松开(吸附时长)", "10.0 min",
"从 eddy 找 Agent", "Agent 入口 · 桌面 App", "提示与失败卡", "出现 · 失败</td><td>App 版本", "点了 · 去清理</td><td>空间不够",
"存储清理", "存储 · 清理</td><td>App 缓存", "1.5 GB", "App 崩溃", "每 App 小时 40.00 次", "<td>崩溃</td><td>App 本身"])
expect(html).toContain(text);
});
test("an old server's answer (schema 1, no device fields) still renders", () => {
const {devices, funnel, retention, adoption, appVersions, flows, ...old} = data;
const html = renderToStaticMarkup(<UsageReport data={{...old, summary: {activeInstallations: 1, portalSessions: 2, portalActiveMs: 1000, appRuntimeMs: 0}}} user="" onUser={() => {}} />);
expect(html).toContain("活跃安装");
expect(html).not.toContain("激活漏斗");
});