Skip to content

Commit a4dbe89

Browse files
committed
test(windows): add red regressions for hook augmenter and UI drive picker
Extends the Windows red-test suite with two more reproduced, Windows-specific failures. No production fixes. - windows_hook_augment_emits_context (integration, DeusData#618): the PreToolUse Grep/Glob augmenter `hook-augment` emits empty stdout for every payload on Windows. src/cli/hook_augment.c gates on POSIX-style absolute paths (cwd[0] == '/' and the walk-up loop's dir[0] == '/'), which a Windows drive-letter cwd never satisfies, so the graph augmentation never fires. A control search_graph confirms the symbol is indexed. - windows_ui_picker_reaches_all_drives (integration, DeusData#548): the UI directory picker's GET /api/browse?path=/ returns no entries and never enumerates logical drives, so drives other than the system drive (D:\, E:\) cannot be selected. handle_browse in src/ui/http_server.c uses opendir without a GetLogicalDriveStrings root case. Needs a UI build (cbm-with-ui) and >1 drive; otherwise it reports a precondition (exit 2). Also records additional ruled-out seed areas (get_code_snippet sanitizes non-UTF-8 to U+FFFD DeusData#530.3; stdio handshake/flush works DeusData#513/DeusData#530.1/DeusData#635; mapped subst-drive indexing keeps the DB DeusData#227/DeusData#367) and cross-platform items left out of this Windows-only PR (DeusData#530.2 nested gitignore, DeusData#530.5 .git/info/exclude, DeusData#530.4 libgit2 build, DeusData#581 memory soak). Signed-off-by: Flipper <jacobphilipp@ymail.com>
1 parent 0d3d0fb commit a4dbe89

4 files changed

Lines changed: 394 additions & 10 deletions

File tree

‎scripts/test-windows.ps1‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,19 @@ Write-Host "Binary: $bin" -ForegroundColor Green
6363

6464
$env:PYTHONUTF8 = "1" # ensure the harness encodes argv/stdio as UTF-8
6565

66+
# test_ui_drive_listing.py reproduces the UI directory-picker bug (#548) and
67+
# therefore needs a UI build (make -f Makefile.cbm cbm-with-ui) plus a machine
68+
# with more than one drive. Against a non-UI binary it reports a precondition
69+
# (exit 2), which is treated as a skip-with-reason, not a failure.
6670
$tests = @(
6771
"tests\windows\test_non_ascii_path.py",
68-
"tests\windows\test_cli_non_ascii_arg.py"
72+
"tests\windows\test_cli_non_ascii_arg.py",
73+
"tests\windows\test_hook_augment.py",
74+
"tests\windows\test_ui_drive_listing.py"
6975
)
7076

71-
$failed = @()
77+
$reds = @()
78+
$precond = @()
7279
foreach ($t in $tests) {
7380
Write-Host "`n=== $t ===" -ForegroundColor Cyan
7481
& $py $t $bin
@@ -77,18 +84,22 @@ foreach ($t in $tests) {
7784
Write-Host "GREEN ($t)" -ForegroundColor Green
7885
} elseif ($code -eq 1) {
7986
Write-Host "RED ($t) - Windows-specific failure reproduced" -ForegroundColor Red
80-
$failed += $t
87+
$reds += $t
8188
} else {
82-
Write-Host "SETUP ERROR ($t) exit=$code" -ForegroundColor Yellow
83-
$failed += $t
89+
Write-Host "PRECONDITION ($t) exit=$code - skipped (see message above)" -ForegroundColor Yellow
90+
$precond += $t
8491
}
8592
}
8693

8794
Write-Host ""
88-
if ($failed.Count -gt 0) {
89-
Write-Host ("RED suite: {0}/{1} Windows red tests failed (expected until the " -f $failed.Count, $tests.Count) -ForegroundColor Red
90-
Write-Host "platform issues are fixed). See tests/windows/RED_TEST_ANALYSIS.md." -ForegroundColor Red
95+
if ($precond.Count -gt 0) {
96+
Write-Host ("Precondition-skipped: {0} (e.g. test_ui_drive_listing needs a UI " -f $precond.Count) -ForegroundColor Yellow
97+
Write-Host "build: make -f Makefile.cbm cbm-with-ui, and >1 drive)." -ForegroundColor Yellow
98+
}
99+
if ($reds.Count -gt 0) {
100+
Write-Host ("RED suite: {0} Windows red tests reproduced platform failures " -f $reds.Count) -ForegroundColor Red
101+
Write-Host "(expected until fixed). See tests/windows/RED_TEST_ANALYSIS.md." -ForegroundColor Red
91102
exit 1
92103
}
93-
Write-Host "All Windows red tests are GREEN." -ForegroundColor Green
104+
Write-Host "All runnable Windows red tests are GREEN." -ForegroundColor Green
94105
exit 0

‎tests/windows/RED_TEST_ANALYSIS.md‎

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,88 @@ flows that shell out to it, not the stdio server path. Holds on Linux/macOS
121121

122122
---
123123

124+
## windows_hook_augment_emits_context
125+
126+
- Class: integration
127+
- Test: `tests/windows/test_hook_augment.py`
128+
- Related issues: #618
129+
- Environment: Windows 11 26200, `hook-augment` CLI subcommand
130+
- Fixture: a repo with a known function `someIndexedSymbol`, indexed; a realistic
131+
Claude Code PreToolUse Grep payload with a Windows drive-letter `cwd`
132+
- Expected: `codebase-memory-mcp hook-augment` emits a `hookSpecificOutput` with
133+
`additionalContext` listing the matching graph symbol (the control
134+
`search_graph` finds the symbol, so the index and project name are fine)
135+
- Actual: `hook-augment` emits **empty stdout** for every payload
136+
- Command: `python tests/windows/test_hook_augment.py build\c\codebase-memory-mcp.exe`
137+
- Minimal failure output:
138+
139+
```
140+
control: search_graph finds someIndexedSymbol in project C-...-repo
141+
hook-augment rc=0 stdout=''
142+
```
143+
144+
- Suspected implementation area: `src/cli/hook_augment.c` has two POSIX-only path
145+
guards. `cbm_cmd_hook_augment` (`_WIN32` branch, ~L330):
146+
`if (!cwd || cwd[0] != '/') { ...; return 0; }` and the `ha_resolve_and_query`
147+
walk-up loop (~L254): `for (...; dir[0] == '/'; ...)`. A Windows `cwd` is a
148+
drive-letter path (`C:\...` / `C:/...`), so `cwd[0]` is never `'/'`; the
149+
augmenter bails before it queries the graph. The PreToolUse Grep/Glob graph
150+
augmentation therefore never fires on Windows. Fix direction: accept
151+
drive-letter absolute paths (and climb them in the walk-up loop).
152+
153+
Holds on Linux/macOS (`cwd` starts with `/`).
154+
155+
---
156+
157+
## windows_ui_picker_reaches_all_drives
158+
159+
- Class: integration
160+
- Test: `tests/windows/test_ui_drive_listing.py`
161+
- Related issues: #548
162+
- Environment: Windows 11 26200 with drives `C:\`, `D:\`, `E:\`; UI build
163+
(`make -f Makefile.cbm cbm-with-ui`); embedded HTTP server on a local port
164+
- Fixture: none — exercises the live `GET /api/browse` endpoint
165+
- Expected: browsing the filesystem root (`/api/browse?path=/`) lets the user
166+
reach every fixed drive (`D:\`, `E:\`), so a project on a non-system drive can
167+
be selected
168+
- Actual: the control browse of an explicit directory returns entries (endpoint
169+
works), but `browse('/')` returns **0 entries** and no drive letters — `D:\`
170+
and `E:\` are unreachable from the picker root
171+
- Command: `python tests/windows/test_ui_drive_listing.py build\c\codebase-memory-mcp.exe`
172+
- Minimal failure output:
173+
174+
```
175+
control browse('C:/Users/jacob') -> dirs(23)
176+
browse('/') -> path='/' dirs(0)=[]
177+
RED: drives ['D:\\', 'E:\\'] are not reachable from the UI root picker
178+
```
179+
180+
- Suspected implementation area: `handle_browse` in `src/ui/http_server.c` does
181+
`opendir(path)` for the requested path. For the root it lists only the current
182+
drive's contents and never enumerates the logical drives
183+
(`GetLogicalDriveStrings`). Fix direction: when the path is the filesystem root
184+
on Windows, return the available drive letters as the directory list so the
185+
picker can descend into any drive.
186+
187+
This test requires a UI build because the HTTP server only starts when the
188+
frontend is embedded (`CBM_EMBEDDED_FILE_COUNT > 0`); against a non-UI binary it
189+
reports a precondition (exit 2), and on a single-drive machine it is not
190+
meaningful (exit 2). Holds on Linux/macOS (a single `/` root with no drive
191+
letters).
192+
193+
---
194+
124195
## Seed areas revisited and ruled out (green on native Windows)
125196

126197
Each was reproduced as a concrete attempt against the production binary and
127198
behaved correctly — recorded as green and **not** included as a red test:
128199

129200
| Area | Seed | Result on Windows |
130201
|---|---|---|
131-
| stdio `initialize` returns before stdin EOF | #513, #635 | green |
202+
| stdio `initialize` returns before stdin EOF; stdout flushes before EOF | #513, #530.1, #635 | green |
132203
| `tools/list` non-empty; all 14 tools return valid JSON-RPC | #530 | green |
204+
| `get_code_snippet` on a CP949 file emits valid UTF-8 (invalid bytes → U+FFFD) | #530.3 | green |
205+
| Indexing a mapped (subst) drive `W:\` — no `bad_root_path`/`store.corrupt`, DB kept | #227, #367 | green (subst; real SMB not testable here) |
133206
| Client exit terminates the server process (no residual `.exe`) | #185, #406 | green |
134207
| `--help` / `--version` exit 0 in PowerShell, cmd, Git Bash | — | green |
135208
| `search_code` works without bash/GNU grep (PowerShell `Select-String`) | #422, #348 | green |
@@ -157,6 +230,18 @@ behaved correctly — recorded as green and **not** included as a red test:
157230
paths over `MAX_PATH` are unreachable by every application, not just CBM.
158231
CBM could opt in via the `\\?\` prefix + wide APIs, but the failure is gated by
159232
a machine-wide policy rather than a clean CBM-only defect, so it is excluded.
233+
- **Cascading nested `.gitignore` (#530.2) and `.git/info/exclude` (#530.5).**
234+
`try_load_nested_gitignore` in `src/discover/discover.c` skips nested
235+
`.gitignore` files once a parent ignore is loaded, and discovery never reads
236+
`.git/info/exclude`. Both are real, but the discovery logic is
237+
platform-independent and reproduces identically on Linux, so they are out of
238+
scope for a Windows-only PR.
239+
- **libgit2 1.8+ build break (#530.4).** `git_allocator` moved to
240+
`<git2/sys/alloc.h>`; cross-platform compile issue, not a Windows runtime bug.
241+
- **Memory growth over hours (#581).** Requires a multi-hour soak to surface and
242+
is not deterministic in a unit/integration test; the existing
243+
`scripts/soak-test.sh` RSS-trend harness is the right vehicle and is not
244+
reproduced as a red test here.
160245
- **C `test-runner` failures on Windows.** The in-process C suite reports many
161246
extraction-count failures concentrated in `test_grammar_probe_*`,
162247
`test_node_creation_probe`, `test_edge_*`, `test_matrix_*`, and

‎tests/windows/test_hook_augment.py‎

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
r"""RED integration test — the PreToolUse hook augmenter is a no-op on Windows.
2+
3+
Reproduces issue #618 at the product surface.
4+
5+
`codebase-memory-mcp hook-augment` is the non-blocking Claude Code PreToolUse
6+
Grep/Glob augmenter: given a hook payload it should emit a `hookSpecificOutput`
7+
with `additionalContext` listing graph symbols that match the searched token.
8+
9+
On Windows it emits nothing for every payload. `src/cli/hook_augment.c` gates on
10+
POSIX-style absolute paths in two places:
11+
12+
cbm_cmd_hook_augment (_WIN32 branch): if (!cwd || cwd[0] != '/') return 0;
13+
ha_resolve_and_query walk-up loop: for (... ; dir[0] == '/'; ...)
14+
15+
A Windows `cwd` is a drive-letter path (`C:\...` / `C:/...`), so `cwd[0]` is
16+
never `'/'`; the augmenter bails before it ever queries the graph.
17+
18+
This test indexes a repo with a known symbol, confirms `search_graph` finds it
19+
(control — proves the index and project name are fine), then invokes
20+
`hook-augment` exactly as the installed PreToolUse hook does and asserts a
21+
`hookSpecificOutput` payload is produced.
22+
23+
Passes on Linux/macOS (`cwd` starts with `/`). Fails on native Windows until the
24+
path guards accept drive-letter absolute paths (and the walk-up loop climbs them).
25+
26+
Exit code: 0 == augmenter fired (green), 1 == no-op (red), 2 == setup error.
27+
28+
Usage:
29+
python test_hook_augment.py <path-to-codebase-memory-mcp[.exe]>
30+
"""
31+
import json
32+
import os
33+
import shutil
34+
import subprocess
35+
import sys
36+
import tempfile
37+
38+
SYMBOL = "someIndexedSymbol"
39+
SRC = "export function %s(a: number): number { return a + 1; }\n" % SYMBOL
40+
41+
42+
def run_cli(binary, cache, args, stdin=None, timeout=120):
43+
env = dict(os.environ)
44+
env["CBM_CACHE_DIR"] = cache
45+
return subprocess.run([binary] + args, capture_output=True, timeout=timeout,
46+
env=env, input=stdin)
47+
48+
49+
def main():
50+
if len(sys.argv) < 2:
51+
print("usage: python test_hook_augment.py <binary>")
52+
return 2
53+
binary = os.path.abspath(sys.argv[1])
54+
if not os.path.exists(binary):
55+
print("FAIL: binary not found: %s" % binary)
56+
return 2
57+
58+
work = tempfile.mkdtemp(prefix="cbm_win_hook_")
59+
try:
60+
repo = os.path.join(work, "repo")
61+
os.makedirs(os.path.join(repo, "src"), exist_ok=True)
62+
with open(os.path.join(repo, "src", "m.ts"), "wb") as f:
63+
f.write(SRC.encode("utf-8"))
64+
cache = os.path.join(work, "cache")
65+
os.makedirs(cache, exist_ok=True)
66+
67+
# repo_path / cwd in the forward-slash drive form Claude Code passes.
68+
repo_fwd = repo.replace("\\", "/")
69+
idx = run_cli(binary, cache, ["cli", "index_repository",
70+
json.dumps({"repo_path": repo_fwd})])
71+
idx_out = (idx.stdout or b"").decode("utf-8", "replace")
72+
if '"nodes"' not in idx_out:
73+
print("SETUP FAIL: index did not run:\n%s" % idx_out[:300])
74+
return 2
75+
76+
# Control: prove the symbol is indexed and queryable.
77+
lp = run_cli(binary, cache, ["cli", "list_projects", "{}"])
78+
projects = json.loads((lp.stdout or b"").decode("utf-8", "replace"))["projects"]
79+
name = projects[0]["name"]
80+
sg = run_cli(binary, cache, ["cli", "search_graph",
81+
json.dumps({"label": "Function",
82+
"name_pattern": ".*%s.*" % SYMBOL,
83+
"project": name})])
84+
if SYMBOL not in (sg.stdout or b"").decode("utf-8", "replace"):
85+
print("SETUP FAIL: control search_graph did not find %s" % SYMBOL)
86+
return 2
87+
print("control: search_graph finds %s in project %s" % (SYMBOL, name))
88+
89+
# Invoke hook-augment exactly as the installed PreToolUse hook does.
90+
payload = json.dumps({
91+
"hook_event_name": "PreToolUse",
92+
"tool_name": "Grep",
93+
"cwd": repo_fwd,
94+
"tool_input": {"pattern": SYMBOL},
95+
}).encode("utf-8")
96+
ha = run_cli(binary, cache, ["hook-augment"], stdin=payload, timeout=60)
97+
out = (ha.stdout or b"").decode("utf-8", "replace").strip()
98+
print("hook-augment rc=%d stdout=%r" % (ha.returncode, out[:200]))
99+
100+
fired = ("hookSpecificOutput" in out) and ("additionalContext" in out)
101+
if fired:
102+
print("\nGREEN: PreToolUse augmenter emitted additionalContext.")
103+
return 0
104+
print("\nRED: hook-augment produced no hookSpecificOutput on Windows "
105+
"(drive-letter cwd fails the cwd[0]=='/' guards in hook_augment.c).")
106+
return 1
107+
finally:
108+
shutil.rmtree(work, ignore_errors=True)
109+
110+
111+
if __name__ == "__main__":
112+
sys.exit(main())

0 commit comments

Comments
 (0)