import { BaseCommand, flags } from '@adonisjs/core/ace' import type { CommandOptions } from '@adonisjs/core/types/ace' import db from '@adonisjs/lucid/services/db' import RuleSets from '#services/rule_sets' import { classKey, describeClass } from '#lib/release/index' /** * Publishes a rule set whose dropped classes are the pending ladder's (pending_classes.dropped; LOG.md (130)): the * edge keeps unnamed releases of those classes out of the pending store from then on, their explored sample * excepted. Run again as the record grows; unchanged classes publish nothing. */ export default class RulesClasses extends BaseCommand { static commandName = 'rules:classes' static description = "Publishes a rule set with the pending ladder's dropped classes" static options: CommandOptions = { startApp: true } @flags.boolean({ description: 'Show what would be published, write nothing' }) declare dryRun: boolean async run() { const { rows } = await db.rawQuery( `SELECT c.tool, g.name AS grp, c.klass, c.probed, c.named FROM pending_classes c JOIN groups g ON g.id = c.group_id WHERE c.dropped ORDER BY 1, 2, 3` ) const next = new Set(rows.map((r: any) => classKey(r.tool, r.grp, Number(r.klass)))) const { version, priorities: _p, ...current } = await RuleSets.current() const before = new Set(current.droppedClasses ?? []) const added = [...next].filter((c) => !before.has(c)) const removed = [...before].filter((c) => !next.has(c)) if (added.length === 0 && removed.length === 0) { this.logger.info( `Unchanged: rule set ${version} has the ${before.size} dropped classes already.` ) return } for (const r of rows.slice(0, 40)) { this.logger.info( ` ${r.tool.padEnd(10)} ${r.grp.padEnd(32)} ${describeClass(Number(r.klass)).padEnd(26)} ${r.named} of ${r.probed} named` ) } if (this.dryRun) { this.logger.info( `Would publish ${next.size} dropped classes (${added.length} added, ${removed.length} removed).` ) return } const published = await RuleSets.publish( { ...current, droppedClasses: [...next].sort() }, `${next.size} dropped classes from the pending ladder` ) this.logger.info( `Rule set ${published}: ${next.size} dropped classes (${added.length} added, ${removed.length} removed).` ) } }