mirror of
https://github.com/BradGroux/veritas-kanban.git
synced 2026-08-28 02:44:59 +00:00
fix: isolate status history tests from real state
This commit is contained in:
parent
e9f63c9199
commit
ddca1b6cb4
2 changed files with 22 additions and 20 deletions
|
|
@ -20,9 +20,7 @@ describe('StatusHistoryService', () => {
|
|||
await fs.mkdir(configDir, { recursive: true });
|
||||
historyFile = path.join(configDir, 'status-history.json');
|
||||
|
||||
// Create service and override private fields
|
||||
service = new StatusHistoryService();
|
||||
(service as any).historyFile = historyFile;
|
||||
service = new StatusHistoryService({ historyFile });
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { readFile, writeFile, mkdir } from 'fs/promises';
|
||||
import { fileExists } from '../storage/fs-helpers.js';
|
||||
import { join } from 'path';
|
||||
import { dirname, join } from 'path';
|
||||
import { createLogger } from '../lib/logger.js';
|
||||
import { withFileLock } from './file-lock.js';
|
||||
const log = createLogger('status-history-service');
|
||||
|
|
@ -36,36 +36,39 @@ export interface StatusPeriod {
|
|||
taskTitle?: string;
|
||||
}
|
||||
|
||||
export interface StatusHistoryServiceOptions {
|
||||
historyFile?: string;
|
||||
}
|
||||
|
||||
export class StatusHistoryService {
|
||||
private historyFile: string;
|
||||
private readonly MAX_ENTRIES = 5000; // Keep more entries for historical analysis
|
||||
private lastEntry: StatusHistoryEntry | null = null;
|
||||
private initPromise: Promise<void>;
|
||||
|
||||
constructor() {
|
||||
this.historyFile = join(process.cwd(), '.veritas-kanban', 'status-history.json');
|
||||
this.initPromise = this.init();
|
||||
}
|
||||
|
||||
private async init(): Promise<void> {
|
||||
await this.ensureDir();
|
||||
await this.loadLastEntry();
|
||||
constructor(options: StatusHistoryServiceOptions = {}) {
|
||||
this.historyFile =
|
||||
options.historyFile || join(process.cwd(), '.veritas-kanban', 'status-history.json');
|
||||
this.initPromise = this.ensureDir();
|
||||
}
|
||||
|
||||
private async ensureDir(): Promise<void> {
|
||||
const dir = join(process.cwd(), '.veritas-kanban');
|
||||
await mkdir(dir, { recursive: true });
|
||||
await mkdir(dirname(this.historyFile), { recursive: true });
|
||||
}
|
||||
|
||||
private async loadLastEntry(): Promise<void> {
|
||||
private async getLastEntry(): Promise<StatusHistoryEntry | null> {
|
||||
if (this.lastEntry) {
|
||||
return this.lastEntry;
|
||||
}
|
||||
|
||||
try {
|
||||
const entries = await this.getHistory(1);
|
||||
if (entries.length > 0) {
|
||||
this.lastEntry = entries[0];
|
||||
}
|
||||
this.lastEntry = entries[0] ?? null;
|
||||
return this.lastEntry;
|
||||
} catch {
|
||||
// Intentionally silent: history file may not exist on first run
|
||||
this.lastEntry = null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -100,8 +103,9 @@ export class StatusHistoryService {
|
|||
|
||||
// Calculate duration of previous status
|
||||
let durationMs: number | undefined;
|
||||
if (this.lastEntry) {
|
||||
const lastTime = new Date(this.lastEntry.timestamp).getTime();
|
||||
const previousEntry = await this.getLastEntry();
|
||||
if (previousEntry) {
|
||||
const lastTime = new Date(previousEntry.timestamp).getTime();
|
||||
durationMs = now.getTime() - lastTime;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue