Skip to content

feat(config): read ~/.testsprite/config for persistent defaults (endpoint_url, output, project_id)#225

Open
Andy00L wants to merge 2 commits into
TestSprite:mainfrom
Andy00L:feat/config-file
Open

feat(config): read ~/.testsprite/config for persistent defaults (endpoint_url, output, project_id)#225
Andy00L wants to merge 2 commits into
TestSprite:mainfrom
Andy00L:feat/config-file

Conversation

@Andy00L

@Andy00L Andy00L commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Reopens #179, which was closed by the July 9 release incident (see the
maintainer's comment there). Same branch, same commits (head a07d97b2),
already rebased onto the current main tip and design-approved by
@zeshi-du on the original PR.

What does this PR do?

defaultConfigPath() reserved ~/.testsprite/config but loadConfig never
read it, so every non-credential preference had to be repeated per command.
This implements the aws-cli credentials-vs-config split: profile-sectioned INI
settings (endpoint_url, output, project_id) read via a new
readConfigFileSettings(profile). Precedence is exactly as accepted in
triage — flag > env > config file > built-in default:

  • endpoint_url slots into the loadConfig cascade just above the built-in
    default (below --endpoint-url and TESTSPRITE_API_URL);
  • output becomes the default of the global --output flag (flag still wins);
  • project_id backs --project on the project-scoped test commands, with the
    validation error now naming both options.
    The file is optional by design: missing/unreadable file or section resolves to
    {} and falls through. TESTSPRITE_CONFIG_FILE overrides the path.

Related issue

Fixes #100

Type of change

  • New feature (non-breaking change that adds functionality)

Checklist

  • PR targets the main branch.
  • Commits follow Conventional Commits.
  • npm run lint and npm run format:check pass.
  • npm run typecheck passes.
  • npm test passes and coverage stays at or above the 80% gate.
  • New behavior is covered by unit tests (mock-based; no network).
  • No secrets, API keys, internal endpoints, or personal data are included.

Notes for reviewers

The INI walk is extracted from parseCredentials into a shared parseIniFile
(null-prototype accumulator + __proto__/constructor/prototype section and
key guards); parseCredentials delegates to it, byte-for-byte same behavior —
including the recent CR/LF hardening, which is untouched. No secrets ever live
in the config file (the key stays in credentials). Env-var default for
--project (TESTSPRITE_PROJECT_ID) is intentionally NOT included here — that
is issue #76; per its triage, env will slot above the config file.

Carried over from the original review: once #144 (TESTSPRITE_PROJECT_ID
default, also closed by the incident) re-lands, I will fold the config-file
lookup into its resolveProjectId helper as requested by @zeshi-du.

Summary by CodeRabbit

  • New Features

    • CLI commands now can use saved project and output settings from the config file when flags are omitted.
    • Profile-based settings are applied more consistently, including support for selecting the right profile automatically.
  • Bug Fixes

    • Improved config loading so saved values are used with the correct priority.
    • Hardened config parsing to better handle malformed or unexpected entries without affecting normal use.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 368575ce-b7d1-43aa-b52b-df7b0a9673b9

📥 Commits

Reviewing files that changed from the base of the PR and between 3305dfa and a07d97b.

📒 Files selected for processing (5)
  • src/commands/test.ts
  • src/index.ts
  • src/lib/config.test.ts
  • src/lib/config.ts
  • src/lib/credentials.ts

Walkthrough

Adds a config-file settings layer read from ~/.testsprite/config, providing persistent defaults for API endpoint, output mode, and project id. Introduces a hardened INI parser shared with credentials parsing, and updates loadConfig, CLI --output default, and requireProjectId to consult this new layer.

Changes

Config-file defaults and hardened parsing

Layer / File(s) Summary
Hardened INI parser
src/lib/credentials.ts
Adds parseIniFile with null-prototype accumulators and skips prototype-pollution-prone section/key names; parseCredentials now delegates to it.
Config-file settings reader
src/lib/config.ts, src/lib/config.test.ts
Adds ConfigFileSettings type, readConfigFileSettings(), configPath option, and wires settings.endpointUrl into loadConfig's apiUrl precedence; adds tests covering profile scoping, missing files/keys, env-based path resolution, and precedence ordering.
CLI output default from config
src/index.ts
Adds profileForDefaults() and configFileOutputDefault() helpers to resolve the profile from argv/env and use config-file output as the Commander --output default.
Project id resolution fallback
src/commands/test.ts
Refactors requireProjectId to accept an optional profile and return a resolved project id from config when --project is omitted; updates runList, runCreate, and runTestRunAll to assign the resolved id.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant loadConfig
  participant readConfigFileSettings
  participant CredentialsFile
  CLI->>loadConfig: request Config (flag/env/profile)
  loadConfig->>CredentialsFile: read apiUrl/apiKey
  loadConfig->>readConfigFileSettings: read settings for profile
  readConfigFileSettings-->>loadConfig: endpointUrl, output, projectId
  loadConfig-->>CLI: resolved apiUrl (flag > env > credentials > config > default)
Loading

Possibly related PRs

Suggested reviewers: ruili-testsprite, zeshi-du

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Core config-file defaults and precedence are implemented, but the requested configuration docs updates are missing. Add the DOCUMENTATION.md configuration table updates describing flag > env > config-file > built-in default precedence.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: persistent defaults from ~/.testsprite/config for config-related values.
Out of Scope Changes check ✅ Passed The changes stay focused on config-file defaults, related command plumbing, tests, and parser hardening needed for the feature.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

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.

[Hackathon] Read ~/.testsprite/config for persistent defaults (output, endpoint, project)

1 participant