Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

3.2 KB
Raw Blame
"""Verify that an oversized release retains its complete published text."""

import subprocess
import sys
from pathlib import Path

import pytest


SCRIPT = (
    Path(__file__).resolve().parents[2]
    / ".github/scripts/shorten_release_notes.py"
)
ASSET_URL = (
    "https://github.com/LearningCircuit/local-deep-research/"
    "releases/download/v2.0.0/release-notes-full.md"
)


def _prepare(body: Path, asset: Path) -> None:
    subprocess.run(
        [
            sys.executable,
            str(SCRIPT),
            str(body),
            str(asset),
            "v2.0.0",
            "LearningCircuit/local-deep-research",
        ],
        check=True,
        capture_output=True,
        text=True,
    )


def test_small_release_body_is_unchanged(tmp_path):
    body = tmp_path / "body.md"
    asset = tmp_path / "release-notes-full.md"
    content = "# Breaking Changes\n\n- A concise migration note.\n"
    body.write_text(content, encoding="utf-8")

    _prepare(body, asset)

    assert body.read_text(encoding="utf-8") == content
    assert not asset.exists()


def test_oversized_release_links_exact_complete_body(tmp_path):
    body = tmp_path / "body.md"
    asset = tmp_path / "release-notes-full.md"
    content = (
        "# 💥 Breaking Changes\n\n"
        + "- A complete migration paragraph with accented text: café.\n\n"
        * 3_000
        + "# What's Changed\n\n- The final PR still appears in the asset.\n"
    )
    body.write_text(content, encoding="utf-8")

    _prepare(body, asset)

    published = body.read_text(encoding="utf-8")
    assert asset.read_text(encoding="utf-8") == content
    assert len(published) <= 124_400
    assert published.startswith(
        f"**Complete release notes:** [Download the full text]({ASSET_URL})."
    )
    assert "[Download all notes and the PR list]" in published
    assert published.count(ASSET_URL) == 2
    assert "The final PR still appears in the asset" not in published
    assert published.endswith(f"({ASSET_URL})._\n")


@pytest.mark.parametrize("newline", ["\n", "\r\n", "\r", "\r\n\n"])
@pytest.mark.parametrize("oversized", [False, True])
def test_original_newline_bytes_are_preserved(tmp_path, newline, oversized):
    body = tmp_path / "body.md"
    asset = tmp_path / "release-notes-full.md"
    paragraph = f"# Release notes{newline}{newline}- Migration: café. {newline}"
    original = (paragraph * (7_000 if oversized else 1)).encode("utf-8")
    body.write_bytes(original)

    _prepare(body, asset)

    if oversized:
        assert asset.read_bytes() == original
        published = body.read_text(encoding="utf-8")
        assert len(published) <= 124_400
        assert published.count(ASSET_URL) == 2
    else:
        assert body.read_bytes() == original
        assert not asset.exists()


def test_newline_bytes_do_not_change_shortening_threshold(tmp_path):
    body = tmp_path / "body.md"
    asset = tmp_path / "release-notes-full.md"
    # CRLF makes this larger than the limit in bytes, but its normalized body
    # is below the character budget and must remain untouched.
    original = b"A line.\r\n" * 15_000
    body.write_bytes(original)

    _prepare(body, asset)

    assert body.read_bytes() == original
    assert not asset.exists()