test: add HTML-fixture regression scaffolding for brittle compat parsing#70
Merged
Conversation
Add fast, network-free characterization tests under tests/unit/ that exercise the brittle version-sensitive parsers in py_moodle.compat against hand-authored HTML fixture files, so a future Moodle-markup change or an accidental selector regression is caught by make test-unit. Covers extract_login_token, extract_sesskey (present and absent), extract_folder_filenames (across both legacy and modern strategies), and extract_version_from_dashboard (modern, legacy, and absent-marker cases), plus a legacy-vs-modern strategy-selection contrast via get_strategy_for_version. All embedded tokens, sesskeys and versions are obviously-fake placeholders with provenance comments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds fast, network-free characterization tests under
tests/unit/that exercise the version-sensitive HTML parsers inpy_moodle.compatagainst hand-authored HTML fixture files. Previously these fragile parsers (login token, sesskey, folder file listing, dashboard version) had no coverage in the fastmake test-unitgate — the only compat tests live intests/test_compat.py, which is auto-markedintegrationand skipped by default. Now an accidental selector/regex regression, or a future Moodle-markup change, is caught by the fast unit layer. Test-only: no source files changed.Linked issue
Closes #68
Specification (SDD)
Add a fixtures directory
tests/unit/fixtures/html/with small, representative, fake-secret HTML documents (login page with alogintokenhidden input, a page embedding theM.cfgsesskey, a folder view listingpluginfile.phpfilenames, and modern/legacy/no-version dashboards), each with a provenance comment. Addtests/unit/test_html_fixtures.pyloading those fixtures viapathlibrelative to__file__and asserting the expected extraction forextract_login_token,extract_sesskey(present and absent),extract_folder_filenames, andextract_version_from_dashboard(modern, legacy, and absent-marker), plus at least one legacy-vs-modern contrast. Uses the existing public compat surface read-only:DEFAULT_COMPATIBILITY/LEGACY_COMPATIBILITYstrategy methods and the module-levelextract_version_from_dashboard/get_strategy_for_version. No behavior change; this is regression/characterization coverage.TDD evidence
Red-green with the source held read-only, so the natural "red" is the fixtures not existing yet.
tests/unit/test_html_fixtures.pyfirst and ran it before creating any fixture:"sesskey":"([^\"]+)", which the parser matched first (returning([^instead of the real value). Fixed the comment to not embed a matching literal:Non-vacuous proof (one-off, NOT committed): renaming the login-token attribute in the fixture (
name="logintoken"->name="logintoken_RENAMED", simulating a Moodle markup change) makes the parser return''and the test fail, then reverting restores green:Test plan
pytest tests/unitgreen (192 passed).Commands run:
Backwards compatibility
Fully backwards compatible. Test-only change: adds new files under
tests/unit/, touches no source and no existing tests, uses only the existing public/read-only compat surface.Documentation
None. Per the issue, the contributor-facing "how brittle-fixture tests work" note is owned by the sibling test-layer-docs issue;
docs/development.mdis intentionally untouched.docs/cli.mdis unaffected (no CLI options changed).Notes for reviewers
tests/unit/test_html_fixtures.pytests/unit/fixtures/html/login_page_modern.htmltests/unit/fixtures/html/sesskey_config_modern.htmltests/unit/fixtures/html/folder_view_modern.htmltests/unit/fixtures/html/dashboard_modern.htmltests/unit/fixtures/html/dashboard_legacy.htmltests/unit/fixtures/html/dashboard_no_version.htmlsrc/py_moodle/compat.py,tests/test_compat.py,tests/conftest.py, anddocs/*are all untouched.extract_folder_filenamestakes aBeautifulSoup(not a raw string), so the folder test parses the fixture with the samelxmlparser the production code uses.extract_folder_filenamesis asserted identical acrossDEFAULT_COMPATIBILITYandLEGACY_COMPATIBILITY, andget_strategy_for_versionis asserted to pickLegacyCompatibilityStrategyfor the 3.x dashboard vsModernCompatibilityStrategyfor the 5.x dashboard.