Skip to content

Validate client-level projectId in the TS and Python clients - #38

Merged
rapguit merged 1 commit into
codespar:mainfrom
AndreLFSMartins:fix/sdk-validate-client-project-id
Jun 26, 2026
Merged

Validate client-level projectId in the TS and Python clients#38
rapguit merged 1 commit into
codespar:mainfrom
AndreLFSMartins:fix/sdk-validate-client-project-id

Conversation

@AndreLFSMartins

Copy link
Copy Markdown
Contributor

Per-session projectId is validated against ^prj_[A-Za-z0-9]{16}$ (Zod schema in types.ts), but the client-level projectId was passed straight to the x-codespar-project header with no validation — in both the TS and Python clients. A malformed client-level scope reached the backend instead of failing fast at construction.

  • TS: extracts PROJECT_ID_REGEX in types.ts (now reused by the Zod schema and the CodeSpar constructor).
  • Python: adds the matching _PROJECT_ID_RE check to AsyncCodeSpar.__init__ (covers the sync client via its factory).
  • Fixes three Python test fixtures in test_session.py that used 17-char ids (never validated before).

Behavior change: a client constructed with a malformed projectId now throws at construction. Tests added (TS + Python).

npm test + tsc --noEmit green for packages/core; pytest + mypy + ruff green for packages/python.

Note: touches packages/core/src/index.ts, which also changes in #37 — a trivial merge conflict on the constructor is expected if both land; whichever merges second rebases.

@rapguit

rapguit commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Going to rebase this on top of current main myself — the conflicts are purely additive (overlap with #36 / #37 in the constructor + test file, and with #54's MockValueSchema / os import), no design decisions involved, and you flagged the rebase ownership in the PR body. Will force-push to your branch shortly and then run the suites again before merging. Thanks for the heads-up note.

Per-session projectId is validated against ^prj_[A-Za-z0-9]{16}$ (Zod
in types.ts), but the client-level projectId was passed straight to the
x-codespar-project header with no validation, in both the TS and Python
clients. A malformed client-level scope reached the backend instead of
failing fast.

Extracts PROJECT_ID_REGEX in types.ts (reused by the Zod schema and the
TS constructor) and adds the matching _PROJECT_ID_RE check to the
Python AsyncCodeSpar constructor (covers the sync client via its
factory). Fixes three Python test fixtures that used 17-char ids.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rapguit
rapguit force-pushed the fix/sdk-validate-client-project-id branch from 6b47c80 to 6c8c002 Compare June 26, 2026 20:27
@rapguit

rapguit commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Rebased and force-pushed to your branch — your commit (6c8c002) is preserved with original authorship, just replayed on top of post-#36 / post-#37 main. Resolutions were the additive kind we discussed:

Verified locally:

  • TS suite: 98/98 pass, tsc --noEmit clean.
  • Python: re-running via CI on this push (my local doesn't have python3-venv handy); your PR body already states pytest + mypy + ruff green, and the CI workflow guards a regression.

Squash-merging once the workflows come back green. Thanks!

@rapguit
rapguit merged commit 194bbbd into codespar:main Jun 26, 2026
7 of 8 checks passed
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.

2 participants