phase: 145_git_source_links
**Phase 145 final verification pass — all green, no code changes needed** - **Verified (no defects found):** resolver `origin_for_source` + `_url_basename` (scp/`.git`/trailing-slash, sanitize, ambiguity WARNING); `origin:`/`branch:` lines in all four read shapes via shared `_origin_lines`; HIGH `<tools>` origin rule (verbatim + only-byte-change pins); `DocContent.origin_url/origin_branch` (absent-never-null serializer); `renderDocument` "Original" anchor (copyable verbatim URL, `_blank`/`noopener`, branch in title); mock scripted origin-link flow (disjoint trigger — grep-verified vs all other E2E files) - **Tests:** `uv run pytest --cov=app --cov-report=term-missing` → 3402 passed, `app/` coverage **99%** (>90% gate); `uv run pytest tests/e2e/test_git_source_links.py -v --no-cov` → **4 passed** in isolation; `uv run ruff check .` → clean; `uv run pyright` → 0 errors, 0 warnings - **Completion criteria:** (1) git read results carry origin/branch, local byte-identical — ✅ (unit pins + E2E control); (2) HIGH `<tools>` rule pinned, LOW byte-identical — ✅; (3) modal AND /document.html show Original link, branch in label when pinned, nothing for local — ✅; (4) full suite green + coverage + E2E + lint/types — ✅; (5) no completed-phase behavior change (read header line 1, mock prefix, done frame/SourceRef untouched, LOW sha) — ✅ - **Extra regression check:** re-ran shared-mock E2E suites `test_read_line_ranges.py` (2 passed) and `test_document_viewer.py` (8 passed) — no cross-suite regressions from the `mock_llm.py` addition - **Documentation:** README.md reviewed in full (env table ⊇ `.env.example`, pages/routes, config defaults, scripts, 17-color palette, 300 s guard, 2 s sync poll, phase-145 provenance section matches implementation) and AGENTS.md (72rem container, no-CDN test, smoke test, gitignore, gates) — **verified consistent, no changes needed** - **Notable:** phase-116 screenshot PNG was regenerated during this phase's E2E runs (byte re-encode only, visually identical, correct no-anchor local-source meta row) — left in tree for the harness commit - **Next pending phase:** `146_search_tool_scope` (then 147, 148, 149)
This commit is contained in:
@@ -15,6 +15,7 @@ from __future__ import annotations
|
||||
import hashlib
|
||||
|
||||
from app.rag.prompts import (
|
||||
ORIGIN_RULE,
|
||||
PERSONA,
|
||||
SUGGEST_INTRO,
|
||||
TOOLS_SECTION,
|
||||
@@ -77,12 +78,18 @@ def test_high_and_low_bases_byte_locked() -> None:
|
||||
#: form — do not re-read a document read IN FULL (answer from it);
|
||||
#: a PARTIAL document (a range read, or a truncated read) is not
|
||||
#: complete in the context until read all — read the other parts with
|
||||
#: ``offset``/``limit``. Only that sentence moved — the prefix (the
|
||||
#: ``ls``-clause opening) and the suffix (the discipline-rules
|
||||
#: ending) survived byte-identical, so they are the same anchors as
|
||||
#: pre-phase-141.
|
||||
TOOLS_SECTION_SHA256 = "3671680bbf4e04efe1186690c18d24869e4974ceb29485cedc3e34a9286bf3b2"
|
||||
TOOLS_SECTION_LEN = 2656
|
||||
#: ``offset``/``limit``. RE-CUT again for phase 145 (task 02): the
|
||||
#: ``read`` clause gains the original-source rule — :data:`ORIGIN_RULE`,
|
||||
#: the one sentence-group appended at the ``read`` clause's end (the
|
||||
#: truncation workflow sentence) and BEFORE the ``grep`` clause begins
|
||||
#: (the ``origin:`` line is a read-result fact; the rule binds the
|
||||
#: ANSWER that uses what the read added). Only that sentence-group was
|
||||
#: inserted — the prefix (the ``ls``-clause opening) and the suffix
|
||||
#: (the discipline-rules ending) survived byte-identical, so they are
|
||||
#: the same anchors as pre-phase-145; the pre-phase-145 sha/length are
|
||||
#: kept below for the diff-style pin.
|
||||
TOOLS_SECTION_SHA256 = "41a84885be98d4e15b95205694d59d364296a30e27758d39ae737881d5bacaa7"
|
||||
TOOLS_SECTION_LEN = 3279
|
||||
TOOLS_SECTION_PREFIX = (
|
||||
"<tools>\n"
|
||||
"You may extend your context with three tools. `ls` lists the "
|
||||
@@ -94,6 +101,33 @@ TOOLS_SECTION_SUFFIX = (
|
||||
"you need.\n</tools>"
|
||||
)
|
||||
|
||||
#: The pre-phase-145 anchors — the section BEFORE :data:`ORIGIN_RULE` was
|
||||
#: inserted. Kept for the diff-style pin: the ONLY byte change is the
|
||||
#: rule's insertion, so removing the rule reproduces these exact bytes.
|
||||
TOOLS_SECTION_PRE_PHASE_145_SHA256 = (
|
||||
"3671680bbf4e04efe1186690c18d24869e4974ceb29485cedc3e34a9286bf3b2"
|
||||
)
|
||||
TOOLS_SECTION_PRE_PHASE_145_LEN = 2656
|
||||
|
||||
|
||||
#: Phase 145 (task 02) — the original-source rule the ``read`` teaching
|
||||
#: carries is :data:`app.rag.prompts.ORIGIN_RULE` (imported above, LOCKED
|
||||
#: verbatim). :data:`TOOLS_SECTION` embeds that exact sentence-group at
|
||||
#: the ``read`` clause's end (the truncation workflow sentence) and
|
||||
#: BEFORE the ``grep`` clause begins. A read result for a git-sourced
|
||||
#: document carries an ``origin:`` line (and a ``branch:`` line when a
|
||||
#: branch is pinned) — the read contract's fact — so when the answer uses
|
||||
#: such a document it includes the original source in the answer: a link
|
||||
#: to the repository (the ``origin`` line) with the document's path (the
|
||||
#: ``Document …`` header) named and the pinned branch when one is shown,
|
||||
#: as the repository's file-view URL where the model can tell it
|
||||
#: (``<repo-url>/blob/<branch>/<path>``), or the repository URL plus the
|
||||
#: path as plain text otherwise. The rule is CONDITIONAL on the ``origin``
|
||||
#: line's presence — a local-sourced document's read result carries none,
|
||||
#: so the rule adds nothing to those answers (the model has no URL to
|
||||
#: cite; it must not invent one — the sentence's conditioning does that
|
||||
#: job).
|
||||
|
||||
|
||||
def test_tools_section_byte_locked() -> None:
|
||||
"""The ``<tools>`` teaching is LOCKED verbatim too (the E2E mock keys
|
||||
@@ -105,6 +139,41 @@ def test_tools_section_byte_locked() -> None:
|
||||
assert TOOLS_SECTION.endswith(TOOLS_SECTION_SUFFIX)
|
||||
|
||||
|
||||
def test_tools_section_origin_rule_verbatim_at_its_position() -> None:
|
||||
"""Phase 145 (task 02): the original-source rule is LOCKED verbatim
|
||||
and sits at its EXACT position — the ``read`` clause's end (the
|
||||
truncation workflow sentence) and BEFORE the ``grep`` clause begins.
|
||||
The sentence-group is pinned byte-for-byte, and the surrounding
|
||||
boundary (the truncation sentence's tail → the rule → the ``grep``
|
||||
clause's opening) is pinned as one contiguous substring, so a move
|
||||
or re-spelling of ANY byte (the rule's or the boundary's) fails."""
|
||||
# Verbatim presence.
|
||||
assert ORIGIN_RULE in TOOLS_SECTION
|
||||
assert TOOLS_SECTION.count(ORIGIN_RULE) == 1 # exactly once
|
||||
# Exact position: after the truncation sentence, before the grep
|
||||
# clause — one contiguous span, no drift at either seam.
|
||||
assert (
|
||||
"it searches the whole document. "
|
||||
+ ORIGIN_RULE
|
||||
+ " `grep` locates an exact string"
|
||||
) in TOOLS_SECTION
|
||||
|
||||
|
||||
def test_tools_section_origin_rule_is_the_only_byte_change() -> None:
|
||||
"""Phase 145 (task 02) diff-style pin: the section's OTHER bytes are
|
||||
byte-identical to pre-phase — the pre-phase section with ONLY the new
|
||||
sentence-group inserted. Removing the rule (and the single space
|
||||
that now separates it from the ``grep`` clause) reproduces the
|
||||
pre-phase-145 section byte-for-byte (sha + length), and the length
|
||||
delta is exactly the rule's length plus that one inserted space."""
|
||||
assert len(TOOLS_SECTION) == (
|
||||
TOOLS_SECTION_PRE_PHASE_145_LEN + len(ORIGIN_RULE) + 1
|
||||
)
|
||||
pre_phase = TOOLS_SECTION.replace(ORIGIN_RULE + " ", "")
|
||||
assert len(pre_phase) == TOOLS_SECTION_PRE_PHASE_145_LEN
|
||||
assert _sha256(pre_phase) == TOOLS_SECTION_PRE_PHASE_145_SHA256
|
||||
|
||||
|
||||
# ---------- the LOW prompt's locked DEFLECT_MODE body ----------
|
||||
|
||||
#: The ``DEFLECT_MODE`` body exactly as it was pre-phase-112 (the
|
||||
|
||||
Reference in New Issue
Block a user