Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 17, 2025

Problem

The oj_test tool currently saves downloaded test cases to the /tmp directory, which means test cases are re-downloaded on every GitHub Actions run. This leads to:

  • Slower CI build times
  • Unnecessary network traffic
  • Reduced reliability due to external network dependencies

Solution

This PR implements testcase caching by moving test case storage from /tmp to a project-local testcases/ directory and adding GitHub Actions cache configuration.

Changes Made

  1. Modified test case storage location (tool/oj_test/src/lib.rs):

    // Before
    let dir = env::temp_dir().join(dir_suffix);
    
    // After  
    let dir = env::current_dir()?.join("testcases").join(dir_suffix);
  2. Added .gitignore entry to exclude test cases from version control:

    testcases/
    
  3. Enhanced GitHub Actions workflow (.github/workflows/rust.yml) with caching:

    - name: Cache testcases
      uses: actions/cache@v4
      with:
        path: testcases/
        key: testcases-${{ hashFiles('**/examples/*.rs') }}
        restore-keys: |
          testcases-

Benefits

  • Faster CI builds: Test cases are cached between runs when solver files are unchanged
  • Reduced network traffic: Avoids re-downloading identical test cases
  • Improved reliability: Less dependency on external network during CI
  • Smart cache invalidation: Cache key based on solver file hashes ensures fresh test cases when problems change

Testing

  • Added unit test to verify correct path construction
  • All existing tests pass
  • Verified .gitignore correctly excludes testcases/ directory
  • Confirmed backwards compatibility - no breaking changes to existing functionality

The cache will be populated on the first workflow run and reused on subsequent runs, significantly improving CI performance for this competitive programming repository.

This pull request was created as a result of the following prompt from Copilot chat.

現在、oj_testツールはoj downloadコマンドでダウンロードしたテストケースを/tmpディレクトリに保存しています。GitHub Actionsでキャッシュを活用するために、以下の変更を実装してください:

必要な変更

1. テストケース保存先の変更

  • tool/oj_test/src/lib.rsdownload_online_judge_testcase関数を修正
  • /tmpディレクトリの代わりに、プロジェクトルートのtestcasesディレクトリ以下に保存するように変更

2. .gitignoreの更新

  • プロジェクトルートの.gitignoreファイルにtestcases/を追加し、テストケースファイルがGitで追跡されないようにする

3. GitHub Actionsの更新

  • .github/workflows/rust.ymloj-testジョブにキャッシュ設定を追加
  • actions/cacheを使用してtestcasesディレクトリをキャッシュ
  • キャッシュキーは問題URLやソルバーファイルのハッシュなど、適切なものを使用

実装の詳細

現在のdownload_online_judge_testcase関数:

pub fn download_online_judge_testcase(problem_url: &str, dir_suffix: &Path) -> Result<PathBuf> {
    let dir = env::temp_dir().join(dir_suffix);
    // ...
}

この部分を、プロジェクトルートのtestcasesディレクトリを使用するように変更してください。

期待される効果

  • GitHub Actionsでのビルド時間短縮(テストケースの再ダウンロードが不要)
  • ネットワークトラフィックの削減
  • より安定したCI/CDパイプライン

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI assigned Copilot and ia7ck Jul 17, 2025
@ia7ck ia7ck closed this Jul 17, 2025
@Copilot Copilot AI changed the title [WIP] GitHub Actionsでテストケースをキャッシュするためにoj_testの保存先を変更 Implement testcase caching for GitHub Actions by moving storage from /tmp to project directory Jul 17, 2025
@Copilot Copilot AI requested a review from ia7ck July 17, 2025 14:31
Copilot finished work on behalf of ia7ck July 17, 2025 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants