Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 13, 2025

This PR adds a comprehensive integration test for the git-link function that simulates real-world usage with an actual git repository.

Changes

  • Added git-link-interactive-simulation test function to git-link-test.el
  • The test creates a temporary git repository with proper configuration
  • Tests the complete workflow: file creation, git operations, and URL generation
  • Verifies the generated URL matches the expected GitHub format

Test Details

The new test function:

  1. Creates a temporary directory with a real git repository
  2. Sets up git configuration (user.name, user.email)
  3. Adds a GitHub remote origin (https://github.com/user/repo.git)
  4. Creates a test file with 5 lines of content
  5. Commits the file to the repository
  6. Opens the file in a buffer and positions cursor at line 3
  7. Calls git-link function with parameters ("origin", 3, nil)
  8. Verifies the result matches: "https://github.com/user/repo/blob/master/test-file.txt#L3"
  9. Properly cleans up all resources using unwind-protect

Testing

All tests pass successfully:

  • Previous 25 tests continue to pass
  • New integration test passes and takes ~50ms (indicating real git operations)
  • Test can be run individually or as part of the full suite

This test provides valuable coverage for the main git-link function end-to-end workflow, complementing the existing unit tests that focus on individual helper functions.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

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

Add the git-link-interactive-simulation function to git-link-test.el.

(ert-deftest git-link-interactive-simulation ()
  "Test interactive git-link function call with cursor at line 3 using real git repo."
  (let ((test-dir (make-temp-file "git-link-test" t)))
    (unwind-protect
        (let ((default-directory test-dir)
              git-link-add-to-kill-ring  ; Don't add to kill ring during test
              git-link-open-in-browser)  ; Don't open browser during test
          
          ;; Set up a real git repository
          (shell-command "git init")
          (shell-command "git config user.name 'Test User'")
          (shell-command "git config user.email '[email protected]'")
          (shell-command "git remote add origin https://github.com/user/repo.git")
          
          ;; Create test file with content
          (with-temp-file (expand-file-name "test-file.txt" test-dir)
            (insert "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\n"))
          
          ;; Add and commit the file
          (shell-command "git add test-file.txt")
          (shell-command "git commit -m 'Initial commit'")
          
          ;; Create a buffer visiting the file and position cursor at line 3
          (with-current-buffer (find-file-noselect (expand-file-name "test-file.txt" test-dir))
            (goto-char (point-min))
            (forward-line 2) ; Move to line 3
            
            ;; Call git-link interactively
            (let ((result (git-link "origin" 3 nil))) ; Line 3, no end line
              ;; Verify the result is the complete expected URL
              (should (equal "https://github.com/user/repo/blob/master/test-file.txt#L3" result)))
            
            ;; Clean up buffer
            (kill-buffer)))
      
      ;; Clean up temporary directory
      (when (file-exists-p test-dir)
        (delete-directory test-dir t)))))

💡 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 changed the title [WIP] feat: Add interactive simulation test Add git-link-interactive-simulation integration test Jul 13, 2025
@Copilot Copilot AI requested a review from sshaw July 13, 2025 00:15
Copilot finished work on behalf of sshaw July 13, 2025 00:15
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