Skip to content

Commit ed9bd1b

Browse files
PhysShellclaude
andcommitted
feat(producer): physical-anchor column, its fixture contract, and the two-contour gate
THE SLICE. The Roslyn extractor stamps the 1-based column of an owned-resource record's anchor (`ColumnOf`, the sibling of `LineOf`); `ownir.load` validates it; `Finding.column` carries it; SARIF emits `region.startColumn`. The human, github and msbuild surfaces are deliberately untouched. `OWNIR_VERSION` does not move — an additive optional field is not a vocabulary change. NULLABLE, AND NEVER SYNTHESIZED. A producer that does not know a column OMITS the field. There is no in-band "not reported" value: SARIF columns are 1-based, so a substituted 1 is indistinguishable from a real first-column finding, and 0 is not a column. A consumer keying a physical anchor on this has to be able to tell "the analysis did not compute a column" from "the analysis computed column 1". Hence the asymmetry against `line`, which degrades to 0: a present-but-invalid column FAILS LOUD at load() (0, negative, bool, string, float), while the tolerant check_facts door degrades it to None. An absent column is a producer honestly reporting less; a coerced one is a coordinate the analysis never computed, sitting in the anchor identity is keyed on. The renderer's caret heuristic stays out. `Diagnostic._caret_col` recovers a column by pulling a name out of the message and searching the source line, falling back to the indentation — fine for drawing a `^`, disqualifying as a coordinate. Pinned behaviourally (no column is invented) and structurally (neither ownir.py nor diag_sarif.py calls it). `column` is NOT in the finding dedup key. It is an anchor refinement, not part of what a finding is, and including it could only split a group that used to collapse — which would be a change to the finding population, the one thing a physical-anchor slice promised not to touch. THE GATE, in two contours. `producer-differential.yml` is path-filtered: producer-contract 52 checks over synthetic facts. Old column-less fact still accepted and still emits no startColumn; a column reaches Finding and SARIF; invalid columns fail loud; the old and new producers agree on every pattern-level field over one fixture, only the anchor moving; the caret heuristic is absent; and the published schema states what the code enforces. mini-corpus-diff own-check at the PR's merge base AND at its head over the frozen corpus/mini, compared through OwnAudit's projections. Merge base, not a golden: a golden is a claim about when somebody last regenerated it, a merge base is a claim about what the change will land on. The comparator is checked out from OwnAudit, not vendored: a second copy of finding identity inside the repo that emits the findings would drift toward whatever made CI green. The long real-corpus run stays in OwnAudit, manual and nightly, off the PR path. corpus/mini is 12 frozen files, every positive paired with a negative control. Three carry the argument: TwoOnOneLine (two findings on one line need two different columns, and the same finding twice must stay one finding), Indentation (four depths, because an indentation-derived column is only distinguishable from the real one when the subscription does not start its line), and DiCaptive (a finding with NO column, so an expectation that permits a transition cannot be tightened into one that demands it). The first PR to add the corpus has no baseline for it; the job says so and skips, rather than diffing against an absent corpus as though it were an empty one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014xaqHit3rqjg7wykNEwFaR
1 parent 0ded835 commit ed9bd1b

20 files changed

Lines changed: 1263 additions & 8 deletions
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
name: producer differential
2+
3+
# The SHORT contour: two jobs that answer in minutes and gate every PR that
4+
# touches the producer.
5+
#
6+
# producer-contract fixture-scale unit tests on synthetic facts. No .NET, no
7+
# corpus, no network. Seconds.
8+
# mini-corpus-diff own-check at the PR's merge base AND at its head over the
9+
# frozen corpus/mini, compared through OwnAudit's projections.
10+
# Minutes.
11+
#
12+
# The long contour — a real corpus, hours — is OwnAudit's `corpus-differential.yml`,
13+
# run manually and nightly. Keeping it off the PR path is the whole point: a job
14+
# people wait hours for is a job people learn to bypass, and a seven-hour red X
15+
# holds the change hostage to the hardware rather than to its own correctness.
16+
#
17+
# WHY THIS IS PATH-FILTERED
18+
# A README typo cannot change what the producer says about C#, so it does not get a
19+
# .NET build and two extractor runs. Compute spent proving something that could not
20+
# have changed is not thoroughness; it is a slower queue for everyone else.
21+
#
22+
# WHY THE COMPARATOR IS CHECKED OUT INSTEAD OF VENDORED
23+
# Own.NET produces SARIF; OwnAudit compares corpora. Copying the projections here
24+
# would put a second implementation of finding identity in the repository that emits
25+
# the findings — and the two would drift, quietly, in the direction that made CI
26+
# green. The cost is a cross-repo checkout; the alternative is a checker that grades
27+
# its own homework.
28+
29+
permissions:
30+
contents: read
31+
32+
on:
33+
pull_request:
34+
paths:
35+
- "frontend/roslyn/**"
36+
- "ownlang/ownir.py"
37+
- "ownlang/diag_sarif.py"
38+
- "ownlang/diagnostics.py"
39+
- "spec/ownir*"
40+
- "scripts/own-check*"
41+
- "corpus/mini/**"
42+
- "tests/test_ownir*.py"
43+
- "tests/test_diag_sarif.py"
44+
- ".github/workflows/producer-differential.yml"
45+
push:
46+
branches: ["**"]
47+
paths:
48+
- "frontend/roslyn/**"
49+
- "ownlang/ownir.py"
50+
- "ownlang/diag_sarif.py"
51+
- "ownlang/diagnostics.py"
52+
- "spec/ownir*"
53+
- "scripts/own-check*"
54+
- "corpus/mini/**"
55+
- "tests/test_ownir*.py"
56+
- "tests/test_diag_sarif.py"
57+
- ".github/workflows/producer-differential.yml"
58+
workflow_dispatch:
59+
60+
concurrency:
61+
group: producer-differential-${{ github.ref }}
62+
cancel-in-progress: true
63+
64+
jobs:
65+
# The fixture-scale contract. Fast enough to run on a push as well as a PR, so a
66+
# branch that has not opened a PR yet still gets the answer.
67+
producer-contract:
68+
name: producer contract (fixtures, no .NET)
69+
runs-on: ubuntu-latest
70+
steps:
71+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
72+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
73+
with:
74+
python-version: "3.11"
75+
76+
# The physical-anchor contract: an old column-less fact still works and emits
77+
# no startColumn; a column reaches Finding.column and SARIF; an INVALID column
78+
# fails loud at load() while degrading on the tolerant door; the old and new
79+
# producers agree on every pattern-level field over one fixture; and the
80+
# renderer's caret heuristic is nowhere on the path.
81+
- name: physical-anchor column contract
82+
run: python tests/test_ownir_column.py
83+
84+
# The bridge and both SARIF projections around it. A column change that broke
85+
# the OwnIR fact vocabulary or the SARIF log shape would land here first.
86+
- name: OwnIR bridge + SARIF projections
87+
run: |
88+
set -euo pipefail
89+
python tests/test_ownir.py
90+
python tests/test_diag_sarif.py
91+
92+
# The frozen corpus is an input, and an input with a broken file is a run that
93+
# measures nothing. This does not compile C# (that is the next job's .NET
94+
# build); it checks the corpus is present and its inventory has not silently
95+
# shrunk, which is the failure a path filter cannot catch.
96+
- name: frozen mini corpus is intact
97+
run: |
98+
set -euo pipefail
99+
n=$(find corpus/mini -maxdepth 1 -name '*.cs' | wc -l)
100+
[ "$n" -ge 10 ] \
101+
|| { echo "FAIL: corpus/mini has $n .cs files, expected at least 10 — a frozen corpus that shrank is a corpus change, not a producer change (see corpus/mini/README.md)"; exit 1; }
102+
test -f corpus/mini/README.md \
103+
|| { echo "FAIL: corpus/mini/README.md is missing — the freeze policy is part of the corpus"; exit 1; }
104+
echo "corpus/mini: $n .cs files"
105+
106+
# base-vs-head over the frozen corpus. PR and manual only: the comparison is
107+
# defined against a MERGE BASE, and a bare push has no target branch to take one
108+
# against. (`HEAD~1` would answer a different question — "did the last commit
109+
# change anything" — and would pass trivially on any branch that rebases.)
110+
mini-corpus-diff:
111+
name: mini corpus diff (merge-base vs head)
112+
if: github.event_name != 'push'
113+
runs-on: ubuntu-latest
114+
timeout-minutes: 30
115+
steps:
116+
- name: Check out Own.NET (the producer)
117+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
118+
with:
119+
# Full history: the runner takes a merge base and checks out two commits
120+
# as git worktrees. A shallow clone has neither.
121+
fetch-depth: 0
122+
123+
- name: Check out OwnAudit (the comparator)
124+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
125+
with:
126+
repository: PhysShell/OwnAudit
127+
path: ownaudit
128+
persist-credentials: false
129+
130+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
131+
with:
132+
python-version: "3.11"
133+
134+
- uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4
135+
with:
136+
dotnet-version: "8.0.x"
137+
138+
# The extractor is built twice (once per worktree), so restoring from cache is
139+
# most of the difference between "a few minutes" and "long enough to be
140+
# skipped".
141+
- name: Cache NuGet packages
142+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4
143+
with:
144+
path: ~/.nuget/packages
145+
key: nuget-${{ runner.os }}-${{ hashFiles('frontend/roslyn/**/*.csproj') }}
146+
restore-keys: nuget-${{ runner.os }}-
147+
148+
- name: Resolve the baseline
149+
id: base
150+
env:
151+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
152+
run: |
153+
set -euo pipefail
154+
# workflow_dispatch has no PR context; fall back to the default branch.
155+
if [ -z "${BASE_SHA:-}" ]; then
156+
git fetch --quiet origin main
157+
BASE_SHA=$(git rev-parse origin/main)
158+
fi
159+
merge_base=$(git merge-base "$BASE_SHA" HEAD)
160+
echo "sha=$merge_base" >> "$GITHUB_OUTPUT"
161+
# BOOTSTRAP: the very first PR to add corpus/mini has no corpus on the base
162+
# side. own-check would then be handed a path that does not exist, exit in
163+
# its hard-error tier, and abort the run — a confusing red X on the one PR
164+
# that cannot possibly have regressed anything. Detect it and say so
165+
# instead. This is NOT a fallback to an empty baseline: an absent corpus and
166+
# a corpus that produced no findings are different claims, and diffing
167+
# against the second when you have the first is how a whole corpus silently
168+
# reads as "removed".
169+
if git ls-tree -d --name-only "$merge_base" -- corpus/mini | grep -q .; then
170+
echo "have_baseline=true" >> "$GITHUB_OUTPUT"
171+
else
172+
echo "have_baseline=false" >> "$GITHUB_OUTPUT"
173+
fi
174+
echo "merge base: $merge_base"
175+
176+
- name: No baseline corpus yet
177+
if: steps.base.outputs.have_baseline != 'true'
178+
run: |
179+
{
180+
echo "## Mini corpus diff: SKIPPED"
181+
echo
182+
echo "\`corpus/mini\` does not exist at the merge base"
183+
echo "(\`${{ steps.base.outputs.sha }}\`), so there is no baseline to compare"
184+
echo "against. This is expected on the PR that introduces the corpus, and on"
185+
echo "no other PR."
186+
echo
187+
echo "The job is skipped rather than run against an empty baseline: an absent"
188+
echo "corpus and a corpus that produced no findings are different claims, and"
189+
echo "treating the first as the second would report the entire corpus as newly"
190+
echo "appeared."
191+
} >> "$GITHUB_STEP_SUMMARY"
192+
193+
- name: Run the differential
194+
id: diff
195+
if: steps.base.outputs.have_baseline == 'true'
196+
working-directory: ownaudit
197+
run: |
198+
set -euo pipefail
199+
PYTHONUTF8=1 PYTHONPATH=. python3 -m corpusdiff.run_differential \
200+
--repo .. \
201+
--base "${{ steps.base.outputs.sha }}" \
202+
--head HEAD \
203+
--corpus corpus/mini \
204+
--out "$GITHUB_WORKSPACE/artifacts/mini-diff" \
205+
--expect corpusdiff/expectations/own-check-start-column.json \
206+
--run-label "pr-${{ github.run_id }}"
207+
208+
- name: Job summary
209+
if: always() && steps.base.outputs.have_baseline == 'true'
210+
run: |
211+
if [ -f artifacts/mini-diff/report.md ]; then
212+
cat artifacts/mini-diff/report.md >> "$GITHUB_STEP_SUMMARY"
213+
else
214+
echo "The differential produced no report - see the step log. Exit 2 means" \
215+
>> "$GITHUB_STEP_SUMMARY"
216+
echo "UNDECIDED (bad input, a malformed expectation, or a producer that" \
217+
>> "$GITHUB_STEP_SUMMARY"
218+
echo "failed to produce a verdict), not 'no differences'." >> "$GITHUB_STEP_SUMMARY"
219+
fi
220+
221+
# On failure too: a run that ended in violations is exactly the one whose
222+
# intermediates someone needs to read. Both sides' SARIF, both normalized
223+
# payloads, the provenance manifests, run.json and the report all travel.
224+
- name: Upload the differential artifacts
225+
if: always() && steps.base.outputs.have_baseline == 'true'
226+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
227+
with:
228+
name: mini-corpus-diff-${{ github.run_id }}
229+
path: artifacts/mini-diff/
230+
if-no-files-found: warn
231+
retention-days: 14

‎AGENTS.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ This file provides guidance to agents when working with code in this repository.
1212
- Adding AST/CFG variants normally requires updating `assert_never` dispatch sites in `ownlang/cfg.py`, `ownlang/analysis.py`, and `ownlang/codegen.py`.
1313
- Codegen has two intentional modes: straight-line, laminar lifetimes get try/finally hoisting; branchy/transferring code emits releases inline. Do not add runtime “released?” flags to paper over static mistakes.
1414
- OwnIR schema is versioned in `ownlang/ownir.py`; additive optional fields like resource/type metadata are tolerated, incompatible vocabulary changes must fail loudly.
15+
- **The physical-anchor `column` is nullable and is NEVER synthesized.** An owned-resource record may carry a 1-based `column` (the extractor's `ColumnOf`, sibling of `LineOf`); it reaches `Finding.column` and SARIF `region.startColumn` only, never the human/github/msbuild surfaces. A producer that does not know a column **omits the field** — there is no in-band "not reported" value, so a substituted `1` is indistinguishable from a real first-column finding. Unlike `line` (which degrades to 0), a present-but-invalid column **fails loud** at `load()` (0, negative, bool, string, float) while degrading to `None` on the tolerant `check_facts` door. Never wire `diagnostics.Diagnostic._caret_col` into it: that heuristic recovers a column by searching the source line for a name from the message and falling back to the indentation — fine for drawing a `^`, disqualifying as a coordinate. `column` is deliberately absent from the finding dedup key, so adding it can never split a group and change the finding population. Coverage is partial on purpose (DI001, from `services[]`, stays line-only) — see `spec/OwnIR.md` §4.1 and `tests/test_ownir_column.py`.
16+
- **The producer gate is two contours, and `corpus/mini/` is frozen.** `.github/workflows/producer-differential.yml` is path-filtered and runs `producer-contract` (fixture tests, seconds) plus `mini-corpus-diff` (own-check at the PR's merge base and at its head over `corpus/mini`, minutes). The comparator is OwnAudit's `corpusdiff`, checked out rather than vendored — Own.NET emits SARIF, OwnAudit compares corpora, and a second copy of finding identity in the repo that produces the findings would drift toward whatever made CI green. The long real-corpus run is OwnAudit's `corpus-differential.yml` (manual + nightly), deliberately off the PR path. Changing `corpus/mini` is a **corpus** change and must not travel in a producer commit — the diff would then have two variables; see `corpus/mini/README.md`.
1517
- For C# repo scans, `scripts/own-check.sh` is the Action/bash surface and defaults to `--flow-locals`; on Windows use `scripts\own-check.ps1` rather than requiring bash.
1618
- The Roslyn extractor auto-adds built `bin/` refs for `.csproj`/`.sln` inputs unless `--no-project-refs`; unresolved external events become advisory OWN050, not guessed leaks.
1719
- `audit/` must stay decoupled from `ownlang` and consumes `own-check` only through its CLI/SARIF; `audit/README.md` says active audit development currently lives in the separate OwnAudit repo.

‎corpus/mini/Advisory.cs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
3+
namespace Own.Corpus.Mini;
4+
5+
// AN ADVISORY, NOT A VERDICT. `ExternalWidget` is deliberately undeclared and
6+
// unreferenced, so the extractor sees a `+=` that looks like an event subscription
7+
// but cannot bind its left side to an event symbol. It does NOT guess a leak: it
8+
// emits an `unresolved-subscription` record and the core surfaces OWN050 —
9+
// "leakage analysis skipped" — as an advisory note, rendered as a warning and
10+
// excluded from the exit code.
11+
//
12+
// It is in the frozen corpus because the advisory population is compared through
13+
// the ledger census rather than through the findings list (normalization routes
14+
// coverage notes out of `findings` and counts them in `coverage`). Without a note
15+
// here, that comparison would be two empty tallies agreeing with each other.
16+
public sealed class UnresolvedSource
17+
{
18+
public UnresolvedSource()
19+
{
20+
ExternalWidget.Changed += OnChanged;
21+
}
22+
23+
private void OnChanged(object? sender, EventArgs e) { }
24+
}

‎corpus/mini/DiCaptive.cs‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
3+
namespace Own.Corpus.Mini;
4+
5+
// A FINDING WITH NO AVAILABLE COLUMN — on purpose, and not as an oversight.
6+
//
7+
// DI001 (a captive dependency) is not an acquire/release finding at all: it comes
8+
// from the `services[]` registration graph, not from a `subscriptions[]` record, and
9+
// the startColumn slice deliberately did not touch that producer. So these findings
10+
// keep a line-only anchor while everything else in this corpus gains a column.
11+
//
12+
// That mixed population is the point. An expectation that permits
13+
// `null-to-positive-integer` must TOLERATE findings whose column stays null — it
14+
// allows a transition, it does not demand one. A gate that required every finding to
15+
// gain a column would fail this file, and the pressure would then be to fabricate a
16+
// coordinate for it, which is the exact outcome the nullable design exists to
17+
// prevent. It also keeps `occurrence_coverage` honestly flat for part of the corpus.
18+
//
19+
// The registration surface only has to parse — the extraction is syntactic, so this
20+
// is not the real Microsoft.Extensions.DependencyInjection.
21+
public sealed class AppDbContext { } // scoped
22+
public sealed class EmailSender { public EmailSender(AppDbContext db) { } } // singleton
23+
public sealed class Clock { } // singleton, no deps
24+
public sealed class Metrics { public Metrics(Clock clock) { } } // singleton -> singleton
25+
26+
public interface IServiceCollection { }
27+
28+
public static class MiniRegistrations
29+
{
30+
public static void Register(IServiceCollection services)
31+
{
32+
services.AddScoped<AppDbContext>();
33+
services.AddSingleton<EmailSender>(); // DI001: singleton captures scoped AppDbContext
34+
services.AddSingleton<Clock>();
35+
services.AddSingleton<Metrics>(); // singleton -> singleton: clean, stays silent
36+
}
37+
38+
// Local stand-ins so the registration calls above bind and parse.
39+
internal static void AddScoped<T>(this IServiceCollection s) { }
40+
internal static void AddSingleton<T>(this IServiceCollection s) { }
41+
}

‎corpus/mini/DisposableField.cs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
3+
namespace Own.Corpus.Mini;
4+
5+
// An IDisposable field the class constructs and never disposes: OWN001
6+
// [resource: disposable field], anchored at the field declaration.
7+
public sealed class FieldLeak
8+
{
9+
private readonly Handle _handle = new Handle();
10+
11+
public bool Open => _handle.IsOpen;
12+
}
13+
14+
// The same field, disposed on teardown -> silent.
15+
public sealed class FieldDisposed : IDisposable
16+
{
17+
private readonly Handle _handle = new Handle();
18+
19+
public bool Open => _handle.IsOpen;
20+
21+
public void Dispose()
22+
{
23+
_handle.Dispose();
24+
}
25+
}

‎corpus/mini/Indentation.cs‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
3+
namespace Own.Corpus.Mini;
4+
5+
// THE SAME LEAK AT FOUR DIFFERENT INDENTATION DEPTHS.
6+
//
7+
// This file exists to catch one specific wrong answer. `Diagnostic._caret_col` — the
8+
// renderer's caret heuristic — falls back to the line's INDENTATION when it cannot
9+
// locate an identifier. A column sourced from that heuristic instead of from the
10+
// syntax location would be "one past the leading whitespace", which is a plausible
11+
// number, is different on every line here, and is WRONG.
12+
//
13+
// The corpus catches it because the real column of `bus.CustomerChanged` is the
14+
// indentation plus zero only when the subscription starts the line. Wrap it in an
15+
// `if` and the two diverge; nest it twice and they diverge further. A fixture with
16+
// one indentation level cannot distinguish the two answers at all.
17+
public sealed class IndentationDepths
18+
{
19+
public IndentationDepths(IEventBus bus, bool flag, bool other)
20+
{
21+
bus.CustomerChanged += OnA;
22+
23+
if (flag)
24+
{
25+
bus.CustomerChanged += OnB;
26+
}
27+
28+
if (flag)
29+
{
30+
if (other)
31+
{
32+
bus.CustomerChanged += OnC;
33+
}
34+
}
35+
36+
// Not at the start of its line: the column of the subscription is well past
37+
// the indentation, so an indentation-derived column is off by the width of
38+
// everything before it.
39+
if (flag) { bus.CustomerChanged += OnD; }
40+
}
41+
42+
private void OnA(object? sender, EventArgs e) { }
43+
private void OnB(object? sender, EventArgs e) { }
44+
private void OnC(object? sender, EventArgs e) { }
45+
private void OnD(object? sender, EventArgs e) { }
46+
}

0 commit comments

Comments
 (0)