Skip to content

feat: add counterfact.yaml config file support with --config option#1723

Merged
pmcelhaney merged 8 commits intomainfrom
copilot/add-counterfact-config-file
Apr 9, 2026
Merged

feat: add counterfact.yaml config file support with --config option#1723
pmcelhaney merged 8 commits intomainfrom
copilot/add-counterfact-config-file

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 8, 2026

Summary

CLI options were becoming unwieldy to pass on every invocation. This adds a counterfact.yaml config file as an alternative — any CLI option can now be set there, with command-line flags always winning on conflict.

# counterfact.yaml
spec: ./openapi.yaml
port: 8080
serve: true
watch: true
proxy-url: https://api.example.com
prefix: /api/v1

Use --config <path> to point at a non-default location.

Original Prompt

The options in the command line are getting unwieldy. It's time to support a counterfact.yaml file as an alternative way to set configuration.

Follow common conventions, e.g. --config to set an alternate config file path; when there's a conflict, command line settings override config file settings

Manual acceptance tests

  • Running with a counterfact.yaml in the current directory starts the server using config values (e.g. port: 8080 overrides the default 3100)
  • An explicit CLI flag (e.g. --port 9000) overrides the same key set in counterfact.yaml
  • --config ./path/to/other.yaml loads options from the specified file instead of counterfact.yaml
  • --config ./nonexistent.yaml exits with a clear "Config file not found" error
  • No counterfact.yaml present and no --config flag → startup proceeds normally with CLI/default values
  • Kebab-case keys in the YAML (e.g. proxy-url, always-fake-optionals) are recognised correctly

Tasks

  • Added src/util/load-config-file.ts: reads and parses YAML, normalises kebab-case keys to camelCase, returns {} when default file is absent, throws when a required file is missing
  • Updated bin/counterfact.js: imports loadConfigFile, adds --config <path> Commander option, merges file config into options before building Config using program.getOptionValueSource() to detect explicit CLI flags
  • Added 9 unit tests in test/util/load-config-file.test.ts using usingTemporaryFiles() per project convention
  • Updated README.md and bin/README.md with the new option and example config
  • Updated docs/usage.md: added --config to the CLI reference block and a new "Using a counterfact.yaml config file" <details> section covering the example YAML, kebab-case key normalisation, custom config path, and missing-file behaviour
  • Added minor changeset

Copilot AI linked an issue Apr 8, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add support for counterfact.yaml configuration file feat: add counterfact.yaml config file support with --config option Apr 8, 2026
Copilot AI requested a review from pmcelhaney April 8, 2026 15:59
Copy link
Copy Markdown
Collaborator

@pmcelhaney pmcelhaney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use usingTemporaryFiles() for the test.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 8, 2026

Use usingTemporaryFiles() for the test.

Done in 4f14c8f — replaced the manual tmpdir/mkdir/writeFile helper with usingTemporaryFiles() throughout the test file.

Copilot AI requested a review from pmcelhaney April 8, 2026 16:25
@pmcelhaney pmcelhaney requested a review from dethell April 8, 2026 18:03
@pmcelhaney pmcelhaney marked this pull request as ready for review April 8, 2026 18:03
Copy link
Copy Markdown
Collaborator

@pmcelhaney pmcelhaney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add documentation in usage.md

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 9, 2026

Add documentation in usage.md

Done in 746b53e — added --config to the CLI reference block and a new "Using a counterfact.yaml config file" <details> section in docs/usage.md, covering the example YAML, kebab-case key normalisation, custom config path, and error/no-file behaviour.

Copilot AI requested a review from pmcelhaney April 9, 2026 15:21
@pmcelhaney pmcelhaney added this pull request to the merge queue Apr 9, 2026
Merged via the queue into main with commit 411ea4d Apr 9, 2026
9 of 16 checks passed
@pmcelhaney pmcelhaney deleted the copilot/add-counterfact-config-file branch April 9, 2026 18:06
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.

Add a config file

2 participants