Skip to content

Commit c72e44c

Browse files
committed
Fix fake git validation in timeout test (#5130)
1 parent 6903dc1 commit c72e44c

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

TESTING_GUIDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Use the full suite by default. Use targeted filters only while iterating locally
1919

2020
## Test Stack
2121

22+
- Issue #5130 keeps the commit-diff timeout regression focused on `diff-tree`: its fake git must echo the commit being verified by `rev-parse --verify <ref>^{commit}`, then the test must confirm the timed-out child process is reaped. Keep production single-commit validation strict.
2223
- Issue #5128 compact graph zero-result coverage belongs in `JsonEnvelopeWrapperIssue4585Tests.cs`. Keep `callees` aligned with `references` and `callers` by asserting an empty compact location envelope and zero returned/total cardinality both with and without explicit `--fields`, while reusing the graph-ready bounded-response fixture.
2324
- Issue #5098 inspect projection coverage belongs in `QueryCommandRunnerInspectTests.cs`. Keep one graph-ready partial-type fixture covering canonical and alias selectors, multiple leaves across collections, parent-over-child precedence, stable row order, empty arrays, compact truncation, byte bounds, body paging/recovery, partial-family metadata, queryless catalog discovery, and typed unknown parent/leaf errors. `ConsoleUiTests.cs` separately pins the `<csv|list>` usage, nested-field help text, and examples.
2425
- Path-containment coverage for #5091 pairs platform-independent `PathCasingTests` seams for mixed parent-namespace case policies and directory identities with `FileIndexerTests` integration through an internal file symlink. Keep both checks when changing internal-symlink policy: a case-insensitive project mount must not make a distinct case-only sibling in its case-sensitive parent namespace appear internal, while genuine same-namespace aliases remain accepted.
@@ -1114,6 +1115,7 @@ dotnet test --filter "FullyQualifiedName~GitHelperTests"
11141115

11151116
## テストスタック
11161117

1118+
- Issue #5130 の commit-diff timeout regression は `diff-tree` に焦点を維持します。fake git は `rev-parse --verify <ref>^{commit}` で検証対象の commit を返し、テストでは timeout した子プロセスが reap されることを確認してください。本番の single-commit validation は厳格なままにします。
11171119
- Issue #5128 の compact graph 0件 coverage は `JsonEnvelopeWrapperIssue4585Tests.cs` が担当します。graph-ready な bounded-response fixture を再利用し、明示的な `--fields` の有無の両方で、`callees` が `references` / `callers` と同様に空の compact location envelope と返却件数・総件数0を維持することを検証してください。
11181120
- Issue #5098 の inspect projection coverage は `QueryCommandRunnerInspectTests.cs` が担当します。graph-ready な partial type fixture 1つで canonical / alias selector、collection をまたぐ複数 leaf、parent の child に対する優先、安定した row 順、空配列、compact truncation、byte 上限、body paging / recovery、partial-family metadata、query 不要の catalog discovery、未知 parent / leaf の型付き error を維持してください。`ConsoleUiTests.cs` では `<csv|list>` usage、nested-field help text、例を別途固定します。
11191121
- #5091 の path containment coverage は、親 directory namespace の case policy と directory identity が混在する状況を OS 非依存で再現する `PathCasingTests` の seam と、内部 file symlink を通す `FileIndexerTests` の integration を対にします。internal-symlink policy を変更するときは両方を維持し、case-insensitive な project mount の policy で、case-sensitive な親 namespace にある別 identity の case-only sibling を内部 path と誤認しないこと、および同一 namespace の正当な alias は引き続き受理されることを検証してください。
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
category: fixed
3+
issues:
4+
- 5130
5+
affected:
6+
- tests/CodeIndex.Tests/GitHelperTests.cs
7+
- TESTING_GUIDE.md
8+
---
9+
10+
## English
11+
12+
- **The commit-diff timeout regression now reaches `diff-tree` (#5130)** — the fake git validation response follows the temporary commit under test, preserving strict single-commit validation while allowing the timeout path to verify child-process cleanup.
13+
14+
## 日本語
15+
16+
- **commit-diff timeout regression が `diff-tree` に到達するようになりました (#5130)** — fake git の validation 応答をテスト対象の一時 commit と一致させ、厳格な single-commit validation を維持しながら timeout 経路で子プロセスの cleanup を検証できるようにしました。

tests/CodeIndex.Tests/GitHelperTests.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ public void GetChangedFilesFromCommit_FailsWhenGitCommandTimesOut()
732732

733733
var fakeGitDir = Path.Combine(_tempDir, "fake-git-timeout");
734734
Directory.CreateDirectory(fakeGitDir);
735-
WriteFakeGitThatHangsOnDiffTree(fakeGitDir);
735+
WriteFakeGitThatHangsOnDiffTree(fakeGitDir, commitId);
736736
var fakeGitPidPath = Path.Combine(fakeGitDir, "diff-tree.pid");
737737

738738
var oldGitExecutablePath = GitHelper.GitExecutablePathOverride;
@@ -971,7 +971,8 @@ public void GetChangedFilesFromCommit_CancelDuringGitCommand_ThrowsOperationCanc
971971
Directory.CreateDirectory(repoDir);
972972
var fakeGitDir = Path.Combine(_tempDir, "fake-git-cancel");
973973
Directory.CreateDirectory(fakeGitDir);
974-
WriteFakeGitThatHangsOnDiffTree(fakeGitDir);
974+
const string commitId = "0123456789abcdef";
975+
WriteFakeGitThatHangsOnDiffTree(fakeGitDir, commitId);
975976

976977
var oldGitExecutablePath = GitHelper.GitExecutablePathOverride;
977978
GitHelper.GitExecutablePathOverride = Path.Combine(fakeGitDir, "git");
@@ -982,7 +983,7 @@ public void GetChangedFilesFromCommit_CancelDuringGitCommand_ThrowsOperationCanc
982983
var stopwatch = Stopwatch.StartNew();
983984

984985
var ex = Assert.Throws<OperationCanceledException>(
985-
() => GitHelper.GetChangedFilesFromCommit(repoDir, "0123456789abcdef", cts.Token));
986+
() => GitHelper.GetChangedFilesFromCommit(repoDir, commitId, cts.Token));
986987

987988
stopwatch.Stop();
988989
Assert.Equal(cts.Token, ex.CancellationToken);
@@ -1835,27 +1836,29 @@ exit 0
18351836
File.SetUnixFileMode(script, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute);
18361837
}
18371838

1838-
private static void WriteFakeGitThatHangsOnDiffTree(string directory)
1839+
private static void WriteFakeGitThatHangsOnDiffTree(string directory, string verifiedCommit)
18391840
{
18401841
var script = Path.Combine(directory, "git");
1841-
File.WriteAllText(script, $$"""
1842+
File.WriteAllText(script, """
18421843
#!/bin/sh
18431844
if [ "$1" = "rev-parse" ]; then
18441845
if [ "$2" = "--symbolic-full-name" ]; then
18451846
exit 0
18461847
fi
18471848
if [ "$2" = "--verify" ]; then
1848-
printf '%s\n' '0123456789abcdef0123456789abcdef01234567'
1849+
printf '%s\n' '__VERIFIED_COMMIT__'
18491850
exit 0
18501851
fi
18511852
fi
18521853
if [ "$1" = "diff-tree" ]; then
18531854
printf '%s\n' "$$" > "$(dirname "$0")/diff-tree.pid"
1854-
sleep {{FakeGitHangSeconds}}
1855+
sleep __HANG_SECONDS__
18551856
exit 0
18561857
fi
18571858
exit 1
1858-
""");
1859+
"""
1860+
.Replace("__VERIFIED_COMMIT__", verifiedCommit, StringComparison.Ordinal)
1861+
.Replace("__HANG_SECONDS__", FakeGitHangSeconds.ToString(System.Globalization.CultureInfo.InvariantCulture), StringComparison.Ordinal));
18591862
if (!OperatingSystem.IsWindows())
18601863
File.SetUnixFileMode(script, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute);
18611864
}

0 commit comments

Comments
 (0)