Sdlc/Structural/ExecutableLoadedInTest: match the lesson's shape (tests only) and carve out guarded scripts #1352

Open
opened 2026-10-25 21:22:36 +00:00 by jared · 0 comments
Owner

Problem

The cop Sdlc/Structural/ExecutableLoadedInTest matches any load/require/require_relative of a bin/ path in any file.
The lesson signal says "A test file", but the matcher has no test-file check.
It also flags scripts that guard their top level, where the lesson's argv/exit hazard does not exist.

Found by the #1325 zero-false-positive audit (docs/plans/class-length-family/sdlc-cop-audit.md).

Observed

The only hit is plugins/os-context/eval/bin/check:7. It is not a test. It loads plugins/os-context/audit/bin/extract, whose top level is guarded by if $PROGRAM_NAME == __FILE__ (extract:428).
The prescribed fix (move behavior to lib/) is not needed for a guarded script.

Reproduce

n/a: matcher is plugins/os-sdlc/lib/os_sdlc/cops/executable_loaded_in_test/resolved_path.rb:9-18; run the cop on plugins/os-context/eval/bin/check.

Approach

Carve-outs go in the cop matcher, never in a config Exclude list or a test-path exclusion.
Restrict the cop to test files by shape (the file defines a Minitest::Test subclass), or rewrite the lesson and message to cover any loader.
Skip a load of a script whose top level is wrapped in if $PROGRAM_NAME == __FILE__ or __FILE__ == $0.

Required work:

  1. Add the guarded-script carve-out — check: present PROGRAM_NAME in plugins/os-sdlc/lib/os_sdlc/cops/executable_loaded_in_test/*.rb

Acceptance criteria

  1. Given a non-test file that loads a bin/ script, when the cop runs, then it reports no offense.
  2. Given a test file that loads a bin/ script with an unguarded top level, when the cop runs, then it reports an offense.
  3. Given a test file that loads a script guarded by $PROGRAM_NAME == __FILE__, when the cop runs, then it reports no offense.

Origin

  • Trigger: #1325 zero-false-positive audit of the Sdlc cops
  • Improvised this session: none
  • Chain: false positive ← matcher lacks test-file and guard checks ← DESIGN (plugins/os-sdlc/lib/os_sdlc/cops/executable_loaded_in_test.rb)
  • Root candidate: none found; searched ExecutableLoadedInTest
  • Where: plugins/os-sdlc/lib/os_sdlc/cops/executable_loaded_in_test/resolved_path.rb
  • Session: eb98cdcd-6783-46a0-b7df-cf18a8fe2a56
  • Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os--claude-worktrees-ticket-1325/eb98cdcd-6783-46a0-b7df-cf18a8fe2a56.jsonl
    VERDICT: CREATE
## Problem The cop `Sdlc/Structural/ExecutableLoadedInTest` matches any `load`/`require`/`require_relative` of a `bin/` path in any file. The lesson signal says "A test file", but the matcher has no test-file check. It also flags scripts that guard their top level, where the lesson's argv/exit hazard does not exist. Found by the #1325 zero-false-positive audit (docs/plans/class-length-family/sdlc-cop-audit.md). ## Observed The only hit is `plugins/os-context/eval/bin/check:7`. It is not a test. It loads `plugins/os-context/audit/bin/extract`, whose top level is guarded by `if $PROGRAM_NAME == __FILE__` (`extract:428`). The prescribed fix (move behavior to lib/) is not needed for a guarded script. ## Reproduce n/a: matcher is `plugins/os-sdlc/lib/os_sdlc/cops/executable_loaded_in_test/resolved_path.rb:9-18`; run the cop on `plugins/os-context/eval/bin/check`. ## Approach Carve-outs go in the cop matcher, never in a config Exclude list or a test-path exclusion. Restrict the cop to test files by shape (the file defines a `Minitest::Test` subclass), or rewrite the lesson and message to cover any loader. Skip a load of a script whose top level is wrapped in `if $PROGRAM_NAME == __FILE__` or `__FILE__ == $0`. Required work: 1. Add the guarded-script carve-out — check: present `PROGRAM_NAME` in `plugins/os-sdlc/lib/os_sdlc/cops/executable_loaded_in_test/*.rb` ## Acceptance criteria 1. Given a non-test file that loads a `bin/` script, when the cop runs, then it reports no offense. 2. Given a test file that loads a `bin/` script with an unguarded top level, when the cop runs, then it reports an offense. 3. Given a test file that loads a script guarded by `$PROGRAM_NAME == __FILE__`, when the cop runs, then it reports no offense. ## Origin - Trigger: #1325 zero-false-positive audit of the Sdlc cops - Improvised this session: none - Chain: false positive ← matcher lacks test-file and guard checks ← DESIGN (plugins/os-sdlc/lib/os_sdlc/cops/executable_loaded_in_test.rb) - Root candidate: none found; searched ExecutableLoadedInTest - Where: plugins/os-sdlc/lib/os_sdlc/cops/executable_loaded_in_test/resolved_path.rb - Session: eb98cdcd-6783-46a0-b7df-cf18a8fe2a56 - Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os--claude-worktrees-ticket-1325/eb98cdcd-6783-46a0-b7df-cf18a8fe2a56.jsonl VERDICT: CREATE
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jared/cc-os#1352
No description provided.