From daf898314ca5852310f333a34a133d8fb60ddd2d Mon Sep 17 00:00:00 2001 From: Luke Maj Date: Wed, 14 Oct 2026 13:15:06 +0200 Subject: [PATCH] feat(serve)!: load flat YAML Libraries for exact keys and Cue --- CHANGELOG.md | 6 + GLOSSARY.md | 4 +- README.md | 90 +- VERSION | 2 +- contextmd/serve/__main__.py | 52 +- contextmd/serve/card.py | 13 +- contextmd/serve/config.py | 2 +- contextmd/serve/store.py | 527 ++++++---- docs/map.md | 3 +- tests/library-corpus.json | 1882 +++++++++++++++++++++++++++++++++++ tests/test_library.py | 206 ++++ tests/test_serve.py | 24 +- 12 files changed, 2581 insertions(+), 230 deletions(-) create mode 100644 tests/library-corpus.json create mode 100644 tests/test_library.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a18e86..cab4a95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [1.0.0] - 2026-10-14 + +### Changed + +- Flat YAML Libraries replace recursive stores, derive exact-key and Cue membership from one header, preserve long knowledge as full-read pointers, and discover project Libraries by convention. + ## [0.6.3] - 2026-10-14 ### Changed diff --git a/GLOSSARY.md b/GLOSSARY.md index 3a8c6dd..4314f00 100644 --- a/GLOSSARY.md +++ b/GLOSSARY.md @@ -9,8 +9,8 @@ once in Chromeria's system glossary, ## Serving **Entry**: -One Markdown file in an entry directory that ContextMD can serve: its keys and -a body. +One Markdown file in a flat Library, with a valid YAML header choosing +exact-key serving, Cue serving or both, and a body holding the knowledge. Its version is a hash of the file, so an edited entry counts as new. **Matcher**: diff --git a/README.md b/README.md index 5a5667c..d24253b 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,62 @@ store check and the hook installer. Sessions outside Chromeria are not served. Requirements: Python 3.12, `curl`, and a Chromeria build with the serving module. +### Library entries + +A Library is one flat folder, with one Markdown file per entry. A joined +Chromeria thread discovers its checkout's `library/`, including when the +project is registered at a subdirectory or the thread uses a worktree. +A non-Git project uses its registered directory. The hook's cwd does not +choose the Library. Registered `exact_keys` and `cue` folders are also flat; +subfolders and `README.md` are skipped. + +The header chooses exact-key serving (`command`, `path` or `error`), Cue +serving (`name` and `applies`), or both. The body holds the knowledge. +`docs/`, `GLOSSARY.md` and ADRs stay where they are; `target` can reference +one of those records, relative to the entry or with a leading `~/`. + +New headers use a YAML 1.2 subset: plain strings, single-quoted strings, +JSON-style double-quoted strings, and one-line flow string lists for keys +(for example, `command: [git push, git fetch]`). Quote values containing +`: `, starting with a YAML indicator such as `*`, or looking like a number +or boolean. `must-know-before` takes a boolean. Repeated or unknown fields, +empty values, block lists, nested collections, anchors, tags, multiline +scalars and trailing comments are rejected. Command keys need at least one +word; error keys cannot consist only of whitespace. Validate new entries independently +of registered-store compatibility: + +```sh +bin/contextmd-serve check --entry library/example.md +bin/contextmd-serve check --project /path/to/project +``` + +Both commands list errors with the file and reason and exit 1 on errors. +The first validates strictly, without reading serving configuration. The +second checks that project's discovered Library and configured Libraries. +Project entries load first; ids are unique per matcher, and an incoming +entry with both matchers is rejected wholly on either collision. + +Bodies up to 1,800 UTF-8 bytes are served whole when the harness has room; +optional Cue display text shrinks first. Longer bodies remain in the file +and serve as `Read in full.` An authored `target` is also named +when the body is omitted. A tight deny limit can require the same self-read +for a short body. If even a complete read instruction cannot fit, the log +records `cut_budget`. + +During the reader transition, registered folders temporarily tolerate +repeated key fields and legacy unquoted colon text, reported in `legacy`. +Legacy warnings alone do not fail the store check. Project Libraries and +`check --entry` stay strict. While any intended reader of a shared Library +runs an older build, writers keep the old form: plain values, one matcher's +fields and a body at most 1,800 bytes, validated by the store check. Old +readers can misresolve quoted targets and cannot serve mixed headers, +flow lists or long bodies. Switch shared writers to strict YAML only after +every intended reader upgrades; then convert legacy files and retire the +temporary serving tolerance. Historical serve cards keep reading old bytes. + ### Exact-key entries -Each entry is one Markdown file in a store directory: +For example: ```markdown --- @@ -41,27 +94,27 @@ Answer every prompt of the PR template before opening a PR. because agents often run `cmd; echo "exit=$?"`, so the call itself succeeds, and Codex reports no failure at all. A printed non-zero exit (`exit=1`, `exit code 2`) also marks the call failed. -- `target` (must-know-before entries only) makes a pointer rule: the deny names +- `target` on a short must-know-before entry makes a pointer rule: the deny names that file, relative to the entry, and the rule lifts once the agent is seen - reading it. Without `target` the rule text is in the deny itself. -- Keys may repeat; any one match serves the entry. The body must stay under - 1,800 UTF-8 bytes, because Claude Code shows only a 2 KB preview of larger - hook context. -- `id` defaults to the file name and must stay within 120 characters. + reading it in full. Without `target` a short rule that fits is in the deny + itself. +- Keys take a string or a non-empty flow string list; any one match serves + the entry. +- `id` defaults to the file name without `.md` and must stay within 120 + Unicode code points. - The entry version is a hash of the file, so an edited entry counts as new. ### Cue entries Cue serves knowledge whose moment has no trigger words, such as a research procedure that applies whenever a request asks for facts beyond what is at -hand. Each Cue entry is one Markdown file in a Cue directory, which must not -lie inside an exact-key directory (each loader rejects the other's fields): +hand. Cue entries share the same flat Library as exact-key entries: ```markdown --- id: agentsmd-research name: Research -applies: The request asks a question whose answer is facts beyond what is at hand. Not: ... +applies: 'The request asks a question whose answer is facts beyond what is at hand. Not: ...' target: ../skills/operations/procedures/research/index.md --- AgentsMD: follow the research procedure. @@ -70,7 +123,7 @@ AgentsMD: follow the research procedure. - Cue scores `: `, so those texts must match what the deployed adapter was trained on; edit them only together with retraining (#4). - An entry that scores at or above the adapter's threshold is served with its - `applies` line first (cut at 600 characters), so the agent can dismiss a + `applies` line first (at most 600 code points), so the agent can dismiss a wrong fire in one read, then the body and "Read `` in full." - `target` is optional and relative to the entry. The body, `id` and version follow the exact-key rules. @@ -83,7 +136,7 @@ AgentsMD: follow the research procedure. | --- | --- | | Session start | The session-start files, outside the turn budgets (Claude Code). After compaction or `/clear` a new context epoch starts and they are served again. | | User message | A new Chromeria run is a new turn: an 8,000-byte serve budget and a 2,000-byte deny budget. Cue scores the conversation and its fires are served at once (on Grok, at the next `PreToolUse`). | -| Before a tool call | A matching must-know-before entry denies the call. A pointer rule keeps denying until the agent reads its target in this session and context epoch; an inline rule lifts once the model was shown it whole. After 3 denies without that, the next call passes, logged `not_read_capped`. One deny carries every whole rule that fits; the rest deny their next matching call. | +| Before a tool call | A matching must-know-before entry denies the call. A record-pointer rule keeps denying until a full read of its target in this session and context epoch; an entry self-pointer needs a full read after that version's first deny. An inline rule lifts once the model was shown it whole. After 3 denies without that, the next call passes, logged `not_read_capped`. One deny carries every whole rule that fits; the rest deny their next matching call. | | Tool result or failure | Other matching entries and the Cue fires, first fit within the serve budget and 2,000 bytes per output. On Grok, which discards this output, they are printed at the next `PreToolUse`. | | Before done | Logged only. | @@ -118,9 +171,10 @@ The stores and session-start files are named in `~/.config/contextmd/serving.jso } ``` -Cue is off unless both `cue` and `cue_url` are set. Add them only once every -Chromeria server reading the file has the Cue lane: an older server rejects a -config with unknown keys and then serves nothing. +Cue runs when `cue_url` is set and a loaded Library has Cue entries; those +entries may come from the project's conventional Library or either configured +list. Add Cue configuration only once every Chromeria reader supports it: +an older server rejects unknown config keys and then serves nothing. Install the hook per harness for the Chromeria base directory: @@ -279,6 +333,12 @@ command. Cards hold transcript text, so keep them on the machine. Run the tests with `python3 -m unittest discover -s tests -t .`. The contract suite in `tests/test_contract.py` runs the real hook against a Chromeria dev server when `CONTEXTMD_CHROMERIA` names a Chromeria checkout. +The standalone Library test compares the shared corpus copies without +starting a server: + +```sh +CONTEXTMD_CHROMERIA=/path/to/chromeria python3 -B -m unittest tests.test_library +``` ## Cue service diff --git a/VERSION b/VERSION index 844f6a9..3eefcb9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.6.3 +1.0.0 diff --git a/contextmd/serve/__main__.py b/contextmd/serve/__main__.py index ba4923e..747acc6 100644 --- a/contextmd/serve/__main__.py +++ b/contextmd/serve/__main__.py @@ -37,7 +37,10 @@ def main(argv=None) -> int: lp = sub.add_parser("log") lp.add_argument("--base", required=True, type=Path) lp.add_argument("--session") - sub.add_parser("check") + check = sub.add_parser("check") + inputs = check.add_mutually_exclusive_group() + inputs.add_argument("--entry", nargs="+", type=Path, help="strictly validate newly authored YAML entries") + inputs.add_argument("--project", type=Path, help="also check this project's conventional Library") rp = sub.add_parser("report") rp.add_argument("--base", required=True, type=Path) rp.add_argument("--since", help="ISO date or time, UTC unless it names a zone") @@ -64,19 +67,44 @@ def main(argv=None) -> int: cp.add_argument("--json", action="store_true", help="the card as JSON, for the outcome judge") ns = ap.parse_args(argv) if ns.cmd == "check": + if ns.entry: + entries, errors = [], [] + for file in ns.entry: + try: + parsed = store.parse_file(file.expanduser().absolute()) + exact, intent = parsed.views() + entries.append({"file": parsed.path, "id": parsed.id, "version": parsed.version, + "matchers": (["exact_key"] if exact else []) + (["intent"] if intent else []), + "long": parsed.long}) + except (store.EntryError, OSError) as exc: + errors.append(f"{file}: {exc}") + print(json.dumps({"entries": entries, "errors": errors}, indent=2)) + return 1 if errors else 0 cfg = config.load() - st, cue = store.load(cfg.exact_keys), store.load_cue(cfg.cue) - print(json.dumps({ - "exact_keys": {"entries": [{"id": e.id, "version": e.version, "must_know_before": e.must_know_before, - "target": e.target, "bytes": len(e.text.encode())} for e in st.entries], - "owners": st.owners, "errors": st.errors}, + directory = store.library_dir(str(ns.project)) if ns.project else None + sources = ([store.Source(directory, False)] if directory else []) + cfg.exact_keys + cfg.cue + library = store.load(sources) + exact_files = {e.path for e in library.entries} + cue_files = {e.path for e in library.cue} + def row(e): + return {"id": e.id, "version": e.version, "target": e.target, "file": e.path, + "bytes": len(e.text.encode()), "long": e.long, "legacy": e.legacy, + "matchers": (["exact_key"] if e.path in exact_files else []) + (["intent"] if e.path in cue_files else [])} + report = { + "exact_keys": {"entries": [{**row(e), "must_know_before": e.must_know_before} for e in library.entries], + "owners": library.owners, "errors": library.errors, "legacy": library.legacy}, "cue": {"url": cfg.cue_url, - "entries": [{"id": e.id, "version": e.version, "name": e.name, "target": e.target, - "applies_chars": len(e.applies), "bytes": len(e.text.encode())} - for e in cue.entries], - "owners": cue.owners, "errors": cue.errors}, - }, indent=2)) - return 1 if st.errors or cue.errors else 0 + "entries": [{**row(e), "name": e.name, "applies_chars": len(e.applies)} for e in library.cue], + "owners": library.owners, "errors": library.errors, "legacy": library.legacy}, + } + if ns.project: + project_entries = {e.path: e for e in [*library.entries, *library.cue] + if directory and Path(e.path).parent == Path(directory)} + report["project"] = {"entries": [row(e) for e in project_entries.values()], + "owners": {directory: library.owners[directory]} if directory in library.owners else {}, + "errors": library.errors, "legacy": library.legacy} + print(json.dumps(report, indent=2)) + return 1 if library.errors else 0 base = ns.base.expanduser().resolve() if ns.cmd == "health": return _health(ns, base) diff --git a/contextmd/serve/card.py b/contextmd/serve/card.py index c82d4ff..3c5374d 100644 --- a/contextmd/serve/card.py +++ b/contextmd/serve/card.py @@ -86,15 +86,17 @@ def rule_text(row: dict, db_path: Path) -> dict: root = Path(directory) if not root.is_dir(): continue - for path in sorted(root.rglob("*.md")): + for path in store.entry_files(root): try: - entry = store.parse(path) + entry = store.parse_file(path, tolerant=True) except (ValueError, UnicodeDecodeError): continue if entry.id != row["entry"]: continue if entry.version == row["version"]: - return {"source": "store", "text": entry.text, "target": entry.target} + exact, cue = entry.views() + view = exact or cue + return {"source": "store", "text": entry.body, "target": view.target} found = _from_history(path, row["version"]) if found: return found @@ -166,10 +168,11 @@ def git(*args): raw = git("show", f"{rev}:{rel}").stdout if raw and hashlib.sha256(raw).hexdigest()[:12] == version: try: - entry = store.parse(path, raw) + entry = store.parse_file(path, raw, tolerant=True) except (ValueError, UnicodeDecodeError): return None - return {"source": "store_history", "text": entry.text, "target": entry.target, "commit": rev} + exact, cue = entry.views() + return {"source": "store_history", "text": entry.body, "target": (exact or cue).target, "commit": rev} return None diff --git a/contextmd/serve/config.py b/contextmd/serve/config.py index 3c0be1d..84bcb5c 100644 --- a/contextmd/serve/config.py +++ b/contextmd/serve/config.py @@ -6,7 +6,7 @@ - ``exact_keys``: store directories (default ``~/.local/share/contextmd/exact-keys``) - ``session_start``: files served at session start and after compaction, each ``{"path": ..., "max_chars": ...}``; they sit outside the turn budgets -- ``cue``: Cue entry directories (default none), never inside an ``exact_keys`` directory +- ``cue``: registered Library directories (default none); header fields choose each entry's matchers - ``cue_url``: the Cue service, such as ``http://100.116.0.2:8710``; without it Cue is off Serving state (budgets, deny state, the log) lives in the Chromeria serving module. diff --git a/contextmd/serve/store.py b/contextmd/serve/store.py index 4c5965c..56b1145 100644 --- a/contextmd/serve/store.py +++ b/contextmd/serve/store.py @@ -1,60 +1,34 @@ -"""The exact-key store: Markdown entries keyed by command, path or error. - -Each entry is one ``.md`` file in a store directory:: - - --- - id: pr-template - command: gh pr create - path: .github/** - error: permission denied (publickey) - must-know-before: true - --- - Answer every prompt of the PR template before opening a PR. - -``command``, ``path`` and ``error`` may repeat; any one key matching serves the -entry. ``id`` defaults to the file name. A must-know-before entry with -``target: `` is a pointer rule: its deny names the file, and it lifts once -the agent is seen reading that file. Without ``target`` it is an inline rule, -whose text is in the deny itself. A relative target is relative to the entry's -directory. The version is derived from the file -bytes, so editing an entry makes it new for deny-once. Store directories are -usually owner repositories (a Library, the Great Library); the commit each -was loaded at goes into the serving log. - -Cue entries live in their own directories (the ``cue`` list of the serving -config), never inside an exact-key directory, because each loader rejects the -other's fields:: - - --- - id: agentsmd-research - name: Research - applies: The request asks a question whose answer is facts beyond what is at hand. Not: ... - target: ../skills/operations/procedures/research/index.md - --- - AgentsMD: follow the research procedure. - -Cue scores ``": "`` (the text it was trained on, so it is never -rewritten for display). ``target`` is optional; the served text ends with -"Read in full." -""" +"""Flat Libraries: strict YAML headers, exact-key and Cue views of one entry. +Registered stores temporarily tolerate repeated keys and unquoted colon text. +New entries use strict ``parse_file``; historical card reads may opt into tolerance. +""" from __future__ import annotations import hashlib +import json import os +import re from dataclasses import dataclass, field from pathlib import Path +from stat import S_ISREG from .keys import Keys, glob_regex, normalize_error -# Claude Code moves hook context over its limit into a file and shows the model -# a 2 KB preview (canary, #5), so one entry must fit well inside that, in UTF-8 bytes. MAX_ENTRY_BYTES = 1800 -# Entry ids appear in logs and in the short deny pointer, which must stay small. MAX_ID_CHARS = 120 -KEY_FIELDS = ("command", "path", "error") -OTHER_FIELDS = ("id", "must-know-before", "target") -CUE_FIELDS = ("id", "name", "applies", "target") +KEY_FIELDS = ('command', 'path', 'error') +FIELDS = ('id', *KEY_FIELDS, 'must-know-before', 'name', 'applies', 'target') +CONTROL = re.compile(r'[\x00-\x08\x0a-\x1f\x7f-\x9f]') +PLAIN_INVALID = re.compile(r'[\ufeff\ufffe\uffff]') +ERROR_BLANK = re.compile(r'^[\u0009-\u000d\u001c-\u001f\u0020\u0085\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+$') +NUMBER = re.compile(r'^(?:0o[0-7]+|[-+]?[0-9]+|0x[0-9a-fA-F]+|[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN|[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+|[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*))$') + + +class EntryError(ValueError): + def __init__(self, code, reason, line=None, field=None): + self.code, self.reason, self.line, self.field = code, reason, line, field + super().__init__((f'line {line}: ' if line else '') + reason) @dataclass @@ -63,35 +37,29 @@ class Entry: version: str text: str must_know_before: bool = False - path: str = "" + path: str = '' target: str | None = None commands: list[list[str]] = field(default_factory=list) paths: list[str] = field(default_factory=list) errors: list[str] = field(default_factory=list) + long: bool = False + legacy: str | None = None def matches(self, keys: Keys) -> str | None: - """The first key of this entry that matches, as ``kind:value``, else None.""" for prefix in self.commands: if keys.has_command(prefix): - return "command:" + " ".join(prefix) + return 'command:' + ' '.join(prefix) for pattern in self.paths: rx = glob_regex(pattern) if any(rx.match(p) for p in keys.paths): - return "path:" + pattern + return 'path:' + pattern if keys.error: for sig in self.errors: if sig in keys.error: - return "error:" + sig + return 'error:' + sig return None -@dataclass -class Store: - entries: list[Entry] - owners: dict[str, str | None] - errors: list[str] - - @dataclass class CueEntry: id: str @@ -99,13 +67,54 @@ class CueEntry: name: str applies: str text: str - path: str = "" + path: str = '' target: str | None = None + long: bool = False + legacy: str | None = None @property def doc(self) -> str: - """What Cue scores: the entry as it was trained on.""" - return f"{self.name}: {self.applies}" + return f'{self.name}: {self.applies}' + + +@dataclass +class Parsed: + id: str + version: str + path: str + body: str + fields: dict + long: bool + legacy: str | None = None + + def views(self): + f = self.fields + target = _target(f['target'], Path(self.path)) if 'target' in f else None + common = dict(id=self.id, version=self.version, text=self.body, path=self.path, + target=target, long=self.long, legacy=self.legacy) + def values(name): + v = f.get(name, []) + return v if isinstance(v, list) else [v] + exact = Entry(**common, must_know_before=f.get('must-know-before', False), + commands=[re.split(r'[ \t]+', c.strip(' \t')) for c in values('command')], + paths=values('path'), errors=[normalize_error(e) for e in values('error')]) if any(k in f for k in KEY_FIELDS) else None + cue = CueEntry(**common, name=f['name'], applies=f['applies']) if 'name' in f else None + return exact, cue + + +@dataclass +class Source: + directory: str + registered: bool = True + + +@dataclass +class Library: + entries: list[Entry] + cue: list[CueEntry] + owners: dict[str, str | None] + errors: list[str] + legacy: list[str] @dataclass @@ -113,155 +122,307 @@ class CueStore: entries: list[CueEntry] owners: dict[str, str | None] errors: list[str] + legacy: list[str] -def _front_matter(path: Path, allowed, raw: bytes | None = None) -> tuple[bytes, dict[str, list[str]], str]: - """The file bytes, its front-matter fields and its body; raises on a malformed entry.""" - raw = path.read_bytes() if raw is None else raw - text = raw.decode("utf-8") - lines = text.split("\n") - if not lines or lines[0].strip() != "---": - raise ValueError("missing front matter") +def _scalar(value, line, tolerant=False): + if not value: + return None + if value[0] == "'": + out, i = '', 1 + while i < len(value): + if value[i] == "'": + if i + 1 < len(value) and value[i + 1] == "'": + out += "'" + i += 2 + continue + if value[i + 1:].strip(' \t'): + raise EntryError('syntax', 'unexpected text after quoted value', line) + break + out += value[i] + i += 1 + else: + raise EntryError('syntax', 'unclosed quoted value', line) + elif value[0] == '"': + try: + # YAML permits raw tabs; the shared control policy still checks the decoded string. + out = json.loads(value, strict=False) + except ValueError: + raise EntryError('syntax', 'invalid quoted value', line) from None + else: + if PLAIN_INVALID.search(value): + raise EntryError('syntax', 'invalid character in plain value or comment', line) + if re.search(r'[ \t]#', value): + raise EntryError('syntax', 'trailing comments are unsupported; quote the value', line) + legacy = value[0] in '*@`%' or bool(re.search(r':[ \t]|:$', value)) + if value[0] in '-?:,[]{}#&*!|>\'"%@`' or legacy: + if not (tolerant and legacy and value[0] not in '[\'"' and value[0] not in '-?:,]{}#&!|>'): + raise EntryError('syntax', 'quote the value', line) + if not legacy: + if value in ('~', 'null', 'Null', 'NULL'): + return None + if value in ('true', 'True', 'TRUE', 'false', 'False', 'FALSE'): + return value.lower() == 'true' + if NUMBER.fullmatch(value): + return 0 # All numeric fields are rejected by the typed header below. + out = value + if CONTROL.search(out) or any(0xD800 <= ord(c) <= 0xDFFF for c in out): + raise EntryError('syntax', 'control character or lone surrogate in value', line) + return out + + +def _value(value, line, tolerant): + if not value.startswith('['): + return _scalar(value, line, tolerant) + if not value.endswith(']'): + raise EntryError('syntax', 'unclosed flow list', line) + inner = value[1:-1] + if not inner.strip(' \t'): + return [] + parts, start, quote, i = [], 0, None, 0 + while i < len(inner): + c = inner[i] + if quote: + if quote == '"' and c == '\\': + i += 2 + continue + if c == quote: + if quote == "'" and i + 1 < len(inner) and inner[i + 1] == "'": + i += 2 + continue + quote = None + elif c in '\'"' and not inner[start:i].strip(' \t'): + quote = c + elif c in '[]{}': + raise EntryError('syntax', 'nested collections are unsupported', line) + elif c == ',': + parts.append(inner[start:i].strip(' \t')) + start = i + 1 + i += 1 + parts.append(inner[start:].strip(' \t')) + if quote or any(not p for p in parts): + raise EntryError('syntax', 'invalid flow list', line) + return [_scalar(p, line) for p in parts] + + +def _strict(path, raw, tolerant): try: - end = lines.index("---", 1) - except ValueError: - raise ValueError("front matter is not closed") from None - fields: dict[str, list[str]] = {} - for line in lines[1:end]: - if not line.strip(): + text = raw.decode('utf-8') + except UnicodeDecodeError: + raise EntryError('encoding', 'not UTF-8') from None + text = text.removeprefix('\ufeff').replace('\r\n', '\n') + if '\r' in text: + raise EntryError('encoding', 'bare carriage return', text[:text.index('\r')].count('\n') + 1) + lines = text.split('\n') + if lines[0].rstrip(' \t') != '---': + raise EntryError('no_header', 'missing front matter') + end = next((i for i in range(1, len(lines)) if lines[i].rstrip(' \t') == '---'), None) + if end is None: + raise EntryError('no_header', 'front matter is not closed') + fields, locations = {}, {} + for i, line in enumerate(lines[1:end], 2): + if CONTROL.search(line): + raise EntryError('encoding', 'control character in header', i) + if not line.strip(' \t'): continue - name, sep, value = line.partition(":") - if not sep: - raise ValueError(f"not a 'name: value' line: {line!r}") - fields.setdefault(name.strip(), []).append(value.strip()) - unknown = set(fields) - set(allowed) + if re.match(r'^ *#', line): + if PLAIN_INVALID.search(line): + raise EntryError('syntax', 'invalid character in plain value or comment', i) + continue + m = re.fullmatch(r'([A-Za-z_][A-Za-z0-9_-]*):(?:[ \t]+(.*))?', line) + if not m: + raise EntryError('syntax', 'expected a field at column zero', i) + name, value = m[1], (m[2] or '').strip(' \t') + if name in fields and not (tolerant and name in KEY_FIELDS): + raise EntryError('duplicate_field', 'repeated field; use a flow list', i, name) + parsed = _value(value, i, tolerant) + if name in fields: + old = fields[name] + fields[name] = (old if isinstance(old, list) else [old]) + (parsed if isinstance(parsed, list) else [parsed]) + else: + fields[name], locations[name] = parsed, i + unknown = sorted(set(fields) - set(FIELDS)) if unknown: - raise ValueError(f"unknown fields: {sorted(unknown)}") - body = "\n".join(lines[end + 1:]).strip() - if not body: - raise ValueError("empty body") - if len(body.encode()) > MAX_ENTRY_BYTES: - raise ValueError(f"body is {len(body.encode())} UTF-8 bytes, over {MAX_ENTRY_BYTES}") - return raw, fields, body - - -def _entry_id(fields: dict[str, list[str]], path: Path) -> str: - entry_id = (fields.get("id") or [path.stem])[-1] + raise EntryError('unknown_field', f'unknown fields: {unknown}') + for name in FIELDS: + if name not in fields: + continue + v = fields[name] + if v is None or v == '' or v == []: + raise EntryError('empty_value', 'empty field value', locations[name], name) + values = v if isinstance(v, list) and name in KEY_FIELDS else [v] + for item in values: + if item is None or item == '': + raise EntryError('empty_value', 'empty field value', locations[name], name) + if (type(item) is not bool if name == 'must-know-before' else not isinstance(item, str)): + raise EntryError('wrong_type', 'wrong field type', locations[name], name) + if name == 'command' and not item.strip(' \t'): + raise EntryError('empty_value', 'empty command key', locations[name], name) + if name == 'error' and ERROR_BLANK.fullmatch(item): + raise EntryError('empty_value', 'empty error key', locations[name], name) + entry_id = fields.get('id', path.name[:-3]) + if not entry_id: + raise EntryError('empty_value', 'empty entry id', field='id') if len(entry_id) > MAX_ID_CHARS: - raise ValueError(f"id is {len(entry_id)} characters, over {MAX_ID_CHARS}") - return entry_id + raise EntryError('id_too_long', f'id is {len(entry_id)} characters, over {MAX_ID_CHARS}', field='id') + body = '\n'.join(lines[end + 1:]).strip(' \t\n') + if not body: + raise EntryError('empty_body', 'empty body') + exact, cue = any(k in fields for k in KEY_FIELDS), any(k in fields for k in ('name', 'applies')) + if not exact and not cue: + raise EntryError('no_matcher', 'no command, path or error key or Cue fields') + if cue and not all(k in fields for k in ('name', 'applies')): + missing = 'name' if 'name' not in fields else 'applies' + raise EntryError('cue_incomplete', f'no {missing}') + if fields.get('must-know-before') and not exact: + raise EntryError('must_know_without_key', 'must-know-before needs an exact key') + return Parsed(entry_id, hashlib.sha256(raw).hexdigest()[:12], str(path), body, fields, + len(body.encode('utf-8')) > MAX_ENTRY_BYTES) + + +def parse_file(path: Path, raw: bytes | None = None, *, tolerant=False) -> Parsed: + raw = path.read_bytes() if raw is None else raw + try: + return _strict(path, raw, False) + except EntryError as strict: + if not tolerant: + raise + result = _strict(path, raw, True) + result.legacy = str(strict) + return result def _target(value: str, path: Path) -> str: - return os.path.realpath(os.path.join(path.parent, os.path.expanduser(value))) + if value == '~': + value = str(Path.home()) + elif value.startswith(('~/', '~\\')): + value = os.path.join(Path.home(), value[2:]) + lexical = os.path.abspath(os.path.join(path.parent, value)) + return os.path.realpath(lexical) if os.path.exists(lexical) else lexical def parse(path: Path, raw: bytes | None = None) -> Entry: - """The entry in ``path``, or in ``raw`` read from that path at another commit.""" - raw, fields, body = _front_matter(path, {*OTHER_FIELDS, *KEY_FIELDS}, raw) - flag = (fields.get("must-know-before") or ["false"])[-1].lower() - if flag not in ("true", "false"): - raise ValueError("must-know-before is not true or false") - target = (fields.get("target") or [None])[-1] - if target is not None: - if flag != "true": - raise ValueError("target is only for must-know-before entries") - target = _target(target, path) - entry = Entry( - id=_entry_id(fields, path), - version=hashlib.sha256(raw).hexdigest()[:12], - text=body, - must_know_before=flag == "true", - path=str(path), - target=target, - commands=[c.split() for c in fields.get("command", []) if c.split()], - paths=[p for p in fields.get("path", []) if p], - errors=[normalize_error(e) for e in fields.get("error", []) if e], - ) - if not (entry.commands or entry.paths or entry.errors): - raise ValueError("no command, path or error key") + entry, _ = parse_file(path, raw).views() + if entry is None: + raise EntryError('no_matcher', 'no command, path or error key') return entry def parse_cue(path: Path) -> CueEntry: - raw, fields, body = _front_matter(path, CUE_FIELDS) - name = (fields.get("name") or [""])[-1] - applies = (fields.get("applies") or [""])[-1] - if not name: - raise ValueError("no name") - if not applies: - raise ValueError("no applies") - target = (fields.get("target") or [None])[-1] - return CueEntry( - id=_entry_id(fields, path), - version=hashlib.sha256(raw).hexdigest()[:12], - name=name, - applies=applies, - text=body, - path=str(path), - target=_target(target, path) if target else None, - ) + _, cue = parse_file(path, tolerant=True).views() + if cue is None: + raise EntryError('cue_incomplete', 'no name or applies') + return cue + + +def library_dir(thread_dir: str) -> str | None: + original = Path(thread_dir).expanduser() + if not original.is_dir(): + return None + original = original.resolve() + root = original + for candidate in (original, *original.parents): + dot = candidate / '.git' + if dot.is_dir() or dot.is_file(): + root = candidate + break + library = root / 'library' + return str(library.resolve()) if library.is_dir() else None + + +def entry_files(root: Path): + return [p for p in _listed_entries(root) if p.is_file()] + + +def _listed_entries(root: Path): + return sorted((p for p in root.iterdir() if p.name.endswith('.md') and p.name.lower() != 'readme.md'), key=lambda p: p.name) + def head_commit(directory: Path) -> str | None: """The commit checked out in the repository holding ``directory``, read without git.""" - d = directory.resolve() - while True: - dot = d / ".git" - if dot.is_file(): # a worktree: "gitdir: " - dot = Path(dot.read_text().split(":", 1)[1].strip()) - if not dot.is_absolute(): - dot = d / dot - if dot.is_dir(): - head = (dot / "HEAD").read_text().strip() - if not head.startswith("ref: "): - return head - ref = head[5:] - common = dot - if (dot / "commondir").exists(): - common = (dot / (dot / "commondir").read_text().strip()).resolve() - for base in (dot, common): - if (base / ref).exists(): - return (base / ref).read_text().strip() - packed = common / "packed-refs" - if packed.exists(): - for line in packed.read_text().splitlines(): - sha, _, name = line.partition(" ") - if name == ref: - return sha - return None - if d.parent == d: - return None - d = d.parent - - -def _load(directories: list[str], parser): - entries, owners, errors, seen = [], {}, [], {} - for directory in directories: - root = Path(os.path.expanduser(directory)) + try: + d = directory.resolve() + while True: + dot = d / ".git" + if dot.is_file(): # a worktree: "gitdir: " + dot = Path(dot.read_text().split(":", 1)[1].strip()) + if not dot.is_absolute(): + dot = d / dot + if dot.is_dir(): + head = (dot / "HEAD").read_text().strip() + if not head.startswith("ref: "): + return head + ref = head[5:] + common = dot + if (dot / "commondir").exists(): + common = (dot / (dot / "commondir").read_text().strip()).resolve() + for base in (dot, common): + if (base / ref).exists(): + return (base / ref).read_text().strip() + packed = common / "packed-refs" + if packed.exists(): + for line in packed.read_text().splitlines(): + sha, _, name = line.partition(" ") + if name == ref: + return sha + return None + if d.parent == d: + return None + d = d.parent + + except (OSError, UnicodeError, IndexError): + return None + + +def load(sources: list[Source | str]) -> Library: + sources = [Source(s) if isinstance(s, str) else s for s in sources] + registered = {os.path.realpath(os.path.expanduser(s.directory)) for s in sources if s.registered} + entries, cue, owners, errors, legacy = [], [], {}, [], [] + roots, exact_ids, cue_ids = set(), {}, {} + for source in sources: + root = Path(os.path.expanduser(source.directory)).resolve() + if root in roots: + continue + roots.add(root) if not root.is_dir(): - errors.append(f"{root}: not a directory") + if source.registered: + errors.append(f'{root}: not a directory') continue owners[str(root)] = head_commit(root) - for path in sorted(root.rglob("*.md")): - if ".git" in path.parts or path.name.lower() == "readme.md": - continue + try: + listed = _listed_entries(root) + except OSError: + errors.append(f'{root}: unreadable directory') + continue + for path in listed: try: - entry = parser(path) - except (ValueError, UnicodeDecodeError) as exc: - errors.append(f"{path}: {exc}") + if not S_ISREG(path.stat().st_mode): + continue + parsed = parse_file(path, tolerant=str(root) in registered) + exact, intent = parsed.views() + except OSError: + errors.append(f'{path}: unreadable') continue - if entry.id in seen: - errors.append(f"{path}: id {entry.id!r} already used by {seen[entry.id]}") + except EntryError as exc: + errors.append(f'{path}: {exc}') continue - seen[entry.id] = path - entries.append(entry) - return entries, owners, errors - - -def load(directories: list[str]) -> Store: - return Store(*_load(directories, parse)) + prior = exact_ids.get(parsed.id) if exact else None + prior = prior or (cue_ids.get(parsed.id) if intent else None) + if prior: + errors.append(f'{path}: id {parsed.id!r} already used by {prior}') + continue + if exact: + exact_ids[parsed.id] = path + entries.append(exact) + if intent: + cue_ids[parsed.id] = path + cue.append(intent) + if parsed.legacy: + legacy.append(f'{path}: {parsed.legacy}') + return Library(entries, cue, owners, errors, legacy) def load_cue(directories: list[str]) -> CueStore: - return CueStore(*_load(directories, parse_cue)) + library = load(directories) + return CueStore(library.cue, library.owners, library.errors, library.legacy) diff --git a/docs/map.md b/docs/map.md index 6d2cc88..88b0e78 100644 --- a/docs/map.md +++ b/docs/map.md @@ -77,7 +77,7 @@ flowchart TD RD["Readers called by path; OpenCode reservations"] %% RD: toolboxmd/chromeria#221 LF["Library format, flat"] - %% LF: #41 + %% LF: #41 toolboxmd/chromeria#268 PT["Pointer-trial retirement"] %% PT: #43 NC["Non-code capture"] @@ -121,6 +121,7 @@ flowchart TD EK --- CK EK --- RD LF -.-> ST + LF -.-> CI PT --> EK NC -.-> C EK -.-> RL diff --git a/tests/library-corpus.json b/tests/library-corpus.json new file mode 100644 index 0000000..de3fb45 --- /dev/null +++ b/tests/library-corpus.json @@ -0,0 +1,1882 @@ +{ + "version": 1, + "entries": [ + { + "name": "plain", + "file": "plain.md", + "text": "---\ncommand: git push\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "git push" + }, + "expect": { + "id": "plain", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "flow", + "file": "flow.md", + "text": "---\ncommand: [git push, \"gh pr create\"]\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": ["git push", "gh pr create"] + }, + "expect": { + "id": "flow", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "comma", + "file": "comma.md", + "text": "---\nerror: ['bad, outcome', 'it''s wrong']\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "error": ["bad, outcome", "it's wrong"] + }, + "expect": { + "id": "comma", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "apostrophe", + "file": "apostrophe.md", + "text": "---\ncommand: [it's fine, fetch]\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": ["it's fine", "fetch"] + }, + "expect": { + "id": "apostrophe", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "both", + "file": "both.md", + "text": "---\ncommand: [git push]\nname: Push\napplies: 'When pushing. Not: fetching.'\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": ["git push"], + "name": "Push", + "applies": "When pushing. Not: fetching." + }, + "expect": { + "id": "both", + "body": "Body.", + "long": false, + "exact": true, + "cue": true, + "legacy": false + } + }, + { + "name": "cue", + "file": "cue.md", + "text": "---\nname: Research\napplies: \"When facts: beyond reach.\"\ntarget: \"docs/record.md\"\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "name": "Research", + "applies": "When facts: beyond reach.", + "target": "docs/record.md" + }, + "expect": { + "id": "cue", + "body": "Body.", + "long": false, + "exact": false, + "cue": true, + "legacy": false + } + }, + { + "name": "target", + "file": "target.md", + "text": "---\ncommand: git push\ntarget: \"record.md\"\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "git push", + "target": "record.md" + }, + "expect": { + "id": "target", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "emoji-id", + "file": "emoji-id.md", + "text": "---\nid: πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€\ncommand: x\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "id": "πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€", + "command": "x" + }, + "expect": { + "id": "πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "json-pair", + "file": "json-pair.md", + "text": "---\nname: \"\\ud83d\\ude00\"\napplies: \"When.\"\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "name": "πŸ˜€", + "applies": "When." + }, + "expect": { + "id": "json-pair", + "body": "Body.", + "long": false, + "exact": false, + "cue": true, + "legacy": false + } + }, + { + "name": "escapes", + "file": "escapes.md", + "text": "---\ncommand: \"gh pr create\"\nerror: \"a\\/b\\u00e9\\twrong\"\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "gh pr create", + "error": "a/bΓ©\twrong" + }, + "expect": { + "id": "escapes", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "single", + "file": "single.md", + "text": "---\ncommand: 'it''s # not: commentary'\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "it's # not: commentary" + }, + "expect": { + "id": "single", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "tab", + "file": "tab.md", + "text": "---\ncommand:\tgit\tpush\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "git\tpush" + }, + "expect": { + "id": "tab", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "comment", + "file": "comment.md", + "text": "---\n# comment\ncommand: git push\n # another\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "git push" + }, + "expect": { + "id": "comment", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "nbsp", + "file": "nbsp.md", + "text": "---\ncommand: ghΒ pr\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "ghΒ pr" + }, + "expect": { + "id": "nbsp", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "core-string", + "file": "core-string.md", + "text": "---\ncommand: 1:30\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "1:30" + }, + "expect": { + "id": "core-string", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "bool", + "file": "bool.md", + "text": "---\ncommand: x\nmust-know-before: TRUE\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "x", + "must-know-before": true + }, + "expect": { + "id": "bool", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "dot", + "file": "a.b.md", + "text": "---\ncommand: x\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "x" + }, + "expect": { + "id": "a.b", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "nel", + "file": "nel.md", + "text": "---\ncommand: x\n---\nBody.Β…\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "x" + }, + "expect": { + "id": "nel", + "body": "Body.Β…", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "feff", + "file": "feff.md", + "text": "---\ncommand: x\n---\nBody.ο»Ώ\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "x" + }, + "expect": { + "id": "feff", + "body": "Body.ο»Ώ", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "1800", + "file": "1800.md", + "text": "---\ncommand: x\n---\nπŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "x" + }, + "expect": { + "id": "1800", + "body": "πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "1801", + "file": "1801.md", + "text": "---\ncommand: x\n---\nπŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€x\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "x" + }, + "expect": { + "id": "1801", + "body": "πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€x", + "long": true, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "long-target", + "file": "long-target.md", + "text": "---\ncommand: x\nmust-know-before: true\ntarget: \"record.md\"\n---\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "x", + "must-know-before": true, + "target": "record.md" + }, + "expect": { + "id": "long-target", + "body": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "long": true, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "tilde-user", + "file": "tilde-user.md", + "text": "---\ncommand: x\ntarget: ~someone/record.md\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "x", + "target": "~someone/record.md" + }, + "expect": { + "id": "tilde-user", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "unicode-error", + "file": "unicode-error.md", + "text": "---\nerror: Erreur Ω‘Ω’, id 34\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "error": "Erreur Ω‘Ω’, id 34" + }, + "expect": { + "id": "unicode-error", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "legacy-command", + "file": "legacy-command.md", + "text": "---\ncommand: git push\ncommand: gh pr create\ncommand: git commit\ncommand: gh pr merge\n---\nBody.\n", + "mode": "legacy", + "yaml": "invalid", + "fields": { + "command": ["git push", "gh pr create", "git commit", "gh pr merge"] + }, + "expect": { + "id": "legacy-command", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": true + } + }, + { + "name": "legacy-cue", + "file": "legacy-cue.md", + "text": "---\nname: Example\napplies: A: b; C: d; E: f. Not: later.\n---\nBody.\n", + "mode": "legacy", + "yaml": "invalid", + "fields": { + "name": "Example", + "applies": "A: b; C: d; E: f. Not: later." + }, + "expect": { + "id": "legacy-cue", + "body": "Body.", + "long": false, + "exact": false, + "cue": true, + "legacy": true + } + }, + { + "name": "legacy-path", + "file": "legacy-path.md", + "text": "---\npath: **/x.md\n---\nBody.\n", + "mode": "legacy", + "yaml": "invalid", + "fields": { + "path": "**/x.md" + }, + "expect": { + "id": "legacy-path", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": true + } + }, + { + "name": "duplicate", + "file": "duplicate.md", + "text": "---\ncommand: x\ncommand: y\n---\nBody.\n", + "mode": "strict", + "yaml": "invalid", + "error": { + "code": "duplicate_field", + "line": 3, + "field": "command" + } + }, + { + "name": "duplicate-id", + "file": "duplicate-id.md", + "text": "---\nid: a\nid: b\ncommand: x\n---\nBody.\n", + "mode": "legacy", + "yaml": "invalid", + "error": { + "code": "duplicate_field", + "line": 3, + "field": "id" + } + }, + { + "name": "colon", + "file": "colon.md", + "text": "---\nname: X\napplies: When: x\n---\nBody.\n", + "mode": "strict", + "yaml": "invalid", + "error": { + "code": "syntax", + "line": 3, + "field": null + } + }, + { + "name": "star", + "file": "star.md", + "text": "---\npath: **/x\n---\nBody.\n", + "mode": "strict", + "yaml": "invalid", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "unknown", + "file": "unknown.md", + "text": "---\ncommand: x\ninvented: y\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "unknown_field", + "line": null, + "field": null + } + }, + { + "name": "empty-field", + "file": "empty-field.md", + "text": "---\ncommand:\nname: X\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "empty_value", + "line": 2, + "field": "command" + } + }, + { + "name": "empty-list", + "file": "empty-list.md", + "text": "---\ncommand: []\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "empty_value", + "line": 2, + "field": "command" + } + }, + { + "name": "empty-quoted", + "file": "empty-quoted.md", + "text": "---\ncommand: ''\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "empty_value", + "line": 2, + "field": "command" + } + }, + { + "name": "space", + "file": "space.md", + "text": "---\ncommand: ' '\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "empty_value", + "line": 2, + "field": "command" + } + }, + { + "name": "wrong-flag", + "file": "wrong-flag.md", + "text": "---\ncommand: x\nmust-know-before: yes\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "wrong_type", + "line": 3, + "field": "must-know-before" + } + }, + { + "name": "wrong-command", + "file": "wrong-command.md", + "text": "---\ncommand: true\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "wrong_type", + "line": 2, + "field": "command" + } + }, + { + "name": "wrong-id", + "file": "wrong-id.md", + "text": "---\nid: 123\ncommand: x\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "wrong_type", + "line": 2, + "field": "id" + } + }, + { + "name": "wrong-item", + "file": "wrong-item.md", + "text": "---\ncommand: [x, false]\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "wrong_type", + "line": 2, + "field": "command" + } + }, + { + "name": "null-item", + "file": "null-item.md", + "text": "---\ncommand: [x, null]\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "empty_value", + "line": 2, + "field": "command" + } + }, + { + "name": "long-id", + "file": "long-id.md", + "text": "---\nid: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\ncommand: x\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "id_too_long", + "line": null, + "field": "id" + } + }, + { + "name": "no-matcher", + "file": "no-matcher.md", + "text": "---\nid: x\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "no_matcher", + "line": null, + "field": null + } + }, + { + "name": "no-applies", + "file": "no-applies.md", + "text": "---\nname: X\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "cue_incomplete", + "line": null, + "field": null + } + }, + { + "name": "must-cue", + "file": "must-cue.md", + "text": "---\nname: X\napplies: When.\nmust-know-before: true\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "must_know_without_key", + "line": null, + "field": null + } + }, + { + "name": "block-list", + "file": "block-list.md", + "text": "---\ncommand:\n - git push\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "syntax", + "line": 3, + "field": null + } + }, + { + "name": "trailing-comma", + "file": "trailing-comma.md", + "text": "---\ncommand: [git push,]\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "nested", + "file": "nested.md", + "text": "---\ncommand: [[git, push]]\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "comment-value", + "file": "comment-value.md", + "text": "---\ncommand: x # ignored\n---\nBody.\n", + "mode": "legacy", + "yaml": "unsupported", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "lone-surrogate", + "file": "lone-surrogate.md", + "text": "---\nname: \"\\ud83d\"\napplies: When.\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "decoded-newline", + "file": "decoded-newline.md", + "text": "---\ncommand: \"git\\npush\"\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "quote", + "file": "quote.md", + "text": "---\ncommand: \"git push\n---\nBody.\n", + "mode": "strict", + "yaml": "invalid", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "flow-quote", + "file": "flow-quote.md", + "text": "---\ncommand: [\"git push, fetch]\n---\nBody.\n", + "mode": "strict", + "yaml": "invalid", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "trailing-text", + "file": "trailing-text.md", + "text": "---\ncommand: \"git push\" more\n---\nBody.\n", + "mode": "strict", + "yaml": "invalid", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "flow-colon", + "file": "flow-colon.md", + "text": "---\ncommand: [a: b]\n---\nBody.\n", + "mode": "legacy", + "yaml": "unsupported", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "key-space", + "file": "key-space.md", + "text": "---\ncommand : x\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "bare-cr", + "file": "bare-cr.md", + "text": "---\ncommand: x\rnext\n---\nBody.\n", + "mode": "strict", + "yaml": "none", + "error": { + "code": "encoding", + "line": 2, + "field": null + } + }, + { + "name": "control", + "file": "control.md", + "text": "---\ncommand: xΒ…y\n---\nBody.\n", + "mode": "strict", + "yaml": "none", + "error": { + "code": "encoding", + "line": 2, + "field": null + } + }, + { + "name": "empty-filename", + "file": ".md", + "text": "---\ncommand: x\n---\nBody.\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "empty_value", + "line": null, + "field": "id" + } + }, + { + "name": "empty-body", + "file": "empty-body.md", + "text": "---\ncommand: x\n---\n \t\n", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "empty_body", + "line": null, + "field": null + } + }, + { + "name": "bom", + "file": "bom.md", + "text": "ο»Ώ---\ncommand: x\n---\nBody.\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "x" + }, + "expect": { + "id": "bom", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "crlf", + "file": "crlf.md", + "text": "---\r\ncommand: x\r\n---\r\nBody.\r\n", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "x" + }, + "expect": { + "id": "crlf", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "bad-utf8", + "file": "bad-utf8.md", + "raw_b64": "LS0tCmNvbW1hbmQ6IHgKLS0tCv8=", + "mode": "strict", + "yaml": "none", + "error": { + "code": "encoding", + "line": null, + "field": null + } + }, + { + "name": "backslash remains part of a POSIX file name", + "file": "a\\b.md", + "text": "---\ncommand: x\n---\nBody.", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "x" + }, + "expect": { + "id": "a\\b", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "valueless field then block item after comment", + "file": "e.md", + "text": "---\ncommand:\n\n# Comment\n- git push\n---\nBody.", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "syntax", + "line": 5, + "field": null + } + }, + { + "name": "valueless field then another field after comment", + "file": "e.md", + "text": "---\ncommand:\n\n# Comment\npath: x\n---\nBody.", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "empty_value", + "line": 2, + "field": "command" + } + }, + { + "name": "trailing valueless field", + "file": "e.md", + "text": "---\npath: x\ncommand:\n---\nBody.", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "empty_value", + "line": 3, + "field": "command" + } + }, + { + "name": "U+FEFF forbidden in plain value", + "file": "e.md", + "text": "---\ncommand: gitο»Ώpush\n---\nBody.", + "mode": "strict", + "yaml": "spec_invalid", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "U+FEFF forbidden in plain flow item", + "file": "e.md", + "text": "---\ncommand: [x, gitο»Ώpush]\n---\nBody.", + "mode": "strict", + "yaml": "spec_invalid", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "U+FEFF forbidden in comment", + "file": "e.md", + "text": "---\n# ο»Ώ comment\ncommand: x\n---\nBody.", + "mode": "strict", + "yaml": "spec_invalid", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "U+FEFF preserved when quoted", + "file": "e.md", + "text": "---\ncommand: \"gitο»Ώpush\"\n---\nBody.", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "gitο»Ώpush" + }, + "expect": { + "id": "e", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "U+FFFE forbidden in plain value", + "file": "e.md", + "text": "---\ncommand: gitοΏΎpush\n---\nBody.", + "mode": "strict", + "yaml": "spec_invalid", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "U+FFFE forbidden in plain flow item", + "file": "e.md", + "text": "---\ncommand: [x, gitοΏΎpush]\n---\nBody.", + "mode": "strict", + "yaml": "spec_invalid", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "U+FFFE forbidden in comment", + "file": "e.md", + "text": "---\n# οΏΎ comment\ncommand: x\n---\nBody.", + "mode": "strict", + "yaml": "spec_invalid", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "U+FFFE preserved when quoted", + "file": "e.md", + "text": "---\ncommand: \"gitοΏΎpush\"\n---\nBody.", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "gitοΏΎpush" + }, + "expect": { + "id": "e", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "U+FFFF forbidden in plain value", + "file": "e.md", + "text": "---\ncommand: gitοΏΏpush\n---\nBody.", + "mode": "strict", + "yaml": "spec_invalid", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "U+FFFF forbidden in plain flow item", + "file": "e.md", + "text": "---\ncommand: [x, gitοΏΏpush]\n---\nBody.", + "mode": "strict", + "yaml": "spec_invalid", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "U+FFFF forbidden in comment", + "file": "e.md", + "text": "---\n# οΏΏ comment\ncommand: x\n---\nBody.", + "mode": "strict", + "yaml": "spec_invalid", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "U+FFFF preserved when quoted", + "file": "e.md", + "text": "---\ncommand: \"gitοΏΏpush\"\n---\nBody.", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "gitοΏΏpush" + }, + "expect": { + "id": "e", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "blank command scalar", + "file": "e.md", + "text": "---\ncommand: \" \\t \"\n---\nBody.", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "empty_value", + "line": 2, + "field": "command" + } + }, + { + "name": "blank command flow item", + "file": "e.md", + "text": "---\ncommand: [git push, \" \"]\n---\nBody.", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "empty_value", + "line": 2, + "field": "command" + } + }, + { + "name": "blank error scalar", + "file": "e.md", + "text": "---\nerror: \" \\t \"\n---\nBody.", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "empty_value", + "line": 2, + "field": "error" + } + }, + { + "name": "blank error flow item", + "file": "e.md", + "text": "---\nerror: [x, \"γ€€\"]\n---\nBody.", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "empty_value", + "line": 2, + "field": "error" + } + }, + { + "name": "raw quoted FEFF error is empty in at least one normalizer", + "file": "e.md", + "text": "---\nerror: \"ο»Ώ\"\n---\nBody.", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "empty_value", + "line": 2, + "field": "error" + } + }, + { + "name": "escaped quoted FEFF error is empty in at least one normalizer", + "file": "e.md", + "text": "---\nerror: \"\\ufeff\"\n---\nBody.", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "empty_value", + "line": 2, + "field": "error" + } + }, + { + "name": "legacy cannot relax raw FEFF in plain", + "file": "e.md", + "text": "---\ncommand: *gitο»Ώpush\n---\nBody.", + "mode": "legacy", + "yaml": "spec_invalid", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "legacy cannot relax empty error", + "file": "e.md", + "text": "---\nerror: \" \"\n---\nBody.", + "mode": "legacy", + "yaml": "unsupported", + "error": { + "code": "empty_value", + "line": 2, + "field": "error" + } + }, + { + "name": "valueless field then block item after blank", + "file": "e.md", + "text": "---\ncommand:\n\n- git push\n---\nBody.", + "mode": "strict", + "yaml": "unsupported", + "error": { + "code": "syntax", + "line": 4, + "field": null + } + }, + { + "name": "plain apostrophe does not start a flow quote", + "file": "e.md", + "text": "---\ncommand: [don't, \"can't\"]\n---\nBody.", + "mode": "strict", + "yaml": "same", + "fields": { + "command": ["don't", "can't"] + }, + "expect": { + "id": "e", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "escaped quoted FEFF command", + "file": "e.md", + "text": "---\ncommand: \"\\ufeff\"\n---\nBody.", + "mode": "strict", + "yaml": "same", + "fields": { + "command": "ο»Ώ" + }, + "expect": { + "id": "e", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "nonempty error with FEFF stays raw", + "file": "e.md", + "text": "---\nerror: \"\\ufeffx\"\n---\nBody.", + "mode": "strict", + "yaml": "same", + "fields": { + "error": "ο»Ώx" + }, + "expect": { + "id": "e", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "raw LS is a YAML non-break character in plain value", + "file": "separator.md", + "mode": "strict", + "yaml": "same", + "text": "---\ncommand: git
push\n---\nBody.", + "fields": { + "command": "git
push" + }, + "expect": { + "id": "separator", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "raw LS is a YAML non-break character in single value", + "file": "separator.md", + "mode": "strict", + "yaml": "same", + "text": "---\ncommand: 'git
push'\n---\nBody.", + "fields": { + "command": "git
push" + }, + "expect": { + "id": "separator", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "raw LS is a YAML non-break character in double value", + "file": "separator.md", + "mode": "strict", + "yaml": "same", + "text": "---\ncommand: \"git
push\"\n---\nBody.", + "fields": { + "command": "git
push" + }, + "expect": { + "id": "separator", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "raw LS is a YAML non-break character in flow value", + "file": "separator.md", + "mode": "strict", + "yaml": "same", + "text": "---\ncommand: [git
push]\n---\nBody.", + "fields": { + "command": ["git
push"] + }, + "expect": { + "id": "separator", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "raw quoted LS-only error is semantically empty", + "file": "separator.md", + "mode": "strict", + "yaml": "unsupported", + "text": "---\nerror: \"
\"\n---\nBody.", + "error": { + "code": "empty_value", + "line": 2, + "field": "error" + } + }, + { + "name": "raw PS is a YAML non-break character in plain value", + "file": "separator.md", + "mode": "strict", + "yaml": "same", + "text": "---\ncommand: git
push\n---\nBody.", + "fields": { + "command": "git
push" + }, + "expect": { + "id": "separator", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "raw PS is a YAML non-break character in single value", + "file": "separator.md", + "mode": "strict", + "yaml": "same", + "text": "---\ncommand: 'git
push'\n---\nBody.", + "fields": { + "command": "git
push" + }, + "expect": { + "id": "separator", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "raw PS is a YAML non-break character in double value", + "file": "separator.md", + "mode": "strict", + "yaml": "same", + "text": "---\ncommand: \"git
push\"\n---\nBody.", + "fields": { + "command": "git
push" + }, + "expect": { + "id": "separator", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "raw PS is a YAML non-break character in flow value", + "file": "separator.md", + "mode": "strict", + "yaml": "same", + "text": "---\ncommand: [git
push]\n---\nBody.", + "fields": { + "command": ["git
push"] + }, + "expect": { + "id": "separator", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "raw quoted PS-only error is semantically empty", + "file": "separator.md", + "mode": "strict", + "yaml": "unsupported", + "text": "---\nerror: \"
\"\n---\nBody.", + "error": { + "code": "empty_value", + "line": 2, + "field": "error" + } + }, + { + "name": "raw tab in double quotes", + "file": "separator.md", + "mode": "strict", + "yaml": "same", + "text": "---\ncommand: \"git\tpush\"\n---\nBody.", + "fields": { + "command": "git\tpush" + }, + "expect": { + "id": "separator", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "raw tab in a quoted flow item", + "file": "separator.md", + "mode": "strict", + "yaml": "same", + "text": "---\ncommand: [\"git\tpush\", git fetch]\n---\nBody.", + "fields": { + "command": ["git\tpush", "git fetch"] + }, + "expect": { + "id": "separator", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "literal backslash followed by raw tab", + "file": "separator.md", + "mode": "strict", + "yaml": "same", + "text": "---\ncommand: \"git\\\\\tpush\"\n---\nBody.", + "fields": { + "command": "git\\\tpush" + }, + "expect": { + "id": "separator", + "body": "Body.", + "long": false, + "exact": true, + "cue": false, + "legacy": false + } + }, + { + "name": "raw tab-only error is semantically empty", + "file": "separator.md", + "mode": "strict", + "yaml": "unsupported", + "text": "---\nerror: \"\t\"\n---\nBody.", + "error": { + "code": "empty_value", + "line": 2, + "field": "error" + } + }, + { + "name": "backslash followed by raw tab is an unsupported escape", + "file": "separator.md", + "mode": "strict", + "yaml": "unsupported", + "text": "---\ncommand: \"git\\\tpush\"\n---\nBody.", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "legacy reader rejects leading flow mapping {x: y}", + "file": "separator.md", + "mode": "legacy", + "yaml": "unsupported", + "text": "---\ncommand: {x: y}\n---\nBody.", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "legacy reader rejects leading flow mapping {x: y", + "file": "separator.md", + "mode": "legacy", + "yaml": "invalid", + "text": "---\ncommand: {x: y\n---\nBody.", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + }, + { + "name": "legacy reader rejects leading flow mapping {x:}", + "file": "separator.md", + "mode": "legacy", + "yaml": "unsupported", + "text": "---\ncommand: {x:}\n---\nBody.", + "error": { + "code": "syntax", + "line": 2, + "field": null + } + } + ], + "stores": [ + { + "name": "flat listing and code point order", + "dirs": ["library", "library/nested"], + "files": { + "library/README.md": "not an entry", + "library/rEaDmE.md": "not an entry", + "library/nested/ignored.md": "not an entry", + "library/πŸ˜€.md": "---\ncommand: x\n---\nEmoji.", + "library/ξ€€.md": "---\ncommand: y\n---\nBMP." + }, + "links": {}, + "sources": [ + { + "directory": "library", + "registered": false + } + ], + "expect": { + "exact": ["ξ€€", "πŸ˜€"], + "cue": [], + "bodies": ["BMP.", "Emoji."], + "errors": [], + "legacy": 0, + "owners": ["library"] + } + }, + { + "name": "project shadows and rejects incoming both wholly", + "dirs": ["project", "shared"], + "files": { + "project/a.md": "---\nid: same\ncommand: x\n---\nProject.", + "shared/both.md": "---\nid: same\ncommand: y\nname: Cue\napplies: When.\n---\nShared." + }, + "links": {}, + "sources": [ + { + "directory": "project", + "registered": false + }, + { + "directory": "shared", + "registered": true + } + ], + "expect": { + "exact": ["same"], + "cue": [], + "bodies": ["Project."], + "errors": ["shared/both.md"], + "legacy": 0, + "owners": ["project", "shared"] + } + }, + { + "name": "same id in distinct matchers stays legal", + "dirs": ["project", "shared"], + "files": { + "project/a.md": "---\nid: same\ncommand: x\n---\nProject.", + "shared/cue.md": "---\nid: same\nname: Cue\napplies: When.\n---\nCue." + }, + "links": {}, + "sources": [ + { + "directory": "project", + "registered": false + }, + { + "directory": "shared", + "registered": true + } + ], + "expect": { + "exact": ["same"], + "cue": ["same"], + "bodies": ["Project.", "Cue."], + "errors": [], + "legacy": 0, + "owners": ["project", "shared"] + } + }, + { + "name": "registered alias grants reading tolerance and deduplicates", + "dirs": ["library"], + "files": { + "library/old.md": "---\ncommand: x\ncommand: y\n---\nLegacy." + }, + "links": { + "alias": "library" + }, + "sources": [ + { + "directory": "library", + "registered": false + }, + { + "directory": "alias", + "registered": true + } + ], + "expect": { + "exact": ["old"], + "cue": [], + "bodies": ["Legacy."], + "errors": [], + "legacy": 1, + "owners": ["library"] + } + }, + { + "name": "project Library refuses legacy", + "dirs": ["library"], + "files": { + "library/old.md": "---\ncommand: x\ncommand: y\n---\nLegacy." + }, + "links": {}, + "sources": [ + { + "directory": "library", + "registered": false + } + ], + "expect": { + "exact": [], + "cue": [], + "bodies": [], + "errors": ["library/old.md"], + "legacy": 0, + "owners": ["library"] + } + }, + { + "name": "missing conventional Library is normal but configured store errors", + "dirs": [], + "files": {}, + "links": {}, + "sources": [ + { + "directory": "missing-project", + "registered": false + }, + { + "directory": "missing-shared", + "registered": true + } + ], + "expect": { + "exact": [], + "cue": [], + "bodies": [], + "errors": ["missing-shared"], + "legacy": 0, + "owners": [] + } + }, + { + "name": "dangling entry is reported but Markdown-named directories are ignored", + "dirs": ["library", "library/folder.md"], + "files": {}, + "links": { + "library/broken.md": "missing" + }, + "sources": [ + { + "directory": "library", + "registered": false + } + ], + "expect": { + "exact": [], + "cue": [], + "bodies": [], + "errors": ["library/broken.md"], + "legacy": 0, + "owners": ["library"] + } + } + ], + "discovery": [ + { + "name": "repository root", + "dirs": ["repo/.git", "repo/library"], + "files": {}, + "links": {}, + "thread": "repo", + "expect": "repo/library" + }, + { + "name": "repository subdirectory", + "dirs": ["repo/.git", "repo/library", "repo/sub/deep"], + "files": {}, + "links": {}, + "thread": "repo/sub/deep", + "expect": "repo/library" + }, + { + "name": "worktree subdirectory", + "dirs": ["tree/library", "tree/sub"], + "files": { + "tree/.git": "gitdir: /unused" + }, + "links": {}, + "thread": "tree/sub", + "expect": "tree/library" + }, + { + "name": "nested repository stops parent discovery", + "dirs": [ + "repo/.git", + "repo/library", + "repo/nested/.git", + "repo/nested/library", + "repo/nested/sub" + ], + "files": {}, + "links": {}, + "thread": "repo/nested/sub", + "expect": "repo/nested/library" + }, + { + "name": "non-Git authoritative directory", + "dirs": ["plain/library"], + "files": {}, + "links": {}, + "thread": "plain", + "expect": "plain/library" + }, + { + "name": "Library symlink resolves physical owner", + "dirs": ["repo/.git", "shared"], + "files": {}, + "links": { + "repo/library": "shared" + }, + "thread": "repo", + "expect": "shared" + }, + { + "name": "Library file is absent", + "dirs": ["repo/.git"], + "files": { + "repo/library": "not a directory" + }, + "links": {}, + "thread": "repo", + "expect": null + }, + { + "name": "dangling Library link is absent", + "dirs": ["repo/.git"], + "files": {}, + "links": { + "repo/library": "missing" + }, + "thread": "repo", + "expect": null + }, + { + "name": "missing thread is absent", + "dirs": [], + "files": {}, + "links": {}, + "thread": "missing", + "expect": null + }, + { + "name": "nested checkout without Library does not inherit parent", + "dirs": ["repo/.git", "repo/library", "repo/nested/.git"], + "files": {}, + "links": {}, + "thread": "repo/nested", + "expect": null + } + ] +} diff --git a/tests/test_library.py b/tests/test_library.py new file mode 100644 index 0000000..bf2ac14 --- /dev/null +++ b/tests/test_library.py @@ -0,0 +1,206 @@ +"""The Library contract, independent of a running Chromeria server.""" +import base64 +import hashlib +import json +import os +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path + +from contextmd.serve import store + +CORPUS = Path(__file__).with_name('library-corpus.json') +BIN = Path(__file__).resolve().parents[1] / 'bin/contextmd-serve' + + +def fixture(root, case): + for directory in case['dirs']: + (root / directory).mkdir(parents=True, exist_ok=True) + for file, text in case['files'].items(): + (root / file).parent.mkdir(parents=True, exist_ok=True) + (root / file).write_text(text) + for file, target in case['links'].items(): + (root / file).parent.mkdir(parents=True, exist_ok=True) + (root / file).symlink_to(root / target, target_is_directory=True) + + +class LibraryCorpusTest(unittest.TestCase): + def test_independent_entry_contract(self): + for case in json.loads(CORPUS.read_text())['entries']: + with self.subTest(case=case['name']): + raw = base64.b64decode(case['raw_b64']) if 'raw_b64' in case else case['text'].encode() + p = Path('/tmp/library-contract') / case['file'] + try: + parsed = store.parse_file(p, raw, tolerant=case['mode'] == 'legacy') + except store.EntryError as error: + self.assertEqual({'code': error.code, 'line': error.line, 'field': error.field}, case.get('error')) + continue + self.assertNotIn('error', case) + exact, cue = parsed.views() + self.assertEqual(parsed.fields, case['fields']) + self.assertEqual({'id': parsed.id, 'body': parsed.body, 'long': parsed.long, + 'exact': exact is not None, 'cue': cue is not None, + 'legacy': parsed.legacy is not None}, case['expect']) + self.assertEqual(parsed.version, hashlib.sha256(raw).hexdigest()[:12]) + + def test_independent_store_contract(self): + for case in json.loads(CORPUS.read_text())['stores']: + with self.subTest(case=case['name']), tempfile.TemporaryDirectory() as d: + root = Path(d).resolve() + fixture(root, case) + library = store.load([store.Source(str(root / s['directory']), s['registered']) + for s in case['sources']]) + observed = {'exact': [e.id for e in library.entries], + 'cue': [e.id for e in library.cue], + 'bodies': [e.text for e in [*library.entries, *library.cue]], + 'errors': [str(Path(e.split(': ', 1)[0]).relative_to(root)) for e in library.errors], + 'legacy': len(library.legacy), + 'owners': [str(Path(p).relative_to(root)) for p in library.owners]} + self.assertEqual(observed, case['expect']) + + def test_independent_discovery_contract(self): + for case in json.loads(CORPUS.read_text())['discovery']: + with self.subTest(case=case['name']), tempfile.TemporaryDirectory() as d: + root = Path(d).resolve() + fixture(root, case) + found = store.library_dir(str(root / case['thread'])) + self.assertEqual(str(Path(found).relative_to(root)) if found else None, case['expect']) + + @unittest.skipIf(os.geteuid() == 0, 'root bypasses directory permissions') + def test_unreadable_directory_is_reported(self): + with tempfile.TemporaryDirectory() as d: + root = Path(d) / 'library' + root.mkdir() + root.chmod(0) + try: + library = store.load([str(root)]) + self.assertEqual(library.entries, []) + self.assertEqual(library.errors, [f'{root}: unreadable directory']) + finally: + root.chmod(0o700) + + def test_corpus_copy_is_identical_without_starting_a_server(self): + if not os.environ.get('CONTEXTMD_CHROMERIA'): + self.skipTest('set CONTEXTMD_CHROMERIA for the file-only twin check') + twin = Path(os.environ['CONTEXTMD_CHROMERIA']) / 'apps/server/src/contextmd/library-corpus.json' + self.assertEqual(CORPUS.read_bytes(), twin.read_bytes()) + + def test_known_normalizer_difference_is_reported_at_its_owner(self): + # #69 owns this inherited matcher difference; the raw parsed field is shared. + raw = '---\nerror: Erreur Ω‘Ω’, id 34\n---\nBody.'.encode() + parsed = store.parse_file(Path('/tmp/unicode.md'), raw) + self.assertEqual(parsed.fields['error'], 'Erreur Ω‘Ω’, id 34') + self.assertEqual(parsed.views()[0].errors, ['erreur #, id #']) + + def test_target_expands_either_home_separator_but_not_other_users(self): + for target in ('~/record.md', '~\\record.md'): + raw = f"---\ncommand: x\ntarget: '{target}'\n---\nBody.".encode() + self.assertEqual(store.parse_file(Path('/tmp/library/e.md'), raw).views()[0].target, + str(Path.home() / 'record.md')) + raw = b"---\ncommand: x\ntarget: '~user/record.md'\n---\nBody." + self.assertEqual(store.parse_file(Path('/tmp/library/e.md'), raw).views()[0].target, + '/tmp/library/~user/record.md') + + +class LibraryAdmissionTest(unittest.TestCase): + def test_strict_admission_cannot_inherit_registered_tolerance(self): + with tempfile.TemporaryDirectory() as d: + p = Path(d) / 'legacy.md' + p.write_text('---\ncommand: git push\ncommand: git commit\n---\nBody.') + self.assertEqual(store.load([d]).errors, []) + result = subprocess.run([sys.executable, '-B', str(BIN), 'check', '--entry', str(p)], + env={**os.environ, 'CONTEXTMD_SERVING_CONFIG': str(Path(d) / 'bad.json')}, + capture_output=True, text=True) + self.assertEqual(result.returncode, 1) + self.assertIn(str(p), json.loads(result.stdout)['errors'][0]) + self.assertIn('repeated field', json.loads(result.stdout)['errors'][0]) + + def test_project_discovery_uses_checkout_boundaries_and_worktree_files(self): + with tempfile.TemporaryDirectory() as d: + root = Path(d) / 'repo' + (root / '.git').mkdir(parents=True) + (root / 'library').mkdir() + sub = root / 'sub' + sub.mkdir() + self.assertEqual(store.library_dir(str(sub)), str(root / 'library')) + nested = sub / 'nested' + nested.mkdir() + (nested / '.git').write_text('gitdir: /unused') + (nested / 'library').mkdir() + child = nested / 'child' + child.mkdir() + self.assertEqual(store.library_dir(str(child)), str(nested / 'library')) + plain = Path(d) / 'plain' + (plain / 'library').mkdir(parents=True) + self.assertEqual(store.library_dir(str(plain)), str(plain / 'library')) + self.assertIsNone(store.library_dir(str(Path(d) / 'missing'))) + + def test_flat_sources_deduplicate_aliases_and_reject_both_entry_wholly(self): + with tempfile.TemporaryDirectory() as d: + project, shared = Path(d) / 'project', Path(d) / 'shared' + project.mkdir() + shared.mkdir() + (project / 'a.md').write_text('---\nid: same\ncommand: x\n---\nProject.') + (shared / 'both.md').write_text('---\nid: same\ncommand: y\nname: Cue\napplies: When.\n---\nShared.') + (project / 'sub').mkdir() + (project / 'sub' / 'ignored.md').write_text('not an entry') + alias = Path(d) / 'alias' + alias.symlink_to(project, target_is_directory=True) + library = store.load([store.Source(str(project), False), str(alias), str(shared)]) + self.assertEqual([e.text for e in library.entries], ['Project.']) + self.assertEqual(library.cue, []) + self.assertEqual(len(library.owners), 2) + self.assertEqual(len(library.errors), 1) + self.assertIn('already used', library.errors[0]) + + +class LibraryRegressionTest(unittest.TestCase): + def test_cue_history_keeps_its_legacy_text_and_record_target(self): + from contextmd.serve.card import rule_text + with tempfile.TemporaryDirectory() as d: + root = Path(d) + library = root / 'library' + library.mkdir() + p = library / 'cue.md' + old = b'---\nid: cue\nname: Cue\napplies: When: this holds.\ntarget: ../record.md\n---\nOld knowledge.' + p.write_bytes(old) + for args in (['init', '-q'], ['add', '.'], + ['-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '-qm', 'cue']): + subprocess.run(['git', '-C', d, *args], check=True, capture_output=True) + p.write_text('---\nid: cue\nname: Cue\napplies: "When this holds."\n---\nNew knowledge.') + row = {'entry': 'cue', 'version': hashlib.sha256(old).hexdigest()[:12], 'owners': {str(library): None}} + recovered = rule_text(row, root / 'unused.sqlite') + self.assertEqual(recovered['source'], 'store_history') + self.assertEqual(recovered['text'], 'Old knowledge.') + self.assertEqual(recovered['target'], str(root / 'record.md')) + + def test_flow_list_keeps_separate_command_keys(self): + with tempfile.TemporaryDirectory() as d: + p = Path(d) / 'push.md' + p.write_text('---\ncommand: [git push, "gh pr create"]\n---\nPull first.\n') + self.assertEqual(store.parse(p).commands, [['git', 'push'], ['gh', 'pr', 'create']]) + + def test_both_matchers_share_a_flat_folder(self): + with tempfile.TemporaryDirectory() as d: + p = Path(d) / 'push.md' + p.write_text('---\ncommand: git push\nname: Push\napplies: "When pushing. Not: a fetch."\n---\nPull first.\n') + exact, cue = store.load([d]), store.load_cue([d]) + self.assertEqual(exact.errors, []) + self.assertEqual(cue.errors, []) + self.assertEqual([e.id for e in exact.entries], ['push']) + self.assertEqual([e.id for e in cue.entries], ['push']) + self.assertEqual(exact.entries[0].version, cue.entries[0].version) + + def test_long_knowledge_keeps_its_authored_target(self): + with tempfile.TemporaryDirectory() as d: + p = Path(d) / 'long.md' + p.write_text('---\ncommand: git push\nmust-know-before: true\ntarget: "record.md"\n---\n' + 'x' * 1801) + e = store.parse(p) + self.assertEqual(e.text, 'x' * 1801) + self.assertEqual(e.target, str(Path(d) / 'record.md')) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_serve.py b/tests/test_serve.py index 1018017..36de91a 100644 --- a/tests/test_serve.py +++ b/tests/test_serve.py @@ -485,8 +485,9 @@ def test_bad_entries_are_reported_not_loaded(self): entry(d, "big", "x" * (store.MAX_ENTRY_BYTES + 1), command="ls") (Path(d) / "README.md").write_text("not an entry") st = store.load([d]) - self.assertEqual([e.id for e in st.entries], ["good"]) - self.assertEqual(len(st.errors), 2) + self.assertEqual([e.id for e in st.entries], ["big", "good"]) + self.assertTrue(st.entries[0].long) + self.assertIn("no command, path or error key", st.errors[0]) def test_long_entry_id_is_rejected(self): with tempfile.TemporaryDirectory() as d: @@ -513,12 +514,13 @@ def test_target_makes_a_pointer_rule_relative_to_the_entry(self): e = store.parse(p) self.assertEqual(e.target, os.path.realpath(Path(d) / "procedures" / "vc.md")) - def test_target_needs_must_know_before(self): + def test_context_entry_can_point_to_a_record(self): with tempfile.TemporaryDirectory() as d: entry(d, "vc", "Read it.", command="git push", target="x.md") st = store.load([d]) - self.assertEqual(st.entries, []) - self.assertIn("target is only for must-know-before entries", st.errors[0]) + self.assertEqual(st.errors, []) + self.assertEqual(st.entries[0].target, str(Path(d) / "x.md")) + self.assertFalse(st.entries[0].must_know_before) def cue_entry(directory, file, body, **fields): @@ -550,22 +552,24 @@ def test_bad_cue_entries_are_reported_not_loaded(self): cue_entry(d, "noname", "Body.", applies="When.") cue_entry(d, "noapplies", "Body.", name="X") cue_entry(d, "exactkey", "Body.", name="X", applies="When.", command="git push") + cue_entry(d, "unknown", "Body.", name="X", applies="When.", invented="no") cue_entry(d, "empty", "", name="X", applies="When.") cue_entry(d, "big", "x" * (store.MAX_ENTRY_BYTES + 1), name="X", applies="When.") cue_entry(d, "zdup", "Body.", id="good", name="Dup", applies="When.") st = store.load_cue([d]) - self.assertEqual([e.id for e in st.entries], ["good"]) + self.assertEqual([e.id for e in st.entries], ["big", "exactkey", "good"]) + self.assertTrue(st.entries[0].long) reasons = " | ".join(st.errors) - for want in ("no name", "no applies", "unknown fields: ['command']", "empty body", - "UTF-8 bytes, over", "already used"): + for want in ("no name", "no applies", "unknown fields: ['invented']", "empty body", "already used"): self.assertIn(want, reasons) - def test_exact_key_loader_still_rejects_cue_fields(self): + def test_cue_only_entry_has_no_exact_keys_and_no_cross_loader_error(self): with tempfile.TemporaryDirectory() as d: cue_entry(d, "cue", "Body.", name="X", applies="When.") st = store.load([d]) self.assertEqual(st.entries, []) - self.assertIn("unknown fields", st.errors[0]) + self.assertEqual(st.errors, []) + self.assertEqual([e.id for e in st.cue], ["cue"]) def test_check_reports_both_lists(self): with tempfile.TemporaryDirectory() as d: