Skip to content
Draft
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
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ jobs:
test:
name: unit + e2e (macOS)
runs-on: macos-latest
# Green runs on shared runners take 20–29 minutes, the e2e step alone 16–22 (2026-10-18), so 30
# cut off slow but passing runs. 45 leaves room without letting a hung run sit for long.
timeout-minutes: 45
# Green runs on shared runners took 29–45 minutes on 2026-11-12, the e2e step alone 25–37 of
# them, and 45 cut off three passing runs in a row (two of them in the merge queue). 70 leaves
# room for a slow runner without letting a hung run sit for long.
timeout-minutes: 70
steps:
- uses: actions/checkout@v5

Expand Down Expand Up @@ -143,6 +144,9 @@ jobs:
- name: Landing page release and responsive tests
run: pnpm --filter @modex/site test:e2e

- name: Browser demo workspace tests
run: pnpm --filter @modex/web test:e2e

- name: Desktop runner memory low point
if: always()
run: apps/ios/ModexCompanion/Scripts/sample-memory.sh --summary "$RUNNER_TEMP/modex-desktop-memory.log"
Expand All @@ -164,6 +168,7 @@ jobs:
path: |
apps/desktop/test-results
apps/site/test-results
apps/web/test-results
if-no-files-found: ignore
retention-days: 7

Expand Down
3 changes: 3 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ itself driving one of them.

- `apps/desktop` — the Electron app (`src/main` process + backends, `src/renderer` React UI,
`e2e/` Playwright). `packages/core` — the offline scripted engine used by demos and tests.
- `apps/site` — the landing page at modex.codes. `apps/web` — the renderer in a browser at
app.modex.codes, on an in-memory demo workspace only: it runs no model, CLI, shell or file
operation and makes no request beyond its own origin. Keep it that way.
- `docs/release-signing.md` — how release builds are signed and notarized, and where the
credentials live (never in the tree). `pnpm --filter @modex/desktop dist` stays ad-hoc for
everyday builds.
Expand Down
15 changes: 9 additions & 6 deletions apps/desktop/e2e/code-review-enablement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { tid } from "./support.js";
import { baseWorld, launchWithGh, prRow, type Harness } from "./code-review-support.js";

/**
* The Code Review setting (#319, #327): hidden by default in a built app until its gates pass, shown from Settings →
* General or by the old switch's "on". Turning it off hides the surface; it does not touch main's records.
* The Code Review setting (#319, #327): shown by default in built apps. Settings → General and the old
* switch preserve an explicit choice to hide the surface; turning it off does not touch main's records.
*/
let h: Harness;
test.afterEach(async () => { await h?.close(); });
Expand All @@ -16,20 +16,23 @@ async function general() {
return tid(h.page, "code-review-in-rail");
}

test("Code Review is hidden by default: the rail leaves it out, makes no gh read, and Settings can show it", async () => {
test("Code Review is visible by default without a switch, stays idle until opened, and survives a reload", async () => {
h = await launchWithGh(baseWorld(), { showCodeReview: false });
const { page } = h;
await expect(tid(page, "open-settings")).toBeVisible();
await expect(tid(page, "rail-code-review")).toHaveCount(0);
await expect(tid(page, "rail-code-review")).toBeVisible();
expect(await page.evaluate(() => localStorage.getItem("modex.codeReview"))).toBeNull();
const box = await general();
await expect(box).not.toBeChecked();
await expect(box).toBeChecked();
expect(h.calls().filter((call) => call.includes("search"))).toEqual([]);
await box.check();
await page.keyboard.press("Escape");
await tid(page, "rail-code-review").click();
await expect(prRow(page, "example-org/lending#73")).toBeVisible();
await page.reload();
await expect(tid(page, "rail-code-review")).toBeVisible();
// The app checks its installed CLIs during this test (version checks and Codex's app-server); what must not start is a model turn.
expect(h.providerStarts().filter((start) => /^claude .*-p\b/.test(start) || /^codex exec\b/.test(start))).toEqual([]);
expect(h.posts()).toEqual([]);
});

test("turning it off is the rollback: the surface leaves at once, survives a relaunch, keeps a draft, and can come back", async () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/e2e/code-review-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function launchWithGh(initial: GhWorld, options: { showCodeReview?:
// Row ages and captures read the renderer's clock: pin it to the fixtures' (test/fixtures/code-review.ts NOW).
await page.clock.setFixedTime(new Date("2026-10-18T20:41:00Z"));
await page.reload();
// Built apps hide Code Review by default (e2e/code-review-enablement.spec.ts); these specs test the workspace itself.
// Workspace fixtures keep the legacy opt-in; the enablement spec omits it to exercise the built app's default.
if (options.showCodeReview !== false) await page.evaluate(() => localStorage.setItem("modex.codeReview", "on"));
await page.reload();
// Settings is always in the rail, whether or not Code Review's button is.
Expand Down
36 changes: 36 additions & 0 deletions apps/desktop/e2e/credit-conservation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { test, expect } from "@playwright/test";
import fs from "node:fs";
import path from "node:path";
import { appDir, launch, seedHome, tid } from "./support";

test("automatic credit conservation defaults on, thresholds save, and disabling persists", async () => {
const { home } = seedHome();
const { app, page } = await launch(home);
try {
const open = async () => {
await tid(page, "open-settings").click();
await tid(page, "settings-nav").getByRole("button", { name: "Auto routing", exact: true }).click();
};
await open();
const enabled = tid(page, "conserve-credits"), percent = tid(page, "low-quota-percent"), balance = tid(page, "low-credit-balance");
await expect(enabled).toBeChecked();
await expect(percent).toHaveValue("20");
await expect(balance).toHaveValue("10");
await percent.fill("25");
await balance.fill("5");
await page.getByText("Conservation chooses economical models", { exact: false }).scrollIntoViewIfNeeded();
await page.screenshot({ path: path.join(appDir, "test-results", "credit-conservation-settings.png") });
await tid(page, "settings").getByRole("button", { name: "Save", exact: true }).click();
await open();
await expect(percent).toHaveValue("25");
await expect(balance).toHaveValue("5");
await enabled.uncheck();
await tid(page, "settings").getByRole("button", { name: "Save", exact: true }).click();
await open();
await expect(enabled).not.toBeChecked();
await expect(percent).toBeDisabled();
await expect(balance).toBeDisabled();
const saved = JSON.parse(fs.readFileSync(path.join(home, "app", "state.json"), "utf8")).settings.routing;
expect([saved.conserve_credits, saved.low_quota_percent, saved.low_credit_balance]).toEqual([false, 25, 5]);
} finally { await app.close(); }
});
29 changes: 29 additions & 0 deletions apps/desktop/e2e/fixtures/local-model-preservation.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Observer-only entry point for disposable, scripted preservation tests. Never packaged.
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
if (process.env.MODEX_E2E !== "1" || process.env.MODEX_LM_NATIVE_E2E === "1") throw new Error("Preservation fixture requires scripted E2E mode.");
const home = fs.realpathSync(process.env.MODEX_HOME ?? "");
if (!home.startsWith(fs.realpathSync(os.tmpdir()) + path.sep) || !path.basename(home).startsWith("modex-e2e-home-") || JSON.parse(fs.readFileSync(path.join(home, "app/state.json"), "utf8")).settings.default_backend !== "mock") throw new Error("Preservation fixture requires a disposable mock home.");
import { LocalModelDiscovery } from "../../dist/src/main/engine/local-models/discovery.js";
globalThis.__lm4DiscoveryResults = [];
globalThis.__lm4DiscoveryStarts = [];
const discover = LocalModelDiscovery.prototype.discover;
LocalModelDiscovery.prototype.discover = async function (ref, requestId) {
globalThis.__lm4DiscoveryStarts.push({ connection: { ...ref }, requestId });
const result = await discover.call(this, ref, requestId);
globalThis.__lm4DiscoveryResults.push({ connection: { ...ref }, requestId, state: result.state });
return result;
};


import { LocalExecution } from "../../dist/src/main/engine/local-models/execution.js";
import { ThreadRunner } from "../../dist/src/main/engine/runner.js";
globalThis.__lm4Calls = { localStarts: 0, sends: 0, durableSends: 0, retries: 0 };
const start = LocalExecution.prototype.start;
LocalExecution.prototype.start = function (...args) { globalThis.__lm4Calls.localStarts++; return start.apply(this, args); };
for (const [method, key] of [["send", "sends"], ["sendDurably", "durableSends"], ["retry", "retries"]]) {
const original = ThreadRunner.prototype[method];
ThreadRunner.prototype[method] = function (...args) { globalThis.__lm4Calls[key]++; return original.apply(this, args); };
}
await import("./local-model-workflow.mjs");
121 changes: 121 additions & 0 deletions apps/desktop/e2e/local-model-preservation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// #381 metadata races through production IPC/store/renderer with the existing scripted native fixture.
// These cases request no coding turns and do not qualify ordinary product admission or real models.
import { test, expect, _electron as electron, type ElectronApplication } from "@playwright/test";
import fs from "node:fs";
import { execFileSync } from "node:child_process";
import { pathToFileURL } from "node:url";
import path from "node:path";
import http from "node:http";
import crypto from "node:crypto";
import type { AddressInfo } from "node:net";
import { appDir, seedHome, tid } from "./support.js";

const PNG_B64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==";
const sha = (bytes: Buffer) => crypto.createHash("sha256").update(bytes).digest("hex");
async function runtime(model: string) {
let current = model, hold = false, release: (() => void) | undefined;
let arrived!: () => void;
const barrier = new Promise<void>(resolve => { arrived = resolve; });
const hits: Array<{ method?: string; url?: string; auth: boolean }> = [];
const server = http.createServer((req, res) => {
hits.push({ method: req.method, url: req.url, auth: Boolean(req.headers.authorization) });
req.resume(); res.setHeader("content-type", "application/json");
const tags = () => res.end(JSON.stringify({ models: [{ name: current, details: { family: "qwen3moe" } }] }));
if (req.url === "/api/tags") {
if (hold) { hold = false; release = () => { current = "Late/Alpha:Q4_0"; if (!res.destroyed) tags(); }; arrived(); }
else tags();
} else if (req.url === "/api/ps") res.end(JSON.stringify({ models: [] }));
else if (req.url === "/api/show") res.end(JSON.stringify({ capabilities: ["completion", "tools"], model_info: { "qwen3moe.context_length": 65536 } }));
else { res.writeHead(404); res.end(); }
});
await new Promise<void>(resolve => server.listen(0, "127.0.0.1", resolve));
return { hits, url: `http://127.0.0.1:${(server.address() as AddressInfo).port}`, hold: () => { hold = true; }, barrier, release: () => release?.(), stop: async () => { release?.(); server.closeAllConnections(); await new Promise<void>(resolve => server.close(() => resolve())); } };
}

test("delayed metadata preserves two thread drafts, image bytes, target and search focus", async ({}, testInfo) => {
const receipt = testInfo.outputPath("local-model-preservation.json");
expect(fs.existsSync(receipt)).toBe(false);
const out: Record<string, any> = { startedAt: new Date().toISOString(), gitHeadAtRun: execFileSync("git", ["rev-parse", "HEAD"], { cwd: appDir, encoding: "utf8" }).trim(), scope: "existing temporary-home scripted LocalExecution bootstrap; production IPC/store/renderer; no real model or product admission", state: "started" };
const persist = () => fs.writeFileSync(receipt, JSON.stringify(out, null, 2) + "\n"); persist();
let app: ElectronApplication | undefined;
let alpha: Awaited<ReturnType<typeof runtime>> | undefined, beta: Awaited<ReturnType<typeof runtime>> | undefined;
try {
alpha = await runtime("Fixture/Alpha:Q4_0"); beta = await runtime("Fixture/Beta:Q4_0");
const { home } = seedHome();
app = await electron.launch({ args: [path.join(appDir, "e2e/fixtures/local-model-preservation.mjs")], cwd: appDir, env: { ...process.env, MODEX_HOME: home, MODEX_E2E: "1", MODEX_E2E_NODE: process.execPath, MODEX_LM_NATIVE_E2E: "", MODEX_LM3_LIVE: "", MODEX_LM3_WIRE: "", MODEX_NO_LOGIN_PATH: "1", TYPESAFE_API_KEY: "", JEV_API_KEY: "" } });
out.mainPid = app.process().pid; persist();
const page = await app.firstWindow(); await page.waitForLoadState("domcontentloaded");
await expect(tid(page, "composer-input")).toBeVisible();
out.document = await page.evaluate(() => location.href); expect(out.document).toBe(pathToFileURL(path.join(appDir, "dist/renderer/index.html")).href);
for (const [label, url] of [["Alpha lab", alpha.url], ["Beta lab", beta.url]]) await page.evaluate(({ label, url }) => window.modex!.invoke("local-models:command", { op: "create", input: { label, runtime: "ollama", url } }), { label, url });
await tid(page, "model-picker").click();
await tid(page, "model-local-option").filter({ hasText: "Fixture/Beta:Q4_0" }).click();
await tid(page, "model-local-context").getByRole("menuitemradio", { name: /65,536/ }).click();
await expect(tid(page, "model-local-badge")).toBeVisible();
const local = await page.evaluate(async () => (await window.modex!.invoke("state:get", undefined)).threads.find(t => t.localTarget)!);
expect(local.localTarget?.model.id).toBe("Fixture/Beta:Q4_0");
out.targetBefore = local.localTarget;
const cloud = await page.evaluate(() => window.modex!.invoke("thread:create", { projectId: "p1", backend: "mock", mode: "chat" }));
// Direct thread:create returns to its caller; unlike routine creation it does not broadcast a window refresh.
await page.reload(); await expect(tid(page, "composer-input")).toBeVisible();
out.setup = "Reload after direct IPC thread creation before the race; production source unchanged";
const select = async (id: string) => page.locator(`[data-testid="thread-row"][data-thread-id="${id}"] button.thread-main`).click();
await select(cloud.id);
await tid(page, "composer-input").fill(" cloud draft with image\nkept exactly ");
await page.evaluate(b64 => {
const dt = new DataTransfer(); dt.items.add(new File([Uint8Array.from(atob(b64), c => c.charCodeAt(0))], "dot.png", { type: "image/png" }));
document.querySelector('[data-testid="composer-input"]')!.dispatchEvent(new ClipboardEvent("paste", { clipboardData: dt, bubbles: true, cancelable: true }));
}, PNG_B64);
await expect(tid(tid(page, "composer-attachments"), "attachment-chip")).toContainText("dot.png");
const staging = path.join(home, "attachments", "staging");
expect(fs.readdirSync(staging)).toHaveLength(1); const staged = path.join(staging, fs.readdirSync(staging)[0]!);
out.imageBefore = sha(fs.readFileSync(staged)); expect(out.imageBefore).toBe(sha(Buffer.from(PNG_B64, "base64")));
await tid(page, "open-settings").click(); await page.getByRole("button", { name: "Local models", exact: true }).click();
const alphaCard = tid(page, "local-connection").filter({ hasText: "Alpha lab" });
await expect(alphaCard).toHaveAttribute("data-state", "ready");
alpha.hold();
await alphaCard.getByTestId("local-refresh").click();
await new Promise<void>((resolve, reject) => {
const timer = setTimeout(() => reject(new Error("Alpha refresh did not reach its barrier within 10s")), 10000);
alpha!.barrier.then(() => { clearTimeout(timer); resolve(); }, error => { clearTimeout(timer); reject(error); });
});
await page.keyboard.press("Escape");
await select(local.id);
await tid(page, "composer-input").fill(" local draft\nkept separately ");
await expect(tid(page, "local-inference-host")).toContainText(beta.url);
await tid(page, "composer-input").evaluate((el: HTMLTextAreaElement) => el.setSelectionRange(1, 5));
await tid(page, "model-picker").click();
const search = page.getByRole("searchbox", { name: "Search models" }); await search.fill("late/ALPHA");
await search.press("Home"); for (let key = 0; key < 4; key++) await search.press("Shift+ArrowRight");
expect(await search.evaluate((el: HTMLInputElement) => ({ start: el.selectionStart, end: el.selectionEnd }))).toEqual({ start: 0, end: 4 });
alpha.release();
await expect(tid(page, "model-local-title")).toHaveText(["Late/Alpha:Q4_0"]);
await expect(search).toHaveValue("late/ALPHA"); await expect(search).toBeFocused();
out.searchSelectionAfter = await search.evaluate((el: HTMLInputElement) => ({ start: el.selectionStart, end: el.selectionEnd }));
expect(out.searchSelectionAfter).toEqual({ start: 0, end: 4 });
const after = await page.evaluate(() => window.modex!.invoke("state:get", undefined));
out.targetAfter = after.threads.find(t => t.id === local.id)!.localTarget; expect(out.targetAfter).toEqual(out.targetBefore);
expect(after.threads.find(t => t.id === cloud.id)!.localTarget).toBeUndefined();
await page.keyboard.press("Escape"); await expect(tid(page, "composer-input")).toHaveValue(" local draft\nkept separately ");
out.localDraftAfter = await tid(page, "composer-input").inputValue();
await tid(page, "composer-input").focus();
out.localSelectionAfter = await tid(page, "composer-input").evaluate((el: HTMLTextAreaElement) => ({ start: el.selectionStart, end: el.selectionEnd }));
expect(out.localSelectionAfter).toEqual({ start: 1, end: 5 });
await select(cloud.id); await expect(tid(page, "composer-input")).toHaveValue(" cloud draft with image\nkept exactly ");
await expect(tid(tid(page, "composer-attachments"), "attachment-chip")).toContainText("dot.png");
out.cloudDraftAfter = await tid(page, "composer-input").inputValue();
out.callCounts = await app.evaluate(() => (globalThis as any).__lm4Calls);
expect(out.callCounts).toEqual({ localStarts: 0, sends: 0, durableSends: 0, retries: 0 });
for (const id of [local.id, cloud.id]) expect(await page.evaluate(threadId => window.modex!.invoke("thread:items", { threadId }), id)).toEqual([]);
out.imageAfter = sha(fs.readFileSync(staged)); expect(out.imageAfter).toBe(out.imageBefore);
for (const r of [alpha, beta]) expect(r.hits.every(h => !h.auth && ((h.method === "GET" && ["/api/tags", "/api/ps"].includes(h.url!)) || (h.method === "POST" && h.url === "/api/show")))).toBe(true);
out.state = "passed";
} catch (error) { out.state = "failed"; out.failure = String(error); throw error; }
finally {
alpha?.release();
out.hits = { alpha: alpha?.hits ?? [], beta: beta?.hits ?? [] };
try { if (app) { await app.close(); out.appClose = "returned"; } else out.appClose = "no returned handle"; }
catch (error) { out.state = "close-failed"; out.closeError = String(error); throw error; }
finally { await Promise.all([alpha, beta].filter((r): r is Awaited<ReturnType<typeof runtime>> => Boolean(r)).map(r => r.stop())); out.finishedAt = new Date().toISOString(); persist(); await testInfo.attach("local-model-preservation.json", { path: receipt, contentType: "application/json" }); }
}
});
Loading
Loading