Skip to content

Commit 10f149b

Browse files
authored
feat: Enable dynamic subdirectory recording paths in the test server (#49)
* allow test-name to include parent path. * address comment: testing the recursive creation of the folders.
1 parent a5d6ec8 commit 10f149b

4 files changed

Lines changed: 84 additions & 8 deletions

File tree

internal/record/recording_https_proxy.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ func (r *RecordingHTTPSProxy) recordResponse(recReq *store.RecordedRequest, resp
203203

204204
recordPath := filepath.Join(r.recordingDir, fileName+".json")
205205

206+
recordDir := filepath.Dir(recordPath)
207+
if err := os.MkdirAll(recordDir, 0755); err != nil {
208+
return err
209+
}
210+
206211
// Default to overwriting the file.
207212
fileMode := os.O_TRUNC
208213
file, err := os.OpenFile(recordPath, fileMode|os.O_CREATE|os.O_WRONLY, 0644)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"recordID": "models/folder1/folder2/python-sample-test_recursive_path",
3+
"interactions": [
4+
{
5+
"request": {
6+
"method": "GET",
7+
"url": "/",
8+
"request": "GET / HTTP/1.1",
9+
"headers": {
10+
"Accept": "*/*",
11+
"Accept-Encoding": "gzip, deflate",
12+
"Connection": "keep-alive",
13+
"Test-Name": "models/folder1/folder2/python-sample-test_recursive_path",
14+
"User-Agent": "python-requests/2.32.5"
15+
},
16+
"bodySegments": [
17+
null
18+
],
19+
"previousRequest": "b4d6e60a9b97e7b98c63df9308728c5c88c0b40c398046772c63447b94608b4d",
20+
"serverAddress": "github.com",
21+
"port": 443,
22+
"protocol": "https"
23+
},
24+
"shaSum": "79c8cd67ce0b39d6c5aeee4f685320e3066331e60171b49108251c3305cd034e",
25+
"response": {
26+
"statusCode": 200,
27+
"headers": {
28+
"Accept-Ranges": "bytes",
29+
"Cache-Control": "max-age=0, private, must-revalidate",
30+
"Content-Encoding": "gzip",
31+
"Content-Language": "en-US",
32+
"Content-Security-Policy": "default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com wss://alive-staging.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com github.githubassets.com edge.fullstory.com rs.fullstory.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com www.youtube-nocookie.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com marketplace-screenshots.githubusercontent.com/ copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com images.ctfassets.net/8aevphvgewt8/; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com github.githubassets.com assets.ctfassets.net/8aevphvgewt8/ videos.ctfassets.net/8aevphvgewt8/; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/",
33+
"Content-Type": "text/html; charset=utf-8",
34+
"Date": "Mon, 15 Sep 2025 17:58:03 GMT",
35+
"Etag": "W/\"cd488b2ea2ae9702b6652dfcb4294b9f\"",
36+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
37+
"Server": "github.com",
38+
"Set-Cookie": "_gh_sess=3YXTN2Kn9fZ548MFymDvF4bmU3CVT1fhBeYO4rhAseW2l4rkmT0wzpD6sxgKPmt6uiXpcanTYQoSk0His54Z5ZVw1bPeaynC5BS5XzhvbMHfO4jT%2Ffg7udqglbBw1lmCRyr34q2WlFb%2F%2BM5aF3ErLwjPQUIHzxN1MH12fLFOxbh919Qvxs%2FEc%2FEdCQkb6a5wSvhYSihZXyGtDSQkRN%2FtE74aZZzOhn9hhHo68SeDmE47VCWIRm%2Bk1MGP3C6YiXwHjHF3T0%2Bu4OupJqUgKvKkbw%3D%3D--q7RzlJy371g%2FhXQu--2ZImD096TJjWHHRIqjJi%2Bg%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax, _octo=GH1.1.1334543195.1757959087; Path=/; Domain=github.com; Expires=Tue, 15 Sep 2026 17:58:07 GMT; Secure; SameSite=Lax, logged_in=no; Path=/; Domain=github.com; Expires=Tue, 15 Sep 2026 17:58:07 GMT; HttpOnly; Secure; SameSite=Lax",
39+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
40+
"Vary": "X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With, Accept-Language,Accept-Encoding, Accept, X-Requested-With",
41+
"X-Content-Type-Options": "nosniff",
42+
"X-Frame-Options": "deny",
43+
"X-Github-Request-Id": "D872:2A9986:920E617:96857F7:68C853AF",
44+
"X-Xss-Protection": "0"
45+
}
46+
}
47+
}
48+
]
49+
}

sdks/python/sample/test-data/recordings/396bab503f4b90ad88858bb4467d59b9e827dcd82e33f41c230e1b8fb43bdc8c.json renamed to sdks/python/sample/test-data/recordings/python-sample-test-single-name.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"recordID": "396bab503f4b90ad88858bb4467d59b9e827dcd82e33f41c230e1b8fb43bdc8c",
2+
"recordID": "python-sample-test-single-name",
33
"interactions": [
44
{
55
"request": {
@@ -10,6 +10,7 @@
1010
"Accept": "*/*",
1111
"Accept-Encoding": "gzip, deflate",
1212
"Connection": "keep-alive",
13+
"Test-Name": "python-sample-test-single-name",
1314
"User-Agent": "python-requests/2.32.5"
1415
},
1516
"bodySegments": [
@@ -20,7 +21,7 @@
2021
"port": 443,
2122
"protocol": "https"
2223
},
23-
"shaSum": "396bab503f4b90ad88858bb4467d59b9e827dcd82e33f41c230e1b8fb43bdc8c",
24+
"shaSum": "1a786dc6d04c039bf6dac4945967c846dd1ffa978a1a7f7073014c19d6cdd131",
2425
"response": {
2526
"statusCode": 200,
2627
"headers": {
@@ -30,16 +31,16 @@
3031
"Content-Language": "en-US",
3132
"Content-Security-Policy": "default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com wss://alive-staging.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com github.githubassets.com edge.fullstory.com rs.fullstory.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com www.youtube-nocookie.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com marketplace-screenshots.githubusercontent.com/ copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com images.ctfassets.net/8aevphvgewt8/; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com github.githubassets.com assets.ctfassets.net/8aevphvgewt8/ videos.ctfassets.net/8aevphvgewt8/; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/",
3233
"Content-Type": "text/html; charset=utf-8",
33-
"Date": "Tue, 09 Sep 2025 15:53:45 GMT",
34-
"Etag": "W/\"8bab6ba1a0068ba77443041a70a012fc\"",
34+
"Date": "Mon, 15 Sep 2025 17:58:03 GMT",
35+
"Etag": "W/\"cd488b2ea2ae9702b6652dfcb4294b9f\"",
3536
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
3637
"Server": "github.com",
37-
"Set-Cookie": "_gh_sess=jjLJMJHJa3yHLlB%2FstksHC7tyxHlTIGMZnISFDY5YvN2pZ40k9erSjDcL6N4fwiK3tI4gqB3ZMiFacRZPexRYU%2Fa4QKkFSyDN1oRGfv19gkqDJWH0UygUOc9239ontofFzh8rPEEnLdtPR3Jxq1Mb2sqs8e9MTvgTueqp1XRNElJvU3h0%2BocyQ%2Fr8XI4pIdLm64jp34ysCaisN%2FFXBa9SHzEIpGfQlrvihtWYcWP%2Bmzl0S5MAwox3%2BVFOiUPdf2AnD86OMXJekNHcxgzc41SPA%3D%3D--bex5KbZP2AtUtYXh--rcQmgTr4hiau78tUK896nQ%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax, _octo=GH1.1.1430909772.1757433231; Path=/; Domain=github.com; Expires=Wed, 09 Sep 2026 15:53:51 GMT; Secure; SameSite=Lax, logged_in=no; Path=/; Domain=github.com; Expires=Wed, 09 Sep 2026 15:53:51 GMT; HttpOnly; Secure; SameSite=Lax",
38+
"Set-Cookie": "_gh_sess=w5DaXbsbx%2F2PlXqycHl0ShvuHiZnHqmL5iYuP%2FD59y8HvO9KC4xSzq9mDzz6ZnENbxpU8MNfwSO8l8kUlKs47gnCup9ikRBOw%2Fam%2FU53gJ0t0RZguRAbej9OLML8jl9A%2FVggEYSJYo1A4JGuEso3uDJMMlbmp2fw1uitkAsMrl2ExUMs35uptt4R1Z3tx631YsjOGz64QlW1MZWbHQzbM0hf3Kd98%2BXJopJnudZrfxesMw%2FyOoNEWclXZS7XDWN68XKAtQl7Nqq1kS4ShsuDPQ%3D%3D--vnkZeXNoz4iRMuQH--S4gx9ntAHwkRRafwzQrJhA%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax, _octo=GH1.1.831469942.1757959087; Path=/; Domain=github.com; Expires=Tue, 15 Sep 2026 17:58:07 GMT; Secure; SameSite=Lax, logged_in=no; Path=/; Domain=github.com; Expires=Tue, 15 Sep 2026 17:58:07 GMT; HttpOnly; Secure; SameSite=Lax",
3839
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
3940
"Vary": "X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With, Accept-Language,Accept-Encoding, Accept, X-Requested-With",
4041
"X-Content-Type-Options": "nosniff",
4142
"X-Frame-Options": "deny",
42-
"X-Github-Request-Id": "D811:22D066:299B1F:2A4602:68C04D8F",
43+
"X-Github-Request-Id": "D872:2A9986:920E5EB:96857C2:68C853AF",
4344
"X-Xss-Protection": "0"
4445
}
4546
}

sdks/python/sample/test_sample.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,33 @@
88
class TestSampleWithServer:
99
"""A test suite that requires the test-server to be running."""
1010

11-
def test_should_receive_200_from_proxied_github(self):
11+
def test_should_receive_200_from_proxied_github_single_name(self):
1212
"""Tests that a request to the proxy returns a successful response."""
1313
print("[PyTest] Making request to test-server proxy for www.github.com...")
14+
15+
custom_headers = {
16+
'Test-Name': 'python-sample-test-single-name',
17+
}
18+
19+
# Use the 'requests' library for a simpler HTTP call
20+
response = requests.get("http://localhost:17080/", headers=custom_headers, timeout=10)
21+
22+
# Pytest uses simple 'assert' statements for checks
23+
assert response.status_code == 200
24+
assert "github" in json.dumps(dict(response.headers))
25+
26+
print("[PyTest] Received 200 OK, content check passed.")
27+
28+
def test_should_receive_200_from_proxied_github_recursive_path(self):
29+
"""Tests that a request to the proxy returns a successful response."""
30+
print("[PyTest] Making request to test-server proxy for www.github.com...")
31+
32+
custom_headers = {
33+
'Test-Name': 'models/folder1/folder2/python-sample-test_recursive_path',
34+
}
1435

1536
# Use the 'requests' library for a simpler HTTP call
16-
response = requests.get("http://localhost:17080/", timeout=10)
37+
response = requests.get("http://localhost:17080/", headers=custom_headers, timeout=10)
1738

1839
# Pytest uses simple 'assert' statements for checks
1940
assert response.status_code == 200

0 commit comments

Comments
 (0)