Skip to content

feat: add refactoring baseline audit - #841

Merged
keito4 merged 3 commits into
mainfrom
fix/issue-812-refactoring-baseline
Jun 17, 2026
Merged

feat: add refactoring baseline audit#841
keito4 merged 3 commits into
mainfrom
fix/issue-812-refactoring-baseline

Conversation

@keito4

@keito4 keito4 commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #812.

  • Add .context/refactoring-baseline.md with the phase-0 baseline metrics for CI status, tracked LOC/file count, and Jest coverage.
  • Add script/audit-references.sh to scan tracked script/ and templates/ files and classify references as code/ci, test, or docs.
  • Add BATS coverage for the audit script and register it in the core script existence checks.

Issue #812 checklist

Tests

  • script/audit-references.sh --format tsv
  • npx bats test/integration/audit_references.bats test/integration/core-scripts.bats
  • shellcheck -x script/audit-references.sh
  • npm run format:check
  • npm run lint
  • npm test
  • npm run shellcheck
  • npm run test:integration
  • bash script/update-agents-md.sh --check
  • npm run test:coverage

Summary by CodeRabbit

  • Chores

    • Added a reference audit utility script for inventorying codebase references across script/ and templates/ directories with Markdown and TSV output formats.
    • Established a refactoring baseline snapshot documenting repository metrics, CI status, and test coverage for Issue #812.
  • Tests

    • Added integration tests to validate reference audit script functionality and verify script permissions.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds script/audit-references.sh, a Bash script that scans script/ and templates/ targets across all tracked repository files, classifies references into code/ci, test, or docs categories, and outputs Markdown or TSV reports. Bats integration tests validate TSV rows and Markdown headings. A baseline snapshot document records CI status, LOC, and Jest coverage metrics.

Changes

Phase 0: Refactoring Baseline and Reference Inventory

Layer / File(s) Summary
audit-references.sh: arg parsing, helpers, main loop, and summary
script/audit-references.sh
Strict Bash script with --format markdown|tsv argument parsing; helper functions for source classification (test/docs/code/ci), target enumeration, TSV/Markdown formatting, and rg/grep-based reference search; main scan loop emitting per-target Markdown sections or TSV rows; and a trailing zero-reference summary section in Markdown mode.
Bats integration tests
test/integration/audit_references.bats, test/integration/core-scripts.bats
Adds assert_tsv_row helper and two tests in audit_references.bats covering TSV-mode row assertions and Markdown-mode heading presence. Adds one test in core-scripts.bats asserting the script exists and is executable.
Refactoring baseline snapshot
.context/refactoring-baseline.md
Documents CI run metadata, tracked file count, total LOC, Jest coverage figures (statements/branches/functions/lines), audit-references.sh usage example, and the phase issue checklist (#812#819).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • keito4/config#552: Modifies test/integration/core-scripts.bats with the same pattern of adding a script existence/executability check, directly parallel to the audit-references.sh check added in this PR.

Suggested labels

released

🐇 A script hops through scripts and templates with glee,
Sniffing out references — "Who mentions me?"
It tallies up code refs, tests, and docs too,
Then writes them in Markdown (or TSV will do)!
The baseline is captured, the phases are set —
Phase Zero complete, and no regressions yet! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add refactoring baseline audit' clearly summarizes the main change: adding baseline metrics and audit capabilities for a refactoring initiative.
Description check ✅ Passed The PR description covers all required template sections with detailed information about changes, includes Issue #812 checklist completion, testing instructions, and related issue reference.
Linked Issues check ✅ Passed All three coding requirements from Issue #812 are met: baseline metrics recorded in .context/refactoring-baseline.md (0-1), audit-references.sh created with code/test/docs reference classification (0-2), and phase issues #812-#819 confirmed to exist (0-3).
Out of Scope Changes check ✅ Passed All changes are directly aligned with Issue #812 objectives: baseline documentation, reference audit script, and corresponding test coverage. No out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-812-refactoring-baseline

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude

claude Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Claude finished @keito4's task in 0s —— View job


I'll analyze this and get back to you.

@keito4 keito4 self-assigned this Jun 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f66813c7f3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +70 to +72
git ls-files 'script/*' 'templates/*' | while IFS= read -r file; do
[ -f "$file" ] || continue
printf '%s\n' "$file"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve audit paths from the repo root

When this script is invoked from any subdirectory (for example, cd script && ../script/audit-references.sh --format tsv), git ls-files still emits repo-relative paths such as script/foo.sh, but this check treats them as relative to the current subdirectory and skips every target; the command then exits successfully with only the TSV header. Please cd to git rev-parse --show-toplevel or prefix these paths with the repo root before filtering/scanning.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@script/audit-references.sh`:
- Around line 23-26: The --format case handler in the script unconditionally
executes shift 2 without validating that a value was actually provided for the
FORMAT flag, causing a shell error instead of controlled failure. Add an
explicit check after the FORMAT assignment to verify that the value is not empty
(i.e., that a second argument exists), and if the check fails, print a usage
message and exit with status 2 before executing the shift statement.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 15f662a8-360e-47d4-9828-305eb5ba6232

📥 Commits

Reviewing files that changed from the base of the PR and between 00f0fe9 and 2be563a.

📒 Files selected for processing (4)
  • .context/refactoring-baseline.md
  • script/audit-references.sh
  • test/integration/audit_references.bats
  • test/integration/core-scripts.bats

Comment on lines +23 to +26
--format)
FORMAT="${2:-}"
shift 2
;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Handle missing --format value before shifting arguments.

shift 2 is unconditional, so script/audit-references.sh --format exits via shell error instead of your controlled validation path. Add an explicit arity check and fail with usage/status 2.

Proposed fix
   case "$1" in
     --format)
+      if [ "$#" -lt 2 ] || [ -z "${2:-}" ]; then
+        echo "Missing value for --format (expected: markdown|tsv)" >&2
+        usage >&2
+        exit 2
+      fi
       FORMAT="${2:-}"
       shift 2
       ;;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
--format)
FORMAT="${2:-}"
shift 2
;;
--format)
if [ "$#" -lt 2 ] || [ -z "${2:-}" ]; then
echo "Missing value for --format (expected: markdown|tsv)" >&2
usage >&2
exit 2
fi
FORMAT="${2:-}"
shift 2
;;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@script/audit-references.sh` around lines 23 - 26, The --format case handler
in the script unconditionally executes shift 2 without validating that a value
was actually provided for the FORMAT flag, causing a shell error instead of
controlled failure. Add an explicit check after the FORMAT assignment to verify
that the value is not empty (i.e., that a second argument exists), and if the
check fails, print a usage message and exit with status 2 before executing the
shift statement.

@keito4
keito4 merged commit f619d85 into main Jun 17, 2026
18 checks passed
@keito4
keito4 deleted the fix/issue-812-refactoring-baseline branch June 17, 2026 11:11
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.117.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released リリース済み

Projects

None yet

Development

Successfully merging this pull request may close these issues.

リファクタリング フェーズ0: 安全網とベースラインの整備

1 participant