Skip to content

test: Provenance clear, fit_primitives auto, align_bodies assertions that can fail (#212) - #226

Merged
gsdali merged 2 commits into
mainfrom
test-audit-212-c
Oct 9, 2026
Merged

gsdali merged 2 commits into
mainfrom
test-audit-212-c

Conversation

@gsdali

@gsdali gsdali commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

What & why

Third batch of #212: tests that passed without being able to fail. Test-only change, no Sources touched.

Refs #212

Checklist

  • New or changed behavior is covered by a unit test in the same PR.
  • Proven to fail: see the table. Full suite: 273 tests in 44 suites passed.

Proven to fail

Change Injected defect New test Old test
ProvenanceStoreTests.clearUnderConcurrency ProvenanceStore.clear removes the whole output directory instead of the sidecar RED (thrown error: provenance.json could not be opened after the post-clear upsert) green
FitPrimitivesToolsTests.autoStrategyPicksHigherScorer (new; panel + sphere at eps 0.05, scores 1.0 vs 0.0) chosen label flipped RED (scores.chosen == "dihedral") green
same auto branch returns the RANSAC segmentation, label unchanged RED (kinds and supportTriangles) green
same dihedral and ransac scores swapped RED (scores.dihedral > scores.ransac) green
AlignToolsTests.applyWritesTransformInPlace manifest write removed from the apply path RED (manifestMtime > backdated) green
AlignToolsTests.preAlignReturnsCoarsePose preAlign translation shifted by 1 mm RED (both corner checks at 0.05 mm) green

Each row edits one line of Sources, runs the new test, then runs the old test (git show HEAD:<path> copied over the new file) against the same injection, then restores with git checkout Sources and re-runs green.

Notes for the reviewer

  • autoStrategyReportsScores keeps the tube fixture, where both scores tie at 1.0, so the choice cannot be tested there; it now asserts the tie and the single 240-triangle cylinder. The new test uses a fixture where the scores differ. I did not find a fixture where RANSAC strictly wins (panel + cube and panel + sphere at several epsilons all favour dihedral), so the "RANSAC chosen" branch is not covered.
  • preAlign measured about 1e-6 mm on this fixture; the 5 mm tolerance was six orders loose.

Not proven

  • SelectionRegistryTests.clearIsAtomicUnderConcurrency cannot detect clear_selections: reported cleared count is not atomic with the actual clear (minor race) #135. I wrote a tool-layer test through RegistryIntrospectionTools.clearSelections and reintroduced the count() then clear() split: it never went red, in a 300-round variant, and in a variant with 4 to 24 producers recording 12000 to 48000 selections while 1 to 4 tasks cleared in a loop (the sums were exact every time). Per the policy I did not ship an unproven test. The doc comment on the existing test now says it guards only the clear() primitive and that nothing here covers the caller-level race. A deterministic test would need a seam between the two hops.
  • The ProvenanceStore test does not control the interleaving, so its concurrent phase asserts only what holds for every interleaving; the deterministic proof is the post-clear upsert.

🤖 Generated with Claude Code

…that can fail

- ProvenanceStore.clear under concurrency: decode the sidecar directly and require an upsert
  after the clear to persist
- fit_primitives auto: a fixture whose scores differ, assert the chosen strategy and the primitives
- align_bodies: preAlign tolerance 5 mm -> 0.05 mm with a far-start control; apply asserts the
  manifest mtime instead of a second-precision timestamp
- SelectionRegistry: drop the claim that clearIsAtomicUnderConcurrency covers #135

Refs #212

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

// Both candidates fit a clean tube perfectly, so the scores tie and the choice is not
// under test here; the result must still be the one cylinder the tube is made of.
#expect(scores.dihedral == scores.ransac)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL: Exact floating-point equality check on scores from two different algorithms

scores.dihedral == scores.ransac compares two Double values produced by different fitting algorithms (dihedral grower vs RANSAC). Even on the same fixture, floating-point results from distinct code paths are virtually never bitwise identical. Use approximate equality with a small epsilon instead (e.g., abs(scores.dihedral - scores.ransac) < 1e-9).


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: the tie check is now abs(dihedral - ransac) < 1e-9 with the scores in the failure message. Both scores are the same inlier fraction on a clean tube so it held exactly, but a tolerance states the intent and is robust.

#expect(!result.isError, "fit_primitives failed: \(result.text)")
let r = try JSONDecoder().decode(FitReport.self, from: Data(result.text.utf8))
let scores = try #require(r.strategyScores)
#expect(scores.dihedral > scores.ransac, "fixture no longer separates the scores: \(scores)")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Strict floating-point inequality may flake on numerical precision

scores.dihedral > scores.ransac uses strict > on Double. If the two scores are extremely close (e.g., 0.999999999 vs 1.0 due to rounding), this could flip. Consider scores.dihedral > scores.ransac + 1e-9 or scores.dihedral >= scores.ransac if a tie is acceptable for "higher scorer" semantics.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in the opposite direction: the assertion is now a margin, dihedral - ransac > 0.5. On this fixture the scores are 1.0 and 0.0 (the test comment says why: the 0.05 mm epsilon starves RANSAC on the sphere's facets), so there is no near-tie to flake on, and the margin fails loudly if the fixture ever stops separating them.


// The manifest rewrite is what triggers the viewport's live reload. Timestamps inside
// the manifest are second-precision, so the proof is the file's mtime, backdated first.
#expect(manifestMtime > backdated, "apply: true must rewrite manifest.json")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: File modification time comparison can be flaky

manifestMtime > backdated relies on filesystem mtime granularity. On some filesystems (APFS, ext4) this is fine, but on others (network shares, FAT, coarse-grained timestamp FS) the mtime may not advance past the backdated value if the write happens within the same timestamp quantum. Consider also checking file size or content hash as a secondary signal, or use a longer backdate interval.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined. The manifest is backdated by an hour before the call, so the comparison is a one-hour gap against a timestamp granularity of at most a couple of seconds on any filesystem, not a race within one quantum. The same test also checks the BREP on disk holds the aligned shape (a few lines below), which is independent of timestamps.

// pass without this.
await store.upsert(
bodyId: "after-clear", record: provenanceRecord(source: "after-src"), outputDir: outputDir)
let afterwards = try JSONDecoder().decode(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Decode sidecar without checking file exists first

After the after-clear upsert, the test decodes sidecar directly at line 156 without an if FileManager.default.fileExists guard (unlike line 137). If clear() deleted the file and no concurrent post* upsert recreated it (race window), this throws instead of failing gracefully. Add the same existence check for consistency.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partly addressed. The race described does not apply: the after-clear upsert is awaited after the task group has finished, and an upsert always writes the file, so the file exists at that point or the upsert was lost, which is exactly what the test is for. The throw would have been a less readable way to say so, so I added a #require on the file existing with the message "provenance.json is missing after an upsert that followed clear()".


// The dihedral candidate's regions: the sphere (12*2 + 9*12*2 = 240 triangles) and the
// 6x6 panel (72 triangles), largest first.
#expect(r.primitives.map(\.kind) == ["sphere", "plane"])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Hard-coded expected primitive kinds and support triangle counts

["sphere", "plane"] and [240, 72] are derived from the fixture's sphereLatSegments: 10, sphereLonSegments: 12 and gridN: 6. If the fixture generation changes, these assertions become stale. Consider computing expected values from the fixture parameters (e.g., sphere triangles = 2 * lonSegments + (latSegments - 1) * lonSegments * 2, panel = gridN * gridN * 2) or extracting them into constants shared with the fixture builder.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partly addressed. These numbers are the expected values and should stay independent of the fixture generator: if the fixture changes the assertion fails loudly, which is what we want from a test of the algorithm's output. I did write them as expressions (12 * 2 + 9 * 12 * 2, 6 * 6 * 2) so the derivation is visible in the assertion instead of only in a comment.

@kilo-code-bot

kilo-code-bot Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
SwiftTests/OCCTMCPCoreTests/AlignToolsTests.swift 174 File modification time comparison can be flaky

SUGGESTION

File Line Issue
SwiftTests/OCCTMCPCoreTests/FitPrimitivesToolsTests.swift 302 Hard-coded expected primitive kinds (["sphere", "plane"])
Files Reviewed (2 files)
  • SwiftTests/OCCTMCPCoreTests/FitPrimitivesToolsTests.swift - 1 issue
  • SwiftTests/OCCTMCPCoreTests/AlignToolsTests.swift - 1 issue

Fix these issues in Kilo Cloud

Previous Review Summary (commit 14878e8)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 14878e8)

Status: 5 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 2
SUGGESTION 2
Issue Details (click to expand)

CRITICAL

File Line Issue
SwiftTests/OCCTMCPCoreTests/FitPrimitivesToolsTests.swift 266 Exact floating-point equality check on scores from two different algorithms

WARNING

File Line Issue
SwiftTests/OCCTMCPCoreTests/FitPrimitivesToolsTests.swift 295 Strict floating-point inequality may flake on numerical precision
SwiftTests/OCCTMCPCoreTests/AlignToolsTests.swift 174 File modification time comparison can be flaky

SUGGESTION

File Line Issue
SwiftTests/OCCTMCPCoreTests/ProvenanceStoreTests.swift 156 Decode sidecar without checking file exists first
SwiftTests/OCCTMCPCoreTests/FitPrimitivesToolsTests.swift 300 Hard-coded expected primitive kinds and support triangle counts
Files Reviewed (4 files)
  • SwiftTests/OCCTMCPCoreTests/AlignToolsTests.swift - 1 issue
  • SwiftTests/OCCTMCPCoreTests/FitPrimitivesToolsTests.swift - 3 issues
  • SwiftTests/OCCTMCPCoreTests/ProvenanceStoreTests.swift - 1 issue
  • SwiftTests/OCCTMCPCoreTests/SelectionRegistryTests.swift - 0 issues

Fix these issues in Kilo Cloud


Reviewed by nemotron-3-ultra-550b-a55b:free · Input: 208.8K · Output: 7.1K · Cached: 82.1K

…re when the sidecar is missing

Addresses the Kilo review on #226.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@gsdali
gsdali merged commit dda2157 into main Oct 9, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant