Skip to content

fix(scanner): repair SD022 compile error breaking estate-wide Hypatia scan - #553

Merged
hyperpolymath merged 1 commit into
mainfrom
claude/charming-curie-bi2cd5
Jun 27, 2026
Merged

fix(scanner): repair SD022 compile error breaking estate-wide Hypatia scan#553
hyperpolymath merged 1 commit into
mainfrom
claude/charming-curie-bi2cd5

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Problem — main does not compile, so every repo's scan is red

The Hypatia reusable workflow git clones this repo and runs mix escript.build before scanning. As of #545 (7df53b1b), main fails to build:

== Compilation error in file lib/rules/structural_drift.ex ==
** (CompileError) undefined function real_subdirs/0

So scan / Hypatia Neurosymbolic Analysis dies at "Build Hypatia scanner" on every consumer repo in the estate (surfaced while verifying #464 — the cache pin is fine, this is the real blocker).

Root cause

#545 rewrote sd022_stale_path_after_rename/1 and renamed the binding real_subdirsreal_basenames (now produced by src_dir_index/1), but left a dangling real_subdirs reference in the final Enum.reject. Two further latent defects from the same half-finished refactor:

  1. The regex uses a negative lookbehind with one capture group, but the pipeline destructured [_, prefix, dir] (two groups) and called real_path_reference?/4 — a FunctionClauseError waiting to fire once the compile error was cleared.
  2. src_dir_index/1 switched to git ls-files, which cannot see an empty src/<dir> directory — so the early-return guard would wrongly short-circuit (this is exactly what the existing test "flags docs referencing src/<dir>/…" sets up).

Fix (minimal, behaviour-preserving)

  • real_subdirsreal_basenames in the final reject.
  • Collapse the vestigial 2-group prefix path to [_, dir] and remove the now-unused real_path_reference?/4 + foreign_prefix?/2 (the lookbehind already excludes prefixed/foreign refs, so they were dead).
  • Guard now also checks File.dir?(repo/src) so an empty src/<dir> still counts.

Net diff: +4 / −25 in one file.

Verification

Ran the real suite locally (Elixir 1.14 / OTP 25):

mix test test/structural_drift_test.exs
32 tests, 0 failures

(All four sd022_* tests pass, plus elixirc compiles the module clean — reproduced the original CompileError first, confirmed it's gone after.)

Once main compiles again, the estate-wide scan lane unblocks. Closes the scan-side of #464.


Drafted by Claude Code; please run mix test / mix escript.build in CI before merge.


Generated by Claude Code

#545's rewrite of sd022_stale_path_after_rename/1 left a dangling
`real_subdirs` after the binding was renamed to `real_basenames`
(src_dir_index/1). `mix escript.build` fails with
"undefined function real_subdirs/0", which breaks the Hypatia scan job
estate-wide — the reusable workflow clones hypatia and builds the
escript before scanning, so every consumer repo's scan dies at build.

Fixes:
- real_subdirs -> real_basenames in the final reject.
- The lookbehind regex has one capture group, so the 2-group
  `[_, prefix, dir]` destructure could never match (FunctionClauseError
  after the compile error was resolved); reduced to `[_, dir]` and
  removed the now-unused real_path_reference?/4 + foreign_prefix?/2
  (the negative lookbehind already excludes prefixed/foreign refs).
- Guard also checks File.dir?(repo/src) so an empty `src/<dir>`
  directory still counts (git ls-files cannot see empty dirs).

Verified locally: mix test test/structural_drift_test.exs -> 32 tests,
0 failures; module compiles via elixirc.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012JvDqQCW4CHxkEBAoJV5FU
@hyperpolymath
hyperpolymath marked this pull request as ready for review June 27, 2026 10:05
@hyperpolymath
hyperpolymath merged commit c90f745 into main Jun 27, 2026
35 of 37 checks passed
@hyperpolymath
hyperpolymath deleted the claude/charming-curie-bi2cd5 branch June 27, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants