Skip to content

test: Flow layers import downward only, with import-time budgets for low modules - #2427

Merged
abrichr merged 4 commits into
mainfrom
test/import-direction
Nov 21, 2026
Merged

abrichr merged 4 commits into
mainfrom
test/import-direction

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member

This is safety-net step A3 of the approved monorepo refactor plan (openadapt-internal#277, section 3.1). It adds a test and contract data, and changes no runtime code.

Layers

import_layers.json gains five layers, lowest first:

Layer Contains
Foundations ir, crypto, ed25519ph, private_file, at_rest, verification, check_level, runtime.effects.effect
Policy and formats approval_mode, policy, run_gate, deployment, runtime.authorization, qualification*, receipts and Seals
Runtime runtime, backends, backend, verifier, verify_run, verify
Products compiler, repair, generate, tx, form_tx, wrap, agent, jit, qualify, fleet, runner, connector
Surfaces __main__, cli_*, console, services

A module may import its own layer or a lower one.

The new test

tests/test_import_direction.py checks four things:

  • No new upward imports. An import of a higher layer fails, whether at module level or inside a function. The 78 upward edges that exist today are listed in import_direction_debt.json. A listed edge that disappears also fails, so the list only shrinks.
  • Layer patterns stay real. Every layer pattern must match at least one module.
  • Import-time budgets. A fresh interpreter imports each listed module, and the test counts the openadapt_flow modules loaded. Today's numbers are the budgets: openadapt_flow 51, ir 51, verification 51, crypto 52, receipt 52, offline_seal 52, public_seal 53, write_receipt 54. Going over budget fails. Going under prints the number to lower the budget to. The B-track PRs will lower these.
  • The checker itself. Unit tests cover lazy upward imports and the longest-pattern rule.

334 modules match no layer yet and are not checked. They get layers as code moves.

test_import_layers.py is unchanged, and all 2,218 of its tests pass.

Collisions

I ran the test on git merge-tree results of this branch with each of these PR heads: #2394, #2410, #2414, #2415, #2411, #2406, #2407, #2412, #2300, #2401, #2375, #2413, #2405 and #2403. All pass.

Exceptions:

Tested locally on Python 3.12 with ruff clean.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 2e552d5

First review of this PR. Author is GitHub abrichr, not Grok. Review only; I am not merging.

The layer assignment is sound for a first wave. check_level and runtime.effects.effect belong in foundations: they are closed types, not drivers. verification as the verdict and tier types also belongs in foundations. One cleanup, not blocking: openadapt_flow.verification is listed again under runtime. The longest-pattern rule ties on equal length and keeps the first match, so it is foundations today; please list it in only one layer so a later edit cannot change that by accident. Longer, more specific patterns correctly keep runtime.authorization and runtime.effects.effect below the rest of runtime, and tx.receipt / form_tx.receipt below tx / form_tx.

A subprocess sys.modules count is the right import-time measure: it starts a fresh interpreter and counts only openadapt_flow and its submodules. Note that openadapt_flow/__init__.py already imports ir, so the 51-module budgets for openadapt_flow and ir are mostly the package import itself. That is still a useful cap, and it will start to tell modules apart only after __init__.py gets thinner. Printing a lower count without raising the budget is the right ratchet.

Leaving 334 unlayered modules (of 763) unchecked is acceptable for this first step, and is documented. New upward edges among unlayered modules are not caught. A later pin of the unlayered count would stop that set from growing silently; I am not asking for it in this PR. The debt list of 78 upward edges can only shrink, which is the right rule.

I am not merging.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 6ad3e6a

Delta review after my APPROVE at 2e552d5fead38947b9fde4099b875e0cf5e74e36 (7059227516). Author is GitHub abrichr, not Grok. Review only; I am not merging.

The only unique change is one line: import_direction_debt.json is listed in packages/flow/public-artifacts.json next to the other import-layer inventories. The file is present at this head. That is the public-artifact registration the lint failure needed. The downward-import checks I approved earlier are unchanged.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

I merged main, which now includes B1 (#2451) and B2 (#2439), and set the import-time budgets to the new sizes:

Module Old budget New budget
openadapt_flow 51 3
openadapt_flow.crypto 52 4
openadapt_flow.ir 51 44
openadapt_flow.offline_seal 52 4
openadapt_flow.public_seal 53 5
openadapt_flow.receipt 52 45
openadapt_flow.verification 51 5
openadapt_flow.write_receipt 54 6

The new head is b9a2b0d1. test_import_direction.py and test_import_layers.py pass.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: b9a2b0d

Re-review at the current head (moved since 6ad3e6af, prior APPROVE 7060694971). The unique commit b9a2b0d10 is an import-time budget update after merging main (B2 and B1). No runtime code changes.

The budgets now match the post-B1/B2 sizes: openadapt_flow 51→3, crypto 52→4, ir 51→44, offline_seal 52→4, public_seal 53→5, receipt 52→45, verification 51→5, write_receipt 54→6. Those are tighter exact ceilings, not raises, and they agree with the counts published on #2451. import_direction_debt.json is unchanged in the unique commit, so the listed upward-edge set still only shrinks. A later import-count regression would still fail the exact-budget test.

No merge from me.

@abrichr
abrichr merged commit c787758 into main Nov 21, 2026
51 of 52 checks passed
@abrichr
abrichr deleted the test/import-direction branch November 21, 2026 12:30
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.

1 participant