Reject matching visit and worker database paths during validation #59
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@goto/cli': patch
|
||||
---
|
||||
|
||||
Reject configurations that point the visit and worker databases at the same path. The CLI, services, and visit seeder now enforce the same rule when loading YAML.
|
||||
@@ -145,6 +145,12 @@ describe('goto-cli config validate', () => {
|
||||
source: validYaml,
|
||||
environment: { ...env, DUMMY_SECRET: 'too-short' }
|
||||
},
|
||||
{
|
||||
name: 'database settings that resolve to the same path',
|
||||
source: `${validYaml}database:\n path: ./data/goto.sqlite\n worker_path: ./work/../data/goto.sqlite\n`,
|
||||
environment: env,
|
||||
issue: '\n /database/worker_path: Must not resolve to the same path as database.path\n'
|
||||
},
|
||||
{
|
||||
name: 'invalid appearance alongside dropped tags',
|
||||
source: `${validYaml} tags: [., ""]\nappearance: false\n`,
|
||||
|
||||
@@ -170,10 +170,10 @@ test('rejects a shared worker/visit file before opening either connection', asyn
|
||||
}
|
||||
expect(failure).toBeInstanceOf(ConfigError);
|
||||
expect(failure).toHaveProperty('issues', [
|
||||
{ path: '/database/worker_path', message: 'Expected a different file from database.path' }
|
||||
{ path: '/database/worker_path', message: 'Must not resolve to the same path as database.path' }
|
||||
]);
|
||||
expect(formatWorkerStartupFailure(failure)).toBe(
|
||||
'Unable to start worker service\n /database/worker_path: Expected a different file from database.path'
|
||||
'Unable to start worker service\n /database/worker_path: Must not resolve to the same path as database.path'
|
||||
);
|
||||
expect(existsSync(join(directory, 'data'))).toBe(false);
|
||||
});
|
||||
|
||||
@@ -49,11 +49,6 @@ export async function startWorkerService(
|
||||
if (prepared.warnings.length > 0) logger.warn(formatConfigWarnings(prepared.warnings));
|
||||
const workerDatabasePath = prepared.configuration.database.worker_path;
|
||||
const applicationDatabasePath = prepared.configuration.database.path;
|
||||
if (workerDatabasePath === applicationDatabasePath) {
|
||||
throw new ConfigError([
|
||||
{ path: '/database/worker_path', message: 'Expected a different file from database.path' }
|
||||
]);
|
||||
}
|
||||
const resources: ShutdownResources = {};
|
||||
const stop = createShutdown(resources);
|
||||
try {
|
||||
|
||||
@@ -29,6 +29,14 @@ export async function loadConfigFile(
|
||||
const database = prepared.configuration.database;
|
||||
database.path = resolve(deploymentRoot, database.path);
|
||||
database.worker_path = resolve(deploymentRoot, database.worker_path);
|
||||
if (database.path === database.worker_path) {
|
||||
throw new ConfigError([
|
||||
{
|
||||
path: '/database/worker_path',
|
||||
message: 'Must not resolve to the same path as database.path'
|
||||
}
|
||||
]);
|
||||
}
|
||||
return prepared;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { resolve } from 'node:path';
|
||||
import { setImmediate } from 'node:timers/promises';
|
||||
import { parseArgs } from 'node:util';
|
||||
import { createVisitPeriod } from '../packages/analytics/src/period.ts';
|
||||
import { loadConfigFile } from '../packages/config/src/index.ts';
|
||||
import { ConfigError, formatConfigError, loadConfigFile } from '../packages/config/src/index.ts';
|
||||
import { openDb, insertVisit } from '../packages/db/src/index.ts';
|
||||
import { generateVisits } from './seed-visits-data.js';
|
||||
|
||||
@@ -77,15 +77,11 @@ function seedPlan(prepared, options) {
|
||||
const total = Object.keys(domains).length * options.visitsPerDomain;
|
||||
if (!Number.isSafeInteger(total))
|
||||
throw new Error('Total visit count exceeds the safe integer range');
|
||||
const databasePath = configuration.database.path;
|
||||
if (databasePath === configuration.database.worker_path) {
|
||||
throw new Error('Visits and worker database paths must differ');
|
||||
}
|
||||
const asOf = Date.now();
|
||||
const period = createVisitPeriod(months, asOf);
|
||||
const since = Date.parse(period.from);
|
||||
return {
|
||||
databasePath,
|
||||
databasePath: configuration.database.path,
|
||||
domains,
|
||||
since,
|
||||
asOf,
|
||||
@@ -165,7 +161,7 @@ async function appendBatch(db, visits) {
|
||||
|
||||
if (import.meta.main) {
|
||||
main().catch((error) => {
|
||||
console.error(error.message);
|
||||
console.error(error instanceof ConfigError ? formatConfigError(error) : error.message);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
}
|
||||
@@ -150,6 +150,23 @@ test('preview opens no SQLite file and applying refuses to create a missing data
|
||||
}
|
||||
});
|
||||
|
||||
test('reports the field when the worker database path conflicts with the default visits path', async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), 'goto-seed-shared-database-'));
|
||||
try {
|
||||
const { configPath } = await deployment(directory);
|
||||
await writeFile(
|
||||
configPath,
|
||||
JSON.stringify({ ...fixture, database: { worker_path: './data/goto.sqlite' } })
|
||||
);
|
||||
const result = run('--config', configPath);
|
||||
assert.equal(result.status, 1);
|
||||
assert.match(result.stderr, /\/database\/worker_path: Must not resolve to the same path/);
|
||||
assert.equal(result.stdout, '');
|
||||
} finally {
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('preview leaves existing visits untouched; apply appends visits for every domain', async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), 'goto-seed-apply-'));
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user