qa360 2.2.7 → 2.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of qa360 might be problematic. Click here for more details.

@@ -1,405 +0,0 @@
1
- /**
2
- * Coverage Vault Integration
3
- *
4
- * Integrates coverage data storage and retrieval with the Evidence Vault.
5
- */
6
- import { promisify } from 'util';
7
- /**
8
- * Coverage Vault class
9
- */
10
- export class CoverageVault {
11
- db;
12
- dbRun;
13
- dbAll;
14
- dbGet;
15
- constructor(db) {
16
- this.db = db;
17
- this.dbRun = promisify(db.run.bind(db));
18
- this.dbAll = promisify(db.all.bind(db));
19
- this.dbGet = promisify(db.get.bind(db));
20
- }
21
- /**
22
- * Initialize coverage tables
23
- */
24
- async initialize() {
25
- const schema = `
26
- -- Coverage metrics table
27
- CREATE TABLE IF NOT EXISTS coverage_metrics (
28
- id INTEGER PRIMARY KEY AUTOINCREMENT,
29
- run_id TEXT NOT NULL REFERENCES runs(id) ON DELETE CASCADE,
30
- gate TEXT NOT NULL,
31
- file_path TEXT NOT NULL,
32
- total_lines INTEGER DEFAULT 0,
33
- covered_lines INTEGER DEFAULT 0,
34
- branch_coverage REAL DEFAULT 0,
35
- function_coverage REAL DEFAULT 0,
36
- line_coverage REAL DEFAULT 0,
37
- statement_coverage REAL DEFAULT 0,
38
- total_branches INTEGER DEFAULT 0,
39
- covered_branches INTEGER DEFAULT 0,
40
- total_functions INTEGER DEFAULT 0,
41
- covered_functions INTEGER DEFAULT 0,
42
- total_statements INTEGER DEFAULT 0,
43
- covered_statements INTEGER DEFAULT 0,
44
- uncovered_lines TEXT,
45
- created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now') * 1000)
46
- );
47
-
48
- CREATE INDEX IF NOT EXISTS idx_coverage_metrics_run_id ON coverage_metrics(run_id);
49
- CREATE INDEX IF NOT EXISTS idx_coverage_metrics_gate ON coverage_metrics(gate);
50
- CREATE INDEX IF NOT EXISTS idx_coverage_metrics_file_path ON coverage_metrics(file_path);
51
- CREATE INDEX IF NOT EXISTS idx_coverage_metrics_run_gate ON coverage_metrics(run_id, gate);
52
-
53
- -- Coverage trends table
54
- CREATE TABLE IF NOT EXISTS coverage_trends (
55
- id INTEGER PRIMARY KEY AUTOINCREMENT,
56
- test_id TEXT NOT NULL,
57
- file_path TEXT NOT NULL,
58
- run_id TEXT NOT NULL REFERENCES runs(id) ON DELETE CASCADE,
59
- coverage_type TEXT NOT NULL,
60
- coverage_value REAL NOT NULL,
61
- date INTEGER NOT NULL,
62
- commit TEXT,
63
- branch TEXT,
64
- UNIQUE(test_id, file_path, coverage_type, date)
65
- );
66
-
67
- CREATE INDEX IF NOT EXISTS idx_coverage_trends_test_id ON coverage_trends(test_id);
68
- CREATE INDEX IF NOT EXISTS idx_coverage_trends_file_path ON coverage_trends(file_path);
69
- CREATE INDEX IF NOT EXISTS idx_coverage_trends_date ON coverage_trends(date);
70
- CREATE INDEX IF NOT EXISTS idx_coverage_trends_type ON coverage_trends(coverage_type);
71
-
72
- -- Coverage summary table (aggregate metrics per run)
73
- CREATE TABLE IF NOT EXISTS coverage_summary (
74
- run_id TEXT PRIMARY KEY REFERENCES runs(id) ON DELETE CASCADE,
75
- line_coverage REAL NOT NULL DEFAULT 0,
76
- branch_coverage REAL NOT NULL DEFAULT 0,
77
- function_coverage REAL NOT NULL DEFAULT 0,
78
- statement_coverage REAL NOT NULL DEFAULT 0,
79
- total_files INTEGER DEFAULT 0,
80
- files_meeting_threshold INTEGER DEFAULT 0,
81
- total_lines INTEGER DEFAULT 0,
82
- covered_lines INTEGER DEFAULT 0,
83
- thresholds_met INTEGER DEFAULT 1,
84
- created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now') * 1000)
85
- );
86
-
87
- CREATE INDEX IF NOT EXISTS idx_coverage_summary_created_at ON coverage_summary(created_at);
88
- `;
89
- const statements = schema
90
- .split(';')
91
- .map(s => s.trim())
92
- .filter(s => s.length > 0);
93
- for (const statement of statements) {
94
- await this.dbRun(statement, []);
95
- }
96
- }
97
- /**
98
- * Store coverage result for a run
99
- */
100
- async storeCoverage(runId, result) {
101
- // Store per-file metrics
102
- for (const [filePath, fileCoverage] of Object.entries(result.files)) {
103
- const record = {
104
- run_id: runId,
105
- gate: result.gate,
106
- file_path: filePath,
107
- total_lines: fileCoverage.totalLines,
108
- covered_lines: fileCoverage.coveredLines,
109
- branch_coverage: fileCoverage.branchCoverage,
110
- function_coverage: fileCoverage.functionCoverage,
111
- line_coverage: fileCoverage.lineCoverage,
112
- statement_coverage: fileCoverage.statementCoverage,
113
- total_branches: fileCoverage.totalBranches,
114
- covered_branches: fileCoverage.coveredBranches,
115
- total_functions: fileCoverage.totalFunctions,
116
- covered_functions: fileCoverage.coveredFunctions,
117
- total_statements: fileCoverage.totalStatements,
118
- covered_statements: fileCoverage.coveredStatements,
119
- uncovered_lines: JSON.stringify(fileCoverage.uncoveredLines),
120
- created_at: Date.now()
121
- };
122
- await this.dbRun(`INSERT INTO coverage_metrics (
123
- run_id, gate, file_path, total_lines, covered_lines,
124
- branch_coverage, function_coverage, line_coverage, statement_coverage,
125
- total_branches, covered_branches, total_functions, covered_functions,
126
- total_statements, covered_statements, uncovered_lines, created_at
127
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
128
- record.run_id, record.gate, record.file_path, record.total_lines, record.covered_lines,
129
- record.branch_coverage, record.function_coverage, record.line_coverage, record.statement_coverage,
130
- record.total_branches, record.covered_branches, record.total_functions, record.covered_functions,
131
- record.total_statements, record.covered_statements, record.uncovered_lines, record.created_at
132
- ]);
133
- }
134
- // Store aggregate summary
135
- await this.storeSummary(runId, result.metrics);
136
- }
137
- /**
138
- * Store coverage summary for a run
139
- */
140
- async storeSummary(runId, metrics) {
141
- await this.dbRun(`INSERT OR REPLACE INTO coverage_summary (
142
- run_id, line_coverage, branch_coverage, function_coverage, statement_coverage,
143
- total_files, files_meeting_threshold, total_lines, covered_lines, thresholds_met, created_at
144
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
145
- runId,
146
- metrics.lineCoverage,
147
- metrics.branchCoverage,
148
- metrics.functionCoverage,
149
- metrics.statementCoverage,
150
- metrics.totalFiles,
151
- metrics.filesMeetingThreshold,
152
- metrics.totalLines,
153
- metrics.coveredLines,
154
- 1, // thresholds_met placeholder
155
- Date.now()
156
- ]);
157
- }
158
- /**
159
- * Retrieve coverage for a run
160
- */
161
- async getCoverage(runId) {
162
- const rows = await this.dbAll(`SELECT * FROM coverage_metrics WHERE run_id = ?`, [runId]);
163
- if (rows.length === 0) {
164
- return null;
165
- }
166
- const files = {};
167
- let gate = 'unknown';
168
- for (const row of rows) {
169
- gate = row.gate;
170
- files[row.file_path] = {
171
- path: row.file_path,
172
- totalLines: row.total_lines,
173
- coveredLines: row.covered_lines,
174
- lineCoverage: row.line_coverage,
175
- totalBranches: row.total_branches,
176
- coveredBranches: row.covered_branches,
177
- branchCoverage: row.branch_coverage,
178
- totalFunctions: row.total_functions,
179
- coveredFunctions: row.covered_functions,
180
- functionCoverage: row.function_coverage,
181
- totalStatements: row.total_statements,
182
- coveredStatements: row.covered_statements,
183
- statementCoverage: row.statement_coverage,
184
- uncoveredLines: JSON.parse(row.uncovered_lines || '[]'),
185
- partiallyCoveredLines: [],
186
- branchesByLine: {}
187
- };
188
- }
189
- // Get summary
190
- const summary = await this.getSummary(runId);
191
- const metrics = summary || {
192
- lineCoverage: 0,
193
- branchCoverage: 0,
194
- functionCoverage: 0,
195
- statementCoverage: 0,
196
- totalFiles: Object.keys(files).length,
197
- filesWithCoverage: Object.keys(files).length,
198
- filesMeetingThreshold: 0,
199
- totalLines: 0,
200
- coveredLines: 0,
201
- timestamp: Date.now()
202
- };
203
- return {
204
- source: 'custom',
205
- gate,
206
- files,
207
- metrics,
208
- format: 'json',
209
- timestamp: Date.now()
210
- };
211
- }
212
- /**
213
- * Get coverage summary for a run
214
- */
215
- async getSummary(runId) {
216
- const row = await this.dbGet(`SELECT * FROM coverage_summary WHERE run_id = ?`, [runId]);
217
- if (!row) {
218
- return null;
219
- }
220
- return {
221
- lineCoverage: row.line_coverage,
222
- branchCoverage: row.branch_coverage,
223
- functionCoverage: row.function_coverage,
224
- statementCoverage: row.statement_coverage,
225
- totalFiles: row.total_files,
226
- filesWithCoverage: row.total_files,
227
- filesMeetingThreshold: row.files_meeting_threshold,
228
- totalLines: row.total_lines,
229
- coveredLines: row.covered_lines,
230
- timestamp: row.created_at
231
- };
232
- }
233
- /**
234
- * Get coverage trends for a file
235
- */
236
- async getTrends(filePath, coverageType = 'line', limit = 30) {
237
- const rows = await this.dbAll(`SELECT * FROM coverage_trends
238
- WHERE file_path = ? AND coverage_type = ?
239
- ORDER BY date DESC
240
- LIMIT ?`, [filePath, coverageType, limit]);
241
- const trends = [];
242
- for (let i = rows.length - 1; i >= 0; i--) {
243
- const row = rows[i];
244
- const prev = i > 0 ? rows[i - 1] : null;
245
- trends.push({
246
- runId: row.run_id,
247
- timestamp: row.date,
248
- coverage: row.coverage_value,
249
- type: coverageType,
250
- change: prev ? row.coverage_value - prev.coverage_value : 0,
251
- commit: row.commit,
252
- branch: row.branch
253
- });
254
- }
255
- return trends;
256
- }
257
- /**
258
- * Get overall coverage trends
259
- */
260
- async getOverallTrends(coverageType = 'line', limit = 30) {
261
- const rows = await this.dbAll(`SELECT
262
- run_id,
263
- ${coverageType}_coverage as coverage_value,
264
- created_at as date
265
- FROM coverage_summary
266
- ORDER BY date DESC
267
- LIMIT ?`, [limit]);
268
- const trends = [];
269
- for (let i = rows.length - 1; i >= 0; i--) {
270
- const row = rows[i];
271
- const prev = i > 0 ? rows[i - 1] : null;
272
- trends.push({
273
- runId: row.run_id,
274
- timestamp: row.date,
275
- coverage: row.coverage_value,
276
- type: coverageType,
277
- change: prev ? row.coverage_value - prev.coverage_value : 0
278
- });
279
- }
280
- return trends;
281
- }
282
- /**
283
- * Get coverage by gate
284
- */
285
- async getCoverageByGate(gate, limit = 10) {
286
- const rows = await this.dbAll(`SELECT
287
- cs.line_coverage,
288
- cs.branch_coverage,
289
- cs.function_coverage,
290
- cs.statement_coverage,
291
- cs.total_files,
292
- cs.files_meeting_threshold,
293
- cs.total_lines,
294
- cs.covered_lines,
295
- cs.created_at as timestamp
296
- FROM coverage_summary cs
297
- JOIN runs r ON cs.run_id = r.id
298
- JOIN gates g ON g.run_id = r.id
299
- WHERE g.name = ?
300
- ORDER BY cs.created_at DESC
301
- LIMIT ?`, [gate, limit]);
302
- return rows.map(row => ({
303
- lineCoverage: row.line_coverage,
304
- branchCoverage: row.branch_coverage,
305
- functionCoverage: row.function_coverage,
306
- statementCoverage: row.statement_coverage,
307
- totalFiles: row.total_files,
308
- filesWithCoverage: row.total_files,
309
- filesMeetingThreshold: row.files_meeting_threshold,
310
- totalLines: row.total_lines,
311
- coveredLines: row.covered_lines,
312
- timestamp: row.timestamp
313
- }));
314
- }
315
- /**
316
- * Get files with lowest coverage
317
- */
318
- async getLowestCoverageFiles(limit = 10) {
319
- const rows = await this.dbAll(`SELECT
320
- file_path,
321
- AVG(line_coverage) as avg_coverage,
322
- gate
323
- FROM coverage_metrics
324
- GROUP BY file_path
325
- ORDER BY avg_coverage ASC
326
- LIMIT ?`, [limit]);
327
- return rows.map(row => ({
328
- filePath: row.file_path,
329
- coverage: row.avg_coverage,
330
- gate: row.gate
331
- }));
332
- }
333
- /**
334
- * Get files with highest coverage
335
- */
336
- async getHighestCoverageFiles(limit = 10) {
337
- const rows = await this.dbAll(`SELECT
338
- file_path,
339
- AVG(line_coverage) as avg_coverage,
340
- gate
341
- FROM coverage_metrics
342
- GROUP BY file_path
343
- ORDER BY avg_coverage DESC
344
- LIMIT ?`, [limit]);
345
- return rows.map(row => ({
346
- filePath: row.file_path,
347
- coverage: row.avg_coverage,
348
- gate: row.gate
349
- }));
350
- }
351
- /**
352
- * Get coverage statistics across all runs
353
- */
354
- async getStatistics() {
355
- const totalRuns = await this.dbGet(`SELECT COUNT(DISTINCT run_id) as count FROM coverage_summary`, []);
356
- const averages = await this.dbGet(`SELECT
357
- AVG(line_coverage) as line,
358
- AVG(branch_coverage) as branch,
359
- AVG(function_coverage) as function
360
- FROM coverage_summary`, []);
361
- const best = await this.dbGet(`SELECT run_id, line_coverage FROM coverage_summary ORDER BY line_coverage DESC LIMIT 1`, []);
362
- const worst = await this.dbGet(`SELECT run_id, line_coverage FROM coverage_summary ORDER BY line_coverage ASC LIMIT 1`, []);
363
- return {
364
- totalRuns: totalRuns?.count || 0,
365
- averageLineCoverage: averages?.line || 0,
366
- averageBranchCoverage: averages?.branch || 0,
367
- averageFunctionCoverage: averages?.function || 0,
368
- bestCoverage: { runId: best?.run_id || '', coverage: best?.line_coverage || 0 },
369
- worstCoverage: { runId: worst?.run_id || '', coverage: worst?.line_coverage || 0 }
370
- };
371
- }
372
- /**
373
- * Delete coverage data for a run
374
- */
375
- async deleteCoverage(runId) {
376
- await this.dbRun(`DELETE FROM coverage_metrics WHERE run_id = ?`, [runId]);
377
- await this.dbRun(`DELETE FROM coverage_summary WHERE run_id = ?`, [runId]);
378
- await this.dbRun(`DELETE FROM coverage_trends WHERE run_id = ?`, [runId]);
379
- }
380
- /**
381
- * Get recent coverage changes (comparison with previous run)
382
- */
383
- async getRecentChanges(limit = 5) {
384
- const rows = await this.dbAll(`SELECT
385
- run_id,
386
- created_at as timestamp,
387
- line_coverage
388
- FROM coverage_summary
389
- ORDER BY created_at DESC
390
- LIMIT ?`, [limit * 2] // Get extra to calculate changes
391
- );
392
- const result = [];
393
- for (let i = 0; i < Math.min(rows.length - 1, limit); i++) {
394
- const current = rows[i];
395
- const previous = rows[i + 1];
396
- result.push({
397
- runId: current.run_id,
398
- timestamp: current.timestamp,
399
- lineCoverage: current.line_coverage,
400
- change: previous ? current.line_coverage - previous.line_coverage : 0
401
- });
402
- }
403
- return result;
404
- }
405
- }
@@ -1,236 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "$id": "https://qa360.dev/schemas/pack.v1.json",
4
- "title": "QA360 Pack Configuration v1",
5
- "description": "Schema for QA360 test pack configuration files",
6
- "type": "object",
7
- "required": ["version", "name", "gates"],
8
- "properties": {
9
- "version": {
10
- "type": "integer",
11
- "const": 1,
12
- "description": "Pack schema version"
13
- },
14
- "name": {
15
- "type": "string",
16
- "minLength": 1,
17
- "maxLength": 100,
18
- "pattern": "^[a-zA-Z0-9_-]+$",
19
- "description": "Pack name (alphanumeric, underscore, hyphen only)"
20
- },
21
- "description": {
22
- "type": "string",
23
- "maxLength": 500,
24
- "description": "Human-readable pack description"
25
- },
26
- "gates": {
27
- "type": "array",
28
- "minItems": 1,
29
- "uniqueItems": true,
30
- "items": {
31
- "type": "string",
32
- "enum": ["api_smoke", "ui", "perf", "sast", "dast", "a11y"]
33
- },
34
- "description": "Quality gates to execute"
35
- },
36
- "targets": {
37
- "type": "object",
38
- "properties": {
39
- "api": {
40
- "type": "object",
41
- "properties": {
42
- "baseUrl": {
43
- "type": "string",
44
- "format": "uri",
45
- "description": "Base URL for API testing"
46
- },
47
- "smoke": {
48
- "type": "array",
49
- "items": {
50
- "type": "string",
51
- "pattern": "^(GET|POST|PUT|DELETE|PATCH) .+ -> \\d{3}$",
52
- "description": "Smoke test definition: METHOD path -> expectedStatus"
53
- }
54
- }
55
- },
56
- "required": ["baseUrl"]
57
- },
58
- "web": {
59
- "type": "object",
60
- "properties": {
61
- "baseUrl": {
62
- "type": "string",
63
- "format": "uri",
64
- "description": "Base URL for web testing"
65
- },
66
- "pages": {
67
- "type": "array",
68
- "items": {
69
- "type": "string",
70
- "description": "Page paths to test"
71
- }
72
- }
73
- },
74
- "required": ["baseUrl"]
75
- }
76
- },
77
- "description": "Test targets configuration"
78
- },
79
- "budgets": {
80
- "type": "object",
81
- "properties": {
82
- "perf_p95_ms": {
83
- "type": "integer",
84
- "minimum": 1,
85
- "maximum": 30000,
86
- "description": "Performance budget: 95th percentile response time in ms"
87
- },
88
- "a11y_min": {
89
- "type": "integer",
90
- "minimum": 0,
91
- "maximum": 100,
92
- "description": "Accessibility minimum score (0-100)"
93
- }
94
- },
95
- "description": "Performance and quality budgets"
96
- },
97
- "security": {
98
- "type": "object",
99
- "properties": {
100
- "sast_max_high": {
101
- "type": "integer",
102
- "minimum": 0,
103
- "description": "Maximum allowed high-severity SAST findings"
104
- },
105
- "secrets_leak": {
106
- "type": "integer",
107
- "const": 0,
108
- "description": "Secrets leak tolerance (must be 0)"
109
- }
110
- },
111
- "description": "Security constraints"
112
- },
113
- "data": {
114
- "type": "object",
115
- "properties": {
116
- "profile": {
117
- "type": "string",
118
- "enum": ["demo", "staging", "production"],
119
- "description": "Data profile to use"
120
- },
121
- "seed": {
122
- "type": "integer",
123
- "minimum": 1,
124
- "description": "Random seed for reproducible data generation"
125
- }
126
- },
127
- "description": "Test data configuration"
128
- },
129
- "hooks": {
130
- "type": "object",
131
- "properties": {
132
- "beforeAll": {
133
- "type": "array",
134
- "items": {
135
- "type": "object",
136
- "properties": {
137
- "run": {
138
- "type": "string",
139
- "description": "Command to execute"
140
- },
141
- "timeout": {
142
- "type": "integer",
143
- "minimum": 1000,
144
- "default": 30000,
145
- "description": "Timeout in milliseconds"
146
- }
147
- },
148
- "required": ["run"]
149
- },
150
- "description": "Commands to run before all tests"
151
- },
152
- "afterAll": {
153
- "type": "array",
154
- "items": {
155
- "type": "object",
156
- "properties": {
157
- "run": {
158
- "type": "string",
159
- "description": "Command to execute"
160
- },
161
- "timeout": {
162
- "type": "integer",
163
- "minimum": 1000,
164
- "default": 30000,
165
- "description": "Timeout in milliseconds"
166
- }
167
- },
168
- "required": ["run"]
169
- },
170
- "description": "Commands to run after all tests"
171
- }
172
- },
173
- "description": "Lifecycle hooks"
174
- },
175
- "execution": {
176
- "type": "object",
177
- "properties": {
178
- "retry_on": {
179
- "type": "array",
180
- "items": {
181
- "type": "string",
182
- "enum": ["ECONNRESET", "ETIMEDOUT", "502", "503", "504", "element-detached", "navigation-timeout"]
183
- },
184
- "description": "Error patterns that trigger retries"
185
- },
186
- "max_retries": {
187
- "type": "integer",
188
- "minimum": 0,
189
- "maximum": 5,
190
- "default": 1,
191
- "description": "Maximum number of retries per test"
192
- },
193
- "fail_on_readiness": {
194
- "type": "boolean",
195
- "default": true,
196
- "description": "Fail if readiness checks fail"
197
- },
198
- "timeout": {
199
- "type": "integer",
200
- "minimum": 1000,
201
- "default": 30000,
202
- "description": "Global timeout per test in milliseconds"
203
- }
204
- },
205
- "description": "Execution configuration"
206
- },
207
- "observability": {
208
- "type": "object",
209
- "properties": {
210
- "metrics": {
211
- "type": "boolean",
212
- "default": true,
213
- "description": "Enable metrics collection"
214
- },
215
- "trace": {
216
- "type": "string",
217
- "enum": ["none", "basic", "detailed"],
218
- "default": "basic",
219
- "description": "Tracing level"
220
- }
221
- },
222
- "description": "Observability settings"
223
- },
224
- "environment": {
225
- "type": "object",
226
- "patternProperties": {
227
- "^[A-Z_][A-Z0-9_]*$": {
228
- "type": "string",
229
- "description": "Environment variable value or secret reference"
230
- }
231
- },
232
- "description": "Environment variables and secrets"
233
- }
234
- },
235
- "additionalProperties": false
236
- }