Skip to content

Commit bcbf46e

Browse files
Copilotpetehauge
andauthored
docs: record Issue #16 User-Agent implementation learnings
- Added TypeScriptDev learning: USER_AGENT constant in src/lib/user-agent.ts, header set in ApimClient.request() at line 108 - Added TestEngineer learning: User-Agent testing patterns for both auth paths - Closes #16 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: petehauge <12090616+petehauge@users.noreply.github.com>
1 parent 8b24861 commit bcbf46e

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

‎.squad/agents/testengineer/history.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,34 @@
7979

8080
**Result:** 42 total tests in resource-uri.test.ts (32 existing + 13 new for buildResourceLabel, minus 3 restructured). All tests pass. Function behavior validated for all documented use cases.
8181

82+
### 2026-04-29: User-Agent Header Testing (Issue #16)
83+
84+
**Context:** Added test coverage for User-Agent header implementation across both lib and client layers.
85+
86+
**Tests Created:**
87+
- `tests/unit/lib/user-agent.test.ts` - 3 tests
88+
- ✅ USER_AGENT constant exports as string
89+
- ✅ USER_AGENT matches format `apiops-cli/{version}`
90+
- ✅ Version in USER_AGENT matches package.json version
91+
92+
- `tests/unit/clients/apim-client.test.ts` - 2 new tests added to "User-Agent" describe block
93+
- ✅ User-Agent header set on authenticated requests (Bearer token path)
94+
- ✅ User-Agent header set on unauthenticated requests (skipAuth blob path)
95+
96+
**Testing Approach:**
97+
- Verified header presence in both auth paths using standard mock setup
98+
- Both tests confirm header is set after auth logic via `headers.set()`
99+
- Used existing test patterns: mock fetch with Response objects, inspect headers in captured context
100+
101+
**Code Review Feedback:**
102+
- One finding: duplicate test replaced with skipAuth blob path test to avoid redundancy
103+
- Ensures both auth flows are covered without test duplication
104+
105+
**Pattern:** When testing client-wide headers:
106+
- Add lib unit test for constant/value verification
107+
- Add client integration tests for both supported request patterns
108+
- Verify header appears in expected request headers captured by mocks
109+
110+
**Result:** 5 new User-Agent tests, all passing. Code review approved.
111+
82112
<!-- Append new learnings here after each session -->

‎.squad/agents/typescriptdev/history.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,30 @@ vi.mocked(fs.access).mockImplementation(async (p) => {
160160
Same rule applies to `expect(fs.copyFile).toHaveBeenCalledWith(...)` assertions — use the resolved form.
161161

162162
**Files:** `tests/unit/services/init-service.test.ts`.
163+
164+
### 2026-04-29: User-Agent Header Implementation (Issue #16)
165+
166+
**Context:** Implemented User-Agent header for all APIM REST API calls to identify the apiops-cli client.
167+
168+
**Key Decisions:**
169+
- Created `src/lib/user-agent.ts` with `USER_AGENT` constant using module pattern: `createRequire` loads package.json at module initialization
170+
- Format: `apiops-cli/{version}` (e.g., `apiops-cli/0.1.0`)
171+
- Header set in `ApimClient.request()` at line 108, after auth logic but before retry loop
172+
- Applied universally to all request types: authenticated (Bearer token) and unauthenticated (SAS blob skipAuth paths)
173+
174+
**Pattern:** When exporting client identifiers:
175+
- Use ES module pattern with `createRequire(import.meta.url)` to load package.json at import time
176+
- No runtime file system calls or dynamic version reads
177+
- Export as constant string from dedicated lib module
178+
- Consumed by clients that need the value
179+
180+
**Files Modified:**
181+
- `src/lib/user-agent.ts` - New file
182+
- `src/clients/apim-client.ts` - Added header set at line 108
183+
184+
**Implementation Details:**
185+
- `headers.set('User-Agent', USER_AGENT)` executes after skipping auth headers but maintaining compatibility
186+
- Tested on both auth paths: standard Bearer token and skipAuth (SAS blob)
187+
- Issue #16 closed
188+
189+
**Tests:** Created `tests/unit/lib/user-agent.test.ts` (3 tests) and added to `apim-client.test.ts` (2 tests)

0 commit comments

Comments
 (0)