@dialecte/cli 0.7.0 → 0.8.1
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/README.md +33 -2194
- package/dist/cli.js +49099 -26727
- package/dist/corpus/manifest.json +692 -0
- package/dist/corpus/overrides/fhir-xhtml.xsd +17 -0
- package/dist/corpus/overrides/xlink.xsd +102 -0
- package/dist/corpus/overrides/xml.xsd +35 -0
- package/dist/dialecte_tdd_pytest.py +792 -0
- package/dist/lookups.d.ts +10 -0
- package/dist/lookups.js +97 -13
- package/dist/schemas/config-list.schema.json +121 -0
- package/dist/schemas/config-yml.schema.json +52 -0
- package/dist/schemas/dialecterc.schema.json +33 -0
- package/dist/schemas/lot-risk.schema.json +32 -0
- package/dist/schemas/risk-line.schema.json +49 -0
- package/dist/schemas/rules.schema.json +51 -0
- package/dist/schemas/scope-change.schema.json +103 -0
- package/dist/tdd-node-reporter.js +167 -0
- package/dist/tdd-reporter.js +2 -0
- package/package.json +25 -6
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// src/lib/tdd/tdd-node-reporter.ts
|
|
2
|
+
import { writeFileSync } from "fs";
|
|
3
|
+
import { resolve, sep } from "path";
|
|
4
|
+
|
|
5
|
+
// src/lib/tdd/tdd.constants.ts
|
|
6
|
+
var NODE_EVENT_TYPES = {
|
|
7
|
+
start: "test:start",
|
|
8
|
+
pass: "test:pass",
|
|
9
|
+
fail: "test:fail",
|
|
10
|
+
stderr: "test:stderr"
|
|
11
|
+
};
|
|
12
|
+
var NODE_TEST_EVENT_TYPES = [
|
|
13
|
+
NODE_EVENT_TYPES.start,
|
|
14
|
+
NODE_EVENT_TYPES.pass,
|
|
15
|
+
NODE_EVENT_TYPES.fail
|
|
16
|
+
];
|
|
17
|
+
var NODE_CODE_FAILURE = "testCodeFailure";
|
|
18
|
+
var NODE_TIMEOUT_FAILURE = "testTimeoutFailure";
|
|
19
|
+
var NODE_TIMEOUT_BOUND_PATTERN = /(\d+)\s*ms/;
|
|
20
|
+
var NODE_TIMEOUT_MESSAGE = "Test timed out in {ms}ms";
|
|
21
|
+
var V8_FRAME_PATTERN = /^\s*at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
22
|
+
var NODE_INTERNAL_FRAME_PREFIX = "node:";
|
|
23
|
+
var BASE_COPY_PYTEST_ARGUMENTS = [
|
|
24
|
+
"-c",
|
|
25
|
+
[
|
|
26
|
+
"import os, sys",
|
|
27
|
+
"folder = sys.argv[1]",
|
|
28
|
+
'current = {"", os.getcwd(), folder}',
|
|
29
|
+
"sys.path[:] = [folder] + [entry for entry in sys.path if entry not in current]",
|
|
30
|
+
'sys.argv = ["pytest"] + sys.argv[2:]',
|
|
31
|
+
"try:",
|
|
32
|
+
" import pytest",
|
|
33
|
+
"except ImportError:",
|
|
34
|
+
' sys.exit("No module named pytest")',
|
|
35
|
+
"sys.exit(pytest.console_main())"
|
|
36
|
+
].join("\n")
|
|
37
|
+
];
|
|
38
|
+
var EDITABLE_PROBE_SCRIPT = [
|
|
39
|
+
"import json, sys",
|
|
40
|
+
"from importlib import metadata",
|
|
41
|
+
"try:",
|
|
42
|
+
" found = metadata.distribution(sys.argv[1])",
|
|
43
|
+
"except metadata.PackageNotFoundError:",
|
|
44
|
+
" sys.exit(0)",
|
|
45
|
+
'direct = json.loads(found.read_text("direct_url.json") or "{}")',
|
|
46
|
+
"paths = [str(path) for path in (found.files or [])]",
|
|
47
|
+
'editable = direct.get("dir_info", {}).get("editable") or any(',
|
|
48
|
+
' "__editable__" in path or path.endswith(".pth") for path in paths',
|
|
49
|
+
")",
|
|
50
|
+
'print("editable" if editable else "installed")'
|
|
51
|
+
].join("\n");
|
|
52
|
+
var CASE_NAME_SEPARATOR = " > ";
|
|
53
|
+
var REPORT_ENVIRONMENT_VARIABLE = "DIALECTE_TDD_REPORT";
|
|
54
|
+
|
|
55
|
+
// src/lib/tdd/tdd-node-reporter.ts
|
|
56
|
+
function readNodeEvents(events) {
|
|
57
|
+
const printed = stderrByFile(events);
|
|
58
|
+
return [...eventsByFile(events)].map(function moduleOf([file, fileEvents]) {
|
|
59
|
+
return readFileEvents({ file, events: fileEvents, printed: printed.get(file) ?? "" });
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async function* tddNodeReporter(source) {
|
|
63
|
+
const events = [];
|
|
64
|
+
for await (const event of source) events.push(event);
|
|
65
|
+
const path = process.env[REPORT_ENVIRONMENT_VARIABLE];
|
|
66
|
+
if (path) writeFileSync(path, JSON.stringify(readNodeEvents(events)));
|
|
67
|
+
yield* [];
|
|
68
|
+
}
|
|
69
|
+
function stderrByFile(events) {
|
|
70
|
+
const printed = /* @__PURE__ */ new Map();
|
|
71
|
+
for (const { type, data } of events) {
|
|
72
|
+
if (type !== NODE_EVENT_TYPES.stderr || data.message === void 0) continue;
|
|
73
|
+
const path = data.entryFile ?? (data.file === void 0 ? void 0 : resolve(data.file));
|
|
74
|
+
if (path !== void 0) printed.set(path, `${printed.get(path) ?? ""}${data.message}`);
|
|
75
|
+
}
|
|
76
|
+
return printed;
|
|
77
|
+
}
|
|
78
|
+
function eventsByFile(events) {
|
|
79
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
80
|
+
for (const event of events) {
|
|
81
|
+
const { file } = event.data;
|
|
82
|
+
if (file === void 0 || event.data.nesting === void 0) continue;
|
|
83
|
+
if (!NODE_TEST_EVENT_TYPES.includes(event.type)) continue;
|
|
84
|
+
const known = byFile.get(file);
|
|
85
|
+
if (known) known.push(event);
|
|
86
|
+
else byFile.set(file, [event]);
|
|
87
|
+
}
|
|
88
|
+
return byFile;
|
|
89
|
+
}
|
|
90
|
+
function readFileEvents(params) {
|
|
91
|
+
const { file } = params;
|
|
92
|
+
const testModule = { file, runner: "node", errors: [], cases: [] };
|
|
93
|
+
const titles = [];
|
|
94
|
+
const casesAtStart = [];
|
|
95
|
+
for (const { type, data } of params.events) {
|
|
96
|
+
const nesting = data.nesting ?? 0;
|
|
97
|
+
if (type === NODE_EVENT_TYPES.start) {
|
|
98
|
+
titles.splice(nesting, titles.length, data.name ?? "");
|
|
99
|
+
casesAtStart.splice(nesting, casesAtStart.length, testModule.cases.length);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const failed = type === NODE_EVENT_TYPES.fail;
|
|
103
|
+
const error = data.details?.error;
|
|
104
|
+
if (isFileTest({ data, file })) {
|
|
105
|
+
if (failed) testModule.errors.push(loadError({ printed: params.printed, error }));
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (data.details?.type === "suite") {
|
|
109
|
+
const casesUnder = testModule.cases.length - (casesAtStart[nesting] ?? 0);
|
|
110
|
+
if (failed && error?.failureType === NODE_CODE_FAILURE && casesUnder === 0)
|
|
111
|
+
testModule.errors.push(reportError(error));
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
testModule.cases.push({
|
|
115
|
+
name: [...titles.slice(0, nesting), data.name ?? ""].join(CASE_NAME_SEPARATOR),
|
|
116
|
+
state: caseStateOf({ data, failed }),
|
|
117
|
+
project: "",
|
|
118
|
+
...data.line !== void 0 && data.column !== void 0 && { location: { line: data.line, column: data.column } },
|
|
119
|
+
errors: failed && error ? [reportError(error)] : []
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return testModule;
|
|
123
|
+
}
|
|
124
|
+
function isFileTest(params) {
|
|
125
|
+
const { data, file } = params;
|
|
126
|
+
if (data.nesting !== 0 || data.details?.type !== "test" || data.name === void 0) return false;
|
|
127
|
+
return file === data.name || file.endsWith(`${sep}${data.name}`) || resolve(data.name) === file;
|
|
128
|
+
}
|
|
129
|
+
function loadError(params) {
|
|
130
|
+
const { printed, error } = params;
|
|
131
|
+
if (printed.trim() !== "") return { message: printed, frames: [] };
|
|
132
|
+
return error ? reportError(error) : { message: "", frames: [] };
|
|
133
|
+
}
|
|
134
|
+
function caseStateOf(params) {
|
|
135
|
+
const { data } = params;
|
|
136
|
+
if (data.todo) return "pending";
|
|
137
|
+
if (data.skip) return "skipped";
|
|
138
|
+
return params.failed ? "failed" : "passed";
|
|
139
|
+
}
|
|
140
|
+
function reportError(error) {
|
|
141
|
+
const { cause } = error;
|
|
142
|
+
const message = typeof cause === "string" ? cause : cause?.message ?? error.message ?? "";
|
|
143
|
+
const name = typeof cause === "object" ? cause.name : void 0;
|
|
144
|
+
const code = typeof cause === "object" ? cause.code : void 0;
|
|
145
|
+
const stack = typeof cause === "object" ? cause.stack : void 0;
|
|
146
|
+
return {
|
|
147
|
+
...name && { name },
|
|
148
|
+
...typeof code === "string" && { code },
|
|
149
|
+
message: error.failureType === NODE_TIMEOUT_FAILURE ? timeoutMessage(message) : message,
|
|
150
|
+
frames: stack === void 0 ? [] : framesOf(stack)
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function timeoutMessage(message) {
|
|
154
|
+
const bound = NODE_TIMEOUT_BOUND_PATTERN.exec(message)?.[1] ?? "0";
|
|
155
|
+
return NODE_TIMEOUT_MESSAGE.replace("{ms}", bound);
|
|
156
|
+
}
|
|
157
|
+
function framesOf(stack) {
|
|
158
|
+
return stack.split("\n").flatMap(function frameOf(line) {
|
|
159
|
+
const matched = V8_FRAME_PATTERN.exec(line);
|
|
160
|
+
if (!matched || matched[1].startsWith(NODE_INTERNAL_FRAME_PREFIX)) return [];
|
|
161
|
+
return [{ file: matched[1], line: Number(matched[2]), column: Number(matched[3]) }];
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
export {
|
|
165
|
+
tddNodeReporter as default,
|
|
166
|
+
readNodeEvents
|
|
167
|
+
};
|
package/dist/tdd-reporter.js
CHANGED
|
@@ -10,6 +10,7 @@ var TddReporter = class {
|
|
|
10
10
|
function reportModule(testModule) {
|
|
11
11
|
return {
|
|
12
12
|
file: testModule.moduleId,
|
|
13
|
+
runner: "vitest",
|
|
13
14
|
errors: testModule.errors().map(reportError),
|
|
14
15
|
cases: [...testModule.children.allTests()].map(function reportCase(testCase) {
|
|
15
16
|
const result = testCase.result();
|
|
@@ -26,6 +27,7 @@ function reportModule(testModule) {
|
|
|
26
27
|
function reportError(error) {
|
|
27
28
|
return {
|
|
28
29
|
...error.name && { name: error.name },
|
|
30
|
+
...typeof error.code === "string" && { code: error.code },
|
|
29
31
|
message: error.message ?? "",
|
|
30
32
|
frames: (error.stacks ?? []).map((frame) => ({
|
|
31
33
|
file: frame.file,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dialecte/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Dialecte CLI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"url": "git+https://github.com/dialecte/cli.git"
|
|
9
9
|
},
|
|
10
10
|
"bin": {
|
|
11
|
-
"dialecte": "
|
|
11
|
+
"dialecte": "dist/cli.js"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"dist",
|
|
@@ -34,13 +34,16 @@
|
|
|
34
34
|
"test:run": "vitest run",
|
|
35
35
|
"test:hook": "node src/cli.ts gate --hook",
|
|
36
36
|
"skills:check": "node src/cli.ts skills check",
|
|
37
|
-
"check": "npm run type-check && npm run lint:check && npm run format:check",
|
|
37
|
+
"check": "npm run type-check && npm run lint:check && npm run format:check && npm run doc:check",
|
|
38
38
|
"prepublishOnly": "node src/release-check.ts && npm run build",
|
|
39
|
-
"prepare": "husky"
|
|
39
|
+
"prepare": "husky",
|
|
40
|
+
"doc:generate": "node src/lib/command-map/command-reference-main.ts",
|
|
41
|
+
"doc:check": "node src/lib/command-map/command-reference-main.ts --check"
|
|
40
42
|
},
|
|
41
43
|
"dependencies": {
|
|
42
44
|
"jsonc-parser": "3.3.1",
|
|
43
|
-
"oxfmt": "^0.75.0"
|
|
45
|
+
"oxfmt": "^0.75.0",
|
|
46
|
+
"yaml": "2.9.1"
|
|
44
47
|
},
|
|
45
48
|
"devDependencies": {
|
|
46
49
|
"@babel/parser": "8.0.7",
|
|
@@ -87,6 +90,17 @@
|
|
|
87
90
|
"scoped": true
|
|
88
91
|
}
|
|
89
92
|
],
|
|
93
|
+
"hook": [
|
|
94
|
+
{
|
|
95
|
+
"name": "check",
|
|
96
|
+
"run": "npm run check"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"name": "rules",
|
|
100
|
+
"run": "node src/cli.ts rules",
|
|
101
|
+
"scoped": true
|
|
102
|
+
}
|
|
103
|
+
],
|
|
90
104
|
"full": [
|
|
91
105
|
{
|
|
92
106
|
"name": "check",
|
|
@@ -139,6 +153,11 @@
|
|
|
139
153
|
"src/lib/handover/sync-node-modules.ts"
|
|
140
154
|
]
|
|
141
155
|
},
|
|
142
|
-
"stepEvents": 1
|
|
156
|
+
"stepEvents": 1,
|
|
157
|
+
"changelog": {
|
|
158
|
+
"asking": [
|
|
159
|
+
"src/lib/command-map/command-map.constants.ts"
|
|
160
|
+
]
|
|
161
|
+
}
|
|
143
162
|
}
|
|
144
163
|
}
|