Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ npm run typecheck

### Browser E2E tests

Browser tests live in `playwright/`, separate from the existing Vitest/JSDOM tests under `test/`. The Playwright setup runs one Chromium smoke test against the real local Node server and uses a synthetic signed-out session response; it does not sign in to GitHub or call a real LLM provider.
Browser tests live in `playwright/`, separate from the existing Vitest/JSDOM tests under `test/`. The Playwright suite runs Chromium against the real local Node server. It covers the signed-out landing page, a synthetic GitHub OAuth callback and session, dashboard KPIs/time range/recent jobs, job search/status/pagination, job progress/findings/diffs, repository toggles/model settings, stats charts, and theme persistence. Dashboard API data is mocked in the browser so these flows do not depend on real GitHub or LLM provider credentials.

Requirements: Node.js 24+, Docker, and disposable local PostgreSQL and Redis services.

Expand All @@ -126,7 +126,7 @@ npm run test:e2e
docker rm -f codra-e2e-postgres codra-e2e-redis 2>/dev/null || true
```

`npm run test:e2e` builds the Node server and dashboard, then Playwright starts the Node server on `http://localhost:3000` automatically. The launcher reads `.env.e2e`, generates a throwaway GitHub App private key for server initialization, disables the background review worker and telemetry, and never needs real GitHub, OAuth, or LLM credentials. The smoke test stubs only `GET /api/auth/session` as signed out. No database migration or seeded application data is needed for this first smoke test; keep `DATABASE_URL` pointed at the disposable database above.
`npm run test:e2e` builds the Node server and dashboard, then Playwright starts the Node server on `http://localhost:3000` automatically. The launcher reads `.env.e2e`, generates a throwaway GitHub App private key for server initialization, disables the background review worker and telemetry, and enables a synthetic identity provider only when the launcher sets `CODRA_E2E_AUTH_ENABLED=true` and the Node server is running with `NODE_ENV=test` and `ENVIRONMENT=test`. The OAuth state validation, callback handler, session store, and protected page routes remain real; no GitHub credentials are used. Browser API fixtures provide deterministic jobs, repositories, model configuration, stats, and diff responses. Keep `DATABASE_URL` and `REDIS_URL` pointed at the disposable services above; Redis is used for the OAuth state and session store, while the callback's account-settings write is best-effort.

The browser output is written to `test-results/` and `playwright-report/`; both are gitignored. To inspect the HTML report after a run, use `npx playwright show-report`.

Expand All @@ -137,6 +137,7 @@ The browser output is written to `test-results/` and `playwright-report/`; both
All documentation content for [codra.run/docs](https://codra.run/docs) lives in `docs/*.mdx` in this repository. Even though the website repo is private, **all documentation is 100% open source** and deploys automatically when PRs are merged into `main`.

### MDX Guidelines

- **Files & Routes**: Each file in `docs/*.mdx` maps directly to a route (e.g. `docs/docker.mdx` -> `codra.run/docs/docker`).
- **Headings with IDs**: Use explicit HTML `<h2 id="section-id">Heading</h2>` for major sections to ensure working anchor links and sidebar navigation. Use standard markdown `###` for subheadings.
- **Callouts**: Use `<Note type="info">`, `<Note type="tip">`, or `<Note type="warn">` (standard blockquotes `> ` also render as info callouts).
Expand Down
47 changes: 47 additions & 0 deletions apps/node/src/e2e-identity-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type {
DashboardSessionUser,
IdentityProvider,
} from "@codraoss/core/ports";

/**
* Synthetic identity provider used only by the disposable Playwright server.
* It exercises the real OAuth state/callback/session path without contacting
* GitHub or requiring user credentials.
*/
export class E2EIdentityProvider implements IdentityProvider {
private readonly identity: DashboardSessionUser = {
provider: "github",
providerUserId: "90000001",
login: "codra-e2e",
name: "Codra E2E User",
avatarUrl: null,
email: "[email protected]",
signedInAt: "2026-01-01T00:00:00.000Z",
metadata: {
githubUserId: 90000001,
githubUsername: "codra-e2e",
},
};

async beginAuthorization(
redirectUri: string,
state: string,
): Promise<{ url: string }> {
const url = new URL("https://codra-e2e.invalid/authorize");
url.searchParams.set("redirect_uri", redirectUri);
url.searchParams.set("state", state);
return { url: url.toString() };
}

async completeAuthorization(
code: string,
state: string,
expectedState: string,
): Promise<{ identity: DashboardSessionUser }> {
if (code !== "codra-e2e-code" || state !== expectedState) {
throw new Error("Invalid synthetic E2E authorization callback.");
}

return { identity: { ...this.identity } };
}
}
52 changes: 40 additions & 12 deletions apps/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ const stubs = {
};

const env: NodeAppBindings = createNodeEnv(stubs);
// This switch is set only by scripts/start-e2e-server.mjs for the disposable
// E2E environment. Never enable the synthetic identity provider in production.
if (
process.env.CODRA_E2E_AUTH_ENABLED === "true" &&
process.env.NODE_ENV === "test" &&
env.ENVIRONMENT === "test"
) {
const { E2EIdentityProvider } = await import("./e2e-identity-provider");
env.IDENTITY_PROVIDER = new E2EIdentityProvider();
}
env.REVIEW_ORCHESTRATOR = new NodeOrchestrator(
createReviewRuntime(env),
stubs.REVIEW_QUEUE,
Expand Down Expand Up @@ -141,17 +151,29 @@ if (process.env.START_API !== "false") {
}

// Model registry refresh in background (zero DB impact, unreferenced interval)
import("@codraoss/models").then(({ ModelRegistryService }) => {
const service = ModelRegistryService.getInstance();
service.refreshFromRemote().catch(() => {});
const timer = setInterval(() => service.refreshFromRemote().catch(() => {}), 60 * 60 * 1000);
(timer as unknown as { unref?: () => void }).unref?.();
}).catch(() => {});

const withTimeout = async <T>(promise: Promise<T>, timeoutMs: number, label: string): Promise<T> => {
import("@codraoss/models")
.then(({ ModelRegistryService }) => {
const service = ModelRegistryService.getInstance();
service.refreshFromRemote().catch(() => {});
const timer = setInterval(
() => service.refreshFromRemote().catch(() => {}),
60 * 60 * 1000,
);
(timer as unknown as { unref?: () => void }).unref?.();
})
.catch(() => {});

const withTimeout = async <T>(
promise: Promise<T>,
timeoutMs: number,
label: string,
): Promise<T> => {
let timer: NodeJS.Timeout | undefined;
const timeoutPromise = new Promise<never>((_, reject) => {
timer = setTimeout(() => reject(new Error(`${label} timed out after ${timeoutMs}ms`)), timeoutMs);
timer = setTimeout(
() => reject(new Error(`${label} timed out after ${timeoutMs}ms`)),
timeoutMs,
);
timer.unref?.();
});
try {
Expand All @@ -176,7 +198,9 @@ const shutdown = async (signal?: string) => {
shutdownStartTime = now;

const globalShutdownTimeout = setTimeout(() => {
logger.error("Global shutdown timed out after 10000ms. Forcing immediate exit.");
logger.error(
"Global shutdown timed out after 10000ms. Forcing immediate exit.",
);
process.exit(1);
}, 10000);
globalShutdownTimeout.unref?.();
Expand All @@ -201,12 +225,16 @@ const shutdown = async (signal?: string) => {
};

const drainTimer = setTimeout(() => {
(server as unknown as { closeAllConnections?: () => void })?.closeAllConnections?.();
(
server as unknown as { closeAllConnections?: () => void }
)?.closeAllConnections?.();
}, 3000);
drainTimer.unref?.();

const hardTimer = setTimeout(() => {
finish(new Error("HTTP server listener close timed out after 5000ms"));
finish(
new Error("HTTP server listener close timed out after 5000ms"),
);
}, 5000);
hardTimer.unref?.();

Expand Down
Loading