Skip to content

fix: ignore stray files when resolving latest schema version#854

Open
ehennestad wants to merge 1 commit into
mainfrom
fix-latest-schema-version-stray-files
Open

fix: ignore stray files when resolving latest schema version#854
ehennestad wants to merge 1 commit into
mainfrom
fix-latest-schema-version-stray-files

Conversation

@ehennestad

Copy link
Copy Markdown
Collaborator

Motivation

Problem — On macOS, Finder silently drops a .DS_Store file into MatNWB's nwb-schema/ folder as soon as the folder is browsed. Any such stray entry makes generateCore() (called without a version argument, i.e. "use latest") silently resolve to an old schema version — 2.1.0 instead of 2.10.0 — so the user unknowingly generates classes for a years-old schema. No error or warning is raised.

Solution — When determining the latest schema version, only folder entries whose name is an exact major.minor.patch version number are considered, so stray files can no longer influence the result.

What changed

  • matnwb.common.findLatestSchemaVersion (used by generateCore to resolve the default schema version) now ignores any entry in nwb-schema/ that is not named as an exact version number.
  • Behavior with a clean nwb-schema/ folder is unchanged.
Implementation notes

Previously only . and .. were excluded from the directory listing. For any other non-version entry, sscanf(name, '%d.%d.%d') returned empty, silently dropping that entry from the version-comparison matrix while it remained in the name list — an off-by-one that made the max-version index point at the wrong name. Entries are now filtered with the anchored pattern ^\d+\.\d+\.\d+$ before parsing.

Examples

With a stray (hidden) file present in nwb-schema/:

strayFile = fullfile(misc.getMatnwbDir(), 'nwb-schema', '.stray_test_file');
fclose(fopen(strayFile, 'w'));
latestVersion = matnwb.common.findLatestSchemaVersion()
delete(strayFile)

Before (silently wrong version):

latestVersion =

    '2.1.0'

After:

latestVersion =

    '2.10.0'

How to test

Run the snippet above on this branch — the result is '2.10.0' regardless of stray files in nwb-schema/. On macOS, simply browsing nwb-schema/ in Finder (which creates .DS_Store) and then calling generateCore() also exercises the fix.

Checklist

  • Have you ensured the PR description clearly describes the problem and solutions?
  • Have you checked to ensure that there aren't other open or previously closed Pull Requests for the same change?
  • If this PR fixes an issue, is the first line of the PR description fix #XX where XX is the issue number?

🤖 Generated with Claude Code

Stray entries in nwb-schema/ (e.g. .DS_Store created by macOS Finder)
shifted the version-comparison matrix off by one, making
findLatestSchemaVersion silently return an old version (2.1.0 instead
of 2.10.0). Filter directory entries to exact major.minor.patch names
before comparing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ehennestad ehennestad requested a review from bendichter July 6, 2026 22:28
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.45%. Comparing base (2ee6a6b) to head (5724f9c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #854   +/-   ##
=======================================
  Coverage   95.45%   95.45%           
=======================================
  Files         228      228           
  Lines        8080     8082    +2     
=======================================
+ Hits         7713     7715    +2     
  Misses        367      367           

☔ 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.

@ehennestad ehennestad enabled auto-merge July 6, 2026 23:05
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