Commit 09e92de
authored
fix(res-to-affine): report the effective engine and fail on degraded output (#730)
Fixes #729.
When the tree-sitter walker cannot start, the tool falls back to the
Phase-1 regex scanner, warns on stderr — and then **reports the
requested engine and exits 0**:
```
res-to-affine: 0 findings, 0 translated [walker] → Model.affine
$ echo $?
0
```
It says `[walker]`. **The scanner produced that file.** Nothing in the
exit code or the summary distinguishes it from a real port, so a sweep
over hundreds of files logs success for every one.
## The consequence, measured
`metadatastician/stapeln` migrated its entire frontend this way:
```
47 .affine files, 20,995 lines
19,203 (91.5%) retained ReScript inside /* ORIGINAL RESCRIPT */ blocks
1,792 ( 8.5%) real AffineScript
0 function declarations, across ALL 47 files
```
Every file reported success. Every file contains **zero functions**.
That repo isn't 8.5% migrated by intent — it's 8.5% migrated **by
accident**. The campaign covers ~3,996 files across ~80 repos.
## Why it's so easy to hit
- **`tools/vendor/` is gitignored by design** (`.gitignore:92`), so the
grammar is absent on every clean clone.
- **The default grammar path resolves relative to the current
directory**, so running the tool from the repo you're migrating — the
natural thing to do — misses a grammar that *is* installed.
That second one caught me: the grammar was installed and it still fell
back, because I invoked it from `stapeln/frontend/src`.
## This change
- Tracks whether the walker was asked for but couldn't run.
- **Reports the effective engine** — `[scanner (DEGRADED)]` rather than
`[walker]`. The summary line no longer states something untrue.
- **Exits 3** on degraded output, with a message naming both causes
above.
- Adds `--allow-scanner-fallback` for callers who genuinely want a
declarations-only skeleton.
- Also marks `--engine=scanner` + `--translate`/`--partial` as degraded
— it already warned no translation would be emitted, but still exited 0,
and an unusable output is unusable whatever the intent.
**Deliberately not changed:** the default grammar path stays
CWD-relative. Making it binary- or repo-root-relative is the better fix,
but it changes behaviour for existing callers, so it belongs in its own
change. The new error message names the trap in the meantime.
## Verified — all four paths, same input (`stapeln/Model.res`)
| Invocation | Exit | Label | Functions |
|---|---|---|---|
| degraded | **3** | `[scanner (DEGRADED)]` | 0 |
| degraded + `--allow-scanner-fallback` | **0** | — | 0 |
| healthy (walker, grammar present) | **0** | `[walker]` | **8** |
The 8-vs-0 is the whole point: identical invocation, identical input,
and the only difference is whether the walker could load.
Built with dune 3.17.2 / OCaml 5.3.0. Note `dune build` alone fails on
`js/playground.bc.js` for want of `js_of_ocaml`; `dune build
tools/res-to-affine/main.exe` is clean.
🤖 Generated with [Claude Code](https://claude.com/claude-code)1 parent 838f804 commit 09e92de
1 file changed
Lines changed: 55 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
43 | 49 | | |
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
47 | 53 | | |
48 | 54 | | |
49 | 55 | | |
| 56 | + | |
50 | 57 | | |
51 | 58 | | |
52 | 59 | | |
| |||
62 | 69 | | |
63 | 70 | | |
64 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
65 | 76 | | |
66 | 77 | | |
67 | 78 | | |
| |||
72 | 83 | | |
73 | 84 | | |
74 | 85 | | |
| 86 | + | |
75 | 87 | | |
76 | 88 | | |
77 | 89 | | |
| |||
88 | 100 | | |
89 | 101 | | |
90 | 102 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
103 | 135 | | |
104 | 136 | | |
105 | 137 | | |
| |||
159 | 191 | | |
160 | 192 | | |
161 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
162 | 203 | | |
163 | 204 | | |
164 | 205 | | |
165 | 206 | | |
166 | 207 | | |
167 | 208 | | |
168 | | - | |
| 209 | + | |
169 | 210 | | |
170 | 211 | | |
171 | 212 | | |
| |||
0 commit comments