@invariantly/cli 0.0.0-stage → 0.0.3

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.
@@ -0,0 +1,125 @@
1
+ import { type Problem } from "./validate.js";
2
+ /** A test (or suite) whose name carries at least one `[INV-NN]` marker. */
3
+ export interface TestLink {
4
+ id: string;
5
+ /** Path relative to the registry's directory, with `/` separators. */
6
+ file: string;
7
+ line: number;
8
+ test: string;
9
+ /** `false` when the test or an enclosing suite is skipped or todo. */
10
+ active: boolean;
11
+ }
12
+ export interface UntestedRule {
13
+ id: string;
14
+ /** Location of the rule in the registry, e.g. "/rules/3". */
15
+ path: string;
16
+ /** How many skipped or todo tests carry this rule's marker. */
17
+ skipped: number;
18
+ }
19
+ export interface CheckResult {
20
+ file: string;
21
+ ok: boolean;
22
+ ruleCount: number;
23
+ /** Registry problems, exactly as `validate` reports them. */
24
+ problems: Problem[];
25
+ testFileCount: number;
26
+ untested: UntestedRule[];
27
+ unknownMarkers: TestLink[];
28
+ links: TestLink[];
29
+ /** Diagnostics that do not change the result, in the order they were found. */
30
+ warnings: Warning[];
31
+ }
32
+ /**
33
+ * A diagnostic that does not change `ok` or the exit code.
34
+ * `code` is an open enum: `pytest-config-invalid`, `pytest-option-ignored`, `lexical-fault`,
35
+ * `skipif-runtime-condition` today; consumers must ignore codes they do not know.
36
+ */
37
+ export interface Warning {
38
+ code: string;
39
+ message: string;
40
+ /** File the warning concerns, relative to the registry's directory, with `/` separators. */
41
+ path: string;
42
+ /** One-based line, present only for a known source location. */
43
+ line?: number;
44
+ }
45
+ /** A `describe`/`it`/`test` call found in a test file. */
46
+ export interface FoundTest {
47
+ kind: "suite" | "test";
48
+ name: string;
49
+ line: number;
50
+ active: boolean;
51
+ /** Markers in this call's own name. */
52
+ ownMarkers: string[];
53
+ /** Own markers plus those of enclosing suites. */
54
+ markers: string[];
55
+ }
56
+ export interface CheckOptions {
57
+ /** Receives diagnostics that do not change the result: lexical faults, configuration problems, `skipif` coverage. */
58
+ warn?: (message: string) => void;
59
+ }
60
+ /**
61
+ * Validates the registry, then links every test file under the registry's directory to its rules.
62
+ * Throws only when the registry, a directory or a test file cannot be read (the CLI turns that into exit 2).
63
+ */
64
+ export declare function checkFile(file: string, schema: object, options?: CheckOptions): Promise<CheckResult>;
65
+ export interface FoundFiles {
66
+ /** vitest/jest test files, relative to the root with `/` separators. */
67
+ js: string[];
68
+ /** Python files that may hold tests (no `venv`/`site-packages` segment, not `conftest.py`). */
69
+ py: string[];
70
+ /** Every directory and file the walk saw, relative, for resolving `testpaths`. */
71
+ seen: Set<string>;
72
+ /** Names of the files directly in the root. */
73
+ rootFiles: Set<string>;
74
+ }
75
+ /** Whether discovery descends into a directory named `name`. */
76
+ export declare function isTestDiscoveryDirectory(name: string): boolean;
77
+ /** Whether discovery considers this regular file as a Python test candidate. */
78
+ export declare function isPythonTestCandidate(rel: string): boolean;
79
+ /** True when `rel` (relative, `/` separators) is a vitest/jest test file that discovery would scan. */
80
+ export declare function isJsTestPath(rel: string): boolean;
81
+ /** Applies `testpaths`, `norecursedirs` and `python_files` to the Python candidates. */
82
+ export declare function selectPythonFiles(found: Pick<FoundFiles, "py" | "seen">, config: PytestConfig): string[];
83
+ /** Finds every test and suite call in a test file. Never evaluates the source. */
84
+ export declare function findTests(source: string): FoundTest[];
85
+ /** A collected pytest test (`kind: "test"`) or test class (`kind: "suite"`). */
86
+ export interface PytestTest extends FoundTest {
87
+ /** An otherwise active test carrying `skipif`: its coverage depends on a runtime condition. */
88
+ conditional: boolean;
89
+ /** Names of literal `pytest.mark.NAME` marks on the test, its classes and its module. */
90
+ marks: string[];
91
+ }
92
+ /** The first lexical fault in a Python file (one-based line and column). */
93
+ export interface LexicalFault {
94
+ line: number;
95
+ column: number;
96
+ message: string;
97
+ }
98
+ /** Where an invariant marker is written: a decorated `def`/`class`, or a `pytestmark` line. */
99
+ export interface MarkerSite {
100
+ ids: string[];
101
+ line: number;
102
+ name: string;
103
+ active: boolean;
104
+ }
105
+ export interface PytestScan {
106
+ tests: PytestTest[];
107
+ sites: MarkerSite[];
108
+ fault?: LexicalFault;
109
+ }
110
+ /** Finds every collected pytest test and test class in a Python file. Never evaluates the source. */
111
+ export declare function findPytestTests(source: string): PytestTest[];
112
+ export declare function scanPytest(source: string): PytestScan;
113
+ export interface PytestConfig {
114
+ /** File the settings came from, or undefined for pytest's defaults. */
115
+ file?: string;
116
+ testpaths: string[];
117
+ pythonFiles: string[];
118
+ norecursedirs: string[];
119
+ /** Mark name deselected by `addopts = -m "not NAME"`. */
120
+ deselect?: string;
121
+ /** Settings present that `check` does not evaluate (they may deselect tests). */
122
+ ignored: string[];
123
+ }
124
+ /** Reads the pytest configuration that applies in `root`; throws when it cannot be used. */
125
+ export declare function readRootPytestConfig(root: string): Promise<PytestConfig>;