diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..82a7397 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/test/fixtures/durable-fixture-tools.ts b/test/fixtures/durable-fixture-tools.ts index 56d5408..d01acc9 100644 --- a/test/fixtures/durable-fixture-tools.ts +++ b/test/fixtures/durable-fixture-tools.ts @@ -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"; @@ -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", diff --git a/test/git-import.test.ts b/test/git-import.test.ts index abcf47d..715c538 100644 --- a/test/git-import.test.ts +++ b/test/git-import.test.ts @@ -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"); diff --git a/test/polish-screens.test.ts b/test/polish-screens.test.ts index 103f173..520237d 100644 --- a/test/polish-screens.test.ts +++ b/test/polish-screens.test.ts @@ -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 Element> = {}; const jsx = (type: unknown, props: Element["props"]): Element => @@ -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: () => () => {} }; @@ -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)) { @@ -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 /")); diff --git a/test/subagents-ui.test.ts b/test/subagents-ui.test.ts index ef303f8..bff2dfe 100644 --- a/test/subagents-ui.test.ts +++ b/test/subagents-ui.test.ts @@ -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((resolve, reject) => requests.push({ id, signal, resolve, reject })) } }; @@ -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(" "); @@ -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();