(directory: string, name: string)
| 39 | export class Service extends Context.Service<Service, Interface>()("@opencode-ai/http-recorder/Cassette") {} |
| 40 | |
| 41 | const cassettePath = (directory: string, name: string) => { |
| 42 | if (!name || path.isAbsolute(name) || path.win32.isAbsolute(name) || name.split(/[\\/]/).includes("..")) |
| 43 | throw new Error(`Invalid cassette name "${name}"`) |
| 44 | const root = path.resolve(directory) |
| 45 | const target = path.resolve(root, `${name}.json`) |
| 46 | const relative = path.relative(root, target) |
| 47 | if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) |
| 48 | throw new Error(`Invalid cassette name "${name}"`) |
| 49 | return target |
| 50 | } |
| 51 | |
| 52 | export const hasCassetteSync = (name: string, options: { readonly directory?: string } = {}) => |
| 53 | fs.existsSync(cassettePath(options.directory ?? DEFAULT_RECORDINGS_DIR, name)) |
no outgoing calls
no test coverage detected