feat(#37-41): Add domains, ideas, relationships, agents, widgets schema

Schema additions for issues #37-41:

New models:
- Domain (#37): Life domains (work, marriage, homelab, etc.)
- Idea (#38): Brain dumps with pgvector embeddings
- Relationship (#39): Generic entity linking (blocks, depends_on)
- Agent (#40): ClawdBot agent tracking with metrics
- AgentSession (#40): Conversation session tracking
- WidgetDefinition (#41): HUD widget registry
- UserLayout (#41): Per-user dashboard configuration

Updated models:
- Task, Event, Project: Added domainId foreign key
- User, Workspace: Added new relations

New enums:
- IdeaStatus: CAPTURED, PROCESSING, ACTIONABLE, ARCHIVED, DISCARDED
- RelationshipType: BLOCKS, BLOCKED_BY, DEPENDS_ON, etc.
- AgentStatus: IDLE, WORKING, WAITING, ERROR, TERMINATED
- EntityType: Added IDEA, DOMAIN

Migration: 20260129182803_add_domains_ideas_agents_widgets
This commit is contained in:
Jason Woltje
2026-01-29 12:29:21 -06:00
parent a220c2dc0a
commit 973502f26e
308 changed files with 18374 additions and 113 deletions

View File

@@ -0,0 +1,45 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { LoginButton } from "./LoginButton";
// Mock window.location
const mockLocation = {
href: "",
assign: vi.fn(),
};
Object.defineProperty(window, "location", {
value: mockLocation,
writable: true,
});
describe("LoginButton", () => {
beforeEach(() => {
mockLocation.href = "";
mockLocation.assign.mockClear();
});
it("should render sign in button", () => {
render(<LoginButton />);
const button = screen.getByRole("button", { name: /sign in/i });
expect(button).toBeInTheDocument();
});
it("should redirect to OIDC endpoint on click", async () => {
const user = userEvent.setup();
render(<LoginButton />);
const button = screen.getByRole("button", { name: /sign in/i });
await user.click(button);
expect(mockLocation.assign).toHaveBeenCalledWith(
"http://localhost:3001/auth/callback/authentik"
);
});
it("should have proper styling", () => {
render(<LoginButton />);
const button = screen.getByRole("button", { name: /sign in/i });
expect(button).toHaveClass("w-full");
});
});

View File

@@ -0,0 +1,19 @@
"use client";
import { Button } from "@mosaic/ui";
const API_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3001";
export function LoginButton() {
const handleLogin = () => {
// Redirect to the backend OIDC authentication endpoint
// BetterAuth will handle the OIDC flow and redirect back to the callback
window.location.assign(`${API_URL}/auth/callback/authentik`);
};
return (
<Button variant="primary" onClick={handleLogin} className="w-full">
Sign In with Authentik
</Button>
);
}

View File

@@ -0,0 +1,83 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { LogoutButton } from "./LogoutButton";
// Mock next/navigation
const mockPush = vi.fn();
vi.mock("next/navigation", () => ({
useRouter: () => ({
push: mockPush,
}),
}));
// Mock auth context
const mockSignOut = vi.fn();
vi.mock("@/lib/auth/auth-context", () => ({
useAuth: () => ({
signOut: mockSignOut,
}),
}));
describe("LogoutButton", () => {
beforeEach(() => {
mockPush.mockClear();
mockSignOut.mockClear();
});
it("should render sign out button", () => {
render(<LogoutButton />);
const button = screen.getByRole("button", { name: /sign out/i });
expect(button).toBeInTheDocument();
});
it("should call signOut and redirect on click", async () => {
const user = userEvent.setup();
mockSignOut.mockResolvedValue(undefined);
render(<LogoutButton />);
const button = screen.getByRole("button", { name: /sign out/i });
await user.click(button);
await waitFor(() => {
expect(mockSignOut).toHaveBeenCalled();
expect(mockPush).toHaveBeenCalledWith("/login");
});
});
it("should redirect to login even if signOut fails", async () => {
const user = userEvent.setup();
mockSignOut.mockRejectedValue(new Error("Sign out failed"));
// Suppress console.error for this test
const consoleErrorSpy = vi
.spyOn(console, "error")
.mockImplementation(() => {});
render(<LogoutButton />);
const button = screen.getByRole("button", { name: /sign out/i });
await user.click(button);
await waitFor(() => {
expect(mockSignOut).toHaveBeenCalled();
expect(mockPush).toHaveBeenCalledWith("/login");
});
consoleErrorSpy.mockRestore();
});
it("should have secondary variant by default", () => {
render(<LogoutButton />);
const button = screen.getByRole("button", { name: /sign out/i });
// The Button component from @mosaic/ui should apply the variant
expect(button).toBeInTheDocument();
});
it("should accept custom variant prop", () => {
render(<LogoutButton variant="primary" />);
const button = screen.getByRole("button", { name: /sign out/i });
expect(button).toBeInTheDocument();
});
});

View File

@@ -0,0 +1,31 @@
"use client";
import { useRouter } from "next/navigation";
import { Button, type ButtonProps } from "@mosaic/ui";
import { useAuth } from "@/lib/auth/auth-context";
interface LogoutButtonProps {
variant?: ButtonProps["variant"];
className?: string;
}
export function LogoutButton({ variant = "secondary", className }: LogoutButtonProps) {
const router = useRouter();
const { signOut } = useAuth();
const handleSignOut = async () => {
try {
await signOut();
} catch (error) {
console.error("Sign out error:", error);
} finally {
router.push("/login");
}
};
return (
<Button variant={variant} onClick={handleSignOut} className={className}>
Sign Out
</Button>
);
}