Add structured chat delivery records
This commit is contained in:
1 parent
a27658b56f
commit
18e0c6338e
10 files changed
+133
-8
No files matched your search
@@ -12,6 +12,72 @@ function createConnection(): DatabaseConnection {
|
||||
}
|
||||
|
||||
describe("chat governance", () => {
|
||||
test("persists memberships, retention policy, and structured delivery metadata", () => {
|
||||
const connection = createConnection();
|
||||
const organization = new OrganizationService(connection.db);
|
||||
const chat = new ChatService(connection.db);
|
||||
const snapshot = new SnapshotService(connection.db);
|
||||
let orgId = "";
|
||||
let employeeId = "";
|
||||
let agentId = "";
|
||||
let spaceId = "";
|
||||
|
||||
connection.transaction(() => {
|
||||
orgId = organization.createOrganization({
|
||||
organizationName: "Acme Operations",
|
||||
employeeName: "Dana Lee",
|
||||
mission: "Coordinate agents with auditable approvals.",
|
||||
goal: "Ship a verified control plane.",
|
||||
});
|
||||
employeeId = (connection.db.prepare("select id from employees where org_id = ?").get(orgId) as { id: string }).id;
|
||||
agentId = organization.createAgent({
|
||||
orgId,
|
||||
name: "Ada Lovelace",
|
||||
role: "Release reviewer",
|
||||
department: "Engineering",
|
||||
modelProviderId: null,
|
||||
modelId: null,
|
||||
budgetCents: 10000,
|
||||
managerAgentId: null,
|
||||
});
|
||||
spaceId = chat.createSpace({
|
||||
orgId,
|
||||
spaceType: "project",
|
||||
name: "release-review",
|
||||
topic: "Release review",
|
||||
visibility: "restricted",
|
||||
memberEmployeeIds: [employeeId],
|
||||
memberAgentIds: [agentId],
|
||||
});
|
||||
chat.sendMessage({
|
||||
orgId,
|
||||
spaceId,
|
||||
threadId: null,
|
||||
senderType: "employee",
|
||||
senderId: employeeId,
|
||||
bodyMd: "/escalate review @Ada-Lovelace release gate",
|
||||
attachmentFileIds: [],
|
||||
});
|
||||
});
|
||||
|
||||
const state = snapshot.load();
|
||||
const message = state.chatMessages[0];
|
||||
const structure = JSON.parse(message!.bodyStructuredJson) as {
|
||||
slashInvocation: { command: string };
|
||||
mentions: Array<{ targetType: string; targetId: string }>;
|
||||
};
|
||||
expect(state.chatSpaces.find((space) => space.id === spaceId)?.retentionPolicy).toBe("restricted_365d");
|
||||
expect(state.chatMemberships
|
||||
.filter((membership) => membership.spaceId === spaceId)
|
||||
.map((membership) => `${membership.principalType}:${membership.principalId}`)
|
||||
.sort())
|
||||
.toEqual([`agent:${agentId}`, `employee:${employeeId}`]);
|
||||
expect(message).toMatchObject({ deliveryState: "sent" });
|
||||
expect(structure.slashInvocation.command).toBe("escalate");
|
||||
expect(structure.mentions[0]).toMatchObject({ targetType: "agent", targetId: agentId });
|
||||
connection.close();
|
||||
});
|
||||
|
||||
test("records board interventions and enforces thread control", () => {
|
||||
const connection = createConnection();
|
||||
const organization = new OrganizationService(connection.db);
|
||||
|
||||
@@ -23,7 +23,7 @@ describe("domain services", () => {
|
||||
const connection = createConnection();
|
||||
|
||||
const rows = connection.db.prepare("select version from schema_migrations order by version asc").all() as Array<{ version: number }>;
|
||||
expect(rows.map((row) => row.version)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]);
|
||||
expect(rows.map((row) => row.version)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]);
|
||||
connection.close();
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user