_automation_reachability.cjs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * Automation reachability probe (test artifact only, NOT committed logic).
  3. * No-login smoke against the authorized intranet target.
  4. * Verifies /admin and /frontend serve HTTP<500 and render a document.
  5. * Does NOT require credentials; logged-in flows are deferred (待核实登录态).
  6. */
  7. const { chromium } = require('@playwright/test');
  8. const BASE = process.env.PW_BASE_URL || 'http://cfc.iwintrue.com';
  9. async function probePath(browser, path) {
  10. const ctx = await browser.newContext();
  11. const page = await ctx.newPage();
  12. const out = { path, base: BASE };
  13. try {
  14. const resp = await page.goto(BASE + path, { waitUntil: 'domcontentloaded', timeout: 30000 });
  15. await page.waitForTimeout(2000);
  16. out.status = resp ? resp.status() : null;
  17. out.ok = resp ? resp.status() < 500 : false;
  18. out.title = String(await page.title()).slice(0, 80);
  19. out.url = page.url().slice(0, 120);
  20. out.bodyLen = (await page.content()).length;
  21. out.hasDocument = out.bodyLen > 0;
  22. } catch (e) {
  23. out.fatal = String(e && e.message ? e.message : e).slice(0, 200);
  24. out.ok = false;
  25. } finally {
  26. await ctx.close();
  27. }
  28. return out;
  29. }
  30. (async () => {
  31. const summary = { base: BASE, ts: new Date().toISOString(), steps: {} };
  32. const browser = await chromium.launch({ headless: true, args: ['--no-sandbox'] });
  33. try {
  34. summary.steps.admin = await probePath(browser, '/admin');
  35. summary.steps.frontend = await probePath(browser, '/frontend');
  36. } catch (e) {
  37. summary.fatal = String(e && e.message ? e.message : e).slice(0, 300);
  38. } finally {
  39. await browser.close();
  40. }
  41. const fs = require('fs');
  42. fs.writeFileSync(__dirname + '/_automation_reachability_result.json', JSON.stringify(summary, null, 2));
  43. console.log(JSON.stringify(summary, null, 2));
  44. })();