Skip to content

Centralize Moodle version compatibility for HTML-driven session and module flows#18

Merged
erseco merged 3 commits intomainfrom
copilot/add-compatibility-layer-for-moodle
Mar 16, 2026
Merged

Centralize Moodle version compatibility for HTML-driven session and module flows#18
erseco merged 3 commits intomainfrom
copilot/add-compatibility-layer-for-moodle

Conversation

Copy link
Contributor

Copilot AI commented Mar 16, 2026

This change introduces a compatibility layer for Moodle versions so selector- and workflow-sensitive logic is no longer scattered across scraping code. It detects the Moodle version during session bootstrap and routes fragile HTML parsing through centralized strategies with selector fallbacks.

  • Compatibility layer

    • Added py_moodle.compat to centralize version parsing, compatibility context, and selector strategy selection.
    • Supports legacy (3.x) and modern (4.x+) strategy ranges, with feature probing when version detection is incomplete.
  • Version detection at login/session initialization

    • Detects Moodle version as part of authentication/session setup.
    • Prefers core_webservice_get_site_info when a token is available, then falls back to dashboard HTML metadata/JS probing.
    • Attaches moodle_version and moodle_compat to the authenticated session so downstream code can use a single compatibility entry point.
  • Refactored fragile flows

    • Replaced hardcoded login token and sesskey extraction with compatibility helpers.
    • Moved generic module edit-form discovery and Moodle error extraction to the compatibility layer.
    • Migrated folder-specific scraping to compatibility-managed selectors for:
      • current user fullname discovery
      • folder file listing from activity pages
  • Regression coverage

    • Added focused tests for representative version-sensitive behavior:
      • version detection from webservice responses
      • version detection from dashboard HTML
      • fallback module form selection
      • fallback folder file extraction
      • fallback user-menu fullname extraction
  • Documentation

    • Added a README compatibility section describing:
      • supported strategy ranges
      • how version detection works
      • where future Moodle HTML changes should be absorbed

Example of the new compatibility entry point:

from py_moodle.compat import get_session_compatibility

compat = get_session_compatibility(session)
sesskey = compat.extract_sesskey(html)
form = compat.find_modedit_form(soup)
files = compat.extract_folder_filenames(soup)

This keeps version-sensitive behavior centralized and makes future Moodle UI changes easier to adapt by updating one module instead of patching individual flows.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /home/REDACTED/.local/bin/pytest pytest -q tests/test_compat.py (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI and others added 2 commits March 16, 2026 09:19
Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Co-authored-by: erseco <1876752+erseco@users.noreply.github.com>
Copilot AI changed the title [WIP] Add compatibility layer for resilient Moodle automation Centralize Moodle version compatibility for HTML-driven session and module flows Mar 16, 2026
Copilot AI requested a review from erseco March 16, 2026 09:23
@erseco erseco marked this pull request as ready for review March 16, 2026 09:56
@erseco erseco merged commit 0697bb2 into main Mar 16, 2026
5 checks passed
@erseco erseco deleted the copilot/add-compatibility-layer-for-moodle branch March 16, 2026 09:56
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.

2 participants