@prestack/thread 0.1.2 → 0.1.4

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.
Files changed (265) hide show
  1. package/CHANGELOG.md +193 -0
  2. package/dist/core/actor.d.ts +1 -1
  3. package/dist/core/actor.js +5 -4
  4. package/dist/core/actor.ts +5 -4
  5. package/dist/core/attach.d.ts +0 -7
  6. package/dist/core/attach.js +67 -58
  7. package/dist/core/attach.ts +61 -68
  8. package/dist/core/chain.js +13 -17
  9. package/dist/core/chain.ts +11 -15
  10. package/dist/core/condition.d.ts +4 -4
  11. package/dist/core/condition.js +2 -2
  12. package/dist/core/descend.d.ts +4 -2
  13. package/dist/core/descend.js +89 -21
  14. package/dist/core/descend.ts +86 -17
  15. package/dist/core/errors/catalogue.d.ts +52 -0
  16. package/dist/{operations/errors/errors.js → core/errors/catalogue.js} +1 -1
  17. package/dist/{operations/errors/errors.ts → core/errors/catalogue.ts} +1 -1
  18. package/dist/{operations/errors/catalog.d.ts → core/errors/error.d.ts} +2 -3
  19. package/dist/{operations/errors/catalog.js → core/errors/error.js} +1 -16
  20. package/dist/{operations/errors/catalog.ts → core/errors/error.ts} +3 -19
  21. package/dist/core/errors/namespaces.d.ts +3 -0
  22. package/dist/core/errors/namespaces.js +15 -0
  23. package/dist/core/errors/namespaces.ts +19 -0
  24. package/dist/core/finding.js +2 -2
  25. package/dist/core/finding.ts +1 -2
  26. package/dist/core/init.d.ts +0 -2
  27. package/dist/core/init.js +51 -15
  28. package/dist/core/init.ts +58 -15
  29. package/dist/core/invoked.d.ts +1 -1
  30. package/dist/core/invoked.js +3 -1
  31. package/dist/core/invoked.ts +5 -2
  32. package/dist/core/round.js +36 -22
  33. package/dist/core/round.ts +26 -9
  34. package/dist/core/rows.d.ts +4 -0
  35. package/dist/core/rows.js +31 -2
  36. package/dist/core/rows.ts +33 -1
  37. package/dist/core/thread.d.ts +3 -3
  38. package/dist/core/tree.d.ts +4 -1
  39. package/dist/core/tree.js +26 -6
  40. package/dist/core/tree.ts +29 -6
  41. package/dist/core/types.d.ts +3 -3
  42. package/dist/core/types.js +3 -1
  43. package/dist/core/types.ts +2 -1
  44. package/dist/derivation/attach.js +1 -1
  45. package/dist/derivation/generators/build.js +6 -6
  46. package/dist/derivation/generators/build.ts +1 -1
  47. package/dist/derivation/generators/check.js +1 -1
  48. package/dist/derivation/generators/determinism.js +1 -1
  49. package/dist/derivation/generators/release.js +60 -47
  50. package/dist/derivation/generators/release.ts +66 -43
  51. package/dist/derivation/release.d.ts +7 -3
  52. package/dist/derivation/release.js +14 -1
  53. package/dist/derivation/release.ts +22 -2
  54. package/dist/integrations/attach.d.ts +4 -0
  55. package/dist/integrations/attach.js +33 -54
  56. package/dist/integrations/attach.ts +50 -57
  57. package/dist/integrations/cli.d.ts +37 -0
  58. package/dist/integrations/cli.js +440 -0
  59. package/dist/integrations/cli.ts +543 -0
  60. package/dist/{core/files.d.ts → integrations/disk.d.ts} +16 -20
  61. package/dist/integrations/disk.js +435 -0
  62. package/dist/integrations/disk.ts +465 -0
  63. package/dist/integrations/generators/read.js +6 -6
  64. package/dist/integrations/generators/read.ts +4 -4
  65. package/dist/integrations/generators/vault.js +10 -11
  66. package/dist/integrations/generators/vault.ts +4 -5
  67. package/dist/{operations/http.d.ts → integrations/https.d.ts} +10 -6
  68. package/dist/integrations/https.js +170 -0
  69. package/dist/integrations/https.ts +216 -0
  70. package/dist/integrations/pglite.d.ts +26 -0
  71. package/dist/integrations/pglite.js +143 -0
  72. package/dist/integrations/pglite.ts +206 -0
  73. package/dist/integrations/secret.d.ts +8 -2
  74. package/dist/integrations/secret.js +3 -5
  75. package/dist/integrations/secret.ts +10 -6
  76. package/dist/integrations/target.d.ts +155 -14
  77. package/dist/integrations/target.js +171 -50
  78. package/dist/integrations/target.ts +377 -61
  79. package/dist/integrations/vault.d.ts +1 -0
  80. package/dist/integrations/vault.js +20 -5
  81. package/dist/integrations/vault.ts +17 -5
  82. package/dist/integrity/attach.js +3 -73
  83. package/dist/integrity/attach.ts +1 -71
  84. package/dist/integrity/check-threads.js +5 -5
  85. package/dist/integrity/check-threads.ts +2 -2
  86. package/dist/integrity/constraint.d.ts +0 -1
  87. package/dist/integrity/constraint.js +267 -366
  88. package/dist/integrity/constraint.ts +267 -375
  89. package/dist/integrity/generators/compiler.js +14 -17
  90. package/dist/integrity/generators/compiler.ts +10 -15
  91. package/dist/integrity/generators/gate.js +15 -15
  92. package/dist/integrity/generators/gate.ts +10 -10
  93. package/dist/integrity/generators/issues.js +7 -7
  94. package/dist/integrity/generators/publish.js +39 -57
  95. package/dist/integrity/generators/publish.ts +44 -55
  96. package/dist/integrity/generators/trial.d.ts +3 -3
  97. package/dist/integrity/generators/trial.js +133 -161
  98. package/dist/integrity/generators/trial.ts +145 -165
  99. package/dist/integrity/lint.js +9 -13
  100. package/dist/integrity/lint.ts +7 -10
  101. package/dist/integrity/lsp/bin.js +5 -4
  102. package/dist/integrity/lsp/bin.ts +3 -1
  103. package/dist/integrity/lsp/diagnostics.js +3 -3
  104. package/dist/integrity/lsp/diagnostics.ts +1 -1
  105. package/dist/integrity/lsp/lint.js +19 -30
  106. package/dist/integrity/lsp/lint.ts +16 -32
  107. package/dist/integrity/lsp/server.js +3 -3
  108. package/dist/integrity/slopnator.d.ts +3 -13
  109. package/dist/integrity/slopnator.js +58 -37
  110. package/dist/integrity/slopnator.ts +53 -37
  111. package/dist/integrity/slopnators/sl_broken_lineage.js +2 -2
  112. package/dist/integrity/slopnators/sl_declared_elsewhere.js +1 -1
  113. package/dist/integrity/slopnators/sl_derived_drift.js +4 -4
  114. package/dist/integrity/slopnators/sl_derived_drift.ts +1 -1
  115. package/dist/integrity/slopnators/sl_door_in_a_node.js +220 -0
  116. package/dist/integrity/slopnators/sl_door_in_a_node.ts +250 -0
  117. package/dist/integrity/slopnators/sl_inert_island.js +10 -8
  118. package/dist/integrity/slopnators/sl_inert_island.ts +8 -6
  119. package/dist/integrity/slopnators/sl_missing_row.js +6 -51
  120. package/dist/integrity/slopnators/sl_missing_row.ts +4 -50
  121. package/dist/integrity/slopnators/sl_no_barrel.js +1 -1
  122. package/dist/integrity/slopnators/sl_no_child_process.js +36 -18
  123. package/dist/integrity/slopnators/sl_no_child_process.ts +44 -18
  124. package/dist/integrity/slopnators/sl_no_dispatch_bypass.js +80 -149
  125. package/dist/integrity/slopnators/sl_no_dispatch_bypass.ts +95 -147
  126. package/dist/integrity/slopnators/sl_no_import_cycle.js +15 -4
  127. package/dist/integrity/slopnators/sl_no_import_cycle.ts +20 -4
  128. package/dist/integrity/slopnators/sl_no_such_command.js +2 -2
  129. package/dist/integrity/slopnators/sl_no_such_command.ts +1 -1
  130. package/dist/integrity/slopnators/sl_outside_an_operation.js +20 -0
  131. package/dist/integrity/slopnators/sl_outside_an_operation.ts +25 -0
  132. package/dist/integrity/slopnators/sl_screen_holds_only_declared.d.ts +2 -0
  133. package/dist/integrity/slopnators/sl_screen_holds_only_declared.js +61 -0
  134. package/dist/integrity/slopnators/sl_screen_holds_only_declared.ts +70 -0
  135. package/dist/integrity/slopnators/sl_secret_literal.js +1 -33
  136. package/dist/integrity/slopnators/sl_secret_literal.ts +1 -33
  137. package/dist/integrity/slopnators/sl_stale_path.js +5 -22
  138. package/dist/integrity/slopnators/sl_stale_path.ts +4 -20
  139. package/dist/integrity/slopnators/sl_twice_meant.js +1 -1
  140. package/dist/integrity/slopnators/sl_twice_parented.js +29 -5
  141. package/dist/integrity/slopnators/sl_twice_parented.ts +28 -4
  142. package/dist/integrity/slopnators/sl_undeclared_crossing.d.ts +4 -1
  143. package/dist/integrity/slopnators/sl_undeclared_crossing.js +426 -62
  144. package/dist/integrity/slopnators/sl_undeclared_crossing.ts +454 -70
  145. package/dist/integrity/slopnators/sl_undeclared_destination.js +59 -25
  146. package/dist/integrity/slopnators/sl_undeclared_destination.ts +69 -21
  147. package/dist/integrity/slopnators/sl_undeclared_list.d.ts +2 -0
  148. package/dist/integrity/slopnators/sl_undeclared_list.js +363 -0
  149. package/dist/integrity/slopnators/sl_undeclared_list.ts +358 -0
  150. package/dist/integrity/slopnators/sl_undeclared_node.js +1 -11
  151. package/dist/integrity/slopnators/sl_undeclared_node.ts +0 -10
  152. package/dist/integrity/slopnators/sl_undeclared_operation.js +111 -29
  153. package/dist/integrity/slopnators/sl_undeclared_operation.ts +134 -26
  154. package/dist/integrity/slopnators/sl_undeclared_variant.js +2 -2
  155. package/dist/integrity/slopnators/sl_undeclared_webhook.d.ts +2 -0
  156. package/dist/integrity/slopnators/sl_undeclared_webhook.js +90 -0
  157. package/dist/integrity/slopnators/sl_undeclared_webhook.ts +108 -0
  158. package/dist/integrity/slopnators/sl_underived_route.d.ts +2 -0
  159. package/dist/integrity/slopnators/sl_underived_route.js +61 -0
  160. package/dist/integrity/slopnators/sl_underived_route.ts +72 -0
  161. package/dist/integrity/slopnators/sl_ungoverned_island.js +3 -3
  162. package/dist/integrity/slopnators/sl_ungoverned_island.ts +1 -1
  163. package/dist/integrity/slopnators/sl_unlisted_program.d.ts +2 -0
  164. package/dist/integrity/slopnators/sl_unlisted_program.js +39 -0
  165. package/dist/integrity/slopnators/sl_unlisted_program.ts +40 -0
  166. package/dist/integrity/slopnators/sl_unnamed_island.js +1 -1
  167. package/dist/integrity/slopnators/sl_unpaired_member.js +3 -3
  168. package/dist/integrity/slopnators/sl_unpaired_member.ts +1 -1
  169. package/dist/integrity/slopnators/sl_unpaired_slopnator.js +4 -4
  170. package/dist/integrity/slopnators/sl_unpaired_slopnator.ts +1 -1
  171. package/dist/integrity/slopnators/sl_unprefixed_member.js +5 -31
  172. package/dist/integrity/slopnators/sl_unprefixed_member.ts +2 -28
  173. package/dist/integrity/slopnators/sl_unthreaded.js +11 -7
  174. package/dist/integrity/slopnators/sl_unthreaded.ts +6 -7
  175. package/dist/integrity/slopnators/sl_untranslated_key.js +2 -25
  176. package/dist/integrity/slopnators/sl_untranslated_key.ts +1 -25
  177. package/dist/integrity/slopnators/sl_unvaulted_secret.d.ts +2 -0
  178. package/dist/integrity/slopnators/sl_unvaulted_secret.js +107 -0
  179. package/dist/integrity/slopnators/sl_unvaulted_secret.ts +132 -0
  180. package/dist/integrity/slopnators/sl_unversioned.js +6 -4
  181. package/dist/integrity/slopnators/sl_unversioned.ts +5 -3
  182. package/dist/integrity/sweep.d.ts +1 -0
  183. package/dist/integrity/sweep.js +105 -42
  184. package/dist/integrity/sweep.ts +115 -42
  185. package/dist/knowledge/attach.js +1 -1
  186. package/dist/knowledge/generators/docsgen.js +8 -6
  187. package/dist/knowledge/generators/docsgen.ts +4 -2
  188. package/dist/knowledge/generators/glossary.js +4 -4
  189. package/dist/knowledge/generators/glossary.ts +1 -1
  190. package/dist/operations/access.d.ts +23 -0
  191. package/dist/operations/access.js +28 -1
  192. package/dist/operations/access.ts +43 -0
  193. package/dist/operations/attach.js +28 -109
  194. package/dist/operations/attach.ts +46 -113
  195. package/dist/operations/capabilities.d.ts +14 -5
  196. package/dist/operations/capabilities.js +13 -4
  197. package/dist/operations/capabilities.ts +27 -8
  198. package/dist/operations/dispatch.d.ts +8 -2
  199. package/dist/operations/dispatch.js +128 -185
  200. package/dist/operations/dispatch.ts +138 -191
  201. package/dist/operations/error-results.d.ts +1 -1
  202. package/dist/operations/error-results.js +2 -2
  203. package/dist/operations/error-results.ts +2 -2
  204. package/dist/operations/generators/capability.d.ts +11 -1
  205. package/dist/operations/generators/capability.js +481 -224
  206. package/dist/operations/generators/capability.ts +562 -233
  207. package/dist/operations/generators/compile.js +66 -39
  208. package/dist/operations/generators/compile.ts +78 -39
  209. package/dist/operations/generators/permits.js +11 -12
  210. package/dist/operations/generators/permits.ts +3 -4
  211. package/dist/operations/generators/seed.d.ts +1 -0
  212. package/dist/operations/generators/seed.js +19 -17
  213. package/dist/operations/generators/seed.ts +22 -14
  214. package/dist/operations/generators/trial.d.ts +6 -8
  215. package/dist/operations/generators/trial.js +200 -70
  216. package/dist/operations/generators/trial.ts +230 -93
  217. package/dist/operations/nodes.d.ts +15 -16
  218. package/dist/operations/nodes.ts +16 -17
  219. package/dist/operations/operations.d.ts +40 -4
  220. package/dist/operations/operations.js +1 -0
  221. package/dist/operations/operations.ts +61 -4
  222. package/dist/operations/result.d.ts +2 -2
  223. package/dist/operations/result.ts +2 -2
  224. package/package.json +1 -4
  225. package/dist/core/answers.d.ts +0 -171
  226. package/dist/core/answers.js +0 -789
  227. package/dist/core/answers.ts +0 -999
  228. package/dist/core/client.d.ts +0 -57
  229. package/dist/core/client.js +0 -247
  230. package/dist/core/client.ts +0 -286
  231. package/dist/core/files.js +0 -145
  232. package/dist/core/files.ts +0 -193
  233. package/dist/integrations/module.d.ts +0 -6
  234. package/dist/integrations/module.js +0 -153
  235. package/dist/integrations/module.ts +0 -191
  236. package/dist/integrity/slopnators/sl_unkept_rows.js +0 -104
  237. package/dist/integrity/slopnators/sl_unkept_rows.ts +0 -111
  238. package/dist/integrity/slopnators/sl_unseamed_reach.js +0 -73
  239. package/dist/integrity/slopnators/sl_unseamed_reach.ts +0 -79
  240. package/dist/operations/cost.d.ts +0 -14
  241. package/dist/operations/cost.js +0 -37
  242. package/dist/operations/cost.ts +0 -58
  243. package/dist/operations/errors/errors.d.ts +0 -52
  244. package/dist/operations/http.js +0 -124
  245. package/dist/operations/http.ts +0 -169
  246. package/dist/operations/memory.d.ts +0 -104
  247. package/dist/operations/memory.js +0 -365
  248. package/dist/operations/memory.ts +0 -470
  249. package/dist/operations/metering.d.ts +0 -55
  250. package/dist/operations/metering.js +0 -247
  251. package/dist/operations/metering.ts +0 -328
  252. package/dist/operations/queue-policy.d.ts +0 -3
  253. package/dist/operations/queue-policy.js +0 -8
  254. package/dist/operations/queue-policy.ts +0 -10
  255. package/dist/operations/seams.d.ts +0 -239
  256. package/dist/operations/seams.js +0 -45
  257. package/dist/operations/seams.ts +0 -364
  258. package/dist/operations/store.d.ts +0 -14
  259. package/dist/operations/store.js +0 -1
  260. package/dist/operations/store.ts +0 -29
  261. /package/dist/{operations → core}/errors/classes.d.ts +0 -0
  262. /package/dist/{operations → core}/errors/classes.js +0 -0
  263. /package/dist/{operations → core}/errors/classes.ts +0 -0
  264. /package/dist/integrity/slopnators/{sl_unkept_rows.d.ts → sl_door_in_a_node.d.ts} +0 -0
  265. /package/dist/integrity/slopnators/{sl_unseamed_reach.d.ts → sl_outside_an_operation.d.ts} +0 -0
@@ -1,7 +1,6 @@
1
1
  import type { Rule } from 'eslint';
2
2
  import type { Constraint, Sourced } from '../constraint.ts';
3
- import { type Byproduct, type Slopnator } from '../slopnator.ts';
4
- export declare const TRIALS_PATH: string;
3
+ import { type Slopnator } from '../slopnator.ts';
5
4
  export interface Scenario {
6
5
  readonly files: readonly Sourced[];
7
6
  readonly at: string;
@@ -31,9 +30,10 @@ export interface Run {
31
30
  readonly passed: number;
32
31
  readonly failed: number;
33
32
  readonly measured: number;
33
+ readonly spent: ReadonlyMap<string, number>;
34
34
  }
35
35
  export declare function probeAt(rule: Constraint): string;
36
36
  export declare function deriveTrials(all: readonly Constraint[], slopnators: ReadonlyMap<string, Slopnator>): Derivation;
37
- export declare function trialsByproduct(derivation: Derivation): Byproduct;
38
37
  export declare function runTrial(trial: Trial, rule: Constraint, module: Rule.RuleModule, parser: unknown, slopnator?: Slopnator): Outcome;
38
+ export declare function crossed(trials: readonly Trial[], all: readonly Constraint[], rules: Readonly<Record<string, Rule.RuleModule>>, parser: unknown, slopnators?: ReadonlyMap<string, Slopnator>, spent?: Map<string, number>): readonly Outcome[];
39
39
  export declare function runTrials(trials: readonly Trial[], all: readonly Constraint[], rules: Readonly<Record<string, Rule.RuleModule>>, parser: unknown, slopnators?: ReadonlyMap<string, Slopnator>): Run;
@@ -1,14 +1,10 @@
1
- import * as disk from 'node:fs';
2
- import { answeredBy, existsSync, readFileSync } from "../../core/files.js";
3
- import { basename, dirname, join, resolve } from 'node:path';
4
- import { exit, invoked } from "../../core/invoked.js";
1
+ import { answeredBy, standing } from '../../integrations/disk.js';
2
+ import { resolve } from 'node:path';
5
3
  import { Linter } from 'eslint';
6
4
  const TREE = findTree();
7
- import { CONSTRAINTS } from "../constraint.js";
8
- import { NOT_WRITTEN, ROOT, governs, load, proofsOf, reads, rules, slopnatorName, sweeps, write } from "../slopnator.js";
9
- import { forget } from "../slopnators/sl_unthreaded.js";
10
- import { findTree } from "../../core/tree.js";
11
- export const TRIALS_PATH = `${findTree().name}/_generated/trials.ts`;
5
+ import { NOT_WRITTEN, ROOT, governs, proofsOf, reads, slopnatorName, sweeps, visits } from '../slopnator.js';
6
+ import { forget } from '../slopnators/sl_unthreaded.js';
7
+ import { findTree } from '../../core/tree.js';
12
8
  const PROBE = 'probe.tsx';
13
9
  const WRAPPINGS = [
14
10
  (source) => source,
@@ -61,13 +57,6 @@ export function deriveTrials(all, slopnators) {
61
57
  }
62
58
  return { trials: trials.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)) };
63
59
  }
64
- export function trialsByproduct(derivation) {
65
- return {
66
- path: TRIALS_PATH,
67
- content: `export const RULE_TRIALS = ${JSON.stringify(derivation.trials, null, 2)} as const
68
- `,
69
- };
70
- }
71
60
  function config(rule, module, parser) {
72
61
  return [
73
62
  {
@@ -81,91 +70,6 @@ function config(rule, module, parser) {
81
70
  },
82
71
  ];
83
72
  }
84
- const flat = (at) => (at.length > 1 && at.endsWith('/') ? at.replace(/\/+$/, '') : at);
85
- const under = (at) => at.startsWith(ROOT) || `${at}/` === ROOT;
86
- const own = (at) => under(at) && !at.slice(ROOT.length).split('/').includes('node_modules');
87
- function beside(at) {
88
- try {
89
- return disk.readdirSync(at, { withFileTypes: true });
90
- }
91
- catch {
92
- return [];
93
- }
94
- }
95
- function outside(at) {
96
- const one = disk.statSync(at, { throwIfNoEntry: false });
97
- if (one === undefined)
98
- return 'none';
99
- return one.isFile() ? 'file' : one.isDirectory() ? 'folder' : 'other';
100
- }
101
- const GONE = 'is not in the scenario this trial stands, and while it runs the scenario is the whole tree.';
102
- function answering(files) {
103
- const held = new Map(files.map((one) => [resolve(ROOT, one.at), one.source]));
104
- const folders = new Set();
105
- const parents = (at) => {
106
- for (let up = dirname(at); under(`${up}/`); up = dirname(up))
107
- folders.add(up);
108
- };
109
- for (const at of held.keys())
110
- parents(at);
111
- const answers = {
112
- kind: (at) => (held.has(at) ? 'file' : folders.has(at) ? 'folder' : own(at) ? 'none' : outside(at)),
113
- read: (at) => {
114
- const said = held.get(at);
115
- if (said !== undefined)
116
- return said;
117
- if (own(at))
118
- throw new Error(`${at} ${GONE}`);
119
- return disk.readFileSync(at, 'utf8');
120
- },
121
- write: (at, said) => {
122
- held.set(at, said);
123
- parents(at);
124
- },
125
- list: (at) => {
126
- const inside = new Map();
127
- const found = own(at) ? [] : folders.has(at) ? beside(at) : disk.readdirSync(at, { withFileTypes: true });
128
- for (const one of found)
129
- inside.set(one.name, { name: one.name, kind: one.isDirectory() ? 'folder' : 'file' });
130
- for (const path of folders)
131
- if (dirname(path) === at)
132
- inside.set(basename(path), { name: basename(path), kind: 'folder' });
133
- for (const path of held.keys())
134
- if (dirname(path) === at)
135
- inside.set(basename(path), { name: basename(path), kind: 'file' });
136
- return [...inside.values()];
137
- },
138
- stat: (at) => {
139
- const said = held.get(at);
140
- if (said !== undefined)
141
- return { size: said.length, modified: 0 };
142
- if (folders.has(at))
143
- return { size: 0, modified: 0 };
144
- if (own(at))
145
- throw new Error(`${at} ${GONE}`);
146
- const one = disk.statSync(at);
147
- return { size: one.size, modified: one.mtimeMs };
148
- },
149
- remove: (at) => {
150
- held.delete(at);
151
- folders.delete(at);
152
- },
153
- real: (at) => (own(at) || held.has(at) || folders.has(at) ? at : disk.realpathSync(at)),
154
- };
155
- return {
156
- kind: (at) => answers.kind(flat(at)),
157
- read: (at) => answers.read(flat(at)),
158
- write: (at, said) => {
159
- answers.write(flat(at), said);
160
- },
161
- list: (at) => answers.list(flat(at)),
162
- stat: (at) => answers.stat(flat(at)),
163
- remove: (at) => {
164
- answers.remove(flat(at));
165
- },
166
- real: (at) => answers.real(flat(at)),
167
- };
168
- }
169
73
  export function runTrial(trial, rule, module, parser, slopnator) {
170
74
  const linter = new Linter();
171
75
  const failures = [];
@@ -181,7 +85,7 @@ export function runTrial(trial, rule, module, parser, slopnator) {
181
85
  const target = trial.scenario.files.find((file) => file.at === trial.scenario.at);
182
86
  let parsed = false;
183
87
  let satisfied = false;
184
- answeredBy(answering(trial.scenario.files));
88
+ answeredBy(standing(ROOT, new Map(trial.scenario.files.map((one) => [resolve(ROOT, one.at), one.source]))));
185
89
  forget();
186
90
  try {
187
91
  if (slopnator !== undefined && !reads(slopnator)) {
@@ -230,8 +134,129 @@ export function runTrial(trial, rule, module, parser, slopnator) {
230
134
  }
231
135
  return { id: trial.id, rule: rule.id, passed: failures.length === 0, parsed, failures };
232
136
  }
137
+ const judged = (who, rules, parser) => [
138
+ {
139
+ files: ['**/*.ts', '**/*.tsx'],
140
+ languageOptions: {
141
+ parser,
142
+ parserOptions: { ecmaVersion: 'latest', sourceType: 'module', ecmaFeatures: { jsx: true } },
143
+ },
144
+ plugins: { rule: { rules: Object.fromEntries(who.map((one) => [one.id, rules[one.id]])) } },
145
+ rules: Object.fromEntries(who.map((one) => ['rule/' + one.id, 'error'])),
146
+ },
147
+ ];
148
+ const failed = (thrown) => 'could not run on it: ' + (thrown instanceof Error ? thrown.message : String(thrown));
149
+ const parseable = (source, at, parser) => WRAPPINGS.find((wrap) => !new Linter().verify(wrap(source), judged([], {}, parser), at).some((one) => one.fatal === true)) ??
150
+ ((said) => said);
151
+ function refusals(scenario, source, judges, rules, parser, slopnators) {
152
+ const found = new Map();
153
+ const note = (who, said) => {
154
+ const held = found.get(who) ?? new Set();
155
+ held.add(said);
156
+ found.set(who, held);
157
+ };
158
+ const walking = judges.filter((one) => {
159
+ const held = slopnators.get(slopnatorName(one.id));
160
+ return held !== undefined && visits(held) && rules[one.id] !== undefined;
161
+ });
162
+ const linted = (who) => {
163
+ const messages = new Linter().verify(source, judged(who, rules, parser), scenario.at);
164
+ if (messages.some((one) => one.fatal === true))
165
+ return;
166
+ for (const one of messages) {
167
+ const by = String(one.ruleId ?? '').replace('rule/', '');
168
+ if (by !== '')
169
+ note(by, one.message);
170
+ }
171
+ };
172
+ const files = scenario.files.map((one) => (one.at === scenario.at ? { at: one.at, source } : one));
173
+ answeredBy(standing(ROOT, new Map(files.map((one) => [resolve(ROOT, one.at), one.source]))));
174
+ forget();
175
+ try {
176
+ try {
177
+ linted(walking);
178
+ }
179
+ catch {
180
+ for (const one of walking) {
181
+ try {
182
+ linted([one]);
183
+ }
184
+ catch (thrown) {
185
+ note(one.id, failed(thrown));
186
+ }
187
+ }
188
+ }
189
+ for (const one of judges) {
190
+ const held = slopnators.get(slopnatorName(one.id));
191
+ if (held === undefined)
192
+ continue;
193
+ if (visits(held))
194
+ continue;
195
+ try {
196
+ if (sweeps(held)) {
197
+ const said = held.holds(undefined, { filename: scenario.at, text: source, ancestors: () => [], comments: () => [] });
198
+ if (said !== false && said !== NOT_WRITTEN)
199
+ note(one.id, typeof said === 'string' ? said : slopnatorName(one.id));
200
+ continue;
201
+ }
202
+ if (!reads(held))
203
+ for (const said of held.checks(ROOT))
204
+ note(one.id, said);
205
+ }
206
+ catch (thrown) {
207
+ note(one.id, failed(thrown));
208
+ }
209
+ }
210
+ }
211
+ finally {
212
+ answeredBy(undefined);
213
+ forget();
214
+ }
215
+ return found;
216
+ }
217
+ export function crossed(trials, all, rules, parser, slopnators = new Map(), spent = new Map()) {
218
+ const found = [];
219
+ const blanks = new Map();
220
+ for (const trial of trials) {
221
+ if (trial.verdict.reports)
222
+ continue;
223
+ const target = trial.scenario.files.find((one) => one.at === trial.scenario.at);
224
+ if (target === undefined)
225
+ continue;
226
+ const judges = all.filter((one) => governs(one, trial.scenario.at));
227
+ if (!judges.some((one) => one.id !== trial.rule))
228
+ continue;
229
+ const began = Date.now();
230
+ const wrap = parseable(target.source, trial.scenario.at, parser);
231
+ const emptied = JSON.stringify([wrap(''), trial.scenario.files.map((one) => (one.at === trial.scenario.at ? { at: one.at, source: '' } : one))]);
232
+ const blank = blanks.get(emptied) ?? refusals(trial.scenario, wrap(''), judges, rules, parser, slopnators);
233
+ blanks.set(emptied, blank);
234
+ const said = refusals(trial.scenario, wrap(target.source), judges, rules, parser, slopnators);
235
+ spent.set(trial.rule, (spent.get(trial.rule) ?? 0) + Date.now() - began);
236
+ for (const [who, messages] of said) {
237
+ if (who === trial.rule)
238
+ continue;
239
+ for (const message of messages) {
240
+ if (blank.get(who)?.has(message) === true)
241
+ continue;
242
+ found.push({
243
+ id: trial.id + '_under_' + who.replace(/-/g, '_'),
244
+ rule: trial.rule,
245
+ passed: false,
246
+ parsed: true,
247
+ failures: [
248
+ 'the form it recommends is refused by ' + who + ', so this law tells somebody to write what another law bans. ' +
249
+ who + ' said: ' + (message.split('Found: ').pop() ?? message),
250
+ ],
251
+ });
252
+ }
253
+ }
254
+ }
255
+ return found;
256
+ }
233
257
  export function runTrials(trials, all, rules, parser, slopnators) {
234
258
  const byName = new Map(all.map((rule) => [rule.id, rule]));
259
+ const spent = new Map();
235
260
  const outcomes = trials.map((trial) => {
236
261
  const rule = byName.get(trial.rule);
237
262
  const module = rules[trial.rule];
@@ -241,72 +266,19 @@ export function runTrials(trials, all, rules, parser, slopnators) {
241
266
  rule: trial.rule,
242
267
  passed: false,
243
268
  parsed: false,
244
- failures: [`no rule named "${trial.rule}" is registered, so this trial is about nothing — regenerate with \`thread trials\``],
269
+ failures: [`the rule "${trial.rule}" has no slopnator on disk, so this trial is about nothing — the file to write is the one its row names in \`at\``],
245
270
  };
246
271
  }
247
- return runTrial(trial, rule, module, parser, slopnators?.get(slopnatorName(rule.id)));
272
+ const began = Date.now();
273
+ const outcome = runTrial(trial, rule, module, parser, slopnators?.get(slopnatorName(rule.id)));
274
+ spent.set(trial.rule, (spent.get(trial.rule) ?? 0) + Date.now() - began);
275
+ return outcome;
248
276
  });
249
277
  return {
250
278
  outcomes,
251
279
  passed: outcomes.filter((outcome) => outcome.passed).length,
252
280
  failed: outcomes.filter((outcome) => !outcome.passed).length,
253
281
  measured: outcomes.filter((outcome) => outcome.parsed).length,
282
+ spent,
254
283
  };
255
284
  }
256
- if (invoked(import.meta.url)) {
257
- const own = await rules();
258
- const governing = own ?? CONSTRAINTS;
259
- const source = own === undefined
260
- ? `the ${String(CONSTRAINTS.length)} constraint(s) this tree authors`
261
- : `the ${String(own.length)} rule(s) this tree declares — a shipped constraint is proved in the package that ships it, against the paths that package governs`;
262
- const slopnators = await load(ROOT, governing);
263
- const derivation = deriveTrials(governing, slopnators);
264
- const byproduct = trialsByproduct(derivation);
265
- if (process.argv.includes('--check')) {
266
- const path = join(ROOT, byproduct.path);
267
- const current = existsSync(path) ? readFileSync(path, 'utf8') : '';
268
- const drifted = current !== byproduct.content;
269
- if (drifted)
270
- console.error(`trial: ${byproduct.path} is not what the rules derive. Run \`thread trials\` and commit the result.`);
271
- console.log(`trial: ${String(derivation.trials.length)} derived from ${source}, ${String(drifted ? 1 : 0)} findings.`);
272
- exit(drifted ? 1 : 0);
273
- }
274
- if (process.argv.includes('--try')) {
275
- const at = process.argv.indexOf('--rule');
276
- const only = at === -1 ? undefined : (process.argv[at + 1] ?? '').split(',').map((one) => one.trim()).filter(Boolean);
277
- const unknown = (only ?? []).filter((id) => !governing.some((rule) => rule.id === id));
278
- if (unknown.length > 0) {
279
- console.error(`trial: no rule is called ${unknown.join(', ')} — a filter naming nothing would measure nothing and exit 0`);
280
- exit(1);
281
- }
282
- const chosen = only === undefined ? derivation.trials : derivation.trials.filter((trial) => only.includes(trial.rule));
283
- if (chosen.length === 0) {
284
- if (only !== undefined) {
285
- console.error('trial: the filter selected no trials, and measuring nothing must not exit 0');
286
- exit(1);
287
- }
288
- if (governing.length > 0) {
289
- console.error(`trial: ${String(governing.length)} rule(s) govern and none derived a trial — every rule owes a \`wrong\` and a \`right\`, so measuring nothing must not exit 0`);
290
- exit(1);
291
- }
292
- console.log(`trial: nothing to prove — ${source}.`);
293
- exit(0);
294
- }
295
- const { default: plugin } = await import("../lint.js");
296
- const parser = (await import('typescript-eslint')).parser;
297
- const run = runTrials(chosen, governing, plugin.rules, parser, slopnators);
298
- for (const outcome of run.outcomes) {
299
- if (outcome.passed)
300
- continue;
301
- for (const failure of outcome.failures)
302
- console.error(`trial: ${outcome.id} — ${failure}`);
303
- }
304
- console.log(`trial: ${String(run.passed)} of ${String(run.outcomes.length)} passed, ${String(run.measured)} measured.`);
305
- if (only !== undefined) {
306
- console.log(`trial: PARTIAL RUN — ${String(derivation.trials.length - chosen.length)} of ${String(derivation.trials.length)} derived trials did not run. \`thread trials\` with no arguments runs every one.`);
307
- }
308
- exit(run.failed === 0 ? 0 : 1);
309
- }
310
- write(ROOT, byproduct);
311
- console.log(`trial: wrote ${byproduct.path} — ${String(derivation.trials.length)} trials from ${source}.`);
312
- }