mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-27 23:58:47 +00:00
* test(dream): accept contextual provenance links in auto_dream assertion integrate.yaml (since #428) requires every `## Sources` entry to be a complete sentence containing the wikilink and explicitly forbids bare `- [[...]]` lines, but the integration assertion only matched the bare line form, so prompt-conformant digests fail the provenance check (reported in #739). Match the provenance link target with or without an alias instead of a specific line form. * test(dream): check provenance with the shared wikilink parser The prefix-based check ("\[[[P]]\]" or "\[[[P|") kept a partial grammar in the assertion and still mismatched the repository's wikilink syntax in both directions: an unterminated aliased span like "[[P|the session record" (no closing brackets) was accepted even though it produces no source link, while valid anchored links such as "[[P#Decision]]" and "[[P#Decision|the decision]]" were rejected even though the shared parser resolves them to the expected target. The assertion now delegates to a small dependency-light helper (tests/integration/_provenance.py) that asks WikilinkHandler.iter_matches whether any parsed link's target equals the changed daily note. Bare links, contextual sentences, aliases, embeds, and anchors all count; unterminated spans and links to other targets do not. Because tests/integration never runs in CI, the helper is also exercised by tests/unit/test_auto_dream_provenance.py with uncredentialed, parameterized cases for each accepted and rejected form, plus a multi-target selection case. --------- Co-authored-by: RerankerGuo <RerankerGuo@users.noreply.github.com>
59 lines
2.5 KiB
Python
59 lines
2.5 KiB
Python
"""CI-scope coverage for the auto_dream provenance assertion logic.
|
|
|
|
``tests/integration/test_auto_dream.py`` needs a live LLM endpoint, so its
|
|
assertions never run in CI. The provenance check lives in
|
|
``tests/integration/_provenance.py`` (kept dependency-light for exactly this
|
|
reason) and is exercised here against the offline string cases for every link
|
|
form the integrate prompt permits — and the forms it must reject.
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
INTEGRATION_DIR = Path(__file__).resolve().parents[1] / "integration"
|
|
sys.path.insert(0, str(INTEGRATION_DIR))
|
|
|
|
# pylint: disable=wrong-import-position
|
|
from _provenance import targets_with_provenance # noqa: E402
|
|
|
|
SOURCE = "daily/2026-05-28/auth-refactor/notes.md"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("body", "expected"),
|
|
[
|
|
# Bare list line (the pre-#428 form the old substring asserted).
|
|
(f"- [[{SOURCE}]]", True),
|
|
# Contextual sentence, no alias — the prompt's required form.
|
|
(f"The session record at [[{SOURCE}]] motivated this change.", True),
|
|
# Contextual sentence with the prompt's canonical alias example.
|
|
(f"See [[{SOURCE}|the session record]] for the full discussion.", True),
|
|
# Anchored link and anchored alias: the anchor is a separate regex
|
|
# group, so the target still compares equal.
|
|
(f"Decided in [[{SOURCE}#Decision]].", True),
|
|
(f"See [[{SOURCE}#Decision|the decision]] for details.", True),
|
|
# Embed form.
|
|
(f"![[{SOURCE}]]", True),
|
|
# Unterminated alias span: not a wikilink, must not count.
|
|
(f"See [[{SOURCE}|the session record", False),
|
|
# No provenance at all.
|
|
("No links here.", False),
|
|
# Link present but to a different source target.
|
|
("Points elsewhere: [[daily/2026-05-28/auth-refactor/other.md]].", False),
|
|
],
|
|
)
|
|
def test_targets_with_provenance(body: str, expected: bool):
|
|
"""Every prompt-permitted link form counts; malformed or foreign links do not."""
|
|
target_texts = {"digest/session-review.md": body}
|
|
assert bool(targets_with_provenance(target_texts, SOURCE)) is expected
|
|
|
|
|
|
def test_targets_with_provenance_lists_only_matching_targets():
|
|
"""Only targets that actually link to the source are listed."""
|
|
target_texts = {
|
|
"digest/with-link.md": f"Derived from [[{SOURCE}|the session record]].",
|
|
"digest/no-link.md": "Independent summary.",
|
|
}
|
|
assert targets_with_provenance(target_texts, SOURCE) == ["digest/with-link.md"]
|