Repository navigation
feat: run every family of the boundary check through the command - #196
Conversation
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.
davinerdo
left a comment
There was a problem hiding this comment.
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.
-
docs/django-host.md:218 (E111): "
squashmigrationscopies theRunPythonfunction into the squashed migration" is wrong. Django 6.1.3'sdb/migrations/writer.py:164-171,186-192swaps the import of a function defined in a migration file for the comment "Functions from the following migrations need manual copying", andsquashmigrations.py:224-230prints "Manual porting required". The squashed file keeps a reference toapp.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:squashmigrationsleaves aRunPythonfunction 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." Theelidable=Trueparenthesis is right (operations/base.py:166, and a probe squash went from 2 operations to 1). -
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 (undermanage.py checkapps, only once Django has loaded the apps), adds no dependency, …". -
docs/django-host.md, four entries say more or less than the code does:
- E109 (216) puts
DEFAULT_DB_ALIASunder "meansdefaultwithout naming it". That reads as if any use of it is reported, but_check_calls._aliasjudges it only in the alias places, where it reads as"default"; a barex = DEFAULT_DB_ALIASgives nothing. Whole sentence: "neolith.E109: a database alias written as a literal or asDEFAULT_DB_ALIASnamesdefaultor another hosted app's alias, inusing=, the place ofusingin a function ofdjango.db.transaction,.using(...),.db_manager(...)orconnections[...]; or the code meansdefaultwithout naming it: a function ofdjango.db.transactioncalled with no alias or withNone,@atomicor@non_atomic_requestsused bare, ordjango.db.connection." - E112 (219) leaves out the unreadable directory that
_check_source.findingsalso 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_packageinclude enums. Use "one of its records or enums". - The contract package (204) says a package
__init__.pyabove a contract module lies "in an outer hosted app … or in no app"._check_package._packagetakes_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".
- E109 (216) puts
-
tests/test_check_end_to_end.py:481-503 and the report rules: a 103-mutant pass on
_check.pyand the rule modules against all 14tests/test_check*.pyleft these survivors:- Deduplicating on
message.msg(or id plus msg) instead of the printed line.from shop.services import Serviceon lines 1 and 2 ofdesk/views.pythen prints one E101 instead of two, and no test fails. Add that fixture and assert both lines. _orderwith the app dropped from the placeless key. Two stale entries,deskanddesk0, then sort by message, soapp desk0:comes beforeapp desk:. Add the pair._orderwith 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._readparses with no filename, so the test can't see the views family. Replacingif path not in classes:withif True:passes all 19 tests. Passfilename=pathin_read, stop excluding<unknown>, and giveevery_rowtwo class-based project views in one file. - Not blocking:
test_check_models.py:331-340,458-459now filter to E106/E107 rows and take the summary count fromlen(ran.findings). An extra E101/E102 there now passes; pinning the exact import rows would keep the old strength.
- Deduplicating on
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.
|
Thanks. Fixed at 6b53c8d; CI green on all five jobs.
|
davinerdo
left a comment
There was a problem hiding this comment.
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.
- 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._sourcecallsinspect.getsourcelines(model). On 3.12,inspect.findsourcerunsast.parseover the class's whole module (3.12inspect.py:1104; 3.13 reads__firstlineno__instead). So each model finding parses itsmodels.pyagain, outside the run's reading. The filter only looks at the immediate caller, and that caller isinspect, so the count can't see this. I re-rantest_every_family_reads_one_reading_of_the_sourceon 3.12.13 / Django 5.2.19, crediting a parse to neolith when any neolith frame is on the stack. All three came back asinspect: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 givensource. Fix: passsourceto_check_models.findings, and take a model's line fromsource.placed(...)'s tree, the way_check_views._class_linealready does for a class (it uses__firstlineno__on 3.13+ and the class statements otherwise). Then have_COUNTEDcount a parse whenever a neolith frame is anywhere on the stack, not just when neolith is the immediate caller, and keepassert "<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.
|
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.
|
davinerdo
left a comment
There was a problem hiding this comment.
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.
Summary
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 asinspectdoes, and on 3.12 the first class statement with the class's qualified name, whereinspect.findsourceparsed the module itself.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.tests/test_check_command.py,test_check_models.pyandtest_check_source.pyassumed 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, andtest_check_command.py's stand-ins take the model rules' newsourceargument.docs/django-host.mdgains an entry per finding id with what to do, each checked against its rule'sid=sites (E111 states whatsquashmigrationsdoes to aRunPythonfunction), and the contract package with its nested-app case;CHANGELOG.mdgets 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, undercheckappsonly once the apps load.Spec trace
No ID added or changed.
tests/test_check_end_to_end.pycites APP-66 to APP-71 and TRN-41.spec_trace --reporton 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
tests/test_check_end_to_end.pyalone: 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.db/migrations/writer.py:164-192andcore/management/commands/squashmigrations.py:218-230(a migration's function is left for manual porting); Django 5.2.19 / 6.1.3db/migrations/operations/base.py:166,apps/registry.py:251; CPython 3.12inspect.py:1039-1110(findsourceparses a class's module, first decorator's line) and 3.13's__firstlineno__read.Changelog (Added): written in
CHANGELOG.mdby this pull request, one entry for the whole boundary check.Part of #14.