@codyswann/lisa 4.97.4 → 4.98.0
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 +42 -75
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/package.json +5 -4
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/rules/reference/derived-branch-plan.md +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-copilot/rules/reference/derived-branch-plan.md +1 -1
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/rules/derived-branch-plan-reference.mdc +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-devin/rules/reference/derived-branch-plan.md +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-openclaw/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-agy/plugin.json +1 -1
- package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-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/plugins/src/base/rules/reference/derived-branch-plan.md +1 -1
- package/scripts/check-phrase-manifest-parity.mjs +83 -0
- package/scripts/classify-phrase-tests.mjs +54 -0
- package/scripts/fix-namespace-test-assertions.mjs +3 -19
- package/scripts/generate-phrase-manifest.mjs +98 -0
- package/scripts/lib/phrase-tests/ast.mjs +147 -0
- package/scripts/lib/phrase-tests/classify.mjs +293 -0
- package/scripts/lib/phrase-tests/fold.mjs +55 -0
- package/scripts/lib/phrase-tests/manifest.mjs +183 -0
- package/scripts/lib/phrase-tests/parity.mjs +74 -0
- package/scripts/lib/phrase-tests/record.mjs +568 -0
- package/scripts/lib/phrase-tests/repo.mjs +99 -0
- package/scripts/lib/phrase-tests/runner.mjs +256 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decide whether a test file is "phrase-only" (CodySwannGT/lisa#4609).
|
|
3
|
+
*
|
|
4
|
+
* The issue's three rules, applied conservatively — a file this rejects stays
|
|
5
|
+
* exactly as it is, so every doubt resolves to "not phrase-only":
|
|
6
|
+
*
|
|
7
|
+
* 1. Its only I/O is reading text files. Imports are limited to the test
|
|
8
|
+
* runner, `path`, `url` and the file-system modules, and the only
|
|
9
|
+
* file-system members it may touch are the read calls.
|
|
10
|
+
* 2. It spawns no process and imports no module under test. A relative
|
|
11
|
+
* import is allowed only when it resolves to a helper inside `tests/`
|
|
12
|
+
* that itself passes rules 1 and 2 (checked transitively), so a helper
|
|
13
|
+
* that reaches into `src/`, `scripts/`, `all/` or `plugins/` rejects the
|
|
14
|
+
* file. `process` may only be used for `process.cwd()`. `require`,
|
|
15
|
+
* dynamic `import()` and `vi` are refused.
|
|
16
|
+
* 3. Every `expect(...)` is a phrase assertion (see `isPhraseChain`), and
|
|
17
|
+
* the test file has at least one. A helper's own `expect` calls must be
|
|
18
|
+
* phrase assertions too.
|
|
19
|
+
* @module scripts/lib/phrase-tests/classify
|
|
20
|
+
*/
|
|
21
|
+
import path from "node:path";
|
|
22
|
+
|
|
23
|
+
import ts from "typescript";
|
|
24
|
+
|
|
25
|
+
import { expectChains, isPhraseChain, parseSource, walk } from "./ast.mjs";
|
|
26
|
+
|
|
27
|
+
/** Package modules a phrase-only file may import. */
|
|
28
|
+
export const ALLOWED_MODULES = Object.freeze([
|
|
29
|
+
"vitest",
|
|
30
|
+
"node:fs",
|
|
31
|
+
"fs",
|
|
32
|
+
"node:fs/promises",
|
|
33
|
+
"fs/promises",
|
|
34
|
+
"fs-extra",
|
|
35
|
+
"node:path",
|
|
36
|
+
"path",
|
|
37
|
+
"node:url",
|
|
38
|
+
"url",
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
/** Modules whose members are file-system calls, checked against READ_CALLS. */
|
|
42
|
+
const FS_MODULES = Object.freeze([
|
|
43
|
+
"node:fs",
|
|
44
|
+
"fs",
|
|
45
|
+
"node:fs/promises",
|
|
46
|
+
"fs/promises",
|
|
47
|
+
"fs-extra",
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
/** The only file-system members a phrase-only file may use. */
|
|
51
|
+
export const READ_CALLS = Object.freeze(["readFileSync", "readFile"]);
|
|
52
|
+
|
|
53
|
+
/** Runner exports that would make a file more than a phrase check. */
|
|
54
|
+
const REFUSED_RUNNER_EXPORTS = Object.freeze(["vi", "vitest", "assert"]);
|
|
55
|
+
|
|
56
|
+
/** Directory a helper must live in to be importable by a phrase-only file. */
|
|
57
|
+
const TESTS_DIR = "tests/";
|
|
58
|
+
|
|
59
|
+
/** Script-module extensions a TypeScript import may spell for a `.ts` file. */
|
|
60
|
+
const JS_EXTENSIONS = Object.freeze([".js", ".mjs", ".cjs"]);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Resolve a relative import from a test file to a repository-relative helper
|
|
64
|
+
* path inside `tests/`, the way TypeScript's bundler resolution would:
|
|
65
|
+
* `./x.js` names `./x.ts`, and a bare `./x` tries `.ts` then `/index.ts`.
|
|
66
|
+
* @param {string} fromFile - Repository-relative importing file.
|
|
67
|
+
* @param {string} specifier - The relative module specifier.
|
|
68
|
+
* @param {(file: string) => boolean} exists - Whether a repo-relative file exists.
|
|
69
|
+
* @returns {string | undefined} The helper path, or undefined when it does not
|
|
70
|
+
* resolve to an existing file under `tests/`.
|
|
71
|
+
*/
|
|
72
|
+
export function resolveTestImport(fromFile, specifier, exists) {
|
|
73
|
+
const target = path.posix.normalize(
|
|
74
|
+
path.posix.join(path.posix.dirname(fromFile), specifier)
|
|
75
|
+
);
|
|
76
|
+
if (!target.startsWith(TESTS_DIR)) return undefined;
|
|
77
|
+
const extension = path.posix.extname(target);
|
|
78
|
+
const stem = JS_EXTENSIONS.includes(extension)
|
|
79
|
+
? target.slice(0, -extension.length)
|
|
80
|
+
: target;
|
|
81
|
+
const candidates = [`${stem}.ts`, `${stem}.mts`, target, `${stem}/index.ts`];
|
|
82
|
+
return candidates.find(candidate => exists(candidate));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The module specifier of an import or re-export, or undefined.
|
|
87
|
+
* @param {ts.Statement} statement - A top-level statement.
|
|
88
|
+
* @returns {string | undefined} The specifier text.
|
|
89
|
+
*/
|
|
90
|
+
function moduleSpecifierOf(statement) {
|
|
91
|
+
const specifier =
|
|
92
|
+
ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement)
|
|
93
|
+
? statement.moduleSpecifier
|
|
94
|
+
: undefined;
|
|
95
|
+
return specifier && ts.isStringLiteral(specifier)
|
|
96
|
+
? specifier.text
|
|
97
|
+
: undefined;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Whether an import or re-export is erased at runtime.
|
|
102
|
+
* @param {ts.Statement} statement - An import or export declaration.
|
|
103
|
+
* @returns {boolean} True for `import type` / `export type`.
|
|
104
|
+
*/
|
|
105
|
+
function isTypeOnly(statement) {
|
|
106
|
+
if (ts.isExportDeclaration(statement)) return statement.isTypeOnly;
|
|
107
|
+
return (
|
|
108
|
+
ts.isImportDeclaration(statement) &&
|
|
109
|
+
statement.importClause?.isTypeOnly === true
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Reasons a package import breaks rules 1 or 2.
|
|
115
|
+
* @param {ts.Statement} statement - One import or re-export.
|
|
116
|
+
* @param {string} specifier - Its (non-relative) module specifier.
|
|
117
|
+
* @param {Set<string>} fsNamespaces - Collects namespace/default fs bindings.
|
|
118
|
+
* @returns {string[]} Zero or more reasons.
|
|
119
|
+
*/
|
|
120
|
+
function packageImportReasons(statement, specifier, fsNamespaces) {
|
|
121
|
+
if (!ALLOWED_MODULES.includes(specifier)) return [`imports ${specifier}`];
|
|
122
|
+
if (!ts.isImportDeclaration(statement)) return [];
|
|
123
|
+
const clause = statement.importClause;
|
|
124
|
+
const isFs = FS_MODULES.includes(specifier);
|
|
125
|
+
if (isFs && clause?.name) fsNamespaces.add(clause.name.text);
|
|
126
|
+
const bindings = clause?.namedBindings;
|
|
127
|
+
if (bindings && ts.isNamespaceImport(bindings)) {
|
|
128
|
+
if (isFs) fsNamespaces.add(bindings.name.text);
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
const named =
|
|
132
|
+
bindings && ts.isNamedImports(bindings) ? bindings.elements : [];
|
|
133
|
+
return named.flatMap(element => {
|
|
134
|
+
const imported = (element.propertyName ?? element.name).text;
|
|
135
|
+
if (isFs && !READ_CALLS.includes(imported)) return [`uses fs.${imported}`];
|
|
136
|
+
if (specifier === "vitest" && REFUSED_RUNNER_EXPORTS.includes(imported))
|
|
137
|
+
return [`imports ${imported} from vitest`];
|
|
138
|
+
return [];
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Reasons a single node breaks rule 1 or 2 outside the import list.
|
|
144
|
+
* @param {ts.Node} node - Any node.
|
|
145
|
+
* @param {Set<string>} fsNamespaces - Namespace/default fs bindings.
|
|
146
|
+
* @returns {string | undefined} A reason, or undefined when the node is fine.
|
|
147
|
+
*/
|
|
148
|
+
function nodeReason(node, fsNamespaces) {
|
|
149
|
+
if (node.kind === ts.SyntaxKind.ImportKeyword) return "dynamic import()";
|
|
150
|
+
if (ts.isIdentifier(node)) {
|
|
151
|
+
if (node.text === "require") return "require()";
|
|
152
|
+
return fsNamespaces.has(node.text) ? fsNamespaceReason(node) : undefined;
|
|
153
|
+
}
|
|
154
|
+
if (!ts.isPropertyAccessExpression(node)) return undefined;
|
|
155
|
+
const owner = node.expression;
|
|
156
|
+
if (!ts.isIdentifier(owner)) return undefined;
|
|
157
|
+
const member = node.name.text;
|
|
158
|
+
if (owner.text === "process" && member !== "cwd") return `process.${member}`;
|
|
159
|
+
if (owner.text === "expect") return `expect.${member}`;
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* A namespace or default `fs` binding may only be used as `fs.readFileSync`,
|
|
165
|
+
* `fs.readFile` or `fs.promises.readFile`. Any other use — destructuring,
|
|
166
|
+
* element access, passing the module along — could reach a write, so it
|
|
167
|
+
* rejects the file.
|
|
168
|
+
* @param {ts.Identifier} identifier - A reference to an fs binding.
|
|
169
|
+
* @returns {string | undefined} A reason, or undefined for a read.
|
|
170
|
+
*/
|
|
171
|
+
function fsNamespaceReason(identifier) {
|
|
172
|
+
const parent = identifier.parent;
|
|
173
|
+
if (ts.isImportClause(parent) || ts.isNamespaceImport(parent)) {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
if (ts.isPropertyAccessExpression(parent) && parent.name === identifier) {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
if (!ts.isPropertyAccessExpression(parent)) {
|
|
180
|
+
return `uses the ${identifier.text} module other than to read`;
|
|
181
|
+
}
|
|
182
|
+
const member = parent.name.text;
|
|
183
|
+
if (READ_CALLS.includes(member)) return undefined;
|
|
184
|
+
return member === "promises" ? promisesReason(parent) : `uses fs.${member}`;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* `fs.promises.readFile` is a read; any other `fs.promises.*` is not.
|
|
189
|
+
* @param {ts.PropertyAccessExpression} node - The `fs.promises` access.
|
|
190
|
+
* @returns {string | undefined} A reason, or undefined for a read.
|
|
191
|
+
*/
|
|
192
|
+
function promisesReason(node) {
|
|
193
|
+
const parent = node.parent;
|
|
194
|
+
return ts.isPropertyAccessExpression(parent) &&
|
|
195
|
+
READ_CALLS.includes(parent.name.text)
|
|
196
|
+
? undefined
|
|
197
|
+
: "uses fs.promises";
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* @typedef {object} Analysis
|
|
202
|
+
* @property {string[]} reasons - Rule breaches in this file or its helpers.
|
|
203
|
+
* @property {number} assertions - `expect(...)` sites in this file itself.
|
|
204
|
+
* @property {string[]} helpers - Helper files reached, transitively.
|
|
205
|
+
*/
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Reasons one relative import breaks rule 2, following it into the helper.
|
|
209
|
+
* @param {string} fileName - The importing file.
|
|
210
|
+
* @param {string} specifier - The relative specifier.
|
|
211
|
+
* @param {(file: string) => string | undefined} readSource - Reads a repo file.
|
|
212
|
+
* @param {Set<string>} seen - Files already analysed.
|
|
213
|
+
* @param {string[]} helpers - Collects every helper reached.
|
|
214
|
+
* @returns {string[]} Zero or more reasons.
|
|
215
|
+
*/
|
|
216
|
+
function helperReasons(fileName, specifier, readSource, seen, helpers) {
|
|
217
|
+
const helper = resolveTestImport(
|
|
218
|
+
fileName,
|
|
219
|
+
specifier,
|
|
220
|
+
file => readSource(file) !== undefined
|
|
221
|
+
);
|
|
222
|
+
if (helper === undefined) {
|
|
223
|
+
return [`imports ${specifier} (not a readable helper under tests/)`];
|
|
224
|
+
}
|
|
225
|
+
if (seen.has(helper)) return [];
|
|
226
|
+
helpers.push(helper);
|
|
227
|
+
const inner = analyse(helper, readSource(helper) ?? "", readSource, seen);
|
|
228
|
+
helpers.push(...inner.helpers);
|
|
229
|
+
return inner.reasons.map(reason => `helper ${helper}: ${reason}`);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Analyse one file (test or helper) and, through its relative imports, every
|
|
234
|
+
* helper it reaches.
|
|
235
|
+
* @param {string} fileName - Repository-relative path.
|
|
236
|
+
* @param {string} text - Its contents.
|
|
237
|
+
* @param {(file: string) => string | undefined} readSource - Reads a repo file.
|
|
238
|
+
* @param {Set<string>} seen - Files already analysed, to stop import cycles.
|
|
239
|
+
* @returns {Analysis} What the file and its helpers break.
|
|
240
|
+
*/
|
|
241
|
+
function analyse(fileName, text, readSource, seen) {
|
|
242
|
+
seen.add(fileName);
|
|
243
|
+
const sourceFile = parseSource(fileName, text);
|
|
244
|
+
/** @type {Set<string>} */
|
|
245
|
+
const fsNamespaces = new Set();
|
|
246
|
+
/** @type {string[]} */
|
|
247
|
+
const helpers = [];
|
|
248
|
+
const reasons = sourceFile.statements.flatMap(statement => {
|
|
249
|
+
const specifier = moduleSpecifierOf(statement);
|
|
250
|
+
if (specifier === undefined || isTypeOnly(statement)) return [];
|
|
251
|
+
return specifier.startsWith(".")
|
|
252
|
+
? helperReasons(fileName, specifier, readSource, seen, helpers)
|
|
253
|
+
: packageImportReasons(statement, specifier, fsNamespaces);
|
|
254
|
+
});
|
|
255
|
+
walk(sourceFile, node => {
|
|
256
|
+
const reason = nodeReason(node, fsNamespaces);
|
|
257
|
+
if (reason) reasons.push(reason);
|
|
258
|
+
});
|
|
259
|
+
const chains = expectChains(sourceFile);
|
|
260
|
+
const nonPhrase = chains.filter(chain => !isPhraseChain(chain)).length;
|
|
261
|
+
if (nonPhrase > 0) reasons.push(`${nonPhrase} non-phrase assertion(s)`);
|
|
262
|
+
return { reasons, assertions: chains.length, helpers };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Classify one test file.
|
|
267
|
+
* @param {string} fileName - Repository-relative path of the test file.
|
|
268
|
+
* @param {string} text - Its contents.
|
|
269
|
+
* @param {(file: string) => string | undefined} [readSource] - Reads a
|
|
270
|
+
* repository-relative file, for following relative helper imports. Without
|
|
271
|
+
* it, every relative import rejects the file.
|
|
272
|
+
* @returns {{ file: string, phraseOnly: boolean, assertions: number, reasons: string[], helpers: string[] }} The verdict.
|
|
273
|
+
*/
|
|
274
|
+
export function classifyTestSource(
|
|
275
|
+
fileName,
|
|
276
|
+
text,
|
|
277
|
+
readSource = () => undefined
|
|
278
|
+
) {
|
|
279
|
+
const { reasons, assertions, helpers } = analyse(
|
|
280
|
+
fileName,
|
|
281
|
+
text,
|
|
282
|
+
readSource,
|
|
283
|
+
new Set()
|
|
284
|
+
);
|
|
285
|
+
if (assertions === 0) reasons.push("no assertions");
|
|
286
|
+
return {
|
|
287
|
+
file: fileName,
|
|
288
|
+
phraseOnly: reasons.length === 0,
|
|
289
|
+
assertions,
|
|
290
|
+
reasons: [...new Set(reasons)],
|
|
291
|
+
helpers: [...new Set(helpers)],
|
|
292
|
+
};
|
|
293
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classify and record a set of test files in one pass (CodySwannGT/lisa#4609).
|
|
3
|
+
* Shared by the one-time generator (working tree) and the parity check (a
|
|
4
|
+
* base commit), so both translate exactly the same way.
|
|
5
|
+
* @module scripts/lib/phrase-tests/fold
|
|
6
|
+
*/
|
|
7
|
+
import { classifyTestSource } from "./classify.mjs";
|
|
8
|
+
import { entryKey } from "./manifest.mjs";
|
|
9
|
+
import { recordTestFile } from "./record.mjs";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {import("./record.mjs").Recording} Recording
|
|
13
|
+
* @typedef {object} Fold
|
|
14
|
+
* @property {number} testFiles - Test files considered.
|
|
15
|
+
* @property {Recording[]} recordings - One per phrase-only file, in path order.
|
|
16
|
+
* @property {Recording[]} translated - Recordings with no reasons.
|
|
17
|
+
* @property {Recording[]} untranslatable - Recordings with reasons.
|
|
18
|
+
* @property {number} raw - Runtime phrase assertions in translated files.
|
|
19
|
+
* @property {Set<string>} keys - Deduped (file, polarity, kind, value) keys of translated files.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Classify `files` and record every phrase-only one.
|
|
24
|
+
* @param {readonly string[]} files - Repository-relative test files.
|
|
25
|
+
* @param {object} options - Where to read.
|
|
26
|
+
* @param {string} options.root - Repository root whose text files the tests read.
|
|
27
|
+
* @param {(file: string) => string | undefined} options.readSource - Reads test and helper sources.
|
|
28
|
+
* @returns {Promise<Fold>} The fold.
|
|
29
|
+
*/
|
|
30
|
+
export async function foldPhraseTests(files, { root, readSource }) {
|
|
31
|
+
const phraseOnly = files.filter(
|
|
32
|
+
file =>
|
|
33
|
+
classifyTestSource(file, readSource(file) ?? "", readSource).phraseOnly
|
|
34
|
+
);
|
|
35
|
+
/** @type {Recording[]} */
|
|
36
|
+
const recordings = [];
|
|
37
|
+
for (const file of phraseOnly) {
|
|
38
|
+
recordings.push(await recordTestFile(file, { root, readSource }));
|
|
39
|
+
}
|
|
40
|
+
const translated = recordings.filter(
|
|
41
|
+
recording => recording.reasons.length === 0
|
|
42
|
+
);
|
|
43
|
+
return {
|
|
44
|
+
testFiles: files.length,
|
|
45
|
+
recordings,
|
|
46
|
+
translated,
|
|
47
|
+
untranslatable: recordings.filter(
|
|
48
|
+
recording => recording.reasons.length > 0
|
|
49
|
+
),
|
|
50
|
+
raw: translated.reduce((sum, recording) => sum + recording.raw, 0),
|
|
51
|
+
keys: new Set(
|
|
52
|
+
translated.flatMap(recording => recording.entries.map(entryKey))
|
|
53
|
+
),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The required-phrases manifest (CodySwannGT/lisa#4609): its shape, how
|
|
3
|
+
* recorded entries fold into it, how it flattens back into one check per
|
|
4
|
+
* (file, phrase), and the failure message for one check.
|
|
5
|
+
*
|
|
6
|
+
* Shared by the one-time generator, the re-runnable parity check and the
|
|
7
|
+
* data-driven test, so all three agree on what an entry is.
|
|
8
|
+
* @module scripts/lib/phrase-tests/manifest
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Repository-relative path of the manifest. */
|
|
12
|
+
export const MANIFEST_PATH = "tests/phrase-manifest/required-phrases.json";
|
|
13
|
+
|
|
14
|
+
/** Explains the file to whoever opens it. */
|
|
15
|
+
export const MANIFEST_COMMENT = Object.freeze([
|
|
16
|
+
"Phrases that must (required) or must not (forbidden) appear in each file, checked by tests/unit/docs/required-phrases.test.ts.",
|
|
17
|
+
"Generated ONCE by scripts/generate-phrase-manifest.mjs from the phrase-only test files it replaced (CodySwannGT/lisa#4609); those files are deleted, so it cannot be regenerated.",
|
|
18
|
+
"It is now the hand-maintained source of truth: add, change or remove phrases here directly, keeping keys and arrays sorted.",
|
|
19
|
+
"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
|
+
]);
|
|
21
|
+
|
|
22
|
+
/** Separates the test file from the test title in a `source` entry. */
|
|
23
|
+
export const SOURCE_SEPARATOR = " › ";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The test file a `source` entry names.
|
|
27
|
+
* @param {string} source - `<test file> › <title>`.
|
|
28
|
+
* @returns {string} The test file.
|
|
29
|
+
*/
|
|
30
|
+
export function sourceTestFile(source) {
|
|
31
|
+
const at = source.indexOf(SOURCE_SEPARATOR);
|
|
32
|
+
return at === -1 ? source : source.slice(0, at);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {{ source: string, flags: string }} Pattern
|
|
37
|
+
* @typedef {{ required: string[], forbidden: string[], requiredPatterns: Pattern[], forbiddenPatterns: Pattern[], source: string[] }} FileEntry
|
|
38
|
+
* @typedef {{ $comment: readonly string[], files: Record<string, FileEntry> }} Manifest
|
|
39
|
+
* @typedef {{ file: string, polarity: "required" | "forbidden", kind: "string" | "pattern", value: string | Pattern }} PhraseCheck
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The FileEntry array a check belongs in.
|
|
44
|
+
* @param {Pick<PhraseCheck, "polarity" | "kind">} check - The check.
|
|
45
|
+
* @returns {"required" | "forbidden" | "requiredPatterns" | "forbiddenPatterns"} The key.
|
|
46
|
+
*/
|
|
47
|
+
function bucket({ polarity, kind }) {
|
|
48
|
+
return kind === "string" ? polarity : `${polarity}Patterns`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A stable, unique key for a check.
|
|
53
|
+
* @param {PhraseCheck} check - The check.
|
|
54
|
+
* @returns {string} The key.
|
|
55
|
+
*/
|
|
56
|
+
export function entryKey({ file, polarity, kind, value }) {
|
|
57
|
+
return JSON.stringify([file, polarity, kind, value]);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Sort and dedupe values by their JSON form.
|
|
62
|
+
* @template T
|
|
63
|
+
* @param {T[]} values - Values.
|
|
64
|
+
* @returns {T[]} Sorted unique values.
|
|
65
|
+
*/
|
|
66
|
+
function sortedUnique(values) {
|
|
67
|
+
const byKey = new Map(values.map(value => [JSON.stringify(value), value]));
|
|
68
|
+
return [...byKey.keys()].sort().map(key => /** @type {T} */ (byKey.get(key)));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Fold recordings into a manifest: keyed by the file read, every array sorted
|
|
73
|
+
* and deduped, each file listing the tests its phrases came from.
|
|
74
|
+
* @param {readonly { entries: readonly (PhraseCheck & { source: string })[] }[]} recordings - Translated recordings.
|
|
75
|
+
* @returns {Manifest} The manifest.
|
|
76
|
+
*/
|
|
77
|
+
export function buildManifest(recordings) {
|
|
78
|
+
/** @type {Map<string, FileEntry>} */
|
|
79
|
+
const files = new Map();
|
|
80
|
+
for (const entry of recordings.flatMap(recording => recording.entries)) {
|
|
81
|
+
const current = files.get(entry.file) ?? {
|
|
82
|
+
required: [],
|
|
83
|
+
forbidden: [],
|
|
84
|
+
requiredPatterns: [],
|
|
85
|
+
forbiddenPatterns: [],
|
|
86
|
+
source: [],
|
|
87
|
+
};
|
|
88
|
+
/** @type {unknown[]} */ (current[bucket(entry)]).push(entry.value);
|
|
89
|
+
current.source.push(entry.source);
|
|
90
|
+
files.set(entry.file, current);
|
|
91
|
+
}
|
|
92
|
+
const sorted = [...files.keys()].sort().map(file => {
|
|
93
|
+
const entry = /** @type {FileEntry} */ (files.get(file));
|
|
94
|
+
return [
|
|
95
|
+
file,
|
|
96
|
+
{
|
|
97
|
+
required: sortedUnique(entry.required),
|
|
98
|
+
forbidden: sortedUnique(entry.forbidden),
|
|
99
|
+
requiredPatterns: sortedUnique(entry.requiredPatterns),
|
|
100
|
+
forbiddenPatterns: sortedUnique(entry.forbiddenPatterns),
|
|
101
|
+
source: sortedUnique(entry.source),
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
});
|
|
105
|
+
return { $comment: MANIFEST_COMMENT, files: Object.fromEntries(sorted) };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Flatten a manifest into one check per (file, phrase), in manifest order.
|
|
110
|
+
* @param {Manifest} manifest - The manifest.
|
|
111
|
+
* @returns {PhraseCheck[]} The checks.
|
|
112
|
+
*/
|
|
113
|
+
export function manifestEntries(manifest) {
|
|
114
|
+
return /** @type {PhraseCheck[]} */ (
|
|
115
|
+
Object.entries(manifest.files).flatMap(([file, entry]) => [
|
|
116
|
+
...entry.required.map(value => ({
|
|
117
|
+
file,
|
|
118
|
+
polarity: "required",
|
|
119
|
+
kind: "string",
|
|
120
|
+
value,
|
|
121
|
+
})),
|
|
122
|
+
...entry.forbidden.map(value => ({
|
|
123
|
+
file,
|
|
124
|
+
polarity: "forbidden",
|
|
125
|
+
kind: "string",
|
|
126
|
+
value,
|
|
127
|
+
})),
|
|
128
|
+
...entry.requiredPatterns.map(value => ({
|
|
129
|
+
file,
|
|
130
|
+
polarity: "required",
|
|
131
|
+
kind: "pattern",
|
|
132
|
+
value,
|
|
133
|
+
})),
|
|
134
|
+
...entry.forbiddenPatterns.map(value => ({
|
|
135
|
+
file,
|
|
136
|
+
polarity: "forbidden",
|
|
137
|
+
kind: "pattern",
|
|
138
|
+
value,
|
|
139
|
+
})),
|
|
140
|
+
])
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* How a phrase reads in a message: a JSON string, or `/source/flags`.
|
|
146
|
+
* @param {PhraseCheck} check - The check.
|
|
147
|
+
* @returns {string} Display form.
|
|
148
|
+
*/
|
|
149
|
+
export function describePhrase({ kind, value }) {
|
|
150
|
+
if (kind === "string") return JSON.stringify(value);
|
|
151
|
+
const pattern = /** @type {Pattern} */ (value);
|
|
152
|
+
return `/${pattern.source}/${pattern.flags}`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Check one phrase against a file's text.
|
|
157
|
+
* @param {string | undefined} text - The file's text, or undefined when it does not exist.
|
|
158
|
+
* @param {PhraseCheck} check - The check.
|
|
159
|
+
* @returns {string | undefined} A failure message naming the file and the
|
|
160
|
+
* phrase, or undefined when the check holds.
|
|
161
|
+
*/
|
|
162
|
+
export function phraseFailure(text, check) {
|
|
163
|
+
if (text === undefined) {
|
|
164
|
+
return `${check.file} does not exist, but the required-phrases manifest lists it`;
|
|
165
|
+
}
|
|
166
|
+
const phrase = describePhrase(check);
|
|
167
|
+
const found =
|
|
168
|
+
check.kind === "string"
|
|
169
|
+
? text.includes(/** @type {string} */ (check.value))
|
|
170
|
+
: text.match(
|
|
171
|
+
new RegExp(
|
|
172
|
+
/** @type {Pattern} */ (check.value).source,
|
|
173
|
+
/** @type {Pattern} */ (check.value).flags
|
|
174
|
+
)
|
|
175
|
+
) !== null;
|
|
176
|
+
if (check.polarity === "required" && !found) {
|
|
177
|
+
return `${check.file} is missing required ${check.kind === "string" ? "phrase" : "pattern"} ${phrase}`;
|
|
178
|
+
}
|
|
179
|
+
if (check.polarity === "forbidden" && found) {
|
|
180
|
+
return `${check.file} contains forbidden ${check.kind === "string" ? "phrase" : "pattern"} ${phrase}`;
|
|
181
|
+
}
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The verdict of the manifest parity check (CodySwannGT/lisa#4609), kept
|
|
3
|
+
* separate from the CLI so every way it can fail is unit-tested.
|
|
4
|
+
*
|
|
5
|
+
* The check must never pass vacuously. It fails when:
|
|
6
|
+
* - the base deletes no test file at all (a base already past the fold
|
|
7
|
+
* proves nothing);
|
|
8
|
+
* - a deleted test file was not phrase-only, or was phrase-only but not
|
|
9
|
+
* fully translatable (it should have been kept);
|
|
10
|
+
* - the deleted phrase-only files are not exactly the test files the
|
|
11
|
+
* manifest's `source` entries name;
|
|
12
|
+
* - any assertion of a deleted file is missing from the manifest;
|
|
13
|
+
* - with `exact`, the manifest holds an entry no deleted file asserted.
|
|
14
|
+
* @module scripts/lib/phrase-tests/parity
|
|
15
|
+
*/
|
|
16
|
+
import { entryKey, manifestEntries, sourceTestFile } from "./manifest.mjs";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Elements of `left` that are not in `right`.
|
|
20
|
+
* @param {Iterable<string>} left - Candidates.
|
|
21
|
+
* @param {Set<string>} right - Reference.
|
|
22
|
+
* @returns {string[]} The difference, sorted.
|
|
23
|
+
*/
|
|
24
|
+
function minus(left, right) {
|
|
25
|
+
return [...left].filter(item => !right.has(item)).sort();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Every way the fold fails to match the manifest.
|
|
30
|
+
* @param {object} input - What to compare.
|
|
31
|
+
* @param {readonly string[]} input.deleted - Test files at the base but not at HEAD.
|
|
32
|
+
* @param {import("./fold.mjs").Fold} input.fold - Their classification and recording.
|
|
33
|
+
* @param {import("./manifest.mjs").Manifest} input.manifest - The manifest.
|
|
34
|
+
* @param {boolean} input.exact - Also fail on manifest entries no deleted file asserted.
|
|
35
|
+
* @returns {string[]} Failure messages; empty when parity holds.
|
|
36
|
+
*/
|
|
37
|
+
export function parityFailures({ deleted, fold, manifest, exact }) {
|
|
38
|
+
const manifestKeys = new Set(manifestEntries(manifest).map(entryKey));
|
|
39
|
+
const sources = new Set(
|
|
40
|
+
Object.values(manifest.files).flatMap(entry =>
|
|
41
|
+
entry.source.map(sourceTestFile)
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
const recorded = new Set(fold.recordings.map(recording => recording.file));
|
|
45
|
+
return [
|
|
46
|
+
...(deleted.length === 0
|
|
47
|
+
? [
|
|
48
|
+
`no test file is deleted between the base and HEAD, so nothing is proved; use the commit before the fold as --base (the manifest came from ${[...sources].sort().slice(0, 3).join(", ")}${sources.size > 3 ? ", ..." : ""})`,
|
|
49
|
+
]
|
|
50
|
+
: []),
|
|
51
|
+
...minus(deleted, recorded).map(
|
|
52
|
+
file => `deleted but not phrase-only: ${file}`
|
|
53
|
+
),
|
|
54
|
+
...fold.untranslatable.map(
|
|
55
|
+
({ file, reasons }) =>
|
|
56
|
+
`deleted but not translatable: ${file}\n ${reasons.slice(0, 3).join("\n ")}`
|
|
57
|
+
),
|
|
58
|
+
...minus(sources, recorded).map(
|
|
59
|
+
file =>
|
|
60
|
+
`the manifest names ${file} as a source, but it is not a deleted phrase-only file`
|
|
61
|
+
),
|
|
62
|
+
...minus(recorded, sources).map(
|
|
63
|
+
file => `deleted phrase-only ${file} is not a source of the manifest`
|
|
64
|
+
),
|
|
65
|
+
...minus(fold.keys, manifestKeys).map(
|
|
66
|
+
key => `missing from the manifest: ${key}`
|
|
67
|
+
),
|
|
68
|
+
...(exact
|
|
69
|
+
? minus(manifestKeys, fold.keys).map(
|
|
70
|
+
key => `in the manifest but asserted by no deleted file: ${key}`
|
|
71
|
+
)
|
|
72
|
+
: []),
|
|
73
|
+
];
|
|
74
|
+
}
|