@mark1russell7/canon-ontology 0.0.0-bootstrap.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +38 -1
- package/build/index.d.mts +655 -0
- package/build/index.mjs +2131 -0
- package/build/index.mjs.map +1 -0
- package/build/targets-DkEkvgll.d.mts +194 -0
- package/build/targets-DsUgzuOM.mjs +877 -0
- package/build/targets-DsUgzuOM.mjs.map +1 -0
- package/build/targets.d.mts +2 -0
- package/build/targets.mjs +1 -0
- package/package.json +69 -5
|
@@ -0,0 +1,877 @@
|
|
|
1
|
+
import { arrayOf, booleanOf, isRecord, numberOf, readArray, readText, recordOf, textOf } from "@mark1russell7/optional/read";
|
|
2
|
+
import { countOf, listOf } from "@mark1russell7/text/english";
|
|
3
|
+
import { formatPurl } from "@mark1russell7/package-id";
|
|
4
|
+
import { sorted } from "@mark1russell7/rigor-statistics";
|
|
5
|
+
// src/ids.ts
|
|
6
|
+
/** The folder of the record files, relative to the root of the repository. */
|
|
7
|
+
const ONTOLOGY_FOLDER = "ontology";
|
|
8
|
+
/** The file of the grammar, relative to the root of the repository. */
|
|
9
|
+
const GRAMMAR_FILE = "schema/grammar.json";
|
|
10
|
+
/** The file of the JSON Schema of one record file, relative to the root of the repository. */
|
|
11
|
+
const RECORD_SCHEMA_FILE = "schema/record.schema.json";
|
|
12
|
+
/**
|
|
13
|
+
* This function gives one part of an id from a name. The part is in lower case. A hyphen goes before each upper-case
|
|
14
|
+
* letter that follows a lower-case letter or a digit. One hyphen replaces each run of other characters. For example,
|
|
15
|
+
* `greatCircleKm` gives `great-circle-km`, and `@mark1russell7/text` gives `mark1russell7-text`.
|
|
16
|
+
*/
|
|
17
|
+
function idPart(name) {
|
|
18
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
19
|
+
}
|
|
20
|
+
/** This function gives an id from a kind and the parts of a name. Each part goes through `idPart`. */
|
|
21
|
+
function makeId(kind, ...parts) {
|
|
22
|
+
return [kind, ...parts.map(idPart)].join(".");
|
|
23
|
+
}
|
|
24
|
+
/** This function gives the kind at the start of an id: the text before the first dot. */
|
|
25
|
+
function kindOfId(id) {
|
|
26
|
+
const dot = id.indexOf(".");
|
|
27
|
+
return dot < 0 ? id : id.slice(0, dot);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* This function gives the path of the file of a record, relative to the root of the repository. The path is the folder
|
|
31
|
+
* of its kind, then the rest of the id. For example, `area.statistics` is in `ontology/area/statistics.json`.
|
|
32
|
+
*/
|
|
33
|
+
function pathOfId(id) {
|
|
34
|
+
const kind = kindOfId(id);
|
|
35
|
+
return `${ONTOLOGY_FOLDER}/${kind}/${id.slice(kind.length + 1)}.json`;
|
|
36
|
+
}
|
|
37
|
+
/** This function gives the id of the repository `owner/name`. */
|
|
38
|
+
function repositoryId(owner, name) {
|
|
39
|
+
return makeId("repository", owner, name);
|
|
40
|
+
}
|
|
41
|
+
/** This function gives the id of the npm package `name`. A scoped name gives the scope and the name as two parts. */
|
|
42
|
+
function npmPackageId(name) {
|
|
43
|
+
const scoped = /^@([^/]+)\/(.+)$/.exec(name);
|
|
44
|
+
return scoped === null ? makeId("package", "npm", name) : makeId("package", "npm", scoped[1] ?? "", scoped[2] ?? "");
|
|
45
|
+
}
|
|
46
|
+
/** This function gives the package URL of the npm package `name`, as the purl specification writes it. */
|
|
47
|
+
function npmPurl(name) {
|
|
48
|
+
const scoped = /^(@[^/]+)\/(.+)$/.exec(name);
|
|
49
|
+
const purl = scoped === null ? {
|
|
50
|
+
type: "npm",
|
|
51
|
+
name
|
|
52
|
+
} : {
|
|
53
|
+
type: "npm",
|
|
54
|
+
namespace: scoped[1] ?? "",
|
|
55
|
+
name: scoped[2] ?? ""
|
|
56
|
+
};
|
|
57
|
+
const text = formatPurl(purl);
|
|
58
|
+
if (text === void 0) throw new Error(`The npm name ${name} gives no package URL.`);
|
|
59
|
+
return text;
|
|
60
|
+
}
|
|
61
|
+
// src/grammar.ts
|
|
62
|
+
/** This function gives the kind with the name `name`, or undefined. */
|
|
63
|
+
function kindOf(grammar, name) {
|
|
64
|
+
return grammar.kinds.find((kind) => kind.name === name);
|
|
65
|
+
}
|
|
66
|
+
/** This function gives the relation kind with the name `name`, or undefined. */
|
|
67
|
+
function relationOf(grammar, name) {
|
|
68
|
+
return grammar.relations.find((relation) => relation.name === name);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* This function gives the kind `name` and each ancestor kind, the nearest first. A loop of parents ends the list at the
|
|
72
|
+
* first kind that comes again. A kind that the grammar does not have gives an empty list.
|
|
73
|
+
*/
|
|
74
|
+
function lineageOf(grammar, name) {
|
|
75
|
+
const lineage = [];
|
|
76
|
+
let kind = kindOf(grammar, name);
|
|
77
|
+
while (kind !== void 0 && !lineage.includes(kind.name)) {
|
|
78
|
+
lineage.push(kind.name);
|
|
79
|
+
kind = kind.parent === null ? void 0 : kindOf(grammar, kind.parent);
|
|
80
|
+
}
|
|
81
|
+
return lineage;
|
|
82
|
+
}
|
|
83
|
+
/** This function tells if a record of the kind `name` is also a record of one of the kinds `allowed`. */
|
|
84
|
+
function isKindIn(grammar, name, allowed) {
|
|
85
|
+
return lineageOf(grammar, name).some((kind) => allowed.includes(kind));
|
|
86
|
+
}
|
|
87
|
+
/** This function gives each relation of the ontology with its two ends, in the order of the record files. */
|
|
88
|
+
function edgesOf(ontology) {
|
|
89
|
+
return ontology.records.flatMap(({ record }) => (record.edges ?? []).map((edge) => ({
|
|
90
|
+
from: record.id,
|
|
91
|
+
type: edge.type,
|
|
92
|
+
to: edge.to,
|
|
93
|
+
qualifiers: edge.qualifiers ?? {},
|
|
94
|
+
envelope: edge.envelope ?? {}
|
|
95
|
+
})));
|
|
96
|
+
}
|
|
97
|
+
/** This function tells if a relation or a record is live: no other record supersedes it, and nobody retired it. */
|
|
98
|
+
function isLive(item) {
|
|
99
|
+
return item.envelope?.superseded_by === void 0 && item.envelope?.retired_from === void 0;
|
|
100
|
+
}
|
|
101
|
+
// src/scope.ts
|
|
102
|
+
/** The largest modulus of a scope. A scope lists its residues, so a larger modulus gives a record that is too long. */
|
|
103
|
+
const SCOPE_MODULUS_LIMIT = 1e6;
|
|
104
|
+
const INTEGER = /^-?(0|[1-9][0-9]*)$/;
|
|
105
|
+
const VARIABLE = /^[a-z][a-z0-9]*$/;
|
|
106
|
+
function readBound(value, name) {
|
|
107
|
+
return typeof value === "string" && INTEGER.test(value) ? BigInt(value) : `The field ${name} of the scope is not an integer as a decimal text.`;
|
|
108
|
+
}
|
|
109
|
+
function readResidues(value, name, modulus) {
|
|
110
|
+
if (!Array.isArray(value) || value.length === 0) return `The field ${name} of the scope is not a list of residues.`;
|
|
111
|
+
const seen = /* @__PURE__ */ new Set();
|
|
112
|
+
for (const residue of value) {
|
|
113
|
+
if (!Number.isSafeInteger(residue) || residue < 0 || residue >= modulus) return `The field ${name} of the scope has ${JSON.stringify(residue)}, which is not a residue from 0 to ${String(modulus - 1)}.`;
|
|
114
|
+
if (seen.has(residue)) return `The field ${name} of the scope has ${String(residue)} two times.`;
|
|
115
|
+
seen.add(residue);
|
|
116
|
+
}
|
|
117
|
+
return sorted([...seen]);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* This function reads the JSON form of a scope. The form has `variable`, `from` and optionally `to`, with the bounds as
|
|
121
|
+
* decimal texts. It can also have `modulus` with one of `residues` and `except`. The function gives the scope, or the
|
|
122
|
+
* text of the problem.
|
|
123
|
+
*/
|
|
124
|
+
function readScope(value) {
|
|
125
|
+
if (!isRecord(value)) return "The scope is not an object.";
|
|
126
|
+
const variable = value["variable"];
|
|
127
|
+
if (typeof variable !== "string" || !VARIABLE.test(variable)) return "The field variable of the scope is not a name.";
|
|
128
|
+
const from = readBound(value["from"], "from");
|
|
129
|
+
if (typeof from === "string") return from;
|
|
130
|
+
const to = value["to"] === void 0 ? void 0 : readBound(value["to"], "to");
|
|
131
|
+
if (typeof to === "string") return to;
|
|
132
|
+
if (to !== void 0 && to < from) return "The field to of the scope is less than the field from.";
|
|
133
|
+
const modulusValue = value["modulus"];
|
|
134
|
+
if (modulusValue === void 0) {
|
|
135
|
+
if (value["residues"] !== void 0 || value["except"] !== void 0) return "The scope has residues but no modulus.";
|
|
136
|
+
return {
|
|
137
|
+
variable,
|
|
138
|
+
from,
|
|
139
|
+
to,
|
|
140
|
+
modulus: 1,
|
|
141
|
+
residues: [0]
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
if (!Number.isSafeInteger(modulusValue) || modulusValue < 1 || modulusValue > 1e6) return `The field modulus of the scope is not an integer from 1 to ${String(SCOPE_MODULUS_LIMIT)}.`;
|
|
145
|
+
const modulus = modulusValue;
|
|
146
|
+
if (value["residues"] === void 0 === (value["except"] === void 0)) return "The scope with a modulus has one of residues and except.";
|
|
147
|
+
if (value["residues"] !== void 0) {
|
|
148
|
+
const residues = readResidues(value["residues"], "residues", modulus);
|
|
149
|
+
return typeof residues === "string" ? residues : {
|
|
150
|
+
variable,
|
|
151
|
+
from,
|
|
152
|
+
to,
|
|
153
|
+
modulus,
|
|
154
|
+
residues
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const except = readResidues(value["except"], "except", modulus);
|
|
158
|
+
if (typeof except === "string") return except;
|
|
159
|
+
const out = new Set(except);
|
|
160
|
+
const residues = Array.from({ length: modulus }, (_, r) => r).filter((r) => !out.has(r));
|
|
161
|
+
return residues.length === 0 ? "The field except of the scope has each residue, so the scope is empty." : {
|
|
162
|
+
variable,
|
|
163
|
+
from,
|
|
164
|
+
to,
|
|
165
|
+
modulus,
|
|
166
|
+
residues
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function residueOf(value, modulus) {
|
|
170
|
+
const m = BigInt(modulus);
|
|
171
|
+
return Number((value % m + m) % m);
|
|
172
|
+
}
|
|
173
|
+
/** This function gives the least modulus d of the classes: the residues modulo the modulus repeat with the period d. */
|
|
174
|
+
function leastPeriod(modulus, residues) {
|
|
175
|
+
for (let d = 1; d < modulus; d++) {
|
|
176
|
+
if (modulus % d !== 0) continue;
|
|
177
|
+
if ([...residues].every((r) => residues.has((r + d) % modulus))) return d;
|
|
178
|
+
}
|
|
179
|
+
return modulus;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* This function gives the canonical form of a scope, or `undefined` for an empty scope. The canonical form has the
|
|
183
|
+
* least modulus of its classes. Its `from` and `to` are values of the set.
|
|
184
|
+
*/
|
|
185
|
+
function canonicalScope(scope) {
|
|
186
|
+
const all = new Set(scope.residues.map((r) => (r % scope.modulus + scope.modulus) % scope.modulus));
|
|
187
|
+
if (all.size === 0) return void 0;
|
|
188
|
+
const modulus = leastPeriod(scope.modulus, all);
|
|
189
|
+
const residues = sorted([...new Set([...all].map((r) => r % modulus))]);
|
|
190
|
+
const set = new Set(residues);
|
|
191
|
+
let step = 0;
|
|
192
|
+
while (!set.has((residueOf(scope.from, modulus) + step) % modulus)) step++;
|
|
193
|
+
const from = scope.from + BigInt(step);
|
|
194
|
+
let to;
|
|
195
|
+
if (scope.to !== void 0) {
|
|
196
|
+
step = 0;
|
|
197
|
+
while (!set.has((residueOf(scope.to, modulus) - step + modulus) % modulus)) step++;
|
|
198
|
+
to = scope.to - BigInt(step);
|
|
199
|
+
if (to < from) return void 0;
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
variable: scope.variable,
|
|
203
|
+
from,
|
|
204
|
+
to,
|
|
205
|
+
modulus,
|
|
206
|
+
residues
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* This function tells if two scopes have the same canonical form. Two equal unbounded sets have the same form. Two
|
|
211
|
+
* equal bounded sets can have different classes, and then the function gives `false`. So a claim of a short range
|
|
212
|
+
* keeps its target open, and a wrong `true` cannot close a target.
|
|
213
|
+
*/
|
|
214
|
+
function sameScope(a, b) {
|
|
215
|
+
const x = canonicalScope(a);
|
|
216
|
+
const y = canonicalScope(b);
|
|
217
|
+
if (x === void 0 || y === void 0) return false;
|
|
218
|
+
return x.variable === y.variable && x.from === y.from && x.to === y.to && x.modulus === y.modulus && x.residues.length === y.residues.length && x.residues.every((r, i) => r === y.residues[i]);
|
|
219
|
+
}
|
|
220
|
+
/** This function tells if a value is in a scope. */
|
|
221
|
+
function inScope(scope, value) {
|
|
222
|
+
return value >= scope.from && (scope.to === void 0 || value <= scope.to) && scope.residues.includes(residueOf(value, scope.modulus));
|
|
223
|
+
}
|
|
224
|
+
/** The most residues that the text of a scope shows. */
|
|
225
|
+
const SHOWN_RESIDUES = 8;
|
|
226
|
+
function residueText(residues) {
|
|
227
|
+
const shown = residues.slice(0, SHOWN_RESIDUES).join(", ");
|
|
228
|
+
return residues.length > SHOWN_RESIDUES ? `{${shown} and ${String(residues.length - SHOWN_RESIDUES)} more}` : `{${shown}}`;
|
|
229
|
+
}
|
|
230
|
+
/** This function gives the scope in words, for example `n ≥ 3, n mod 840 not in {1, 121}`. */
|
|
231
|
+
function scopeText(scope) {
|
|
232
|
+
const v = scope.variable;
|
|
233
|
+
const range = scope.to === void 0 ? `${v} ≥ ${String(scope.from)}` : `${String(scope.from)} ≤ ${v} ≤ ${String(scope.to)}`;
|
|
234
|
+
if (scope.modulus === 1) return range;
|
|
235
|
+
const has = new Set(scope.residues);
|
|
236
|
+
const missing = Array.from({ length: scope.modulus }, (_, r) => r).filter((r) => !has.has(r));
|
|
237
|
+
return missing.length < scope.residues.length ? `${range}, ${v} mod ${String(scope.modulus)} not in ${residueText(missing)}` : `${range}, ${v} mod ${String(scope.modulus)} in ${residueText(scope.residues)}`;
|
|
238
|
+
}
|
|
239
|
+
// src/results.ts
|
|
240
|
+
/** The problem statuses that are claims. The status `open` claims nothing. */
|
|
241
|
+
const CLAIM_STATUSES = ["solved", "disproved"];
|
|
242
|
+
/** This function gives the scope of a record, or `undefined` when the record has no valid scope. */
|
|
243
|
+
function scopeOf(record) {
|
|
244
|
+
const value = record?.attrs["scope"];
|
|
245
|
+
if (value === void 0) return void 0;
|
|
246
|
+
const scope = readScope(value);
|
|
247
|
+
return typeof scope === "string" ? void 0 : scope;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* This function tells if a result has the full scope of a problem. A problem or a result with no valid scope gives
|
|
251
|
+
* `false`, so such a result cannot close a problem.
|
|
252
|
+
*/
|
|
253
|
+
function hasFullScope(result, problem) {
|
|
254
|
+
const a = scopeOf(result);
|
|
255
|
+
const b = scopeOf(problem);
|
|
256
|
+
return a !== void 0 && b !== void 0 && sameScope(a, b);
|
|
257
|
+
}
|
|
258
|
+
function liveRecords(ontology, kind) {
|
|
259
|
+
return ontology.records.map(({ record }) => record).filter((record) => record.kind === kind && isLive(record));
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* This function gives each claim that needs a result record, with its state. A status claim needs a result about its
|
|
263
|
+
* problem. A `solves` claim needs a result about its function and about its problem. The problem id orders the list.
|
|
264
|
+
* A function can solve a part of a problem, so a partial `solves` claim is true. A partial status claim is not.
|
|
265
|
+
*/
|
|
266
|
+
function resultClaimsOf(ontology) {
|
|
267
|
+
const edges = edgesOf(ontology).filter(isLive);
|
|
268
|
+
const results = new Set(liveRecords(ontology, "result").map((record) => record.id));
|
|
269
|
+
const about = /* @__PURE__ */ new Map();
|
|
270
|
+
for (const edge of edges) {
|
|
271
|
+
if (edge.type !== "about" || !results.has(edge.from)) continue;
|
|
272
|
+
const set = about.get(edge.from) ?? /* @__PURE__ */ new Set();
|
|
273
|
+
set.add(edge.to);
|
|
274
|
+
about.set(edge.from, set);
|
|
275
|
+
}
|
|
276
|
+
const byId = new Map(ontology.records.map(({ record }) => [record.id, record]));
|
|
277
|
+
const resultsAbout = (...ids) => [...about].filter(([, targets]) => ids.every((id) => targets.has(id))).map(([id]) => id).sort();
|
|
278
|
+
const fullOf = (problem, found) => found.filter((id) => hasFullScope(byId.get(id), byId.get(problem)));
|
|
279
|
+
const stateOf = (found, full) => full.length > 0 ? "checked" : found.length > 0 ? "partial" : "not checked";
|
|
280
|
+
const claims = [];
|
|
281
|
+
for (const problem of liveRecords(ontology, "problem")) {
|
|
282
|
+
const status = problem.attrs["status"];
|
|
283
|
+
if (typeof status !== "string" || !CLAIM_STATUSES.includes(status)) continue;
|
|
284
|
+
const found = resultsAbout(problem.id);
|
|
285
|
+
const full = fullOf(problem.id, found);
|
|
286
|
+
claims.push({
|
|
287
|
+
kind: "status",
|
|
288
|
+
problem: problem.id,
|
|
289
|
+
status,
|
|
290
|
+
state: stateOf(found, full),
|
|
291
|
+
results: found,
|
|
292
|
+
full
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
const functions = new Set(liveRecords(ontology, "function").map((record) => record.id));
|
|
296
|
+
for (const edge of edges) {
|
|
297
|
+
if (edge.type !== "solves" || !functions.has(edge.from)) continue;
|
|
298
|
+
const found = resultsAbout(edge.from, edge.to);
|
|
299
|
+
const full = fullOf(edge.to, found);
|
|
300
|
+
claims.push({
|
|
301
|
+
kind: "solves",
|
|
302
|
+
problem: edge.to,
|
|
303
|
+
function: edge.from,
|
|
304
|
+
state: stateOf(found, full),
|
|
305
|
+
results: found,
|
|
306
|
+
full
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
return claims.sort((a, b) => a.problem.localeCompare(b.problem) || a.kind.localeCompare(b.kind) || (a.function ?? "").localeCompare(b.function ?? ""));
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* This function tells if a claim fails the rule of the results. A claim with no result fails. A status claim fails
|
|
313
|
+
* also when none of its results has the scope of the problem: a partial result cannot close a problem.
|
|
314
|
+
*/
|
|
315
|
+
function claimFails(claim) {
|
|
316
|
+
return claim.state === "not checked" || claim.kind === "status" && claim.state === "partial";
|
|
317
|
+
}
|
|
318
|
+
// src/targets.ts
|
|
319
|
+
/** The sizes, the smallest first. */
|
|
320
|
+
const SIZES = [
|
|
321
|
+
"XS",
|
|
322
|
+
"S",
|
|
323
|
+
"M",
|
|
324
|
+
"L",
|
|
325
|
+
"XL"
|
|
326
|
+
];
|
|
327
|
+
/** The repository of the ontology. A target that adds records to the ontology goes to it. */
|
|
328
|
+
const ONTOLOGY_REPOSITORY = "metrograph-labs/canon";
|
|
329
|
+
/** The npm package that has the map of homes. A target that changes the map goes to its repository. */
|
|
330
|
+
const MAP_PACKAGE = "@mark1russell7/conventions";
|
|
331
|
+
/** The indexes of the ontology that the rules read. */
|
|
332
|
+
var Graph = class {
|
|
333
|
+
byId;
|
|
334
|
+
edges;
|
|
335
|
+
constructor(ontology) {
|
|
336
|
+
this.byId = new Map(ontology.records.map(({ record }) => [record.id, record]));
|
|
337
|
+
this.edges = edgesOf(ontology).filter((edge) => isLive(edge) && kindOfId(edge.from) !== "target");
|
|
338
|
+
}
|
|
339
|
+
/** This function gives the live relations of the type `type` that start at `from`. */
|
|
340
|
+
out(from, type) {
|
|
341
|
+
return this.edges.filter((edge) => edge.from === from && edge.type === type);
|
|
342
|
+
}
|
|
343
|
+
/** This function gives the live relations of the type `type` that end at `to`. */
|
|
344
|
+
in(to, type) {
|
|
345
|
+
return this.edges.filter((edge) => edge.to === to && edge.type === type);
|
|
346
|
+
}
|
|
347
|
+
/** This function gives each live relation of the type `type`. */
|
|
348
|
+
all(type) {
|
|
349
|
+
return this.edges.filter((edge) => edge.type === type);
|
|
350
|
+
}
|
|
351
|
+
/** This function gives the text attribute `name` of the record `id`, or an empty text. */
|
|
352
|
+
text(id, name) {
|
|
353
|
+
const value = this.byId.get(id)?.attrs[name];
|
|
354
|
+
return typeof value === "string" ? value : "";
|
|
355
|
+
}
|
|
356
|
+
/** This function gives the repository of a record: the record itself, or the end of its chain of part-of relations. */
|
|
357
|
+
repositoryOf(id) {
|
|
358
|
+
let current = id;
|
|
359
|
+
for (let step = 0; step < 8 && current !== void 0; step += 1) {
|
|
360
|
+
if (kindOfId(current) === "repository") return current;
|
|
361
|
+
current = this.out(current, "part-of")[0]?.to;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/** This function gives the repository as owner/name. */
|
|
365
|
+
slug(repositoryId) {
|
|
366
|
+
return `${this.text(repositoryId, "owner")}/${this.text(repositoryId, "name")}`;
|
|
367
|
+
}
|
|
368
|
+
/** This function gives the home of an area, with the state of the relation home-of. */
|
|
369
|
+
homeOf(areaId) {
|
|
370
|
+
const edge = this.in(areaId, "home-of")[0];
|
|
371
|
+
return edge === void 0 ? void 0 : {
|
|
372
|
+
repository: edge.from,
|
|
373
|
+
state: String(edge.qualifiers["state"] ?? "")
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
/** This function gives the id of a live finding about each record of `about` with the claim `claim` and the result `result`. */
|
|
377
|
+
finding(claim, result, about) {
|
|
378
|
+
for (const [id, record] of this.byId) {
|
|
379
|
+
if (record.kind !== "finding" || record.attrs["claim"] !== claim || record.attrs["result"] !== result || !isLive(record)) continue;
|
|
380
|
+
const ends = new Set(this.out(id, "about").map((edge) => edge.to));
|
|
381
|
+
if (about.every((end) => ends.has(end))) return id;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/** This function gives the name of a record in a title. A package or a function gives its name, an area its title, a repository its slug. */
|
|
385
|
+
label(id) {
|
|
386
|
+
const kind = kindOfId(id);
|
|
387
|
+
if (kind === "repository") return this.slug(id);
|
|
388
|
+
if (kind === "area") return this.text(id, "title");
|
|
389
|
+
return this.text(id, "name") || id;
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
/** This function gives the id of a target from its gap and the id of its subject. */
|
|
393
|
+
function targetId(gap, subject) {
|
|
394
|
+
return `target.${gap}.${subject.slice(kindOfId(subject).length + 1)}`;
|
|
395
|
+
}
|
|
396
|
+
/** This function reads the size and the acceptance of a record, when it has them. */
|
|
397
|
+
function workOf(record) {
|
|
398
|
+
const size = record?.attrs["size"];
|
|
399
|
+
const acceptance = record?.attrs["acceptance"];
|
|
400
|
+
return {
|
|
401
|
+
...typeof size === "string" && SIZES.includes(size) ? { size } : {},
|
|
402
|
+
...acceptance !== void 0 ? { acceptance } : {}
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
/** Rule build-function: each planned function with a place gives a target to build it in that place. */
|
|
406
|
+
function buildFunction(graph) {
|
|
407
|
+
const drafts = [];
|
|
408
|
+
for (const [id, record] of graph.byId) {
|
|
409
|
+
if (record.kind !== "function" || record.attrs["state"] !== "planned") continue;
|
|
410
|
+
const place = graph.out(id, "planned-in")[0]?.to;
|
|
411
|
+
const repository = place === void 0 ? void 0 : graph.repositoryOf(place);
|
|
412
|
+
if (place === void 0 || repository === void 0) continue;
|
|
413
|
+
const { size = "M", acceptance } = workOf(record);
|
|
414
|
+
if (acceptance === void 0) continue;
|
|
415
|
+
const area = graph.out(id, "covers")[0]?.to;
|
|
416
|
+
drafts.push({
|
|
417
|
+
subject: id,
|
|
418
|
+
gap: "build-function",
|
|
419
|
+
title: `Build ${graph.label(id)} in ${graph.label(place)}`,
|
|
420
|
+
home: graph.slug(repository),
|
|
421
|
+
...area !== void 0 ? { area } : {},
|
|
422
|
+
size,
|
|
423
|
+
claimable: graph.byId.get(repository)?.attrs["exists"] === true,
|
|
424
|
+
acceptance,
|
|
425
|
+
why: `${graph.label(id)} is planned in ${graph.label(place)}: ${graph.text(id, "summary")}`
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
return drafts;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Rule move-copy: each package or function that holds a copy of the code of an area gives a target. The target moves the
|
|
432
|
+
* copy to the home of the area. A copy that depends on a planned function comes after the target of that function. A
|
|
433
|
+
* copy of an area with a planned home comes after the first package of that home.
|
|
434
|
+
*
|
|
435
|
+
* Rule correct-map: a finding that refutes the claim of the map of homes that a repository holds a copy gives a target.
|
|
436
|
+
* The target removes the claim from the map. Rule find-copy gives no target for that claim.
|
|
437
|
+
*/
|
|
438
|
+
function moveCopy(graph) {
|
|
439
|
+
const drafts = [];
|
|
440
|
+
const mapRepository = graph.repositoryOf(npmPackageId(MAP_PACKAGE));
|
|
441
|
+
const copies = graph.all("holds-copy");
|
|
442
|
+
const finer = codePairs(graph);
|
|
443
|
+
for (const edge of copies) {
|
|
444
|
+
const repository = graph.repositoryOf(edge.from);
|
|
445
|
+
const home = graph.homeOf(edge.to);
|
|
446
|
+
if (repository === void 0 || home === void 0) continue;
|
|
447
|
+
if (kindOfId(edge.from) === "repository" && finer.has(`${repository} ${edge.to}`)) continue;
|
|
448
|
+
const after = [...graph.out(edge.from, "depends-on").filter((dependency) => graph.byId.get(dependency.to)?.attrs["state"] === "planned").map((dependency) => targetId("build-function", dependency.to)), ...home.state === "planned" ? [targetId("first-package", edge.to)] : []];
|
|
449
|
+
const ready = home.state === "published" || home.state === "unpublished";
|
|
450
|
+
const area = graph.label(edge.to);
|
|
451
|
+
const copy = graph.label(edge.from);
|
|
452
|
+
const homeSlug = graph.slug(home.repository);
|
|
453
|
+
const areaName = edge.to.slice(5);
|
|
454
|
+
const refuted = kindOfId(edge.from) === "repository" ? graph.finding("holds-copy", "refuted", [edge.from, edge.to]) : void 0;
|
|
455
|
+
if (refuted !== void 0) {
|
|
456
|
+
drafts.push({
|
|
457
|
+
subject: `${edge.from}.${areaName}`,
|
|
458
|
+
about: [edge.from, edge.to],
|
|
459
|
+
gap: "correct-map",
|
|
460
|
+
title: `Remove ${copy} from the map of homes for ${area}`,
|
|
461
|
+
home: mapRepository === void 0 ? ONTOLOGY_REPOSITORY : graph.slug(mapRepository),
|
|
462
|
+
area: edge.to,
|
|
463
|
+
size: "XS",
|
|
464
|
+
claimable: false,
|
|
465
|
+
acceptance: {
|
|
466
|
+
text: `The map of homes no longer names ${copy} for ${area}.`,
|
|
467
|
+
checks: [`The next import of the map gives no relation holds-copy from ${edge.from} to ${edge.to}.`, "`pnpm canon targets --check` passes."]
|
|
468
|
+
},
|
|
469
|
+
why: `The finding ${refuted} refutes the claim of the map that ${copy} holds a copy of the code of ${area}. Only the maintainer changes the map.`
|
|
470
|
+
});
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
if (kindOfId(edge.from) === "repository") continue;
|
|
474
|
+
const { size = "M", acceptance } = workOf(graph.byId.get(edge.from));
|
|
475
|
+
drafts.push({
|
|
476
|
+
subject: edge.from,
|
|
477
|
+
gap: "move-copy",
|
|
478
|
+
title: `Replace ${copy} in ${graph.slug(repository)} with the code of the home of ${area}`,
|
|
479
|
+
home: graph.slug(repository),
|
|
480
|
+
area: edge.to,
|
|
481
|
+
size,
|
|
482
|
+
claimable: ready && after.length === 0,
|
|
483
|
+
acceptance: acceptance ?? {
|
|
484
|
+
text: `${graph.slug(repository)} keeps no copy of the code of ${area}. It uses the home ${homeSlug}.`,
|
|
485
|
+
checks: [`The map of homes names ${graph.slug(repository)} in no alsoIn entry of the area ${edge.to.slice(5)}.`, `\`conventions check\` passes in ${graph.slug(repository)}: the rule home-package finds no copy of the area.`]
|
|
486
|
+
},
|
|
487
|
+
why: `${copy} holds code of ${area}, and the home of ${area} is ${homeSlug}${ready ? "" : ` (state ${home.state})`}.`,
|
|
488
|
+
...after.length > 0 ? { after } : {}
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
return drafts;
|
|
492
|
+
}
|
|
493
|
+
/** This function gives each pair "<repository> <area>" where a record of a package or a function holds a copy of the code of the area. */
|
|
494
|
+
function codePairs(graph) {
|
|
495
|
+
const finer = graph.all("holds-copy").filter((edge) => kindOfId(edge.from) !== "repository");
|
|
496
|
+
return new Set(finer.map((edge) => `${graph.repositoryOf(edge.from) ?? ""} ${edge.to}`));
|
|
497
|
+
}
|
|
498
|
+
/** This function reads the places of a record of kind candidate. It drops a place with a bad field. */
|
|
499
|
+
function placesOf(record) {
|
|
500
|
+
return readArray(record?.attrs["places"], (value) => {
|
|
501
|
+
const file = textOf(value, "file");
|
|
502
|
+
const line = numberOf(value, "line");
|
|
503
|
+
const name = textOf(value, "name");
|
|
504
|
+
return file === void 0 || line === void 0 || name === void 0 ? void 0 : {
|
|
505
|
+
file,
|
|
506
|
+
line,
|
|
507
|
+
name
|
|
508
|
+
};
|
|
509
|
+
}) ?? [];
|
|
510
|
+
}
|
|
511
|
+
/** The most places that the acceptance of a find-copy target names. The text tells the number of the others. */
|
|
512
|
+
const PLACES_SHOWN = 5;
|
|
513
|
+
/** This function gives the size of a find-copy target from the number of places: 1 is XS, 2 to 5 is S, more is M. */
|
|
514
|
+
function findSize(places) {
|
|
515
|
+
return places === 1 ? "XS" : places <= 5 ? "S" : "M";
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Rule find-copy: a repository and an area give a target when a claim tells of a copy and no record names its code.
|
|
519
|
+
* The target reads the code. It adds each copy to the ontology, or a finding that refutes the claim.
|
|
520
|
+
*
|
|
521
|
+
* - A claim is a relation holds-copy of the map of homes, or a record of kind candidate of the duplication atlas. The two
|
|
522
|
+
* claims of one pair give one target.
|
|
523
|
+
* - A pair with a package or a function of the repository for the area gives no target. Rule move-copy has it.
|
|
524
|
+
* - A refuted finding about the pair gives no target. For a claim of the map, rule correct-map has it.
|
|
525
|
+
* - The size comes from the number of places of the candidate. A claim of the map with no candidate has the size S.
|
|
526
|
+
*/
|
|
527
|
+
function findCopy(graph) {
|
|
528
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
529
|
+
for (const edge of graph.all("holds-copy")) if (kindOfId(edge.from) === "repository") pairs.set(`${edge.from} ${edge.to}`, {
|
|
530
|
+
repository: edge.from,
|
|
531
|
+
area: edge.to,
|
|
532
|
+
map: true
|
|
533
|
+
});
|
|
534
|
+
for (const record of graph.byId.values()) {
|
|
535
|
+
if (record.kind !== "candidate" || !isLive(record)) continue;
|
|
536
|
+
const ends = graph.out(record.id, "about").map((edge) => edge.to);
|
|
537
|
+
const repository = ends.find((id) => kindOfId(id) === "repository");
|
|
538
|
+
const area = ends.find((id) => kindOfId(id) === "area");
|
|
539
|
+
if (repository === void 0 || area === void 0) continue;
|
|
540
|
+
const key = `${repository} ${area}`;
|
|
541
|
+
pairs.set(key, {
|
|
542
|
+
repository,
|
|
543
|
+
area,
|
|
544
|
+
map: pairs.get(key)?.map === true,
|
|
545
|
+
candidate: record
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
const finer = codePairs(graph);
|
|
549
|
+
const drafts = [];
|
|
550
|
+
for (const [key, { repository, area: areaId, map, candidate }] of pairs) {
|
|
551
|
+
const home = graph.homeOf(areaId);
|
|
552
|
+
if (home === void 0 || home.repository === repository || finer.has(key)) continue;
|
|
553
|
+
if (graph.finding("holds-copy", "refuted", [repository, areaId]) !== void 0) continue;
|
|
554
|
+
const area = graph.label(areaId);
|
|
555
|
+
const copy = graph.label(repository);
|
|
556
|
+
const places = placesOf(candidate);
|
|
557
|
+
const commit = typeof candidate?.attrs["commit"] === "string" ? candidate.attrs["commit"] : "";
|
|
558
|
+
const shown = places.slice(0, 5).map((place) => `\`${place.file}:${String(place.line)}\` ${place.name}`);
|
|
559
|
+
const more = places.length > 5 ? [countOf(places.length - 5, "more place")] : [];
|
|
560
|
+
const found = `duplication atlas finds ${countOf(places.length, "function")} with the names of ${area} in ${copy} at the commit ${commit.slice(0, 12)}`;
|
|
561
|
+
drafts.push({
|
|
562
|
+
subject: `${repository}.${areaId.slice(5)}`,
|
|
563
|
+
about: [repository, areaId],
|
|
564
|
+
gap: "find-copy",
|
|
565
|
+
title: `Find the code of ${area} in ${copy}`,
|
|
566
|
+
home: ONTOLOGY_REPOSITORY,
|
|
567
|
+
area: areaId,
|
|
568
|
+
size: candidate === void 0 ? "S" : findSize(places.length),
|
|
569
|
+
claimable: home.state === "published" || home.state === "unpublished",
|
|
570
|
+
acceptance: {
|
|
571
|
+
text: `Each copy of the code of ${area} in ${copy} is a record of canon, or a finding with its evidence shows that there is no copy.`,
|
|
572
|
+
checks: [
|
|
573
|
+
`Each new record of kind function has the relations holds-copy to ${areaId} and part-of to ${repository}, a size and an acceptance.`,
|
|
574
|
+
"Each new record names the files of the copy on the main branch of the repository.",
|
|
575
|
+
...candidate === void 0 ? [] : [`The read examines each place of ${candidate.id}: ${listOf([...shown, ...more])}.`],
|
|
576
|
+
`With no copy, a record of kind finding has the claim holds-copy, the result refuted, and the relations about to ${repository} and ${areaId}.`,
|
|
577
|
+
"`pnpm canon check` and `pnpm canon targets --check` pass."
|
|
578
|
+
]
|
|
579
|
+
},
|
|
580
|
+
why: candidate === void 0 ? `The map of homes names ${copy} for ${area}, but no record names the code of the copy.` : map ? `The map of homes names ${copy} for ${area}, and the ${found}. No record names the code of the copy.` : `The ${found}. A match of names is not a proof of a copy, so an agent reads the code.`
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
return drafts;
|
|
584
|
+
}
|
|
585
|
+
/** A text that ends with this pattern ends a sentence, so the next sentence needs no full stop before it. */
|
|
586
|
+
const STOP = /[.!?]$/;
|
|
587
|
+
/** Rule first-release: each package that is in its repository but not in the registry gives a target to release it. */
|
|
588
|
+
function firstRelease(graph) {
|
|
589
|
+
const drafts = [];
|
|
590
|
+
for (const [id, record] of graph.byId) {
|
|
591
|
+
if (record.kind !== "package" || record.attrs["state"] !== "unpublished") continue;
|
|
592
|
+
const repository = graph.repositoryOf(id);
|
|
593
|
+
if (repository === void 0) continue;
|
|
594
|
+
const name = graph.label(id);
|
|
595
|
+
const area = graph.out(id, "covers")[0]?.to;
|
|
596
|
+
drafts.push({
|
|
597
|
+
subject: id,
|
|
598
|
+
gap: "first-release",
|
|
599
|
+
title: `Release ${name} to npm`,
|
|
600
|
+
home: graph.slug(repository),
|
|
601
|
+
...area !== void 0 ? { area } : {},
|
|
602
|
+
size: "XS",
|
|
603
|
+
claimable: false,
|
|
604
|
+
acceptance: {
|
|
605
|
+
text: `npm has the package ${name}.`,
|
|
606
|
+
checks: [`\`npm view ${name} version\` gives a version.`, "The next import of the map gives the state published."]
|
|
607
|
+
},
|
|
608
|
+
why: `${name} is in ${graph.slug(repository)}, but npm does not have it. Only the maintainer releases a new package.`
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
return drafts;
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Rule first-package: each planned home in a repository that exists, with no package that covers the area, gives a target
|
|
615
|
+
* to make the first package. Rule make-repository: each home in a repository that does not exist gives a target to make it.
|
|
616
|
+
*/
|
|
617
|
+
function firstPackageAndRepository(graph) {
|
|
618
|
+
const drafts = [];
|
|
619
|
+
for (const edge of graph.all("home-of")) {
|
|
620
|
+
const repository = graph.byId.get(edge.from);
|
|
621
|
+
const area = graph.label(edge.to);
|
|
622
|
+
const slug = graph.slug(edge.from);
|
|
623
|
+
if (repository?.attrs["exists"] === false) drafts.push({
|
|
624
|
+
subject: edge.from,
|
|
625
|
+
gap: "make-repository",
|
|
626
|
+
title: `Make the repository ${slug} for ${area}`,
|
|
627
|
+
home: slug,
|
|
628
|
+
area: edge.to,
|
|
629
|
+
size: "S",
|
|
630
|
+
claimable: false,
|
|
631
|
+
acceptance: {
|
|
632
|
+
text: `The public repository ${slug} exists.`,
|
|
633
|
+
checks: ["The next import of the map gives `exists: true` for the repository."]
|
|
634
|
+
},
|
|
635
|
+
why: `${slug} is the home of ${area}, but it does not exist. Only the maintainer makes a repository.`
|
|
636
|
+
});
|
|
637
|
+
else if (edge.qualifiers["state"] === "planned" && graph.in(edge.to, "covers").every((cover) => graph.byId.get(cover.from)?.attrs["state"] === "planned")) drafts.push({
|
|
638
|
+
subject: edge.to,
|
|
639
|
+
gap: "first-package",
|
|
640
|
+
title: `Make the first package of ${area} in ${slug}`,
|
|
641
|
+
home: slug,
|
|
642
|
+
area: edge.to,
|
|
643
|
+
size: "M",
|
|
644
|
+
claimable: false,
|
|
645
|
+
acceptance: {
|
|
646
|
+
text: `${slug} has a package for ${area}.`,
|
|
647
|
+
checks: ["The next import of the map gives a package that covers the area."]
|
|
648
|
+
},
|
|
649
|
+
why: `${slug} is the planned home of ${area}, and no package covers it. A new package needs the maintainer.`
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
return drafts;
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Rule find-home: each area with no home gives a target to choose its home in the map of homes. Only the maintainer
|
|
656
|
+
* chooses a home.
|
|
657
|
+
*/
|
|
658
|
+
function findHome(graph) {
|
|
659
|
+
const drafts = [];
|
|
660
|
+
const mapRepository = graph.repositoryOf(npmPackageId(MAP_PACKAGE));
|
|
661
|
+
for (const [id, record] of graph.byId) {
|
|
662
|
+
if (record.kind !== "area" || graph.in(id, "home-of").length > 0) continue;
|
|
663
|
+
const area = graph.label(id);
|
|
664
|
+
drafts.push({
|
|
665
|
+
subject: id,
|
|
666
|
+
gap: "find-home",
|
|
667
|
+
title: `Choose a home for ${area}`,
|
|
668
|
+
home: mapRepository === void 0 ? ONTOLOGY_REPOSITORY : graph.slug(mapRepository),
|
|
669
|
+
area: id,
|
|
670
|
+
size: "S",
|
|
671
|
+
claimable: false,
|
|
672
|
+
acceptance: {
|
|
673
|
+
text: `The map of homes has a row for ${area}, with its home repository and its packages.`,
|
|
674
|
+
checks: ["The next import of the map gives the relation home-of to the area.", "`pnpm canon check` passes."]
|
|
675
|
+
},
|
|
676
|
+
why: `${area} has no home. Only the maintainer chooses a home.`
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
return drafts;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Rule compute-problem: each open problem with a computation gives a target to build the computation in the home of an
|
|
683
|
+
* area that it needs. It comes after the targets that give a home to each area it needs, and that build each planned
|
|
684
|
+
* function it needs.
|
|
685
|
+
*/
|
|
686
|
+
function computeProblem(graph) {
|
|
687
|
+
const drafts = [];
|
|
688
|
+
for (const [id, record] of graph.byId) {
|
|
689
|
+
if (record.kind !== "problem" || record.attrs["status"] !== "open" || graph.text(id, "computation") === "") continue;
|
|
690
|
+
const needs = graph.out(id, "needs").map((edge) => edge.to);
|
|
691
|
+
const after = [];
|
|
692
|
+
let place;
|
|
693
|
+
let live = true;
|
|
694
|
+
for (const need of needs) if (kindOfId(need) === "area") {
|
|
695
|
+
const home = graph.homeOf(need);
|
|
696
|
+
if (home === void 0) {
|
|
697
|
+
after.push(targetId("find-home", need));
|
|
698
|
+
live = false;
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
place ??= home;
|
|
702
|
+
if (home.state !== "published" && home.state !== "unpublished") {
|
|
703
|
+
live = false;
|
|
704
|
+
if (home.state === "planned") after.push(targetId("first-package", need));
|
|
705
|
+
}
|
|
706
|
+
} else if (graph.byId.get(need)?.attrs["state"] === "planned") after.push(targetId("build-function", need));
|
|
707
|
+
const ready = place !== void 0 && live;
|
|
708
|
+
const partial = graph.in(id, "about").map((edge) => edge.from).filter((from) => {
|
|
709
|
+
const result = graph.byId.get(from);
|
|
710
|
+
return result?.kind === "result" && isLive(result) && !hasFullScope(result, record);
|
|
711
|
+
}).sort();
|
|
712
|
+
const title = graph.text(id, "title");
|
|
713
|
+
const certificate = graph.text(id, "certificate") || "witness";
|
|
714
|
+
const { size = "M", acceptance } = workOf(record);
|
|
715
|
+
drafts.push({
|
|
716
|
+
subject: id,
|
|
717
|
+
gap: "compute-problem",
|
|
718
|
+
title: `Compute ${title}`,
|
|
719
|
+
home: place === void 0 ? ONTOLOGY_REPOSITORY : graph.slug(place.repository),
|
|
720
|
+
size,
|
|
721
|
+
claimable: ready && after.length === 0,
|
|
722
|
+
acceptance: acceptance ?? {
|
|
723
|
+
text: `A function computes ${graph.text(id, "computation")}, and each result has a certificate of the kind ${certificate}.`,
|
|
724
|
+
checks: [
|
|
725
|
+
`A record of kind function has the relation solves to ${id}.`,
|
|
726
|
+
certificate === "ledger" ? "A test checks that the ledger names each range that is done, with no gap and no overlap." : "A test checks each witness against the statement of the problem.",
|
|
727
|
+
"`pnpm canon check` passes."
|
|
728
|
+
]
|
|
729
|
+
},
|
|
730
|
+
why: `${title} is open, and a computation helps: ${graph.text(id, "computation")}${partial.length > 0 ? `${STOP.test(graph.text(id, "computation")) ? "" : "."} ${countOf(partial.length, "result")} ${partial.length === 1 ? "settles" : "settle"} only a part of its scope.` : ""}`,
|
|
731
|
+
...after.length > 0 ? { after } : {},
|
|
732
|
+
...partial.length > 0 ? { partial } : {}
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
return drafts;
|
|
736
|
+
}
|
|
737
|
+
/** The gates that rule test-gate asks of each home repository. The read also gives the gate rigs, with no target. */
|
|
738
|
+
const NECESSARY_GATES = [
|
|
739
|
+
"mutation",
|
|
740
|
+
"property",
|
|
741
|
+
"speed"
|
|
742
|
+
];
|
|
743
|
+
/** The work to add each gate of `NECESSARY_GATES` to a repository `slug`. */
|
|
744
|
+
function addWork(gate, slug) {
|
|
745
|
+
const next = (gateName) => `The next import of canon gives the ${gateName} gate of ${slug} with \`exists: true\`.`;
|
|
746
|
+
if (gate === "mutation") return {
|
|
747
|
+
title: `Add the mutation gate to ${slug}`,
|
|
748
|
+
size: "M",
|
|
749
|
+
claimable: true,
|
|
750
|
+
acceptance: {
|
|
751
|
+
text: `${slug} has a lane file of mutation tests and a workflow that calls \`reusable-mutation.yml\` of \`mark1russell7/template\`.`,
|
|
752
|
+
checks: [
|
|
753
|
+
`The lane file names each package of ${slug}, and each package has a gate.`,
|
|
754
|
+
"The workflow gives a score for each package, at or above its gate.",
|
|
755
|
+
next("mutation")
|
|
756
|
+
]
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
if (gate === "property") return {
|
|
760
|
+
title: `Add property tests to ${slug}`,
|
|
761
|
+
size: "S",
|
|
762
|
+
claimable: true,
|
|
763
|
+
acceptance: {
|
|
764
|
+
text: `A package of ${slug} has property tests with \`fast-check\` or \`@mark1russell7/rigor-testkit\`.`,
|
|
765
|
+
checks: [
|
|
766
|
+
"A property test checks a law of the code of the home, and it fails when the law breaks.",
|
|
767
|
+
"The tests of the repository pass in CI.",
|
|
768
|
+
next("property")
|
|
769
|
+
]
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
return {
|
|
773
|
+
title: `Add a speed gate to ${slug}`,
|
|
774
|
+
size: "M",
|
|
775
|
+
claimable: false,
|
|
776
|
+
acceptance: {
|
|
777
|
+
text: `A workflow of ${slug} starts a bench of \`@mark1russell7/rigor-bench\` on each pull request, and its verdict can fail the pull request.`,
|
|
778
|
+
checks: [
|
|
779
|
+
"A package file names `@mark1russell7/rigor-bench` in its dependencies.",
|
|
780
|
+
"The bench job gives the verdict of `gateOf` or `notSlowerVerdict`, and a slower case fails the job.",
|
|
781
|
+
next("speed")
|
|
782
|
+
]
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Rule test-gate: each home repository that exists gives a target for each gate of `NECESSARY_GATES` that its read
|
|
788
|
+
* finds absent. It also gives a target for a gate with no necessary check. A gate with no read gives no target.
|
|
789
|
+
*
|
|
790
|
+
* - An absent mutation or property gate is claimable. A speed gate needs the maintainer, who chooses the timed cases.
|
|
791
|
+
* - A gate that is not a necessary check needs the maintainer, because only the maintainer changes the rules of a branch.
|
|
792
|
+
*/
|
|
793
|
+
function testGate(graph) {
|
|
794
|
+
const drafts = [];
|
|
795
|
+
for (const [id, record] of graph.byId) {
|
|
796
|
+
if (record.kind !== "repository" || record.attrs["exists"] !== true || graph.out(id, "home-of").length === 0) continue;
|
|
797
|
+
const read = recordOf(record.attrs, "test_gates");
|
|
798
|
+
const branch = textOf(read, "branch") ?? "";
|
|
799
|
+
const slug = graph.slug(id);
|
|
800
|
+
for (const gate of NECESSARY_GATES) {
|
|
801
|
+
const fact = recordOf(recordOf(read, "gates"), gate);
|
|
802
|
+
const exists = booleanOf(fact, "exists");
|
|
803
|
+
const necessary = booleanOf(fact, "necessary");
|
|
804
|
+
const base = {
|
|
805
|
+
subject: `${id}.${gate}`,
|
|
806
|
+
about: [id],
|
|
807
|
+
gap: "test-gate",
|
|
808
|
+
home: slug
|
|
809
|
+
};
|
|
810
|
+
if (exists === false) {
|
|
811
|
+
const missing = arrayOf(fact, "missing", readText) ?? [];
|
|
812
|
+
drafts.push({
|
|
813
|
+
...base,
|
|
814
|
+
...addWork(gate, slug),
|
|
815
|
+
why: `The read of ${slug} on the branch ${branch} does not find ${listOf(missing.length > 0 ? missing : [`the ${gate} gate`])}.`
|
|
816
|
+
});
|
|
817
|
+
} else if (exists === true && necessary === false) {
|
|
818
|
+
const checks = (arrayOf(fact, "checks", readText) ?? []).map((check) => `\`${check}\``);
|
|
819
|
+
drafts.push({
|
|
820
|
+
...base,
|
|
821
|
+
title: `Make the ${gate} gate a necessary check of ${slug}`,
|
|
822
|
+
size: gate === "mutation" ? "S" : "XS",
|
|
823
|
+
claimable: false,
|
|
824
|
+
acceptance: {
|
|
825
|
+
text: `The rules of the branch ${branch} of ${slug} name a check of the ${gate} gate as a necessary check.`,
|
|
826
|
+
checks: [
|
|
827
|
+
...gate === "mutation" ? ["A workflow on each pull request calls `reusable-mutation.yml` with the input `changed`, so its check starts on each pull request."] : [],
|
|
828
|
+
checks.length > 0 ? `\`gh api repos/${slug}/rules/branches/${branch}\` names the check ${listOf(checks, { conjunction: "or" })}.` : `\`gh api repos/${slug}/rules/branches/${branch}\` names a check of a job of the ${gate} gate.`,
|
|
829
|
+
`The next import of canon gives the ${gate} gate of ${slug} with \`necessary: true\`.`
|
|
830
|
+
]
|
|
831
|
+
},
|
|
832
|
+
why: `${slug} has the ${gate} gate, but the rules of the branch ${branch} name no check of it as necessary. Only the maintainer changes the rules of a branch.`
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
return drafts;
|
|
838
|
+
}
|
|
839
|
+
/** This function gives the order of two targets: the claimable targets first, then the smaller, then by id. */
|
|
840
|
+
function compareTargets(a, b) {
|
|
841
|
+
if (a.attrs.claimable !== b.attrs.claimable) return a.attrs.claimable ? -1 : 1;
|
|
842
|
+
const size = SIZES.indexOf(a.attrs.size) - SIZES.indexOf(b.attrs.size);
|
|
843
|
+
if (size !== 0) return size;
|
|
844
|
+
return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* This function is the target query. It applies each rule to the records, and gives each target in the order of
|
|
848
|
+
* `compareTargets`. It reads no record of kind target, so its result depends on the other records only.
|
|
849
|
+
*/
|
|
850
|
+
function targetsOf(ontology) {
|
|
851
|
+
const graph = new Graph(ontology);
|
|
852
|
+
return [
|
|
853
|
+
...buildFunction(graph),
|
|
854
|
+
...moveCopy(graph),
|
|
855
|
+
...findCopy(graph),
|
|
856
|
+
...firstRelease(graph),
|
|
857
|
+
...firstPackageAndRepository(graph),
|
|
858
|
+
...findHome(graph),
|
|
859
|
+
...computeProblem(graph),
|
|
860
|
+
...testGate(graph)
|
|
861
|
+
].map(({ subject, about = [subject], after, ...attrs }) => ({
|
|
862
|
+
id: targetId(attrs.gap, subject),
|
|
863
|
+
kind: "target",
|
|
864
|
+
attrs: after === void 0 ? attrs : {
|
|
865
|
+
...attrs,
|
|
866
|
+
after
|
|
867
|
+
},
|
|
868
|
+
envelope: { derived: true },
|
|
869
|
+
edges: about.map((to) => ({
|
|
870
|
+
type: "about",
|
|
871
|
+
to
|
|
872
|
+
}))
|
|
873
|
+
})).sort(compareTargets);
|
|
874
|
+
}
|
|
875
|
+
export { kindOfId as A, kindOf as C, ONTOLOGY_FOLDER as D, GRAMMAR_FILE as E, repositoryId as F, npmPackageId as M, npmPurl as N, RECORD_SCHEMA_FILE as O, pathOfId as P, isLive as S, relationOf as T, readScope as _, SIZES as a, edgesOf as b, targetsOf as c, hasFullScope as d, resultClaimsOf as f, inScope as g, canonicalScope as h, PLACES_SHOWN as i, makeId as j, idPart as k, CLAIM_STATUSES as l, SCOPE_MODULUS_LIMIT as m, NECESSARY_GATES as n, compareTargets as o, scopeOf as p, ONTOLOGY_REPOSITORY as r, targetId as s, MAP_PACKAGE as t, claimFails as u, sameScope as v, lineageOf as w, isKindIn as x, scopeText as y };
|
|
876
|
+
|
|
877
|
+
//# sourceMappingURL=targets-DsUgzuOM.mjs.map
|