ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/quality/checks/q08_agent_correctness.ts

checks/q08_agent_correctness.ts

32 líneas, 2.2 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. // QLT-R08. Every live professional agent of the product (layer "Product", type ProductAgent; agents with
  2. // `kind: professional`, or every agent when the schema has no such kind) has a correctness indicator that is not
  3. // retired, has a cadence and has at least one dataset (a dataset whose `indicators` names it). Without the agents
  4. // collection there is nothing to check and the norm holds.
  5. import type { Project, Result } from '../../collections/checks/lib/speclib.ts';
  6. import { main } from '../../collections/checks/lib/runner.ts';
  7. import { addr, fld, has, live, refs } from './lib/qlib.ts';
  8. export const RULE = { id: 'qlt-r08', title: 'A professional agent has a correctness indicator with a dataset and a cadence', scope: 'professional agents of the product' };
  9. export function check(p: Project, res: Result): void {
  10. if (!res.part('product agents', p.need('AGENT'))) return;
  11. const hasKind = JSON.stringify(p.schema('AGENT').kind ?? {}).includes('professional');
  12. const agents = p.records('AGENT').filter((a) => live(p, a, 'AGENT') && (!hasKind || String(a.fm.kind ?? '') === 'professional'));
  13. res.scope = agents.map((a) => addr(a.id));
  14. const fAgent = fld(p, 'IND', 'AGENT', 'agent');
  15. const fDsInd = fld(p, 'DS', 'IND', 'indicators');
  16. const withData = new Set(p.records('DS').filter((d) => p.category(d, 'DS') !== 'dropped').flatMap((d) => refs(p, d, fDsInd, 'IND')));
  17. const inds = p.records('IND').filter((i) => p.category(i, 'IND') !== 'dropped' && String(i.fm.kind ?? '') === 'correctness');
  18. for (const a of agents) {
  19. const mine = inds.filter((i) => refs(p, i, fAgent, 'AGENT').includes(a.id));
  20. if (!mine.length) {
  21. res.hole(addr(a.id), `${p.label(a, 'AGENT')}: no correctness indicator`, 'create an indicator kind: correctness with agent pointing to this agent', 'no-correctness');
  22. continue;
  23. }
  24. if (!mine.some((i) => has(i, 'cadence') && withData.has(i.id)))
  25. res.hole(addr(a.id), `${p.label(a, 'AGENT')}: the correctness indicator has no dataset or cadence (${mine.map((i) => p.label(i, 'IND')).join(', ')})`,
  26. 'write cadence and create a dataset that refers to the indicator', 'no-dataset');
  27. }
  28. }
  29. if (import.meta.main) main({ RULE, check });