Skip to content

Add tests for config module and extract loadConfigFrom for testability#277

Open
coding-creed-technologies wants to merge 1 commit into
Conway-Research:mainfrom
coding-creed-technologies:3tg-generated-tests
Open

Add tests for config module and extract loadConfigFrom for testability#277
coding-creed-technologies wants to merge 1 commit into
Conway-Research:mainfrom
coding-creed-technologies:3tg-generated-tests

Conversation

@coding-creed-technologies

Copy link
Copy Markdown

Summary

This PR adds unit tests for the configuration module and introduces a small refactor to make the loading logic easier to test.

loadConfig was split so the file parsing logic is handled by a new function: loadConfigFrom(configPath: string)

This allows tests to provide custom config files directly without mocking getConfigPath.

Changes

  • Add unit tests for exported functions in config.ts
  • Extract loadConfigFrom from loadConfig
  • Test configuration loading behavior with custom file paths
  • Verify default merging and treasury policy validation
  • Test filesystem persistence in saveConfig
  • Test path expansion in resolvePath
  • Test config generation via createConfig

Test Isolation

To make the tests deterministic and independent of the runtime environment:

  • Filesystem interactions (fs) are mocked.
  • A mock implementation for wallet.ts was added so that getAutomatonDir() can be controlled during tests.

This allows the configuration logic to be tested without relying on the real user environment.

Notes

The refactor is purely structural and does not change runtime behavior.

Impact

Improves test coverage and makes the configuration logic easier to maintain and refactor safely.


Attribution

This contribution was generated with assistance from 3TG

3TG is a behavior-first test generation tool for TypeScript functions that creates clean, maintainable tests and improves developer productivity.

Add unit tests for all exported functions in config.ts.

To make the configuration loading logic easier to test, `loadConfig`
was refactored by extracting the file-loading logic into a new
`loadConfigFrom(configPath)` function.

This allows tests to provide custom config file paths without
mocking `getConfigPath`.

Tests cover:
- getConfigPath
- loadConfig
- loadConfigFrom
- saveConfig
- resolvePath
- createConfig

They verify config loading, default merging, treasury validation,
path resolution, and config persistence behavior.

The refactor does not change runtime behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant