testdriverai 7.2.3 → 7.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.
@@ -1,142 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const crypto = require("crypto");
4
-
5
- /**
6
- * Generate a cache key from a prompt
7
- * Uses a hash to create a safe filename
8
- */
9
- function getCacheKey(prompt) {
10
- // Normalize the prompt by trimming and converting to lowercase
11
- const normalized = prompt.trim().toLowerCase();
12
-
13
- // Create a hash for the filename
14
- const hash = crypto.createHash("md5").update(normalized).digest("hex");
15
-
16
- // Also create a sanitized version of the prompt for readability
17
- const sanitized = normalized
18
- .replace(/[^a-z0-9\s]/g, "") // Remove special chars
19
- .replace(/\s+/g, "-") // Replace spaces with hyphens
20
- .substring(0, 50); // Limit length
21
-
22
- // Combine sanitized prompt with hash for uniqueness
23
- return `${sanitized}-${hash}.yaml`;
24
- }
25
-
26
- /**
27
- * Get the cache directory path
28
- * Creates it if it doesn't exist
29
- */
30
- function getCacheDir() {
31
- const cacheDir = path.join(process.cwd(), ".testdriver", ".cache");
32
-
33
- if (!fs.existsSync(cacheDir)) {
34
- fs.mkdirSync(cacheDir, { recursive: true });
35
- }
36
-
37
- return cacheDir;
38
- }
39
-
40
- /**
41
- * Get the full path to a cache file
42
- */
43
- function getCachePath(prompt) {
44
- const cacheDir = getCacheDir();
45
- const key = getCacheKey(prompt);
46
- return path.join(cacheDir, key);
47
- }
48
-
49
- /**
50
- * Check if a cached response exists for a prompt
51
- */
52
- function hasCache(prompt) {
53
- const cachePath = getCachePath(prompt);
54
- return fs.existsSync(cachePath);
55
- }
56
-
57
- /**
58
- * Read cached YAML for a prompt
59
- * Returns null if no cache exists
60
- */
61
- function readCache(prompt) {
62
- if (!hasCache(prompt)) {
63
- return null;
64
- }
65
-
66
- try {
67
- const cachePath = getCachePath(prompt);
68
- const yaml = fs.readFileSync(cachePath, "utf8");
69
- return yaml;
70
- } catch {
71
- // If there's an error reading the cache, return null
72
- return null;
73
- }
74
- }
75
-
76
- /**
77
- * Write YAML to cache for a prompt
78
- */
79
- function writeCache(prompt, yaml) {
80
- try {
81
- const cachePath = getCachePath(prompt);
82
- fs.writeFileSync(cachePath, yaml, "utf8");
83
- return cachePath;
84
- } catch {
85
- // Silently fail if we can't write to cache
86
- return null;
87
- }
88
- }
89
-
90
- /**
91
- * Clear all cached prompts
92
- */
93
- function clearCache() {
94
- const cacheDir = getCacheDir();
95
-
96
- try {
97
- const files = fs.readdirSync(cacheDir);
98
-
99
- for (const file of files) {
100
- if (file.endsWith(".yaml")) {
101
- fs.unlinkSync(path.join(cacheDir, file));
102
- }
103
- }
104
-
105
- return true;
106
- } catch {
107
- return false;
108
- }
109
- }
110
-
111
- /**
112
- * Get cache statistics
113
- */
114
- function getCacheStats() {
115
- const cacheDir = getCacheDir();
116
-
117
- try {
118
- const files = fs.readdirSync(cacheDir);
119
- const yamlFiles = files.filter((f) => f.endsWith(".yaml"));
120
-
121
- return {
122
- count: yamlFiles.length,
123
- files: yamlFiles,
124
- };
125
- } catch {
126
- return {
127
- count: 0,
128
- files: [],
129
- };
130
- }
131
- }
132
-
133
- module.exports = {
134
- getCacheKey,
135
- getCacheDir,
136
- getCachePath,
137
- hasCache,
138
- readCache,
139
- writeCache,
140
- clearCache,
141
- getCacheStats,
142
- };