Skip to content

refactor(inventory): move source collection and command planning into inventory_sources - #1338

Draft
gcs8 wants to merge 2 commits into
mainfrom
refactor/inventory-sources
Draft

gcs8 wants to merge 2 commits into
mainfrom
refactor/inventory-sources

Conversation

@gcs8

@gcs8 gcs8 commented Nov 17, 2026

Copy link
Copy Markdown
Owner

What moved

The source collection and command planning block of InventoryService moves from app/services/inventory.py into the new module app/services/inventory_sources.py:

  • the 32 methods from _summarize_ssh_failures to _collect_inventory_source_bundle (1,172 lines), into InventorySourceCollectionMixin;
  • the two source DTOs SourcePublication and InventorySourceBundle;
  • the twelve module constants the block reads: SSH_FAILURE_CONTEXTS_BY_COMMAND, SSH_FAILURE_CONTEXTS_BY_PREFIX, MPRUTIL_UNIT_COMMAND_PATTERN, MPRUTIL_UNNUMBERED_READ_PATTERN, MPRUTIL_SUBCOMMAND_LABELS, DEFAULT_SSH_FAILURE_CONTEXT, SSH_COMMAND_FAILURE_REASON, SCALE_CONFIGURED_SG_SES_FAILURE_REGEX, SSH_LOGIN_FAILURE_REASONS, SSH_PARTIAL_INTERNAL_ERROR_STATUS, LINUX_NVME_LIST_SUBSYS_COMMAND, LINUX_ENCLOSURE_SYSFS_MAP_COMMAND.

Every moved line is unchanged apart from leading whitespace. Source TTLs, cache admission, publication, locks and generations stay on InventoryService.

How the old names keep working

  • InventoryService inherits InventorySourceCollectionMixin. The methods stay methods of the same instance and class, with the same kind (instance, class or static method) and signature. self. and cls. lookups stay late-bound, so a replacement on the instance or on the class still reaches moved code, and the collector state attributes stay on the service instance.
  • app.services.inventory re-exports every moved constant and DTO by name; they are the same objects.
  • The new module does not import app.services.inventory. That module calls inventory_sources.bind_facade(...) at the end of its import. _drain_inventory_worker, _certificate_verify_code_label and _public_source_failure_message stay in inventory.py; the moved code calls them through three one-line wrappers that look them up on the inventory module at each call, so a replacement there still takes effect. The literal InventoryService. reads in one moved static method read the class bound by bind_facade; nothing subclasses InventoryService.
  • The moved code logs through the same logger object, logging.getLogger("app.services.inventory").
  • Imports that only the moved code used stay imported in inventory.py, marked noqa: F401, so those names stay importable from it.

Behaviour

Unchanged. The only visible difference is the file name inside logged stack frames of the internal-error log line, which now reads inventory_sources.py:<line> for frames in moved code. Message text, category, level and logger name do not change. One existing assertion that pinned inventory.py in those frames is widened in one line to accept either file name; it still requires a frame (tests/test_inventory_status_error_text.py:673).

Tests

New class InventorySourceCollectionModuleTests in tests/test_inventory.py, 8 tests. All 8 fail on the base commit because the new module does not exist (1 failure, 7 errors). They check that the new module imports without the inventory module, that every moved method and name is reachable where it was, that replacements made on the instance, on the class and on the inventory module still reach moved code (each with a control case), that moved code logs through the inventory logger, and that the mixin docstring lists exactly what the mixin reads on its host.

Local runs, all OK, 0 failed:

  • python -m unittest tests.test_inventory: 617 run.
  • The other twelve modules that reach the moved names by private name, plus every other test module that names a moved name, the source-reading sweeps and the registration checks (tests.test_account_bootstrap tests.test_background_refresh_busy_routes tests.test_background_refresh_deadlines tests.test_bounded_parser_work tests.test_combined_shelf_upgrade tests.test_core_counter_markers tests.test_core_fabric_legacy_controller tests.test_disk_retention_accounting tests.test_history_service tests.test_inventory_status_error_text tests.test_platform_parity_fixtures tests.test_route_contracts tests.test_sas_fabric tests.test_ssh_connection_keep tests.test_ssh_diagnostic_safety tests.test_ssh_failure_contexts tests.test_truenas_middleware_limits tests.test_ses_unknown_occupancy_consumers tests.test_public_doc_privacy tests.test_source_shape tests.test_unittest_shards tests.test_unittest_identities tests.test_dev_check tests.test_ci_contract tests.test_changelog_fragments): 1,403 run.
  • ruff check on the touched files and git diff --check: clean.

Size

app/services/inventory.py goes from 19,284 to 17,929 lines; its ceiling in tests/test_source_shape.py is lowered from 19750 to 18250. The new module has 1,504 lines.

Refs #1328

gcs8 added 2 commits November 17, 2026 00:08
… inventory_sources

Move the 32 source collection and command planning methods of
InventoryService, the two source DTOs and the twelve module constants
they read into app/services/inventory_sources.py, as
InventorySourceCollectionMixin. InventoryService inherits the mixin, so
the methods stay methods of the same instance and class: self and cls
lookups stay late-bound and the collector state stays on the service.
The moved lines are unchanged.

app.services.inventory keeps every name it had: the constants and DTOs
are re-exported as the same objects. The new module does not import the
inventory module; the inventory module binds itself at the end of its
import, and the three leaf helpers that stay there are looked up on it
at each call. The moved code logs through the same logger object.

One existing assertion is widened to accept the new file name in logged
stack frames. The inventory.py size ceiling is lowered to 18250.

No behaviour change.

Refs #1328
@github-actions github-actions Bot added the internal Refactor, chore, test or CI change with no operator-visible behavior label Nov 17, 2026
@gcs8

gcs8 commented Nov 17, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T05:41:08.772578Z 8ea258d Manual request
🔒 Security Review ✅ Completed 2026-11-17T05:45:09.113226Z 8ea258d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 8ea258dd9d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 8ea258dd9d

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Refactor, chore, test or CI change with no operator-visible behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant