-
Notifications
You must be signed in to change notification settings - Fork 0
level-2: add --severity flag + PowerShell own-check.ps1 #1 --severity {error,warning} (default error): threaded through the core renderer (Finding.render/_github/_msbuild + render_finding), the ownir CLI (--severity, validated; only valid for ownir), own-check.sh, and the composite Action's new 'severity' input. A presentation choice — the finding is still the core's verdict — so a build can show leaks as advisory warnings instead of failing. Resolves P-013 open question #1. #2 scripts/own-check.ps1: a PowerShell twin of own-check.sh so Windows/VS users without bash get the same one-command pipeline (same flags/output). #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8ee41d3
docs: add a how-to for running Own.NET (CLI, Visual Studio Error List…
claude e252ee7
level-2: add --severity flag + PowerShell own-check.ps1
claude b15e588
DI001: captive-dependency check (P-006), core side
claude 3a4d3c3
address CodeRabbit on PR #11: reject ownir-only flags by presence
claude 68b856b
address CodeRabbit on PR #11: harden DI services validation
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| # How-to: run Own.NET on your C# (CLI · CI · Visual Studio) | ||
|
|
||
| Own.NET finds lifetime/resource leaks C# can't express (event/timer leaks, | ||
| undisposed `IDisposable`, ignored `Subscribe()` tokens, `ArrayPool` rent-without- | ||
| return). This guide shows the three ways to actually *run* it on your code. | ||
|
|
||
| > **There is no VSIX and no Roslyn analyzer.** On purpose — the checker is one | ||
| > Python core, and an in-process analyzer would force a second checker in C# (or | ||
| > shell out to Python on every keystroke). Instead the same finding is rendered | ||
| > in a format the host already understands: GitHub annotations for CI, and the | ||
| > **MSBuild diagnostic format** (`file(line): error CODE: …`) that the Visual | ||
| > Studio **Error List** parses for free. See | ||
| > [P-013](proposals/P-013-distribution-surface.md) for the why. | ||
|
|
||
| ## 0. Prerequisites | ||
|
|
||
| The pipeline is two stages — a Roslyn extractor (C#) and the Python core — so you | ||
| need both runtimes plus an Own.NET checkout: | ||
|
|
||
| - **.NET SDK** 8.0+ (`dotnet`) — builds/runs the extractor. | ||
| - **Python** 3.11+ — runs the core. | ||
| - An **Own.NET checkout** somewhere on disk; below it is `$OWN` (e.g. | ||
| `git clone https://github.com/PhysShell/Own.NET ~/own.net`). | ||
|
|
||
| Nothing is installed into your project — the tool reads your `.cs`, it does not | ||
| add a dependency. | ||
|
|
||
| ## 1. From a terminal (the foundation everything else wraps) | ||
|
|
||
| ```bash | ||
| # human-readable (default) | ||
| "$OWN/scripts/own-check.sh" -- path/to/your/Project | ||
|
|
||
| # Visual Studio / MSBuild Error List format | ||
| "$OWN/scripts/own-check.sh" --format msbuild -- path/to/your/Project | ||
|
|
||
| # CI annotations; non-zero exit on any finding | ||
| "$OWN/scripts/own-check.sh" --format github --fail-on-finding -- . | ||
|
|
||
| # advisory: render findings as warnings (won't fail a build) | ||
| "$OWN/scripts/own-check.sh" --format msbuild --severity warning -- path/to/your/Project | ||
| ``` | ||
|
|
||
| `own-check.sh` walks the path for `*.cs` (skipping `bin`/`obj`/`.git`/ | ||
| `node_modules`/`packages` and generated files), runs the extractor → the core, | ||
| and prints findings. `--format msbuild` prints exactly: | ||
|
|
||
| ```text | ||
| src/Vm/CustomerViewModel.cs(12): error OWN001: event 'bus.CustomerChanged' is subscribed (handler 'OnCustomerChanged') but never unsubscribed — the source keeps 'CustomerViewModel' alive (leak) [resource: subscription token] | ||
| ``` | ||
|
|
||
| That line shape is the canonical MSBuild diagnostic — which is the whole trick | ||
| for Visual Studio. | ||
|
|
||
| Exit codes: `0` clean · `1` findings (only with `--fail-on-finding`) · `≥2` a | ||
| hard error (bad facts). Without `--fail-on-finding` the script always exits `0` | ||
| so it never breaks a wrapping build by accident. | ||
|
|
||
| ## 2. In Visual Studio | ||
|
|
||
| Two approaches, cheapest first. | ||
|
|
||
| ### Option A — External Tool (on-demand, no build coupling) — recommended | ||
|
|
||
| Run the check from a menu item and get clickable results. **Tools → External | ||
| Tools… → Add:** | ||
|
|
||
| | Field | Value | | ||
| | --- | --- | | ||
| | Title | `Own.NET leak check` | | ||
| | Command | `bash` (Linux/macOS), or `C:\Program Files\Git\bin\bash.exe` (Git Bash on Windows) | | ||
| | Arguments | `"<OWN>/scripts/own-check.sh" --format msbuild -- "$(ProjectDir)"` | | ||
| | Initial directory | `$(SolutionDir)` | | ||
| | ✔ **Use Output window** | checked | | ||
|
|
||
| Run it from **Tools → Own.NET leak check**. Output appears in the Output window, | ||
| and because the lines are in canonical MSBuild format, Visual Studio makes each | ||
| one **double-click-to-navigate** to the exact file and line. | ||
|
|
||
| > On Windows the script needs a bash (WSL or Git Bash). If you'd rather not, use | ||
| > the raw two-command form from §4 in a `.cmd`/PowerShell External Tool instead. | ||
|
|
||
| ### Option B — MSBuild target (findings in the Error List on every build) | ||
|
|
||
| Drop a `Directory.Build.targets` next to your solution (or add the `<Target>` to | ||
| a `.csproj`): | ||
|
|
||
| ```xml | ||
| <Project> | ||
| <PropertyGroup> | ||
| <!-- Path to your Own.NET checkout. --> | ||
| <OwnNetRoot>/abs/path/to/own.net</OwnNetRoot> | ||
| </PropertyGroup> | ||
|
|
||
| <Target Name="OwnNetLeakCheck" BeforeTargets="Build"> | ||
| <Exec Command="bash "$(OwnNetRoot)/scripts/own-check.sh" --format msbuild --severity warning -- "$(MSBuildProjectDirectory)"" | ||
| ContinueOnError="true" /> | ||
| </Target> | ||
| </Project> | ||
| ``` | ||
|
|
||
| The MSBuild `Exec` task scans the command's output for canonical diagnostic | ||
| lines and raises them as build diagnostics, so they land in the **Error List** | ||
| and the build log without any analyzer. | ||
|
|
||
| **Severity:** `--severity` chooses how the host shows a finding. The target | ||
| above uses `--severity warning` so findings are **advisory** — they appear in | ||
| the Error List but don't fail the build, which is what you want on every | ||
| inner-loop build. Drop `--severity warning` (the default is `error`) if you'd | ||
| rather a leak break the build, e.g. on a release/CI configuration. | ||
|
|
||
| > Note: this runs the extractor build (`dotnet run`) as part of your build, which | ||
| > adds a few seconds. For large solutions prefer Option A or the CI job (§3) over | ||
| > a `BeforeTargets="Build"` hook on every inner-loop build. | ||
|
|
||
| ## 3. In CI (GitHub Actions) | ||
|
|
||
| The reusable composite action annotates the PR diff. Add to a workflow (full | ||
| example in [`examples/ci/own-check.yml`](../examples/ci/own-check.yml)): | ||
|
|
||
| ```yaml | ||
| - uses: actions/checkout@v4 | ||
| - uses: PhysShell/own.net@main # pin a tag for stability | ||
| with: | ||
| path: . | ||
| format: github | ||
| fail-on-finding: "true" | ||
| ``` | ||
|
|
||
| Findings appear as inline `error` annotations on the changed lines, and the | ||
| check goes red. This is the path that needs no local setup at all. | ||
|
|
||
| ## 4. Windows without bash (PowerShell) | ||
|
|
||
| If you have no bash, use the bundled PowerShell twin — same flags, same output, | ||
| no shell dependency: | ||
|
|
||
| ```powershell | ||
| & "$OWN\scripts\own-check.ps1" -Format msbuild -- src\MyApp | ||
| & "$OWN\scripts\own-check.ps1" -Format github -Severity warning -FailOnFinding -- . | ||
| ``` | ||
|
|
||
| Point a Visual Studio External Tool (§2A) at `powershell.exe` with arguments | ||
| `-File "<OWN>\scripts\own-check.ps1" -Format msbuild -- "$(ProjectDir)"`, or an | ||
| MSBuild `Exec` (§2B) at `powershell -File "$(OwnNetRoot)\scripts\own-check.ps1" …`, | ||
| instead of the bash command. | ||
|
|
||
| ## Caveats | ||
|
|
||
| - **Heuristic findings can be false positives** (e.g. ownership handed to a | ||
| callee). Treat output as a reviewer, not a gate, until you've calibrated it on | ||
| your codebase — and prefer `--fail-on-finding` only once it's quiet. | ||
| - **One method at a time, syntax-only.** The extractor does not do | ||
| interprocedural/`async`/whole-program analysis yet (by design — see the | ||
| ROADMAP). It honestly skips what it can't model rather than guessing. | ||
| - **`bin`/`obj`/generated files are skipped**; paths are reported relative to the | ||
| scan root so they resolve in the editor and on the PR. | ||
|
|
||
| For the design rationale and the full surface ladder, see | ||
| [P-013](proposals/P-013-distribution-surface.md). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.