Skip to content
This repository was archived by the owner on Oct 22, 2026. It is now read-only.
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
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,47 @@ jobs:
working-directory: app
run: npm test

test-e2e:
name: Test (E2E Analyst brief)
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Set up Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: app/package-lock.json

- name: Install dependencies
working-directory: app
run: npm ci

- name: Install Playwright Chromium
working-directory: app
run: npx playwright install chromium --with-deps

- name: Set up uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
python-version: "3.12"

- name: Install Python dependencies (stub generator)
run: uv sync --all-extras --group dev

- name: Generate E2E causal stub fixture
run: uv run python scripts/gen_e2e_causal_stub.py

- name: Run Playwright E2E (Tier 1 + causal stub)
working-directory: app
run: npm run test:e2e
env:
CI: "true"

lint:
name: Lint & type check
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
node_modules/
dist/
.vite/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
*.tsbuildinfo
# Override root .gitignore which ignores lib/ (Python build artifact rule)
!src/lib/
33 changes: 33 additions & 0 deletions app/e2e/analyst-brief-preview.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { test, expect } from "@playwright/test";
import {
MOCK_BRIEF,
collectBinderErrors,
mockLocalLlm,
openFixtureVessel,
seedRegionStorage,
useFixtureData,
} from "./helpers";

test.describe("Analyst brief — production opt-in (Tier 3 mock)", () => {
test.beforeEach(async ({ page }) => {
await seedRegionStorage(page);
await useFixtureData(page);
await mockLocalLlm(page);
});

test("Use local LLM enables brief on preview build", async ({ page }) => {
const binderErrors = collectBinderErrors(page);
await page.goto("/");
await openFixtureVessel(page);

const optIn = page.getByRole("button", { name: /Use local LLM/i });
if (await optIn.isVisible().catch(() => false)) {
await optIn.click();
}

await expect(page.getByText("Generating…")).toBeHidden({ timeout: 60_000 });
await expect(page.getByText(MOCK_BRIEF)).toBeVisible({ timeout: 60_000 });
await expect(page.getByText(/LLM offline|not configured/i)).toHaveCount(0);
expect(binderErrors).toEqual([]);
});
});
35 changes: 35 additions & 0 deletions app/e2e/analyst-brief.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { test, expect } from "@playwright/test";
import {
MOCK_BRIEF,
collectBinderErrors,
mockLocalLlm,
openFixtureVessel,
seedRegionStorage,
useFixtureData,
} from "./helpers";

test.describe("Analyst brief — local LLM (Tier 1 mock)", () => {
test.beforeEach(async ({ page }) => {
await seedRegionStorage(page);
await useFixtureData(page);
await mockLocalLlm(page);
});

test("Regenerate shows brief without offline state (dev → localhost:8443)", async ({
page,
}) => {
const binderErrors = collectBinderErrors(page);
await page.goto("/");
await openFixtureVessel(page);

await expect(page.getByText("Generating…")).toBeHidden({ timeout: 60_000 });
await expect(page.getByText(MOCK_BRIEF)).toBeVisible({ timeout: 60_000 });
await expect(page.getByText(/LLM offline|not configured/i)).toHaveCount(0);

await page.getByRole("button", { name: "Regenerate" }).click();
await expect(page.getByText("Generating…")).toBeVisible();
await expect(page.getByText(MOCK_BRIEF)).toBeVisible({ timeout: 60_000 });

expect(binderErrors).toEqual([]);
});
});
26 changes: 26 additions & 0 deletions app/e2e/causal-stub.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { test, expect } from "@playwright/test";
import {
collectBinderErrors,
mockLocalLlm,
openFixtureVessel,
seedRegionStorage,
useFixtureData,
} from "./helpers";

test.describe("causal_effects regime-only stub (#588 regression)", () => {
test.beforeEach(async ({ page }) => {
await seedRegionStorage(page);
await useFixtureData(page, "e2e_ducklake_manifest.json");
await mockLocalLlm(page);
});

test("no DuckDB Binder Error for mmsi on regime-only causal parquet", async ({
page,
}) => {
const binderErrors = collectBinderErrors(page);
await page.goto("/");
await openFixtureVessel(page);
await page.waitForTimeout(2_000);
expect(binderErrors).toEqual([]);
});
});
128 changes: 128 additions & 0 deletions app/e2e/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import type { Page } from "@playwright/test";

export const LOCAL_LLM_CHAT = "https://localhost:8443/v1/chat/completions";
export const MOCK_BRIEF =
"Mock patrol brief for E2E. Vessel confidence and AIS gaps warrant analyst review in the Singapore Strait corridor.";

/** Fixture watchlist row with confidence above default filter (0.4). */
export const FIXTURE_MMSI = "226855092";
export const FIXTURE_VESSEL_LABEL = "HYDRA 1";

/** Force bundled fixtures (ignore live R2 and stale OPFS from prior local dev). */
export async function useFixtureData(page: Page, manifest = "ducklake_manifest.json"): Promise<void> {
const manifestPath = `public/fixtures/${manifest}`;

await page.route(/arktrace-public\.edgesentry\.io/i, (route) => route.abort());

await page.route(/ducklake_manifest\.json/i, async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
path: manifestPath,
});
});

await page.route(/\.parquet/i, async (route) => {
const url = route.request().url();
if (url.includes("/fixtures/")) return route.continue();
return route.abort();
});
}

export function seedRegionStorage(page: Page): Promise<void> {
return page.addInitScript(async () => {
localStorage.setItem("arktrace.regions", JSON.stringify(["singapore"]));
localStorage.removeItem("arktrace:useLocalLlm");
// Fresh OPFS so E2E uses fixture manifest, not a prior R2 sync on localhost.
try {
const root = await navigator.storage.getDirectory();
for await (const [name] of root.entries()) {
await root.removeEntry(name, { recursive: true });
}
} catch {
/* OPFS unavailable */
}
if ("serviceWorker" in navigator) {
const regs = await navigator.serviceWorker.getRegistrations();
await Promise.all(regs.map((r) => r.unregister()));
}
});
}

/** Mock local LLM (Caddy :8443) with CORS headers for cross-origin SPA. */
export async function mockLocalLlm(page: Page, brief = MOCK_BRIEF): Promise<void> {
const cors = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
};

await page.route(LOCAL_LLM_CHAT, async (route) => {
if (route.request().method() === "OPTIONS") {
await route.fulfill({ status: 204, headers: cors });
return;
}
await route.fulfill({
status: 200,
headers: { ...cors, "Content-Type": "application/json" },
body: JSON.stringify({
choices: [{ message: { content: brief } }],
}),
});
});

await page.route("https://localhost:8443/v1/models", async (route) => {
if (route.request().method() === "OPTIONS") {
await route.fulfill({ status: 204, headers: cors });
return;
}
await route.fulfill({
status: 200,
headers: { ...cors, "Content-Type": "application/json" },
body: JSON.stringify({ data: [{ id: "mock" }] }),
});
});
}

export function collectBinderErrors(page: Page): string[] {
const errors: string[] = [];
page.on("console", (msg) => {
if (msg.type() !== "error") return;
const text = msg.text();
if (text.includes("Binder Error") && text.includes("mmsi")) {
errors.push(text);
}
});
return errors;
}

export async function waitForWatchlistReady(page: Page): Promise<void> {
await page.evaluate(async () => {
try {
const root = await navigator.storage.getDirectory();
for await (const [name] of root.entries()) {
await root.removeEntry(name, { recursive: true });
}
} catch {
/* ignore */
}
});

const resync = page.getByRole("button", { name: "Re-sync" });
const syncR2 = page.getByRole("button", { name: "Sync from R2" });
if (await resync.isVisible().catch(() => false)) {
await resync.click();
} else if (await syncR2.isVisible().catch(() => false)) {
await syncR2.click();
}

await page.getByText(/files loaded/i).waitFor({ timeout: 90_000 });
await page.getByPlaceholder(/Search name/i).fill(FIXTURE_MMSI);
await page.getByText(FIXTURE_VESSEL_LABEL).first().waitFor({ timeout: 30_000 });
}

export async function openFixtureVessel(page: Page): Promise<void> {
await waitForWatchlistReady(page);
await page.getByText(FIXTURE_VESSEL_LABEL).first().click();
await page.getByText("Analyst brief").waitFor({ timeout: 30_000 });
}
64 changes: 64 additions & 0 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
"lint": "tsc --noEmit && eslint src/",
"test": "vitest run",
"test:watch": "vitest",
"coverage": "vitest run --coverage"
"coverage": "vitest run --coverage",
"dev:e2e": "VITE_MANIFEST_URL=http://127.0.0.1:5173/fixtures/ducklake_manifest.json vite --host 127.0.0.1 --port 5173",
"preview:e2e": "vite preview --host 127.0.0.1 --port 4173",
"build:e2e": "VITE_MANIFEST_URL=http://127.0.0.1:4173/fixtures/ducklake_manifest.json npm run build",
"test:e2e": "playwright test",
"test:e2e:preview": "playwright test -c playwright.preview.config.ts",
"test:e2e:install": "playwright install chromium --with-deps"
},
"dependencies": {
"@duckdb/duckdb-wasm": "^1.29.0",
Expand All @@ -26,6 +32,7 @@
},
"devDependencies": {
"@eslint/js": "^9.39.4",
"@playwright/test": "^1.60.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3",
Expand Down
Loading
Loading