qa360 1.4.5 → 2.0.1
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.
- package/README.md +1 -1
- package/dist/commands/ai.d.ts +41 -0
- package/dist/commands/ai.js +499 -0
- package/dist/commands/ask.js +12 -12
- package/dist/commands/coverage.d.ts +8 -0
- package/dist/commands/coverage.js +252 -0
- package/dist/commands/explain.d.ts +27 -0
- package/dist/commands/explain.js +630 -0
- package/dist/commands/flakiness.d.ts +73 -0
- package/dist/commands/flakiness.js +435 -0
- package/dist/commands/generate.d.ts +66 -0
- package/dist/commands/generate.js +438 -0
- package/dist/commands/init.d.ts +56 -9
- package/dist/commands/init.js +217 -10
- package/dist/commands/monitor.d.ts +27 -0
- package/dist/commands/monitor.js +225 -0
- package/dist/commands/ollama.d.ts +40 -0
- package/dist/commands/ollama.js +301 -0
- package/dist/commands/pack.d.ts +37 -9
- package/dist/commands/pack.js +240 -141
- package/dist/commands/regression.d.ts +8 -0
- package/dist/commands/regression.js +340 -0
- package/dist/commands/repair.d.ts +26 -0
- package/dist/commands/repair.js +307 -0
- package/dist/commands/retry.d.ts +43 -0
- package/dist/commands/retry.js +275 -0
- package/dist/commands/run.d.ts +8 -3
- package/dist/commands/run.js +45 -31
- package/dist/commands/slo.d.ts +8 -0
- package/dist/commands/slo.js +327 -0
- package/dist/core/adapters/playwright-native-api.d.ts +183 -0
- package/dist/core/adapters/playwright-native-api.js +461 -0
- package/dist/core/adapters/playwright-ui.d.ts +7 -0
- package/dist/core/adapters/playwright-ui.js +29 -1
- package/dist/core/ai/anthropic-provider.d.ts +50 -0
- package/dist/core/ai/anthropic-provider.js +211 -0
- package/dist/core/ai/deepseek-provider.d.ts +81 -0
- package/dist/core/ai/deepseek-provider.js +254 -0
- package/dist/core/ai/index.d.ts +60 -0
- package/dist/core/ai/index.js +18 -0
- package/dist/core/ai/llm-client.d.ts +45 -0
- package/dist/core/ai/llm-client.js +7 -0
- package/dist/core/ai/mock-provider.d.ts +49 -0
- package/dist/core/ai/mock-provider.js +121 -0
- package/dist/core/ai/ollama-provider.d.ts +78 -0
- package/dist/core/ai/ollama-provider.js +192 -0
- package/dist/core/ai/openai-provider.d.ts +48 -0
- package/dist/core/ai/openai-provider.js +188 -0
- package/dist/core/ai/provider-factory.d.ts +160 -0
- package/dist/core/ai/provider-factory.js +269 -0
- package/dist/core/auth/api-key-provider.d.ts +16 -0
- package/dist/core/auth/api-key-provider.js +63 -0
- package/dist/core/auth/aws-iam-provider.d.ts +35 -0
- package/dist/core/auth/aws-iam-provider.js +177 -0
- package/dist/core/auth/azure-ad-provider.d.ts +15 -0
- package/dist/core/auth/azure-ad-provider.js +99 -0
- package/dist/core/auth/basic-auth-provider.d.ts +26 -0
- package/dist/core/auth/basic-auth-provider.js +111 -0
- package/dist/core/auth/gcp-adc-provider.d.ts +27 -0
- package/dist/core/auth/gcp-adc-provider.js +126 -0
- package/dist/core/auth/index.d.ts +238 -0
- package/dist/core/auth/index.js +82 -0
- package/dist/core/auth/jwt-provider.d.ts +19 -0
- package/dist/core/auth/jwt-provider.js +160 -0
- package/dist/core/auth/manager.d.ts +84 -0
- package/dist/core/auth/manager.js +230 -0
- package/dist/core/auth/oauth2-provider.d.ts +17 -0
- package/dist/core/auth/oauth2-provider.js +114 -0
- package/dist/core/auth/totp-provider.d.ts +31 -0
- package/dist/core/auth/totp-provider.js +134 -0
- package/dist/core/auth/ui-login-provider.d.ts +26 -0
- package/dist/core/auth/ui-login-provider.js +198 -0
- package/dist/core/cache/index.d.ts +7 -0
- package/dist/core/cache/index.js +6 -0
- package/dist/core/cache/lru-cache.d.ts +203 -0
- package/dist/core/cache/lru-cache.js +397 -0
- package/dist/core/coverage/analyzer.d.ts +101 -0
- package/dist/core/coverage/analyzer.js +415 -0
- package/dist/core/coverage/collector.d.ts +74 -0
- package/dist/core/coverage/collector.js +459 -0
- package/dist/core/coverage/config.d.ts +37 -0
- package/dist/core/coverage/config.js +156 -0
- package/dist/core/coverage/index.d.ts +11 -0
- package/dist/core/coverage/index.js +15 -0
- package/dist/core/coverage/types.d.ts +267 -0
- package/dist/core/coverage/types.js +6 -0
- package/dist/core/coverage/vault.d.ts +95 -0
- package/dist/core/coverage/vault.js +405 -0
- package/dist/core/dashboard/assets.d.ts +6 -0
- package/dist/core/dashboard/assets.js +690 -0
- package/dist/core/dashboard/index.d.ts +6 -0
- package/dist/core/dashboard/index.js +5 -0
- package/dist/core/dashboard/server.d.ts +72 -0
- package/dist/core/dashboard/server.js +354 -0
- package/dist/core/dashboard/types.d.ts +70 -0
- package/dist/core/dashboard/types.js +5 -0
- package/dist/core/discoverer/index.d.ts +115 -0
- package/dist/core/discoverer/index.js +250 -0
- package/dist/core/flakiness/index.d.ts +228 -0
- package/dist/core/flakiness/index.js +384 -0
- package/dist/core/generation/code-formatter.d.ts +111 -0
- package/dist/core/generation/code-formatter.js +307 -0
- package/dist/core/generation/code-generator.d.ts +144 -0
- package/dist/core/generation/code-generator.js +293 -0
- package/dist/core/generation/generator.d.ts +40 -0
- package/dist/core/generation/generator.js +76 -0
- package/dist/core/generation/index.d.ts +30 -0
- package/dist/core/generation/index.js +28 -0
- package/dist/core/generation/pack-generator.d.ts +107 -0
- package/dist/core/generation/pack-generator.js +416 -0
- package/dist/core/generation/prompt-builder.d.ts +132 -0
- package/dist/core/generation/prompt-builder.js +672 -0
- package/dist/core/generation/source-analyzer.d.ts +213 -0
- package/dist/core/generation/source-analyzer.js +657 -0
- package/dist/core/generation/test-optimizer.d.ts +117 -0
- package/dist/core/generation/test-optimizer.js +328 -0
- package/dist/core/generation/types.d.ts +214 -0
- package/dist/core/generation/types.js +4 -0
- package/dist/core/index.d.ts +23 -1
- package/dist/core/index.js +39 -0
- package/dist/core/pack/validator.js +31 -1
- package/dist/core/pack-v2/index.d.ts +9 -0
- package/dist/core/pack-v2/index.js +8 -0
- package/dist/core/pack-v2/loader.d.ts +62 -0
- package/dist/core/pack-v2/loader.js +231 -0
- package/dist/core/pack-v2/migrator.d.ts +56 -0
- package/dist/core/pack-v2/migrator.js +455 -0
- package/dist/core/pack-v2/validator.d.ts +61 -0
- package/dist/core/pack-v2/validator.js +577 -0
- package/dist/core/regression/detector.d.ts +107 -0
- package/dist/core/regression/detector.js +497 -0
- package/dist/core/regression/index.d.ts +9 -0
- package/dist/core/regression/index.js +11 -0
- package/dist/core/regression/trend-analyzer.d.ts +102 -0
- package/dist/core/regression/trend-analyzer.js +345 -0
- package/dist/core/regression/types.d.ts +222 -0
- package/dist/core/regression/types.js +7 -0
- package/dist/core/regression/vault.d.ts +87 -0
- package/dist/core/regression/vault.js +289 -0
- package/dist/core/repair/engine/fixer.d.ts +24 -0
- package/dist/core/repair/engine/fixer.js +226 -0
- package/dist/core/repair/engine/suggestion-engine.d.ts +18 -0
- package/dist/core/repair/engine/suggestion-engine.js +187 -0
- package/dist/core/repair/index.d.ts +10 -0
- package/dist/core/repair/index.js +13 -0
- package/dist/core/repair/repairer.d.ts +90 -0
- package/dist/core/repair/repairer.js +284 -0
- package/dist/core/repair/types.d.ts +91 -0
- package/dist/core/repair/types.js +6 -0
- package/dist/core/repair/utils/error-analyzer.d.ts +28 -0
- package/dist/core/repair/utils/error-analyzer.js +264 -0
- package/dist/core/retry/flakiness-integration.d.ts +60 -0
- package/dist/core/retry/flakiness-integration.js +228 -0
- package/dist/core/retry/index.d.ts +14 -0
- package/dist/core/retry/index.js +16 -0
- package/dist/core/retry/retry-engine.d.ts +80 -0
- package/dist/core/retry/retry-engine.js +296 -0
- package/dist/core/retry/types.d.ts +178 -0
- package/dist/core/retry/types.js +52 -0
- package/dist/core/retry/vault.d.ts +77 -0
- package/dist/core/retry/vault.js +304 -0
- package/dist/core/runner/e2e-helpers.d.ts +102 -0
- package/dist/core/runner/e2e-helpers.js +153 -0
- package/dist/core/runner/phase3-runner.d.ts +101 -2
- package/dist/core/runner/phase3-runner.js +559 -24
- package/dist/core/self-healing/assertion-healer.d.ts +97 -0
- package/dist/core/self-healing/assertion-healer.js +371 -0
- package/dist/core/self-healing/engine.d.ts +122 -0
- package/dist/core/self-healing/engine.js +538 -0
- package/dist/core/self-healing/index.d.ts +10 -0
- package/dist/core/self-healing/index.js +11 -0
- package/dist/core/self-healing/selector-healer.d.ts +103 -0
- package/dist/core/self-healing/selector-healer.js +372 -0
- package/dist/core/self-healing/types.d.ts +152 -0
- package/dist/core/self-healing/types.js +6 -0
- package/dist/core/slo/config.d.ts +107 -0
- package/dist/core/slo/config.js +360 -0
- package/dist/core/slo/index.d.ts +11 -0
- package/dist/core/slo/index.js +15 -0
- package/dist/core/slo/sli-calculator.d.ts +92 -0
- package/dist/core/slo/sli-calculator.js +364 -0
- package/dist/core/slo/slo-tracker.d.ts +148 -0
- package/dist/core/slo/slo-tracker.js +379 -0
- package/dist/core/slo/types.d.ts +281 -0
- package/dist/core/slo/types.js +7 -0
- package/dist/core/slo/vault.d.ts +102 -0
- package/dist/core/slo/vault.js +427 -0
- package/dist/core/tui/index.d.ts +7 -0
- package/dist/core/tui/index.js +6 -0
- package/dist/core/tui/monitor.d.ts +92 -0
- package/dist/core/tui/monitor.js +271 -0
- package/dist/core/tui/renderer.d.ts +33 -0
- package/dist/core/tui/renderer.js +218 -0
- package/dist/core/tui/types.d.ts +63 -0
- package/dist/core/tui/types.js +5 -0
- package/dist/core/types/pack-v2.d.ts +425 -0
- package/dist/core/types/pack-v2.js +8 -0
- package/dist/core/vault/index.d.ts +116 -0
- package/dist/core/vault/index.js +400 -5
- package/dist/core/watch/index.d.ts +7 -0
- package/dist/core/watch/index.js +6 -0
- package/dist/core/watch/watch-mode.d.ts +213 -0
- package/dist/core/watch/watch-mode.js +389 -0
- package/dist/index.js +68 -68
- package/dist/utils/config.d.ts +5 -0
- package/dist/utils/config.js +136 -0
- package/package.json +5 -1
- package/dist/core/adapters/playwright-api.d.ts +0 -82
- package/dist/core/adapters/playwright-api.js +0 -264
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QA360 LRU Cache Module
|
|
3
|
+
*
|
|
4
|
+
* Intelligent caching system for HTTP responses to avoid redundant requests.
|
|
5
|
+
* Features:
|
|
6
|
+
* - LRU (Least Recently Used) eviction policy
|
|
7
|
+
* - TTL (Time To Live) expiration
|
|
8
|
+
* - Size-based limits
|
|
9
|
+
* - Cache key generation based on request parameters
|
|
10
|
+
* - Thread-safe operations (async-friendly)
|
|
11
|
+
* - Metrics and statistics
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const cache = new ResponseCache({
|
|
16
|
+
* maxSize: 100,
|
|
17
|
+
* ttl: 60000, // 1 minute
|
|
18
|
+
* maxSizeBytes: 10 * 1024 * 1024 // 10MB
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* const response = await cache.getOrFetch('GET:/api/users', async () => {
|
|
22
|
+
* return await fetch('/api/users');
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* LRU Response Cache
|
|
28
|
+
*
|
|
29
|
+
* Thread-safe LRU cache with TTL and size-based eviction.
|
|
30
|
+
*/
|
|
31
|
+
export class ResponseCache {
|
|
32
|
+
cache;
|
|
33
|
+
maxSize;
|
|
34
|
+
ttl;
|
|
35
|
+
maxSizeBytes;
|
|
36
|
+
currentSizeBytes;
|
|
37
|
+
enableStats;
|
|
38
|
+
verbose;
|
|
39
|
+
stats;
|
|
40
|
+
constructor(options = {}) {
|
|
41
|
+
this.maxSize = options.maxSize ?? 100;
|
|
42
|
+
this.ttl = options.ttl ?? 300000; // 5 minutes default
|
|
43
|
+
this.maxSizeBytes = options.maxSizeBytes ?? 10 * 1024 * 1024; // 10MB default
|
|
44
|
+
this.enableStats = options.enableStats ?? true;
|
|
45
|
+
this.verbose = options.verbose ?? false;
|
|
46
|
+
this.currentSizeBytes = 0;
|
|
47
|
+
this.cache = new Map();
|
|
48
|
+
this.stats = {
|
|
49
|
+
hits: 0,
|
|
50
|
+
misses: 0,
|
|
51
|
+
additions: 0,
|
|
52
|
+
evictions: 0,
|
|
53
|
+
size: 0,
|
|
54
|
+
sizeBytes: 0,
|
|
55
|
+
hitRate: 0,
|
|
56
|
+
avgEntrySize: 0
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get a value from cache by key
|
|
61
|
+
* Returns undefined if not found or expired
|
|
62
|
+
*/
|
|
63
|
+
get(key) {
|
|
64
|
+
const entry = this.cache.get(key);
|
|
65
|
+
if (!entry) {
|
|
66
|
+
this._recordMiss();
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
// Check if entry has expired
|
|
70
|
+
const now = Date.now();
|
|
71
|
+
const age = now - entry.createdAt;
|
|
72
|
+
if (age > this.ttl) {
|
|
73
|
+
// Entry expired, remove it
|
|
74
|
+
this._remove(key);
|
|
75
|
+
this._recordMiss();
|
|
76
|
+
if (this.verbose) {
|
|
77
|
+
console.log(`📦 Cache EXPIRED: ${key} (age: ${age}ms, TTL: ${this.ttl}ms)`);
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
// Update last accessed time and hit count
|
|
82
|
+
entry.lastAccessed = now;
|
|
83
|
+
entry.hitCount++;
|
|
84
|
+
// Move to end of Map to mark as most recently used
|
|
85
|
+
this.cache.delete(key);
|
|
86
|
+
this.cache.set(key, entry);
|
|
87
|
+
this._recordHit();
|
|
88
|
+
if (this.verbose) {
|
|
89
|
+
console.log(`📦 Cache HIT: ${key} (age: ${age}ms, hits: ${entry.hitCount})`);
|
|
90
|
+
}
|
|
91
|
+
return entry.data;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Set a value in cache by key
|
|
95
|
+
* If key exists, updates the entry
|
|
96
|
+
* If cache is full, evicts LRU entry
|
|
97
|
+
*/
|
|
98
|
+
set(key, data, size) {
|
|
99
|
+
const now = Date.now();
|
|
100
|
+
const entrySize = size ?? this._estimateSize(data);
|
|
101
|
+
// Check if we need to evict entries
|
|
102
|
+
// First, if key already exists, we'll replace it (size may be different)
|
|
103
|
+
const existing = this.cache.get(key);
|
|
104
|
+
if (existing) {
|
|
105
|
+
this.currentSizeBytes -= existing.size;
|
|
106
|
+
this.cache.delete(key);
|
|
107
|
+
}
|
|
108
|
+
// Evict entries if we're over size limits
|
|
109
|
+
while ((this.cache.size >= this.maxSize) ||
|
|
110
|
+
(this.currentSizeBytes + entrySize > this.maxSizeBytes)) {
|
|
111
|
+
this._evictLRU();
|
|
112
|
+
}
|
|
113
|
+
// Add new entry
|
|
114
|
+
const entry = {
|
|
115
|
+
data,
|
|
116
|
+
createdAt: now,
|
|
117
|
+
lastAccessed: now,
|
|
118
|
+
hitCount: 0,
|
|
119
|
+
size: entrySize,
|
|
120
|
+
key
|
|
121
|
+
};
|
|
122
|
+
this.cache.set(key, entry);
|
|
123
|
+
this.currentSizeBytes += entrySize;
|
|
124
|
+
this._recordAddition();
|
|
125
|
+
if (this.verbose) {
|
|
126
|
+
console.log(`📦 Cache SET: ${key} (size: ${entrySize} bytes, total: ${this.cache.size} entries)`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get a value from cache, or compute and cache it if not present
|
|
131
|
+
* This is the main method to use for caching operations
|
|
132
|
+
*/
|
|
133
|
+
async getOrFetch(key, fetchFn, size) {
|
|
134
|
+
const cached = this.get(key);
|
|
135
|
+
if (cached !== undefined) {
|
|
136
|
+
return cached;
|
|
137
|
+
}
|
|
138
|
+
// Cache miss - fetch and cache
|
|
139
|
+
const data = await fetchFn();
|
|
140
|
+
this.set(key, data, size);
|
|
141
|
+
return data;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Check if a key exists in cache and is not expired
|
|
145
|
+
*/
|
|
146
|
+
has(key) {
|
|
147
|
+
const entry = this.cache.get(key);
|
|
148
|
+
if (!entry)
|
|
149
|
+
return false;
|
|
150
|
+
const age = Date.now() - entry.createdAt;
|
|
151
|
+
return age <= this.ttl;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Delete a specific entry from cache
|
|
155
|
+
*/
|
|
156
|
+
delete(key) {
|
|
157
|
+
const entry = this.cache.get(key);
|
|
158
|
+
if (!entry)
|
|
159
|
+
return false;
|
|
160
|
+
this.currentSizeBytes -= entry.size;
|
|
161
|
+
return this.cache.delete(key);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Clear all entries from cache
|
|
165
|
+
*/
|
|
166
|
+
clear() {
|
|
167
|
+
this.cache.clear();
|
|
168
|
+
this.currentSizeBytes = 0;
|
|
169
|
+
if (this.enableStats) {
|
|
170
|
+
this.stats.hits = 0;
|
|
171
|
+
this.stats.misses = 0;
|
|
172
|
+
this.stats.additions = 0;
|
|
173
|
+
this.stats.evictions = 0;
|
|
174
|
+
}
|
|
175
|
+
if (this.verbose) {
|
|
176
|
+
console.log('📦 Cache CLEARED');
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Remove expired entries from cache
|
|
181
|
+
* Returns the number of entries removed
|
|
182
|
+
*/
|
|
183
|
+
purgeExpired() {
|
|
184
|
+
const now = Date.now();
|
|
185
|
+
let removed = 0;
|
|
186
|
+
const keys = Array.from(this.cache.keys());
|
|
187
|
+
for (const key of keys) {
|
|
188
|
+
const entry = this.cache.get(key);
|
|
189
|
+
if (entry) {
|
|
190
|
+
const age = now - entry.createdAt;
|
|
191
|
+
if (age > this.ttl) {
|
|
192
|
+
this._remove(key);
|
|
193
|
+
removed++;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (this.verbose && removed > 0) {
|
|
198
|
+
console.log(`📦 Cache PURGED: ${removed} expired entries removed`);
|
|
199
|
+
}
|
|
200
|
+
return removed;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Get cache statistics
|
|
204
|
+
*/
|
|
205
|
+
getStats() {
|
|
206
|
+
const totalRequests = this.stats.hits + this.stats.misses;
|
|
207
|
+
return {
|
|
208
|
+
hits: this.stats.hits,
|
|
209
|
+
misses: this.stats.misses,
|
|
210
|
+
additions: this.stats.additions,
|
|
211
|
+
evictions: this.stats.evictions,
|
|
212
|
+
size: this.cache.size,
|
|
213
|
+
sizeBytes: this.currentSizeBytes,
|
|
214
|
+
hitRate: totalRequests > 0 ? this.stats.hits / totalRequests : 0,
|
|
215
|
+
avgEntrySize: this.cache.size > 0 ? Math.round(this.currentSizeBytes / this.cache.size) : 0
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Reset cache statistics
|
|
220
|
+
*/
|
|
221
|
+
resetStats() {
|
|
222
|
+
this.stats.hits = 0;
|
|
223
|
+
this.stats.misses = 0;
|
|
224
|
+
this.stats.additions = 0;
|
|
225
|
+
this.stats.evictions = 0;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Get all cache keys (useful for debugging)
|
|
229
|
+
*/
|
|
230
|
+
keys() {
|
|
231
|
+
return Array.from(this.cache.keys());
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Get cache size
|
|
235
|
+
*/
|
|
236
|
+
get size() {
|
|
237
|
+
return this.cache.size;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Check if cache is empty
|
|
241
|
+
*/
|
|
242
|
+
isEmpty() {
|
|
243
|
+
return this.cache.size === 0;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Evict least recently used entry (private method)
|
|
247
|
+
* Since we move accessed entries to the end, the first entry is the LRU
|
|
248
|
+
*/
|
|
249
|
+
_evictLRU() {
|
|
250
|
+
// Get the first key (least recently used)
|
|
251
|
+
const lruKey = this.cache.keys().next().value;
|
|
252
|
+
if (lruKey) {
|
|
253
|
+
const entry = this.cache.get(lruKey);
|
|
254
|
+
this._remove(lruKey);
|
|
255
|
+
this.stats.evictions++;
|
|
256
|
+
if (this.verbose) {
|
|
257
|
+
console.log(`📦 Cache EVICT: ${lruKey} (LRU, last accessed: ${entry ? new Date(entry.lastAccessed).toISOString() : 'unknown'})`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Remove entry and update size tracking (private method)
|
|
263
|
+
*/
|
|
264
|
+
_remove(key) {
|
|
265
|
+
const entry = this.cache.get(key);
|
|
266
|
+
if (entry) {
|
|
267
|
+
this.currentSizeBytes -= entry.size;
|
|
268
|
+
this.cache.delete(key);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Estimate size of data in bytes (private method)
|
|
273
|
+
*/
|
|
274
|
+
_estimateSize(data) {
|
|
275
|
+
if (data === null || data === undefined) {
|
|
276
|
+
return 0;
|
|
277
|
+
}
|
|
278
|
+
if (typeof data === 'string') {
|
|
279
|
+
return data.length * 2; // UTF-16 uses 2 bytes per char
|
|
280
|
+
}
|
|
281
|
+
if (typeof data === 'number') {
|
|
282
|
+
return 8;
|
|
283
|
+
}
|
|
284
|
+
if (typeof data === 'boolean') {
|
|
285
|
+
return 4;
|
|
286
|
+
}
|
|
287
|
+
if (data instanceof ArrayBuffer || data instanceof SharedArrayBuffer) {
|
|
288
|
+
return data.byteLength;
|
|
289
|
+
}
|
|
290
|
+
if (Array.isArray(data)) {
|
|
291
|
+
return data.reduce((sum, item) => sum + this._estimateSize(item), 0);
|
|
292
|
+
}
|
|
293
|
+
if (typeof data === 'object') {
|
|
294
|
+
return JSON.stringify(data).length * 2;
|
|
295
|
+
}
|
|
296
|
+
return 100; // Default estimate
|
|
297
|
+
}
|
|
298
|
+
_recordHit() {
|
|
299
|
+
if (this.enableStats) {
|
|
300
|
+
this.stats.hits++;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
_recordMiss() {
|
|
304
|
+
if (this.enableStats) {
|
|
305
|
+
this.stats.misses++;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
_recordAddition() {
|
|
309
|
+
if (this.enableStats) {
|
|
310
|
+
this.stats.additions++;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Generate a cache key from request parameters
|
|
316
|
+
*
|
|
317
|
+
* The key is generated based on:
|
|
318
|
+
* - HTTP method
|
|
319
|
+
* - URL
|
|
320
|
+
* - Vary headers (Authorization, Content-Type, etc.)
|
|
321
|
+
* - Request body (for POST/PUT/PATCH)
|
|
322
|
+
* - Query parameters
|
|
323
|
+
*/
|
|
324
|
+
export function generateCacheKey(options) {
|
|
325
|
+
const parts = [];
|
|
326
|
+
// Method and URL form the base
|
|
327
|
+
parts.push(`${options.method}:${options.url}`);
|
|
328
|
+
// Add query parameters if present
|
|
329
|
+
if (options.params && Object.keys(options.params).length > 0) {
|
|
330
|
+
const sortedParams = Object.keys(options.params)
|
|
331
|
+
.sort()
|
|
332
|
+
.map(k => `${k}=${options.params[k]}`)
|
|
333
|
+
.join('&');
|
|
334
|
+
parts.push(sortedParams);
|
|
335
|
+
}
|
|
336
|
+
// Add vary headers (default: Authorization, Content-Type)
|
|
337
|
+
const varyHeaders = options.varyHeaders ?? ['authorization', 'content-type'];
|
|
338
|
+
if (options.headers) {
|
|
339
|
+
const headerValues = [];
|
|
340
|
+
for (const header of varyHeaders) {
|
|
341
|
+
const value = options.headers[header];
|
|
342
|
+
if (value) {
|
|
343
|
+
headerValues.push(`${header}:${value}`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (headerValues.length > 0) {
|
|
347
|
+
parts.push(headerValues.join(';'));
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
// Add body hash for POST/PUT/PATCH (simplified)
|
|
351
|
+
if (options.body && ['POST', 'PUT', 'PATCH'].includes(options.method)) {
|
|
352
|
+
const bodyStr = typeof options.body === 'string' ? options.body : JSON.stringify(options.body);
|
|
353
|
+
// Simple hash of body content
|
|
354
|
+
let hash = 0;
|
|
355
|
+
for (let i = 0; i < bodyStr.length; i++) {
|
|
356
|
+
const char = bodyStr.charCodeAt(i);
|
|
357
|
+
hash = ((hash << 5) - hash) + char;
|
|
358
|
+
hash = hash & hash; // Convert to 32bit integer
|
|
359
|
+
}
|
|
360
|
+
parts.push(`body:${Math.abs(hash)}`);
|
|
361
|
+
}
|
|
362
|
+
return parts.join('|');
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Create a response cache with default options for HTTP caching
|
|
366
|
+
*/
|
|
367
|
+
export function createResponseCache(options) {
|
|
368
|
+
return new ResponseCache(options);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Global default cache instance (singleton pattern)
|
|
372
|
+
* Can be used across the application for shared caching
|
|
373
|
+
*/
|
|
374
|
+
let defaultCacheInstance = null;
|
|
375
|
+
/**
|
|
376
|
+
* Get or create the default cache instance
|
|
377
|
+
*/
|
|
378
|
+
export function getDefaultCache() {
|
|
379
|
+
if (!defaultCacheInstance) {
|
|
380
|
+
defaultCacheInstance = new ResponseCache({
|
|
381
|
+
maxSize: 200,
|
|
382
|
+
ttl: 300000, // 5 minutes
|
|
383
|
+
maxSizeBytes: 20 * 1024 * 1024, // 20MB
|
|
384
|
+
enableStats: true
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
return defaultCacheInstance;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Reset the default cache instance
|
|
391
|
+
*/
|
|
392
|
+
export function resetDefaultCache() {
|
|
393
|
+
if (defaultCacheInstance) {
|
|
394
|
+
defaultCacheInstance.clear();
|
|
395
|
+
}
|
|
396
|
+
defaultCacheInstance = null;
|
|
397
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coverage Analyzer
|
|
3
|
+
*
|
|
4
|
+
* Analyzes coverage data to provide insights, trends, and recommendations.
|
|
5
|
+
*/
|
|
6
|
+
import type { FileCoverage, CoverageMetrics, CoverageResult, CoverageTrend, CoverageGap, CoverageComparison, CoverageThreshold, CoverageType, CoverageReport } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Historical coverage data point
|
|
9
|
+
*/
|
|
10
|
+
interface HistoricalCoverage {
|
|
11
|
+
runId: string;
|
|
12
|
+
timestamp: number;
|
|
13
|
+
metrics: CoverageMetrics;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Coverage Analyzer class
|
|
17
|
+
*/
|
|
18
|
+
export declare class CoverageAnalyzer {
|
|
19
|
+
private history;
|
|
20
|
+
/**
|
|
21
|
+
* Analyze coverage and generate insights
|
|
22
|
+
*/
|
|
23
|
+
analyze(result: CoverageResult, threshold?: CoverageThreshold): CoverageReport;
|
|
24
|
+
/**
|
|
25
|
+
* Check if coverage meets thresholds
|
|
26
|
+
*/
|
|
27
|
+
checkThresholds(metrics: CoverageMetrics, threshold?: CoverageThreshold): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Check if a single file meets thresholds
|
|
30
|
+
*/
|
|
31
|
+
checkFileThresholds(file: FileCoverage, threshold?: CoverageThreshold): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Find coverage gaps
|
|
34
|
+
*/
|
|
35
|
+
findGaps(files: Record<string, FileCoverage>, threshold?: CoverageThreshold): CoverageGap[];
|
|
36
|
+
/**
|
|
37
|
+
* Calculate priority for covering a file
|
|
38
|
+
*/
|
|
39
|
+
private calculatePriority;
|
|
40
|
+
/**
|
|
41
|
+
* Estimate effort to cover a file
|
|
42
|
+
*/
|
|
43
|
+
private estimateEffort;
|
|
44
|
+
/**
|
|
45
|
+
* Generate test suggestions for a file
|
|
46
|
+
*/
|
|
47
|
+
private generateSuggestions;
|
|
48
|
+
/**
|
|
49
|
+
* Group consecutive numbers into ranges
|
|
50
|
+
*/
|
|
51
|
+
private groupConsecutiveNumbers;
|
|
52
|
+
/**
|
|
53
|
+
* Get top and bottom files by coverage
|
|
54
|
+
*/
|
|
55
|
+
getTopFiles(files: Record<string, FileCoverage>, limit?: number): Array<{
|
|
56
|
+
path: string;
|
|
57
|
+
coverage: number;
|
|
58
|
+
type: 'best' | 'worst';
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* Compare two coverage results
|
|
62
|
+
*/
|
|
63
|
+
compare(baseResult: CoverageResult, compareResult: CoverageResult): CoverageComparison;
|
|
64
|
+
/**
|
|
65
|
+
* Add historical coverage data
|
|
66
|
+
*/
|
|
67
|
+
addHistory(key: string, data: HistoricalCoverage): void;
|
|
68
|
+
/**
|
|
69
|
+
* Get coverage trends
|
|
70
|
+
*/
|
|
71
|
+
getTrends(key: string, type?: CoverageType, limit?: number): CoverageTrend[];
|
|
72
|
+
/**
|
|
73
|
+
* Calculate trend direction
|
|
74
|
+
*/
|
|
75
|
+
getTrendDirection(trends: CoverageTrend[]): 'improving' | 'stable' | 'declining';
|
|
76
|
+
/**
|
|
77
|
+
* Predict future coverage based on trends
|
|
78
|
+
*/
|
|
79
|
+
predictCoverage(key: string, type: CoverageType | undefined, targetCoverage: number): {
|
|
80
|
+
predictedReach: number | null;
|
|
81
|
+
projectedCoverage: number;
|
|
82
|
+
confidence: 'high' | 'medium' | 'low';
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Generate coverage summary text
|
|
86
|
+
*/
|
|
87
|
+
generateSummary(metrics: CoverageMetrics): string;
|
|
88
|
+
/**
|
|
89
|
+
* Format coverage percentage with color indicator
|
|
90
|
+
*/
|
|
91
|
+
formatCoverage(percentage: number, threshold?: number): string;
|
|
92
|
+
/**
|
|
93
|
+
* Clear history
|
|
94
|
+
*/
|
|
95
|
+
clearHistory(key?: string): void;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Create a coverage analyzer
|
|
99
|
+
*/
|
|
100
|
+
export declare function createCoverageAnalyzer(): CoverageAnalyzer;
|
|
101
|
+
export {};
|