From c72e44c9571e63ecbc56e9a23f4cc0936814c199 Mon Sep 17 00:00:00 2001 From: Widthdom Date: Sat, 22 Aug 2026 16:12:49 +0900 Subject: [PATCH] Fix fake git validation in timeout test (#5130) --- TESTING_GUIDE.md | 2 ++ changelog.d/unreleased/5130.fixed.md | 16 ++++++++++++++++ tests/CodeIndex.Tests/GitHelperTests.cs | 19 +++++++++++-------- 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 changelog.d/unreleased/5130.fixed.md diff --git a/TESTING_GUIDE.md b/TESTING_GUIDE.md index 0bafbfaaf..021f48edd 100644 --- a/TESTING_GUIDE.md +++ b/TESTING_GUIDE.md @@ -19,6 +19,7 @@ Use the full suite by default. Use targeted filters only while iterating locally ## Test Stack +- 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 ^{commit}`, then the test must confirm the timed-out child process is reaped. Keep production single-commit validation strict. - 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. - 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 `` usage, nested-field help text, and examples. - 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" ## テストスタック +- Issue #5130 の commit-diff timeout regression は `diff-tree` に焦点を維持します。fake git は `rev-parse --verify ^{commit}` で検証対象の commit を返し、テストでは timeout した子プロセスが reap されることを確認してください。本番の single-commit validation は厳格なままにします。 - Issue #5128 の compact graph 0件 coverage は `JsonEnvelopeWrapperIssue4585Tests.cs` が担当します。graph-ready な bounded-response fixture を再利用し、明示的な `--fields` の有無の両方で、`callees` が `references` / `callers` と同様に空の compact location envelope と返却件数・総件数0を維持することを検証してください。 - 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` では `` usage、nested-field help text、例を別途固定します。 - #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 は引き続き受理されることを検証してください。 diff --git a/changelog.d/unreleased/5130.fixed.md b/changelog.d/unreleased/5130.fixed.md new file mode 100644 index 000000000..73ccff0ac --- /dev/null +++ b/changelog.d/unreleased/5130.fixed.md @@ -0,0 +1,16 @@ +--- +category: fixed +issues: + - 5130 +affected: + - tests/CodeIndex.Tests/GitHelperTests.cs + - TESTING_GUIDE.md +--- + +## English + +- **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. + +## 日本語 + +- **commit-diff timeout regression が `diff-tree` に到達するようになりました (#5130)** — fake git の validation 応答をテスト対象の一時 commit と一致させ、厳格な single-commit validation を維持しながら timeout 経路で子プロセスの cleanup を検証できるようにしました。 diff --git a/tests/CodeIndex.Tests/GitHelperTests.cs b/tests/CodeIndex.Tests/GitHelperTests.cs index c34edec87..205c6a84f 100644 --- a/tests/CodeIndex.Tests/GitHelperTests.cs +++ b/tests/CodeIndex.Tests/GitHelperTests.cs @@ -732,7 +732,7 @@ public void GetChangedFilesFromCommit_FailsWhenGitCommandTimesOut() var fakeGitDir = Path.Combine(_tempDir, "fake-git-timeout"); Directory.CreateDirectory(fakeGitDir); - WriteFakeGitThatHangsOnDiffTree(fakeGitDir); + WriteFakeGitThatHangsOnDiffTree(fakeGitDir, commitId); var fakeGitPidPath = Path.Combine(fakeGitDir, "diff-tree.pid"); var oldGitExecutablePath = GitHelper.GitExecutablePathOverride; @@ -971,7 +971,8 @@ public void GetChangedFilesFromCommit_CancelDuringGitCommand_ThrowsOperationCanc Directory.CreateDirectory(repoDir); var fakeGitDir = Path.Combine(_tempDir, "fake-git-cancel"); Directory.CreateDirectory(fakeGitDir); - WriteFakeGitThatHangsOnDiffTree(fakeGitDir); + const string commitId = "0123456789abcdef"; + WriteFakeGitThatHangsOnDiffTree(fakeGitDir, commitId); var oldGitExecutablePath = GitHelper.GitExecutablePathOverride; GitHelper.GitExecutablePathOverride = Path.Combine(fakeGitDir, "git"); @@ -982,7 +983,7 @@ public void GetChangedFilesFromCommit_CancelDuringGitCommand_ThrowsOperationCanc var stopwatch = Stopwatch.StartNew(); var ex = Assert.Throws( - () => GitHelper.GetChangedFilesFromCommit(repoDir, "0123456789abcdef", cts.Token)); + () => GitHelper.GetChangedFilesFromCommit(repoDir, commitId, cts.Token)); stopwatch.Stop(); Assert.Equal(cts.Token, ex.CancellationToken); @@ -1835,27 +1836,29 @@ exit 0 File.SetUnixFileMode(script, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute); } - private static void WriteFakeGitThatHangsOnDiffTree(string directory) + private static void WriteFakeGitThatHangsOnDiffTree(string directory, string verifiedCommit) { var script = Path.Combine(directory, "git"); - File.WriteAllText(script, $$""" + File.WriteAllText(script, """ #!/bin/sh if [ "$1" = "rev-parse" ]; then if [ "$2" = "--symbolic-full-name" ]; then exit 0 fi if [ "$2" = "--verify" ]; then - printf '%s\n' '0123456789abcdef0123456789abcdef01234567' + printf '%s\n' '__VERIFIED_COMMIT__' exit 0 fi fi if [ "$1" = "diff-tree" ]; then printf '%s\n' "$$" > "$(dirname "$0")/diff-tree.pid" - sleep {{FakeGitHangSeconds}} + sleep __HANG_SECONDS__ exit 0 fi exit 1 -"""); +""" + .Replace("__VERIFIED_COMMIT__", verifiedCommit, StringComparison.Ordinal) + .Replace("__HANG_SECONDS__", FakeGitHangSeconds.ToString(System.Globalization.CultureInfo.InvariantCulture), StringComparison.Ordinal)); if (!OperatingSystem.IsWindows()) File.SetUnixFileMode(script, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute); }