包文件→ .shtukbase/packages/decisions/checks/d03_supersedes.ts
checks/d03_supersedes.ts
34 行, 1.6 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- // DEC-R03 (the chain part). A decision is changed by a new one, not rewritten: `supersedes` leads to an existing
- // decision in the phase `replaced`, and every replaced decision is superseded by some decision. Edits of an accepted
- // decision's text are not seen: that needs the history.
- // The shared part is norms-core's (this package requires it), side by side in .shtukbase/packages/.
- import { type Head, address, main, records, status, values } from '../../norms-core/checks/pagelib.ts';
- const FOLDER = 'knowledge/decisions';
- export const RULE = { id: 'dec-r03', title: 'A decision is changed by replacing it: the supersedes chain is intact' };
- export function check(): string[] {
- const decs = new Map<string, Head>();
- for (const [addr, head] of records(FOLDER)) decs.set(addr, head);
- const replacedBy = new Set<string>();
- const out: string[] = [];
- for (const [addr, head] of decs) {
- for (const ref of values(head.supersedes)) {
- let target = address(ref);
- if (!target.includes('/')) target = `${FOLDER}/${target}`;
- const hit = decs.get(target);
- if (hit === undefined) {
- out.push(`${addr}: supersedes points to ${ref}, there is no such decision`);
- continue;
- }
- replacedBy.add(target);
- if (status(hit) !== 'replaced') out.push(`${addr}: replaces ${target}, but that one is in the state "${status(hit) || '—'}", not "replaced"`);
- }
- }
- for (const [addr, head] of decs)
- if (status(head) === 'replaced' && !replacedBy.has(addr)) out.push(`${addr}: the decision is replaced, but no decision refers to it in supersedes`);
- return out;
- }
- if (import.meta.main) main({ RULE, check });