|
| 1 | +# Windows Red-Test Analysis |
| 2 | + |
| 3 | +Deterministic, Windows-only red tests found during a native-Windows red-test |
| 4 | +campaign. They reproduce platform-specific failures at the product surface and |
| 5 | +are intended as regression guards while the underlying issues are fixed in |
| 6 | +separate maintainer PRs. **This PR contains no production fixes.** |
| 7 | + |
| 8 | +## Environment |
| 9 | + |
| 10 | +- OS: Microsoft Windows 11 Pro, build 10.0.26200 |
| 11 | +- Source build: MinGW-w64 GCC 15.2.0 (MSYS2), `make -f Makefile.cbm cbm` |
| 12 | +- Filesystem: NTFS, code page 65001 (UTF-8 console) |
| 13 | +- Shells/launchers exercised: PowerShell 5.1 (5.1.26100), `cmd.exe`, |
| 14 | + Git Bash (MSYS2), direct Win32 process launch, Python `subprocess.Popen`, |
| 15 | + Python stdio (line-delimited JSON-RPC) transport |
| 16 | +- CBM source commit under test: `b075f05` |
| 17 | +- Binary: `build/c/codebase-memory-mcp.exe` (production build) |
| 18 | + |
| 19 | +### Sanitizer note |
| 20 | + |
| 21 | +The MinGW/LLVM toolchain available on this machine ships **no** `libasan` / |
| 22 | +`libubsan`, so an AddressSanitizer/UBSan build is not possible natively (the plan |
| 23 | +anticipates this). The C unit/invariant suite (`build/c/test-runner`) was built |
| 24 | +with `SANITIZE=` and runs; the two red tests below are product-level integration |
| 25 | +tests that drive a real `codebase-memory-mcp.exe` over stdio. On a host where the |
| 26 | +toolchain provides sanitizers (Linux container, WSL), the same fixtures should be |
| 27 | +run through an ASan/UBSan binary via `scripts/test.sh`. |
| 28 | + |
| 29 | +## How to run |
| 30 | + |
| 31 | +```powershell |
| 32 | +# Builds build/c/codebase-memory-mcp.exe if missing, then runs the red suite. |
| 33 | +pwsh -File scripts/test-windows.ps1 |
| 34 | +# or, against an installed/relocated binary: |
| 35 | +pwsh -File scripts/test-windows.ps1 -Binary "C:\path\to\codebase-memory-mcp.exe" |
| 36 | +``` |
| 37 | + |
| 38 | +Each test exits `0` (green / invariant holds), `1` (red / Windows failure |
| 39 | +reproduced), or `2` (environment/setup error). Standard-library Python 3 only. |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +## windows_non_ascii_repo_path_preserves_definitions |
| 44 | + |
| 45 | +- Class: integration |
| 46 | +- Test: `tests/windows/test_non_ascii_path.py` |
| 47 | +- Related issues: #636, #357, #571 (naming), #530 |
| 48 | +- Environment: Windows 11 26200, PowerShell 5.1 / Python stdio, NTFS, CP 65001 |
| 49 | +- Fixture: byte-identical 2-file TypeScript repo (`src/math.ts`, `src/main.ts`), |
| 50 | + copied to an ASCII parent path and to four non-ASCII parent paths |
| 51 | + (Latin-1 accents `café`, Cyrillic `проект`, CJK `日本語`, Greek `Ωμέγα`) |
| 52 | +- Expected: each non-ASCII copy produces the same graph counts as the ASCII |
| 53 | + baseline (12 nodes / 20 edges / 5 definition nodes) |
| 54 | +- Actual: every non-ASCII copy produces **5 nodes / 4 edges / 0 definition |
| 55 | + nodes** — only `File`/`Folder` nodes; zero `Function`/`Class`/`Method` |
| 56 | +- Command: `python tests/windows/test_non_ascii_path.py build\c\codebase-memory-mcp.exe` |
| 57 | +- Minimal failure output: |
| 58 | + |
| 59 | + ``` |
| 60 | + baseline (ASCII): nodes=12 edges=20 definitions=5 |
| 61 | + [FAIL] non-ascii/latin1_accents nodes=5 edges=4 definitions=0 (baseline 12/20/5) |
| 62 | + [FAIL] non-ascii/cyrillic nodes=5 edges=4 definitions=0 (baseline 12/20/5) |
| 63 | + [FAIL] non-ascii/cjk nodes=5 edges=4 definitions=0 (baseline 12/20/5) |
| 64 | + [FAIL] non-ascii/greek nodes=5 edges=4 definitions=0 (baseline 12/20/5) |
| 65 | + ``` |
| 66 | + |
| 67 | +- Suspected implementation area: the per-pass source readers |
| 68 | + `read_file()` in `src/pipeline/pass_definitions.c`, `pass_calls.c`, |
| 69 | + `pass_parallel.c`, `pass_semantic.c` (and the `k8s`/`lsp_cross`/`pkgmap` |
| 70 | + variants) open files with plain `fopen(path, "rb")`. On Windows `fopen` |
| 71 | + interprets the UTF-8 path in the active **ANSI code page**, so a path with |
| 72 | + non-ASCII bytes cannot be opened and the tree-sitter parser receives no bytes. |
| 73 | + Directory discovery already uses the wide API |
| 74 | + (`cbm_utf8_to_wide` + `FindFirstFileW` in `src/foundation/compat_fs.c`, |
| 75 | + `src/foundation/platform.c`), which is why `File`/`Folder` nodes still appear |
| 76 | + while all definitions vanish. Fix direction: route the pass-level reads through |
| 77 | + the wide layer (`cbm_utf8_to_wide` + `_wfopen`), or add a shared |
| 78 | + UTF-8-aware file reader and use it from every pass. |
| 79 | + |
| 80 | +Verified with `_wfopen` vs `fopen` on a non-ASCII path: `fopen(utf8, "rb")` |
| 81 | +returns `NULL`, `_wfopen(cbm_utf8_to_wide(utf8), L"rb")` opens the same file. |
| 82 | + |
| 83 | +This invariant holds on Linux/macOS (byte-transparent UTF-8 filesystem); the test |
| 84 | +turns green once the pass readers convert to wide. |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## windows_cli_non_ascii_repo_path_is_honored |
| 89 | + |
| 90 | +- Class: integration |
| 91 | +- Test: `tests/windows/test_cli_non_ascii_arg.py` |
| 92 | +- Related issues: #636, #423, #20 |
| 93 | +- Environment: Windows 11 26200, `cli` argv path, NTFS, CP 65001 |
| 94 | +- Fixture: a TypeScript repo under a non-ASCII directory (`café_日本語_repo`), |
| 95 | + created with the OS wide API so it genuinely exists; an ASCII control repo |
| 96 | +- Expected: `codebase-memory-mcp cli index_repository '{"repo_path":"<non-ascii>"}'` |
| 97 | + indexes the directory (ASCII control proves the CLI path works) |
| 98 | +- Actual: the ASCII control indexes; the non-ASCII invocation fails with |
| 99 | + `repo_path is required` (the mangled, now-invalid-UTF-8 JSON argument is |
| 100 | + rejected) and exits non-zero |
| 101 | +- Command: `python tests/windows/test_cli_non_ascii_arg.py build\c\codebase-memory-mcp.exe` |
| 102 | +- Minimal failure output: |
| 103 | + |
| 104 | + ``` |
| 105 | + ASCII control: indexed OK |
| 106 | + non-ASCII argv: rc=1 |
| 107 | + stderr: ... repo_path is required |
| 108 | + ``` |
| 109 | + |
| 110 | +- Suspected implementation area: `int main(int argc, char **argv)` in |
| 111 | + `src/main.c` does not use `wmain` / `GetCommandLineW`, so on Windows the C |
| 112 | + runtime delivers `argv` in the ANSI code page. The non-ASCII bytes in the JSON |
| 113 | + argument are corrupted before `yyjson` parses them. Fix direction: read the |
| 114 | + wide command line on Windows (`GetCommandLineW` + `CommandLineToArgvW`, or a |
| 115 | + `wmain` entrypoint) and convert each argument to UTF-8. |
| 116 | + |
| 117 | +Real MCP clients pass `repo_path` inside a JSON-RPC message over stdio (which is |
| 118 | +byte-clean), so this affects the documented `cli` entrypoint and the hook/install |
| 119 | +flows that shell out to it, not the stdio server path. Holds on Linux/macOS |
| 120 | +(argv is UTF-8 bytes). |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +## Seed areas revisited and ruled out (green on native Windows) |
| 125 | + |
| 126 | +Each was reproduced as a concrete attempt against the production binary and |
| 127 | +behaved correctly — recorded as green and **not** included as a red test: |
| 128 | + |
| 129 | +| Area | Seed | Result on Windows | |
| 130 | +|---|---|---| |
| 131 | +| stdio `initialize` returns before stdin EOF | #513, #635 | green | |
| 132 | +| `tools/list` non-empty; all 14 tools return valid JSON-RPC | #530 | green | |
| 133 | +| Client exit terminates the server process (no residual `.exe`) | #185, #406 | green | |
| 134 | +| `--help` / `--version` exit 0 in PowerShell, cmd, Git Bash | — | green | |
| 135 | +| `search_code` works without bash/GNU grep (PowerShell `Select-String`) | #422, #348 | green | |
| 136 | +| `.gitignore` and `.cbmignore` honored | #274 | green | |
| 137 | +| `detect_changes` reports real changed files across commits | #371, #137 | green | |
| 138 | +| `query_graph` shapes (counts, paths, labels) — no crash/disconnect | #627 | green | |
| 139 | +| Paths with spaces, `&`, `()`, `[]`, `#`, `%`, `!`, apostrophe | #272 | green | |
| 140 | +| Mixed slash/backslash and lower-case drive letters | #133 | green | |
| 141 | +| Non-UTF-8 (CP949) source file emits valid UTF-8 JSON; no crash | #511 | green | |
| 142 | +| Re-index is idempotent (counts stable, single project) | #140 | green | |
| 143 | +| Index never escapes the selected root | #331 | green | |
| 144 | +| Every JSON-RPC response decodes as strict UTF-8 | invariant | green | |
| 145 | + |
| 146 | +## Observed but intentionally out of scope for this PR |
| 147 | + |
| 148 | +- **Project-name collision for non-ASCII paths (#571/#20).** Two distinct repos |
| 149 | + (`проект`, `日本語`) under the same parent derive the *same* project name, |
| 150 | + because `cbm_project_name_from_path` (`src/pipeline/fqn.c`) maps every |
| 151 | + non-`[A-Za-z0-9._-]` byte to `-` and then trims. This is a real bug but it is |
| 152 | + **not Windows-specific** — `cbm_project_name_from_path` is platform-independent |
| 153 | + and collides identically on Linux. Per the campaign rules it is recorded here |
| 154 | + and left for a cross-platform PR. |
| 155 | +- **Paths longer than 260 characters.** This machine has |
| 156 | + `HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled = 0`, so |
| 157 | + paths over `MAX_PATH` are unreachable by every application, not just CBM. |
| 158 | + CBM could opt in via the `\\?\` prefix + wide APIs, but the failure is gated by |
| 159 | + a machine-wide policy rather than a clean CBM-only defect, so it is excluded. |
| 160 | +- **C `test-runner` failures on Windows.** The in-process C suite reports many |
| 161 | + extraction-count failures concentrated in `test_grammar_probe_*`, |
| 162 | + `test_node_creation_probe`, `test_edge_*`, `test_matrix_*`, and |
| 163 | + `test_integration.c` (e.g. `integ_index_has_files` finds 0 files even for an |
| 164 | + **ASCII** fixture). The production binary indexes those same ASCII/CRLF cases |
| 165 | + correctly (CRLF vs LF source files were verified to extract identically), so |
| 166 | + these look like in-process test-harness issues rather than user-facing product |
| 167 | + regressions. Distinguishing genuine Windows-only product regressions from |
| 168 | + fixture/harness sensitivity requires a Linux baseline of the same commit and is |
| 169 | + left as a follow-up; they are deliberately **not** converted into red tests |
| 170 | + here to avoid shipping undiagnosed assertions. |
| 171 | + |
| 172 | +## Stop-condition coverage |
| 173 | + |
| 174 | +- Shells/launchers covered: PowerShell 5.1, `cmd.exe`, Git Bash, direct Win32, |
| 175 | + Python `subprocess`, Python stdio JSON-RPC (>= 3 required). |
| 176 | +- Classes covered in the green streak: smoke, integration, unit (the passing |
| 177 | + `build/c/test-runner` cases), invariant. |
| 178 | +- Seed areas (Unicode paths, mapped-drive/UNC, stdio, `search_code`, |
| 179 | + install/update, watcher/ignore, query, memory/process lifecycle) were each |
| 180 | + revisited or explicitly ruled out above. |
0 commit comments