Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(health): count Pascal for-in loops, add a performance dialect (#2233)
Laentir Valetov7ee0dff56188
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.mdindex c21ccb986..0e62eecba 100644--- a/docs/CHANGELOG.md+++ b/docs/CHANGELOG.md@@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0---+## [Unreleased]++### Changed++- **`HEALTH_ANALYZER_VERSION` is 31.** Pascal opts into assertion detection: DUnit's `Check` / `CheckEquals` / `Fail` family (a new `asserts/lexicon.py` row, broad tier) and DUnitX's `Assert.*` plus the RTL's own `Assert(cond, msg)` (narrow tier — `Assert` is itself an assert-prefixed identifier, so no row was needed). A call in flat statement position sits under a node named `statement`, not the `expression_statement` every other mapped grammar uses, and a `try`'s guarded body and its `except`/`finally` clauses use a distinct `statements` container rather than `block` — both were invisible to the assertion pass, so every assertion inside a `try ... finally Free; end` (close to universal in Delphi tests) went uncounted. Measured on a real ~150-file Delphi codebase's `Test*.dpr` suite: assertion coverage moved from 66/120 files (1,844 assertions) to 86/120 (2,873). `large_assertion_block` / `duplicated_assertion_block` now fire for Pascal; `assertion_free_test` deliberately does not — it gates on a `SHIPPING_LANGUAGES` allowlist that needs its own measured-precision pass before Pascal joins it. Existing indexes re-score on their next update; `STORE_FORMAT_VERSION` and `PARSER_SCHEMA_VERSION` are unchanged.+- **`HEALTH_ANALYZER_VERSION` is 30.** A Pascal call to a zero-argument procedure may omit its parentheses entirely (`Q.Open;` is as idiomatic as `Q.Open();`), which produces no `exprCall` node at all — just a bare `identifier` / `exprDot` sitting directly under a `statement` wrapper, the same wrapper `Exit;` / `inherited;` use. The performance pass's `call_kinds` gate only recognised `exprCall`, so every parenless call was invisible to it regardless of sink kind — filesystem, subprocess, db and network alike. A new `bare_call_wrapper_kinds` / `PerfDialect.bare_statement_call` hook (default: no-op for every other language) tells a parenless call apart from the wrapper's other tenants; Pascal now finds an `io_in_loop` on `Q.Open;` in a loop exactly as it already did on `Q.Open();`. Existing indexes re-score on their next update; `STORE_FORMAT_VERSION` and `PARSER_SCHEMA_VERSION` are unchanged.+- **`HEALTH_ANALYZER_VERSION` is 29.** Pascal's `for x in collection do` parses as its own `foreach` node, distinct from the counted `for`, and was missing from `loop_kinds` — the walker skipped it entirely, so any Pascal function using a for-in loop understated both CCN and nesting depth. Pascal also gained a `PerfDialect` (filesystem and subprocess sinks by RTL/VCL/FPC call name, e.g. `CopyFile` / `TFileStream.SaveToFile` / `ShellExecute`), so `io_in_loop` / `hot_path_sync_io` now fire for it instead of the performance pass silently skipping every Pascal file. The `uses` clause now feeds the shared `io_kind` table too (`FireDAC` / `ADODB` → db, `IdHTTP` / `System.Net.HttpClient` → network), so a `TDataSet.Open` / `.ExecSQL` / `.Post` or an HTTP client's `.Get` / `.Post` inside a loop is now a `db` / `network` `io_in_loop` finding when the file's own imports back it up, rather than staying silent — the same file-wide (not receiver-scoped) evidence trade the design already documents for languages with no per-variable type binding. Existing indexes re-score on their next update; `STORE_FORMAT_VERSION` and `PARSER_SCHEMA_VERSION` are unchanged.+## [0.52.0] - 2026-09-20A wide cycle. Documentation makes assertions about code, and this repository has the graph to check them, so a fourth deterministic analysis joins the pipeline: it reads the repository's own markdown, extracts the claims each document makes, resolves them against the real tree, and reports the ones the tree refutes. No model is involved, findings refresh on every update, and the reverse view answers which documents name a given file.diff --git a/docs/layers/LANGUAGE_SUPPORT.md b/docs/layers/LANGUAGE_SUPPORT.mdindex ec6866052..89ecaf5b2 100644--- a/docs/layers/LANGUAGE_SUPPORT.md+++ b/docs/layers/LANGUAGE_SUPPORT.md@@ -373,7 +373,7 @@ map before markers fire. This table is why a language is Full rather than Good.| Scala | ✅ | ✅ | ✅ | later | later | later | ✅ || Ruby | ✅ | ✅ | ✅ | later | later | later | ✅ || Dart | ✅ | n/a | ✅ | later | later | later | ✅ |-| Object Pascal | ✅ | n/a | later | n/a | n/a | later | n/a |+| Object Pascal | ✅ | n/a | ✅ | n/a | n/a | later | ✅ || Razor | ✅ | n/a | n/a | n/a | n/a | later | ✅ || Shell | ✅ | n/a | n/a | n/a | n/a | n/a | n/a |@@ -828,6 +828,19 @@ cannot check.- **Razor has no import edges**, and an attribute-bound handler carries none.- **Object Pascal's `extends`/`implements` split is a naming heuristic**,inferred from the `I`-prefix convention rather than a language guarantee.+- **Object Pascal's DB/network performance sinks are gated on file-wide+ `uses`-clause evidence, not per-receiver evidence.** A file importing+ `FireDAC` gates every `.Open` / `.ExecSQL` / `.Post` call in it, not only+ calls on an actual `TFDQuery`, because a Pascal variable's declared type has+ no textual link back to the unit it came from the way `client = requests.Session()`+ does in Python.+- **Object Pascal has no `assertion_free_test`.** `large_assertion_block` /+ `duplicated_assertion_block` / `mock_saturated_test` all read the same+ assertion counts and work for it; `assertion_free_test` additionally gates+ on a `SHIPPING_LANGUAGES` allowlist that needs its own measured-precision+ pass (see the module docstring) before Pascal joins it. It has no mock+ dialect either, so `mock_saturated_test`'s mock-setup half stays at zero --+ advisory and harmless, never a false `mock_saturated_test` positive.- **A GDScript `uid://` resolves through the `.uid` sidecar Godot writes forscripts**, so a `preload` naming one reaches its file. A uid naming a scenedoes not: Godot writes no sidecar for `.tscn` / `.tres`, and the@@ -859,7 +872,7 @@ Per-language mechanics behind these:| C# | Full (health) | Dataflow dialect || Dart | Good | riverpod / get_it dynamic hints, dataflow dialect || GDScript | Good | The health dialects (complexity, performance, dataflow) that would take it to Full; the grammar supports all three |-| Object Pascal | Good | Assertion and performance markers, a dedicated `uses` resolver |+| Object Pascal | Good | A dedicated `uses` resolver; `assertion_free_test` needs a measured-precision pass before it joins its language allowlist || COBOL | Good | Copybook resolution, source-format normalization, dialect coverage, health markers || VB.NET | Good | Health markers, project-level `<Import Include=...>` as implicit imports || Elixir | Good | Health markers, and a call-resolution strategy beyond same-file |diff --git a/packages/core/src/repowise/core/analysis/health/asserts/lexicon.py b/packages/core/src/repowise/core/analysis/health/asserts/lexicon.pyindex 9aaaa8d39..49b9312ea 100644--- a/packages/core/src/repowise/core/analysis/health/asserts/lexicon.py+++ b/packages/core/src/repowise/core/analysis/health/asserts/lexicon.py@@ -158,6 +158,35 @@ _JS_TS = AssertDialect()+# DUnit's ``TTestCase`` oracle family (``TestFramework.pas``), called bare+# (inherited protected methods, no receiver) inside a test method. DUnitX's+# ``Assert.*`` needs no row: the narrow tier already takes any callee chain+# carrying an ``assert``-prefixed identifier, and ``Assert`` (the receiver) is+# one -- same reason the Go row above only needs ``require``.+_PASCAL = AssertDialect(+ assert_names=frozenset(+ {+ "check",+ "checkequals",+ "checknotequals",+ "checksame",+ "checknotsame",+ "checkis",+ "checknull",+ "checknotnull",+ "checktrue",+ "checkfalse",+ "checkequalsmem",+ "checkexception",+ "fail",+ "failequals",+ "failnotequals",+ "failnotsame",+ }+ ),+)++# Keyed by ``LanguageTag`` (``ingestion/models.py``), as ``LANGUAGE_MAPS`` and# ``MOCK_DIALECTS`` are.ASSERT_DIALECTS: dict[str, AssertDialect] = {@@ -165,6 +194,7 @@ ASSERT_DIALECTS: dict[str, AssertDialect] = {"java": _JAVA,"javascript": _JS_TS,"jsx": _JS_TS,+ "pascal": _PASCAL,"python": _PY,"typescript": _JS_TS,"tsx": _JS_TS,diff --git a/packages/core/src/repowise/core/analysis/health/complexity/assertions.py b/packages/core/src/repowise/core/analysis/health/complexity/assertions.pyindex 128c7028c..53bb83009 100644--- a/packages/core/src/repowise/core/analysis/health/complexity/assertions.py+++ b/packages/core/src/repowise/core/analysis/health/complexity/assertions.py@@ -244,7 +244,10 @@ def _assertion_tier(stmt: Node, lmap: LanguageNodeMap, dialect: AssertDialect |# only ever appear as the single child of an ``expression_statement``,# so they can't form a run of ≥2 at this level.)call: Node | None = stmt- elif stmt.type == _EXPRESSION_STATEMENT:+ elif stmt.type == _EXPRESSION_STATEMENT or stmt.type in lmap.expr_stmt_kinds:+ # ``expr_stmt_kinds`` is the same shape as the hardcoded+ # ``expression_statement`` name above, for a grammar whose wrapper is+ # not literally called that (Pascal's is ``statement``).call = _find_assert_call(stmt, lmap.assert_call_kinds)if call is None:# A property-terminated assertion is capped at broad for the samediff --git a/packages/core/src/repowise/core/analysis/health/complexity/languages.py b/packages/core/src/repowise/core/analysis/health/complexity/languages.pyindex e6c03dc84..942ad47ee 100644--- a/packages/core/src/repowise/core/analysis/health/complexity/languages.py+++ b/packages/core/src/repowise/core/analysis/health/complexity/languages.py@@ -115,6 +115,16 @@ class LanguageNodeMap:# false positive, and no vocabulary row can give it any.assert_kinds: frozenset[str] = frozenset()assert_call_kinds: frozenset[str] = frozenset()+ # * ``expr_stmt_kinds`` — this language's wrapper node type(s) for "an+ # expression used as a full statement", when that wrapper is not+ # literally named ``expression_statement`` (most grammars this pass+ # already serves use that exact name, hardcoded in+ # ``assertions._assertion_tier``; Pascal's is called ``statement``).+ # Empty by default: a grammar whose wrapper IS ``expression_statement``+ # needs nothing here, and one with no wrapper at all (a call sits+ # directly in the statement list, e.g. Kotlin) needs nothing here+ # either -- ``stmt.type in assert_call_kinds`` already matches it.+ expr_stmt_kinds: frozenset[str] = frozenset()# ------------------------------------------------------------------# Performance pass (io_in_loop / string_concat_in_loop /@@ -133,6 +143,16 @@ class LanguageNodeMap:# walker, so this set only needs the dedicated async node types.call_kinds: frozenset[str] = frozenset()async_function_kinds: frozenset[str] = frozenset()+ # Statement-wrapper node type(s) that MAY wrap a call with no ``call_kinds``+ # node at all -- a parenless call (Pascal's ``Q.Open;``, valid for any+ # zero-argument procedure). Every wrapped statement of this kind reaches+ # ``PerfDialect.bare_statement_call``, which returns the node to treat as+ # the call (typically the wrapper's sole named child) or ``None`` when the+ # statement is not a call at all (Pascal's bare ``Exit;`` / ``inherited;``+ # take this same wrapper shape and correctly return ``None``). Empty by+ # default: a language whose call site always has its own dedicated node+ # (most grammars) needs neither this field nor the hook.+ bare_call_wrapper_kinds: frozenset[str] = frozenset()# ------------------------------------------------------------------# Dataflow def/use pass (intra-procedural CFG + reaching definitions).@@ -775,7 +795,10 @@ _PASCAL = LanguageNodeMap(# recursive walker already counts one branch per level without special# casing.branch_kinds=frozenset({"if", "ifElse"}),- loop_kinds=frozenset({"for", "while", "repeat"}),+ # ``for`` is the counted ``for i := a to b do`` loop; ``foreach`` is the+ # distinct ``for x in collection do`` grammar node (its own node type,+ # not a variant of ``for``) -- both are loops and must both count.+ loop_kinds=frozenset({"for", "foreach", "while", "repeat"}),try_kinds=frozenset({"try"}),# A bound handler (``on E: Exception do``) is an ``exceptionHandler``# node; a bare ``except ... end`` with no ``on`` clauses has no such@@ -793,6 +816,18 @@ _PASCAL = LanguageNodeMap(# not generic operator text inside a binary node, so no text-sniffing# set is needed here (unlike the C-family languages above).boolean_operator_kinds=frozenset({"kAnd", "kOr"}),+ # DUnit's ``Check`` / ``CheckEquals`` / ``Fail`` family are ordinary calls+ # named in ``asserts/lexicon.py``'s Pascal row (broad tier); DUnitX's+ # ``Assert.AreEqual`` / ``Assert.IsTrue`` / ... need no row at all -- the+ # narrow tier already matches any callee chain with an ``assert``-prefixed+ # identifier, and ``Assert`` (the receiver) is one. Same for the RTL's own+ # ``Assert(cond, msg)`` runtime-assertion call.+ assert_call_kinds=frozenset({"exprCall"}),+ # A call in flat statement position -- ``CheckEquals(5, X);`` as much as a+ # structural statement -- sits directly under a ``statement`` wrapper, not+ # a node literally named ``expression_statement`` the way most grammars+ # this pass serves spell it.+ expr_stmt_kinds=frozenset({"statement"}),# No class-level metrics: Pascal splits a class into an interface-only# ``declClass`` (method SIGNATURES only, via ``declProc`` -- no bodies)# and a fully separate implementation section where each qualified@@ -804,7 +839,14 @@ _PASCAL = LanguageNodeMap(# every class. Same posture as Go (external-receiver methods): left# unmapped rather than emitting a misleading zero-method class.if_kinds=frozenset({"if", "ifElse"}),- block_kinds=frozenset({"block"}),+ # ``block`` is the ``begin ... end`` container; ``statements`` is the+ # grammar's OTHER flat statement-list node, used for a ``try``'s guarded+ # body and each ``except``/``finally`` clause's body (``try`` has no+ # ``begin``/``end`` of its own). Both are true statement-list containers,+ # so both belong here -- without ``statements``, every assertion inside a+ # ``try ... finally Free; end`` (a near-universal Delphi test idiom) was+ # invisible to the assertion pass and to mock-setup counting.+ block_kinds=frozenset({"block", "statements"}),# No dedicated ``return`` node -- ``Result := ...`` is an ordinary# assignment and a bare ``Exit`` / ``Exit(...)`` is an ordinary# identifier/call statement, so neither edges to the CFG exit specially@@ -817,6 +859,17 @@ _PASCAL = LanguageNodeMap(break_kinds=frozenset(),continue_kinds=frozenset(),with_kinds=frozenset({"with"}),+ # ``exprCall`` is the one call-expression node, covering both a bare+ # ``Foo(x)`` (``entity`` is an ``identifier``) and a method call+ # ``Obj.Foo(x)`` (``entity`` is an ``exprDot``). Feeds the perf pass+ # (``perf/dialects/pascal.py``).+ call_kinds=frozenset({"exprCall"}),+ # A parenless call to a zero-argument procedure (``Q.Open;`` / ``Close;``)+ # has no ``exprCall`` node at all -- it is a bare ``identifier`` or+ # ``exprDot`` sitting directly under a ``statement`` wrapper (the same+ # wrapper ``Break``/``Continue``/``Exit`` use, per the comment above).+ # ``PascalPerfDialect.bare_statement_call`` tells the two apart.+ bare_call_wrapper_kinds=frozenset({"statement"}),)diff --git a/packages/core/src/repowise/core/analysis/health/complexity/perf_walk.py b/packages/core/src/repowise/core/analysis/health/complexity/perf_walk.pyindex 3c7cede51..6c71a3c83 100644--- a/packages/core/src/repowise/core/analysis/health/complexity/perf_walk.py+++ b/packages/core/src/repowise/core/analysis/health/complexity/perf_walk.py@@ -233,9 +233,17 @@ def _collect_perf_hits(fn_kinds = lmap.function_kindslambda_kinds = lmap.lambda_kindsasync_fn_kinds = lmap.async_function_kinds+ bare_call_wrapper_kinds = lmap.bare_call_wrapper_kinds# Block-iteration loops (Ruby ``items.each do … end``): only pay for the# per-call-node hook when the dialect actually overrides it.do_block_loop = _overrides(dialect, "block_loop_body")+ # Parenless calls (Pascal ``Q.Open;``): only probe a bare-call wrapper+ # (``statement``) when the dialect actually overrides the hook, same+ # pay-for-what-you-use posture as ``do_block_loop``.+ do_bare_stmt_call = (+ bool(bare_call_wrapper_kinds)+ and _overrides(dialect, "bare_statement_call")+ )do_chunked = _overrides(dialect, "is_chunked_loop")do_magnitude = _overrides(dialect, "loop_magnitude")do_batch = _overrides(dialect, "batch_form")@@ -380,23 +388,33 @@ def _collect_perf_hits(PerfHit(icm, node.start_point[0] + 1, next_func, "", func_start=next_start))+ call_node: Node | None = Noneif t in call_kinds:- method = dialect.callee_method_name(node) or ""- root_name = dialect.callee_root_name(node) or ""- awaited = dialect.is_awaited(node)- line = node.start_point[0] + 1+ call_node = node+ elif do_bare_stmt_call and t in bare_call_wrapper_kinds:+ # A parenless call (Pascal ``Q.Open;``): no ``call_kinds`` node+ # exists at all, so the dialect is asked whether this particular+ # statement wrapper IS one (it also wraps non-call statements —+ # Pascal's bare ``Exit;`` / ``inherited;`` — that must stay None).+ call_node = dialect.bare_statement_call(node)++ if call_node is not None:+ method = dialect.callee_method_name(call_node) or ""+ root_name = dialect.callee_root_name(call_node) or ""+ awaited = dialect.is_awaited(call_node)+ line = call_node.start_point[0] + 1if do_bare_call_marker:# A call that is its own iteration construct (``.reduce`` with an# accumulator spread) — a perf smell at any loop depth.- bare = dialect.bare_call_marker(root_name, method, node)+ bare = dialect.bare_call_marker(root_name, method, call_node)if bare is not None:hits.append(PerfHit(bare, line, next_func, "", func_start=next_start))kind = dialect.call_sink_kind(- node, awaited=awaited, io_names=io_names, has_db_import=has_db_import+ call_node, awaited=awaited, io_names=io_names, has_db_import=has_db_import)if kind is not None:if loop_depth >= 1:- facts = loop_facts(node, sink=True)+ facts = loop_facts(call_node, sink=True)hits.append(PerfHit("io_in_loop", line, next_func, kind, func_start=next_start, loop=facts))@@ -462,7 +480,7 @@ def _collect_perf_hits(else:if loop_depth >= 1:marker = (- dialect.loop_call_marker(root_name, method, node, list_names)+ dialect.loop_call_marker(root_name, method, call_node, list_names)if do_loop_call_markerelse None)@@ -470,7 +488,7 @@ def _collect_perf_hits(hits.append(PerfHit(marker, line, next_func, "", func_start=next_start,- loop=loop_facts(node, sink=False),+ loop=loop_facts(call_node, sink=False),))elif method:@@ -480,7 +498,7 @@ def _collect_perf_hits(targets = _acc(next_start, next_func)[0]if method not in targets:targets[method] = line- facts = loop_facts(node, sink=False)+ facts = loop_facts(call_node, sink=False)if facts is not None:call_facts.setdefault(next_start, {})[line] = factsif do_lock_io and lock_depth >= 1 and method:diff --git a/packages/core/src/repowise/core/analysis/health/engine.py b/packages/core/src/repowise/core/analysis/health/engine.pyindex 3dd12d96b..e55698e15 100644--- a/packages/core/src/repowise/core/analysis/health/engine.py+++ b/packages/core/src/repowise/core/analysis/health/engine.py@@ -112,6 +112,46 @@ log = structlog.get_logger(__name__)# and a declining call's arguments are not scanned, so an assertion passed as an# argument still does not stand in for the header's oracle.#+# v31: Pascal opts into assertion detection (``assert_call_kinds``): DUnit's+# ``Check``/``CheckEquals``/``Fail`` family (a new ``asserts/lexicon.py`` row,+# broad tier) and DUnitX's ``Assert.*`` plus the RTL's own ``Assert(cond, msg)``+# (narrow tier, no row needed -- ``Assert`` itself is an assert-prefixed+# identifier). A new ``expr_stmt_kinds`` field tells the walker that a call in+# flat statement position sits under a node named ``statement``, not the+# hardcoded ``expression_statement`` every other mapped grammar uses.+# ``block_kinds`` also gains ``statements`` (plural) -- a ``try``'s guarded+# body and its ``except``/``finally`` clauses use that distinct container, not+# ``block``, so every assertion inside a ``try ... finally Free; end`` (close+# to universal in Delphi tests) was invisible before this: measured on a real+# ~150-file Delphi codebase's Test*.dpr suite, assertion coverage moved from+# 66/120 files (1844 assertions) to 86/120 (2873). ``large_assertion_block`` /+# ``duplicated_assertion_block`` now fire for Pascal; ``assertion_free_test``+# deliberately does not -- it gates on a ``SHIPPING_LANGUAGES`` allowlist that+# needs its own measured-precision pass before Pascal joins it.+#+# v30: a Pascal call to a zero-argument procedure may omit its parentheses+# entirely (``Q.Open;``), which produces no ``exprCall`` node at all -- just a+# bare ``identifier`` / ``exprDot`` under a ``statement`` wrapper, invisible to+# the whole performance pass regardless of sink kind. The new+# ``bare_call_wrapper_kinds`` / ``PerfDialect.bare_statement_call`` hook (a+# no-op for every language that does not map it) tells that shape apart from+# the wrapper's other tenants (``Exit;`` / ``inherited;``), so ``Q.Open;`` now+# finds the same ``io_in_loop`` as ``Q.Open();`` already did.+#+# v29: Pascal's ``uses`` clause now feeds ``io_boundaries.collect_io_names``+# (``FireDAC`` / ``ADODB`` -> db, ``IdHTTP`` / ``System.Net.HttpClient`` ->+# network), and the Pascal ``PerfDialect`` gates ``TDataSet.Open`` /+# ``.ExecSQL`` / ``.Post`` and an HTTP client's ``.Get`` / ``.Post`` on that+# evidence -- a loop calling one of these now produces a ``db`` / ``network``+# ``io_in_loop`` where before it stayed silent (filesystem/subprocess only).+#+# v28: Pascal's ``foreach`` (``for x in collection do``) was absent from its+# ``loop_kinds``, so a for-in loop contributed no CCN and opened no nesting+# level -- stored complexity / nesting for any Pascal function using one+# understates both. Pascal also gained a ``PerfDialect`` (filesystem /+# subprocess sinks by RTL/VCL/FPC name), so ``io_in_loop`` / ``hot_path_sync_io``+# now fire for it instead of the pass silently skipping every Pascal file.+## v27: a new marker, ``lazy_load_in_loop`` (a lazy relationship read on each# iteration of a loop over its rows); and ``unbounded_read_reduced_in_memory`` now# runs on ``init`` too, where it never ran before. A v26 store built by ``init`` has@@ -263,7 +303,7 @@ log = structlog.get_logger(__name__)# forms. Files that were counted untested and are not become tested, which# moves untested-hotspot findings and the scores that carry them, on every# language with a prefix or spec convention rather than Ruby alone.-HEALTH_ANALYZER_VERSION = 27+HEALTH_ANALYZER_VERSION = 31def walked_functions(diff --git a/packages/core/src/repowise/core/analysis/health/perf/dialects/__init__.py b/packages/core/src/repowise/core/analysis/health/perf/dialects/__init__.pyindex 62fc04ec5..ed51d1665 100644--- a/packages/core/src/repowise/core/analysis/health/perf/dialects/__init__.py+++ b/packages/core/src/repowise/core/analysis/health/perf/dialects/__init__.py@@ -20,6 +20,7 @@ from . import dart as _dartfrom . import go as _gofrom . import java as _javafrom . import kotlin as _kotlin+from . import pascal as _pascalfrom . import python as _pythonfrom . import ruby as _rubyfrom . import rust as _rust@@ -56,6 +57,7 @@ _REGISTER: tuple[tuple[str, BasePerfDialect], ...] = (# on purpose: no perf dialect has been written for it, and the coverage# report names it as an unsupported language rather than pretending a# detector ran.+ ("pascal", _pascal.DIALECT),)for _tag, _dialect in _REGISTER:diff --git a/packages/core/src/repowise/core/analysis/health/perf/dialects/base.py b/packages/core/src/repowise/core/analysis/health/perf/dialects/base.pyindex 3df6270b0..b91825118 100644--- a/packages/core/src/repowise/core/analysis/health/perf/dialects/base.py+++ b/packages/core/src/repowise/core/analysis/health/perf/dialects/base.py@@ -629,6 +629,25 @@ class BasePerfDialect:"""return False+ def bare_statement_call(self, node: Node) -> Node | None:+ """The call site inside *node*, a ``LanguageNodeMap.bare_call_wrapper_kinds``+ statement wrapper, if this particular statement is a parenless call --+ else ``None``.++ Only relevant to a grammar where a call with no arguments can omit its+ parentheses (Pascal's ``Q.Open;``), so the call site is not any+ ``call_kinds`` node at all but a bare identifier/member-access sitting+ directly in statement position. The SAME wrapper shape holds other+ non-call statements too (Pascal's bare ``Exit;`` / ``inherited;``), so+ this has to tell them apart, not just unwrap unconditionally.++ Default ``None`` -- a language with no such wrapper in+ ``bare_call_wrapper_kinds`` never reaches this hook, and one that maps+ the field but returns ``None`` here for a given node just means "this+ statement is not a call."+ """+ return None+# The registry, populated by ``dialects/__init__.py`` from each language module.# Keyed by ``LanguageTag``; a missing key ⇒ the perf pass is silent for thatdiff --git a/packages/core/src/repowise/core/analysis/health/perf/dialects/pascal.py b/packages/core/src/repowise/core/analysis/health/perf/dialects/pascal.pynew file mode 100644index 000000000..5083bca58--- /dev/null+++ b/packages/core/src/repowise/core/analysis/health/perf/dialects/pascal.py@@ -0,0 +1,227 @@+"""Pascal (Delphi/FPC) ``PerfDialect``.++Flagship: a filesystem or process-spawn round-trip inside a loop+(``io_in_loop``) — ``CopyFile`` / ``TFileStream.SaveToFile`` / ``WinExec``+called once per iteration instead of once, the classic batch-file-ops+anti-pattern in a file manager / build tool codebase.++Pascal's one call-expression node (``exprCall``, see ``LanguageNodeMap``'s+``call_kinds``) spells its callee under the ``entity`` field rather than the+generic base extraction's ``function`` field, and a qualified call+(``Obj.Method(x)``) is an ``exprDot`` (``lhs``/``operator``/``rhs``) rather+than a ``member_expression`` — so callee extraction is overridden outright+rather than reusing ``BasePerfDialect``'s field-name probing.++A call to a zero-argument procedure may omit its parentheses entirely+(``Q.Open;`` is as idiomatic as ``Q.Open();``), which produces no ``exprCall``+node at all — just a bare ``identifier`` / ``exprDot`` sitting directly under+a ``statement`` wrapper. :meth:`PascalPerfDialect.bare_statement_call` (via+``LanguageNodeMap.bare_call_wrapper_kinds``) tells that shape apart from the+statement wrapper's other tenants (``Exit;`` / ``inherited;``), and+:meth:`_entity_of` treats the resulting bare node as its own entity, so every+sink lexicon below applies identically regardless of parentheses.++Filesystem and subprocess sinks below are unambiguous, distinctively-named+RTL/VCL/FPC calls that never collide with an unrelated API, so they fire on+the name alone. DB and network verbs (``Open`` / ``ExecSQL`` / ``Get`` /+``Post``) are NOT distinctive -- they collide with ordinary collection and+stream methods everywhere in this codebase family -- so they additionally+require ``uses``-clause evidence (``io_boundaries.collect_io_names``'s+Pascal branch, keyed off the shared ``io_kind`` table: ``FireDAC`` / ``ADODB``+-> db, ``IdHTTP`` / ``System.Net.HttpClient`` -> network) before they fire.+That evidence is file-wide, not receiver-scoped like Python's ``client.get()``+-> ``client`` bound to ``requests`` -- a variable named ``FDConnection`` has+no textual link back to the ``FireDAC`` unit it came from -- so a file that+imports FireDAC AND separately calls an unrelated ``.Open`` on something else+can still false-fire. Precision trades against the alternative, which is no+DB/network signal for Pascal at all.++No ``async``/``await`` in the language, so ``blocking_sync_in_async`` is not+in :attr:`markers`. String accumulation is idiomatically ``s := s + x``, not+a ``+=`` compound assignment (``{$COPERATORS ON}`` is off by default), which+the generic ``is_string_concat`` predicate cannot express without risking+false positives on ordinary reassignment -- ``string_concat_in_loop`` is+therefore also left out rather than guessed.+"""++from __future__ import annotations++from typing import TYPE_CHECKING++from .base import BasePerfDialect++if TYPE_CHECKING:+ from tree_sitter import Node++# Filesystem round-trips. Bare RTL functions (SysUtils / System.IOUtils /+# WinAPI) with no receiver, so they fire regardless of ``is_attribute``.+_FS_BARE: frozenset[str] = frozenset(+ {+ "DeleteFile",+ "RenameFile",+ "CopyFile",+ "MoveFile",+ "MoveFileEx",+ "ForceDirectories",+ "RemoveDir",+ "RmDir",+ "CreateDir",+ "MkDir",+ "FileOpen",+ "FileCreate",+ "FileRead",+ "FileWrite",+ "FileClose",+ "FileSeek",+ "FileGetDate",+ "FileSetDate",+ "FileExists",+ "DirectoryExists",+ "FindFirst",+ "FindNext",+ "FindClose",+ "TDirectory.GetFiles",+ "TDirectory.GetDirectories",+ "TFile.Copy",+ "TFile.Move",+ "TFile.Delete",+ "TFile.ReadAllText",+ "TFile.WriteAllText",+ "TFile.ReadAllBytes",+ "TFile.WriteAllBytes",+ }+)+# Stream / string-list I/O methods. Always called on a receiver+# (``Stream.LoadFromFile`` / ``List.SaveToFile``), so gated on ``is_attribute``+# -- a bare helper of the same name elsewhere stays silent.+_FS_METHODS: frozenset[str] = frozenset(+ {+ "LoadFromFile",+ "SaveToFile",+ "LoadFromStream",+ "SaveToStream",+ }+)+# Process-spawn round-trips. ``Execute`` collides with ordinary business logic+# (any ``TCommand.Execute``), so it is excluded; the rest are distinctive+# enough by name alone.+_SUBPROCESS_BARE: frozenset[str] = frozenset(+ {+ "ExecuteProcess",+ "ShellExecute",+ "ShellExecuteEx",+ "WinExec",+ "CreateProcess",+ "CreateProcessW",+ "CreateProcessA",+ }+)+# TDataSet-family round-trips (FireDAC / ADO / dbGo / ZeosLib all share this+# vocabulary). Gated on ``uses``-clause DB evidence -- see the module+# docstring -- since ``Open`` / ``Post`` collide with unrelated stream and+# collection methods on their own.+_DB_METHODS: frozenset[str] = frozenset({"Open", "ExecSQL", "Post"})+# Indy / ``System.Net.HttpClient`` / FPC ``fphttpclient`` verb calls. Gated on+# ``uses``-clause network evidence for the same reason.+_NETWORK_METHODS: frozenset[str] = frozenset({"Get", "Post", "Put", "Patch", "Delete", "Head"})+++class PascalPerfDialect(BasePerfDialect):+ language = "pascal"+ markers = frozenset({"io_in_loop", "hot_path_sync_io"})++ # -- callee extraction (Pascal's own field names) -------------------------++ @staticmethod+ def _entity_of(call_node: Node) -> Node | None:+ """The callee expression a call site names.++ An ``exprCall`` (parenthesized call) carries it in its ``entity``+ field. A parenless call has no wrapping ``exprCall`` at all --+ :meth:`bare_statement_call` hands back the bare ``identifier`` /+ ``exprDot`` itself as *call_node*, which already IS its own entity.+ """+ if call_node.type == "exprCall":+ return call_node.child_by_field_name("entity")+ if call_node.type in ("identifier", "exprDot"):+ return call_node+ return None++ def callee_root_name(self, call_node: Node) -> str | None:+ entity = self._entity_of(call_node)+ if entity is None:+ return None+ node = entity+ for _ in range(8):+ if node.type != "exprDot":+ break+ lhs = node.child_by_field_name("lhs")+ if lhs is None:+ break+ node = lhs+ if node.text is None:+ return None+ return node.text.decode("utf-8", "replace").split(".")[-1]++ def callee_method_name(self, call_node: Node) -> str | None:+ entity = self._entity_of(call_node)+ if entity is None:+ return None+ if entity.type == "exprDot":+ rhs = entity.child_by_field_name("rhs")+ if rhs is not None and rhs.text is not None:+ return rhs.text.decode("utf-8", "replace")+ return None+ if entity.text is None:+ return None+ return entity.text.decode("utf-8", "replace")++ def callee_is_attribute(self, call_node: Node) -> bool:+ entity = self._entity_of(call_node)+ return entity is not None and entity.type == "exprDot"++ def bare_statement_call(self, node: Node) -> Node | None:+ """*node* is a ``statement`` wrapper; return its sole named child if+ that child is a bare ``identifier`` / ``exprDot`` -- a parenless call+ (``Q.Open;`` / ``FindClose;``). The same wrapper also carries+ non-call statements (``Exit;`` / ``inherited;`` -- also a bare+ ``identifier`` in the grammar's case of ``Exit``!), which this cannot+ structurally rule out; sink lexicon membership is what keeps a bare+ ``Exit`` harmless (it names no sink). A statement already headed by+ its own ``exprCall`` (the parenthesized form) returns ``None`` here --+ that call site is reached separately, through ``call_kinds``, so+ returning it again would double-count the hit.+ """+ named = node.named_children+ if len(named) != 1:+ return None+ child = named[0]+ return child if child.type in ("identifier", "exprDot") else None++ # -- sink classification (the lexicon) ------------------------------------++ def sink_kind(+ self,+ root: str,+ method: str,+ *,+ awaited: bool,+ is_attribute: bool,+ io_names: dict[str, str],+ has_db_import: bool,+ ) -> str | None:+ qualified = f"{root}.{method}"+ if method in _FS_BARE or qualified in _FS_BARE:+ return "filesystem"+ if is_attribute and method in _FS_METHODS:+ return "filesystem"+ if method in _SUBPROCESS_BARE:+ return "subprocess"+ if is_attribute and has_db_import and method in _DB_METHODS:+ return "db"+ if is_attribute and method in _NETWORK_METHODS and "network" in io_names.values():+ return "network"+ return None+++DIALECT = PascalPerfDialect()diff --git a/packages/core/src/repowise/core/analysis/health/perf/io_boundaries.py b/packages/core/src/repowise/core/analysis/health/perf/io_boundaries.pyindex feb68875e..7f1798b26 100644--- a/packages/core/src/repowise/core/analysis/health/perf/io_boundaries.py+++ b/packages/core/src/repowise/core/analysis/health/perf/io_boundaries.py@@ -158,6 +158,22 @@ def collect_io_names(tree_root: _NodeLike, language: str) -> dict[str, str]:if kind is not None:for name in bound:names.setdefault(name, kind)+ elif node.type == "declUses" and language == "pascal":+ # Pascal's ``uses`` clause is one flat node listing every unit+ # (``uses SysUtils, Classes, IdHTTP;``), unlike Go's grouped+ # import which nests a per-line ``import_spec`` leaf. Classifying+ # the whole node would pick whichever unit's kind resolves first+ # out of an unordered set and bind ALL of them to it (so+ # ``IdHTTP`` could inherit ``db`` from a ``FireDAC`` listed in the+ # same clause) -- so each ``moduleName`` child is classified on+ # its own instead.+ for child in node.children:+ if child.type != "moduleName":+ continue+ kind, bound = _classify_import(child)+ if kind is not None:+ for name in bound:+ names.setdefault(name, kind)elif "import" in node.type or node.type in ("using_directive", "use_declaration"):# Classify only the *leaf* import node. A Go grouped# ``import ( "database/sql"; "regexp" )`` is an ``import_declaration``diff --git a/packages/core/src/repowise/core/ingestion/external_systems/io_kind.py b/packages/core/src/repowise/core/ingestion/external_systems/io_kind.pyindex 06ca4c7b1..1f396ee28 100644--- a/packages/core/src/repowise/core/ingestion/external_systems/io_kind.py+++ b/packages/core/src/repowise/core/ingestion/external_systems/io_kind.py@@ -73,6 +73,10 @@ _DB_NAMES: frozenset[str] = frozenset({# Ruby (require-feature names; ``pg`` / ``mysql2`` / ``redis`` above are# shared with the Node ecosystem)."activerecord", "active_record", "sequel", "mongoid", "sqlite3", "mongo",+ # Object Pascal / Delphi (``uses`` clause unit names; ``firedac`` resolves+ # a qualified ``FireDAC.Comp.Client`` too via the progressive dotted-prefix+ # candidates the import classifier already generates).+ "firedac", "adodb",})_NETWORK_NAMES: frozenset[str] = frozenset({@@ -101,6 +105,13 @@ _NETWORK_NAMES: frozenset[str] = frozenset({# Ruby (require-feature names; ``require "net/http"`` resolves via its# ``http`` segment above)."httparty", "faraday", "rest-client", "rest_client", "typhoeus", "excon",+ # Object Pascal / Delphi (``uses`` clause unit names). Indy's client unit+ # is ``IdHTTP`` itself, not a package root, so it is seeded bare. The+ # modern RTL client is the fully qualified ``System.Net.HttpClient`` --+ # deliberately NOT the bare ``system.net.http`` prefix shared with .NET+ # above, since Pascal's own ``System`` unit is ubiquitous and a bare+ # ``System`` or ``System.Net`` prefix would over-match almost every file.+ "idhttp", "system.net.httpclient", "fphttpclient",})_FILESYSTEM_NAMES: frozenset[str] = frozenset({diff --git a/packages/core/src/repowise/core/upgrade/_data/CHANGELOG.md b/packages/core/src/repowise/core/upgrade/_data/CHANGELOG.mdindex c21ccb986..0e62eecba 100644--- a/packages/core/src/repowise/core/upgrade/_data/CHANGELOG.md+++ b/packages/core/src/repowise/core/upgrade/_data/CHANGELOG.md@@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0---+## [Unreleased]++### Changed++- **`HEALTH_ANALYZER_VERSION` is 31.** Pascal opts into assertion detection: DUnit's `Check` / `CheckEquals` / `Fail` family (a new `asserts/lexicon.py` row, broad tier) and DUnitX's `Assert.*` plus the RTL's own `Assert(cond, msg)` (narrow tier — `Assert` is itself an assert-prefixed identifier, so no row was needed). A call in flat statement position sits under a node named `statement`, not the `expression_statement` every other mapped grammar uses, and a `try`'s guarded body and its `except`/`finally` clauses use a distinct `statements` container rather than `block` — both were invisible to the assertion pass, so every assertion inside a `try ... finally Free; end` (close to universal in Delphi tests) went uncounted. Measured on a real ~150-file Delphi codebase's `Test*.dpr` suite: assertion coverage moved from 66/120 files (1,844 assertions) to 86/120 (2,873). `large_assertion_block` / `duplicated_assertion_block` now fire for Pascal; `assertion_free_test` deliberately does not — it gates on a `SHIPPING_LANGUAGES` allowlist that needs its own measured-precision pass before Pascal joins it. Existing indexes re-score on their next update; `STORE_FORMAT_VERSION` and `PARSER_SCHEMA_VERSION` are unchanged.+- **`HEALTH_ANALYZER_VERSION` is 30.** A Pascal call to a zero-argument procedure may omit its parentheses entirely (`Q.Open;` is as idiomatic as `Q.Open();`), which produces no `exprCall` node at all — just a bare `identifier` / `exprDot` sitting directly under a `statement` wrapper, the same wrapper `Exit;` / `inherited;` use. The performance pass's `call_kinds` gate only recognised `exprCall`, so every parenless call was invisible to it regardless of sink kind — filesystem, subprocess, db and network alike. A new `bare_call_wrapper_kinds` / `PerfDialect.bare_statement_call` hook (default: no-op for every other language) tells a parenless call apart from the wrapper's other tenants; Pascal now finds an `io_in_loop` on `Q.Open;` in a loop exactly as it already did on `Q.Open();`. Existing indexes re-score on their next update; `STORE_FORMAT_VERSION` and `PARSER_SCHEMA_VERSION` are unchanged.+- **`HEALTH_ANALYZER_VERSION` is 29.** Pascal's `for x in collection do` parses as its own `foreach` node, distinct from the counted `for`, and was missing from `loop_kinds` — the walker skipped it entirely, so any Pascal function using a for-in loop understated both CCN and nesting depth. Pascal also gained a `PerfDialect` (filesystem and subprocess sinks by RTL/VCL/FPC call name, e.g. `CopyFile` / `TFileStream.SaveToFile` / `ShellExecute`), so `io_in_loop` / `hot_path_sync_io` now fire for it instead of the performance pass silently skipping every Pascal file. The `uses` clause now feeds the shared `io_kind` table too (`FireDAC` / `ADODB` → db, `IdHTTP` / `System.Net.HttpClient` → network), so a `TDataSet.Open` / `.ExecSQL` / `.Post` or an HTTP client's `.Get` / `.Post` inside a loop is now a `db` / `network` `io_in_loop` finding when the file's own imports back it up, rather than staying silent — the same file-wide (not receiver-scoped) evidence trade the design already documents for languages with no per-variable type binding. Existing indexes re-score on their next update; `STORE_FORMAT_VERSION` and `PARSER_SCHEMA_VERSION` are unchanged.+## [0.52.0] - 2026-09-20A wide cycle. Documentation makes assertions about code, and this repository has the graph to check them, so a fourth deterministic analysis joins the pipeline: it reads the repository's own markdown, extracts the claims each document makes, resolves them against the real tree, and reports the ones the tree refutes. No model is involved, findings refresh on every update, and the reverse view answers which documents name a given file.diff --git a/tests/unit/health/test_assertion_vocabulary.py b/tests/unit/health/test_assertion_vocabulary.pyindex a2239fb22..7e59c52fb 100644--- a/tests/unit/health/test_assertion_vocabulary.py+++ b/tests/unit/health/test_assertion_vocabulary.py@@ -141,6 +141,79 @@ describe("thing", () => {assert _counts(source, "tests/thing.test.ts", "typescript")["it callback"][0] == 0+# ---------------------------------------------------------------------------+# Object Pascal — DUnit's Check*/Fail family (broad) and DUnitX's Assert.*+# plus the RTL's own Assert() (both narrow, no dialect row needed)+# ---------------------------------------------------------------------------+++def test_pascal_dunit_check_family_is_broad_not_narrow() -> None:+ """``CheckEquals`` / ``CheckTrue`` / ``Fail`` count but never join a run.++ None start with ``assert``/``expect``, so they are broad-tier only via+ the Pascal ``AssertDialect`` row — same posture as Go's bare receiver+ list.+ """+ _require("pascal")+ source = (+ "unit UTestFoo;\ninterface\nimplementation\n"+ "procedure TFooTest.TestBar;\nbegin\n"+ " CheckEquals(5, GetValue);\n"+ " CheckTrue(IsOk);\n"+ " Fail('boom');\n"+ "end;\nend.\n"+ )+ count, blocks = _counts(source, "TestFoo.pas", "pascal")["TestBar"]+ assert count == 3+ assert blocks == 0+++def test_pascal_dunitx_assert_dot_needs_no_dialect_row() -> None:+ """``Assert.AreEqual`` / ``Assert.IsTrue`` are narrow via the receiver+ identifier alone, and form a run like any other narrow-tier pair."""+ _require("pascal")+ source = (+ "unit UTestFoo;\ninterface\nimplementation\n"+ "procedure TFooTest.TestBar;\nbegin\n"+ " Assert.AreEqual(5, GetValue);\n"+ " Assert.IsTrue(IsOk);\n"+ "end;\nend.\n"+ )+ count, blocks = _counts(source, "TestFoo.pas", "pascal")["TestBar"]+ assert count == 2+ assert blocks == 1+++def test_pascal_runtime_assert_call_is_narrow() -> None:+ """The RTL's own ``Assert(cond, msg)`` matches the narrow prefix rule+ like any other assert-prefixed callee -- no Pascal-specific handling."""+ _require("pascal")+ source = (+ "unit UTestFoo;\ninterface\nimplementation\n"+ "procedure TFooTest.TestBar;\nbegin\n"+ " Assert(SomeCheck, 'x');\n"+ " Assert(OtherCheck, 'y');\n"+ "end;\nend.\n"+ )+ count, blocks = _counts(source, "TestFoo.pas", "pascal")["TestBar"]+ assert count == 2+ assert blocks == 1+++def test_pascal_production_code_has_no_false_assertions() -> None:+ """Ordinary calls, including a name merely containing ``check`` as a+ substring (``CheckoutCart``, not an exact broad-tier name), count nothing."""+ _require("pascal")+ source = (+ "unit U;\ninterface\nimplementation\n"+ "procedure Bar;\nbegin\n"+ " CheckoutCart;\n"+ " DoNormalWork;\n"+ "end;\nend.\n"+ )+ assert _counts(source, "u.pas", "pascal")["Bar"] == (0, 0)++# ---------------------------------------------------------------------------# The boundary the phase turns on# ---------------------------------------------------------------------------diff --git a/tests/unit/health/test_complexity_walker.py b/tests/unit/health/test_complexity_walker.pyindex 8b2674f10..8ab55cdcf 100644--- a/tests/unit/health/test_complexity_walker.py+++ b/tests/unit/health/test_complexity_walker.py@@ -156,6 +156,30 @@ def test_pascal_complex_method_ccn():assert many.param_count == 5+def test_pascal_foreach_counts_as_a_loop():+ # Regression: ``for x in collection do`` parses as a distinct `foreach`+ # node (not a `for` variant), which was absent from loop_kinds -- the+ # walker skipped it entirely, undercounting both CCN and nesting for any+ # for-in loop (common over TList/TStringList/generics in real Delphi+ # code).+ src = (+ b"unit U;\ninterface\nimplementation\n"+ b"procedure Bar(Lst: TList);\nvar X: Integer;\nbegin\n"+ b" for X in Lst do\n"+ b" begin\n"+ b" if X > 0 then\n"+ b" begin\n"+ b" WriteLn(X);\n"+ b" end;\n"+ b" end;\n"+ b"end;\nend.\n"+ )+ fn = _find(walk_file("u.pas", "pascal", src).functions, "Bar")+ assert fn is not None+ assert fn.ccn == 3, f"expected CCN 3 (base + foreach + if), got {fn.ccn}"+ assert fn.max_nesting == 2, f"expected the if nested inside the foreach, got {fn.max_nesting}"++def test_pascal_else_if_chain_is_flat_not_nested():# Regression: found on a real ~40-arm `else if` VK-code dispatch chain# (StringToVK in a real Delphi codebase) — every arm nests the grammar'sdiff --git a/tests/unit/health/test_model_version_coupling.py b/tests/unit/health/test_model_version_coupling.pyindex 5d817b7f2..99798173d 100644--- a/tests/unit/health/test_model_version_coupling.py+++ b/tests/unit/health/test_model_version_coupling.py@@ -22,7 +22,7 @@ from repowise.core.analysis.health.refactoring.identity import (# The three stamps as they stand together. Moving either identity model means# moving the analyzer with it, and updating this tuple in the same commit.-_STAMPS = (27, 2, 2)+_STAMPS = (31, 2, 2)def test_the_identity_models_and_the_analyzer_stamp_are_pinned_together() -> None:diff --git a/tests/unit/health/test_perf_io_in_loop.py b/tests/unit/health/test_perf_io_in_loop.pyindex 5045f8cff..0594a844b 100644--- a/tests/unit/health/test_perf_io_in_loop.py+++ b/tests/unit/health/test_perf_io_in_loop.py@@ -183,6 +183,123 @@ _CASES = [[],"sync helpers on an imported I/O pkg (isCancel/create) are not sinks",),+ (+ "pascal",+ b"unit U;\ninterface\nimplementation\n"+ b"procedure F(Names: TStringList);\nvar I: Integer;\nbegin\n"+ b" for I := 0 to Names.Count - 1 do\n"+ b" CopyFile(PChar(Names[I]), PChar('dest'), False);\n"+ b"end;\nend.\n",+ [("io_in_loop", "filesystem")],+ "bare CopyFile in a data-dependent loop",+ ),+ (+ "pascal",+ b"unit U;\ninterface\nimplementation\n"+ b"procedure F(Names: TStringList; FS: TFileStream);\nvar I: Integer;\nbegin\n"+ b" for I := 0 to Names.Count - 1 do\n"+ b" FS.SaveToFile(Names[I]);\n"+ b"end;\nend.\n",+ [("io_in_loop", "filesystem")],+ "attribute-call stream I/O (SaveToFile) in a loop",+ ),+ (+ "pascal",+ b"unit U;\ninterface\nimplementation\n"+ b"procedure F(Items: TStringList);\nvar I: Integer;\nbegin\n"+ b" for I := 0 to Items.Count - 1 do\n"+ b" WinExec(PAnsiChar(Items[I]), 0);\n"+ b"end;\nend.\n",+ [("io_in_loop", "subprocess")],+ "process spawn per iteration",+ ),+ (+ "pascal",+ b"unit U;\ninterface\nimplementation\n"+ b"procedure F(S: string; Items: TStringList);\nvar I: Integer; T: string;\nbegin\n"+ b" for I := 0 to Items.Count - 1 do\n"+ b" begin\n"+ b" T := Copy(S, 1, I);\n"+ b" DoNormalWork(T);\n"+ b" end;\n"+ b"end;\nend.\n",+ [],+ "built-in substring Copy() is not TFile.Copy -- ordinary computation",+ ),+ (+ "pascal",+ b"unit U;\ninterface\nuses SysUtils, FireDAC.Comp.Client;\nimplementation\n"+ b"procedure F(Q: TFDQuery; Ids: TStringList);\nvar I: Integer;\nbegin\n"+ b" for I := 0 to Ids.Count - 1 do\n"+ b" Q.Open();\n"+ b"end;\nend.\n",+ [("io_in_loop", "db")],+ "DB dataset .Open() in a loop, gated by a FireDAC uses-clause import",+ ),+ (+ "pascal",+ b"unit U;\ninterface\nuses SysUtils, IdHTTP;\nimplementation\n"+ b"procedure F(Http: TIdHTTP; Urls: TStringList);\nvar I: Integer;\nbegin\n"+ b" for I := 0 to Urls.Count - 1 do\n"+ b" Http.Get(Urls[I]);\n"+ b"end;\nend.\n",+ [("io_in_loop", "network")],+ "HTTP client .Get() in a loop, gated by an IdHTTP uses-clause import",+ ),+ (+ "pascal",+ b"unit U;\ninterface\nimplementation\n"+ b"procedure F(Q: TFDQuery; Ids: TStringList);\nvar I: Integer;\nbegin\n"+ b" for I := 0 to Ids.Count - 1 do\n"+ b" Q.Open();\n"+ b"end;\nend.\n",+ [],+ "the same .Open() call with no uses-clause DB evidence is not a sink",+ ),+ (+ "pascal",+ b"unit U;\ninterface\nimplementation\n"+ b"procedure F(L: TStringList; Ids: TStringList);\nvar I: Integer;\nbegin\n"+ b" for I := 0 to Ids.Count - 1 do\n"+ b" L.Delete(0);\n"+ b"end;\nend.\n",+ [],+ "TStringList.Delete is not a DB verb even with no uses evidence",+ ),+ (+ "pascal",+ b"unit U;\ninterface\nuses SysUtils, FireDAC.Comp.Client;\nimplementation\n"+ b"procedure F(Q: TFDQuery; Ids: TStringList);\nvar I: Integer;\nbegin\n"+ b" for I := 0 to Ids.Count - 1 do\n"+ b" Q.Open;\n"+ b"end;\nend.\n",+ [("io_in_loop", "db")],+ "parenless .Open (no exprCall node at all) is still a DB sink",+ ),+ (+ "pascal",+ b"unit U;\ninterface\nimplementation\n"+ b"procedure F(Items: TStringList);\nvar I: Integer;\nbegin\n"+ b" for I := 0 to Items.Count - 1 do\n"+ b" FindClose;\n"+ b"end;\nend.\n",+ [("io_in_loop", "filesystem")],+ "parenless bare FindClose is still a filesystem sink",+ ),+ (+ "pascal",+ b"unit U;\ninterface\nuses SysUtils, FireDAC.Comp.Client;\nimplementation\n"+ b"procedure F(Q: TFDQuery; Ids: TStringList);\nvar I: Integer;\nbegin\n"+ b" for I := 0 to Ids.Count - 1 do\n"+ b" begin\n"+ b" if I = 0 then Exit;\n"+ b" inherited;\n"+ b" Q.Open;\n"+ b" end;\n"+ b"end;\nend.\n",+ [("io_in_loop", "db")],+ "bare Exit/inherited in the same statement-wrapper shape do not false-fire",+ ),]diff --git a/tests/unit/ingestion/test_io_kind.py b/tests/unit/ingestion/test_io_kind.pyindex 47de85cca..2964c5ea5 100644--- a/tests/unit/ingestion/test_io_kind.py+++ b/tests/unit/ingestion/test_io_kind.py@@ -52,6 +52,14 @@ def test_io_kinds_are_the_frozen_canonical_set() -> None:# TS / Node filesystem / subprocess("node:fs", "filesystem"),("child_process", "subprocess"),+ # Object Pascal / Delphi (uses-clause unit names)+ ("firedac", "db"),+ ("adodb", "db"),+ ("idhttp", "network"),+ ("fphttpclient", "network"),+ # Progressive dotted prefix, the shape the Pascal import classifier+ # generates for a qualified unit (``FireDAC.Comp.Client``).+ ("system.net.httpclient", "network"),],)def test_known_libs_map_to_expected_io_kind(name: str, expected: str) -> None:@@ -72,3 +80,13 @@ def test_classification_is_case_and_whitespace_insensitive() -> None:assert classify_io_kind("HTTPX") == "network"assert classify_io_kind(" SQLAlchemy ") == "db"assert classify_io_kind("@Prisma/Client") == "db"+++def test_pascal_bare_system_prefix_is_not_seeded() -> None:+ """Delphi's ``System`` unit is in nearly every ``uses`` clause; a bare+ ``system`` or ``system.net`` entry would make almost every Pascal file+ read as a network/db import. Only the full qualified+ ``system.net.httpclient`` is seeded -- guard against a future addition+ seeding the short prefixes by accident."""+ assert classify_io_kind("system") is None+ assert classify_io_kind("system.net") is None