diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35a97ad..bd7f00d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/app/.gitignore b/app/.gitignore index fe2f0eb..0265e86 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -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/ diff --git a/app/e2e/analyst-brief-preview.spec.ts b/app/e2e/analyst-brief-preview.spec.ts new file mode 100644 index 0000000..73b52a1 --- /dev/null +++ b/app/e2e/analyst-brief-preview.spec.ts @@ -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([]); + }); +}); diff --git a/app/e2e/analyst-brief.spec.ts b/app/e2e/analyst-brief.spec.ts new file mode 100644 index 0000000..935927b --- /dev/null +++ b/app/e2e/analyst-brief.spec.ts @@ -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([]); + }); +}); diff --git a/app/e2e/causal-stub.spec.ts b/app/e2e/causal-stub.spec.ts new file mode 100644 index 0000000..a978cd6 --- /dev/null +++ b/app/e2e/causal-stub.spec.ts @@ -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([]); + }); +}); diff --git a/app/e2e/helpers.ts b/app/e2e/helpers.ts new file mode 100644 index 0000000..ab3c71d --- /dev/null +++ b/app/e2e/helpers.ts @@ -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 { + 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 { + 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 { + 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 { + 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 { + await waitForWatchlistReady(page); + await page.getByText(FIXTURE_VESSEL_LABEL).first().click(); + await page.getByText("Analyst brief").waitFor({ timeout: 30_000 }); +} diff --git a/app/package-lock.json b/app/package-lock.json index 260f894..73b90ee 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -18,6 +18,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", @@ -2528,6 +2529,22 @@ "integrity": "sha512-RKJ22hX8mHe3Y6wH/N3wCM6BWtjaxIyyUIkpHOvfFnxdI4yD4tBXEBKSbriGujF6jnSVkJrffuo6vxACiSSxIw==", "license": "ISC" }, + "node_modules/@playwright/test": { + "version": "1.60.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.60.0.tgz", + "integrity": "sha512-O71yZIbAh/PxDMNGns37GHBIfrVkEVyn+AXyIa5dOTfb4/xNvRWV+Vv/NMbNCtODB/pO7vLlF2OTmMVLhmr7Ag==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.60.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/@rolldown/pluginutils": { "version": "1.0.0-beta.27", "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-beta.27.tgz", @@ -6879,6 +6896,53 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/playwright": { + "version": "1.60.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.60.0.tgz", + "integrity": "sha512-hheHdokM8cdqCb0lcE3s+zT4t4W+vvjpGxsZlDnikarzx8tSzMebh3UiFtgqwFwnTnjYQcsyMF8ei2mCO/tpeA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.60.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.60.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.60.0.tgz", + "integrity": "sha512-9bW6zvX/m0lEbgTKJ6YppOKx8H3VOPBMOCFh2irXFOT4BbHgrx5hPjwJYLT40Lu+4qtD36qKc/Hn56StUW57IA==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/playwright/node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/possible-typed-array-names": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz", diff --git a/app/package.json b/app/package.json index d1e6206..eb45b51 100644 --- a/app/package.json +++ b/app/package.json @@ -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", @@ -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", diff --git a/app/playwright.config.ts b/app/playwright.config.ts new file mode 100644 index 0000000..a3199d6 --- /dev/null +++ b/app/playwright.config.ts @@ -0,0 +1,37 @@ +import { defineConfig, devices } from "@playwright/test"; + +// Incomplete browser cache when Cursor sandbox sets PLAYWRIGHT_BROWSERS_PATH. +if (process.env.PLAYWRIGHT_BROWSERS_PATH?.includes("cursor-sandbox-cache")) { + delete process.env.PLAYWRIGHT_BROWSERS_PATH; +} + +const DEV_PORT = 5173; + +const chromiumDevice = process.env.CI + ? devices["Desktop Chrome"] + : { ...devices["Desktop Chrome"], channel: "chrome" as const }; + +export default defineConfig({ + testDir: "./e2e", + fullyParallel: false, + forbidOnly: !!process.env.CI, + retries: process.env.CI ? 1 : 0, + workers: 1, + reporter: process.env.CI ? "github" : "list", + timeout: 120_000, + use: { + baseURL: `http://127.0.0.1:${DEV_PORT}`, + trace: "on-first-retry", + video: "off", + // PWA caches R2 Parquet; block SW so route/mock and fixtures are deterministic. + serviceWorkers: "block", + }, + testIgnore: "**/analyst-brief-preview.spec.ts", + projects: [{ name: "chromium", use: chromiumDevice }], + webServer: { + command: "npm run dev:e2e", + url: `http://127.0.0.1:${DEV_PORT}`, + reuseExistingServer: false, + timeout: 120_000, + }, +}); diff --git a/app/playwright.preview.config.ts b/app/playwright.preview.config.ts new file mode 100644 index 0000000..8d4ba01 --- /dev/null +++ b/app/playwright.preview.config.ts @@ -0,0 +1,20 @@ +import base from "./playwright.config"; +import { defineConfig, devices } from "@playwright/test"; + +const PREVIEW_PORT = 4173; + +const chromiumDevice = process.env.CI + ? devices["Desktop Chrome"] + : { ...devices["Desktop Chrome"], channel: "chrome" as const }; + +export default defineConfig({ + ...base, + testMatch: "**/analyst-brief-preview.spec.ts", + projects: [{ name: "chromium-preview", use: { ...chromiumDevice, baseURL: `http://127.0.0.1:${PREVIEW_PORT}` } }], + webServer: { + command: "npm run build:e2e && npm run preview:e2e", + url: `http://127.0.0.1:${PREVIEW_PORT}`, + reuseExistingServer: !process.env.CI, + timeout: 180_000, + }, +}); diff --git a/app/public/fixtures/causal_effects_regime_only.parquet b/app/public/fixtures/causal_effects_regime_only.parquet new file mode 100644 index 0000000..87197c9 Binary files /dev/null and b/app/public/fixtures/causal_effects_regime_only.parquet differ diff --git a/app/public/fixtures/e2e_ducklake_manifest.json b/app/public/fixtures/e2e_ducklake_manifest.json new file mode 100644 index 0000000..4570d69 --- /dev/null +++ b/app/public/fixtures/e2e_ducklake_manifest.json @@ -0,0 +1,34 @@ +{ + "generated_at": "2026-05-25T00:00:00Z", + "base_url": "/fixtures", + "files": [ + { + "key": "fixtures/watchlist.parquet", + "url": "/fixtures/watchlist.parquet", + "size_bytes": 7989, + "table": "watchlist", + "register_as": "watchlist.parquet" + }, + { + "key": "fixtures/validation_metrics.parquet", + "url": "/fixtures/validation_metrics.parquet", + "size_bytes": 1646, + "table": "validation_metrics", + "register_as": "validation_metrics.parquet" + }, + { + "key": "fixtures/causal_effects_regime_only.parquet", + "url": "/fixtures/causal_effects_regime_only.parquet", + "size_bytes": 1024, + "table": "causal_effects", + "register_as": "causal_effects.parquet" + }, + { + "key": "fixtures/score_history.parquet", + "url": "/fixtures/score_history.parquet", + "size_bytes": 13594, + "table": "score_history", + "register_as": "score_history.parquet" + } + ] +} diff --git a/app/src/lib/llmEndpoint.test.ts b/app/src/lib/llmEndpoint.test.ts index 9dbfd3f..722721d 100644 --- a/app/src/lib/llmEndpoint.test.ts +++ b/app/src/lib/llmEndpoint.test.ts @@ -28,8 +28,8 @@ function setLocation(url: string) { /** Vitest runs with import.meta.env.DEV true — stub production for getLlmEndpoint tests. */ function stubProductionEnv() { vi.stubEnv("MODE", "production"); - vi.stubEnv("PROD", "true"); - vi.stubEnv("DEV", ""); + vi.stubEnv("PROD", true); + vi.stubEnv("DEV", false); vi.stubEnv("VITE_LLM_ENDPOINT", ""); } diff --git a/docs/ref-llm-grounding.md b/docs/ref-llm-grounding.md index 00a37b2..f7141c6 100644 --- a/docs/ref-llm-grounding.md +++ b/docs/ref-llm-grounding.md @@ -92,3 +92,51 @@ No SHAP signal values, ownership paths, or ATT coefficients are included in the ## Verifiability Every claim in an analyst brief can be verified against the displayed SHAP panel and vessel detail row. The brief is clearly labelled "Analyst brief" and visually separated from the deterministic SHAP attribution and ATT outputs. Analysts are instructed in the [SOP](https://edgesentry.github.io/indago/sop/) to treat the brief as a synthesis aid, not a primary evidence source. + +--- + +## Local LLM setup (`run_llama.sh`) + +| Component | URL | +|---|---| +| llama-server | `http://localhost:8080/v1` | +| Caddy (HTTPS + CORS) | `https://localhost:8443/v1` | + +```bash +cd arktrace && bash scripts/run_llama.sh +curl -sk https://localhost:8443/v1/models | head -c 200 +``` + +Production SPA: open `https://arktrace.edgesentry.io?local_llm=1` or click **Use local LLM** on the Analyst brief panel (same machine as `run_llama.sh`). + +### Failure modes + +| Symptom | Cause | Fix | +|---|---|---| +| `ERR_CONNECTION_REFUSED` on `:8443` | Caddy not running | Restart `run_llama.sh`; check `/tmp/caddy-llama.log` | +| CORS: duplicate `Access-Control-Allow-Origin` | Caddy + llama both emit CORS | Use current `scripts/caddy/local-llm.caddy.in` (strips upstream headers) | +| `ERR_CERT_DATE_INVALID` / TLS blocked | Caddy local CA not trusted | Visit `https://localhost:8443/v1/models` once and accept cert (Safari) | +| Brief shows “not configured” on production | No `VITE_LLM_ENDPOINT` and no opt-in | `?local_llm=1` or **Use local LLM** | +| `Binder Error: mmsi` in console | R2 `causal_effects.parquet` regime-only stub | Harmless for brief; guarded in `duckdb.ts` (#588) | + +--- + +## E2E tests (Playwright) + +CI runs **Tier 1** mock-LLM tests (no GGUF download): + +```bash +cd arktrace/app +npm ci +uv run python ../scripts/gen_e2e_causal_stub.py # regime-only causal fixture +npm run test:e2e:install +npm run test:e2e +``` + +| Tier | Command | Notes | +|---|---|---| +| **1 — CI** | `npm run test:e2e` | Mocks `https://localhost:8443/v1/chat/completions`; fixtures via `VITE_MANIFEST_URL` | +| **2 — Manual / nightly** | `run_llama.sh` + dev SPA | Real inference; MMSI `352179000` per Cap Vista [#63](https://github.com/edgesentry/edgesentry-commercial/issues/63) | +| **3 — Preview opt-in** | `analyst-brief-preview.spec.ts` | Production build + **Use local LLM** + mock | + +Tracked in [arktrace#589](https://github.com/edgesentry/arktrace/issues/589). diff --git a/scripts/caddy/local-llm.caddy.in b/scripts/caddy/local-llm.caddy.in index 5453caf..6c4fc30 100644 --- a/scripts/caddy/local-llm.caddy.in +++ b/scripts/caddy/local-llm.caddy.in @@ -16,7 +16,14 @@ https://localhost:HTTPS_PORT { respond 204 } - reverse_proxy localhost:UPSTREAM_PORT + # llama-server also emits Access-Control-* when Origin is set; strip upstream + # headers so the browser sees a single ACAO value (duplicate values fail CORS). + reverse_proxy localhost:UPSTREAM_PORT { + header_down -Access-Control-Allow-Origin + header_down -Access-Control-Allow-Methods + header_down -Access-Control-Allow-Headers + header_down -Access-Control-Allow-Credentials + } header { Access-Control-Allow-Origin * diff --git a/scripts/gen_e2e_causal_stub.py b/scripts/gen_e2e_causal_stub.py new file mode 100644 index 0000000..c37ad32 --- /dev/null +++ b/scripts/gen_e2e_causal_stub.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +"""Write regime-only causal_effects stub for Playwright E2E (no mmsi column).""" + +from pathlib import Path + +import polars as pl + +OUT = Path(__file__).resolve().parents[1] / "app/public/fixtures/causal_effects_regime_only.parquet" + +SCHEMA = { + "regime": pl.Utf8, + "label": pl.Utf8, + "n_treated": pl.Int32, + "n_control": pl.Int32, + "att_estimate": pl.Float64, + "att_ci_lower": pl.Float64, + "att_ci_upper": pl.Float64, + "p_value": pl.Float64, + "is_significant": pl.Boolean, + "calibrated_weight": pl.Float64, +} + +if __name__ == "__main__": + df = pl.DataFrame( + { + "regime": ["singapore"], + "label": ["stub"], + "n_treated": [0], + "n_control": [0], + "att_estimate": [0.0], + "att_ci_lower": [0.0], + "att_ci_upper": [0.0], + "p_value": [1.0], + "is_significant": [False], + "calibrated_weight": [0.0], + }, + schema=SCHEMA, + ) + OUT.parent.mkdir(parents=True, exist_ok=True) + df.write_parquet(OUT) + print(f"wrote {OUT} ({OUT.stat().st_size} bytes)") diff --git a/scripts/run_llama.sh b/scripts/run_llama.sh index 7940ff8..491b7ff 100755 --- a/scripts/run_llama.sh +++ b/scripts/run_llama.sh @@ -145,10 +145,12 @@ for i in $(seq 1 30); do CADDY_PID="" if command -v caddy &>/dev/null; then SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - CADDY_CFG="$(mktemp /tmp/caddy-arktrace-llm.XXXXXX.caddy)" + # macOS mktemp requires XXXXXX at end of template (not before .caddyfile). + CADDY_CFG="$(mktemp /tmp/caddy-arktrace-llm.XXXXXX)" sed -e "s/HTTPS_PORT/${HTTPS_PORT}/g" -e "s/UPSTREAM_PORT/${PORT}/g" \ "${SCRIPT_DIR}/caddy/local-llm.caddy.in" > "${CADDY_CFG}" - caddy run --config "${CADDY_CFG}" > /tmp/caddy-llama.log 2>&1 & + # Caddy 2.11+ treats unknown extensions as JSON; our template is Caddyfile syntax. + caddy run --config "${CADDY_CFG}" --adapter caddyfile > /tmp/caddy-llama.log 2>&1 & CADDY_PID=$! # Poll until Caddy is accepting TLS connections (cert renewal can take # several seconds on an expired cert — a fixed sleep 1 races this).