Skip to content

Code copy test reads 20px padding where it expects 12px #5175

Closed

Description

@leaf-agent

The scheduled run 41432142330 records this failing boundary. This report supplies CI evidence; it has not reproduced the failure on current main or established its cause.

Reconcile against current main and active repair work, reproduce the focused boundary, and fix the highest incorrect owner while preserving the originating change’s intent and the user behavior. Reuse an existing owner when reproduction proves a shared mechanism. Follow normal review and landing gates.

tests.journeys.test_render_anchors::test_code_copy_keeps_source_and_stays_beside_scrolling_and_revised_blocks — Linux
browser = <render_harness.WatchedBrowser object at 0x7f7c26fbf680>
serve = <function serve.<locals>.go at 0x7f7c250faf20>

    def test_code_copy_keeps_source_and_stays_beside_scrolling_and_revised_blocks(
        browser, serve
    ):
        """Copy uses source, including whitespace, rather than rendered annotations.
    
        A numbered widget and both ordinary block shapes share the same gesture.
        The retained widget's Copy returns after a hidden widget is detached and
        reconnected. The control stays reachable beside horizontally scrolling code,
        and a revision updates its source or removes it without duplicating controls.
        """
        colored = '\n  print("' + "long source " * 30 + '")\t\n'
        suffix = "VISIBLE_END"
        plain = "dense_source_" * 30 + suffix
        widget = 'def greet():\n    return "hello"'
    
        def document(colored_source=colored, plain_source=plain, *, keep_colored=True):
            return leaf_page(
                "copy source",
                '<h1 id="title">Copy source</h1>'
                + (
                    '<pre id="colored" style="anchor-name: --authored-colored, --authored-secondary">'
                    '<code class="language-python">'
                    + escape(colored_source)
                    + "</code></pre>"
                    if keep_colored
                    else ""
                )
                + '<pre id="plain" tabindex="0"><code>'
                + escape(plain_source)
                + '</code></pre><a id="after-copy" href="#title">After code</a>'
                + '<lf-code id="numbered" language="python" hi="2"><pre>'
                + escape(widget)
                + '</pre><lf-note at="2">This annotation is not source.</lf-note></lf-code>'
                + '<lf-draft id="draft"><pre>A draft copies its own Markdown.</pre></lf-draft>',
                head="<style>#plain { anchor-name: --authored-plain; }"
                "#numbered.lf-rendered > pre { anchor-name: --authored-numbered; }</style>",
            )
    
        url = live_url(serve(document()))
        page = open_page(browser, url)
        page.context.grant_permissions(["clipboard-read", "clipboard-write"])
        # The draft's control is its own (`lf-draft.js`); these are the code blocks'.
        expect(page.locator("#draft .lf-draft-tools > .lf-code-copy")).to_have_count(1)
        controls = page.locator(".lf-code-copy:not(#draft *)")
        expect(controls).to_have_count(3)
        document_controls = page.locator(".lf-chrome .lf-code-copy")
        expect(document_controls).to_have_count(2)
        expect(page.locator("#colored")).to_have_attribute("tabindex", "0")
        expect(page.locator("#colored")).to_have_attribute("aria-keyshortcuts", "Enter")
        expect(page.locator("#numbered lf-note")).to_contain_text("not source")
        expect(page.locator("#numbered .lf-quiet")).to_have_count(1)
    
        anchors = {}
        for block, control in (
            ("colored", document_controls.nth(0)),
            ("plain", document_controls.nth(1)),
            ("numbered", page.locator("#numbered > .lf-code-copy")),
        ):
            anchors[block] = control.evaluate(
                """(copy, selector) => {
                  const pre = document.querySelector(selector);
                  return {
                    names: getComputedStyle(pre).anchorName.split(',').map(name => name.trim()),
                    copyAnchor: getComputedStyle(copy).positionAnchor,
                  };
                }""",
                f"#{block}" if block != "numbered" else "#numbered > pre",
            )
        authored = {
            "colored": {"--authored-colored", "--authored-secondary"},
            "plain": {"--authored-plain"},
            "numbered": {"--authored-numbered"},
        }
        for block, reading in anchors.items():
            assert authored[block].issubset(reading["names"]), anchors
            assert reading["copyAnchor"] in reading["names"], anchors
    
        def copy(pre_selector, control, expected, *, keyboard=False):
            button = control.get_by_role("button")
            pre = page.locator(pre_selector)
            expect(button).to_have_attribute("aria-label", "Copy code")
            pre.scroll_into_view_if_needed()
            page.mouse.move(0, 0)
            page.evaluate(RELEASE_FOCUS)
            expect(control).to_have_css("opacity", "0")
    
            def geometry():
                return control.evaluate(
                    """(copy, selector) => {
                      const pre = document.querySelector(selector);
                      const source = pre.querySelector('code') ?? pre.querySelector('.lf-code-line');
                      const range = new Range();
                      range.selectNodeContents(source);
                      const rect = box => [box.x, box.y, box.width, box.height];
                      return {
                        padding: getComputedStyle(pre).paddingTop,
                        frame: rect(pre.getBoundingClientRect()),
                        source: rect(range.getClientRects()[0]),
                        copy: rect(copy.getBoundingClientRect()),
                      };
                    }""",
                    pre_selector,
                )
    
            before = geometry()
            assert before["padding"] == "12px", before
            # Copy's toolbar stands just inside the block's top-right corner.
            frame, overlay = before["frame"], before["copy"]
            assert 0 <= overlay[1] - frame[1] <= 8, before
            assert 0 <= frame[0] + frame[2] - overlay[0] - overlay[2] <= 8, before
            if keyboard:
                # Enter on the source copies it, though the control stands outside
                # authored markup and the Tab sequence. The register names that press
                # wherever it names keys: the command reference and the block's
                # aria-keyshortcuts.
                pre.focus()
                expect(pre).to_have_attribute("aria-keyshortcuts", "Enter")
                page.keyboard.press("?")
                expect(
                    command_reference_rows(page, "On a code block").get_by_text(
                        "Copy code", exact=True
                    )
                ).to_be_visible()
                page.keyboard.press("Escape")
                expect(pre).to_be_focused()
            else:
                pre.hover()
                expect(control).to_have_css("opacity", "1")
                button.hover()
            expect(control).to_have_css("opacity", "1")
            after = geometry()
            for box in ("frame", "source", "copy"):
                assert after[box] == pytest.approx(before[box], abs=0.5), (before, after)
            if keyboard:
                page.keyboard.press("Enter")
                expect(pre).to_be_focused()
            else:
                button.click()
            expect(button).to_have_attribute("aria-label", "Code copied")
            expect_panel_says(page, "Code copied")
            assert page.evaluate("navigator.clipboard.readText()") == expected
    
>       copy("#colored", document_controls.nth(0), colored)

/home/runner/work/leaf/leaf/tests/journeys/test_render_anchors.py:417: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

pre_selector = '#colored'
control = <Locator frame=<Frame name= url='http://127.0.0.1:33703/'> selector='.lf-chrome .lf-code-copy >> nth=0'>
expected = '\n  print("long source long source long source long source long source long source long source long source long sourc...rce long source long source long source long source long source long source long source long source long source ")\t\n'
keyboard = False

    def copy(pre_selector, control, expected, *, keyboard=False):
        button = control.get_by_role("button")
        pre = page.locator(pre_selector)
        expect(button).to_have_attribute("aria-label", "Copy code")
        pre.scroll_into_view_if_needed()
        page.mouse.move(0, 0)
        page.evaluate(RELEASE_FOCUS)
        expect(control).to_have_css("opacity", "0")
    
        def geometry():
            return control.evaluate(
                """(copy, selector) => {
                  const pre = document.querySelector(selector);
                  const source = pre.querySelector('code') ?? pre.querySelector('.lf-code-line');
                  const range = new Range();
                  range.selectNodeContents(source);
                  const rect = box => [box.x, box.y, box.width, box.height];
                  return {
                    padding: getComputedStyle(pre).paddingTop,
                    frame: rect(pre.getBoundingClientRect()),
                    source: rect(range.getClientRects()[0]),
                    copy: rect(copy.getBoundingClientRect()),
                  };
                }""",
                pre_selector,
            )
    
        before = geometry()
>       assert before["padding"] == "12px", before
E       AssertionError: {'padding': '20px', 'frame': [240, 121.453125, 720, 82], 'source': [255, 144.453125, 0, 16], 'copy': [932, 125.453125, 24, 24]}
E       assert '20px' == '12px'
E         
E         - 12px
E         ? -
E         + 20px
E         ?  +

/home/runner/work/leaf/leaf/tests/journeys/test_render_anchors.py:380: AssertionError

Full diagnostics are in the run’s pytest-results-* JUnit artifacts.

Cause of a failure tracked in #4225.

Activity

  1. added
    tend-ci-cause
    on Nov 3, 2026
  2. leaf-agent commented on Nov 3, 2026

    @leaf-agent
    CollaboratorAuthor

    This is a stale test expectation. #4738 deliberately gave every page code block a code line (20px) above its code, so the composer doesn't jump when a fence's source is revealed. The Copy journey still pinned the old 12px for every block. I reproduced the failure on current main.

    #5233 updates the journey: page blocks now expect 20px, and the numbered lf-code widget keeps its own 12px inset, which #4738 didn't change. No product code changes. The journey passes locally with the update. The PR's review and CI are still pending, and it lands through the normal Tend landing path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    tend-ci-cause

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions