circle-ir-ai 4.37.0 → 4.40.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/CHANGELOG.md +126 -0
- package/dist/agents/mastra/workflow.d.ts +16 -0
- package/dist/agents/mastra/workflow.d.ts.map +1 -1
- package/dist/agents/mastra/workflow.js +118 -22
- package/dist/agents/mastra/workflow.js.map +1 -1
- package/dist/blast-radius/import-map.d.ts +121 -0
- package/dist/blast-radius/import-map.d.ts.map +1 -0
- package/dist/blast-radius/import-map.js +735 -0
- package/dist/blast-radius/import-map.js.map +1 -0
- package/dist/blast-radius/index.d.ts +36 -4
- package/dist/blast-radius/index.d.ts.map +1 -1
- package/dist/blast-radius/index.js +397 -45
- package/dist/blast-radius/index.js.map +1 -1
- package/dist/blast-radius/radius.d.ts +304 -6
- package/dist/blast-radius/radius.d.ts.map +1 -1
- package/dist/blast-radius/radius.js +1547 -6
- package/dist/blast-radius/radius.js.map +1 -1
- package/dist/blast-radius/types.d.ts +79 -2
- package/dist/blast-radius/types.d.ts.map +1 -1
- package/dist/blast-radius/types.js +2 -2
- package/dist/cache/tree-cache.d.ts +10 -0
- package/dist/cache/tree-cache.d.ts.map +1 -1
- package/dist/cache/tree-cache.js +3 -1
- package/dist/cache/tree-cache.js.map +1 -1
- package/dist/cache/verify-cache.d.ts +7 -0
- package/dist/cache/verify-cache.d.ts.map +1 -1
- package/dist/cache/verify-cache.js +19 -2
- package/dist/cache/verify-cache.js.map +1 -1
- package/dist/dead-code/detector.d.ts +29 -2
- package/dist/dead-code/detector.d.ts.map +1 -1
- package/dist/dead-code/detector.js +6 -2
- package/dist/dead-code/detector.js.map +1 -1
- package/dist/dead-code/engine.d.ts +35 -1
- package/dist/dead-code/engine.d.ts.map +1 -1
- package/dist/dead-code/engine.js +247 -3
- package/dist/dead-code/engine.js.map +1 -1
- package/dist/dead-code/illata-client.d.ts +160 -0
- package/dist/dead-code/illata-client.d.ts.map +1 -0
- package/dist/dead-code/illata-client.js +291 -0
- package/dist/dead-code/illata-client.js.map +1 -0
- package/dist/dead-code/index.d.ts +1 -0
- package/dist/dead-code/index.d.ts.map +1 -1
- package/dist/dead-code/index.js +1 -0
- package/dist/dead-code/index.js.map +1 -1
- package/dist/dead-code/rules/dead-code-java.dl +132 -0
- package/dist/health-score/calculator.d.ts.map +1 -1
- package/dist/health-score/calculator.js +13 -5
- package/dist/health-score/calculator.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/llm/config.d.ts +21 -0
- package/dist/llm/config.d.ts.map +1 -1
- package/dist/llm/config.js +36 -0
- package/dist/llm/config.js.map +1 -1
- package/dist/llm/cwe-rubrics.d.ts +17 -0
- package/dist/llm/cwe-rubrics.d.ts.map +1 -0
- package/dist/llm/cwe-rubrics.js +51 -0
- package/dist/llm/cwe-rubrics.js.map +1 -0
- package/dist/llm/model-route-dispatcher.d.ts +17 -0
- package/dist/llm/model-route-dispatcher.d.ts.map +1 -1
- package/dist/llm/model-route-dispatcher.js +53 -3
- package/dist/llm/model-route-dispatcher.js.map +1 -1
- package/dist/llm/model-route.d.ts.map +1 -1
- package/dist/llm/model-route.js +4 -1
- package/dist/llm/model-route.js.map +1 -1
- package/dist/llm/verification.d.ts +1 -0
- package/dist/llm/verification.d.ts.map +1 -1
- package/dist/llm/verification.js +14 -6
- package/dist/llm/verification.js.map +1 -1
- package/dist/mcp/tools/blast-radius.d.ts +6 -4
- package/dist/mcp/tools/blast-radius.d.ts.map +1 -1
- package/dist/mcp/tools/blast-radius.js +53 -12
- package/dist/mcp/tools/blast-radius.js.map +1 -1
- package/dist/quality/calculator.d.ts.map +1 -1
- package/dist/quality/calculator.js +11 -2
- package/dist/quality/calculator.js.map +1 -1
- package/dist/scope/product-paths.d.ts +117 -12
- package/dist/scope/product-paths.d.ts.map +1 -1
- package/dist/scope/product-paths.js +422 -38
- package/dist/scope/product-paths.js.map +1 -1
- package/dist/secret-scan/scanner.d.ts +5 -0
- package/dist/secret-scan/scanner.d.ts.map +1 -1
- package/dist/secret-scan/scanner.js +74 -3
- package/dist/secret-scan/scanner.js.map +1 -1
- package/dist/security-scan/finding-labels.d.ts +3 -0
- package/dist/security-scan/finding-labels.d.ts.map +1 -0
- package/dist/security-scan/finding-labels.js +18 -0
- package/dist/security-scan/finding-labels.js.map +1 -0
- package/dist/security-scan/scanner.d.ts +32 -4
- package/dist/security-scan/scanner.d.ts.map +1 -1
- package/dist/security-scan/scanner.js +81 -13
- package/dist/security-scan/scanner.js.map +1 -1
- package/dist/selectors/exclude.d.ts +5 -1
- package/dist/selectors/exclude.d.ts.map +1 -1
- package/dist/selectors/exclude.js +15 -2
- package/dist/selectors/exclude.js.map +1 -1
- package/dist/skills/bundle-loader.d.ts.map +1 -1
- package/dist/skills/bundle-loader.js +6 -3
- package/dist/skills/bundle-loader.js.map +1 -1
- package/dist/spec-gap/analyzer.d.ts +8 -0
- package/dist/spec-gap/analyzer.d.ts.map +1 -1
- package/dist/spec-gap/analyzer.js +6 -3
- package/dist/spec-gap/analyzer.js.map +1 -1
- package/dist/specifica/binary-entries.d.ts +96 -0
- package/dist/specifica/binary-entries.d.ts.map +1 -0
- package/dist/specifica/binary-entries.js +318 -0
- package/dist/specifica/binary-entries.js.map +1 -0
- package/dist/specifica/environment/index.d.ts.map +1 -1
- package/dist/specifica/environment/index.js +5 -3
- package/dist/specifica/environment/index.js.map +1 -1
- package/dist/specifica/environment/read-code.d.ts +9 -2
- package/dist/specifica/environment/read-code.d.ts.map +1 -1
- package/dist/specifica/environment/read-code.js +12 -5
- package/dist/specifica/environment/read-code.js.map +1 -1
- package/dist/specifica/evidence-extractor.d.ts.map +1 -1
- package/dist/specifica/evidence-extractor.js +12 -1
- package/dist/specifica/evidence-extractor.js.map +1 -1
- package/dist/specifica/file-routes.d.ts.map +1 -1
- package/dist/specifica/file-routes.js +2 -1
- package/dist/specifica/file-routes.js.map +1 -1
- package/dist/specifica/generator.js +1 -0
- package/dist/specifica/generator.js.map +1 -1
- package/dist/specifica/learned-diff.d.ts.map +1 -1
- package/dist/specifica/learned-diff.js +3 -2
- package/dist/specifica/learned-diff.js.map +1 -1
- package/dist/specifica/level-design.d.ts +7 -0
- package/dist/specifica/level-design.d.ts.map +1 -1
- package/dist/specifica/level-design.js +10 -7
- package/dist/specifica/level-design.js.map +1 -1
- package/dist/specifica/library-surface-python-rust.d.ts +56 -0
- package/dist/specifica/library-surface-python-rust.d.ts.map +1 -0
- package/dist/specifica/library-surface-python-rust.js +466 -0
- package/dist/specifica/library-surface-python-rust.js.map +1 -0
- package/dist/specifica/library-surface.d.ts +13 -1
- package/dist/specifica/library-surface.d.ts.map +1 -1
- package/dist/specifica/library-surface.js +41 -1
- package/dist/specifica/library-surface.js.map +1 -1
- package/dist/specifica/modules.d.ts +28 -1
- package/dist/specifica/modules.d.ts.map +1 -1
- package/dist/specifica/modules.js +141 -10
- package/dist/specifica/modules.js.map +1 -1
- package/dist/specifica/spec-tree.d.ts +34 -1
- package/dist/specifica/spec-tree.d.ts.map +1 -1
- package/dist/specifica/spec-tree.js +242 -54
- package/dist/specifica/spec-tree.js.map +1 -1
- package/dist/specifica/toml-lines.d.ts +33 -0
- package/dist/specifica/toml-lines.d.ts.map +1 -0
- package/dist/specifica/toml-lines.js +77 -0
- package/dist/specifica/toml-lines.js.map +1 -0
- package/dist/specifica/tree-types.d.ts +2 -2
- package/dist/specifica/tree-types.d.ts.map +1 -1
- package/dist/specifica/tree-writer.d.ts +1 -0
- package/dist/specifica/tree-writer.d.ts.map +1 -1
- package/dist/specifica/tree-writer.js +4 -1
- package/dist/specifica/tree-writer.js.map +1 -1
- package/dist/specifica/ts-rule-sources.d.ts +10 -1
- package/dist/specifica/ts-rule-sources.d.ts.map +1 -1
- package/dist/specifica/ts-rule-sources.js +98 -1
- package/dist/specifica/ts-rule-sources.js.map +1 -1
- package/dist/specifica/types.d.ts +13 -0
- package/dist/specifica/types.d.ts.map +1 -1
- package/dist/specifica/use-cases.d.ts +78 -3
- package/dist/specifica/use-cases.d.ts.map +1 -1
- package/dist/specifica/use-cases.js +236 -12
- package/dist/specifica/use-cases.js.map +1 -1
- package/dist/trust/compare.d.ts.map +1 -1
- package/dist/trust/compare.js +11 -1
- package/dist/trust/compare.js.map +1 -1
- package/dist/trust/passes/ai-config-detect.d.ts +4 -0
- package/dist/trust/passes/ai-config-detect.d.ts.map +1 -1
- package/dist/trust/passes/ai-config-detect.js +23 -2
- package/dist/trust/passes/ai-config-detect.js.map +1 -1
- package/dist/trust/passes/ai-generated-fingerprint.d.ts.map +1 -1
- package/dist/trust/passes/ai-generated-fingerprint.js +2 -1
- package/dist/trust/passes/ai-generated-fingerprint.js.map +1 -1
- package/dist/trust/passes/code-complexity.d.ts.map +1 -1
- package/dist/trust/passes/code-complexity.js +2 -1
- package/dist/trust/passes/code-complexity.js.map +1 -1
- package/dist/trust/passes/conformance-attestation.d.ts.map +1 -1
- package/dist/trust/passes/conformance-attestation.js +2 -1
- package/dist/trust/passes/conformance-attestation.js.map +1 -1
- package/dist/trust/passes/cross-skill-interaction.d.ts.map +1 -1
- package/dist/trust/passes/cross-skill-interaction.js +3 -2
- package/dist/trust/passes/cross-skill-interaction.js.map +1 -1
- package/dist/trust/passes/data-exfiltration.d.ts.map +1 -1
- package/dist/trust/passes/data-exfiltration.js +2 -1
- package/dist/trust/passes/data-exfiltration.js.map +1 -1
- package/dist/trust/passes/dep-manifests.d.ts.map +1 -1
- package/dist/trust/passes/dep-manifests.js +2 -1
- package/dist/trust/passes/dep-manifests.js.map +1 -1
- package/dist/trust/passes/deprecated-usage.d.ts.map +1 -1
- package/dist/trust/passes/deprecated-usage.js +2 -1
- package/dist/trust/passes/deprecated-usage.js.map +1 -1
- package/dist/trust/passes/deprecation-no-replacement.d.ts.map +1 -1
- package/dist/trust/passes/deprecation-no-replacement.js +2 -1
- package/dist/trust/passes/deprecation-no-replacement.js.map +1 -1
- package/dist/trust/passes/doc-coverage.d.ts.map +1 -1
- package/dist/trust/passes/doc-coverage.js +2 -1
- package/dist/trust/passes/doc-coverage.js.map +1 -1
- package/dist/trust/passes/eu-ai-act-flags.d.ts.map +1 -1
- package/dist/trust/passes/eu-ai-act-flags.js +3 -2
- package/dist/trust/passes/eu-ai-act-flags.js.map +1 -1
- package/dist/trust/passes/excessive-permissions.d.ts.map +1 -1
- package/dist/trust/passes/excessive-permissions.js +2 -1
- package/dist/trust/passes/excessive-permissions.js.map +1 -1
- package/dist/trust/passes/inconsistent-error-handling.d.ts.map +1 -1
- package/dist/trust/passes/inconsistent-error-handling.js +2 -1
- package/dist/trust/passes/inconsistent-error-handling.js.map +1 -1
- package/dist/trust/passes/inconsistent-naming.d.ts.map +1 -1
- package/dist/trust/passes/inconsistent-naming.js +51 -12
- package/dist/trust/passes/inconsistent-naming.js.map +1 -1
- package/dist/trust/passes/inconsistent-param-order.d.ts.map +1 -1
- package/dist/trust/passes/inconsistent-param-order.js +2 -1
- package/dist/trust/passes/inconsistent-param-order.js.map +1 -1
- package/dist/trust/passes/missing-guard-dom.d.ts.map +1 -1
- package/dist/trust/passes/missing-guard-dom.js +2 -1
- package/dist/trust/passes/missing-guard-dom.js.map +1 -1
- package/dist/trust/passes/performance-passes.d.ts.map +1 -1
- package/dist/trust/passes/performance-passes.js +2 -1
- package/dist/trust/passes/performance-passes.js.map +1 -1
- package/dist/trust/passes/prompt-injection.d.ts.map +1 -1
- package/dist/trust/passes/prompt-injection.js +36 -4
- package/dist/trust/passes/prompt-injection.js.map +1 -1
- package/dist/trust/passes/throws-mismatch.d.ts.map +1 -1
- package/dist/trust/passes/throws-mismatch.js +2 -1
- package/dist/trust/passes/throws-mismatch.js.map +1 -1
- package/dist/trust/passes/tool-poisoning.d.ts.map +1 -1
- package/dist/trust/passes/tool-poisoning.js +3 -2
- package/dist/trust/passes/tool-poisoning.js.map +1 -1
- package/dist/trust/passes/unnecessary-object-hotspot.d.ts.map +1 -1
- package/dist/trust/passes/unnecessary-object-hotspot.js +2 -1
- package/dist/trust/passes/unnecessary-object-hotspot.js.map +1 -1
- package/dist/trust/scoring.d.ts.map +1 -1
- package/dist/trust/scoring.js +6 -2
- package/dist/trust/scoring.js.map +1 -1
- package/dist/utils/dirent-order.d.ts +21 -0
- package/dist/utils/dirent-order.d.ts.map +1 -0
- package/dist/utils/dirent-order.js +21 -0
- package/dist/utils/dirent-order.js.map +1 -0
- package/dist/utils/file-skip.d.ts +11 -0
- package/dist/utils/file-skip.d.ts.map +1 -1
- package/dist/utils/file-skip.js +29 -0
- package/dist/utils/file-skip.js.map +1 -1
- package/package.json +3 -3
|
@@ -17,23 +17,32 @@
|
|
|
17
17
|
* - **levels**: the learned spec tree's levels those files sit in, keyed as
|
|
18
18
|
* `SpecLevel` is (`path`, `source_root`, `name`), by the spec tree's own
|
|
19
19
|
* rule (specifica/modules.ts `levelOf`, over `detectModules` with the same
|
|
20
|
-
* product scope), so the answer joins the stored tree (cognium-ai#1070)
|
|
20
|
+
* product scope), so the answer joins the stored tree (cognium-ai#1070);
|
|
21
|
+
* - **tests**: the declarations in test files (the product-scope rule,
|
|
22
|
+
* reason `test`) that reach the changed declarations, followed backwards
|
|
23
|
+
* over the same call graphs up to `maxHops` calls (cognium-ai#1072). Which
|
|
24
|
+
* tests reach a change; not which tests can be left out.
|
|
21
25
|
*
|
|
22
26
|
* Deterministic and model-free. A graph is built only for the languages the
|
|
23
27
|
* items touch, once per call, and only over the files that can call into the
|
|
24
28
|
* change: the changed files, plus the files whose text names a changed
|
|
25
29
|
* declaration or a changed file (a call or an import has to name what it
|
|
26
|
-
* reaches). On a large repository that is a small slice of it.
|
|
30
|
+
* reaches). On a large repository that is a small slice of it. The test walk
|
|
31
|
+
* widens that slice one hop at a time, to the files that name a caller found
|
|
32
|
+
* so far (at the last hop, test files only), and rebuilds the graph over it;
|
|
33
|
+
* `call_sites` still come from the first graph.
|
|
27
34
|
*/
|
|
28
35
|
import * as fs from 'fs';
|
|
29
36
|
import * as path from 'path';
|
|
30
37
|
import { buildTsCallGraph, buildJavaGraph, buildPythonGraph, buildGoGraph } from 'circle-ir';
|
|
31
38
|
import { buildUsageIndexWithStats, collectSourceFiles } from '../bom/usage.js';
|
|
32
39
|
import { detectModules, levelOf, repositoryName } from '../specifica/modules.js';
|
|
33
|
-
import {
|
|
40
|
+
import { productScope } from '../scope/product-paths.js';
|
|
41
|
+
import { assembleRadius, BLAST_TEST_HOPS, BLAST_TEST_RULE, callersOf, carriersOf, stepOutOf, emptyBasis, presentRadius, selectChanged, testsOf, unionRadius, unknownTests, walkBackwards, plainDecoratorNames, } from './radius.js';
|
|
34
42
|
import { manifestDeclares } from './manifest.js';
|
|
43
|
+
import { FileResolver, importMapIsEmpty, loadImportMap, rewriteImports } from './import-map.js';
|
|
35
44
|
export * from './types.js';
|
|
36
|
-
export { BLAST_THRESHOLDS, levelFor, labelFor, moduleOf, selectChanged, callersOf, assembleRadius, unionRadius, presentRadius, displayName, groupByLevel, repositoryLevelOnly } from './radius.js';
|
|
45
|
+
export { BLAST_THRESHOLDS, BLAST_TEST_HOPS, BLAST_TEST_RULE, levelFor, labelFor, moduleOf, selectChanged, callersOf, carriersOf, stepOutOf, callLikeReceiver, plainDecoratorNames, codeOnly, importBindings, moduleExports, followImport, followableNames, BLAST_FOLLOW_BUDGET, walkBackwards, testsOf, joinTests, unknownTests, assembleRadius, unionRadius, presentRadius, displayName, groupByLevel, repositoryLevelOnly } from './radius.js';
|
|
37
46
|
export { manifestDeclares } from './manifest.js';
|
|
38
47
|
const FAMILY_OF_EXT = {
|
|
39
48
|
'.ts': 'typescript', '.mts': 'typescript', '.cts': 'typescript', '.tsx': 'typescript',
|
|
@@ -87,7 +96,16 @@ async function buildFacts(family, sources) {
|
|
|
87
96
|
: family === 'python' ? await buildPythonGraph(sources)
|
|
88
97
|
: family === 'go' ? await buildGoGraph(sources)
|
|
89
98
|
: await buildTsCallGraph(sources);
|
|
90
|
-
return {
|
|
99
|
+
return {
|
|
100
|
+
scheme: g.scheme,
|
|
101
|
+
files: g.files,
|
|
102
|
+
edges: g.edges,
|
|
103
|
+
unresolved: g.unresolved,
|
|
104
|
+
partial: g.partial,
|
|
105
|
+
// For the test walk only: values that may run, and what the environment runs.
|
|
106
|
+
references: g.references,
|
|
107
|
+
entries: g.entries.map((e) => ({ id: e.id, kind: e.kind })),
|
|
108
|
+
};
|
|
91
109
|
}
|
|
92
110
|
const IDENT = /^[A-Za-z_$][\w$]*$/;
|
|
93
111
|
/** The identifiers a reference to this declaration would spell: its name and its owners' names. */
|
|
@@ -96,6 +114,24 @@ function namesOf(qualifiedName, name) {
|
|
|
96
114
|
const parts = [name, ...member.split(/[./]/)].map((p) => p.replace(/@.*$/, ''));
|
|
97
115
|
return parts.filter((p) => IDENT.test(p) && p !== 'constructor');
|
|
98
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* The names an import of a test file would spell: as `moduleNamesOf`, and
|
|
119
|
+
* its whole stem even with dots in it (`./order.fixtures`, `./helpers.test`).
|
|
120
|
+
* A Go import names the package's directory (`e2e.MakeTotal()` from
|
|
121
|
+
* `test/e2e/helpers.go`), not the file.
|
|
122
|
+
*/
|
|
123
|
+
function testModuleNamesOf(family, rel) {
|
|
124
|
+
const stem = path.posix.basename(rel).replace(/\.[^.]+$/, '');
|
|
125
|
+
const out = new Set(moduleNamesOf(rel));
|
|
126
|
+
if (/^[\w$.-]+$/.test(stem))
|
|
127
|
+
out.add(stem);
|
|
128
|
+
if (family === 'go') {
|
|
129
|
+
const dir = path.posix.basename(path.posix.dirname(rel));
|
|
130
|
+
if (dir && dir !== '.' && IDENT.test(dir))
|
|
131
|
+
out.add(dir);
|
|
132
|
+
}
|
|
133
|
+
return [...out];
|
|
134
|
+
}
|
|
99
135
|
/** The names an import of this file would spell: its stem, and for an index module its directory. */
|
|
100
136
|
function moduleNamesOf(rel) {
|
|
101
137
|
const stem = path.posix.basename(rel).replace(/\.[^.]+$/, '');
|
|
@@ -122,6 +158,35 @@ function reExports(family, rel, code) {
|
|
|
122
158
|
return path.posix.basename(rel) === '__init__.py';
|
|
123
159
|
return false;
|
|
124
160
|
}
|
|
161
|
+
/** The test walk's default file budget per language: `max(minFiles, perFirstGraphFile × first-graph files)`. */
|
|
162
|
+
export const BLAST_TEST_BUDGET = { minFiles: 2000, perFirstGraphFile: 4 };
|
|
163
|
+
/** `maxHops` as given, or the default; anything else is refused. */
|
|
164
|
+
function testHops(maxHops) {
|
|
165
|
+
if (maxHops === undefined)
|
|
166
|
+
return BLAST_TEST_HOPS.default;
|
|
167
|
+
if (!Number.isInteger(maxHops) || maxHops < BLAST_TEST_HOPS.min || maxHops > BLAST_TEST_HOPS.max) {
|
|
168
|
+
throw new RangeError(`maxHops must be an integer from ${BLAST_TEST_HOPS.min} to ${BLAST_TEST_HOPS.max}, got ${String(maxHops)}`);
|
|
169
|
+
}
|
|
170
|
+
return maxHops;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Which files are tests: the product-scope rule, reason `test`. Always the
|
|
174
|
+
* rule itself, whatever the call's own product scope: turning the scope off
|
|
175
|
+
* (`productScope: false`, `SCOPE_ALL_PATHS=1`) or bringing a test folder back
|
|
176
|
+
* into it does not make its files product code for this answer.
|
|
177
|
+
*/
|
|
178
|
+
function testFiles(root) {
|
|
179
|
+
const scope = productScope(root, { env: {} });
|
|
180
|
+
const memo = new Map();
|
|
181
|
+
return (file) => {
|
|
182
|
+
let hit = memo.get(file);
|
|
183
|
+
if (hit === undefined) {
|
|
184
|
+
hit = scope.classify(file)?.reason === 'test';
|
|
185
|
+
memo.set(file, hit);
|
|
186
|
+
}
|
|
187
|
+
return hit;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
125
190
|
/**
|
|
126
191
|
* The learned tree's levels for this repository, by the spec tree's rule:
|
|
127
192
|
* modules detected once, with the product scope generate-spec uses.
|
|
@@ -150,6 +215,11 @@ export async function blastRadius(codeRoot, items, opts = {}) {
|
|
|
150
215
|
throw new Error(`code_root is not a directory: ${codeRoot}`);
|
|
151
216
|
}
|
|
152
217
|
const prefilter = opts.prefilter !== false;
|
|
218
|
+
const maxHops = testHops(opts.maxHops);
|
|
219
|
+
const withTests = opts.tests !== false;
|
|
220
|
+
if (opts.maxTestFiles !== undefined && (!Number.isInteger(opts.maxTestFiles) || opts.maxTestFiles < 1)) {
|
|
221
|
+
throw new RangeError(`maxTestFiles must be a positive integer, got ${String(opts.maxTestFiles)}`);
|
|
222
|
+
}
|
|
153
223
|
const bounds = { maxFiles: opts.walk?.maxFiles ?? BLAST_WALK.maxFiles, maxDepth: opts.walk?.maxDepth ?? BLAST_WALK.maxDepth };
|
|
154
224
|
// The learned tree's levels, once per call.
|
|
155
225
|
const levelNotes = [];
|
|
@@ -172,10 +242,15 @@ export async function blastRadius(codeRoot, items, opts = {}) {
|
|
|
172
242
|
const qualifiedName = new Map();
|
|
173
243
|
const graphNotes = [];
|
|
174
244
|
const cuts = [];
|
|
245
|
+
// What each language's graph was built from, for the test walk to widen.
|
|
246
|
+
const sourcesOf = new Map();
|
|
247
|
+
let isTest = () => false;
|
|
175
248
|
if (changedFiles.size > 0) {
|
|
176
249
|
const { ensureAnalyzerInitialized, isAnalyzerInitialized } = await import('../utils/analyzer-init.js');
|
|
177
250
|
if (!isAnalyzerInitialized())
|
|
178
251
|
await ensureAnalyzerInitialized();
|
|
252
|
+
if (withTests)
|
|
253
|
+
isTest = testFiles(root);
|
|
179
254
|
// Only the languages that need a graph: the bound counts only their files.
|
|
180
255
|
const languages = new Set([...changedFiles.keys()].flatMap((f) => LANGUAGES_OF[f]));
|
|
181
256
|
const walk = collectSourceFiles(root, root, { ...bounds, languages });
|
|
@@ -190,16 +265,17 @@ export async function blastRadius(codeRoot, items, opts = {}) {
|
|
|
190
265
|
list.push(src);
|
|
191
266
|
byFamily.set(family, list);
|
|
192
267
|
}
|
|
193
|
-
for (const family of
|
|
268
|
+
for (const family of FAMILIES) {
|
|
194
269
|
const changed = changedFiles.get(family);
|
|
195
270
|
if (!changed)
|
|
196
271
|
continue;
|
|
197
272
|
try {
|
|
198
|
-
const
|
|
199
|
-
if (sources.length === 0)
|
|
273
|
+
const fs0 = await graphSources(family, byFamily.get(family) ?? [], changed, items, root, prefilter);
|
|
274
|
+
if (fs0.sources.length === 0)
|
|
200
275
|
continue;
|
|
201
|
-
const facts = await buildFacts(family, sources);
|
|
276
|
+
const facts = await buildFacts(family, fs0.sources);
|
|
202
277
|
factsOf.set(family, facts);
|
|
278
|
+
sourcesOf.set(family, fs0);
|
|
203
279
|
for (const f of facts.files) {
|
|
204
280
|
fileFacts.set(f.file, { family, file: f });
|
|
205
281
|
for (const d of f.decls)
|
|
@@ -237,7 +313,7 @@ export async function blastRadius(codeRoot, items, opts = {}) {
|
|
|
237
313
|
// Per item, what it changes (for the batch, worked out again over the union).
|
|
238
314
|
const changedOf = [];
|
|
239
315
|
const regionsOf = [];
|
|
240
|
-
const
|
|
316
|
+
const pending = items.map((item, index) => {
|
|
241
317
|
const basis = emptyBasis();
|
|
242
318
|
basis.notes.push(...graphNotes, ...levelNotes);
|
|
243
319
|
const touched = [];
|
|
@@ -247,6 +323,8 @@ export async function blastRadius(codeRoot, items, opts = {}) {
|
|
|
247
323
|
regionsOf[index] = regionsBy;
|
|
248
324
|
// Whether the code facts back the answer: a location with no facts, or a bump with nothing read, leaves the level not known.
|
|
249
325
|
let unbacked = false;
|
|
326
|
+
// A location read but naming no declaration (top-level lines, an unknown symbol): its effect on tests cannot be followed.
|
|
327
|
+
let undeclared = false;
|
|
250
328
|
for (const loc of item.locations ?? []) {
|
|
251
329
|
const rel = toRel(root, loc.file);
|
|
252
330
|
if (rel === null) {
|
|
@@ -274,6 +352,7 @@ export async function blastRadius(codeRoot, items, opts = {}) {
|
|
|
274
352
|
}
|
|
275
353
|
const ids = selectChanged(ff.file, loc);
|
|
276
354
|
if (ids.size === 0) {
|
|
355
|
+
undeclared = true;
|
|
277
356
|
basis.notes.push(`${rel}${loc.symbol ? ` has no declaration named ${loc.symbol}` : ' has no declaration on those lines'}; counted as touched only`);
|
|
278
357
|
continue;
|
|
279
358
|
}
|
|
@@ -354,34 +433,285 @@ export async function blastRadius(codeRoot, items, opts = {}) {
|
|
|
354
433
|
basis.truncated = true;
|
|
355
434
|
basis.notes.push(cutNote);
|
|
356
435
|
}
|
|
357
|
-
return
|
|
436
|
+
return {
|
|
437
|
+
id: item.id,
|
|
438
|
+
touched,
|
|
439
|
+
callSites,
|
|
440
|
+
importSites,
|
|
441
|
+
basis,
|
|
442
|
+
known: !unbacked,
|
|
443
|
+
// Tests can be said only when every location was read down to its declarations, the walk was whole,
|
|
444
|
+
// and nothing else changes: a bump's tests (through its import sites) are not followed.
|
|
445
|
+
testsKnowable: !unbacked && !undeclared && changedBy.size > 0 && cutNote === null && !item.dependency,
|
|
446
|
+
};
|
|
447
|
+
});
|
|
448
|
+
// Every item's changes together: the test walk widens each graph once for all of them, and the batch is worked out over them.
|
|
449
|
+
const changedAll = new Map();
|
|
450
|
+
const regionsAll = new Map();
|
|
451
|
+
items.forEach((_, i) => {
|
|
452
|
+
for (const [family, ids] of changedOf[i]) {
|
|
453
|
+
const set = changedAll.get(family) ?? new Set();
|
|
454
|
+
for (const id of ids)
|
|
455
|
+
set.add(id);
|
|
456
|
+
changedAll.set(family, set);
|
|
457
|
+
}
|
|
458
|
+
for (const [family, regions] of regionsOf[i])
|
|
459
|
+
regionsAll.set(family, [...(regionsAll.get(family) ?? []), ...regions]);
|
|
460
|
+
});
|
|
461
|
+
// Each language's graph, widened toward the tests that reach the changes.
|
|
462
|
+
const testGraphs = new Map();
|
|
463
|
+
let importMap;
|
|
464
|
+
const tsImports = () => {
|
|
465
|
+
if (importMap === undefined) {
|
|
466
|
+
const map = loadImportMap(root, bounds.maxDepth);
|
|
467
|
+
importMap = importMapIsEmpty(map) ? null : { map, files: new FileResolver(root) };
|
|
468
|
+
}
|
|
469
|
+
return importMap;
|
|
470
|
+
};
|
|
471
|
+
for (const family of withTests ? FAMILIES : []) {
|
|
472
|
+
const facts = factsOf.get(family);
|
|
473
|
+
const changed = changedAll.get(family);
|
|
474
|
+
if (!facts || !changed)
|
|
475
|
+
continue;
|
|
476
|
+
const sources = sourcesOf.get(family);
|
|
477
|
+
const budget = Math.min(bounds.maxFiles, opts.maxTestFiles ?? Math.max(BLAST_TEST_BUDGET.minFiles, BLAST_TEST_BUDGET.perFirstGraphFile * sources.sources.length));
|
|
478
|
+
const imports = family === 'typescript' ? tsImports() : null;
|
|
479
|
+
testGraphs.set(family, await testGraph(family, facts, sources, changed, isTest, maxHops, budget, imports));
|
|
480
|
+
}
|
|
481
|
+
const radii = pending.map((p, i) => {
|
|
482
|
+
const tests = withTests ? itemTests(p, changedOf[i], regionsOf[i], testGraphs, qualifiedName, isTest, maxHops) : unknownTests(maxHops);
|
|
483
|
+
return assembleRadius(p.id, p.touched, p.callSites, p.importSites, p.basis, p.known, levelOfFile, tests);
|
|
358
484
|
});
|
|
359
485
|
const result = { code_root: root, items: radii.map(presentRadius) };
|
|
360
486
|
if (opts.batchId !== undefined) {
|
|
361
487
|
// The batch's callers, again from the facts, over the union of the items' changes.
|
|
362
|
-
const changedAll = new Map();
|
|
363
|
-
const regionsAll = new Map();
|
|
364
|
-
items.forEach((_, i) => {
|
|
365
|
-
for (const [family, ids] of changedOf[i]) {
|
|
366
|
-
const set = changedAll.get(family) ?? new Set();
|
|
367
|
-
for (const id of ids)
|
|
368
|
-
set.add(id);
|
|
369
|
-
changedAll.set(family, set);
|
|
370
|
-
}
|
|
371
|
-
for (const [family, regions] of regionsOf[i])
|
|
372
|
-
regionsAll.set(family, [...(regionsAll.get(family) ?? []), ...regions]);
|
|
373
|
-
});
|
|
374
488
|
const callSites = [];
|
|
375
489
|
let unresolved = 0;
|
|
490
|
+
let testsUnresolved = 0;
|
|
376
491
|
for (const [family, changed] of changedAll) {
|
|
377
492
|
const answer = callersOf(factsOf.get(family), changed, qualifiedName, regionsAll.get(family) ?? []);
|
|
378
493
|
callSites.push(...answer.call_sites);
|
|
379
494
|
unresolved += answer.unresolved_sites;
|
|
495
|
+
const tg = testGraphs.get(family);
|
|
496
|
+
if (tg)
|
|
497
|
+
testsUnresolved += testsOf(tg.facts, changed, tg.qualified, regionsAll.get(family) ?? [], isTest, maxHops, tg.options).unresolved_sites;
|
|
380
498
|
}
|
|
381
|
-
result.batch = presentRadius(unionRadius(opts.batchId, radii, { call_sites: callSites, unresolved_sites: unresolved }, levelOfFile));
|
|
499
|
+
result.batch = presentRadius(unionRadius(opts.batchId, radii, { call_sites: callSites, unresolved_sites: unresolved, tests_unresolved_sites: testsUnresolved }, levelOfFile));
|
|
382
500
|
}
|
|
383
501
|
return result;
|
|
384
502
|
}
|
|
503
|
+
const FAMILIES = ['typescript', 'java', 'python', 'go'];
|
|
504
|
+
/** An item's tests, over each language it changes. */
|
|
505
|
+
function itemTests(p, changedBy, regionsBy, testGraphs, qualifiedName, isTest, maxHops) {
|
|
506
|
+
if (changedBy.size === 0)
|
|
507
|
+
return unknownTests(maxHops);
|
|
508
|
+
const reached = [];
|
|
509
|
+
const reachedChanged = new Set();
|
|
510
|
+
const notKnown = { unresolved: new Set(), entries: new Set(), partial: new Set(), uncalled: new Set() };
|
|
511
|
+
let unresolved = 0;
|
|
512
|
+
let backed = p.testsKnowable;
|
|
513
|
+
for (const [family, changed] of changedBy) {
|
|
514
|
+
const tg = testGraphs.get(family);
|
|
515
|
+
const answer = testsOf(tg.facts, changed, tg.qualified, regionsBy.get(family) ?? [], isTest, maxHops, tg.options);
|
|
516
|
+
reached.push(...answer.reached);
|
|
517
|
+
for (const id of answer.reachedChanged)
|
|
518
|
+
reachedChanged.add(id);
|
|
519
|
+
for (const k of ['unresolved', 'entries', 'partial', 'uncalled'])
|
|
520
|
+
for (const id of answer.notKnown[k])
|
|
521
|
+
notKnown[k].add(id);
|
|
522
|
+
unresolved += answer.unresolved_sites;
|
|
523
|
+
if (tg.cutNote) {
|
|
524
|
+
backed = false;
|
|
525
|
+
p.basis.notes.push(tg.cutNote);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
const all = [...changedBy.values()].flatMap((ids) => [...ids]);
|
|
529
|
+
const maybe = new Set([...notKnown.unresolved, ...notKnown.entries, ...notKnown.partial, ...notKnown.uncalled]);
|
|
530
|
+
const unreached = [];
|
|
531
|
+
if (backed) {
|
|
532
|
+
for (const id of all)
|
|
533
|
+
if (!reachedChanged.has(id) && !maybe.has(id))
|
|
534
|
+
unreached.push(qualifiedName.get(id) ?? id);
|
|
535
|
+
const count = (n, one, many) => `${n} changed ${n === 1 ? `declaration ${one}` : `declarations ${many}`}`;
|
|
536
|
+
if (notKnown.unresolved.size > 0) {
|
|
537
|
+
p.basis.notes.push(`${count(notKnown.unresolved.size, 'is', 'are')} not listed as unreached: calls the graph could not resolve (an import from outside the tree, an unknown receiver) may reach them`);
|
|
538
|
+
}
|
|
539
|
+
if (notKnown.entries.size > 0) {
|
|
540
|
+
p.basis.notes.push(`${count(notKnown.entries.size, 'is', 'are')} not listed as unreached: a route or another framework entry runs them, and tests that reach them that way (over HTTP, through a container) are not followed`);
|
|
541
|
+
}
|
|
542
|
+
if (notKnown.partial.size > 0) {
|
|
543
|
+
p.basis.notes.push(`${count(notKnown.partial.size, 'is', 'are')} not listed as unreached: test files that did not parse completely name them`);
|
|
544
|
+
}
|
|
545
|
+
if (notKnown.uncalled.size > 0) {
|
|
546
|
+
p.basis.notes.push(`${count(notKnown.uncalled.size, 'is', 'are')} not listed as unreached: they, or code on a path to them, may run without a call the graph records (on import: a field's initializer, a module's top-level code and the callbacks it passes on, a Python default argument; when a class is defined or built: its static blocks, decorators and field initializers; on a property access: a getter or setter; by the runtime: methods such as toString, then, __str__, compareTo or String), and tests that run them that way are not followed`);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
const known = backed && all.every((id) => reachedChanged.has(id) || !maybe.has(id));
|
|
550
|
+
// "Unreached" is said only when every changed declaration is accounted for.
|
|
551
|
+
return { reached, unreached: known ? unreached : [], unresolved_sites: unresolved, status: known ? 'known' : 'unknown', max_hops: maxHops, rule: BLAST_TEST_RULE };
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* One language's graph for the test walk. Without the prefilter the first
|
|
555
|
+
* graph already holds every file. With it, the graph is widened one hop at
|
|
556
|
+
* a time: the files that name a declaration the walk has reached (by name,
|
|
557
|
+
* or by importing its module, through re-exporting modules too) are added
|
|
558
|
+
* and the graph rebuilt, until no reached declaration is left to follow or
|
|
559
|
+
* `maxHops` is spent. A caller at the last hop matters only if it is a test,
|
|
560
|
+
* so for those only test files are added. Test code is called from other
|
|
561
|
+
* test files only, and only from one that imports its module (an import, or
|
|
562
|
+
* for Java the class name, which is the file's stem; for Go the package
|
|
563
|
+
* directory) or names it from the same directory (a Go or Java package); a
|
|
564
|
+
* name alone in another directory (a test helper called `item` or `setup`)
|
|
565
|
+
* does not pull a file in. Once the graph would hold more than half the
|
|
566
|
+
* language's files, it takes all of them in one build (a graph of
|
|
567
|
+
* everything, as without the prefilter) when that fits the budget. Stops
|
|
568
|
+
* (and says so) past `maxFiles` files, the budget.
|
|
569
|
+
*
|
|
570
|
+
* TypeScript: the graph is built with each file's tsconfig-path and
|
|
571
|
+
* workspace-package import specifiers rewritten to relative paths
|
|
572
|
+
* (`importMap`), so `@/lib/fmt` and `@repo/core/x` resolve: always when any
|
|
573
|
+
* file in it has such an import (one rebuild when no widening round needs
|
|
574
|
+
* one), so the prefilter does not change the answer.
|
|
575
|
+
*/
|
|
576
|
+
async function testGraph(family, first, sources, changed, isTest, maxHops, maxFiles, imports) {
|
|
577
|
+
const qualifiedOf = (facts) => {
|
|
578
|
+
const q = new Map();
|
|
579
|
+
for (const f of facts.files)
|
|
580
|
+
for (const d of f.decls)
|
|
581
|
+
q.set(d.id, d.qualified_name);
|
|
582
|
+
return q;
|
|
583
|
+
};
|
|
584
|
+
const inGraph = new Map(sources.sources.map((s) => [s.path, s.code]));
|
|
585
|
+
const answer = (built, cutNote, noTestFiles = false) => {
|
|
586
|
+
// Read once per graph, for every item and the batch.
|
|
587
|
+
const decorators = new Map();
|
|
588
|
+
return {
|
|
589
|
+
facts: built.facts,
|
|
590
|
+
qualified: qualifiedOf(built.facts),
|
|
591
|
+
options: {
|
|
592
|
+
partialTestTexts: built.facts.partial.filter((f) => isTest(f) && built.text.has(f)).map((f) => ({ path: f, code: built.text.get(f) })),
|
|
593
|
+
sourceText: (file) => built.text.get(file),
|
|
594
|
+
decoratorNames: (file) => {
|
|
595
|
+
let names = decorators.get(file);
|
|
596
|
+
if (!names) {
|
|
597
|
+
names = plainDecoratorNames(built.text.get(file) ?? '');
|
|
598
|
+
decorators.set(file, names);
|
|
599
|
+
}
|
|
600
|
+
return names;
|
|
601
|
+
},
|
|
602
|
+
...(noTestFiles ? { noTestFiles } : {}),
|
|
603
|
+
},
|
|
604
|
+
...(cutNote ? { cutNote } : {}),
|
|
605
|
+
};
|
|
606
|
+
};
|
|
607
|
+
const unreadTests = sources.unread.filter(isTest);
|
|
608
|
+
const unreadNote = unreadTests.length === 0 ? undefined
|
|
609
|
+
: `${unreadTests.length} ${family} test ${unreadTests.length === 1 ? 'file is' : 'files are'} larger than ${MAX_FILE_BYTES / 1024} KB and not read; tests in them are not known`;
|
|
610
|
+
let built = { facts: first, text: new Map(inGraph) };
|
|
611
|
+
// Nothing to widen: no file of the language is a test.
|
|
612
|
+
if (![...sources.sources, ...sources.texts].some((s) => isTest(s.path)))
|
|
613
|
+
return answer(built, unreadNote, unreadTests.length === 0);
|
|
614
|
+
let facts = first;
|
|
615
|
+
const codeOf = new Map(sources.texts.map((s) => [s.path, s.code]));
|
|
616
|
+
const rewritten = new Map();
|
|
617
|
+
const rewrite = (p, code) => {
|
|
618
|
+
let r = rewritten.get(p);
|
|
619
|
+
if (!r) {
|
|
620
|
+
r = imports ? rewriteImports(p, code, imports.map, imports.files) : { code, targets: [] };
|
|
621
|
+
rewritten.set(p, r);
|
|
622
|
+
}
|
|
623
|
+
return r;
|
|
624
|
+
};
|
|
625
|
+
let aliased = imports === null;
|
|
626
|
+
// How each reached declaration's callers were looked for: in every file, or in test files only.
|
|
627
|
+
// The prefilter already looked in every file for the changed declarations' (not the functions they sit in).
|
|
628
|
+
const followed = new Map([...changed].map((id) => [id, 'all']));
|
|
629
|
+
for (let rebuilds = 0;;) {
|
|
630
|
+
const { dist } = walkBackwards(facts, new Set(carriersOf(facts, changed).keys()), maxHops - 1, [], new Map(), stepOutOf(facts, isTest));
|
|
631
|
+
const declOf = new Map();
|
|
632
|
+
for (const f of facts.files)
|
|
633
|
+
for (const d of f.decls)
|
|
634
|
+
declOf.set(d.id, { decl: d, file: f.file });
|
|
635
|
+
// Callers looked for in every file, in test files only (a product declaration one hop from the bound),
|
|
636
|
+
// and callers of test code (test files that import its module, or name it from the same directory).
|
|
637
|
+
const wide = { names: new Set(), modules: new Set() };
|
|
638
|
+
const lastHop = { names: new Set(), modules: new Set() };
|
|
639
|
+
const testCode = { modules: new Set(), namesByDir: new Map() };
|
|
640
|
+
for (const [id, hops] of dist) {
|
|
641
|
+
const at = declOf.get(id);
|
|
642
|
+
if (!at || at.decl.kind === 'module')
|
|
643
|
+
continue;
|
|
644
|
+
// A caller one hop from the bound counts only if it is a test; a test's callers are tests too.
|
|
645
|
+
const inTest = isTest(at.file);
|
|
646
|
+
const scope = hops + 1 < maxHops && !inTest ? 'all' : 'tests';
|
|
647
|
+
const had = followed.get(id);
|
|
648
|
+
if (had === 'all' || had === scope)
|
|
649
|
+
continue;
|
|
650
|
+
followed.set(id, scope);
|
|
651
|
+
const names = namesOf(at.decl.qualified_name, at.decl.name);
|
|
652
|
+
if (names.length === 0)
|
|
653
|
+
continue;
|
|
654
|
+
if (inTest) {
|
|
655
|
+
for (const m of testModuleNamesOf(family, at.file))
|
|
656
|
+
testCode.modules.add(m);
|
|
657
|
+
const dir = path.posix.dirname(at.file);
|
|
658
|
+
const set = testCode.namesByDir.get(dir) ?? new Set();
|
|
659
|
+
for (const n of names)
|
|
660
|
+
set.add(n);
|
|
661
|
+
testCode.namesByDir.set(dir, set);
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
const into = scope === 'all' ? wide : lastHop;
|
|
665
|
+
for (const n of names)
|
|
666
|
+
into.names.add(n);
|
|
667
|
+
for (const m of moduleNamesOf(at.file))
|
|
668
|
+
into.modules.add(m);
|
|
669
|
+
}
|
|
670
|
+
const added = new Set();
|
|
671
|
+
const take = (picked) => { for (const p of picked)
|
|
672
|
+
if (!inGraph.has(p))
|
|
673
|
+
added.add(p); };
|
|
674
|
+
take(pickNaming(family, sources.texts, wide.names, wide.modules));
|
|
675
|
+
take(pickNaming(family, sources.texts, lastHop.names, lastHop.modules, isTest));
|
|
676
|
+
take(pickNaming(family, sources.texts, new Set(), testCode.modules, isTest));
|
|
677
|
+
for (const [dir, names] of testCode.namesByDir) {
|
|
678
|
+
take(pickNaming(family, sources.texts, names, new Set(), (p) => isTest(p) && path.posix.dirname(p) === dir));
|
|
679
|
+
}
|
|
680
|
+
// Imports the import map resolves (tsconfig paths, workspace packages): the test graph is built with them
|
|
681
|
+
// whenever any file in it has one, whether or not a widening round needs a rebuild, so the answer does not
|
|
682
|
+
// depend on the prefilter.
|
|
683
|
+
let needAliases = false;
|
|
684
|
+
if (!aliased) {
|
|
685
|
+
needAliases = [...inGraph].some(([p, code]) => rewrite(p, code).targets.length > 0);
|
|
686
|
+
if (!needAliases)
|
|
687
|
+
aliased = true;
|
|
688
|
+
}
|
|
689
|
+
if (added.size === 0 && !needAliases)
|
|
690
|
+
break;
|
|
691
|
+
if (inGraph.size + added.size > maxFiles || rebuilds >= maxHops) {
|
|
692
|
+
return answer(built, unreadNote ?? `the test walk stopped at ${inGraph.size} ${family} files (its budget is ${maxFiles}); tests further from the change are not known`);
|
|
693
|
+
}
|
|
694
|
+
// Past half the language's files, more rounds cost more than one graph of all of them: take them all now (within the budget).
|
|
695
|
+
const total = inGraph.size + [...codeOf.keys()].filter((p) => !inGraph.has(p)).length;
|
|
696
|
+
if ((inGraph.size + added.size) * 2 > total && total <= maxFiles)
|
|
697
|
+
for (const p of codeOf.keys())
|
|
698
|
+
if (!inGraph.has(p))
|
|
699
|
+
added.add(p);
|
|
700
|
+
for (const p of added)
|
|
701
|
+
inGraph.set(p, codeOf.get(p));
|
|
702
|
+
const rebuilt = [...inGraph].map(([p, code]) => ({ path: p, code: rewrite(p, code).code })).sort(byPath);
|
|
703
|
+
try {
|
|
704
|
+
facts = await buildFacts(family, rebuilt);
|
|
705
|
+
}
|
|
706
|
+
catch (err) {
|
|
707
|
+
return answer(built, `the ${family} test walk could not widen its graph (${err.message}); tests further from the change are not known`);
|
|
708
|
+
}
|
|
709
|
+
built = { facts, text: new Map(rebuilt.map((s) => [s.path, s.code])) };
|
|
710
|
+
aliased = true;
|
|
711
|
+
rebuilds++;
|
|
712
|
+
}
|
|
713
|
+
return answer(built, unreadNote);
|
|
714
|
+
}
|
|
385
715
|
function tooLarge(abs) {
|
|
386
716
|
try {
|
|
387
717
|
return fs.statSync(abs).size > MAX_FILE_BYTES;
|
|
@@ -405,17 +735,19 @@ function walkCutNote(cuts) {
|
|
|
405
735
|
* (with `prefilter`) only those other files whose text names a changed
|
|
406
736
|
* declaration or imports a changed file, directly or through a re-exporting
|
|
407
737
|
* module. A call or an import has to spell what it reaches, so the files
|
|
408
|
-
* left out cannot call into the change.
|
|
738
|
+
* left out cannot call into the change. `texts` keeps the other files'
|
|
739
|
+
* texts, for the test walk to widen over.
|
|
409
740
|
*/
|
|
410
741
|
async function graphSources(family, all, changed, items, root, prefilter) {
|
|
411
742
|
const relOf = (src) => src.rel.split(path.sep).join('/');
|
|
412
|
-
const byPath = (a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
413
743
|
const changedSources = [];
|
|
414
744
|
for (const rel of [...changed].sort()) {
|
|
415
745
|
const code = readSource(path.join(root, rel));
|
|
416
746
|
if (code !== null)
|
|
417
747
|
changedSources.push({ path: rel, code });
|
|
418
748
|
}
|
|
749
|
+
// Files too large (or unreadable) to read: their calls are not in any graph.
|
|
750
|
+
const unread = [];
|
|
419
751
|
if (!prefilter) {
|
|
420
752
|
const sources = [...changedSources];
|
|
421
753
|
for (const src of all) {
|
|
@@ -424,11 +756,13 @@ async function graphSources(family, all, changed, items, root, prefilter) {
|
|
|
424
756
|
const code = readSource(src.abs);
|
|
425
757
|
if (code !== null)
|
|
426
758
|
sources.push({ path: relOf(src), code });
|
|
759
|
+
else
|
|
760
|
+
unread.push(relOf(src));
|
|
427
761
|
}
|
|
428
|
-
return sources.sort(byPath);
|
|
762
|
+
return { sources: sources.sort(byPath), texts: [], unread };
|
|
429
763
|
}
|
|
430
764
|
if (changedSources.length === 0)
|
|
431
|
-
return [];
|
|
765
|
+
return { sources: [], texts: [], unread };
|
|
432
766
|
// The changed declarations' names, from a graph of the changed files alone.
|
|
433
767
|
const seed = await buildFacts(family, changedSources);
|
|
434
768
|
const names = new Set();
|
|
@@ -445,12 +779,6 @@ async function graphSources(family, all, changed, items, root, prefilter) {
|
|
|
445
779
|
}
|
|
446
780
|
}
|
|
447
781
|
}
|
|
448
|
-
if (names.size === 0)
|
|
449
|
-
return changedSources;
|
|
450
|
-
const modules = new Set();
|
|
451
|
-
for (const rel of changed)
|
|
452
|
-
for (const n of moduleNamesOf(rel))
|
|
453
|
-
modules.add(n);
|
|
454
782
|
const texts = [];
|
|
455
783
|
for (const src of all) {
|
|
456
784
|
const rel = relOf(src);
|
|
@@ -459,33 +787,57 @@ async function graphSources(family, all, changed, items, root, prefilter) {
|
|
|
459
787
|
const code = readSource(src.abs);
|
|
460
788
|
if (code !== null)
|
|
461
789
|
texts.push({ path: rel, code });
|
|
790
|
+
else
|
|
791
|
+
unread.push(rel);
|
|
462
792
|
}
|
|
463
|
-
|
|
793
|
+
if (names.size === 0)
|
|
794
|
+
return { sources: changedSources, texts, unread };
|
|
795
|
+
const modules = new Set();
|
|
796
|
+
for (const rel of changed)
|
|
797
|
+
for (const n of moduleNamesOf(rel))
|
|
798
|
+
modules.add(n);
|
|
799
|
+
const picked = pickNaming(family, texts, names, modules);
|
|
800
|
+
return { sources: [...changedSources, ...texts.filter((t) => picked.has(t.path))].sort(byPath), texts, unread };
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* The files (of `texts`) whose text names one of `names`, or names one of
|
|
804
|
+
* `modules` (an import of it), and to a fixed point the files that name a
|
|
805
|
+
* module re-exporting one of them. With `allow`, only allowed files are
|
|
806
|
+
* picked for naming, but a re-exporting module on the way is always picked
|
|
807
|
+
* (an importer reaches the declaration through it).
|
|
808
|
+
*/
|
|
809
|
+
function pickNaming(family, texts, names, modules, allow = () => true) {
|
|
464
810
|
const picked = new Set();
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
811
|
+
const nameRe = wordsRe(names);
|
|
812
|
+
if (nameRe)
|
|
813
|
+
for (const t of texts)
|
|
814
|
+
if (allow(t.path) && nameRe.test(t.code))
|
|
815
|
+
picked.add(t.path);
|
|
816
|
+
// Files that import a named module, and (to a fixed point) the importers of modules that re-export it.
|
|
817
|
+
const seen = new Set(modules);
|
|
469
818
|
const expanded = new Set();
|
|
470
|
-
let frontier = modules;
|
|
819
|
+
let frontier = new Set(modules);
|
|
471
820
|
while (frontier.size > 0) {
|
|
472
821
|
const re = wordsRe(frontier);
|
|
473
822
|
const next = new Set();
|
|
474
823
|
for (const t of texts) {
|
|
475
824
|
if (!re.test(t.code))
|
|
476
825
|
continue;
|
|
477
|
-
|
|
478
|
-
if (
|
|
826
|
+
const barrel = reExports(family, t.path, t.code);
|
|
827
|
+
if (barrel || allow(t.path))
|
|
828
|
+
picked.add(t.path);
|
|
829
|
+
if (expanded.has(t.path) || !barrel)
|
|
479
830
|
continue;
|
|
480
831
|
expanded.add(t.path);
|
|
481
832
|
for (const n of moduleNamesOf(t.path))
|
|
482
|
-
if (!
|
|
483
|
-
|
|
833
|
+
if (!seen.has(n)) {
|
|
834
|
+
seen.add(n);
|
|
484
835
|
next.add(n);
|
|
485
836
|
}
|
|
486
837
|
}
|
|
487
838
|
frontier = next;
|
|
488
839
|
}
|
|
489
|
-
return
|
|
840
|
+
return picked;
|
|
490
841
|
}
|
|
842
|
+
const byPath = (a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
491
843
|
//# sourceMappingURL=index.js.map
|