@gate-forge/pack-sqlalchemy 0.20.1 → 0.21.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/README.md +26 -0
- package/dist/detector.d.ts.map +1 -1
- package/dist/detector.js +45 -1
- package/dist/detector.js.map +1 -1
- package/package.json +5 -4
- package/python/gateforge_sqlalchemy_detector/__main__.py +34 -2
- package/python/gateforge_sqlalchemy_detector/reachability.py +495 -0
- package/python/gateforge_sqlalchemy_detector/scan.py +21 -1
package/README.md
CHANGED
|
@@ -365,6 +365,32 @@ never silently suppresses obligations. `NO_PLANE_MAPPING` remains available for
|
|
|
365
365
|
tests that intentionally disable plane attribution (programmatic or
|
|
366
366
|
config-driven).
|
|
367
367
|
|
|
368
|
+
## Internal reachability
|
|
369
|
+
|
|
370
|
+
The detector can prove a table internal, but only when the owner binds an
|
|
371
|
+
entry-point category to it in `.gateforge/classification-policy.yml`:
|
|
372
|
+
|
|
373
|
+
```yaml
|
|
374
|
+
trustedInternalEntryPoints:
|
|
375
|
+
- category: migration
|
|
376
|
+
detector: gateforge.pack-sqlalchemy
|
|
377
|
+
- category: worker
|
|
378
|
+
detector: gateforge.pack-sqlalchemy
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
With no binding, the detector emits no reachability signal and no table is
|
|
382
|
+
derived internal from code. A binding makes the detector report the tables
|
|
383
|
+
written by that category's entry points (Alembic `upgrade`, a
|
|
384
|
+
`__main__` maintenance block, or a Celery task). The rules, the writer
|
|
385
|
+
list, and what gives no signal are in `packages/cli/guides/REFERENCE.md`,
|
|
386
|
+
section "Internal entry points (the `trustedInternalEntryPoints:` section)".
|
|
387
|
+
|
|
388
|
+
Reachability is one input to the certificate, not the whole proof. A
|
|
389
|
+
linked `http.endpoint` or an incomplete scan still blocks it.
|
|
390
|
+
A route that writes a table through a helper, or enqueues a worker with
|
|
391
|
+
`.delay()`, is not linked to that endpoint, so the endpoint check does not
|
|
392
|
+
block that table; narrow the category with `patterns`.
|
|
393
|
+
|
|
368
394
|
## Classification workflow (example app)
|
|
369
395
|
|
|
370
396
|
1. **Discover** — the detector finds `accounts` and emits normalized
|
package/dist/detector.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAsBA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,gBAAgB,EAEtB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,SAAS,EAGf,MAAM,aAAa,CAAC;AAYrB,2EAA2E;AAC3E,eAAO,MAAM,eAAe,UAAqD,CAAC;AAElF;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,GAAE,SAAS,MAAM,EAAO,GAAG,MAAM,CAAC,UAAU,CAOlF;AAED,oDAAoD;AACpD,MAAM,WAAW,yBAAyB;IACxC;;;;OAIG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;;OAGG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,mEAAmE;IACnE,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mEAAmE;IACnE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,6EAA6E;AAC7E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CACN,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC;QACT,SAAS,EAAE,OAAO,EAAE,CAAC;QACrB,UAAU,EAAE,OA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
package/dist/detector.js
CHANGED
|
@@ -254,11 +254,12 @@ export function createSqlalchemyDetector(options = {}) {
|
|
|
254
254
|
TENANT_SCOPE_COLUMNS;
|
|
255
255
|
return {
|
|
256
256
|
async discover(paths, context) {
|
|
257
|
+
const categories = grantedInternalCategories(context?.sections.trustedInternalEntryPoints);
|
|
257
258
|
if (paths.length === 0) {
|
|
258
259
|
return { resources: [], unresolved: [], findings: [], classificationSignals: [] };
|
|
259
260
|
}
|
|
260
261
|
const session = new PluginSession({
|
|
261
|
-
command:
|
|
262
|
+
command: launchCommand(command, categories),
|
|
262
263
|
pluginId,
|
|
263
264
|
pluginVersion,
|
|
264
265
|
cwd: process.cwd(),
|
|
@@ -291,6 +292,49 @@ export function createSqlalchemyDetector(options = {}) {
|
|
|
291
292
|
},
|
|
292
293
|
};
|
|
293
294
|
}
|
|
295
|
+
/** Entry-point categories this detector derives internal claims for. */
|
|
296
|
+
const INTERNAL_ENTRY_CATEGORIES = {
|
|
297
|
+
migration: true,
|
|
298
|
+
'maintenance-command': true,
|
|
299
|
+
worker: true,
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* The internal entry-point categories the trusted policy grants this detector
|
|
303
|
+
* (`trustedInternalEntryPoints`). Absent section grants none. A grant bound to
|
|
304
|
+
* another detector is not ours and is dropped; a malformed grant, or one of ours
|
|
305
|
+
* naming an unknown category, throws so a typo can never silently widen or
|
|
306
|
+
* narrow the derived claims.
|
|
307
|
+
*/
|
|
308
|
+
function grantedInternalCategories(section) {
|
|
309
|
+
if (section === undefined)
|
|
310
|
+
return [];
|
|
311
|
+
if (!Array.isArray(section)) {
|
|
312
|
+
throw new Error('trustedInternalEntryPoints must be an array of entry-point grants');
|
|
313
|
+
}
|
|
314
|
+
const granted = [];
|
|
315
|
+
for (const entry of section) {
|
|
316
|
+
if (typeof entry !== 'object' || entry === null) {
|
|
317
|
+
throw new Error('trustedInternalEntryPoints entries must be objects');
|
|
318
|
+
}
|
|
319
|
+
const grant = entry;
|
|
320
|
+
if (typeof grant.category !== 'string' || grant.category === '') {
|
|
321
|
+
throw new Error('trustedInternalEntryPoints entries need a non-empty string category');
|
|
322
|
+
}
|
|
323
|
+
if (grant.detector !== PACK_PLUGIN_ID)
|
|
324
|
+
continue;
|
|
325
|
+
if (!Object.hasOwn(INTERNAL_ENTRY_CATEGORIES, grant.category)) {
|
|
326
|
+
throw new Error(`trustedInternalEntryPoints names unknown category '${grant.category}'`);
|
|
327
|
+
}
|
|
328
|
+
granted.push(grant.category);
|
|
329
|
+
}
|
|
330
|
+
return granted;
|
|
331
|
+
}
|
|
332
|
+
/** The pinned command plus `--internal-entry-categories` when any category is granted. */
|
|
333
|
+
function launchCommand(base, categories) {
|
|
334
|
+
if (categories.length === 0)
|
|
335
|
+
return [...base];
|
|
336
|
+
return [...base, `--internal-entry-categories=${categories.join(',')}`];
|
|
337
|
+
}
|
|
294
338
|
/** True when a plane rule can never map anything. */
|
|
295
339
|
function planeIsNoop(plane) {
|
|
296
340
|
return plane === NO_PLANE_MAPPING;
|
package/dist/detector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EACL,aAAa,GAId,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,GAKpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,6BAA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,0FAA0F;AAC1F,SAAS,aAAa,CAAC,IAAuB,EAAE,UAA6B;IAC3E,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,IAAI,EAAE,+BAA+B,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC1E,CAAC;AAED,qDAAqD;AACrD,SAAS,WAAW,CAAC,KAAgB;IACnC,OAAO,KAAK,KAAK,gBAAgB,CAAC;AACpC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gate-forge/pack-sqlalchemy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "SQLAlchemy CRUD discovery pack: AST-only python detector (GPP/3), in-process TS discover entry, configurable plane mapping, entity-adapter schema.",
|
|
6
6
|
"type": "module",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
|
-
"import": "./dist/index.js"
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
14
15
|
}
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
@@ -28,8 +29,8 @@
|
|
|
28
29
|
"test": "vitest run"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@gate-forge/core": "^0.
|
|
32
|
-
"@gate-forge/plugin-protocol": "^0.
|
|
32
|
+
"@gate-forge/core": "^0.21.0",
|
|
33
|
+
"@gate-forge/plugin-protocol": "^0.21.0",
|
|
33
34
|
"yaml": "^2.8.1",
|
|
34
35
|
"zod": "^4.1.5"
|
|
35
36
|
},
|
|
@@ -15,6 +15,9 @@ Usage:
|
|
|
15
15
|
python3 -m gateforge_sqlalchemy_detector [root]
|
|
16
16
|
# root: scan root (default: process cwd, which the CLI sets to the
|
|
17
17
|
# repo root); every discover path resolves under it.
|
|
18
|
+
# --internal-entry-categories=LIST: comma list of migration,
|
|
19
|
+
# maintenance-command, worker; the host passes the trusted internal
|
|
20
|
+
# entry points it grants. Absent: no internal claims are derived.
|
|
18
21
|
"""
|
|
19
22
|
|
|
20
23
|
from __future__ import annotations
|
|
@@ -32,17 +35,46 @@ except ImportError: # monorepo bootstrap: ../plugin-protocol/python
|
|
|
32
35
|
from gateforge_sqlalchemy_detector import PLUGIN_ID, VERSION
|
|
33
36
|
|
|
34
37
|
|
|
35
|
-
|
|
38
|
+
_ENTRY_CATEGORIES = ("migration", "maintenance-command", "worker")
|
|
39
|
+
_CATEGORY_FLAG = "--internal-entry-categories="
|
|
40
|
+
_scan_root: Path | None = None
|
|
41
|
+
_categories: tuple[str, ...] = ()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _parse_categories(value: str) -> tuple[str, ...]:
|
|
45
|
+
"""Validates a comma list of entry categories; an unknown name is an error."""
|
|
46
|
+
names = tuple(part for part in value.split(",") if part)
|
|
47
|
+
unknown = [name for name in names if name not in _ENTRY_CATEGORIES]
|
|
48
|
+
if unknown:
|
|
49
|
+
raise ValueError(f"unknown internal entry category: {', '.join(unknown)}")
|
|
50
|
+
return names
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _parse_args(argv: list[str]) -> tuple[Path | None, tuple[str, ...]]:
|
|
54
|
+
"""Splits argv into the optional scan root and the derived entry categories."""
|
|
55
|
+
root: Path | None = None
|
|
56
|
+
categories: tuple[str, ...] = ()
|
|
57
|
+
for arg in argv:
|
|
58
|
+
if arg.startswith(_CATEGORY_FLAG):
|
|
59
|
+
categories = _parse_categories(arg[len(_CATEGORY_FLAG):])
|
|
60
|
+
elif not arg.startswith("--") and root is None:
|
|
61
|
+
root = Path(arg).resolve()
|
|
62
|
+
return root, categories
|
|
36
63
|
|
|
37
64
|
|
|
38
65
|
def _discover(paths: list[str]) -> dict:
|
|
39
66
|
"""GPP/3 discover handler: scans each repo-relative path in order."""
|
|
40
67
|
from gateforge_sqlalchemy_detector import scan
|
|
41
68
|
|
|
42
|
-
return scan.scan(paths, _scan_root)
|
|
69
|
+
return scan.scan(paths, _scan_root, _categories)
|
|
43
70
|
|
|
44
71
|
|
|
45
72
|
if __name__ == "__main__":
|
|
73
|
+
try:
|
|
74
|
+
_scan_root, _categories = _parse_args(sys.argv[1:])
|
|
75
|
+
except ValueError as error:
|
|
76
|
+
print(error, file=sys.stderr)
|
|
77
|
+
raise SystemExit(2) from None
|
|
46
78
|
try:
|
|
47
79
|
raise SystemExit(serve(PLUGIN_ID, VERSION, _discover))
|
|
48
80
|
except ProtocolError as error:
|
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
"""Code-derived internal reachability for SQLAlchemy tables (P3 i).
|
|
2
|
+
|
|
3
|
+
A table is internal for an entry-point category when an entry point of that
|
|
4
|
+
category reaches a writer of the table. Every list below is closed: a shape
|
|
5
|
+
that is not named gives no edge and no writer, and so no signal.
|
|
6
|
+
|
|
7
|
+
The walk works on ``ast`` only. Nothing here imports or runs the scanned code.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import ast
|
|
13
|
+
import re
|
|
14
|
+
from collections import Counter
|
|
15
|
+
|
|
16
|
+
from . import PLUGIN_ID
|
|
17
|
+
from .scan import _module_to_relpath, _signal, loc
|
|
18
|
+
|
|
19
|
+
SA_MODULES = frozenset({"sqlalchemy", "sqlalchemy.orm"})
|
|
20
|
+
# A `__main__` block that reaches one of these starts a server: no entry point.
|
|
21
|
+
SERVER_NAMES = frozenset({"run", "serve", "serve_forever"})
|
|
22
|
+
WRITE_CALLS = frozenset({"insert", "update", "delete"})
|
|
23
|
+
SESSION_ADD_CALLS = frozenset({"add", "add_all"})
|
|
24
|
+
SQL_IDENT = r'(?:"(?:[^"]|"")+"|\w+)'
|
|
25
|
+
LITERAL_WRITE = re.compile(
|
|
26
|
+
rf"^\s*(?:INSERT\s+INTO|UPDATE|DELETE\s+FROM)\s+"
|
|
27
|
+
rf"(?:ONLY\s+(?!(?:SET|WHERE|VALUES|SELECT|USING)\b))?"
|
|
28
|
+
rf"(?:{SQL_IDENT}\s*\.\s*)?({SQL_IDENT})",
|
|
29
|
+
re.IGNORECASE,
|
|
30
|
+
)
|
|
31
|
+
SCOPE_NODES = (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef, ast.Lambda)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def reachability_signals(indexes, trees, tables, categories):
|
|
35
|
+
"""Derives one ``internality`` signal per (table, entry category) reached.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
indexes: ``{relpath: FileIndex}`` for every scanned, non-test file.
|
|
39
|
+
trees: ``{relpath: ast.Module}``, the same files as ``indexes``.
|
|
40
|
+
tables: ``[(relpath, class_qname_or_None, table_name)]`` for every
|
|
41
|
+
table resource: a declarative class (qname set) or a ``Table()``
|
|
42
|
+
call (qname None).
|
|
43
|
+
categories: The entry-point categories to derive, a subset of
|
|
44
|
+
``migration``, ``maintenance-command`` and ``worker``.
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
list[dict]: ``ClassificationSignal`` documents (unsorted).
|
|
48
|
+
"""
|
|
49
|
+
return _Walker(indexes, trees, tables).signals(categories)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _own_nodes(stmts):
|
|
53
|
+
"""Yields the nodes of one function or block scope, skipping nested scopes.
|
|
54
|
+
|
|
55
|
+
A nested function, class or lambda is yielded as one node (so its name
|
|
56
|
+
still counts as a binding) but its body is not walked.
|
|
57
|
+
"""
|
|
58
|
+
stack = list(stmts)
|
|
59
|
+
while stack:
|
|
60
|
+
node = stack.pop()
|
|
61
|
+
yield node
|
|
62
|
+
if isinstance(node, SCOPE_NODES):
|
|
63
|
+
continue
|
|
64
|
+
stack.extend(ast.iter_child_nodes(node))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _final_name(func):
|
|
68
|
+
if isinstance(func, ast.Name):
|
|
69
|
+
return func.id
|
|
70
|
+
if isinstance(func, ast.Attribute):
|
|
71
|
+
return func.attr
|
|
72
|
+
return None
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _str_const(node):
|
|
76
|
+
if isinstance(node, ast.Constant) and isinstance(node.value, str):
|
|
77
|
+
return node.value
|
|
78
|
+
return None
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _listed(table):
|
|
82
|
+
"""A single resolved table as a one-item list, or an empty list."""
|
|
83
|
+
return [table] if table is not None else []
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _is_main_guard(stmt):
|
|
87
|
+
"""True for a module-level ``if __name__ == "__main__":``."""
|
|
88
|
+
if not isinstance(stmt, ast.If):
|
|
89
|
+
return False
|
|
90
|
+
test = stmt.test
|
|
91
|
+
if not (
|
|
92
|
+
isinstance(test, ast.Compare)
|
|
93
|
+
and len(test.ops) == 1
|
|
94
|
+
and isinstance(test.ops[0], ast.Eq)
|
|
95
|
+
and len(test.comparators) == 1
|
|
96
|
+
):
|
|
97
|
+
return False
|
|
98
|
+
sides = [test.left, test.comparators[0]]
|
|
99
|
+
names = [s for s in sides if isinstance(s, ast.Name) and s.id == "__name__"]
|
|
100
|
+
consts = [s for s in sides if isinstance(s, ast.Constant) and s.value == "__main__"]
|
|
101
|
+
return len(names) == 1 and len(consts) == 1
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _has_revision(tree):
|
|
105
|
+
"""True when the module binds ``revision`` to a string literal (alembic)."""
|
|
106
|
+
for stmt in tree.body:
|
|
107
|
+
if isinstance(stmt, ast.Assign):
|
|
108
|
+
targets = stmt.targets
|
|
109
|
+
elif isinstance(stmt, ast.AnnAssign):
|
|
110
|
+
targets = [stmt.target]
|
|
111
|
+
else:
|
|
112
|
+
continue
|
|
113
|
+
bound = any(isinstance(t, ast.Name) and t.id == "revision" for t in targets)
|
|
114
|
+
if bound and _str_const(stmt.value) is not None:
|
|
115
|
+
return True
|
|
116
|
+
return False
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _is_celery_class_call(node, imports):
|
|
120
|
+
"""True for a call to ``celery.Celery``, however celery was imported."""
|
|
121
|
+
if not isinstance(node, ast.Call):
|
|
122
|
+
return False
|
|
123
|
+
func = node.func
|
|
124
|
+
if isinstance(func, ast.Name):
|
|
125
|
+
ref = imports.get(func.id)
|
|
126
|
+
return ref is not None and ref.level == 0 and ref.module == "celery" and ref.name == "Celery"
|
|
127
|
+
if isinstance(func, ast.Attribute) and func.attr == "Celery" and isinstance(func.value, ast.Name):
|
|
128
|
+
ref = imports.get(func.value.id)
|
|
129
|
+
return ref is not None and ref.level == 0 and ref.module == "celery" and ref.name is None
|
|
130
|
+
return False
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _celery_bindings(tree, imports):
|
|
134
|
+
"""Module-level names bound by ``<name> = Celery(...)``, Celery being celery's."""
|
|
135
|
+
names = set()
|
|
136
|
+
for stmt in tree.body:
|
|
137
|
+
if isinstance(stmt, ast.Assign) and _is_celery_class_call(stmt.value, imports):
|
|
138
|
+
for target in stmt.targets:
|
|
139
|
+
if isinstance(target, ast.Name):
|
|
140
|
+
names.add(target.id)
|
|
141
|
+
return names
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _param_nodes(fn):
|
|
145
|
+
if fn is None:
|
|
146
|
+
return []
|
|
147
|
+
args = fn.args
|
|
148
|
+
nodes = list(args.posonlyargs) + list(args.args) + list(args.kwonlyargs)
|
|
149
|
+
if args.vararg is not None:
|
|
150
|
+
nodes.append(args.vararg)
|
|
151
|
+
if args.kwarg is not None:
|
|
152
|
+
nodes.append(args.kwarg)
|
|
153
|
+
return nodes
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _bound_names(own):
|
|
157
|
+
"""Every name a scope binds, once per binding; parameters excluded."""
|
|
158
|
+
for node in own:
|
|
159
|
+
if isinstance(node, ast.Name) and isinstance(node.ctx, ast.Store):
|
|
160
|
+
yield node.id
|
|
161
|
+
elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
|
|
162
|
+
yield node.name
|
|
163
|
+
elif isinstance(node, (ast.Import, ast.ImportFrom)):
|
|
164
|
+
for alias in node.names:
|
|
165
|
+
yield alias.asname or alias.name.split(".")[0]
|
|
166
|
+
elif isinstance(node, ast.ExceptHandler) and node.name is not None:
|
|
167
|
+
yield node.name
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _bound_count(own, name):
|
|
171
|
+
"""How many times a scope binds ``name``, parameters excluded."""
|
|
172
|
+
return sum(1 for bound in _bound_names(own) if bound == name)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _binding_source(own, name):
|
|
176
|
+
"""The value expression of the one plain binding of ``name``, if any."""
|
|
177
|
+
for node in own:
|
|
178
|
+
if isinstance(node, ast.Assign) and any(
|
|
179
|
+
isinstance(t, ast.Name) and t.id == name for t in node.targets
|
|
180
|
+
):
|
|
181
|
+
return node.value
|
|
182
|
+
if isinstance(node, ast.AnnAssign) and isinstance(node.target, ast.Name) and node.target.id == name:
|
|
183
|
+
return node.value
|
|
184
|
+
if isinstance(node, (ast.With, ast.AsyncWith)):
|
|
185
|
+
for item in node.items:
|
|
186
|
+
if isinstance(item.optional_vars, ast.Name) and item.optional_vars.id == name:
|
|
187
|
+
return item.context_expr
|
|
188
|
+
return None
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def _table_key(table):
|
|
192
|
+
return (table[0], table[1] or "", table[2])
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _table_signal(table, category, location):
|
|
196
|
+
relpath, symbol, name = table
|
|
197
|
+
signal = _signal("internality", category, "code-positive", PLUGIN_ID, location, name, symbol)
|
|
198
|
+
if symbol is not None:
|
|
199
|
+
# A declarative class target carries its symbol only: the bare table
|
|
200
|
+
# name would bind the signal to every same-named table in the scan.
|
|
201
|
+
del signal["target"]["resourceName"]
|
|
202
|
+
return signal
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class _Walker:
|
|
206
|
+
"""Resolves entry points, call edges and writers over one scan's indexes."""
|
|
207
|
+
|
|
208
|
+
def __init__(self, indexes, trees, tables):
|
|
209
|
+
self.indexes = indexes
|
|
210
|
+
self.trees = trees
|
|
211
|
+
self.tables = list(tables)
|
|
212
|
+
self.funcs = {
|
|
213
|
+
rel: {
|
|
214
|
+
stmt.name: stmt
|
|
215
|
+
for stmt in tree.body
|
|
216
|
+
if isinstance(stmt, (ast.FunctionDef, ast.AsyncFunctionDef))
|
|
217
|
+
}
|
|
218
|
+
for rel, tree in trees.items()
|
|
219
|
+
}
|
|
220
|
+
self.celery_apps = {rel: _celery_bindings(tree, self.indexes[rel].imports) for rel, tree in trees.items()}
|
|
221
|
+
self.module_bound = {rel: Counter(_bound_names(_own_nodes(tree.body))) for rel, tree in trees.items()}
|
|
222
|
+
|
|
223
|
+
# -- name resolution ------------------------------------------------
|
|
224
|
+
|
|
225
|
+
def _rebound(self, rel, own, fn, name):
|
|
226
|
+
"""True when ``name`` is bound other than by its one module-level import."""
|
|
227
|
+
if self.module_bound[rel][name] != 1:
|
|
228
|
+
return True
|
|
229
|
+
return _bound_count(own, name) > 0 or any(p.arg == name for p in _param_nodes(fn))
|
|
230
|
+
|
|
231
|
+
def _sa_symbol(self, rel, node, own=(), fn=None):
|
|
232
|
+
"""The sqlalchemy (or sqlalchemy.orm) name a node refers to, else None.
|
|
233
|
+
|
|
234
|
+
``own`` and ``fn`` are the calling scope: a name rebound there, or
|
|
235
|
+
passed as one of its parameters, is not the import.
|
|
236
|
+
"""
|
|
237
|
+
imports = self.indexes[rel].imports
|
|
238
|
+
if isinstance(node, ast.Name):
|
|
239
|
+
ref = imports.get(node.id)
|
|
240
|
+
if ref is not None and ref.level == 0 and ref.name is not None and ref.module in SA_MODULES:
|
|
241
|
+
return None if self._rebound(rel, own, fn, node.id) else ref.name
|
|
242
|
+
return None
|
|
243
|
+
if isinstance(node, ast.Attribute) and isinstance(node.value, ast.Name):
|
|
244
|
+
ref = imports.get(node.value.id)
|
|
245
|
+
if ref is None or ref.level != 0 or self._rebound(rel, own, fn, node.value.id):
|
|
246
|
+
return None
|
|
247
|
+
if ref.name is None and ref.module in SA_MODULES:
|
|
248
|
+
return node.attr
|
|
249
|
+
if ref.module == "sqlalchemy" and ref.name == "orm":
|
|
250
|
+
return node.attr
|
|
251
|
+
return None
|
|
252
|
+
|
|
253
|
+
def _is_alembic_op(self, rel, node):
|
|
254
|
+
if not isinstance(node, ast.Name):
|
|
255
|
+
return False
|
|
256
|
+
ref = self.indexes[rel].imports.get(node.id)
|
|
257
|
+
return ref is not None and ref.level == 0 and ref.module == "alembic" and ref.name == "op"
|
|
258
|
+
|
|
259
|
+
def _is_celery_import(self, rel, local, name):
|
|
260
|
+
ref = self.indexes[rel].imports.get(local)
|
|
261
|
+
return ref is not None and ref.level == 0 and ref.module == "celery" and ref.name == name
|
|
262
|
+
|
|
263
|
+
def _celery_app(self, rel, local):
|
|
264
|
+
if local in self.celery_apps[rel]:
|
|
265
|
+
return True
|
|
266
|
+
ref = self.indexes[rel].imports.get(local)
|
|
267
|
+
if ref is None or ref.level != 0 or ref.name is None:
|
|
268
|
+
return False
|
|
269
|
+
target = _module_to_relpath(self.indexes, ref.module)
|
|
270
|
+
return target is not None and ref.name in self.celery_apps[target]
|
|
271
|
+
|
|
272
|
+
def _class_table(self, rel, name):
|
|
273
|
+
"""The one table class a model name resolves to, else None."""
|
|
274
|
+
ref = self.indexes[rel].imports.get(name)
|
|
275
|
+
if ref is None:
|
|
276
|
+
target, want = rel, name
|
|
277
|
+
elif ref.level == 0 and ref.name is not None:
|
|
278
|
+
target = _module_to_relpath(self.indexes, ref.module)
|
|
279
|
+
if target is None:
|
|
280
|
+
return None
|
|
281
|
+
want = ref.name
|
|
282
|
+
else:
|
|
283
|
+
return None
|
|
284
|
+
hits = [
|
|
285
|
+
t for t in self.tables
|
|
286
|
+
if t[1] is not None and t[0] == target and t[1].rsplit(".", 1)[-1] == want
|
|
287
|
+
]
|
|
288
|
+
return hits[0] if len(hits) == 1 else None
|
|
289
|
+
|
|
290
|
+
def _literal_table(self, name):
|
|
291
|
+
"""The one table resource in the scan with this name, else None."""
|
|
292
|
+
hits = [t for t in self.tables if t[2] == name]
|
|
293
|
+
return hits[0] if len(hits) == 1 else None
|
|
294
|
+
|
|
295
|
+
def _table_of(self, rel, own, fn, node):
|
|
296
|
+
"""The table an expression denotes: a model, ``M.__table__``, or ``table("lit")``."""
|
|
297
|
+
if isinstance(node, ast.Name):
|
|
298
|
+
return self._class_table(rel, node.id)
|
|
299
|
+
if isinstance(node, ast.Attribute) and node.attr == "__table__" and isinstance(node.value, ast.Name):
|
|
300
|
+
return self._class_table(rel, node.value.id)
|
|
301
|
+
if isinstance(node, ast.Call) and self._sa_symbol(rel, node.func, own, fn) == "table" and node.args:
|
|
302
|
+
literal = _str_const(node.args[0])
|
|
303
|
+
if literal is not None:
|
|
304
|
+
return self._literal_table(literal)
|
|
305
|
+
return None
|
|
306
|
+
|
|
307
|
+
def _callee(self, rel, call):
|
|
308
|
+
"""The same-file or imported module-level function a call reaches."""
|
|
309
|
+
func = call.func
|
|
310
|
+
if isinstance(func, ast.Name):
|
|
311
|
+
if func.id in self.funcs[rel]:
|
|
312
|
+
return (rel, func.id)
|
|
313
|
+
ref = self.indexes[rel].imports.get(func.id)
|
|
314
|
+
if ref is not None and ref.level == 0 and ref.name is not None:
|
|
315
|
+
target = _module_to_relpath(self.indexes, ref.module)
|
|
316
|
+
if target is not None and ref.name in self.funcs[target]:
|
|
317
|
+
return (target, ref.name)
|
|
318
|
+
return None
|
|
319
|
+
if isinstance(func, ast.Attribute) and isinstance(func.value, ast.Name):
|
|
320
|
+
ref = self.indexes[rel].imports.get(func.value.id)
|
|
321
|
+
if ref is not None and ref.level == 0 and ref.name is None:
|
|
322
|
+
target = _module_to_relpath(self.indexes, ref.module)
|
|
323
|
+
if target is not None and func.attr in self.funcs[target]:
|
|
324
|
+
return (target, func.attr)
|
|
325
|
+
return None
|
|
326
|
+
|
|
327
|
+
# -- writers --------------------------------------------------------
|
|
328
|
+
|
|
329
|
+
def _is_session_ctor(self, rel, own, fn, node):
|
|
330
|
+
if not isinstance(node, ast.Call):
|
|
331
|
+
return False
|
|
332
|
+
if self._sa_symbol(rel, node.func, own, fn) == "Session":
|
|
333
|
+
return True
|
|
334
|
+
return (
|
|
335
|
+
isinstance(node.func, ast.Call)
|
|
336
|
+
and self._sa_symbol(rel, node.func.func, own, fn) == "sessionmaker"
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
def _is_session_receiver(self, rel, own, fn, name):
|
|
340
|
+
"""True when ``name`` is bound exactly once in the scope, to a session."""
|
|
341
|
+
params = [p for p in _param_nodes(fn) if p.arg == name]
|
|
342
|
+
if len(params) + _bound_count(own, name) != 1:
|
|
343
|
+
return False
|
|
344
|
+
if params:
|
|
345
|
+
annotation = params[0].annotation
|
|
346
|
+
return annotation is not None and self._sa_symbol(rel, annotation, own, fn) == "Session"
|
|
347
|
+
source = _binding_source(own, name)
|
|
348
|
+
return source is not None and self._is_session_ctor(rel, own, fn, source)
|
|
349
|
+
|
|
350
|
+
def _writes(self, rel, own, fn, call):
|
|
351
|
+
"""The tables one call writes, as a list of table tuples."""
|
|
352
|
+
symbol = self._sa_symbol(rel, call.func, own, fn)
|
|
353
|
+
if symbol is not None:
|
|
354
|
+
return self._sa_writes(rel, own, fn, symbol, call)
|
|
355
|
+
if isinstance(call.func, ast.Attribute):
|
|
356
|
+
return self._method_writes(rel, own, fn, call)
|
|
357
|
+
return []
|
|
358
|
+
|
|
359
|
+
def _sa_writes(self, rel, own, fn, symbol, call):
|
|
360
|
+
"""Writes made by a sqlalchemy-imported call: ``insert(X)`` and ``text(S)``."""
|
|
361
|
+
if symbol in WRITE_CALLS and call.args:
|
|
362
|
+
return _listed(self._table_of(rel, own, fn, call.args[0]))
|
|
363
|
+
if symbol == "text" and call.args:
|
|
364
|
+
return self._literal_write(_str_const(call.args[0]))
|
|
365
|
+
return []
|
|
366
|
+
|
|
367
|
+
def _method_writes(self, rel, own, fn, call):
|
|
368
|
+
"""Writes made by a method call: ``X.__table__.insert()``, alembic ops and session adds."""
|
|
369
|
+
func = call.func
|
|
370
|
+
if func.attr in WRITE_CALLS and isinstance(func.value, ast.Attribute) and func.value.attr == "__table__":
|
|
371
|
+
return _listed(self._table_of(rel, own, fn, func.value))
|
|
372
|
+
if not call.args:
|
|
373
|
+
return []
|
|
374
|
+
if func.attr == "bulk_insert" and self._is_alembic_op(rel, func.value):
|
|
375
|
+
return _listed(self._table_of(rel, own, fn, call.args[0]))
|
|
376
|
+
if func.attr == "execute" and self._is_alembic_op(rel, func.value):
|
|
377
|
+
return self._literal_write(_str_const(call.args[0]))
|
|
378
|
+
if (
|
|
379
|
+
func.attr in SESSION_ADD_CALLS
|
|
380
|
+
and isinstance(func.value, ast.Name)
|
|
381
|
+
and self._is_session_receiver(rel, own, fn, func.value.id)
|
|
382
|
+
):
|
|
383
|
+
return self._session_adds(rel, func.attr, call.args[0])
|
|
384
|
+
return []
|
|
385
|
+
|
|
386
|
+
def _session_adds(self, rel, attr, arg):
|
|
387
|
+
"""Tables of ``M(...)`` objects passed to ``add`` or to ``add_all([...])``."""
|
|
388
|
+
items = arg.elts if attr == "add_all" and isinstance(arg, ast.List) else [arg]
|
|
389
|
+
out = []
|
|
390
|
+
for item in items:
|
|
391
|
+
if isinstance(item, ast.Call) and isinstance(item.func, ast.Name):
|
|
392
|
+
out.extend(_listed(self._class_table(rel, item.func.id)))
|
|
393
|
+
return out
|
|
394
|
+
|
|
395
|
+
def _literal_write(self, text):
|
|
396
|
+
"""The table a literal INSERT/UPDATE/DELETE statement names, if unambiguous."""
|
|
397
|
+
if text is None:
|
|
398
|
+
return []
|
|
399
|
+
match = LITERAL_WRITE.match(text)
|
|
400
|
+
if match is None:
|
|
401
|
+
return []
|
|
402
|
+
name = match.group(1)
|
|
403
|
+
if name.startswith('"'):
|
|
404
|
+
name = name[1:-1].replace('""', '"')
|
|
405
|
+
return _listed(self._literal_table(name))
|
|
406
|
+
|
|
407
|
+
# -- entry points and closure ---------------------------------------
|
|
408
|
+
|
|
409
|
+
def _worker(self, rel, fdef):
|
|
410
|
+
for dec in fdef.decorator_list:
|
|
411
|
+
target = dec.func if isinstance(dec, ast.Call) else dec
|
|
412
|
+
if isinstance(target, ast.Name) and self._is_celery_import(rel, target.id, "shared_task"):
|
|
413
|
+
return True
|
|
414
|
+
if (
|
|
415
|
+
isinstance(target, ast.Attribute)
|
|
416
|
+
and target.attr == "task"
|
|
417
|
+
and isinstance(target.value, ast.Name)
|
|
418
|
+
and self._celery_app(rel, target.value.id)
|
|
419
|
+
):
|
|
420
|
+
return True
|
|
421
|
+
return False
|
|
422
|
+
|
|
423
|
+
def _closure(self, rel, stmts, fn):
|
|
424
|
+
"""The entry body plus every module-level body it reaches, in BFS order.
|
|
425
|
+
|
|
426
|
+
Each body is ``(relpath, own_nodes, function_node_or_None)``.
|
|
427
|
+
"""
|
|
428
|
+
bodies = [(rel, list(_own_nodes(stmts)), fn)]
|
|
429
|
+
seen = set()
|
|
430
|
+
if fn is not None:
|
|
431
|
+
seen.add((rel, fn.name))
|
|
432
|
+
index = 0
|
|
433
|
+
while index < len(bodies):
|
|
434
|
+
cur_rel, own, _ = bodies[index]
|
|
435
|
+
index += 1
|
|
436
|
+
for node in own:
|
|
437
|
+
if not isinstance(node, ast.Call):
|
|
438
|
+
continue
|
|
439
|
+
callee = self._callee(cur_rel, node)
|
|
440
|
+
if callee is None or callee in seen:
|
|
441
|
+
continue
|
|
442
|
+
seen.add(callee)
|
|
443
|
+
crel, cname = callee
|
|
444
|
+
cfn = self.funcs[crel][cname]
|
|
445
|
+
bodies.append((crel, list(_own_nodes(cfn.body)), cfn))
|
|
446
|
+
return bodies
|
|
447
|
+
|
|
448
|
+
def _starts_server(self, bodies):
|
|
449
|
+
return any(
|
|
450
|
+
isinstance(node, ast.Call) and _final_name(node.func) in SERVER_NAMES
|
|
451
|
+
for _, own, _ in bodies
|
|
452
|
+
for node in own
|
|
453
|
+
)
|
|
454
|
+
|
|
455
|
+
def _entry_bodies(self, category, rel, tree, stmt):
|
|
456
|
+
"""The reached bodies when ``stmt`` is an entry point of ``category``, else None."""
|
|
457
|
+
if category == "migration":
|
|
458
|
+
if isinstance(stmt, ast.FunctionDef) and stmt.name == "upgrade" and _has_revision(tree):
|
|
459
|
+
return self._closure(rel, stmt.body, stmt)
|
|
460
|
+
return None
|
|
461
|
+
if category == "maintenance-command":
|
|
462
|
+
if not _is_main_guard(stmt):
|
|
463
|
+
return None
|
|
464
|
+
bodies = self._closure(rel, stmt.body, None)
|
|
465
|
+
return None if self._starts_server(bodies) else bodies
|
|
466
|
+
if category == "worker" and isinstance(stmt, (ast.FunctionDef, ast.AsyncFunctionDef)) and self._worker(rel, stmt):
|
|
467
|
+
return self._closure(rel, stmt.body, stmt)
|
|
468
|
+
return None
|
|
469
|
+
|
|
470
|
+
def _entries(self, category):
|
|
471
|
+
"""Entry points of one category, as ``(relpath, node, bodies)`` in (file, line, col) order."""
|
|
472
|
+
found = []
|
|
473
|
+
for rel in sorted(self.trees):
|
|
474
|
+
tree = self.trees[rel]
|
|
475
|
+
for stmt in tree.body:
|
|
476
|
+
bodies = self._entry_bodies(category, rel, tree, stmt)
|
|
477
|
+
if bodies is not None:
|
|
478
|
+
found.append((rel, stmt, bodies))
|
|
479
|
+
found.sort(key=lambda e: (e[0], e[1].lineno, e[1].col_offset))
|
|
480
|
+
return found
|
|
481
|
+
|
|
482
|
+
def signals(self, categories):
|
|
483
|
+
out = []
|
|
484
|
+
for category in sorted(set(categories)):
|
|
485
|
+
emitted = set()
|
|
486
|
+
for rel, node, bodies in self._entries(category):
|
|
487
|
+
tables = set()
|
|
488
|
+
for brel, own, fn in bodies:
|
|
489
|
+
for item in own:
|
|
490
|
+
if isinstance(item, ast.Call):
|
|
491
|
+
tables.update(self._writes(brel, own, fn, item))
|
|
492
|
+
for table in sorted(tables - emitted, key=_table_key):
|
|
493
|
+
emitted.add(table)
|
|
494
|
+
out.append(_table_signal(table, category, loc(rel, node)))
|
|
495
|
+
return out
|
|
@@ -783,6 +783,7 @@ class FileIndex:
|
|
|
783
783
|
|
|
784
784
|
def __init__(self, relpath: str, tree: ast.Module):
|
|
785
785
|
self.relpath = relpath
|
|
786
|
+
self.tree = tree
|
|
786
787
|
self.classes: list[ClassRecord] = []
|
|
787
788
|
self.table_calls: list[dict] = [] # {table_name, target, node}
|
|
788
789
|
# Module-level bindings of the form ``X = declarative_base()`` /
|
|
@@ -1812,13 +1813,16 @@ def _normalize_path(rel: str) -> str:
|
|
|
1812
1813
|
return path
|
|
1813
1814
|
|
|
1814
1815
|
|
|
1815
|
-
def scan(
|
|
1816
|
+
def scan(
|
|
1817
|
+
paths: list[str], root: Path | None = None, categories: tuple[str, ...] = ()
|
|
1818
|
+
) -> dict:
|
|
1816
1819
|
"""Collect the full deterministic discovery outcome for one request.
|
|
1817
1820
|
|
|
1818
1821
|
Args:
|
|
1819
1822
|
paths: Repo-root-relative paths from the discover request.
|
|
1820
1823
|
root: Scan root directory (defaults to the process cwd, which the
|
|
1821
1824
|
CLI sets to the repo root).
|
|
1825
|
+
categories: Internal entry-point categories to derive; empty derives none.
|
|
1822
1826
|
|
|
1823
1827
|
Returns:
|
|
1824
1828
|
dict: {"resources": [...], "unresolved": [...], "findings": [...],
|
|
@@ -1851,6 +1855,7 @@ def scan(paths: list[str], root: Path | None = None) -> dict:
|
|
|
1851
1855
|
continue
|
|
1852
1856
|
indexes[relpath] = index
|
|
1853
1857
|
resources: list[dict] = []
|
|
1858
|
+
table_refs: list[tuple[str, str | None, str]] = []
|
|
1854
1859
|
unresolved: list[dict] = []
|
|
1855
1860
|
signals: list[dict] = []
|
|
1856
1861
|
|
|
@@ -1932,6 +1937,7 @@ def scan(paths: list[str], root: Path | None = None) -> dict:
|
|
|
1932
1937
|
else SQLMODEL_CLASS_NAME_PROVENANCE
|
|
1933
1938
|
)
|
|
1934
1939
|
resources.append(_table_resource(relpath, rec, provenance, table_name))
|
|
1940
|
+
table_refs.append((relpath, rec.qname, table_name))
|
|
1935
1941
|
identity = _identity_signal(rec, relpath, table_name, rec.node)
|
|
1936
1942
|
if identity is not None:
|
|
1937
1943
|
signals.append(identity)
|
|
@@ -1944,11 +1950,25 @@ def scan(paths: list[str], root: Path | None = None) -> dict:
|
|
|
1944
1950
|
for relpath in sorted(indexes):
|
|
1945
1951
|
for call in indexes[relpath].table_calls:
|
|
1946
1952
|
resources.append(_call_table_resource(relpath, call))
|
|
1953
|
+
table_refs.append((relpath, None, call["table_name"]))
|
|
1947
1954
|
facts = _table_call_facts(call)
|
|
1948
1955
|
identity = _identity_signal(facts, relpath, call["table_name"], call["node"])
|
|
1949
1956
|
if identity is not None:
|
|
1950
1957
|
signals.append(identity)
|
|
1951
1958
|
|
|
1959
|
+
if categories:
|
|
1960
|
+
# Imported here: reachability.py imports this module's helpers.
|
|
1961
|
+
from .reachability import reachability_signals
|
|
1962
|
+
|
|
1963
|
+
signals.extend(
|
|
1964
|
+
reachability_signals(
|
|
1965
|
+
indexes,
|
|
1966
|
+
{rel: idx.tree for rel, idx in indexes.items()},
|
|
1967
|
+
table_refs,
|
|
1968
|
+
categories,
|
|
1969
|
+
)
|
|
1970
|
+
)
|
|
1971
|
+
|
|
1952
1972
|
resources.sort(key=lambda r: r["id"])
|
|
1953
1973
|
unresolved.sort(
|
|
1954
1974
|
key=lambda u: (
|