Files
chemenu/tools/chemenu/tests/test_log_append.py
T
torben 24cd221b21
CI / verify (push) Successful in 55s
Release / release (push) Successful in 39s
fix: stale wiki/ path literals nach kb/ nachgezogen, mit Test-Guard gegen die naechste Umbenennung
Files changed:
- CHANGES.md
- VERSION
- kb/entities/projects/Chemenu.md
- kb/log.md
- tools/chemenu/commands/_util.py
- tools/chemenu/commands/cite_cmd.py
- tools/chemenu/commands/git_publish.py
- tools/chemenu/commands/log_append.py
- tools/chemenu/commands/page_ops.py
- tools/chemenu/commands/provenance_cmd.py
- tools/chemenu/commands/raw_cmd.py
- tools/chemenu/commands/run_budget.py
- tools/chemenu/commands/touch.py
- tools/chemenu/commands/xref.py
- tools/chemenu/frontmatter_io.py
- tools/chemenu/lint_core.py
- tools/chemenu/tests/test_log_append.py
- tools/chemenu/tests/test_source_hygiene.py
- tools/chemenu/tests/test_touch.py
- tools/chemenu/tests/test_type_resolver.py
- tools/chemenu/type_resolver.py
- tools/wikitool
- types/type-spec.md
- types/type-spec.schema.yaml
2026-09-17 08:59:25 +02:00

78 lines
2.4 KiB
Python

from chemenu.commands.log_append import (
format_log_entry,
ingests_since_last_lint,
log_status,
parse_log_entries,
)
def test_log_entry_format_matches_convention():
entry = format_log_entry("ingest", "raw/notes/gateway.example.net.md", "Some details.", today="2026-08-02")
assert entry == (
"## [2026-08-02] ingest | raw/notes/gateway.example.net.md\n"
"\n"
"Some details.\n"
"\n"
"---\n"
)
def test_log_entry_without_body_has_no_blank_body_block():
entry = format_log_entry("query", "What projects use MQTT?", "", today="2026-08-02")
assert entry == "## [2026-08-02] query | What projects use MQTT?\n\n---\n"
def test_parse_log_entries_reads_date_op_and_title_in_file_order():
text = (
"# Wiki Log\n\n"
"## [2026-08-01] ingest | raw/notes/a.md\n\n---\n\n"
"## [2026-08-02] lint | Lint Report 2026-08-02.md\n\n---\n"
)
assert parse_log_entries(text) == [
("2026-08-01", "ingest", "raw/notes/a.md"),
("2026-08-02", "lint", "Lint Report 2026-08-02.md"),
]
def test_ingests_since_last_lint_resets_on_a_lint_entry():
entries = [
("2026-08-01", "ingest", "a.md"),
("2026-08-02", "ingest", "b.md"),
("2026-08-03", "lint", "Lint Report.md"),
("2026-08-04", "ingest", "c.md"),
]
assert ingests_since_last_lint(entries) == 1
def test_ingests_since_last_lint_counts_from_the_start_when_never_linted():
entries = [
("2026-08-01", "ingest", "a.md"),
("2026-08-02", "query", "What is X?"),
("2026-08-03", "ingest", "b.md"),
]
assert ingests_since_last_lint(entries) == 2
def test_log_status_reports_zero_with_no_log_file(tmp_path, monkeypatch, capsys):
import chemenu.config as config
monkeypatch.setattr(config, "LOG_FILE", tmp_path / "log.md")
log_status()
assert "No kb/log.md yet" in capsys.readouterr().out
def test_log_status_warns_at_the_ten_ingest_threshold(tmp_path, monkeypatch, capsys):
import chemenu.config as config
log_file = tmp_path / "log.md"
body = "".join(
format_log_entry("ingest", f"raw/notes/{i}.md", today="2026-08-01") for i in range(10)
)
log_file.write_text(body, encoding="utf-8")
monkeypatch.setattr(config, "LOG_FILE", log_file)
log_status()
out = capsys.readouterr().out
assert "Ingests since last lint: 10" in out
assert "Threshold reached" in out