@boringparts/verule 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/dist/additional-inputs.d.ts +13 -0
- package/dist/additional-inputs.js +68 -0
- package/dist/cli-command-identity.d.ts +13 -0
- package/dist/cli-command-identity.js +15 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +42 -0
- package/dist/config-loader.d.ts +14 -0
- package/dist/config-loader.js +105 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/inline-ignore.d.ts +44 -0
- package/dist/inline-ignore.js +297 -0
- package/dist/main.d.ts +12 -0
- package/dist/main.js +594 -0
- package/dist/observation.d.ts +111 -0
- package/dist/observation.js +767 -0
- package/dist/projects.d.ts +21 -0
- package/dist/projects.js +168 -0
- package/dist/report-wire.d.ts +1623 -0
- package/dist/report-wire.js +738 -0
- package/dist/session-command.d.ts +48 -0
- package/dist/session-command.js +73 -0
- package/dist/session.d.ts +18 -0
- package/dist/session.js +812 -0
- package/dist/shared-session.d.ts +13 -0
- package/dist/shared-session.js +338 -0
- package/dist/types.d.ts +328 -0
- package/dist/types.js +41 -0
- package/dist/watch-command.d.ts +839 -0
- package/dist/watch-command.js +104 -0
- package/dist/watch.d.ts +59 -0
- package/dist/watch.js +806 -0
- package/package.json +44 -3
- package/README.md +0 -3
package/dist/session.js
ADDED
|
@@ -0,0 +1,812 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { performance } from "node:perf_hooks";
|
|
5
|
+
import { defineAdapter as tssaeDefineAdapter, defineModel as tssaeDefineModel, extractBasisEvidence, openProject, syntaxLocationOf, } from "tssae";
|
|
6
|
+
import { createAdditionalInputRegistry, createScopedAdditionalInputRegistrar, validateAdditionalInputPaths, } from "./additional-inputs.js";
|
|
7
|
+
import { INLINE_IGNORE_RULE_ID, parseInlineIgnoreDirectives, resolveInlineIgnores, } from "./inline-ignore.js";
|
|
8
|
+
import { ObservationCollector, normalizeObserveConfig, normalizeTargetSpec, } from "./observation.js";
|
|
9
|
+
import { buildDiagnostics, buildGaps, resolveProjectEntries, } from "./projects.js";
|
|
10
|
+
import { REPORT_SCHEMA_VERSION, VeruleExecutionError, toVeruleError, } from "./types.js";
|
|
11
|
+
// Watch needs these paths for hashing without adding them to the public project summary.
|
|
12
|
+
const sessionWorkspaceFileStates = new WeakMap();
|
|
13
|
+
/** Returns all workspace source file paths tracked by the active session for file watching. */
|
|
14
|
+
export function getSessionWorkspaceFiles(session) {
|
|
15
|
+
return sessionWorkspaceFileStates.get(session)?.files ?? [];
|
|
16
|
+
}
|
|
17
|
+
function canonicalizeDir(dirPath) {
|
|
18
|
+
if (!existsSync(dirPath))
|
|
19
|
+
return dirPath;
|
|
20
|
+
try {
|
|
21
|
+
return realpathSync.native(dirPath);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return dirPath;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function invokeProjectQuery(fn) {
|
|
28
|
+
try {
|
|
29
|
+
return await fn();
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
throw toVeruleError(err);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function invokeProjectSync(fn) {
|
|
36
|
+
try {
|
|
37
|
+
return fn();
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
throw toVeruleError(err);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function validateRules(rules) {
|
|
44
|
+
const seen = new Set();
|
|
45
|
+
for (const rule of rules) {
|
|
46
|
+
if (typeof rule.id !== "string" || rule.id.trim() === "") {
|
|
47
|
+
throw new VeruleExecutionError("INVALID_CONFIG", "Each rule must have a non-empty string id.");
|
|
48
|
+
}
|
|
49
|
+
if (seen.has(rule.id)) {
|
|
50
|
+
throw new VeruleExecutionError("INVALID_CONFIG", `Duplicate rule id: "${rule.id}".`);
|
|
51
|
+
}
|
|
52
|
+
if (rule.id === INLINE_IGNORE_RULE_ID) {
|
|
53
|
+
throw new VeruleExecutionError("INVALID_CONFIG", `Rule id "${INLINE_IGNORE_RULE_ID}" is reserved.`);
|
|
54
|
+
}
|
|
55
|
+
if (typeof rule.run !== "function") {
|
|
56
|
+
throw new VeruleExecutionError("INVALID_CONFIG", `Rule "${rule.id}" must provide a run function.`);
|
|
57
|
+
}
|
|
58
|
+
seen.add(rule.id);
|
|
59
|
+
}
|
|
60
|
+
return [...rules];
|
|
61
|
+
}
|
|
62
|
+
/** Validates a project model definition and attaches provenance metadata. */
|
|
63
|
+
export function defineModel(model) {
|
|
64
|
+
return invokeProjectSync(() => tssaeDefineModel(model));
|
|
65
|
+
}
|
|
66
|
+
function validateModels(models) {
|
|
67
|
+
const seen = new Set();
|
|
68
|
+
const validated = [];
|
|
69
|
+
for (const model of models) {
|
|
70
|
+
const normalized = defineModel(model);
|
|
71
|
+
if (seen.has(normalized.id)) {
|
|
72
|
+
throw new VeruleExecutionError("INVALID_CONFIG", `Duplicate model id: "${normalized.id}".`);
|
|
73
|
+
}
|
|
74
|
+
seen.add(normalized.id);
|
|
75
|
+
validated.push(normalized);
|
|
76
|
+
}
|
|
77
|
+
return validated;
|
|
78
|
+
}
|
|
79
|
+
function validateAdapters(adapters) {
|
|
80
|
+
const seen = new Set();
|
|
81
|
+
const validated = [];
|
|
82
|
+
for (const adapter of adapters) {
|
|
83
|
+
const normalized = invokeProjectSync(() => tssaeDefineAdapter(adapter));
|
|
84
|
+
if (seen.has(normalized.id)) {
|
|
85
|
+
throw new VeruleExecutionError("INVALID_CONFIG", `Duplicate adapter id: "${normalized.id}".`);
|
|
86
|
+
}
|
|
87
|
+
seen.add(normalized.id);
|
|
88
|
+
validated.push(normalized);
|
|
89
|
+
}
|
|
90
|
+
return validated;
|
|
91
|
+
}
|
|
92
|
+
function validateAdapterPackageNames(packageNames) {
|
|
93
|
+
const seen = new Set();
|
|
94
|
+
const normalized = [];
|
|
95
|
+
for (const rawName of packageNames) {
|
|
96
|
+
if (typeof rawName !== "string" || rawName.trim() === "") {
|
|
97
|
+
throw new VeruleExecutionError("INVALID_CONFIG", "Adapter package names must be non-empty strings.");
|
|
98
|
+
}
|
|
99
|
+
const packageName = rawName.trim();
|
|
100
|
+
if (seen.has(packageName)) {
|
|
101
|
+
throw new VeruleExecutionError("INVALID_CONFIG", `Duplicate adapter package name: "${packageName}".`);
|
|
102
|
+
}
|
|
103
|
+
seen.add(packageName);
|
|
104
|
+
normalized.push(packageName);
|
|
105
|
+
}
|
|
106
|
+
return normalized;
|
|
107
|
+
}
|
|
108
|
+
function selectRules(baseRules, ruleIds) {
|
|
109
|
+
if (!ruleIds || ruleIds.length === 0) {
|
|
110
|
+
return baseRules;
|
|
111
|
+
}
|
|
112
|
+
const byId = new Map(baseRules.map((rule) => [rule.id, rule]));
|
|
113
|
+
const selected = [];
|
|
114
|
+
const seen = new Set();
|
|
115
|
+
for (const id of ruleIds) {
|
|
116
|
+
const found = byId.get(id);
|
|
117
|
+
if (!found) {
|
|
118
|
+
throw new VeruleExecutionError("INVALID_CONFIG", `Unknown rule id "${id}".`);
|
|
119
|
+
}
|
|
120
|
+
if (!seen.has(id)) {
|
|
121
|
+
seen.add(id);
|
|
122
|
+
selected.push(found);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return selected;
|
|
126
|
+
}
|
|
127
|
+
/** Validates and normalizes a rule definition. */
|
|
128
|
+
export function defineRule(rule) {
|
|
129
|
+
if (typeof rule.id !== "string" || rule.id.trim() === "") {
|
|
130
|
+
throw new VeruleExecutionError("INVALID_CONFIG", "Rule id must be a non-empty string.");
|
|
131
|
+
}
|
|
132
|
+
if (typeof rule.run !== "function") {
|
|
133
|
+
throw new VeruleExecutionError("INVALID_CONFIG", `Rule "${rule.id}" must provide a run function.`);
|
|
134
|
+
}
|
|
135
|
+
return rule;
|
|
136
|
+
}
|
|
137
|
+
/** Validates and normalizes a Verule project configuration, defaulting to zero rules. */
|
|
138
|
+
export function defineConfig(config) {
|
|
139
|
+
if (config.tsconfig !== undefined && config.projects !== undefined) {
|
|
140
|
+
throw new VeruleExecutionError("INVALID_CONFIG", 'Specify either "tsconfig" or "projects", not both.');
|
|
141
|
+
}
|
|
142
|
+
if (config.projects !== undefined && config.projects.length === 0) {
|
|
143
|
+
throw new VeruleExecutionError("INVALID_CONFIG", '"projects" must contain at least one tsconfig path when specified.');
|
|
144
|
+
}
|
|
145
|
+
const rules = validateRules(config.rules ?? []);
|
|
146
|
+
const models = validateModels(config.models ?? []);
|
|
147
|
+
const configuredAdapters = config.adapters ?? [];
|
|
148
|
+
const adapters = validateAdapters(configuredAdapters.filter((adapter) => typeof adapter !== "string"));
|
|
149
|
+
const adapterPackages = validateAdapterPackageNames([
|
|
150
|
+
...("adapterPackages" in config ? config.adapterPackages : []),
|
|
151
|
+
...configuredAdapters.filter((adapter) => typeof adapter === "string"),
|
|
152
|
+
]);
|
|
153
|
+
const additionalInputs = validateAdditionalInputPaths(config.additionalInputs);
|
|
154
|
+
return {
|
|
155
|
+
...(config.tsconfig !== undefined ? { tsconfig: config.tsconfig } : {}),
|
|
156
|
+
...(config.projects !== undefined
|
|
157
|
+
? { projects: [...config.projects] }
|
|
158
|
+
: {}),
|
|
159
|
+
rules,
|
|
160
|
+
models,
|
|
161
|
+
adapters,
|
|
162
|
+
adapterPackages,
|
|
163
|
+
additionalInputs,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function stableSerialize(value) {
|
|
167
|
+
if (value === null || typeof value !== "object") {
|
|
168
|
+
return JSON.stringify(value) ?? "undefined";
|
|
169
|
+
}
|
|
170
|
+
if (Array.isArray(value)) {
|
|
171
|
+
return `[${value.map((item) => stableSerialize(item)).join(",")}]`;
|
|
172
|
+
}
|
|
173
|
+
const record = value;
|
|
174
|
+
const keys = Object.keys(record).toSorted();
|
|
175
|
+
return `{${keys
|
|
176
|
+
.filter((key) => record[key] !== undefined)
|
|
177
|
+
.map((key) => `${JSON.stringify(key)}:${stableSerialize(record[key])}`)
|
|
178
|
+
.join(",")}}`;
|
|
179
|
+
}
|
|
180
|
+
function sha256Prefix(input) {
|
|
181
|
+
return createHash("sha256").update(input).digest("hex").slice(0, 16);
|
|
182
|
+
}
|
|
183
|
+
function summarizeRule(rule) {
|
|
184
|
+
return {
|
|
185
|
+
id: rule.id,
|
|
186
|
+
digest: sha256Prefix(stableSerialize({
|
|
187
|
+
id: rule.id,
|
|
188
|
+
description: rule.description ?? null,
|
|
189
|
+
run: rule.run.toString(),
|
|
190
|
+
})),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function summarizeModel(model) {
|
|
194
|
+
return {
|
|
195
|
+
id: model.id,
|
|
196
|
+
...(model.version !== undefined ? { version: model.version } : {}),
|
|
197
|
+
digest: sha256Prefix(stableSerialize({
|
|
198
|
+
id: model.id,
|
|
199
|
+
version: model.version ?? null,
|
|
200
|
+
description: model.description ?? null,
|
|
201
|
+
facts: model.facts ?? null,
|
|
202
|
+
...(model.instanceBehaviors !== undefined
|
|
203
|
+
? { instanceBehaviors: model.instanceBehaviors }
|
|
204
|
+
: {}),
|
|
205
|
+
...(model.cleanupOperations !== undefined
|
|
206
|
+
? { cleanupOperations: model.cleanupOperations }
|
|
207
|
+
: {}),
|
|
208
|
+
...(model.lifecycleEvents !== undefined
|
|
209
|
+
? { lifecycleEvents: model.lifecycleEvents }
|
|
210
|
+
: {}),
|
|
211
|
+
})),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function summarizeAdapter(adapter) {
|
|
215
|
+
return {
|
|
216
|
+
id: adapter.id,
|
|
217
|
+
version: adapter.version ?? null,
|
|
218
|
+
provides: adapter.provides
|
|
219
|
+
.map((provider) => provider.factType.id)
|
|
220
|
+
.toSorted(),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function computeReportIdentity(snapshotDigest, entries, rules, models, additionalInputs = [], adapters = [], adapterPackages = []) {
|
|
224
|
+
const ruleSummaries = rules.map(summarizeRule);
|
|
225
|
+
const modelSummaries = models.map(summarizeModel);
|
|
226
|
+
const adapterSummaries = adapters
|
|
227
|
+
.map(summarizeAdapter)
|
|
228
|
+
.toSorted((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
229
|
+
const configDigest = sha256Prefix(stableSerialize({
|
|
230
|
+
entries,
|
|
231
|
+
rules: ruleSummaries,
|
|
232
|
+
models: modelSummaries,
|
|
233
|
+
...(additionalInputs.length > 0 ? { additionalInputs } : {}),
|
|
234
|
+
...(adapterSummaries.length > 0 ? { adapters: adapterSummaries } : {}),
|
|
235
|
+
...(adapterPackages.length > 0 ? { adapterPackages } : {}),
|
|
236
|
+
}));
|
|
237
|
+
return {
|
|
238
|
+
snapshotDigest,
|
|
239
|
+
configDigest,
|
|
240
|
+
rules: ruleSummaries,
|
|
241
|
+
models: modelSummaries,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function resolveCheckpointLocation(target) {
|
|
245
|
+
if ("location" in target) {
|
|
246
|
+
return target.location;
|
|
247
|
+
}
|
|
248
|
+
if ("file" in target && "line" in target && "start" in target) {
|
|
249
|
+
return target;
|
|
250
|
+
}
|
|
251
|
+
return syntaxLocationOf(target);
|
|
252
|
+
}
|
|
253
|
+
function resolveNextConfig(current, options) {
|
|
254
|
+
if (options?.config !== undefined) {
|
|
255
|
+
return defineConfig(options.config);
|
|
256
|
+
}
|
|
257
|
+
const rules = options?.rules ? validateRules(options.rules) : current.rules;
|
|
258
|
+
const models = options?.models
|
|
259
|
+
? validateModels(options.models)
|
|
260
|
+
: current.models;
|
|
261
|
+
const adapters = options?.adapters
|
|
262
|
+
? validateAdapters(options.adapters.filter((adapter) => typeof adapter !== "string"))
|
|
263
|
+
: current.adapters;
|
|
264
|
+
const adapterPackages = options?.adapters
|
|
265
|
+
? validateAdapterPackageNames(options.adapters.filter((adapter) => typeof adapter === "string"))
|
|
266
|
+
: current.adapterPackages;
|
|
267
|
+
const additionalInputs = options?.additionalInputs !== undefined
|
|
268
|
+
? validateAdditionalInputPaths(options.additionalInputs)
|
|
269
|
+
: current.additionalInputs;
|
|
270
|
+
if (options?.entries !== undefined) {
|
|
271
|
+
if (options.entries.length === 0) {
|
|
272
|
+
throw new VeruleExecutionError("INVALID_CONFIG", '"entries" must contain at least one tsconfig path when specified.');
|
|
273
|
+
}
|
|
274
|
+
return {
|
|
275
|
+
projects: [...options.entries],
|
|
276
|
+
rules,
|
|
277
|
+
models,
|
|
278
|
+
adapters,
|
|
279
|
+
adapterPackages,
|
|
280
|
+
additionalInputs,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
...(current.tsconfig !== undefined ? { tsconfig: current.tsconfig } : {}),
|
|
285
|
+
...(current.projects !== undefined ? { projects: current.projects } : {}),
|
|
286
|
+
rules,
|
|
287
|
+
models,
|
|
288
|
+
adapters,
|
|
289
|
+
adapterPackages,
|
|
290
|
+
additionalInputs,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function isSessionCheckOptions(value) {
|
|
294
|
+
return value !== undefined && !Array.isArray(value);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Opens an analysis session backed by a single TSSAE `ProjectSession`.
|
|
298
|
+
*
|
|
299
|
+
* Call `session.close()` when finished to release the snapshot and terminate the engine process.
|
|
300
|
+
*/
|
|
301
|
+
export async function openSession(options) {
|
|
302
|
+
let normalizedConfig = options.config
|
|
303
|
+
? defineConfig(options.config)
|
|
304
|
+
: defineConfig({});
|
|
305
|
+
const absCwd = resolve(options.cwd);
|
|
306
|
+
const canonicalCwd = canonicalizeDir(absCwd);
|
|
307
|
+
let adapterResolutionRoot = resolve(options.adapterResolutionRoot ?? absCwd);
|
|
308
|
+
const sessionObserve = normalizeObserveConfig(options.observe, options.observeLimit);
|
|
309
|
+
let openIoMetrics;
|
|
310
|
+
const openStart = performance.now();
|
|
311
|
+
const tssaeSession = await invokeProjectQuery(() => openProject({
|
|
312
|
+
cwd: absCwd,
|
|
313
|
+
...(normalizedConfig.tsconfig !== undefined
|
|
314
|
+
? { tsconfig: normalizedConfig.tsconfig }
|
|
315
|
+
: {}),
|
|
316
|
+
...(normalizedConfig.projects !== undefined
|
|
317
|
+
? { projects: normalizedConfig.projects }
|
|
318
|
+
: {}),
|
|
319
|
+
models: normalizedConfig.models,
|
|
320
|
+
adapters: [
|
|
321
|
+
...normalizedConfig.adapters,
|
|
322
|
+
...normalizedConfig.adapterPackages,
|
|
323
|
+
],
|
|
324
|
+
additionalInputs: normalizedConfig.additionalInputs,
|
|
325
|
+
adapterResolutionRoot,
|
|
326
|
+
...(sessionObserve.mode !== "off"
|
|
327
|
+
? {
|
|
328
|
+
observe: sessionObserve,
|
|
329
|
+
onRpcMetrics: (io) => {
|
|
330
|
+
openIoMetrics = io;
|
|
331
|
+
},
|
|
332
|
+
}
|
|
333
|
+
: {}),
|
|
334
|
+
}));
|
|
335
|
+
const openDurationMs = performance.now() - openStart;
|
|
336
|
+
const workspaceFileState = {
|
|
337
|
+
files: tssaeSession.workspaceSourceFiles,
|
|
338
|
+
};
|
|
339
|
+
let closed = false;
|
|
340
|
+
let pendingOpenIoMetrics = openIoMetrics;
|
|
341
|
+
let pendingOpenDurationMs = openDurationMs;
|
|
342
|
+
let pendingConfigLoadMs = options.configLoadMs ?? 0;
|
|
343
|
+
const explicitRegistrations = [];
|
|
344
|
+
let lastRuleRegistrations = [];
|
|
345
|
+
function syncNonConfigEntries(registry, entries) {
|
|
346
|
+
for (const entry of entries) {
|
|
347
|
+
const targetPath = resolve(canonicalCwd, entry.file);
|
|
348
|
+
for (const source of entry.sources) {
|
|
349
|
+
if (source.kind !== "config") {
|
|
350
|
+
registry.registerAdditionalInput(targetPath, source);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
function buildSessionRegistry(configInputs, explicit, dynamic, tssaeEntries) {
|
|
356
|
+
const registry = createAdditionalInputRegistry({ cwd: absCwd });
|
|
357
|
+
for (const filePath of configInputs) {
|
|
358
|
+
registry.registerAdditionalInput(filePath, { kind: "config" });
|
|
359
|
+
}
|
|
360
|
+
for (const item of explicit) {
|
|
361
|
+
registry.registerAdditionalInput(item.filePath, item.source);
|
|
362
|
+
}
|
|
363
|
+
for (const item of dynamic) {
|
|
364
|
+
registry.registerAdditionalInput(item.filePath, item.source);
|
|
365
|
+
}
|
|
366
|
+
syncNonConfigEntries(registry, tssaeEntries);
|
|
367
|
+
return registry;
|
|
368
|
+
}
|
|
369
|
+
let sessionRegistry = buildSessionRegistry(normalizedConfig.additionalInputs, explicitRegistrations, lastRuleRegistrations, tssaeSession.additionalInputs);
|
|
370
|
+
function assertOpen() {
|
|
371
|
+
if (closed) {
|
|
372
|
+
throw new VeruleExecutionError("SESSION_CLOSED", "Analysis session is already closed.");
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function createRuleContext(ruleId, projectCtx, activeSnapshotId, collected, collector, additionalInputRegistrar) {
|
|
376
|
+
const scopedAdditionalInputs = createScopedAdditionalInputRegistrar(additionalInputRegistrar, { kind: "rule", id: ruleId });
|
|
377
|
+
const assertActiveSnapshot = () => {
|
|
378
|
+
assertOpen();
|
|
379
|
+
if (activeSnapshotId !== tssaeSession.snapshotId) {
|
|
380
|
+
throw new VeruleExecutionError("STALE_SNAPSHOT", `Snapshot ${String(activeSnapshotId)} has been superseded by snapshot ${String(tssaeSession.snapshotId)}.`);
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
return {
|
|
384
|
+
project: projectCtx.project,
|
|
385
|
+
models: projectCtx.models,
|
|
386
|
+
getModel: (id) => projectCtx.getModel(id),
|
|
387
|
+
findSyntax: (query) => invokeProjectQuery(() => projectCtx.findSyntax(query)),
|
|
388
|
+
typeAt: (targets) => invokeProjectQuery(() => projectCtx.typeAt(targets)),
|
|
389
|
+
listBranches: (functions) => invokeProjectQuery(() => projectCtx.listBranches(functions)),
|
|
390
|
+
branchCoverage: (query) => invokeProjectQuery(() => projectCtx.branchCoverage(query)),
|
|
391
|
+
resolveDeclarations: (targets, opts) => invokeProjectQuery(() => projectCtx.resolveDeclarations(targets, opts)),
|
|
392
|
+
resolveCalls: (targets, opts) => invokeProjectQuery(() => projectCtx.resolveCalls(targets, opts)),
|
|
393
|
+
projectCalls: (calls, opts) => invokeProjectQuery(() => projectCtx.projectCalls(calls, opts)),
|
|
394
|
+
projectSignatures: (signatures, opts) => invokeProjectQuery(() => projectCtx.projectSignatures(signatures, opts)),
|
|
395
|
+
projectTypes: (types, opts) => invokeProjectQuery(() => projectCtx.projectTypes(types, opts)),
|
|
396
|
+
isAssignableTo: (pairs) => invokeProjectQuery(() => projectCtx.isAssignableTo(pairs)),
|
|
397
|
+
syntaxOf: (targets, opts) => invokeProjectQuery(() => projectCtx.syntaxOf(targets, opts)),
|
|
398
|
+
callersOf: (declarations, opts) => invokeProjectQuery(() => projectCtx.callersOf(declarations, opts)),
|
|
399
|
+
calleesOf: (calls) => invokeProjectQuery(() => projectCtx.calleesOf(calls)),
|
|
400
|
+
resolveImplementations: (targets) => invokeProjectQuery(() => projectCtx.resolveImplementations(targets)),
|
|
401
|
+
valuePropagation: (opts) => invokeProjectQuery(() => projectCtx.valuePropagation(opts)),
|
|
402
|
+
resolveInstances: (targets, opts) => invokeProjectQuery(() => projectCtx.resolveInstances(targets, opts)),
|
|
403
|
+
projectInstances: (instances, opts) => invokeProjectQuery(() => projectCtx.projectInstances(instances, opts)),
|
|
404
|
+
callEffects: (opts) => invokeProjectQuery(() => projectCtx.callEffects(opts)),
|
|
405
|
+
instanceCleanup: (opts) => invokeProjectQuery(() => projectCtx.instanceCleanup(opts)),
|
|
406
|
+
facts: (factType, opts) => invokeProjectQuery(() => projectCtx.facts(factType, opts)),
|
|
407
|
+
registerAdditionalInput: (filePath) => {
|
|
408
|
+
assertActiveSnapshot();
|
|
409
|
+
return scopedAdditionalInputs.registerAdditionalInput(filePath);
|
|
410
|
+
},
|
|
411
|
+
readAdditionalInput: (filePath) => {
|
|
412
|
+
assertActiveSnapshot();
|
|
413
|
+
return scopedAdditionalInputs.readAdditionalInput(filePath);
|
|
414
|
+
},
|
|
415
|
+
report: (input) => {
|
|
416
|
+
assertActiveSnapshot();
|
|
417
|
+
collected.push({
|
|
418
|
+
ruleId,
|
|
419
|
+
projectId: projectCtx.project.projectId,
|
|
420
|
+
at: input.at,
|
|
421
|
+
message: input.message,
|
|
422
|
+
...(input.findingKey !== undefined
|
|
423
|
+
? { findingKey: input.findingKey }
|
|
424
|
+
: {}),
|
|
425
|
+
evidence: extractBasisEvidence(input.basis),
|
|
426
|
+
});
|
|
427
|
+
},
|
|
428
|
+
checkpoint: (name, target, outcome, detail) => {
|
|
429
|
+
if (!collector.isActive()) {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
collector.recordCheckpoint({
|
|
433
|
+
ruleId,
|
|
434
|
+
projectId: projectCtx.project.projectId,
|
|
435
|
+
name,
|
|
436
|
+
outcome,
|
|
437
|
+
resolveLocation: () => resolveCheckpointLocation(target),
|
|
438
|
+
...(detail !== undefined ? { detailFn: detail } : {}),
|
|
439
|
+
});
|
|
440
|
+
},
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
async function executeCheckRun(runOptions) {
|
|
444
|
+
assertOpen();
|
|
445
|
+
const baseRules = runOptions?.rulesOverride
|
|
446
|
+
? validateRules(runOptions.rulesOverride)
|
|
447
|
+
: normalizedConfig.rules;
|
|
448
|
+
const rules = selectRules(baseRules, runOptions?.ruleIds);
|
|
449
|
+
const explainTarget = runOptions?.at !== undefined
|
|
450
|
+
? normalizeTargetSpec(runOptions.at, absCwd)
|
|
451
|
+
: undefined;
|
|
452
|
+
if (explainTarget !== undefined && rules.length === 0) {
|
|
453
|
+
throw new VeruleExecutionError("INVALID_CONFIG", "At least one rule must be configured or selected via ruleIds to explain a target location.");
|
|
454
|
+
}
|
|
455
|
+
const effectiveObserve = runOptions?.observe !== undefined ||
|
|
456
|
+
runOptions?.observeLimit !== undefined
|
|
457
|
+
? normalizeObserveConfig(runOptions.observe ?? sessionObserve.mode, runOptions.observeLimit ?? sessionObserve.limit)
|
|
458
|
+
: sessionObserve;
|
|
459
|
+
const configLoadMs = runOptions?.configLoadMs ?? pendingConfigLoadMs;
|
|
460
|
+
pendingConfigLoadMs = 0;
|
|
461
|
+
const openMs = pendingOpenDurationMs;
|
|
462
|
+
pendingOpenDurationMs = 0;
|
|
463
|
+
const configuredAdaptersById = new Map();
|
|
464
|
+
for (const adapter of normalizedConfig.adapters) {
|
|
465
|
+
configuredAdaptersById.set(adapter.id, {
|
|
466
|
+
id: adapter.id,
|
|
467
|
+
factTypeIds: adapter.provides.map((provider) => provider.factType.id),
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
for (const native of tssaeSession.nativeAdapters) {
|
|
471
|
+
if (!configuredAdaptersById.has(native.providerId)) {
|
|
472
|
+
configuredAdaptersById.set(native.providerId, {
|
|
473
|
+
id: native.providerId,
|
|
474
|
+
factTypeIds: [],
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
const collector = new ObservationCollector({
|
|
479
|
+
mode: effectiveObserve.mode,
|
|
480
|
+
...(effectiveObserve.limit !== undefined
|
|
481
|
+
? { limit: effectiveObserve.limit }
|
|
482
|
+
: {}),
|
|
483
|
+
nativeAdapters: tssaeSession.nativeAdapters,
|
|
484
|
+
configuredAdapters: [...configuredAdaptersById.values()],
|
|
485
|
+
...(explainTarget !== undefined ? { explainTarget } : {}),
|
|
486
|
+
configAndOpenMs: configLoadMs + openMs,
|
|
487
|
+
});
|
|
488
|
+
if (pendingOpenIoMetrics) {
|
|
489
|
+
collector.recordRpcCall(pendingOpenIoMetrics);
|
|
490
|
+
pendingOpenIoMetrics = undefined;
|
|
491
|
+
}
|
|
492
|
+
const collected = [];
|
|
493
|
+
const collectedGaps = [];
|
|
494
|
+
const runRegistry = buildSessionRegistry(normalizedConfig.additionalInputs, explicitRegistrations, [], []);
|
|
495
|
+
const runRuleRegistrations = [];
|
|
496
|
+
const runRegistrar = {
|
|
497
|
+
cwd: runRegistry.cwd,
|
|
498
|
+
registerAdditionalInput: (filePath, source) => {
|
|
499
|
+
sessionRegistry.registerAdditionalInput(filePath, source);
|
|
500
|
+
runRuleRegistrations.push({ filePath, source });
|
|
501
|
+
return runRegistry.registerAdditionalInput(filePath, source);
|
|
502
|
+
},
|
|
503
|
+
readAdditionalInput: (filePath, source) => {
|
|
504
|
+
sessionRegistry.registerAdditionalInput(filePath, source);
|
|
505
|
+
runRuleRegistrations.push({ filePath, source });
|
|
506
|
+
return runRegistry.readAdditionalInput(filePath, source);
|
|
507
|
+
},
|
|
508
|
+
listAdditionalInputs: () => runRegistry.listAdditionalInputs(),
|
|
509
|
+
getTrackedAbsolutePaths: () => runRegistry.getTrackedAbsolutePaths(),
|
|
510
|
+
};
|
|
511
|
+
const currentSnapshotId = tssaeSession.snapshotId;
|
|
512
|
+
for (const project of tssaeSession.projects) {
|
|
513
|
+
for (const rule of rules) {
|
|
514
|
+
let ruleEngineMs = 0;
|
|
515
|
+
const ruleStart = collector.isObserveEnabled() ? performance.now() : 0;
|
|
516
|
+
const observer = {
|
|
517
|
+
onGaps: (gaps) => {
|
|
518
|
+
collectedGaps.push(...gaps);
|
|
519
|
+
collector.recordRuleGaps(rule.id, gaps);
|
|
520
|
+
},
|
|
521
|
+
...(collector.isObserveEnabled()
|
|
522
|
+
? {
|
|
523
|
+
observe: effectiveObserve,
|
|
524
|
+
onRpcMetrics: (io) => collector.recordRpcCall(io),
|
|
525
|
+
}
|
|
526
|
+
: {}),
|
|
527
|
+
...(explainTarget !== undefined ? { explainTarget } : {}),
|
|
528
|
+
...(collector.isActive()
|
|
529
|
+
? {
|
|
530
|
+
onQueryCompleted: (event) => {
|
|
531
|
+
if (event.cacheStatus === "computed") {
|
|
532
|
+
collector.addEngineQueryMs(event.durationMs);
|
|
533
|
+
ruleEngineMs += event.durationMs;
|
|
534
|
+
}
|
|
535
|
+
collector.recordQuery({
|
|
536
|
+
ruleId: rule.id,
|
|
537
|
+
op: event.op,
|
|
538
|
+
projectId: event.projectId,
|
|
539
|
+
provider: event.provider,
|
|
540
|
+
...(event.providers !== undefined
|
|
541
|
+
? { providers: event.providers }
|
|
542
|
+
: {}),
|
|
543
|
+
cacheStatus: event.cacheStatus,
|
|
544
|
+
candidateCount: event.candidateCount,
|
|
545
|
+
durationMs: event.durationMs,
|
|
546
|
+
summary: event.summary,
|
|
547
|
+
...(event.matchedLocations !== undefined
|
|
548
|
+
? { matchedLocations: event.matchedLocations }
|
|
549
|
+
: {}),
|
|
550
|
+
...(event.detail !== undefined
|
|
551
|
+
? { detail: event.detail }
|
|
552
|
+
: {}),
|
|
553
|
+
});
|
|
554
|
+
},
|
|
555
|
+
}
|
|
556
|
+
: {}),
|
|
557
|
+
...(collector.isExplainEnabled()
|
|
558
|
+
? {
|
|
559
|
+
onFactExplain: (event) => {
|
|
560
|
+
collector.recordFactExplain({
|
|
561
|
+
ruleId: rule.id,
|
|
562
|
+
...(event.subjectLocation !== undefined
|
|
563
|
+
? { subjectLocation: event.subjectLocation }
|
|
564
|
+
: {}),
|
|
565
|
+
gaps: event.gaps,
|
|
566
|
+
localGaps: event.localGaps,
|
|
567
|
+
});
|
|
568
|
+
},
|
|
569
|
+
onProviderEvaluation: (evaluation) => {
|
|
570
|
+
collector.recordProviderEvaluation({
|
|
571
|
+
ruleId: rule.id,
|
|
572
|
+
evaluation,
|
|
573
|
+
});
|
|
574
|
+
},
|
|
575
|
+
onCleanupCovered: (event) => {
|
|
576
|
+
collector.recordCleanupPaths({
|
|
577
|
+
ruleId: rule.id,
|
|
578
|
+
targetLocations: event.targetLocations,
|
|
579
|
+
paths: event.paths,
|
|
580
|
+
});
|
|
581
|
+
},
|
|
582
|
+
}
|
|
583
|
+
: {}),
|
|
584
|
+
};
|
|
585
|
+
const projectCtx = invokeProjectSync(() => tssaeSession.project(project, { observer }));
|
|
586
|
+
const ctx = createRuleContext(rule.id, projectCtx, currentSnapshotId, collected, collector, runRegistrar);
|
|
587
|
+
try {
|
|
588
|
+
await rule.run(ctx);
|
|
589
|
+
}
|
|
590
|
+
catch (err) {
|
|
591
|
+
if (err instanceof VeruleExecutionError) {
|
|
592
|
+
throw err;
|
|
593
|
+
}
|
|
594
|
+
const mapped = toVeruleError(err, "RULE_EXECUTION_ERROR");
|
|
595
|
+
if (mapped.code !== "RULE_EXECUTION_ERROR" || err !== mapped.cause) {
|
|
596
|
+
// Preserve TssaeError codes/details while wrapping generic JS rule throws with rule context.
|
|
597
|
+
if (err instanceof Error &&
|
|
598
|
+
(err.name === "TssaeError" || "code" in err)) {
|
|
599
|
+
throw mapped;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
603
|
+
throw new VeruleExecutionError("RULE_EXECUTION_ERROR", `Rule "${rule.id}" failed: ${detail}`, { cause: err });
|
|
604
|
+
}
|
|
605
|
+
finally {
|
|
606
|
+
if (collector.isObserveEnabled()) {
|
|
607
|
+
const ruleElapsed = performance.now() - ruleStart;
|
|
608
|
+
collector.addRuleExecutionMs(Math.max(0, ruleElapsed - ruleEngineMs));
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
const scannedComments = await invokeProjectQuery(() => tssaeSession.scanComments(collector.isObserveEnabled()
|
|
614
|
+
? {
|
|
615
|
+
observe: effectiveObserve,
|
|
616
|
+
onRpcMetrics: (io) => collector.recordRpcCall(io),
|
|
617
|
+
}
|
|
618
|
+
: undefined));
|
|
619
|
+
const scannedDirectives = parseInlineIgnoreDirectives(scannedComments);
|
|
620
|
+
const settlement = resolveInlineIgnores({
|
|
621
|
+
directives: scannedDirectives,
|
|
622
|
+
collected,
|
|
623
|
+
projects: tssaeSession.projects,
|
|
624
|
+
configuredRuleIds: new Set(baseRules.map((rule) => rule.id)),
|
|
625
|
+
executedRuleIds: new Set(rules.map((rule) => rule.id)),
|
|
626
|
+
isPartialRuleSelection: runOptions?.ruleIds !== undefined && runOptions.ruleIds.length > 0,
|
|
627
|
+
});
|
|
628
|
+
const diagnostics = buildDiagnostics(settlement.diagnostics);
|
|
629
|
+
const gaps = buildGaps(collectedGaps);
|
|
630
|
+
syncNonConfigEntries(runRegistry, tssaeSession.additionalInputs);
|
|
631
|
+
const additionalInputs = runRegistry.listAdditionalInputs();
|
|
632
|
+
if (!runOptions?.ruleIds && !runOptions?.rulesOverride) {
|
|
633
|
+
lastRuleRegistrations = runRuleRegistrations;
|
|
634
|
+
sessionRegistry = buildSessionRegistry(normalizedConfig.additionalInputs, explicitRegistrations, lastRuleRegistrations, tssaeSession.additionalInputs);
|
|
635
|
+
}
|
|
636
|
+
else {
|
|
637
|
+
syncNonConfigEntries(sessionRegistry, tssaeSession.additionalInputs);
|
|
638
|
+
}
|
|
639
|
+
const observation = collector.buildObservationReport();
|
|
640
|
+
const explanations = explainTarget
|
|
641
|
+
? rules.map((rule) => collector.buildExplainResult({
|
|
642
|
+
ruleId: rule.id,
|
|
643
|
+
projects: tssaeSession.projects,
|
|
644
|
+
diagnostics,
|
|
645
|
+
suppressions: settlement.suppressions,
|
|
646
|
+
}))
|
|
647
|
+
: undefined;
|
|
648
|
+
return {
|
|
649
|
+
reportVersion: REPORT_SCHEMA_VERSION,
|
|
650
|
+
status: diagnostics.length > 0 ? "findings" : "clean",
|
|
651
|
+
projects: tssaeSession.projects,
|
|
652
|
+
fileOrigins: tssaeSession.fileOrigins,
|
|
653
|
+
additionalInputs,
|
|
654
|
+
diagnostics,
|
|
655
|
+
gaps,
|
|
656
|
+
identity: computeReportIdentity(tssaeSession.snapshotDigest, resolveProjectEntries(normalizedConfig), rules, normalizedConfig.models, normalizedConfig.additionalInputs, normalizedConfig.adapters, normalizedConfig.adapterPackages),
|
|
657
|
+
...(settlement.entries.length > 0
|
|
658
|
+
? { inlineIgnores: settlement.entries }
|
|
659
|
+
: {}),
|
|
660
|
+
...(observation !== undefined ? { observation } : {}),
|
|
661
|
+
...(explanations !== undefined && explanations.length === 1
|
|
662
|
+
? { explanation: explanations[0] }
|
|
663
|
+
: {}),
|
|
664
|
+
...(explanations !== undefined && explanations.length > 1
|
|
665
|
+
? { explanations }
|
|
666
|
+
: {}),
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
const analysisSession = {
|
|
670
|
+
get snapshotId() {
|
|
671
|
+
return tssaeSession.snapshotId;
|
|
672
|
+
},
|
|
673
|
+
get projects() {
|
|
674
|
+
return tssaeSession.projects;
|
|
675
|
+
},
|
|
676
|
+
get fileOrigins() {
|
|
677
|
+
return tssaeSession.fileOrigins;
|
|
678
|
+
},
|
|
679
|
+
get additionalInputs() {
|
|
680
|
+
return sessionRegistry.listAdditionalInputs();
|
|
681
|
+
},
|
|
682
|
+
get memory() {
|
|
683
|
+
return tssaeSession.memory;
|
|
684
|
+
},
|
|
685
|
+
registerAdditionalInput: (filePath, source) => {
|
|
686
|
+
assertOpen();
|
|
687
|
+
const entry = invokeProjectSync(() => tssaeSession.registerAdditionalInput(filePath, source));
|
|
688
|
+
explicitRegistrations.push({ filePath, source });
|
|
689
|
+
return sessionRegistry.registerAdditionalInput(filePath, source) ?? entry;
|
|
690
|
+
},
|
|
691
|
+
check: (optionsOrRules) => {
|
|
692
|
+
if (isSessionCheckOptions(optionsOrRules)) {
|
|
693
|
+
return executeCheckRun(optionsOrRules);
|
|
694
|
+
}
|
|
695
|
+
return executeCheckRun(optionsOrRules !== undefined
|
|
696
|
+
? { rulesOverride: optionsOrRules }
|
|
697
|
+
: undefined);
|
|
698
|
+
},
|
|
699
|
+
update: async (updateOptions) => {
|
|
700
|
+
assertOpen();
|
|
701
|
+
const changedAdditionalFiles = sessionRegistry.refresh();
|
|
702
|
+
const nextConfig = resolveNextConfig(normalizedConfig, updateOptions);
|
|
703
|
+
const nextAdapterResolutionRoot = resolve(updateOptions?.adapterResolutionRoot ?? adapterResolutionRoot);
|
|
704
|
+
const nextEntries = resolveProjectEntries(nextConfig);
|
|
705
|
+
const prevIdentity = computeReportIdentity("", resolveProjectEntries(normalizedConfig), normalizedConfig.rules, normalizedConfig.models, normalizedConfig.additionalInputs, normalizedConfig.adapters, normalizedConfig.adapterPackages);
|
|
706
|
+
const nextIdentity = computeReportIdentity("", nextEntries, nextConfig.rules, nextConfig.models, nextConfig.additionalInputs, nextConfig.adapters, nextConfig.adapterPackages);
|
|
707
|
+
const tssaeUpdate = await invokeProjectQuery(() => tssaeSession.update({
|
|
708
|
+
...(updateOptions?.changed !== undefined
|
|
709
|
+
? { changed: updateOptions.changed }
|
|
710
|
+
: {}),
|
|
711
|
+
...(updateOptions?.created !== undefined
|
|
712
|
+
? { created: updateOptions.created }
|
|
713
|
+
: {}),
|
|
714
|
+
...(updateOptions?.deleted !== undefined
|
|
715
|
+
? { deleted: updateOptions.deleted }
|
|
716
|
+
: {}),
|
|
717
|
+
adapterResolutionRoot: nextAdapterResolutionRoot,
|
|
718
|
+
entries: nextEntries,
|
|
719
|
+
models: nextConfig.models,
|
|
720
|
+
adapters: [...nextConfig.adapters, ...nextConfig.adapterPackages],
|
|
721
|
+
additionalInputs: nextConfig.additionalInputs,
|
|
722
|
+
}));
|
|
723
|
+
const invalidatedReasons = [...tssaeUpdate.recomputation.invalidatedBy];
|
|
724
|
+
const existingReasons = new Set(invalidatedReasons);
|
|
725
|
+
const changedSet = new Set(updateOptions?.changed ?? []);
|
|
726
|
+
for (const file of changedAdditionalFiles) {
|
|
727
|
+
const marker = `additional-input:${file}`;
|
|
728
|
+
if (!changedSet.has(file) && !existingReasons.has(marker)) {
|
|
729
|
+
invalidatedReasons.push(marker);
|
|
730
|
+
existingReasons.add(marker);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
if (stableSerialize(prevIdentity.rules) !==
|
|
734
|
+
stableSerialize(nextIdentity.rules) &&
|
|
735
|
+
!existingReasons.has("rules")) {
|
|
736
|
+
invalidatedReasons.push("rules");
|
|
737
|
+
existingReasons.add("rules");
|
|
738
|
+
}
|
|
739
|
+
if (updateOptions?.config !== undefined &&
|
|
740
|
+
invalidatedReasons.length === 0) {
|
|
741
|
+
invalidatedReasons.push("config");
|
|
742
|
+
}
|
|
743
|
+
normalizedConfig = nextConfig;
|
|
744
|
+
adapterResolutionRoot = nextAdapterResolutionRoot;
|
|
745
|
+
workspaceFileState.files = tssaeUpdate.workspaceSourceFiles;
|
|
746
|
+
sessionRegistry = buildSessionRegistry(nextConfig.additionalInputs, explicitRegistrations, lastRuleRegistrations, tssaeSession.additionalInputs);
|
|
747
|
+
const recomputation = {
|
|
748
|
+
...tssaeUpdate.recomputation,
|
|
749
|
+
invalidatedBy: invalidatedReasons,
|
|
750
|
+
};
|
|
751
|
+
return {
|
|
752
|
+
previousSnapshotId: tssaeUpdate.previousSnapshotId,
|
|
753
|
+
snapshotId: tssaeUpdate.snapshotId,
|
|
754
|
+
projects: tssaeUpdate.projects,
|
|
755
|
+
fileOrigins: tssaeUpdate.fileOrigins,
|
|
756
|
+
additionalInputs: sessionRegistry.listAdditionalInputs(),
|
|
757
|
+
recomputation,
|
|
758
|
+
memory: tssaeUpdate.memory,
|
|
759
|
+
};
|
|
760
|
+
},
|
|
761
|
+
explain: async (explainOptions) => {
|
|
762
|
+
const report = await executeCheckRun({
|
|
763
|
+
...(explainOptions.rulesOverride !== undefined
|
|
764
|
+
? { rulesOverride: explainOptions.rulesOverride }
|
|
765
|
+
: {}),
|
|
766
|
+
...(explainOptions.ruleId !== undefined
|
|
767
|
+
? { ruleIds: [explainOptions.ruleId] }
|
|
768
|
+
: {}),
|
|
769
|
+
at: explainOptions.at,
|
|
770
|
+
...(explainOptions.observe !== undefined
|
|
771
|
+
? { observe: explainOptions.observe }
|
|
772
|
+
: {}),
|
|
773
|
+
...(explainOptions.observeLimit !== undefined
|
|
774
|
+
? { observeLimit: explainOptions.observeLimit }
|
|
775
|
+
: {}),
|
|
776
|
+
});
|
|
777
|
+
const primaryExplanation = report.explanation ?? report.explanations?.[0];
|
|
778
|
+
if (!primaryExplanation) {
|
|
779
|
+
throw new VeruleExecutionError("ENGINE_ERROR", "Failed to generate explanation for the requested target.");
|
|
780
|
+
}
|
|
781
|
+
return {
|
|
782
|
+
...report,
|
|
783
|
+
explanation: primaryExplanation,
|
|
784
|
+
};
|
|
785
|
+
},
|
|
786
|
+
close: async () => {
|
|
787
|
+
if (closed)
|
|
788
|
+
return;
|
|
789
|
+
closed = true;
|
|
790
|
+
await tssaeSession.close();
|
|
791
|
+
},
|
|
792
|
+
};
|
|
793
|
+
sessionWorkspaceFileStates.set(analysisSession, workspaceFileState);
|
|
794
|
+
return analysisSession;
|
|
795
|
+
}
|
|
796
|
+
/** Runs a one-shot check in a dedicated analysis session and releases resources before returning. */
|
|
797
|
+
export async function runCheck(options) {
|
|
798
|
+
const session = await openSession(options);
|
|
799
|
+
try {
|
|
800
|
+
return await session.check({
|
|
801
|
+
...(options.ruleIds !== undefined ? { ruleIds: options.ruleIds } : {}),
|
|
802
|
+
...(options.at !== undefined ? { at: options.at } : {}),
|
|
803
|
+
...(options.observe !== undefined ? { observe: options.observe } : {}),
|
|
804
|
+
...(options.observeLimit !== undefined
|
|
805
|
+
? { observeLimit: options.observeLimit }
|
|
806
|
+
: {}),
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
finally {
|
|
810
|
+
await session.close();
|
|
811
|
+
}
|
|
812
|
+
}
|