Files
waggle-os/packages/server/tests/local/pins-documents-data-dir.test.ts
shumeiko.it 74200d46e8 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).
2026-11-01 02:08:57 +01:00

52 lines
1.9 KiB
TypeScript

import { afterEach, describe, expect, it } from 'vitest';
import Fastify, { type FastifyInstance } from 'fastify';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { documentRoutes } from '../../src/local/routes/documents.js';
import { pinRoutes } from '../../src/local/routes/pins.js';
/** UF-064: pins and documents follow the server's data directory, not ~/.waggle. */
describe('pins and documents storage', () => {
let server: FastifyInstance;
let dataDir: string;
async function buildServer(): Promise<FastifyInstance> {
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);
});
});