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
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI

on:
push:
branches: [dev]
pull_request:
branches: [dev]

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
- run: npm ci
- run: npm run typecheck
- run: npm run build
- run: npm test
5 changes: 3 additions & 2 deletions test/fixtures/durable-fixture-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import assert from "node:assert/strict";
import { randomUUID } from "node:crypto";
import { spawn } from "node:child_process";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { setTimeout as delay } from "node:timers/promises";
import { Type } from "@earendil-works/pi-ai";
import { defineExtension, defineTool } from "@earendil-works/pi-durable";
Expand Down Expand Up @@ -51,7 +52,7 @@ export function makeFixtureExtension(opts: FixtureMissionToolsOptions) {
const edit = createEditTool();
const workspace = join(opts.scope, "workspace");
const socketPath = join(opts.scope, "w.sock");
const workerScript = join(new URL(".", import.meta.url).pathname, "durable-worker.mjs");
const workerScript = join(dirname(fileURLToPath(import.meta.url)), "durable-worker.mjs");

const fixtureEdit = defineTool({
name: "fixture_edit",
Expand Down
5 changes: 5 additions & 0 deletions test/git-import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ process.env.COGITATOR_HOME = home;
process.env.COGITATOR_PI_AGENT_DIR = piDir;
process.env.COGITATOR_AGENTS_DIR = join(piDir, "agents");
process.env.COGITATOR_SKILLS_DIRS = join(home, "skills");
// Isolate `git remote get-url` from the runner's url.*.insteadof rewrites so M2
// compares the stored origin, not a rewritten GitHub URL.
process.env.GIT_CONFIG_GLOBAL = "/dev/null";
process.env.GIT_CONFIG_SYSTEM = "/dev/null";
process.env.GIT_CONFIG_NOSYSTEM = "1";
writeFileSync(join(piDir, "models-store.json"), JSON.stringify({ openai: { models: [{ id: "gpt-5.4" }] } }));

const { normalizeGitUrl, localDirFor, cloneRepo, gitErrorDetail, isInsideDir } = await import("../src/git-import.js");
Expand Down
41 changes: 36 additions & 5 deletions test/polish-screens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const settle = async () => { for (let i = 0; i < 12; i++) await Promise.resolve(
function harness(screen: string, api: object, fetch?: unknown, component = "default") {
const slots: unknown[] = [];
let cursor = 0;
let mounted = false;
const effectSlots: Array<{ deps?: unknown[] }> = [];
let effectCursor = 0;
const callbackSlots: Array<{ value?: unknown; deps?: unknown[] }> = [];
let callbackCursor = 0;
const effects: Array<() => void> = [];
const exports: Record<string, (props: unknown) => Element> = {};
const jsx = (type: unknown, props: Element["props"]): Element =>
Expand Down Expand Up @@ -50,8 +53,21 @@ function harness(screen: string, api: object, fetch?: unknown, component = "defa
if (!(index in slots)) slots[index] = { current: initial };
return slots[index];
},
useCallback: (callback: unknown) => callback,
useEffect: (effect: () => void) => { if (!mounted) effects.push(effect); },
useCallback: (callback: unknown, deps?: unknown[]) => {
const slot = callbackSlots[callbackCursor++] ??= {};
if (slot.deps && deps && deps.length === slot.deps.length && deps.every((value, i) => Object.is(value, slot.deps![i]))) {
return slot.value;
}
slot.value = callback;
slot.deps = deps;
return callback;
},
useEffect: (effect: () => void, deps?: unknown[]) => {
const slot = effectSlots[effectCursor++] ??= {};
if (slot.deps && deps && deps.length === slot.deps.length && deps.every((value, i) => Object.is(value, slot.deps![i]))) return;
effects.push(effect);
slot.deps = deps;
},
};
if (name === "./api" || name === "../api") return { api };
if (name === "./ui" || name === "../ui") return { Modal: "Modal", PageHead: "PageHead", ErrorText: "ErrorText", Field: "Field", useToast: () => () => {} };
Expand All @@ -60,13 +76,24 @@ function harness(screen: string, api: object, fetch?: unknown, component = "defa
});
return (props = {}) => {
cursor = 0;
effectCursor = 0;
callbackCursor = 0;
const tree = exports[component]!(props);
mounted = true;
while (effects.length) effects.shift()!();
return tree;
};
}

function hasText(element: Element, needle: string): boolean {
const visit = (node: unknown): boolean => {
if (typeof node === "string" && node.includes(needle)) return true;
if (Array.isArray(node)) return node.some(visit);
if (node && typeof node === "object") return visit((node as Element).props?.children);
return false;
};
return visit(element.props?.children);
}

function find(node: unknown, predicate: (element: Element) => boolean): Element | undefined {
if (!node || typeof node !== "object") return;
if (Array.isArray(node)) {
Expand Down Expand Up @@ -141,7 +168,11 @@ test("folder picker explains an empty root and retains a named add action", asyn
const render = harness("Workspaces", {
browse: async () => ({ path: "/", parent: null, entries: [] }),
}, undefined, "AddWorkspaceModal");
render(); await settle();
const local = find(render(), (e) => e.type === "button" && hasText(e, "Dossier sur le serveur"));
assert.ok(local, "local source control is present while GitHub is the default mode");
(local.props.onClick as () => void)();
render();
await settle();
const tree = render();
assert.ok(find(tree, (e) => e.type === "p" && e.props.children === "Aucun sous-dossier. Tu peux ajouter le dossier actuel."));
assert.ok(find(tree, (e) => e.type === "button" && e.props.children === "Ajouter /"));
Expand Down
16 changes: 15 additions & 1 deletion test/subagents-ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function harness() {
require(name: string) {
if (name === "react/jsx-runtime") return { jsx, jsxs: jsx };
if (name === "./i18n") return i18n;
if (name === "./SubagentConversation") return { SubagentConversation() { return null; } };
if (name === "./ui") return { Empty: "Empty" };
if (name === "./api") return { api: { conversationSubagents: (id: string, signal: AbortSignal) =>
new Promise<Snapshot>((resolve, reject) => requests.push({ id, signal, resolve, reject })) } };
Expand Down Expand Up @@ -60,6 +61,19 @@ function harness() {
return { render, requests, counts, timers, poll, unmount };
}

function findNode(node: unknown, predicate: (element: Node) => boolean): Node | undefined {
if (node == null || typeof node !== "object") return;
if (Array.isArray(node)) {
for (const child of node) {
const match = findNode(child, predicate);
if (match) return match;
}
return;
}
const element = node as Node;
return predicate(element) ? element : findNode(element.props?.children, predicate);
}

function text(node: unknown): string {
if (node == null || typeof node === "boolean") return "";
if (Array.isArray(node)) return node.map(text).join(" ");
Expand Down Expand Up @@ -88,7 +102,7 @@ test("subagent panel: loading, model/status, visible refresh failure, explicit r
const failed = ui.render();
assert.ok(text(failed).includes(i18n.t("chat.subagentsRefreshError")));
assert.ok(text(failed).includes("Inspect the build"), "last list remains visible with its stale warning");
const alert = (failed.props.children as Node[]).find((node) => node?.props?.role === "alert")!;
const alert = findNode(failed, (node) => node.props?.role === "alert")!;
const button = (alert.props.children as Node[]).find((node) => node?.type === "button")!;
(button.props.onClick as () => void)();
ui.render();
Expand Down
Loading