circle-ir-ai 4.43.0 → 4.44.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 +72 -0
- package/dist/blast-radius/radius.d.ts +1 -1
- package/dist/blast-radius/types.d.ts +1 -1
- package/dist/blast-radius/types.d.ts.map +1 -1
- package/dist/bom/usage.d.ts +2 -0
- package/dist/bom/usage.d.ts.map +1 -1
- package/dist/bom/usage.js +2 -2
- package/dist/bom/usage.js.map +1 -1
- package/dist/change-scope/canonical.d.ts +35 -0
- package/dist/change-scope/canonical.d.ts.map +1 -0
- package/dist/change-scope/canonical.js +84 -0
- package/dist/change-scope/canonical.js.map +1 -0
- package/dist/change-scope/index.d.ts +73 -0
- package/dist/change-scope/index.d.ts.map +1 -0
- package/dist/change-scope/index.js +1503 -0
- package/dist/change-scope/index.js.map +1 -0
- package/dist/change-scope/scope.d.ts +63 -0
- package/dist/change-scope/scope.d.ts.map +1 -0
- package/dist/change-scope/scope.js +725 -0
- package/dist/change-scope/scope.js.map +1 -0
- package/dist/change-scope/side.d.ts +161 -0
- package/dist/change-scope/side.d.ts.map +1 -0
- package/dist/change-scope/side.js +148 -0
- package/dist/change-scope/side.js.map +1 -0
- package/dist/change-scope/slice-rules.d.ts +129 -0
- package/dist/change-scope/slice-rules.d.ts.map +1 -0
- package/dist/change-scope/slice-rules.js +190 -0
- package/dist/change-scope/slice-rules.js.map +1 -0
- package/dist/change-scope/types.d.ts +191 -0
- package/dist/change-scope/types.d.ts.map +1 -0
- package/dist/change-scope/types.js +41 -0
- package/dist/change-scope/types.js.map +1 -0
- package/dist/dead-code/engine.d.ts +8 -0
- package/dist/dead-code/engine.d.ts.map +1 -1
- package/dist/dead-code/engine.js +3 -3
- package/dist/dead-code/engine.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +7 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +10 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/tools/change-scope.d.ts +35 -0
- package/dist/mcp/tools/change-scope.d.ts.map +1 -0
- package/dist/mcp/tools/change-scope.js +112 -0
- package/dist/mcp/tools/change-scope.js.map +1 -0
- package/dist/scope/product-paths.d.ts +8 -3
- package/dist/scope/product-paths.d.ts.map +1 -1
- package/dist/scope/product-paths.js +22 -3
- package/dist/scope/product-paths.js.map +1 -1
- package/dist/specifica/evidence-extractor.d.ts +4 -0
- package/dist/specifica/evidence-extractor.d.ts.map +1 -1
- package/dist/specifica/evidence-extractor.js +25 -9
- package/dist/specifica/evidence-extractor.js.map +1 -1
- package/dist/specifica/file-routes.d.ts +10 -3
- package/dist/specifica/file-routes.d.ts.map +1 -1
- package/dist/specifica/file-routes.js +52 -9
- package/dist/specifica/file-routes.js.map +1 -1
- package/dist/specifica/generator.d.ts.map +1 -1
- package/dist/specifica/generator.js +4 -1
- package/dist/specifica/generator.js.map +1 -1
- package/dist/specifica/index.d.ts +1 -1
- package/dist/specifica/index.d.ts.map +1 -1
- package/dist/specifica/index.js +1 -1
- package/dist/specifica/index.js.map +1 -1
- package/dist/specifica/java-erp-entries.d.ts +130 -0
- package/dist/specifica/java-erp-entries.d.ts.map +1 -0
- package/dist/specifica/java-erp-entries.js +867 -0
- package/dist/specifica/java-erp-entries.js.map +1 -0
- package/dist/specifica/learned-tree.d.ts +2 -0
- package/dist/specifica/learned-tree.d.ts.map +1 -1
- package/dist/specifica/learned-tree.js.map +1 -1
- package/dist/specifica/level-design.d.ts +41 -4
- package/dist/specifica/level-design.d.ts.map +1 -1
- package/dist/specifica/level-design.js +847 -24
- package/dist/specifica/level-design.js.map +1 -1
- package/dist/specifica/library-surface-java.d.ts +49 -0
- package/dist/specifica/library-surface-java.d.ts.map +1 -0
- package/dist/specifica/library-surface-java.js +235 -0
- package/dist/specifica/library-surface-java.js.map +1 -0
- package/dist/specifica/library-surface-python-rust.d.ts.map +1 -1
- package/dist/specifica/library-surface-python-rust.js +13 -0
- package/dist/specifica/library-surface-python-rust.js.map +1 -1
- package/dist/specifica/library-surface.d.ts +4 -1
- package/dist/specifica/library-surface.d.ts.map +1 -1
- package/dist/specifica/library-surface.js +5 -2
- package/dist/specifica/library-surface.js.map +1 -1
- package/dist/specifica/modules.d.ts +20 -1
- package/dist/specifica/modules.d.ts.map +1 -1
- package/dist/specifica/modules.js +403 -66
- package/dist/specifica/modules.js.map +1 -1
- package/dist/specifica/provenance.d.ts +6 -2
- package/dist/specifica/provenance.d.ts.map +1 -1
- package/dist/specifica/provenance.js +8 -3
- package/dist/specifica/provenance.js.map +1 -1
- package/dist/specifica/python-entries.d.ts +96 -0
- package/dist/specifica/python-entries.d.ts.map +1 -0
- package/dist/specifica/python-entries.js +475 -0
- package/dist/specifica/python-entries.js.map +1 -0
- package/dist/specifica/python-modules.d.ts +64 -0
- package/dist/specifica/python-modules.d.ts.map +1 -0
- package/dist/specifica/python-modules.js +433 -0
- package/dist/specifica/python-modules.js.map +1 -0
- package/dist/specifica/rule-facts.d.ts +105 -0
- package/dist/specifica/rule-facts.d.ts.map +1 -0
- package/dist/specifica/rule-facts.js +512 -0
- package/dist/specifica/rule-facts.js.map +1 -0
- package/dist/specifica/spec-generator.d.ts +3 -1
- package/dist/specifica/spec-generator.d.ts.map +1 -1
- package/dist/specifica/spec-generator.js +13 -7
- package/dist/specifica/spec-generator.js.map +1 -1
- package/dist/specifica/spec-tree.d.ts +24 -0
- package/dist/specifica/spec-tree.d.ts.map +1 -1
- package/dist/specifica/spec-tree.js +245 -47
- package/dist/specifica/spec-tree.js.map +1 -1
- package/dist/specifica/state-machines.d.ts +85 -0
- package/dist/specifica/state-machines.d.ts.map +1 -0
- package/dist/specifica/state-machines.js +1073 -0
- package/dist/specifica/state-machines.js.map +1 -0
- package/dist/specifica/throw-scopes.d.ts +94 -0
- package/dist/specifica/throw-scopes.d.ts.map +1 -0
- package/dist/specifica/throw-scopes.js +757 -0
- package/dist/specifica/throw-scopes.js.map +1 -0
- package/dist/specifica/tree-types.d.ts +24 -2
- package/dist/specifica/tree-types.d.ts.map +1 -1
- package/dist/specifica/tree-types.js.map +1 -1
- package/dist/specifica/ts-entries.d.ts +137 -0
- package/dist/specifica/ts-entries.d.ts.map +1 -0
- package/dist/specifica/ts-entries.js +616 -0
- package/dist/specifica/ts-entries.js.map +1 -0
- package/dist/specifica/ts-rule-sources.d.ts +48 -6
- package/dist/specifica/ts-rule-sources.d.ts.map +1 -1
- package/dist/specifica/ts-rule-sources.js +383 -32
- package/dist/specifica/ts-rule-sources.js.map +1 -1
- package/dist/specifica/types.d.ts +16 -0
- package/dist/specifica/types.d.ts.map +1 -1
- package/dist/specifica/use-cases.d.ts +36 -6
- package/dist/specifica/use-cases.d.ts.map +1 -1
- package/dist/specifica/use-cases.js +345 -45
- package/dist/specifica/use-cases.js.map +1 -1
- package/dist/specifica/validation-constraints.d.ts +36 -0
- package/dist/specifica/validation-constraints.d.ts.map +1 -0
- package/dist/specifica/validation-constraints.js +184 -0
- package/dist/specifica/validation-constraints.js.map +1 -0
- package/dist/utils/file-skip.d.ts.map +1 -1
- package/dist/utils/file-skip.js +19 -1
- package/dist/utils/file-skip.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,725 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The change scope over two sides (C4 0.7.1 §15.2–§15.3, §16; plan D29,
|
|
3
|
+
* D30, D32): pure.
|
|
4
|
+
*
|
|
5
|
+
* D32: 0.1 reuses only self-contained reads. When a file changed, every
|
|
6
|
+
* anchor with a `module_closure` or `route` read has `complete: false` with
|
|
7
|
+
* reason `closure_reuse_deferred` and re-runs, its digests and `reached`
|
|
8
|
+
* reported for information; tests are advisory (every entry `unproven`) and
|
|
9
|
+
* `select_all` is true. The deferral does not count against the top-level
|
|
10
|
+
* `complete`: every deferred anchor re-runs and every test runs, so a run can
|
|
11
|
+
* still be `exact`. An empty diff reuses everything. D30's positive-proof
|
|
12
|
+
* rules below are the design for 0.2, run only with `closureReuse` (the
|
|
13
|
+
* engine flag `CIRCLE_IR_AI_CHANGE_SCOPE_CLOSURE_REUSE=1`, off by default,
|
|
14
|
+
* experimental); the flag's state is bound into `rules`.
|
|
15
|
+
*
|
|
16
|
+
* Slices are bytes, and the facts only choose the files (D29). A
|
|
17
|
+
* `module_closure` is the module and every in-repository module it reaches by
|
|
18
|
+
* imports, same-package files (Java, Go) and the graph's rows, followed to a
|
|
19
|
+
* fixpoint, with the non-code files they import and the build and tool
|
|
20
|
+
* configuration over each module (`BUILD_CONFIG`), each by its bytes. A
|
|
21
|
+
* `route` is the closure of every module on the registration chain from an
|
|
22
|
+
* app entry, with the HTML file that names it. A `decl_text` is a part per
|
|
23
|
+
* declaration: its raw bytes from its first decorator.
|
|
24
|
+
*
|
|
25
|
+
* An anchor's reach set is the module closure of the module that holds `at`
|
|
26
|
+
* (or of its route chain). It is reached when a changed declaration or file
|
|
27
|
+
* lies in its reach set or slice, or its digests differ. Its `complete`
|
|
28
|
+
* (§15.3) needs both:
|
|
29
|
+
* - A. a slice that can be computed soundly: no in-repository name that
|
|
30
|
+
* resolves nowhere, no module whose imports are unknown, no stylesheet
|
|
31
|
+
* import not understood, a route chain that resolves from an app entry, no
|
|
32
|
+
* link out of the tree, no cut walk;
|
|
33
|
+
* - B. positive proof (D30), for `module_closure` and `route` reads: every
|
|
34
|
+
* changed file is in the slice's bytes, or is source in a fully resolved
|
|
35
|
+
* language that parsed completely, is not configuration by file pattern,
|
|
36
|
+
* is not under a framework's convention roots, and is reached by some
|
|
37
|
+
* followed import (the orphan rule), while nothing in the closure uses a
|
|
38
|
+
* loading form the engine does not follow. Test files are exempt from the
|
|
39
|
+
* convention and orphan rules for non-test anchors. `decl_text`, `file` and
|
|
40
|
+
* `config_key` reads are self-contained: B does not apply to them.
|
|
41
|
+
*
|
|
42
|
+
* `reached[]` follows every reach-graph edge, a class's members with it;
|
|
43
|
+
* `impacted_tests[]` is selected by file closure. Moves come from circle-ir's
|
|
44
|
+
* `detectMoves`.
|
|
45
|
+
*
|
|
46
|
+
* The declared gaps (C4 §16.3, D30), which `complete: true` and a run's
|
|
47
|
+
* `exact` are relative to: a module outside a closure that writes into a
|
|
48
|
+
* closure module's exports at import time (`setCurrency('EUR')` in
|
|
49
|
+
* `main.ts`), and convention loading by frameworks not on `CONVENTIONS` of
|
|
50
|
+
* a file that some followed import also reaches.
|
|
51
|
+
*/
|
|
52
|
+
import { createRequire } from 'module';
|
|
53
|
+
import { detectMoves } from 'circle-ir';
|
|
54
|
+
import { anchorDigest, blake3Hex, blake3Of, byCodePoints, jcs } from './canonical.js';
|
|
55
|
+
import { SideIndex, tierOf } from './side.js';
|
|
56
|
+
import { sliceRulesDescription } from './slice-rules.js';
|
|
57
|
+
import { CHANGE_SCOPE_SCHEME, READ_SHAPE_CONTEXT, READ_SHAPES, TREE_FACTS, } from './types.js';
|
|
58
|
+
const req = createRequire(import.meta.url);
|
|
59
|
+
const ENGINE_VERSION = req('../../package.json').version;
|
|
60
|
+
const CIRCLE_IR_VERSION = req('circle-ir/package.json').version;
|
|
61
|
+
export const MAX_ANCHORS = 10_000;
|
|
62
|
+
const MAX_INCOMPLETE = 100;
|
|
63
|
+
const ANCHOR_KEYS = ['anchor_id', 'at', 'reads'];
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
// Request checks: anything malformed is refused (C4 §15.4's 400), never guessed
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
const isStr = (v) => typeof v === 'string' && v.length > 0;
|
|
68
|
+
const keysAre = (o, allowed, required) => Object.keys(o).every((k) => allowed.includes(k)) && required.every((k) => isStr(o[k]));
|
|
69
|
+
function atForm(at) {
|
|
70
|
+
if (!at || typeof at !== 'object')
|
|
71
|
+
return null;
|
|
72
|
+
if (keysAre(at, ['decl'], ['decl']))
|
|
73
|
+
return 'decl';
|
|
74
|
+
if (keysAre(at, ['file'], ['file']))
|
|
75
|
+
return 'file';
|
|
76
|
+
const a = at;
|
|
77
|
+
if (keysAre(at, ['route', 'decl'], ['route']) && (a.decl === undefined || isStr(a.decl)))
|
|
78
|
+
return 'route';
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const TARGETS = {
|
|
82
|
+
decl_text: ['decl'], file: ['file'], module_closure: ['file', 'decl'], route: ['route'], config_key: ['key'],
|
|
83
|
+
};
|
|
84
|
+
const CLOSURE_SHAPES = new Set(['module_closure', 'route']);
|
|
85
|
+
function readProblem(r) {
|
|
86
|
+
if (!r || typeof r !== 'object' || !('read_shape' in r))
|
|
87
|
+
return 'a read needs read_shape';
|
|
88
|
+
const read = r;
|
|
89
|
+
if (!READ_SHAPES.includes(read.read_shape)) {
|
|
90
|
+
return `unknown or deferred read shape ${JSON.stringify(read.read_shape)}: send an empty reads[] for a control that declares one (C4 §16)`;
|
|
91
|
+
}
|
|
92
|
+
const shape = read.read_shape;
|
|
93
|
+
if (Object.keys(read).some((k) => k !== 'read_shape' && k !== 'target'))
|
|
94
|
+
return `${shape} takes no parameters`;
|
|
95
|
+
const t = read.target;
|
|
96
|
+
const form = !t || typeof t !== 'object' ? null
|
|
97
|
+
: keysAre(t, ['file', 'key'], ['file', 'key']) ? 'key' : atForm(t);
|
|
98
|
+
return form && TARGETS[shape].includes(form) ? null : `${shape} takes ${TARGETS[shape].map((f) => (f === 'key' ? '{file, key}' : f === 'route' ? '{route, decl?}' : `{${f}}`)).join(' or ')}`;
|
|
99
|
+
}
|
|
100
|
+
/** Throws a `TypeError` naming the anchor for any request C4 §15.4 answers 400. */
|
|
101
|
+
export function checkAnchors(anchors) {
|
|
102
|
+
if (!Array.isArray(anchors))
|
|
103
|
+
throw new TypeError('anchors must be an array');
|
|
104
|
+
if (anchors.length === 0)
|
|
105
|
+
throw new TypeError('anchors must hold at least one anchor (C4 §15.1)');
|
|
106
|
+
if (anchors.length > MAX_ANCHORS)
|
|
107
|
+
throw new TypeError(`more than ${MAX_ANCHORS} anchors`);
|
|
108
|
+
const seen = new Set();
|
|
109
|
+
for (const a of anchors) {
|
|
110
|
+
if (!a || typeof a !== 'object' || !isStr(a.anchor_id))
|
|
111
|
+
throw new TypeError('every anchor needs an anchor_id');
|
|
112
|
+
const extra = Object.keys(a).filter((k) => !ANCHOR_KEYS.includes(k));
|
|
113
|
+
if (extra.length > 0)
|
|
114
|
+
throw new TypeError(`anchor ${a.anchor_id}: unknown key ${extra.map((k) => JSON.stringify(k)).join(', ')}`);
|
|
115
|
+
if (seen.has(a.anchor_id))
|
|
116
|
+
throw new TypeError(`anchor ${a.anchor_id}: anchor_id is repeated`);
|
|
117
|
+
seen.add(a.anchor_id);
|
|
118
|
+
if (!atForm(a.at))
|
|
119
|
+
throw new TypeError(`anchor ${a.anchor_id}: "at" must be exactly one of {decl}, {file} or {route, decl?}`);
|
|
120
|
+
if (a.reads !== undefined && !Array.isArray(a.reads))
|
|
121
|
+
throw new TypeError(`anchor ${a.anchor_id}: reads must be an array`);
|
|
122
|
+
for (const r of a.reads ?? []) {
|
|
123
|
+
const p = readProblem(r);
|
|
124
|
+
if (p)
|
|
125
|
+
throw new TypeError(`anchor ${a.anchor_id}: ${p}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The module closure of `seeds` (C4 §16.1): imports, same-package files
|
|
131
|
+
* (Java, Go) and the files the declarations' graph rows point to, followed
|
|
132
|
+
* together to a fixpoint, with the build and tool configuration over each
|
|
133
|
+
* module (config that is code walked like a module).
|
|
134
|
+
*/
|
|
135
|
+
function moduleClosure(idx, seeds) {
|
|
136
|
+
const side = idx.side;
|
|
137
|
+
const out = { files: new Map(), why: [], hard: [], forms: [] };
|
|
138
|
+
const seen = new Set();
|
|
139
|
+
const queue = [];
|
|
140
|
+
const add = (p) => { if (!seen.has(p)) {
|
|
141
|
+
seen.add(p);
|
|
142
|
+
queue.push(p);
|
|
143
|
+
} };
|
|
144
|
+
for (const s of seeds)
|
|
145
|
+
add(s);
|
|
146
|
+
for (let i = 0; i < queue.length; i++) {
|
|
147
|
+
const f = queue[i];
|
|
148
|
+
const hash = side.fileHash(f);
|
|
149
|
+
if (hash === null) {
|
|
150
|
+
out.hard.push(`${side.name}: ${f} is not tracked or cannot be read`);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
out.files.set(f, hash);
|
|
154
|
+
const kind = side.fileKind(f);
|
|
155
|
+
if (kind === 'symlink') {
|
|
156
|
+
// Hop by hop (B2): every link passed through counts by its text, and the file it lands on by its bytes.
|
|
157
|
+
const r = side.resolveLink(f);
|
|
158
|
+
for (const h of r?.hops ?? []) {
|
|
159
|
+
const hh = side.fileHash(h);
|
|
160
|
+
if (hh !== null)
|
|
161
|
+
out.files.set(h, hh);
|
|
162
|
+
}
|
|
163
|
+
if (r?.target)
|
|
164
|
+
add(r.target);
|
|
165
|
+
else
|
|
166
|
+
out.hard.push(`${side.name}: ${r?.why ?? `${f} cannot be followed`}`);
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
const imports = side.imports(f);
|
|
170
|
+
if (imports === null) {
|
|
171
|
+
out.why.push(kind === 'code'
|
|
172
|
+
? `${side.name}: the imports of ${f} are not known (skipped for size or by directory, or unparsable)`
|
|
173
|
+
: `${side.name}: ${f} is ${kind === 'gitlink' ? 'a submodule' : 'in a language'} with no import facts`);
|
|
174
|
+
}
|
|
175
|
+
for (const imp of imports ?? []) {
|
|
176
|
+
if (imp.kind === 'file' && imp.path)
|
|
177
|
+
add(imp.path);
|
|
178
|
+
else if (imp.kind === 'missing')
|
|
179
|
+
out.why.push(`${side.name}: ${f} imports ${imp.specifier}, an in-repository name that resolves to nothing tracked`);
|
|
180
|
+
else if (imp.kind === 'opaque')
|
|
181
|
+
out.why.push(`${side.name}: ${f} imports ${imp.specifier}, a package committed under node_modules, whose imports are not known`);
|
|
182
|
+
}
|
|
183
|
+
for (const form of side.forms(f))
|
|
184
|
+
out.forms.push(`${f}: ${form}`);
|
|
185
|
+
if (side.partial.has(f))
|
|
186
|
+
out.why.push(`${side.name}: ${f} did not parse completely`);
|
|
187
|
+
// The graph's rows add what imports do not show: a qualified name used without an import, polymorphic targets.
|
|
188
|
+
for (const id of idx.inFile(f))
|
|
189
|
+
for (const e of idx.edges(id)) {
|
|
190
|
+
const tf = idx.fileOf(e.to);
|
|
191
|
+
if (tf && tf !== f)
|
|
192
|
+
add(tf);
|
|
193
|
+
}
|
|
194
|
+
// Build and tool configuration: config that is code is walked like a module.
|
|
195
|
+
for (const m of side.manifests(f)) {
|
|
196
|
+
if (side.fileKind(m) === 'code')
|
|
197
|
+
add(m);
|
|
198
|
+
else if (!out.files.has(m)) {
|
|
199
|
+
const h = side.fileHash(m);
|
|
200
|
+
if (h !== null)
|
|
201
|
+
out.files.set(m, h);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return out;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The registration chain of a route (C4 §16.1 `route`): every module on an
|
|
209
|
+
* import path from an app entry to a module that registers the route, the
|
|
210
|
+
* route component's module, and the HTML files that name the entry. Null
|
|
211
|
+
* when nothing registers the route. Adds to `why` a chain with no app entry
|
|
212
|
+
* and a registration or mount the facts could not resolve on it (§15.3 A5).
|
|
213
|
+
*/
|
|
214
|
+
function routeChain(idx, route, decl, why) {
|
|
215
|
+
const side = idx.side;
|
|
216
|
+
const entries = idx.routes(route, decl);
|
|
217
|
+
if (entries.length === 0)
|
|
218
|
+
return null;
|
|
219
|
+
const registering = [...new Set(entries.map((e) => e.file))];
|
|
220
|
+
const up = new Set(registering);
|
|
221
|
+
const todo = [...registering];
|
|
222
|
+
while (todo.length > 0)
|
|
223
|
+
for (const i of side.importers(todo.pop()))
|
|
224
|
+
if (!up.has(i)) {
|
|
225
|
+
up.add(i);
|
|
226
|
+
todo.push(i);
|
|
227
|
+
}
|
|
228
|
+
const starts = [...up].filter((f) => side.appEntries.has(f));
|
|
229
|
+
const chain = new Set(registering);
|
|
230
|
+
if (starts.length === 0) {
|
|
231
|
+
why.push(`${side.name}: no app entry leads to ${registering.join(', ')}, so the registration chain of ${route} does not resolve`);
|
|
232
|
+
for (const f of up)
|
|
233
|
+
chain.add(f);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
const fwd = [...starts];
|
|
237
|
+
for (const f of starts) {
|
|
238
|
+
chain.add(f);
|
|
239
|
+
for (const h of side.namedBy(f))
|
|
240
|
+
chain.add(h);
|
|
241
|
+
}
|
|
242
|
+
while (fwd.length > 0) {
|
|
243
|
+
for (const i of side.imports(fwd.pop()) ?? [])
|
|
244
|
+
if (i.kind === 'file' && i.path && up.has(i.path) && !chain.has(i.path)) {
|
|
245
|
+
chain.add(i.path);
|
|
246
|
+
fwd.push(i.path);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
for (const id of new Set(entries.map((e) => e.id))) {
|
|
251
|
+
const f = idx.fileOf(id);
|
|
252
|
+
if (f)
|
|
253
|
+
chain.add(f);
|
|
254
|
+
}
|
|
255
|
+
for (const p of idx.parts) {
|
|
256
|
+
for (const r of p.graph.unresolvedRegistrations ?? []) {
|
|
257
|
+
if (chain.has(r.site.file))
|
|
258
|
+
why.push(`${side.name}: ${r.site.file}:${r.site.line} registers a ${r.reason === 'mount-unresolved' ? 'mount' : 'handler'} the facts do not resolve (${r.reason})`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return [...chain].sort(byCodePoints);
|
|
262
|
+
}
|
|
263
|
+
/** One read at one side: its digest parts, or null when its target is not there. */
|
|
264
|
+
function readAt(idx, read, into) {
|
|
265
|
+
const side = idx.side;
|
|
266
|
+
const descriptor = jcs({ read_shape: read.read_shape, target: read.target });
|
|
267
|
+
const fromClosure = (c) => {
|
|
268
|
+
into.why.push(...c.hard);
|
|
269
|
+
into.closureWhy.push(...c.why);
|
|
270
|
+
into.forms.push(...c.forms);
|
|
271
|
+
return [...c.files].map(([p, h]) => { into.sliceFiles.add(p); return [p, side.fileMode(p) ?? '', h]; });
|
|
272
|
+
};
|
|
273
|
+
switch (read.read_shape) {
|
|
274
|
+
case 'decl_text': {
|
|
275
|
+
const ids = idx.select(read.target.decl);
|
|
276
|
+
if (ids.length === 0)
|
|
277
|
+
return null;
|
|
278
|
+
const parts = [];
|
|
279
|
+
for (const id of ids) {
|
|
280
|
+
const file = idx.fileOf(id);
|
|
281
|
+
const bytes = side.declText(id);
|
|
282
|
+
if (bytes === null)
|
|
283
|
+
into.why.push(`${side.name}: the bytes of ${read.target.decl} cannot be read${side.declProblem(id) ? `: ${side.declProblem(id)}` : ''}`);
|
|
284
|
+
if (side.partial.has(file))
|
|
285
|
+
into.why.push(`${side.name}: ${file} did not parse completely`);
|
|
286
|
+
parts.push([file, id, blake3Hex(bytes ?? new Uint8Array())]);
|
|
287
|
+
for (const d of idx.within(id))
|
|
288
|
+
into.sliceDecls.add(d);
|
|
289
|
+
}
|
|
290
|
+
return { descriptor, parts };
|
|
291
|
+
}
|
|
292
|
+
case 'module_closure': {
|
|
293
|
+
const t = read.target;
|
|
294
|
+
const seeds = t.decl !== undefined
|
|
295
|
+
? [...new Set(idx.select(t.decl).map((id) => idx.fileOf(id)))]
|
|
296
|
+
: side.fileHash(t.file) === null ? [] : [t.file];
|
|
297
|
+
if (seeds.length === 0)
|
|
298
|
+
return null;
|
|
299
|
+
return { descriptor, parts: fromClosure(moduleClosure(idx, seeds)) };
|
|
300
|
+
}
|
|
301
|
+
case 'route': {
|
|
302
|
+
const chain = routeChain(idx, read.target.route, read.target.decl, into.closureWhy);
|
|
303
|
+
return chain ? { descriptor, parts: fromClosure(moduleClosure(idx, chain)) } : null;
|
|
304
|
+
}
|
|
305
|
+
default: {
|
|
306
|
+
// `file`, and `config_key` = `file` of the containing file: its stored bytes and its mode (S2); a symlink's
|
|
307
|
+
// text at every hop and the bytes it lands on, resolved hop by hop against the listing (B2).
|
|
308
|
+
const file = read.target.file;
|
|
309
|
+
const hash = side.fileHash(file);
|
|
310
|
+
if (hash === null)
|
|
311
|
+
return null;
|
|
312
|
+
const parts = [[file, side.fileMode(file) ?? '', hash]];
|
|
313
|
+
into.sliceFiles.add(file);
|
|
314
|
+
const link = side.resolveLink(file);
|
|
315
|
+
if (link) {
|
|
316
|
+
const also = link.target ? [...link.hops, link.target] : link.hops;
|
|
317
|
+
for (const p of also) {
|
|
318
|
+
const h = side.fileHash(p);
|
|
319
|
+
if (p === file || h === null)
|
|
320
|
+
continue;
|
|
321
|
+
parts.push([p, side.fileMode(p) ?? '', h]);
|
|
322
|
+
into.sliceFiles.add(p);
|
|
323
|
+
}
|
|
324
|
+
if (!link.target)
|
|
325
|
+
into.why.push(`${side.name}: ${link.why ?? `${file} cannot be followed`}`);
|
|
326
|
+
}
|
|
327
|
+
return { descriptor, parts };
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function anchorAt(idx, anchor) {
|
|
332
|
+
const side = idx.side;
|
|
333
|
+
const at = anchor.at;
|
|
334
|
+
const out = { located: false, testAnchor: false, reachFiles: new Set(), sliceFiles: new Set(), sliceDecls: new Set(), parts: [], missing: [], why: [], closureWhy: [], forms: [] };
|
|
335
|
+
// Reach is for reporting: what makes it unsound is not the anchor's completeness (§15.3, over the slice only).
|
|
336
|
+
const aside = [];
|
|
337
|
+
const form = atForm(at);
|
|
338
|
+
const seeds = form === 'decl' ? [...new Set(idx.select(at.decl).map((id) => idx.fileOf(id)))]
|
|
339
|
+
: form === 'file' ? (side.fileHash(at.file) === null ? [] : [at.file])
|
|
340
|
+
: routeChain(idx, at.route, at.decl, aside) ?? [];
|
|
341
|
+
out.located = seeds.length > 0;
|
|
342
|
+
out.testAnchor = seeds.some((f) => side.isTest(f));
|
|
343
|
+
out.reachFiles = new Set(moduleClosure(idx, seeds).files.keys());
|
|
344
|
+
for (const read of anchor.reads ?? []) {
|
|
345
|
+
const part = readAt(idx, read, out);
|
|
346
|
+
if (part === null) {
|
|
347
|
+
out.missing.push(jcs({ read_shape: read.read_shape, target: read.target }));
|
|
348
|
+
out.parts = null;
|
|
349
|
+
}
|
|
350
|
+
else if (out.parts)
|
|
351
|
+
out.parts.push(part);
|
|
352
|
+
}
|
|
353
|
+
if (side.walkCut)
|
|
354
|
+
out.why.push(`${side.name}: the walk stopped at its bounds`);
|
|
355
|
+
return out;
|
|
356
|
+
}
|
|
357
|
+
const reachedMemo = new WeakMap();
|
|
358
|
+
/** The files some followed import, reference or graph row of any tracked file reaches (D30's orphan rule). */
|
|
359
|
+
function reachedByImport(idx) {
|
|
360
|
+
const hit = reachedMemo.get(idx);
|
|
361
|
+
if (hit)
|
|
362
|
+
return hit;
|
|
363
|
+
const side = idx.side;
|
|
364
|
+
const out = new Set(side.named);
|
|
365
|
+
for (const p of side.paths) {
|
|
366
|
+
for (const i of side.imports(p) ?? [])
|
|
367
|
+
if (i.kind === 'file' && i.path && i.path !== p)
|
|
368
|
+
out.add(i.path);
|
|
369
|
+
const r = side.resolveLink(p);
|
|
370
|
+
if (r) {
|
|
371
|
+
for (const h of r.hops)
|
|
372
|
+
out.add(h);
|
|
373
|
+
if (r.target)
|
|
374
|
+
out.add(r.target);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
for (const id of idx.decls.keys()) {
|
|
378
|
+
const f = idx.fileOf(id);
|
|
379
|
+
for (const e of idx.edges(id)) {
|
|
380
|
+
const tf = idx.fileOf(e.to);
|
|
381
|
+
if (tf && tf !== f)
|
|
382
|
+
out.add(tf);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
reachedMemo.set(idx, out);
|
|
386
|
+
return out;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Why a changed file is not understood (C4 0.7.1 §15.3 B; D30), or null when
|
|
390
|
+
* it is, judged at each side where it exists: not source in a fully resolved
|
|
391
|
+
* language, not parsed completely, configuration by file pattern, under a
|
|
392
|
+
* framework's convention roots, or an orphan that no followed import
|
|
393
|
+
* reaches. Test files are exempt from the convention and orphan rules unless
|
|
394
|
+
* the anchor is itself a test.
|
|
395
|
+
*/
|
|
396
|
+
function notUnderstood(idx, c, testAnchor) {
|
|
397
|
+
for (const i of idx) {
|
|
398
|
+
const side = i.side;
|
|
399
|
+
if (side.fileKind(c) === null)
|
|
400
|
+
continue;
|
|
401
|
+
const base = side.notUnderstood(c);
|
|
402
|
+
if (base)
|
|
403
|
+
return base.reason;
|
|
404
|
+
if (!testAnchor && side.isTest(c))
|
|
405
|
+
continue;
|
|
406
|
+
const fw = side.convention(c);
|
|
407
|
+
if (fw)
|
|
408
|
+
return `convention: ${fw}`;
|
|
409
|
+
if (!reachedByImport(i).has(c))
|
|
410
|
+
return 'orphan: no followed import reaches it';
|
|
411
|
+
}
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
const listed = (xs, n = 3) => (xs.length <= n ? xs.join(', ') : `${xs.slice(0, n).join(', ')} and ${xs.length - n} more`);
|
|
415
|
+
function anchorScope(idx, anchor, sides, changed, changedFiles, rules, closureReuse, emptyDiff) {
|
|
416
|
+
const notes = [];
|
|
417
|
+
const via = new Set();
|
|
418
|
+
let touched = false;
|
|
419
|
+
sides.forEach((s, n) => {
|
|
420
|
+
for (const f of changedFiles)
|
|
421
|
+
if (s.reachFiles.has(f) || s.sliceFiles.has(f))
|
|
422
|
+
touched = true;
|
|
423
|
+
for (const id of changed) {
|
|
424
|
+
const f = idx[n].fileOf(id);
|
|
425
|
+
if (s.sliceDecls.has(id) || (f !== undefined && (s.reachFiles.has(f) || s.sliceFiles.has(f))))
|
|
426
|
+
via.add(id);
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
let reached = touched || via.size > 0;
|
|
430
|
+
let complete = true;
|
|
431
|
+
let digests = [null, null];
|
|
432
|
+
const reads = anchor.reads ?? [];
|
|
433
|
+
const nowhere = sides[0].missing.filter((r) => sides[1].missing.includes(r));
|
|
434
|
+
if (nowhere.length > 0) {
|
|
435
|
+
// Its slice cannot be computed at all (§15.3 A).
|
|
436
|
+
notes.push(`a read names nothing at base or head: ${nowhere.join(', ')}`);
|
|
437
|
+
reached = true;
|
|
438
|
+
complete = false;
|
|
439
|
+
}
|
|
440
|
+
if (!sides[0].located && !sides[1].located) {
|
|
441
|
+
// Answered, not refused, with null digests (§15.2).
|
|
442
|
+
notes.push('"at" names nothing at base or head');
|
|
443
|
+
reached = true;
|
|
444
|
+
}
|
|
445
|
+
else if (reads.length > 0 && nowhere.length === 0) {
|
|
446
|
+
digests = [sides[0].parts ? anchorDigest(rules, sides[0].parts) : null, sides[1].parts ? anchorDigest(rules, sides[1].parts) : null];
|
|
447
|
+
const oneSide = [...new Set([...sides[0].missing, ...sides[1].missing])];
|
|
448
|
+
if (oneSide.length > 0)
|
|
449
|
+
notes.push(`a read resolves at one side only: ${oneSide.join(', ')}`);
|
|
450
|
+
if (digests[0] !== digests[1] || oneSide.length > 0)
|
|
451
|
+
reached = true;
|
|
452
|
+
}
|
|
453
|
+
// Reasons that hold whatever changed (the self-contained reads', a link a closure cannot follow, unreadable bytes,
|
|
454
|
+
// a cut walk), and those that only proving a changed file outside a closure needs (0.2, behind the flag).
|
|
455
|
+
const why = [...new Set([...sides[0].why, ...sides[1].why])].sort(byCodePoints);
|
|
456
|
+
const closureWhy = [...new Set([...sides[0].closureWhy, ...sides[1].closureWhy])].filter((w) => !why.includes(w)).sort(byCodePoints);
|
|
457
|
+
if (why.length > 0)
|
|
458
|
+
complete = false;
|
|
459
|
+
const closureRead = reads.some((r) => CLOSURE_SHAPES.has(r.read_shape));
|
|
460
|
+
const answer = (c, extra = {}, lead = []) => ({
|
|
461
|
+
anchor_id: anchor.anchor_id, reached, complete: c, ...extra,
|
|
462
|
+
via: [...via].sort(byCodePoints), digest_base: digests[0], digest_head: digests[1], notes: [...lead, ...notes, ...why, ...closureWhy],
|
|
463
|
+
});
|
|
464
|
+
if (closureRead && !closureReuse) {
|
|
465
|
+
// D32: without the experimental flag, an empty diff reuses a closure or route anchor, unless it is incomplete for a
|
|
466
|
+
// reason that holds whatever changed (a read that names nothing, N2; a link out of the tree or unreadable bytes, B2).
|
|
467
|
+
if (emptyDiff)
|
|
468
|
+
return { scope: answer(complete), counts: complete };
|
|
469
|
+
// A PR that changed a file re-runs it; nothing below can make it complete. The deferral hides only itself (S3).
|
|
470
|
+
const other = !complete;
|
|
471
|
+
return {
|
|
472
|
+
scope: answer(false, { reason: 'closure_reuse_deferred' }, [
|
|
473
|
+
'closure and route reuse waits for 0.2 (D32): this anchor always re-runs; its digests and reach are for information',
|
|
474
|
+
...(other ? ['incomplete for another reason as well, which the deferral does not cover, so the run is not complete'] : []),
|
|
475
|
+
]),
|
|
476
|
+
counts: !other,
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
if (closureWhy.length > 0)
|
|
480
|
+
complete = false;
|
|
481
|
+
// B, positive proof (D30), for closure reads: every changed file in the slice's bytes, or provably outside it.
|
|
482
|
+
if (closureRead) {
|
|
483
|
+
const outside = changedFiles.filter((c) => !sides[0].sliceFiles.has(c) && !sides[1].sliceFiles.has(c));
|
|
484
|
+
const testAnchor = sides[0].testAnchor || sides[1].testAnchor;
|
|
485
|
+
const unknown = outside.map((c) => [c, notUnderstood(idx, c, testAnchor)]).filter((x) => x[1] !== null);
|
|
486
|
+
const forms = [...new Set([...sides[0].forms, ...sides[1].forms])].sort(byCodePoints);
|
|
487
|
+
if (unknown.length > 0) {
|
|
488
|
+
complete = false;
|
|
489
|
+
notes.push(`changed, outside the slice and not understood, so not provably outside it (D30): ${listed(unknown.map(([c, why]) => `${c} (${why})`))}`);
|
|
490
|
+
}
|
|
491
|
+
else if (outside.length > 0 && forms.length > 0) {
|
|
492
|
+
complete = false;
|
|
493
|
+
notes.push(`the closure uses a loading form the engine does not follow (${listed(forms, 2)}), so ${outside.length} changed file(s) outside it are not provably outside (D30)`);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return { scope: answer(complete), counts: complete };
|
|
497
|
+
}
|
|
498
|
+
// ---------------------------------------------------------------------------
|
|
499
|
+
// The answer
|
|
500
|
+
// ---------------------------------------------------------------------------
|
|
501
|
+
function changedDecls(base, head) {
|
|
502
|
+
const files = (idx) => idx.parts.flatMap((p) => p.graph.files);
|
|
503
|
+
const { diff, moves } = detectMoves(files(base), files(head));
|
|
504
|
+
const out = new Map();
|
|
505
|
+
for (const [, after] of diff.body_changed)
|
|
506
|
+
out.set(after.id, { id: after.id, change: 'changed', columns: ['body_hash'] });
|
|
507
|
+
for (const d of diff.added)
|
|
508
|
+
out.set(d.id, { id: d.id, change: 'added' });
|
|
509
|
+
for (const d of diff.removed)
|
|
510
|
+
out.set(d.id, { id: d.id, change: 'removed' });
|
|
511
|
+
for (const m of moves)
|
|
512
|
+
out.set(m.to.id, { id: m.to.id, change: 'moved', from: m.from.id, ...(m.from.body_hash !== m.to.body_hash ? { columns: ['body_hash'] } : {}) });
|
|
513
|
+
// Decorators ids@0.1 leaves outside the body (an export statement's, a member's): a change there is a change of the declaration.
|
|
514
|
+
for (const id of new Set([...base.side.decorators.keys(), ...head.side.decorators.keys()])) {
|
|
515
|
+
if (!base.decls.has(id) || !head.decls.has(id) || base.side.decorators.get(id) === head.side.decorators.get(id))
|
|
516
|
+
continue;
|
|
517
|
+
const c = out.get(id) ?? { id, change: 'changed', columns: [] };
|
|
518
|
+
c.columns = [...new Set([...(c.columns ?? []), 'decorators'])].sort(byCodePoints);
|
|
519
|
+
out.set(id, c);
|
|
520
|
+
}
|
|
521
|
+
return [...out.values()].sort((a, b) => byCodePoints(a.id, b.id));
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Unresolved sites that may call a target unseen: circle-ir's `couldReach`
|
|
525
|
+
* predicate (not exported at its package root) over every body. Wider than
|
|
526
|
+
* `reach()` on purpose: `reach()` skips a target that has a strong path, so
|
|
527
|
+
* a test reaching it only through a computed callee went unseen (R6).
|
|
528
|
+
*/
|
|
529
|
+
function unresolvedInto(idx, targets) {
|
|
530
|
+
const names = new Set();
|
|
531
|
+
let modules = false;
|
|
532
|
+
let callable = false;
|
|
533
|
+
for (const id of targets) {
|
|
534
|
+
const d = idx.decls.get(id)?.decl;
|
|
535
|
+
if (!d || d.kind === 'field')
|
|
536
|
+
continue;
|
|
537
|
+
if (d.kind === 'module')
|
|
538
|
+
modules = true;
|
|
539
|
+
else {
|
|
540
|
+
callable = true;
|
|
541
|
+
names.add(d.name);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
const out = [];
|
|
545
|
+
const side = idx.side.name;
|
|
546
|
+
for (const p of idx.parts) {
|
|
547
|
+
for (const u of p.graph.unresolved) {
|
|
548
|
+
if (u.reason === 'external')
|
|
549
|
+
continue;
|
|
550
|
+
const load = u.methodName === '<module>';
|
|
551
|
+
const computed = !load && (u.methodName.startsWith('<') || u.methodName.startsWith('('));
|
|
552
|
+
if (load ? modules : computed ? callable : names.has(u.methodName)) {
|
|
553
|
+
out.push({ reason: 'unresolved_call', side, path: u.site.file, line: u.site.line, detail: `${load ? 'a computed module load' : `a call to ${u.methodName}`} (${u.reason}) may reach a changed declaration unseen` });
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
if (!callable)
|
|
557
|
+
continue;
|
|
558
|
+
for (const r of p.graph.unresolvedRegistrations ?? []) {
|
|
559
|
+
if (r.reason === 'handler-unresolved')
|
|
560
|
+
out.push({ reason: 'unresolved_registration', side, path: r.site.file, line: r.site.line, detail: `a handler that was not resolved may run a changed declaration` });
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return out;
|
|
564
|
+
}
|
|
565
|
+
export function scopeOf(baseSide, headSide, anchors, graphFailures = [], opts = {}) {
|
|
566
|
+
const closureReuse = opts.closureReuse === true;
|
|
567
|
+
const idx = [new SideIndex(baseSide), new SideIndex(headSide)];
|
|
568
|
+
const [base, head] = idx;
|
|
569
|
+
const graphs = [...new Set(idx.flatMap((i) => i.parts.map((p) => p.graph.scheme)))].sort(byCodePoints);
|
|
570
|
+
const rules = blake3Of({
|
|
571
|
+
producer: 'circle-ir-ai/change-scope', version: ENGINE_VERSION, circle_ir: CIRCLE_IR_VERSION, graphs,
|
|
572
|
+
context: READ_SHAPE_CONTEXT, facts: TREE_FACTS, slice_rules: sliceRulesDescription(), closure_reuse: closureReuse,
|
|
573
|
+
});
|
|
574
|
+
const changed = changedDecls(base, head);
|
|
575
|
+
const changedIds = new Set(changed.flatMap((c) => (c.from ? [c.id, c.from] : [c.id])));
|
|
576
|
+
// Reached: reverse distances at each side, joined.
|
|
577
|
+
const dist = new Map();
|
|
578
|
+
for (const i of idx) {
|
|
579
|
+
for (const [id, d] of i.reverseFrom(changedIds)) {
|
|
580
|
+
const had = dist.get(id);
|
|
581
|
+
if (!had || d.hops < had.hops || (d.hops === had.hops && d.rank < had.rank))
|
|
582
|
+
dist.set(id, d);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
const reachedIds = [...dist.keys()].filter((id) => !changedIds.has(id));
|
|
586
|
+
// Changed files (C4 §15.2): tracked paths whose stored object or mode differs, as the index lists them (S1, S2), and
|
|
587
|
+
// a path that turned between file, symlink and gitlink. A path whose stored bytes cannot be read is not listed: it
|
|
588
|
+
// cuts the walk (N1).
|
|
589
|
+
const all = [baseSide, headSide];
|
|
590
|
+
const files = [...new Set(all.flatMap((s) => [...s.paths]))].sort(byCodePoints);
|
|
591
|
+
const changedFiles = files.filter((p) => baseSide.fileId(p) !== headSide.fileId(p)
|
|
592
|
+
|| (baseSide.fileKind(p) ?? headSide.fileKind(p)) !== (headSide.fileKind(p) ?? baseSide.fileKind(p)));
|
|
593
|
+
const sides = anchors.map((a) => [anchorAt(base, a), anchorAt(head, a)]);
|
|
594
|
+
const walkCut = all.some((s) => s.walkCut);
|
|
595
|
+
const emptyDiff = changedFiles.length === 0 && !walkCut;
|
|
596
|
+
const answers = anchors.map((a, n) => anchorScope(idx, a, sides[n], changedIds, changedFiles, rules, closureReuse, emptyDiff)).sort((a, b) => byCodePoints(a.scope.anchor_id, b.scope.anchor_id));
|
|
597
|
+
const anchorScopes = answers.map((a) => a.scope);
|
|
598
|
+
// Impacted tests, by file closure (D30): a test whose closure holds a changed file; also one whose closure cannot
|
|
599
|
+
// prove a changed file outside it (an unfollowed form, or a closure that cannot be computed soundly).
|
|
600
|
+
const tests = [];
|
|
601
|
+
const testFiles = new Map();
|
|
602
|
+
for (const e of head.tests()) {
|
|
603
|
+
const f = head.fileOf(e.id) ?? e.file;
|
|
604
|
+
(testFiles.get(f) ?? testFiles.set(f, []).get(f)).push(e.id);
|
|
605
|
+
}
|
|
606
|
+
for (const [tf, ids] of [...testFiles].sort((a, b) => byCodePoints(a[0], b[0]))) {
|
|
607
|
+
const closures = idx.filter((i) => i.side.fileHash(tf) !== null).map((i) => moduleClosure(i, [tf]));
|
|
608
|
+
const holds = new Set(closures.flatMap((c) => [...c.files.keys()]));
|
|
609
|
+
const inClosure = changedFiles.filter((c) => holds.has(c));
|
|
610
|
+
const unsound = closures.some((c) => c.why.length > 0 || c.hard.length > 0 || c.forms.length > 0);
|
|
611
|
+
// Code loaded by convention, or reached by no import, may be loaded by a test the closure cannot see (D30).
|
|
612
|
+
const byConvention = changedFiles.some((c) => {
|
|
613
|
+
if (holds.has(c))
|
|
614
|
+
return false;
|
|
615
|
+
const why = notUnderstood(idx, c, true);
|
|
616
|
+
return why !== null && (why.startsWith('convention') || (why.startsWith('orphan') && !idx.some((i) => i.side.isTest(c))));
|
|
617
|
+
});
|
|
618
|
+
const unproven = inClosure.length === 0 && ((unsound && changedFiles.some((c) => !holds.has(c))) || byConvention);
|
|
619
|
+
if (inClosure.length === 0 && !unproven)
|
|
620
|
+
continue;
|
|
621
|
+
for (const t of [...new Set(ids)]) {
|
|
622
|
+
const d = dist.get(t);
|
|
623
|
+
const reaches = new Set();
|
|
624
|
+
if (d)
|
|
625
|
+
for (const i of idx)
|
|
626
|
+
for (const id of i.reachClosure([t]))
|
|
627
|
+
if (changedIds.has(id))
|
|
628
|
+
reaches.add(id);
|
|
629
|
+
tests.push({
|
|
630
|
+
id: t, files: inClosure, reaches: [...reaches].sort(byCodePoints),
|
|
631
|
+
...(d && reaches.size > 0 ? { hops: d.hops, tier: tierOf(d.rank) } : {}),
|
|
632
|
+
...(unproven ? { unproven: true } : {}),
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
tests.sort((a, b) => byCodePoints(a.id, b.id));
|
|
637
|
+
// D32: tests are advisory; a PR run that changed a file selects every test.
|
|
638
|
+
const selectAll = !closureReuse && !emptyDiff;
|
|
639
|
+
if (!closureReuse)
|
|
640
|
+
for (const t of tests)
|
|
641
|
+
t.unproven = true;
|
|
642
|
+
const incomplete = [...graphFailures];
|
|
643
|
+
let complete;
|
|
644
|
+
if (!closureReuse) {
|
|
645
|
+
// D32 (C4 0.7.1 §15.3): the AND of the anchors not counting the deferral (every deferred anchor re-runs and every
|
|
646
|
+
// test is selected), and every changed tracked path listed: a cut walk may leave one out. The deferral hides only
|
|
647
|
+
// itself: a deferred anchor incomplete for another reason counts (S3). The 0.2 design's other file-level checks
|
|
648
|
+
// vouch for closure test selection and `reached[]`, on which nothing rests in 0.1.
|
|
649
|
+
incomplete.length = 0;
|
|
650
|
+
for (const s of all)
|
|
651
|
+
if (s.walkCut)
|
|
652
|
+
incomplete.push({ reason: 'walk_truncated', side: s.name, detail: 'the walk stopped at its bounds: a changed path may be missing from changed_files[]' });
|
|
653
|
+
complete = incomplete.length === 0 && answers.every((a) => a.counts);
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
complete = topLevelD30();
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* D30's top level (§15.3), behind the flag: every anchor; no changed file the engine does not understand; no
|
|
660
|
+
* referenced code the graphs leave out; no unresolved site that may reach a changed or reaching declaration (R6).
|
|
661
|
+
*/
|
|
662
|
+
function topLevelD30() {
|
|
663
|
+
for (const p of changedFiles) {
|
|
664
|
+
const why = notUnderstood(idx, p, false);
|
|
665
|
+
if (!why)
|
|
666
|
+
continue;
|
|
667
|
+
const s = all.find((x) => x.notUnderstood(p)) ?? (headSide.fileKind(p) !== null ? headSide : baseSide);
|
|
668
|
+
const reason = why.startsWith('convention') ? 'convention' : why.startsWith('orphan') ? 'orphan' : s.notUnderstood(p).reason;
|
|
669
|
+
incomplete.push({ reason, side: s.name, path: p, detail: s.notUnderstood(p)?.detail ?? `${p} is not understood (${why})` });
|
|
670
|
+
}
|
|
671
|
+
const changedSet = new Set(changedFiles);
|
|
672
|
+
for (const s of all) {
|
|
673
|
+
for (const p of s.referencedUngraphed)
|
|
674
|
+
if (!changedSet.has(p))
|
|
675
|
+
incomplete.push({ reason: 'skipped_size', side: s.name, path: p, detail: `${p} is referenced but not in the graph (over the size bound or in a skipped directory)` });
|
|
676
|
+
if (s.walkCut)
|
|
677
|
+
incomplete.push({ reason: 'walk_truncated', side: s.name, detail: 'the walk stopped at its bounds' });
|
|
678
|
+
}
|
|
679
|
+
for (const i of idx)
|
|
680
|
+
incomplete.push(...unresolvedInto(i, [...changedIds, ...reachedIds]));
|
|
681
|
+
return incomplete.length === 0 && anchorScopes.every((a) => a.complete);
|
|
682
|
+
}
|
|
683
|
+
// Declarations: every id the answer names, and every anchor's location and read targets.
|
|
684
|
+
const declarations = {};
|
|
685
|
+
const name = (id) => {
|
|
686
|
+
const d = head.decls.get(id) ?? base.decls.get(id);
|
|
687
|
+
if (d && !declarations[id])
|
|
688
|
+
declarations[id] = { kind: d.decl.kind, qualified_name: d.decl.qualified_name, path: d.file };
|
|
689
|
+
};
|
|
690
|
+
[...changedIds, ...reachedIds, ...tests.map((t) => t.id)].forEach(name);
|
|
691
|
+
for (const a of anchors) {
|
|
692
|
+
for (const i of idx) {
|
|
693
|
+
const at = a.at;
|
|
694
|
+
if (at.decl)
|
|
695
|
+
i.select(at.decl).forEach(name);
|
|
696
|
+
for (const r of a.reads ?? []) {
|
|
697
|
+
const t = r.target;
|
|
698
|
+
if (t?.decl)
|
|
699
|
+
i.select(t.decl).forEach(name);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
const sortedDecls = Object.fromEntries(Object.keys(declarations).sort(byCodePoints).map((k) => [k, declarations[k]]));
|
|
704
|
+
const listing = (s) => blake3Of({ files: [...s.paths].sort(byCodePoints).map((p) => [p, s.fileMode(p), s.fileHash(p)]) });
|
|
705
|
+
const body = {
|
|
706
|
+
scheme: CHANGE_SCOPE_SCHEME,
|
|
707
|
+
engine: { package: 'circle-ir-ai', version: ENGINE_VERSION },
|
|
708
|
+
rules,
|
|
709
|
+
facts: TREE_FACTS,
|
|
710
|
+
base: listing(baseSide),
|
|
711
|
+
head: listing(headSide),
|
|
712
|
+
complete,
|
|
713
|
+
changed,
|
|
714
|
+
changed_files: changedFiles,
|
|
715
|
+
reached: reachedIds.sort(byCodePoints).map((id) => ({ id, hops: dist.get(id).hops, tier: tierOf(dist.get(id).rank) })),
|
|
716
|
+
anchors: anchorScopes,
|
|
717
|
+
impacted_tests: tests,
|
|
718
|
+
select_all: selectAll,
|
|
719
|
+
declarations: sortedDecls,
|
|
720
|
+
incomplete: incomplete.slice(0, MAX_INCOMPLETE),
|
|
721
|
+
incomplete_total: incomplete.length,
|
|
722
|
+
};
|
|
723
|
+
return { ...body, scope_digest: blake3Of(body) };
|
|
724
|
+
}
|
|
725
|
+
//# sourceMappingURL=scope.js.map
|