Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

test(market-maker): cover engine liveness and style the engine-down banner

nirholasd66bddd406af
diff --git a/src/launch-copilot.css b/src/launch-copilot.css
index dcd0f7dd7..20da14fbf 100644
--- a/src/launch-copilot.css
+++ b/src/launch-copilot.css
@@ -120,6 +120,15 @@
/* dashboard */
.lc-dash { display: flex; flex-direction: column; gap: var(--space-md); }
+/* engine-down banner: the policy is armed but no worker is sweeping it */
+.lc-notice {
+ display: flex; gap: var(--space-sm); align-items: flex-start;
+ padding: var(--space-sm); border-radius: var(--radius-md);
+ background: color-mix(in srgb, var(--warn) 8%, var(--surface-1));
+ border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
+}
+.lc-notice__icon { color: var(--warn); font-size: var(--text-md); line-height: 1.2; flex: none; }
+.lc-notice__title { font-family: var(--font-display); font-size: var(--text-sm); color: var(--warn); margin: 0 0 2px; }
.lc-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: var(--space-xs); }
.lc-stat { display: flex; flex-direction: column; gap: 2px; padding: var(--space-sm); border-radius: var(--radius-md); background: var(--surface-1); border: 1px solid var(--stroke); }
.lc-stat__v { font-family: var(--font-mono); font-size: var(--text-md); font-weight: var(--weight-semibold); color: var(--ink-bright); }
diff --git a/tests/market-maker.test.js b/tests/market-maker.test.js
index 43fe34890..fd2e054e9 100644
--- a/tests/market-maker.test.js
+++ b/tests/market-maker.test.js
@@ -13,6 +13,7 @@ import { describe, it, expect } from 'vitest';
import {
GUARDS, PRESETS, PolicyError,
normalizePolicyPatch, assertPolicySafe, toPublicPolicy, toPublicAction, SOL,
+ engineLivenessFromBeat, ENGINE_STALE_AFTER_SECONDS,
} from '../api/_lib/market-maker.js';
describe('normalizePolicyPatch — presets + coercion', () => {
@@ -144,3 +145,38 @@ describe('toPublicPolicy / toPublicAction', () => {
expect(a.kind).toBe('defend_buy');
});
});
+
+describe('engineLivenessFromBeat: is a worker actually sweeping?', () => {
+ const NOW = Date.parse('2026-06-23T12:00:00Z');
+
+ it('reports a fresh heartbeat as live', () => {
+ const e = engineLivenessFromBeat({ mode: 'simulate', last_beat_at: '2026-06-23T11:59:30Z' }, NOW);
+ expect(e.live).toBe(true);
+ expect(e.mode).toBe('simulate');
+ expect(e.seconds_since_beat).toBe(30);
+ expect(e.stale_after_seconds).toBe(ENGINE_STALE_AFTER_SECONDS);
+ });
+
+ it('reports a stale heartbeat as down (six missed beats)', () => {
+ const e = engineLivenessFromBeat({ mode: 'live', last_beat_at: '2026-06-23T11:50:00Z' }, NOW);
+ expect(e.live).toBe(false);
+ expect(e.seconds_since_beat).toBe(600);
+ expect(e.last_beat_at).toBe('2026-06-23T11:50:00.000Z');
+ });
+
+ it('treats a missing or unreadable heartbeat as down, never as live', () => {
+ for (const row of [null, undefined, {}, { last_beat_at: null }, { last_beat_at: 'not-a-date' }]) {
+ const e = engineLivenessFromBeat(row, NOW);
+ expect(e.live).toBe(false);
+ expect(e.last_beat_at).toBeNull();
+ expect(e.seconds_since_beat).toBeNull();
+ }
+ });
+
+ it('holds the boundary exactly at the stale window', () => {
+ const at = new Date(NOW - ENGINE_STALE_AFTER_SECONDS * 1000).toISOString();
+ const past = new Date(NOW - (ENGINE_STALE_AFTER_SECONDS + 1) * 1000).toISOString();
+ expect(engineLivenessFromBeat({ last_beat_at: at }, NOW).live).toBe(true);
+ expect(engineLivenessFromBeat({ last_beat_at: past }, NOW).live).toBe(false);
+ });
+});