Repository navigation
Commit 880b993
committed
fix(runtime): search the whole rule for stray modules, not two directories
`strayModules` listed the immediate entries of the rule root and `captures/`
and nothing else, so any nested directory evaded it completely. Create
`<rule>/lib/helper.ts`, have `check.ts` import it, and the rule discovered
as clean while unsigned code ran and `check.ts` still matched its blessed
signature.
The threat model was stated correctly and implemented as something narrower.
"One import away" is not "one directory away": `import "./lib/helper.ts"`
reaches an arbitrarily deep relative path in a single hop, exactly like
`import "./helper.ts"`. Bounding the search to two directories left the hole
this slice exists to close, in the slice that closes it.
Now walks the whole rule directory, excluding `.tests/` at any depth for the
reason already documented: fixtures are data a check reads, and a fixture
that is itself TypeScript is the normal case.
Also considers only files. `readdir` returns directories too, so a directory
named `helper.ts` would have been reported as a stray module — a false
positive refusing a fine rule with an error naming something that cannot
run. `withFileTypes` plus `isFile()` was needed for the recursion anyway.
An unreadable directory now propagates instead of being swallowed, matching
`isMissingDirectory`'s contract: reading `EACCES` as "nothing here" would
make an unsearchable rule indistinguishable from a clean one, which is the
same failure this whole guard exists to prevent.
Four new cases cover the gap — `lib/helper.ts`, `captures/nested/helper.js`,
`a/b/c/deep.mjs`, and a directory named `helper.ts`. Reverting the recursion
fails exactly those and leaves the three root-level cases passing, so they
detect the gap rather than the guard's existence.
Found by the review on #217.1 parent b0ca3cd commit 880b993
4 files changed
Lines changed: 80 additions & 17 deletions
File tree
- .changeset
- openspec/changes/generator-payload-alignment/specs/cli-runtime-rule-execution
- packages/cli
- src/rules/runtime
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
73 | | - | |
74 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
59 | 65 | | |
60 | 66 | | |
61 | 67 | | |
62 | 68 | | |
63 | 69 | | |
64 | 70 | | |
65 | 71 | | |
66 | | - | |
| 72 | + | |
67 | 73 | | |
68 | 74 | | |
69 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | | - | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
89 | 95 | | |
90 | | - | |
91 | | - | |
92 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
93 | 103 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
98 | 122 | | |
99 | 123 | | |
100 | 124 | | |
| 125 | + | |
| 126 | + | |
101 | 127 | | |
102 | 128 | | |
103 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
440 | 440 | | |
441 | 441 | | |
442 | 442 | | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
443 | 448 | | |
444 | 449 | | |
445 | 450 | | |
| |||
455 | 460 | | |
456 | 461 | | |
457 | 462 | | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
458 | 469 | | |
459 | 470 | | |
460 | 471 | | |
| |||
470 | 481 | | |
471 | 482 | | |
472 | 483 | | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
473 | 501 | | |
474 | 502 | | |
475 | 503 | | |
| |||
484 | 512 | | |
485 | 513 | | |
486 | 514 | | |
| 515 | + | |
487 | 516 | | |
488 | | - | |
| 517 | + | |
489 | 518 | | |
490 | 519 | | |
491 | 520 | | |
| |||
0 commit comments