inward_dependency_test counts constants inside comments and string literals #744

Closed
opened 2026-09-26 14:43:20 +00:00 by jared · 2 comments
Owner

Problem

plugins/os-sdlc/tests/inward_dependency_test.rb finds referenced constants with a regex scan of File.read raw text. Commit c78dd226 fixed qualified-constant resolution through the Zeitwerk cpath map, but the regex still matches constant-shaped text inside comments and string literals, so the baseline it records can count references that are not real code dependencies.

Approach

Replace the regex scan with a tokenizer (Ripper or Prism) that yields only constant-path tokens, and drop any token whose source position falls inside a comment or a string literal. Re-run the scanner and re-record KNOWN_VIOLATIONS, which stands at 75 today.

Required work:

  1. Replace the regex-based referenced_constants with a Ripper- or Prism-based tokenizer that walks constant-path nodes.
  2. Exclude tokens inside comments and string literals from the returned constant list.
  3. Re-run the scanner against the current tree and update KNOWN_VIOLATIONS from 75 to the new count — check: bin/rake test TEST=plugins/os-sdlc/tests/inward_dependency_test.rb (or the project's equivalent runner).

Rejected: patching the regex with more exclusion patterns — a tokenizer is the direct fix for "is this token code," a regex is an approximation of it.

Acceptance criteria

  1. Given a file with a constant name inside a comment, when referenced_constants scans it, then that occurrence is not counted.
  2. Given a file with a constant name inside a string literal, when referenced_constants scans it, then that occurrence is not counted.
  3. Given a file with a genuine constant-path reference in code, when referenced_constants scans it, then that occurrence is still counted.
  4. Given the corrected scan, when run against the current tree, then KNOWN_VIOLATIONS is re-recorded to match the new count.

Owner sketch

class InwardDependencyTest
  def referenced_constants(source)
  end
end

Origin

  • Trigger: user review of inward_dependency_test.rb after commit c78dd226 (#741), 2026-09-26.
  • Improvised this session: none.
  • Chain: KNOWN_VIOLATIONS can include false positives ← referenced_constants regex-scans raw file text instead of tokenizing it ← IMPROVISATION, the regex scan predates the Zeitwerk cpath fix and was never revisited for comment/string false positives.
  • Root candidate: this ticket.
  • Where: plugins/os-sdlc/tests/inward_dependency_test.rb
  • Session: d0c72a0b-34c7-4dae-bf3b-7400ef21ad4a
  • Transcript: not available in this invocation
## Problem plugins/os-sdlc/tests/inward_dependency_test.rb finds referenced constants with a regex scan of `File.read` raw text. Commit c78dd226 fixed qualified-constant resolution through the Zeitwerk cpath map, but the regex still matches constant-shaped text inside comments and string literals, so the baseline it records can count references that are not real code dependencies. ## Approach Replace the regex scan with a tokenizer (Ripper or Prism) that yields only constant-path tokens, and drop any token whose source position falls inside a comment or a string literal. Re-run the scanner and re-record KNOWN_VIOLATIONS, which stands at 75 today. Required work: 1. Replace the regex-based `referenced_constants` with a Ripper- or Prism-based tokenizer that walks constant-path nodes. 2. Exclude tokens inside comments and string literals from the returned constant list. 3. Re-run the scanner against the current tree and update KNOWN_VIOLATIONS from 75 to the new count — check: `bin/rake test TEST=plugins/os-sdlc/tests/inward_dependency_test.rb` (or the project's equivalent runner). Rejected: patching the regex with more exclusion patterns — a tokenizer is the direct fix for "is this token code," a regex is an approximation of it. ## Acceptance criteria 1. Given a file with a constant name inside a comment, when `referenced_constants` scans it, then that occurrence is not counted. 2. Given a file with a constant name inside a string literal, when `referenced_constants` scans it, then that occurrence is not counted. 3. Given a file with a genuine constant-path reference in code, when `referenced_constants` scans it, then that occurrence is still counted. 4. Given the corrected scan, when run against the current tree, then KNOWN_VIOLATIONS is re-recorded to match the new count. ## Owner sketch ```ruby class InwardDependencyTest def referenced_constants(source) end end ``` ## Origin - Trigger: user review of inward_dependency_test.rb after commit c78dd226 (#741), 2026-09-26. - Improvised this session: none. - Chain: KNOWN_VIOLATIONS can include false positives ← referenced_constants regex-scans raw file text instead of tokenizing it ← IMPROVISATION, the regex scan predates the Zeitwerk cpath fix and was never revisited for comment/string false positives. - Root candidate: this ticket. - Where: plugins/os-sdlc/tests/inward_dependency_test.rb - Session: d0c72a0b-34c7-4dae-bf3b-7400ef21ad4a - Transcript: not available in this invocation
Author
Owner

Started on branch crc-pass-os-sdlc.

Started on branch crc-pass-os-sdlc.
Author
Owner

Resolution

Done: Tokenized inward-dependency scanner with Prism so constants inside comments and string literals no longer count as references; baseline dropped 75 -> 73.

Evidence: commit fd59331c; suite 1430 runs, 3252 assertions, 0 failures, 0 errors, 10 skips

Follow-ups: none

## Resolution **Done:** Tokenized inward-dependency scanner with Prism so constants inside comments and string literals no longer count as references; baseline dropped 75 -> 73. **Evidence:** commit fd59331c; suite 1430 runs, 3252 assertions, 0 failures, 0 errors, 10 skips **Follow-ups:** none
jared closed this issue 2026-09-26 14:47:36 +00:00
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#744
No description provided.