graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Cover attach timeout and pending model pick in the node suite
Cursor Agentd202a9cc2f7a
diff --git a/apps/native/lib/attachments.test.ts b/apps/native/lib/attachments.test.tsindex 9c3cc046..adf1d1cf 100644--- a/apps/native/lib/attachments.test.ts+++ b/apps/native/lib/attachments.test.ts@@ -92,13 +92,24 @@ test("uploadAttachment times out instead of hanging the composer", async () => {const file = new File([new Uint8Array([1])], "shot.png", { type: "image/png" });const original = globalThis.fetch;globalThis.fetch = (async (_url: unknown, init?: { signal?: AbortSignal }) => {+ const signal = init?.signal;+ if (!signal) throw new Error("expected abort signal");await new Promise((_, reject) => {- init?.signal?.addEventListener("abort", () => reject(init.signal?.reason ?? new DOMException("aborted", "AbortError")), { once: true });+ const fail = () => reject(signal.reason ?? new DOMException("The operation was aborted.", "TimeoutError"));+ if (signal.aborted) {+ fail();+ return;+ }+ const timer = setTimeout(fail, 100);+ signal.addEventListener("abort", () => {+ clearTimeout(timer);+ fail();+ }, { once: true });});throw new Error("unreachable");}) as typeof fetch;try {- await assert.rejects(() => uploadAttachment(file, 20), /timed out/);+ await assert.rejects(() => uploadAttachment(file, 15), /timed out/);} finally {globalThis.fetch = original;}diff --git a/apps/native/lib/composer-model-pick.test.ts b/apps/native/lib/composer-model-pick.test.tsnew file mode 100644index 00000000..dfabbd83--- /dev/null+++ b/apps/native/lib/composer-model-pick.test.ts@@ -0,0 +1,52 @@+import { test } from "node:test";+import assert from "node:assert/strict";+import {+ catalogMayWriteChatModel,+ catalogMayWriteGlobalKey,+ liveComposerKey,+ modelDisplayName,+ paneComposerKey,+ resolveComposerModel,+ sameModels,+ shouldConfirmModelSwitch,+} from "./composer-model.ts";++test("the pill keeps an unknown live key instead of catalog[0]", () => {+ const decoy = { key: "catalog-zero", name: "catalog-zero" };+ const pill = resolveComposerModel([decoy], "running-live");+ assert.equal(pill.key, "running-live");+ assert.equal(pill.name, "running-live");+});++test("a tab with an agent does not inherit another chat's global pick", () => {+ assert.equal(liveComposerKey(undefined, "catalog-zero", true), undefined);+ assert.equal(liveComposerKey("running-live", "catalog-zero", true), "running-live");+ assert.equal(liveComposerKey(undefined, "catalog-zero", false), "catalog-zero");+});++test("a pending pick owns the pane pill until the new agent answers", () => {+ assert.equal(paneComposerKey("glm-5.3-flash", "glm-5.3-flash", true, { chatId: 2, key: "grok-4.6" }, 2), "grok-4.6");+ assert.equal(paneComposerKey("glm-5.3-flash", "glm-5.3-flash", true, { chatId: 2, key: "grok-4.6" }, 1), "glm-5.3-flash");+});++test("catalog refresh does not overwrite a pending pick or the global inherit", () => {+ assert.equal(catalogMayWriteChatModel(2, { chatId: 2 }), false);+ assert.equal(catalogMayWriteChatModel(1, { chatId: 2 }), true);+ assert.equal(catalogMayWriteChatModel(1, null), true);+ assert.equal(catalogMayWriteGlobalKey(true), false);+ assert.equal(catalogMayWriteGlobalKey(false), true);+});++test("a chat with history or a running turn confirms before respawn", () => {+ assert.equal(shouldConfirmModelSwitch(1, false), true);+ assert.equal(shouldConfirmModelSwitch(0, true), true);+ assert.equal(shouldConfirmModelSwitch(0, false), false);+ assert.equal(modelDisplayName([{ key: "a", name: "Alpha" }], "a"), "Alpha");+ assert.equal(modelDisplayName([], null), "the current model");+});++test("sameModels ignores a new array of the same rows", () => {+ const row = { key: "running-live", name: "running-live" };+ assert.equal(sameModels([row], [{ ...row }]), true);+ assert.equal(sameModels([row], [{ key: "other", name: "other" }]), false);+});diff --git a/apps/native/lib/composer-model.test.ts b/apps/native/lib/composer-model.test.tsindex 55accbef..024f63a4 100644--- a/apps/native/lib/composer-model.test.ts+++ b/apps/native/lib/composer-model.test.ts@@ -4,17 +4,7 @@ import { mkdtempSync, writeFileSync, rmSync } from "node:fs";import os from "node:os";import path from "node:path";import { modelChoices } from "./acp-client";-import {- catalogMayWriteChatModel,- catalogMayWriteGlobalKey,- liveComposerKey,- modelDisplayName,- paneComposerKey,- pillFromAcp,- resolveComposerModel,- sameModels,- shouldConfirmModelSwitch,-} from "./composer-model";+import { liveComposerKey, paneComposerKey, pillFromAcp, resolveComposerModel, sameModels } from "./composer-model";test("the pill keeps an unknown live key instead of catalog[0]", () => {const decoy = { key: "catalog-zero", name: "catalog-zero" };@@ -34,22 +24,6 @@ test("a pending pick owns the pane pill until the new agent answers", () => {expect(paneComposerKey("glm-5.3-flash", "glm-5.3-flash", true, { chatId: 2, key: "grok-4.6" }, 1)).toBe("glm-5.3-flash");});-test("catalog refresh does not overwrite a pending pick or the global inherit", () => {- expect(catalogMayWriteChatModel(2, { chatId: 2 })).toBe(false);- expect(catalogMayWriteChatModel(1, { chatId: 2 })).toBe(true);- expect(catalogMayWriteChatModel(1, null)).toBe(true);- expect(catalogMayWriteGlobalKey(true)).toBe(false);- expect(catalogMayWriteGlobalKey(false)).toBe(true);-});--test("a chat with history or a running turn confirms before respawn", () => {- expect(shouldConfirmModelSwitch(1, false)).toBe(true);- expect(shouldConfirmModelSwitch(0, true)).toBe(true);- expect(shouldConfirmModelSwitch(0, false)).toBe(false);- expect(modelDisplayName([{ key: "a", name: "Alpha" }], "a")).toBe("Alpha");- expect(modelDisplayName([], null)).toBe("the current model");-});-test("sameModels ignores a new array of the same rows", () => {const row = { key: "running-live", name: "running-live" };expect(sameModels([row], [{ ...row }])).toBe(true);diff --git a/apps/native/package.json b/apps/native/package.jsonindex 0f43179a..0a9b7b8f 100644--- a/apps/native/package.json+++ b/apps/native/package.json@@ -10,7 +10,7 @@"start": "NEXT_TELEMETRY_DISABLED=1 next start --port 3000","mock-serve": "node scripts/mock-serve.mjs","lint": "next lint",- "test": "node --experimental-strip-types --test lib/cite-markup.test.ts lib/graff-events.test.ts lib/acp.test.ts lib/sessions.test.ts lib/session-store.test.ts lib/follow-scroll.test.ts lib/prompt-queue.test.ts lib/prompt-queue-steer.test.ts lib/prompt-queue-resume.test.ts lib/streaming-code.test.ts lib/agents.test.ts lib/mermaid-plugin.test.ts lib/prompt-history.test.ts lib/attachments.test.ts lib/idle-http.test.ts lib/workspaces.test.ts lib/fuzzy.test.ts lib/folder-picker.test.ts lib/browser/annotations.test.ts lib/browser/url.test.ts lib/extension-bridge.test.ts components/site/harness-split.test.ts components/site/appearance-panel.test.ts",+ "test": "node --experimental-strip-types --test lib/cite-markup.test.ts lib/graff-events.test.ts lib/acp.test.ts lib/sessions.test.ts lib/session-store.test.ts lib/follow-scroll.test.ts lib/prompt-queue.test.ts lib/prompt-queue-steer.test.ts lib/prompt-queue-resume.test.ts lib/streaming-code.test.ts lib/agents.test.ts lib/mermaid-plugin.test.ts lib/prompt-history.test.ts lib/attachments.test.ts lib/idle-http.test.ts lib/composer-model-pick.test.ts lib/workspaces.test.ts lib/fuzzy.test.ts lib/folder-picker.test.ts lib/browser/annotations.test.ts lib/browser/url.test.ts lib/extension-bridge.test.ts components/site/harness-split.test.ts components/site/appearance-panel.test.ts","electron:build": "bash electron/build.sh","test:electron": "bun test electron/policy.test.cjs","test:webauthn": "node scripts/test-webauthn.mjs",