Skip to content

Commit 832f0ce

Browse files
Widthdomclaude
andauthored
Fix empty IL from ilspycmd -o fallback, surface disassembler failures, and drop the redundant retry (#332)
* Fix ilspycmd -o fallback to read IL from its output directory ilspycmd treats -o as an output directory and writes <input file name without extension>.il inside it, leaving stdout empty. nildiff passed a file path, so after a successful exit File.Exists(tempOut) was false, the empty stdout was used, and the fallback always produced empty IL while leaking ilspy_out_* directories. Pass a fresh temporary directory, read the input-named IL file from it, and remove the directory recursively after every attempt, including failures and timeouts. FakeDisassembler now emulates the real ilspycmd -o semantics. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0169z7S1N3Vmq8rHkry7EDVa * Treat disassembler runs that exit 0 without IL as failures A run that exited 0 but produced no IL was accepted as successful empty IL. That skipped the remaining argument sets and disassemblers, so the IL comparison retried the same deterministic empty result until its retry limit and failed, with nothing explaining why. Now such a run counts toward the failure blacklist, logs a console warning with the command, file, ilspycmd output directory (noting "(no IL file found)" when ilspycmd wrote no IL file), and stderr, and falls through to the next argument set or disassembler. An IL cache hit that holds only disassembler notices is removed via the new ILCache.RemoveIL and regenerated instead of becoming empty IL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0169z7S1N3Vmq8rHkry7EDVa * Log each failed disassembly attempt and show timeouts on the console A timed-out attempt was silent unless every disassembler failed, so the DisassemblerTimeoutSeconds guidance in the TimeoutException never reached users whose run fell back to another argument set or tool. Log every failed attempt with the file, command, and working directory. Timeouts are environment-dependent and actionable, so they are console warnings that keep the DisassemblerTimeoutSeconds guidance. Start failures and non-zero exits are routine fallback steps (e.g. a candidate tool that is not installed) and go to the log file only to avoid flooding the console; the final error still reports the root cause when every attempt fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0169z7S1N3Vmq8rHkry7EDVa * Remove the raw-disassembly retry from IL comparison ILOutputService re-disassembled the same old/new pair up to 5 times when a raw side was empty. The disassembler service now treats a run that exits 0 without IL as a failed attempt and falls back across argument sets and disassemblers itself, and an empty result is deterministic for a given tool and assembly, so the retry only repeated the same outcome. Disassemble each pair once. An empty raw side, possible only from a non-conforming IDotNetDisassembleService implementation, fails immediately with an error diagnostic; diagnostics no longer carry Attempt= / WillRetry=. Filtered-empty sides are still logged as warnings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0169z7S1N3Vmq8rHkry7EDVa --------- Co-authored-by: Claude <noreply@anthropic.com>
2 parents d42e1c8 + d499924 commit 832f0ce

17 files changed

Lines changed: 987 additions & 281 deletions

‎CHANGELOG.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
99

1010
### [Unreleased]
1111

12+
#### Removed
13+
14+
- **IL comparison no longer re-disassembles a pair when either side's raw IL is empty** — `ILOutputService` used to retry the same old/new pair up to 5 attempts when the raw IL of either side (old or new) was empty. The disassembler service now treats a run that exits 0 without IL as a failed attempt and falls back across argument sets and disassemblers itself, and an empty result is deterministic for a given tool and assembly, so the retry only repeated the same outcome. Each pair is disassembled once; empty raw IL on either side (possible only from a non-conforming `IDotNetDisassembleService` implementation) fails immediately with an error diagnostic, and diagnostics no longer include `Attempt=` / `WillRetry=`. Filtered-empty sides are still logged as warnings. Affected: `Services/ILOutputService.cs`, `USER_GUIDE.md`. Tests: `DiffDotNetAssembliesAsync_WhenRawIlSideIsEmpty_ThrowsWithoutRetrying`, `DiffDotNetAssembliesAsync_WhenFilteredIlSideIsEmpty_LogsWarningAndCompares`.
15+
1216
#### Fixed
1317

18+
- **ilspycmd `-o` fallback reads the IL it actually writes** — `ilspycmd -o` takes an output directory and writes `<input name>.il` inside it, but nildiff passed a file path, so the fallback always returned empty IL after a successful exit and left `ilspy_out_*` directories in the temp folder. nildiff now passes a fresh temporary directory, reads the generated `<input name>.il` file, and deletes the directory recursively after every attempt, including failures and timeouts. Affected: `Services/DotNetDisassembleService.cs`, `Services/DotNetDisassembleService.Streaming.cs`, `Services/DotNetDisassembleService.VersionLabel.cs`, `FolderDiffIL4DotNet.Tests/Helpers/FakeDisassemblerProgram.cs`. Tests: `DisassembleAsync_WhenIlspyStdoutModeFails_ReadsIlFromOutputDirectoryAndRemovesIt`, `DisassemblePairAsLinesWithSameDisassemblerAsync_WhenIlspyStdoutModeFails_ReadsIlFromOutputDirectoryAndRemovesIt`, `ResolveIlspyOutputFile_ReturnsInputNamedIlFileOnly`, `BuildArgSets_IlspyCommand_PassesTemporaryOutputDirectoryToOutputFlag`, `CleanupTemporaryPathBestEffort_WhenPathIsDirectory_DeletesItRecursivelyWithoutWarning`.
19+
- **Disassembler runs that exit 0 without IL are failures** — Such runs were accepted as successful empty IL, which skipped the remaining argument sets and disassemblers and made IL comparison fail after its raw-disassembly retries. They now count toward the disassembler failure blacklist, log a console warning with the command, file, ilspycmd output directory (marked `(no IL file found)` when ilspycmd wrote no IL file), and stderr, and continue with the next argument set or disassembler. IL cache hits that contain only disassembler notices are removed and regenerated instead of becoming empty IL. Added `ILCache.RemoveIL`. Affected: `Services/DotNetDisassembleService.cs`, `Services/DotNetDisassembleService.Streaming.cs`, `Services/DotNetDisassembleService.OutputSanitizer.cs`, `Services/Caching/ILCache.cs`, `doc/TROUBLESHOOTING.md`. Tests: `DisassembleAsync_WhenPrimaryToolExitsZeroWithoutIl_LogsStderrAndFallsBackToNextTool`, `DisassemblePairAsLinesWithSameDisassemblerAsync_WhenPrimaryToolExitsZeroWithoutIl_LogsStderrAndFallsBackToNextTool`, `DisassemblePairAsLinesWithSameDisassemblerAsync_WhenEveryToolExitsZeroWithoutIl_ThrowsInsteadOfReturningEmptyIl`, `DisassembleAsync_WhenCachedIlContainsOnlyToolNotices_RemovesEntryAndRegeneratesIl`, `ILCacheRemoveIL_RemovesMemoryAndDiskEntries`, `ContainsIlContent_DetectsAnyLineThatIsNeitherBlankNorToolNotice`.
20+
- **Disassembler timeouts are reported when a fallback succeeds** — A timed-out attempt was silent unless every disassembler failed, so its `DisassemblerTimeoutSeconds` guidance never reached users whose run fell back to another argument set or tool. Each failed attempt is now logged with the file, command, and working directory: timeouts as console warnings that keep the `DisassemblerTimeoutSeconds` guidance, and start failures and non-zero exits in the log file only, because they are routine fallback steps (for example, a candidate tool that is not installed) and the final error already reports the root cause when every attempt fails. Affected: `Services/DotNetDisassembleService.cs`, `Services/DotNetDisassembleService.Streaming.cs`, `USER_GUIDE.md`, `doc/TROUBLESHOOTING.md`. Tests: `DisassemblePairAsLinesWithSameDisassemblerAsync_WhenAttemptTimesOut_LogsTimeoutGuidanceToConsoleAndFallsBack`, `DisassembleAsync_WhenAttemptExitsNonZero_LogsFailureToFileOnlyAndFallsBack`.
1421
- **npm audit CI uses patched brace-expansion** — Updated the 2.x override and lockfile from `2.1.4` to `2.1.7`, resolving the reported denial-of-service vulnerabilities and the transitive `minimatch` finding without adding audit exceptions.
1522
- **npm audit CI uses patched js-yaml** — Updated the 3.x override and lockfile to `3.15.2`, resolving `GHSA-2883-xcg3-v3hh` without adding an audit exception.
1623
- **Benchmark regression CI compares matching execution environments** — Preserved BenchmarkDotNet host metadata and partitioned trusted history by CPU, core topology, OS, architecture, runtime/SDK, build configuration, and BenchmarkDotNet version. Mixed-host legacy history starts a visible five-sample warmup per environment; warning/failure thresholds, ancestry checks, and trusted publication restrictions remain unchanged. Added regression coverage for environment isolation, invalid host metadata, report combination, and real slowdowns within one environment.
@@ -1770,8 +1777,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
17701777

17711778
### [Unreleased]
17721779

1780+
#### 削除
1781+
1782+
- **IL 比較で old/new のいずれか片側でも raw IL が空のとき、ペアを再逆アセンブルしないように変更** — `ILOutputService` は old/new のいずれか片側でも raw IL が空の場合、同じ old/new ペアを最大 5 回まで再試行していました。逆アセンブルサービスが、終了コード 0 で IL を出さない実行を失敗した試行として扱い、引数セットと逆アセンブラのフォールバックを自ら行うようになったこと、また空の結果は同じツールとアセンブリの組み合わせでは毎回同じになることから、この再試行は同じ結果を繰り返すだけでした。各ペアの逆アセンブルは 1 回にし、いずれか片側でも raw IL が空の場合(規約に従わない `IDotNetDisassembleService` 実装でのみ起こり得る)はエラー診断を出して即座に失敗させます。診断から `Attempt=` / `WillRetry=` を除きました。フィルタ後に空になった側は引き続き警告としてログ出力します。対象: `Services/ILOutputService.cs`, `USER_GUIDE.md`。テスト: `DiffDotNetAssembliesAsync_WhenRawIlSideIsEmpty_ThrowsWithoutRetrying`, `DiffDotNetAssembliesAsync_WhenFilteredIlSideIsEmpty_LogsWarningAndCompares`。
1783+
17731784
#### 修正
17741785

1786+
- **ilspycmd の `-o` フォールバックで実際に書き出された IL を読むように修正** — `ilspycmd -o` は出力ディレクトリを受け取り、その中に `<入力名>.il` を書き出しますが、nildiff はファイルパスを渡していたため、このフォールバックは正常終了しても常に空の IL を返し、一時フォルダに `ilspy_out_*` ディレクトリを残していました。新しい一時ディレクトリを渡して生成された `<入力名>.il` ファイルを読み取り、失敗やタイムアウトを含むすべての試行の後にディレクトリを再帰的に削除するようにしました。対象: `Services/DotNetDisassembleService.cs`, `Services/DotNetDisassembleService.Streaming.cs`, `Services/DotNetDisassembleService.VersionLabel.cs`, `FolderDiffIL4DotNet.Tests/Helpers/FakeDisassemblerProgram.cs`。テスト: `DisassembleAsync_WhenIlspyStdoutModeFails_ReadsIlFromOutputDirectoryAndRemovesIt`, `DisassemblePairAsLinesWithSameDisassemblerAsync_WhenIlspyStdoutModeFails_ReadsIlFromOutputDirectoryAndRemovesIt`, `ResolveIlspyOutputFile_ReturnsInputNamedIlFileOnly`, `BuildArgSets_IlspyCommand_PassesTemporaryOutputDirectoryToOutputFlag`, `CleanupTemporaryPathBestEffort_WhenPathIsDirectory_DeletesItRecursivelyWithoutWarning`。
1787+
- **終了コード 0 で IL を出さない逆アセンブラ実行を失敗として扱うように修正** — このような実行は空の IL として成功扱いされていたため、残りの引数セットや逆アセンブラが試されず、IL 比較は raw 逆アセンブルの再試行後に失敗していました。逆アセンブラ失敗のブラックリスト計数に含め、コマンド、ファイル、ilspycmd の出力ディレクトリ(ilspycmd が IL ファイルを書かなかった場合は `(no IL file found)` を付記)、stderr を含む警告をコンソールに出力したうえで、次の引数セットまたは逆アセンブラへ進むようにしました。逆アセンブラの通知行だけを含む IL キャッシュヒットは、空の IL にせず削除して再生成します。`ILCache.RemoveIL` を追加しました。対象: `Services/DotNetDisassembleService.cs`, `Services/DotNetDisassembleService.Streaming.cs`, `Services/DotNetDisassembleService.OutputSanitizer.cs`, `Services/Caching/ILCache.cs`, `doc/TROUBLESHOOTING.md`。テスト: `DisassembleAsync_WhenPrimaryToolExitsZeroWithoutIl_LogsStderrAndFallsBackToNextTool`, `DisassemblePairAsLinesWithSameDisassemblerAsync_WhenPrimaryToolExitsZeroWithoutIl_LogsStderrAndFallsBackToNextTool`, `DisassemblePairAsLinesWithSameDisassemblerAsync_WhenEveryToolExitsZeroWithoutIl_ThrowsInsteadOfReturningEmptyIl`, `DisassembleAsync_WhenCachedIlContainsOnlyToolNotices_RemovesEntryAndRegeneratesIl`, `ILCacheRemoveIL_RemovesMemoryAndDiskEntries`, `ContainsIlContent_DetectsAnyLineThatIsNeitherBlankNorToolNotice`。
1788+
- **フォールバックが成功した場合も逆アセンブラのタイムアウトを通知するように修正** — タイムアウトした試行は、すべての逆アセンブラが失敗しない限り何も出力されなかったため、別の引数セットやツールへフォールバックした実行では `DisassemblerTimeoutSeconds` の案内が利用者に届きませんでした。失敗した各試行を、ファイル、コマンド、作業ディレクトリとともにログ出力するようにしました。タイムアウトは `DisassemblerTimeoutSeconds` の案内を含む警告としてコンソールにも出力し、起動失敗と非 0 終了はログファイルのみに記録します。後者はフォールバックの通常過程(未インストールの候補ツール等)であり、すべての試行が失敗した場合は最終エラーが原因を報告するためです。対象: `Services/DotNetDisassembleService.cs`, `Services/DotNetDisassembleService.Streaming.cs`, `USER_GUIDE.md`, `doc/TROUBLESHOOTING.md`。テスト: `DisassemblePairAsLinesWithSameDisassemblerAsync_WhenAttemptTimesOut_LogsTimeoutGuidanceToConsoleAndFallsBack`, `DisassembleAsync_WhenAttemptExitsNonZero_LogsFailureToFileOnlyAndFallsBack`。
17751789
- **npm audit CI で修正版 brace-expansion を使用** — 2.x override と lockfile を `2.1.4` から `2.1.7` に更新し、監査例外を追加せず、報告されたサービス拒否の脆弱性と依存先から波及した `minimatch` の検出を解消しました。
17761790
- **npm audit CI で修正版 js-yaml を使用** — 3.x override と lockfile を `3.15.2` に更新し、監査例外を追加せず `GHSA-2883-xcg3-v3hh` を解消しました。
17771791
- **ベンチマーク回帰 CI を同一実行環境で比較** — BenchmarkDotNet のホスト情報を保持し、CPU、コア構成、OS、アーキテクチャ、runtime/SDK、ビルド構成、BenchmarkDotNet バージョンごとに信頼済み履歴を分離しました。旧来のホスト混在履歴は環境ごとに明示的な 5 サンプルのウォームアップから開始し、warning/failure 閾値、祖先チェック、信頼済み公開の制約は維持します。環境分離、不正なホスト情報、レポート結合、同一環境内での実際の遅化に回帰テストを追加しました。

‎FolderDiffIL4DotNet.Tests/Helpers/FakeDisassemblerProgram.cs‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
var failPattern = GetEnv("FAIL_PATTERN");
3131
var failExit = int.TryParse(GetEnv("FAIL_EXIT"), out var fe) ? fe : 90;
3232
var counterPath = GetEnv("COUNTER_PATH");
33+
// Exit code used only when no "-o" is passed (simulates a stdout-mode failure).
34+
// "-o" が無い場合にだけ使う終了コード(stdout モードの失敗を再現)。
35+
var stdoutModeExit = int.TryParse(GetEnv("STDOUT_EXIT"), out var se) ? se : (int?)null;
36+
// "1" writes no IL at all (an empty environment value cannot be set portably).
37+
// "1" で IL を一切書かない(空文字の環境変数は移植性のある設定ができないため)。
38+
var emptyOutput = GetEnv("EMPTY_OUTPUT") == "1";
39+
var stderrOutput = GetEnv("STDERR");
40+
var sleepMilliseconds = int.TryParse(GetEnv("SLEEP_MS"), out var sm) ? sm : 0;
3341

3442
// Handle version flags / バージョンフラグの処理
3543
if (cmdArgs.Any(a => a == "--version" || a == "-v" || a == "-h"))
@@ -47,5 +55,27 @@
4755
if (!string.IsNullOrEmpty(failPattern) && cmdArgs.Any(a => a.EndsWith(failPattern, StringComparison.Ordinal)))
4856
return failExit;
4957

50-
Console.WriteLine(output);
58+
if (sleepMilliseconds > 0)
59+
Thread.Sleep(sleepMilliseconds);
60+
61+
if (!string.IsNullOrEmpty(stderrOutput))
62+
Console.Error.WriteLine(stderrOutput);
63+
64+
// Emulate ilspycmd: "-o" names an output DIRECTORY and "<input name>.il" is written inside it; stdout stays empty.
65+
// ilspycmd を模倣: "-o" は出力ディレクトリを指し、その中に "<入力名>.il" を書き出す。stdout には何も出さない。
66+
var outputOptionIndex = Array.IndexOf(cmdArgs, "-o");
67+
if (outputOptionIndex >= 0 && outputOptionIndex + 1 < cmdArgs.Length)
68+
{
69+
var outputDirectory = cmdArgs[outputOptionIndex + 1];
70+
Directory.CreateDirectory(outputDirectory);
71+
if (!emptyOutput)
72+
File.WriteAllText(Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(cmdArgs[^1]) + ".il"), output + Environment.NewLine);
73+
return exit;
74+
}
75+
76+
if (stdoutModeExit.HasValue)
77+
return stdoutModeExit.Value;
78+
79+
if (!emptyOutput)
80+
Console.WriteLine(output);
5181
return exit;

0 commit comments

Comments
 (0)