fix(FN-3808): increase create-room member role typography
- Increase the member role text sizing in CreateRoomModal for better readability - Update CreateRoomModal.css with the adjusted typography value - Keep the change scoped to create-room role styling only Fusion-Task-Id: FN-3808
This commit is contained in:
236
packages/dashboard/src/__tests__/chat-room-routes.test.ts
Normal file
236
packages/dashboard/src/__tests__/chat-room-routes.test.ts
Normal file
@@ -0,0 +1,236 @@
|
||||
import { mkdtempSync } from "node:fs";
|
||||
import { rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { ChatStore, Database } from "@fusion/core";
|
||||
import { request } from "../test-request.js";
|
||||
|
||||
class MockStore {
|
||||
constructor(private readonly rootDir: string, private readonly db: Database) {}
|
||||
|
||||
getRootDir(): string { return this.rootDir; }
|
||||
getFusionDir(): string { return join(this.rootDir, ".fusion"); }
|
||||
getKbDir(): string { return join(this.rootDir, ".fusion"); }
|
||||
getDatabase(): Database { return this.db; }
|
||||
}
|
||||
|
||||
describe("Chat Room API Routes", () => {
|
||||
let tempRoot: string;
|
||||
let db: Database;
|
||||
let store: MockStore;
|
||||
let chatStore: ChatStore;
|
||||
let app: ReturnType<typeof import("../server.js").createServer>;
|
||||
|
||||
beforeEach(async () => {
|
||||
tempRoot = mkdtempSync(join(tmpdir(), "fusion-chat-room-routes-"));
|
||||
const fusionDir = join(tempRoot, ".fusion");
|
||||
db = new Database(fusionDir, { inMemory: true });
|
||||
db.init();
|
||||
store = new MockStore(tempRoot, db);
|
||||
chatStore = new ChatStore(fusionDir, db);
|
||||
const { createServer } = await import("../server.js");
|
||||
app = createServer(store as any, { chatStore });
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
db.close();
|
||||
await rm(tempRoot, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("create + fetch + update + delete room", async () => {
|
||||
const createRes = await request(app, "POST", "/api/chat/rooms", JSON.stringify({ name: "Engineering" }), {
|
||||
"content-type": "application/json",
|
||||
});
|
||||
expect(createRes.status).toBe(201);
|
||||
|
||||
const roomId = (createRes.body as any).room.id as string;
|
||||
|
||||
const getRes = await request(app, "GET", `/api/chat/rooms/${roomId}`);
|
||||
expect(getRes.status).toBe(200);
|
||||
|
||||
const patchRes = await request(
|
||||
app,
|
||||
"PATCH",
|
||||
`/api/chat/rooms/${roomId}`,
|
||||
JSON.stringify({ description: "Core team" }),
|
||||
{ "content-type": "application/json" },
|
||||
);
|
||||
expect(patchRes.status).toBe(200);
|
||||
expect((patchRes.body as any).room.description).toBe("Core team");
|
||||
|
||||
const delRes = await request(app, "DELETE", `/api/chat/rooms/${roomId}`);
|
||||
expect(delRes.status).toBe(200);
|
||||
expect((delRes.body as any).success).toBe(true);
|
||||
});
|
||||
|
||||
it("validates create and slug collision", async () => {
|
||||
const missingName = await request(app, "POST", "/api/chat/rooms", JSON.stringify({}), {
|
||||
"content-type": "application/json",
|
||||
});
|
||||
expect(missingName.status).toBe(400);
|
||||
|
||||
const first = await request(app, "POST", "/api/chat/rooms", JSON.stringify({ name: "Platform Team", projectId: "p1" }), {
|
||||
"content-type": "application/json",
|
||||
});
|
||||
expect(first.status).toBe(201);
|
||||
|
||||
const duplicate = await request(app, "POST", "/api/chat/rooms", JSON.stringify({ name: "platform-team", projectId: "p1" }), {
|
||||
"content-type": "application/json",
|
||||
});
|
||||
expect(duplicate.status).toBe(409);
|
||||
});
|
||||
|
||||
it("returns 404 for unknown room", async () => {
|
||||
const res = await request(app, "GET", "/api/chat/rooms/room-missing");
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
|
||||
it("handles room members add/delete", async () => {
|
||||
const createRes = await request(app, "POST", "/api/chat/rooms", JSON.stringify({ name: "Ops" }), {
|
||||
"content-type": "application/json",
|
||||
});
|
||||
const roomId = (createRes.body as any).room.id as string;
|
||||
|
||||
const addRes = await request(
|
||||
app,
|
||||
"POST",
|
||||
`/api/chat/rooms/${roomId}/members`,
|
||||
JSON.stringify({ agentId: "agent-1", role: "member" }),
|
||||
{ "content-type": "application/json" },
|
||||
);
|
||||
expect(addRes.status).toBe(201);
|
||||
|
||||
const addRes2 = await request(
|
||||
app,
|
||||
"POST",
|
||||
`/api/chat/rooms/${roomId}/members`,
|
||||
JSON.stringify({ agentId: "agent-1", role: "member" }),
|
||||
{ "content-type": "application/json" },
|
||||
);
|
||||
expect(addRes2.status).toBe(201);
|
||||
|
||||
const deleteRes = await request(app, "DELETE", `/api/chat/rooms/${roomId}/members/agent-1`);
|
||||
expect(deleteRes.status).toBe(200);
|
||||
|
||||
const deleteMissing = await request(app, "DELETE", `/api/chat/rooms/${roomId}/members/agent-1`);
|
||||
expect(deleteMissing.status).toBe(404);
|
||||
});
|
||||
|
||||
it("persists room message and validates sender/content", async () => {
|
||||
const createRoomRes = await request(app, "POST", "/api/chat/rooms", JSON.stringify({ name: "Product" }), {
|
||||
"content-type": "application/json",
|
||||
});
|
||||
const roomId = (createRoomRes.body as any).room.id as string;
|
||||
|
||||
const beforeCount = chatStore.getRoomMessages(roomId).length;
|
||||
|
||||
const postRes = await request(
|
||||
app,
|
||||
"POST",
|
||||
`/api/chat/rooms/${roomId}/messages`,
|
||||
JSON.stringify({ content: " hello world " }),
|
||||
{ "content-type": "application/json" },
|
||||
);
|
||||
expect(postRes.status).toBe(201);
|
||||
|
||||
const messageId = (postRes.body as any).message.id as string;
|
||||
const persisted = chatStore.getRoomMessage(messageId);
|
||||
expect(persisted?.content).toBe("hello world");
|
||||
|
||||
const afterCount = chatStore.getRoomMessages(roomId).length;
|
||||
expect(afterCount).toBe(beforeCount + 1);
|
||||
|
||||
const invalidSender = await request(
|
||||
app,
|
||||
"POST",
|
||||
`/api/chat/rooms/${roomId}/messages`,
|
||||
JSON.stringify({ content: "x", senderAgentId: "agent-1" }),
|
||||
{ "content-type": "application/json" },
|
||||
);
|
||||
expect(invalidSender.status).toBe(400);
|
||||
|
||||
const emptyContent = await request(
|
||||
app,
|
||||
"POST",
|
||||
`/api/chat/rooms/${roomId}/messages`,
|
||||
JSON.stringify({ content: " " }),
|
||||
{ "content-type": "application/json" },
|
||||
);
|
||||
expect(emptyContent.status).toBe(400);
|
||||
});
|
||||
|
||||
it("deletes messages and supports pagination", async () => {
|
||||
const room = chatStore.createRoom({ name: "QA" });
|
||||
const m1 = chatStore.addRoomMessage(room.id, { role: "user", content: "one" });
|
||||
const m2 = chatStore.addRoomMessage(room.id, { role: "user", content: "two" });
|
||||
const m3 = chatStore.addRoomMessage(room.id, { role: "user", content: "three" });
|
||||
|
||||
const page = await request(app, "GET", `/api/chat/rooms/${room.id}/messages?limit=2&offset=1`);
|
||||
expect(page.status).toBe(200);
|
||||
expect((page.body as any).messages.map((m: any) => m.id)).toEqual([m2.id, m3.id]);
|
||||
|
||||
const del1 = await request(app, "DELETE", `/api/chat/rooms/${room.id}/messages/${m1.id}`);
|
||||
expect(del1.status).toBe(200);
|
||||
|
||||
const del2 = await request(app, "DELETE", `/api/chat/rooms/${room.id}/messages/${m1.id}`);
|
||||
expect(del2.status).toBe(404);
|
||||
});
|
||||
|
||||
it("handles message attachments route", async () => {
|
||||
const room = chatStore.createRoom({ name: "Files" });
|
||||
const message = chatStore.addRoomMessage(room.id, { role: "user", content: "hello" });
|
||||
|
||||
const badPayload = await request(
|
||||
app,
|
||||
"POST",
|
||||
`/api/chat/rooms/${room.id}/messages/${message.id}/attachments`,
|
||||
JSON.stringify("invalid"),
|
||||
{ "content-type": "application/json" },
|
||||
);
|
||||
expect(badPayload.status).toBe(400);
|
||||
|
||||
const addAttachment = await request(
|
||||
app,
|
||||
"POST",
|
||||
`/api/chat/rooms/${room.id}/messages/${message.id}/attachments`,
|
||||
JSON.stringify({
|
||||
id: "att-1",
|
||||
filename: "a.txt",
|
||||
originalName: "a.txt",
|
||||
mimeType: "text/plain",
|
||||
size: 1,
|
||||
createdAt: new Date().toISOString(),
|
||||
}),
|
||||
{ "content-type": "application/json" },
|
||||
);
|
||||
expect(addAttachment.status).toBe(200);
|
||||
expect((addAttachment.body as any).message.attachments).toHaveLength(1);
|
||||
|
||||
const missingMessage = await request(
|
||||
app,
|
||||
"POST",
|
||||
`/api/chat/rooms/${room.id}/messages/missing/attachments`,
|
||||
JSON.stringify({
|
||||
id: "att-2",
|
||||
filename: "b.txt",
|
||||
originalName: "b.txt",
|
||||
mimeType: "text/plain",
|
||||
size: 1,
|
||||
createdAt: new Date().toISOString(),
|
||||
}),
|
||||
{ "content-type": "application/json" },
|
||||
);
|
||||
expect(missingMessage.status).toBe(404);
|
||||
});
|
||||
|
||||
it("rate-limits GET /chat/rooms", async () => {
|
||||
let status = 200;
|
||||
for (let i = 0; i < 1020; i++) {
|
||||
const res = await request(app, "GET", "/api/chat/rooms");
|
||||
status = res.status;
|
||||
if (status === 429) break;
|
||||
}
|
||||
expect(status).toBe(429);
|
||||
});
|
||||
});
|
||||
136
packages/dashboard/src/__tests__/sse-chat-rooms.test.ts
Normal file
136
packages/dashboard/src/__tests__/sse-chat-rooms.test.ts
Normal file
@@ -0,0 +1,136 @@
|
||||
import { EventEmitter } from "node:events";
|
||||
import { mkdtempSync } from "node:fs";
|
||||
import { rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { Request, Response } from "express";
|
||||
import { ChatStore, Database } from "@fusion/core";
|
||||
import type { TaskStore } from "@fusion/core";
|
||||
import { createSSE } from "../sse.js";
|
||||
|
||||
class MockSocket extends EventEmitter {
|
||||
destroyed = false;
|
||||
setKeepAlive = vi.fn();
|
||||
destroy = vi.fn(() => {
|
||||
if (this.destroyed) return;
|
||||
this.destroyed = true;
|
||||
this.emit("close");
|
||||
});
|
||||
}
|
||||
|
||||
class MockResponse extends EventEmitter {
|
||||
headers = new Map<string, string>();
|
||||
writableEnded = false;
|
||||
destroyed = false;
|
||||
write = vi.fn();
|
||||
flushHeaders = vi.fn();
|
||||
end = vi.fn(() => {
|
||||
if (this.writableEnded) return;
|
||||
this.writableEnded = true;
|
||||
this.emit("close");
|
||||
});
|
||||
|
||||
constructor(readonly socket: MockSocket) {
|
||||
super();
|
||||
}
|
||||
|
||||
setHeader(name: string, value: string): void {
|
||||
this.headers.set(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
function createMockStore(): TaskStore {
|
||||
const researchStore = {
|
||||
on: vi.fn(),
|
||||
off: vi.fn(),
|
||||
};
|
||||
return {
|
||||
on: vi.fn(),
|
||||
off: vi.fn(),
|
||||
getResearchStore: vi.fn(() => researchStore),
|
||||
} as unknown as TaskStore;
|
||||
}
|
||||
|
||||
function openSseConnection(chatStore: ChatStore) {
|
||||
const store = createMockStore();
|
||||
const socket = new MockSocket();
|
||||
const req = new EventEmitter() as Request & { query: Record<string, string>; socket: MockSocket };
|
||||
req.query = { clientId: "chat-room-events" };
|
||||
req.socket = socket;
|
||||
const res = new MockResponse(socket);
|
||||
|
||||
createSSE(store, undefined, undefined, undefined, undefined, undefined, undefined, chatStore)(
|
||||
req,
|
||||
res as unknown as Response,
|
||||
);
|
||||
|
||||
return { req, res };
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
describe("chat room SSE events", () => {
|
||||
it("relays room lifecycle/member/message events and cleans up listeners", async () => {
|
||||
const tempRoot = mkdtempSync(join(tmpdir(), "fusion-sse-chat-room-"));
|
||||
const fusionDir = join(tempRoot, ".fusion");
|
||||
const db = new Database(fusionDir, { inMemory: true });
|
||||
db.init();
|
||||
const chatStore = new ChatStore(fusionDir, db);
|
||||
const { req, res } = openSseConnection(chatStore);
|
||||
|
||||
const room = chatStore.createRoom({
|
||||
name: "engineering",
|
||||
projectId: "proj-1",
|
||||
createdBy: "agent-owner",
|
||||
memberAgentIds: ["agent-owner"],
|
||||
});
|
||||
const member = chatStore.addRoomMember(room.id, "agent-2", "member");
|
||||
const message = chatStore.addRoomMessage(room.id, {
|
||||
role: "user",
|
||||
content: "hello room",
|
||||
senderAgentId: null,
|
||||
mentions: [],
|
||||
});
|
||||
const updatedRoom = chatStore.updateRoom(room.id, { description: "updated" });
|
||||
expect(updatedRoom).toBeDefined();
|
||||
chatStore.removeRoomMember(room.id, "agent-2");
|
||||
const attachmentUpdatedMessage = chatStore.addRoomMessageAttachment(room.id, message.id, {
|
||||
id: "att-1",
|
||||
filename: "doc.txt",
|
||||
originalName: "doc.txt",
|
||||
mimeType: "text/plain",
|
||||
size: 3,
|
||||
createdAt: new Date().toISOString(),
|
||||
});
|
||||
chatStore.deleteRoomMessage(message.id);
|
||||
chatStore.deleteRoom(room.id);
|
||||
|
||||
expect(res.write).toHaveBeenCalledWith(`event: chat:room:created\ndata: ${JSON.stringify(room)}\n\n`);
|
||||
expect(res.write).toHaveBeenCalledWith(`event: chat:room:member:added\ndata: ${JSON.stringify(member)}\n\n`);
|
||||
expect(res.write).toHaveBeenCalledWith(`event: chat:room:message:added\ndata: ${JSON.stringify(message)}\n\n`);
|
||||
expect(res.write).toHaveBeenCalledWith(`event: chat:room:updated\ndata: ${JSON.stringify(updatedRoom)}\n\n`);
|
||||
expect(res.write).toHaveBeenCalledWith(
|
||||
`event: chat:room:member:removed\ndata: ${JSON.stringify({ roomId: room.id, agentId: "agent-2" })}\n\n`,
|
||||
);
|
||||
expect(res.write).toHaveBeenCalledWith(`event: chat:room:message:updated\ndata: ${JSON.stringify(attachmentUpdatedMessage)}\n\n`);
|
||||
expect(res.write).toHaveBeenCalledWith(`event: chat:room:message:deleted\ndata: ${JSON.stringify({ id: message.id })}\n\n`);
|
||||
expect(res.write).toHaveBeenCalledWith(`event: chat:room:deleted\ndata: ${JSON.stringify({ id: room.id })}\n\n`);
|
||||
|
||||
req.emit("close");
|
||||
|
||||
expect(EventEmitter.listenerCount(chatStore, "chat:room:created")).toBe(0);
|
||||
expect(EventEmitter.listenerCount(chatStore, "chat:room:updated")).toBe(0);
|
||||
expect(EventEmitter.listenerCount(chatStore, "chat:room:deleted")).toBe(0);
|
||||
expect(EventEmitter.listenerCount(chatStore, "chat:room:member:added")).toBe(0);
|
||||
expect(EventEmitter.listenerCount(chatStore, "chat:room:member:removed")).toBe(0);
|
||||
expect(EventEmitter.listenerCount(chatStore, "chat:room:message:added")).toBe(0);
|
||||
expect(EventEmitter.listenerCount(chatStore, "chat:room:message:updated")).toBe(0);
|
||||
expect(EventEmitter.listenerCount(chatStore, "chat:room:message:deleted")).toBe(0);
|
||||
|
||||
db.close();
|
||||
await rm(tempRoot, { recursive: true, force: true });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user