witan-code 0.11.1__tar.gz → 0.12.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {witan_code-0.11.1 → witan_code-0.12.1}/CHANGELOG.md +70 -1
- {witan_code-0.11.1 → witan_code-0.12.1}/PKG-INFO +2 -2
- {witan_code-0.11.1 → witan_code-0.12.1}/pyproject.toml +11 -5
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_chunked_load.py +1 -1
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_ingest.py +142 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_remote_proxy.py +11 -4
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_remote_store.py +250 -2
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_store.py +306 -24
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/bridge.py +18 -2
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/cli.py +10 -1
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/github_app.py +11 -1
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/graph.py +4 -17
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/indexer.py +19 -7
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/ingest.py +87 -10
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/remote/store.py +106 -20
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/server.py +47 -25
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/store.py +134 -72
- witan_code-0.11.1/uv.lock +0 -1787
- witan_code-0.11.1/witan_code/chunking.py +0 -80
- {witan_code-0.11.1 → witan_code-0.12.1}/.gitignore +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/README.md +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/config/claude.json +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/config/copilot.json +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/config/pi.json +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/docs/BRANCH_INDEXING.md +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/docs/CLI_REFERENCE.md +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/docs/EDGE_PRECISION_TIERS.md +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/docs/PACKAGE_MAP.md +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/docs/STAGE2_STITCHING.md +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/docs/SYMBOL_FORMAT.md +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/docs/SYMBOL_TABLE.md +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/docs/USER_GUIDE.md +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/install.sh +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/__init__.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/conftest.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_batched_deletes.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_branches.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_bridge.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_cli_dispatch.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_cli_hooks.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_cli_output_format.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_config.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_config_targets.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_context.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_crossrepo.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_edges.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_elicit.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_enrichment.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_github_app.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_graph.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_hooks.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_identity.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_indexer.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_indexer_scope.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_languages.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_maintenance.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_package_map.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_reaper.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_repo.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_server.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_setup.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_stitch.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_symbol_table.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_tasks.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_views.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/tests/test_visualize.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/__init__.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/__main__.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/bridge_extractors.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/config.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/context.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/edges.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/elicit.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/extensions/pi/codegraph.ts +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/hooks.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/identity.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/maintenance.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/output.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/package_map.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/queries/bridge.gq +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/queries/code_mutations.gq +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/queries/code_read.gq +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/queries/delete.gq +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/queries_ts/bash.scm +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/queries_ts/hcl.scm +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/queries_ts/python.scm +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/queries_ts/sql.scm +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/queries_ts/typescript.scm +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/queries_ts/yaml.scm +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/reaper.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/remote/__init__.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/remote/oidc.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/remote/proxy.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/repo.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/schema/bridge-schema.pg +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/schema/code-schema.pg +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/setup.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/skills/witan-code/SKILL.md +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/stitch.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/views.py +0 -0
- {witan_code-0.11.1 → witan_code-0.12.1}/witan_code/visualize.py +0 -0
|
@@ -6,6 +6,74 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/) (pre-1.0:
|
|
7
7
|
a MINOR bump may include breaking changes).
|
|
8
8
|
|
|
9
|
+
## [0.12.1] - 2026-08-07
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- **`RemoteStoreClient.load` sized its batches by the wrong ceiling.** The same
|
|
14
|
+
defect found in witan's `migrate merge`, latent here: `load` defaulted to
|
|
15
|
+
`LOAD_MAX_BYTES` (omnigraph's 8 MiB buffered-body budget) while this transport
|
|
16
|
+
ships records as a JSON tool parameter, where the MCP SDK caps request bodies
|
|
17
|
+
at 4 MiB. A large enough index over `code_transport = "mcp"` would have failed
|
|
18
|
+
with `413 Request body too large` — from the SDK rather than from omnigraph.
|
|
19
|
+
Now defaults to `witan_core.chunking.MCP_LOAD_MAX_BYTES`.
|
|
20
|
+
|
|
21
|
+
Not hit in practice before now, which is why it is recorded as a fix rather
|
|
22
|
+
than a regression: the deployed indexer does not use this transport.
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- **Requires `witan-core>=0.11`** — `remote/store.py` evaluates
|
|
27
|
+
`MCP_LOAD_MAX_BYTES` as a default argument, so it resolves at import time and
|
|
28
|
+
0.10 does not export it.
|
|
29
|
+
|
|
30
|
+
## [0.12.0] - 2026-08-07
|
|
31
|
+
|
|
32
|
+
> Also covers 0.11.0 and 0.11.1, published from the workspace without their own
|
|
33
|
+
> entries; their content is folded in below.
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
|
|
37
|
+
- **Requires `witan-core>=0.10`.** `chunk_records` and the batch-loading half
|
|
38
|
+
of `OmnigraphClient` moved *out* of this package and into
|
|
39
|
+
`witan_core.chunking` / `OmnigraphClient.load_batch`, so a code index and a
|
|
40
|
+
memory merge share one split rule instead of two copies. Behaviour is
|
|
41
|
+
unchanged; this is a breaking change only for anyone importing
|
|
42
|
+
`witan_code.chunking` directly, which is why it is a minor bump.
|
|
43
|
+
|
|
44
|
+
### Fixed
|
|
45
|
+
|
|
46
|
+
- **`code_indexed_repos` returned nothing against a multi-graph server.**
|
|
47
|
+
Enumerating a server's graphs is not something the CLI can answer — it now
|
|
48
|
+
goes over HTTP to the server's own `/graphs`, whose envelope the previous
|
|
49
|
+
parser did not match.
|
|
50
|
+
|
|
51
|
+
### Performance
|
|
52
|
+
|
|
53
|
+
- **Per-graph listing queries now fan out** rather than running in sequence:
|
|
54
|
+
6.4s → 0.70s across the deployed graph set.
|
|
55
|
+
|
|
56
|
+
### Added
|
|
57
|
+
|
|
58
|
+
- **`code_store_mutate_many` — batched writes for the MCP transport.**
|
|
59
|
+
`RemoteStoreClient.change_many` was the last per-row writer in witan-code:
|
|
60
|
+
every other write path collapses N rows into one `omnigraph mutate` and
|
|
61
|
+
therefore one Lance version, while this one looped `code_store_mutate`
|
|
62
|
+
because that tool takes a query *file* the server resolves against its own
|
|
63
|
+
`queries_dir` and there was no way to hand it a composed body. The new tool
|
|
64
|
+
takes the same `(query, name, params)` steps `mutate` takes one at a time and
|
|
65
|
+
calls the real `change_many` server-side, so the splice stays where
|
|
66
|
+
`queries_dir` lives and the wire payload stays params rather than GQ — a
|
|
67
|
+
client still cannot send arbitrary GQ through a surface Cedar scopes by named
|
|
68
|
+
query. The concrete win is the reindex delete path: `_delete_file_steps`
|
|
69
|
+
emits 2 steps per changed-or-purged file, so a 200-file reindex over this
|
|
70
|
+
transport was 400 sequential MCP calls and 400 Lance versions and is now one
|
|
71
|
+
of each. `chunk_size` keeps meaning statements-per-commit, applied as one
|
|
72
|
+
call per chunk, so commit granularity is identical to the subprocess
|
|
73
|
+
transport's. **Feature-detected**, since this is a deployed contract: a
|
|
74
|
+
client meeting a server that predates the tool falls back to the per-step
|
|
75
|
+
loop, which is slow rather than broken.
|
|
76
|
+
|
|
9
77
|
## [0.10.0] - 2026-08-01
|
|
10
78
|
|
|
11
79
|
### Added
|
|
@@ -29,7 +97,8 @@ a MINOR bump may include breaking changes).
|
|
|
29
97
|
`code_server`, which is unchanged. Compaction and view reaping refuse here
|
|
30
98
|
too; they belong to the cluster's own scheduled jobs.
|
|
31
99
|
- **`code_store_*` tools** — the server half of the above: `read`, `mutate`,
|
|
32
|
-
`load`, `open`, `views`, `graphs
|
|
100
|
+
`load`, `open`, `views`, `graphs` (`mutate_many` joined them later),
|
|
101
|
+
mirroring the store operations the write
|
|
33
102
|
path performs rather than modelling indexing itself, so indexing policy
|
|
34
103
|
stays with the client that has the checkout. Mediated, not arbitrary:
|
|
35
104
|
`query` may only name a query file bundled with the server, and the graph is
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: witan-code
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.12.1
|
|
4
4
|
Summary: witan-code — tree-sitter code graph + cross-repo bridge (mounts under `witan code`)
|
|
5
5
|
Project-URL: Homepage, https://github.com/mitodl/agent-kit/tree/main/mcp/servers/witan-code
|
|
6
6
|
Project-URL: Repository, https://github.com/mitodl/agent-kit
|
|
@@ -26,7 +26,7 @@ Requires-Dist: tree-sitter-sql<0.4,>=0.3
|
|
|
26
26
|
Requires-Dist: tree-sitter-typescript<0.24,>=0.23
|
|
27
27
|
Requires-Dist: tree-sitter-yaml<0.8,>=0.7
|
|
28
28
|
Requires-Dist: tree-sitter<0.26,>=0.25
|
|
29
|
-
Requires-Dist: witan-core[cli,remote]<1,>=0.
|
|
29
|
+
Requires-Dist: witan-core[cli,observability,remote]<1,>=0.11
|
|
30
30
|
Provides-Extra: tasks
|
|
31
31
|
Requires-Dist: fastmcp-tasks<5,>=4.0.0b1; extra == 'tasks'
|
|
32
32
|
Description-Content-Type: text/markdown
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "witan-code"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.12.1"
|
|
4
4
|
description = "witan-code — tree-sitter code graph + cross-repo bridge (mounts under `witan code`)"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "BSD-3-Clause"
|
|
@@ -15,10 +15,16 @@ dependencies = [
|
|
|
15
15
|
# proxy) behind `witan-code login` and the read commands' remote mode.
|
|
16
16
|
# Costs nothing extra in practice — fastmcp is already required here and
|
|
17
17
|
# itself depends on httpx2, the extra's only other dependency.
|
|
18
|
-
# >=0.
|
|
19
|
-
#
|
|
20
|
-
# install resolve a witan-core
|
|
21
|
-
|
|
18
|
+
# >=0.11: remote/store.py evaluates witan_core.chunking.MCP_LOAD_MAX_BYTES
|
|
19
|
+
# as a default argument — so it resolves at import time, and 0.10 does not
|
|
20
|
+
# export it. A looser floor lets an external install resolve a witan-core
|
|
21
|
+
# the server cannot even import; that is what this pin is for, and it has
|
|
22
|
+
# now been tripped twice.
|
|
23
|
+
# (>=0.10 was already required for witan_core.chunking + load_batch, both
|
|
24
|
+
# moved up from this package; >=0.9 for observability.middleware; >=0.8 for
|
|
25
|
+
# OmnigraphClient.change_many with chunk_size on the batched reindex
|
|
26
|
+
# deletes.)
|
|
27
|
+
"witan-core[cli,remote,observability]>=0.11,<1",
|
|
22
28
|
"fastmcp>=3.4.2,<5",
|
|
23
29
|
"cyclopts>=4,<5",
|
|
24
30
|
# [targets.<name>] override models (config.py) — also transitively pulled
|
|
@@ -194,6 +194,148 @@ def test_a_write_and_a_read_round_trip_through_the_surface(sample_repo, monkeypa
|
|
|
194
194
|
assert f"{REPO}#src/added.py" not in {row["slug"] for row in on_main}
|
|
195
195
|
|
|
196
196
|
|
|
197
|
+
# ── Batched mutation ──────────────────────────────────────────────────────────
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
@requires_stack
|
|
201
|
+
def test_a_batch_of_deletes_applies_every_step(sample_repo, monkeypatch):
|
|
202
|
+
"""The server half of the batch: the client sends params, the splice and
|
|
203
|
+
the queries_dir lookup stay here, and all of it lands."""
|
|
204
|
+
from witan_code import indexer
|
|
205
|
+
|
|
206
|
+
monkeypatch.setenv("WITAN_ACTOR", "act-alice")
|
|
207
|
+
indexer.index_path(sample_repo, config=cfg_module.load())
|
|
208
|
+
|
|
209
|
+
view = ingest.open_view(REPO, "act-alice/feature_x")
|
|
210
|
+
before = {
|
|
211
|
+
row["slug"]
|
|
212
|
+
for row in ingest.read(REPO, view, "code_read.gq", "all_file_hashes", {})
|
|
213
|
+
}
|
|
214
|
+
assert before, "nothing indexed, so the delete would prove nothing"
|
|
215
|
+
|
|
216
|
+
applied = ingest.mutate_many(
|
|
217
|
+
REPO,
|
|
218
|
+
view,
|
|
219
|
+
[
|
|
220
|
+
{"query": "delete.gq", "name": "delete_file", "params": {"id": slug}}
|
|
221
|
+
for slug in sorted(before)
|
|
222
|
+
],
|
|
223
|
+
)
|
|
224
|
+
assert applied == len(before)
|
|
225
|
+
after = {
|
|
226
|
+
row["slug"]
|
|
227
|
+
for row in ingest.read(REPO, view, "code_read.gq", "all_file_hashes", {})
|
|
228
|
+
}
|
|
229
|
+
assert after == set()
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
@requires_stack
|
|
233
|
+
def test_a_bad_step_refuses_the_whole_batch_and_commits_no_prefix(
|
|
234
|
+
sample_repo, monkeypatch
|
|
235
|
+
):
|
|
236
|
+
"""Validation runs over every step before any of them does. Otherwise a
|
|
237
|
+
typo in step 300 leaves 299 deletes applied and the caller told it failed."""
|
|
238
|
+
from witan_code import indexer
|
|
239
|
+
|
|
240
|
+
monkeypatch.setenv("WITAN_ACTOR", "act-alice")
|
|
241
|
+
indexer.index_path(sample_repo, config=cfg_module.load())
|
|
242
|
+
|
|
243
|
+
view = ingest.open_view(REPO, "act-alice/feature_x")
|
|
244
|
+
before = {
|
|
245
|
+
row["slug"]
|
|
246
|
+
for row in ingest.read(REPO, view, "code_read.gq", "all_file_hashes", {})
|
|
247
|
+
}
|
|
248
|
+
good = [
|
|
249
|
+
{"query": "delete.gq", "name": "delete_file", "params": {"id": slug}}
|
|
250
|
+
for slug in sorted(before)
|
|
251
|
+
]
|
|
252
|
+
with pytest.raises(ingest.IngestRefused):
|
|
253
|
+
ingest.mutate_many(
|
|
254
|
+
REPO, view, [*good, {"query": "../etc/passwd.gq", "name": "x"}]
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
after = {
|
|
258
|
+
row["slug"]
|
|
259
|
+
for row in ingest.read(REPO, view, "code_read.gq", "all_file_hashes", {})
|
|
260
|
+
}
|
|
261
|
+
assert after == before
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
@pytest.mark.parametrize(
|
|
265
|
+
"step",
|
|
266
|
+
[
|
|
267
|
+
{"name": "delete_file", "params": {}},
|
|
268
|
+
{"query": "delete.gq", "params": {}},
|
|
269
|
+
{"query": "", "name": "delete_file"},
|
|
270
|
+
{"query": "delete.gq", "name": ""},
|
|
271
|
+
{"query": "delete.gq", "name": 7},
|
|
272
|
+
],
|
|
273
|
+
) # every one of these passes the tool's `list[dict]` schema — see the module
|
|
274
|
+
# comment above `_step_field`: the schema constrains the container, not the
|
|
275
|
+
# contents, so these guards are the only thing standing between a malformed
|
|
276
|
+
# step and an opaque failure several layers down.
|
|
277
|
+
def test_a_malformed_step_is_refused_by_name(step, tmp_path, monkeypatch):
|
|
278
|
+
"""The steps arrive as free-form dicts off the wire, so say which field is
|
|
279
|
+
wrong rather than raising a KeyError from inside the splice.
|
|
280
|
+
|
|
281
|
+
The actor owns the view here deliberately: authorization runs BEFORE step
|
|
282
|
+
validation, so without it every case would refuse for the wrong reason.
|
|
283
|
+
"""
|
|
284
|
+
monkeypatch.setenv("WITAN_CODE_DIR", str(tmp_path / "code"))
|
|
285
|
+
monkeypatch.setenv("WITAN_ACTOR", "act-alice")
|
|
286
|
+
with pytest.raises(ingest.IngestRefused, match="non-empty"):
|
|
287
|
+
ingest.mutate_many(REPO, "act-alice/x", [step])
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
@pytest.mark.parametrize("params", ["oops", ["id", "x"], 7, True])
|
|
291
|
+
def test_non_object_params_are_refused_rather_than_shipped_to_the_engine(
|
|
292
|
+
params, tmp_path, monkeypatch
|
|
293
|
+
):
|
|
294
|
+
"""`params` reaches `change_many` and becomes the `--params` JSON of a
|
|
295
|
+
composed mutation. A string or a list gets that far and then fails as an
|
|
296
|
+
opaque omnigraph CLI error, several layers below whoever sent it.
|
|
297
|
+
|
|
298
|
+
Note `step.get("params") or {}` would NOT have caught these: every value
|
|
299
|
+
here is truthy, so it sailed straight through.
|
|
300
|
+
"""
|
|
301
|
+
monkeypatch.setenv("WITAN_CODE_DIR", str(tmp_path / "code"))
|
|
302
|
+
monkeypatch.setenv("WITAN_ACTOR", "act-alice")
|
|
303
|
+
step = {"query": "delete.gq", "name": "delete_file", "params": params}
|
|
304
|
+
with pytest.raises(ingest.IngestRefused, match="must be an object"):
|
|
305
|
+
ingest.mutate_many(REPO, "act-alice/x", [step])
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
@pytest.mark.parametrize(
|
|
309
|
+
"step",
|
|
310
|
+
[
|
|
311
|
+
{"query": "delete.gq", "name": "delete_file"},
|
|
312
|
+
{"query": "delete.gq", "name": "delete_file", "params": None},
|
|
313
|
+
],
|
|
314
|
+
)
|
|
315
|
+
def test_omitted_and_null_params_both_mean_no_params(step, tmp_path, monkeypatch):
|
|
316
|
+
"""The guard must not turn the ordinary "this mutation takes no arguments"
|
|
317
|
+
case into a refusal."""
|
|
318
|
+
monkeypatch.setenv("WITAN_CODE_DIR", str(tmp_path / "code"))
|
|
319
|
+
monkeypatch.setenv("WITAN_ACTOR", "act-alice")
|
|
320
|
+
assert ingest._step_params(step) == {}
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
@requires_stack
|
|
324
|
+
def test_a_batch_into_someone_elses_view_is_refused(sample_repo, monkeypatch):
|
|
325
|
+
"""`mutate_many` is a write, so it goes through the same ownership gate
|
|
326
|
+
every other write does — being a batch does not route around it."""
|
|
327
|
+
from witan_code import indexer
|
|
328
|
+
|
|
329
|
+
monkeypatch.setenv("WITAN_ACTOR", "act-alice")
|
|
330
|
+
indexer.index_path(sample_repo, config=cfg_module.load())
|
|
331
|
+
with pytest.raises(ingest.IngestRefused, match="owned by act-bob"):
|
|
332
|
+
ingest.mutate_many(
|
|
333
|
+
REPO,
|
|
334
|
+
"act-bob/feature_x",
|
|
335
|
+
[{"query": "delete.gq", "name": "delete_file", "params": {"id": "x"}}],
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
|
|
197
339
|
@requires_stack
|
|
198
340
|
def test_the_graph_listing_names_repos_not_ids(sample_repo):
|
|
199
341
|
"""A client cannot invert `graph_id`, so the server answers in repo URIs."""
|
|
@@ -71,13 +71,20 @@ def test_token_provider_is_called_per_invocation(proxy):
|
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
@requires_stack
|
|
74
|
-
def
|
|
75
|
-
|
|
76
|
-
# keyword-only, so the proxy maps it via the tool's input schema.
|
|
77
|
-
hits = proxy.code_search_symbol("helper")
|
|
74
|
+
def test_keyword_args_reach_the_server(proxy):
|
|
75
|
+
hits = proxy.code_search_symbol(query="helper")
|
|
78
76
|
assert any(h["name"] == "helper" for h in hits)
|
|
79
77
|
|
|
80
78
|
|
|
79
|
+
@requires_stack
|
|
80
|
+
def test_positional_arg_is_refused(proxy):
|
|
81
|
+
# MCP is keyword-only on the wire. The proxy used to map positionals onto
|
|
82
|
+
# the input schema's property order, which is unordered by specification —
|
|
83
|
+
# see witan_core.remote.proxy's module docstring for what that misbound.
|
|
84
|
+
with pytest.raises(RemoteToolUnavailable, match="by keyword"):
|
|
85
|
+
proxy.code_search_symbol("helper")
|
|
86
|
+
|
|
87
|
+
|
|
81
88
|
@requires_stack
|
|
82
89
|
def test_repo_none_is_not_rewritten_client_side(proxy, monkeypatch):
|
|
83
90
|
"""The divergence from witan-council's proxy, pinned.
|
|
@@ -234,12 +234,31 @@ def test_an_unknown_transport_is_rejected_at_load(monkeypatch, tmp_path):
|
|
|
234
234
|
# ── The transport itself ──────────────────────────────────────────────────────
|
|
235
235
|
|
|
236
236
|
|
|
237
|
+
class _Tool:
|
|
238
|
+
def __init__(self, name):
|
|
239
|
+
self.name = name
|
|
240
|
+
|
|
241
|
+
|
|
237
242
|
class _FakeClient:
|
|
238
|
-
"""Stands in for a connected MCP client; records the calls it served.
|
|
243
|
+
"""Stands in for a connected MCP client; records the calls it served.
|
|
244
|
+
|
|
245
|
+
``tools`` is the surface the deployment advertises. It defaults to the full
|
|
246
|
+
current one; a test pins an OLDER deployment by passing a narrower set.
|
|
247
|
+
"""
|
|
248
|
+
|
|
249
|
+
DEFAULT_TOOLS = (
|
|
250
|
+
"code_store_read",
|
|
251
|
+
"code_store_mutate",
|
|
252
|
+
"code_store_mutate_many",
|
|
253
|
+
"code_store_load",
|
|
254
|
+
"code_store_open",
|
|
255
|
+
"code_store_views",
|
|
256
|
+
)
|
|
239
257
|
|
|
240
|
-
def __init__(self, log, fail_first=False):
|
|
258
|
+
def __init__(self, log, fail_first=False, tools=None):
|
|
241
259
|
self._log = log
|
|
242
260
|
self._fail_first = fail_first
|
|
261
|
+
self._tools = self.DEFAULT_TOOLS if tools is None else tuple(tools)
|
|
243
262
|
|
|
244
263
|
async def __aenter__(self):
|
|
245
264
|
self._log.append(("connect", None))
|
|
@@ -248,6 +267,10 @@ class _FakeClient:
|
|
|
248
267
|
async def __aexit__(self, *_exc):
|
|
249
268
|
self._log.append(("disconnect", None))
|
|
250
269
|
|
|
270
|
+
async def list_tools(self):
|
|
271
|
+
self._log.append(("list_tools", None))
|
|
272
|
+
return [_Tool(name) for name in self._tools]
|
|
273
|
+
|
|
251
274
|
async def call_tool(self, name, arguments):
|
|
252
275
|
if self._fail_first:
|
|
253
276
|
self._fail_first = False
|
|
@@ -340,3 +363,228 @@ def test_cluster_side_operations_are_refused_not_faked(call):
|
|
|
340
363
|
session = StoreSession("http://x/mcp", lambda: "jwt", lambda _t: _FakeClient([]))
|
|
341
364
|
with pytest.raises(RemoteStoreUnsupported):
|
|
342
365
|
call(RemoteStoreClient(REPO, session))
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
def test_load_chunks_against_the_mcp_budget_not_omnigraph_s():
|
|
369
|
+
"""Regression: records ride as a JSON tool parameter, so the SDK cap binds.
|
|
370
|
+
|
|
371
|
+
`load` defaulted to `LOAD_MAX_BYTES` — omnigraph's 8 MiB buffered-body
|
|
372
|
+
budget — while this transport's real ceiling is the MCP Python SDK's 4 MiB
|
|
373
|
+
request cap. A large enough index would have failed here exactly as `witan
|
|
374
|
+
migrate merge` did against the deployment: `413 Request body too large`,
|
|
375
|
+
from the SDK rather than from omnigraph.
|
|
376
|
+
|
|
377
|
+
Asserts on the request bodies these batches actually become, not on the
|
|
378
|
+
batch count, so the JSONL-vs-envelope accounting difference cannot quietly
|
|
379
|
+
eat the margin.
|
|
380
|
+
"""
|
|
381
|
+
import json
|
|
382
|
+
|
|
383
|
+
from mcp.server.streamable_http_manager import DEFAULT_MAX_REQUEST_BODY_SIZE
|
|
384
|
+
|
|
385
|
+
log: list = []
|
|
386
|
+
session = StoreSession("http://x/mcp", lambda: "jwt", lambda _t: _FakeClient(log))
|
|
387
|
+
|
|
388
|
+
# ~6 MiB of records: over the SDK cap, under omnigraph's 8 MiB budget, so
|
|
389
|
+
# the old default produced a single request the deployment would refuse.
|
|
390
|
+
records = [
|
|
391
|
+
{"type": "Symbol", "data": {"slug": f"sym-{i}", "body": "x" * 4096}}
|
|
392
|
+
for i in range(1500)
|
|
393
|
+
]
|
|
394
|
+
RemoteStoreClient(REPO, session).load(records)
|
|
395
|
+
|
|
396
|
+
loads = [args for name, args in log if name == "code_store_load"]
|
|
397
|
+
assert len(loads) > 1, "should have split; a single call is the old bug"
|
|
398
|
+
|
|
399
|
+
for args in loads:
|
|
400
|
+
body = json.dumps(
|
|
401
|
+
{
|
|
402
|
+
"jsonrpc": "2.0",
|
|
403
|
+
"id": 1,
|
|
404
|
+
"method": "tools/call",
|
|
405
|
+
"params": {"name": "code_store_load", "arguments": args},
|
|
406
|
+
}
|
|
407
|
+
)
|
|
408
|
+
assert len(body.encode()) < DEFAULT_MAX_REQUEST_BODY_SIZE
|
|
409
|
+
|
|
410
|
+
# Nothing dropped on the way through the splitter.
|
|
411
|
+
assert sum(len(args["records"]) for args in loads) == len(records)
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
# ── Batched mutation ──────────────────────────────────────────────────────────
|
|
415
|
+
#
|
|
416
|
+
# `change_many` was the last per-row writer in witan-code: every other write
|
|
417
|
+
# path collapses N rows into one commit, and this one looped `change`. What
|
|
418
|
+
# these pin is the COUNT — one call and one commit per chunk, not per step —
|
|
419
|
+
# because a reindex's cost is exactly that count.
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
def _steps(n):
|
|
423
|
+
return [("delete.gq", "delete_file", {"id": f"f{i}"}) for i in range(n)]
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def _calls(log, name):
|
|
427
|
+
return [args for entry, args in log if entry == name]
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
def test_a_batch_is_one_call_carrying_every_step():
|
|
431
|
+
"""The deliverable. 400 deletes used to be 400 round trips and 400 Lance
|
|
432
|
+
versions; they are now one of each."""
|
|
433
|
+
log: list = []
|
|
434
|
+
session = StoreSession("http://x/mcp", lambda: "jwt", lambda _t: _FakeClient(log))
|
|
435
|
+
RemoteStoreClient(REPO, session, branch="act-alice/x").change_many(_steps(400))
|
|
436
|
+
session.close()
|
|
437
|
+
|
|
438
|
+
batched = _calls(log, "code_store_mutate_many")
|
|
439
|
+
assert len(batched) == 1
|
|
440
|
+
assert _calls(log, "code_store_mutate") == []
|
|
441
|
+
assert batched[0]["graph"] == REPO
|
|
442
|
+
assert batched[0]["view"] == "act-alice/x"
|
|
443
|
+
assert len(batched[0]["steps"]) == 400
|
|
444
|
+
# The wire form carries params, never composed GQ — that is what keeps the
|
|
445
|
+
# tier's surface the named queries Cedar already scopes.
|
|
446
|
+
assert batched[0]["steps"][0] == {
|
|
447
|
+
"query": "delete.gq",
|
|
448
|
+
"name": "delete_file",
|
|
449
|
+
"params": {"id": "f0"},
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def test_the_steps_keep_their_order_over_the_wire():
|
|
454
|
+
"""An edge statement may reference a node an earlier step inserted."""
|
|
455
|
+
log: list = []
|
|
456
|
+
session = StoreSession("http://x/mcp", lambda: "jwt", lambda _t: _FakeClient(log))
|
|
457
|
+
RemoteStoreClient(REPO, session).change_many(_steps(5))
|
|
458
|
+
session.close()
|
|
459
|
+
sent = _calls(log, "code_store_mutate_many")[0]["steps"]
|
|
460
|
+
assert [step["params"]["id"] for step in sent] == ["f0", "f1", "f2", "f3", "f4"]
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def test_chunk_size_still_means_statements_per_commit():
|
|
464
|
+
"""Commit granularity must not depend on which transport is in use, or a
|
|
465
|
+
partial failure means something different remotely than it does locally."""
|
|
466
|
+
log: list = []
|
|
467
|
+
session = StoreSession("http://x/mcp", lambda: "jwt", lambda _t: _FakeClient(log))
|
|
468
|
+
RemoteStoreClient(REPO, session).change_many(_steps(250), chunk_size=100)
|
|
469
|
+
session.close()
|
|
470
|
+
|
|
471
|
+
batched = _calls(log, "code_store_mutate_many")
|
|
472
|
+
assert [len(call["steps"]) for call in batched] == [100, 100, 50]
|
|
473
|
+
# Every step is sent exactly once; the chunking drops none and repeats none.
|
|
474
|
+
assert [step["params"]["id"] for call in batched for step in call["steps"]] == [
|
|
475
|
+
f"f{i}" for i in range(250)
|
|
476
|
+
]
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
def test_a_chunk_size_below_one_is_refused_rather_than_dropping_every_write():
|
|
480
|
+
"""`range(0, n, 0)` raises, but `range(0, n, -1)` is EMPTY — the second
|
|
481
|
+
would return normally having written nothing at all."""
|
|
482
|
+
session = StoreSession("http://x/mcp", lambda: "jwt", lambda _t: _FakeClient([]))
|
|
483
|
+
for size in (0, -1):
|
|
484
|
+
with pytest.raises(ValueError, match="chunk_size must be >= 1"):
|
|
485
|
+
RemoteStoreClient(REPO, session).change_many(_steps(3), chunk_size=size)
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
def test_an_empty_batch_costs_nothing():
|
|
489
|
+
log: list = []
|
|
490
|
+
session = StoreSession("http://x/mcp", lambda: "jwt", lambda _t: _FakeClient(log))
|
|
491
|
+
RemoteStoreClient(REPO, session).change_many([])
|
|
492
|
+
assert log == []
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
def test_a_deployment_without_the_batch_tool_gets_the_per_step_loop():
|
|
496
|
+
"""This is a DEPLOYED contract: the server ships before its clients, but a
|
|
497
|
+
client can still meet an older one. It must be slow, not broken."""
|
|
498
|
+
log: list = []
|
|
499
|
+
older = [t for t in _FakeClient.DEFAULT_TOOLS if t != "code_store_mutate_many"]
|
|
500
|
+
session = StoreSession(
|
|
501
|
+
"http://x/mcp", lambda: "jwt", lambda _t: _FakeClient(log, tools=older)
|
|
502
|
+
)
|
|
503
|
+
RemoteStoreClient(REPO, session, branch="act-alice/x").change_many(_steps(3))
|
|
504
|
+
session.close()
|
|
505
|
+
|
|
506
|
+
assert _calls(log, "code_store_mutate_many") == []
|
|
507
|
+
assert [c["params"]["id"] for c in _calls(log, "code_store_mutate")] == [
|
|
508
|
+
"f0",
|
|
509
|
+
"f1",
|
|
510
|
+
"f2",
|
|
511
|
+
]
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
class _Unaskable(_FakeClient):
|
|
515
|
+
"""A deployment too old to answer `list_tools` at all."""
|
|
516
|
+
|
|
517
|
+
def __init__(self, log, **kw):
|
|
518
|
+
super().__init__(log, **kw)
|
|
519
|
+
self.asked = 0
|
|
520
|
+
|
|
521
|
+
async def list_tools(self):
|
|
522
|
+
self.asked += 1
|
|
523
|
+
raise RuntimeError("no such method")
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
def test_a_server_that_cannot_be_asked_falls_back_rather_than_failing():
|
|
527
|
+
"""A deployment too old to answer `list_tools` is certainly too old to have
|
|
528
|
+
the batch tool, and refusing here would fail an index that can succeed."""
|
|
529
|
+
log: list = []
|
|
530
|
+
session = StoreSession("http://x/mcp", lambda: "jwt", lambda _t: _Unaskable(log))
|
|
531
|
+
RemoteStoreClient(REPO, session).change_many(_steps(2))
|
|
532
|
+
session.close()
|
|
533
|
+
assert len(_calls(log, "code_store_mutate")) == 2
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
def test_a_failed_tool_listing_is_cached_like_a_successful_one():
|
|
537
|
+
"""Otherwise an index re-asks a server that already refused once, paying a
|
|
538
|
+
round trip AND an exception on every batch — the per-call cost this whole
|
|
539
|
+
change exists to remove."""
|
|
540
|
+
log: list = []
|
|
541
|
+
old = _Unaskable(log)
|
|
542
|
+
session = StoreSession("http://x/mcp", lambda: "jwt", lambda _t: old)
|
|
543
|
+
client = RemoteStoreClient(REPO, session)
|
|
544
|
+
for _ in range(5):
|
|
545
|
+
client.change_many(_steps(1))
|
|
546
|
+
session.close()
|
|
547
|
+
|
|
548
|
+
assert old.asked == 1, f"re-asked {old.asked} times; should ask once per connection"
|
|
549
|
+
assert len(_calls(log, "code_store_mutate")) == 5 # all five still written
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
def test_a_reconnect_clears_a_cached_failure_too():
|
|
553
|
+
"""The cache dies with the connection, so a transport blip costs the slow
|
|
554
|
+
path only until the next reconnect — not for the life of the process."""
|
|
555
|
+
log: list = []
|
|
556
|
+
old = _Unaskable(log)
|
|
557
|
+
session = StoreSession("http://x/mcp", lambda: "jwt", lambda _t: old)
|
|
558
|
+
client = RemoteStoreClient(REPO, session)
|
|
559
|
+
client.change_many(_steps(1))
|
|
560
|
+
assert old.asked == 1
|
|
561
|
+
session._disconnect()
|
|
562
|
+
client.change_many(_steps(1))
|
|
563
|
+
session.close()
|
|
564
|
+
assert old.asked == 2
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
def test_the_tool_surface_is_asked_once_per_connection_not_once_per_batch():
|
|
568
|
+
"""An index issues many batches; re-listing the surface each time would put
|
|
569
|
+
back the round trip batching just removed."""
|
|
570
|
+
log: list = []
|
|
571
|
+
session = StoreSession("http://x/mcp", lambda: "jwt", lambda _t: _FakeClient(log))
|
|
572
|
+
client = RemoteStoreClient(REPO, session)
|
|
573
|
+
client.change_many(_steps(2))
|
|
574
|
+
client.change_many(_steps(2))
|
|
575
|
+
client.change_many(_steps(2))
|
|
576
|
+
session.close()
|
|
577
|
+
assert [entry for entry, _ in log].count("list_tools") == 1
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
def test_a_reconnect_re_asks_the_surface():
|
|
581
|
+
"""A dropped connection may reconnect to a different replica mid-rollout,
|
|
582
|
+
so the cached surface must not outlive the connection it describes."""
|
|
583
|
+
log: list = []
|
|
584
|
+
clients = iter([_FakeClient(log, fail_first=True), _FakeClient(log)])
|
|
585
|
+
session = StoreSession("http://x/mcp", lambda: "jwt", lambda _t: next(clients))
|
|
586
|
+
client = RemoteStoreClient(REPO, session)
|
|
587
|
+
client.change_many(_steps(1))
|
|
588
|
+
client.change_many(_steps(1))
|
|
589
|
+
session.close()
|
|
590
|
+
assert [entry for entry, _ in log].count("list_tools") == 2
|