( state: SyncState, repoSlug: string, etag?: string | null, )
| 186 | // ─── Fetch (pull) ──────────────────────────────────────────── |
| 187 | |
| 188 | async function fetchTeamMemoryOnce( |
| 189 | state: SyncState, |
| 190 | repoSlug: string, |
| 191 | etag?: string | null, |
| 192 | ): Promise<TeamMemorySyncFetchResult> { |
| 193 | try { |
| 194 | await checkAndRefreshOAuthTokenIfNeeded() |
| 195 | |
| 196 | const auth = getAuthHeaders() |
| 197 | if (auth.error) { |
| 198 | return { |
| 199 | success: false, |
| 200 | error: auth.error, |
| 201 | skipRetry: true, |
| 202 | errorType: 'auth', |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | const headers: Record<string, string> = { ...auth.headers } |
| 207 | if (etag) { |
| 208 | headers['If-None-Match'] = `"${etag.replace(/"/g, '')}"` |
| 209 | } |
| 210 | |
| 211 | const endpoint = getTeamMemorySyncEndpoint(repoSlug) |
| 212 | const response = await axios.get(endpoint, { |
| 213 | headers, |
| 214 | timeout: TEAM_MEMORY_SYNC_TIMEOUT_MS, |
| 215 | validateStatus: status => |
| 216 | status === 200 || status === 304 || status === 404, |
| 217 | }) |
| 218 | |
| 219 | if (response.status === 304) { |
| 220 | logForDebugging('team-memory-sync: not modified (304)', { |
| 221 | level: 'debug', |
| 222 | }) |
| 223 | return { success: true, notModified: true, checksum: etag ?? undefined } |
| 224 | } |
| 225 | |
| 226 | if (response.status === 404) { |
| 227 | logForDebugging('team-memory-sync: no remote data (404)', { |
| 228 | level: 'debug', |
| 229 | }) |
| 230 | state.lastKnownChecksum = null |
| 231 | return { success: true, isEmpty: true } |
| 232 | } |
| 233 | |
| 234 | const parsed = TeamMemoryDataSchema().safeParse(response.data) |
| 235 | if (!parsed.success) { |
| 236 | logForDebugging('team-memory-sync: invalid response format', { |
| 237 | level: 'warn', |
| 238 | }) |
| 239 | return { |
| 240 | success: false, |
| 241 | error: 'Invalid team memory response format', |
| 242 | skipRetry: true, |
| 243 | errorType: 'parse', |
| 244 | } |
| 245 | } |
no test coverage detected