Skip to content

fix(api-inventory): preserve dataclass constructor semantics in static module scan #2023

Description

@seonghobae

Finding

The static public-API inventory repair on #1717 correctly stopped executing discovered module names, but its AST dataclass projection no longer matches the runtime constructor contract that the inventory is supposed to describe.

Current #1717 head before this repair: 4493f58ac02ba16e08e2d8dc6b0e2ef2b2407db8.

tools/inventory_public_api.py::_ast_class_params() currently treats every public annotated dataclass field as a constructor parameter and drops every underscore-prefixed field. That is not how dataclass-generated __init__ works:

  • field(init=False) is not a constructor parameter even when the field name is public;
  • InitVar participates in the generated constructor, including an underscore-prefixed InitVar;
  • ClassVar does not participate in the generated constructor.

A concrete repository-owned regression is fast_mlsirm.scoring.rag.RAGPerturbationAnchor. Its canonical runtime-derived inventory row in docs/api/inventory-20260917.csv is:

anchor_id, baseline_request_fingerprint, perturbed_request_fingerprint, perturbation_specification_fingerprint, perturbation_run_fingerprint, perturbation_kind, _anchor_token=None

The source class also has public derived fields expected_construct, expected_direction, and construct_basis declared with field(init=False). The current static projection would include those three false constructor parameters and omit _anchor_token, changing the governed API inventory solely because the scanner implementation changed.

Required repair

Keep repository module discovery static. Do not restore importlib.import_module(modname), suppress Semgrep, or weaken SAST policy.

Acceptance:

  • add a public regression against the real RAGPerturbationAnchor source;
  • static dataclass projection excludes field(init=False) and ClassVar fields;
  • it includes actual constructor InitVar fields even when their names begin with _;
  • existing default/default_factory rendering remains intact;
  • exact-head inventory/CI/SAST evidence is reacquired after the causal fix.

This is API-governance tooling, not psychometric arithmetic; no scientific estimator behavior should change.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions