Skip to content

refactor: reorganize tests into __tests__/ and harden supply chain security - #24

Merged
nazozokc merged 4 commits into
mainfrom
AI-agent
Jun 22, 2026
Merged

refactor: reorganize tests into __tests__/ and harden supply chain security#24
nazozokc merged 4 commits into
mainfrom
AI-agent

Conversation

@nazozokc

@nazozokc nazozokc commented Jun 22, 2026

Copy link
Copy Markdown
Owner

変更内容

セキュリティ修正

  • pricing.ts: プライシングキャッシュファイルのパーミッションを 0o600 に修正(他ファイルと統一)
  • pnpm-workspace.yaml: 非推奨の allowBuilds から onlyBuiltDependencies に移行

サプライチェーンセキュリティ強化

  • SECURITY.md: 脆弱性報告ポリシーを追加
  • OpenSSF Scorecard CI: 週次自動評価ワークフローを追加
  • CI強化: Lockfile新鮮性チェック + pnpm audit を追加
  • Socket.devバッジ: バージョン固定から最新追従に変更
  • files フィールド: 存在しない npm-shrinkwrap.json 参照を削除

テスト再編成

  • テストファイルを src/__tests__/ に集約。import pathをすべて ../ に修正
  • tsconfig.json の exclude パターンを更新

検証

  • ✅ 全203テスト通過
  • ✅ ビルド成功(tsdown / vite)
  • pnpm install --frozen-lockfile 正常

Summary by CodeRabbit

  • Security

    • Added automated vulnerability auditing to CI pipeline
    • Introduced OpenSSF Scorecard security analysis
    • Published security vulnerability reporting guidelines
    • Enhanced cache file permission security
  • Documentation

    • Added security policy documentation
    • Updated README with visual improvements
  • Chores

    • Optimized workspace build configuration
    • Refined NPM package publishing contents

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@nazozokc, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 38 minutes and 30 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9452b521-c7fd-4fbf-bd97-d6d1cc5ff9c2

📥 Commits

Reviewing files that changed from the base of the PR and between 8b78039 and 20989de.

📒 Files selected for processing (2)
  • .envrc
  • pnpm-workspace.yaml
📝 Walkthrough

Walkthrough

Adds supply-chain security hardening across CI (lockfile freshness check, pnpm audit, OpenSSF Scorecard workflow), workspace config (onlyBuiltDependencies), npm publish file allowlist, a SECURITY.md policy, and a 0o600 permission on the pricing cache file. Separately, all test files are moved to src/__tests__ with import paths and tsconfig.json exclusion updated accordingly.

Changes

Supply Chain & CI Security Hardening

Layer / File(s) Summary
CI lockfile verification, audit, and Scorecard workflow
.github/workflows/check.yml, .github/workflows/scorecard.yml
check.yml adds a pnpm install --lockfile-only freshness check and a post-test pnpm audit --audit-level=high step. A new scorecard.yml workflow runs OpenSSF Scorecard on main pushes and weekly, uploading SARIF results via the CodeQL action.
Supply-chain restrictions, publish allowlist, and security policy
pnpm-workspace.yaml, subtrack/package.json, SECURITY.md, subtrack/README.md
pnpm-workspace.yaml replaces allowBuilds with onlyBuiltDependencies: [esbuild]. subtrack/package.json adds a files whitelist (dist, LICENSE, README.md). SECURITY.md defines the vulnerability reporting policy, scope, supported versions, and supply-chain measures. README.md adds a Socket badge.
Restrictive permissions on pricing cache file
subtrack/src/pricing.ts
writeFileSync in ensurePricingCache now passes mode: 0o600, restricting the on-disk JSON cache file to owner-only read/write.

Test Directory Restructuring

Layer / File(s) Summary
tsconfig exclude updated for __tests__ directory
subtrack/tsconfig.json
exclude entry changes from src/**/*.test.ts to src/__tests__, aligning TypeScript compilation exclusion with the new test directory layout.
Test import paths updated to parent-relative
subtrack/src/__tests__/commands.test.ts, subtrack/src/__tests__/crypto.test.ts, subtrack/src/__tests__/db.test.ts, subtrack/src/__tests__/display.test.ts, subtrack/src/__tests__/pricing.test.ts
All static and dynamic imports across every test file are updated from ./<module>.ts to ../<module>.ts. Test logic and assertions are unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • nazozokc/subtrack#12: Introduced exportCsv/exportMd tests in display.test.ts whose import paths are directly updated by this PR's test restructuring.
  • nazozokc/subtrack#13: Heavily expanded commands.test.ts, db.test.ts, and display.test.ts test suites whose module resolution this PR aligns with the src/__tests__ directory move.
  • nazozokc/subtrack#21: Modified the same check.yml CI workflow to add type-checking and build gates, which this PR extends with lockfile verification and audit steps.

Suggested labels

subtrack, ci, dependencies

Poem

🐰 Hop, hop, hooray for locked-down deps!
The lockfile's fresh, no sneaky intercepts.
My cache writes safe at 0o600,
Supply chain tamed — no rogue install scripts.
The Scorecard watches from its weekly perch,
And tests now live where __tests__ beams with mirth!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: reorganize tests into tests/ and harden supply chain security' accurately summarizes the main changes: test reorganization into tests/ directory and supply chain security enhancements (SECURITY.md, OpenSSF Scorecard, lockfile checks, pnpm audit, file permissions, and workspace config updates).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch AI-agent

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 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 @.github/workflows/check.yml:
- Line 22: Replace the unpinned `actions/checkout@v4` reference with a pinned
commit hash version in the format `actions/checkout@<commit-hash>`. Visit
https://github.com/actions/checkout/releases to find the latest v4 commit hash
and update the action reference to pin it to that specific commit instead of
using the version tag. This applies to all instances of the checkout action in
the workflow file to ensure consistent security hardening across all action
references.

In @.github/workflows/scorecard.yml:
- Line 22: Replace the version tags in the GitHub Actions references with
specific commit hashes to follow security best practices. For the
actions/checkout action (currently using `@v4`), ossf/scorecard-action (currently
using `@v2.4.0`), and github/codeql-action/upload-sarif (currently using `@v3`),
update each uses statement to pin to a specific commit hash instead of the
version tag. Verify the correct commit hashes by checking each action's releases
page on GitHub and update all three action references accordingly.

In `@subtrack/src/__tests__/display.test.ts`:
- Line 5: The import statement for spreadSubscription is missing the required
.ts file extension. Update the import statement by adding the .ts extension to
the import path from "../display" to "../display.ts" to comply with the repo's
coding guidelines that require explicit .ts extensions for local imports.

In `@subtrack/tsconfig.json`:
- Line 2: The exclude array in tsconfig.json currently hardcodes the exclusion
of src/__tests__, which conflicts with the repository's policy of co-locating
test files as *.test.ts alongside source modules. Remove the src/__tests__
exclusion and replace it with a pattern that excludes co-located test files such
as **/*.test.ts and **/*.test.tsx to align with the project's coding guidelines.
🪄 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: e1f611eb-a927-4bf7-8192-8101a525d910

📥 Commits

Reviewing files that changed from the base of the PR and between 5a983a8 and 8b78039.

📒 Files selected for processing (13)
  • .github/workflows/check.yml
  • .github/workflows/scorecard.yml
  • SECURITY.md
  • pnpm-workspace.yaml
  • subtrack/README.md
  • subtrack/package.json
  • subtrack/src/__tests__/commands.test.ts
  • subtrack/src/__tests__/crypto.test.ts
  • subtrack/src/__tests__/db.test.ts
  • subtrack/src/__tests__/display.test.ts
  • subtrack/src/__tests__/pricing.test.ts
  • subtrack/src/pricing.ts
  • subtrack/tsconfig.json

@@ -22,10 +22,16 @@ jobs:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Pin GitHub Actions to commit hashes.

The actions/checkout@v4 reference on line 22 is unpinned. Per GitHub security best practices and the requirements flagged by static analysis, all action references must be pinned to a specific commit hash (not a tag or branch) to prevent supply-chain attacks and ensure reproducible workflows.

While the lockfile verification (lines 25–26) and audit logic (lines 36–37) are sound, the unpinned action undermines the security hardening intent of this PR.

🔒 Proposed fix: Pin action to commit hash
-      - uses: actions/checkout@v4
+      - uses: actions/checkout@44c85305e41dfe471331e387f004d221add66d31 # v4.1.1

(Verify the latest v4.x commit hash at https://github.com/actions/checkout/releases)

Also applies to: 25-37

🤖 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 @.github/workflows/check.yml at line 22, Replace the unpinned
`actions/checkout@v4` reference with a pinned commit hash version in the format
`actions/checkout@<commit-hash>`. Visit
https://github.com/actions/checkout/releases to find the latest v4 commit hash
and update the action reference to pin it to that specific commit instead of
using the version tag. This applies to all instances of the checkout action in
the workflow file to ensure consistent security hardening across all action
references.

Source: Linters/SAST tools

security-events: write

steps:
- uses: actions/checkout@v4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Pin all GitHub Actions to commit hashes.

Three action references are unpinned and violate security best practices:

  • Line 22: actions/checkout@v4
  • Line 26: ossf/scorecard-action@v2.4.0
  • Line 33: github/codeql-action/upload-sarif@v3

Unpinned tags and versions are mutable and vulnerable to supply-chain attacks (tag hijacking, compromised releases). All actions must be pinned to specific commit hashes.

🔒 Proposed fix: Pin all actions to commit hashes
-      - uses: actions/checkout@v4
+      - uses: actions/checkout@44c85305e41dfe471331e387f004d221add66d31 # v4.1.1

-      - uses: ossf/scorecard-action@v2.4.0
+      - uses: ossf/scorecard-action@dc50aa9510b46c811795eb24b2f1ba02a914a587 # v2.4.0

-        uses: github/codeql-action/upload-sarif@v3
+        uses: github/codeql-action/upload-sarif@cdcdbbfb34304309f8c18fe68d3a021711ae8f642 # v3.1.1

(Verify commit hashes at each action's GitHub releases page)

Also applies to: 26-26, 33-33

🧰 Tools
🪛 zizmor (1.25.2)

[error] 22-22: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)

(unpinned-uses)

🤖 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 @.github/workflows/scorecard.yml at line 22, Replace the version tags in the
GitHub Actions references with specific commit hashes to follow security best
practices. For the actions/checkout action (currently using `@v4`),
ossf/scorecard-action (currently using `@v2.4.0`), and
github/codeql-action/upload-sarif (currently using `@v3`), update each uses
statement to pin to a specific commit hash instead of the version tag. Verify
the correct commit hashes by checking each action's releases page on GitHub and
update all three action references accordingly.

Source: Linters/SAST tools

import type { Database } from "sql.js"
import { spreadSubscription } from "./display"
import type { SharedArgs } from "./types.ts"
import { spreadSubscription } from "../display"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use .ts extension for this local static import.

import { spreadSubscription } from "../display" violates the repo rule requiring explicit .ts for local imports.

As per coding guidelines, subtrack/**/*.{ts,tsx}: “Import local files with .ts extension (e.g., import { x } from "./foo.ts")".

🤖 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 `@subtrack/src/__tests__/display.test.ts` at line 5, The import statement for
spreadSubscription is missing the required .ts file extension. Update the import
statement by adding the .ts extension to the import path from "../display" to
"../display.ts" to comply with the repo's coding guidelines that require
explicit .ts extensions for local imports.

Source: Coding guidelines

Comment thread subtrack/tsconfig.json
@@ -1,5 +1,5 @@
{
"exclude": ["src/**/*.test.ts"],
"exclude": ["src/__tests__"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

src/__tests__ exclusion codifies a test layout that conflicts with project test-location policy.

This change hardwires centralized tests under src/__tests__, which conflicts with the repository rule requiring co-located *.test.ts files beside source modules.

As per coding guidelines, subtrack/**/*.test.{ts,tsx}: “Co-locate test files as *.test.ts alongside source files”.

🤖 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 `@subtrack/tsconfig.json` at line 2, The exclude array in tsconfig.json
currently hardcodes the exclusion of src/__tests__, which conflicts with the
repository's policy of co-locating test files as *.test.ts alongside source
modules. Remove the src/__tests__ exclusion and replace it with a pattern that
excludes co-located test files such as **/*.test.ts and **/*.test.tsx to align
with the project's coding guidelines.

Source: Coding guidelines

The onlyBuiltDependencies field in pnpm-workspace.yaml is not compatible
with pnpm v11.5.1 when running pnpm install --frozen-lockfile because the
lockfile was generated with the allowBuilds format and pnpm does not
automatically reconcile the new format with existing lockfile entries.

Change back to the allowBuilds format which correctly allows esbuild
postinstall scripts to run, fixing the CI failure.
@nazozokc
nazozokc merged commit 5506040 into main Jun 22, 2026
12 checks passed
@nazozokc
nazozokc deleted the AI-agent branch June 22, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant