Skip to content

Commit fc7e302

Browse files
authored
Isolate console-sensitive tests from concurrent logging (#4813)
* Fix console-sensitive test isolation (#4798) * Cover all global console capture tests (#4798)
1 parent dbc7903 commit fc7e302

12 files changed

Lines changed: 70 additions & 13 deletions

TESTING_GUIDE.md

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
category: fixed
3+
issues:
4+
- 4798
5+
affected:
6+
- tests/CodeIndex.Tests/AuditLogSinkTests.cs
7+
- tests/CodeIndex.Tests/CliFlagSchemaTests.cs
8+
- tests/CodeIndex.Tests/CommandErrorWriterTests.cs
9+
- tests/CodeIndex.Tests/TestConsoleLock.cs
10+
- tests/CodeIndex.Tests/ConsoleCaptureTests.cs
11+
- tests/CodeIndex.Tests/DiffCommandHelpersTests.cs
12+
- tests/CodeIndex.Tests/LicensePolicyTests.cs
13+
- tests/CodeIndex.Tests/ProgramCliTests.cs
14+
- tests/CodeIndex.Tests/SymbolExtractorTests.cs
15+
- tests/CodeIndex.Tests/TestTelemetryTests.cs
16+
- TESTING_GUIDE.md
17+
---
18+
19+
## English
20+
21+
- **Console-sensitive tests no longer capture concurrent request-id logs (#4798)** — every test class that owns process-global console streams now belongs to a non-parallel collection, preventing MCP request-id and global diagnostic lines from unrelated tests from entering captured stdout or stderr.
22+
23+
## 日本語
24+
25+
- **console-sensitive test が並行実行された request-id log を取り込まないようになりました (#4798)** — process-global な console stream を占有する全テストクラスを non-parallel collection に所属させ、無関係なテストの MCP request-id や global diagnostic 行が capture 中の stdout / stderr に混入することを防ぎます。

tests/CodeIndex.Tests/AuditLogSinkTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace CodeIndex.Tests;
1010

11+
[Collection("Console sensitive")]
1112
public class AuditLogSinkTests
1213
{
1314
[Fact]

tests/CodeIndex.Tests/CliFlagSchemaTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace CodeIndex.Tests;
1414
/// #1570 で導入した「フラグ単一情報源」の契約を守るためのテスト群。スキーマと
1515
/// 補完スクリプト、コマンド一覧、parser-vs-completion の許容差分がずれた瞬間に失敗する。
1616
/// </summary>
17+
[Collection("Console sensitive")]
1718
public class CliFlagSchemaTests
1819
{
1920
[Fact]

tests/CodeIndex.Tests/CommandErrorWriterTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CodeIndex.Tests;
44

5+
[Collection("Console sensitive")]
56
public class CommandErrorWriterTests
67
{
78
[Fact]

tests/CodeIndex.Tests/ConsoleCaptureTests.cs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,38 @@ namespace CodeIndex.Tests;
66
public class ConsoleCaptureTests
77
{
88
[Fact]
9-
public void ImportCancellationFixture_UsesConsoleSensitiveCollection_Issue4650()
9+
public void ConsoleSensitiveCollection_AssignsGlobalCaptureClassesAndDisablesParallelization_Issues4650_4798()
1010
{
11-
var attribute = Assert.Single(
12-
typeof(ExportImportCommandRunnerCancellationTests).CustomAttributes,
13-
static candidate => candidate.AttributeType == typeof(CollectionAttribute));
14-
var collectionName = Assert.Single(attribute.ConstructorArguments);
11+
Type[] consoleSensitiveTypes =
12+
[
13+
typeof(AuditLogSinkTests),
14+
typeof(CliFlagSchemaTests),
15+
typeof(CommandErrorWriterTests),
16+
typeof(DiffCommandHelpersTests),
17+
typeof(ExportImportCommandRunnerCancellationTests),
18+
typeof(LicensePolicyTests),
19+
typeof(ProgramCliTests),
20+
typeof(SymbolExtractorTests),
21+
typeof(TestTelemetryTests),
22+
];
1523

16-
Assert.Equal("Console sensitive", collectionName.Value);
24+
foreach (var type in consoleSensitiveTypes)
25+
{
26+
var attribute = Assert.Single(
27+
type.CustomAttributes,
28+
static candidate => candidate.AttributeType == typeof(CollectionAttribute));
29+
var collectionName = Assert.Single(attribute.ConstructorArguments);
30+
Assert.Equal("Console sensitive", collectionName.Value);
31+
}
32+
33+
var definition = Assert.Single(
34+
typeof(ConsoleSensitiveCollection).CustomAttributes,
35+
static candidate => candidate.AttributeType == typeof(CollectionDefinitionAttribute));
36+
var disableParallelization = Assert.Single(
37+
definition.NamedArguments,
38+
static candidate => candidate.MemberName == nameof(CollectionDefinitionAttribute.DisableParallelization));
39+
40+
Assert.True(Assert.IsType<bool>(disableParallelization.TypedValue.Value));
1741
}
1842

1943
[Fact]

tests/CodeIndex.Tests/DiffCommandHelpersTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace CodeIndex.Tests;
55

6+
[Collection("Console sensitive")]
67
public sealed class DiffCommandHelpersTests
78
{
89
[Fact]

tests/CodeIndex.Tests/LicensePolicyTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace CodeIndex.Tests;
66
/// Guards licensing and distribution metadata from silently drifting back to
77
/// permissive productization defaults.
88
/// </summary>
9+
[Collection("Console sensitive")]
910
public class LicensePolicyTests
1011
{
1112
private static readonly string[] CanonicalLegalNoticeFiles =

tests/CodeIndex.Tests/ProgramCliTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace CodeIndex.Tests;
1616
/// Black-box CLI tests for Program entrypoint behavior.
1717
/// Program エントリポイント挙動のブラックボックステスト。
1818
/// </summary>
19+
[Collection("Console sensitive")]
1920
public class ProgramCliTests
2021
{
2122
[ProductionRuntimeFact]

tests/CodeIndex.Tests/SymbolExtractorTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace CodeIndex.Tests;
1616
/// Tests for SymbolExtractor.
1717
/// SymbolExtractorのテスト。
1818
/// </summary>
19+
[Collection("Console sensitive")]
1920
public partial class SymbolExtractorTests
2021
{
2122
private static void AssertSymbolsContain(

0 commit comments

Comments
 (0)