Sdlc/Structural/CollaboratorConstructionInInitialize: carve out parameter-built parts and value types #1348

Closed
opened 2026-10-25 21:20:05 +00:00 by jared · 2 comments
Owner

Problem

Sdlc/Structural/CollaboratorConstructionInInitialize flags def initialize bodies with 2 or more Const.new sends. The cop cannot see whether tests have a seam, so it flags code that is correct.
Counterexamples:

  1. A composition root that no test needs to change. The lesson itself calls this a false positive.
  2. Parts built only from initialize parameters: plugins/os-adr/lib/adr/record/challenge.rb:12-13 builds Gate and Deletion from the injected judge: and repository:; plugins/os-backlog/lib/backlog/checkout.rb:9-10 is the same. The parameters are the seam.
  3. Value or stdlib types outside the cop's list: Pathname, Mutex, StringIO, and raise Error.new.

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

Approach

Carve out by shape in the cop matcher (plugins/os-sdlc/lib/os_sdlc/cops/collaborator_construction_in_initialize.rb), never by config Exclude. Skip .new calls whose every argument is an initialize parameter, an ivar copy of one, or a literal. Skip value/stdlib and exception receivers. Drop the "report it to the human" text from the lint lesson.

Required work:

  1. Remove the report-to-human text — check: absent Report it to the human in plugins/os-sdlc/lint-lessons/sdlc-structural-collaborator-construction-in-initialize.yml

Acceptance criteria

  1. Given each counterexample under Problem, when the cop runs, then it reports no offense.
  2. Given the true-positive shape the cop targets, when the cop runs, then it still reports an offense.
  3. Given the repo, when rubocop runs, then no Exclude list or test-path exclusion carries the carve-out.

Owner sketch

The carve-out lives in the cop matcher.

Origin

  • Trigger: the #1325 zero-false-positive audit of the Sdlc cops
  • Improvised this session: none
  • Chain: false positive on valid code <- cop matcher too broad <- DESIGN (cop source: plugins/os-sdlc/lib/os_sdlc/cops/collaborator_construction_in_initialize.rb)
  • Root candidate: none found; searched CollaboratorConstructionInInitialize, composition root, construction in initialize, carve
  • Where: plugins/os-sdlc/lib/os_sdlc/cops/collaborator_construction_in_initialize.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 `Sdlc/Structural/CollaboratorConstructionInInitialize` flags `def initialize` bodies with 2 or more `Const.new` sends. The cop cannot see whether tests have a seam, so it flags code that is correct. Counterexamples: 1. A composition root that no test needs to change. The lesson itself calls this a false positive. 2. Parts built only from initialize parameters: plugins/os-adr/lib/adr/record/challenge.rb:12-13 builds Gate and Deletion from the injected `judge:` and `repository:`; plugins/os-backlog/lib/backlog/checkout.rb:9-10 is the same. The parameters are the seam. 3. Value or stdlib types outside the cop's list: Pathname, Mutex, StringIO, and `raise Error.new`. Found by the #1325 zero-false-positive audit (docs/plans/class-length-family/sdlc-cop-audit.md). ## Approach Carve out by shape in the cop matcher (plugins/os-sdlc/lib/os_sdlc/cops/collaborator_construction_in_initialize.rb), never by config `Exclude`. Skip `.new` calls whose every argument is an initialize parameter, an ivar copy of one, or a literal. Skip value/stdlib and exception receivers. Drop the "report it to the human" text from the lint lesson. Required work: 1. Remove the report-to-human text — check: absent `Report it to the human` in `plugins/os-sdlc/lint-lessons/sdlc-structural-collaborator-construction-in-initialize.yml` ## Acceptance criteria 1. Given each counterexample under Problem, when the cop runs, then it reports no offense. 2. Given the true-positive shape the cop targets, when the cop runs, then it still reports an offense. 3. Given the repo, when rubocop runs, then no `Exclude` list or test-path exclusion carries the carve-out. ## Owner sketch The carve-out lives in the cop matcher. ## Origin - Trigger: the #1325 zero-false-positive audit of the Sdlc cops - Improvised this session: none - Chain: false positive on valid code <- cop matcher too broad <- DESIGN (cop source: plugins/os-sdlc/lib/os_sdlc/cops/collaborator_construction_in_initialize.rb) - Root candidate: none found; searched CollaboratorConstructionInInitialize, composition root, construction in initialize, carve - Where: plugins/os-sdlc/lib/os_sdlc/cops/collaborator_construction_in_initialize.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
Author
Owner

Work started on branch ticket-1348 via /os-sdlc:implement.

Work started on branch ticket-1348 via /os-sdlc:implement.
Author
Owner

Resolution

Done: CollaboratorConstructionInInitialize no longer flags parts built from initialize parameters or value types (carve-out per the ticket's acceptance criteria).

Evidence: Implementation 211 commit (HEAD of ticket-1348): cop collaborator_construction_in_initialize.rb plus tests in plugins/os-sdlc/tests/cops/collaborator_construction_in_initialize_test.rb; full suite green; contract-auditor pass.

Follow-ups: none

## Resolution **Done:** CollaboratorConstructionInInitialize no longer flags parts built from initialize parameters or value types (carve-out per the ticket's acceptance criteria). **Evidence:** Implementation 211 commit (HEAD of ticket-1348): cop collaborator_construction_in_initialize.rb plus tests in plugins/os-sdlc/tests/cops/collaborator_construction_in_initialize_test.rb; full suite green; contract-auditor pass. **Follow-ups:** none
jared closed this issue 2026-10-28 13:58:26 +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#1348
No description provided.