Skip to content

Extract CSMA library to scripts/lib/ to eliminate duplication #70

Description

@fullsend-ai-retro

What happened

In PR #35, the CSMA rate-limit resilience library (~300 lines) was inlined into scripts/post-prioritize.sh (lines 15–332). The same library was also inlined into scripts/post-prioritize-test.sh (lines 269–586) for unit testing. The comment # --- Inlined from lib/github-api-csma.sh --- indicates this code originally lived in a shared lib/ directory, but no such directory exists in the repo today.

What could go better

The library is now copy-pasted in two files (script and test), totaling ~600 duplicated lines. Any bug fix, new retry pattern, or behavioral change to the CSMA logic requires updating both copies in lockstep. If additional scripts adopt CSMA (see related proposal), the duplication would compound further. The risk is moderate — the library is stable by nature (retry logic rarely changes) — but the current pattern also forces the test file to inline the library separately rather than testing the canonical copy, which weakens the test's coverage guarantee. Confidence: medium-high. The duplication is factual; the maintenance risk is a judgment call informed by the codebase's growth trajectory.

Proposed change

Create scripts/lib/github-api-csma.sh containing the canonical CSMA library. Update post-prioritize.sh to source "${SCRIPT_DIR}/lib/github-api-csma.sh" instead of inlining. The test file should also source the canonical copy for its unit tests, ensuring it tests the actual production code. The post-scripts run on the GitHub Actions runner (not in the sandbox), so source is reliable. The include-guard (GITHUB_API_CSMA_SH_LOADED) already exists in the inlined code, so multiple source calls are safe.

Validation criteria

After extraction: (1) scripts/lib/github-api-csma.sh exists as a single file. (2) post-prioritize.sh no longer contains the inlined CSMA block — it sources the lib. (3) post-prioritize-test.sh sources the same lib and all 6 existing tests (happy-path, rate-limit-retry, auth-error, exhausted-retries, exit0-rate-limit-retry, exit0-rate-limit-exhausted) continue to pass. (4) No other file in the repo contains a duplicate copy of the CSMA functions.


Generated by retro agent from #35

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions