@codyswann/lisa 5.2.0 → 5.2.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/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +29 -59
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/package.json +4 -5
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
- package/scripts/check-phrase-manifest-parity.mjs +6 -3
- package/scripts/classify-phrase-tests.mjs +109 -20
- package/scripts/fix-namespace-test-assertions.mjs +3 -20
- package/scripts/lib/phrase-tests/doc-taint.mjs +708 -0
- package/scripts/lib/phrase-tests/inventory.mjs +381 -0
- package/scripts/lib/phrase-tests/manifest.mjs +14 -2
- package/scripts/lib/phrase-tests/marker-classes.mjs +323 -0
- package/scripts/lib/phrase-tests/redact.mjs +88 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classify every Markdown phrase assertion (CodySwannGT/lisa#4867): each
|
|
3
|
+
* required-phrases manifest entry, and each `toContain` / `toMatch` site in a
|
|
4
|
+
* unit test that reads a Markdown document. The class of each phrase comes
|
|
5
|
+
* from `marker-classes.mjs`; this module only finds the phrases.
|
|
6
|
+
* @module scripts/lib/phrase-tests/inventory
|
|
7
|
+
*/
|
|
8
|
+
import ts from "typescript";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
booleanLiteral,
|
|
12
|
+
expectChains,
|
|
13
|
+
isPhraseChain,
|
|
14
|
+
parseSource,
|
|
15
|
+
walk,
|
|
16
|
+
} from "./ast.mjs";
|
|
17
|
+
import {
|
|
18
|
+
MANIFEST_COMMENT,
|
|
19
|
+
manifestEntries,
|
|
20
|
+
SOURCE_GUARDS_COMMENT,
|
|
21
|
+
} from "./manifest.mjs";
|
|
22
|
+
import {
|
|
23
|
+
analyseDocTaint,
|
|
24
|
+
mentionsDocumentPath,
|
|
25
|
+
subjectSource,
|
|
26
|
+
} from "./doc-taint.mjs";
|
|
27
|
+
import { classifyPhrase } from "./marker-classes.mjs";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {{ cls: string, rule: string, parser: readonly string[] }} PhraseVerdict
|
|
31
|
+
* @typedef {object} AssertionVerdict
|
|
32
|
+
* @property {string} file - The test file.
|
|
33
|
+
* @property {number} line - 1-based line of the assertion.
|
|
34
|
+
* @property {string} matcher - `toContain`, `not.toMatch`, `includes` ...
|
|
35
|
+
* @property {string} subject - Source text of the `expect(...)` argument.
|
|
36
|
+
* @property {"markdown" | "other" | "unknown"} source - Where that text comes from.
|
|
37
|
+
* @property {"string" | "pattern" | "expression"} kind - What the phrase is.
|
|
38
|
+
* @property {string | { source: string, flags: string }} value - The phrase,
|
|
39
|
+
* or the argument's source text when it is not a literal.
|
|
40
|
+
* @property {string} cls - Its class.
|
|
41
|
+
* @property {string} rule - The rule that decided the class.
|
|
42
|
+
* @property {readonly string[]} parser - The parser behind a MACHINE-TOKEN.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/** Phrases pinned in a file that is not a Markdown document. */
|
|
46
|
+
const NOT_MARKDOWN = "NOT-MARKDOWN";
|
|
47
|
+
|
|
48
|
+
/** Classes a report counts, in display order. */
|
|
49
|
+
export const REPORT_CLASSES = Object.freeze([
|
|
50
|
+
"MACHINE-TOKEN",
|
|
51
|
+
"STRUCTURAL",
|
|
52
|
+
"WORDING",
|
|
53
|
+
"UNRESOLVED",
|
|
54
|
+
NOT_MARKDOWN,
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
/** A Markdown document: the only kind of file whose wording this culls. */
|
|
58
|
+
const MARKDOWN_FILE = /\.mdc?$/u;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Count verdicts by class, every class present even when zero.
|
|
62
|
+
* @param {readonly { cls: string }[]} verdicts - Classified phrases.
|
|
63
|
+
* @returns {Record<string, number>} Counts keyed by class.
|
|
64
|
+
*/
|
|
65
|
+
export function countByClass(verdicts) {
|
|
66
|
+
/** @type {Record<string, number>} */
|
|
67
|
+
const counts = Object.fromEntries(REPORT_CLASSES.map(cls => [cls, 0]));
|
|
68
|
+
for (const { cls } of verdicts) counts[cls] = (counts[cls] ?? 0) + 1;
|
|
69
|
+
return counts;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Count assertion sites by where their subject text comes from.
|
|
74
|
+
* @param {readonly { source: string }[]} sites - Classified sites.
|
|
75
|
+
* @returns {Record<string, number>} Counts for markdown, other and unknown.
|
|
76
|
+
*/
|
|
77
|
+
export function countBySource(sites) {
|
|
78
|
+
/** @type {Record<string, number>} */
|
|
79
|
+
const counts = { markdown: 0, other: 0, unknown: 0 };
|
|
80
|
+
for (const { source } of sites) counts[source] = (counts[source] ?? 0) + 1;
|
|
81
|
+
return counts;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Classify one manifest check. A check on a file that is not a Markdown
|
|
86
|
+
* document — a workflow, a hook, a script — is NOT-MARKDOWN: it pins source
|
|
87
|
+
* text, not guidance prose, and is outside what CodySwannGT/lisa#4867 culls.
|
|
88
|
+
* @param {import("./manifest.mjs").PhraseCheck} check - The check.
|
|
89
|
+
* @returns {{ cls: string, rule: string, parser: readonly string[] }} Its class.
|
|
90
|
+
*/
|
|
91
|
+
export function classifyCheck(check) {
|
|
92
|
+
if (!MARKDOWN_FILE.test(check.file)) {
|
|
93
|
+
return { cls: NOT_MARKDOWN, rule: "not-a-markdown-document", parser: [] };
|
|
94
|
+
}
|
|
95
|
+
return check.kind === "string"
|
|
96
|
+
? classifyPhrase(/** @type {string} */ (check.value))
|
|
97
|
+
: classifyPhrase(
|
|
98
|
+
/** @type {import("./manifest.mjs").Pattern} */ (check.value).source,
|
|
99
|
+
{ isPattern: true }
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Classify every entry of the required-phrases manifest.
|
|
105
|
+
* @param {import("./manifest.mjs").Manifest} manifest - The manifest.
|
|
106
|
+
* @returns {{ files: number, entries: number, counts: Record<string, number>, verdicts: (import("./manifest.mjs").PhraseCheck & PhraseVerdict)[] }} The report.
|
|
107
|
+
*/
|
|
108
|
+
export function classifyManifest(manifest) {
|
|
109
|
+
const verdicts = manifestEntries(manifest).map(check => ({
|
|
110
|
+
...check,
|
|
111
|
+
...classifyCheck(check),
|
|
112
|
+
}));
|
|
113
|
+
return {
|
|
114
|
+
files: Object.keys(manifest.files).length,
|
|
115
|
+
entries: verdicts.length,
|
|
116
|
+
counts: countByClass(verdicts),
|
|
117
|
+
verdicts,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Classes that may stay in the required-phrases manifest. */
|
|
122
|
+
export const LOAD_BEARING = Object.freeze(["MACHINE-TOKEN", "STRUCTURAL"]);
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The entries of a manifest whose class passes `keep`, dropping every file
|
|
126
|
+
* left with none.
|
|
127
|
+
* @param {import("./manifest.mjs").Manifest} manifest - The manifest.
|
|
128
|
+
* @param {(cls: string) => boolean} keep - Which classes to keep.
|
|
129
|
+
* @param {readonly string[]} comment - The `$comment` of the result.
|
|
130
|
+
* @returns {import("./manifest.mjs").Manifest} The selected manifest.
|
|
131
|
+
*/
|
|
132
|
+
export function selectEntries(manifest, keep, comment) {
|
|
133
|
+
const kept =
|
|
134
|
+
(
|
|
135
|
+
/** @type {string} */ file,
|
|
136
|
+
/** @type {"required" | "forbidden"} */ polarity,
|
|
137
|
+
/** @type {"string" | "pattern"} */ kind
|
|
138
|
+
) =>
|
|
139
|
+
(/** @type {any} */ value) =>
|
|
140
|
+
keep(classifyCheck({ file, polarity, kind, value }).cls);
|
|
141
|
+
const files = Object.entries(manifest.files).flatMap(([file, entry]) => {
|
|
142
|
+
const selected = {
|
|
143
|
+
required: entry.required.filter(kept(file, "required", "string")),
|
|
144
|
+
forbidden: entry.forbidden.filter(kept(file, "forbidden", "string")),
|
|
145
|
+
requiredPatterns: entry.requiredPatterns.filter(
|
|
146
|
+
kept(file, "required", "pattern")
|
|
147
|
+
),
|
|
148
|
+
forbiddenPatterns: entry.forbiddenPatterns.filter(
|
|
149
|
+
kept(file, "forbidden", "pattern")
|
|
150
|
+
),
|
|
151
|
+
source: entry.source,
|
|
152
|
+
};
|
|
153
|
+
const empty =
|
|
154
|
+
selected.required.length +
|
|
155
|
+
selected.forbidden.length +
|
|
156
|
+
selected.requiredPatterns.length +
|
|
157
|
+
selected.forbiddenPatterns.length ===
|
|
158
|
+
0;
|
|
159
|
+
return empty ? [] : [[file, selected]];
|
|
160
|
+
});
|
|
161
|
+
return { $comment: comment, files: Object.fromEntries(files) };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Split a manifest: its MACHINE-TOKEN and STRUCTURAL entries stay as the
|
|
166
|
+
* required-phrases manifest, its NOT-MARKDOWN entries move to the
|
|
167
|
+
* source-text guards, and its WORDING entries are dropped.
|
|
168
|
+
*
|
|
169
|
+
* The guards already on disk are merged, never replaced: after the first
|
|
170
|
+
* run the manifest holds no NOT-MARKDOWN entries, so a second run would
|
|
171
|
+
* otherwise write an empty guards file. Running it again is a no-op.
|
|
172
|
+
* @param {import("./manifest.mjs").Manifest} manifest - The manifest.
|
|
173
|
+
* @param {import("./manifest.mjs").Manifest} [existingGuards] - The
|
|
174
|
+
* source-text guards file as it stands, if there is one.
|
|
175
|
+
* @returns {{ manifest: import("./manifest.mjs").Manifest, sourceGuards: import("./manifest.mjs").Manifest }} The two files.
|
|
176
|
+
*/
|
|
177
|
+
export function pruneManifest(manifest, existingGuards) {
|
|
178
|
+
const found = selectEntries(
|
|
179
|
+
manifest,
|
|
180
|
+
cls => cls === NOT_MARKDOWN,
|
|
181
|
+
SOURCE_GUARDS_COMMENT
|
|
182
|
+
);
|
|
183
|
+
return {
|
|
184
|
+
manifest: selectEntries(
|
|
185
|
+
manifest,
|
|
186
|
+
cls => LOAD_BEARING.includes(cls),
|
|
187
|
+
MANIFEST_COMMENT
|
|
188
|
+
),
|
|
189
|
+
sourceGuards: existingGuards
|
|
190
|
+
? mergeManifests(existingGuards, found, SOURCE_GUARDS_COMMENT)
|
|
191
|
+
: found,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** The arrays of a manifest file entry. */
|
|
196
|
+
const ENTRY_KEYS = /** @type {const} */ ([
|
|
197
|
+
"required",
|
|
198
|
+
"forbidden",
|
|
199
|
+
"requiredPatterns",
|
|
200
|
+
"forbiddenPatterns",
|
|
201
|
+
"source",
|
|
202
|
+
]);
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Append the values of `more` that `base` lacks, keeping `base` in order.
|
|
206
|
+
* @param {readonly unknown[]} base - Existing values.
|
|
207
|
+
* @param {readonly unknown[]} more - Values to add.
|
|
208
|
+
* @returns {unknown[]} The union.
|
|
209
|
+
*/
|
|
210
|
+
function union(base, more) {
|
|
211
|
+
const seen = new Set(base.map(value => JSON.stringify(value)));
|
|
212
|
+
return [...base, ...more.filter(value => !seen.has(JSON.stringify(value)))];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Merge two manifests. Every value in `base` stays where it is and new
|
|
217
|
+
* values are appended, so merging nothing new returns `base` unchanged.
|
|
218
|
+
* @param {import("./manifest.mjs").Manifest} base - The manifest kept.
|
|
219
|
+
* @param {import("./manifest.mjs").Manifest} more - Entries to add.
|
|
220
|
+
* @param {readonly string[]} comment - The `$comment` of the result.
|
|
221
|
+
* @returns {import("./manifest.mjs").Manifest} The merged manifest.
|
|
222
|
+
*/
|
|
223
|
+
export function mergeManifests(base, more, comment) {
|
|
224
|
+
const files = { ...base.files };
|
|
225
|
+
for (const [file, entry] of Object.entries(more.files)) {
|
|
226
|
+
const current = files[file];
|
|
227
|
+
files[file] = current
|
|
228
|
+
? /** @type {import("./manifest.mjs").FileEntry} */ (
|
|
229
|
+
Object.fromEntries(
|
|
230
|
+
ENTRY_KEYS.map(key => [key, union(current[key], entry[key])])
|
|
231
|
+
)
|
|
232
|
+
)
|
|
233
|
+
: entry;
|
|
234
|
+
}
|
|
235
|
+
const sorted = Object.keys(files)
|
|
236
|
+
.sort()
|
|
237
|
+
.map(file => [file, files[file]]);
|
|
238
|
+
return { $comment: comment, files: Object.fromEntries(sorted) };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Calls that read a file's text. */
|
|
242
|
+
const READ_CALLS = /\b(?:readFileSync|readFile)\b/u;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Whether a test file reads a Markdown document: it spells a `.md` / `.mdc`
|
|
246
|
+
* extension and a document root in its literals and calls a file read.
|
|
247
|
+
* @param {ts.SourceFile} sourceFile - The parsed test file.
|
|
248
|
+
* @returns {boolean} True when the file reads Markdown.
|
|
249
|
+
*/
|
|
250
|
+
export function readsMarkdown(sourceFile) {
|
|
251
|
+
return READ_CALLS.test(sourceFile.text) && mentionsDocumentPath(sourceFile);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* `const NAME = <string or regex literal>` bindings in a file, so an
|
|
256
|
+
* assertion that names a constant still resolves to its phrase.
|
|
257
|
+
* @param {ts.SourceFile} sourceFile - The parsed test file.
|
|
258
|
+
* @returns {Map<string, ts.Expression>} Initialisers keyed by name.
|
|
259
|
+
*/
|
|
260
|
+
function constantLiterals(sourceFile) {
|
|
261
|
+
/** @type {Map<string, ts.Expression>} */
|
|
262
|
+
const constants = new Map();
|
|
263
|
+
/** @type {Set<string>} */
|
|
264
|
+
const shadowed = new Set();
|
|
265
|
+
walk(sourceFile, node => {
|
|
266
|
+
if (
|
|
267
|
+
ts.isVariableDeclaration(node) &&
|
|
268
|
+
ts.isIdentifier(node.name) &&
|
|
269
|
+
node.initializer &&
|
|
270
|
+
ts.isVarConst(node)
|
|
271
|
+
) {
|
|
272
|
+
const name = node.name.text;
|
|
273
|
+
if (constants.has(name) || shadowed.has(name)) {
|
|
274
|
+
constants.delete(name);
|
|
275
|
+
shadowed.add(name);
|
|
276
|
+
} else {
|
|
277
|
+
constants.set(name, node.initializer);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
return constants;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* The phrase an assertion argument spells, if it is a literal.
|
|
286
|
+
* @param {ts.Expression | undefined} node - The argument.
|
|
287
|
+
* @param {Map<string, ts.Expression>} constants - File constants.
|
|
288
|
+
* @returns {{ kind: "string", value: string } | { kind: "pattern", value: { source: string, flags: string } } | undefined} The phrase.
|
|
289
|
+
*/
|
|
290
|
+
export function literalPhrase(node, constants) {
|
|
291
|
+
if (node === undefined) return undefined;
|
|
292
|
+
if (ts.isStringLiteralLike(node)) return { kind: "string", value: node.text };
|
|
293
|
+
if (node.kind === ts.SyntaxKind.RegularExpressionLiteral) {
|
|
294
|
+
const text = node.getText();
|
|
295
|
+
const end = text.lastIndexOf("/");
|
|
296
|
+
return {
|
|
297
|
+
kind: "pattern",
|
|
298
|
+
value: { source: text.slice(1, end), flags: text.slice(end + 1) },
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
if (ts.isIdentifier(node) && constants.has(node.text)) {
|
|
302
|
+
const initializer = constants.get(node.text);
|
|
303
|
+
return initializer === node
|
|
304
|
+
? undefined
|
|
305
|
+
: literalPhrase(initializer, new Map());
|
|
306
|
+
}
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* The argument and polarity of one phrase chain: `toContain(x)` /
|
|
312
|
+
* `toMatch(x)`, or `<text>.includes(x)` checked with `toBe(true|false)`.
|
|
313
|
+
* @param {ReturnType<typeof import("./ast.mjs").readExpectChain>} chain - A phrase chain.
|
|
314
|
+
* @returns {{ argument: ts.Expression | undefined, negated: boolean, matcher: string }} The parts.
|
|
315
|
+
*/
|
|
316
|
+
export function phraseParts(chain) {
|
|
317
|
+
if (chain.matcher !== "toBe") {
|
|
318
|
+
return {
|
|
319
|
+
argument: chain.args[0],
|
|
320
|
+
negated: chain.negated,
|
|
321
|
+
matcher: chain.matcher ?? "",
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
const includes = /** @type {ts.CallExpression} */ (chain.subject);
|
|
325
|
+
const expected = booleanLiteral(chain.args[0]);
|
|
326
|
+
return {
|
|
327
|
+
// Not a boolean literal: the polarity is unknown, so leave the
|
|
328
|
+
// argument unset and let the site report UNRESOLVED.
|
|
329
|
+
argument: expected === undefined ? undefined : includes.arguments[0],
|
|
330
|
+
negated: expected === chain.negated,
|
|
331
|
+
matcher: "includes",
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Classify every phrase assertion in a test file that reads Markdown.
|
|
337
|
+
* @param {string} fileName - Repository-relative test path.
|
|
338
|
+
* @param {string} text - Its contents.
|
|
339
|
+
* @returns {AssertionVerdict[]} One verdict per phrase assertion site; empty when the
|
|
340
|
+
* file reads no Markdown. `source` says whether the asserted text is a
|
|
341
|
+
* Markdown document ("markdown"), something else such as script output
|
|
342
|
+
* ("other"), or could not be traced ("unknown"); only "markdown" sites are
|
|
343
|
+
* Markdown wording assertions.
|
|
344
|
+
*/
|
|
345
|
+
export function classifyAssertions(fileName, text) {
|
|
346
|
+
const sourceFile = parseSource(fileName, text);
|
|
347
|
+
if (!readsMarkdown(sourceFile)) return [];
|
|
348
|
+
const constants = constantLiterals(sourceFile);
|
|
349
|
+
const taint = analyseDocTaint(sourceFile);
|
|
350
|
+
return expectChains(sourceFile)
|
|
351
|
+
.filter(isPhraseChain)
|
|
352
|
+
.map(chain => {
|
|
353
|
+
const { argument, negated, matcher } = phraseParts(chain);
|
|
354
|
+
const phrase = literalPhrase(argument, constants);
|
|
355
|
+
const line =
|
|
356
|
+
sourceFile.getLineAndCharacterOfPosition(chain.site.getStart()).line +
|
|
357
|
+
1;
|
|
358
|
+
const base = {
|
|
359
|
+
file: fileName,
|
|
360
|
+
line,
|
|
361
|
+
matcher: negated ? `not.${matcher}` : matcher,
|
|
362
|
+
subject: chain.subject?.getText(sourceFile) ?? "",
|
|
363
|
+
source: subjectSource(chain.subject, taint),
|
|
364
|
+
};
|
|
365
|
+
if (phrase === undefined) {
|
|
366
|
+
return {
|
|
367
|
+
...base,
|
|
368
|
+
kind: "expression",
|
|
369
|
+
value: argument?.getText(sourceFile) ?? "",
|
|
370
|
+
cls: "UNRESOLVED",
|
|
371
|
+
rule: "argument-not-literal",
|
|
372
|
+
parser: [],
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
const verdict =
|
|
376
|
+
phrase.kind === "string"
|
|
377
|
+
? classifyPhrase(phrase.value)
|
|
378
|
+
: classifyPhrase(phrase.value.source, { isPattern: true });
|
|
379
|
+
return { ...base, ...phrase, ...verdict };
|
|
380
|
+
});
|
|
381
|
+
}
|
|
@@ -11,11 +11,23 @@
|
|
|
11
11
|
/** Repository-relative path of the manifest. */
|
|
12
12
|
export const MANIFEST_PATH = "tests/phrase-manifest/required-phrases.json";
|
|
13
13
|
|
|
14
|
+
/** Repository-relative path of the non-Markdown source-text guards. */
|
|
15
|
+
export const SOURCE_GUARDS_PATH =
|
|
16
|
+
"tests/phrase-manifest/source-text-guards.json";
|
|
17
|
+
|
|
18
|
+
/** Explains the source-text guards file to whoever opens it. */
|
|
19
|
+
export const SOURCE_GUARDS_COMMENT = Object.freeze([
|
|
20
|
+
"Phrases that must (required) or must not (forbidden) appear in files that are NOT Markdown documents — workflows, hooks, scripts — checked by tests/unit/docs/required-phrases.test.ts.",
|
|
21
|
+
"These guard source text, not guidance prose, so they are outside CodySwannGT/lisa#4867's Markdown cull; they were split out of required-phrases.json so that file holds only MACHINE-TOKEN and STRUCTURAL entries. A Markdown file listed here fails the test.",
|
|
22
|
+
"Same schema as required-phrases.json; hand-maintained, so keep keys and arrays sorted. Patterns are RegExp { source, flags } with String#match semantics.",
|
|
23
|
+
]);
|
|
24
|
+
|
|
14
25
|
/** Explains the file to whoever opens it. */
|
|
15
26
|
export const MANIFEST_COMMENT = Object.freeze([
|
|
16
27
|
"Phrases that must (required) or must not (forbidden) appear in each file, checked by tests/unit/docs/required-phrases.test.ts.",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
28
|
+
"Only load-bearing phrases belong here (CodySwannGT/lisa#4867): a MACHINE-TOKEN that shipped code parses, or a STRUCTURAL frontmatter line. Guidance wording needs review, not a test, so any other class fails the test. Guards on non-Markdown files live in tests/phrase-manifest/source-text-guards.json.",
|
|
29
|
+
"The classes and the parser behind each token are in scripts/lib/phrase-tests/marker-classes.mjs; `node scripts/classify-phrase-tests.mjs --classify-manifest` classifies every entry.",
|
|
30
|
+
"First generated by scripts/generate-phrase-manifest.mjs from deleted phrase-only tests (CodySwannGT/lisa#4609), then pruned to its load-bearing entries; it is hand-maintained, so keep keys and arrays sorted.",
|
|
19
31
|
"Patterns are RegExp { source, flags } and use String#match semantics. `source` lists the deleted tests each file's phrases came from, as `<test file> › <describe > it title>`.",
|
|
20
32
|
]);
|
|
21
33
|
|