Skip to content

refactor: reference platform constants instead of hardcoded strings#1747

Open
vldcmp-uipath wants to merge 1 commit into
mainfrom
refactor/centralize-platform-constants
Open

refactor: reference platform constants instead of hardcoded strings#1747
vldcmp-uipath wants to merge 1 commit into
mainfrom
refactor/centralize-platform-constants

Conversation

@vldcmp-uipath

@vldcmp-uipath vldcmp-uipath commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Replaces hardcoded string literals across the uipath and uipath-platform packages with the constants defined in uipath.platform.common.constants — the single source of truth. Source code only (tests untouched except where a key's casing changed; see below).

Covers every constant in platform/common/constants.py that had hardcoded usages:

  • HeadersX-UiPath-Internal-TenantId / -AccountId, x-uipath-folderkey, x-uipath-agenthub-configHEADER_*
  • Env varsUIPATH_URL, UIPATH_ACCESS_TOKEN, UIPATH_TENANT_ID, UIPATH_ORGANIZATION_ID, UIPATH_FOLDER_KEY, UIPATH_JOB_KEY, UIPATH_PROCESS_KEY/_UUID/_VERSION, UIPATH_TRACE_ID, UIPATH_PROJECT_ID, UIPATH_AGENT_ID, UIPATH_PROJECT_FILES_SOURCEENV_*
  • File namespyproject.toml, uipath.json, entry-points.json, bindings.json, studio_metadata.json, .env*_FILE / DOTENV_FILE
  • Folder namesevals / evaluationsLEGACY_EVAL_FOLDER / EVALS_FOLDER
  • Removed a duplicate COMMUNITY_agents_SUFFIX definition in evaluators_helpers.py and repointed its consumer to the platform constant.

Side-effect / bug fix

The header constants are lowercase (e.g. x-uipath-internal-tenantid) while several call sites set the mixed-case literal (X-UiPath-Internal-TenantId) as a plain-dict key. When both spellings were present they were sent as two distinct headers and merged server-side. Routing every call site through the single constant collapses them to one canonical header, avoiding the duplicate.

Notes / out of scope

  • Existing uipath._utils.constants and uipath.eval.constants imports are left untouched — handled by the separate consolidation PR.
  • A few literals were intentionally not converted: user-facing message strings that name a file/env-var in prose, and package paths that merely contain a filename (e.g. "content/entry-points.json", "content/bindings_v2.json") which have no exact matching constant.
  • A handful of currently-lightweight modules (cli_new, cli_invoke, functions/*, models/*, etc.) now import the platform package; this adds the platform import cost (~200–300ms) to those code paths, accepted in favor of single-source-of-truth consistency.

Versions

  • uipath 2.11.11 → 2.11.12
  • uipath-platform 0.1.74 → 0.1.75

Testing

  • ruff check + ruff format --check clean on src and tests for both packages
  • Custom httpx linter: no violations
  • Full test suites pass for both uipath and uipath-platform (only credential-gated integration tests skipped)
  • All edited modules import cleanly (no circular imports); uipath --help works

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings June 24, 2026 11:14

Copilot AI left a comment

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.

Pull request overview

This PR refactors both uipath and uipath-platform to replace hardcoded environment variable names, header keys, and project file/folder names with shared constants from uipath.platform.common.constants, ensuring a single source of truth and eliminating mixed-case header duplication.

Changes:

  • Replaced hardcoded env-var/header/file/folder string literals with uipath.platform.common.constants across runtime, CLI, tracing, and eval code paths.
  • Canonicalized internal routing headers to the constant values (lowercase keys) and updated affected tests accordingly.
  • Removed a duplicate COMMUNITY_agents_SUFFIX definition and bumped package versions/lockfiles.

Reviewed changes

Copilot reviewed 36 out of 38 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/uipath/uv.lock Updates lock metadata and bumps uipath / uipath-platform versions.
packages/uipath/tests/tracing/test_otel_exporters.py Updates assertions to use platform header constants.
packages/uipath/tests/cli/chat/test_voice_bridge.py Updates header assertions to use platform header constants.
packages/uipath/tests/cli/chat/test_bridge.py Updates header assertions to use platform header constants.
packages/uipath/src/uipath/tracing/_otel_exporters.py Replaces env var + header literals with platform constants for tracing exporter setup.
packages/uipath/src/uipath/functions/factory.py Uses UIPATH_CONFIG_FILE constant as the default config filename.
packages/uipath/src/uipath/functions/init.py Uses UIPATH_CONFIG_FILE constant when registering the default runtime factory.
packages/uipath/src/uipath/eval/mocks/_simulate_component_service.py Uses platform internal header constants for routing headers.
packages/uipath/src/uipath/eval/evaluators/llm_as_judge_evaluator.py Switches to platform COMMUNITY_agents_SUFFIX constant.
packages/uipath/src/uipath/eval/_helpers/evaluators_helpers.py Removes duplicate COMMUNITY_agents_SUFFIX definition.
packages/uipath/src/uipath/_utils/_auth.py Uses DOTENV_FILE constant for .env handling.
packages/uipath/src/uipath/_cli/models/uipath_json_schema.py Uses UIPATH_CONFIG_FILE constant for default config loading.
packages/uipath/src/uipath/_cli/models/runtime_schema.py Uses ENTRY_POINTS_FILE constant for $id default.
packages/uipath/src/uipath/_cli/cli_pack.py Uses platform constants for common project filenames and related error messages.
packages/uipath/src/uipath/_cli/cli_new.py Uses platform constants when generating project files and CLI messages.
packages/uipath/src/uipath/_cli/cli_invoke.py Uses PYTHON_CONFIGURATION_FILE constant for reading project metadata.
packages/uipath/src/uipath/_cli/cli_init.py Uses platform constants for config/env/entry-points/pyproject file handling.
packages/uipath/src/uipath/_cli/cli_eval.py Uses ENV_FOLDER_KEY constant when setting env vars.
packages/uipath/src/uipath/_cli/_utils/_service_base.py Uses platform env var constants when constructing a client from env.
packages/uipath/src/uipath/_cli/_utils/_project_files.py Uses platform constants for project config discovery and eval folder handling.
packages/uipath/src/uipath/_cli/_utils/_common.py Uses platform ENV_BASE_URL constant for CLI env validation.
packages/uipath/src/uipath/_cli/_telemetry.py Uses ENV_UIPATH_AGENT_ID constant for telemetry enrichment.
packages/uipath/src/uipath/_cli/_push/sw_file_handler.py Uses platform constants for ignored files and eval folder naming.
packages/uipath/src/uipath/_cli/_evals/_telemetry.py Uses ENV_TENANT_ID constant for telemetry enrichment.
packages/uipath/src/uipath/_cli/_evals/_progress_reporter.py Uses platform env var constants for project/agent identity and file-source attribution.
packages/uipath/src/uipath/_cli/_debug/_bridge.py Uses platform env/header constants for remote debug bridge configuration.
packages/uipath/src/uipath/_cli/_chat/_voice_bridge.py Uses platform env/header constants for conversational voice bridge headers.
packages/uipath/src/uipath/_cli/_chat/_bridge.py Uses platform env/header constants for conversational chat bridge headers.
packages/uipath/src/uipath/_cli/_auth/_url_utils.py Uses ENV_BASE_URL constant when resolving domain defaults.
packages/uipath/src/uipath/_cli/_auth/_auth_session.py Uses ENV_UIPATH_ACCESS_TOKEN constant when persisting tokens to env.
packages/uipath/src/uipath/_cli/_auth/_auth_service.py Uses platform env var constants when writing auth results to env and checking reuse.
packages/uipath/pyproject.toml Bumps uipath version to 2.11.10.
packages/uipath-platform/uv.lock Bumps uipath-platform version to 0.1.72 in lockfile.
packages/uipath-platform/tests/services/test_service_url_overrides.py Updates header assertions to use platform header constants.
packages/uipath-platform/src/uipath/platform/common/_span_utils.py Replaces tracing/process env var literals with constants.
packages/uipath-platform/src/uipath/platform/common/_service_url_overrides.py Uses internal routing header constants when injecting routing headers.
packages/uipath-platform/src/uipath/platform/chat/_llm_gateway_service.py Uses HEADER_AGENTHUB_CONFIG constant for optional header injection.
packages/uipath-platform/pyproject.toml Bumps uipath-platform version to 0.1.72.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Replace hardcoded string literals (headers, env-var names, file names,
folder names, and the community-agents suffix) across the `uipath` and
`uipath-platform` packages with the constants defined in
`uipath.platform.common.constants` — the single source of truth.

Scope: source code only.

- Headers: X-UiPath-Internal-TenantId / -AccountId, x-uipath-folderkey,
  x-uipath-agenthub-config now use HEADER_* constants.
- Env vars: UIPATH_URL, UIPATH_ACCESS_TOKEN, UIPATH_TENANT_ID,
  UIPATH_ORGANIZATION_ID, UIPATH_FOLDER_KEY, UIPATH_JOB_KEY,
  UIPATH_PROCESS_KEY/_UUID/_VERSION, UIPATH_TRACE_ID, UIPATH_PROJECT_ID,
  UIPATH_AGENT_ID, UIPATH_PROJECT_FILES_SOURCE now use ENV_* constants.
- File names: pyproject.toml, uipath.json, entry-points.json,
  bindings.json, studio_metadata.json, .env now use the *_FILE constants.
- Folder names: evals / evaluations now use LEGACY_EVAL_FOLDER /
  EVALS_FOLDER.
- Removed a duplicate COMMUNITY_agents_SUFFIX definition in
  evaluators_helpers.py and repointed its consumer to the platform constant.

Side-effect / bug fix: the header constants are lowercase
(e.g. "x-uipath-internal-tenantid") while several call sites set the
mixed-case literal ("X-UiPath-Internal-TenantId") as a plain-dict key.
When both spellings were present they were sent as two distinct headers
and merged server-side. Routing every call site through the single
constant collapses them to one canonical header, avoiding the duplicate.

Existing `uipath._utils.constants` and `uipath.eval.constants` imports are
left untouched (handled by the separate consolidation PR). A handful of
literals were intentionally not converted: user-facing message strings that
name a file/env-var in prose, and package paths that merely contain a
filename (e.g. "content/entry-points.json", "content/bindings_v2.json")
which have no exact matching constant.

Bumps uipath 2.11.9 -> 2.11.10 and uipath-platform 0.1.71 -> 0.1.72.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vldcmp-uipath vldcmp-uipath force-pushed the refactor/centralize-platform-constants branch from be43eb0 to 9135a5e Compare June 24, 2026 14:43
@github-actions github-actions Bot added test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-integrations labels Jun 24, 2026
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:uipath-integrations test:uipath-langchain Triggers tests in the uipath-langchain-python repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants