* feat: replace manual oauth with better-auth * fix: lint * chore: refactor accounts to unify github + vercel * feat: enhance auth config with host allowlisting Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * fix: add newline at end of manifest.json Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * fix: update betterAuth database schema mappings Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * fix: sanitize redirects and preserve destination in github flow Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * feat: enhance GitHub app callback with installation sync tracking Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * build: add BETTER_AUTH_SECRET to turbo env Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * refactor: update sign-in callback to skip onboarding Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> --------- Co-authored-by: nicoalbanese <49612682+nicoalbanese@users.noreply.github.com> Co-authored-by: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com>
139 lines
4.1 KiB
TypeScript
139 lines
4.1 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
|
|
mock.module("server-only", () => ({}));
|
|
|
|
let sessionRecord: { userId: string } | null = null;
|
|
let chats: Array<{ id: string }> = [];
|
|
let userRecord: { name: string | null; username: string | null } | null = null;
|
|
let githubProfile: { username: string; externalUserId: string } | null = null;
|
|
|
|
const originalVercelUrl = process.env.VERCEL_URL;
|
|
const originalVercelEnv = process.env.VERCEL_ENV;
|
|
const originalProductionUrl =
|
|
process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL;
|
|
|
|
function restoreEnv() {
|
|
if (originalVercelUrl === undefined) {
|
|
delete process.env.VERCEL_URL;
|
|
} else {
|
|
process.env.VERCEL_URL = originalVercelUrl;
|
|
}
|
|
|
|
if (originalVercelEnv === undefined) {
|
|
delete process.env.VERCEL_ENV;
|
|
} else {
|
|
process.env.VERCEL_ENV = originalVercelEnv;
|
|
}
|
|
|
|
if (originalProductionUrl === undefined) {
|
|
delete process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL;
|
|
} else {
|
|
process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL =
|
|
originalProductionUrl;
|
|
}
|
|
}
|
|
|
|
mock.module("@/app/api/generate-pr/_lib/generate-pr-helpers", () => ({
|
|
getConversationContext: async () => "",
|
|
}));
|
|
|
|
mock.module("@/lib/db/sessions", () => ({
|
|
getSessionById: async () => sessionRecord,
|
|
getChatsBySessionId: async () => chats,
|
|
}));
|
|
|
|
mock.module("@/lib/github/token", () => ({
|
|
getGitHubUserProfile: async () => githubProfile,
|
|
}));
|
|
|
|
mock.module("@/lib/db/client", () => ({
|
|
db: {
|
|
query: {
|
|
users: {
|
|
findFirst: async () => userRecord,
|
|
},
|
|
},
|
|
},
|
|
}));
|
|
|
|
const prContentModulePromise = import("./pr-content");
|
|
|
|
describe("pr-content", () => {
|
|
beforeEach(() => {
|
|
sessionRecord = null;
|
|
chats = [];
|
|
userRecord = null;
|
|
githubProfile = null;
|
|
restoreEnv();
|
|
});
|
|
|
|
afterEach(() => {
|
|
restoreEnv();
|
|
});
|
|
|
|
test("resolvePullRequestContextSection returns a single-line footer with chat link and attribution", async () => {
|
|
const { resolvePullRequestContextSection } = await prContentModulePromise;
|
|
|
|
sessionRecord = { userId: "user-1" };
|
|
chats = [{ id: "chat-2" }, { id: "chat-1" }];
|
|
userRecord = { name: "Nico Albanese", username: "nico" };
|
|
githubProfile = { username: "nicoalbanese10", externalUserId: "12345" };
|
|
|
|
const section = await resolvePullRequestContextSection({
|
|
sessionId: "session-1",
|
|
appBaseUrl: "https://openharness.dev",
|
|
});
|
|
|
|
expect(section).toBe(
|
|
"[Chat](https://openharness.dev/sessions/session-1/chats/chat-2) - Built with guidance from [Nico Albanese](https://github.com/nicoalbanese10)",
|
|
);
|
|
});
|
|
|
|
test("resolvePullRequestContextSection falls back to plain-text attribution when no GitHub account exists", async () => {
|
|
const { resolvePullRequestContextSection } = await prContentModulePromise;
|
|
|
|
sessionRecord = { userId: "user-1" };
|
|
userRecord = { name: null, username: "nico" };
|
|
|
|
const section = await resolvePullRequestContextSection({
|
|
sessionId: "session-1",
|
|
});
|
|
|
|
expect(section).toBe("Built with guidance from nico");
|
|
});
|
|
|
|
test("resolvePullRequestAppBaseUrl prefers the active deployment url", async () => {
|
|
const { resolvePullRequestAppBaseUrl } = await prContentModulePromise;
|
|
|
|
process.env.VERCEL_URL = "preview-openharness.vercel.app";
|
|
process.env.VERCEL_ENV = "preview";
|
|
process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL = "openharness.dev";
|
|
|
|
expect(resolvePullRequestAppBaseUrl()).toBe(
|
|
"https://preview-openharness.vercel.app",
|
|
);
|
|
|
|
delete process.env.VERCEL_URL;
|
|
process.env.VERCEL_ENV = "production";
|
|
|
|
expect(resolvePullRequestAppBaseUrl()).toBe("https://openharness.dev");
|
|
});
|
|
|
|
test("appendPullRequestContextSection appends the footer after a horizontal rule", async () => {
|
|
const { appendPullRequestContextSection } = await prContentModulePromise;
|
|
|
|
expect(
|
|
appendPullRequestContextSection(
|
|
"## Summary\n\nInitial body\n",
|
|
"[Chat](https://example.com) - Built with guidance from Nico",
|
|
),
|
|
).toBe(`## Summary
|
|
|
|
Initial body
|
|
|
|
---
|
|
|
|
[Chat](https://example.com) - Built with guidance from Nico`);
|
|
});
|
|
});
|