From da6c67b72d8f494f1ce5281c49569582e50ed5ef Mon Sep 17 00:00:00 2001 From: DeNNiiInc Date: Mon, 29 Dec 2025 10:54:59 +1100 Subject: [PATCH] Fix crashes in runner.js and git command in server.js --- lib/db.js | 3 ++- lib/runner.js | 32 ++++++++++++++++++-------------- server.js | 2 +- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/db.js b/lib/db.js index db88ca0..8f6f1d0 100644 --- a/lib/db.js +++ b/lib/db.js @@ -15,7 +15,8 @@ async function initSchema() { scores JSONB NOT NULL, metrics JSONB NOT NULL, user_uuid TEXT NOT NULL, - user_ip TEXT NOT NULL + user_ip TEXT NOT NULL, + filmstrip JSONB ); `; await client.query(query); diff --git a/lib/runner.js b/lib/runner.js index 1c80731..8249241 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -150,20 +150,24 @@ async function _executeTest(url, options) { + // Safe property access + const getScore = (cat) => (lhr.categories[cat] && lhr.categories[cat].score) ? lhr.categories[cat].score * 100 : 0; + const getMetric = (aud) => (lhr.audits[aud] && lhr.audits[aud].numericValue) ? lhr.audits[aud].numericValue : 0; + const summary = { id: testId, url: lhr.finalUrl, timestamp: lhr.fetchTime, scores: { - performance: lhr.categories.performance.score * 100, - accessibility: lhr.categories.accessibility.score * 100, - bestPractices: lhr.categories['best-practices'].score * 100, - seo: lhr.categories.seo.score * 100, + performance: getScore('performance'), + accessibility: getScore('accessibility'), + bestPractices: getScore('best-practices'), + seo: getScore('seo'), }, metrics: { - lcp: lhr.audits['largest-contentful-paint'].numericValue, - cls: lhr.audits['cumulative-layout-shift'].numericValue, - tbt: lhr.audits['total-blocking-time'].numericValue, + lcp: getMetric('largest-contentful-paint'), + cls: getMetric('cumulative-layout-shift'), + tbt: getMetric('total-blocking-time'), }, userAgent: lhr.userAgent, isMobile: isMobile, @@ -221,15 +225,15 @@ async function _executeTest(url, options) { url: lhr.finalUrl, timestamp: lhr.fetchTime, scores: { - performance: lhr.categories.performance.score * 100, - accessibility: lhr.categories.accessibility.score * 100, - bestPractices: lhr.categories['best-practices'].score * 100, - seo: lhr.categories.seo.score * 100, + performance: getScore('performance'), + accessibility: getScore('accessibility'), + bestPractices: getScore('best-practices'), + seo: getScore('seo'), }, metrics: { - lcp: lhr.audits['largest-contentful-paint'].numericValue, - cls: lhr.audits['cumulative-layout-shift'].numericValue, - tbt: lhr.audits['total-blocking-time'].numericValue, + lcp: getMetric('largest-contentful-paint'), + cls: getMetric('cumulative-layout-shift'), + tbt: getMetric('total-blocking-time'), }, userAgent: lhr.userAgent, isMobile: isMobile, diff --git a/server.js b/server.js index 6f74587..c905b29 100644 --- a/server.js +++ b/server.js @@ -14,7 +14,7 @@ app.use('/reports', express.static(path.join(__dirname, 'reports'))); // API Endpoint: Git Info app.get("/api/git-info", (req, res) => { - exec('/usr/bin/git log -1 --format="%H|%cr"', (error, stdout, stderr) => { + exec('git log -1 --format="%H|%cr"', (error, stdout, stderr) => { if (error) { console.error("Error getting git info:", error); console.error("Stderr:", stderr);