Skip to content

Resolve the validator's Fortran constants from definitions.py - #2042

Merged
sbryngelson merged 2 commits into
MFlowCode:masterfrom
sbryngelson:fix/validator-constant-fallbacks
Oct 13, 2026
Merged

sbryngelson merged 2 commits into
MFlowCode:masterfrom
sbryngelson:fix/validator-constant-fallbacks

Conversation

@sbryngelson

Copy link
Copy Markdown
Member

Follow-up to #2021, from a Codex review comment on it.

case_validator.py re-resolved six m_constants.fpp values with its own get_fortran_constants().get(name, default) fallbacks — a second copy of numbers definitions.py already resolves through _fc(). Two had drifted:

constant validator m_constants.fpp effect
num_ib_patches_max_namelist 50000 810000 too strict — rejects valid cases above 50000
num_patches_max 1000 10 too permissive — accepts 1000 IC patches into a 10-element Fortran array

The first is what Codex caught: raising the definitions.py fallback in #2021 did not actually make 810000 usable, because check_ibm() still capped num_ibs at 50000. The second turned up while checking the remaining four (num_ib_airfoils_max, num_stl_models_max, num_turb_sources_max, num_bc_patches_max, all correct), and is the worse direction: too strict gives a clear rejection, too permissive sails past validation into an array overrun.

No CI or development behaviour changes. These defaults are only reached when src/ is absent, as in the Homebrew layout they exist for; with the sources present get_fortran_constants() already returned the real values, so the validator was already using 810000 and 10. Only the packaged case is affected.

Changes

  • case_validator.py imports the resolved constants from definitions.py instead of re-defaulting, so there is one source of truth. get_fortran_constants is no longer needed there.
  • definitions.py gains NTS for num_turb_sources_max, the one constant the validator needed that was not already exposed.
  • The fallback test is widened to scan the whole toolchain for any get_fortran_constants().get(name, default) whose default disagrees with m_constants.fpp. TestFortranConstantFallbacks walked _fc() calls in definitions.py only, which is exactly why it passed over both of these — closing the class rather than the two instances.

Testing

Written test-first: the new TestFortranConstantGetFallbacks fails on master naming both stale fallbacks, and passes after the change.

  • pytest toolchain/mfc/params_tests/test_definitions.py — 22 passed
  • pytest toolchain/mfc/ -k "validator or case_valid" — 101 passed
  • ./mfc.sh precheck — all 7 stages pass

case_validator.py re-resolved six m_constants.fpp values with its own
get_fortran_constants().get(name, default) fallbacks, a second copy of
numbers definitions.py already resolves through _fc(). Two had drifted:

- num_ib_patches_max_namelist: 50000 vs 810000, too strict, so MFlowCode#2021
  raising the definitions.py fallback did not actually make 810000
  usable.
- num_patches_max: 1000 vs 10, too permissive, which is the worse
  direction -- it accepts 1000 IC patches into a 10-element Fortran
  array instead of rejecting them.

These defaults are only reached when src/ is absent, as in a Homebrew
layout, so with the sources present the validator already used the real
values: no CI or development behaviour changes here, only the packaged
case.

Import the resolved constants instead, adding NTS for the one the
validator needed that definitions.py did not already expose, and widen
the fallback test to scan the whole toolchain for any
get_fortran_constants().get(name, default) whose default disagrees with
m_constants.fpp. The existing test walked _fc() calls in definitions.py
only, which is why it passed over both of these.

Reported by Codex on MFlowCode#2021, which caught the num_ibs cap; the
num_patches_max one turned up while checking the rest.
Copilot AI balanced review requested due to automatic review settings October 13, 2026 02:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T02:41:59.657214Z 15006cd New commits
ℹ️ 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 71d2a36a7b

ℹ️ 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".

Comment thread toolchain/mfc/params/definitions.py Outdated
NAF = _fc("num_ib_airfoils_max", 5) # ib_airfoil (Fortran array bound)
NSM = _fc("num_stl_models_max", 10) # stl_models (Fortran array bound)
NPB = _fc("num_particle_clouds_max", 10) # particle_cloud (Fortran array bound)
NTS = _fc("num_turb_sources_max", 10) # turbulent source array bound (case_validator)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reuse NTS when registering turbulent sources

When src/ is unavailable and this fallback is revised, _load() still shadows the new module constant with its own _fc(..., 10) assignment at line 863, so the validator and the registered turb_pos/synth_L range retain independently edited limits and can drift again. Remove the local assignment and let _load() use this exported NTS so the change actually establishes one source of truth, as required by the repository's DRY guidance.

AGENTS.md reference: AGENTS.md:L18-L18

Useful? React with 👍 / 👎.

_load() resolved num_turb_sources_max a second time, so the NTS that
case_validator imports and the NTS that registers turb_pos/synth_L were
two independently editable assignments -- not the single source of truth
this PR is for. Use the module-level constant.

Guard it: no name may be resolved by more than one _fc() call. It was
the only duplicate; num_synth_shells_max stays local because nothing
outside _load() needs it.

Reported by Codex on this PR.
@sbryngelson
sbryngelson merged commit 7306d16 into MFlowCode:master Oct 13, 2026
19 checks passed
@github-actions

Copy link
Copy Markdown

Claude Code Review

Head SHA: 15006cd

Files changed:

  • 3
  • toolchain/mfc/case_validator.py
  • toolchain/mfc/params/definitions.py
  • toolchain/mfc/params_tests/test_definitions.py

Findings:
No issues found. Checked in step 4: case_validator.py, definitions.py, test_definitions.py. The imported constants (NIB, NAF, NSM, NTS, NB, NUM_PATCHES_MAX) all resolve at module level through _fc with the same names the old .get() calls used. NTS is moved to module level, so _load() still sees it.

@codecov

codecov Bot commented Oct 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.91%. Comparing base (62f658a) to head (15006cd).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2042   +/-   ##
=======================================
  Coverage   61.91%   61.91%           
=======================================
  Files          86       86           
  Lines       22848    22848           
  Branches     3360     3360           
=======================================
  Hits        14147    14147           
  Misses       6207     6207           
  Partials     2494     2494           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants