Skip to content

feat: run every family of the boundary check through the command - #196

Merged
vignzpie merged 10 commits into
release/0.1.0a4from
feat/boundary-wire
Nov 26, 2026
Merged

vignzpie merged 10 commits into
release/0.1.0a4from
feat/boundary-wire

Conversation

@vignzpie

@vignzpie vignzpie commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Task 7 of Roadmap step 7: boundary check #14, the last of step 7: phase 5 of the check runs every family over one reading of the hosted apps' source, so each file is parsed once: the model rules, reading itself (E112, W104, W101), and the import (E101 to E105, W105), call (E108 to E111, W103) and view (W102) rules of tasks 4 to 6. The rules on models and views now place a class from that reading instead of parsing its file again: views through Source.placed, which the call rules share; models, and the model lines E105 and W105 take, through _check_models.place_of, which reads __firstlineno__ on 3.13 and later as inspect does, and on 3.12 the first class statement with the class's qualified name, where inspect.findsource parsed the module itself.
  • New tests/test_check_end_to_end.py, under both entries in fresh processes: one row of each family for a report-only app; one project with every row of ADR 0030's findings table at once (each once, a duplicate on one line printed once, one import repeated on two lines printed on each, sorted with one line's findings by id, two stale entries by app, exact summary, the same stdout under both entries, no database file); every failing app listed (status 0); a listed app with warnings only (E113); each file parsed once across all families, counting every parse made while any frame of neolith's is on the stack, a nameless one included, with two class-based project views in one file; and the contract-package edges the guide states.
  • The earlier command tests in tests/test_check_command.py, test_check_models.py and test_check_source.py assumed only their own family ran: their fixtures keep their one finding, or their assertions name the other family's rows exactly where they are the point; test_check_views.py's parse probe counts where the run now reads, and test_check_command.py's stand-ins take the model rules' new source argument.
  • docs/django-host.md gains an entry per finding id with what to do, each checked against its rule's id= sites (E111 states what squashmigrations does to a RunPython function), and the contract package with its nested-app case; CHANGELOG.md gets one Added entry for the whole check, replacing task 2's, and it and the README say the command refuses a connection while it runs, under checkapps only once the apps load.

Spec trace

No ID added or changed. tests/test_check_end_to_end.py cites APP-66 to APP-71 and TRN-41. spec_trace --report on CI at ed54ca6: 252 requirements, 240 covered by passing tests, 5 marked not tested, 0 problems; APP-66 to APP-71 covered by 64, 15, 59, 32, 9 and 18 citing tests.

How it was verified

  • Mutation on 3.13 / Django 6.1 against tests/test_check_end_to_end.py alone: dropping each family, renaming each of the 17 ids, deduplicating on the message instead of the line, dropping the app or the id from _order's keys, and the views rule parsing on its own, all killed. The parse-count test, run on 3.12.13 / Django 5.2.19 against the previous head's code, fails on the model rule's parses.
  • Source read: Django 6.1.3 db/migrations/writer.py:164-192 and core/management/commands/squashmigrations.py:218-230 (a migration's function is left for manual porting); Django 5.2.19 / 6.1.3 db/migrations/operations/base.py:166, apps/registry.py:251; CPython 3.12 inspect.py:1039-1110 (findsource parses a class's module, first decorator's line) and 3.13's __firstlineno__ read.
  • CI at ed54ca6: lint, types and all four test jobs pass (11,712 passed, 4 skipped on 3.12 / Django 5.2; 11,713 passed, 3 skipped on 3.15 / Django 6.1).

Changelog (Added): written in CHANGELOG.md by this pull request, one entry for the whole boundary check.

Part of #14.

One row of each family under both entries for a report-only app, and one
project with every row of ADR 0030's findings table at once. The earlier
command tests keep their one finding now that every family runs.
Phase 5 runs every family over one reading of the hosted apps' source.
@vignzpie vignzpie added this to the 0.1.0a4 milestone Nov 26, 2026
@vignzpie vignzpie mentioned this pull request Nov 26, 2026
7 tasks done
@vignzpie
vignzpie marked this pull request as ready for review November 26, 2026 06:17
@vignzpie
vignzpie requested a review from davinerdo November 26, 2026 06:17

@davinerdo davinerdo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Changes needed. The wiring holds. The guide's E111 entry misstates what squashmigrations does, the changelog claims more than the guide allows, and three report rules the end-to-end test is meant to pin can still be mutated without failing.

  1. docs/django-host.md:218 (E111): "squashmigrations copies the RunPython function into the squashed migration" is wrong. Django 6.1.3's db/migrations/writer.py:164-171,186-192 swaps the import of a function defined in a migration file for the comment "Functions from the following migrations need manual copying", and squashmigrations.py:224-230 prints "Manual porting required". The squashed file keeps a reference to app.migrations.0002_data.fwd, which doesn't compile until someone ports the function by hand. A reader who trusts this sentence will expect the squash to carry the call over, not to need a hand edit. Fix: "Squashing alone does not remove it: squashmigrations leaves a RunPython function defined in a migration file where it is, refers to it from the squashed migration and asks for it to be copied in by hand ("Manual porting required"), so the call stays in the app's migrations." The elidable=True parenthesis is right (operations/base.py:166, and a probe squash went from 2 operations to 1).

  2. CHANGELOG.md:11: "It opens no database connection" contradicts the guide's own No database paragraph. Under manage.py checkapps, Django loads the apps before the command starts, so a query made while they load is not guarded. This entry becomes the release notes. Fix: "It opens no database connection itself and refuses any while it runs (under manage.py checkapps, only once Django has loaded the apps), adds no dependency, …".

  3. docs/django-host.md, four entries say more or less than the code does:

    • E109 (216) puts DEFAULT_DB_ALIAS under "means default without naming it". That reads as if any use of it is reported, but _check_calls._alias judges it only in the alias places, where it reads as "default"; a bare x = DEFAULT_DB_ALIAS gives nothing. Whole sentence: "neolith.E109: a database alias written as a literal or as DEFAULT_DB_ALIAS names default or another hosted app's alias, in using=, the place of using in a function of django.db.transaction, .using(...), .db_manager(...) or connections[...]; or the code means default without naming it: a function of django.db.transaction called with no alias or with None, @atomic or @non_atomic_requests used bare, or django.db.connection."
    • E112 (219) leaves out the unreadable directory that _check_source.findings also reports (directory …: cannot be read). Use "a file or directory of a hosted app cannot be read, or a file cannot be compiled".
    • E105 (212) says "a contract the app provides or one of its records", but line 204 and _check_package include enums. Use "one of its records or enums".
    • The contract package (204) says a package __init__.py above a contract module lies "in an outer hosted app … or in no app". _check_package._package takes _holder(package), which is any installed app, so an outer undeclared app is a third case. Use "in an outer installed app when the app is nested in one, or in no app; one outside every hosted app is code in no hosted app, an undeclared app's included, and chains go through it".
  4. tests/test_check_end_to_end.py:481-503 and the report rules: a 103-mutant pass on _check.py and the rule modules against all 14 tests/test_check*.py left these survivors:

    • Deduplicating on message.msg (or id plus msg) instead of the printed line. from shop.services import Service on lines 1 and 2 of desk/views.py then prints one E101 instead of two, and no test fails. Add that fixture and assert both lines.
    • _order with the app dropped from the placeless key. Two stale entries, desk and desk0, then sort by message, so app desk0: comes before app desk:. Add the pair.
    • _order with the id dropped from the located key. This needs two findings on one path and line whose id order differs from their message order.
    • The parse-count test drops <unknown>, and _check_views._read parses with no filename, so the test can't see the views family. Replacing if path not in classes: with if True: passes all 19 tests. Pass filename=path in _read, stop excluding <unknown>, and give every_row two class-based project views in one file.
    • Not blocking: test_check_models.py:331-340,458-459 now filter to E106/E107 rows and take the summary count from len(ran.findings). An extra E101/E102 there now passes; pinning the exact import rows would keep the old strength.

Direction: All three docs findings come from restating a rule from memory instead of from its source of truth. The changelog and E109/E112/E105 drifted from the code they summarise, and the squash sentence described Django without running it. Before the next push, check each guide entry against the docstring and the id= sites of its rule. For any sentence about what another tool does (squashmigrations, checkapps load order), run the tool on a fixture. For the tests, run one mutant of each key and branch of _report/_order against the end-to-end file alone; the body's mutant list covered families and ids, not the report's own rules.

Checked: the integration under both entries (a URLconf that queries or raises is refused in phase 4; five family orders × three PYTHONHASHSEEDs give identical output; 704 files in 1.4 s, each ast.parsed once), each of the body's named mutants (all killed except a fresh Source for views, which is equivalent), Django 6.1.3's writer and squash code, and the Packwerk quote against the retrospective.

…s file

The rule on views parsed a project file of its own, with no file name, so
a URLconf that W103 had already read was parsed twice. It now takes the
tree from Source.placed, which the call rules use too. The end-to-end
test counts every parse, a nameless one included, and pins the report's
rules: a repeated line, stale entries ordered by app, and one line's
findings ordered by id. The model tests pin their import rows exactly.
E111 says a squash leaves a RunPython function for copying by hand.
E109, E112, E105 and the contract package's outer apps say what the
code reports. The changelog and README say the command refuses a
connection while it runs, and under checkapps only once the apps load.
… not

On Python 3.12, inspect.findsource parses a class's module with no file
name, so the parse count saw three nameless parses that are not the
check's. The count now keeps the parses made from neolith's modules, and
still refuses a nameless one of those.
@vignzpie

vignzpie commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

Thanks. Fixed at 6b53c8d; CI green on all five jobs.

  1. E111 squash: the sentence now says squashmigrations leaves the function where it is, refers to it from the squashed migration and asks for it to be copied by hand ("Manual porting required"), as writer.py:164-192 and squashmigrations.py:218-230 in 6.1.3 do.
  2. Changelog: "opens no database connection itself and refuses any while it runs (under manage.py checkapps, only once Django has loaded the apps)". README.md:51 made the same claim and now says the same.
  3. Guide entries: E109, E112, E105 and the contract package's outer installed app take your wording, each checked against its rule's id= sites; E105's changelog wording and _check_imports' docstring gained "enum" too, and the changelog's E112 the directory.
  4. Report rules: every_row now has an import repeated on lines 3 and 4, stale bare and bare0, and command_scope("shop"), connections["default"] on one line (E109 before E110, the reverse of their messages); the three mutants fail against the end-to-end file alone.
  5. Parse count: with filename=path and two class-based views in urls.py, the count showed urls.py: 2, since W103 had already read it. So the views rule now takes the tree from the run's reading (Source.placed, shared with the call rules), not a parse of its own. The count no longer drops <unknown>; it keeps only parses made from neolith's modules, since on 3.12 CI saw three nameless parses that are not neolith's (3.12's inspect.findsource parses a class's module that way; CI at bf243a8).
  6. Not blocking, done: _model_rows now takes the exact (place, id) import rows each model test expects.

@vignzpie
vignzpie requested a review from davinerdo November 26, 2026 07:33

@davinerdo davinerdo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Changes needed. All five round-1 points are fixed and I checked each one. One problem is left: on Python 3.12 the model rule still parses its own files a second time. This round's parse-count filter hides that, and the description, which becomes the squash commit message, says the opposite.

  1. tests/test_check_end_to_end.py:492 and src/neolith/_check_models.py:242-243: on 3.12, the three nameless parses that the new caller filter drops are made by neolith. _check_models._source calls inspect.getsourcelines(model). On 3.12, inspect.findsource runs ast.parse over the class's whole module (3.12 inspect.py:1104; 3.13 reads __firstlineno__ instead). So each model finding parses its models.py again, outside the run's reading. The filter only looks at the immediate caller, and that caller is inspect, so the count can't see this. I re-ran test_every_family_reads_one_reading_of_the_source on 3.12.13 / Django 5.2.19, crediting a parse to neolith when any neolith frame is on the stack. All three came back as inspect:findsource <- inspect:getsourcelines <- neolith._check_models:_source. That contradicts the summary ("every family over one reading … so each file is parsed once: the model rules, …"), "counting every parse neolith makes", the test's comment that these parses are "other code's", and your reply ("not neolith's"). On 3.12, the version CI uses as its floor, the model rules are the one family that doesn't share the reading. findings(configs) is never given source. Fix: pass source to _check_models.findings, and take a model's line from source.placed(...)'s tree, the way _check_views._class_line already does for a class (it uses __firstlineno__ on 3.13+ and the class statements otherwise). Then have _COUNTED count a parse whenever a neolith frame is anywhere on the stack, not just when neolith is the immediate caller, and keep assert "<unknown>" not in counts. With that walk the current head fails on 3.12, so the test would pin this fix.

Direction: This is the second round in which the parse count had an exclusion that hid a family parsing on its own. Round 1 dropped <unknown>; this round drops parses whose immediate caller isn't neolith. "Parsed once" is a claim about what the run causes, so the counter has to attribute a parse by the whole stack, not by the frame that happens to call ast.parse. Before you filter anything out of a count like this, print the full stack of each excluded call. Run it on every interpreter CI uses, because 3.12's inspect and 3.13's take different paths.

Checked: each round-1 fix against its source (E109/E112/E105/contract-package wording against _check_calls._alias, _check_source.findings and _check_package; the changelog and README against the guide's No database paragraph). Source.placed matches the old _first_party/_read behaviour for sourceless and unreadable files. The changed test files pass on 3.13 / Django 6.1.3. A 7-mutant pass against test_check_end_to_end.py alone killed _order without the app, _order without the id, dedupe on msg, the views rule parsing on its own (with and without a file name) and placed bypassing the cache. if path not in classes → if True survives, but it is now equivalent, because Source.read caches.

…file

On Python 3.12, inspect.getsourcelines finds a class by parsing its whole
module, so each model finding, and each model line E105 and W105 take,
parsed its models.py again outside the run's reading. place_of now takes
__firstlineno__ on 3.13 and later, as inspect does, and on 3.12 the first
class statement with the class's qualified name from the run's tree. The
parse count credits a parse to neolith when any of its frames is on the
stack, so the nameless parse inspect makes is counted and refused.
@vignzpie

Copy link
Copy Markdown
Collaborator Author

Right: those three parses were neolith's, and my reply and the test's comment said otherwise. Fixed at ed54ca6; CI green on all five jobs.

  1. Model rule on 3.12: _check_models.findings now takes source, and place_of (which also gives E105's and W105's model lines) reads __firstlineno__ on 3.13 and later, and on 3.12 the first class statement with the class's qualified name from the run's tree, as inspect.findsource finds it. It no longer calls getsourcelines; the class walk moved to _check_source.class_statements, shared with the views rule.
  2. The count: _COUNTED now credits a parse when any neolith frame is on the stack, and keeps assert "<unknown>" not in counts. Run on 3.12.13 / Django 5.2.19, it fails on the previous head's code and passes at ed54ca6; the check test files pass on 3.12 and 3.13 locally.

@vignzpie
vignzpie requested a review from davinerdo November 26, 2026 08:00

@davinerdo davinerdo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve. Since 6b53c8d the model rule places a model from the run's one reading of its file, and the parse count now attributes each parse by its whole stack, so the last open point is fixed.

Checked: on 3.12.13 / Django 5.2.19, test_every_family_reads_one_reading_of_the_source fails against 6b53c8d's src ('<unknown>': 3) and passes at ed54ca6, so the test pins the fix. The check test files pass on 3.12 (347) and 3.13. place_of matches the old inspect.getsourcelines line and file on 3.12 and 3.13 for a plain model, a model with multi-line stacked decorators, a class defined twice under if/else, a model inside a function, a model nested in a plain class, one in a package's __init__, one in a submodule, and one in an unhosted module through Meta.app_label. On 3.12 the model rule now reads first, and the file records it puts in the shared cache are the same path, module and package as the app walk's, so no later family gets a different record. The description matches the head, and CI is green on all five jobs.

@vignzpie
vignzpie merged commit 77fa4a0 into release/0.1.0a4 Nov 26, 2026
5 checks passed
@vignzpie
vignzpie deleted the feat/boundary-wire branch November 26, 2026 08:06
@vignzpie vignzpie mentioned this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants