fix: enhance API interactions by adding authorization headers and improving page reload handling

This commit is contained in:
GitHub Actions
2026-02-25 19:03:05 +00:00
parent 5b436a883d
commit 122030269e
8 changed files with 143 additions and 58 deletions

View File

@@ -22,6 +22,31 @@
*/
import { APIRequestContext, APIResponse } from '@playwright/test';
import { readFileSync } from 'fs';
import { STORAGE_STATE } from '../constants';
/**
* Read auth token from storage state and return Authorization headers.
* Use this for page.request calls that need Bearer token auth.
*/
export function getStorageStateAuthHeaders(): Record<string, string> {
try {
const state = JSON.parse(readFileSync(STORAGE_STATE, 'utf-8'));
for (const origin of state.origins ?? []) {
for (const entry of origin.localStorage ?? []) {
if (entry.name === 'charon_auth_token' && entry.value) {
return { Authorization: `Bearer ${entry.value}` };
}
}
}
for (const cookie of state.cookies ?? []) {
if (cookie.name === 'auth_token' && cookie.value) {
return { Authorization: `Bearer ${cookie.value}` };
}
}
} catch { /* no-op */ }
return {};
}
/**
* API error response