Compare commits

..

2 Commits

Author SHA1 Message Date
peptiderepo
027b078915 ci: add daily Deploy Health Monitor (drift + deploy-failure)
Scheduled GitHub Actions check (runs on GitHub infra, not the dead local cron):
for each app repo, compares the latest production deployment SHA to main and
flags failed deploy runs. Opens one de-duplicated 'deploy-health' issue when
something is off — the alarm that was missing when deploys silently broke.

Agent-Session: cto deploy-health-monitor
2026-06-09 07:11:24 +00:00
peptiderepo
07d23b420b ci(deploy): retry rsync on Hostinger runner-IP throttle + best-effort inventory guard
Pilot surfaced an exit-255 SSH connection timeout (documented Hostinger
rate-limiting of concurrent runner IPs). rsync now retries 4x/25s; the plugin
count guard is best-effort so a throttled check can't fail a good deploy.

Agent-Session: cto harden-deploy
2026-06-09 07:10:16 +00:00
7 changed files with 57 additions and 110 deletions

View File

@@ -79,10 +79,7 @@ jobs:
deploy-production: deploy-production:
name: Deploy to Production name: Deploy to Production
# Smoke is now a GATE: a smoke FAILURE blocks production. A deliberately needs: [deploy-staging]
# 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 runs-on: ubuntu-latest
environment: production environment: production
steps: steps:

View File

@@ -45,23 +45,7 @@ jobs:
if (sts.length) prodState = sts[0].state; if (sts.length) prodState = sts[0].state;
} }
if (runConc === 'failure') problems.push(`**${repo}**: latest deploy run failed (\`${short(runSha)}\`)`); if (runConc === 'failure') problems.push(`**${repo}**: latest deploy run failed (\`${short(runSha)}\`)`);
if (prodSha && prodSha !== main) { if (prodSha && prodSha !== main) problems.push(`**${repo}**: prod behind main — prod=\`${short(prodSha)}\` vs main=\`${short(main)}\` (undeployed commits)`);
// Only real drift if undeployed commits touch DEPLOYABLE files
// (ignore .github/, tests/, and docs/build files the deploy excludes).
try {
const cmp = (await github.rest.repos.compareCommits({owner, repo, base: prodSha, head: main})).data;
const deployable = (cmp.files || []).some(f => {
const x = f.filename;
if (x.startsWith('.github/') || x.startsWith('tests/')) return false;
if (/^(ARCHITECTURE|CONVENTIONS|CHANGELOG|README)\.md$/.test(x)) return false;
if (/^(composer\.(json|lock)|phpunit\.xml(\.dist)?|\.?phpcs\.xml\.dist)$/.test(x)) return false;
return true;
});
if (deployable) problems.push(`**${repo}**: prod behind main — prod=\`${short(prodSha)}\` vs main=\`${short(main)}\` (undeployed code changes)`);
} catch (e) {
problems.push(`**${repo}**: prod sha != main sha (could not diff: ${e.message})`);
}
}
if (prodSha && prodState !== 'success') problems.push(`**${repo}**: last production deployment state is \`${prodState}\``); if (prodSha && prodState !== 'success') problems.push(`**${repo}**: last production deployment state is \`${prodState}\``);
core.info(`${repo}: main=${short(main)} lastRun=${runConc} prodDeploy=${short(prodSha)}/${prodState}`); core.info(`${repo}: main=${short(main)} lastRun=${runConc} prodDeploy=${short(prodSha)}/${prodState}`);
} catch (e) { } catch (e) {

View File

@@ -7,11 +7,6 @@
* *
* The saved auth state (playwright/.auth/admin.json) is reused by the * 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. * "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'; import { test as setup, expect } from '@playwright/test';
@@ -20,14 +15,9 @@ import * as fs from 'fs';
const AUTH_FILE = path.join(__dirname, 'playwright/.auth/admin.json'); const AUTH_FILE = path.join(__dirname, 'playwright/.auth/admin.json');
const MAX_ATTEMPTS = 3; setup('authenticate as WP admin', async ({ page }) => {
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 user = process.env.WP_ADMIN_USER;
const password = process.env.WP_ADMIN_PASSWORD; const password = process.env.WP_ADMIN_PASSWORD;
const baseURL = process.env.BASE_URL ?? 'https://staging.peptiderepo.com';
if (!user || !password) { if (!user || !password) {
throw new Error( throw new Error(
@@ -35,69 +25,28 @@ setup('authenticate as WP admin', async ({ browser }) => {
); );
} }
// Ensure auth directory exists // Ensure directory exists
fs.mkdirSync(path.dirname(AUTH_FILE), { recursive: true }); fs.mkdirSync(path.dirname(AUTH_FILE), { recursive: true });
let lastError: unknown; await page.goto('/wp-login.php');
await page.fill('#user_login', user);
await page.fill('#user_pass', password);
await page.click('#wp-submit');
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) { // Wait for any post-login navigation. The site may redirect successful logins
console.log( // to the homepage (via a login_redirect filter) rather than to wp-admin —
`[setup] Login attempt ${attempt}/${MAX_ATTEMPTS} — navigating to wp-login.php ...` // 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,
});
// Fresh context per attempt so stale cookies / throttle state don't carry over. // Navigate explicitly into wp-admin to capture the authenticated admin session.
const context = await browser.newContext({ baseURL }); await page.goto('/wp-admin/');
const page = await context.newPage(); await expect(page).toHaveURL(/\/wp-admin\//, { timeout: 20_000 });
await expect(page.locator('#wpadminbar')).toBeVisible();
try { // Persist session cookies + localStorage to disk
await page.goto('/wp-login.php', { timeout: NAV_TIMEOUT }); await page.context().storageState({ path: AUTH_FILE });
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,14 +39,31 @@ test.describe('Reconstitution Calculator', () => {
expect(options).toBeGreaterThan(1); // >1 means at least one peptide beyond placeholder expect(options).toBeGreaterThan(1); // >1 means at least one peptide beyond placeholder
}); });
test('fills inputs and gets a numeric result', async ({ page }) => { test('fills inputs and gets a numeric result', async ({ page }) => {
const calc = page.locator('.prc-calculator'); // Select BPC-157 or the first non-placeholder option
// The calculator auto-computes once a peptide preset is chosen (the preset const select = page.locator('select').first();
// supplies vial size, recommended water volume and a default dose). const firstPeptide = select.locator('option').nth(1);
await calc.locator('#prc-peptide-select').selectOption({ index: 1 }); const firstValue = await firstPeptide.getAttribute('value');
// Results panel unhides and renders numeric result cards. await select.selectOption(firstValue ?? '');
const results = page.locator('#prc-results');
await expect(results).toBeVisible({ timeout: 10_000 }); // Fill reconstitution volume (mL) — use a known valid value
await expect(page.locator('.prc-result-card__value').first()).toHaveText(/\d/, { timeout: 5_000 }); 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
});
}); });

View File

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

View File

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

View File

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