Add unit tests for loadTorchConfig with dependency injection

Refactored `loadTorchConfig` to support dependency injection for `fs`, enabling true unit tests without disk I/O. Added comprehensive unit tests in `test/torch-config-unit.test.mjs`.

- Refactored `loadTorchConfig` to accept optional `fileSystem` argument.
- Created `test/torch-config-unit.test.mjs` with mocked fs tests.
- Verified existing tests pass.

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-02-14 14:15:08 +00:00
1 parent 695adb6dc9
commit 3a48c76a6c
2 files changed
+74 -3

No files matched your search

+3 -3
View File
@@ -84,15 +84,15 @@ export function _resetTorchConfigCache() {
cachedConfig = null;
}
export function loadTorchConfig() {
export function loadTorchConfig(fileSystem = fs) {
if (cachedConfig) return cachedConfig;
const configPath = getTorchConfigPath();
let raw = {};
if (fs.existsSync(configPath)) {
if (fileSystem.existsSync(configPath)) {
try {
raw = JSON.parse(fs.readFileSync(configPath, 'utf8'));
raw = JSON.parse(fileSystem.readFileSync(configPath, 'utf8'));
} catch (err) {
throw new Error(`Failed to parse ${configPath}: ${err.message}`, { cause: err });
}