witan-code 0.27.1__tar.gz → 0.28.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 (112) hide show
  1. {witan_code-0.27.1 → witan_code-0.28.0}/CHANGELOG.md +66 -0
  2. {witan_code-0.27.1 → witan_code-0.28.0}/PKG-INFO +2 -2
  3. {witan_code-0.27.1 → witan_code-0.28.0}/changelog.d/README.md +1 -1
  4. {witan_code-0.27.1 → witan_code-0.28.0}/docs/BRANCH_INDEXING.md +4 -2
  5. {witan_code-0.27.1 → witan_code-0.28.0}/pyproject.toml +26 -3
  6. witan_code-0.28.0/tests/test_branches_served.py +114 -0
  7. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_hooks.py +233 -22
  8. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_indexer_scope.py +77 -0
  9. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_ingest.py +8 -6
  10. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_reaper.py +22 -3
  11. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_remote_store.py +21 -114
  12. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_store.py +12 -8
  13. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/extensions/pi/codegraph.ts +21 -6
  14. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/graph.py +19 -26
  15. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/hooks.py +104 -18
  16. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/indexer.py +55 -8
  17. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/ingest.py +1 -1
  18. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/reaper.py +4 -4
  19. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/remote/store.py +10 -48
  20. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/store.py +25 -3
  21. witan_code-0.27.1/changelog.d/20261023_162839_blarghmatey_witan_code_codex_hooks.md +0 -3
  22. witan_code-0.27.1/changelog.d/20261023_163336_blarghmatey_witan_code_codex_hooks.md +0 -3
  23. {witan_code-0.27.1 → witan_code-0.28.0}/.gitignore +0 -0
  24. {witan_code-0.27.1 → witan_code-0.28.0}/README.md +0 -0
  25. {witan_code-0.27.1 → witan_code-0.28.0}/config/claude.json +0 -0
  26. {witan_code-0.27.1 → witan_code-0.28.0}/config/copilot.json +0 -0
  27. {witan_code-0.27.1 → witan_code-0.28.0}/config/pi.json +0 -0
  28. {witan_code-0.27.1 → witan_code-0.28.0}/conftest.py +0 -0
  29. {witan_code-0.27.1 → witan_code-0.28.0}/docs/CLI_REFERENCE.md +0 -0
  30. {witan_code-0.27.1 → witan_code-0.28.0}/docs/EDGE_PRECISION_TIERS.md +0 -0
  31. {witan_code-0.27.1 → witan_code-0.28.0}/docs/PACKAGE_MAP.md +0 -0
  32. {witan_code-0.27.1 → witan_code-0.28.0}/docs/STAGE2_STITCHING.md +0 -0
  33. {witan_code-0.27.1 → witan_code-0.28.0}/docs/SYMBOL_FORMAT.md +0 -0
  34. {witan_code-0.27.1 → witan_code-0.28.0}/docs/SYMBOL_TABLE.md +0 -0
  35. {witan_code-0.27.1 → witan_code-0.28.0}/docs/USER_GUIDE.md +0 -0
  36. {witan_code-0.27.1 → witan_code-0.28.0}/install.sh +0 -0
  37. {witan_code-0.27.1 → witan_code-0.28.0}/tests/__init__.py +0 -0
  38. {witan_code-0.27.1 → witan_code-0.28.0}/tests/conftest.py +0 -0
  39. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_batched_deletes.py +0 -0
  40. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_branches.py +0 -0
  41. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_bridge.py +0 -0
  42. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_chunked_load.py +0 -0
  43. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_cli_dispatch.py +0 -0
  44. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_cli_hooks.py +0 -0
  45. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_cli_output_format.py +0 -0
  46. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_cli_selected_target.py +0 -0
  47. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_config.py +0 -0
  48. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_config_targets.py +0 -0
  49. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_context.py +0 -0
  50. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_crossrepo.py +0 -0
  51. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_edges.py +0 -0
  52. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_elicit.py +0 -0
  53. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_enrichment.py +0 -0
  54. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_github_app.py +0 -0
  55. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_graph.py +0 -0
  56. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_identity.py +0 -0
  57. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_index_failure_diagnostics.py +0 -0
  58. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_index_reports_its_store.py +0 -0
  59. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_index_requires_a_repo_key.py +0 -0
  60. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_indexer.py +0 -0
  61. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_languages.py +0 -0
  62. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_maintenance.py +0 -0
  63. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_package_map.py +0 -0
  64. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_rebuild_honours_the_repo_key.py +0 -0
  65. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_refusal_audit.py +0 -0
  66. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_remote_proxy.py +0 -0
  67. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_repo.py +0 -0
  68. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_server.py +0 -0
  69. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_setup.py +0 -0
  70. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_stitch.py +0 -0
  71. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_symbol_table.py +0 -0
  72. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_tasks.py +0 -0
  73. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_tool_schema.py +0 -0
  74. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_views.py +0 -0
  75. {witan_code-0.27.1 → witan_code-0.28.0}/tests/test_visualize.py +0 -0
  76. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/__init__.py +0 -0
  77. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/__main__.py +0 -0
  78. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/bridge.py +0 -0
  79. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/bridge_extractors.py +0 -0
  80. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/cli.py +0 -0
  81. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/config.py +0 -0
  82. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/context.py +0 -0
  83. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/edges.py +0 -0
  84. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/elicit.py +0 -0
  85. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/github_app.py +0 -0
  86. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/identity.py +0 -0
  87. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/maintenance.py +0 -0
  88. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/output.py +0 -0
  89. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/package_map.py +0 -0
  90. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/queries/bridge.gq +0 -0
  91. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/queries/code_mutations.gq +0 -0
  92. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/queries/code_read.gq +0 -0
  93. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/queries/delete.gq +0 -0
  94. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/queries_ts/bash.scm +0 -0
  95. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/queries_ts/hcl.scm +0 -0
  96. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/queries_ts/python.scm +0 -0
  97. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/queries_ts/sql.scm +0 -0
  98. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/queries_ts/typescript.scm +0 -0
  99. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/queries_ts/yaml.scm +0 -0
  100. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/remote/__init__.py +0 -0
  101. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/remote/oidc.py +0 -0
  102. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/remote/proxy.py +0 -0
  103. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/repo.py +0 -0
  104. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/schema/bridge-schema.pg +0 -0
  105. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/schema/code-schema.pg +0 -0
  106. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/selected_target.py +0 -0
  107. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/server.py +0 -0
  108. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/setup.py +0 -0
  109. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/skills/witan-code/SKILL.md +0 -0
  110. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/stitch.py +0 -0
  111. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/views.py +0 -0
  112. {witan_code-0.27.1 → witan_code-0.28.0}/witan_code/visualize.py +0 -0
@@ -8,6 +8,51 @@ a MINOR bump may include breaking changes).
8
8
 
9
9
  <!-- scriv-insert-here -->
10
10
 
11
+ ## [0.28.0] - 2026-11-09
12
+
13
+ ### Changed
14
+
15
+ - Requires `witan-core>=0.51`, which pins omnigraph 0.14 (storage format 16)
16
+ and speaks HTTP contract 0.14 or 0.13, whichever the server stamps. A 0.14
17
+ data tier refuses an older client's requests. The floor also covers
18
+ `store_cli_args(..., binary=)`, `OmnigraphClient.commit_list`, the branched
19
+ HTTP transport and `OmnigraphClient(actor=)`.
20
+ - The `schema plan` check on a local code store addresses the store with
21
+ `store_cli_args`, so it takes `--target` on omnigraph 0.14 (which removed
22
+ the positional store URI) and `--store` before it. Code and bridge store
23
+ `init` passes the generated operator config on 0.14 (`init_cli_args`).
24
+ - A branch view on a deployed server reads, writes and lists its commits
25
+ over HTTP, with the branch as a request field, instead of through the
26
+ omnigraph CLI, which 0.14 refuses for a plain-http server.
27
+ `branch_last_write` (the reaper's idleness check) uses
28
+ `OmnigraphClient.commit_list`.
29
+ - A deployment's ingest client asserts the caller's actor to the data tier
30
+ (`Omnigraph-If-Actor`), so on omnigraph 0.14 a token mapped to the wrong
31
+ actor is refused instead of writing under someone else's name. `StoreRef`
32
+ carries the `actor`.
33
+ - The PostToolUse drainer indexes its whole queue as one batch
34
+ (`indexer.index_paths`) and waits `FLUSH_INTERVAL_SECONDS` (30s) since the
35
+ checkout's last flush before starting the next. An edit-heavy session now
36
+ runs at most one index per 30s per checkout (three commits on the branch
37
+ view when the batch is at most 64 changed files and fits one load chunk),
38
+ instead of one index run per edit back to back. The first edit after a
39
+ quiet spell still flushes at once, and edits made during the wait join the
40
+ next flush, so the last edit of a session is still indexed.
41
+ - The Pi extension queues edits through `witan-code reindex-hook` and seeds
42
+ through `witan-code session-init`, the commands the Claude and Codex hooks
43
+ run, instead of a detached `witan-code index` per edit that bypassed the
44
+ drainer.
45
+
46
+ ### Removed
47
+
48
+ - `RemoteStoreClient.change_many` no longer falls back to one
49
+ `code_store_mutate` per statement when the deployment's tool list lacks, or
50
+ fails to return, `code_store_mutate_many`. A failed listing was cached for
51
+ the connection's lifetime, which turned a reindex's deletes into one commit
52
+ per statement. A store tier without `code_store_mutate_many` (served since
53
+ witan-code 0.12.0) now fails the call instead. `StoreSession.has_tool` is
54
+ gone with it.
55
+
11
56
  ## [0.27.1] - 2026-10-26
12
57
 
13
58
  ### Changed
@@ -16,6 +61,27 @@ a MINOR bump may include breaking changes).
16
61
  `witan-cli` Keycloak client will require PKCE, and `witan-code login` on an older
17
62
  witan-core will then fail.
18
63
 
64
+ ### Fixed
65
+
66
+ - `reindex-hook` purges files a Codex `apply_patch` deletes or renames away. It
67
+ read only the headers naming a file left on disk, so a `*** Delete File:`
68
+ path and the `*** Update File:` source of a `*** Move to:` kept their symbols
69
+ in the graph until the next SessionStart full refresh, and
70
+ `code_find_definition` went on returning the old path. The hook now queues
71
+ those paths too, and indexing a file that is no longer on disk
72
+ (`index_path`, which the hook's drainer calls) drops its rows and its
73
+ cross-repo bindings. The drainer used to skip a queued file deleted before it
74
+ ran; it now purges it the same way. (Shipped in 0.27.1, left out at release.)
75
+ - `inject-context` gives Codex guidance for tools Codex has. `witan-code setup`
76
+ registers one bare `UserPromptSubmit` hook for Claude Code and Codex, so
77
+ Codex got Claude's block, which says to load the `code_*` tools with
78
+ `ToolSearch` and to run `/witan-code`; Codex has neither. Without
79
+ `--client`, the command now reads the hook's stdin payload, and a Codex
80
+ payload (it carries `turn_id`) gets Codex's `tool_search` call and a pointer
81
+ to the `witan-code` skill. Any other payload, or none, gets the Claude block
82
+ as before. `--client codex` selects the Codex block explicitly. (Shipped in
83
+ 0.27.1, left out at release.)
84
+
19
85
  ## [0.27.0] - 2026-10-21
20
86
 
21
87
  ### Changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: witan-code
3
- Version: 0.27.1
3
+ Version: 0.28.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,observability,remote,sentry]<1,>=0.46
29
+ Requires-Dist: witan-core[cli,observability,remote,sentry]<1,>=0.51
30
30
  Provides-Extra: tasks
31
31
  Requires-Dist: fastmcp-tasks<5,>=4; extra == 'tasks'
32
32
  Description-Content-Type: text/markdown
@@ -5,7 +5,7 @@ to `../CHANGELOG.md` — parallel branches editing the same lines in one shared
5
5
  file is what caused the version/changelog drift `bin/check_versions.py`
6
6
  exists to catch.
7
7
 
8
- Add one with `just changelog witan-code` (or `uvx scriv@1.8.0 create` from
8
+ Add one with `just changelog witan-code` (or `uvx scriv@1.8.1 create` from
9
9
  this directory's parent), fill in whichever category section(s) apply, and
10
10
  commit the file alongside your change. `just bump witan-code <part>` folds
11
11
  every pending fragment into `../CHANGELOG.md` under the new version heading
@@ -210,8 +210,10 @@ witan-code reap-views # report every local stor
210
210
  witan-code reap-views --store https://… --graph code-x --apply # the scheduled job
211
211
  ```
212
212
 
213
- Idleness comes from `omnigraph commit list --branch`, filtered to commits whose
214
- `manifest_branch` is the view itself — `branch list` returns bare names, with no
213
+ Idleness comes from the view's commit list (`GET /graphs/<id>/commits?branch=`
214
+ on a deployed server, `omnigraph commit list --branch` on a local store),
215
+ filtered to commits whose `graph_branch` (`manifest_branch` before omnigraph's
216
+ 2026-08-20 rename) is the view itself — `branch list` returns bare names, with no
215
217
  date, owner, or size. Two rules follow:
216
218
 
217
219
  * **`main` is never reaped**, however idle. It is the view every reader falls
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "witan-code"
3
- version = "0.27.1"
3
+ version = "0.28.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"
@@ -188,7 +188,30 @@ dependencies = [
188
188
  # sends PKCE (`S256`) only from 0.46.0, and the `witan-cli` Keycloak client
189
189
  # is switched to require it once that is out. 0.45 imports and runs, then
190
190
  # every `witan-code login` is refused by Keycloak.
191
- "witan-core[cli,remote,observability,sentry]>=0.46,<1",
191
+ #
192
+ # ★ >=0.48 IS A RUNTIME FLOOR of the `strict` kind above: `store.py` calls
193
+ # `store_cli_args(..., binary=)`, a keyword witan-core 0.48.0 added in the
194
+ # same change (omnigraph 0.14 `--target` addressing). 0.46 imports fine,
195
+ # then the first `schema plan` check raises TypeError, so
196
+ # `just check-core-floor` cannot see it.
197
+ #
198
+ # ★ >=0.49 IS A RUNTIME AND BEHAVIOUR FLOOR: `graph.branch_last_write`
199
+ # calls `OmnigraphClient.commit_list`, added in witan-core 0.49.0 in the
200
+ # same change, so on 0.48 the reaper raises AttributeError. 0.49 is also
201
+ # the first that sends a branch view's reads and writes over HTTP; on 0.48
202
+ # they shell out, which the 0.14 CLI refuses for a plain-http server.
203
+ #
204
+ # ★ >=0.50 IS A COMPATIBILITY FLOOR: 0.50.0 pins omnigraph 0.14 (storage
205
+ # format 16) and speaks HTTP contract 0.14 (or 0.13, negotiated). A 0.14
206
+ # server refuses a 0.13 request with `400 api_contract_mismatch`, so 0.49
207
+ # imports and runs, then fails on the first read of a shared code graph
208
+ # once the data tier is on 0.14.
209
+ #
210
+ # ★ >=0.51 IS A RUNTIME FLOOR of the `strict` kind above: `graph.py`
211
+ # passes `actor=` to witan-core's `OmnigraphClient`, a keyword added in
212
+ # witan-core 0.51.0 in the same change (Omnigraph-If-Actor). 0.50 imports
213
+ # fine, then a deployed ingest raises TypeError.
214
+ "witan-core[cli,remote,observability,sentry]>=0.51,<1",
192
215
  "fastmcp>=4,<5",
193
216
  "cyclopts>=4,<6",
194
217
  # [targets.<name>] override models (config.py) — also transitively pulled
@@ -271,7 +294,7 @@ testpaths = ["tests"]
271
294
  packages = ["witan_code"]
272
295
 
273
296
  [tool.bumpversion]
274
- current_version = "0.27.1"
297
+ current_version = "0.28.0"
275
298
  allow_dirty = true
276
299
 
277
300
  [[tool.bumpversion.files]]
@@ -0,0 +1,114 @@
1
+ """witan-code's branch views against a real omnigraph-server, over HTTP only.
2
+
3
+ A view's reads, writes and commit list each carry the view's branch. Against a
4
+ deployed server those have to go over HTTP: the 0.14 CLI refuses a plain-http
5
+ server target, which is what the deployed data tier is. So these fail the
6
+ moment anything here shells out, and assert on where each write landed rather
7
+ than on what was sent, because a branch the server ignored would still look
8
+ right on the wire.
9
+
10
+ Needs ``omnigraph-server``; see ``testsupport/omnigraph_server.py``.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import time
16
+
17
+ import pytest
18
+ from testsupport.omnigraph_server import (
19
+ omnigraph_server_bin, # noqa: F401 (a fixture)
20
+ requires_omnigraph_server,
21
+ serve,
22
+ )
23
+
24
+ from witan_code import config as cfg_module
25
+ from witan_code.graph import OmnigraphClient
26
+ from witan_core import omnigraph as og
27
+
28
+ pytestmark = requires_omnigraph_server
29
+
30
+ GRAPH = "code-served"
31
+ VIEW = "act-alice/feature_x"
32
+
33
+
34
+ def _file(slug: str) -> dict:
35
+ return {
36
+ "id": slug,
37
+ "repo": "github.com/test/repo",
38
+ "path": slug,
39
+ "language": "python",
40
+ "content_hash": "h",
41
+ "indexed_at": "2026-10-28T00:00:00Z",
42
+ }
43
+
44
+
45
+ def _slugs(client: OmnigraphClient) -> set[str]:
46
+ return {row["slug"] for row in client.read("code_read.gq", "all_file_hashes", {})}
47
+
48
+
49
+ @pytest.fixture
50
+ def served(tmp_path, monkeypatch, omnigraph_server_bin): # noqa: F811
51
+ def no_subprocess(*args, **kwargs):
52
+ raise AssertionError(f"shelled out against a served graph: {args}")
53
+
54
+ with serve(tmp_path, cfg_module._SCHEMA_FILE, GRAPH, omnigraph_server_bin) as url:
55
+ monkeypatch.setattr(og.subprocess, "run", no_subprocess)
56
+
57
+ def client(branch: str | None = None) -> OmnigraphClient:
58
+ return OmnigraphClient(
59
+ url, cfg_module._QUERIES_DIR, branch=branch, graph_id=GRAPH
60
+ )
61
+
62
+ yield client
63
+
64
+
65
+ def test_a_view_reads_writes_and_dates_its_own_branch_over_http(served):
66
+ main, view = served(), served(VIEW)
67
+ view.ensure_branch()
68
+
69
+ main.change("code_mutations.gq", "insert_file", _file("on-main"))
70
+ view.change("code_mutations.gq", "insert_file", _file("on-view"))
71
+ view.change_many(
72
+ [
73
+ ("code_mutations.gq", "insert_file", _file("batched-1")),
74
+ ("code_mutations.gq", "insert_file", _file("batched-2")),
75
+ ]
76
+ )
77
+
78
+ assert _slugs(main) == {"on-main"}
79
+ assert _slugs(view) == {"on-view", "batched-1", "batched-2"}
80
+
81
+ written = view.branch_last_write(VIEW)
82
+ assert written is not None
83
+ assert abs(written - time.time()) < 300
84
+
85
+
86
+ def test_a_view_with_no_writes_of_its_own_has_no_last_write(served):
87
+ served().change("code_mutations.gq", "insert_file", _file("on-main"))
88
+ empty = served("act-bob/untouched")
89
+ empty.ensure_branch()
90
+
91
+ assert served().branch_last_write("act-bob/untouched") is None
92
+
93
+
94
+ def test_a_missing_view_is_refused_at_once_not_read_from_main(served, monkeypatch):
95
+ """0.13 answers a branch that does not exist with 404 `not_found`. Waiting
96
+ cannot create it, so it fails on the first attempt (the sleep would only
97
+ run between retries) instead of spending the call budget."""
98
+ main = served()
99
+ main.change("code_mutations.gq", "insert_file", _file("on-main"))
100
+
101
+ def no_retry(seconds):
102
+ raise AssertionError(f"retried a missing branch (slept {seconds}s)")
103
+
104
+ missing = served("act-alice/never_created")
105
+
106
+ with monkeypatch.context() as patch:
107
+ patch.setattr(og.time, "sleep", no_retry)
108
+ with pytest.raises(RuntimeError, match="not found"):
109
+ missing.read("code_read.gq", "all_file_hashes", {})
110
+ with pytest.raises(RuntimeError, match="not found"):
111
+ missing.change("code_mutations.gq", "insert_file", _file("lost"))
112
+ with pytest.raises(RuntimeError, match="not found"):
113
+ main.commit_list("act-alice/never_created")
114
+ assert _slugs(main) == {"on-main"}
@@ -6,6 +6,7 @@ the lock handoff, stdin-JSON parsing, path resolution), not the real indexer
6
6
  or a real detached drainer. The lock itself is real: a kernel flock.
7
7
  """
8
8
 
9
+ import itertools
9
10
  import json
10
11
  import os
11
12
  import shutil
@@ -47,10 +48,47 @@ def _spawned(monkeypatch):
47
48
  return calls
48
49
 
49
50
 
51
+ class _Clock:
52
+ """Stands in for the `time` module inside hooks.py, so the flush interval
53
+ is walked instead of waited out."""
54
+
55
+ def __init__(self):
56
+ self.now = 1_000_000.0
57
+ self.slept: list[float] = []
58
+
59
+ def time(self) -> float:
60
+ return self.now
61
+
62
+ def sleep(self, seconds: float) -> None:
63
+ self.slept.append(seconds)
64
+ self.now += seconds
65
+
66
+
67
+ @pytest.fixture(autouse=True)
68
+ def _clock(monkeypatch):
69
+ clock = _Clock()
70
+ monkeypatch.setattr(hooks, "time", clock)
71
+ return clock
72
+
73
+
50
74
  @pytest.fixture
51
75
  def _indexed(monkeypatch):
76
+ """Every target indexed, flattened: the foreground path's single files and
77
+ the drainer's batches alike."""
52
78
  calls = []
53
79
  monkeypatch.setattr(hooks.indexer, "index_path", lambda p, force: calls.append(p))
80
+ monkeypatch.setattr(
81
+ hooks.indexer, "index_paths", lambda ts, force: calls.extend(ts)
82
+ )
83
+ return calls
84
+
85
+
86
+ @pytest.fixture
87
+ def _batches(monkeypatch):
88
+ calls = []
89
+ monkeypatch.setattr(
90
+ hooks.indexer, "index_paths", lambda ts, force: calls.append(list(ts))
91
+ )
54
92
  return calls
55
93
 
56
94
 
@@ -290,7 +328,7 @@ def test_reindex_hook_leaves_the_path_to_a_running_drainer(_repo, _spawned):
290
328
  # ── drain_pending ─────────────────────────────────────────────────────────────
291
329
 
292
330
 
293
- def test_drain_pending_indexes_each_queued_target_once_and_releases(_repo, _indexed):
331
+ def test_drain_pending_indexes_the_queue_as_one_batch_and_releases(_repo, _batches):
294
332
  a, b = _repo / "a.py", _repo / "b.py"
295
333
  for path in (a, b):
296
334
  path.write_text("x = 1")
@@ -299,7 +337,7 @@ def test_drain_pending_indexes_each_queued_target_once_and_releases(_repo, _inde
299
337
 
300
338
  hooks.drain_pending(_repo, hooks._try_lock(_repo))
301
339
 
302
- assert _indexed == [a, b]
340
+ assert _batches == [[a, b]]
303
341
  assert not hooks._has_pending(_repo)
304
342
  assert not context._busy_path(_repo).exists()
305
343
  fd = hooks._try_lock(_repo)
@@ -314,21 +352,21 @@ def test_drain_pending_picks_up_a_target_queued_while_it_held_the_lock(
314
352
  for path in (a, b):
315
353
  path.write_text("x = 1")
316
354
  hooks._enqueue(_repo, a)
317
- indexed = []
355
+ batches = []
318
356
 
319
- def _index(p, force):
320
- indexed.append(p)
321
- if p == a:
357
+ def _index(targets, force):
358
+ batches.append(targets)
359
+ if targets == [a]:
322
360
  # An edit landing mid-drain: its hook finds the lock held and
323
361
  # leaves the path to this drainer's re-check.
324
362
  assert hooks._try_lock(_repo) is None
325
363
  hooks._enqueue(_repo, b)
326
364
 
327
- monkeypatch.setattr(hooks.indexer, "index_path", _index)
365
+ monkeypatch.setattr(hooks.indexer, "index_paths", _index)
328
366
 
329
367
  hooks.drain_pending(_repo, hooks._try_lock(_repo))
330
368
 
331
- assert indexed == [a, b]
369
+ assert batches == [[a], [b]]
332
370
 
333
371
 
334
372
  def test_drain_pending_marks_the_checkout_busy_while_it_works(_repo, monkeypatch):
@@ -338,8 +376,8 @@ def test_drain_pending_marks_the_checkout_busy_while_it_works(_repo, monkeypatch
338
376
  seen = []
339
377
  monkeypatch.setattr(
340
378
  hooks.indexer,
341
- "index_path",
342
- lambda p, force: seen.append(context.indexing_in_progress()),
379
+ "index_paths",
380
+ lambda ts, force: seen.append(context.indexing_in_progress()),
343
381
  )
344
382
 
345
383
  hooks.drain_pending(_repo, hooks._try_lock(_repo))
@@ -348,6 +386,81 @@ def test_drain_pending_marks_the_checkout_busy_while_it_works(_repo, monkeypatch
348
386
  assert context.indexing_in_progress() is False
349
387
 
350
388
 
389
+ def test_drain_pending_is_not_busy_while_it_waits_out_the_interval(
390
+ _repo, _batches, _clock, monkeypatch
391
+ ):
392
+ """The context block reads the marker as "a reindex is running" and holds
393
+ back its broken-store warning on it, so the wait must not set it."""
394
+ a, b = _repo / "a.py", _repo / "b.py"
395
+ for path in (a, b):
396
+ path.write_text("x = 1")
397
+ hooks._enqueue(_repo, a)
398
+ hooks.drain_pending(_repo, hooks._try_lock(_repo))
399
+ hooks._enqueue(_repo, b)
400
+ context._busy_path(_repo).touch() # as _submit leaves it before spawning
401
+ during_wait = []
402
+ real_sleep = _clock.sleep
403
+
404
+ def _sleep(seconds: float) -> None:
405
+ during_wait.append(context.indexing_in_progress())
406
+ real_sleep(seconds)
407
+
408
+ monkeypatch.setattr(_clock, "sleep", _sleep)
409
+
410
+ hooks.drain_pending(_repo, hooks._try_lock(_repo))
411
+
412
+ assert during_wait == [False]
413
+ assert _batches == [[a], [b]]
414
+
415
+
416
+ def test_drain_pending_batches_a_symlink_into_another_repo_on_its_own(
417
+ _repo, tmp_path, _batches
418
+ ):
419
+ """A target is queued under its unresolved path's checkout, but
420
+ index_paths groups by the resolved one and refuses a mixed batch; one
421
+ such target must not drop the edits queued beside it."""
422
+ other = tmp_path / "other"
423
+ other.mkdir()
424
+ subprocess.run(["git", "init", "-q", str(other)], check=True)
425
+ (other / "b.py").write_text("x = 1")
426
+ a, link = _repo / "a.py", _repo / "link.py"
427
+ a.write_text("x = 1")
428
+ link.symlink_to(other / "b.py")
429
+ for path in (a, link):
430
+ hooks._enqueue(_repo, path)
431
+
432
+ hooks.drain_pending(_repo, hooks._try_lock(_repo))
433
+
434
+ assert sorted(_batches) == sorted([[a], [link]])
435
+ assert not hooks._has_pending(_repo)
436
+
437
+
438
+ def test_drain_pending_isolates_a_target_that_cannot_be_resolved(
439
+ _repo, _batches, monkeypatch
440
+ ):
441
+ """Before 3.13, Path.resolve() raises RuntimeError on a symlink loop. The
442
+ failure is raised here directly so the test holds on every version: the
443
+ target gets a batch of its own, whose failure the per-batch handler
444
+ absorbs, instead of taking down the whole flush and the queue re-check."""
445
+ a, loop = _repo / "a.py", _repo / "loop.py"
446
+ for path in (a, loop):
447
+ path.write_text("x = 1")
448
+ hooks._enqueue(_repo, path)
449
+ real_anchor_dir = hooks.indexer.anchor_dir
450
+
451
+ def _anchor_dir(path):
452
+ if path.name == "loop.py":
453
+ raise RuntimeError(f"Symlink loop from {path!r}")
454
+ return real_anchor_dir(path)
455
+
456
+ monkeypatch.setattr(hooks.indexer, "anchor_dir", _anchor_dir)
457
+
458
+ hooks.drain_pending(_repo, hooks._try_lock(_repo))
459
+
460
+ assert _batches == [[a], [loop]]
461
+ assert not hooks._has_pending(_repo)
462
+
463
+
351
464
  def test_drain_pending_purges_a_target_deleted_since_it_was_queued(_repo, _indexed):
352
465
  hooks._enqueue(_repo, _repo / "gone.py")
353
466
 
@@ -376,28 +489,126 @@ def test_drain_pending_skips_targets_of_a_removed_checkout(_repo, _indexed):
376
489
  assert _indexed == []
377
490
 
378
491
 
379
- def test_drain_pending_continues_past_a_failing_target(_repo, monkeypatch):
380
- a, b = _repo / "a.py", _repo / "b.py"
381
- for path in (a, b):
382
- path.write_text("x = 1")
383
- hooks._enqueue(_repo, path)
384
- indexed = []
492
+ def test_drain_pending_releases_after_a_failing_batch(_repo, monkeypatch):
493
+ a = _repo / "a.py"
494
+ a.write_text("x = 1")
495
+ hooks._enqueue(_repo, a)
385
496
 
386
- def _index(p, force):
387
- if p == a:
388
- raise RuntimeError("write authority changed during preparation")
389
- indexed.append(p)
497
+ def _index(targets, force):
498
+ raise RuntimeError("write authority changed during preparation")
390
499
 
391
- monkeypatch.setattr(hooks.indexer, "index_path", _index)
500
+ monkeypatch.setattr(hooks.indexer, "index_paths", _index)
392
501
 
393
502
  hooks.drain_pending(_repo, hooks._try_lock(_repo))
394
503
 
395
- assert indexed == [b]
504
+ assert not hooks._has_pending(_repo)
396
505
  fd = hooks._try_lock(_repo)
397
506
  assert fd is not None # released despite the failure
398
507
  os.close(fd)
399
508
 
400
509
 
510
+ # ── Flush pacing ──────────────────────────────────────────────────────────────
511
+
512
+
513
+ def test_an_edit_heavy_session_flushes_at_most_once_per_interval(
514
+ _repo, monkeypatch, _clock
515
+ ):
516
+ """The bound this exists for. Edits arrive every 3s for 5 minutes, each
517
+ during a flush or during the wait for the next, which is what an agent
518
+ editing continuously looks like to the drainer. Flushes start at least
519
+ FLUSH_INTERVAL_SECONDS apart, and every edit lands in one of them."""
520
+ edit_every = 3.0
521
+ index_takes = 8.0
522
+ session_ends = _clock.now + 300.0
523
+ edits: list = []
524
+ flushes: list[tuple[float, list]] = []
525
+ next_edit = [_clock.now]
526
+
527
+ def _edit_until(now: float) -> None:
528
+ while next_edit[0] <= now and next_edit[0] < session_ends:
529
+ path = _repo / f"f{len(edits)}.py"
530
+ path.write_text("x = 1")
531
+ edits.append(path)
532
+ hooks._enqueue(_repo, path)
533
+ next_edit[0] += edit_every
534
+
535
+ real_sleep = _clock.sleep
536
+
537
+ def _sleep(seconds: float) -> None:
538
+ real_sleep(seconds)
539
+ _edit_until(_clock.now)
540
+
541
+ def _index(targets, force):
542
+ flushes.append((_clock.now, list(targets)))
543
+ _clock.now += index_takes
544
+ _edit_until(_clock.now)
545
+
546
+ monkeypatch.setattr(_clock, "sleep", _sleep)
547
+ monkeypatch.setattr(hooks.indexer, "index_paths", _index)
548
+ _edit_until(_clock.now)
549
+
550
+ hooks.drain_pending(_repo, hooks._try_lock(_repo))
551
+
552
+ starts = [at for at, _ in flushes]
553
+ gaps = [b - a for a, b in itertools.pairwise(starts)]
554
+ assert gaps
555
+ assert min(gaps) >= hooks.FLUSH_INTERVAL_SECONDS
556
+ # 100 edits; per-edit indexing would have been 100 writes.
557
+ assert len(edits) == 100
558
+ assert len(flushes) <= 300.0 / hooks.FLUSH_INTERVAL_SECONDS + 1
559
+ # Nothing lost, the last edit of the session included, each indexed once.
560
+ assert [t for _, batch in flushes for t in batch] == edits
561
+ assert edits[-1] in flushes[-1][1]
562
+ assert not hooks._has_pending(_repo)
563
+
564
+
565
+ def test_a_new_drainer_waits_out_the_previous_one_s_interval(_repo, _batches, _clock):
566
+ """A drainer exits once its queue is empty, so the interval has to outlive
567
+ it: the next edit spawns a fresh drainer that must not flush at once."""
568
+ a, b = _repo / "a.py", _repo / "b.py"
569
+ for path in (a, b):
570
+ path.write_text("x = 1")
571
+ hooks._enqueue(_repo, a)
572
+ hooks.drain_pending(_repo, hooks._try_lock(_repo))
573
+ _clock.now += 10.0
574
+
575
+ hooks._enqueue(_repo, b)
576
+ hooks.drain_pending(_repo, hooks._try_lock(_repo))
577
+
578
+ assert _batches == [[a], [b]]
579
+ assert _clock.slept == [hooks.FLUSH_INTERVAL_SECONDS - 10.0]
580
+
581
+
582
+ def test_the_first_edit_after_a_quiet_spell_flushes_at_once(_repo, _batches, _clock):
583
+ a, b = _repo / "a.py", _repo / "b.py"
584
+ for path in (a, b):
585
+ path.write_text("x = 1")
586
+ hooks._enqueue(_repo, a)
587
+ hooks.drain_pending(_repo, hooks._try_lock(_repo))
588
+ _clock.now += hooks.FLUSH_INTERVAL_SECONDS + 1
589
+
590
+ hooks._enqueue(_repo, b)
591
+ hooks.drain_pending(_repo, hooks._try_lock(_repo))
592
+
593
+ assert _batches == [[a], [b]]
594
+ assert _clock.slept == []
595
+
596
+
597
+ def test_a_stamp_from_the_future_waits_one_interval_at_most(_repo, _batches, _clock):
598
+ """A wall clock that stepped back must not stall the queue for hours."""
599
+ a = _repo / "a.py"
600
+ a.write_text("x = 1")
601
+ stamp = hooks._flushed_path(_repo)
602
+ stamp.touch()
603
+ os.utime(stamp, (_clock.now + 3600, _clock.now + 3600))
604
+ hooks._enqueue(_repo, a)
605
+
606
+ hooks.drain_pending(_repo, hooks._try_lock(_repo))
607
+
608
+ assert _batches == [[a]]
609
+ assert _clock.slept == [hooks.FLUSH_INTERVAL_SECONDS]
610
+
611
+
401
612
  # ── lock and state ────────────────────────────────────────────────────────────
402
613
 
403
614