Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review: attachment size limits, baseUrl validation, CRLF SSE parsing, aria-label, openclaw route tests

[._.]/ Adam Eivy5a589454a714
diff --git a/client/src/components/AppContextPicker.jsx b/client/src/components/AppContextPicker.jsx
index eff0d0fe4b..5f47569ca3 100644
--- a/client/src/components/AppContextPicker.jsx
+++ b/client/src/components/AppContextPicker.jsx
@@ -6,6 +6,7 @@ export default function AppContextPicker({
onChange,
label = 'App context',
placeholder = 'PortOS (default)',
+ ariaLabel,
includeDefaultOption = true,
className = '',
selectClassName = 'w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm min-h-[44px]',
@@ -20,7 +21,7 @@ export default function AppContextPicker({
value={value}
onChange={(event) => onChange?.(event.target.value)}
className={selectClassName}
- aria-label={label || placeholder}
+ aria-label={ariaLabel || label || placeholder}
>
{includeDefaultOption && <option value="">{placeholder}</option>}
{apps.map(app => (
diff --git a/client/src/components/cos/TaskAddForm.jsx b/client/src/components/cos/TaskAddForm.jsx
index a9919c032c..e7fb408ca5 100644
--- a/client/src/components/cos/TaskAddForm.jsx
+++ b/client/src/components/cos/TaskAddForm.jsx
@@ -241,6 +241,7 @@ export default function TaskAddForm({ providers, apps, onTaskAdded, compact = fa
onChange={(appId) => setNewTask(t => ({ ...t, app: appId }))}
label=""
placeholder="PortOS"
+ ariaLabel="Select app context"
showRepoPath={false}
selectClassName="w-full px-2 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm min-h-[44px]"
/>
diff --git a/client/src/services/apiOpenClaw.js b/client/src/services/apiOpenClaw.js
index f2ee7d09f4..34f90e8ca0 100644
--- a/client/src/services/apiOpenClaw.js
+++ b/client/src/services/apiOpenClaw.js
@@ -50,7 +50,7 @@ export async function streamOpenClawMessage(sessionId, { message, context, attac
};
const flushEventBlock = (block) => {
- const lines = block.split('\n');
+ const lines = block.split(/\r?\n/);
let eventName = 'message';
const dataLines = [];
@@ -80,7 +80,7 @@ export async function streamOpenClawMessage(sessionId, { message, context, attac
if (done) break;
buffer += decoder.decode(value, { stream: true });
- const parts = buffer.split('\n\n');
+ const parts = buffer.split(/\r?\n\r?\n/);
buffer = parts.pop() || '';
for (const part of parts) flushEventBlock(part);
}
diff --git a/server/integrations/openclaw/api.js b/server/integrations/openclaw/api.js
index 4a54147c1b..8d0c31578d 100644
--- a/server/integrations/openclaw/api.js
+++ b/server/integrations/openclaw/api.js
@@ -120,13 +120,25 @@ async function loadConfig() {
const envEnabled = parseBoolean(process.env.OPENCLAW_ENABLED);
const enabled = pickFirst(envEnabled, fileConfig.enabled, true);
const baseUrlRaw = pickFirst(process.env.OPENCLAW_BASE_URL, fileConfig.baseUrl, '');
- const baseUrl = typeof baseUrlRaw === 'string' ? baseUrlRaw.trim() : '';
- const configured = enabled !== false && Boolean(baseUrl);
+ let finalBaseUrl = typeof baseUrlRaw === 'string' ? baseUrlRaw.trim() : '';
+ let configured = enabled !== false && Boolean(finalBaseUrl);
+
+ if (configured && finalBaseUrl) {
+ try {
+ // Validate that baseUrl is a well-formed URL; invalid values should not mark the integration as configured.
+ // This avoids later failures in URL-joining logic that would otherwise surface as generic "unreachable" errors.
+ // eslint-disable-next-line no-new
+ new URL(finalBaseUrl);
+ } catch {
+ configured = false;
+ finalBaseUrl = '';
+ }
+ }
return {
enabled,
configured,
- baseUrl,
+ baseUrl: finalBaseUrl,
authToken: pickFirst(process.env.OPENCLAW_AUTH_TOKEN, fileConfig.authToken, ''),
authHeader: pickFirst(process.env.OPENCLAW_AUTH_HEADER, fileConfig.authHeader, 'Authorization'),
authScheme: pickFirst(process.env.OPENCLAW_AUTH_SCHEME, fileConfig.authScheme, 'Bearer'),
diff --git a/server/routes/openclaw.js b/server/routes/openclaw.js
index 6b6673a165..b3cb5c2a9e 100644
--- a/server/routes/openclaw.js
+++ b/server/routes/openclaw.js
@@ -12,6 +12,11 @@ import {
const router = express.Router();
+// ~10 MB as base64 = ~13,333,333 chars (base64 expands 3 bytes → 4 chars)
+const ATTACHMENT_BASE64_MAX_CHARS = 13_333_333;
+// 50 MB combined base64 cap across all attachments in a single request
+const ATTACHMENTS_TOTAL_BASE64_MAX_CHARS = 50_000_000;
+
const attachmentSchema = z.object({
kind: z.enum(['image', 'file']).optional(),
sourceType: z.enum(['base64', 'url']).optional(),
@@ -19,7 +24,7 @@ const attachmentSchema = z.object({
filename: z.string().trim().min(1).optional(),
mediaType: z.string().trim().min(1).optional(),
mimeType: z.string().trim().min(1).optional(),
- data: z.string().trim().min(1).optional(),
+ data: z.string().trim().min(1).max(ATTACHMENT_BASE64_MAX_CHARS, 'Attachment base64 data exceeds the 10 MB per-attachment limit.').optional(),
url: z.string().trim().url().optional()
}).superRefine((value, ctx) => {
const hasData = typeof value.data === 'string' && value.data.trim().length > 0;
@@ -60,6 +65,16 @@ const sendMessageSchema = z.object({
message: z.string().trim().min(1),
context: contextSchema,
attachments: z.array(attachmentSchema).max(8).optional()
+}).superRefine((value, ctx) => {
+ if (!value.attachments || value.attachments.length === 0) return;
+ const totalChars = value.attachments.reduce((sum, a) => sum + (typeof a.data === 'string' ? a.data.length : 0), 0);
+ if (totalChars > ATTACHMENTS_TOTAL_BASE64_MAX_CHARS) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ['attachments'],
+ message: `Combined attachment base64 data exceeds the 50 MB total limit (${Math.round(totalChars / 1_000_000)} MB submitted).`
+ });
+ }
});
router.get('/status', asyncHandler(async (req, res) => {
diff --git a/server/routes/openclaw.test.js b/server/routes/openclaw.test.js
new file mode 100644
index 0000000000..fd17934240
--- /dev/null
+++ b/server/routes/openclaw.test.js
@@ -0,0 +1,466 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import express from 'express';
+import { request } from '../lib/testHelper.js';
+import openclawRoutes from './openclaw.js';
+
+vi.mock('../integrations/openclaw/api.js', () => ({
+ getRuntimeStatus: vi.fn(),
+ listSessions: vi.fn(),
+ getSessionMessages: vi.fn(),
+ sendSessionMessage: vi.fn(),
+ streamSessionMessage: vi.fn()
+}));
+
+import * as openclawApi from '../integrations/openclaw/api.js';
+
+const CONFIGURED_STATUS = {
+ configured: true,
+ enabled: true,
+ reachable: true,
+ label: 'OpenClaw Runtime',
+ defaultSession: 'main',
+ message: null,
+ runtime: null
+};
+
+const UNCONFIGURED_STATUS = {
+ configured: false,
+ enabled: true,
+ reachable: false,
+ label: 'OpenClaw Runtime',
+ defaultSession: null,
+ message: 'OpenClaw is not configured'
+};
+
+describe('OpenClaw Routes', () => {
+ let app;
+
+ beforeEach(() => {
+ app = express();
+ // Match the 50mb body limit used in production (server/index.js)
+ app.use(express.json({ limit: '50mb' }));
+ app.use('/api/openclaw', openclawRoutes);
+ vi.clearAllMocks();
+ });
+
+ // ===========================================================================
+ // GET /api/openclaw/status
+ // ===========================================================================
+
+ describe('GET /api/openclaw/status', () => {
+ it('should return configured status when OpenClaw is set up', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(CONFIGURED_STATUS);
+
+ const response = await request(app).get('/api/openclaw/status');
+
+ expect(response.status).toBe(200);
+ expect(response.body.configured).toBe(true);
+ expect(response.body.reachable).toBe(true);
+ expect(openclawApi.getRuntimeStatus).toHaveBeenCalledTimes(1);
+ });
+
+ it('should return unconfigured status when OpenClaw is not set up', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(UNCONFIGURED_STATUS);
+
+ const response = await request(app).get('/api/openclaw/status');
+
+ expect(response.status).toBe(200);
+ expect(response.body.configured).toBe(false);
+ expect(response.body.reachable).toBe(false);
+ });
+ });
+
+ // ===========================================================================
+ // GET /api/openclaw/sessions
+ // ===========================================================================
+
+ describe('GET /api/openclaw/sessions', () => {
+ it('should return sessions list when configured', async () => {
+ openclawApi.listSessions.mockResolvedValue({
+ configured: true,
+ reachable: true,
+ label: 'OpenClaw Runtime',
+ defaultSession: 'main',
+ sessions: [
+ { id: 'main', title: 'Main Session', status: 'active' },
+ { id: 'work', title: 'Work Session', status: 'idle' }
+ ]
+ });
+
+ const response = await request(app).get('/api/openclaw/sessions');
+
+ expect(response.status).toBe(200);
+ expect(response.body.sessions).toHaveLength(2);
+ expect(response.body.configured).toBe(true);
+ expect(openclawApi.listSessions).toHaveBeenCalledTimes(1);
+ });
+
+ it('should return empty sessions when unconfigured', async () => {
+ openclawApi.listSessions.mockResolvedValue({
+ configured: false,
+ reachable: false,
+ sessions: [],
+ defaultSession: null,
+ label: 'OpenClaw Runtime'
+ });
+
+ const response = await request(app).get('/api/openclaw/sessions');
+
+ expect(response.status).toBe(200);
+ expect(response.body.configured).toBe(false);
+ expect(response.body.sessions).toHaveLength(0);
+ });
+ });
+
+ // ===========================================================================
+ // GET /api/openclaw/sessions/:id/messages
+ // ===========================================================================
+
+ describe('GET /api/openclaw/sessions/:id/messages', () => {
+ it('should return messages for a session', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(CONFIGURED_STATUS);
+ openclawApi.getSessionMessages.mockResolvedValue({
+ configured: true,
+ reachable: true,
+ sessionId: 'main',
+ messages: [
+ { id: 'msg-1', role: 'user', content: 'Hello', createdAt: '2026-01-01T00:00:00.000Z' },
+ { id: 'msg-2', role: 'assistant', content: 'Hi there', createdAt: '2026-01-01T00:00:01.000Z' }
+ ]
+ });
+
+ const response = await request(app).get('/api/openclaw/sessions/main/messages');
+
+ expect(response.status).toBe(200);
+ expect(response.body.messages).toHaveLength(2);
+ expect(response.body.sessionId).toBe('main');
+ expect(openclawApi.getSessionMessages).toHaveBeenCalledWith('main', { limit: 50 });
+ });
+
+ it('should respect limit query param', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(CONFIGURED_STATUS);
+ openclawApi.getSessionMessages.mockResolvedValue({
+ configured: true,
+ reachable: true,
+ sessionId: 'main',
+ messages: []
+ });
+
+ await request(app).get('/api/openclaw/sessions/main/messages?limit=10');
+
+ expect(openclawApi.getSessionMessages).toHaveBeenCalledWith('main', { limit: 10 });
+ });
+
+ it('should cap limit at 200', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(CONFIGURED_STATUS);
+ openclawApi.getSessionMessages.mockResolvedValue({
+ configured: true,
+ reachable: true,
+ sessionId: 'main',
+ messages: []
+ });
+
+ await request(app).get('/api/openclaw/sessions/main/messages?limit=999');
+
+ expect(openclawApi.getSessionMessages).toHaveBeenCalledWith('main', { limit: 200 });
+ });
+
+ it('should return unconfigured response without calling getSessionMessages when not configured', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(UNCONFIGURED_STATUS);
+
+ const response = await request(app).get('/api/openclaw/sessions/main/messages');
+
+ expect(response.status).toBe(200);
+ expect(response.body.configured).toBe(false);
+ expect(response.body.messages).toHaveLength(0);
+ expect(openclawApi.getSessionMessages).not.toHaveBeenCalled();
+ });
+
+ it('should use default limit of 50 when limit is invalid', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(CONFIGURED_STATUS);
+ openclawApi.getSessionMessages.mockResolvedValue({
+ configured: true,
+ reachable: true,
+ sessionId: 'main',
+ messages: []
+ });
+
+ await request(app).get('/api/openclaw/sessions/main/messages?limit=notanumber');
+
+ expect(openclawApi.getSessionMessages).toHaveBeenCalledWith('main', { limit: 50 });
+ });
+ });
+
+ // ===========================================================================
+ // POST /api/openclaw/sessions/:id/messages
+ // ===========================================================================
+
+ describe('POST /api/openclaw/sessions/:id/messages', () => {
+ it('should send a message and return the reply', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(CONFIGURED_STATUS);
+ openclawApi.sendSessionMessage.mockResolvedValue({
+ ok: true,
+ configured: true,
+ reachable: true,
+ sessionId: 'main',
+ message: {
+ id: 'resp-1',
+ role: 'assistant',
+ content: 'Hello back!',
+ createdAt: '2026-01-01T00:00:01.000Z',
+ status: 'completed'
+ }
+ });
+
+ const response = await request(app)
+ .post('/api/openclaw/sessions/main/messages')
+ .send({ message: 'Hello!' });
+
+ expect(response.status).toBe(200);
+ expect(response.body.ok).toBe(true);
+ expect(response.body.message.role).toBe('assistant');
+ expect(openclawApi.sendSessionMessage).toHaveBeenCalledWith('main', expect.objectContaining({ message: 'Hello!' }));
+ });
+
+ it('should pass context and attachments to the service', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(CONFIGURED_STATUS);
+ openclawApi.sendSessionMessage.mockResolvedValue({
+ ok: true,
+ configured: true,
+ reachable: true,
+ sessionId: 'main',
+ message: { id: 'resp-1', role: 'assistant', content: 'Got it', createdAt: '2026-01-01T00:00:01.000Z', status: 'completed' }
+ });
+
+ const payload = {
+ message: 'Review this',
+ context: { appName: 'myapp', repoPath: '/projects/myapp' },
+ attachments: [{ sourceType: 'url', url: 'https://example.com/image.png', kind: 'image' }]
+ };
+
+ const response = await request(app)
+ .post('/api/openclaw/sessions/main/messages')
+ .send(payload);
+
+ expect(response.status).toBe(200);
+ expect(openclawApi.sendSessionMessage).toHaveBeenCalledWith('main', expect.objectContaining({
+ message: 'Review this',
+ context: expect.objectContaining({ appName: 'myapp' }),
+ attachments: expect.arrayContaining([expect.objectContaining({ url: 'https://example.com/image.png' })])
+ }));
+ });
+
+ it('should return 400 when message is missing', async () => {
+ const response = await request(app)
+ .post('/api/openclaw/sessions/main/messages')
+ .send({ context: { appName: 'myapp' } });
+
+ expect(response.status).toBe(400);
+ expect(openclawApi.sendSessionMessage).not.toHaveBeenCalled();
+ });
+
+ it('should return 400 when message is empty string', async () => {
+ const response = await request(app)
+ .post('/api/openclaw/sessions/main/messages')
+ .send({ message: ' ' });
+
+ expect(response.status).toBe(400);
+ expect(openclawApi.sendSessionMessage).not.toHaveBeenCalled();
+ });
+
+ it('should return 503 when OpenClaw is not configured', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(UNCONFIGURED_STATUS);
+
+ const response = await request(app)
+ .post('/api/openclaw/sessions/main/messages')
+ .send({ message: 'Hello' });
+
+ expect(response.status).toBe(503);
+ expect(response.body.code).toBe('OPENCLAW_UNCONFIGURED');
+ expect(openclawApi.sendSessionMessage).not.toHaveBeenCalled();
+ });
+
+ it('should return 400 when attachment count exceeds 8', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(CONFIGURED_STATUS);
+
+ const attachments = Array.from({ length: 9 }, (_, i) => ({
+ sourceType: 'url',
+ url: `https://example.com/image${i}.png`,
+ kind: 'image'
+ }));
+
+ const response = await request(app)
+ .post('/api/openclaw/sessions/main/messages')
+ .send({ message: 'Too many', attachments });
+
+ expect(response.status).toBe(400);
+ expect(openclawApi.sendSessionMessage).not.toHaveBeenCalled();
+ });
+
+ it('should return 400 when attachment has neither data nor url', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(CONFIGURED_STATUS);
+
+ const response = await request(app)
+ .post('/api/openclaw/sessions/main/messages')
+ .send({
+ message: 'Bad attachment',
+ attachments: [{ kind: 'image', sourceType: 'base64' }]
+ });
+
+ expect(response.status).toBe(400);
+ expect(openclawApi.sendSessionMessage).not.toHaveBeenCalled();
+ });
+
+ it('should return 400 when a base64 attachment exceeds the 10 MB per-attachment limit', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(CONFIGURED_STATUS);
+
+ // 13,333,334 chars > ATTACHMENT_BASE64_MAX_CHARS (13,333,333)
+ const oversizedData = 'A'.repeat(13_333_334);
+
+ const response = await request(app)
+ .post('/api/openclaw/sessions/main/messages')
+ .send({
+ message: 'Big attachment',
+ attachments: [{ sourceType: 'base64', data: oversizedData, mediaType: 'image/png', kind: 'image' }]
+ });
+
+ expect(response.status).toBe(400);
+ expect(response.body.code).toBe('VALIDATION_ERROR');
+ expect(openclawApi.sendSessionMessage).not.toHaveBeenCalled();
+ });
+
+ it('should return 400 when combined attachments exceed the 50 MB total limit', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(CONFIGURED_STATUS);
+
+ // Use 6 attachments each at 9,000,000 chars (each individually under the ~13.3M per-attachment cap)
+ // Combined = 54,000,000 chars > ATTACHMENTS_TOTAL_BASE64_MAX_CHARS (50,000,000).
+ // A dedicated app instance with a higher body-parser limit is required here so Express
+ // parses the request and hands it to Zod, rather than rejecting it with 413 itself.
+ const bigApp = express();
+ bigApp.use(express.json({ limit: '100mb' }));
+ bigApp.use('/api/openclaw', openclawRoutes);
+
+ const data = 'A'.repeat(9_000_000);
+ const attachments = Array.from({ length: 6 }, () => ({
+ sourceType: 'base64',
+ data,
+ mediaType: 'image/png',
+ kind: 'image'
+ }));
+
+ const response = await request(bigApp)
+ .post('/api/openclaw/sessions/main/messages')
+ .send({ message: 'Combined too large', attachments });
+
+ expect(response.status).toBe(400);
+ expect(response.body.code).toBe('VALIDATION_ERROR');
+ expect(openclawApi.sendSessionMessage).not.toHaveBeenCalled();
+ });
+
+ it('should accept a valid base64 attachment within size limits', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(CONFIGURED_STATUS);
+ openclawApi.sendSessionMessage.mockResolvedValue({
+ ok: true,
+ configured: true,
+ reachable: true,
+ sessionId: 'main',
+ message: { id: 'r1', role: 'assistant', content: 'ok', createdAt: '2026-01-01T00:00:00.000Z', status: 'completed' }
+ });
+
+ // 100 chars — well within any limit
+ const response = await request(app)
+ .post('/api/openclaw/sessions/main/messages')
+ .send({
+ message: 'Small attachment',
+ attachments: [{ sourceType: 'base64', data: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==', mediaType: 'image/png', kind: 'image' }]
+ });
+
+ expect(response.status).toBe(200);
+ expect(openclawApi.sendSessionMessage).toHaveBeenCalledTimes(1);
+ });
+ });
+
+ // ===========================================================================
+ // POST /api/openclaw/sessions/:id/messages/stream
+ // ===========================================================================
+
+ describe('POST /api/openclaw/sessions/:id/messages/stream', () => {
+ it('should return 503 when OpenClaw is not configured', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(UNCONFIGURED_STATUS);
+
+ const response = await request(app)
+ .post('/api/openclaw/sessions/main/messages/stream')
+ .send({ message: 'Stream this' });
+
+ expect(response.status).toBe(503);
+ expect(response.body.code).toBe('OPENCLAW_UNCONFIGURED');
+ expect(openclawApi.streamSessionMessage).not.toHaveBeenCalled();
+ });
+
+ it('should return 400 when message is missing', async () => {
+ const response = await request(app)
+ .post('/api/openclaw/sessions/main/messages/stream')
+ .send({});
+
+ expect(response.status).toBe(400);
+ expect(openclawApi.streamSessionMessage).not.toHaveBeenCalled();
+ });
+
+ it('should return 400 when a base64 attachment exceeds the per-attachment size limit', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(CONFIGURED_STATUS);
+
+ const oversizedData = 'A'.repeat(13_333_334);
+
+ const response = await request(app)
+ .post('/api/openclaw/sessions/main/messages/stream')
+ .send({
+ message: 'Stream big',
+ attachments: [{ sourceType: 'base64', data: oversizedData, mediaType: 'image/png', kind: 'image' }]
+ });
+
+ expect(response.status).toBe(400);
+ expect(openclawApi.streamSessionMessage).not.toHaveBeenCalled();
+ });
+
+ it('should stream SSE events when configured and upstream is available', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(CONFIGURED_STATUS);
+
+ const sseChunks = ['data: {"type":"text_delta","text":"Hello"}\n\n', 'data: [DONE]\n\n'];
+ let chunkIndex = 0;
+ const mockReader = {
+ read: vi.fn().mockImplementation(async () => {
+ if (chunkIndex < sseChunks.length) {
+ const encoder = new TextEncoder();
+ return { done: false, value: encoder.encode(sseChunks[chunkIndex++]) };
+ }
+ return { done: true, value: undefined };
+ }),
+ cancel: vi.fn().mockResolvedValue(undefined)
+ };
+ const mockBody = { getReader: vi.fn().mockReturnValue(mockReader) };
+ const mockResponse = { ok: true, body: mockBody };
+
+ openclawApi.streamSessionMessage.mockResolvedValue({ response: mockResponse });
+
+ const response = await request(app)
+ .post('/api/openclaw/sessions/main/messages/stream')
+ .send({ message: 'Stream this' });
+
+ expect(response.status).toBe(200);
+ expect(response.headers['content-type']).toContain('text/event-stream');
+ expect(openclawApi.streamSessionMessage).toHaveBeenCalledWith('main', expect.objectContaining({ message: 'Stream this' }));
+ });
+
+ it('should write an error SSE event when upstream body is null', async () => {
+ openclawApi.getRuntimeStatus.mockResolvedValue(CONFIGURED_STATUS);
+ openclawApi.streamSessionMessage.mockResolvedValue({ response: { ok: true, body: null } });
+
+ const response = await request(app)
+ .post('/api/openclaw/sessions/main/messages/stream')
+ .send({ message: 'No body' });
+
+ expect(response.status).toBe(200);
+ expect(response.text).toContain('No upstream stream body');
+ });
+ });
+});