Skip to content

Fix Django/Wagtail search-bar parity bugs (container, wasmPath, Amazee trigger, per-page language)#2

Open
jeremyandrews wants to merge 1 commit into
mainfrom
fix/django-adapter-search-parity
Open

Fix Django/Wagtail search-bar parity bugs (container, wasmPath, Amazee trigger, per-page language)#2
jeremyandrews wants to merge 1 commit into
mainfrom
fix/django-adapter-search-parity

Conversation

@jeremyandrews
Copy link
Copy Markdown
Member

Summary

Brings the Django adapter in line with the PHP adapters, fixing four issues surfaced by the GitMastery (demos/git-manual-django) demo. Each is paired with a regression test at the layer that would have caught it.

Fixes

  1. Search UI mount (container){% scolta_search %} now emits a container CSS selector in window.scolta matching the rendered mount <div>. scolta.js auto-init reads it to locate its mount point; without it the markup rendered but the search box never did. (carried in from an earlier session; now under test)
  2. wasmPath — now points at the full WASM glue module (…/wasm/scolta_core.js) rather than the containing directory, because scolta.js calls import(wasmPath) directly and a bare directory 404s. (carried in; now under test)
  3. Amazee auto-provision triggermaybe_auto_provision() now gates on no API key configured instead of ai_provider == 'amazee'. This mirrors the PHP adapters (ScoltaAiService::createClient lazy-provisions whenever getApiKeySource() === 'none'): a site with no key gets the free Amazee trial automatically; an explicit key always wins. Previously the default anthropic provider never provisioned and AI silently degraded.
  4. Per-page languageSearchableMixin.to_searchable_content() derives the per-page filter language from a Wagtail locale (self.locale.language_code) when present, so multilingual sites populate the language facet per page instead of collapsing every page into the index's single bucket. Plain Django models without a locale keep the ContentItem default; explicit overrides must pass language= themselves (documented in the mixin).

Tests

  • tests/test_search_browser.py (new) — browser-layer mount regression via Playwright; skips cleanly when chromium/playwright is absent. tests/browser_urls.py (new) serves the real assets.
  • tests/test_adapter.pycontainer + wasmPath config guards.
  • tests/test_amazee_django.py — key-gate trigger contract: default provider (anthropic) + no key + empty storage provisions; explicit key no-ops; already-stored creds no-op.
  • tests/test_wagtail.py — Wagtail-locale language derivation; plain model keeps the default.
  • tests/conftest.py — autouse fixture keeps AI-view tests hermetic now that "no key" triggers provisioning (the Amazee unit tests import the function directly and inject a fake client, so they're unaffected).
  • CI: playwright install --with-deps chromium step added before the test run.

Testing done

  • ruff check src tests clean; pytest 70 passed locally.
  • Live-verified against the running demo (https://gitmastery-django.ddev.site/) on the editable package install:
    • / serves the search UI in main content, not the header; results render below the header band (no overlap).
    • Built index language filter map: {en: 286, es/fr/it/de: 285} (was {en: 1426}).
    • An English search returns zero /de//es//fr//it/ URLs; an Italian search from /it/ returns only /it/ URLs (auto language filter).
    • Health endpoint flips to ai_configured: true (provider anthropic → openai via the Amazee trial) after one search — the free trial provisions with no key set.

…e trigger, per-page language)

Brings the Django adapter in line with the PHP adapters on four fronts surfaced
by the GitMastery demo:

- {% scolta_search %} now emits a `container` selector in window.scolta matching
  the rendered mount div. scolta.js auto-init reads it to find its mount point;
  without it the markup rendered but the search box never did.
- {% scolta_search %} now sets `wasmPath` to the full WASM glue module
  (.../wasm/scolta_core.js), not the containing directory — scolta.js does
  import(wasmPath) directly, so a bare directory 404s.
- Amazee auto-provisioning now triggers on a key gate, not a provider gate:
  maybe_auto_provision() provisions a free trial whenever no API key is
  configured, regardless of ai_provider (mirrors the PHP getApiKeySource()
  === 'none' contract). An explicit key always wins. Previously it required
  ai_provider == 'amazee', so the default 'anthropic' never provisioned and AI
  silently degraded.
- SearchableMixin.to_searchable_content() derives the per-page filter language
  from a Wagtail locale (self.locale.language_code) when present, so
  multilingual sites populate the language facet per page instead of collapsing
  every page into the default bucket. Plain models keep the default; explicit
  overrides must pass language= themselves.

Tests: browser-layer search-bar mount regression (Playwright, skips when
chromium is absent) + container/wasmPath config guards; Amazee key-gate trigger
contract (default provider + no key provisions, explicit key no-ops, stored
creds no-op); Wagtail-locale language derivation. A conftest autouse fixture
keeps AI-view tests hermetic now that no key triggers provisioning. CI installs
chromium for the browser test.
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