ShtukbaseStandard
package file→ .shtukbase/packages/decisions/checks/d03_supersedes.ts

checks/d03_supersedes.ts

34 lines, 1.6 KB.

  1. // DEC-R03 (the chain part). A decision is changed by a new one, not rewritten: `supersedes` leads to an existing
  2. // decision in the phase `replaced`, and every replaced decision is superseded by some decision. Edits of an accepted
  3. // decision's text are not seen: that needs the history.
  4. // The shared part is norms-core's (this package requires it), side by side in .shtukbase/packages/.
  5. import { type Head, address, main, records, status, values } from '../../norms-core/checks/pagelib.ts';
  6. const FOLDER = 'knowledge/decisions';
  7. export const RULE = { id: 'dec-r03', title: 'A decision is changed by replacing it: the supersedes chain is intact' };
  8. export function check(): string[] {
  9. const decs = new Map<string, Head>();
  10. for (const [addr, head] of records(FOLDER)) decs.set(addr, head);
  11. const replacedBy = new Set<string>();
  12. const out: string[] = [];
  13. for (const [addr, head] of decs) {
  14. for (const ref of values(head.supersedes)) {
  15. let target = address(ref);
  16. if (!target.includes('/')) target = `${FOLDER}/${target}`;
  17. const hit = decs.get(target);
  18. if (hit === undefined) {
  19. out.push(`${addr}: supersedes points to ${ref}, there is no such decision`);
  20. continue;
  21. }
  22. replacedBy.add(target);
  23. if (status(hit) !== 'replaced') out.push(`${addr}: replaces ${target}, but that one is in the state "${status(hit) || '—'}", not "replaced"`);
  24. }
  25. }
  26. for (const [addr, head] of decs)
  27. if (status(head) === 'replaced' && !replacedBy.has(addr)) out.push(`${addr}: the decision is replaced, but no decision refers to it in supersedes`);
  28. return out;
  29. }
  30. if (import.meta.main) main({ RULE, check });