Compare commits

..

5 Commits

Author SHA1 Message Date
peptiderepo
5a859e6d1a fix(setup): retry login up to 3× with 90s timeout and 15s backoff
Hostinger rate-limits GitHub runner IPs on wp-login.php, causing
TimeoutError (30s) during the auth setup step. This has produced 6
deploy-gate failures over 2 days across multiple repos.

Changes:
- Raise navigation timeout from 30s to 90s per attempt
- Wrap the full login sequence in a retry loop (up to 3 attempts)
- Create a fresh BrowserContext per attempt so stale cookies / throttle
  state cannot carry over between retries
- Wait 15s between attempts to let transient throttle windows clear
- Log each attempt number and outcome clearly (console.log + console.error)
  so any future failure is diagnosable from the CI log without a local repro
- On final failure, surface a hint pointing to the Hostinger throttle cause

Assertion behaviour: unchanged. The #wpadminbar check and storageState
write are identical to before — retries only affect getting past wp-login.

No changes to smoke test assertions, playwright.config.ts, or workflow files.

Agent-Session: e2e-login-flake-20260612
2026-06-12 02:32:14 +00:00
peptiderepo
3c29588824 ci(deploy): promote smoke to a production gate (#10)
deploy-production now needs smoke; a smoke FAILURE blocks prod while a skipped
smoke (run_smoke:false) still allows it. Automated functional gate replacing
the removed human approval gate — hands-off but safe.

Agent-Session: cto gate-smoke

Co-authored-by: peptiderepo <peptiderepo@users.noreply.github.com>
2026-06-09 22:28:41 +07:00
peptiderepo
a09d210895 test(smoke): label-agnostic admin-menu check (#9)
The peptide CPT menu was restructured (no top-level 'Peptides' label), so the
text=Peptides assertion failed. Assert the CPT's admin link by href
(a[href*='post_type=peptide']) and toBeAttached — robust to label changes and
submenu (hidden-until-hover) placement.

Agent-Session: cto smoke-green

Co-authored-by: peptiderepo <peptiderepo@users.noreply.github.com>
2026-06-09 22:24:44 +07:00
peptiderepo
3ed4b10ecd test(smoke): fix remaining 6 failures (#8)
- 02 search: target the visible .hero-search instance; the old .first()
  selector matched the hidden header search-overlay (instance 1).
- 01 calculator: it auto-computes from the peptide preset; select the peptide
  and assert #prc-results, scoped to .prc-calculator (the old broad
  button[type=submit] selector clicked the PSA search button).
- 03 admin: 'const nav' had been swallowed into a comment (ReferenceError).
- 04 rest-api: PSA /search returns {results:[]} with no 'status' key; drop it.

Auth fixed separately via a dedicated staging CI admin (ci-smoke) + corrected
STAGING_WP_ADMIN_* secrets; the global.setup failure was cascading into these.

Agent-Session: cto smoke-green

Co-authored-by: peptiderepo <peptiderepo@users.noreply.github.com>
2026-06-09 22:20:39 +07:00
peptiderepo
655843e42b ci(monitor): drop false drift alerts (#7)
Compare prod-deployment SHA to main and ignore changes confined to .github/,
tests/, and docs/build files (which the deploy excludes) — so infra-only commits
don't trip a false 'prod behind main' alert every day.

Agent-Session: cto monitor-drift-filter

Co-authored-by: peptiderepo <peptiderepo@users.noreply.github.com>
2026-06-09 14:15:28 +07:00
6 changed files with 93 additions and 56 deletions

View File

@@ -79,7 +79,10 @@ jobs:
deploy-production:
name: Deploy to Production
needs: [deploy-staging]
# Smoke is now a GATE: a smoke FAILURE blocks production. A deliberately
# skipped smoke (run_smoke: false) still allows prod via the if-condition.
needs: [deploy-staging, smoke]
if: ${{ !cancelled() && needs.deploy-staging.result == 'success' && needs.smoke.result != 'failure' }}
runs-on: ubuntu-latest
environment: production
steps:

View File

@@ -7,6 +7,11 @@
*
* The saved auth state (playwright/.auth/admin.json) is reused by the
* "chromium" project so individual tests don't each incur a login round-trip.
*
* Retry hardening (2026-06-12): Hostinger rate-limits GitHub runner IPs on
* wp-login.php, causing TimeoutError on page.goto. The login attempt is now
* retried up to MAX_ATTEMPTS times with a fresh browser context per attempt
* and BACKOFF_MS delay between attempts so transient throttle windows clear.
*/
import { test as setup, expect } from '@playwright/test';
@@ -15,9 +20,14 @@ import * as fs from 'fs';
const AUTH_FILE = path.join(__dirname, 'playwright/.auth/admin.json');
setup('authenticate as WP admin', async ({ page }) => {
const MAX_ATTEMPTS = 3;
const BACKOFF_MS = 15_000; // 15 s between attempts
const NAV_TIMEOUT = 90_000; // raised from 30 s → 90 s per attempt
setup('authenticate as WP admin', async ({ browser }) => {
const user = process.env.WP_ADMIN_USER;
const password = process.env.WP_ADMIN_PASSWORD;
const baseURL = process.env.BASE_URL ?? 'https://staging.peptiderepo.com';
if (!user || !password) {
throw new Error(
@@ -25,28 +35,69 @@ setup('authenticate as WP admin', async ({ page }) => {
);
}
// Ensure directory exists
// Ensure auth directory exists
fs.mkdirSync(path.dirname(AUTH_FILE), { recursive: true });
await page.goto('/wp-login.php');
await page.fill('#user_login', user);
await page.fill('#user_pass', password);
await page.click('#wp-submit');
let lastError: unknown;
// Wait for any post-login navigation. The site may redirect successful logins
// to the homepage (via a login_redirect filter) rather than to wp-admin —
// staging does this. So we don't assert the post-submit URL; instead, we
// verify we're no longer ON wp-login.php (which would indicate a credential
// rejection or 2FA prompt) and then navigate explicitly to wp-admin.
await page.waitForURL((url) => !url.pathname.includes('/wp-login.php'), {
timeout: 20_000,
});
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
console.log(
`[setup] Login attempt ${attempt}/${MAX_ATTEMPTS} — navigating to wp-login.php ...`
);
// Navigate explicitly into wp-admin to capture the authenticated admin session.
await page.goto('/wp-admin/');
await expect(page).toHaveURL(/\/wp-admin\//, { timeout: 20_000 });
await expect(page.locator('#wpadminbar')).toBeVisible();
// Fresh context per attempt so stale cookies / throttle state don't carry over.
const context = await browser.newContext({ baseURL });
const page = await context.newPage();
// Persist session cookies + localStorage to disk
await page.context().storageState({ path: AUTH_FILE });
try {
await page.goto('/wp-login.php', { timeout: NAV_TIMEOUT });
await page.fill('#user_login', user);
await page.fill('#user_pass', password);
await page.click('#wp-submit');
// Wait for any post-login navigation. The site may redirect successful
// logins to the homepage (via a login_redirect filter) rather than to
// wp-admin — staging does this. So we don't assert the post-submit URL;
// instead, we verify we're no longer ON wp-login.php (which would
// indicate a credential rejection or 2FA prompt) and then navigate
// explicitly to wp-admin.
await page.waitForURL(
(url) => !url.pathname.includes('/wp-login.php'),
{ timeout: NAV_TIMEOUT }
);
// Navigate explicitly into wp-admin to capture the authenticated admin session.
await page.goto('/wp-admin/', { timeout: NAV_TIMEOUT });
await expect(page).toHaveURL(/\/wp-admin\//, { timeout: 20_000 });
await expect(page.locator('#wpadminbar')).toBeVisible({ timeout: 20_000 });
// Persist session cookies + localStorage to disk
await page.context().storageState({ path: AUTH_FILE });
console.log(`[setup] Login succeeded on attempt ${attempt}/${MAX_ATTEMPTS}`);
await context.close();
return; // success — exit setup
} catch (err) {
lastError = err;
const message = err instanceof Error ? err.message : String(err);
console.error(
`[setup] Login attempt ${attempt}/${MAX_ATTEMPTS} FAILED: ${message}`
);
await context.close();
if (attempt < MAX_ATTEMPTS) {
console.log(`[setup] Waiting ${BACKOFF_MS / 1000}s before retry ...`);
await new Promise((resolve) => setTimeout(resolve, BACKOFF_MS));
}
}
}
// All attempts exhausted — surface the last error with a clear diagnostic.
throw new Error(
`[setup] All ${MAX_ATTEMPTS} login attempts failed. ` +
`Last error: ${lastError instanceof Error ? lastError.message : String(lastError)}\n` +
`Hint: Hostinger may still be throttling GitHub runner IPs. ` +
`Re-run the workflow once the throttle window clears, or increase BACKOFF_MS / MAX_ATTEMPTS.`
);
});

View File

@@ -39,31 +39,14 @@ test.describe('Reconstitution Calculator', () => {
expect(options).toBeGreaterThan(1); // >1 means at least one peptide beyond placeholder
});
test('fills inputs and gets a numeric result', async ({ page }) => {
// Select BPC-157 or the first non-placeholder option
const select = page.locator('select').first();
const firstPeptide = select.locator('option').nth(1);
const firstValue = await firstPeptide.getAttribute('value');
await select.selectOption(firstValue ?? '');
// Fill reconstitution volume (mL) — use a known valid value
const volInput = page.locator('input[name*="recon"], input[placeholder*="mL"], input[type="number"]').first();
await volInput.fill('2');
// Fill desired dose
const doseInput = page.locator('input[name*="dose"], input[placeholder*="dose"], input[type="number"]').nth(1);
await doseInput.fill('250');
// Trigger calculation (button or auto-calculate on input)
const calcButton = page.locator('button[type="submit"], button:has-text("Calculate")');
if (await calcButton.count() > 0) {
await calcButton.first().click();
}
// Results container should show a non-zero concentration or injection volume
const results = page.locator('.prc-results, .calculator-results, [data-prc-result]').first();
await expect(results).toBeVisible({ timeout: 5_000 });
const resultText = await results.textContent();
expect(resultText).toMatch(/\d+(\.\d+)?/); // contains at least one number
});
test('fills inputs and gets a numeric result', async ({ page }) => {
const calc = page.locator('.prc-calculator');
// The calculator auto-computes once a peptide preset is chosen (the preset
// supplies vial size, recommended water volume and a default dose).
await calc.locator('#prc-peptide-select').selectOption({ index: 1 });
// Results panel unhides and renders numeric result cards.
const results = page.locator('#prc-results');
await expect(results).toBeVisible({ timeout: 10_000 });
await expect(page.locator('.prc-result-card__value').first()).toHaveText(/\d/, { timeout: 5_000 });
});
});

View File

@@ -25,14 +25,14 @@ test.describe('Peptide Search AI', () => {
test('search input widget is present on page', async ({ page }) => {
// PSA renders a form with class .psa-search-form or input with data-psa attr
const searchInput = page.locator(
'.psa-search-form input, input[name*="peptide"], input[placeholder*="peptide" i], [data-psa] input'
'.hero-search .psa-search-input'
).first();
await expect(searchInput).toBeVisible({ timeout: 10_000 });
});
test('searching for a known peptide returns results', async ({ page }) => {
const searchInput = page.locator(
'.psa-search-form input, input[name*="peptide"], input[placeholder*="peptide" i], [data-psa] input'
'.hero-search .psa-search-input'
).first();
await expect(searchInput).toBeVisible();
@@ -41,7 +41,7 @@ test.describe('Peptide Search AI', () => {
await searchInput.press('Enter');
// Results container should appear and contain something
const results = page.locator('.psa-results, .psa-search-results, [data-psa-results]').first();
const results = page.locator('.hero-search .psa-search-results').first();
await expect(results).toBeVisible({ timeout: 15_000 });
const text = await results.textContent();
expect((text ?? '').trim().length).toBeGreaterThan(0);
@@ -57,7 +57,7 @@ test.describe('Peptide Search AI', () => {
);
const searchInput = page.locator(
'.psa-search-form input, input[name*="peptide"], input[placeholder*="peptide" i], [data-psa] input'
'.hero-search .psa-search-input'
).first();
await searchInput.fill('TB-500');
await searchInput.press('Enter');

View File

@@ -97,10 +97,11 @@ test.describe('WP Admin — PRAutoBlogger settings page', () => {
test.describe('WP Admin — Peptide Repo Core admin', () => {
test('PR Core menu item exists in wp-admin', async ({ page }) => {
await page.goto(`${ADMIN}/`);
// PR Core registers the peptide CPT which creates a "Peptides" menu item const nav = page.locator('#adminmenu');
// PR Core registers the peptide CPT which creates a "Peptides" menu item
const nav = page.locator('#adminmenu');
await expect(nav).toBeVisible();
// "Peptides" top-level menu item is registered by the peptide CPT
await expect(nav.locator('text=Peptides')).toBeVisible({ timeout: 10_000 });
// PR Core registers the peptide CPT, which adds a post_type=peptide admin menu/submenu (label-agnostic).
await expect(nav.locator('a[href*="post_type=peptide"]').first()).toBeAttached({ timeout: 10_000 });
});
test('PR Core Settings page loads', async ({ page }) => {

View File

@@ -38,7 +38,6 @@ test.describe('REST API — Peptide Search AI', () => {
expect([200, 404]).toContain(res.status());
if (res.status() === 200) {
const body = await res.json();
expect(body).toHaveProperty('status');
expect(body).toHaveProperty('results');
}
});