Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle skipped audits and groups #911

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hanna-skryl
Copy link
Collaborator

Fixes #903

This fix enhances the filtering of report results by audits and groups through the core configuration (currently implemented for the Lighthouse plugin only).

The isSkipped property is introduced in the PluginConfig metadata for audits and groups, ensuring the complete set of plugin audits and groups is retained during CoreConfig validation to prevent unexpected errors. Filtering is now deferred to the filter middleware, which accurately handles skipped items by removing categories that contain only skipped or zero-weight references.

@hanna-skryl hanna-skryl self-assigned this Jan 7, 2025
@hanna-skryl hanna-skryl changed the title fix: handle skipped audits and groups fix: handle skipped audits and groups Jan 7, 2025
@hanna-skryl hanna-skryl force-pushed the fix/invalid-category-references branch from 8610bf6 to 884f53c Compare January 7, 2025 00:54
Copy link

github-actions bot commented Jan 7, 2025

Code PushUp

🤨 Code PushUp report has both improvements and regressions – compared target commit 29a4de4 with source commit 4777a83.

🕵️ See full comparison in Code PushUp portal 🔍

🏷️ Categories

🏷️ Category ⭐ Previous score ⭐ Current score 🔄 Score change
Performance 🟡 56 🟡 51 ↓ −4.6
Code coverage 🟢 91 🟢 91 ↑ +0.1
Security 🟡 81 🟡 81
Updates 🟡 80 🟡 80
Accessibility 🟢 91 🟢 91
Best Practices 🟢 100 🟢 100
SEO 🟡 61 🟡 61
Bug prevention 🟢 100 🟢 100
Code style 🟢 100 🟢 100
👍 1 group improved, 👎 1 group regressed, 👍 4 audits improved, 👎 4 audits regressed, 12 audits changed without impacting score

🗃️ Groups

🔌 Plugin 🗃️ Group ⭐ Previous score ⭐ Current score 🔄 Score change
Lighthouse Performance 🟡 56 🟡 51 ↓ −4.6
Code coverage Code coverage metrics 🟢 91 🟢 91 ↑ +0.1

15 other groups are unchanged.

🛡️ Audits

🔌 Plugin 🛡️ Audit 📏 Previous value 📏 Current value 🔄 Value change
Lighthouse Speed Index 🟨 4.7 s 🟥 6.6 s ↑ +41.7 %
Lighthouse Time to Interactive 🟥 11.8 s 🟥 15.4 s ↑ +29.9 %
Lighthouse First Contentful Paint 🟨 2.9 s 🟨 2.7 s ↓ −8.8 %
Lighthouse Largest Contentful Paint 🟨 3.2 s 🟨 3.5 s ↑ +8.3 %
Lighthouse Total Blocking Time 🟥 3,940 ms 🟥 7,610 ms ↑ +93.3 %
Code coverage Branch coverage 🟨 85.6 % 🟨 85.9 % ↑ +0.3 %
Code coverage Line coverage 🟩 90.4 % 🟩 90.5 % ↑ +0.1 %
Code coverage Function coverage 🟩 93.1 % 🟩 93.2 % ↑ +0.1 %
Lighthouse Avoids enormous network payloads 🟩 Total size was 1,828 KiB 🟩 Total size was 1,816 KiB ↓ −0.7 %
Lighthouse Minimizes main-thread work 🟥 14.4 s 🟥 19.4 s ↑ +35.1 %
Lighthouse Metrics 🟩 100% 🟩 100% ↑ +29.9 %
Lighthouse JavaScript execution time 🟥 5.6 s 🟥 8.8 s ↑ +56.2 %
Lighthouse Eliminate render-blocking resources 🟥 Potential savings of 1,250 ms 🟥 Potential savings of 220 ms ↓ −82.6 %
Lighthouse Max Potential First Input Delay 🟥 1,520 ms 🟥 2,500 ms ↑ +64 %
Lighthouse Reduce unused CSS 🟥 Potential savings of 66 KiB 🟥 Potential savings of 66 KiB ↓ −33.3 %
Lighthouse Server Backend Latencies 🟩 130 ms 🟩 60 ms ↓ −54.5 %
Lighthouse Uses efficient cache policy on static assets 🟨 28 resources found 🟨 28 resources found ↓ −0.1 %
Lighthouse Initial server response time was short 🟩 Root document took 270 ms 🟩 Root document took 330 ms ↑ +19.8 %
Lighthouse Network Round Trip Times 🟩 10 ms 🟩 20 ms ↑ +67.1 %
Lighthouse Avoids an excessive DOM size 🟥 2,133 elements 🟥 2,134 elements ↑ +0.1 %

568 other audits are unchanged.

@hanna-skryl hanna-skryl marked this pull request as ready for review January 7, 2025 19:47
@hanna-skryl hanna-skryl requested a review from BioPhoton as a code owner January 7, 2025 19:47
@hanna-skryl hanna-skryl force-pushed the fix/invalid-category-references branch from 1e29603 to 10e761b Compare January 8, 2025 03:29
Comment on lines +20 to 33
it('should mark audits in onlyAudits as not skipped', () => {
const pluginConfig = lighthousePlugin('https://code-pushup-portal.com', {
onlyAudits: ['first-contentful-paint'],
});

expect(() => pluginConfigSchema.parse(pluginConfig)).not.toThrow();

expect(pluginConfig.audits[0]).toEqual(
expect(
pluginConfig.audits.find(({ slug }) => slug === 'first-contentful-paint'),
).toEqual(
expect.objectContaining({
slug: 'first-contentful-paint',
isSkipped: false,
}),
);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm missing some assertion that the other audits have isSkipped: true. (Same for groups.)

Comment on lines +162 to +172
const weightMap = new Map<string, number>();
plugin.groups.forEach(group => {
group.refs.forEach(ref => {
weightMap.set(ref.slug, (weightMap.get(ref.slug) ?? 0) + ref.weight);
});
});
const totalWeight = plugin.audits.reduce(
(sum, audit) => sum + (weightMap.get(audit.slug) ?? 0),
0,
);
return totalWeight === 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This implementation doesn't take into account that an audit can be referenced by multiple groups within the plugin. I would simply sum up the weights for each group, and then check if some group has a total weight of 0.

Comment on lines +87 to +102
const invalidArgs = [
{ option: 'onlyCategories', args: onlyCategories ?? [] },
{ option: 'skipCategories', args: skipCategories ?? [] },
].filter(({ args }) =>
args.some(arg => skippedCategories.some(({ slug }) => slug === arg)),
);
if (invalidArgs.length > 0) {
throw new OptionValidationError(
invalidArgs
.map(
({ option, args }) =>
`The --${option} argument references skipped categories: ${args.join(', ')}`,
)
.join('. '),
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wouldn't throw validation errors in this case. Skipping an already skipped category seems harmless to me. And we could simply remove skipped categories from onlyCategories. Only if all of onlyCategories are skipped would we consider that a validation error, because that leaves us with nothing to run. But other than that, I would just log a warning. The "skipping already skipped" warning should probably be behind verbose flag as well. 🤔

.map(({ isSkipped, ...props }) => props);
}

export function processPlugins(plugins: PluginConfig[]): PluginConfig[] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The name processPlugins isn't very self-explanatory:

Suggested change
export function processPlugins(plugins: PluginConfig[]): PluginConfig[] {
export function filterSkippedInPlugins(plugins: PluginConfig[]): PluginConfig[] {

Comment on lines +104 to +106
isSkipped: isSkippedDescription
? isSkippedSchema.describe(isSkippedDescription)
: isSkippedSchema,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please also re-generate the Markdown docs (npx nx generate-docs models)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix onlyAudits and onlyGroups errors in Lighthouse plugin
2 participants