Skip to content

feat(python): read and enforce the reference facet in the Python loader - #698

Merged
dmealing merged 10 commits into
mainfrom
fm/mo-140-w1-b1-py
Dec 3, 2026
Merged

dmealing merged 10 commits into
mainfrom
fm/mo-140-w1-b1-py

Conversation

@dmealing

@dmealing dmealing commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • The Python loader reads the reference facet (ref on a type: "attr" entry in a provider definition) and carries it to AttrSchema.ref. resolve_references takes an optional registry and resolves facet attributes through a new SymbolTable (loader/symbol_table.py). Unresolved, wrong-kind, and cross-system values are refused (ERR_REF_UNRESOLVED, ERR_REF_WRONG_KIND). Canonical values are the path the lookup walked; values that would not re-resolve to the same target are kept as written.
  • ReferenceDescriptor becomes (attr, facet), with target_type, error_code, target_sub_types, and field_path moved onto ReferenceFacet. SymbolTable moves from registered_validation to loader/symbol_table.py. The registry manifest writes ref only on attributes that declare one. A provider's own non-ErrorCode code keeps its spelling in MetaError.provider_code.
  • Adds tests/unit/test_reference_facet.py and the changelog.d/python-reference-facet.md entry. spec/metamodel-definitions.md is updated to match. No definition file uses the facet yet, so no generated output changes.
Validation

Risk Assessment

✅ Low: approval carried from an earlier review

Testing

Broad regression came from the configured test command scripts/ci-local.sh --affected --strict-toolchains, which passed at this target commit. Here I drove two scenarios. The valid loader code is accepted, and the trailing-newline code is refused with a ValueError. The 48 focused reference-facet unit tests pass. No source changed in this turn, so the broad run was not repeated. No background processes were started.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Valid errorCode loader code is accepted by the Python reference facet reader (local Python call, synthetic input 'ERR_X') ✅ pass live PYTHONPATH=src python3 -c ... _to_reference_facet returned ReferenceFacet(error_code='ERR_X')
Trailing-newline errorCode is refused by the Python reader (adversarial, 'ERR_X\n') ✅ pass live Same command: 'w has an invalid reference facet: errorCode must be a loader code (ERR_ and upper case).'
Reference facet unit suite (refusal and acceptance matrix) ✅ pass live pytest tests/unit/test_reference_facet.py: 48 passed

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

♻️ **Review** - review carried from run 01M8XQ5PD53YN9BK42T2MK7S5Y at 348c635 (no new branch work since the approved head; the base changes merged since touch no reviewed code)

♻️ review carried from run 01M8XQ5PD53YN9BK42T2MK7S5Y at 348c635 (no new branch work since the approved head; the base changes merged since touch no reviewed code)

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Valid errorCode loader code is accepted by the Python reference facet reader (local Python call, synthetic input 'ERR_X') ✅ pass live PYTHONPATH=src python3 -c ... _to_reference_facet returned ReferenceFacet(error_code='ERR_X')
Trailing-newline errorCode is refused by the Python reader (adversarial, 'ERR_X\n') ✅ pass live Same command: 'w has an invalid reference facet: errorCode must be a loader code (ERR_ and upper case).'
Reference facet unit suite (refusal and acceptance matrix) ✅ pass live pytest tests/unit/test_reference_facet.py: 48 passed
  • scripts/ci-local.sh --affected --strict-toolchains
  • cd server/python && python3 -m pytest tests/unit/test_reference_facet.py -q (48 passed)
  • PYTHONPATH=src python3 -c importing metaobjects.spec_metamodel._to_reference_facet and calling it with errorCode 'ERR_X' (accepted) and 'ERR_X\n' (refused)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

The spec reader validates `ref` on an attr entry and carries it to AttrSchema.ref; the
registry-derived walk enforces it through a kind-typed symbol table (System.child,
pkg::System.child, bare values found in the referrer's containers first, untyped lookup
only for the wrong-kind code); the reference pass binds facet attributes to the walked
path and keeps a value as written when its canonical spelling would not reload to the
same target; the registry manifest writes `ref` only when present. Provider codes keep
their spelling in MetaError.provider_code. Mirrors the TypeScript and C# loaders; no
definition file uses the facet, so no registry, manifest or generated output changes.
… code

Review finding from the first gate run: both still formatted MetaError.code, so a
facet's own code (code ERR_UNKNOWN plus provider_code) printed as ERR_UNKNOWN.
# Conflicts:
#	spec/metamodel-definitions.md
# Conflicts:
#	spec/metamodel-definitions.md
@dmealing
dmealing merged commit 877fed0 into main Dec 3, 2026
11 checks passed
@dmealing
dmealing deleted the fm/mo-140-w1-b1-py branch December 3, 2026 12:23
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