diff --git a/docs/architecture/source-mapping.md b/docs/architecture/source-mapping.md index e3caf3ee613..3f63eacdd88 100644 --- a/docs/architecture/source-mapping.md +++ b/docs/architecture/source-mapping.md @@ -32,6 +32,10 @@ replace. ([the host backend](mcp-source-worker-boundary.md#the-host-backend)). - `source_worker/qualification/record_mapped.py`: the recorder, and `Replay`, which answers a reader from a recording. +- `source_worker/qualification/stand_in_channel.py` (`Channel`, `Stdio`): a stand-in for + an account host's tool channel over a server started as a local process. +- `source_worker/mappings/wiki.json`: the reference mapping, for an open-source wiki's + protocol server. ## Invariants @@ -93,13 +97,24 @@ sorted keys, no space after `:` or `,`, and each string JSON-escaped. A flag is | `items_path` | The list of items in the result; empty when the result is the list | | `id_path` | The id inside one item | | `revision_path`, `modified_path`, `title_path`, `link_path` | Optional paths inside one item | -| `next_cursor_path` | The cursor of the next page; absent, `null` or empty on the last | +| `next_cursor_path` | The cursor of the next page; no page follows without one | | `complete` | Whether a listing read to its end names every document | | `changed_since` | Whether the tool can list only what changed since a time | A result that is itself the list has no place for a cursor, so `load` refuses `next_cursor_path` beside an empty `items_path`. +An optional path of an item (`revision_path`, `modified_path`, `title_path`, +`link_path`) reads as empty when its last key is absent or `null`. A member above the +last key that is absent, `null` or not an object refuses with `protocol`, and so does a +value that is not a string. + +`next_cursor_path` is optional along its whole length. A member that is absent or +`null` at any depth means that no page follows, and so does an empty cursor: a server +may leave out the whole member that holds its cursor on a listing's last page. A member +that is present and is not an object where the path goes on, and a cursor that is not a +string, refuse with `protocol`. + A path is a list of object keys. `not_found` and `denied` are matchers: `is_error` and `text_prefix`. A result matches when its error flag equals `is_error` and its one text block starts with `text_prefix`. `load` refuses a mapping whose two matchers could match @@ -346,14 +361,33 @@ SHA-256 of its text. Before anything is written, every upstream id, every cursor and every name given with `--name` is replaced by a neutral value such as `doc-0001`, the same wherever it recurs. -A UUID is found in either spelling; another id is replaced as written. The recorder -stops when a call still holds one of them. Tool definitions are written as advertised, -without their descriptions, because their digest is what a mapping pins. Run -`make format` on the written files before committing them. - -`source_worker/tests/test_mapping_proof.py` replays the recording under -`source_worker/tests/fixtures/mapped/example/`, which is built by hand for a made-up -server, through `Replay`, which refuses a call the recording does not hold. +A UUID is found in either spelling. Any other value is replaced as written and as a +link spells it: with `_` for a space, percent-encoded, or both. A number is never +replaced, so a server that names its rows by number is recorded from a workspace made +for the recording. The recorder stops when a call still holds one of the values in one +of those spellings. Tool +definitions are written as advertised, parameter descriptions included and without the +tool's own description, because their digest is what a mapping pins. Run `make format` +on the written files before committing them. + +`source_worker/tests/test_mapping_proof.py` replays two recordings through `Replay`, +which refuses a call the recording does not hold: + +- `source_worker/tests/fixtures/mapped/example/` is built by hand for a made-up server. +- `source_worker/tests/fixtures/mapped/wiki/` holds what an open-source wiki's protocol + server answered for a wiki of made-up pages. `source_worker/mappings/wiki.json`, the + reference mapping, reads it. The directory's `README.md` says how to repeat the + recording. + +`source_worker/qualification/stand_in_channel.py` is the `ToolCaller` of the second +recording. `Channel` stands between the reader and a server as an account host's +channel does: it lists the server's tools as advertised, and it raises `too_large` for +a result over its cap, `reconnect_required` when the account needs a sign-in, +`server_off` when the server is not enabled and `tool_not_allowed` for a tool the +host's policy refuses. `Stdio` starts the server as a local process. The proof test +puts `Channel` in each of those states over the recording, and the reader raises the +channel's code unchanged. The package never imports the module. + `source_worker/tests/test_reader_contract.py` holds the rules every reader keeps. ## Related diff --git a/docs/guides/document-worker-beside-a-host.md b/docs/guides/document-worker-beside-a-host.md index b2b1fc0e6f8..56e15ea614b 100644 --- a/docs/guides/document-worker-beside-a-host.md +++ b/docs/guides/document-worker-beside-a-host.md @@ -35,6 +35,16 @@ source whose `profile_digest` is the digest of a file there, so a mapping nobody there reads nothing. The directory holds at most 64 mappings, and a file that is not a mapping stops the run with a `ValueError`. +`source_worker/mappings/wiki.json` is the worked example: the reference mapping for an +open-source wiki's protocol server, which a test reads on results recorded from that +server. Its listing is the wiki's feed of changes, so a page changed twice is two items +with one id: the worker fetches the page once more for each older change, and a fetched +page carries the modified time of the item listed last for it. A deployment proves its +own channel with the same +[recorder](../architecture/source-mapping.md#recording-fixtures): its operators run it +through the host's channel when the server or the host is upgraded, and replay the +recording before they approve the mapping's digest. + ## 2. Assign the source A namespace administrator, not the agent, assigns the source to the agent's subject with diff --git a/source_worker/loom_source_worker/readers/mcp_mapped.py b/source_worker/loom_source_worker/readers/mcp_mapped.py index bcaaa1c2090..7a1ae6d9e2d 100644 --- a/source_worker/loom_source_worker/readers/mcp_mapped.py +++ b/source_worker/loom_source_worker/readers/mcp_mapped.py @@ -64,6 +64,19 @@ def _optional(value: Any, path: tuple[str, ...] | None) -> str: return found +def _cursor(value: Any, path: tuple[str, ...] | None) -> str: + """The next page's cursor: as `_optional`, and empty too when a member above the + last key is absent or null. A server may leave out the whole member that holds + its cursor on a listing's last page.""" + for key in (path or ())[:-1]: + if not isinstance(value, dict): + raise ReaderError("protocol") + value = value.get(key) + if value is None: + return "" + return _optional(value, path and path[-1:]) + + def _size(text: str) -> int: """The text's bytes; a string that is not UTF-8 text is refused.""" try: @@ -297,7 +310,7 @@ async def list_since( link=self._link(_optional(item, listing.link_path)), ) ) - following = _optional(value, listing.next_cursor_path) or None + following = _cursor(value, listing.next_cursor_path) or None if following is not None and following == cursor: raise ReaderError("protocol") self._listed.update((item.id, item) for item in items) diff --git a/source_worker/mappings/wiki.json b/source_worker/mappings/wiki.json new file mode 100644 index 00000000000..9db323ed473 --- /dev/null +++ b/source_worker/mappings/wiki.json @@ -0,0 +1,39 @@ +{ + "version": 1, + "link_origins": ["https://wiki.example.test"], + "limits": { "max_result_bytes": 400000, "max_text_bytes": 100000, "max_pages_per_turn": 8 }, + "fetch": { + "tool": "get-page", + "definition_sha256": "9e3cca2f72bb5b02e01ab1b1c1d2298bb8bea5ce1065a11b1518f2f0687a0390", + "arguments": { "title": { "$value": "document_id" }, "metadata": true }, + "result": "structured", + "id_path": ["title"], + "title_path": ["title"], + "text_path": ["source"], + "link_path": ["url"], + "revision_path": ["latestRevisionTimestamp"], + "truncated_marker": "\"truncation\":{" + }, + "list": { + "tool": "get-recent-changes", + "definition_sha256": "2bc201822fb95157d4785ef7de5735e11965d6c54b2c059a734e5202c920ba97", + "arguments": { + "user": { "$value": "scope" }, + "since": { "$value": "since" }, + "continue": { "$value": "cursor" } + }, + "result": "structured", + "items_path": ["changes"], + "id_path": ["title"], + "revision_path": ["timestamp"], + "modified_path": ["timestamp"], + "title_path": ["title"], + "next_cursor_path": ["truncation", "continueWith", "value"], + "complete": false, + "changed_since": true + }, + "removed": { + "mode": "fetch_not_found", + "not_found": { "is_error": true, "text_prefix": "{\"category\":\"not_found\"" } + } +} diff --git a/source_worker/qualification/record_mapped.py b/source_worker/qualification/record_mapped.py index 126f31b7f8a..e350dc37346 100644 --- a/source_worker/qualification/record_mapped.py +++ b/source_worker/qualification/record_mapped.py @@ -18,8 +18,9 @@ Every upstream id, every cursor and every given name is replaced by a neutral value, the same wherever it recurs, so the second page is still asked for by the first page's -cursor. A UUID is found in either spelling; any other id is replaced as written. Tool -definitions are not rewritten: their digest is what a mapping pins. +cursor. A UUID is found in either spelling; any other value is replaced as written and +as a link spells it. A number is never replaced. Tool definitions are not rewritten: +their digest is what a mapping pins. """ from __future__ import annotations @@ -33,6 +34,7 @@ from collections.abc import Sequence from pathlib import Path from typing import Any +from urllib.parse import quote from loom_source_worker.mapping import PLACEHOLDER, Mapping, load from loom_source_worker.readers.mcp_mapped import MappedReader @@ -63,6 +65,13 @@ def upstream_ids(text: str) -> list[str]: return [match.group(0) for match in _UUID.finditer(text)] +def spellings(value: str) -> list[str]: + """A value as written and as a link spells it: with `_` for a space, percent-encoded, + or both. A link that spells a space as `_` may keep a title's punctuation.""" + underscored = value.replace(" ", "_") + return list(dict.fromkeys((value, underscored, quote(underscored), quote(value)))) + + def placed(template: Any, arguments: Any) -> dict[str, Any]: """The value a call carries at each placeholder of its template, outside lists.""" if not isinstance(template, dict): @@ -76,7 +85,8 @@ def placed(template: Any, arguments: Any) -> dict[str, Any]: return found -def _definition(entry: dict[str, Any]) -> ToolDefinition: +def definition(entry: dict[str, Any]) -> ToolDefinition: + """A tool as one entry of `tools/list` advertises it.""" hint = entry.get("annotations", {}).get("readOnlyHint") return ToolDefinition( entry["name"], entry["inputSchema"], entry.get("outputSchema"), hint is True @@ -104,7 +114,7 @@ class Replay: """A `ToolCaller` that answers from a recording and refuses every other call.""" def __init__(self, directory: Path) -> None: - self.tools = [_definition(entry) for entry in _read(directory / "tools.json")] + self.tools = [definition(entry) for entry in _read(directory / "tools.json")] self.recorded: dict[str, Any] = { name: _read(directory / f"{name}.json") for name in CALLS @@ -180,13 +190,14 @@ def scrub(self, value: Any) -> Any: return value value = _UUID.sub(self._uuid, value) for known in sorted(self._values, key=len, reverse=True): - value = value.replace(known, self._values[known]) + for spelling in spellings(known): + value = value.replace(spelling, self._values[known]) return value -async def _expected(mapping: Mapping, out: Path, scope: str, document: str) -> dict[str, Any]: - """What the reader makes of the written recording: every listed document, and the - fetched one with the hash of its text.""" +async def expected(mapping: Mapping, out: Path, scope: str, document: str) -> dict[str, Any]: + """What the reader makes of the written recording, as `expected.json` holds it: + every listed document, and the fetched one with the hash of its text.""" reader = MappedReader(mapping, Replay(out), items=[], scope=scope) deadline = asyncio.get_running_loop().time() + _SECONDS documents: dict[str, dict[str, str]] = {} @@ -278,16 +289,17 @@ async def record( scrubbed = {name: neutral.scrub(call) for name, call in files.items()} upstream = [scope, empty_scope, *fetches.values(), *names] + held = [spelling for value in upstream for spelling in spellings(value)] for name, call in scrubbed.items(): text = json.dumps(call, ensure_ascii=False) # Nothing is written while a call still holds what was to be replaced. - if upstream_ids(text) or any(value in text for value in upstream): + if upstream_ids(text) or any(spelling in text for spelling in held): raise SystemExit(f"{name} still holds an upstream id or name") _write(out / "tools.json", [_entry(tool) for tool in tools]) for name, call in scrubbed.items(): _write(out / f"{name}.json", call) - expected = await _expected(mapping, out, neutral.scrub(scope), neutral.scrub(document)) - _write(out / "expected.json", expected) + made = await expected(mapping, out, neutral.scrub(scope), neutral.scrub(document)) + _write(out / "expected.json", made) def main() -> None: diff --git a/source_worker/qualification/stand_in_channel.py b/source_worker/qualification/stand_in_channel.py new file mode 100644 index 00000000000..46cd5fcd7e4 --- /dev/null +++ b/source_worker/qualification/stand_in_channel.py @@ -0,0 +1,137 @@ +"""A stand-in for an account host's tool channel, to record a protocol server on one machine. + +Beside an account host the recorder's `ToolCaller` is the host's channel. `Channel` +stands in for it over a server that needs no credential, started as a local process: + + RECORD_SERVER_COMMAND='["node", "server.js"]' \ + python source_worker/qualification/record_mapped.py --caller stand_in_channel:local ... + +It lists the server's tools as advertised, refuses a result over its size cap, and +refuses as a channel does when the account needs a sign-in, the server is not enabled +or a tool is not allowed. Each refusal is a `ReaderError` with the reader's code and no +text of any host. The package never imports this module. +""" + +from __future__ import annotations + +import atexit +import json +import os +import subprocess +from collections.abc import Sequence +from dataclasses import dataclass +from typing import Any + +from loom_source_worker.mapping import canonical +from loom_source_worker.sync_types import ReaderError, ToolCaller, ToolDefinition, ToolResult +from record_mapped import definition + +# The stand-in's cap on one result: its text blocks and its structured content. +MAX_RESULT_BYTES = 1_000_000 + + +class Stdio: + """`ToolCaller` over a protocol server started as a local process, which reads and + writes one JSON-RPC message a line. A call waits for its answer on the pipe, so no + deadline ends it. The process ends with the one that started it.""" + + def __init__(self, command: Sequence[str]) -> None: + self._command = list(command) + self._process: subprocess.Popen[bytes] | None = None + self._sent = 0 + + def _write(self, message: dict[str, Any]) -> None: + assert self._process is not None and self._process.stdin is not None + self._process.stdin.write(json.dumps(message).encode() + b"\n") + self._process.stdin.flush() + + def _answer(self, method: str, params: dict[str, Any]) -> dict[str, Any]: + if self._process is None: + self._process = subprocess.Popen( + self._command, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, + ) + atexit.register(self._process.terminate) + client = {"name": "record-mapped", "version": "0"} + hello = {"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": client} + self._answer("initialize", hello) + self._write({"jsonrpc": "2.0", "method": "notifications/initialized"}) + assert self._process.stdout is not None + self._sent += 1 + self._write({"jsonrpc": "2.0", "id": self._sent, "method": method, "params": params}) + while line := self._process.stdout.readline(): + try: + message = json.loads(line) + except ValueError: + continue + if isinstance(message, dict) and message.get("id") == self._sent: + result = message.get("result") + if not isinstance(result, dict): + # A JSON-RPC error is no tool result. + raise ReaderError("protocol") + return result + raise ReaderError("upstream_unavailable") + + async def list_tools(self) -> list[ToolDefinition]: + tools: list[ToolDefinition] = [] + params: dict[str, Any] = {} + while True: + page = self._answer("tools/list", params) + tools += map(definition, page["tools"]) + if not page.get("nextCursor"): + return tools + params = {"cursor": page["nextCursor"]} + + async def call_tool( + self, name: str, arguments: dict[str, Any], *, deadline: float + ) -> ToolResult: + result = self._answer("tools/call", {"name": name, "arguments": arguments}) + texts = [block["text"] for block in result.get("content", []) if block["type"] == "text"] + return ToolResult(result.get("structuredContent"), texts, result.get("isError") is True) + + +@dataclass +class Channel: + """`ToolCaller` between a reader and `server`, as an account host's channel stands + between them. `signed_in`: the account has a credential the channel can add. + `enabled`: the server is turned on for the agent. `refused_tools`: the tools the + host's policy does not allow; they are still listed.""" + + server: ToolCaller + max_result_bytes: int = MAX_RESULT_BYTES + signed_in: bool = True + enabled: bool = True + refused_tools: frozenset[str] = frozenset() + + def _admit(self) -> None: + if not self.enabled: + raise ReaderError("server_off") + if not self.signed_in: + raise ReaderError("reconnect_required") + + async def list_tools(self) -> list[ToolDefinition]: + self._admit() + return await self.server.list_tools() + + async def call_tool( + self, name: str, arguments: dict[str, Any], *, deadline: float + ) -> ToolResult: + self._admit() + if name in self.refused_tools: + raise ReaderError("tool_not_allowed") + result = await self.server.call_tool(name, arguments, deadline=deadline) + size = sum(len(text.encode()) for text in result.texts) + if result.structured is not None: + size += len(canonical(result.structured)) + if size > self.max_result_bytes: + # The channel carries no part of a result over its cap. + raise ReaderError("too_large") + return result + + +def local() -> Channel: + """The channel over the server whose command line `RECORD_SERVER_COMMAND` holds, + as a JSON list. The server reads its own settings from the environment.""" + return Channel(Stdio(json.loads(os.environ["RECORD_SERVER_COMMAND"]))) diff --git a/source_worker/tests/fixtures/mapped/wiki/README.md b/source_worker/tests/fixtures/mapped/wiki/README.md new file mode 100644 index 00000000000..98c6f587c50 --- /dev/null +++ b/source_worker/tests/fixtures/mapped/wiki/README.md @@ -0,0 +1,110 @@ +# Recorded results of an open-source wiki's protocol server + +These files hold what the server answered through the stand-in channel +(`source_worker/qualification/stand_in_channel.py`) to the calls of the reference mapping +(`source_worker/mappings/wiki.json`). `source_worker/tests/test_mapping_proof.py` replays +them. + +The wiki held made-up pages only and was removed after the recording. The recorder +replaced its page names, its user names and its cursor by neutral values. The results +keep the wiki's row numbers (pages, revisions, users) and the times of the changes. +`tools.json` holds the two tool definitions as the server advertises them, parameter +descriptions included, because a mapping pins their digest. + +## A page changed twice + +The mapping lists the wiki's feed of changes, newest first, so an item is a change and +not a page. The server lists every change of a page: the page that was changed twice, +`doc-0001`, is two items with one id, one on each page of the listing, and +`expected.json` holds it once. The reader makes this of it: + +- It yields both items, each with its own change's time as revision and modified time. +- A fetch returns the page's newest revision. Its modified time is that of the item + listed last for the page, which is the older change. +- The sync engine compares each item's revision with the stored copy's, so an older + change of a page costs one more fetch in every listing that names it. + +## Repeat the recording + +The server is the npm package `@professional-wiki/mediawiki-mcp-server` at 0.24.0, run +over stdio against a wiki from the container image `mediawiki:1.43`. It needs Docker, +Node.js 22 and the worker package's Python environment. + +1. Start the wiki on SQLite under a made-up origin, so that every link it returns is on + `https://wiki.example.test`: + + ```bash + docker run -d --name wiki-recording -p 127.0.0.1:28941:80 mediawiki:1.43 + docker exec wiki-recording sh -c 'php maintenance/run.php install --dbtype sqlite \ + --dbpath /var/www/data --server https://wiki.example.test --scriptpath "" \ + --pass "$(head -c 18 /dev/urandom | base64)" "Harbor log" Keeper' + ``` + +2. Make the pages: 53 short pages and one long page by one user, then a second change + of the first page, the last five changes more than a minute after the others, and a + user with no change. The listing then holds 55 changes on two pages of 50, and the + listing of what changed in the last minute fits one. + + ```bash + docker exec -i wiki-recording sh -s <<'SH' + set -e + pass="$(head -c 18 /dev/urandom | base64)" + php maintenance/run.php createAndPromote "Harbor desk" "$pass" + php maintenance/run.php createAndPromote "Quiet desk" "$pass" + note() { + printf 'Berth %s is checked at the start of each watch.\n\nThe lamp, the fenders and the mooring lines are noted in the log.\n' "$1" | + php maintenance/run.php edit --user "Harbor desk" --summary "Watch note" "Berth note $1" + } + for n in $(seq 1 50); do note "$n"; done + sleep 65 + for n in $(seq 51 53); do note "$n"; done + awk 'BEGIN { for (i = 1; i <= 2400; i++) printf "Line %d of the tide table: the reading was taken at the outer mark.\n", i }' | + php maintenance/run.php edit --user "Harbor desk" --summary "Tide table" "Tide table" + printf 'Berth 1 is checked at the start of each watch.\n\nThe lamp was replaced.\n' | + php maintenance/run.php edit --user "Harbor desk" --summary "Lamp replaced" "Berth note 1" + chown -R www-data:www-data /var/www/data + SH + ``` + +3. Install the server in an empty directory and write its `config.json` there: + + ```bash + npm install @professional-wiki/mediawiki-mcp-server@0.24.0 + ``` + + ```json + { + "defaultWiki": "wiki.example.test", + "uploadDirs": [], + "wikis": { + "wiki.example.test": { + "sitename": "Harbor log", + "server": "http://localhost:28941", + "articlepath": "/index.php", + "scriptpath": "", + "token": null, + "private": false + } + } + } + ``` + +4. Record from the repository root. `MCP_TRUSTED_HOSTS` lets the server read the wiki's + own origin from a local address. `MCP_CONTENT_MAX_BYTES` lowers the size at which the + server cuts a page from its default of 75,000 bytes, so that the cut page's file + stays small; the result has the same members at either size. + + ```bash + CONFIG=/config.json MCP_TRUSTED_HOSTS=localhost:28941 MCP_CONTENT_MAX_BYTES=4096 \ + RECORD_SERVER_COMMAND='["node", "/node_modules/@professional-wiki/mediawiki-mcp-server/dist/index.js"]' \ + python source_worker/qualification/record_mapped.py \ + --caller stand_in_channel:local --mapping source_worker/mappings/wiki.json \ + --out source_worker/tests/fixtures/mapped/wiki \ + --scope "Harbor desk" --empty-scope "Quiet desk" --document "Berth note 1" \ + --missing "Berth note 404" --truncated "Tide table" + ``` + +5. Run `make format`, then remove the wiki: `docker rm -f wiki-recording`. + +A recording made again holds other times and row numbers, so `expected.json` and the +`since` argument of `list_changed.json` change with it. diff --git a/source_worker/tests/fixtures/mapped/wiki/expected.json b/source_worker/tests/fixtures/mapped/wiki/expected.json new file mode 100644 index 00000000000..451762609a2 --- /dev/null +++ b/source_worker/tests/fixtures/mapped/wiki/expected.json @@ -0,0 +1,436 @@ +{ + "documents": [ + { + "id": "doc-0001", + "title": "doc-0001", + "text_sha256": "91b80dd2ec23218a38413043401011718ca815dfd19911b1ac41c67fc8c19054", + "link": "https://wiki.example.test/index.php/doc-0001", + "revision": "2026-12-06T10:52:09Z", + "modified_at": "2026-12-06T10:50:39Z" + }, + { + "id": "doc-0002", + "title": "doc-0002", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:52:09Z", + "modified_at": "2026-12-06T10:52:09Z" + }, + { + "id": "doc-0003", + "title": "doc-0003", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:52:08Z", + "modified_at": "2026-12-06T10:52:08Z" + }, + { + "id": "doc-0004", + "title": "doc-0004", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:52:07Z", + "modified_at": "2026-12-06T10:52:07Z" + }, + { + "id": "doc-0005", + "title": "doc-0005", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:52:07Z", + "modified_at": "2026-12-06T10:52:07Z" + }, + { + "id": "doc-0006", + "title": "doc-0006", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:51:02Z", + "modified_at": "2026-12-06T10:51:02Z" + }, + { + "id": "doc-0007", + "title": "doc-0007", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:51:01Z", + "modified_at": "2026-12-06T10:51:01Z" + }, + { + "id": "doc-0008", + "title": "doc-0008", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:51:01Z", + "modified_at": "2026-12-06T10:51:01Z" + }, + { + "id": "doc-0009", + "title": "doc-0009", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:51:00Z", + "modified_at": "2026-12-06T10:51:00Z" + }, + { + "id": "doc-0010", + "title": "doc-0010", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:51:00Z", + "modified_at": "2026-12-06T10:51:00Z" + }, + { + "id": "doc-0011", + "title": "doc-0011", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:59Z", + "modified_at": "2026-12-06T10:50:59Z" + }, + { + "id": "doc-0012", + "title": "doc-0012", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:59Z", + "modified_at": "2026-12-06T10:50:59Z" + }, + { + "id": "doc-0013", + "title": "doc-0013", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:58Z", + "modified_at": "2026-12-06T10:50:58Z" + }, + { + "id": "doc-0014", + "title": "doc-0014", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:58Z", + "modified_at": "2026-12-06T10:50:58Z" + }, + { + "id": "doc-0015", + "title": "doc-0015", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:58Z", + "modified_at": "2026-12-06T10:50:58Z" + }, + { + "id": "doc-0016", + "title": "doc-0016", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:57Z", + "modified_at": "2026-12-06T10:50:57Z" + }, + { + "id": "doc-0017", + "title": "doc-0017", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:57Z", + "modified_at": "2026-12-06T10:50:57Z" + }, + { + "id": "doc-0018", + "title": "doc-0018", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:56Z", + "modified_at": "2026-12-06T10:50:56Z" + }, + { + "id": "doc-0019", + "title": "doc-0019", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:56Z", + "modified_at": "2026-12-06T10:50:56Z" + }, + { + "id": "doc-0020", + "title": "doc-0020", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:55Z", + "modified_at": "2026-12-06T10:50:55Z" + }, + { + "id": "doc-0021", + "title": "doc-0021", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:55Z", + "modified_at": "2026-12-06T10:50:55Z" + }, + { + "id": "doc-0022", + "title": "doc-0022", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:54Z", + "modified_at": "2026-12-06T10:50:54Z" + }, + { + "id": "doc-0023", + "title": "doc-0023", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:54Z", + "modified_at": "2026-12-06T10:50:54Z" + }, + { + "id": "doc-0024", + "title": "doc-0024", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:53Z", + "modified_at": "2026-12-06T10:50:53Z" + }, + { + "id": "doc-0025", + "title": "doc-0025", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:53Z", + "modified_at": "2026-12-06T10:50:53Z" + }, + { + "id": "doc-0026", + "title": "doc-0026", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:52Z", + "modified_at": "2026-12-06T10:50:52Z" + }, + { + "id": "doc-0027", + "title": "doc-0027", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:52Z", + "modified_at": "2026-12-06T10:50:52Z" + }, + { + "id": "doc-0028", + "title": "doc-0028", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:52Z", + "modified_at": "2026-12-06T10:50:52Z" + }, + { + "id": "doc-0029", + "title": "doc-0029", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:51Z", + "modified_at": "2026-12-06T10:50:51Z" + }, + { + "id": "doc-0030", + "title": "doc-0030", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:51Z", + "modified_at": "2026-12-06T10:50:51Z" + }, + { + "id": "doc-0031", + "title": "doc-0031", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:50Z", + "modified_at": "2026-12-06T10:50:50Z" + }, + { + "id": "doc-0032", + "title": "doc-0032", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:50Z", + "modified_at": "2026-12-06T10:50:50Z" + }, + { + "id": "doc-0033", + "title": "doc-0033", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:49Z", + "modified_at": "2026-12-06T10:50:49Z" + }, + { + "id": "doc-0034", + "title": "doc-0034", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:49Z", + "modified_at": "2026-12-06T10:50:49Z" + }, + { + "id": "doc-0035", + "title": "doc-0035", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:48Z", + "modified_at": "2026-12-06T10:50:48Z" + }, + { + "id": "doc-0036", + "title": "doc-0036", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:48Z", + "modified_at": "2026-12-06T10:50:48Z" + }, + { + "id": "doc-0037", + "title": "doc-0037", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:47Z", + "modified_at": "2026-12-06T10:50:47Z" + }, + { + "id": "doc-0038", + "title": "doc-0038", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:47Z", + "modified_at": "2026-12-06T10:50:47Z" + }, + { + "id": "doc-0039", + "title": "doc-0039", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:47Z", + "modified_at": "2026-12-06T10:50:47Z" + }, + { + "id": "doc-0040", + "title": "doc-0040", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:46Z", + "modified_at": "2026-12-06T10:50:46Z" + }, + { + "id": "doc-0041", + "title": "doc-0041", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:46Z", + "modified_at": "2026-12-06T10:50:46Z" + }, + { + "id": "doc-0042", + "title": "doc-0042", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:45Z", + "modified_at": "2026-12-06T10:50:45Z" + }, + { + "id": "doc-0043", + "title": "doc-0043", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:45Z", + "modified_at": "2026-12-06T10:50:45Z" + }, + { + "id": "doc-0044", + "title": "doc-0044", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:44Z", + "modified_at": "2026-12-06T10:50:44Z" + }, + { + "id": "doc-0045", + "title": "doc-0045", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:44Z", + "modified_at": "2026-12-06T10:50:44Z" + }, + { + "id": "doc-0046", + "title": "doc-0046", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:43Z", + "modified_at": "2026-12-06T10:50:43Z" + }, + { + "id": "doc-0047", + "title": "doc-0047", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:43Z", + "modified_at": "2026-12-06T10:50:43Z" + }, + { + "id": "doc-0048", + "title": "doc-0048", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:42Z", + "modified_at": "2026-12-06T10:50:42Z" + }, + { + "id": "doc-0049", + "title": "doc-0049", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:42Z", + "modified_at": "2026-12-06T10:50:42Z" + }, + { + "id": "doc-0050", + "title": "doc-0050", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:41Z", + "modified_at": "2026-12-06T10:50:41Z" + }, + { + "id": "doc-0051", + "title": "doc-0051", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:41Z", + "modified_at": "2026-12-06T10:50:41Z" + }, + { + "id": "doc-0052", + "title": "doc-0052", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:40Z", + "modified_at": "2026-12-06T10:50:40Z" + }, + { + "id": "doc-0053", + "title": "doc-0053", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:40Z", + "modified_at": "2026-12-06T10:50:40Z" + }, + { + "id": "doc-0054", + "title": "doc-0054", + "text_sha256": "", + "link": "", + "revision": "2026-12-06T10:50:40Z", + "modified_at": "2026-12-06T10:50:40Z" + } + ] +} diff --git a/source_worker/tests/fixtures/mapped/wiki/fetch.json b/source_worker/tests/fixtures/mapped/wiki/fetch.json new file mode 100644 index 00000000000..200fc0ac37a --- /dev/null +++ b/source_worker/tests/fixtures/mapped/wiki/fetch.json @@ -0,0 +1,28 @@ +{ + "name": "get-page", + "arguments": { + "title": "doc-0001", + "metadata": true + }, + "result": { + "content": [ + { + "type": "text", + "text": "Latest revision ID: 56\nPage ID: 2\nTitle: doc-0001\nLatest revision timestamp: 2026-12-06T10:52:09Z\nContent model: wikitext\nSize: 70\nSections:\n- 0 (Lead)\nURL: https://wiki.example.test/index.php/doc-0001\nSource:\n\nBerth 1 is checked at the start of each watch.\n\nThe lamp was replaced.\n\nWiki: wiki.example.test" + } + ], + "isError": false, + "structuredContent": { + "latestRevisionId": 56, + "pageId": 2, + "title": "doc-0001", + "latestRevisionTimestamp": "2026-12-06T10:52:09Z", + "contentModel": "wikitext", + "size": 70, + "sections": ["0 (Lead)"], + "url": "https://wiki.example.test/index.php/doc-0001", + "source": "Berth 1 is checked at the start of each watch.\n\nThe lamp was replaced.", + "wiki": "wiki.example.test" + } + } +} diff --git a/source_worker/tests/fixtures/mapped/wiki/fetch_missing.json b/source_worker/tests/fixtures/mapped/wiki/fetch_missing.json new file mode 100644 index 00000000000..0a3be113f9b --- /dev/null +++ b/source_worker/tests/fixtures/mapped/wiki/fetch_missing.json @@ -0,0 +1,16 @@ +{ + "name": "get-page", + "arguments": { + "title": "doc-0055", + "metadata": true + }, + "result": { + "content": [ + { + "type": "text", + "text": "{\"category\":\"not_found\",\"message\":\"Page \\\"doc-0055\\\" not found\"}" + } + ], + "isError": true + } +} diff --git a/source_worker/tests/fixtures/mapped/wiki/fetch_truncated.json b/source_worker/tests/fixtures/mapped/wiki/fetch_truncated.json new file mode 100644 index 00000000000..89ed640e430 --- /dev/null +++ b/source_worker/tests/fixtures/mapped/wiki/fetch_truncated.json @@ -0,0 +1,36 @@ +{ + "name": "get-page", + "arguments": { + "title": "doc-0002", + "metadata": true + }, + "result": { + "content": [ + { + "type": "text", + "text": "Latest revision ID: 55\nPage ID: 55\nTitle: doc-0002\nLatest revision timestamp: 2026-12-06T10:52:09Z\nContent model: wikitext\nSize: 166892\nSections:\n- 0 (Lead)\nURL: https://wiki.example.test/index.php/doc-0002\nSource:\n\nLine 1 of the tide table: the reading was taken at the outer mark.\nLine 2 of the tide table: the reading was taken at the outer mark.\nLine 3 of the tide table: the reading was taken at the outer mark.\nLine 4 of the tide table: the reading was taken at the outer mark.\nLine 5 of the tide table: the reading was taken at the outer mark.\nLine 6 of the tide table: the reading was taken at the outer mark.\nLine 7 of the tide table: the reading was taken at the outer mark.\nLine 8 of the tide table: the reading was taken at the outer mark.\nLine 9 of the tide table: the reading was taken at the outer mark.\nLine 10 of the tide table: the reading was taken at the outer mark.\nLine 11 of the tide table: the reading was taken at the outer mark.\nLine 12 of the tide table: the reading was taken at the outer mark.\nLine 13 of the tide table: the reading was taken at the outer mark.\nLine 14 of the tide table: the reading was taken at the outer mark.\nLine 15 of the tide table: the reading was taken at the outer mark.\nLine 16 of the tide table: the reading was taken at the outer mark.\nLine 17 of the tide table: the reading was taken at the outer mark.\nLine 18 of the tide table: the reading was taken at the outer mark.\nLine 19 of the tide table: the reading was taken at the outer mark.\nLine 20 of the tide table: the reading was taken at the outer mark.\nLine 21 of the tide table: the reading was taken at the outer mark.\nLine 22 of the tide table: the reading was taken at the outer mark.\nLine 23 of the tide table: the reading was taken at the outer mark.\nLine 24 of the tide table: the reading was taken at the outer mark.\nLine 25 of the tide table: the reading was taken at the outer mark.\nLine 26 of the tide table: the reading was taken at the outer mark.\nLine 27 of the tide table: the reading was taken at the outer mark.\nLine 28 of the tide table: the reading was taken at the outer mark.\nLine 29 of the tide table: the reading was taken at the outer mark.\nLine 30 of the tide table: the reading was taken at the outer mark.\nLine 31 of the tide table: the reading was taken at the outer mark.\nLine 32 of the tide table: the reading was taken at the outer mark.\nLine 33 of the tide table: the reading was taken at the outer mark.\nLine 34 of the tide table: the reading was taken at the outer mark.\nLine 35 of the tide table: the reading was taken at the outer mark.\nLine 36 of the tide table: the reading was taken at the outer mark.\nLine 37 of the tide table: the reading was taken at the outer mark.\nLine 38 of the tide table: the reading was taken at the outer mark.\nLine 39 of the tide table: the reading was taken at the outer mark.\nLine 40 of the tide table: the reading was taken at the outer mark.\nLine 41 of the tide table: the reading was taken at the outer mark.\nLine 42 of the tide table: the reading was taken at the outer mark.\nLine 43 of the tide table: the reading was taken at the outer mark.\nLine 44 of the tide table: the reading was taken at the outer mark.\nLine 45 of the tide table: the reading was taken at the outer mark.\nLine 46 of the tide table: the reading was taken at the outer mark.\nLine 47 of the tide table: the reading was taken at the outer mark.\nLine 48 of the tide table: the reading was taken at the outer mark.\nLine 49 of the tide table: the reading was taken at the outer mark.\nLine 50 of the tide table: the reading was taken at the outer mark.\nLine 51 of the tide table: the reading was taken at the outer mark.\nLine 52 of the tide table: the reading was taken at the outer mark.\nLine 53 of the tide table: the reading was taken at the outer mark.\nLine 54 of the tide table: the reading was taken at the outer mark.\nLine 55 of the tide table: the reading was taken at the outer mark.\nLine 56 of the tide table: the reading was taken at the outer mark.\nLine 57 of the tide table: the reading was taken at the outer mark.\nLine 58 of the tide table: the reading was taken at the outer mark.\nLine 59 of the tide table: the reading was taken at the outer mark.\nLine 60 of the tide table: the reading was taken at the outer mark.\nLine 61 of the tide table\n\nTruncation:\n Reason: content-truncated\n Returned bytes: 4096\n Total bytes: 166892\n Item noun: wikitext\n Tool name: get-page\n Remedy hint: The page has no sections, so no narrower read returns more of it.\nWiki: wiki.example.test" + } + ], + "isError": false, + "structuredContent": { + "latestRevisionId": 55, + "pageId": 55, + "title": "doc-0002", + "latestRevisionTimestamp": "2026-12-06T10:52:09Z", + "contentModel": "wikitext", + "size": 166892, + "sections": ["0 (Lead)"], + "url": "https://wiki.example.test/index.php/doc-0002", + "source": "Line 1 of the tide table: the reading was taken at the outer mark.\nLine 2 of the tide table: the reading was taken at the outer mark.\nLine 3 of the tide table: the reading was taken at the outer mark.\nLine 4 of the tide table: the reading was taken at the outer mark.\nLine 5 of the tide table: the reading was taken at the outer mark.\nLine 6 of the tide table: the reading was taken at the outer mark.\nLine 7 of the tide table: the reading was taken at the outer mark.\nLine 8 of the tide table: the reading was taken at the outer mark.\nLine 9 of the tide table: the reading was taken at the outer mark.\nLine 10 of the tide table: the reading was taken at the outer mark.\nLine 11 of the tide table: the reading was taken at the outer mark.\nLine 12 of the tide table: the reading was taken at the outer mark.\nLine 13 of the tide table: the reading was taken at the outer mark.\nLine 14 of the tide table: the reading was taken at the outer mark.\nLine 15 of the tide table: the reading was taken at the outer mark.\nLine 16 of the tide table: the reading was taken at the outer mark.\nLine 17 of the tide table: the reading was taken at the outer mark.\nLine 18 of the tide table: the reading was taken at the outer mark.\nLine 19 of the tide table: the reading was taken at the outer mark.\nLine 20 of the tide table: the reading was taken at the outer mark.\nLine 21 of the tide table: the reading was taken at the outer mark.\nLine 22 of the tide table: the reading was taken at the outer mark.\nLine 23 of the tide table: the reading was taken at the outer mark.\nLine 24 of the tide table: the reading was taken at the outer mark.\nLine 25 of the tide table: the reading was taken at the outer mark.\nLine 26 of the tide table: the reading was taken at the outer mark.\nLine 27 of the tide table: the reading was taken at the outer mark.\nLine 28 of the tide table: the reading was taken at the outer mark.\nLine 29 of the tide table: the reading was taken at the outer mark.\nLine 30 of the tide table: the reading was taken at the outer mark.\nLine 31 of the tide table: the reading was taken at the outer mark.\nLine 32 of the tide table: the reading was taken at the outer mark.\nLine 33 of the tide table: the reading was taken at the outer mark.\nLine 34 of the tide table: the reading was taken at the outer mark.\nLine 35 of the tide table: the reading was taken at the outer mark.\nLine 36 of the tide table: the reading was taken at the outer mark.\nLine 37 of the tide table: the reading was taken at the outer mark.\nLine 38 of the tide table: the reading was taken at the outer mark.\nLine 39 of the tide table: the reading was taken at the outer mark.\nLine 40 of the tide table: the reading was taken at the outer mark.\nLine 41 of the tide table: the reading was taken at the outer mark.\nLine 42 of the tide table: the reading was taken at the outer mark.\nLine 43 of the tide table: the reading was taken at the outer mark.\nLine 44 of the tide table: the reading was taken at the outer mark.\nLine 45 of the tide table: the reading was taken at the outer mark.\nLine 46 of the tide table: the reading was taken at the outer mark.\nLine 47 of the tide table: the reading was taken at the outer mark.\nLine 48 of the tide table: the reading was taken at the outer mark.\nLine 49 of the tide table: the reading was taken at the outer mark.\nLine 50 of the tide table: the reading was taken at the outer mark.\nLine 51 of the tide table: the reading was taken at the outer mark.\nLine 52 of the tide table: the reading was taken at the outer mark.\nLine 53 of the tide table: the reading was taken at the outer mark.\nLine 54 of the tide table: the reading was taken at the outer mark.\nLine 55 of the tide table: the reading was taken at the outer mark.\nLine 56 of the tide table: the reading was taken at the outer mark.\nLine 57 of the tide table: the reading was taken at the outer mark.\nLine 58 of the tide table: the reading was taken at the outer mark.\nLine 59 of the tide table: the reading was taken at the outer mark.\nLine 60 of the tide table: the reading was taken at the outer mark.\nLine 61 of the tide table", + "truncation": { + "reason": "content-truncated", + "returnedBytes": 4096, + "totalBytes": 166892, + "itemNoun": "wikitext", + "toolName": "get-page", + "remedyHint": "The page has no sections, so no narrower read returns more of it." + }, + "wiki": "wiki.example.test" + } + } +} diff --git a/source_worker/tests/fixtures/mapped/wiki/list_changed.json b/source_worker/tests/fixtures/mapped/wiki/list_changed.json new file mode 100644 index 00000000000..579f7852708 --- /dev/null +++ b/source_worker/tests/fixtures/mapped/wiki/list_changed.json @@ -0,0 +1,80 @@ +{ + "name": "get-recent-changes", + "arguments": { + "user": "scope-0001", + "since": "2026-12-06T10:51:09Z" + }, + "result": { + "content": [ + { + "type": "text", + "text": "Changes:\n- Type: edit\n Title: doc-0001\n Timestamp: 2026-12-06T10:52:09Z\n User: scope-0001\n Userid: 3\n Revision ID: 56\n Old revision ID: 2\n Size delta: -43\n Comment: Lamp replaced\n- Type: new\n Title: doc-0002\n Timestamp: 2026-12-06T10:52:09Z\n User: scope-0001\n Userid: 3\n Revision ID: 55\n Old revision ID: 0\n Size delta: 166892\n Comment: doc-0002\n Is new: true\n- Type: new\n Title: doc-0003\n Timestamp: 2026-12-06T10:52:08Z\n User: scope-0001\n Userid: 3\n Revision ID: 54\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0004\n Timestamp: 2026-12-06T10:52:07Z\n User: scope-0001\n Userid: 3\n Revision ID: 53\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0005\n Timestamp: 2026-12-06T10:52:07Z\n User: scope-0001\n Userid: 3\n Revision ID: 52\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\nWiki: wiki.example.test" + } + ], + "isError": false, + "structuredContent": { + "changes": [ + { + "type": "edit", + "title": "doc-0001", + "timestamp": "2026-12-06T10:52:09Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 56, + "oldRevisionId": 2, + "sizeDelta": -43, + "comment": "Lamp replaced" + }, + { + "type": "new", + "title": "doc-0002", + "timestamp": "2026-12-06T10:52:09Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 55, + "oldRevisionId": 0, + "sizeDelta": 166892, + "comment": "doc-0002", + "isNew": true + }, + { + "type": "new", + "title": "doc-0003", + "timestamp": "2026-12-06T10:52:08Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 54, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0004", + "timestamp": "2026-12-06T10:52:07Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 53, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0005", + "timestamp": "2026-12-06T10:52:07Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 52, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + } + ], + "wiki": "wiki.example.test" + } + } +} diff --git a/source_worker/tests/fixtures/mapped/wiki/list_empty.json b/source_worker/tests/fixtures/mapped/wiki/list_empty.json new file mode 100644 index 00000000000..5321e924e65 --- /dev/null +++ b/source_worker/tests/fixtures/mapped/wiki/list_empty.json @@ -0,0 +1,19 @@ +{ + "name": "get-recent-changes", + "arguments": { + "user": "scope-0002" + }, + "result": { + "content": [ + { + "type": "text", + "text": "Changes: (none)\nWiki: wiki.example.test" + } + ], + "isError": false, + "structuredContent": { + "changes": [], + "wiki": "wiki.example.test" + } + } +} diff --git a/source_worker/tests/fixtures/mapped/wiki/list_first.json b/source_worker/tests/fixtures/mapped/wiki/list_first.json new file mode 100644 index 00000000000..c47448e84d5 --- /dev/null +++ b/source_worker/tests/fixtures/mapped/wiki/list_first.json @@ -0,0 +1,629 @@ +{ + "name": "get-recent-changes", + "arguments": { + "user": "scope-0001" + }, + "result": { + "content": [ + { + "type": "text", + "text": "Changes:\n- Type: edit\n Title: doc-0001\n Timestamp: 2026-12-06T10:52:09Z\n User: scope-0001\n Userid: 3\n Revision ID: 56\n Old revision ID: 2\n Size delta: -43\n Comment: Lamp replaced\n- Type: new\n Title: doc-0002\n Timestamp: 2026-12-06T10:52:09Z\n User: scope-0001\n Userid: 3\n Revision ID: 55\n Old revision ID: 0\n Size delta: 166892\n Comment: doc-0002\n Is new: true\n- Type: new\n Title: doc-0003\n Timestamp: 2026-12-06T10:52:08Z\n User: scope-0001\n Userid: 3\n Revision ID: 54\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0004\n Timestamp: 2026-12-06T10:52:07Z\n User: scope-0001\n Userid: 3\n Revision ID: 53\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0005\n Timestamp: 2026-12-06T10:52:07Z\n User: scope-0001\n Userid: 3\n Revision ID: 52\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0006\n Timestamp: 2026-12-06T10:51:02Z\n User: scope-0001\n Userid: 3\n Revision ID: 51\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0007\n Timestamp: 2026-12-06T10:51:01Z\n User: scope-0001\n Userid: 3\n Revision ID: 50\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0008\n Timestamp: 2026-12-06T10:51:01Z\n User: scope-0001\n Userid: 3\n Revision ID: 49\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0009\n Timestamp: 2026-12-06T10:51:00Z\n User: scope-0001\n Userid: 3\n Revision ID: 48\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0010\n Timestamp: 2026-12-06T10:51:00Z\n User: scope-0001\n Userid: 3\n Revision ID: 47\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0011\n Timestamp: 2026-12-06T10:50:59Z\n User: scope-0001\n Userid: 3\n Revision ID: 46\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0012\n Timestamp: 2026-12-06T10:50:59Z\n User: scope-0001\n Userid: 3\n Revision ID: 45\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0013\n Timestamp: 2026-12-06T10:50:58Z\n User: scope-0001\n Userid: 3\n Revision ID: 44\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0014\n Timestamp: 2026-12-06T10:50:58Z\n User: scope-0001\n Userid: 3\n Revision ID: 43\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0015\n Timestamp: 2026-12-06T10:50:58Z\n User: scope-0001\n Userid: 3\n Revision ID: 42\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0016\n Timestamp: 2026-12-06T10:50:57Z\n User: scope-0001\n Userid: 3\n Revision ID: 41\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0017\n Timestamp: 2026-12-06T10:50:57Z\n User: scope-0001\n Userid: 3\n Revision ID: 40\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0018\n Timestamp: 2026-12-06T10:50:56Z\n User: scope-0001\n Userid: 3\n Revision ID: 39\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0019\n Timestamp: 2026-12-06T10:50:56Z\n User: scope-0001\n Userid: 3\n Revision ID: 38\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0020\n Timestamp: 2026-12-06T10:50:55Z\n User: scope-0001\n Userid: 3\n Revision ID: 37\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0021\n Timestamp: 2026-12-06T10:50:55Z\n User: scope-0001\n Userid: 3\n Revision ID: 36\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0022\n Timestamp: 2026-12-06T10:50:54Z\n User: scope-0001\n Userid: 3\n Revision ID: 35\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0023\n Timestamp: 2026-12-06T10:50:54Z\n User: scope-0001\n Userid: 3\n Revision ID: 34\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0024\n Timestamp: 2026-12-06T10:50:53Z\n User: scope-0001\n Userid: 3\n Revision ID: 33\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0025\n Timestamp: 2026-12-06T10:50:53Z\n User: scope-0001\n Userid: 3\n Revision ID: 32\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0026\n Timestamp: 2026-12-06T10:50:52Z\n User: scope-0001\n Userid: 3\n Revision ID: 31\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0027\n Timestamp: 2026-12-06T10:50:52Z\n User: scope-0001\n Userid: 3\n Revision ID: 30\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0028\n Timestamp: 2026-12-06T10:50:52Z\n User: scope-0001\n Userid: 3\n Revision ID: 29\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0029\n Timestamp: 2026-12-06T10:50:51Z\n User: scope-0001\n Userid: 3\n Revision ID: 28\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0030\n Timestamp: 2026-12-06T10:50:51Z\n User: scope-0001\n Userid: 3\n Revision ID: 27\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0031\n Timestamp: 2026-12-06T10:50:50Z\n User: scope-0001\n Userid: 3\n Revision ID: 26\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0032\n Timestamp: 2026-12-06T10:50:50Z\n User: scope-0001\n Userid: 3\n Revision ID: 25\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0033\n Timestamp: 2026-12-06T10:50:49Z\n User: scope-0001\n Userid: 3\n Revision ID: 24\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0034\n Timestamp: 2026-12-06T10:50:49Z\n User: scope-0001\n Userid: 3\n Revision ID: 23\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0035\n Timestamp: 2026-12-06T10:50:48Z\n User: scope-0001\n Userid: 3\n Revision ID: 22\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0036\n Timestamp: 2026-12-06T10:50:48Z\n User: scope-0001\n Userid: 3\n Revision ID: 21\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0037\n Timestamp: 2026-12-06T10:50:47Z\n User: scope-0001\n Userid: 3\n Revision ID: 20\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0038\n Timestamp: 2026-12-06T10:50:47Z\n User: scope-0001\n Userid: 3\n Revision ID: 19\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0039\n Timestamp: 2026-12-06T10:50:47Z\n User: scope-0001\n Userid: 3\n Revision ID: 18\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0040\n Timestamp: 2026-12-06T10:50:46Z\n User: scope-0001\n Userid: 3\n Revision ID: 17\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0041\n Timestamp: 2026-12-06T10:50:46Z\n User: scope-0001\n Userid: 3\n Revision ID: 16\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0042\n Timestamp: 2026-12-06T10:50:45Z\n User: scope-0001\n Userid: 3\n Revision ID: 15\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0043\n Timestamp: 2026-12-06T10:50:45Z\n User: scope-0001\n Userid: 3\n Revision ID: 14\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0044\n Timestamp: 2026-12-06T10:50:44Z\n User: scope-0001\n Userid: 3\n Revision ID: 13\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0045\n Timestamp: 2026-12-06T10:50:44Z\n User: scope-0001\n Userid: 3\n Revision ID: 12\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0046\n Timestamp: 2026-12-06T10:50:43Z\n User: scope-0001\n Userid: 3\n Revision ID: 11\n Old revision ID: 0\n Size delta: 114\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0047\n Timestamp: 2026-12-06T10:50:43Z\n User: scope-0001\n Userid: 3\n Revision ID: 10\n Old revision ID: 0\n Size delta: 113\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0048\n Timestamp: 2026-12-06T10:50:42Z\n User: scope-0001\n Userid: 3\n Revision ID: 9\n Old revision ID: 0\n Size delta: 113\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0049\n Timestamp: 2026-12-06T10:50:42Z\n User: scope-0001\n Userid: 3\n Revision ID: 8\n Old revision ID: 0\n Size delta: 113\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0050\n Timestamp: 2026-12-06T10:50:41Z\n User: scope-0001\n Userid: 3\n Revision ID: 7\n Old revision ID: 0\n Size delta: 113\n Comment: Watch note\n Is new: true\nTruncation:\n Reason: more-available\n Returned count: 50\n Item noun: changes\n Tool name: get-recent-changes\n Continue with:\n Param: continue\n Value: cursor-0001\nWiki: wiki.example.test" + } + ], + "isError": false, + "structuredContent": { + "changes": [ + { + "type": "edit", + "title": "doc-0001", + "timestamp": "2026-12-06T10:52:09Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 56, + "oldRevisionId": 2, + "sizeDelta": -43, + "comment": "Lamp replaced" + }, + { + "type": "new", + "title": "doc-0002", + "timestamp": "2026-12-06T10:52:09Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 55, + "oldRevisionId": 0, + "sizeDelta": 166892, + "comment": "doc-0002", + "isNew": true + }, + { + "type": "new", + "title": "doc-0003", + "timestamp": "2026-12-06T10:52:08Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 54, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0004", + "timestamp": "2026-12-06T10:52:07Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 53, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0005", + "timestamp": "2026-12-06T10:52:07Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 52, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0006", + "timestamp": "2026-12-06T10:51:02Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 51, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0007", + "timestamp": "2026-12-06T10:51:01Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 50, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0008", + "timestamp": "2026-12-06T10:51:01Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 49, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0009", + "timestamp": "2026-12-06T10:51:00Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 48, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0010", + "timestamp": "2026-12-06T10:51:00Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 47, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0011", + "timestamp": "2026-12-06T10:50:59Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 46, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0012", + "timestamp": "2026-12-06T10:50:59Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 45, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0013", + "timestamp": "2026-12-06T10:50:58Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 44, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0014", + "timestamp": "2026-12-06T10:50:58Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 43, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0015", + "timestamp": "2026-12-06T10:50:58Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 42, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0016", + "timestamp": "2026-12-06T10:50:57Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 41, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0017", + "timestamp": "2026-12-06T10:50:57Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 40, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0018", + "timestamp": "2026-12-06T10:50:56Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 39, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0019", + "timestamp": "2026-12-06T10:50:56Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 38, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0020", + "timestamp": "2026-12-06T10:50:55Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 37, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0021", + "timestamp": "2026-12-06T10:50:55Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 36, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0022", + "timestamp": "2026-12-06T10:50:54Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 35, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0023", + "timestamp": "2026-12-06T10:50:54Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 34, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0024", + "timestamp": "2026-12-06T10:50:53Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 33, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0025", + "timestamp": "2026-12-06T10:50:53Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 32, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0026", + "timestamp": "2026-12-06T10:50:52Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 31, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0027", + "timestamp": "2026-12-06T10:50:52Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 30, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0028", + "timestamp": "2026-12-06T10:50:52Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 29, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0029", + "timestamp": "2026-12-06T10:50:51Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 28, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0030", + "timestamp": "2026-12-06T10:50:51Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 27, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0031", + "timestamp": "2026-12-06T10:50:50Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 26, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0032", + "timestamp": "2026-12-06T10:50:50Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 25, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0033", + "timestamp": "2026-12-06T10:50:49Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 24, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0034", + "timestamp": "2026-12-06T10:50:49Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 23, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0035", + "timestamp": "2026-12-06T10:50:48Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 22, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0036", + "timestamp": "2026-12-06T10:50:48Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 21, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0037", + "timestamp": "2026-12-06T10:50:47Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 20, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0038", + "timestamp": "2026-12-06T10:50:47Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 19, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0039", + "timestamp": "2026-12-06T10:50:47Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 18, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0040", + "timestamp": "2026-12-06T10:50:46Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 17, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0041", + "timestamp": "2026-12-06T10:50:46Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 16, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0042", + "timestamp": "2026-12-06T10:50:45Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 15, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0043", + "timestamp": "2026-12-06T10:50:45Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 14, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0044", + "timestamp": "2026-12-06T10:50:44Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 13, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0045", + "timestamp": "2026-12-06T10:50:44Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 12, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0046", + "timestamp": "2026-12-06T10:50:43Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 11, + "oldRevisionId": 0, + "sizeDelta": 114, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0047", + "timestamp": "2026-12-06T10:50:43Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 10, + "oldRevisionId": 0, + "sizeDelta": 113, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0048", + "timestamp": "2026-12-06T10:50:42Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 9, + "oldRevisionId": 0, + "sizeDelta": 113, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0049", + "timestamp": "2026-12-06T10:50:42Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 8, + "oldRevisionId": 0, + "sizeDelta": 113, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0050", + "timestamp": "2026-12-06T10:50:41Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 7, + "oldRevisionId": 0, + "sizeDelta": 113, + "comment": "Watch note", + "isNew": true + } + ], + "truncation": { + "reason": "more-available", + "returnedCount": 50, + "itemNoun": "changes", + "toolName": "get-recent-changes", + "continueWith": { + "param": "continue", + "value": "cursor-0001" + } + }, + "wiki": "wiki.example.test" + } + } +} diff --git a/source_worker/tests/fixtures/mapped/wiki/list_second.json b/source_worker/tests/fixtures/mapped/wiki/list_second.json new file mode 100644 index 00000000000..b030f830d03 --- /dev/null +++ b/source_worker/tests/fixtures/mapped/wiki/list_second.json @@ -0,0 +1,81 @@ +{ + "name": "get-recent-changes", + "arguments": { + "user": "scope-0001", + "continue": "cursor-0001" + }, + "result": { + "content": [ + { + "type": "text", + "text": "Changes:\n- Type: new\n Title: doc-0051\n Timestamp: 2026-12-06T10:50:41Z\n User: scope-0001\n Userid: 3\n Revision ID: 6\n Old revision ID: 0\n Size delta: 113\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0052\n Timestamp: 2026-12-06T10:50:40Z\n User: scope-0001\n Userid: 3\n Revision ID: 5\n Old revision ID: 0\n Size delta: 113\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0053\n Timestamp: 2026-12-06T10:50:40Z\n User: scope-0001\n Userid: 3\n Revision ID: 4\n Old revision ID: 0\n Size delta: 113\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0054\n Timestamp: 2026-12-06T10:50:40Z\n User: scope-0001\n Userid: 3\n Revision ID: 3\n Old revision ID: 0\n Size delta: 113\n Comment: Watch note\n Is new: true\n- Type: new\n Title: doc-0001\n Timestamp: 2026-12-06T10:50:39Z\n User: scope-0001\n Userid: 3\n Revision ID: 2\n Old revision ID: 0\n Size delta: 113\n Comment: Watch note\n Is new: true\nWiki: wiki.example.test" + } + ], + "isError": false, + "structuredContent": { + "changes": [ + { + "type": "new", + "title": "doc-0051", + "timestamp": "2026-12-06T10:50:41Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 6, + "oldRevisionId": 0, + "sizeDelta": 113, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0052", + "timestamp": "2026-12-06T10:50:40Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 5, + "oldRevisionId": 0, + "sizeDelta": 113, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0053", + "timestamp": "2026-12-06T10:50:40Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 4, + "oldRevisionId": 0, + "sizeDelta": 113, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0054", + "timestamp": "2026-12-06T10:50:40Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 3, + "oldRevisionId": 0, + "sizeDelta": 113, + "comment": "Watch note", + "isNew": true + }, + { + "type": "new", + "title": "doc-0001", + "timestamp": "2026-12-06T10:50:39Z", + "user": "scope-0001", + "userid": 3, + "revisionId": 2, + "oldRevisionId": 0, + "sizeDelta": 113, + "comment": "Watch note", + "isNew": true + } + ], + "wiki": "wiki.example.test" + } + } +} diff --git a/source_worker/tests/fixtures/mapped/wiki/tools.json b/source_worker/tests/fixtures/mapped/wiki/tools.json new file mode 100644 index 00000000000..7548f2d12e2 --- /dev/null +++ b/source_worker/tests/fixtures/mapped/wiki/tools.json @@ -0,0 +1,123 @@ +[ + { + "name": "get-page", + "inputSchema": { + "type": "object", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "title": { + "type": "string", + "description": "Wiki page title" + }, + "content": { + "default": "source", + "description": "Type of content to return", + "type": "string", + "enum": ["source", "html", "none"] + }, + "metadata": { + "default": false, + "description": "Whether to include metadata (page ID, revision info, size, section outline) in the response", + "type": "boolean" + }, + "section": { + "description": "Section number (0 = lead; 1..N = heading sections). Narrows content to one section.", + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "wiki": { + "description": "Wiki to target, as a key from the mcp://wikis/ resources (e.g. en.wikipedia.org), or the full mcp://wikis/ URI. Omit to use the default wiki.", + "type": "string" + } + }, + "required": ["title"] + }, + "annotations": { + "readOnlyHint": true + } + }, + { + "name": "get-recent-changes", + "inputSchema": { + "type": "object", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "since": { + "description": "ISO 8601 timestamp — only return changes at or after this time", + "type": "string" + }, + "until": { + "description": "ISO 8601 timestamp — only return changes at or before this time", + "type": "string" + }, + "namespace": { + "description": "Namespace IDs to restrict the feed to — e.g. [0, 1] for main and talk", + "minItems": 1, + "type": "array", + "items": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "types": { + "description": "Event types to include. Defaults to edit and new (content changes only).", + "minItems": 1, + "type": "array", + "items": { + "type": "string", + "enum": ["edit", "new", "log", "categorize", "external"] + } + }, + "user": { + "description": "Username — return only changes by this user. Mutually exclusive with excludeUser.", + "type": "string" + }, + "excludeUser": { + "description": "Username — exclude changes by this user. Mutually exclusive with user.", + "type": "string" + }, + "tag": { + "description": "Change tag — return only changes carrying this tag", + "type": "string" + }, + "hideBots": { + "description": "Omit bot-flagged edits", + "type": "boolean" + }, + "hideMinor": { + "description": "Omit minor-flagged edits", + "type": "boolean" + }, + "hideAnon": { + "description": "Omit edits by anonymous users", + "type": "boolean" + }, + "hideRedirects": { + "description": "Omit changes whose target is a redirect", + "type": "boolean" + }, + "hidePatrolled": { + "description": "Omit patrolled edits. Requires patrol rights.", + "type": "boolean" + }, + "showPatrolStatus": { + "description": "Include per-row patrol status; adds an \"Unpatrolled: yes\" line to unpatrolled rows. Requires patrol rights.", + "type": "boolean" + }, + "continue": { + "description": "Continuation token from a prior call's truncation marker", + "type": "string" + }, + "wiki": { + "description": "Wiki to target, as a key from the mcp://wikis/ resources (e.g. en.wikipedia.org), or the full mcp://wikis/ URI. Omit to use the default wiki.", + "type": "string" + } + } + }, + "annotations": { + "readOnlyHint": true + } + } +] diff --git a/source_worker/tests/test_mapping_proof.py b/source_worker/tests/test_mapping_proof.py index 023d78569c0..539db313377 100644 --- a/source_worker/tests/test_mapping_proof.py +++ b/source_worker/tests/test_mapping_proof.py @@ -1,23 +1,38 @@ """The mapped reader on a recording: one server's tool definitions and results, -replayed through a scripted tool channel that refuses every call it did not record.""" +replayed through a scripted tool channel that refuses every call it did not record. + +`example` is built by hand for a made-up server. `wiki` holds what an open-source +wiki's protocol server answered, and is read with the reference mapping.""" from __future__ import annotations import asyncio import hashlib import json +import re from collections.abc import Callable from dataclasses import replace +from datetime import UTC, datetime from pathlib import Path from typing import Any +from urllib.parse import urlsplit import pytest from loom_source_worker.mapping import Mapping, definition_digest, fill, load from loom_source_worker.readers.mcp_mapped import MappedReader -from loom_source_worker.sync_types import Page, ReaderError, ToolDefinition, ToolResult -from record_mapped import CALLS, NEUTRAL, Replay, placed, upstream_ids +from loom_source_worker.sync_types import ( + Page, + ReaderError, + ToolCaller, + ToolDefinition, + ToolResult, +) +from record_mapped import CALLS, NEUTRAL, Replay, expected, placed, upstream_ids +from stand_in_channel import Channel _DIR = Path(__file__).parent / "fixtures" / "mapped" / "example" +_WIKI = _DIR.parent / "wiki" +_REFERENCE = Path(__file__).parents[1] / "mappings" / "wiki.json" _SCOPE = "scope-0001" @@ -32,13 +47,13 @@ def _mapping(change: Callable[[dict[str, Any]], Any] | None = None) -> Mapping: return load(json.dumps(raw).encode()) -def _expected() -> dict[str, dict[str, str]]: - documents = json.loads((_DIR / "expected.json").read_text())["documents"] +def _expected(directory: Path = _DIR) -> dict[str, dict[str, str]]: + documents = json.loads((directory / "expected.json").read_text())["documents"] return {document["id"]: document for document in documents} -def _reader(mapping: Mapping, replay: Replay, scope: str = _SCOPE) -> MappedReader: - return MappedReader(mapping, replay, items=[], scope=scope) +def _reader(mapping: Mapping, caller: ToolCaller, scope: str = _SCOPE) -> MappedReader: + return MappedReader(mapping, caller, items=[], scope=scope) async def _pages( @@ -333,19 +348,281 @@ async def test_an_empty_listing_yields_one_empty_page(mapping: Mapping, replay: assert (page.items, page.gone, page.complete) == ([], [], True) -async def test_no_fixture_holds_an_upstream_id_or_name(mapping: Mapping, replay: Replay) -> None: +def _nested_cursor(raw: dict[str, Any]) -> None: + """The cursor two members down, as a server that reports it inside a paging member.""" + raw["list"]["next_cursor_path"] = ["paging", "next", "value"] + + +def _paging(replay: Replay, call: str, **member: Any) -> None: + """The recorded listing with its cursor left out, or with `paging` as given.""" + + def change(value: dict[str, Any]) -> None: + del value["next_cursor"] + value.update(member) + + _listing(change)(replay.recorded[call]["result"]) + + +_LAST_PAGE: dict[str, dict[str, Any]] = { + "the member is absent": {}, + "the member is null": {"paging": None}, + "the member holds nothing": {"paging": {}}, + "the member under it is null": {"paging": {"next": None}}, + "the member under it holds nothing": {"paging": {"next": {}}}, + "the cursor is null": {"paging": {"next": {"value": None}}}, + "the cursor is empty": {"paging": {"next": {"value": ""}}}, +} + + +@pytest.mark.parametrize("case", sorted(_LAST_PAGE)) +async def test_a_listing_ends_when_the_cursor_member_is_absent(replay: Replay, case: str) -> None: + nested = _mapping(_nested_cursor) + _paging(replay, "list_first", paging={"next": {"value": "cursor-0001"}}) + _paging(replay, "list_second", **_LAST_PAGE[case]) + pages = await _pages(_reader(nested, replay)) + assert [item.id for page in pages for item in page.items] == list(_expected()) + assert [page.more for page in pages] == [True, False] + assert json.loads(pages[-1].checkpoint)["cursor"] is None + + # A scope that lists nothing has no such member either. + _paging(replay, "list_empty", **_LAST_PAGE[case]) + (page,) = await _pages(_reader(nested, replay, scope="scope-0002")) + assert (page.items, page.more) == ([], False) + + +# Each value is falsy, so a reader that took any empty value for an absent member +# would end the listing here and drop the pages after it. +_WRONG_TYPE: dict[str, Any] = { + "a string where the member is an object": "", + "a list where the member is an object": [], + "a number where the member is an object": 0, + "a string where the member under it is an object": {"next": ""}, + "a list where the member under it is an object": {"next": []}, + "a number where the member under it is an object": {"next": 0}, + "a number as the cursor": {"next": {"value": 0}}, +} + + +@pytest.mark.parametrize("case", sorted(_WRONG_TYPE)) +async def test_a_cursor_member_of_the_wrong_type_still_refuses(replay: Replay, case: str) -> None: + _paging(replay, "list_first", paging=_WRONG_TYPE[case]) + assert await _code(_pages(_reader(_mapping(_nested_cursor), replay))) == "protocol" + + +async def test_an_item_field_keeps_the_last_key_rule(replay: Replay) -> None: + nested = _mapping(lambda raw: raw["list"].update(title_path=["properties", "title"])) + + def under_properties(value: dict[str, Any]) -> None: + for row in value["results"]: + row["properties"] = {"title": row.pop("title")} + + for call in ("list_first", "list_second"): + _listing(under_properties)(replay.recorded[call]["result"]) + expected = _expected() + titles = [item.title for page in await _pages(_reader(nested, replay)) for item in page.items] + assert titles == [document["title"] for document in expected.values()] + + # The last key may be absent: the item has no title. + _listing(lambda value: value["results"][0]["properties"].clear())( + replay.recorded["list_first"]["result"] + ) + (first, _), _ = [page.items for page in await _pages(_reader(nested, replay))] + assert (first.id, first.title) == ("doc-0001", "") + + # The member that holds it may not: null, or left out. + for change in ( + lambda value: value["results"][0].update(properties=None), + lambda value: value["results"][0].pop("properties"), + ): + _listing(change)(replay.recorded["list_first"]["result"]) + assert await _code(_pages(_reader(nested, replay))) == "protocol" + + +def _reference() -> Mapping: + return load(_REFERENCE.read_bytes()) + + +def _structured(replay: Replay, call: str) -> dict[str, Any]: + value: dict[str, Any] = replay.recorded[call]["result"]["structuredContent"] + return value + + +def _asked(mapping: Mapping, replay: Replay, call: str) -> str: + """The document a recorded fetch asked for.""" + asked: str = placed(mapping.fetch.arguments, replay.recorded[call]["arguments"])["document_id"] + return asked + + +_RECORDINGS: dict[str, tuple[Path, Callable[[], Mapping]]] = { + "example": (_DIR, _mapping), + "wiki": (_WIKI, _reference), +} +_URL = re.compile(r"https?://[^\s\"\\]+") + + +@pytest.mark.parametrize("recording", sorted(_RECORDINGS)) +async def test_no_fixture_holds_an_upstream_id_or_name(recording: str) -> None: + directory, load_mapping = _RECORDINGS[recording] + mapping, replay = load_mapping(), Replay(directory) assert mapping.listing is not None - for name in (*CALLS, "expected"): - assert upstream_ids((_DIR / f"{name}.json").read_text()) == [], name + # The wiki had no page its reader may not read, so that recording holds no denial. + assert set(CALLS) - set(replay.recorded) == ({"fetch_denied"} if recording == "wiki" else set()) + # The definitions are written as advertised, so only an id is looked for in them. + assert upstream_ids((directory / "tools.json").read_text()) == [] + for name in (*replay.recorded, "expected"): + text = (directory / f"{name}.json").read_text() + assert upstream_ids(text) == [], name + for url in _URL.findall(text): + link = urlsplit(url) + # A link is on the made-up origin the mapping approves and ends in a neutral + # value: no file names a real host or spells a document's name in a link. + assert f"{link.scheme}://{link.netloc}" in mapping.link_origins, (name, url) + assert NEUTRAL.fullmatch(link.path.rpartition("/")[2]), (name, url) assert upstream_ids( "the page 0b9f6a52-3c1d-4e7a-9f20-6d5c4b3a2e1f, also 0B9F6A523C1D4E7A9F206D5C4B3A2E1F" ) ids = [item.id for page in await _pages(_reader(mapping, replay)) for item in page.items] - assert ids == list(_expected()) + # A listing of changes names a page once a change; the expected file holds it once. + assert list(dict.fromkeys(ids)) == list(_expected(directory)) for call in replay.recorded.values(): part = mapping.fetch if call["name"] == mapping.fetch.tool else mapping.listing at = placed(part.arguments, call["arguments"]) ids += [at[name] for name in ("document_id", "scope", "cursor") if name in at] - ids.append(_listing_text(replay, "list_first")["next_cursor"]) + if recording == "example": + ids.append(_listing_text(replay, "list_first")["next_cursor"]) + else: + ids.append(_structured(replay, "list_first")["truncation"]["continueWith"]["value"]) + # The server names the page and the user of every change, and its wiki. + for call in ("list_first", "list_second", "list_changed"): + for change in _structured(replay, call)["changes"]: + ids += [change["title"], change["user"]] + results = [call["result"] for call in replay.recorded.values()] + hosts = { + result["structuredContent"]["wiki"] + for result in results + if "structuredContent" in result + } + assert hosts == {urlsplit(origin).netloc for origin in mapping.link_origins} assert all(NEUTRAL.fullmatch(value) for value in ids), ids + + +async def test_the_reference_mapping_pins_the_recorded_definitions() -> None: + mapping, replay = _reference(), Replay(_WIKI) + assert mapping.listing is not None + assert {tool.name: definition_digest(tool) for tool in replay.tools} == { + mapping.fetch.tool: mapping.fetch.definition_sha256, + mapping.listing.tool: mapping.listing.definition_sha256, + } + assert all(tool.read_only for tool in replay.tools) + + +async def test_the_reference_mapping_reads_what_the_recording_expects() -> None: + mapping, replay = _reference(), Replay(_WIKI) + asked = _asked(mapping, replay, "fetch") + # The recorder reads the directory again as it did when it wrote the file. + assert await expected(mapping, _WIKI, _SCOPE, asked) == json.loads( + (_WIKI / "expected.json").read_text() + ) + document = await _reader(mapping, replay).fetch(asked, deadline=_soon()) + # The server spells a link with the page's name, which the recording replaced. + assert document.link == f"{mapping.link_origins[0]}/index.php/{document.id}" + + +async def test_a_page_changed_twice_is_two_items_and_is_fetched_with_the_older_time() -> None: + mapping, replay = _reference(), Replay(_WIKI) + reader = _reader(mapping, replay) + listed = [item for page in await _pages(reader) for item in page.items] + asked = _asked(mapping, replay, "fetch") + # The server lists every change of a page, newest first, and one page was changed + # twice: it is two items with one id. + ids = [item.id for item in listed] + assert {key for key in ids if ids.count(key) > 1} == {asked} + newer, older = (item for item in listed if item.id == asked) + assert datetime.fromisoformat(newer.revision) > datetime.fromisoformat(older.revision) + assert (older.revision, newer.revision) == (older.modified_at, newer.modified_at) + # A fetch reads the newest revision. Its modified time is that of the item listed + # last for the page, which is the older change. + document = await reader.fetch(asked, deadline=_soon()) + assert (document.revision, document.modified_at) == (newer.revision, older.modified_at) + + +async def test_the_recorded_listing_ends_where_the_server_leaves_its_cursor_member_out() -> None: + mapping, replay = _reference(), Replay(_WIKI) + assert mapping.listing is not None + # The server holds the cursor two members down, and only while a page follows. + cursor = _structured(replay, "list_first")["truncation"]["continueWith"]["value"] + for call in ("list_second", "list_changed", "list_empty"): + assert "truncation" not in _structured(replay, call), call + + # The recorded listing by time was asked from the newest change, so the clock is + # one that is past it. + after = datetime(2027, 1, 1, tzinfo=UTC) + reader = MappedReader(mapping, replay, items=[], scope=_SCOPE, now=lambda: after) + pages = await _pages(reader) + assert [len(page.items) for page in pages] == [50, 5] + assert [page.more for page in pages] == [True, False] + first, second = replay.recorded["list_first"], replay.recorded["list_second"] + assert replay.calls == [ + (first["name"], first["arguments"]), + (second["name"], second["arguments"]), + ] + assert placed(mapping.listing.arguments, replay.calls[1][1])["cursor"] == cursor + # An item is a change, not a page: the listing never names every page of the scope. + assert not any(page.complete for page in pages) + + changed = await _pages(reader, pages[-1].checkpoint, full=False) + recorded = [change["title"] for change in _structured(replay, "list_changed")["changes"]] + assert [item.id for page in changed for item in page.items] == recorded != [] + (nothing,) = await _pages(_reader(mapping, replay, scope="scope-0002")) + assert (nothing.items, nothing.more) == ([], False) + + +async def test_the_recorded_missing_page_is_gone_and_the_cut_page_is_too_large() -> None: + mapping, replay = _reference(), Replay(_WIKI) + reader = _reader(mapping, replay) + await _pages(reader) + missing, cut = (_asked(mapping, replay, call) for call in ("fetch_missing", "fetch_truncated")) + assert await _code(reader.fetch(missing, deadline=_soon())) == "protocol" + assert await reader.removed(missing, deadline=_soon()) == "gone" + # The server cut the page at its own cap and says so in a member the mapping names. + assert "truncation" in _structured(replay, "fetch_truncated") + assert await _code(reader.fetch(cut, deadline=_soon())) == "too_large" + assert await reader.removed(cut, deadline=_soon()) == "unknown" + assert await reader.removed(_asked(mapping, replay, "fetch"), deadline=_soon()) == "present" + + +# What a channel refuses, and the code the worker's status table reads: a sign-in asks +# for a reconnect, a server or a tool that is off blocks the source, and a result over +# the cap counts its one document. +_REFUSALS: dict[str, tuple[dict[str, Any], str]] = { + "the account needs a sign-in": ({"signed_in": False}, "reconnect_required"), + "the server is not enabled": ({"enabled": False}, "server_off"), + "the fetch tool is not allowed": ( + {"refused_tools": frozenset({"get-page"})}, + "tool_not_allowed", + ), + "a result is over the channel's cap": ({"max_result_bytes": 512}, "too_large"), +} + + +@pytest.mark.parametrize("case", sorted(_REFUSALS)) +async def test_a_refusal_of_the_channel_reaches_the_engine_by_its_code(case: str) -> None: + state, code = _REFUSALS[case] + mapping, replay = _reference(), Replay(_WIKI) + reader = _reader(mapping, Channel(replay, **state)) + document = _asked(mapping, replay, "fetch") + assert await _code(reader.fetch(document, deadline=_soon())) == code + # A refusal is no evidence that the page is gone. + assert await reader.removed(document, deadline=_soon()) == "unknown" + assert await reader.removed(_asked(mapping, replay, "fetch_missing"), deadline=_soon()) == ( + "unknown" + ) + # Only a result's size is judged after the call: every other refusal sends nothing. + sent = [name for name, _ in replay.calls] + assert (mapping.fetch.tool in sent) == (code == "too_large") + if code == "tool_not_allowed": + # The other tool still answers, so the listing reads to its end. + assert [page.more for page in await _pages(reader)] == [True, False] + else: + assert await _code(_pages(reader)) == code diff --git a/source_worker/tests/test_record_mapped.py b/source_worker/tests/test_record_mapped.py index b83e0631c16..c3686ab45cc 100644 --- a/source_worker/tests/test_record_mapped.py +++ b/source_worker/tests/test_record_mapped.py @@ -9,6 +9,7 @@ from datetime import datetime from pathlib import Path from typing import Any +from urllib.parse import quote from uuid import NAMESPACE_URL, uuid5 import pytest @@ -34,6 +35,11 @@ class _Workspace: # When page `n` was edited: a day apart, so one page changed since the newest. edited = "2026-02-0{n}T08:00:00.000Z" + @staticmethod + def link(key: str) -> str: + # The link spells the id without its dashes. + return "https://docs.example.test/" + key.replace("-", "") + async def list_tools(self) -> list[ToolDefinition]: return Replay(_EXAMPLE).tools @@ -47,8 +53,7 @@ async def call_tool( { "id": key, "title": f"Notes {n} by {_PERSON}", - # The link spells the id without its dashes. - "url": "https://docs.example.test/" + key.replace("-", ""), + "url": self.link(key), "last_edited_time": self.edited.format(n=n + 1), } for n, key in enumerate(self.pages) @@ -76,6 +81,21 @@ def _fetch(self, key: str) -> ToolResult: return ToolResult(None, [text], False) +class _Titled(_Workspace): + """The same workspace on a server whose ids are titles.""" + + scope, empty = "Field desk", "Night desk" + pages = ["Field note 1", "Field note 2", "Field note (old) 3", "Field note 4"] + missing, denied = "Field note 8", "Field note 9" + + @staticmethod + def link(key: str) -> str: + # One page's link spells a space as `_` and keeps the title's punctuation, the + # next percent-encodes both. + spelled = key.replace(" ", "_") if key[-1] in "13" else quote(key) + return "https://docs.example.test/" + spelled + + def _files(directory: Path) -> dict[str, str]: return {path.name: path.read_text() for path in directory.iterdir()} @@ -142,6 +162,32 @@ async def test_the_recorder_writes_a_recording_without_upstream_ids_or_names( assert all(NEUTRAL.fullmatch(key) for key in ids) +async def test_the_recorder_replaces_an_id_as_a_link_spells_it(tmp_path: Path) -> None: + mapping = load((_EXAMPLE / "mapping.json").read_bytes()) + upstream = _Titled() + await record( + upstream, + mapping, + tmp_path, + scope=upstream.scope, + empty_scope=upstream.empty, + document=upstream.pages[0], + missing=upstream.missing, + truncated=upstream.pages[2], + denied=upstream.denied, + ) + for name, text in _files(tmp_path).items(): + for spelling in ("Field note", "Field_note", "Field%20note"): + assert spelling not in text, name + + reader = MappedReader(mapping, Replay(tmp_path), items=[], scope="scope-0001") + deadline = asyncio.get_running_loop().time() + 30 + pages = [page async for page in reader.list_since(None, full=True, deadline=deadline)] + assert [item.link for page in pages for item in page.items] == [ + f"https://docs.example.test/doc-000{n}" for n in range(1, 5) + ] + + async def test_the_recorder_refuses_a_scope_that_is_not_two_pages(tmp_path: Path) -> None: mapping = load((_EXAMPLE / "mapping.json").read_bytes()) upstream = _Workspace()