fix(ts-sdk): resolve git context from CI env vars - #100
Open
gbsierra wants to merge 3 commits into
Open
Conversation
Author
|
Note: The issue references |
There was a problem hiding this comment.
2 issues found across 5 files
Confidence score: 3/5
- There is concrete regression risk in
packages/traceroot/src/git_context.ts:normalizeRepocan return raw non-URL remotes, andautoDetectGitContext()then uses that value, which may expose local filesystem paths ingitRepo. relativePathinpackages/traceroot/src/git_context.tsappears to rely on prefix matching without a directory-boundary check, so files outside the repo can be incorrectly treated as inside, which can skew tracing/context behavior.- Given the high confidence and medium-high severities (6–7/10), this is not merge-blocking by itself but carries meaningful user-impact risk and should be fixed or mitigated before relying on the new behavior.
- Pay close attention to
packages/traceroot/src/git_context.ts- repo normalization and path-boundary handling can leak metadata and misclassify file scope.
Architecture diagram
sequenceDiagram
participant User as User Code
participant Init as TraceRoot.initialize()
participant Harvest as harvestCiGitContext()
participant Auto as autoDetectGitContext()
participant Git as local git
Note over User,Git: Git context resolution order
User->>Init: NEW: options.gitRepo?, options.gitRef?
alt Explicit args provided
Init->>Init: Use directly
else Explicit missing → TRACEROOT_GIT_* env
Init->>Init: Read TRACEROOT_GIT_REPO, TRACEROOT_GIT_REF
end
Note over Init,Harvest: NEW: CI/platform resolution inserted here
alt repo or ref still missing
Init->>Harvest: harvestCiGitContext(process.env)
Harvest->>Harvest: Check platform candidates in order:
Note over Harvest: GitHub Actions, Vercel, GitLab CI,<br/>CircleCI, Bitbucket, Render
Harvest->>Harvest: For each platform:
Note over Harvest: First platform with repo wins for repo<br/>First platform with ref wins for ref (independent)
Harvest-->>Init: { gitRepo?, gitRef? }
Init->>Init: Fill missing fields from CI context
end
alt repo or ref still missing
Init->>Auto: autoDetectGitContext()
Auto->>Git: git remote get-url origin
Git-->>Auto: remote URL
Auto->>Git: git rev-parse HEAD
Git-->>Auto: commit SHA
Auto-->>Init: { gitRepo?, gitRef? }
Init->>Init: Fill remaining missing fields
end
opt both repo and ref still undefined
Init->>Init: warnMissingGitContextOnce()
Note over Init: Warn once, omit fields from spans
end
Init->>Init: Proceed with initialization
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
1 issue found across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Author
|
@cubic-dev-ai review |
@gbsierra I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
No issues found across 5 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant App as User Application
participant SDK as TraceRoot SDK
participant GitCtx as git_context.ts
participant CiEnv as CI Environment
participant LocalGit as Local .git directory
participant Telemetry as OpenTelemetry Pipeline
Note over App,Telemetry: Git Context Resolution Flow
App->>SDK: initialize({ gitRepo?, gitRef? })
Note over SDK: Resolution order: explicit args → TRACEROOT_GIT_* env → CI/platform env → local git
alt Explicit args provided
SDK->>SDK: Use options.gitRepo / options.gitRef
else Check TRACEROOT_GIT_* env vars
SDK->>CiEnv: Read TRACEROOT_GIT_REPO, TRACEROOT_GIT_REF
CiEnv-->>SDK: env values or undefined
SDK->>SDK: Use if available
end
alt Still missing repo or ref
SDK->>GitCtx: harvestCiGitContext(process.env)
Note over GitCtx: Check platform env vars in priority order
GitCtx->>CiEnv: GitHub Actions (GITHUB_REPOSITORY, GITHUB_SHA)
GitCtx->>CiEnv: Vercel (VERCEL_GIT_REPO_OWNER, VERCEL_GIT_REPO_SLUG, VERCEL_GIT_COMMIT_SHA)
GitCtx->>CiEnv: GitLab CI (CI_PROJECT_PATH, CI_COMMIT_SHA)
GitCtx->>CiEnv: CircleCI (CIRCLE_PROJECT_USERNAME, CIRCLE_PROJECT_REPONAME, CIRCLE_SHA1)
GitCtx->>CiEnv: Bitbucket (BITBUCKET_REPO_FULL_NAME, BITBUCKET_COMMIT)
GitCtx->>CiEnv: Render (RENDER_GIT_COMMIT)
Note over GitCtx: Resolve repo and ref independently from first matching platform
CiEnv-->>GitCtx: Platform env values
GitCtx-->>SDK: { gitRepo?, gitRef? }
SDK->>SDK: Use CI values if still missing
end
alt Still missing repo or ref
SDK->>GitCtx: autoDetectGitContext()
GitCtx->>LocalGit: git remote get-url origin
LocalGit-->>GitCtx: Remote URL
GitCtx->>GitCtx: normalizeRemoteRepo(remote)
Note over GitCtx: Accepts only https/ssh/git@ URL forms, rejects local paths
GitCtx->>LocalGit: git rev-parse HEAD
LocalGit-->>GitCtx: Commit SHA
GitCtx-->>SDK: { gitRepo?, gitRef? }
SDK->>SDK: Use local git values if still missing
end
alt Both repo and ref unresolved
SDK->>SDK: warnMissingGitContextOnce()
Note over SDK: Single warning, no fabricated defaults, fields omitted from spans
end
SDK->>Telemetry: Configure provider with gitRepo, gitRef resource attributes
SDK-->>App: initialize() complete
Note over App,SDK: Source Location Capture (after init)
App->>SDK: observe() / trace operations
SDK->>GitCtx: captureSourceLocation()
GitCtx->>GitCtx: Parse call stack, skip internal frames
GitCtx->>GitCtx: stackPathToFilePath() - normalize file:// URLs
GitCtx->>GitCtx: relativePath(filepath, gitRoot)
Note over GitCtx: Handles Windows paths, macOS case-insensitive matching, prefix collision prevention
GitCtx-->>SDK: { file?, line?, function? }
SDK->>Telemetry: Attach source location to span
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes traceroot-ai/traceroot#1023
Adds CI/platform git context resolution before local git auto-detection.
Changes
harvestCiGitContext(env)for CI/deploy metadata.explicit args -> TRACEROOT_GIT_* -> CI/platform env -> local git -> warn once.Acceptance Criteria
harvestCiGitContext(env)returns{ gitRepo?, gitRef? }, normalizes repo toowner/repo, and resolves repo/ref independently.TRACEROOT_GIT_*and local git detection.Design Decisions
Validation
Follow-Up Considerations
PATHin tests.Summary by cubic
Resolve git repo/ref in the TS SDK from CI env vars before local git, and harden path and remote parsing across platforms. This prevents missing git context in production and avoids invalid repo stamping or absolute path leaks.
harvestCiGitContext()to read git repo/ref from CI env vars (GitHub Actions, Vercel, GitLab CI, CircleCI, Bitbucket, Render), resolving fields independently and normalizingowner/repo.TRACEROOT_GIT_*→ CI/platform env → local git. No fabricated defaults.file://stack paths and Windows slashes, prevent prefix collisions, handle macOS case-insensitive repo paths, and never emit absolute paths.Written for commit e0b3b65. Summary will update on new commits.