t5558: add tests for creationToken heuristic

As documented in the bundle URI design doc in 2da14fad8fe (docs: document bundle URI standard, 2022-08-09), the 'creationToken' member of a bundle URI allows a bundle provider to specify a total order on the bundles. Future changes will allow the Git client to understand these members and modify its behavior around downloading the bundles in that order. In the meantime, create tests that add creation tokens to the bundle list. For now, the Git client correctly ignores these unknown keys. Create a new test helper function, test_remote_https_urls, which filters GIT_TRACE2_EVENT output to extract a list of URLs passed to git-remote-https child processes. This can be used to verify the order of these requests as we implement the creationToken heuristic. For now, we need to sort the actual output since the current client does not have a well-defined order that it applies to the bundles. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jan 31, 2023 at 13:29 UTC 7bc73e7b61e60cbc0730a4f0e938c482c459e000
2 files changed +75 -2
t/t5558-clone-bundle-uri.sh
+67 -2
@@ -285,6 +285,8 @@ test_expect_success 'clone HTTP bundle' '
285 '
286
287 test_expect_success 'clone bundle list (HTTP, no heuristic)' '
288 + test_when_finished rm -f trace*.txt &&
289 +
290 cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" &&
291 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
292 [bundle]
@@ -304,12 +306,26 @@ test_expect_success 'clone bundle list (HTTP, no heuristic)' '
306 uri = $HTTPD_URL/bundle-4.bundle
307 EOF
308
307 - git clone --bundle-uri="$HTTPD_URL/bundle-list" \
309 + GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" \
310 + git clone --bundle-uri="$HTTPD_URL/bundle-list" \
311 clone-from clone-list-http 2>err &&
312 ! grep "Repository lacks these prerequisite commits" err &&
313
314 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
312 - git -C clone-list-http cat-file --batch-check <oids
315 + git -C clone-list-http cat-file --batch-check <oids &&
316 +
317 + cat >expect <<-EOF &&
318 + $HTTPD_URL/bundle-1.bundle
319 + $HTTPD_URL/bundle-2.bundle
320 + $HTTPD_URL/bundle-3.bundle
321 + $HTTPD_URL/bundle-4.bundle
322 + $HTTPD_URL/bundle-list
323 + EOF
324 +
325 + # Sort the list, since the order is not well-defined
326 + # without a heuristic.
327 + test_remote_https_urls <trace-clone.txt | sort >actual &&
328 + test_cmp expect actual
329 '
330
331 test_expect_success 'clone bundle list (HTTP, any mode)' '
@@ -350,6 +366,55 @@ test_expect_success 'clone bundle list (HTTP, any mode)' '
366 test_cmp expect actual
367 '
368
369 +test_expect_success 'clone bundle list (http, creationToken)' '
370 + test_when_finished rm -f trace*.txt &&
371 +
372 + cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" &&
373 + cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
374 + [bundle]
375 + version = 1
376 + mode = all
377 + heuristic = creationToken
378 +
379 + [bundle "bundle-1"]
380 + uri = bundle-1.bundle
381 + creationToken = 1
382 +
383 + [bundle "bundle-2"]
384 + uri = bundle-2.bundle
385 + creationToken = 2
386 +
387 + [bundle "bundle-3"]
388 + uri = bundle-3.bundle
389 + creationToken = 3
390 +
391 + [bundle "bundle-4"]
392 + uri = bundle-4.bundle
393 + creationToken = 4
394 + EOF
395 +
396 + GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" git \
397 + clone --bundle-uri="$HTTPD_URL/bundle-list" \
398 + "$HTTPD_URL/smart/fetch.git" clone-list-http-2 &&
399 +
400 + git -C clone-from for-each-ref --format="%(objectname)" >oids &&
401 + git -C clone-list-http-2 cat-file --batch-check <oids &&
402 +
403 + cat >expect <<-EOF &&
404 + $HTTPD_URL/bundle-1.bundle
405 + $HTTPD_URL/bundle-2.bundle
406 + $HTTPD_URL/bundle-3.bundle
407 + $HTTPD_URL/bundle-4.bundle
408 + $HTTPD_URL/bundle-list
409 + EOF
410 +
411 + # Since the creationToken heuristic is not yet understood by the
412 + # client, the order cannot be verified at this moment. Sort the
413 + # list for consistent results.
414 + test_remote_https_urls <trace-clone.txt | sort >actual &&
415 + test_cmp expect actual
416 +'
417 +
418 # Do not add tests here unless they use the HTTP server, as they will
419 # not run unless the HTTP dependencies exist.
420
t/test-lib-functions.sh
+8
@@ -1833,6 +1833,14 @@ test_region () {
1833 return 0
1834 }
1835
1836 +# Given a GIT_TRACE2_EVENT log over stdin, writes to stdout a list of URLs
1837 +# sent to git-remote-https child processes.
1838 +test_remote_https_urls() {
1839 + grep -e '"event":"child_start".*"argv":\["git-remote-https",".*"\]' |
1840 + sed -e 's/{"event":"child_start".*"argv":\["git-remote-https","//g' \
1841 + -e 's/"\]}//g'
1842 +}
1843 +
1844 # Print the destination of symlink(s) provided as arguments. Basically
1845 # the same as the readlink command, but it's not available everywhere.
1846 test_readlink () {