The community edition defaulted to ~/.waggle, the data directory of the commercial Waggle, so both editions would open the same config, vault, waggle.db, marketplace catalog and skills. Default to ~/.waggle-community instead (ADR-0011). WAGGLE_DATA_DIR still overrides it wherever it did; nothing is migrated from ~/.waggle. The name is defined once as DEFAULT_DATA_DIR_NAME and DEFAULT_DATA_DIR_LABEL in @waggle/shared, with defaultDataDir() in @waggle/core for the sidecar, the CLI, the agent and the model caches. The marketplace installs on its own without workspace packages, so it keeps a copy in its data-dir.ts; the CLI help, which loads no dependency, spells the path out and its runtime test checks it. The marketplace security scan also flags skills that reference the new skills folder. Tests that asserted the old default now use the constant, and comments name the new directory.
93 lines
3.3 KiB
TypeScript
93 lines
3.3 KiB
TypeScript
/**
|
|
* D11 (UX-Refactor P4) — dataDir resolution.
|
|
*
|
|
* - resolveDataDir: explicit option > WAGGLE_DATA_DIR env > ~/.waggle-community. Before
|
|
* D11, startService ignored the env var while local/index.ts and the
|
|
* marketplace installer honored it — a custom install split
|
|
* its state across two directories.
|
|
*/
|
|
import { describe, it, expect, afterEach, vi } from 'vitest';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import os from 'node:os';
|
|
import { DEFAULT_DATA_DIR_NAME } from '@waggle/shared';
|
|
import { startService, resolveDataDir } from '../src/local/service.js';
|
|
import type { FastifyInstance } from 'fastify';
|
|
|
|
function makeTmpDir(): string {
|
|
return fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-d11-test-'));
|
|
}
|
|
|
|
const ENV_KEY = 'WAGGLE_DATA_DIR';
|
|
|
|
describe('resolveDataDir (D11)', () => {
|
|
const envBefore = process.env[ENV_KEY];
|
|
afterEach(() => {
|
|
if (envBefore === undefined) delete process.env[ENV_KEY];
|
|
else process.env[ENV_KEY] = envBefore;
|
|
});
|
|
|
|
it('explicit option wins over the env var', () => {
|
|
process.env[ENV_KEY] = 'D:/somewhere/else';
|
|
expect(resolveDataDir('D:/explicit')).toBe('D:/explicit');
|
|
});
|
|
|
|
it('WAGGLE_DATA_DIR is honored when no option is given', () => {
|
|
process.env[ENV_KEY] = 'D:/from-env';
|
|
expect(resolveDataDir()).toBe('D:/from-env');
|
|
});
|
|
|
|
it('defaults to ~/.waggle-community with neither, never the commercial ~/.waggle (ADR-0011)', () => {
|
|
delete process.env[ENV_KEY];
|
|
expect(resolveDataDir()).toBe(path.join(os.homedir(), DEFAULT_DATA_DIR_NAME));
|
|
expect(resolveDataDir()).not.toBe(path.join(os.homedir(), '.waggle'));
|
|
});
|
|
|
|
it('a set-but-EMPTY env var falls through to the default (never an empty dataDir)', () => {
|
|
process.env[ENV_KEY] = '';
|
|
expect(resolveDataDir()).toBe(path.join(os.homedir(), DEFAULT_DATA_DIR_NAME));
|
|
});
|
|
});
|
|
|
|
describe('startService honors WAGGLE_DATA_DIR (D11 integration)', () => {
|
|
const envBefore = process.env[ENV_KEY];
|
|
let server: FastifyInstance | undefined;
|
|
let tmp: string | undefined;
|
|
|
|
afterEach(async () => {
|
|
if (envBefore === undefined) delete process.env[ENV_KEY];
|
|
else process.env[ENV_KEY] = envBefore;
|
|
if (server) await server.close();
|
|
server = undefined;
|
|
if (tmp) fs.rmSync(tmp, { recursive: true, force: true });
|
|
tmp = undefined;
|
|
});
|
|
|
|
it('boots against the env-pointed directory when no dataDir option is passed', async () => {
|
|
tmp = makeTmpDir();
|
|
const envDir = path.join(tmp, 'env-pointed');
|
|
process.env[ENV_KEY] = envDir;
|
|
const port = 4600 + Math.floor(Math.random() * 400);
|
|
const logSpy = vi.spyOn(console, 'log');
|
|
|
|
try {
|
|
const result = await startService({ port, skipLiteLLM: true });
|
|
server = result.server;
|
|
|
|
// The env-pointed dir got the install, ~/.waggle-community got nothing new from us.
|
|
expect(fs.existsSync(path.join(envDir, 'waggle.db'))).toBe(true);
|
|
expect(server.localConfig.dataDir).toBe(envDir);
|
|
|
|
// The ratified D11 deliverable is the LOG LINE itself — pin it (review
|
|
// gap: deleting the line kept every gate green).
|
|
const dataDirLine = logSpy.mock.calls
|
|
.map((c) => String(c[0]))
|
|
.find((m) => m.includes('[waggle:service] Data dir:'));
|
|
expect(dataDirLine).toContain(envDir);
|
|
expect(dataDirLine?.endsWith(`Data dir: ${envDir}`)).toBe(true);
|
|
} finally {
|
|
logSpy.mockRestore();
|
|
}
|
|
});
|
|
});
|