Restore experiment→wiki crosslinks + fix broken wiki-crosslinks test

← All Specs

Restore experiment→wiki crosslinks + fix broken wiki-crosslinks test

Task ID: experiment-wiki-crosslinks-restore-2026-05-18 Layer: Atlas (artifact_detail) Date: 2026-05-18 Status: open — follow-up to experiment-artifact-extras-2026-05-13 Priority: high (real product gap + a permanently-broken test) v1 carve-out: user-authorized; v1 still serves scidex.ai

Symptom

tests/test_wiki_crosslinks.py::test_experiment_detail_shows_wiki_crosslinks
fails: it does client.get("/experiment/<slug>", follow_redirects=False),
asserts status_code == 200, and asserts "📖 Wiki Pages" in html. The
route now 301-redirects (no body) and the string no longer exists.

Root cause

This is not a regression from PR #1413. Timeline (from git log):

  • Test added: commit a1c9c112e, 2026-04-16.
  • Type-alias 301 redirect for /experiment/{artifact_id:path} added:
commit 11bbe3c4b (PR #1229), 2026-04-28 — broke the test that day.
  • PR #1413, 2026-05-13 — deleted the already-unreachable
experiment_detail handler (which contained the 📖 Wiki Pages
section). It only removed dead code.

The deeper issue: the 📖 Wiki Pages panel was a **real, user-facing
capability** that the redirect silently dropped on 2026-04-28. artifact_detail has a Related Wiki Pages panel
(_hyp_related_wiki_panel, api.py:34772, header entity &#x1f4d9; 📙)
but it is hypothesis-only — it queries target_artifact_id = 'hypothesis-{id}' and is wired solely into the
hypothesis branch's Evidence section. /artifact/<exp_id> surfaces **no
wiki crosslinks for experiments under any heading**. So experiment→wiki
crosslinks have been missing from the product since 2026-04-28.

Fix

Restore the capability on the canonical page, then unbreak the test.

  • **api.py — add a wiki-crosslinks block to
  • _render_experiment_extras_html** (insert into sections,
    immediately before the function's final return at ~api.py:31436).
    Model the chip markup on _hyp_related_wiki_panel (api.py:34772–34802)
    but query for experiment keys:


    SELECT wp.slug, wp.title, wp.entity_type, MAX(al.strength) AS strength
       FROM artifact_links al
       JOIN wiki_pages wp ON wp.slug = SUBSTR(al.source_artifact_id, 6)
       WHERE al.target_artifact_id = %s
         AND al.source_artifact_id LIKE 'wiki-%'
       GROUP BY wp.slug, wp.title, wp.entity_type
       ORDER BY strength DESC LIMIT 15

    Key-form caveat — verify before shipping. The deleted handler
    keyed target_artifact_id on experiment-<id>; the new artifact
    page is reached at the bare <id>. artifact_links may hold the
    crosslink under either form. Probe the live DB for the fixture the
    test uses (_find_artifact_with_wiki_links("experiment")) and key
    the query on whichever form actually has rows — or query both with
    target_artifact_id IN (%s, 'experiment-' || %s). Do not assume.
    Gate the section on a non-empty result (consistent with every other
    block in the helper).

  • tests/test_wiki_crosslinks.py — unbreak the assertions
  • (lines 70, 75): change follow_redirects=FalseTrue and assert
    the artifact page's real heading. The new block should use the same
    Related Wiki Pages wording as _hyp_related_wiki_panel (📙
    &#x1f4d9;, not 📖) so the assertion becomes
    assert "Related Wiki Pages" in html. While here, also fix
    test_analysis_detail_shows_wiki_crosslinks (same redirect breakage,
    same two-line pattern) and test_direct_join_query_returns_results
    (uses SQLite ? placeholders + positional row indexing — broken on
    the psycopg/dict_row connection independent of this work).

    Verification

    • Pick the experiment id returned by
    _find_artifact_with_wiki_links("experiment"); confirm
    /artifact/<id> now renders a "Related Wiki Pages" panel with the
    expected wiki chips.
    • An experiment with no wiki links renders no panel (no empty stub).
    • pytest tests/test_wiki_crosslinks.py passes all four methods.
    • No spillover: hypothesis/analysis artifacts unchanged; the new block
    only appears for experiment artifacts with artifact_links rows.
    • Post-deploy: restart scidex-api, confirm live render (see
    operational note about deploy ordering in memory).

    File: experiment-wiki-crosslinks-restore-2026-05-18_spec.md
    Modified: 2026-05-18 19:31
    Size: 4.2 KB