mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 18:04:18 +00:00
a7aaa29c16
An unreadable or empty encryption-key file was treated the same as a missing one: regenerate and overwrite. That is the one case where regenerating is the worst possible move - every secret already at rest becomes undecryptable, permanently. Both now refuse to start and say which file to fix. The key-rotation script advertised re-encrypting all stored secrets while its hardcoded column lists had drifted: the AirTrail key, the per-user LLM key and the plugin OAuth tokens were never migrated, so they silently stopped decrypting after a rotation. The parity test now pins the full set against what the code actually encrypts, rather than two tables of it. The schema_version bump ran outside the migration's transaction, so a crash in between left the schema advanced and the version stale - the next boot replayed a non-idempotent step and exited, turning one crash into a boot loop. And the TICKETJSON receipt migration matched with LIKE, which SQLite treats case-insensitively, so a note somebody had typed starting 'ticketjson:' was cut up and its text dropped. Also: APP_VERSION was interpolated into migration SQL instead of bound, the capture-metadata backfill passed (photoId, userId) to a (userId, photoId) signature and its mock keyed on the wrong argument, TRUST_PROXY=0 was accepted and silently coerced to 1, demo-reset hardcoded the db path instead of honouring TREK_DB_FILE, and a demo instance with no DEMO_ADMIN_PASS set now says out loud that its admin password is the published default.
41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
/**
|
|
* Structural guard for demo-reset's DB path.
|
|
*
|
|
* demo-reset closes the live connection, copies the baseline over the database
|
|
* file and reopens. It used to compute that file itself as data/travel.db, which
|
|
* is wrong the moment TREK_DB_FILE moves the database elsewhere: the baseline
|
|
* lands on an unrelated file and the real database is never reset. The path has
|
|
* to come from the connection that database.ts actually opened.
|
|
*
|
|
* It is pinned on the source rather than executed because demo-reset resolves
|
|
* ../db/database through a runtime require() (the module is a boot-time
|
|
* singleton), which vitest's module runner cannot resolve.
|
|
*/
|
|
import { describe, it, expect } from 'vitest';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
const source = fs.readFileSync(path.join(__dirname, '..', '..', '..', 'src', 'demo', 'demo-reset.ts'), 'utf8');
|
|
|
|
describe('demo-reset DB path', () => {
|
|
it('DEMORESET-001: never hardcodes the default travel.db path', () => {
|
|
expect(source).not.toContain("'travel.db'");
|
|
});
|
|
|
|
it('DEMORESET-002: takes the path from the open connection', () => {
|
|
expect(source).toContain('db.name');
|
|
// Both entry points, not just one of them.
|
|
const uses = source.match(/liveDbPath\(db\)/g) ?? [];
|
|
expect(uses.length).toBe(2);
|
|
});
|
|
|
|
it('DEMORESET-003: keeps the baseline next to the data directory', () => {
|
|
expect(source).toContain("path.join(dataDir, 'travel-baseline.db')");
|
|
});
|
|
|
|
it('DEMORESET-004: bails out on an in-memory database instead of copying files', () => {
|
|
const guards = source.match(/=== ':memory:'/g) ?? [];
|
|
expect(guards.length).toBe(2);
|
|
});
|
|
});
|