@hailstails/hone 2.0.0-pre.4 → 2.0.0-pre.6

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 (135) hide show
  1. package/ADOPTING.md +10 -19
  2. package/CHANGELOG.md +46 -0
  3. package/MIGRATING.md +25 -14
  4. package/README.md +3 -4
  5. package/chunks/chunk-2U5EKYGS.js +14348 -0
  6. package/chunks/{chunk-FPIP7JEC.js → chunk-4AJQHZ7I.js} +1 -1
  7. package/chunks/chunk-4PHKVNM3.js +2377 -0
  8. package/chunks/{chunk-CXM5KBZX.js → chunk-6LTJRJOE.js} +1 -1
  9. package/chunks/{chunk-PVSC4SE3.js → chunk-BISP2JOL.js} +4 -6
  10. package/chunks/{chunk-BRANVR7K.js → chunk-FRE5IA3C.js} +1 -1
  11. package/chunks/{chunk-E4D5WDRX.js → chunk-GMLT3MHO.js} +252 -254
  12. package/chunks/chunk-M4VSJ27S.js +139 -0
  13. package/chunks/{chunk-YGMO5Z6U.js → chunk-P2VHWLK4.js} +182 -193
  14. package/chunks/{chunk-LD766VWU.js → chunk-U6W65ZOF.js} +31 -2
  15. package/chunks/{chunk-BKQ3K766.js → chunk-WPEOCLTP.js} +39 -33
  16. package/chunks/{chunk-A3RL4O5V.js → chunk-XNIXPQQ5.js} +35 -2
  17. package/docs/extending.md +2 -2
  18. package/methods/lenses/function-first.md +2 -2
  19. package/package.json +1 -1
  20. package/rules/README.md +5 -3
  21. package/rules/SPIRIT.md +1 -1
  22. package/rules/numbers.md +4 -4
  23. package/rules/principles/no-leak-across-a-boundary.md +1 -1
  24. package/rules/principles.md +1 -1
  25. package/rules/record-kinds/authorised-location.md +1 -1
  26. package/rules/records.md +11 -19
  27. package/rules/rules.md +5 -5
  28. package/rules/sources.md +6 -7
  29. package/rules/typescript/checks.md +55 -387
  30. package/rules/typescript/recipes/adapter-per-outside-party.md +10 -5
  31. package/rules/typescript/recipes/assert-to-narrow.md +114 -4
  32. package/rules/typescript/recipes/closure-factory.md +5 -5
  33. package/rules/typescript/recipes/companion-test-file.md +5 -3
  34. package/rules/typescript/recipes/composed-orchestrator.md +6 -4
  35. package/rules/typescript/recipes/composition-root.md +5 -3
  36. package/rules/typescript/recipes/{bounded-context-generic.md → constrained-context-generic.md} +6 -4
  37. package/rules/typescript/recipes/copy-never-write-in.md +6 -4
  38. package/rules/typescript/recipes/declared-not-bundled.md +5 -3
  39. package/rules/typescript/recipes/dependency-record.md +5 -3
  40. package/rules/typescript/recipes/domain-vocabulary-list.md +5 -3
  41. package/rules/typescript/recipes/entity-module.md +8 -5
  42. package/rules/typescript/recipes/exact-pins-and-a-lock-file.md +5 -3
  43. package/rules/typescript/recipes/extension-outside-the-vendored-code.md +5 -3
  44. package/rules/typescript/recipes/failure-asserted-as-a-value.md +44 -4
  45. package/rules/typescript/recipes/failure-mapping-at-the-adapter.md +8 -5
  46. package/rules/typescript/recipes/fix-the-declaration-not-the-value.md +5 -3
  47. package/rules/typescript/recipes/functional-iteration.md +8 -3
  48. package/rules/typescript/recipes/guard-clauses.md +5 -3
  49. package/rules/typescript/recipes/integration-test-owns-its-scratch.md +5 -3
  50. package/rules/typescript/recipes/integration-test-suffix.md +5 -3
  51. package/rules/typescript/recipes/it-each-over-typed-rows.md +117 -0
  52. package/rules/typescript/recipes/map-out-at-the-adapter.md +36 -4
  53. package/rules/typescript/recipes/meaning-in-names-not-comments.md +5 -5
  54. package/rules/typescript/recipes/named-exported-type.md +5 -3
  55. package/rules/typescript/recipes/narrow-ports.md +5 -3
  56. package/rules/typescript/recipes/one-argument-object.md +8 -3
  57. package/rules/typescript/recipes/{port-in-the-domain.md → port-in-a-module-of-its-own.md} +7 -5
  58. package/rules/typescript/recipes/ports-in-the-argument.md +5 -3
  59. package/rules/typescript/recipes/repo-scripts-only.md +5 -3
  60. package/rules/typescript/recipes/result-union.md +5 -5
  61. package/rules/typescript/recipes/screaming-folders.md +5 -5
  62. package/rules/typescript/recipes/shared-strict-base-config.md +5 -5
  63. package/rules/typescript/recipes/stub-with-vi-fn.md +130 -0
  64. package/rules/typescript/recipes/tagged-union-and-exhaustive-switch.md +5 -3
  65. package/rules/typescript/recipes/whole-words.md +5 -3
  66. package/rules/typescript/recipes/whole-written-out-expectation.md +284 -4
  67. package/rules/typescript/recipes/world-values-through-a-port.md +5 -3
  68. package/rules/typescript/recipes/zod-at-the-producers-adapter.md +8 -3
  69. package/rules/typescript/recipes.md +567 -21
  70. package/rules/typescript/symptoms/ambient-randomness.md +1 -1
  71. package/rules/typescript/symptoms/answer-set-in-a-hook.md +1 -1
  72. package/rules/typescript/symptoms/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site.md +1 -1
  73. package/rules/typescript/symptoms/{assertion-outside-a-test.md → assertion-outside-a-test-body.md} +1 -1
  74. package/rules/typescript/symptoms/branch-in-a-test/test-body.md +10 -184
  75. package/rules/typescript/symptoms/branch-in-a-test.md +11 -1
  76. package/rules/typescript/symptoms/claimed-type/non-null-assertions.md +1 -1
  77. package/rules/typescript/symptoms/{code-or-prose-read-as-text.md → code-or-prose-read-as-text-in-a-test.md} +2 -2
  78. package/rules/typescript/symptoms/computed-value-in-a-test/test-body.md +26 -117
  79. package/rules/typescript/symptoms/computed-value-in-a-test.md +1 -1
  80. package/rules/typescript/symptoms/date-used-directly.md +1 -1
  81. package/rules/typescript/symptoms/default-for-a-required-value.md +1 -1
  82. package/rules/typescript/symptoms/double-with-a-body/logic-in-a-passed-function.md +1 -18
  83. package/rules/typescript/symptoms/double-with-a-body.md +1 -1
  84. package/rules/typescript/symptoms/{export-from-a-test-file.md → export-from-a-test.md} +1 -1
  85. package/rules/typescript/symptoms/failure-shaped-as-success.md +1 -1
  86. package/rules/typescript/symptoms/inherited-environment-in-a-subprocess/git-spawn-environment.md +1 -1
  87. package/rules/typescript/symptoms/inner-layer-imports-outer.md +1 -1
  88. package/rules/typescript/symptoms/library-class-built-in-place.md +1 -1
  89. package/rules/typescript/symptoms/loop-keyword/loop-statement.md +1 -1
  90. package/rules/typescript/symptoms/outside-import-past-a-boundary/import-or-require.md +1 -0
  91. package/rules/typescript/symptoms/outside-import-past-a-boundary.md +5 -4
  92. package/rules/typescript/symptoms/outside-type-in-a-signature.md +2 -2
  93. package/rules/typescript/symptoms/{port-outside-the-domain.md → port-beside-its-adapter.md} +2 -2
  94. package/rules/typescript/symptoms/port-named-for-a-mechanism.md +1 -1
  95. package/rules/typescript/symptoms/process-global-used-in-place.md +1 -1
  96. package/rules/typescript/symptoms/rebinding/test-body.md +1 -18
  97. package/rules/typescript/symptoms/rebinding.md +11 -1
  98. package/rules/typescript/symptoms/schema-past-its-adapter.md +2 -2
  99. package/rules/typescript/symptoms/text-past-its-reader/test-body.md +2 -17
  100. package/rules/typescript/symptoms/text-past-its-reader.md +1 -1
  101. package/rules/typescript/symptoms/throw-or-catch-in-a-test/try-block.md +1 -25
  102. package/rules/typescript/symptoms/type-declared-in-a-test/test-type-declaration.md +1 -1
  103. package/rules/typescript/symptoms/unasserted-call.md +1 -1
  104. package/rules/typescript/symptoms.md +35 -35
  105. package/src/application/conformance/conformance-testing-types.d.ts +2 -0
  106. package/src/domain/language-layer/authored-item-types.d.ts +21 -5
  107. package/src/domain/runner/runner-result-types.d.ts +1 -2
  108. package/src/eslint-plugin.js +40 -38
  109. package/src/hone.js +15 -13638
  110. package/src/infrastructure/disciplines-file/version-one-names.json +4 -5
  111. package/src/infrastructure/engines/eslint/runner/runner.js +56 -70
  112. package/src/infrastructure/engines/walker/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site/assertion-site.js +1 -1
  113. package/src/infrastructure/engines/walker/branch-in-a-test/test-body/test-body-logic.js +39 -65
  114. package/src/infrastructure/engines/walker/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read/raw-read.js +1 -1
  115. package/src/infrastructure/engines/walker/{export-from-a-test-file → export-from-a-test}/test-file-export/test-file-export.js +1 -1
  116. package/src/infrastructure/engines/walker/runner/runner.js +10 -10
  117. package/src/infrastructure/engines/walker/strictness-weakened/strict/compiler-overrides.js +3 -3
  118. package/src/infrastructure/engines/walker/type-declared-in-a-test/test-type-declaration/test-type-declaration.examples.json +15 -3
  119. package/src/infrastructure/engines/walker/type-declared-in-a-test/test-type-declaration/test-type-declaration.js +118 -4
  120. package/src/measure-engines.process.js +80 -0
  121. package/src/testing.d.ts +1 -0
  122. package/src/testing.js +111 -26
  123. package/chunks/chunk-7FVSZ2VL.js +0 -1304
  124. package/chunks/chunk-BIDD2YWP.js +0 -398
  125. package/rules/record-kinds/boundary-record.md +0 -9
  126. package/rules/typescript/recipes/iteach-over-typed-rows.md +0 -18
  127. package/rules/typescript/recipes/stub-with-vifn.md +0 -20
  128. /package/rules/typescript/symptoms/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read.md +0 -0
  129. /package/rules/typescript/symptoms/{export-from-a-test-file → export-from-a-test}/test-file-export.md +0 -0
  130. /package/src/infrastructure/engines/walker/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site/assertion-site.examples.json +0 -0
  131. /package/src/infrastructure/engines/walker/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site/piece.json +0 -0
  132. /package/src/infrastructure/engines/walker/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read/piece.json +0 -0
  133. /package/src/infrastructure/engines/walker/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read/raw-read.examples.json +0 -0
  134. /package/src/infrastructure/engines/walker/{export-from-a-test-file → export-from-a-test}/test-file-export/piece.json +0 -0
  135. /package/src/infrastructure/engines/walker/{export-from-a-test-file → export-from-a-test}/test-file-export/test-file-export.examples.json +0 -0
@@ -8,6 +8,9 @@ import {
8
8
  import "../../../../../../chunks/chunk-DGOLOS5A.js";
9
9
 
10
10
  // src/infrastructure/engines/walker/type-declared-in-a-test/test-type-declaration/test-type-declaration.ts
11
+ var ROW_TABLE_RECEIVERS = /* @__PURE__ */ new Set(["it", "describe"]);
12
+ var ROW_TABLE_METHOD = "each";
13
+ var READONLY_ARRAY = "ReadonlyArray";
11
14
  var enclosingAugmentation = ({
12
15
  syntaxApi,
13
16
  node
@@ -18,10 +21,121 @@ var enclosingAugmentation = ({
18
21
  return container;
19
22
  return enclosingAugmentation({ syntaxApi, node: container });
20
23
  };
21
- var check = syntaxNodeCheck({
22
- eligibility: testFileEligibility,
23
- found: ({ syntaxApi, node, sourceFile }) => (syntaxApi.isTypeAliasDeclaration(node) || syntaxApi.isInterfaceDeclaration(node) || syntaxApi.isEnumDeclaration(node)) && enclosingAugmentation({ syntaxApi, node }) === void 0 ? { at: node, snippet: node.name.getText(sourceFile) } : void 0
24
- });
24
+ var importedNamesOf = (request) => {
25
+ const { syntaxApi, sourceFile } = request;
26
+ return new Set(
27
+ sourceFile.statements.flatMap((statement) => {
28
+ if (!syntaxApi.isImportDeclaration(statement) || statement.importClause === void 0)
29
+ return [];
30
+ const { name, namedBindings } = statement.importClause;
31
+ const named = namedBindings === void 0 || syntaxApi.isNamespaceImport(namedBindings) ? [] : namedBindings.elements.map((element) => element.name.text);
32
+ return name === void 0 ? named : [name.text, ...named];
33
+ })
34
+ );
35
+ };
36
+ var wholeRowPart = (parts) => parts.length > 0 && parts.every((part) => part === "fits-a-row") ? "fits-a-row" : "breaks-a-row";
37
+ var primitiveKeywordPart = ({ syntaxApi, node }) => {
38
+ const { SyntaxKind } = syntaxApi;
39
+ return [
40
+ SyntaxKind.StringKeyword,
41
+ SyntaxKind.NumberKeyword,
42
+ SyntaxKind.BooleanKeyword,
43
+ SyntaxKind.BigIntKeyword,
44
+ SyntaxKind.SymbolKeyword,
45
+ SyntaxKind.UndefinedKeyword
46
+ ].includes(node.kind) || syntaxApi.isLiteralTypeNode(node) && node.literal.kind === SyntaxKind.NullKeyword ? "fits-a-row" : "breaks-a-row";
47
+ };
48
+ var importedTypeReferencePart = (request) => {
49
+ const { syntaxApi, importedNames, node } = request;
50
+ return syntaxApi.isTypeReferenceNode(node) && syntaxApi.isIdentifier(node.typeName) && importedNames.has(node.typeName.text) && (node.typeArguments ?? []).every(
51
+ (argument) => rowMemberPart({ ...request, node: argument }) === "fits-a-row"
52
+ ) ? "fits-a-row" : "breaks-a-row";
53
+ };
54
+ var readonlyListPart = (request) => {
55
+ const { syntaxApi, node } = request;
56
+ if (syntaxApi.isTypeOperatorNode(node))
57
+ return node.operator === syntaxApi.SyntaxKind.ReadonlyKeyword && syntaxApi.isArrayTypeNode(node.type) ? importedTypeReferencePart({ ...request, node: node.type.elementType }) : "breaks-a-row";
58
+ if (!syntaxApi.isTypeReferenceNode(node) || !syntaxApi.isIdentifier(node.typeName) || node.typeName.text !== READONLY_ARRAY)
59
+ return "breaks-a-row";
60
+ const [element, ...others] = node.typeArguments ?? [];
61
+ return element !== void 0 && others.length === 0 ? importedTypeReferencePart({ ...request, node: element }) : "breaks-a-row";
62
+ };
63
+ var rowMemberPart = (request) => [importedTypeReferencePart, readonlyListPart, primitiveKeywordPart].some(
64
+ (partOf) => partOf(request) === "fits-a-row"
65
+ ) ? "fits-a-row" : "breaks-a-row";
66
+ var objectMemberPart = (request) => {
67
+ const { syntaxApi, node } = request;
68
+ return syntaxApi.isPropertySignature(node) && node.type !== void 0 && node.questionToken === void 0 ? rowMemberPart({ ...request, node: node.type }) : "breaks-a-row";
69
+ };
70
+ var tupleElementPart = (request) => {
71
+ const { syntaxApi, node } = request;
72
+ if (!syntaxApi.isNamedTupleMember(node)) return rowMemberPart(request);
73
+ return node.dotDotDotToken === void 0 && node.questionToken === void 0 ? rowMemberPart({ ...request, node: node.type }) : "breaks-a-row";
74
+ };
75
+ var tupleRowPart = (request) => {
76
+ const { syntaxApi, node } = request;
77
+ return syntaxApi.isTupleTypeNode(node) ? wholeRowPart(node.elements.map((element) => tupleElementPart({ ...request, node: element }))) : "breaks-a-row";
78
+ };
79
+ var rowShapePart = (request) => {
80
+ const { syntaxApi, node } = request;
81
+ if (syntaxApi.isTypeOperatorNode(node))
82
+ return node.operator === syntaxApi.SyntaxKind.ReadonlyKeyword ? tupleRowPart({ ...request, node: node.type }) : "breaks-a-row";
83
+ if (syntaxApi.isTypeLiteralNode(node))
84
+ return wholeRowPart(
85
+ node.members.map((member) => objectMemberPart({ ...request, node: member }))
86
+ );
87
+ return tupleRowPart(request);
88
+ };
89
+ var rowUseOf = (request) => {
90
+ const { syntaxApi, identifier } = request;
91
+ const reference = identifier.parent;
92
+ if (!syntaxApi.isTypeReferenceNode(reference) || reference.typeArguments !== void 0)
93
+ return "other-use";
94
+ const call = reference.parent;
95
+ return syntaxApi.isCallExpression(call) && call.typeArguments?.length === 1 && call.typeArguments.includes(reference) && syntaxApi.isPropertyAccessExpression(call.expression) && syntaxApi.isIdentifier(call.expression.expression) && ROW_TABLE_RECEIVERS.has(call.expression.expression.text) && call.expression.name.text === ROW_TABLE_METHOD ? "row-table-argument" : "other-use";
96
+ };
97
+ var useIn = (request) => {
98
+ const { syntaxApi, declared, use } = request;
99
+ return syntaxApi.forEachChild(
100
+ request.node,
101
+ (child) => syntaxApi.isIdentifier(child) && child !== declared && child.text === declared.text && rowUseOf({ syntaxApi, identifier: child }) === use ? use : useIn({ ...request, node: child })
102
+ );
103
+ };
104
+ var rowVerdictOf = (request) => {
105
+ const { syntaxApi, sourceFile, node } = request;
106
+ if (!syntaxApi.isTypeAliasDeclaration(node) || node.parent !== sourceFile || node.typeParameters !== void 0 || node.modifiers?.some((modifier) => modifier.kind === syntaxApi.SyntaxKind.ExportKeyword) === true || rowShapePart({ syntaxApi, importedNames: request.readImportedNames(), node: node.type }) === "breaks-a-row")
107
+ return "flagged";
108
+ const uses = { syntaxApi, node: sourceFile, declared: node.name };
109
+ return useIn({ ...uses, use: "other-use" }) === void 0 && useIn({ ...uses, use: "row-table-argument" }) !== void 0 ? "spared" : "flagged";
110
+ };
111
+ var check = {
112
+ prepare: (request) => {
113
+ const importedNames = /* @__PURE__ */ new WeakMap();
114
+ const importedNamesIn = (visit) => {
115
+ const known = importedNames.get(visit.sourceFile);
116
+ if (known !== void 0) return known;
117
+ const names = importedNamesOf(visit);
118
+ importedNames.set(visit.sourceFile, names);
119
+ return names;
120
+ };
121
+ return syntaxNodeCheck({
122
+ eligibility: testFileEligibility,
123
+ found: ({ syntaxApi, node, sourceFile }) => {
124
+ if (!syntaxApi.isTypeAliasDeclaration(node) && !syntaxApi.isInterfaceDeclaration(node) && !syntaxApi.isEnumDeclaration(node))
125
+ return void 0;
126
+ if (enclosingAugmentation({ syntaxApi, node }) !== void 0) return void 0;
127
+ const verdict = rowVerdictOf({
128
+ syntaxApi,
129
+ sourceFile,
130
+ node,
131
+ readImportedNames: () => importedNamesIn({ syntaxApi, sourceFile })
132
+ });
133
+ if (verdict === "spared") return void 0;
134
+ return { at: node, snippet: node.name.getText(sourceFile) };
135
+ }
136
+ }).prepare(request);
137
+ }
138
+ };
25
139
  export {
26
140
  check
27
141
  };
@@ -0,0 +1,80 @@
1
+ import {
2
+ INSTALLED_PORTS,
3
+ REPLY_PIPE_DESCRIPTOR,
4
+ createDefaultProcessPort,
5
+ measureEngines,
6
+ runEnginesMeasurement,
7
+ versionTwoStagesOver
8
+ } from "../chunks/chunk-2U5EKYGS.js";
9
+ import "../chunks/chunk-4PHKVNM3.js";
10
+ import "../chunks/chunk-P2VHWLK4.js";
11
+ import "../chunks/chunk-XNIXPQQ5.js";
12
+ import "../chunks/chunk-M4VSJ27S.js";
13
+ import "../chunks/chunk-U6W65ZOF.js";
14
+ import "../chunks/chunk-4AJQHZ7I.js";
15
+ import "../chunks/chunk-BISP2JOL.js";
16
+ import "../chunks/chunk-FRE5IA3C.js";
17
+ import "../chunks/chunk-D6645WPB.js";
18
+ import "../chunks/chunk-Z6JHBNDS.js";
19
+ import {
20
+ moduleExtensionOf
21
+ } from "../chunks/chunk-WPEOCLTP.js";
22
+ import "../chunks/chunk-YONPKP3C.js";
23
+ import "../chunks/chunk-OO5KV7KN.js";
24
+ import "../chunks/chunk-RANIXNWY.js";
25
+ import "../chunks/chunk-DGOLOS5A.js";
26
+
27
+ // src/composition/engines-measurement.ts
28
+ var measureInProcess = async (request) => {
29
+ const { tree, ...locations } = request.measuring;
30
+ const stages = versionTwoStagesOver({
31
+ ports: INSTALLED_PORTS,
32
+ locations: {
33
+ ...locations,
34
+ moduleExtension: moduleExtensionOf({ moduleUrl: request.moduleUrl })
35
+ }
36
+ });
37
+ const measured = await measureEngines({
38
+ stages: { ...stages, tree: () => ({ outcome: "ok", value: tree }) }
39
+ });
40
+ return measured.outcome === "failed" ? measured : { outcome: "ok", value: measured.value.runs };
41
+ };
42
+ var runMeasurementProcess = (request) => runEnginesMeasurement({
43
+ process: request.process,
44
+ request: request.request,
45
+ reply: request.reply,
46
+ measure: (measuring) => measureInProcess({ moduleUrl: request.moduleUrl, measuring })
47
+ });
48
+
49
+ // src/infrastructure/node/process/reply-port.ts
50
+ import { writeFileSync } from "node:fs";
51
+ var createReplyPort = (options) => ({
52
+ write: (request) => {
53
+ options.replySurface.writeDescriptor({ descriptor: REPLY_PIPE_DESCRIPTOR, text: request.text });
54
+ }
55
+ });
56
+ var defaultReplySurface = {
57
+ writeDescriptor: (request) => {
58
+ writeFileSync(request.descriptor, request.text);
59
+ }
60
+ };
61
+ var createDefaultReplyPort = () => createReplyPort({ replySurface: defaultReplySurface });
62
+
63
+ // src/infrastructure/node/process/request-port.ts
64
+ import { readFileSync } from "node:fs";
65
+ var STANDARD_INPUT_DESCRIPTOR = 0;
66
+ var createRequestPort = (options) => ({
67
+ read: () => options.requestSurface.readDescriptor({ descriptor: STANDARD_INPUT_DESCRIPTOR })
68
+ });
69
+ var defaultRequestSurface = {
70
+ readDescriptor: (request) => readFileSync(request.descriptor, "utf8")
71
+ };
72
+ var createDefaultRequestPort = () => createRequestPort({ requestSurface: defaultRequestSurface });
73
+
74
+ // src/measure-engines.process.ts
75
+ await runMeasurementProcess({
76
+ process: createDefaultProcessPort({}),
77
+ request: createDefaultRequestPort(),
78
+ reply: createDefaultReplyPort(),
79
+ moduleUrl: import.meta.url
80
+ });
package/src/testing.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { CheckConformanceOf, CheckUnderTestOf, RepoPathOf } from "./application/conformance/conformance-testing-types.js";
2
+ export type { CheckBinding } from "./domain/runner/check-binding.js";
2
3
  export type { CaseUnderTest, CheckRequest, CheckConformanceFailure, CheckUnderTest, ConformanceSetupFailure, ConformanceSetupFailureKind, RuleSetUnderTest, TeamRuleSetUnderTest, } from "./application/conformance/conformance-testing-types.js";
3
4
  export declare const repoPathOf: RepoPathOf;
4
5
  export declare const checkUnderTestOf: CheckUnderTestOf;
package/src/testing.js CHANGED
@@ -1,18 +1,24 @@
1
1
  import {
2
- createNamedConformancePort,
3
- defaultClauseSettings
4
- } from "../chunks/chunk-YGMO5Z6U.js";
2
+ defaultClauseSettings,
3
+ rejectedCall,
4
+ runnerEnginesOver,
5
+ runnerInvalidOutput,
6
+ runnerModuleAt
7
+ } from "../chunks/chunk-P2VHWLK4.js";
5
8
  import {
6
9
  installRootOfApiEntry,
7
10
  loadFailureDetail
8
- } from "../chunks/chunk-A3RL4O5V.js";
11
+ } from "../chunks/chunk-XNIXPQQ5.js";
9
12
  import {
10
13
  checkPieceOf,
11
14
  readNamedPiece,
12
15
  teamRuleSetOf
13
- } from "../chunks/chunk-FPIP7JEC.js";
14
- import "../chunks/chunk-PVSC4SE3.js";
15
- import "../chunks/chunk-BRANVR7K.js";
16
+ } from "../chunks/chunk-4AJQHZ7I.js";
17
+ import {
18
+ caseVerdictSchema,
19
+ runnerResultSchema
20
+ } from "../chunks/chunk-BISP2JOL.js";
21
+ import "../chunks/chunk-FRE5IA3C.js";
16
22
  import "../chunks/chunk-Z6JHBNDS.js";
17
23
  import {
18
24
  TOOL_RULE_SET,
@@ -26,7 +32,7 @@ import {
26
32
  moduleExtensionOf,
27
33
  parsedJson,
28
34
  sourceCaseSchema
29
- } from "../chunks/chunk-BKQ3K766.js";
35
+ } from "../chunks/chunk-WPEOCLTP.js";
30
36
  import {
31
37
  gatheredOutcomes
32
38
  } from "../chunks/chunk-YONPKP3C.js";
@@ -44,6 +50,30 @@ var casesByEdition = (request) => {
44
50
  });
45
51
  };
46
52
 
53
+ // src/application/conformance/create-case-under-test.ts
54
+ var createCaseUnderTest = (request) => ({
55
+ name: request.example.name,
56
+ file: request.example.fileName,
57
+ source: request.example.source,
58
+ edition: request.example.edition ?? request.defaultEdition
59
+ });
60
+
61
+ // src/application/conformance/create-check-binding.ts
62
+ var createCheckBinding = (request) => {
63
+ const { check, ruleSet, engine, piece } = request;
64
+ return {
65
+ address: check,
66
+ ruleSet,
67
+ engine,
68
+ anchor: piece.anchor,
69
+ pieceRoot: piece.pieceRoot,
70
+ settings: piece.settings,
71
+ forms: piece.forms,
72
+ checkSettings: defaultClauseSettings({ declarations: piece.declarations }),
73
+ edition: piece.editions.default
74
+ };
75
+ };
76
+
47
77
  // src/application/conformance/check-conformance.ts
48
78
  var ruleSetInvalid = (request) => ({
49
79
  outcome: "failed",
@@ -98,18 +128,17 @@ var checkUnderTestOf = (request) => {
98
128
  }
99
129
  const { ruleSet, check, engine } = request;
100
130
  const { piece, examples: examples2 } = read.value;
131
+ const binding = createCheckBinding({ check, ruleSet: read.value.ruleSet, engine, piece });
101
132
  return {
102
133
  outcome: "ok",
103
134
  value: {
104
135
  ruleSet,
105
136
  check,
106
137
  engine,
107
- examples: examples2.map((example) => ({
108
- name: example.name,
109
- file: example.fileName,
110
- source: example.source,
111
- edition: example.edition ?? piece.editions.default
112
- }))
138
+ binding,
139
+ examples: examples2.map(
140
+ (example) => createCaseUnderTest({ example, defaultEdition: binding.edition })
141
+ )
113
142
  }
114
143
  };
115
144
  };
@@ -128,17 +157,7 @@ var checkConformanceOf = async (request) => {
128
157
  };
129
158
  }
130
159
  const { piece, examples: examples2, ruleSet } = read.value;
131
- const binding = {
132
- address: request.check,
133
- ruleSet,
134
- engine: mechanism,
135
- anchor: piece.anchor,
136
- pieceRoot: piece.pieceRoot,
137
- settings: piece.settings,
138
- forms: piece.forms,
139
- checkSettings: defaultClauseSettings({ declarations: piece.declarations }),
140
- edition: piece.editions.default
141
- };
160
+ const binding = createCheckBinding({ check: request.check, ruleSet, engine: mechanism, piece });
142
161
  const conformed = gatheredOutcomes({
143
162
  outcomes: await Promise.all(
144
163
  casesByEdition({ cases: examples2, defaultEdition: binding.edition }).map(
@@ -267,6 +286,71 @@ var createNamedCheckExamplesRepository = (ports) => ({
267
286
  read: (request) => readExamples({ ...ports, ...request })
268
287
  });
269
288
 
289
+ // src/infrastructure/engines/protocol/conformance.ts
290
+ import { z as z2 } from "zod";
291
+ var caseVerdictsResultSchema = runnerResultSchema({
292
+ value: z2.array(caseVerdictSchema).readonly()
293
+ });
294
+ var lineSet = (request) => [...new Set(request.lines)].toSorted((left, right) => left - right);
295
+ var verdictsNaming = (request) => request.verdicts.filter((verdict) => verdict.caseName === request.caseName);
296
+ var unmatchedVerdict = (request) => {
297
+ const missing = request.cases.find(
298
+ (sourceCase) => verdictsNaming({ verdicts: request.verdicts, caseName: sourceCase.name }).length !== 1
299
+ );
300
+ if (missing !== void 0) {
301
+ return `case ${missing.name} has no single verdict`;
302
+ }
303
+ const unknown = request.verdicts.find(
304
+ (verdict) => !request.cases.some((sourceCase) => sourceCase.name === verdict.caseName)
305
+ );
306
+ return unknown === void 0 ? void 0 : `a verdict names the unknown case ${unknown.caseName}`;
307
+ };
308
+ var caseConformance = (request) => {
309
+ const { sourceCase } = request;
310
+ const expectedLines = lineSet({ lines: sourceCase.expectedLines });
311
+ const flaggedLines = lineSet({
312
+ lines: verdictsNaming({ verdicts: request.verdicts, caseName: sourceCase.name }).flatMap(
313
+ (verdict) => verdict.flaggedLines
314
+ )
315
+ });
316
+ if (expectedLines.join(" ") === flaggedLines.join(" ")) {
317
+ return [];
318
+ }
319
+ return [{ caseName: sourceCase.name, expectedLines, flaggedLines }];
320
+ };
321
+ var conformanceOf = (request) => {
322
+ const parsed = caseVerdictsResultSchema.safeParse(request.returned);
323
+ if (!parsed.success) {
324
+ return runnerInvalidOutput({ detail: z2.prettifyError(parsed.error) });
325
+ }
326
+ if (parsed.data.outcome === "failed") {
327
+ return parsed.data;
328
+ }
329
+ const verdicts = parsed.data.value;
330
+ const unmatched = unmatchedVerdict({ verdicts, cases: request.cases });
331
+ if (unmatched !== void 0) {
332
+ return runnerInvalidOutput({ detail: unmatched });
333
+ }
334
+ return {
335
+ outcome: "ok",
336
+ value: request.cases.flatMap((sourceCase) => caseConformance({ sourceCase, verdicts }))
337
+ };
338
+ };
339
+ var compareCases = async (request) => Promise.resolve().then(request.act).then(
340
+ (returned) => conformanceOf({ returned, cases: request.cases }),
341
+ (thrown) => rejectedCall({ thrown })
342
+ );
343
+ var namedCheckConformance = async (request) => {
344
+ const compared = await compareCases({
345
+ ...request,
346
+ act: () => request.runner.conform({ binding: request.binding, cases: request.cases })
347
+ });
348
+ return compared.outcome === "failed" ? compared : {
349
+ outcome: "ok",
350
+ value: compared.value.map((failure) => ({ ...failure, check: request.binding.address }))
351
+ };
352
+ };
353
+
270
354
  // src/testing.ts
271
355
  var path = createDefaultPathPort({});
272
356
  var moduleUrl = import.meta.url;
@@ -274,6 +358,7 @@ var installRoot = installRootOfApiEntry({ path, moduleUrl });
274
358
  var fileText = createDefaultFileTextPort({});
275
359
  var modules = createDefaultModuleLoaderPort({});
276
360
  var examples = createNamedCheckExamplesRepository({ fileText, path });
361
+ var { namedEngine } = runnerEnginesOver({ runnerModuleOf: runnerModuleAt });
277
362
  var repoPathOf2 = repoPathOf;
278
363
  var checkUnderTestOf2 = (request) => installRoot.outcome === "failed" ? {
279
364
  outcome: "failed",
@@ -301,7 +386,7 @@ var checkConformanceOf2 = (request) => installRoot.outcome === "failed" ? Promis
301
386
  loadFailureDetail,
302
387
  path,
303
388
  modules,
304
- enginePort: createNamedConformancePort({}),
389
+ enginePort: { load: namedEngine.load, conform: namedCheckConformance },
305
390
  moduleExtension: moduleExtensionOf({ moduleUrl })
306
391
  });
307
392
  export {