Skip to content
This repository was archived by the owner on Oct 2, 2025. It is now read-only.

fix: Prevent undefined org in trace submissions [jules] - #691

Open
jmoseley wants to merge 2 commits into
mainfrom
fix-undefined-org-in-traces
Open

fix: Prevent undefined org in trace submissions [jules]#691
jmoseley wants to merge 2 commits into
mainfrom
fix-undefined-org-in-traces

Conversation

@jmoseley

Copy link
Copy Markdown
Contributor

Closes #664

The CheckpointManager in packages/gensx-core/src/checkpoint.ts could allow trace submissions with an 'undefined' string or an empty string as the organization ID if checkpoints were enabled and the org ID was not properly set or was explicitly set to "undefined".

This change enhances the validation in the CheckpointManager constructor. It now explicitly checks if this.org is an empty string or the literal string "undefined" when checkpoints are enabled (i.e., an API key is present). If either condition is met, an error is thrown, preventing the client from attempting to send traces with an invalid org ID.

Added new test cases to packages/gensx-core/tests/checkpoint.test.tsx to cover scenarios where:

  • org is undefined, an empty string, or the string "undefined" with checkpoints enabled (should throw).
  • org is valid with checkpoints enabled (should not throw).
  • org is problematic but checkpoints are disabled (should not throw).

Closes #664

The CheckpointManager in packages/gensx-core/src/checkpoint.ts
could allow trace submissions with an 'undefined' string or an empty
string as the organization ID if checkpoints were enabled and the
org ID was not properly set or was explicitly set to "undefined".

This change enhances the validation in the CheckpointManager constructor.
It now explicitly checks if `this.org` is an empty string or the literal
string "undefined" when checkpoints are enabled (i.e., an API key is present).
If either condition is met, an error is thrown, preventing the client
from attempting to send traces with an invalid org ID.

Added new test cases to packages/gensx-core/tests/checkpoint.test.tsx
to cover scenarios where:
- org is undefined, an empty string, or the string "undefined" with checkpoints enabled (should throw).
- org is valid with checkpoints enabled (should not throw).
- org is problematic but checkpoints are disabled (should not throw).
@vercel

vercel Bot commented May 20, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
gensx-docs ⬜️ Skipped (Inspect) May 20, 2025 5:38pm
gensx-home ⬜️ Skipped (Inspect) May 20, 2025 5:38pm

@jmoseley jmoseley changed the title Fix: Prevent undefined org in trace submissions [jules] fix: Prevent undefined org in trace submissions [jules] May 20, 2025
if (this.checkpointsEnabled && (this.org === "" || this.org === "undefined")) {
throw new Error(
"Organization not set. Set it via constructor options, GENSX_ORG environment variable, or in ~/.config/gensx/config. You can disable checkpoints by setting GENSX_CHECKPOINTS=false or unsetting GENSX_API_KEY.",
"Organization not set or is invalid ('undefined' string). A valid organization ID must be set via constructor options, GENSX_ORG environment variable, or in ~/.config/gensx/config when checkpoints are enabled. You can disable checkpoints by setting GENSX_CHECKPOINTS=false or unsetting GENSX_API_KEY.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"Organization not set or is invalid ('undefined' string). A valid organization ID must be set via constructor options, GENSX_ORG environment variable, or in ~/.config/gensx/config when checkpoints are enabled. You can disable checkpoints by setting GENSX_CHECKPOINTS=false or unsetting GENSX_API_KEY.",
"Organization not set or is invalid. A valid organization must be set via constructor options, GENSX_ORG environment variable, or in ~/.config/gensx/config when checkpoints are enabled. You can disable checkpoints by setting GENSX_CHECKPOINTS=false or unsetting GENSX_API_KEY.",


test("throws error if apiKey is present and org is undefined", () => {
expect(() => new CheckpointManager({ apiKey: "test-key", org: undefined })).toThrow(
"Organization not set or is invalid ('undefined' string). A valid organization ID must be set via constructor options, GENSX_ORG environment variable, or in ~/.config/gensx/config when checkpoints are enabled. You can disable checkpoints by setting GENSX_CHECKPOINTS=false or unsetting GENSX_API_KEY.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"Organization not set or is invalid ('undefined' string). A valid organization ID must be set via constructor options, GENSX_ORG environment variable, or in ~/.config/gensx/config when checkpoints are enabled. You can disable checkpoints by setting GENSX_CHECKPOINTS=false or unsetting GENSX_API_KEY.",
"Organization not set or is invalid. A valid organization must be set via constructor options, GENSX_ORG environment variable, or in ~/.config/gensx/config when checkpoints are enabled. You can disable checkpoints by setting GENSX_CHECKPOINTS=false or unsetting GENSX_API_KEY.",


test("throws error if apiKey is present and org is an empty string", () => {
expect(() => new CheckpointManager({ apiKey: "test-key", org: "" })).toThrow(
"Organization not set or is invalid ('undefined' string). A valid organization ID must be set via constructor options, GENSX_ORG environment variable, or in ~/.config/gensx/config when checkpoints are enabled. You can disable checkpoints by setting GENSX_CHECKPOINTS=false or unsetting GENSX_API_KEY.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"Organization not set or is invalid ('undefined' string). A valid organization ID must be set via constructor options, GENSX_ORG environment variable, or in ~/.config/gensx/config when checkpoints are enabled. You can disable checkpoints by setting GENSX_CHECKPOINTS=false or unsetting GENSX_API_KEY.",
"Organization not set or is invalid. A valid organization must be set via constructor options, GENSX_ORG environment variable, or in ~/.config/gensx/config when checkpoints are enabled. You can disable checkpoints by setting GENSX_CHECKPOINTS=false or unsetting GENSX_API_KEY.",


test("throws error if apiKey is present and org is 'undefined' string", () => {
expect(() => new CheckpointManager({ apiKey: "test-key", org: "undefined" })).toThrow(
"Organization not set or is invalid ('undefined' string). A valid organization ID must be set via constructor options, GENSX_ORG environment variable, or in ~/.config/gensx/config when checkpoints are enabled. You can disable checkpoints by setting GENSX_CHECKPOINTS=false or unsetting GENSX_API_KEY.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"Organization not set or is invalid ('undefined' string). A valid organization ID must be set via constructor options, GENSX_ORG environment variable, or in ~/.config/gensx/config when checkpoints are enabled. You can disable checkpoints by setting GENSX_CHECKPOINTS=false or unsetting GENSX_API_KEY.",
"Organization not set or is invalid. A valid organization must be set via constructor options, GENSX_ORG environment variable, or in ~/.config/gensx/config when checkpoints are enabled. You can disable checkpoints by setting GENSX_CHECKPOINTS=false or unsetting GENSX_API_KEY.",

Test: Enhance CheckpointManager org validation tests

This commit significantly expands the test coverage for the `org`
validation logic within the `CheckpointManager` constructor in
`packages/gensx-core/src/checkpoint.ts`.

The previous tests primarily focused on validation when `apiKey` and `org`
were passed directly as constructor options. These new tests ensure
robustness by also verifying behavior when these configurations are sourced
from environment variables (`GENSX_API_KEY`, `GENSX_ORG`) and from the
global configuration file.

Key additions and changes:
- Restructured tests into sub-suites for clarity: "using constructor options",
  "using environment variables", and "using config file".
- Added comprehensive test cases for scenarios where `org` is invalid
  (empty, "undefined" string, or not set) when checkpoints are enabled
  via environment variables or a mocked config file.
- Verified correct behavior when `org` and `apiKey` are valid via these
  alternative sources.
- Tested the defined override hierarchy: Constructor options > Environment
  variables > Config file. This includes ensuring that if a higher-priority
  source provides an invalid `org` (while enabling checkpoints), an error
  is thrown even if a lower-priority source had a valid `org`.
- Employed mocking and careful management of environment
  variables within tests to ensure isolation and accuracy.

These enhanced tests provide greater confidence that the `CheckpointManager`
correctly validates the organization ID regardless of how it's configured,
preventing issues like #664 under a wider range of conditions.
@vercel
vercel Bot temporarily deployed to Preview – gensx-docs May 20, 2025 17:38 Inactive
@vercel
vercel Bot temporarily deployed to Preview – gensx-home May 20, 2025 17:38 Inactive
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Traces are being sent with undefined as the org

2 participants