* Convert a cache key to a filesystem-safe filename component. * Hashes the full key to guarantee uniqueness while preserving a readable * provider prefix at the start of the filename.
(cacheKey: string)
| 151 | * provider prefix at the start of the filename. |
| 152 | */ |
| 153 | function cacheKeyToFilename(cacheKey: string): string { |
| 154 | const prefix = cacheKey.split(":")[0] // provider name -- always filesystem-safe |
| 155 | // The compound cache key embeds the API-key discriminator, so it is treated as |
| 156 | // password-tainted by static analysis; deriveCacheDigest keeps the filename derivation |
| 157 | // off the weak-hash sink while still producing a collision-free, irreversible component. |
| 158 | const hash = deriveCacheDigest(cacheKey, FILENAME_DIGEST_BYTES) |
| 159 | return `${prefix}_${hash}` |
| 160 | } |
| 161 | |
| 162 | async function writeModels(cacheKey: string, data: ModelRecord) { |
| 163 | const filename = `${cacheKeyToFilename(cacheKey)}_models.json` |
no test coverage detected