portfolio-optimiser/tests/test_ingest_golden_http.py
Kjell Tore Guttormsen 392f8493da chore(repo): planning artifacts become local-only; fixture builders become code
Operator ruling 2026-08-05, which settles decision (g): planning documents are
generally never public, and what OUR OWN sessions generate does not go out on
the forge at all. The example itself stays public so others can run the
process.

`.claude/projects/` is the Voyage session workbench -- 25 briefs/plans/reviews
this project's own sessions produced. Untracked and gitignored, exactly as
STATE.md already is, and for the same stated reason: this repo has a public
mirror, so that class of material is local-only rather than tracked.

The line is drawn at who wrote the document, and it is drawn deliberately:
`docs/plan/`, `docs/research/` and `docs/rapport/` stay tracked. Those are
curated, dated documents written for the repo's readers, three of them linked
from the README as the decision record. Move that line if it was meant wider.

Two files were NOT process artifacts and are not deleted. Both
`build_fixture.py` scripts are cited by tracked tests
(`test_ingest_golden_sql.py`, `test_ingest_golden_http.py`) as the documented
rebuild path for byte-exact goldens -- reproduction code that had landed in the
wrong directory. Moved next to the goldens they build; both docstrings updated,
so no tracked file is left pointing into an untracked tree (verified: the only
remaining `.claude/projects` string in a tracked file is the .gitignore rule
itself). One prose reference in the dated Foundry auth recipe was dropped for
the same reason.

652 tests still pass.

Does NOT address the 27 of these already readable on open/ since the S12
release -- untracking stops future publication only. That retraction is a
separate operator decision and is deliberately not taken here.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GWsexbQjPo9rsV3aUE54ZS
2026-08-05 10:08:17 +02:00

64 lines
2.4 KiB
Python

"""I6 golden regression — the §11 golden extraction case for `http`, byte-for-byte.
Mirrors tests/test_ingest_golden_sql.py for the third source type. The case pins the §5 http
rules AS RULES: the body is rendered verbatim inside a fenced code block (NOT a markdown table),
so a raw ``|`` and ``\`` survive un-escaped — the exact discriminator vs ``render_table``. RED when
ANY byte of the expected bundle diverges (spec §11 "Golden regression" seam).
The canned ``get`` returns the committed fixture payloads (rebuild:
``examples/ingest-golden-http/build_fixture.py``) — no socket, no credentials
(``credential_ref`` is null), so the golden runs offline. The base_url / query never enter the
bundle, so the golden is checkout-location independent.
"""
from __future__ import annotations
from pathlib import Path
from portfolio_optimiser.ingest import HttpGet, materialize
GOLDEN = Path(__file__).resolve().parents[1] / "examples" / "ingest-golden-http"
def _bundle_bytes(directory: Path) -> dict[str, bytes]:
return {p.name: p.read_bytes() for p in sorted(directory.iterdir()) if p.is_file()}
def _fixture_get(fixture_dir: Path) -> HttpGet:
"""Canned transport: map the joined URL's last path segment to its committed fixture file."""
def get(url: str, credential: str | None) -> str:
name = url.rsplit("/", 1)[-1]
return (fixture_dir / name).read_text(encoding="utf-8")
return get
def test_golden_http_extraction_is_bit_deterministic(tmp_path: Path) -> None:
ingested_at = (GOLDEN / "ingested-at.txt").read_text(encoding="utf-8").strip()
fake_get = _fixture_get(GOLDEN / "fixture")
out = tmp_path / "bundle"
materialize(
GOLDEN / "manifest.json",
out,
ingested_at=ingested_at,
allow_network=True,
http_get=fake_get,
)
expected = _bundle_bytes(GOLDEN / "expected-bundle")
actual = _bundle_bytes(out)
# File-SET equality first — catches extra AND missing files, not just diverging bytes.
assert actual.keys() == expected.keys()
for name, content in expected.items():
assert actual[name] == content, f"golden byte divergence in {name}"
# §10: a second run over the same output leaves every byte unchanged.
materialize(
GOLDEN / "manifest.json",
out,
ingested_at=ingested_at,
allow_network=True,
http_get=fake_get,
)
assert _bundle_bytes(out) == expected