From 9c0333c744b59113bbbcd11c8b35ee17166aa957 Mon Sep 17 00:00:00 2001
From: Sami Hiltunen <shiltunen@gitlab.com>
Date: Thu, 18 Apr 2024 18:36:30 +0300
Subject: [PATCH] Pass snapshot repository's relative path to Gitaly in tests

Gitaly passes the repository's relative path to Rails when it calls
the internal API. The relative path passed is the transaction's
snapshot repository's relative path. Without it Gitaly will not be
able to apply the repository's quarantine correctly as the quarantine
paths are relative to the snapshot repository.

While the relative path is passed in production code, tests haven't
been updated to pass the relative to Gitaly. This leads to test
failures when transactions are enabled in Gitaly.

Pass the relative path of the repository in the tests to ensure its
present when transactions are enabled. The relative path passed in
tests is the same as the actual relative path of the repository. In
reality the two paths would be different. As Gitaly is stubbed out
in the tests, it doesn't start a transaction and rewrite the relative
path so we use the original one.
---
 spec/requests/api/internal/base_spec.rb | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/spec/requests/api/internal/base_spec.rb b/spec/requests/api/internal/base_spec.rb
index 0969ef93ef64c..0ebacf5e9fdb7 100644
--- a/spec/requests/api/internal/base_spec.rb
+++ b/spec/requests/api/internal/base_spec.rb
@@ -618,7 +618,10 @@ def request_response(request:, call:, method:, metadata:) # rubocop:disable Lint
       end
 
       context 'git push with personal snippet' do
-        subject { push(key, personal_snippet, env: env.to_json, changes: snippet_changes) }
+        # relative_path is sent from Gitaly to Rails when invoking internal API. In production it points to the
+        # transaction's snapshot repository. As Gitaly is stubbed out from the invocation loop, there is no transaction
+        # and thus no snapshot repository. Pass the original relative path.
+        subject { push(key, personal_snippet, env: env.to_json, changes: snippet_changes, relative_path: "#{personal_snippet.repository.disk_path}.git") }
 
         it 'responds with success' do
           subject
@@ -650,7 +653,10 @@ def request_response(request:, call:, method:, metadata:) # rubocop:disable Lint
       end
 
       context 'git push with project snippet' do
-        subject { push(key, project_snippet, env: env.to_json, changes: snippet_changes) }
+        # relative_path is sent from Gitaly to Rails when invoking internal API. In production it points to the
+        # transaction's snapshot repository. As Gitaly is stubbed out from the invocation loop, there is no transaction
+        # and thus no snapshot repository. Pass the original relative path.
+        subject { push(key, project_snippet, env: env.to_json, changes: snippet_changes, relative_path: "#{project_snippet.repository.disk_path}.git") }
 
         it 'responds with success' do
           subject
-- 
GitLab