LibreChat/scripts/quality/ignore.mts
Atef Bellaaj 715bf1f9e9
🧪 feat: Changed-Line Mutation Selection and Single Quality Report Comment (#18111)
Select mutants from changed lines and ignore logging-only mutants; rank survivors by risk topic from whole-word identifier matches.
Publish one quality report comment, edited in place, with the verdict, change risk (coverage gaps and CRAP refactor hints) and mutation survivors grouped by line.
Bundle the report data into one quality-report artifact; shard artifacts are internal.
Map api/ source aliases into coverage evidence and enforce a per-shard execution budget.
Move Redis cluster runtime files out of the checkout.
2026-11-16 08:00:48 -05:00

78 lines
2.9 KiB
TypeScript

import { VISITOR_KEYS } from '@babel/types';
import { declareValuePlugin, PluginKind } from '@stryker-mutator/api/plugin';
import type { CallExpression, Node } from '@babel/types';
import type { NodePath } from '@babel/core';
import type { Ignorer } from '@stryker-mutator/api/ignore';
export const REASON = 'logging-only';
const LOG_METHODS = new Set(['error', 'warn', 'info', 'debug', 'verbose', 'silly']);
const SIDE_EFFECT_TYPES = new Set([
'CallExpression',
'OptionalCallExpression',
'NewExpression',
'AssignmentExpression',
'UpdateExpression',
'AwaitExpression',
'YieldExpression',
'TaggedTemplateExpression',
'ImportExpression',
]);
function isNode(value: unknown): value is Node {
return !!value && typeof value === 'object' && 'type' in (value as object);
}
/** Depth-first scan; a call, mutation, `await`/`yield`, tagged template, dynamic import, or
* `delete` anywhere disqualifies the argument. */
function hasSideEffect(node: Node): boolean {
if (SIDE_EFFECT_TYPES.has(node.type)) return true;
if (node.type === 'UnaryExpression' && node.operator === 'delete') return true;
for (const key of VISITOR_KEYS[node.type] ?? []) {
const value = (node as unknown as Record<string, unknown>)[key];
if (Array.isArray(value)) {
if (value.some((item) => isNode(item) && hasSideEffect(item))) return true;
} else if (isNode(value) && hasSideEffect(value)) {
return true;
}
}
return false;
}
/** `logger.<level>(...)`, with side-effect-free arguments. */
function isLoggerCall(node: Node): node is CallExpression {
if (node.type !== 'CallExpression') return false;
const callee = node.callee;
if (callee.type !== 'MemberExpression' || callee.computed) return false;
if (callee.object.type !== 'Identifier' || callee.object.name !== 'logger') return false;
if (callee.property.type !== 'Identifier' || !LOG_METHODS.has(callee.property.name)) return false;
return !node.arguments.some((argument) => isNode(argument) && hasSideEffect(argument));
}
/** A standalone `logger.<level>(...)` call, as a statement on its own. */
function isLoggerStatement(node: Node): boolean {
return node.type === 'ExpressionStatement' && isLoggerCall(node.expression);
}
/** Ignores a mutant confined to a standalone, side-effect-free `logger.<level>(...)` call, and the
* block-emptying mutant of a block whose every statement is such a call. */
export class LoggingIgnorer implements Ignorer {
shouldIgnore(path: NodePath): string | undefined {
if (isLoggerStatement(path.node)) return REASON;
if (
path.isBlockStatement() &&
path.node.body.length > 0 &&
path.node.body.every(isLoggerStatement)
) {
return REASON;
}
return undefined;
}
}
export const LOGGER_IGNORER_NAME = 'quality-logger';
export const strykerPlugins = [
declareValuePlugin(PluginKind.Ignore, LOGGER_IGNORER_NAME, new LoggingIgnorer()),
];