feat: Implement live environment loading and update race storage metadata handling
This commit is contained in:
parent
4f003bb5a9
commit
77e48b8139
8 changed files with 76 additions and 100 deletions
|
|
@ -11,11 +11,16 @@ const {
|
|||
|
||||
const LIVE_EXPECTED_RACE_STORAGE = {
|
||||
year: '2026',
|
||||
monthFolder: '04.APRILE',
|
||||
monthFolder: '03.MARZO',
|
||||
raceFolder: 'HMF_2026',
|
||||
relativeDir: '2026/04.APRILE/HMF_2026'
|
||||
relativeDir: '2026/03.MARZO/HMF_2026'
|
||||
};
|
||||
|
||||
const LIVE_SAMPLE_PHOTO_IDS = [
|
||||
'21.ARRIVO_CON TEMPO\\DSC_8385.JPG',
|
||||
'21.ARRIVO_CON TEMPO\\DSC_8295.JPG'
|
||||
];
|
||||
|
||||
function escapeRegExp(value) {
|
||||
return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
|
|
@ -175,10 +180,7 @@ async function expectLegacyFaceAiGalleryToRemainStable(page, expectedPhotoIds, h
|
|||
}
|
||||
|
||||
test('renders the exact live FaceAI filtered sample URL with visible thumbnails', async ({ page }) => {
|
||||
const samplePhotoIds = [
|
||||
'00.PANORAMICA\\GIC_7918.JPG',
|
||||
'02.PARTENZA\\GIC_7918.JPG'
|
||||
];
|
||||
const samplePhotoIds = LIVE_SAMPLE_PHOTO_IDS;
|
||||
const sampleUrl = `${LIVE_SITE_BASE_URL}/42%20HALF%20MARATHON%20FIRENZE_gara-1018545---48-1.html?faceaiMatchSource=faceai&faceaiMatchCount=2&faceaiPhotoIds=${encodeURIComponent(samplePhotoIds.join(','))}`;
|
||||
|
||||
await ensureLiveAuthenticatedRacePage(page);
|
||||
|
|
@ -197,7 +199,7 @@ test('renders the exact live FaceAI filtered sample URL with visible thumbnails'
|
|||
await expectLegacyFaceAiGalleryToRemainStable(page, samplePhotoIds);
|
||||
});
|
||||
|
||||
test('keeps the live Firenze FaceAI race storage metadata pinned to April 2026', async ({ page }) => {
|
||||
test('keeps the live Firenze FaceAI race storage metadata pinned to the stored server path', async ({ page }) => {
|
||||
await ensureLiveAuthenticatedRacePage(page);
|
||||
|
||||
await expect(page.locator('#faceAiRaceYear')).toHaveValue(LIVE_EXPECTED_RACE_STORAGE.year);
|
||||
|
|
@ -217,10 +219,7 @@ test('keeps the live Firenze FaceAI race storage metadata pinned to April 2026',
|
|||
});
|
||||
|
||||
test('resolves the live Firenze sample photo lookups inside the current race', async ({ page }) => {
|
||||
const samplePhotoIds = [
|
||||
'00.PANORAMICA\\GIC_7918.JPG',
|
||||
'02.PARTENZA\\GIC_7918.JPG'
|
||||
];
|
||||
const samplePhotoIds = LIVE_SAMPLE_PHOTO_IDS;
|
||||
|
||||
await ensureLiveAuthenticatedRacePage(page);
|
||||
|
||||
|
|
@ -302,10 +301,9 @@ test('returns to the live race page from FaceAI without leaving the legacy spinn
|
|||
expect(bodyState.ariaBusy).not.toBe('true');
|
||||
});
|
||||
|
||||
test.skip(!LIVE_SITE_RUN_UPLOAD_FLOW, 'Set LIVE_SITE_RUN_UPLOAD_FLOW=1 to exercise the live upload flow.');
|
||||
|
||||
test('accepts the supplied portrait image for the live upload flow', async ({ page }) => {
|
||||
test.slow();
|
||||
test.skip(!LIVE_SITE_RUN_UPLOAD_FLOW, 'Set LIVE_SITE_RUN_UPLOAD_FLOW=1 to exercise the live upload flow.');
|
||||
|
||||
requirePortraitFixture();
|
||||
|
||||
|
|
@ -356,6 +354,12 @@ test('accepts the supplied portrait image for the live upload flow', async ({ pa
|
|||
const expectedPhotoIds = (finalUrl.searchParams.get('faceaiPhotoIds') || '').split(',').map((value) => value.trim()).filter(Boolean);
|
||||
expect(expectedPhotoIds.length, 'Expected the final race page URL to include at least one FaceAI photo identifier.').toBeGreaterThan(0);
|
||||
|
||||
for (const photoKey of expectedPhotoIds) {
|
||||
const lookup = await lookupLivePhoto(page, photoKey);
|
||||
expect(lookup.status, `Expected FaceAI to return a photo key that resolves on the current live race page: ${photoKey}`).toBe(200);
|
||||
expect(lookup.payload && lookup.payload.found, `Expected FaceAI to return a photo key that exists in the current live race: ${photoKey}`).toBe(true);
|
||||
}
|
||||
|
||||
const visiblePhotoIds = await waitForVisibleLegacyPhotoIds(page, expectedPhotoIds.length);
|
||||
expect(visiblePhotoIds.length, 'Expected at least one legacy race thumbnail to remain visible after FaceAI filtering.').toBeGreaterThan(0);
|
||||
expect(visiblePhotoIds.sort()).toEqual(expectedPhotoIds.slice().sort());
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { expect } = require('@playwright/test');
|
||||
const { loadLiveEnv } = require('./load-live-env');
|
||||
|
||||
loadLiveEnv();
|
||||
|
||||
const WORKSPACE_ROOT = path.resolve(__dirname, '..', '..', '..');
|
||||
const LIVE_SITE_BASE_URL = process.env.LIVE_SITE_BASE_URL || 'https://www.regalamiunsorriso.it';
|
||||
|
|
|
|||
52
faceai/tests/live-site/load-live-env.js
Normal file
52
faceai/tests/live-site/load-live-env.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
let loaded = false;
|
||||
|
||||
function parseEnvLine(line) {
|
||||
const trimmed = String(line || '').trim();
|
||||
if (!trimmed || trimmed.startsWith('#')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const separatorIndex = trimmed.indexOf('=');
|
||||
if (separatorIndex <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const key = trimmed.slice(0, separatorIndex).trim();
|
||||
let value = trimmed.slice(separatorIndex + 1).trim();
|
||||
|
||||
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
||||
value = value.slice(1, -1);
|
||||
}
|
||||
|
||||
return { key, value };
|
||||
}
|
||||
|
||||
function loadLiveEnv() {
|
||||
if (loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
|
||||
const envPath = path.resolve(__dirname, '..', '..', '.env');
|
||||
if (!fs.existsSync(envPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const envText = fs.readFileSync(envPath, 'utf8');
|
||||
for (const line of envText.split(/\r?\n/)) {
|
||||
const entry = parseEnvLine(line);
|
||||
if (!entry || !entry.key || Object.prototype.hasOwnProperty.call(process.env, entry.key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
process.env[entry.key] = entry.value;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
loadLiveEnv
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue