From 74200d46e8d5c274d09b8e6f31beebe838c5f912 Mon Sep 17 00:00:00 2001 From: "shumeiko.it" Date: Sun, 1 Nov 2026 02:08:57 +0100 Subject: [PATCH] fix: five defects found while rewriting the docs (UF-061 to UF-065) - Key messages named a Settings > API Keys tab that does not exist; they now point at Settings > Models (UF-061). - The connector suggestion looked for vault.db, which never exists; it now checks the vault for a connector entry (UF-062). - /config and /preferences were registered with a leading slash and never matched (UF-063). - Pins and documents were written under ~/.waggle whatever the data directory; they now use the server's data directory (UF-064). - The Windows uninstaller named a Data & Privacy page that does not exist (UF-065). --- app/src-tauri/nsis/installer.nsi | 2 +- .../os/apps/chat-blocks/ErrorBlock.test.tsx | 4 +- docs/oss/upstream-fixes.md | 50 ++++++++++++++++++ .../agent/src/commands/workflow-commands.ts | 2 +- .../agent/tests/workflow-commands.test.ts | 8 +++ packages/server/src/local/index.ts | 5 +- .../server/src/local/proactive-handlers.ts | 5 +- .../src/local/routes/anthropic-proxy.ts | 6 +-- packages/server/src/local/routes/chat.ts | 6 +-- packages/server/src/local/routes/documents.ts | 24 +++++---- packages/server/src/local/routes/pins.ts | 30 ++++++----- packages/server/src/local/service.ts | 2 +- .../local/pins-documents-data-dir.test.ts | 51 +++++++++++++++++++ .../server/tests/proactive-handlers.test.ts | 16 ++++++ 14 files changed, 171 insertions(+), 40 deletions(-) create mode 100644 packages/server/tests/local/pins-documents-data-dir.test.ts diff --git a/app/src-tauri/nsis/installer.nsi b/app/src-tauri/nsis/installer.nsi index 3bf9f1f..6b76bf4 100644 --- a/app/src-tauri/nsis/installer.nsi +++ b/app/src-tauri/nsis/installer.nsi @@ -19,7 +19,7 @@ !macro NSIS_HOOK_PREUNINSTALL StrCmp $DeleteAppDataCheckboxState "1" 0 +2 MessageBox MB_OK|MB_ICONINFORMATION \ - "For safety, Waggle always preserves app data during uninstall. Data can only be erased from Settings > Data & Privacy while Waggle is installed." + "For safety, Waggle always preserves app data during uninstall. Data can only be erased from Settings > General > Erase all my data while Waggle is installed." StrCpy $DeleteAppDataCheckboxState 0 DetailPrint "Preserving Waggle app data." !macroend diff --git a/apps/web/src/components/os/apps/chat-blocks/ErrorBlock.test.tsx b/apps/web/src/components/os/apps/chat-blocks/ErrorBlock.test.tsx index 2f8c052..7ed410e 100644 --- a/apps/web/src/components/os/apps/chat-blocks/ErrorBlock.test.tsx +++ b/apps/web/src/components/os/apps/chat-blocks/ErrorBlock.test.tsx @@ -35,7 +35,7 @@ function renderBlock(b: ErrorContentBlock, onRetry?: () => void) { describe('isAuthShapedError', () => { it('matches the server auth/API-key copy and raw 401', () => { - expect(isAuthShapedError('API key is invalid or expired. Update it in Settings > API Keys.')).toBe(true); + expect(isAuthShapedError('API key is invalid or expired. Update it in Settings > Models.')).toBe(true); expect(isAuthShapedError('Could not reach the AI model. Check that your API key is configured.')).toBe(true); expect(isAuthShapedError('Request failed with 401')).toBe(true); expect(isAuthShapedError('Unauthorized')).toBe(true); @@ -50,7 +50,7 @@ describe('isAuthShapedError', () => { describe('ErrorBlock', () => { it('auth-shaped error shows both actions; settings click deep-links to Models', () => { const onRetry = vi.fn(); - renderBlock(block('API key is invalid or expired. Update it in Settings > API Keys.'), onRetry); + renderBlock(block('API key is invalid or expired. Update it in Settings > Models.'), onRetry); expect(screen.getByRole('button', { name: /retry/i })).toBeInTheDocument(); const keyBtn = screen.getByRole('button', { name: /open api key settings/i }); fireEvent.click(keyBtn); diff --git a/docs/oss/upstream-fixes.md b/docs/oss/upstream-fixes.md index 1365fe9..e51afa0 100644 --- a/docs/oss/upstream-fixes.md +++ b/docs/oss/upstream-fixes.md @@ -89,6 +89,11 @@ Baseline: commit `b20b138` of the main Waggle repository. | UF-058 | The mock-embedding warning names a variable Waggle does not read | Fixed | Sidecar, embeddings | | UF-059 | Installers ship third-party code without its notices | Open | Licensing, packaging | | UF-060 | The sidecar ships `buffers` 0.1.1, which has no license | Open | Licensing | +| UF-061 | Key messages send users to "Settings > API Keys", which does not exist | Fixed | Sidecar | +| UF-062 | The connector suggestion looks for `vault.db`, which never exists | Fixed | Sidecar | +| UF-063 | `/config` and `/preferences` never run `/settings` | Fixed | Agent, commands | +| UF-064 | Pins and documents ignore the configured data directory | Fixed | Sidecar | +| UF-065 | The Windows uninstaller names a "Data & Privacy" settings page that does not exist | Fixed | Desktop, Windows installer | ## Entries @@ -605,3 +610,48 @@ Entries UF-010 to UF-019 come from the UI audit `anti-slop/audit-001-2026-10-14. - Cause: `exceljs` 4.4.0 still depends on `unzipper` 0.10, which pulls in the unmaintained `binary` and `buffers` packages. - What we did: nothing in the code yet. The OSS license gate lists it as an exception pending the licensing review, so the issue shows on every run. - Recommendation: remove the dependency, for example with an npm override to a newer `unzipper` release if one no longer depends on `binary` (check that `exceljs` still reads workbooks), or ask the author for a license. + +### UF-061. Key messages send users to "Settings > API Keys", which does not exist +- Status: Fixed +- Found: 2026-11-01 +- Where: at commit `b20b138`, `packages/server/src/local/service.ts:403`, `packages/server/src/local/index.ts:3036,3208`, `packages/server/src/local/routes/anthropic-proxy.ts:910,1120,1127`, `packages/server/src/local/routes/chat.ts:1818,1864,3738` +- Symptom: when no provider key is set or a key has expired, the health status, the proxy errors and the chat replies tell the user to open "Settings > API Keys". Settings has no such tab; its tabs are General, Models, Permissions, Channels, Backup and Advanced (plus the commercial ones). +- Cause: the copy was written for an earlier Settings layout. Keys moved to the Provider Keys section of Settings → Models and to the Vault app; the chat error action already opens Settings → Models. +- What we did: every message now says "Settings > Models". +- Recommendation: point the copy at Settings > Models, and keep the server copy and the Settings tab names in one shared constant. + +### UF-062. The connector suggestion looks for `vault.db`, which never exists +- Status: Fixed +- Found: 2026-11-01 +- Where: at commit `b20b138`, `packages/server/src/local/proactive-handlers.ts:292` +- Symptom: after 50 memories the "Connect your external tools" suggestion appears even when the user has connected GitHub, Slack or another connector. +- Cause: the handler treats the existence of `/vault.db` as "a connector is set up", but the vault is `vault.json` (`packages/core/src/vault.ts`). The file check is also too broad: provider API keys live in the same vault. +- What we did: the proactive context now carries the vault, and the handler checks for a `connector:` entry. A test covers both cases. +- Recommendation: same change in the main project. + +### UF-063. `/config` and `/preferences` never run `/settings` +- Status: Fixed +- Found: 2026-11-01 +- Where: at commit `b20b138`, `packages/agent/src/commands/workflow-commands.ts:442` +- Symptom: typing `/config` or `/preferences` in chat answers "Unknown command". +- Cause: the aliases are registered as `'/config'` and `'/preferences'`, but the registry strips the leading slash before the lookup, as it does for every other alias. +- What we did: registered the aliases without the slash and added a test. +- Recommendation: same change in the main project; the registry could also reject aliases that start with `/`. + +### UF-064. Pins and documents ignore the configured data directory +- Status: Fixed +- Found: 2026-11-01 +- Where: at commit `b20b138`, `packages/server/src/local/routes/pins.ts:32`, `packages/server/src/local/routes/documents.ts:37` +- Symptom: with `WAGGLE_DATA_DIR` or a custom data directory, pinned messages and the document version registry are still written to `~/.waggle/workspaces//`, so they split from the rest of the workspace and survive a data erase of the configured directory. +- Cause: both routes build the path from `os.homedir()` instead of the server's data directory. +- What we did: both routes use `localConfig.dataDir`. A test checks where the files land. +- Recommendation: same change in the main project, and a lint rule against `os.homedir()` in routes. + +### UF-065. The Windows uninstaller names a "Data & Privacy" settings page that does not exist +- Status: Fixed +- Found: 2026-11-01 +- Where: at commit `b20b138`, `app/src-tauri/nsis/installer.nsi:22` +- Symptom: when the user ticks "delete app data" in the uninstaller, the message says data can only be erased from "Settings > Data & Privacy". There is no such page. +- Cause: the copy predates the current Settings layout; the erase action is the "Erase all my data" button on Settings → General. +- What we did: the message now names Settings > General > Erase all my data. +- Recommendation: same change in the main project. diff --git a/packages/agent/src/commands/workflow-commands.ts b/packages/agent/src/commands/workflow-commands.ts index 2dca195..613d9a2 100644 --- a/packages/agent/src/commands/workflow-commands.ts +++ b/packages/agent/src/commands/workflow-commands.ts @@ -439,7 +439,7 @@ function importCommand(): CommandDefinition { function settingsCommand(): CommandDefinition { return { name: 'settings', - aliases: ['/config', '/preferences'], + aliases: ['config', 'preferences'], description: 'Show current workspace and agent settings', usage: '/settings', handler: async (_args, context) => { diff --git a/packages/agent/tests/workflow-commands.test.ts b/packages/agent/tests/workflow-commands.test.ts index d5d68b0..73ec1e1 100644 --- a/packages/agent/tests/workflow-commands.test.ts +++ b/packages/agent/tests/workflow-commands.test.ts @@ -90,6 +90,14 @@ describe('CommandRegistry', () => { expect(result).toContain('Unknown command'); expect(result).toContain('/nonexistent'); }); + + it('runs /settings through its /config and /preferences aliases (UF-063)', () => { + const registry = new CommandRegistry(); + registerWorkflowCommands(registry); + + expect(registry.get('config')?.name).toBe('settings'); + expect(registry.get('preferences')?.name).toBe('settings'); + }); }); describe('Workflow Commands', () => { diff --git a/packages/server/src/local/index.ts b/packages/server/src/local/index.ts index 76eb74d..3950db0 100644 --- a/packages/server/src/local/index.ts +++ b/packages/server/src/local/index.ts @@ -1370,6 +1370,7 @@ export async function buildLocalServer(config: Partial = {}) { workspaceManager: wsManager, memory, waggleDb, + vault, }; /** Emit a ProactiveMessage through the delivery router pipeline. */ @@ -2185,7 +2186,7 @@ export async function buildLocalServer(config: Partial = {}) { return null; } - function markAnthropicProxyDegraded(detail = 'Built-in Anthropic proxy (API key invalid or expired, update in Settings > API Keys)'): void { + function markAnthropicProxyDegraded(detail = 'Built-in Anthropic proxy (API key invalid or expired, update in Settings > Models)'): void { server.agentState.llmProvider.health = 'degraded'; server.agentState.llmProvider.detail = detail; } @@ -2356,7 +2357,7 @@ export async function buildLocalServer(config: Partial = {}) { const keyValid = freshAnthropicValidation(); if (keyValid === false) { llm.health = 'degraded'; - llm.detail = 'Built-in Anthropic proxy (API key invalid or expired, update in Settings > API Keys)'; + llm.detail = 'Built-in Anthropic proxy (API key invalid or expired, update in Settings > Models)'; markAnthropicProxyDegraded(llm.detail); } else if (keyValid === null) { validateAnthropicKeyInBackground(); diff --git a/packages/server/src/local/proactive-handlers.ts b/packages/server/src/local/proactive-handlers.ts index c929742..0f10ae2 100644 --- a/packages/server/src/local/proactive-handlers.ts +++ b/packages/server/src/local/proactive-handlers.ts @@ -36,6 +36,8 @@ export interface ProactiveContext { memory: MemoryStore; /** waggle.db, which holds awareness items. */ waggleDb: import('@waggle/core').WaggleDB; + /** Connector credentials live in the vault under `connector:`. */ + vault?: Pick; } // ── Helpers ──────────────────────────────────────────────────────────── @@ -276,8 +278,7 @@ export async function suggestCapabilities(ctx: ProactiveContext): Promise 50) { const hasConnectors = (() => { try { - const vaultPath = path.join(ctx.dataDir, 'vault.db'); - return fs.existsSync(vaultPath); + return ctx.vault?.list().some((entry) => entry.name.startsWith('connector:')) ?? false; } catch { return false; } diff --git a/packages/server/src/local/routes/anthropic-proxy.ts b/packages/server/src/local/routes/anthropic-proxy.ts index da4215c..053380d 100644 --- a/packages/server/src/local/routes/anthropic-proxy.ts +++ b/packages/server/src/local/routes/anthropic-proxy.ts @@ -907,7 +907,7 @@ async function forwardCompatibleProvider( if (apiKeys.length === 0) { return reply.status(500).send({ error: { - message: `No ${route.providerId} API key configured. Add one in Settings > API Keys.`, + message: `No ${route.providerId} API key configured. Add one in Settings > Models.`, }, }); } @@ -1117,14 +1117,14 @@ export const anthropicProxyRoutes: FastifyPluginAsync = async (server) => { if (route.providerId === 'anthropic' && !getAnthropicKey(server)) { releaseProxySpend(server, claimProxySpendHandoff(server, request, body)); return reply.status(500).send({ - error: { message: 'No Anthropic API key configured. Add one in Settings > API Keys.' }, + error: { message: 'No Anthropic API key configured. Add one in Settings > Models.' }, }); } if (route.providerId !== 'anthropic' && getProviderApiKeys(route.providerId, server.vault).length === 0) { releaseProxySpend(server, claimProxySpendHandoff(server, request, body)); return reply.status(500).send({ error: { - message: `No ${route.providerId} API key configured. Add one in Settings > API Keys.`, + message: `No ${route.providerId} API key configured. Add one in Settings > Models.`, }, }); } diff --git a/packages/server/src/local/routes/chat.ts b/packages/server/src/local/routes/chat.ts index fce4cfa..3c90bd0 100644 --- a/packages/server/src/local/routes/chat.ts +++ b/packages/server/src/local/routes/chat.ts @@ -1748,7 +1748,7 @@ ${wsConfig?.templateId ? `- Workspace template: ${wsConfig.templateId} — tailo reroutedMessage = rerouted; } else if (cmdResult.startsWith(AGENT_LOOP_REROUTE_PREFIX) && !litellmAvailable) { const cmdName = message.trim().split(/\s+/)[0]; - const friendlyError = `**${cmdName} requires AI.** This command needs a working LLM connection.\n\nConfigure an API key in Settings > API Keys, then try again.`; + const friendlyError = `**${cmdName} requires AI.** This command needs a working LLM connection.\n\nConfigure an API key in Settings > Models, then try again.`; const words = friendlyError.split(' '); for (const word of words) { if (turnSignal.aborted) return; @@ -1794,7 +1794,7 @@ ${wsConfig?.templateId ? `- Workspace template: ${wsConfig.templateId} — tailo if (shouldEchoMode) { // Setup-required mode — respond without pretending the user's input // was answered. The raw turn is still persisted for continuity. - const echoResponse = '**No AI model is ready.**\n\nConfigure a provider key in Settings > API Keys, or install and verify a local model in Settings > Models, then try again.'; + const echoResponse = '**No AI model is ready.**\n\nConfigure a provider key in Settings > Models, or install and verify a local model in Settings > Models, then try again.'; const words = echoResponse.split(' '); for (const word of words) { if (turnSignal.aborted) return; @@ -3471,7 +3471,7 @@ ${wsConfig?.templateId ? `- Workspace template: ${wsConfig.templateId} — tailo if (err.message.includes('ECONNREFUSED')) { errorMessage = 'Could not reach the AI model. Check that your API key is configured in Settings.'; } else if (err.message.includes('401') || err.message.includes('Unauthorized')) { - errorMessage = 'API key is invalid or expired. Update it in Settings > API Keys.'; + errorMessage = 'API key is invalid or expired. Update it in Settings > Models.'; } else if (err.message.includes('timeout') || err.message.includes('ETIMEDOUT')) { errorMessage = 'The request timed out. The model may be overloaded. Try again in a moment.'; } else if (err.message.includes('context_length') || err.message.includes('too many tokens')) { diff --git a/packages/server/src/local/routes/documents.ts b/packages/server/src/local/routes/documents.ts index 3a3ca78..221fb57 100644 --- a/packages/server/src/local/routes/documents.ts +++ b/packages/server/src/local/routes/documents.ts @@ -6,7 +6,7 @@ * POST /api/workspaces/:id/documents — register a new document version * GET /api/workspaces/:id/documents/:name/versions — list versions of a document * - * Versions are stored in ~/.waggle/workspaces/{id}/documents.json. + * Versions are stored in /workspaces/{id}/documents.json. * Part of Wave 7 — Professional & Vertical Features. */ @@ -33,13 +33,13 @@ interface DocumentsRegistry { } /** Resolve the documents.json path for a workspace. */ -function documentsFilePath(workspaceId: string): string { - return path.join(os.homedir(), '.waggle', 'workspaces', workspaceId, 'documents.json'); +function documentsFilePath(dataDir: string, workspaceId: string): string { + return path.join(dataDir, 'workspaces', workspaceId, 'documents.json'); } /** Read document registry from disk. Returns empty registry if file doesn't exist. */ -function readRegistry(workspaceId: string): DocumentsRegistry { - const filePath = documentsFilePath(workspaceId); +function readRegistry(dataDir: string, workspaceId: string): DocumentsRegistry { + const filePath = documentsFilePath(dataDir, workspaceId); try { if (fs.existsSync(filePath)) { const raw = fs.readFileSync(filePath, 'utf-8'); @@ -52,8 +52,8 @@ function readRegistry(workspaceId: string): DocumentsRegistry { } /** Write document registry to disk. Creates directory if needed. */ -function writeRegistry(workspaceId: string, registry: DocumentsRegistry): void { - const filePath = documentsFilePath(workspaceId); +function writeRegistry(dataDir: string, workspaceId: string, registry: DocumentsRegistry): void { + const filePath = documentsFilePath(dataDir, workspaceId); const dir = path.dirname(filePath); if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); @@ -62,13 +62,15 @@ function writeRegistry(workspaceId: string, registry: DocumentsRegistry): void { } export const documentRoutes: FastifyPluginAsync = async (server) => { + const dataDir = server.localConfig?.dataDir || process.env.WAGGLE_DATA_DIR || path.join(os.homedir(), '.waggle'); + // GET /api/workspaces/:id/documents — list all tracked documents server.get<{ Params: { id: string }; }>('/api/workspaces/:id/documents', async (request) => { const { id } = request.params; assertSafeSegment(id, 'id'); - const registry = readRegistry(id); + const registry = readRegistry(dataDir, id); return { documents: registry.documents.map(doc => ({ name: doc.name, @@ -96,7 +98,7 @@ export const documentRoutes: FastifyPluginAsync = async (server) => { } assertSafeSegment(name, 'name'); - const registry = readRegistry(id); + const registry = readRegistry(dataDir, id); let doc = registry.documents.find(d => d.name === name); if (!doc) { @@ -116,7 +118,7 @@ export const documentRoutes: FastifyPluginAsync = async (server) => { }; doc.versions.push(version); - writeRegistry(id, registry); + writeRegistry(dataDir, id, registry); return reply.status(201).send({ document: name, version }); }); @@ -128,7 +130,7 @@ export const documentRoutes: FastifyPluginAsync = async (server) => { const { id, name } = request.params; assertSafeSegment(id, 'id'); assertSafeSegment(name, 'name'); - const registry = readRegistry(id); + const registry = readRegistry(dataDir, id); const doc = registry.documents.find(d => d.name === name); if (!doc) { diff --git a/packages/server/src/local/routes/pins.ts b/packages/server/src/local/routes/pins.ts index 230f85c..896434b 100644 --- a/packages/server/src/local/routes/pins.ts +++ b/packages/server/src/local/routes/pins.ts @@ -6,7 +6,7 @@ * POST /api/workspaces/:id/pins — add pin * DELETE /api/workspaces/:id/pins/:pinId — remove pin * - * Pins are stored in a JSON file at ~/.waggle/workspaces/{id}/pins.json. + * Pins are stored in a JSON file at /workspaces/{id}/pins.json. * Part of Wave 5 — Visibility & Polish. */ @@ -28,13 +28,13 @@ export interface PinnedItem { } /** Resolve the pins.json path for a workspace. */ -function pinsFilePath(workspaceId: string): string { - return path.join(os.homedir(), '.waggle', 'workspaces', workspaceId, 'pins.json'); +function pinsFilePath(dataDir: string, workspaceId: string): string { + return path.join(dataDir, 'workspaces', workspaceId, 'pins.json'); } /** Read pins from disk. Returns empty array if file doesn't exist. */ -function readPins(workspaceId: string): PinnedItem[] { - const filePath = pinsFilePath(workspaceId); +function readPins(dataDir: string, workspaceId: string): PinnedItem[] { + const filePath = pinsFilePath(dataDir, workspaceId); try { if (fs.existsSync(filePath)) { const raw = fs.readFileSync(filePath, 'utf-8'); @@ -47,8 +47,8 @@ function readPins(workspaceId: string): PinnedItem[] { } /** Write pins to disk. Creates directory if needed. */ -function writePins(workspaceId: string, pins: PinnedItem[]): void { - const filePath = pinsFilePath(workspaceId); +function writePins(dataDir: string, workspaceId: string, pins: PinnedItem[]): void { + const filePath = pinsFilePath(dataDir, workspaceId); const dir = path.dirname(filePath); if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); @@ -57,12 +57,14 @@ function writePins(workspaceId: string, pins: PinnedItem[]): void { } export const pinRoutes: FastifyPluginAsync = async (server) => { + const dataDir = server.localConfig?.dataDir || process.env.WAGGLE_DATA_DIR || path.join(os.homedir(), '.waggle'); + // GET /api/workspaces/:id/pins — list pins for workspace server.get<{ Params: { id: string }; }>('/api/workspaces/:id/pins', async (request) => { const { id } = request.params; - const pins = readPins(id); + const pins = readPins(dataDir, id); return { pins }; }); @@ -86,7 +88,7 @@ export const pinRoutes: FastifyPluginAsync = async (server) => { return reply.status(400).send({ error: 'messageRole must be "assistant" or "user"' }); } - const pins = readPins(id); + const pins = readPins(dataDir, id); const pin: PinnedItem = { id: crypto.randomUUID(), workspaceId: id, @@ -96,7 +98,7 @@ export const pinRoutes: FastifyPluginAsync = async (server) => { label, }; pins.push(pin); - writePins(id, pins); + writePins(dataDir, id, pins); return reply.status(201).send({ pin }); }); @@ -113,7 +115,7 @@ export const pinRoutes: FastifyPluginAsync = async (server) => { return reply.status(400).send({ error: 'status must be "draft" or "final"' }); } - const pins = readPins(id); + const pins = readPins(dataDir, id); const pin = pins.find(p => p.id === pinId); if (!pin) { return reply.status(404).send({ error: 'Pin not found' }); @@ -122,7 +124,7 @@ export const pinRoutes: FastifyPluginAsync = async (server) => { if (status !== undefined) pin.status = status; if (label !== undefined) pin.label = label; - writePins(id, pins); + writePins(dataDir, id, pins); return { pin }; }); @@ -131,13 +133,13 @@ export const pinRoutes: FastifyPluginAsync = async (server) => { Params: { id: string; pinId: string }; }>('/api/workspaces/:id/pins/:pinId', async (request, reply) => { const { id, pinId } = request.params; - const pins = readPins(id); + const pins = readPins(dataDir, id); const idx = pins.findIndex(p => p.id === pinId); if (idx === -1) { return reply.status(404).send({ error: 'Pin not found' }); } pins.splice(idx, 1); - writePins(id, pins); + writePins(dataDir, id, pins); return { ok: true }; }); }; diff --git a/packages/server/src/local/service.ts b/packages/server/src/local/service.ts index f87d8e2..564a5a7 100644 --- a/packages/server/src/local/service.ts +++ b/packages/server/src/local/service.ts @@ -383,7 +383,7 @@ export async function startService(options?: ServiceOptions): Promise { + let server: FastifyInstance; + let dataDir: string; + + async function buildServer(): Promise { + dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-pins-docs-')); + const instance = Fastify({ logger: false }); + instance.decorate('localConfig', { dataDir } as never); + await instance.register(pinRoutes); + await instance.register(documentRoutes); + await instance.ready(); + return instance; + } + + afterEach(async () => { + await server?.close(); + fs.rmSync(dataDir, { recursive: true, force: true }); + }); + + it('writes pins.json and documents.json under the configured data directory', async () => { + server = await buildServer(); + + const pin = await server.inject({ + method: 'POST', + url: '/api/workspaces/ws-one/pins', + payload: { messageContent: 'Keep this', messageRole: 'assistant' }, + }); + expect(pin.statusCode).toBeLessThan(300); + const doc = await server.inject({ + method: 'POST', + url: '/api/workspaces/ws-one/documents', + payload: { name: 'plan', path: '/tmp/plan.md' }, + }); + expect(doc.statusCode).toBeLessThan(300); + + expect(fs.existsSync(path.join(dataDir, 'workspaces', 'ws-one', 'pins.json'))).toBe(true); + expect(fs.existsSync(path.join(dataDir, 'workspaces', 'ws-one', 'documents.json'))).toBe(true); + + const list = await server.inject({ method: 'GET', url: '/api/workspaces/ws-one/pins' }); + expect(list.json().pins).toHaveLength(1); + }); +}); diff --git a/packages/server/tests/proactive-handlers.test.ts b/packages/server/tests/proactive-handlers.test.ts index 132f992..eb73de7 100644 --- a/packages/server/tests/proactive-handlers.test.ts +++ b/packages/server/tests/proactive-handlers.test.ts @@ -275,5 +275,21 @@ describe('Proactive Handlers', () => { const result = await suggestCapabilities(ctx); expect(result).toBeNull(); }); + + it('suggests connectors only while none is connected (UF-062)', async () => { + fs.mkdirSync(path.join(tmpDir, 'skills', 'research-skill'), { recursive: true }); + const ws = wsManager.create({ name: 'Busy Project', group: 'Test' }); + for (let i = 0; i < 51; i++) { + await memory.remember({ scope: workspaceScope(ws.id), text: `Distinct memory number ${i}` }); + } + const entries = [{ name: 'anthropic', updatedAt: '2026-11-01T00:00:00.000Z' }]; + const ctx = { ...makeContext(), vault: { list: () => entries } }; + + const withoutConnector = await suggestCapabilities(ctx); + expect(withoutConnector?.actionUrl).toBe('/connectors'); + + entries.push({ name: 'connector:github', updatedAt: '2026-11-01T00:00:00.000Z' }); + expect(await suggestCapabilities(ctx)).toBeNull(); + }); }); });