Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .depcheckrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"@lavamoat/preinstall-always-fail",
"@types/*",
"@yarnpkg/types",
"prettier-plugin-packagejson",
"eslint-plugin-n",
"oxlint-tsgolint",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier unused by depcheck

Medium Severity

prettier stays a runtime dependency for auto-changelog --prettier, but lint:misc no longer invokes the prettier binary and .prettierrc.js is gone. depcheck therefore treats prettier as unused, so yarn lint:dependencies --check fails. eslint-plugin-n and oxlint-tsgolint were added to .depcheckrc.json ignores for the same kind of indirect use, but prettier was not.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b709ec0. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked this, depcheck doesn't flag it. It counts prettier as used because it's a peer dependency of auto changelog, which the changelog check script imports, so lint:dependencies passes.

"@swc/cli",
"@swc/core",
"ts-node",
Expand Down
64 changes: 0 additions & 64 deletions .eslintrc.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#!/usr/bin/env node

import { Octokit } from '@octokit/rest';
import { downloadArtifactZip, findFilesInZip } from './lib/artifact-download.mjs';
import { parsePlaywrightJsonReport } from './lib/parse-playwright-json.mjs';
import { createSlackBlocks, sendSlackBatched } from './lib/slack-test-health-blocks.mjs';

import {
downloadArtifactZip,
findFilesInZip,
} from './lib/artifact-download.mjs';
import { partitionSummary } from './lib/classify-report-buckets.mjs';
import { parsePlaywrightJsonReport } from './lib/parse-playwright-json.mjs';
import {
createSlackBlocks,
sendSlackBatched,
} from './lib/slack-test-health-blocks.mjs';
import { summarizeTestHealth } from './lib/summarize-test-health.mjs';
import { getDateRange, getWorkflowRuns } from './lib/workflow-runs.mjs';

Expand All @@ -28,7 +35,8 @@ const env = {
WORKFLOW_IDS: process.env.WORKFLOW_IDS,
BRANCH: process.env.BRANCH || 'main',
LOOKBACK_DAYS: parsePositiveInt(process.env.LOOKBACK_DAYS, 1),
ARTIFACT_NAME_PREFIX: process.env.ARTIFACT_NAME_PREFIX || 'playwright-json-report',
ARTIFACT_NAME_PREFIX:
process.env.ARTIFACT_NAME_PREFIX || 'playwright-json-report',
RESULTS_FILE_PATTERN: process.env.RESULTS_FILE_PATTERN || 'playwright-report',
TOP_N: parsePositiveInt(process.env.TOP_N, 15),
REPORT_TITLE: process.env.REPORT_TITLE || 'Playwright Test Health Report',
Expand All @@ -46,16 +54,22 @@ if (!env.WORKFLOW_IDS) {

function getWorkflowIds() {
return env.WORKFLOW_IDS.split(',')
.map(value => value.trim())
.map((value) => value.trim())
.filter(Boolean);
}

function isTestFailureFinding(finding) {
return finding.classification === 'broken' || finding.classification === 'flaky' || finding.classification === 'infra';
return (
finding.classification === 'broken' ||
finding.classification === 'flaky' ||
finding.classification === 'infra'
);
}

function countTestFailureRuns(findings) {
return new Set(findings.filter(isTestFailureFinding).map(finding => finding.runId)).size;
return new Set(
findings.filter(isTestFailureFinding).map((finding) => finding.runId),
).size;
}

async function getMergedWorkflowRuns(github, dateRange) {
Expand All @@ -74,7 +88,9 @@ async function getMergedWorkflowRuns(github, dateRange) {
runs.push(...workflowRuns);
}

const dedupedRuns = Array.from(new Map(runs.map(run => [run.id, run])).values());
const dedupedRuns = Array.from(
new Map(runs.map((run) => [run.id, run])).values(),
);
dedupedRuns.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
return dedupedRuns;
}
Expand All @@ -95,7 +111,9 @@ async function collectFindings(github, runs) {
},
);

const matching = artifacts.filter(artifact => artifact.name.startsWith(env.ARTIFACT_NAME_PREFIX));
const matching = artifacts.filter((artifact) =>
artifact.name.startsWith(env.ARTIFACT_NAME_PREFIX),
);
matchingArtifacts += matching.length;

if (matching.length === 0) {
Expand All @@ -113,7 +131,9 @@ async function collectFindings(github, runs) {
const jsonFiles = findFilesInZip(zip, env.RESULTS_FILE_PATTERN);

if (jsonFiles.length === 0) {
console.log(` ⚠️ No ${env.RESULTS_FILE_PATTERN} file found in ${artifact.name}`);
console.log(
` ⚠️ No ${env.RESULTS_FILE_PATTERN} file found in ${artifact.name}`,
);
continue;
}

Expand All @@ -124,17 +144,23 @@ async function collectFindings(github, runs) {
findings.push(
...parsePlaywrightJsonReport(report, {
runId: run.id,
runUrl: run.html_url || `https://github.com/${env.OWNER}/${env.REPOSITORY}/actions/runs/${run.id}`,
runUrl:
run.html_url ||
`https://github.com/${env.OWNER}/${env.REPOSITORY}/actions/runs/${run.id}`,
date: run.created_at,
artifactName: artifact.name,
}),
);
} catch (error) {
console.log(` ❌ Invalid JSON in ${artifact.name}/${file.path}: ${error.message}`);
console.log(
` ❌ Invalid JSON in ${artifact.name}/${file.path}: ${error.message}`,
);
}
}
} catch (error) {
console.log(` ❌ Failed to process artifact ${artifact.name}: ${error.message}`);
console.log(
` ❌ Failed to process artifact ${artifact.name}: ${error.message}`,
);
}
}
}
Expand Down Expand Up @@ -166,21 +192,24 @@ async function sendSlackReport(summary, dateDisplay, metadata) {
}

function logClassificationDiagnostics(summary, metadata) {
const { brokenItems, flakyItems, watchItems, infraItems } = partitionSummary(summary);
const { brokenItems, flakyItems, watchItems, infraItems } =
partitionSummary(summary);

console.log('\n🧾 Classification diagnostics');
console.log(` Lookback: ${env.LOOKBACK_DAYS} day(s)`);
console.log(` Unique tests observed: ${summary.length}`);
console.log(
` Buckets -> failing: ${brokenItems.length}, infra: ${infraItems.length}, flaky: ${flakyItems.length}, watch: ${watchItems.length}`,
);
console.log(` CI runs: ${metadata.workflowCount} | Test-failure runs: ${metadata.testFailureRunCount}`);
console.log(
` CI runs: ${metadata.workflowCount} | Test-failure runs: ${metadata.testFailureRunCount}`,
);
console.log(` Other CI failures: ${metadata.otherFailedRunCount}`);

if (watchItems.length > 0) {
const preview = watchItems
.slice(0, 5)
.map(test => {
.map((test) => {
const broken = test.historicalBrokenCount ?? 0;
const flaky = test.historicalFlakyCount ?? 0;
return `${test.name} (${test.projectName}, failed ${broken}, flaky ${flaky})`;
Expand Down Expand Up @@ -208,16 +237,24 @@ async function main() {
return;
}

const failedRunCount = workflowRuns.filter(run => run.conclusion === 'failure').length;
const { findings, matchingArtifacts } = await collectFindings(github, workflowRuns);
const failedRunCount = workflowRuns.filter(
(run) => run.conclusion === 'failure',
).length;
const { findings, matchingArtifacts } = await collectFindings(
github,
workflowRuns,
);

if (matchingArtifacts === 0) {
console.log('⚠️ No matching artifacts found.');
return;
}

const testFailureRunCount = countTestFailureRuns(findings);
const otherFailedRunCount = Math.max(0, failedRunCount - testFailureRunCount);
const otherFailedRunCount = Math.max(
0,
failedRunCount - testFailureRunCount,
);
const summary = summarizeTestHealth(findings);

logClassificationDiagnostics(summary, {
Expand All @@ -235,16 +272,20 @@ async function main() {
} catch (error) {
console.error('❌ Error:', error.message);
if (error.status === 401) {
console.log('\n💡 GitHub token is unauthorized. Ensure it has repo and actions:read permissions.');
console.log(
'\n💡 GitHub token is unauthorized. Ensure it has repo and actions:read permissions.',
);
}
if (error.status === 404) {
console.log('\n💡 One or more workflows were not found. Check WORKFLOW_IDS values.');
console.log(
'\n💡 One or more workflows were not found. Check WORKFLOW_IDS values.',
);
}
process.exit(1);
}
}

main().catch(error => {
main().catch((error) => {
console.error('\n❌ Unexpected error:', error);
process.exit(1);
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ export async function downloadArtifactZip(github, { owner, repo, artifactId }) {
}

export function findFilesInZip(zip, filePattern) {
return zip.files.filter(file => {
return zip.files.filter((file) => {
const fileName = path.basename(file.path);
return file.path.startsWith(filePattern) || fileName.startsWith(filePattern);
return (
file.path.startsWith(filePattern) || fileName.startsWith(filePattern)
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ export function instabilityScore(test) {

export function partitionSummary(summary) {
const infraItems = summary
.filter(test => test.latestClassification === 'infra')
.filter((test) => test.latestClassification === 'infra')
.sort((a, b) => (b.infraCount ?? 0) - (a.infraCount ?? 0));

const brokenItems = summary
.filter(test => test.latestClassification === 'broken')
.filter((test) => test.latestClassification === 'broken')
.sort((a, b) => historicalBroken(b) - historicalBroken(a));

const flakyItems = summary
.filter(test => test.latestClassification === 'flaky')
.filter((test) => test.latestClassification === 'flaky')
.sort((a, b) => historicalFlaky(b) - historicalFlaky(a));

const watchItems = summary
.filter(
test =>
(test) =>
test.latestClassification === 'passed' &&
(historicalBroken(test) > 0 || historicalFlaky(test) > 0),
)
Expand All @@ -44,9 +44,18 @@ export function partitionSummary(summary) {
export function allocateBucketSlots(topN, counts) {
const { broken = 0, flaky = 0, watch = 0, infra = 0 } = counts;

let maxBroken = Math.min(broken, Math.max(Math.ceil(topN * 0.4), broken > 0 ? 2 : 0));
let maxFlaky = Math.min(flaky, Math.max(Math.ceil(topN * 0.25), flaky > 0 ? 2 : 0));
let maxInfra = Math.min(infra, Math.max(Math.ceil(topN * 0.1), infra > 0 ? 1 : 0));
let maxBroken = Math.min(
broken,
Math.max(Math.ceil(topN * 0.4), broken > 0 ? 2 : 0),
);
let maxFlaky = Math.min(
flaky,
Math.max(Math.ceil(topN * 0.25), flaky > 0 ? 2 : 0),
);
let maxInfra = Math.min(
infra,
Math.max(Math.ceil(topN * 0.1), infra > 0 ? 1 : 0),
);
let maxWatch = Math.min(watch, topN - maxBroken - maxFlaky - maxInfra);

let remaining = topN - (maxBroken + maxFlaky + maxWatch + maxInfra);
Expand All @@ -67,7 +76,9 @@ export function allocateBucketSlots(topN, counts) {
remaining -= extra;
}

const byKey = Object.fromEntries(buckets.map(bucket => [bucket.key, bucket.max]));
const byKey = Object.fromEntries(
buckets.map((bucket) => [bucket.key, bucket.max]),
);

return {
maxBroken: byKey.broken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export function normalizeRepoFilePath(filePath, { prefix } = {}) {

let normalized = String(filePath).replace(/\\/g, '/');

const isAbsolute = normalized.startsWith('/') || /^[A-Za-z]:\//.test(normalized);
const isAbsolute =
normalized.startsWith('/') || /^[A-Za-z]:\//.test(normalized);
if (isAbsolute) {
const testsMatch = normalized.match(/(?:^|\/)(tests\/.+)$/);
if (testsMatch) {
Expand All @@ -34,7 +35,10 @@ export function normalizeRepoFilePath(filePath, { prefix } = {}) {

normalized = normalized.replace(/^\/+/, '');

const cleanPrefix = prefix?.trim().replace(/\\/g, '/').replace(/^\/+|\/+$/g, '');
const cleanPrefix = prefix
?.trim()
.replace(/\\/g, '/')
.replace(/^\/+|\/+$/g, '');
if (cleanPrefix) {
const alreadyPrefixed =
normalized === cleanPrefix ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ function extractFirstFailureError(test) {
if (!firstFailure) {
return 'No error details';
}
return firstFailure?.error?.message ?? firstFailure?.errors?.[0]?.message ?? 'No error details';
return (
firstFailure?.error?.message ??
firstFailure?.errors?.[0]?.message ??
'No error details'
);
}

function extractInfraError(error) {
Expand Down
Loading
Loading