witan-code 0.11.0__tar.gz → 0.12.0__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.
Files changed (100) hide show
  1. {witan_code-0.11.0 → witan_code-0.12.0}/CHANGELOG.md +49 -1
  2. {witan_code-0.11.0 → witan_code-0.12.0}/PKG-INFO +2 -2
  3. {witan_code-0.11.0 → witan_code-0.12.0}/pyproject.toml +11 -6
  4. witan_code-0.12.0/tests/test_chunked_load.py +190 -0
  5. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_ingest.py +142 -0
  6. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_remote_proxy.py +11 -4
  7. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_remote_store.py +204 -2
  8. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_store.py +306 -24
  9. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/bridge.py +18 -2
  10. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/cli.py +10 -1
  11. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/github_app.py +11 -1
  12. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/graph.py +37 -15
  13. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/indexer.py +66 -8
  14. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/ingest.py +87 -10
  15. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/remote/store.py +127 -24
  16. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/server.py +47 -25
  17. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/store.py +134 -72
  18. witan_code-0.11.0/uv.lock +0 -1787
  19. {witan_code-0.11.0 → witan_code-0.12.0}/.gitignore +0 -0
  20. {witan_code-0.11.0 → witan_code-0.12.0}/README.md +0 -0
  21. {witan_code-0.11.0 → witan_code-0.12.0}/config/claude.json +0 -0
  22. {witan_code-0.11.0 → witan_code-0.12.0}/config/copilot.json +0 -0
  23. {witan_code-0.11.0 → witan_code-0.12.0}/config/pi.json +0 -0
  24. {witan_code-0.11.0 → witan_code-0.12.0}/docs/BRANCH_INDEXING.md +0 -0
  25. {witan_code-0.11.0 → witan_code-0.12.0}/docs/CLI_REFERENCE.md +0 -0
  26. {witan_code-0.11.0 → witan_code-0.12.0}/docs/EDGE_PRECISION_TIERS.md +0 -0
  27. {witan_code-0.11.0 → witan_code-0.12.0}/docs/PACKAGE_MAP.md +0 -0
  28. {witan_code-0.11.0 → witan_code-0.12.0}/docs/STAGE2_STITCHING.md +0 -0
  29. {witan_code-0.11.0 → witan_code-0.12.0}/docs/SYMBOL_FORMAT.md +0 -0
  30. {witan_code-0.11.0 → witan_code-0.12.0}/docs/SYMBOL_TABLE.md +0 -0
  31. {witan_code-0.11.0 → witan_code-0.12.0}/docs/USER_GUIDE.md +0 -0
  32. {witan_code-0.11.0 → witan_code-0.12.0}/install.sh +0 -0
  33. {witan_code-0.11.0 → witan_code-0.12.0}/tests/__init__.py +0 -0
  34. {witan_code-0.11.0 → witan_code-0.12.0}/tests/conftest.py +0 -0
  35. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_batched_deletes.py +0 -0
  36. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_branches.py +0 -0
  37. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_bridge.py +0 -0
  38. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_cli_dispatch.py +0 -0
  39. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_cli_hooks.py +0 -0
  40. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_cli_output_format.py +0 -0
  41. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_config.py +0 -0
  42. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_config_targets.py +0 -0
  43. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_context.py +0 -0
  44. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_crossrepo.py +0 -0
  45. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_edges.py +0 -0
  46. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_elicit.py +0 -0
  47. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_enrichment.py +0 -0
  48. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_github_app.py +0 -0
  49. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_graph.py +0 -0
  50. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_hooks.py +0 -0
  51. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_identity.py +0 -0
  52. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_indexer.py +0 -0
  53. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_indexer_scope.py +0 -0
  54. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_languages.py +0 -0
  55. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_maintenance.py +0 -0
  56. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_package_map.py +0 -0
  57. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_reaper.py +0 -0
  58. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_repo.py +0 -0
  59. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_server.py +0 -0
  60. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_setup.py +0 -0
  61. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_stitch.py +0 -0
  62. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_symbol_table.py +0 -0
  63. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_tasks.py +0 -0
  64. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_views.py +0 -0
  65. {witan_code-0.11.0 → witan_code-0.12.0}/tests/test_visualize.py +0 -0
  66. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/__init__.py +0 -0
  67. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/__main__.py +0 -0
  68. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/bridge_extractors.py +0 -0
  69. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/config.py +0 -0
  70. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/context.py +0 -0
  71. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/edges.py +0 -0
  72. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/elicit.py +0 -0
  73. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/extensions/pi/codegraph.ts +0 -0
  74. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/hooks.py +0 -0
  75. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/identity.py +0 -0
  76. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/maintenance.py +0 -0
  77. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/output.py +0 -0
  78. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/package_map.py +0 -0
  79. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/queries/bridge.gq +0 -0
  80. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/queries/code_mutations.gq +0 -0
  81. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/queries/code_read.gq +0 -0
  82. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/queries/delete.gq +0 -0
  83. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/queries_ts/bash.scm +0 -0
  84. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/queries_ts/hcl.scm +0 -0
  85. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/queries_ts/python.scm +0 -0
  86. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/queries_ts/sql.scm +0 -0
  87. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/queries_ts/typescript.scm +0 -0
  88. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/queries_ts/yaml.scm +0 -0
  89. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/reaper.py +0 -0
  90. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/remote/__init__.py +0 -0
  91. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/remote/oidc.py +0 -0
  92. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/remote/proxy.py +0 -0
  93. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/repo.py +0 -0
  94. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/schema/bridge-schema.pg +0 -0
  95. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/schema/code-schema.pg +0 -0
  96. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/setup.py +0 -0
  97. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/skills/witan-code/SKILL.md +0 -0
  98. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/stitch.py +0 -0
  99. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/views.py +0 -0
  100. {witan_code-0.11.0 → witan_code-0.12.0}/witan_code/visualize.py +0 -0
@@ -6,6 +6,53 @@ 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.0] - 2026-08-07
10
+
11
+ > Also covers 0.11.0 and 0.11.1, published from the workspace without their own
12
+ > entries; their content is folded in below.
13
+
14
+ ### Changed
15
+
16
+ - **Requires `witan-core>=0.10`.** `chunk_records` and the batch-loading half
17
+ of `OmnigraphClient` moved *out* of this package and into
18
+ `witan_core.chunking` / `OmnigraphClient.load_batch`, so a code index and a
19
+ memory merge share one split rule instead of two copies. Behaviour is
20
+ unchanged; this is a breaking change only for anyone importing
21
+ `witan_code.chunking` directly, which is why it is a minor bump.
22
+
23
+ ### Fixed
24
+
25
+ - **`code_indexed_repos` returned nothing against a multi-graph server.**
26
+ Enumerating a server's graphs is not something the CLI can answer — it now
27
+ goes over HTTP to the server's own `/graphs`, whose envelope the previous
28
+ parser did not match.
29
+
30
+ ### Performance
31
+
32
+ - **Per-graph listing queries now fan out** rather than running in sequence:
33
+ 6.4s → 0.70s across the deployed graph set.
34
+
35
+ ### Added
36
+
37
+ - **`code_store_mutate_many` — batched writes for the MCP transport.**
38
+ `RemoteStoreClient.change_many` was the last per-row writer in witan-code:
39
+ every other write path collapses N rows into one `omnigraph mutate` and
40
+ therefore one Lance version, while this one looped `code_store_mutate`
41
+ because that tool takes a query *file* the server resolves against its own
42
+ `queries_dir` and there was no way to hand it a composed body. The new tool
43
+ takes the same `(query, name, params)` steps `mutate` takes one at a time and
44
+ calls the real `change_many` server-side, so the splice stays where
45
+ `queries_dir` lives and the wire payload stays params rather than GQ — a
46
+ client still cannot send arbitrary GQ through a surface Cedar scopes by named
47
+ query. The concrete win is the reindex delete path: `_delete_file_steps`
48
+ emits 2 steps per changed-or-purged file, so a 200-file reindex over this
49
+ transport was 400 sequential MCP calls and 400 Lance versions and is now one
50
+ of each. `chunk_size` keeps meaning statements-per-commit, applied as one
51
+ call per chunk, so commit granularity is identical to the subprocess
52
+ transport's. **Feature-detected**, since this is a deployed contract: a
53
+ client meeting a server that predates the tool falls back to the per-step
54
+ loop, which is slow rather than broken.
55
+
9
56
  ## [0.10.0] - 2026-08-01
10
57
 
11
58
  ### Added
@@ -29,7 +76,8 @@ a MINOR bump may include breaking changes).
29
76
  `code_server`, which is unchanged. Compaction and view reaping refuse here
30
77
  too; they belong to the cluster's own scheduled jobs.
31
78
  - **`code_store_*` tools** — the server half of the above: `read`, `mutate`,
32
- `load`, `open`, `views`, `graphs`, mirroring the store operations the write
79
+ `load`, `open`, `views`, `graphs` (`mutate_many` joined them later),
80
+ mirroring the store operations the write
33
81
  path performs rather than modelling indexing itself, so indexing policy
34
82
  stays with the client that has the checkout. Mediated, not arbitrary:
35
83
  `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.11.0
3
+ Version: 0.12.0
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.8
29
+ Requires-Dist: witan-core[cli,observability,remote]<1,>=0.10
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.11.0"
3
+ version = "0.12.0"
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,15 @@ 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.8: the batched reindex deletes call OmnigraphClient.change_many with
19
- # chunk_size, neither of which 0.7 has. A looser floor lets an external
20
- # install resolve a witan-core that fails on the first reindex.
21
- "witan-core[cli,remote]>=0.8,<1",
18
+ # >=0.10: graph.py and remote/store.py import witan_core.chunking and call
19
+ # OmnigraphClient.load_batch at module scope — both moved up from this
20
+ # package into witan-core so a code index and a memory merge share one
21
+ # split rule, so 0.9 has neither. A looser floor lets an external install
22
+ # resolve a witan-core the server cannot even import. (>=0.9 was already
23
+ # required for witan_core.observability.middleware; >=0.8 for
24
+ # OmnigraphClient.change_many with chunk_size on the batched reindex
25
+ # deletes.)
26
+ "witan-core[cli,remote,observability]>=0.10,<1",
22
27
  "fastmcp>=3.4.2,<5",
23
28
  "cyclopts>=4,<5",
24
29
  # [targets.<name>] override models (config.py) — also transitively pulled
@@ -102,7 +107,7 @@ testpaths = ["tests"]
102
107
  packages = ["witan_code"]
103
108
 
104
109
  [tool.bumpversion]
105
- current_version = "0.11.0"
110
+ current_version = "0.11.1"
106
111
  allow_dirty = true
107
112
 
108
113
  [[tool.bumpversion.files]]
@@ -0,0 +1,190 @@
1
+ """A repo-scale load must survive the server's request-body ceiling.
2
+
3
+ `omnigraph load` POSTs its data file as one body, so a large repo got back
4
+ `413 Payload Too Large` against the deployed server while working fine against
5
+ a local store. Splitting it is not just slicing: an edge whose endpoint is in
6
+ neither the store nor its own batch fails the WHOLE load, and the indexer's
7
+ record list routinely has cross-file edges ahead of their target nodes.
8
+ """
9
+
10
+ import hashlib
11
+ import json
12
+
13
+ import pytest
14
+
15
+ from witan_code import indexer
16
+ from witan_core.chunking import LOAD_MAX_BYTES, chunk_records
17
+
18
+ from .conftest import requires_stack
19
+
20
+
21
+ def _node(slug, type_="Symbol", **extra):
22
+ return {"type": type_, "data": {"slug": slug, **extra}}
23
+
24
+
25
+ def _edge(kind, src, dst):
26
+ return {"edge": kind, "from": src, "to": dst}
27
+
28
+
29
+ # ── chunk_records ─────────────────────────────────────────────────
30
+
31
+
32
+ def test_empty_yields_nothing():
33
+ assert list(chunk_records([])) == []
34
+
35
+
36
+ def test_max_bytes_must_be_positive():
37
+ with pytest.raises(ValueError, match="max_bytes must be >= 1"):
38
+ list(chunk_records([_node("a")], 0))
39
+
40
+
41
+ def test_every_node_precedes_every_edge():
42
+ """The property the whole design rests on.
43
+
44
+ Input deliberately interleaves them the way `_file_records` does — each
45
+ file's nodes then its edges — with an edge pointing at a node defined in a
46
+ LATER file. Slicing by index would put that edge in an earlier batch than
47
+ its target and fail the load.
48
+ """
49
+ records = [
50
+ _node("f1::a"),
51
+ _edge("Calls", "f1::a", "f2::b"), # target defined below
52
+ _node("f2::b"),
53
+ _edge("Calls", "f2::b", "f1::a"),
54
+ ]
55
+ batches = list(chunk_records(records, LOAD_MAX_BYTES))
56
+ flat = [record for batch in batches for record in batch]
57
+ last_node = max(i for i, r in enumerate(flat) if "type" in r)
58
+ first_edge = min(i for i, r in enumerate(flat) if "type" not in r)
59
+ assert last_node < first_edge
60
+ assert len(flat) == len(records), "no record may be dropped"
61
+
62
+
63
+ def test_nothing_is_dropped_or_duplicated():
64
+ records = [_node(f"s{i}") for i in range(50)]
65
+ records += [_edge("Calls", f"s{i}", f"s{i + 1}") for i in range(49)]
66
+ flat = [r for batch in chunk_records(records, 200) for r in batch]
67
+ assert flat == [r for r in records if "type" in r] + [
68
+ r for r in records if "type" not in r
69
+ ]
70
+
71
+
72
+ def test_batches_respect_the_byte_budget():
73
+ records = [_node(f"s{i}", padding="x" * 100) for i in range(40)]
74
+ budget = 500
75
+ batches = list(chunk_records(records, budget))
76
+ assert len(batches) > 1, "the budget must actually force a split"
77
+ for batch in batches:
78
+ if len(batch) == 1:
79
+ continue # an unsplittable single record is allowed to exceed
80
+ size = sum(len(json.dumps(r).encode()) + 1 for r in batch)
81
+ assert size <= budget
82
+
83
+
84
+ def test_an_oversized_record_is_yielded_alone_not_dropped():
85
+ big = _node("huge", padding="x" * 5000)
86
+ records = [_node("small"), big, _node("small2")]
87
+ batches = list(chunk_records(records, 100))
88
+ flat = [r for batch in batches for r in batch]
89
+ assert big in flat
90
+ assert [b for b in batches if b == [big]], "oversized record needs its own batch"
91
+
92
+
93
+ # ── _defer_content_hashes ─────────────────────────────────────────
94
+
95
+
96
+ def test_defer_swaps_in_a_sentinel_and_returns_the_real_rows():
97
+ real_hash = hashlib.sha256(b"x").hexdigest()
98
+ records = [
99
+ {"type": "CodeFile", "data": {"slug": "r#a.py", "content_hash": real_hash}},
100
+ _node("r#a.py::foo"),
101
+ _edge("Defines", "r#a.py", "r#a.py::foo"),
102
+ ]
103
+ returned = indexer._defer_content_hashes(records)
104
+
105
+ assert records[0]["data"]["content_hash"] == indexer._PENDING_CONTENT_HASH
106
+ assert returned == [
107
+ {"type": "CodeFile", "data": {"slug": "r#a.py", "content_hash": real_hash}}
108
+ ]
109
+ assert records[1:] == [
110
+ _node("r#a.py::foo"),
111
+ _edge("Defines", "r#a.py", "r#a.py::foo"),
112
+ ]
113
+
114
+
115
+ def test_sentinel_can_never_collide_with_a_real_hash():
116
+ """The skip check is `stored == sha256(file)`; the sentinel must never match."""
117
+ digest = hashlib.sha256(b"anything").hexdigest()
118
+ assert indexer._PENDING_CONTENT_HASH != digest
119
+ assert len(indexer._PENDING_CONTENT_HASH) != len(digest)
120
+
121
+
122
+ # ── Against a real store ──────────────────────────────────────────
123
+
124
+
125
+ @requires_stack
126
+ def test_chunked_load_builds_the_same_graph_as_one_call(sample_repo, monkeypatch):
127
+ """Force many tiny batches and prove cross-batch edges still resolve.
128
+
129
+ This is the test that would have caught naive slicing: with a 1-record
130
+ budget, every edge is in its own batch and can only resolve against nodes
131
+ already persisted by an earlier one.
132
+ """
133
+ from witan_code import config as cfg_mod
134
+ from witan_code import graph as graph_mod
135
+
136
+ real_load = graph_mod.OmnigraphClient.load
137
+
138
+ def tiny_batches(self, records, mode="merge", **kwargs):
139
+ return real_load(self, records, mode, max_bytes=1)
140
+
141
+ monkeypatch.setattr(graph_mod.OmnigraphClient, "load", tiny_batches)
142
+ stats = indexer.index_path(sample_repo, config=cfg_mod.load())
143
+ assert stats.indexed >= 1
144
+ assert stats.edges >= 1
145
+
146
+ from witan_code import repo as repo_mod
147
+ from witan_code import store as store_mod
148
+
149
+ cfg = cfg_mod.load()
150
+ client = store_mod.ensure_store(repo_mod.detect(start=sample_repo), cfg).client(cfg)
151
+ hashes = {
152
+ row["slug"]: row["content_hash"]
153
+ for row in client.read("code_read.gq", "all_file_hashes", {})
154
+ }
155
+ assert hashes, "the repo should have indexed files"
156
+ assert indexer._PENDING_CONTENT_HASH not in hashes.values(), (
157
+ "every hash must be committed once the load completed"
158
+ )
159
+
160
+
161
+ @requires_stack
162
+ def test_a_failed_load_leaves_the_file_reindexable(sample_repo, monkeypatch):
163
+ """The property the sentinel exists to preserve.
164
+
165
+ If the hash-commit load never happens, the next run must re-index the file
166
+ rather than skip it. Without the sentinel the file would carry its real
167
+ hash from the first load and be skipped forever.
168
+ """
169
+ from witan_code import config as cfg_mod
170
+ from witan_code import graph as graph_mod
171
+
172
+ real_load = graph_mod.OmnigraphClient.load
173
+ calls = {"n": 0}
174
+
175
+ def fail_the_hash_commit(self, records, mode="merge", **kwargs):
176
+ calls["n"] += 1
177
+ if calls["n"] == 2: # the hash-commit load
178
+ msg = "simulated mid-load failure"
179
+ raise RuntimeError(msg)
180
+ return real_load(self, records, mode, **kwargs)
181
+
182
+ monkeypatch.setattr(graph_mod.OmnigraphClient, "load", fail_the_hash_commit)
183
+ cfg = cfg_mod.load()
184
+ with pytest.raises(RuntimeError, match="simulated mid-load failure"):
185
+ indexer.index_path(sample_repo, config=cfg)
186
+
187
+ monkeypatch.setattr(graph_mod.OmnigraphClient, "load", real_load)
188
+ stats = indexer.index_path(sample_repo, config=cfg_mod.load())
189
+ assert stats.indexed >= 1, "the file must be re-indexed, not skipped"
190
+ assert stats.skipped == 0
@@ -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 test_positional_first_arg_is_mapped_to_its_param_name(proxy):
75
- # CLI-style call sites pass the first argument positionally; MCP is
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.