Skip to content

[OPIK-5696][TS SDK] Align TS wizard to also save project_name to ~/.opik.config#6134

Merged
yaricom merged 5 commits intomainfrom
yaricom/OPIK-5696-TS-save_project_name-opik-config
Apr 9, 2026
Merged

[OPIK-5696][TS SDK] Align TS wizard to also save project_name to ~/.opik.config#6134
yaricom merged 5 commits intomainfrom
yaricom/OPIK-5696-TS-save_project_name-opik-config

Conversation

@yaricom
Copy link
Copy Markdown
Contributor

@yaricom yaricom commented Apr 8, 2026

Details

Context

The TS wizard (npx opik-configure) already asks for project name — good. But it should also save it to ~/.opik.config (in addition to .env) so that both SDKs share the same configuration. This way a user who configures via one SDK doesn't have to reconfigure for the other.

Changes needed

  • node-wizard.ts: After saving to .env, also write project_name to ~/.opik.config
  • Consider reading project_name from ~/.opik.config in loadFromConfigFile() (already supported in Config.ts)

Acceptance Criteria

  • New user → npx opik-configure → creates Opik client → trace — Trace lands in the project name entered during configure (not Default Project)
  • User has project_name in ~/.opik.config → trace — Trace lands in the correct project, no warning
  • OPIK_CONFIG_PATH points to nonexistent file — SDK warns and continues (does not crash)

Summary

The TypeScript npx opik-configure wizard now saves configuration (including project_name) to ~/.opik.config in addition to the project's .env file, so both the Python and TypeScript SDKs share the same persistent configuration. Unit testing infrastructure was also added to the configure tool package.

Changes by Component

TypeScript SDK

  • node-wizard.ts: After writing env vars to .env/.env.local, calls the new saveToOpikConfigStep to persist url_override, project_name, and (for cloud/self-hosted) api_key and workspace to ~/.opik.config.
  • save-to-opik-config.ts (new): Implements saveToOpikConfigStep which reads, merges, and writes ~/.opik.config using the ini package (same as the main SDK's Config.ts). Respects OPIK_CONFIG_PATH env var with tilde expansion, creates missing parent directories, and falls back to the default path with a warning if directory creation fails.
  • steps/index.ts: Re-exports the new step.
  • package.json: Added ini ^5.0.0 (runtime dependency) and vitest ^3.0.5 (dev dependency); added test and test:watch scripts.
  • tsconfig.json: Added tests directory to the TypeScript include list.
  • vitest.config.ts (new): Minimal Vitest configuration for the configure tool package.
  • tests/steps/save-to-opik-config.test.ts (new): 8 unit tests covering: new file creation, cloud vs local credential inclusion, merge with existing config, preservation of other INI sections, custom OPIK_CONFIG_PATH (existing parent dir), parent directory auto-creation, fallback on directory creation failure, and writeFile error handling. Uses module-level vi.mock('fs') for ESM compatibility and isolates OPIK_CONFIG_PATH via beforeEach/afterEach.

Infrastructure

  • typescript_sdk_unit_tests.yml: Added two CI steps to install dependencies and run tests for the configure tool package (separate from the main SDK test run).

Files Changed

 .github/workflows/typescript_sdk_unit_tests.yml    |   8 +
 sdks/typescript/src/opik/configure/package.json    |   8 +-
 .../src/opik/configure/src/nodejs/node-wizard.ts   |  11 ++
 .../src/opik/configure/src/steps/index.ts          |   1 +
 .../configure/src/steps/save-to-opik-config.ts     |  82 ++++++++++
 .../tests/steps/save-to-opik-config.test.ts        | 172 +++++++++++++++++++++
 sdks/typescript/src/opik/configure/tsconfig.json   |   2 +-
 .../typescript/src/opik/configure/vitest.config.ts |   9 ++
 8 files changed, 290 insertions(+), 3 deletions(-)

Change checklist

  • User facing
  • Documentation update

Issues

  • Resolves #
  • OPIK-5696

AI-WATERMARK

AI-WATERMARK: yes

  • If yes:
    • Tools: Claude Code v2.1.87
    • Model(s): Sonnet 4.6
    • Scope: Code and tests
    • Human verification: Done

Testing

Introduced new unit test

Documentation

Nothing added

yaricom added 2 commits April 8, 2026 16:29
…pik.config` in the Node.js SDK

- Introduced `saveToOpikConfigStep` to manage Opik configuration as an INI file with merging support.
- Integrated `saveToOpikConfigStep` into the Node.js configuration wizard.
- Updated step exports for inclusion in the configuration flow.
…guration tool

- Introduced Vitest for testing the Node.js SDK configuration tool.
- Exported `parseOpikSection` and `serializeOpikSection` for unit testing.
- Added comprehensive test cases for `parseOpikSection`, `serializeOpikSection`, and `saveToOpikConfigStep` logic.
- Updated `tsconfig.json` to include `tests` directory.
- Added new test scripts to `package.json` and updated workflows to run tests for the configuration tool.
@yaricom yaricom requested review from a team as code owners April 8, 2026 14:03
@github-actions github-actions bot added dependencies Pull requests that update a dependency file Infrastructure typescript *.ts *.tsx TypeScript SDK labels Apr 8, 2026
…improve file path resolution

- Replaced custom INI parsing/serialization logic with the `ini` package to simplify code and improve maintainability.
- Added support for `OPIK_CONFIG_PATH` environment variable to allow custom configuration file paths.
- Implemented fallback mechanism for invalid or non-existent `OPIK_CONFIG_PATH` directories.
- Updated tests to reflect `ini` package integration and new path resolution logic.
…ATH and update fallback handling

- Added logic to create directories recursively when `OPIK_CONFIG_PATH` parent directory is missing.
- Improved error handling and warnings for directory creation failures.
- Enhanced tests to validate directory creation and fallback behaviors.
- Introduced setup/teardown logic to ensure `OPIK_CONFIG_PATH` is isolated during tests.
- Removed redundant `process.env.OPIK_CONFIG_PATH` cleanup from individual test cases.
Copy link
Copy Markdown
Contributor

@awkoy awkoy left a comment

Choose a reason for hiding this comment

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

Great job!

@yaricom yaricom merged commit 7f22903 into main Apr 9, 2026
26 checks passed
@yaricom yaricom deleted the yaricom/OPIK-5696-TS-save_project_name-opik-config branch April 9, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file Infrastructure TypeScript SDK typescript *.ts *.tsx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants