ver 1.2
This commit is contained in:
@@ -38,6 +38,29 @@ def test_frontmatter_existing_json_is_preserved() -> None:
|
||||
assert echo.normalize_json_scalar('"2026-06-20"') == b'"2026-06-20"'
|
||||
|
||||
|
||||
def test_read_many_dedups_and_maps_each_path() -> None:
|
||||
# Concurrency helper contract, no network: monkeypatch the per-file fetch.
|
||||
orig = echo.get_text
|
||||
echo.get_text = lambda p: f"T:{p}"
|
||||
try:
|
||||
assert echo.read_many(["a", "b", "a"]) == {"a": "T:a", "b": "T:b"}
|
||||
finally:
|
||||
echo.get_text = orig
|
||||
|
||||
|
||||
def test_read_many_empty_returns_empty_dict() -> None:
|
||||
assert echo.read_many([]) == {}
|
||||
|
||||
|
||||
def test_read_many_tolerates_unreadable_file_as_none() -> None:
|
||||
orig = echo.get_text
|
||||
echo.get_text = lambda p: None if p == "bad" else f"T:{p}"
|
||||
try:
|
||||
assert echo.read_many(["ok", "bad"]) == {"ok": "T:ok", "bad": None}
|
||||
finally:
|
||||
echo.get_text = orig
|
||||
|
||||
|
||||
def test_stem_extracts_literal_directory_prefix() -> None:
|
||||
assert check_routing.stem(r"^projects/active/[^/]+\.md$") == "projects/active/"
|
||||
assert check_routing.stem(r"^areas/(business|personal)/[^/]+\.md$") == "areas/"
|
||||
@@ -86,6 +109,44 @@ def test_kind_for_path() -> None:
|
||||
assert echo_index.kind_for_path("journal/daily/2026-01-01.md") is None
|
||||
|
||||
|
||||
def test_derive_aliases_produces_punctuation_variants() -> None:
|
||||
al = echo_index.derive_aliases("ECHO Memory")
|
||||
assert "echo-memory" in al and "echo memory" in al
|
||||
assert echo_index.derive_aliases("") == []
|
||||
|
||||
|
||||
def test_upsert_folds_in_title_variants_and_drops_slug() -> None:
|
||||
index = {"entities": {}}
|
||||
e = echo_index.upsert(index, "echo-memory", "projects/active/echo-memory.md",
|
||||
"project", "Echo Memory")
|
||||
assert "echo memory" in e["aliases"] # space variant auto-derived
|
||||
assert "echo-memory" not in e["aliases"] # equals the slug -> not stored redundantly
|
||||
|
||||
|
||||
def test_fuzzy_candidates_finds_shortened_name() -> None:
|
||||
# The real bug: a project slugged "echo" must surface for the mention "echo memory".
|
||||
index = {"entities": {"echo": {"path": "projects/active/echo.md", "kind": "project",
|
||||
"title": "echo", "aliases": []}}}
|
||||
cands = echo_index.fuzzy_candidates(index, "echo memory")
|
||||
assert cands and cands[0][0] == "echo"
|
||||
# exact resolve still misses (it's exact-only) — fuzzy is the safety net:
|
||||
assert echo_index.resolve(index, "echo memory")[0] is None
|
||||
|
||||
|
||||
def test_fuzzy_candidates_ignores_common_and_short_tokens() -> None:
|
||||
index = {"entities": {"data": {"path": "x.md", "kind": "concept",
|
||||
"title": "data", "aliases": []}}}
|
||||
assert echo_index.fuzzy_candidates(index, "data pipeline") == []
|
||||
|
||||
|
||||
def test_aliases_in_frontmatter_flow_and_block() -> None:
|
||||
flow = '---\ntype: project\naliases: ["echo memory", "echo plugin"]\n---\n# x\n'
|
||||
assert echo_index.aliases_in_frontmatter(flow) == ["echo memory", "echo plugin"]
|
||||
block = "---\ntype: project\naliases:\n - echo memory\n - echo plugin\n---\n# x\n"
|
||||
assert echo_index.aliases_in_frontmatter(block) == ["echo memory", "echo plugin"]
|
||||
assert echo_index.aliases_in_frontmatter("# no frontmatter\n") == []
|
||||
|
||||
|
||||
def test_links_add_related_is_idempotent_and_bidirectional_token() -> None:
|
||||
text = "---\ntype: person\n---\n\n# Bob\n\n## Related\n"
|
||||
new, changed = echo_links.add_related(text, "resources/companies/mpm.md")
|
||||
|
||||
Reference in New Issue
Block a user