Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
Improve local media and library processing
wyt7e99788591f2
diff --git a/bin/kb-embed-worker.cjs b/bin/kb-embed-worker.cjsindex 699502b7..331bf5d4 100644--- a/bin/kb-embed-worker.cjs+++ b/bin/kb-embed-worker.cjs@@ -21,10 +21,15 @@* would be a bug — showDownloadProgress stays false.** This file is plain CommonJS on purpose: utilityProcess runs it as-is with no- * tsx hook, and it resolves `fastembed` from the (asar-unpacked) node_modules- * exactly like the in-process require did.+ * tsx hook. Resolve dependencies through the logical application root: the+ * physical unpacked tree does not contain every JavaScript dependency.*/+const path = require('node:path');+const { createRequire } = require('node:module');+const requireApp = createRequire(path.join(__dirname, '..', 'package.json')+ .replace(/([\\/])app\.asar\.unpacked([\\/])/g, '$1app.asar$2'));+const DEFAULT_EMBED_BATCH_SIZE = 32;function nativeEmbedLoadCode(err) {@@ -46,7 +51,7 @@ async function initEmbedder() {_initPromise = (async () => {// CJS entry (fastembed's ESM entry imports `tar` as a default export,// which breaks with tar@7) — same require the in-process path used.- const { FlagEmbedding, EmbeddingModel } = require('fastembed');+ const { FlagEmbedding, EmbeddingModel } = requireApp('fastembed');const cacheDir = process.env.ORKAS_EMBED_MODEL_DIR || undefined;const em = await FlagEmbedding.init({model: EmbeddingModel.BGESmallZH,diff --git a/bin/sharp-worker.cjs b/bin/sharp-worker.cjsindex 8c517c55..00f39e93 100644--- a/bin/sharp-worker.cjs+++ b/bin/sharp-worker.cjs@@ -131,7 +131,9 @@ async function processImage(operation, buffer, options = {}) {...(options.density !== undefined ? { density: options.density } : {}),});if (operation === 'metadata') return pipeline.metadata();- if (options.resize) pipeline = pipeline.resize(options.resize.width, options.resize.height, { fit: options.resize.fit });+ if (options.composite) pipeline = pipeline.composite(options.composite);+ if (options.extract) pipeline = pipeline.extract(options.extract);+ if (options.resize) pipeline = pipeline.resize(options.resize);const encodeOptions = options.encodeOptions || {};if (options.format === 'png') pipeline = pipeline.png(encodeOptions);else if (options.format === 'jpeg') pipeline = pipeline.jpeg(encodeOptions);diff --git a/docs/test/tts-generation-regression.md b/docs/test/tts-generation-regression.mdnew file mode 100644index 00000000..0879c894--- /dev/null+++ b/docs/test/tts-generation-regression.md@@ -0,0 +1,51 @@+# Text-to-speech and VoiceStudio regression++Use synthetic or explicitly authorized audio and isolated output directories.+Deterministic contracts prove routing, files and recovery; pronunciation,+reference-voice similarity and perceptual quality require a separately authorized+real-provider evaluation. Do not record credentials or private audio in evidence.++## Provider and model boundaries++- Configure a user-owned supported API key. Missing, expired, malformed and+ denied credentials fail clearly; recovery succeeds after explicit correction.+- Search/image/video/voice provider selection follows this build's public API-key+ policy. Model selection remains provider-owned where the settings expose only+ provider/key. No hosted account, quota, private credential sentinel or automatic+ managed fallback is introduced.+- Verify request shape, voice capabilities, input limits, format and error+ classification with controlled transport. Unknown voices, malformed references+ and rejected output do not become success. Cancellation makes no retry.++## Text, voice and file journeys++| User scenario | Independent outcome |+| --- | --- |+| Plain, long and multilingual narration | The requested text is covered once, in order; chunks do not lose or duplicate words. The returned audio is nonempty, decodable and has plausible duration. |+| Required subtitle/transcript sidecars | Text matches the requested source, cues are ordered and within audio duration, encoding survives reload, and unrelated branding or internal control text is absent. |+| Reference voice | Only explicitly supplied reference bytes are sent; invalid format, empty data, unavailable voice or provider rejection leaves an actionable failure. |+| Existing audio inspection | Duration, format and channel information come from the actual file. Silence, missing files and malformed bytes do not produce invented measurements. |+| Edit, extract, mix and transcribe | The requested operation runs through the owning audio capability; text-only requests do not accidentally create speech, and transcription does not silently invoke synthesis. |+| Multiple audio/text outputs | Each producer-declared file resolves to the delivered artifact; derived text and timing sidecars remain associated with their own audio. Repeated display does not duplicate publication. |+| Project and ordinary conversations | Equivalent source inputs produce equivalent valid artifacts in their authorized scope. Project data never leaks into the global scope or a different local user. |+| Interrupted or partial generation | A clear failure preserves accepted prior outputs and the user request. A later explicit retry remains usable; no duplicate charge/request or false final artifact appears. |+| Explicit single-operation request | Run only the requested operation. Preserve parameters and input ownership rather than adding an unsolicited multi-step workflow. |+| Paths and output visibility | Relative and absolute authorized source paths, non-ASCII names, spaces and project paths work; traversal, missing files and managed/private paths fail safely. |++## Validation layers++Run the owning audio, voice API, output-publication and VoiceStudio unit suites+through `npm run test:js`. Use real temporary artifacts and decode/inspect their+bytes, not only mocked success flags. Compare transcript coverage, cue boundaries,+file identity and retained output after failure.++A real provider canary additionally needs authorized test credentials and a+bounded input. Evaluate content/voice quality independently from API completion.+For each supported desktop platform, check native format/tool availability,+artifact preview, cancellation and restart. A pass on macOS does not establish+Windows or Linux behavior. Missing hardware/service evidence stays explicit.++Inspect all warnings, errors, retries and fallback. Logs retain only stable codes+and masked identifiers; keys, full local paths, source text and audio bytes must+remain absent. Hosted-account watermark and subscription scenarios are excluded;+ordinary audio/text artifact integrity remains covered.diff --git a/src/main/features/image_studio.ts b/src/main/features/image_studio.tsindex a038a1dc..924314f0 100644--- a/src/main/features/image_studio.ts+++ b/src/main/features/image_studio.ts@@ -6,7 +6,7 @@ import type { NativeImage as ElectronNativeImage } from 'electron';import { hardenedWebPreferences } from '../util/window-security';import { isPathAllowed } from '../util/path-sandbox';-import { encodeImage } from '../util/sharp-runtime';+import { encodeImage, imageMetadata } from '../util/sharp-runtime';import { isImageStudioGeneration, type ImageStudioGenerationOutput } from './image_studio_provenance';import {extractCssImports,@@ -1035,6 +1035,15 @@ export async function normalizeImageStudioSnapshot(capturedPng: Buffer,canvas: ImageStudioManifest['canvas'],): Promise<Buffer> {+ const source = await imageMetadata(capturedPng);+ const scaleX = source.width / canvas.width;+ const scaleY = source.height / canvas.height;+ // Display density may scale both axes, with at most one physical pixel of+ // rounding. A clipped viewport is not a density change and must not stretch.+ if (!(scaleX > 0 && scaleY > 0)+ || Math.abs(scaleX - scaleY) > Math.max(1 / canvas.width, 1 / canvas.height)) {+ throw new Error(`E_IMAGE_STUDIO_CAPTURE_GEOMETRY: Expected a proportional ${canvas.width}x${canvas.height} capture; got ${source.width}x${source.height}.`);+ }const { data } = await encodeImage(capturedPng, {resize: { width: canvas.width, height: canvas.height, fit: 'fill' },format: 'png',@@ -1043,7 +1052,7 @@ export async function normalizeImageStudioSnapshot(}async function renderHtmlSnapshot(projectDirAbs: string, manifest: ImageStudioManifest, outputAbsPath: string): Promise<{- image: ReturnType<typeof analyzeNativeImage>;+ image?: ReturnType<typeof analyzeNativeImage>;layoutBlockers: ImageStudioIssue[];}> {const electron = await import('electron');@@ -1058,14 +1067,18 @@ async function renderHtmlSnapshot(projectDirAbs: string, manifest: ImageStudioMawidth: manifest.canvas.width,height: manifest.canvas.height,useContentSize: true,+ enableLargerThanScreen: true,backgroundColor: '#00000000',webPreferences: hardenedWebPreferences({ session: ses, backgroundThrottling: false }),});try {+ // Constructor centering on Windows/Linux can constrain the viewport to the+ // display work area. Restore the canvas before loading, as VideoStudio does.+ win.setContentSize(manifest.canvas.width, manifest.canvas.height);const entryAbs = path.resolve(projectDirAbs, manifest.entry || 'index.html');await withTimeout(win.loadURL(pathToFileURL(entryAbs).toString()), IMAGE_STUDIO_LOAD_TIMEOUT_MS, 'E_IMAGE_STUDIO_LOAD_TIMEOUT: HTML entry did not finish loading.');const requiredCopyLiteral = JSON.stringify(JSON.stringify(manifest.brief.required_copy));- const requiredCopyLayouts = await withTimeout(win.webContents.executeJavaScript(`(async () => {+ const layout = await withTimeout(win.webContents.executeJavaScript(`(async () => {if (document.fonts && document.fonts.ready) await document.fonts.ready;const images = Array.from(document.images || []);await Promise.all(images.map((img) => img.complete ? Promise.resolve() : new Promise((resolve) => {@@ -1077,7 +1090,25 @@ async function renderHtmlSnapshot(projectDirAbs: string, manifest: ImageStudioMaconst visibleText = (element) => Array.from(String(element.innerText || '')).filter((char) => !/\\s/u.test(char));const elements = [document.body, ...Array.from(document.body.querySelectorAll('*'))];- return requiredCopy.map((copy) => {+ const root = document.scrollingElement || document.documentElement;+ const rootStyle = getComputedStyle(document.documentElement);+ const bodyStyle = getComputedStyle(document.body);+ const scrolls = (mode, extent, size) => mode === 'scroll'+ || (mode !== 'hidden' && mode !== 'clip' && extent > size + 1);+ const rootMode = (axis) => rootStyle[axis] === 'visible' ? bodyStyle[axis] : rootStyle[axis];+ let scrollingAreas = Number(scrolls(rootMode('overflowX'), root.scrollWidth, innerWidth)+ || scrolls(rootMode('overflowY'), root.scrollHeight, innerHeight));+ for (const element of elements) {+ if (element === document.body || !(element instanceof HTMLElement)) continue;+ const rect = element.getBoundingClientRect();+ const style = getComputedStyle(element);+ if (rect.width <= 0 || rect.height <= 0 || style.visibility === 'hidden' || Number(style.opacity) === 0) continue;+ if (['auto', 'scroll'].includes(style.overflowX) && scrolls(style.overflowX, element.scrollWidth, element.clientWidth)+ || ['auto', 'scroll'].includes(style.overflowY) && scrolls(style.overflowY, element.scrollHeight, element.clientHeight)) {+ scrollingAreas += 1;+ }+ }+ const requiredCopyLayouts = requiredCopy.map((copy) => {const copyChars = Array.from(String(copy)).filter((char) => !/\\s/u.test(char));const candidates = elements.filter((element) => {const style = getComputedStyle(element);@@ -1139,7 +1170,17 @@ async function renderHtmlSnapshot(projectDirAbs: string, manifest: ImageStudioMawritingMode: getComputedStyle(element).writingMode || '',};});+ return { viewport: { width: innerWidth, height: innerHeight }, scrollingAreas, requiredCopyLayouts };})()`, true), IMAGE_STUDIO_LOAD_TIMEOUT_MS, 'E_IMAGE_STUDIO_READY_TIMEOUT: fonts or local images did not become ready.');+ if (layout.viewport.width !== manifest.canvas.width || layout.viewport.height !== manifest.canvas.height) {+ throw new Error(`E_IMAGE_STUDIO_VIEWPORT_MISMATCH: Expected a ${manifest.canvas.width}x${manifest.canvas.height} canvas viewport; got ${layout.viewport.width}x${layout.viewport.height}. No image was written.`);+ }+ if (layout.scrollingAreas > 0) {+ return { layoutBlockers: [{+ code: 'E_IMAGE_LAYOUT_SCROLLING',+ message: `The image composition has ${layout.scrollingAreas} scrolling area(s). Fit the complete layout inside the declared canvas before taking another snapshot.`,+ }] };+ }const captured = await withTimeout(win.webContents.capturePage(), IMAGE_STUDIO_LOAD_TIMEOUT_MS, 'E_IMAGE_STUDIO_CAPTURE_TIMEOUT: screenshot capture timed out.');const bytes = await normalizeImageStudioSnapshot(captured.toPNG(), manifest.canvas);await fs.mkdir(path.dirname(outputAbsPath), { recursive: true });@@ -1148,7 +1189,7 @@ async function renderHtmlSnapshot(projectDirAbs: string, manifest: ImageStudioMareturn {image: analyzeNativeImage(image),layoutBlockers: requiredCopyLayoutIssues(- Array.isArray(requiredCopyLayouts) ? requiredCopyLayouts : [],+ Array.isArray(layout.requiredCopyLayouts) ? layout.requiredCopyLayouts : [],),};} finally {@@ -1223,6 +1264,9 @@ export async function snapshotImageStudioProject(input: {};}const rendered = await renderHtmlSnapshot(path.resolve(input.projectDirAbs), inspection.manifest, path.resolve(input.outputAbsPath));+ if (!rendered.image) {+ return { ...inspection, ok: false, blockers: [...inspection.blockers, ...rendered.layoutBlockers] };+ }const image = rendered.image;const evidencePath = path.resolve(input.outputAbsPath);const review = rendered.layoutBlockers.lengthdiff --git a/src/main/features/library_smoke.ts b/src/main/features/library_smoke.tsnew file mode 100644index 00000000..7a845a02--- /dev/null+++ b/src/main/features/library_smoke.ts@@ -0,0 +1,101 @@+/** Real packaged Library acceptance, called only by the isolated launch smoke.+ * No embedder transport overrides: this must exercise the production supervisor,+ * unpacked utilityProcess worker, offline model and archive dependency graph.+ */+import * as assert from 'node:assert/strict';+import * as fs from 'node:fs';+import * as path from 'node:path';+import { WS_ROOT, userContextsDir } from '../paths';+import * as users from './users';+import * as projects from './projects';+import * as files from './project_files';+import * as contexts from './contexts';+import * as projectIndex from './project_library_indexer';+import * as globalIndex from './kb_indexer';+import * as kb from './kb_vector';+import * as vectors from './vec_store';+import * as embed from './kb_embed';+import { createLibraryTool } from '../model/core-agent/kb-tools';++function checkVector(vector: number[]): void {+ assert.equal(vector?.length, 512, 'Library embedding dimensions');+ assert.ok(vector.every(Number.isFinite), 'Library embedding must be finite');+ const norm = Math.sqrt(vector.reduce((sum, value) => sum + value * value, 0));+ assert.ok(Math.abs(norm - 1) < 0.01, 'Library embedding must be normalized');+}++export async function runPackagedLibrarySmoke() {+ const marker = String(process.env.ORKAS_PACKAGED_LAUNCH_SMOKE_FILE || '');+ // Refuse to create fixture documents in an ordinary installation, even if+ // someone calls this helper outside the packaged-only IPC handler.+ assert.ok(marker && path.isAbsolute(marker), 'Library smoke requires an isolated launch marker');+ assert.equal(WS_ROOT, path.join(path.dirname(marker), 'workspace'), 'Library smoke requires isolated storage');+ const uid = users.getActiveUserId();+ const name = '资料库验收.md';+ const original = 'Library packaged acceptance: the original recovery code is cobalt-741.';+ const revised = 'Library packaged acceptance: the revised recovery code is amber-852.';+ const globalBody = 'Global Library acceptance: the independent recovery code is violet-963.';+ const work = path.join(WS_ROOT, 'library-smoke-work');+ fs.mkdirSync(work, { recursive: true });+ const seed = path.join(work, 'seed.md');+ fs.writeFileSync(seed, original);+ try {+ const batch = await embed.embedTexts([original, globalBody]);+ assert.equal(batch.length, 2, 'Library worker batch cardinality');+ batch.forEach(checkVector);+ assert.notDeepEqual(batch[0], batch[1], 'Library worker must not return a constant placeholder');+ embed.closeEmbedder();+ checkVector(await embed.embedQuery(original));++ const created = await projects.createProject(uid, 'Packaged Library acceptance');+ assert.ok(created.ok, 'Library smoke project creation');+ const pid = created.project.project_id;+ assert.ok((await files.copyProjectEntryFromPath(uid, pid, seed, name)).ok, 'Library import');+ await projectIndex.drain(uid, pid);+ assert.equal(projectIndex.getFileByPath(uid, pid, name)?.status, 'ready', 'Library saved file must index');+ const projectTool = createLibraryTool({ userId: uid, projectId: pid });+ const readProject = () => projectTool.execute({ action: 'read', path: name, scope: 'project' }, {} as any);+ const initialRead = await readProject();+ assert.ok(!initialRead.isError && initialRead.content.includes(original), 'Library indexed read');+ const search = await projectTool.execute({ action: 'search', query: original, scope: 'project' }, {} as any);+ assert.ok(!search.isError && search.content.includes(name) && search.content.includes('cobalt-741'), 'Library semantic search');+ assert.deepEqual(await files.copyProjectEntryFromPath(uid, pid, seed, name), { ok: false, error: 'target_exists' });+ const retained = await files.readProjectTextFile(uid, pid, name);+ assert.ok(retained.ok === true, 'Library source retained');+ assert.equal(retained.content, original);++ const checkout = path.join(work, '编辑副本.md');+ const checked = await files.checkoutProjectFile(uid, pid, name, checkout);+ assert.ok(checked.ok, 'Library checkout');+ assert.equal(fs.readFileSync(checkout, 'utf8'), original);+ fs.writeFileSync(checkout, revised);+ assert.ok((await files.replaceProjectFileFromPath(uid, pid, checkout, name, checked.revision)).ok, 'Library revision replacement');+ await projectIndex.drain(uid, pid);+ vectors.closeAllVecStores();+ const updatedRead = await readProject();+ assert.ok(!updatedRead.isError && updatedRead.content.includes(revised) && !updatedRead.content.includes(original), 'Library reopened current chunks');+ assert.equal((await files.replaceProjectFileFromPath(uid, pid, seed, name, checked.revision)).ok, false, 'Library stale revision protection');+ const current = await files.readProjectTextFile(uid, pid, name);+ assert.ok(current.ok === true, 'Library current source retained');+ assert.equal(current.content, revised);++ fs.writeFileSync(seed, globalBody);+ fs.mkdirSync(userContextsDir(uid), { recursive: true });+ assert.ok(contexts.copyContextEntryFromPath(seed, name, uid).ok, 'Global Library import');+ await globalIndex.drain(uid);+ assert.equal(kb.getFileByPath(uid, name)?.status, 'ready', 'Global Library readiness');+ const globalTool = createLibraryTool({ userId: uid });+ const globalSearch = await globalTool.execute({ action: 'search', query: globalBody }, {} as any);+ assert.ok(!globalSearch.isError && globalSearch.content.includes(name) && globalSearch.content.includes('violet-963'), 'Global Library semantic search');+ vectors.closeAllVecStores();+ const globalRead = await globalTool.execute({ action: 'read', path: name }, {} as any);+ assert.ok(!globalRead.isError && globalRead.content.includes(globalBody) && !globalRead.content.includes(revised), 'Global Library reopened read');+ const scopedRead = await readProject();+ assert.ok(!scopedRead.isError && scopedRead.content.includes(revised) && !scopedRead.content.includes(globalBody), 'Library scope isolation');+ return { embeddingDimensions: 512, workerRespawn: true, projectReady: true, projectSearchRead: true,+ revisionPersisted: true, staleRevisionRejected: true, globalSearchRead: true, scopeIsolated: true };+ } finally {+ embed.closeEmbedder();+ vectors.closeAllVecStores();+ }+}diff --git a/src/main/features/search/index.ts b/src/main/features/search/index.tsindex 76d41832..b1004b8c 100644--- a/src/main/features/search/index.ts+++ b/src/main/features/search/index.ts@@ -54,6 +54,7 @@ export {upsertContext, dropContext,indexChatMessage,dropChatConversation,+ reindexChatConversation,reconcileContextsIndex,invalidateContextsIndex,flushAll,@@ -540,9 +541,21 @@ export async function searchChats(return (await searchChatsWithStatus(userId, query, options)).results;}-/** Cheap coverage-only IPC path: no source bodies, embeddings or rebuild. */-export async function searchIndexStatus(userId: string): Promise<{ chat_index_complete: boolean }> {- return { chat_index_complete: indexer.isChatsIndexTrusted(userId) || await indexer.isChatsIndexCurrent(userId) };+/** Cheap coverage-only IPC path: no source bodies, embeddings or rebuild.+ * An unverified index schedules its idle repair here, so opening search starts+ * the catch-up instead of waiting for a typed query. `chat_index_building` is+ * true only until the account's first full build completes: after that an+ * unverified index can lack at most the catch-up work, which the search UI+ * does not announce. `chat_index_complete` keeps its verified meaning for the+ * history tools that report coverage. */+export async function searchIndexStatus(+ userId: string,+): Promise<{ chat_index_complete: boolean; chat_index_building: boolean }> {+ if (indexer.isChatsIndexTrusted(userId) || await indexer.isChatsIndexCurrent(userId)) {+ return { chat_index_complete: true, chat_index_building: false };+ }+ indexer.scheduleChatIndexRepair(userId);+ return { chat_index_complete: false, chat_index_building: !chatStore.hasCompletedRebuild(userId) };}/** Query-local index status: a scheduled repair must not turn a partial miss@@ -551,17 +564,18 @@ export async function searchChatsWithStatus(userId: string,query: string,options: SearchChatsOptions = {},-): Promise<{ results: SearchResult[]; indexComplete: boolean }> {+): Promise<{ results: SearchResult[]; indexComplete: boolean; indexBuilding: boolean }> {const q = (query || '').trim();- if (!q) return { results: [], indexComplete: true };+ if (!q) return { results: [], indexComplete: true, indexBuilding: false };// Appends hand their upsert to a deferred chain so a send is not held up by// the index; a reader pays that cost instead, and only when it searches.await indexer.drainDeferredChatWrites(userId);- // Cold and partial indexes use the same background path. Searching must- // never inherit a history-wide rebuild, including during first migration.- let indexComplete = (await searchIndexStatus(userId)).chat_index_complete;- if (!indexComplete) indexer.scheduleChatIndexRepair(userId);+ // Cold and partial indexes use the same background path (the status check+ // schedules it). Searching must never inherit a history-wide rebuild,+ // including during first migration.+ const status = await searchIndexStatus(userId);+ let indexComplete = status.chat_index_complete;const tokens = tokenize(q);// Normalize BM25 against the currently available corpus, including a// partially rebuilt index.@@ -650,7 +664,7 @@ export async function searchChatsWithStatus(const { visible: _visible, ...snippet } = projected || { visible: false, snippet: '' };return [{ ...result, ...snippet }];});- return { results, indexComplete };+ return { results, indexComplete, indexBuilding: status.chat_index_building };}// ── Agent / skill body search (in-memory, no persistent index) ──────────@@ -947,6 +961,7 @@ export async function searchAll(total?: number;degradation_code?: SearchDegradationCode | 'multiple';chat_index_complete?: boolean;+ chat_index_building?: boolean;}> {const q = (query || '').trim();if (!q) return { results: [] };@@ -954,6 +969,7 @@ export async function searchAll(const buckets: SearchResult[] = [];const degradations = new Set<SearchDegradationCode>();let chatIndexComplete: boolean | undefined;+ let chatIndexBuilding: boolean | undefined;const tasks: Array<Promise<void>> = [];if (scope === 'all' || scope === 'context') {tasks.push(searchContexts(q, userId, requestedLimit).then((r) => { buckets.push(...r); }));@@ -972,6 +988,7 @@ export async function searchAll(tasks.push(searchChatsWithStatus(userId, q, { limit: requestedLimit }).then((page) => {buckets.push(...page.results);chatIndexComplete = page.indexComplete;+ chatIndexBuilding = page.indexBuilding;}));}if (scope === 'all' || scope === 'agent') {@@ -989,6 +1006,7 @@ export async function searchAll(results: _limitSearchResults(merged, requestedLimit, scope),total: merged.length,...(chatIndexComplete !== undefined ? { chat_index_complete: chatIndexComplete } : {}),+ ...(chatIndexBuilding !== undefined ? { chat_index_building: chatIndexBuilding } : {}),...(degradationCode ? { degradation_code: degradationCode } : {}),};}diff --git a/src/main/features/search/indexer.ts b/src/main/features/search/indexer.tsindex 575e2aae..7a60195a 100644--- a/src/main/features/search/indexer.ts+++ b/src/main/features/search/indexer.ts@@ -922,7 +922,41 @@ export function dropChatConversation(userId: string, cid: string): Promise<void>scheduleChatIndexRepair(userId, 1_000);return Promise.resolve();}- return _queueChatWrite(userId, () => _chatWorker(userId).deleteConversation(cid));+ return _queueChatWrite(userId, async () => {+ await _chatWorker(userId).deleteConversation(cid);+ // Its documents and watermark are gone, so no repair has anything left to+ // re-read for it; a stale mark would only keep a clean quit from trusting+ // the index again.+ if (!_chatReconcileRuns.has(userId)) _dirtyChats.get(userId)?.delete(cid);+ });+}++/** Re-read one conversation after an in-place rewrite of existing records+ * (message tombstones). Appends use indexChatMessage; this keeps an otherwise+ * current index trusted instead of leaving deleted text searchable until the+ * next full repair. Any failure falls back to invalidation and idle repair. */+export function reindexChatConversation(userId: string, cid: string): Promise<void> {+ if (_chatReconcileRuns.has(userId) || _isMigrating(userId)) {+ _noteChatChange(userId, cid);+ _invalidatedChats.add(userId);+ _currentChatIndexes.delete(userId);+ scheduleChatIndexRepair(userId, 1_000);+ return Promise.resolve();+ }+ return _queueChatWrite(userId, async () => {+ const file = _chatJsonlFile(userId, cid);+ const st = await fsp.stat(file).catch(() => undefined);+ const worker = _chatWorker(userId);+ const rebuilt = !!st && await _reindexChatFile(+ userId, { fileKey: cid, file, mtime: st.mtimeMs, size: st.size }, () => _closing, worker,+ );+ if (rebuilt) return;+ _markChatDirty(userId, cid);+ _invalidatedChats.add(userId);+ _currentChatIndexes.delete(userId);+ await worker.invalidate(cid);+ scheduleChatIndexRepair(userId);+ });}// ── Internal handle for query-side reads ─────────────────────────────────diff --git a/src/main/features/tts.ts b/src/main/features/tts.tsindex 750b348f..c9652d67 100644--- a/src/main/features/tts.ts+++ b/src/main/features/tts.ts@@ -4,8 +4,10 @@* interface:** - 'openai-compatible' (PRIMARY): BYO user TTS API in the OpenAI- * `/audio/speech` shape — ElevenLabs / OpenAI / any compatible gateway.+ * `/audio/speech` shape — OpenAI / any compatible gateway.* Config = a saved `TtsProfile` (base url, key, model, voice).+ * - 'elevenlabs': native `/text-to-speech/:voice_id`, selected only by the+ * saved profile's explicit provider id; shares the audio HTTP lifecycle.* - 'doubao': Volcengine V3 TTS (`/api/v3/tts/unidirectional`). NOT OpenAI-* compatible — `X-Api-Key` + `X-Api-Resource-Id` auth (the API-key console* method) and an NDJSON stream of base64 audio chunks. Routed by@@ -356,32 +358,38 @@ function combineSignal(signal: AbortSignal | undefined, timeoutMs: number): Aborreturn signal ? AbortSignal.any([signal, timeout]) : timeout;}-// ── Backend: OpenAI-compatible /audio/speech (BYO) ──────────────────────────+// ── Backends: binary-audio HTTP (OpenAI-compatible / ElevenLabs BYO) ────────-class OpenAICompatibleTtsBackend implements TtsBackend {- readonly id = 'openai-compatible';- constructor(private readonly profile: {- baseUrl: string;- apiKey: string;- model: string;- provider?: string;- voice?: string;- format?: string;- label?: string;- }) {}+class HttpAudioTtsBackend implements TtsBackend {+ readonly id: string;+ constructor(private readonly profile: { provider?: string; baseUrl: string; apiKey: string; model: string; voice?: string; format?: string; label?: string }) {+ this.id = profile.provider === 'elevenlabs' ? 'elevenlabs' : 'openai-compatible';+ }async synthesize(p: TtsParams): Promise<TtsResult> {const base = this.profile.baseUrl.replace(/\/+$/, '');- const url = `${base}/audio/speech`;const voice = p.voice || this.profile.voice;const format = (p.format || this.profile.format || 'mp3').toLowerCase();- const body: Record<string, unknown> = {+ let url = `${base}/audio/speech`;+ let headers: Record<string, string> = { Authorization: `Bearer ${this.profile.apiKey}`, 'Content-Type': 'application/json' };+ let body: Record<string, unknown> = {model: this.profile.model,input: p.text,...(voice ? { voice } : {}),response_format: format,...(typeof p.speed === 'number' ? { speed: p.speed } : {}),};+ if (this.id === 'elevenlabs') {+ // Native contract: https://elevenlabs.io/docs/api-reference/text-to-speech/convert+ // Request PCM 24k for WAV; 44.1k PCM/WAV requires a Pro subscription.+ const codecs: Record<string, string> = { mp3: 'mp3_44100_128', wav: 'pcm_24000', pcm: 'pcm_24000', opus: 'opus_48000_128' };+ if (!voice || !Object.hasOwn(codecs, format) || (p.speed !== undefined && (!Number.isFinite(p.speed) || p.speed < 0.7 || p.speed > 1.2))) {+ return { ok: false, errorCode: 'E_TTS_ARG', message: 'ElevenLabs requires a voice id, mp3/wav/pcm/opus output, and speed between 0.7 and 1.2.', requestDisposition: 'rejected_preflight', chargeStatus: 'not_charged', retryPolicy: 'safe_after_plan_fix' };+ }+ url = `${base}/text-to-speech/${encodeURIComponent(voice)}?${new URLSearchParams({ output_format: codecs[format] })}`;+ headers = { 'xi-api-key': this.profile.apiKey, 'Content-Type': 'application/json' };+ body = { text: p.text, model_id: this.profile.model, ...(p.speed !== undefined ? { voice_settings: { speed: p.speed } } : {}) };+ }p.onProgress?.({ phase: 'tts.request', message: `requesting speech from ${this.profile.label || base}` });let resp: Response;@@ -389,11 +397,8 @@ class OpenAICompatibleTtsBackend implements TtsBackend {resp = await fetch(url, {method: 'POST',headers: {- 'Authorization': `Bearer ${this.profile.apiKey}`,- 'Content-Type': 'application/json',- ...(this.profile.provider === ORKAS_API_PROVIDER- ? orkasApiUsageHeaders(p.usageContext)- : {}),+ ...headers,+ ...(this.profile.provider === ORKAS_API_PROVIDER ? orkasApiUsageHeaders(p.usageContext) : {}),},body: JSON.stringify(body),signal: combineSignal(p.signal, TTS_TIMEOUT_MS),@@ -425,7 +430,8 @@ class OpenAICompatibleTtsBackend implements TtsBackend {const buf = Buffer.from(await resp.arrayBuffer());if (buf.length > MAX_TTS_BYTES) return sentFailure('E_TTS_TOO_LARGE', 'The speech response was too large and was not saved.');if (!buf.length) return sentFailure('E_TTS_EMPTY', 'The speech provider returned empty audio.');- return persistSynthesizedAudio(this.id, p.outputAbsPath, buf);+ const audio = this.id === 'elevenlabs' && format === 'wav' ? wrapPcm16MonoWav(buf) : buf;+ return persistSynthesizedAudio(this.id, p.outputAbsPath, audio);}}@@ -604,7 +610,7 @@ function resolveTtsBackend(routeRef?: string): TtsBackend {const envKey = process.env.ORKAS_TTS_API_KEY;const envModel = process.env.ORKAS_TTS_MODEL;if (envBase && envKey && envModel && (!routeRef || routeRef === 'env:tts')) {- return new OpenAICompatibleTtsBackend({+ return new HttpAudioTtsBackend({baseUrl: envBase, apiKey: envKey, model: envModel,...(process.env.ORKAS_TTS_VOICE ? { voice: process.env.ORKAS_TTS_VOICE } : {}),...(process.env.ORKAS_TTS_FORMAT ? { format: process.env.ORKAS_TTS_FORMAT } : {}),@@ -624,7 +630,7 @@ function resolveTtsBackend(routeRef?: string): TtsBackend {label: p.label,});}- return new OpenAICompatibleTtsBackend(p);+ return new HttpAudioTtsBackend(p);}return new UnconfiguredTtsBackend();}@@ -643,6 +649,10 @@ export function configuredTtsBackendId(): string {}export async function generateSpeech(p: TtsParams): Promise<TtsResult> {+ return generateSpeechWithProvider(p);+}++async function generateSpeechWithProvider(p: TtsParams): Promise<TtsResult> {if (!p.text.trim()) return { ok: false, errorCode: 'E_TTS_ARG', message: 'text is required' };const resolved = await resolveTtsSelection({...(p.routeRef ? { routeRef: p.routeRef } : {}),diff --git a/src/main/features/video_production_control.ts b/src/main/features/video_production_control.tsindex 0d06e974..a7b907c7 100644--- a/src/main/features/video_production_control.ts+++ b/src/main/features/video_production_control.ts@@ -88,7 +88,9 @@ export type VideoProductionGenerationTransaction = {intent_signature?: string;output_path: string;reserved_output_paths?: string[];- status: 'pending' | 'completed' | 'failed';+ /** `released`: ended before any provider request was sent; kept only in+ * history and never consumes the paid generation confirmation. */+ status: 'pending' | 'completed' | 'failed' | 'released';started_at: string;updated_at: string;completed_at?: string;@@ -1283,6 +1285,39 @@ export async function beginVideoProductionGeneration(input: {});}+/** End a pending attempt that failed before any provider request was sent+ * (for example a reference upload). Nothing billable happened, so the slot is+ * freed and the same paid generation confirmation covers the retry; the+ * released attempt stays in history with its error code. Recording it as+ * `failed` demanded a new paid confirmation for a request that never left. */+export async function releaseVideoProductionGeneration(input: {+ statePath: string;+ planPath: string;+ transactionId: string;+ segmentId: string;+ kind: VideoProductionGenerationKind;+ errorCode?: string;+}): Promise<VideoProductionGenerationTransaction> {+ const key = transactionKey(input.kind, input.segmentId);+ let released: VideoProductionGenerationTransaction | undefined;+ await updateState(input.statePath, input.planPath, (next) => {+ const transaction = next.transactions[key];+ if (!transaction || transaction.transaction_id !== input.transactionId || transaction.status !== 'pending') {+ throw new Error('E_VIDEO_PRODUCTION_GENERATION_TRANSACTION_STALE: transaction no longer owns this segment');+ }+ released = {+ ...transaction,+ status: 'released',+ updated_at: new Date().toISOString(),+ ...(input.errorCode ? { error_code: input.errorCode } : {}),+ };+ next.transaction_history = [...next.transaction_history, released].slice(-50);+ delete next.transactions[key];+ });+ if (!released) throw new Error('E_VIDEO_PRODUCTION_GENERATION_TRANSACTION_STALE');+ return released;+}+export async function finishVideoProductionGeneration(input: {statePath: string;planPath: string;diff --git a/src/main/model/core-agent/video-studio-tool.ts b/src/main/model/core-agent/video-studio-tool.tsindex 7b5c9d63..2104cc65 100644--- a/src/main/model/core-agent/video-studio-tool.ts+++ b/src/main/model/core-agent/video-studio-tool.ts@@ -554,6 +554,24 @@ function missingUserTurnGateResult(};}+/** Fields of a Gate D refusal for a draft rendered in the current turn: the+ * user has not seen it, so the next step is theirs (`outcome: need_user`). */+function draftRenderedThisTurnStop(): Record<string, unknown> {+ return {+ current_review_status: 'pending',+ requires_user_decision: true,+ user_reconfirmation_required: false,+ next_step_owner: 'user',+ interaction_required: true,+ interaction_mode: 'request_gate_decision',+ form_policy: 'plain_message_no_form',+ automatic_recovery_expected: false,+ same_turn_continuation_required: false,+ billable_request_sent: false,+ next_action: 'show_current_artifact_and_request_user_decision',+ };+}+/*** Ops whose behavior depends on skill-side protocol knowledge (gate decisions,* evidence shapes, review verdicts). A skill generation that predates the host@@ -4640,6 +4658,84 @@ export function parentCompositionAudioFault(rawManifest: unknown): string {return '';}+/** composition.approve_plan inherits a parent approval only for a real AUTO+ * child: both plan_path and segment_id, plan_path an approved production plan+ * outside this composition, and segment_id one of its compose segments.+ * Identify that subject before any child check. On 2026-09-20 a standalone+ * composition passed its own manifest as plan_path and got three unrelated+ * child refusals in a row ("must remain silent", "both required", "plan.segments+ * must be a non-empty array") before the model found the standalone call. */+async function autoChildSubjectRefusal(input: {+ op: string;+ parentPlanRaw: string;+ parentSegmentId: string;+ parentPlanAbs: string;+ parentPlanAllowed: boolean;+ compositionDirAbs: string;+ userId: string;+ projectId?: string;+}): Promise<Record<string, unknown> | null> {+ const standalone = 'For this composition\'s own plan, omit plan_path and segment_id; its approval is the user\'s reply to the plan you displayed.';+ const refusal = (errorCode: string, message: string, extra: Record<string, unknown> = {}) => ({+ ok: false,+ op: input.op,+ errorCode,+ message,+ ...extra,+ requires_user_decision: false,+ user_reconfirmation_required: false,+ next_step_owner: 'agent',+ same_turn_continuation_required: true,+ interaction_required: false,+ billable_request_sent: false,+ next_action: 'retry_composition.approve_plan_as_standalone_or_with_a_valid_parent_binding',+ });+ if (!input.parentPlanRaw || !input.parentSegmentId) {+ return refusal(+ 'E_PARENT_COMPOSITION_BINDING_INCOMPLETE',+ `AUTO inheritance needs both plan_path (the approved parent production plan) and segment_id (its compose segment); this call has only ${input.parentPlanRaw ? 'plan_path' : 'segment_id'}. ${standalone}`,+ );+ }+ if (!input.parentPlanAllowed) {+ return refusal('E_PATH_OUT_OF_SCOPE', `plan_path is outside scope: ${input.parentPlanAbs}`);+ }+ const relative = path.relative(input.compositionDirAbs, input.parentPlanAbs);+ if (!relative || (!relative.startsWith('..') && !path.isAbsolute(relative))) {+ return refusal(+ 'E_PARENT_COMPOSITION_BINDING_SELF',+ `plan_path ${input.parentPlanRaw} is inside composition_dir, so it is this composition's own file, not a parent production plan. ${standalone}`,+ );+ }+ let parent: Awaited<ReturnType<typeof validateVideoProductionPlanApproval>>;+ try {+ parent = await validateVideoProductionPlanApproval({+ statePath: videoProductionControlStatePath({+ userId: input.userId,+ ...(input.projectId ? { projectId: input.projectId } : {}),+ planPath: input.parentPlanAbs,+ }),+ planPath: input.parentPlanAbs,+ });+ } catch (err) {+ return refusal(+ 'E_PARENT_COMPOSITION_BINDING_UNAPPROVED',+ `plan_path ${input.parentPlanRaw} is not an approved production plan (${(err as Error).message || String(err)}). AUTO inheritance reuses the parent's production.approve_plan approval. ${standalone}`,+ );+ }+ const segments = Array.isArray(parent.identity.plan.segments)+ ? parent.identity.plan.segments.filter(isIntentRecord)+ : [];+ const composeIds = segments.filter((segment) => segment.source === 'compose').map((segment) => String(segment.id));+ if (!segments.some((segment) => segment.id === input.parentSegmentId)) {+ return refusal(+ 'E_PARENT_COMPOSITION_SEGMENT_INVALID',+ `The approved parent EDL has no compose segment named ${input.parentSegmentId}. Its compose segments are: ${composeIds.join(', ') || 'none'}.`,+ { compose_segment_ids: composeIds },+ );+ }+ return null;+}+async function validateParentCompositionBinding(input: {parentIdentity: VideoProductionPlanIdentity;segmentId: string;@@ -9217,9 +9313,9 @@ export function createVideoStudioTool(opts: VideoStudioToolOpts): AgentTool {enum: [...OPS],description: 'Keyframe preview must end the current turn; draft resumes after a later real user reply. No preview-approval op. Retry exhaustion allows one fresh turn to approve one narration materialize call; never reuse an old turn.',},- plan_path: { type: 'string', description: 'Canonical project/plan.json for production.* operations or AUTO child-composition production-plan inheritance.' },+ plan_path: { type: 'string', description: 'Canonical project/plan.json for production.* operations. composition.* operations take it only with segment_id, to inherit that approved parent plan\'s compose segment; omit both for a standalone composition.' },delivered_video_path: { type: 'string', description: 'Final video for production.status. Direct model output receives a readable-video check and advisory spec differences; locally assembled output also checks timing, canvas, narration, loudness, and captions.' },- segment_id: { type: 'string', description: 'Parent EDL segment id for AUTO child-composition production-plan inheritance.' },+ segment_id: { type: 'string', description: 'Parent EDL compose segment id for AUTO child-composition inheritance; requires plan_path.' },composition_dir: { type: 'string', description: 'Directory containing composition-manifest.json and generated index.html; prepare may run before index.html exists.' },decision_evidence: {type: 'object',@@ -9832,6 +9928,26 @@ export function createVideoStudioTool(opts: VideoStudioToolOpts): AgentTool {}}}+ // Whether this approval is an AUTO child is answered before anything+ // is created or checked as one (including the child directory below).+ if (op === 'composition.approve_plan') {+ const subjectSegmentId = String(input.segment_id || '').trim();+ const subjectPlanRaw = String(input.plan_path || '').trim();+ if (subjectSegmentId || subjectPlanRaw) {+ const subjectPlanAbs = subjectPlanRaw ? resolvePath(ctx, opts, subjectPlanRaw, roots) : '';+ const subjectRefusal = await autoChildSubjectRefusal({+ op,+ parentPlanRaw: subjectPlanRaw,+ parentSegmentId: subjectSegmentId,+ parentPlanAbs: subjectPlanAbs,+ parentPlanAllowed: !!subjectPlanAbs && isPathAllowed(subjectPlanAbs, roots),+ compositionDirAbs,+ userId: opts.userId,+ ...(opts.projectId ? { projectId: opts.projectId } : {}),+ });+ if (subjectRefusal) return { content: resultContent(subjectRefusal), isError: true } as ToolResult;+ }+ }const dirCheck = await inspectInputDir(compositionDirAbs);const standaloneMissingStatus = op === 'composition.status'&& !dirCheck.exists@@ -11662,6 +11778,25 @@ export function createVideoStudioTool(opts: VideoStudioToolOpts): AgentTool {},});}+ if (approval.errorCode === 'E_GATE_D_APPROVAL_REQUIRED') {+ // The draft was rendered in this very turn, so the user has not+ // seen it and nothing here can confirm it: a stop on the user,+ // like the other gate refusals. As plain text it carried no+ // outcome, so the turn ended as an ordinary completion (2026-10-07+ // live run): the user's confirmation opened a new task row, and a+ // task waiting on this one could start from the unconfirmed draft.+ return reviewToolResult({+ opts,+ state: stateBefore,+ result: {+ ok: false,+ op,+ errorCode: approval.errorCode,+ message: approval.message,+ ...draftRenderedThisTurnStop(),+ },+ });+ }return { content: `${approval.errorCode}: ${approval.message}`, isError: true } as ToolResult;}return {@@ -11815,11 +11950,18 @@ export function createVideoStudioTool(opts: VideoStudioToolOpts): AgentTool {const gate = await validateVideoStudioGate(gateStatePath, 'draft', compositionDirAbs, opts.turnId || '');if (gate.ok === false) {const currentState = await readVideoProductionState(gateStatePath, compositionDirAbs);+ // An unconfirmed draft from an earlier turn may be confirmed by the+ // current message (approve it, then export); one rendered in this+ // turn has not been seen yet, so the user owns the next step.+ const unseenDraft = gate.errorCode === 'E_GATE_D_APPROVAL_REQUIRED'+ && !!opts.turnId+ && currentState.draft?.turn_id === opts.turnId;const blockedResult = {ok: false,op,errorCode: gate.errorCode,message: gate.message,+ ...(unseenDraft ? draftRenderedThisTurnStop() : {}),...(currentState.current_candidate? { current_candidate: currentState.current_candidate }: {}),diff --git a/src/main/util/sharp-runtime.ts b/src/main/util/sharp-runtime.tsindex 9647e468..d802e64e 100644--- a/src/main/util/sharp-runtime.ts+++ b/src/main/util/sharp-runtime.ts@@ -1,5 +1,5 @@import * as path from 'node:path';-import type { Metadata, OutputInfo, SharpOptions, PngOptions, JpegOptions, WebpOptions } from 'sharp';+import type { Metadata, OutputInfo, SharpOptions, PngOptions, JpegOptions, WebpOptions, ResizeOptions, Region } from 'sharp';import { PC_ROOT } from '../paths';import { createLogger } from '../logger';import { bundledNodeExecutable } from './bundled-runtime';@@ -7,7 +7,9 @@ import { bundledNodeExecutable } from './bundled-runtime';interface ImageRequestOptions extends Pick<SharpOptions, 'failOn' | 'limitInputPixels' | 'density'> {format?: 'png' | 'jpeg' | 'webp';encodeOptions?: PngOptions | JpegOptions | WebpOptions;- resize?: { width: number; height: number; fit: 'fill' };+ resize?: Pick<ResizeOptions, 'width' | 'height' | 'fit' | 'withoutEnlargement'>;+ composite?: Array<{ input: Buffer }>;+ extract?: Region;}interface ImageClient {diff --git a/test/e2e/image_studio_e2e_capture.spec.ts b/test/e2e/image_studio_e2e_capture.spec.tsnew file mode 100644index 00000000..e13c6416--- /dev/null+++ b/test/e2e/image_studio_e2e_capture.spec.ts@@ -0,0 +1,135 @@+import { existsSync, readFileSync } from 'node:fs';+import path from 'node:path';+import sharp from 'sharp';+import { test } from './fixtures/web-app-eval';+import { expect } from './fixtures/orkas';++const modulePath = path.resolve(__dirname, '../../src/main/features/image_studio.ts');+const scores = { intent_alignment: 90, composition: 90, craft: 90, text_legibility: 90, defect_freedom: 90, specificity: 90 };++function createPoster(orkas: { createWorkspaceFile(name: string, content: string): string }, name: string, content: string, height = 1080) {+ const entry = orkas.createWorkspaceFile(`${name}/index.html`, `<!doctype html><html><head><style>+ html,body{margin:0}main{position:relative;width:1080px;height:${height}px;background:#f6efdc}+ p{margin:0}svg{position:absolute;right:0;bottom:0;width:40px;height:40px}+ </style></head><body><main><p>City Coffee Fest</p>${content}+ <svg xmlns="http://www.w3.org/2000/svg"><rect width="40" height="40" fill="#2468ae"/></svg>+ <div style="position:absolute;left:0;bottom:0;width:40px;height:40px;background:#b82e37"></div>+ </main></body></html>`);+ orkas.createWorkspaceFile(`${name}/image-manifest.json`, JSON.stringify({+ schema_version: 1, route: 'compose', entry: 'index.html', canvas: { width: 1080, height },+ brief: { purpose: 'Event poster', audience: 'Coffee lovers', required_copy: ['City Coffee Fest'], must_include: [], must_avoid: [] },+ art_direction: { subject_world: 'Coffee festival', one_job: 'Announce the event', visual_tradition: 'Editorial poster',+ composition: 'Title and illustration', signature_device: 'Coffee cup', typography: 'Sans serif', color_light_material: 'Cream paper' },+ generation_budget: { max_calls: 0 },+ }));+ return { projectDirAbs: path.dirname(entry), outputAbsPath: path.join(path.dirname(entry), 'evidence.png'),+ stateAbsPath: path.join(path.dirname(entry), 'state.json') };+}++test('exports all poster corners after the host initially constrains the capture window', async ({ sdkOrkas: orkas }) => {+ // Real Chromium pixels are the oracle. The event simulates work-area clamping+ // without supplying a mock screenshot or the expected rendered answer.+ // Native screenshots apply the display's color conversion before production.+ // Render an independent small reference rather than assume literal RGB bytes.+ const referencePng = await orkas.electronApp!.evaluate(async ({ BrowserWindow }) => {+ const win = new BrowserWindow({ width: 120, height: 60, useContentSize: true, show: false,+ backgroundColor: '#00000000', webPreferences: { sandbox: true, contextIsolation: true, backgroundThrottling: false } });+ try {+ await win.loadURL('data:text/html,' + encodeURIComponent(`<!doctype html><style>+ html,body{margin:0}div{position:absolute;top:0;width:40px;height:40px}+ </style><div style="left:0;background:#b82e37"></div><div style="left:60px;background:#2468ae"></div>`));+ return (await win.webContents.capturePage()).toPNG().toString('base64');+ } finally { win.destroy(); }+ });+ const reference = await sharp(Buffer.from(referencePng, 'base64')).ensureAlpha().raw().toBuffer({ resolveWithObject: true });+ const referencePixel = (x: number) => {+ const px = Math.floor(x * reference.info.width / 120), py = Math.floor(20 * reference.info.height / 60);+ return [...reference.data.subarray((py * reference.info.width + px) * 4, (py * reference.info.width + px) * 4 + 4)];+ };+ expect(referencePixel(20)[3]).toBe(255);+ expect(referencePixel(80)[3]).toBe(255);+ for (const height of [1080, 2160]) {+ const input = createPoster(orkas, `poster-${height}`, '', height);+ const output = path.join(input.projectDirAbs, 'delivery.png');+ const result = await orkas.electronApp!.evaluate(async ({ app, BrowserWindow }, args) => {+ const studio = (process as any).mainModule.require(args.modulePath);+ const clamp = (_event: unknown, win: Electron.BrowserWindow) => win.setContentSize(640, 480);+ const before = BrowserWindow.getAllWindows().length;+ app.on('browser-window-created', clamp);+ try {+ const inspection = await studio.snapshotImageStudioProject(args.input);+ if (inspection.ok) {+ await studio.submitImageStudioDesignReview({ stateAbsPath: args.input.stateAbsPath,+ evidenceAbsPath: args.input.outputAbsPath, verdict: 'passed', scope: 'Complete poster', findings: [], qualityScores: args.scores });+ await studio.exportImageStudioProject({ stateAbsPath: args.input.stateAbsPath, outputAbsPath: args.output, format: 'png' });+ }+ return { ok: inspection.ok, blockers: inspection.blockers, remaining: BrowserWindow.getAllWindows().length - before };+ } finally { app.removeListener('browser-window-created', clamp); }+ }, { modulePath, input, output, scores });+ expect(result).toEqual({ ok: true, blockers: [], remaining: 0 });+ const decoded = await sharp(readFileSync(output)).ensureAlpha().raw().toBuffer({ resolveWithObject: true });+ expect(decoded.info).toMatchObject({ width: 1080, height, channels: 4 });+ const pixel = (x: number, y: number) => [...decoded.data.subarray((y * 1080 + x) * 4, (y * 1080 + x) * 4 + 4)];+ expect(pixel(20, height - 20)).toEqual(referencePixel(20));+ expect(pixel(1060, height - 20)).toEqual(referencePixel(80));+ }+});++test('blocks page and nested scrolling before export and succeeds after the layout is repaired', async ({ sdkOrkas: orkas }) => {+ for (const [name, content] of [+ ['page', '<div style="position:absolute;top:1070px;width:1120px;height:100px">Event details</div>'],+ ['nested', '<section style="width:200px;height:100px;overflow:auto"><div style="width:300px;height:200px">Event details</div></section>'],+ ['forced', '<section style="width:200px;height:100px;overflow:scroll">Event details</section>'],+ ]) {+ const input = createPoster(orkas, `overflow-${name}`, content);+ const result = await orkas.electronApp!.evaluate(async (_, args) => {+ const studio = (process as any).mainModule.require(args.modulePath);+ const inspection = await studio.snapshotImageStudioProject(args.input);+ let reviewError = '';+ try {+ await studio.submitImageStudioDesignReview({ stateAbsPath: args.input.stateAbsPath,+ evidenceAbsPath: args.input.outputAbsPath, verdict: 'passed', scope: 'Complete poster', findings: [], qualityScores: args.scores });+ } catch (error) { reviewError = String(error); }+ return { ok: inspection.ok, blockers: inspection.blockers, reviewError };+ }, { modulePath, input, scores });+ expect(result.ok).toBe(false);+ expect(result.blockers).toEqual(expect.arrayContaining([expect.objectContaining({ code: 'E_IMAGE_LAYOUT_SCROLLING' })]));+ expect(result.reviewError).toContain('E_IMAGE_REVIEW_EVIDENCE_REQUIRED');+ expect(existsSync(input.outputAbsPath)).toBe(false);+ expect(existsSync(input.stateAbsPath)).toBe(false);+ // Intentional cropping of decorative bleed is valid; scrollable deliverables+ // are not. A repaired layout must be capturable without restarting the app.+ const repaired = createPoster(orkas, `overflow-${name}`, '<section style="width:200px;height:100px;overflow:hidden"><div style="width:300px;height:200px">Decoration</div></section>');+ const inspection = await orkas.electronApp!.evaluate(async (_, args) =>+ (process as any).mainModule.require(args.modulePath).snapshotImageStudioProject(args.input), { modulePath, input: repaired });+ expect(inspection.ok).toBe(true);+ }+});++test('rejects an unrecoverable viewport mismatch without replacing existing evidence', async ({ sdkOrkas: orkas }) => {+ const input = createPoster(orkas, 'unresizable', '');+ const good = await orkas.electronApp!.evaluate(async (_, args) =>+ (process as any).mainModule.require(args.modulePath).snapshotImageStudioProject(args.input), { modulePath, input });+ expect(good.ok).toBe(true);+ const imageBefore = readFileSync(input.outputAbsPath);+ const stateBefore = readFileSync(input.stateAbsPath);+ const result = await orkas.electronApp!.evaluate(async ({ app, BrowserWindow }, args) => {+ const studio = (process as any).mainModule.require(args.modulePath);+ const constrain = (_event: unknown, win: Electron.BrowserWindow) => {+ win.setContentSize(640, 480);+ win.setContentSize = () => {};+ };+ const before = BrowserWindow.getAllWindows().length;+ app.on('browser-window-created', constrain);+ try {+ await studio.snapshotImageStudioProject(args.input);+ return { error: '', remaining: BrowserWindow.getAllWindows().length - before };+ } catch (error) {+ return { error: String(error), remaining: BrowserWindow.getAllWindows().length - before };+ } finally { app.removeListener('browser-window-created', constrain); }+ }, { modulePath, input });+ expect(result.error).toContain('E_IMAGE_STUDIO_VIEWPORT_MISMATCH');+ expect(result.remaining).toBe(0);+ expect(readFileSync(input.outputAbsPath)).toEqual(imageBefore);+ expect(readFileSync(input.stateAbsPath)).toEqual(stateBefore);+});diff --git a/test/fixtures/kb/embed-worker-request.cjs b/test/fixtures/kb/embed-worker-request.cjsnew file mode 100644index 00000000..ab244a0e--- /dev/null+++ b/test/fixtures/kb/embed-worker-request.cjs@@ -0,0 +1,35 @@+// Exercise the worker protocol with fixture-only dependencies. An isolated+// process also releases Electron's native ASAR cache before fixture cleanup.+const fs = require('node:fs');+const path = require('node:path');+const vm = require('node:vm');+const assert = require('node:assert/strict');+const { createRequire } = require('node:module');++async function requestWorker(sourceFile, workerDir, modelDir) {+ let receive;+ let reply;+ const response = new Promise(resolve => { reply = resolve; });+ const timer = setTimeout(() => reply({ timedOut: true }), 2000);+ try {+ vm.runInNewContext(fs.readFileSync(sourceFile, 'utf8'), {+ __dirname: workerDir,+ require: createRequire(path.join(workerDir, 'kb-embed-worker.cjs')),+ process: {+ env: { ORKAS_EMBED_MODEL_DIR: modelDir },+ parentPort: { on: (_name, callback) => { receive = callback; }, postMessage: reply },+ exit: () => { throw new Error('Worker exited before handling a request'); },+ },+ });+ assert.equal(typeof receive, 'function');+ receive({ data: { id: 17, type: 'embed', texts: ['first document', 'second document'] } });+ return await response;+ } finally { clearTimeout(timer); }+}++module.exports = { requestWorker };+if (require.main === module) {+ requestWorker(...process.argv.slice(2)).then(result => {+ process.stdout.write(JSON.stringify(result));+ }, error => { process.stderr.write(error.stack + '\n'); process.exitCode = 1; });+}diff --git a/test/fixtures/office/text-collision-render.cjs b/test/fixtures/office/text-collision-render.cjsindex 2d31557c..5dafa4ff 100644--- a/test/fixtures/office/text-collision-render.cjs+++ b/test/fixtures/office/text-collision-render.cjs@@ -40,7 +40,12 @@ app.whenReady().then(async () => {for (const [name, body] of Object.entries(cases)) {const html = '<!doctype html><style>body{margin:0}.slide{position:relative;width:800px;height:600px}.shape{position:absolute;width:300px;height:60px;white-space:pre-wrap;font:20px/24px monospace}.shape-text{width:100%;height:100%}</style><div class="slide">' + body + '</div>';await win.loadURL('data:text/html;base64,' + Buffer.from(html).toString('base64'));- await win.webContents.executeJavaScript('document.fonts.ready');+ // Match production Office capture: settle fonts and layout before the+ // bounded audit, so cold layout work does not consume its own budget.+ await win.webContents.executeJavaScript(`(async () => {+ await document.fonts.ready;+ await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));+ })()`);results[name] = await win.webContents.executeJavaScript(PPTX_TEXT_COLLISION_SCRIPT);}fs.writeFileSync(process.argv[3], JSON.stringify(results));diff --git a/test/main/features/fabric_pipeline_e2e.test.ts b/test/main/features/fabric_pipeline_e2e.test.tsindex 2ce9f3e7..d552e8b6 100644--- a/test/main/features/fabric_pipeline_e2e.test.ts+++ b/test/main/features/fabric_pipeline_e2e.test.ts@@ -15,7 +15,7 @@ import * as path from 'node:path';* (via the runner's `deps.advance`), because the real commander's decisions are* covered separately by the L4 benchmark. Everything else is exercised for real.*- * Code-task deliverables are represented as `result_ref` pointers (PR refs) — the+ * Code-task completion is represented by review and human approval — the* code-vertical convention (code lives in the repo, not 资料库). The 资料库* write-back tool (`library_save`) is unit-tested in library-save-tool.test.ts.*/@@ -105,7 +105,7 @@ describe('fabric pipeline e2e', () => {// 5. The commander turn works A on the board: progress → deliver → review.// Deliverable is a PR ref (code lives in the repo).await pt.updateTask(UID, pid, A.task.id, { status: 'progress' });- await pt.updateTask(UID, pid, A.task.id, { status: 'review', result_ref: 'pr#101' });+ await pt.updateTask(UID, pid, A.task.id, { status: 'review' });convoRunning = false; // the advance conversation finished its turn// 6. A awaits human review and B is still dep-blocked → nothing actionable.@@ -125,7 +125,7 @@ describe('fabric pipeline e2e', () => {expect(await runner.advanceProjectIfDue(UID, pid, deps)).toBe('advanced');expect(fired).toEqual([A.task.id, B.task.id]);await pt.updateTask(UID, pid, B.task.id, { status: 'progress' });- await pt.updateTask(UID, pid, B.task.id, { status: 'review', result_ref: 'pr#102' });+ await pt.updateTask(UID, pid, B.task.id, { status: 'review' });convoRunning = false;// 9. Human requests changes on B → back to progress (not done).@@ -135,7 +135,7 @@ describe('fabric pipeline e2e', () => {expect(pt.computeProgress(await pt.listTasks(UID, pid))).toMatchObject({ total: 2, done: 1, open: 1 });// 10. Rework → review again → approve → done. Backlog complete.- await pt.updateTask(UID, pid, B.task.id, { status: 'review', result_ref: 'pr#102-v2' });+ await pt.updateTask(UID, pid, B.task.id, { status: 'review' });const decB2 = await pt.decideReview(UID, pid, B.task.id, 'approved');expect(decB2.ok).toBe(true);if (decB2.ok) expect(decB2.task.status).toBe('done');diff --git a/test/main/features/image-production-credits.test.ts b/test/main/features/image-production-credits.test.tsindex 5fb7bc3d..0a655069 100644--- a/test/main/features/image-production-credits.test.ts+++ b/test/main/features/image-production-credits.test.ts@@ -10,8 +10,10 @@ vi.mock('../../../src/main/features/image_gen', () => ({import {buildImageProductionQuoteSegment,+ creditsFromMilli,estimateImageProductionCredits,imageProductionQuotePayloadSegments,+ withCreditTwins,} from '../../../src/main/features/image_production_credits';function candidate(provider: string, supportsEdit = true): any {diff --git a/test/main/features/image_gen.test.ts b/test/main/features/image_gen.test.tsindex d4b7ad0a..70cb36ac 100644--- a/test/main/features/image_gen.test.ts+++ b/test/main/features/image_gen.test.ts@@ -144,7 +144,7 @@ describe('image_gen › pickImageGenProfile', () => {const m = await import('../../../src/main/features/image_gen');const picked = m.pickImageGenProfile();expect(picked!.entry.profileId).toBe('google:studio');- expect(picked!.capability.model).toBe('gemini-3.1-flash-image-preview');+ expect(picked!.capability.model).toBe('gemini-nano-banana-2.1');expect(picked!.capability.api).toBe('gemini');});});diff --git a/test/main/features/image_studio.test.ts b/test/main/features/image_studio.test.tsindex d788fda9..635030f7 100644--- a/test/main/features/image_studio.test.ts+++ b/test/main/features/image_studio.test.ts@@ -69,6 +69,12 @@ describe('ImageStudio project contract', () => {}});+ it('rejects a clipped screenshot instead of stretching it into a valid-looking canvas', async () => {+ const clipped = await sharp({ create: { width: 400, height: 180, channels: 4, background: '#2468ae' } }).png().toBuffer();+ await expect(normalizeImageStudioSnapshot(clipped, { width: 400, height: 240 }))+ .rejects.toThrow('E_IMAGE_STUDIO_CAPTURE_GEOMETRY');+ });+it('only exempts verified raster provenance, independent of route and legacy flags', () => {expect(imageStudioEvidenceIsGeneration(null)).toBe(false);expect(imageStudioEvidenceIsGeneration({ route: 'generate' } as any)).toBe(false);diff --git a/test/main/features/kb_embed.test.ts b/test/main/features/kb_embed.test.tsindex bc71c09b..9d0f948c 100644--- a/test/main/features/kb_embed.test.ts+++ b/test/main/features/kb_embed.test.ts@@ -47,6 +47,18 @@ afterEach(() => {});describe('kb_embed supervisor', () => {+ it('fails closed when the channel factory denies execution and recovers only with an explicit fake', async () => {+ const denied = vi.fn(() => { throw new Error('Fixture embedding execution denied'); });+ _setEmbedChannelFactoryForTest(denied);+ await expect(embedTexts(['guard probe'])).rejects.toThrow('Fixture embedding execution denied');+ expect(denied).toHaveBeenCalledOnce();+ expect(channels).toHaveLength(0);++ _setEmbedChannelFactoryForTest(factory);+ expect(await embedQuery('recovery probe')).toEqual([0, 1]);+ expect(channels).toHaveLength(1);+ });+it('empty input never spawns a worker', async () => {expect(await embedTexts([])).toEqual([]);expect(channels).toHaveLength(0);diff --git a/test/main/features/kb_embed_worker.test.ts b/test/main/features/kb_embed_worker.test.tsnew file mode 100644index 00000000..7a34cc0d--- /dev/null+++ b/test/main/features/kb_embed_worker.test.ts@@ -0,0 +1,96 @@+import { afterEach, beforeEach, describe, expect, it } from 'vitest';+import * as fs from 'node:fs';+import * as os from 'node:os';+import * as path from 'node:path';+import { createRequire } from 'node:module';+import { spawnSync } from 'node:child_process';+import { finished } from 'node:stream/promises';+import { createPackageFromStreams } from '@electron/asar';++const workerSourceFile = path.resolve(__dirname, '../../../bin/kb-embed-worker.cjs');+const requestFixture = path.resolve(__dirname, '../../fixtures/kb/embed-worker-request.cjs');+const { requestWorker } = createRequire(import.meta.url)(requestFixture);+const disk = createRequire(import.meta.url)('original-fs') as typeof fs;+let root: string;++beforeEach(() => { root = fs.mkdtempSync(path.join(os.tmpdir(), 'orkas-embed-worker-')); });+afterEach(async () => {+ // Remove physical archive bytes, rather than traversing Electron's ASAR view.+ await disk.promises.rm(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });+});++function write(relative: string, body: string): void {+ const file = path.join(root, relative);+ fs.mkdirSync(path.dirname(file), { recursive: true });+ fs.writeFileSync(file, body);+}++const embedPackage = `+const marker = require('@fixture/tokenizer');+exports.EmbeddingModel = { BGESmallZH: 'fixture-model' };+exports.FlagEmbedding = { init: async () => ({+ async *embed(texts) { yield texts.map(() => new Float32Array(marker)); }+}) };+`;++async function request(workerDir: string, isolatedArchive = false): Promise<Record<string, any>> {+ if (!isolatedArchive) return requestWorker(workerSourceFile, workerDir, path.join(root, 'model'));+ const child = spawnSync(process.execPath, [requestFixture, workerSourceFile, workerDir, path.join(root, 'model')], {+ env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' }, encoding: 'utf8', timeout: 5000,+ });+ // Preserve native diagnostics for the owning test log policy.+ if (child.stderr) process.stderr.write(child.stderr);+ expect(child.error).toBeUndefined();+ expect(child.status).toBe(0);+ return JSON.parse(child.stdout);+}++describe('Library embedding worker dependency loading', () => {+ it.each(['development', 'packaged'] as const)(+ 'loads the full dependency graph from the %s application root', async layout => {+ const appRoot = layout === 'packaged' ? 'stage' : 'source';+ const workerRoot = layout === 'packaged' ? 'app.asar.unpacked' : 'source';+ write(`${appRoot}/package.json`, '{}');+ write(`${appRoot}/node_modules/fastembed/index.js`, embedPackage);+ write(`${appRoot}/node_modules/@fixture/tokenizer/index.js`, 'module.exports = [7, 11];');+ if (layout === 'packaged') {+ // electron-builder unpacks FastEmbed, while a JS-only transitive+ // dependency remains exclusively in the archive. A source-only test+ // cannot catch a worker resolving from the physical unpacked tree.+ const stage = path.join(root, appRoot);+ const entries: Parameters<typeof createPackageFromStreams>[1] = [+ 'node_modules', 'node_modules/fastembed', 'node_modules/@fixture', 'node_modules/@fixture/tokenizer',+ ].map(relative => ({ type: 'directory', path: relative, unpacked: false }));+ for (const relative of ['package.json', 'node_modules/fastembed/index.js', 'node_modules/@fixture/tokenizer/index.js']) {+ const file = path.join(stage, relative);+ entries.push({ type: 'file', path: relative, unpacked: relative === 'node_modules/fastembed/index.js',+ stat: disk.statSync(file), streamGenerator: () => disk.createReadStream(file) });+ }+ await finished(await createPackageFromStreams(path.join(root, 'app.asar'), entries));+ expect(fs.existsSync(path.join(root, workerRoot, 'node_modules/fastembed/index.js'))).toBe(true);+ expect(fs.existsSync(path.join(root, workerRoot, 'node_modules/@fixture/tokenizer/index.js'))).toBe(false);+ }+ const result = await request(path.join(root, workerRoot, 'bin'), layout === 'packaged');+ expect(result).toEqual({ id: 17, ok: true, vectors: [[7, 11], [7, 11]] });+ },+ );++ it('reports a genuinely missing dependency as failure rather than empty embeddings', async () => {+ write('source/node_modules/fastembed/index.js', embedPackage);+ const result = await request(path.join(root, 'source/bin'));+ expect(result).toMatchObject({ id: 17, ok: false });+ expect(result.error).toContain("Cannot find module '@fixture/tokenizer'");+ expect(result).not.toHaveProperty('vectors');+ });++ it('preserves the existing private native-load diagnostic through the worker protocol', async () => {+ write('source/node_modules/fastembed/index.js', `+ throw Object.assign(new Error('onnxruntime native fixture failed'), { code: 'ERR_DLOPEN_FAILED' });+ `);+ expect(await request(path.join(root, 'source/bin'))).toEqual({+ id: 17, ok: false,+ error: 'native embedding runtime failed to load',+ errorCode: 'E_LIBRARY_NATIVE_ONNX_LOAD',+ });+ });+});diff --git a/test/main/features/library_smoke.test.ts b/test/main/features/library_smoke.test.tsnew file mode 100644index 00000000..067e2007--- /dev/null+++ b/test/main/features/library_smoke.test.ts@@ -0,0 +1,103 @@+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import * as fs from 'node:fs';+import * as os from 'node:os';+import * as path from 'node:path';++vi.mock('../../../src/main/logger', () => ({+ createLogger: (scope: string) => Object.fromEntries(['info', 'debug', 'warn', 'error'].map(level =>+ [level, (...args: unknown[]) => console[level as 'info' | 'debug' | 'warn' | 'error'](`[${scope}]`, ...args)])),+}));+let root: string;+let previousRoot: string | undefined;+let previousMarker: string | undefined;+let replyMode: 'valid' | 'missing-dependency' | 'constant' | 'missing-vector';+let channels: number;+let smoke: typeof import('../../../src/main/features/library_smoke');+let embed: typeof import('../../../src/main/features/kb_embed');++beforeEach(async () => {+ root = fs.mkdtempSync(path.join(os.tmpdir(), 'orkas-library-smoke-'));+ previousRoot = process.env.ORKAS_WORKSPACE_ROOT;+ previousMarker = process.env.ORKAS_PACKAGED_LAUNCH_SMOKE_FILE;+ process.env.ORKAS_WORKSPACE_ROOT = path.join(root, 'workspace');+ process.env.ORKAS_PACKAGED_LAUNCH_SMOKE_FILE = path.join(root, 'ready.json');+ vi.resetModules();+ (await import('../../../src/main/features/users')).activateUser('library-smoke-fixture');+ embed = await import('../../../src/main/features/kb_embed');+ replyMode = 'valid'; channels = 0;+ // This layer protects the acceptance oracle and real storage/revision path.+ // The release launch uses no factory override and loads the actual worker.+ embed._setEmbedChannelFactoryForTest(() => {+ channels++;+ let receive: (message: unknown) => void;+ return {+ onMessage: cb => { receive = cb; }, onExit: () => {}, kill: () => {},+ postMessage: (message: any) => queueMicrotask(() => {+ if (replyMode === 'missing-dependency') {+ receive({ id: message.id, ok: false, error: 'Cannot find module fixture-tokenizer' });+ return;+ }+ const texts: string[] = replyMode === 'missing-vector' ? message.texts.slice(1) : message.texts;+ const vectors = texts.map(text => {+ const vector = new Array(512).fill(0);+ const value = replyMode === 'constant' ? 1 : (text.includes('Global') ? 2 : 3);+ vector[0] = value / Math.sqrt(value * value + 1);+ vector[1] = 1 / Math.sqrt(value * value + 1);+ return vector;+ });+ receive({ id: message.id, ok: true, vectors });+ }),+ };+ });+ smoke = await import('../../../src/main/features/library_smoke');+});++afterEach(async () => {+ vi.restoreAllMocks();+ embed._setEmbedChannelFactoryForTest(null);+ (await import('../../../src/main/features/project_library_indexer'))._resetQueuesForTests();+ (await import('../../../src/main/features/vec_store')).closeAllVecStores();+ if (previousRoot === undefined) delete process.env.ORKAS_WORKSPACE_ROOT;+ else process.env.ORKAS_WORKSPACE_ROOT = previousRoot;+ if (previousMarker === undefined) delete process.env.ORKAS_PACKAGED_LAUNCH_SMOKE_FILE;+ else process.env.ORKAS_PACKAGED_LAUNCH_SMOKE_FILE = previousMarker;+ fs.rmSync(root, { recursive: true, force: true });+});++describe('packaged Library acceptance oracle', () => {+ it('requires search/read, replacement, persistence and scope isolation, and respawns its worker', async () => {+ expect(await smoke.runPackagedLibrarySmoke()).toEqual({+ embeddingDimensions: 512, workerRespawn: true, projectReady: true, projectSearchRead: true,+ revisionPersisted: true, staleRevisionRejected: true, globalSearchRead: true, scopeIsolated: true,+ });+ expect(channels).toBe(2);+ });++ it('refuses an ordinary installation before writing fixture documents or spawning a worker', async () => {+ delete process.env.ORKAS_PACKAGED_LAUNCH_SMOKE_FILE;+ await expect(smoke.runPackagedLibrarySmoke()).rejects.toThrow(/isolated launch marker/);+ expect(channels).toBe(0);+ expect(fs.existsSync(path.join(root, 'workspace/library-smoke-work'))).toBe(false);+ });++ it('refuses a marker paired with a different workspace', async () => {+ process.env.ORKAS_PACKAGED_LAUNCH_SMOKE_FILE = path.join(root, 'other/ready.json');+ await expect(smoke.runPackagedLibrarySmoke()).rejects.toThrow(/isolated storage/);+ expect(channels).toBe(0);+ });++ it.each(['missing-dependency', 'missing-vector', 'constant'] as const)(+ 'cannot certify a shipped worker with %s output', async mode => {+ replyMode = mode;+ await expect(smoke.runPackagedLibrarySmoke()).rejects.toThrow(+ mode === 'missing-dependency' ? /Cannot find module/ : mode === 'constant' ? /constant placeholder/ : /count mismatch/,+ );+ },+ );++ it('rejects an acknowledged replacement that leaves the old Library bytes and chunks', async () => {+ const files = await import('../../../src/main/features/project_files');+ vi.spyOn(files, 'replaceProjectFileFromPath').mockResolvedValue({ ok: true } as any);+ await expect(smoke.runPackagedLibrarySmoke()).rejects.toThrow(/reopened current chunks/);+ });+});diff --git a/test/main/features/office/pptx-text-collision_e2e.test.ts b/test/main/features/office/pptx-text-collision_e2e.test.tsindex 74575c04..4e0c1728 100644--- a/test/main/features/office/pptx-text-collision_e2e.test.ts+++ b/test/main/features/office/pptx-text-collision_e2e.test.ts@@ -5,6 +5,7 @@ import * as os from 'node:os';import * as path from 'node:path';import { promisify } from 'node:util';import { describe, expect, it } from 'vitest';+import { ELECTRON_MACOS_TASK_POLICY_WARNING_RE } from '../../../../scripts/model-eval-log-policy.mjs';const require = createRequire(import.meta.url);@@ -18,7 +19,14 @@ describe('rendered PPT text collision evidence', () => {const logs = await promisify(execFile)(require('electron'), [path.resolve('test/fixtures/office/text-collision-render.cjs'), process.cwd(), output,], { env, timeout: 30_000, maxBuffer: 256 * 1024 });- expect(logs.stderr).toBe('');+ const stderr = logs.stderr.split(/\r?\n/).filter(line => line.trim());+ const isKnownHostWarning = (line: string) => process.platform === 'darwin'+ && ELECTRON_MACOS_TASK_POLICY_WARNING_RE.test(line);+ // Preserve native diagnostics and their owning case. The shared policy+ // recognizes only these exact macOS task-policy warnings; unknown+ // stderr still fails this real rendered-geometry scenario.+ for (const line of stderr.filter(isKnownHostWarning)) console.warn('[native-host-warning]', line);+ expect(stderr.filter(line => !isKnownHostWarning(line))).toEqual([]);expect(logs.stdout.trim()).toBe('');const results = JSON.parse(fs.readFileSync(output, 'utf8'));expect(results.collision).toMatchObject({ status: 'checked', assessed_text_elements: 2,@@ -32,7 +40,7 @@ describe('rendered PPT text collision evidence', () => {}expect(results.hidden.warnings).toHaveLength(1);for (const name of ['rotated', 'effect']) {- expect(results[name], name).toMatchObject({ status: 'partial', warnings: [] });+ expect(results[name], JSON.stringify({ name, audit: results[name] })).toMatchObject({ status: 'partial', warnings: [] });expect(Object.keys(results[name].skipped).length).toBeGreaterThan(0);}// Identical painted text may be intentional decoration: report a candidate,diff --git a/test/main/features/search/index.test.ts b/test/main/features/search/index.test.tsindex 839c42d1..30bf05e8 100644--- a/test/main/features/search/index.test.ts+++ b/test/main/features/search/index.test.ts@@ -595,7 +595,8 @@ describe('search › searchChats — group-chat shape end-to-end', () => {postings: {},}));const s = await loadSearch();- expect(await s.searchChatsWithStatus(TEST_UID, 'recoveredmarker')).toEqual({ results: [], indexComplete: false });+ // The legacy snapshot is still migrating: this is a first build.+ expect(await s.searchChatsWithStatus(TEST_UID, 'recoveredmarker')).toEqual({ results: [], indexComplete: false, indexBuilding: true });expect(s.__searchTestHooks.hasPendingChatRepair(TEST_UID)).toBe(true);await s.reconcileActive();expect(await s.searchChats(TEST_UID, 'recoveredmarker')).toMatchObject([@@ -908,7 +909,8 @@ describe('search › startup reconcile', () => {expect(indexer.isChatsIndexTrusted(TEST_UID)).toBe(false);expect(fs.existsSync(chatStore.chatStorePath('inactive-user')),'an inactive profile must not be scanned at startup').toBe(false);- expect(await s.searchChatsWithStatus(TEST_UID, 'fallback token')).toEqual({ results: [], indexComplete: false });+ // Built once before, so only catch-up is pending: not announced as building.+ expect(await s.searchChatsWithStatus(TEST_UID, 'fallback token')).toEqual({ results: [], indexComplete: false, indexBuilding: false });expect(s.__searchTestHooks.hasPendingChatRepair(TEST_UID)).toBe(true);await indexer.reconcileChatsIndex(TEST_UID);const results = await s.searchChats(TEST_UID, 'fallback token');diff --git a/test/main/features/search/indexer.test.ts b/test/main/features/search/indexer.test.tsindex fccb7807..beb0b530 100644--- a/test/main/features/search/indexer.test.ts+++ b/test/main/features/search/indexer.test.ts@@ -686,4 +686,30 @@ describe('search/indexer › chat index trust across a clean restart', () => {ix = await restart();expect(await ix.isChatsIndexCurrent('u1')).toBe(false);});++ it('keeps trust across a clean restart after a conversation is deleted in the session', async () => {+ writeChat('u1', 'c1', [{ from: 'user', ts: 't1', text: 'kept conversation' }]);+ writeChat('u1', 'c2', [{ from: 'user', ts: 't1', text: 'deleted conversation' }]);+ let ix = await loadIndexer();+ await ix.reconcileChatsIndex('u1');+ expect(await ix.isChatsIndexCurrent('u1')).toBe(true);+ fs.rmSync(path.join(tmpDir, 'u1', 'cloud', 'chats', 'c2.jsonl'));+ moveCatalog('conversation removed');+ await ix.dropChatConversation('u1', 'c2');++ ix = await restart();+ expect(await ix.isChatsIndexCurrent('u1')).toBe(true);+ const search = await import('../../../../src/main/features/search/index');+ expect(await search.searchChats('u1', 'deleted')).toEqual([]);+ });++ it('falls back to invalidation and repair when a rewritten conversation cannot be re-read', async () => {+ writeChat('u1', 'c1', [{ from: 'user', ts: 't1', text: 'present' }]);+ const ix = await loadIndexer();+ await ix.reconcileChatsIndex('u1');+ expect(ix.isChatsIndexTrusted('u1')).toBe(true);+ await ix.reindexChatConversation('u1', 'missing-conversation');+ expect(ix.isChatsIndexTrusted('u1')).toBe(false);+ expect(ix.hasPendingChatRepair('u1')).toBe(true);+ });});diff --git a/test/main/features/search/migration.test.ts b/test/main/features/search/migration.test.tsindex f1e554c1..e3261ddc 100644--- a/test/main/features/search/migration.test.ts+++ b/test/main/features/search/migration.test.ts@@ -105,7 +105,8 @@ it('defers new messages without blocking search and catches them up before marki// These promises must settle while the source read is still parked.await ix.drainDeferredChatWrites();expect(store.postingsFor('u1', 'freshmarker')).toHaveLength(0);- expect(await search.searchChatsWithStatus('u1', 'freshmarker')).toEqual({ results: [], indexComplete: false });+ expect(await search.searchChatsWithStatus('u1', 'freshmarker'))+ .toEqual({ results: [], indexComplete: false, indexBuilding: true });expect((await search.searchChatsWithStatus('u1', 'oldmarker')).results).toHaveLength(1);expect(fs.existsSync(legacy)).toBe(true);} finally { h.release(); }@@ -146,6 +147,43 @@ it('does not rebuild a cold index on the search path and returns coverage to gloexpect(search.__searchTestHooks.hasPendingChatRepair('u1')).toBe(true);});+it('announces a first build and starts its repair from the status check alone', async () => {+ write('c1', 'firstbuildmarker');+ const boot = await import('../../../../src/main/util/boot_init');+ boot.configureBootAdmission({ isRuntimeBusy: () => true });+ const search = await import('../../../../src/main/features/search');+ // Opening search reads status only; it must not wait for a typed query.+ expect(await search.searchIndexStatus('u1')).toEqual({ chat_index_complete: false, chat_index_building: true });+ expect(search.__searchTestHooks.hasPendingChatRepair('u1')).toBe(true);+});++it('keeps a once-built index unannounced after a restart and catches it up from the status check', async () => {+ write('c1', 'keptmarker');+ let search = await import('../../../../src/main/features/search');+ const ix = await import('../../../../src/main/features/search/indexer');+ expect((await ix.reconcileChatsIndex('u1')).complete).toBe(true);+ expect(await search.searchIndexStatus('u1')).toEqual({ chat_index_complete: true, chat_index_building: false });+ await search.flushAll();+ // A conversation arrives while no process trusts the index (a relaunch that+ // skipped the quit work, a crash, a sync): the next start cannot verify it.+ write('c2', 'catchupmarker');+ vi.resetModules();+ (await import('../../../../src/main/features/users')).activateUser('u1');+ const boot = await import('../../../../src/main/util/boot_init');+ boot.configureBootAdmission({ isRuntimeBusy: () => true });+ search = await import('../../../../src/main/features/search');+ expect(await search.searchIndexStatus('u1')).toEqual({ chat_index_complete: false, chat_index_building: false });+ expect(search.__searchTestHooks.hasPendingChatRepair('u1')).toBe(true);+ // The kept index still answers while the catch-up waits for an idle runtime.+ expect((await search.searchChats('u1', 'keptmarker')).map(r => r.cid)).toEqual(['c1']);+ vi.useFakeTimers({ toFake: ['Date'] });+ vi.setSystemTime(Date.now() + 5_000);+ boot.configureBootAdmission({ isRuntimeBusy: () => false });+ await vi.waitFor(async () => expect((await search.searchIndexStatus('u1')).chat_index_complete).toBe(true),+ { timeout: 4_000 });+ expect((await search.searchChats('u1', 'catchupmarker')).map(r => r.cid)).toEqual(['c2']);+});+it('automatically resumes an interrupted startup slice only after the runtime becomes idle', async () => {write('c1', 'firstmarker'); write('c2', 'lastmarker'); legacySnapshot();const search = await import('../../../../src/main/features/search');diff --git a/test/main/features/tts_elevenlabs_lifecycle.test.ts b/test/main/features/tts_elevenlabs_lifecycle.test.tsnew file mode 100644index 00000000..1b468b33--- /dev/null+++ b/test/main/features/tts_elevenlabs_lifecycle.test.ts@@ -0,0 +1,108 @@+import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import path from 'node:path';+import { afterEach, beforeEach, expect, it, vi } from 'vitest';++const fixture = vi.hoisted(() => ({ profiles: [] as any[] }));+vi.mock('../../../src/main/features/tts_auth', async original => ({+ ...await original<any>(),+ listUsableTtsProfiles: () => fixture.profiles,+}));+import { generateSpeech } from '../../../src/main/features/tts';+import { listTtsCapabilities } from '../../../src/main/features/tts_capabilities';+import { listTtsProviderPresets } from '../../../src/main/features/tts_auth';++let root: string;+let prior: NodeJS.ProcessEnv;+beforeEach(() => {+ root = mkdtempSync(path.join(tmpdir(), 'elevenlabs-http-'));+ prior = { ...process.env };+ delete process.env.ORKAS_TTS_BASE_URL;+ const preset = listTtsProviderPresets().find(p => p.id === 'elevenlabs')!;+ fixture.profiles = [{ id: 'saved-elevenlabs', provider: preset.id, baseUrl: preset.baseUrl,+ model: preset.defaultModel, apiKey: 'fixture-key', voice: 'JBFqnCBsd6RMkjVDRZzb', label: 'ElevenLabs', createdAt: 1 }];+});+afterEach(() => {+ vi.unstubAllGlobals();+ process.env = prior;+ rmSync(root, { recursive: true, force: true });+});+async function request(format = 'mp3', speed?: number, signal?: AbortSignal) {+ const [route] = await listTtsCapabilities();+ return generateSpeech({ text: 'A clear release update.', outputAbsPath: path.join(root, `voice.${format}`),+ routeRef: route.routeRef, voiceRef: route.voices[0].voiceRef, format, speed, signal });+}++// Independent oracle: https://elevenlabs.io/docs/api-reference/text-to-speech/convert+// Native voice_id path + xi-api-key; model_id/text body; codec query parameter.+// PCM 24k is available without a Pro plan and is wrapped locally for WAV output.+it.each([['mp3', 'mp3_44100_128'], ['wav', 'pcm_24000'], ['opus', 'opus_48000_128']])(+ 'uses the saved ElevenLabs preset through voice selection and persists %s audio', async (format, codec) => {+ const audio = format === 'wav' ? Buffer.alloc(4800) : Buffer.from('fixture audio');+ const fetch = vi.fn(async (url: string, init?: RequestInit) => {+ expect(url).toBe(`https://api.elevenlabs.io/v1/text-to-speech/JBFqnCBsd6RMkjVDRZzb?output_format=${codec}`);+ expect(init?.headers).toEqual({ 'xi-api-key': 'fixture-key', 'Content-Type': 'application/json' });+ expect(JSON.parse(String(init?.body))).toEqual({ text: 'A clear release update.', model_id: 'eleven_multilingual_v2', voice_settings: { speed: 1.05 } });+ return new Response(audio, { headers: { 'Content-Type': 'audio/mpeg' } });+ });+ vi.stubGlobal('fetch', fetch);+ expect(await request(format, 1.05)).toMatchObject({ ok: true, backend: 'elevenlabs' });+ expect(fetch).toHaveBeenCalledOnce();+ const bytes = readFileSync(path.join(root, `voice.${format}`));+ if (format === 'wav') {+ expect(bytes.subarray(0, 4).toString()).toBe('RIFF');+ expect(bytes.readUInt32LE(24)).toBe(24000);+ expect(bytes.subarray(44)).toEqual(audio);+ } else expect(bytes).toEqual(audio);+ });++it('omits optional voice settings and encodes the voice as one path segment', async () => {+ fixture.profiles[0].voice = 'voice/with space';+ const fetch = vi.fn(async () => new Response(Buffer.from('audio')));+ vi.stubGlobal('fetch', fetch);+ expect(await request()).toMatchObject({ ok: true });+ const [url, init] = fetch.mock.calls[0] as any;+ expect(url).toBe('https://api.elevenlabs.io/v1/text-to-speech/voice%2Fwith%20space?output_format=mp3_44100_128');+ expect(JSON.parse(init.body)).toEqual({ text: 'A clear release update.', model_id: 'eleven_multilingual_v2' });+});++it.each([0.5, 1.3, NaN, Infinity])('rejects unsupported native speed without dispatch (%s)', async speed => {+ const fetch = vi.fn(); vi.stubGlobal('fetch', fetch);+ expect(await request('mp3', speed)).toMatchObject({ ok: false, errorCode: 'E_TTS_ARG', chargeStatus: 'not_charged' });+ expect(fetch).not.toHaveBeenCalled(); expect(existsSync(path.join(root, 'voice.mp3'))).toBe(false);+});++it.each(['flac', 'constructor', '__proto__'])('rejects unsupported output codec %s without dispatch', async format => {+ const fetch = vi.fn(); vi.stubGlobal('fetch', fetch);+ expect(await request(format)).toMatchObject({ ok: false, errorCode: 'E_TTS_ARG', chargeStatus: 'not_charged' });+ expect(fetch).not.toHaveBeenCalled();+});++it.each([401, 422, 502, 200])('does not save error responses or replay synthesis (HTTP %s)', async status => {+ const fetch = vi.fn(async () => new Response('{"detail":"private provider error"}', { status, headers: { 'Content-Type': 'application/json' } }));+ vi.stubGlobal('fetch', fetch);+ const result = await request();+ expect(result).toMatchObject({ ok: false, requestDisposition: 'sent', chargeStatus: 'unknown' });+ expect(JSON.stringify(result)).not.toContain('private provider error');+ expect(fetch).toHaveBeenCalledOnce(); expect(existsSync(path.join(root, 'voice.mp3'))).toBe(false);+});++it('preserves unknown charge status after a transport error without replay', async () => {+ const fetch = vi.fn(async () => { throw new Error('fixture connection closed'); }); vi.stubGlobal('fetch', fetch);+ expect(await request()).toMatchObject({ ok: false, errorCode: 'E_TTS_NETWORK', requestDisposition: 'sent', chargeStatus: 'unknown' });+ expect(fetch).toHaveBeenCalledOnce(); expect(existsSync(path.join(root, 'voice.mp3'))).toBe(false);+});++it('preserves cancellation before the native request', async () => {+ const fetch = vi.fn(); vi.stubGlobal('fetch', fetch);+ const controller = new AbortController(); controller.abort();+ expect(await request('mp3', undefined, controller.signal)).toMatchObject({ ok: false, requestDisposition: 'not_sent', chargeStatus: 'not_charged' });+ expect(fetch).not.toHaveBeenCalled();+});++it('keeps an explicit custom gateway on the OpenAI-compatible protocol', async () => {+ fixture.profiles[0].provider = 'custom';+ const fetch = vi.fn(async () => new Response(Buffer.from('audio'))); vi.stubGlobal('fetch', fetch);+ expect(await request()).toMatchObject({ ok: true, backend: 'openai-compatible' });+ expect(fetch.mock.calls[0][0]).toBe('https://api.elevenlabs.io/v1/audio/speech');+});diff --git a/test/main/features/video_production_control.test.ts b/test/main/features/video_production_control.test.tsindex ecacb262..e62dfcc3 100644--- a/test/main/features/video_production_control.test.ts+++ b/test/main/features/video_production_control.test.ts@@ -13,6 +13,7 @@ import {videoProductionControlSummary,beginVideoProductionGeneration,finishVideoProductionGeneration,+ releaseVideoProductionGeneration,readVideoProductionControlState,readVideoProductionPlanIdentity,validateVideoProductionPlanApproval,@@ -300,6 +301,55 @@ describe('VideoStudio project production control', () => {.rejects.toThrow(/E_VIDEO_PRODUCTION_GENERATION_UNCERTAIN/);});+ it('lets the same paid confirmation retry an attempt that never dispatched, but not one that did', async () => {+ await approveVideoProductionPlan({ statePath, planPath, turnId: 'turn-b' });+ await approveVideoProductionGeneration({ statePath, planPath, turnId: 'turn-c' });+ const args = {+ statePath,+ planPath,+ segmentId: 'shot-1',+ kind: 'video' as const,+ outputPath: path.join(root, 'shot-1.mp4'),+ request: request(),+ };+ const first = await beginVideoProductionGeneration(args);+ if (first.status !== 'started') throw new Error('expected started transaction');+ const releaseArgs = {+ statePath,+ planPath,+ transactionId: first.transaction.transaction_id,+ segmentId: 'shot-1',+ kind: 'video' as const,+ errorCode: 'PROVIDER_API_ERROR',+ };++ // The reference upload failed before any provider request left.+ expect(await releaseVideoProductionGeneration(releaseArgs))+ .toMatchObject({ status: 'released', error_code: 'PROVIDER_API_ERROR' });+ const released = await readVideoProductionControlState(statePath, planPath);+ expect(released.transactions['video:shot-1']).toBeUndefined();+ expect(released.transaction_history.map((transaction) => transaction.status)).toEqual(['released']);+ await expect(releaseVideoProductionGeneration(releaseArgs))+ .rejects.toThrow(/E_VIDEO_PRODUCTION_GENERATION_TRANSACTION_STALE/);++ const retry = await beginVideoProductionGeneration(args);+ if (retry.status !== 'started') throw new Error('expected the retry to start');+ expect(retry.transaction.approval_id).toBe(first.transaction.approval_id);++ // Once a request was sent, a failure still needs a new paid confirmation.+ await finishVideoProductionGeneration({+ statePath,+ planPath,+ transactionId: retry.transaction.transaction_id,+ segmentId: 'shot-1',+ kind: 'video',+ ok: false,+ errorCode: 'PROVIDER_API_ERROR',+ });+ await expect(beginVideoProductionGeneration(args))+ .rejects.toThrow(/E_VIDEO_PRODUCTION_GENERATION_REAPPROVAL_REQUIRED/);+ });+it('requires a new path after reapproving an uncertain provider attempt', async () => {await approveVideoProductionPlan({ statePath, planPath, turnId: 'turn-b' });await approveVideoProductionGeneration({ statePath, planPath, turnId: 'turn-c-1' });diff --git a/test/main/features/voice_studio_core.test.ts b/test/main/features/voice_studio_core.test.tsindex d620951d..3ab7246d 100644--- a/test/main/features/voice_studio_core.test.ts+++ b/test/main/features/voice_studio_core.test.ts@@ -192,7 +192,7 @@ describe('VoiceStudio audio project journeys', () => {expect(() => audio.whisperSegments({ transcription: [{ text: 'missing timing' }] })).toThrow('invalid segment timing');});- it('runs the bundled transcription pipeline and saves a readable result without fetching dependencies', async () => {+ it.runIf(process.env.ORKAS_REAL_WHISPER_TEST === '1')('runs the bundled transcription pipeline and saves a readable result without fetching dependencies', async () => {await fs.writeFile(path.join(root, 'silence.wav'), Buffer.from(tone(1).map((b, i) => i < 44 ? b : 0)));await save({ schema_version: 1, segments: [] });const result = await call('transcribe', { input_path: 'silence.wav', language: 'en' });diff --git a/test/main/ipc/media-diagnose.test.ts b/test/main/ipc/media-diagnose.test.tsindex fad7cc85..ba45dcb9 100644--- a/test/main/ipc/media-diagnose.test.ts+++ b/test/main/ipc/media-diagnose.test.ts@@ -63,6 +63,20 @@ async function invoke(payload: Record<string, unknown>): Promise<any> {}describe('media.diagnose', () => {+ it('identifies lexical OS temporary scope and ENOENT versus ENOTDIR with the existing single async stat', async () => {+ const { chatMediaLocalUrl } = await import('../../../src/main/util/chat-media-url');+ await invoke({ url: 'not a url' });+ const syncLookup = vi.spyOn(fs, 'realpathSync');+ for (const code of ['ENOENT', 'ENOTDIR']) {+ const stat = vi.spyOn(fs.promises, 'stat').mockRejectedValue(Object.assign(new Error('private marker'), { code }));+ const res = await invoke({ url: chatMediaLocalUrl(path.join(tmpDir, 'missing.mp4')), diagnosticOnly: true });+ expect(res.media_failure_context).toBe(`local|os_temp|${code.toLowerCase()}`);+ expect(stat).toHaveBeenCalledOnce();+ expect(JSON.stringify(res)).not.toContain(tmpDir);+ stat.mockRestore();+ }+ expect(syncLookup).not.toHaveBeenCalled();+ });it('distinguishes an available local image without returning its path', async () => {const imagePath = path.join(tmpDir, 'image #1%.png');fs.writeFileSync(imagePath, Buffer.from('not decoded by this diagnostic'));@@ -93,7 +107,7 @@ describe('media.diagnose', () => {const read = vi.spyOn(fs, 'readFileSync');const asyncStat = vi.spyOn(fs.promises, 'stat');const result = await invoke({ url: chatMediaLocalUrl(file), diagnosticOnly: true });- expect(result).toEqual({ ok: true, diagnosis: 'stat_available', media_kind: 'image' });+ expect(result).toEqual({ ok: true, diagnosis: 'stat_available', media_kind: 'image', media_failure_context: 'local|os_temp|stat_available' });expect(asyncStat).toHaveBeenCalledOnce();expect(syncStat).not.toHaveBeenCalled();expect(read).not.toHaveBeenCalled();@@ -106,7 +120,8 @@ describe('media.diagnose', () => {await invoke({ url: 'not a url' });const stat = vi.spyOn(fs.promises, 'stat').mockRejectedValue(Object.assign(new Error('private-source-marker'), { code }));const result = await invoke({ url: 'chat-media://local/private/source.mp4', diagnosticOnly: true });- expect(result).toEqual({ ok: true, diagnosis, media_kind: 'video' });+ expect(result).toEqual({ ok: true, diagnosis, media_kind: 'video',+ media_failure_context: `local|other_local|${code === 'EIO' ? 'io_error' : code.toLowerCase()}` });expect(stat).toHaveBeenCalledOnce();expect(JSON.stringify(result)).not.toContain('private');},diff --git a/test/main/model/core-agent/image-studio-tool.test.ts b/test/main/model/core-agent/image-studio-tool.test.tsindex d8f24d73..9b725291 100644--- a/test/main/model/core-agent/image-studio-tool.test.ts+++ b/test/main/model/core-agent/image-studio-tool.test.ts@@ -43,6 +43,7 @@ const electronImage = vi.hoisted(() => {image: baseImage,baseImage,changedImage,+ scrollingAreas: 0,requiredCopyLayouts: [] as Array<{copy: string;lineGlyphCounts: number[];@@ -57,8 +58,11 @@ vi.mock('electron', () => ({fromPartition: () => ({ webRequest: { onBeforeRequest: vi.fn() } }),},BrowserWindow: class BrowserWindow {+ viewport = { width: 0, height: 0 };+ setContentSize(width: number, height: number) { this.viewport = { width, height }; }webContents = {- executeJavaScript: vi.fn(async () => electronImage.requiredCopyLayouts),+ executeJavaScript: vi.fn(async () => ({ viewport: this.viewport,+ scrollingAreas: electronImage.scrollingAreas, requiredCopyLayouts: electronImage.requiredCopyLayouts })),capturePage: vi.fn(async () => electronImage.image),};loadURL = vi.fn(async () => undefined);@@ -94,6 +98,7 @@ let previousComfyBaseUrl: string | undefined;beforeEach(() => {electronImage.image = electronImage.baseImage;electronImage.requiredCopyLayouts = [];+ electronImage.scrollingAreas = 0;previousComfyBaseUrl = process.env.ORKAS_COMFYUI_BASE_URL;delete process.env.ORKAS_COMFYUI_BASE_URL;vi.stubGlobal('fetch', vi.fn(() => { throw new Error('Unexpected network call in ImageStudio integration test'); }));@@ -195,6 +200,28 @@ describe('image_studio tool', () => {expect(JSON.parse(result.content)).toMatchObject({ ok: false });});+ it('keeps a scrolling composition out of delivered files and gives a layout repair handoff', async () => {+ electronImage.scrollingAreas = 1;+ const onFileWritten = vi.fn();+ const onOutputsPublished = vi.fn();+ const tool = createImageStudioTool({ userId: USER_ID, agentId: IMAGE_STUDIO_AGENT_ID,+ extraRoots: [root], onFileWritten, onOutputsPublished });+ const outputPath = path.join(root, 'evidence', 'scrolling.png');+ const result = await tool.execute({ op: 'project.snapshot', project_dir: projectDir, output_path: outputPath }, { workingDir: root } as any);+ expect(result.isError).toBe(true);+ expect(result.images).toBeUndefined();+ expect(JSON.parse(result.content)).toMatchObject({ ok: false, current_candidate: null,+ inspection: { blockers: [expect.objectContaining({ code: 'E_IMAGE_LAYOUT_SCROLLING' })] },+ recovery_context: { next_operation: 'repair_project_then_project.inspect' } });+ expect(fs.existsSync(outputPath)).toBe(false);+ expect(onFileWritten).not.toHaveBeenCalled();+ expect(onOutputsPublished).not.toHaveBeenCalled();+ const exported = await tool.execute({ op: 'project.export', project_dir: projectDir, output_path: path.join(root, 'final.png') }, { workingDir: root } as any);+ expect(exported.isError).toBe(true);+ expect(exported.content).toContain('E_IMAGE_REVIEW_EVIDENCE_REQUIRED');+ expect(fs.existsSync(path.join(root, 'final.png'))).toBe(false);+ });+it('attaches the passing candidate and declared references in one ordered visual batch', async () => {const referencePath = path.join(projectDir, 'assets', 'reference.png');fs.mkdirSync(path.dirname(referencePath), { recursive: true });diff --git a/test/main/model/core-agent/video-studio-state-tool.test.ts b/test/main/model/core-agent/video-studio-state-tool.test.tsindex e3d593e8..1d32254b 100644--- a/test/main/model/core-agent/video-studio-state-tool.test.ts+++ b/test/main/model/core-agent/video-studio-state-tool.test.ts@@ -2526,6 +2526,55 @@ describe('VideoStudio production-state tool protocol', () => {'turn-draft',{ draft_ready: true, path: path.join(workspace, 'project', 'render', 'draft.mp4') },)).toBe(true);+ // A draft rendered in this very turn is unseen: the user's message in it+ // predates the draft, so confirming or exporting stops on the user with+ // the v2 outcome instead of a plain-text refusal the turn ran past+ // (2026-10-07 live run).+ const sameTurnTool = mod.createVideoStudioTool({+ userId: UID,+ cid: 'cid-explicit-gates',+ turnId: 'turn-draft',+ agentId: VIDEO_STUDIO_AGENT_ID,+ agentName: 'VideoStudio',+ userMessage: '<msg from="user">确认制作</msg>',+ });+ for (const op of ['composition.approve_draft', 'composition.export']) {+ const sameTurn = await sameTurnTool.execute({+ op,+ composition_dir: 'project/composition',+ ...(op === 'composition.approve_draft'+ ? { decision_evidence: decisionEvidence('draft', 'approve', '确认制作') }+ : { output_path: 'project/render/final.mp4' }),+ }, ctx);+ expect(sameTurn.isError).toBe(true);+ expect(parseResult(sameTurn.content)).toMatchObject({+ errorCode: 'E_GATE_D_APPROVAL_REQUIRED',+ outcome: 'need_user',+ next_step_owner: 'user',+ next_action: 'show_current_artifact_and_request_user_decision',+ });+ expect(sameTurn.synthesizeAndEndTurn).toBe(true);+ }+ expect((await stateMod.readVideoProductionState(statePath, compositionDir)).draft?.status).toBe('ready');+ // An unconfirmed draft from an earlier turn keeps the agent-owned path:+ // the current message may confirm it, so export only says to approve first.+ const laterExport = await mod.createVideoStudioTool({+ userId: UID,+ cid: 'cid-explicit-gates',+ turnId: 'turn-later-export',+ agentId: VIDEO_STUDIO_AGENT_ID,+ agentName: 'VideoStudio',+ userMessage: '<msg from="user">可以,导出吧</msg>',+ }).execute({+ op: 'composition.export',+ composition_dir: 'project/composition',+ output_path: 'project/render/final.mp4',+ }, ctx);+ expect(parseResult(laterExport.content)).toMatchObject({+ errorCode: 'E_GATE_D_APPROVAL_REQUIRED',+ outcome: 'continue',+ });+ expect(laterExport.synthesizeAndEndTurn).not.toBe(true);const wrongGateTool = mod.createVideoStudioTool({userId: UID,cid: 'cid-explicit-gates',@@ -3938,6 +3987,104 @@ describe('VideoStudio production-state tool protocol', () => {expect(fs.readdirSync(strayChild)).toEqual([]);});+ it('names the standalone approval when a composition passes its own files as an AUTO parent binding', async () => {+ // 2026-09-20 (client 1.7.1): a standalone composition passed its own+ // manifest as plan_path. Every call entered the AUTO child branch and got a+ // different child-only refusal — "must remain silent", "both required",+ // "plan.segments must be a non-empty array" — before the model found the+ // standalone call, and the user was asked to agree a third time.+ makePlanVisualOnly();+ const toolMod = await import('../../../../src/main/model/core-agent/video-studio-tool');+ const ctx = { workingDir: workspace, state: {} } as any;+ const opts = {+ userId: UID,+ cid: 'cid-standalone-own-plan-path',+ turnId: 'turn-standalone-own-plan-path',+ agentId: VIDEO_STUDIO_AGENT_ID,+ agentName: 'VideoStudio',+ userMessage: '<msg from="user" to="79df9cc89f5f">@VideoStudio\n确认,继续制作。</msg>',+ };+ const approve = async (extra: Record<string, unknown>) => toolMod+ .createVideoStudioTool(opts)+ .execute({ ...compositionInput('composition.approve_plan'), ...extra }, ctx);+ const ownManifest = 'project/composition/composition-manifest.json';++ // The trace's first shape: plan_path alone, pointing at its own manifest.+ const onlyPlanPath = await approve({ plan_path: ownManifest });+ expect(onlyPlanPath.isError).toBe(true);+ const incomplete = parseResult(String(onlyPlanPath.content));+ expect(incomplete).toMatchObject({+ errorCode: 'E_PARENT_COMPOSITION_BINDING_INCOMPLETE',+ requires_user_decision: false,+ billable_request_sent: false,+ });+ expect(incomplete.message).toContain('omit plan_path and segment_id');+ expect(incomplete.message).not.toMatch(/silent|narration/);++ // Its later shape: the same file plus an invented segment id.+ const ownFile = parseResult(String((await approve({+ plan_path: ownManifest,+ segment_id: 'saudi-state-transition',+ })).content));+ expect(ownFile.errorCode).toBe('E_PARENT_COMPOSITION_BINDING_SELF');+ expect(ownFile.message).toContain('omit plan_path and segment_id');+ expect(ownFile.message).not.toContain('plan.segments');++ // The refusals recorded nothing; the standalone call in the same user turn+ // approves without asking the user again.+ const standalone = await approve({});+ expect(standalone.isError, String(standalone.content)).toBe(false);+ expect(parseResult(String(standalone.content)).approval_inherited).toBe(false);+ });++ it('refuses an AUTO binding to an unapproved parent, an unknown segment, or an out-of-scope plan before creating the child', async () => {+ const toolMod = await import('../../../../src/main/model/core-agent/video-studio-tool');+ const ctx = { workingDir: workspace, state: {} } as any;+ writeAutoParentPlan();+ const childDir = path.join(workspace, 'project', 'compositions', 'intro');+ const inherit = async (extra: Record<string, unknown>) => toolMod.createVideoStudioTool({+ userId: UID,+ cid: 'cid-auto-subject',+ turnId: 'turn-auto-subject',+ agentId: VIDEO_STUDIO_AGENT_ID,+ agentName: 'VideoStudio',+ userMessage: '<msg from="user">unrelated later turn</msg>',+ }).execute({+ op: 'composition.approve_plan',+ composition_dir: 'project/compositions/intro',+ plan_path: 'project/plan.json',+ segment_id: 'intro',+ ...extra,+ }, ctx);++ const unapproved = parseResult(String((await inherit({})).content));+ expect(unapproved.errorCode).toBe('E_PARENT_COMPOSITION_BINDING_UNAPPROVED');+ expect(unapproved.message).toContain('omit plan_path and segment_id');+ expect(fs.existsSync(childDir)).toBe(false);++ await toolMod.createVideoStudioTool({+ userId: UID,+ cid: 'cid-auto-subject-parent',+ turnId: 'turn-auto-subject-parent',+ agentId: VIDEO_STUDIO_AGENT_ID,+ agentName: 'VideoStudio',+ userMessage: approvalSubmission('gate_b_decision', 'approve'),+ }).execute({ op: 'production.approve_plan', plan_path: 'project/plan.json' }, ctx);++ const unknown = parseResult(String((await inherit({ segment_id: 'outro' })).content));+ expect(unknown).toMatchObject({+ errorCode: 'E_PARENT_COMPOSITION_SEGMENT_INVALID',+ compose_segment_ids: ['intro'],+ });+ expect(fs.existsSync(childDir)).toBe(false);++ const outside = parseResult(String((await inherit({+ plan_path: path.join(root, 'elsewhere', 'plan.json'),+ })).content));+ expect(outside.errorCode).toBe('E_PATH_OUT_OF_SCOPE');+ expect(fs.existsSync(childDir)).toBe(false);+ });+it('tells a narrated AUTO child to name the assembler instead of signing a voice', async () => {// 2026-08-04, 14:54: five consecutive E_GATE_B_ARTIFACT_INVALID on the same// child. stage-assemble said "keep it silent, audio.owner:none", while thediff --git a/test/main/util/sharp-runtime.test.ts b/test/main/util/sharp-runtime.test.tsindex 17b569af..2045d7c3 100644--- a/test/main/util/sharp-runtime.test.ts+++ b/test/main/util/sharp-runtime.test.ts@@ -1,4 +1,4 @@-import { fork, type ChildProcess } from 'node:child_process';+import { fork, spawnSync, type ChildProcess } from 'node:child_process';import { once } from 'node:events';import fs from 'node:fs';import os from 'node:os';@@ -44,6 +44,29 @@ afterEach(async () => {});describe('isolated bundled-Node image processing', () => {+ it('masks private screenshot pixels before cropping and resizing in stock Node', async () => {+ const images = client();+ const masked = await images.request('encode', input(12, 6), {+ format: 'png', composite: [{ input: Buffer.from('<svg width="12" height="6"><rect width="6" height="6" fill="black"/></svg>') }],+ });+ const cropped = await images.request('encode', masked.data, {+ format: 'png', extract: { left: 4, top: 0, width: 4, height: 6 },+ });+ const resized = await images.request('encode', cropped.data, {+ format: 'png', resize: { width: 8, height: 12, fit: 'inside', withoutEnlargement: false },+ });+ expect(resized.info).toMatchObject({ width: 8, height: 12 });+ const decoded = spawnSync(node!, ['-e', `const chunks=[];process.stdin.on('data',b=>chunks.push(b));process.stdin.on('end',async()=>{const {data,info}=await require(${JSON.stringify(require.resolve('sharp'))})(Buffer.concat(chunks)).ensureAlpha().raw().toBuffer({resolveWithObject:true});console.log(JSON.stringify({first:[...data.subarray(0,4)],last:[...data.subarray(data.length-4)],width:info.width,height:info.height}));});`], {+ input: resized.data, encoding: 'utf8', timeout: 10_000,+ env: { ...process.env, ELECTRON_RUN_AS_NODE: undefined },+ });+ expect(decoded.status, decoded.stderr).toBe(0);+ expect(decoded.stderr).toBe('');+ expect(JSON.parse(decoded.stdout)).toEqual({ first: [0, 0, 0, 255], last: [20, 40, 60, 255], width: 8, height: 12 });+ await expect(images.request('encode', masked.data, { format: 'png', extract: { left: 20, top: 0, width: 4, height: 6 } })).rejects.toThrow('E_IMAGE_PROCESS');+ expect(await images.request('metadata', input())).toMatchObject({ width: 4, height: 3 });+ });+it('preserves image dimensions and format across concurrent calls in a reused process', async () => {expect(node).toBeTruthy();const images = client();