-
Notifications
You must be signed in to change notification settings - Fork 15
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
base: main
Are you sure you want to change the base?
Conversation
8610bf6
to
884f53c
Compare
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👍 1 group improved, 👎 1 group regressed, 👍 4 audits improved, 👎 4 audits regressed, 12 audits changed without impacting score🗃️ Groups
15 other groups are unchanged. 🛡️ Audits
568 other audits are unchanged. |
1e29603
to
10e761b
Compare
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, | ||
}), | ||
); | ||
}); |
There was a problem hiding this comment.
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.)
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; |
There was a problem hiding this comment.
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.
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('. '), | ||
); | ||
} |
There was a problem hiding this comment.
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[] { |
There was a problem hiding this comment.
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:
export function processPlugins(plugins: PluginConfig[]): PluginConfig[] { | |
export function filterSkippedInPlugins(plugins: PluginConfig[]): PluginConfig[] { |
isSkipped: isSkippedDescription | ||
? isSkippedSchema.describe(isSkippedDescription) | ||
: isSkippedSchema, |
There was a problem hiding this comment.
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
)?
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 thePluginConfig
metadata for audits and groups, ensuring the complete set of plugin audits and groups is retained duringCoreConfig
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.