UNPKG

agentic-qe

Version:

Agentic Quality Engineering Fleet System - AI-driven quality management platform

125 lines 3.75 kB
"use strict"; /** * Quality Baseline Command * Set and manage quality baselines */ Object.defineProperty(exports, "__esModule", { value: true }); exports.baseline = void 0; const Logger_1 = require("../../../utils/Logger"); async function baseline(options) { const logger = Logger_1.Logger.getInstance(); const action = options.action || 'set'; try { // Ensure baselines table exists await ensureBaselinesTable(options.database); switch (action) { case 'set': return await setBaseline(options, logger); case 'get': return await getBaseline(options, logger); case 'list': return await listBaselines(options, logger); case 'delete': return await deleteBaseline(options, logger); default: throw new Error(`Unknown action: ${action}`); } } catch (error) { logger.error('Failed to manage baseline:', error); throw error; } } exports.baseline = baseline; async function ensureBaselinesTable(database) { await database.exec(` CREATE TABLE IF NOT EXISTS quality_baselines ( name TEXT PRIMARY KEY, metrics TEXT NOT NULL, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP, description TEXT ) `); } async function setBaseline(options, logger) { if (!options.metrics || !options.name) { throw new Error('metrics and name are required for setting baseline'); } const timestamp = new Date().toISOString(); await options.database.run(` INSERT OR REPLACE INTO quality_baselines (name, metrics, timestamp, description) VALUES (?, ?, ?, ?) `, [ options.name, JSON.stringify(options.metrics), timestamp, `Baseline set at ${timestamp}` ]); logger.info(`Quality baseline "${options.name}" set with ${Object.keys(options.metrics).length} metrics`); return { success: true, baselineSet: true, baseline: { name: options.name, metrics: options.metrics, timestamp } }; } async function getBaseline(options, logger) { if (!options.name) { throw new Error('name is required for getting baseline'); } const row = await options.database.get(` SELECT name, metrics, timestamp, description FROM quality_baselines WHERE name = ? `, [options.name]); if (!row) { throw new Error(`Baseline "${options.name}" not found`); } const baseline = { name: row.name, metrics: JSON.parse(row.metrics), timestamp: row.timestamp, description: row.description }; logger.info(`Retrieved baseline "${options.name}"`); return { success: true, baseline }; } async function listBaselines(options, logger) { const rows = await options.database.all(` SELECT name, metrics, timestamp, description FROM quality_baselines ORDER BY timestamp DESC `); const baselines = rows.map(row => ({ name: row.name, metrics: JSON.parse(row.metrics), timestamp: row.timestamp, description: row.description })); logger.info(`Listed ${baselines.length} baselines`); return { success: true, baselines }; } async function deleteBaseline(options, logger) { if (!options.name) { throw new Error('name is required for deleting baseline'); } await options.database.run(` DELETE FROM quality_baselines WHERE name = ? `, [options.name]); logger.info(`Deleted baseline "${options.name}"`); return { success: true, deleted: true }; } //# sourceMappingURL=baseline.js.map