fix: dist export erzeugt die TOC-Region nach dem Marker-Strip neu (CI-Fund im Export-Replay)
Files changed: - CHANGES.md - VERSION - tools/chemenu/commands/dist_cmd.py - tools/chemenu/tests/test_dist_cmd.py
This commit is contained in:
@@ -45,7 +45,16 @@ from typing import Callable, NamedTuple, Optional, Union
|
||||
|
||||
import typer
|
||||
|
||||
from chemenu import config, conventions, kb_collections, kb_state, ownership, version as version_mod
|
||||
from chemenu import (
|
||||
blocks,
|
||||
config,
|
||||
conventions,
|
||||
kb_collections,
|
||||
kb_state,
|
||||
ownership,
|
||||
toc,
|
||||
version as version_mod,
|
||||
)
|
||||
from chemenu.commands._util import console, fail, rel_path, success, today_iso
|
||||
|
||||
app = typer.Typer(help="Build a distributable copy of the wiki machinery.")
|
||||
@@ -213,7 +222,18 @@ def _read_planned_file(path: Path, label: str) -> PlannedFile:
|
||||
if path.suffix != ".md":
|
||||
return PlannedFile(text, executable)
|
||||
_validate_markers(text, label)
|
||||
return PlannedFile(strip_markers(text), executable)
|
||||
stripped = strip_markers(text)
|
||||
# A table-of-contents region describes the file it sits in, and stripping
|
||||
# just changed that file: `AGENTS.md`'s marked block wraps the whole
|
||||
# `## Developing this stack` section, so the shipped copy has one heading
|
||||
# fewer than the working tree's TOC lists. Regenerating here - after the
|
||||
# strip, on the text that actually ships - is what keeps a fresh
|
||||
# instance's own `docs verify` green on the very first run. A file with
|
||||
# no region, or one the strip pushed under the threshold, is handled by
|
||||
# `toc.upsert` itself.
|
||||
if blocks.find(stripped, toc.REGION_NAME) is not None:
|
||||
stripped = toc.upsert(stripped)
|
||||
return PlannedFile(stripped, executable)
|
||||
|
||||
|
||||
def _copy_tree(
|
||||
|
||||
@@ -12,7 +12,7 @@ from pathlib import Path
|
||||
import pytest
|
||||
import typer
|
||||
|
||||
from chemenu import config, version as version_mod
|
||||
from chemenu import config, toc, version as version_mod
|
||||
from chemenu.commands import dist_cmd
|
||||
|
||||
|
||||
@@ -183,6 +183,36 @@ def test_plan_strips_markers_but_keeps_surrounding_content(repo):
|
||||
assert "Knowledge base (vendored)" not in agents
|
||||
|
||||
|
||||
def test_plan_refreshes_a_table_of_contents_after_stripping(repo):
|
||||
"""A marked block can wrap a whole section - the real `AGENTS.md`'s wraps
|
||||
`## Developing this stack` - so the shipped copy has one heading fewer
|
||||
than the working tree's TOC lists. The plan regenerates the region on the
|
||||
stripped text; without that, a fresh instance's very first `docs verify`
|
||||
fails on a file nobody touched, which is how CI's export replay caught
|
||||
this and pytest did not."""
|
||||
path = repo / "AGENTS.md"
|
||||
filler = "\n".join(f"Line {i}." for i in range(120))
|
||||
path.write_text(
|
||||
"# AGENTS\n\nCore rules.\n\n"
|
||||
f"## Kept\n\n{filler}\n\n"
|
||||
"<!-- dist:strip-start -->\n"
|
||||
"## Dev only\n\nNot shipped.\n"
|
||||
"<!-- dist:strip-end -->\n\n"
|
||||
"## Changelog\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
# The region as `docs toc --apply` writes it in the working tree, where
|
||||
# the stripped section is still present and so belongs in the TOC.
|
||||
path.write_text(toc.upsert(path.read_text(encoding="utf-8")), encoding="utf-8")
|
||||
assert "[Dev only](#dev-only)" in path.read_text(encoding="utf-8")
|
||||
|
||||
agents = dist_cmd.build_plan()["AGENTS.md"].content
|
||||
assert "## Dev only" not in agents
|
||||
assert "[Dev only](#dev-only)" not in agents
|
||||
assert "[Kept](#kept)" in agents
|
||||
assert "[Changelog](#changelog)" in agents
|
||||
|
||||
|
||||
def test_plan_excludes_venv_and_pycache(repo):
|
||||
plan = dist_cmd.build_plan()
|
||||
assert not any(".venv" in relative for relative in plan)
|
||||
|
||||
Reference in New Issue
Block a user