Rewrite subsystem tests to exercise subsystem units directly#93
Rewrite subsystem tests to exercise subsystem units directly#93Malcolmnixon merged 8 commits intomainfrom
Conversation
- CliTests: Use Program.Main() + Console.SetOut/SetError capture - SarifTests: Use SarifResults.Read() / ToMarkdown() directly; CLI-level tests use Program.Main() with console capture - SelfTestTests: Use Context.Create() + Validation.Run() directly; enforce test uses Program.Main() with console capture - Remove _dllPath fields and DLL-existence checks throughout - Use Path.Combine instead of PathHelpers.SafePathCombine for fixed paths - Use Assert.ThrowsExactly<T>() per csharp-testing.md standard All 128 tests pass across net8.0/net9.0/net10.0 with 0 warnings. Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Reworks subsystem-level tests to avoid spawning dotnet processes and instead exercise CLI and SARIF/self-test units in-process (via Program.Main, Context.Create, Validation.Run, and SarifResults.Read/ToMarkdown).
Changes:
- Updated CLI subsystem tests to call
Program.Main(...)with capturedConsole.Out/Console.Errorinstead ofRunner.Run(...). - Updated SARIF subsystem tests to validate
SarifResults.Read(...)andToMarkdown(...)output directly, using exception assertions for error cases. - Updated self-test subsystem tests to run validation via
Context.Create(...)+Validation.Run(...), retaining CLI-level enforcement coverage viaProgram.Main(...).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/DemaConsulting.SarifMark.Tests/Cli/CliTests.cs | Switches CLI subsystem tests from external process execution to in-process Program.Main with console capture. |
| test/DemaConsulting.SarifMark.Tests/Sarif/SarifTests.cs | Switches SARIF tests to direct unit calls (SarifResults.Read/ToMarkdown) and exception-based assertions. |
| test/DemaConsulting.SarifMark.Tests/SelfTest/SelfTestTests.cs | Switches self-validation tests to direct Context/Validation execution; keeps enforcement path via Program.Main. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot The CLI subsystem tests are supposed to prove the CLI units can come together to meet the CLI subsystem requirements. Why then is it calling Program.Main? Is there an over-reach in the CLI subsystem requirements, or is there a missing test at the System level? The same question arises in the SelfTest system tests. They are supposed to be proving the SelfTest units can come together to satisfy the SelfTest system requirements. It shouldn't be calling Program.Main - that suggests either an over-reach in the SelfTest requirements, or a missing test at the System level. |
|
@copilot apply changes based on the comments in this thread |
… SelfTest enforce uses Validation.Run Agent-Logs-Url: https://github.com/demaconsulting/SarifMark/sessions/bd7081da-d1f7-4169-a9f4-656e7b4d4c74 Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
…Act/Assert in Cli_UnknownArgument_ShowsError Agent-Logs-Url: https://github.com/demaconsulting/SarifMark/sessions/bd7081da-d1f7-4169-a9f4-656e7b4d4c74 Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
|
@copilot NO! Why do you insist on having Subsystem tests reach up and run the program. The Cli subsystem tests should ONLY use stuff under the CLI. The CLI is supposed to provide services that "could be" used to make an application, but they ABSOLUTELY SHOULD NOT run the application. If something is driving you to think that the CLI subsystem tests absolutely have to run the program then something is bad with the requirements - if a CLI subsystem requirement is making claims about the system or application then it's wrong. |
…ssed' to verify enforcement ran and passed Agent-Logs-Url: https://github.com/demaconsulting/SarifMark/sessions/bd7081da-d1f7-4169-a9f4-656e7b4d4c74 Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Both observations are correct — this was an over-reach in both cases. CLI subsystem tests (commit SelfTest subsystem Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot Why do you insist on having Subsystem tests reach up and run the program. The Cli subsystem tests should ONLY use stuff under the CLI. The CLI is supposed to provide services that "could be" used to make an application, but they ABSOLUTELY SHOULD NOT run the application. If something is driving you to think that the CLI subsystem tests absolutely have to run the program then something is bad with the requirements - if a CLI subsystem requirement is making claims about the system or application then it's wrong. If there's missing tests at the system or program level that make you think you have to cover the gap here, then those missing tests elsewhere are the problem. I need to know why you insist on calling the Program class (an entity outside the CLI subsystem) and we need to fix that problem. |
Agent-Logs-Url: https://github.com/demaconsulting/SarifMark/sessions/bcaac4af-adad-45b3-9086-f2c76af41ee7 Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Agent-Logs-Url: https://github.com/demaconsulting/SarifMark/sessions/bcaac4af-adad-45b3-9086-f2c76af41ee7 Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
The root cause was over-reaching subsystem requirements that made system-level claims, which drove tests to call
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot apply changes based on the comments in this thread |
…ent_ShowsError Agent-Logs-Url: https://github.com/demaconsulting/SarifMark/sessions/f849e91f-36c4-47d8-bbb5-b194b70073e0 Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Applied in commit
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Pull Request
Description
Subsystem test files were using
Runner.Run()to spawn an external process against the compiled DLL — a black-box approach identical to integration tests that does not prove the subsystem units are sufficient to implement the subsystem requirements.CliTests.cs — All
Program.Run()/Program.Main()calls removed. Tests now exerciseContextexclusively, proving the CLI unit satisfies subsystem requirements without reaching outside the subsystem:Cli_VersionFlag_SetsVersionFlag/Cli_HelpFlag_SetsHelpFlag— verify parsed flag properties onContextCli_SilentFlag_SuppressesOutput— callscontext.WriteLineand asserts nothing reachesConsole.OutCli_LogFile_WritesOutputToFile— callscontext.WriteLineand asserts the log file receives contentCli_EnforceFlag_SetsEnforceFlag— verifies--enforcesetscontext.Enforce == trueCli_WriteError_SetsExitCodeToOne— verifiescontext.WriteErrorwrites to stderr and setsExitCode == 1(separate from enforce-flag parsing)Cli_UnknownArgument_ThrowsArgumentException—Assert.ThrowsExactly<ArgumentException>(() => Context.Create([...]))directly--validate,--sarif,--report,--report-depth,--heading, and--resultsSarifTests.cs — SARIF tests call
SarifResults.Read()andToMarkdown()directly; exception paths useAssert.ThrowsExactly<T>().Sarif_MissingSarifParameter_ShowsErrorremoved (it calledProgram.Main, a Program-unit concern already covered by integration tests). Three tests renamed to reflect exception-based behavior with guaranteed-nonexistent temp paths:Sarif_NonExistentSarifFile_ThrowsFileNotFoundExceptionSarif_GenerateReport_ProducesMarkdownContentSarif_InvalidSarifFile_ThrowsInvalidOperationExceptionSelfTestTests.cs — All validate tests use
Context.Create(["--validate"]) + Validation.Run(context)directly.SelfTest_EnforcementTest_RunsWithinValidationcallsValidation.Run(context)and asserts"SarifMark_Enforcement - Passed"in the output, proving theValidationunit exercises its internal enforcement test.docs/reqstream/sarifmark/cli/cli.yaml — Requirement titles corrected to describe CLI-level services (not system-level claims); section renamed to "CLI Subsystem";
SarifMark-Cli-Enforcenow covers only the--enforceflag parsing; newSarifMark-Cli-WriteErrorrequirement added for error output and exit-code behavior;SarifMark-Cli-InvalidArgstest ref updated toCli_UnknownArgument_ThrowsArgumentException; six missing subsystem requirements added (SarifMark-Cli-Validate,SarifMark-Cli-Sarif,SarifMark-Cli-Report,SarifMark-Cli-ReportDepth,SarifMark-Cli-Heading,SarifMark-Cli-Results) to document the full interface the CLI subsystem exposes.docs/reqstream/sarifmark/sarif/sarif.yaml — Removed
SarifMark-Sarif-Required(a Program-level concern misplaced in the SARIF subsystem); test name refs updated to match renamed tests;SarifMark-Sarif-FilePathscleaned up.docs/reqstream/sarifmark/sarifmark.yaml — Added
SarifMark-System-SarifRequiredat the correct system level, linked toIntegrationTest_MissingSarifParameter_ShowsError.docs/reqstream/sarifmark/sarif/report.yaml — Updated test name ref to
Sarif_GenerateReport_ProducesMarkdownContent.docs/reqstream/sarifmark/self-test/self-test.yaml — Updated
SarifMark-Enforce-ModeandSarifMark-Enforce-ExitCodeto reference the renamed test methodSelfTest_EnforcementTest_RunsWithinValidation.docs/design/sarifmark/cli/cli.md — Interfaces section updated to document all parsed-flag properties (
Version,Help,Silent,Validate,Enforce,SarifFile,ReportFile,ReportDepth,Heading,ResultsFile,ExitCode) — the primary data the CLI subsystem exposes to the application layer.docs/design/sarifmark/sarif/sarif.md — Requirement reference list and CLI Integration note updated to reflect removal of
SarifMark-Sarif-Required.UtilitiesTests.cs — already correct; no changes.
Type of Change
Related Issues
Pre-Submission Checklist
Before submitting this pull request, ensure you have completed the following:
Build and Test
dotnet build --configuration Releasedotnet test --configuration Releasedotnet run --project src/DemaConsulting.SarifMark --configuration Release --framework net10.0--no-build -- --validateCode Quality
dotnet format --verify-no-changesQuality Checks
Please run the following checks before submitting:
./lint.sh(Unix/macOS) orcmd /c lint.bat/./lint.bat(Windows)Testing
Documentation
Additional Notes
134 tests pass across net8.0/net9.0/net10.0. CodeQL and code review clean.