mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-16 17:09:09 +00:00
* fix(6848): add auto-cleanup for telemetry tables that grow without bound Add retention-based cleanup for 4 tables that had no prune policy: - domain_cost_history (timestamp INTEGER, unix epoch) - compression_cache_stats (created_at DATETIME) - xp_audit_log (created_at TEXT) - compression_run_telemetry (timestamp INTEGER, unix epoch) All default to 30-day retention, integrated into runAutoCleanup() which runs on startup + every 6h via startCleanupScheduler(). Also runs VACUUM after startup cleanup to reclaim disk space. 6 unit tests covering retention boundary, no-op on recent data, and DEFAULT_DATABASE_SETTINGS key existence. Closes #6848 * ci: retrigger CI for Electron Package Smoke flaky test * ci: retrigger flaky integration test (batch-e2e timeout) * test(#6848): rewrite tests to call real cleanup functions with seeded DB data Replace mock-only assertions with integration-style tests that seed data into the isolated test DB, call the actual cleanup functions from src/lib/db/cleanup.ts, and verify rows are correctly deleted. All 6 tests now exercise real code paths: - cleanupDomainCostHistory: verify old rows deleted, recent preserved - cleanupCompressionCacheStats: verify old rows deleted, recent preserved - cleanupXpAuditLog: verify old rows deleted, recent preserved - cleanupCompressionRunTelemetry: ensure table + verify cleanup - Combined: all 4 functions return 0 deletions when data is within retention - DEFAULT_DATABASE_SETTINGS: verify new retention keys exist with value 30 * test(#6848): self-contained DATA_DIR isolation for the cleanup test Builds on the existing rewrite (already correctly importing and calling the real cleanupDomainCostHistory/cleanupCompressionCacheStats/ cleanupXpAuditLog/cleanupCompressionRunTelemetry from src/lib/db/cleanup.ts with real seeded-row assertions instead of re-implementing the DELETE inline) and closes the remaining gap: DATA_DIR isolation relied entirely on the test:unit harness's `--import ./tests/_setup/isolateDataDir.ts`, which is invisible from the test file itself. Per CONTRIBUTING.md/CLAUDE.md, a single test file is documented to run directly as `node --import tsx/esm --test tests/unit/<file>.test.ts` — without the harness's isolation import, getDbInstance() resolves to the developer's real ~/.omniroute/storage.sqlite, and this file's DELETE-based cleanup calls operate on real rows, not test rows. Confirmed by running it that way before this fix: it deleted 238 real compression_cache_stats rows and 53 real xp_audit_log rows (assertions failed on the row counts, which is how the gap surfaced) instead of the 2/3 rows the test itself inserted. Fix: mkdtempSync + DATA_DIR override before the first src/lib/db/* import (self-contained, matches the pattern in tests/unit/duckduckgo-vqd-429-misclassification-6996.test.ts), plus test.after() calling resetDbInstance() and removing the temp dir — the repo's DB-test-cleanup rule (a dangling handle can hang the native test runner). Re-ran after the fix: same 6/6 pass, now against an isolated /tmp DB with the expected 3/2/3/2 row counts, in ~3s instead of ~15s. Red-first proof: reset cleanupDomainCostHistory's cutoff to a no-op (`cutoffEpoch = 0`, never matches a real row) — the dedicated "cleanupDomainCostHistory: deletes rows older than retention window" test failed as expected; restored and reran clean (6/6). Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
133 lines
3.3 KiB
TypeScript
133 lines
3.3 KiB
TypeScript
/**
|
|
* Database performance optimization settings stored in SQLite key-value pairs.
|
|
* User-configurable aggregation, retention, and optimization settings.
|
|
*/
|
|
|
|
export interface DatabaseSettings {
|
|
/** 1. Location (read-only display) */
|
|
location: {
|
|
databasePath: string;
|
|
dataDir: string;
|
|
walSizeBytes: number;
|
|
schemaVersion: number;
|
|
};
|
|
|
|
/** 2. Logs (what gets captured) */
|
|
logs: {
|
|
detailedLogsEnabled: boolean;
|
|
callLogPipelineEnabled: boolean;
|
|
maxDetailSizeKb: number;
|
|
ringBufferSize: number;
|
|
};
|
|
|
|
/** 3. Backup (backup/restore/import/export) */
|
|
backup: {
|
|
autoBackupEnabled: boolean;
|
|
autoBackupFrequency: "never" | "daily" | "weekly" | "monthly";
|
|
keepLastNBackups: number;
|
|
};
|
|
|
|
/** 4. Cache (moved from CacheSettingsTab) */
|
|
cache: {
|
|
semanticCacheEnabled: boolean;
|
|
semanticCacheMaxSize: number;
|
|
semanticCacheTTL: number;
|
|
promptCacheEnabled: boolean;
|
|
promptCacheStrategy: "auto" | "system-only" | "manual";
|
|
alwaysPreserveClientCache: "auto" | "always" | "never";
|
|
};
|
|
|
|
/** 5. Retention (per-table cleanup policies) */
|
|
retention: {
|
|
quotaSnapshots: number;
|
|
compressionAnalytics: number;
|
|
mcpAudit: number;
|
|
a2aEvents: number;
|
|
callLogs: number;
|
|
usageHistory: number;
|
|
memoryEntries: number;
|
|
domainCostHistory: number;
|
|
compressionCacheStats: number;
|
|
xpAuditLog: number;
|
|
compressionRunTelemetry: number;
|
|
autoCleanupEnabled: boolean;
|
|
};
|
|
|
|
/** 6. Compression (aggregation) */
|
|
aggregation: {
|
|
enabled: boolean;
|
|
rawDataRetentionDays: number;
|
|
granularity: "hourly" | "daily" | "weekly";
|
|
};
|
|
|
|
/** 7. Optimization (auto_vacuum, VACUUM, page/cache) */
|
|
optimization: {
|
|
autoVacuumMode: "NONE" | "FULL" | "INCREMENTAL";
|
|
scheduledVacuum: "never" | "daily" | "weekly" | "monthly";
|
|
vacuumHour: number;
|
|
pageSize: number;
|
|
cacheSize: number;
|
|
optimizeOnStartup: boolean;
|
|
};
|
|
|
|
/** Read-only stats */
|
|
stats: {
|
|
databaseSizeBytes: number;
|
|
pageCount: number;
|
|
freelistCount: number;
|
|
lastVacuumAt: string | null;
|
|
lastOptimizationAt: string | null;
|
|
integrityCheck: "ok" | "error" | null;
|
|
};
|
|
}
|
|
|
|
/** Default database settings */
|
|
export const DEFAULT_DATABASE_SETTINGS: Omit<DatabaseSettings, "location" | "stats"> = {
|
|
logs: {
|
|
detailedLogsEnabled: false,
|
|
callLogPipelineEnabled: false,
|
|
maxDetailSizeKb: 10,
|
|
ringBufferSize: 500,
|
|
},
|
|
backup: {
|
|
autoBackupEnabled: false,
|
|
autoBackupFrequency: "never",
|
|
keepLastNBackups: 5,
|
|
},
|
|
cache: {
|
|
semanticCacheEnabled: true,
|
|
semanticCacheMaxSize: 100,
|
|
semanticCacheTTL: 1800000,
|
|
promptCacheEnabled: true,
|
|
promptCacheStrategy: "auto",
|
|
alwaysPreserveClientCache: "auto",
|
|
},
|
|
retention: {
|
|
quotaSnapshots: 7,
|
|
compressionAnalytics: 30,
|
|
mcpAudit: 30,
|
|
a2aEvents: 30,
|
|
callLogs: 30,
|
|
usageHistory: 30,
|
|
memoryEntries: 30,
|
|
domainCostHistory: 30,
|
|
compressionCacheStats: 30,
|
|
xpAuditLog: 30,
|
|
compressionRunTelemetry: 30,
|
|
autoCleanupEnabled: true,
|
|
},
|
|
aggregation: {
|
|
enabled: true,
|
|
rawDataRetentionDays: 30,
|
|
granularity: "daily",
|
|
},
|
|
optimization: {
|
|
autoVacuumMode: "FULL",
|
|
scheduledVacuum: "weekly",
|
|
vacuumHour: 2,
|
|
pageSize: 4096,
|
|
cacheSize: 16384,
|
|
optimizeOnStartup: true,
|
|
},
|
|
};
|