witan-code 0.30.0__tar.gz → 0.32.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.
- {witan_code-0.30.0 → witan_code-0.32.0}/CHANGELOG.md +94 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/PKG-INFO +16 -16
- {witan_code-0.30.0 → witan_code-0.32.0}/README.md +13 -13
- {witan_code-0.30.0 → witan_code-0.32.0}/docs/USER_GUIDE.md +14 -7
- {witan_code-0.30.0 → witan_code-0.32.0}/pyproject.toml +13 -4
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/conftest.py +15 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_branches.py +200 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_context.py +32 -0
- witan_code-0.32.0/tests/test_diff_impact.py +685 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_edges.py +9 -2
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_indexer_scope.py +158 -3
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_maintenance.py +33 -7
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_remote_proxy.py +3 -14
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_remote_store.py +3 -4
- witan_code-0.32.0/tests/test_search_docstrings.py +284 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_server.py +64 -1
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_setup.py +9 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_store.py +9 -10
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_tool_schema.py +44 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_visualize.py +69 -3
- witan_code-0.32.0/tests/test_why.py +416 -0
- witan_code-0.32.0/tests/test_xref.py +361 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/cli.py +360 -18
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/config.py +5 -48
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/context.py +12 -4
- witan_code-0.32.0/witan_code/diff_impact.py +708 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/graph.py +4 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/indexer.py +314 -39
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/ingest.py +5 -3
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/maintenance.py +11 -5
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/output.py +9 -1
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/queries/bridge.gq +1 -1
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/queries/code_read.gq +50 -2
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/remote/store.py +5 -3
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/repo.py +27 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/schema/bridge-schema.pg +2 -1
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/schema/code-schema.pg +9 -5
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/server.py +389 -167
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/setup.py +15 -6
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/skills/witan-code/SKILL.md +5 -4
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/store.py +24 -22
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/visualize.py +16 -8
- witan_code-0.32.0/witan_code/xref.py +345 -0
- witan_code-0.30.0/tests/test_config.py +0 -64
- {witan_code-0.30.0 → witan_code-0.32.0}/.gitignore +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/changelog.d/README.md +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/config/claude.json +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/config/copilot.json +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/config/pi.json +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/conftest.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/docs/BRANCH_INDEXING.md +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/docs/CLI_REFERENCE.md +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/docs/EDGE_PRECISION_TIERS.md +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/docs/PACKAGE_MAP.md +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/docs/STAGE2_STITCHING.md +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/docs/SYMBOL_FORMAT.md +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/docs/SYMBOL_TABLE.md +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/install.sh +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/__init__.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_batched_deletes.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_branches_served.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_bridge.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_chunked_load.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_cli_dispatch.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_cli_help_docstrings.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_cli_hooks.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_cli_output_format.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_cli_selected_target.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_config_targets.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_crossrepo.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_elicit.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_enrichment.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_github_app.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_graph.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_hooks.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_identity.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_index_failure_diagnostics.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_index_reports_its_store.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_index_requires_a_repo_key.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_indexer.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_ingest.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_languages.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_package_map.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_reaper.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_rebuild_honours_the_repo_key.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_refusal_audit.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_repo.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_stitch.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_symbol_table.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_tasks.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/tests/test_views.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/__init__.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/__main__.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/bridge.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/bridge_extractors.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/edges.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/elicit.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/extensions/pi/codegraph.ts +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/github_app.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/hooks.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/identity.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/package_map.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/queries/code_mutations.gq +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/queries/delete.gq +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/queries_ts/bash.scm +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/queries_ts/hcl.scm +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/queries_ts/python.scm +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/queries_ts/sql.scm +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/queries_ts/typescript.scm +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/queries_ts/yaml.scm +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/reaper.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/remote/__init__.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/remote/oidc.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/remote/proxy.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/selected_target.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/stitch.py +0 -0
- {witan_code-0.30.0 → witan_code-0.32.0}/witan_code/views.py +0 -0
|
@@ -8,6 +8,100 @@ a MINOR bump may include breaking changes).
|
|
|
8
8
|
|
|
9
9
|
<!-- scriv-insert-here -->
|
|
10
10
|
|
|
11
|
+
## [0.32.0] - 2026-11-17
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- `code_callers` accepts an optional `branch`, with the semantics `code_impact` and `code_find_definition` already have. A deployed server has no checkout to follow, so a remote caller could only read the default view; `branch="feature/x"` reads that branch's callers or callees. Omitted, the tool follows the checkout's branch view for the current repo as before.
|
|
16
|
+
|
|
17
|
+
- `code_find_definition` takes `symbol_id` in place of `name` to look up one exact id: it returns that symbol alone, or `[]` when the id's repo has no index or the index has no such symbol. A name lookup is capped at 50 rows, so it could not answer "is this id still defined" for a name that repeats across files (every `<module>`, Django's `Command.handle`). The lookup is routed by the id's repo like the other id-routed tools, and `branch` selects the view as it does for a name lookup. Passing both `name` and `symbol_id`, or neither, is refused.
|
|
18
|
+
|
|
19
|
+
- The indexer resolves calls into other files of the repo through each file's imports, for Python (absolute and relative imports, `from pkg import mod`, `import pkg.mod as m`) and TS/JS (relative `import { f }` and `import * as ns`). A call whose callee is an imported name or an attribute chain rooted at one (`f()`, `mod.f()`, `Cls.method()`) gets a `Calls`/`References` edge to the symbol in the other file, so `code_callers`, `code_impact` and `witan code diff-impact` now list callers in other modules, on main and branch views alike. Calls through an instance (`obj.method()`), re-exports, star imports, `require()` and path aliases are not followed. Existing stores need one `witan-code reindex` (or a forced CI index) to get these edges for files that have not changed since.
|
|
20
|
+
- Indexing a file re-links the stored files that mention its module name (and, for a package `__init__.py` or an `index.ts`, the names it defines, since `from . import f` or `from './index'` reaches it without its directory's name), found with one `git grep` over the work tree. Re-indexing a file deletes its symbols and every edge into them, so without this the edit hook's one-file run dropped a module's cross-file callers. It also links a caller written before the module or function it calls. The re-linked files' own rows are not rewritten.
|
|
21
|
+
|
|
22
|
+
- Every tool carries MCP annotations. The `code_*` queries and the read-only
|
|
23
|
+
`code_store_*` tools are `readOnlyHint`; `code_store_open` is
|
|
24
|
+
non-destructive and idempotent; `code_reindex` is destructive and
|
|
25
|
+
idempotent, because it deletes a changed file's rows before loading their
|
|
26
|
+
replacements; the `code_store_mutate*` and `code_store_load` tools are
|
|
27
|
+
destructive.
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- `code_search_symbol` returns `{"symbols": [...]}` instead of a bare list, so the result has room for the `note` below. A caller that read the list now reads `result["symbols"]`.
|
|
32
|
+
|
|
33
|
+
- `witan code diff-impact` takes "tests to run" from a symbol's callers when the graph can reach them (a module-level Python function or class, or a module-level TS/JS function). The `git grep` name search now runs only for methods and nested defs, TS/JS classes, interfaces and type aliases, languages without import resolution, and a repo with no code graph, and the label drops "(stand-in)".
|
|
34
|
+
|
|
35
|
+
- The cluster graph-id function moved to witan-core as `witan_core.graph_ids.code_graph_id`, along with `CODE_GRAPH_PREFIX`, `BRIDGE_GRAPH_ID` and `GRAPH_ID_RE`. `witan_code.config` no longer defines them. The ids it returns are unchanged. Requires witan-core 0.57.0.
|
|
36
|
+
|
|
37
|
+
- Parameter descriptions are cut to what an agent needs to choose a value.
|
|
38
|
+
`repo`, `branch`, `symbol_id` and `min_precision` point at the server
|
|
39
|
+
instructions instead of repeating them. The manifest drops from 25,598 to
|
|
40
|
+
21,157 characters.
|
|
41
|
+
|
|
42
|
+
### Fixed
|
|
43
|
+
|
|
44
|
+
- A file named directly to the indexer (the edit hook's case) is held to the full walk's path rules as well as git's ignore rules, under the name the walk would list it by. An edit under an excluded directory (e.g. `build/`, `node_modules/`), below a nested checkout, or below a symlinked directory was indexed, and the next full index purged it again. Such a file now writes nothing, and rows it already has are dropped on that edit unless the walk still collects the file under its own resolved path (e.g. an excluded `build/alias.py -> ../a.py` leaves `a.py` alone). `witan code why` reports it as `not indexed: <rule>`, and points rows a rule now excludes at a full index of the repo.
|
|
45
|
+
|
|
46
|
+
- `code_search_symbol` says when it skipped the docstring search. A store whose schema has no `Symbol.docstring` index, or a deployed witan-code tier older than the docstring query, answers with name matches only, and the only sign was a warning in the server's log, which a client of a deployed store never sees. The result now carries a `note` starting `docstring search unavailable` that gives the reason and, in a cross-repo fan-out, how many of the stores searched skipped it. The tool docs also say that only the first 500 characters of a docstring are indexed.
|
|
47
|
+
|
|
48
|
+
## [0.31.0] - 2026-11-13
|
|
49
|
+
|
|
50
|
+
### Added
|
|
51
|
+
|
|
52
|
+
- `witan code why <path>` says whether a file is in the code graph, in the view the `code_*` tools read from its checkout, and if not, which indexer rule left it out (unsupported language, skipped directory, nested checkout, symlinked directory, gitignored) with the fix. An empty `code_*` result reads the same for an unused symbol and for a file the indexer never wrote; this tells the two apart. The rules are the indexer's own filter, now one function both the git-listing and disk-walk paths call, so the explanation cannot drift from what gets indexed. It reads the `--target`'s stores, and refuses (naming `code_transport`) when a remote URL sends the `code_*` reads to a deployment while the code-graph stores are local, since its answer would describe a graph those reads never use.
|
|
53
|
+
|
|
54
|
+
- `code_search_symbol` matches symbol docstrings as well as qualified names, so a query like "rate limiting" finds a symbol whose docstring describes it even when its name does not. A second BM25 run over `Symbol.docstring` is appended after the name run, keeping only the symbols the name run did not return, so a docstring-only match never outranks a name match, across a cross-repo fan-out too. Each run returns up to 50 symbols per store.
|
|
55
|
+
|
|
56
|
+
- `code_callers` takes `direction="callees"` to list the symbols a function calls, following the same `Calls` edges outward. The default, `direction="callers"`, is unchanged. Like the callers query it reads the checkout's branch view for the current repo.
|
|
57
|
+
|
|
58
|
+
- `witan code diff-impact --base origin/main` maps a branch's diff to the symbols it changes, by parsing both sides of each changed file with the indexer's parser (a decorator-only edit maps to the decorated symbol), then lists each symbol's callers, the bindings in other repos that share its env vars, endpoints and packages, the test files that name it (a stand-in for "tests to run", since the graph has no test-to-code edges), and the witan tasks and memories that cite it, plus the tasks claimed on the head branch. Every list carries its total next to what is shown (`--limit`, `--max-items`), changed test files are listed by file rather than looked up, renamed files are listed with a note that every symbol id in them moved, and the notes say what the answer cannot see: an unindexed repo, symbols missing from the index, callers in other files, and callers only this branch adds. Tasks and memories are skipped, with a note, when witan (council) is not installed. Honors `--output-format`. Its in-process lookups are pinned to the base branch's view, so a symbol the branch removed resolves against main even after the branch is indexed.
|
|
59
|
+
- `code_impact`, `code_cross_repo_impact` and `code_symbols_in_file` accept an optional `branch`, with the semantics `code_find_definition` already has: omitted, they follow the checkout's branch view for the current repo as before; `branch="main"` reads the default view from a checkout whose own branch is indexed. On `code_impact` it applies to the root symbol's repo, and on `code_cross_repo_impact` it selects that repo's bridge overlay. The server instructions now say which id-routed tools take `branch`.
|
|
60
|
+
|
|
61
|
+
### Changed
|
|
62
|
+
|
|
63
|
+
- `code_find_definition` and `code_search_symbol` docs no longer contrast their `repo=""` with the witan memory/task tools, which now refuse an empty `repo` and take `all_repos=True` instead. Behaviour is unchanged.
|
|
64
|
+
|
|
65
|
+
- The `witan-code` skill points at `recall(symbol_id=…)` for the memories and
|
|
66
|
+
tasks attached to a symbol, since witan folded `symbol_context` into
|
|
67
|
+
`recall`.
|
|
68
|
+
- `witan code diff-impact` reads each changed symbol's tasks and memories
|
|
69
|
+
through `recall(symbol_id=…, hops=0, include_superseded=True)`. It still
|
|
70
|
+
called the removed `symbol_context`, so it failed on every changed non-test
|
|
71
|
+
symbol when witan was installed.
|
|
72
|
+
|
|
73
|
+
### Fixed
|
|
74
|
+
|
|
75
|
+
- The optimize and cleanup throttle stamps
|
|
76
|
+
(`witan-code-{optimize,cleanup}-<digest>.json`) and the context hook's
|
|
77
|
+
cached bridge verdict (`codegraph-bridge-<digest>.probe`) moved from the bare
|
|
78
|
+
temp dir into witan-code's private per-user state dir, where the reindex
|
|
79
|
+
queue already lives (0700 under `$TMPDIR` on POSIX,
|
|
80
|
+
`%LOCALAPPDATA%\witan-code\state` on Windows). Another user could create a
|
|
81
|
+
predictable name in a shared `TMPDIR` first, as a file pinning a wrong
|
|
82
|
+
bridge verdict or as a symlink the write would follow. If the state dir is
|
|
83
|
+
refused, the hook probes the bridge uncached instead of dropping its block.
|
|
84
|
+
The first Stop hook after upgrading finds neither stamp, so it runs one
|
|
85
|
+
optimize and one `--cleanup-older-than 2d` cleanup that the old stamps might
|
|
86
|
+
have deferred (the cleanup by up to its 7-day window).
|
|
87
|
+
|
|
88
|
+
- `witan --target <name> code doctor` reads that target's code graphs. `doctor` used the config loaded when the server module was imported, which never sees a forwarded `--target`.
|
|
89
|
+
|
|
90
|
+
- `witan-code setup --agent codex` writes Codex's `witan-code` MCP entry as the installed `witan-code serve`, the same CLI its hooks call, instead of a `uvx --from git+…` entry. Which platforms get the CLI entry now follows agent-config-kit's registry: every platform it writes hooks for. Requires agent-config-kit 0.13, the first release with Codex hooks.
|
|
91
|
+
- `witan-code setup` warns when `witan-code` is not on PATH, since the hooks and the `witan-code serve` MCP entry it registers both need it.
|
|
92
|
+
|
|
93
|
+
- `code_repo_dependencies` and the bridge explorer draw the "ol-infrastructure
|
|
94
|
+
deploys repo X" edge again. The extractor has written a repo service anchor
|
|
95
|
+
as the bare repo URI with `sub_kind="repo"` since #7, but the graph builder
|
|
96
|
+
still looked for a `repo:` key prefix and the `all_bindings` read did not
|
|
97
|
+
return `sub_kind`, so no deployed graph ever had a service edge. Image and
|
|
98
|
+
app-name anchors still draw no edge: nothing in the indexed repos yet says
|
|
99
|
+
which repo builds an image.
|
|
100
|
+
|
|
101
|
+
### Notes
|
|
102
|
+
|
|
103
|
+
- `Symbol.docstring` gains `@index` in `code-schema.pg`. On omnigraph 0.15 both `schema plan` (a local store) and `cluster plan` (a cluster) report it as one supported `add_constraint` step, and the apply indexes the docstrings already stored, so no code graph needs a rebuild. A local store gains the index on its next index, through the schema apply that already runs when the schema file changes. A cluster's `code-<repo>` graphs gain it when an omnigraph-server image built with this schema boots and runs `cluster apply`. Until a store has the index, omnigraph 0.15 refuses the docstring run (`T27`). A client reading through a deployed MCP tier (`code_transport = "mcp"`) older than this release is refused too, because the tier looks the query up in its own bundled `code_read.gq`. In both cases `code_search_symbol` returns name matches only and logs `witan.code.search.docstring_search_unavailable`.
|
|
104
|
+
|
|
11
105
|
## [0.30.0] - 2026-11-12
|
|
12
106
|
|
|
13
107
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: witan-code
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.32.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
|
|
@@ -10,7 +10,7 @@ License-Expression: BSD-3-Clause
|
|
|
10
10
|
Keywords: agent,code-graph,coding-agent,mcp,static-analysis,tree-sitter
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
12
|
Requires-Python: >=3.11
|
|
13
|
-
Requires-Dist: agent-config-kit<1,>=0.
|
|
13
|
+
Requires-Dist: agent-config-kit<1,>=0.13
|
|
14
14
|
Requires-Dist: cyclopts<6,>=4
|
|
15
15
|
Requires-Dist: fastmcp<5,>=4
|
|
16
16
|
Requires-Dist: joserfc<2,>=1.0
|
|
@@ -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.
|
|
29
|
+
Requires-Dist: witan-core[cli,observability,remote,sentry]<1,>=0.57.0
|
|
30
30
|
Provides-Extra: tasks
|
|
31
31
|
Requires-Dist: fastmcp-tasks<5,>=4; extra == 'tasks'
|
|
32
32
|
Description-Content-Type: text/markdown
|
|
@@ -246,8 +246,9 @@ file + a capture→kind map), and any new node types to `_DEF_NODE_TYPES`.
|
|
|
246
246
|
|
|
247
247
|
## Install
|
|
248
248
|
|
|
249
|
-
witan-code is usually installed as part of the `witan` umbrella
|
|
250
|
-
|
|
249
|
+
witan-code is usually installed as part of the `witan` umbrella: one `witan
|
|
250
|
+
serve` mounts witan-code's `code_*` tools whenever witan-code is installed
|
|
251
|
+
alongside it, and `witan setup` registers that one server. See the
|
|
251
252
|
[witan README](../witan/README.md) for the one-step setup.
|
|
252
253
|
|
|
253
254
|
To use witan-code **standalone** (code graph only, no memory/task tools):
|
|
@@ -375,14 +376,13 @@ bindings.
|
|
|
375
376
|
|
|
376
377
|
Set `code_server` (env `WITAN_CODE_SERVER`) and each repo's code graph is
|
|
377
378
|
instead a graph on the deployed omnigraph-server, addressed as `--server <url>
|
|
378
|
-
--graph <id>` with the id from `
|
|
379
|
+
--graph <id>` with the id from `witan_core.graph_ids.code_graph_id()` — e.g.
|
|
379
380
|
`https://github.com/mitodl/ol-django` → `code-github-com-mitodl-ol-django`.
|
|
380
|
-
The bridge graph is the fixed `code-bridge`.
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
and
|
|
384
|
-
|
|
385
|
-
ids the server actually serves.
|
|
381
|
+
The bridge graph is the fixed `code-bridge`. ol-infrastructure's provisioning
|
|
382
|
+
(`applications/omnigraph/cluster_config.py`) imports the same function from
|
|
383
|
+
witan-core to *declare* the graphs and apply their schema; this client never
|
|
384
|
+
creates one, and indexing a repo the cluster has no graph for fails immediately
|
|
385
|
+
with the id it expected and the ids the server actually serves.
|
|
386
386
|
|
|
387
387
|
This is the **data tier** and is independent of `remote_url`
|
|
388
388
|
([Remote mode](#remote-mode)), which routes read *tools* through a deployed
|
|
@@ -504,12 +504,12 @@ indexer first).
|
|
|
504
504
|
|
|
505
505
|
| Tool | Returns |
|
|
506
506
|
|------|---------|
|
|
507
|
-
| `code_find_definition(name)` | symbols whose name / qualified name matches |
|
|
507
|
+
| `code_find_definition(name)` / `code_find_definition(symbol_id=...)` | symbols whose name / qualified name matches (at most 50 per repo), or the one symbol with that exact id |
|
|
508
508
|
| `code_find_references(symbol_id)` | incoming `References` + `Calls` |
|
|
509
|
-
| `code_callers(symbol_id)` | incoming `Calls` |
|
|
510
|
-
| `code_impact(symbol_id, max_depth=5, max_nodes=200)` | transitive callers via BFS |
|
|
509
|
+
| `code_callers(symbol_id, direction="callers", branch=None)` | incoming `Calls`; `direction="callees"` for outgoing |
|
|
510
|
+
| `code_impact(symbol_id, max_depth=5, max_nodes=200, branch=None)` | transitive callers via BFS |
|
|
511
511
|
| `code_symbols_in_file(path)` | symbols defined in a file |
|
|
512
|
-
| `code_search_symbol(query)` | BM25 search over symbol qualified names |
|
|
512
|
+
| `code_search_symbol(query)` | BM25 search over symbol qualified names, then docstrings (name matches first) |
|
|
513
513
|
| `code_reindex(path=None)` | index/re-index the repo or a subpath |
|
|
514
514
|
|
|
515
515
|
Cross-repo bridge tools (resolve the shared `_bridge.omni` store; return `[]` /
|
|
@@ -213,8 +213,9 @@ file + a capture→kind map), and any new node types to `_DEF_NODE_TYPES`.
|
|
|
213
213
|
|
|
214
214
|
## Install
|
|
215
215
|
|
|
216
|
-
witan-code is usually installed as part of the `witan` umbrella
|
|
217
|
-
|
|
216
|
+
witan-code is usually installed as part of the `witan` umbrella: one `witan
|
|
217
|
+
serve` mounts witan-code's `code_*` tools whenever witan-code is installed
|
|
218
|
+
alongside it, and `witan setup` registers that one server. See the
|
|
218
219
|
[witan README](../witan/README.md) for the one-step setup.
|
|
219
220
|
|
|
220
221
|
To use witan-code **standalone** (code graph only, no memory/task tools):
|
|
@@ -342,14 +343,13 @@ bindings.
|
|
|
342
343
|
|
|
343
344
|
Set `code_server` (env `WITAN_CODE_SERVER`) and each repo's code graph is
|
|
344
345
|
instead a graph on the deployed omnigraph-server, addressed as `--server <url>
|
|
345
|
-
--graph <id>` with the id from `
|
|
346
|
+
--graph <id>` with the id from `witan_core.graph_ids.code_graph_id()` — e.g.
|
|
346
347
|
`https://github.com/mitodl/ol-django` → `code-github-com-mitodl-ol-django`.
|
|
347
|
-
The bridge graph is the fixed `code-bridge`.
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
and
|
|
351
|
-
|
|
352
|
-
ids the server actually serves.
|
|
348
|
+
The bridge graph is the fixed `code-bridge`. ol-infrastructure's provisioning
|
|
349
|
+
(`applications/omnigraph/cluster_config.py`) imports the same function from
|
|
350
|
+
witan-core to *declare* the graphs and apply their schema; this client never
|
|
351
|
+
creates one, and indexing a repo the cluster has no graph for fails immediately
|
|
352
|
+
with the id it expected and the ids the server actually serves.
|
|
353
353
|
|
|
354
354
|
This is the **data tier** and is independent of `remote_url`
|
|
355
355
|
([Remote mode](#remote-mode)), which routes read *tools* through a deployed
|
|
@@ -471,12 +471,12 @@ indexer first).
|
|
|
471
471
|
|
|
472
472
|
| Tool | Returns |
|
|
473
473
|
|------|---------|
|
|
474
|
-
| `code_find_definition(name)` | symbols whose name / qualified name matches |
|
|
474
|
+
| `code_find_definition(name)` / `code_find_definition(symbol_id=...)` | symbols whose name / qualified name matches (at most 50 per repo), or the one symbol with that exact id |
|
|
475
475
|
| `code_find_references(symbol_id)` | incoming `References` + `Calls` |
|
|
476
|
-
| `code_callers(symbol_id)` | incoming `Calls` |
|
|
477
|
-
| `code_impact(symbol_id, max_depth=5, max_nodes=200)` | transitive callers via BFS |
|
|
476
|
+
| `code_callers(symbol_id, direction="callers", branch=None)` | incoming `Calls`; `direction="callees"` for outgoing |
|
|
477
|
+
| `code_impact(symbol_id, max_depth=5, max_nodes=200, branch=None)` | transitive callers via BFS |
|
|
478
478
|
| `code_symbols_in_file(path)` | symbols defined in a file |
|
|
479
|
-
| `code_search_symbol(query)` | BM25 search over symbol qualified names |
|
|
479
|
+
| `code_search_symbol(query)` | BM25 search over symbol qualified names, then docstrings (name matches first) |
|
|
480
480
|
| `code_reindex(path=None)` | index/re-index the repo or a subpath |
|
|
481
481
|
|
|
482
482
|
Cross-repo bridge tools (resolve the shared `_bridge.omni` store; return `[]` /
|
|
@@ -55,9 +55,10 @@ index. See the main [README](../README.md) for the full two-layer table.
|
|
|
55
55
|
|
|
56
56
|
## Installation
|
|
57
57
|
|
|
58
|
-
witan-code is usually installed as part of the `witan` umbrella package
|
|
59
|
-
`witan
|
|
60
|
-
`
|
|
58
|
+
witan-code is usually installed as part of the `witan` umbrella package: one
|
|
59
|
+
`witan serve` mounts witan-code's `code_*` tools whenever witan-code is
|
|
60
|
+
installed alongside it, and `witan setup` registers that one server and
|
|
61
|
+
installs the shared `omnigraph` binary in one step. See the [witan README](../../witan/README.md)
|
|
61
62
|
for that one-step setup.
|
|
62
63
|
|
|
63
64
|
To use witan-code **standalone** (code graph only, no memory/task tools):
|
|
@@ -131,6 +132,7 @@ copy the matching snippet from `config/` into your agent's config — see
|
|
|
131
132
|
|
|
132
133
|
```bash
|
|
133
134
|
code_callers(symbol_id="https://github.com/org/repo#app/client.py::ServiceClient.run")
|
|
135
|
+
code_callers(symbol_id="...", direction="callees") # what it calls
|
|
134
136
|
code_impact(symbol_id="...", max_depth=5, max_nodes=200) # transitive callers
|
|
135
137
|
```
|
|
136
138
|
|
|
@@ -234,10 +236,15 @@ Don't re-derive the mechanics here — see:
|
|
|
234
236
|
`branch` argument of `code_find_definition` / `code_search_symbol` /
|
|
235
237
|
`code_symbols_in_file`) to read it.
|
|
236
238
|
- **Caller/impact results look wrong or incomplete.** `Calls`, `References`,
|
|
237
|
-
`Imports`, and `Inherits` are **heuristic** — syntactic name resolution
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
`Imports`, and `Inherits` are **heuristic** — syntactic name resolution.
|
|
240
|
+
A call resolves to a definition in the same file, or, in Python and TS/JS,
|
|
241
|
+
to one in another file of the repo when the callee is an imported name or
|
|
242
|
+
an attribute of one (`mod.func()`, `Cls.method()`). Calls through an
|
|
243
|
+
instance (`obj.method()`), re-exports, star imports, `require()`, path
|
|
244
|
+
aliases, and shadowing aren't followed. After upgrading, run
|
|
245
|
+
`witan-code reindex` once: an incremental run skips unchanged files,
|
|
246
|
+
so their calls into other files are not resolved until they change.
|
|
247
|
+
Treat them as a high-recall starting point for investigation,
|
|
241
248
|
not a verified call graph. `Defines`/`Contains` (and Stage-2 precise
|
|
242
249
|
cross-repo edges) are exact by contrast.
|
|
243
250
|
- **No pre-built `omnigraph` binary for your platform.** Only
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "witan-code"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.32.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"
|
|
@@ -30,7 +30,11 @@ dependencies = [
|
|
|
30
30
|
# pi-mcp-adapter is missing when Pi's built-in MCP will load the entry
|
|
31
31
|
# from 0.12.0. Older resolutions import and run, and print the false
|
|
32
32
|
# warning.
|
|
33
|
-
|
|
33
|
+
# >=0.13: Codex hooks (and the codex platform itself) arrive in 0.13.0.
|
|
34
|
+
# `cli_hook_platforms()` reads them from the registry, so an older
|
|
35
|
+
# resolution writes Codex a uvx MCP entry, and `--agent codex` raises
|
|
36
|
+
# KeyError on the missing platform.
|
|
37
|
+
"agent-config-kit>=0.13,<1",
|
|
34
38
|
# `remote`: the ADR-0005 client stack (OIDC device grant + MCP-client
|
|
35
39
|
# proxy) behind `witan-code login` and the read commands' remote mode.
|
|
36
40
|
# Costs nothing extra in practice — fastmcp is already required here and
|
|
@@ -222,7 +226,12 @@ dependencies = [
|
|
|
222
226
|
# ★ >=0.52 IS AN IMPORT FLOOR: hooks.py imports `witan_core._filelock`
|
|
223
227
|
# (added in witan-core 0.52.0 by #601) at module scope, so 0.51.1 cannot
|
|
224
228
|
# import the hook commands at all.
|
|
225
|
-
|
|
229
|
+
#
|
|
230
|
+
# ★ >=0.57 IS AN IMPORT FLOOR: store.py, indexer.py and ingest.py import
|
|
231
|
+
# `witan_core.graph_ids` at module scope. It moved there from config.py so
|
|
232
|
+
# ol-infrastructure's cluster provisioning can import the same function
|
|
233
|
+
# instead of mirroring it.
|
|
234
|
+
"witan-core[cli,remote,observability,sentry]>=0.57.0,<1",
|
|
226
235
|
"fastmcp>=4,<5",
|
|
227
236
|
"cyclopts>=4,<6",
|
|
228
237
|
# [targets.<name>] override models (config.py) — also transitively pulled
|
|
@@ -305,7 +314,7 @@ testpaths = ["tests"]
|
|
|
305
314
|
packages = ["witan_code"]
|
|
306
315
|
|
|
307
316
|
[tool.bumpversion]
|
|
308
|
-
current_version = "0.
|
|
317
|
+
current_version = "0.32.0"
|
|
309
318
|
allow_dirty = true
|
|
310
319
|
|
|
311
320
|
[[tool.bumpversion.files]]
|
|
@@ -8,6 +8,8 @@ tree-sitter-<lang> wheels, not the optional tree-sitter-language-pack), not an
|
|
|
8
8
|
optional extra — so there's nothing to gate on there.
|
|
9
9
|
"""
|
|
10
10
|
|
|
11
|
+
import asyncio
|
|
12
|
+
import inspect
|
|
11
13
|
import shutil
|
|
12
14
|
|
|
13
15
|
import pytest
|
|
@@ -19,6 +21,19 @@ requires_stack = pytest.mark.skipif(
|
|
|
19
21
|
reason="requires omnigraph binary",
|
|
20
22
|
)
|
|
21
23
|
|
|
24
|
+
|
|
25
|
+
def tool_fn(tool):
|
|
26
|
+
"""A FastMCP tool as a plain callable; an ``async`` one runs to completion.
|
|
27
|
+
|
|
28
|
+
Called directly rather than through an MCP client, a tool that takes a
|
|
29
|
+
``ctx: Context`` gets none and falls back to its non-interactive default.
|
|
30
|
+
"""
|
|
31
|
+
fn = getattr(tool, "fn", tool)
|
|
32
|
+
if inspect.iscoroutinefunction(fn):
|
|
33
|
+
return lambda *a, **kw: asyncio.run(fn(*a, **kw))
|
|
34
|
+
return fn
|
|
35
|
+
|
|
36
|
+
|
|
22
37
|
# Narrower than requires_stack: maintenance (optimize/cleanup) exercises the
|
|
23
38
|
# omnigraph binary directly and has no tree-sitter involvement.
|
|
24
39
|
requires_omnigraph = pytest.mark.skipif(
|
|
@@ -597,6 +597,48 @@ def test_two_writers_on_one_branch_do_not_overwrite_each_other(tmp_path, monkeyp
|
|
|
597
597
|
assert not _has("act-bob/feature_shared", "alice_only_symbol")
|
|
598
598
|
|
|
599
599
|
|
|
600
|
+
@requires_stack
|
|
601
|
+
def test_callees_follow_the_checkouts_branch_view(tmp_path, monkeypatch):
|
|
602
|
+
"""`code_callers(direction="callees")` routes by symbol id like the callers
|
|
603
|
+
query does, so on a feature branch it reads that branch's view: a call the
|
|
604
|
+
branch added shows up there and nowhere on main."""
|
|
605
|
+
from witan_code import config as cfg_mod
|
|
606
|
+
from witan_code import indexer
|
|
607
|
+
from witan_code import server as srv
|
|
608
|
+
|
|
609
|
+
monkeypatch.setenv("WITAN_REPO", REPO)
|
|
610
|
+
monkeypatch.setenv("WITAN_CODE_DIR", str(tmp_path / "code"))
|
|
611
|
+
monkeypatch.setattr(srv, "cfg", cfg_mod.load())
|
|
612
|
+
|
|
613
|
+
def reset():
|
|
614
|
+
srv._clients.clear()
|
|
615
|
+
srv._store_branches.clear()
|
|
616
|
+
srv._git_context.clear()
|
|
617
|
+
|
|
618
|
+
reset()
|
|
619
|
+
base = _git_repo(tmp_path / "r")
|
|
620
|
+
(base / "svc.py").write_text(SAMPLE)
|
|
621
|
+
indexer.index_path(base, config=srv.cfg)
|
|
622
|
+
|
|
623
|
+
_git(base, "checkout", "-q", "-b", "feature/x")
|
|
624
|
+
(base / "svc.py").write_text(
|
|
625
|
+
SAMPLE.replace("return helper()", "audit()\n return helper()")
|
|
626
|
+
+ "\n\ndef audit():\n return 0\n"
|
|
627
|
+
)
|
|
628
|
+
indexer.index_path(base, config=srv.cfg)
|
|
629
|
+
|
|
630
|
+
run_id = f"{REPO}#svc.py::Service.run"
|
|
631
|
+
monkeypatch.chdir(base)
|
|
632
|
+
reset()
|
|
633
|
+
on_branch = _fn(srv.code_callers)(run_id, direction="callees")
|
|
634
|
+
assert {c["qualified_name"] for c in on_branch} == {"audit", "helper"}
|
|
635
|
+
|
|
636
|
+
_git(base, "checkout", "-q", "main")
|
|
637
|
+
reset()
|
|
638
|
+
on_main = _fn(srv.code_callers)(run_id, direction="callees")
|
|
639
|
+
assert {c["qualified_name"] for c in on_main} == {"helper"}
|
|
640
|
+
|
|
641
|
+
|
|
600
642
|
@requires_stack
|
|
601
643
|
def test_a_reader_can_enumerate_every_writers_view_of_a_branch(tmp_path, monkeypatch):
|
|
602
644
|
"""Isolation and visibility are not in tension: the views are separated by
|
|
@@ -781,3 +823,161 @@ def test_a_branch_name_with_a_slash_is_not_read_as_a_view_name(tmp_path, monkeyp
|
|
|
781
823
|
"slashed_branch_symbol", repo=REPO, branch="feature/new-api"
|
|
782
824
|
)
|
|
783
825
|
assert found, "a raw git branch with a slash must map through sanitization"
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
# ── `branch` on the id- and file-routed tools ─────────────────────
|
|
829
|
+
#
|
|
830
|
+
# Locally, these tools follow the checkout's branch view once it is indexed.
|
|
831
|
+
# A symbol that branch removed is gone from that view, so a caller asking
|
|
832
|
+
# "what did this removal break" needs to read main: `branch="main"`.
|
|
833
|
+
|
|
834
|
+
MAIN_SVC = SAMPLE + (
|
|
835
|
+
'\n\ndef retired():\n return os.environ["SHARED_URL"] or helper()\n'
|
|
836
|
+
)
|
|
837
|
+
BRANCH_SVC = SAMPLE + "\n\ndef fresh():\n return helper()\n"
|
|
838
|
+
PROVIDER = "https://github.com/test/infra"
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
@pytest.fixture
|
|
842
|
+
def removal_on_an_indexed_branch(tmp_path, monkeypatch):
|
|
843
|
+
"""`retired` on main, gone on `feature/x` (indexed), `fresh` added there.
|
|
844
|
+
|
|
845
|
+
`retired` reads SHARED_URL, which a second repo provides, so it has a
|
|
846
|
+
cross-repo surface on main and none in the branch's overlay.
|
|
847
|
+
"""
|
|
848
|
+
from witan_code import config as cfg_mod
|
|
849
|
+
from witan_code import indexer
|
|
850
|
+
from witan_code import server as srv
|
|
851
|
+
|
|
852
|
+
monkeypatch.setenv("WITAN_CODE_DIR", str(tmp_path / "code"))
|
|
853
|
+
monkeypatch.setattr(srv, "cfg", cfg_mod.load())
|
|
854
|
+
|
|
855
|
+
infra = tmp_path / "infra"
|
|
856
|
+
infra.mkdir()
|
|
857
|
+
(infra / "Pulumi.QA.yaml").write_text(
|
|
858
|
+
'config:\n app:env_vars:\n SHARED_URL: "https://x.example.com"\n'
|
|
859
|
+
)
|
|
860
|
+
indexer.index_path(infra, repo_override=PROVIDER, config=srv.cfg)
|
|
861
|
+
|
|
862
|
+
monkeypatch.setenv("WITAN_REPO", REPO)
|
|
863
|
+
base = _git_repo(tmp_path / "r")
|
|
864
|
+
(base / "svc.py").write_text("import os\n" + MAIN_SVC)
|
|
865
|
+
indexer.index_path(base, config=srv.cfg)
|
|
866
|
+
_git(base, "checkout", "-q", "-b", "feature/x")
|
|
867
|
+
(base / "svc.py").write_text("import os\n" + BRANCH_SVC)
|
|
868
|
+
indexer.index_path(base, config=srv.cfg)
|
|
869
|
+
|
|
870
|
+
monkeypatch.chdir(base)
|
|
871
|
+
srv._clients.clear()
|
|
872
|
+
srv._store_branches.clear()
|
|
873
|
+
srv._git_context.clear()
|
|
874
|
+
return srv
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
@requires_stack
|
|
878
|
+
def test_symbols_in_file_reads_the_named_branchs_view(removal_on_an_indexed_branch):
|
|
879
|
+
srv = removal_on_an_indexed_branch
|
|
880
|
+
|
|
881
|
+
def names(**kwargs):
|
|
882
|
+
rows = _fn(srv.code_symbols_in_file)("svc.py", repo=REPO, **kwargs)
|
|
883
|
+
return {r["qualified_name"] for r in rows}
|
|
884
|
+
|
|
885
|
+
on_branch, on_main = names(), names(branch="main")
|
|
886
|
+
assert "fresh" in on_branch and "retired" not in on_branch
|
|
887
|
+
assert "retired" in on_main and "fresh" not in on_main
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
@requires_stack
|
|
891
|
+
def test_impact_walks_the_named_branchs_view(removal_on_an_indexed_branch):
|
|
892
|
+
srv = removal_on_an_indexed_branch
|
|
893
|
+
helper = f"{REPO}#svc.py::helper"
|
|
894
|
+
|
|
895
|
+
def callers(**kwargs):
|
|
896
|
+
impact = _fn(srv.code_impact)(helper, max_depth=1, **kwargs)
|
|
897
|
+
return {c["qualified_name"] for c in impact["impacted"]}
|
|
898
|
+
|
|
899
|
+
on_branch, on_main = callers(), callers(branch="main")
|
|
900
|
+
assert "fresh" in on_branch and "retired" not in on_branch
|
|
901
|
+
assert "retired" in on_main and "fresh" not in on_main
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
@requires_stack
|
|
905
|
+
def test_cross_repo_impact_reads_the_named_branchs_overlay(
|
|
906
|
+
removal_on_an_indexed_branch,
|
|
907
|
+
):
|
|
908
|
+
srv = removal_on_an_indexed_branch
|
|
909
|
+
retired = f"{REPO}#svc.py::retired"
|
|
910
|
+
|
|
911
|
+
on_branch = _fn(srv.code_cross_repo_impact)(retired)
|
|
912
|
+
assert on_branch["cross_repo"] == [], "the branch's overlay no longer has it"
|
|
913
|
+
|
|
914
|
+
on_main = _fn(srv.code_cross_repo_impact)(retired, branch="main")
|
|
915
|
+
assert {b["repo"] for b in on_main["cross_repo"]} == {PROVIDER}
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
@requires_stack
|
|
919
|
+
def test_callers_reads_the_named_branchs_view(removal_on_an_indexed_branch):
|
|
920
|
+
srv = removal_on_an_indexed_branch
|
|
921
|
+
helper = f"{REPO}#svc.py::helper"
|
|
922
|
+
|
|
923
|
+
def callers(**kwargs):
|
|
924
|
+
return {c["qualified_name"] for c in _fn(srv.code_callers)(helper, **kwargs)}
|
|
925
|
+
|
|
926
|
+
on_branch, on_main = callers(), callers(branch="main")
|
|
927
|
+
assert "fresh" in on_branch and "retired" not in on_branch
|
|
928
|
+
assert "retired" in on_main and "fresh" not in on_main
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
@requires_stack
|
|
932
|
+
def test_callers_reads_a_branch_from_a_server_with_no_checkout(
|
|
933
|
+
removal_on_an_indexed_branch, tmp_path, monkeypatch
|
|
934
|
+
):
|
|
935
|
+
"""A deployed server has no checkout to follow, so without `branch` it
|
|
936
|
+
reads main, and `branch` is the only way to reach a branch's edges."""
|
|
937
|
+
srv = removal_on_an_indexed_branch
|
|
938
|
+
elsewhere = tmp_path / "not-a-repo"
|
|
939
|
+
elsewhere.mkdir()
|
|
940
|
+
monkeypatch.chdir(elsewhere)
|
|
941
|
+
monkeypatch.delenv("WITAN_REPO")
|
|
942
|
+
srv._git_context.clear()
|
|
943
|
+
assert srv._cached_detect() is None
|
|
944
|
+
helper = f"{REPO}#svc.py::helper"
|
|
945
|
+
|
|
946
|
+
def callers(**kwargs):
|
|
947
|
+
return {c["qualified_name"] for c in _fn(srv.code_callers)(helper, **kwargs)}
|
|
948
|
+
|
|
949
|
+
default, on_branch = callers(), callers(branch="feature/x")
|
|
950
|
+
assert "retired" in default and "fresh" not in default
|
|
951
|
+
assert "fresh" in on_branch and "retired" not in on_branch
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
@requires_stack
|
|
955
|
+
def test_callers_keeps_the_branch_after_the_reindex_offer(
|
|
956
|
+
removal_on_an_indexed_branch, monkeypatch
|
|
957
|
+
):
|
|
958
|
+
"""The missing-store fallback indexes the checkout, then must still read
|
|
959
|
+
the view `branch` names, not the checkout's own (feature/x here)."""
|
|
960
|
+
from witan_code import indexer
|
|
961
|
+
|
|
962
|
+
from .test_elicit import _AcceptCtx
|
|
963
|
+
|
|
964
|
+
srv = removal_on_an_indexed_branch
|
|
965
|
+
indexed = []
|
|
966
|
+
real_client_for_symbol = srv._client_for_symbol
|
|
967
|
+
monkeypatch.setattr(
|
|
968
|
+
srv,
|
|
969
|
+
"_client_for_symbol",
|
|
970
|
+
lambda sid, branch=None: (
|
|
971
|
+
real_client_for_symbol(sid, branch) if indexed else None
|
|
972
|
+
),
|
|
973
|
+
)
|
|
974
|
+
monkeypatch.setattr(
|
|
975
|
+
indexer, "index_path", lambda *args, **kwargs: indexed.append(True)
|
|
976
|
+
)
|
|
977
|
+
helper = f"{REPO}#svc.py::helper"
|
|
978
|
+
|
|
979
|
+
rows = _fn(srv.code_callers)(helper, branch="main", ctx=_AcceptCtx(True))
|
|
980
|
+
|
|
981
|
+
assert indexed
|
|
982
|
+
names = {c["qualified_name"] for c in rows}
|
|
983
|
+
assert "retired" in names and "fresh" not in names
|
|
@@ -293,8 +293,13 @@ def test_the_bridge_verdict_is_cached_across_processes(tmp_path, monkeypatch):
|
|
|
293
293
|
(code_dir / "_bridge.omni").mkdir(parents=True)
|
|
294
294
|
monkeypatch.setenv("WITAN_CODE_DIR", str(code_dir))
|
|
295
295
|
monkeypatch.setenv("TMPDIR", str(tmp_path))
|
|
296
|
+
monkeypatch.setattr(tempfile, "tempdir", str(tmp_path))
|
|
297
|
+
monkeypatch.setenv("LOCALAPPDATA", str(tmp_path))
|
|
296
298
|
cfg = cfg_mod.load()
|
|
297
299
|
|
|
300
|
+
# In the private state dir, not the bare temp dir another user can write.
|
|
301
|
+
assert context._bridge_probe_path(cfg).parent == context.state_dir()
|
|
302
|
+
|
|
298
303
|
probes = []
|
|
299
304
|
|
|
300
305
|
def _probe(ref, config=None, *, bridge=False):
|
|
@@ -318,6 +323,33 @@ def test_the_bridge_verdict_is_cached_across_processes(tmp_path, monkeypatch):
|
|
|
318
323
|
assert len(probes) == 2
|
|
319
324
|
|
|
320
325
|
|
|
326
|
+
def test_a_refused_state_dir_probes_uncached(tmp_path, monkeypatch):
|
|
327
|
+
"""state_dir() raises when its directory is not ours. The verdict must
|
|
328
|
+
still come back, uncached, rather than the raise blanking the block."""
|
|
329
|
+
from witan_code import config as cfg_mod
|
|
330
|
+
|
|
331
|
+
code_dir = tmp_path / "code"
|
|
332
|
+
(code_dir / "_bridge.omni").mkdir(parents=True)
|
|
333
|
+
monkeypatch.setenv("WITAN_CODE_DIR", str(code_dir))
|
|
334
|
+
cfg = cfg_mod.load()
|
|
335
|
+
|
|
336
|
+
def _refused():
|
|
337
|
+
raise PermissionError("not a directory owned by this user")
|
|
338
|
+
|
|
339
|
+
monkeypatch.setattr(context, "state_dir", _refused)
|
|
340
|
+
probes = []
|
|
341
|
+
|
|
342
|
+
def _probe(ref, config=None, *, bridge=False):
|
|
343
|
+
probes.append(ref)
|
|
344
|
+
return context.store_module.StoreHealth(ref, None, error="stale")
|
|
345
|
+
|
|
346
|
+
monkeypatch.setattr(context.store_module, "store_health", _probe)
|
|
347
|
+
|
|
348
|
+
assert context._bridge_ok(cfg) is False
|
|
349
|
+
assert context._bridge_ok(cfg) is False
|
|
350
|
+
assert len(probes) == 2
|
|
351
|
+
|
|
352
|
+
|
|
321
353
|
def test_lock_path_does_not_collide_on_sanitization(tmp_path, monkeypatch):
|
|
322
354
|
monkeypatch.setattr(tempfile, "tempdir", str(tmp_path))
|
|
323
355
|
|