From ffeb50bd029ac95a0cf7015ccbba6bcd1d65f44e Mon Sep 17 00:00:00 2001 From: Salman Chishti Date: Wed, 8 Apr 2026 16:49:32 +0000 Subject: [PATCH] fix: prevent duplicate orchestration ID in user-agent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add idempotency check to getUserAgentWithOrchestrationId — if the tag is already present in baseUserAgent, return it unchanged. This prevents doubling when both the exported helper and getOctokitOptions run for the same client. --- .../github/__tests__/orchestration.test.ts | 18 ++++++++++++++++++ packages/github/src/internal/utils.ts | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/github/__tests__/orchestration.test.ts b/packages/github/__tests__/orchestration.test.ts index 3b851ddb..0bda82f0 100644 --- a/packages/github/__tests__/orchestration.test.ts +++ b/packages/github/__tests__/orchestration.test.ts @@ -59,6 +59,14 @@ describe('orchestration ID support', () => { process.env['ACTIONS_ORCHESTRATION_ID'] = ' ' expect(getUserAgentWithOrchestrationId('my-app')).toBe('my-app') }) + + it('does not duplicate orchestration ID if already present in base', () => { + process.env['ACTIONS_ORCHESTRATION_ID'] = 'abc-123' + const alreadyTagged = 'my-app actions_orchestration_id/abc-123' + expect(getUserAgentWithOrchestrationId(alreadyTagged)).toBe( + alreadyTagged + ) + }) }) describe('public re-export', () => { @@ -110,5 +118,15 @@ describe('orchestration ID support', () => { const opts = getOctokitOptions('fake-token') expect(opts.userAgent).toBe('actions_orchestration_id/bad_chars_here_') }) + + it('does not duplicate orchestration ID when caller already applied it', () => { + process.env['ACTIONS_ORCHESTRATION_ID'] = 'test-orch-id' + const opts = getOctokitOptions('fake-token', { + userAgent: 'my-app actions_orchestration_id/test-orch-id' + }) + expect(opts.userAgent).toBe( + 'my-app actions_orchestration_id/test-orch-id' + ) + }) }) }) diff --git a/packages/github/src/internal/utils.ts b/packages/github/src/internal/utils.ts index 5ff4db52..03c5822a 100644 --- a/packages/github/src/internal/utils.ts +++ b/packages/github/src/internal/utils.ts @@ -49,8 +49,10 @@ export function getUserAgentWithOrchestrationId( const orchId = process.env['ACTIONS_ORCHESTRATION_ID']?.trim() if (orchId) { const sanitizedId = orchId.replace(/[^a-z0-9_.-]/gi, '_') + const tag = `actions_orchestration_id/${sanitizedId}` + if (baseUserAgent?.includes(tag)) return baseUserAgent const ua = baseUserAgent ? `${baseUserAgent} ` : '' - return `${ua}actions_orchestration_id/${sanitizedId}` + return `${ua}${tag}` } return baseUserAgent }