Repository navigation
test: Provenance clear, fit_primitives auto, align_bodies assertions that can fail (#212) - #226
Conversation
…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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"]) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Code Review SummaryStatus: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (2 files)
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
Issue Details (click to expand)CRITICAL
WARNING
SUGGESTION
Files Reviewed (4 files)
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]>
What & why
Third batch of #212: tests that passed without being able to fail. Test-only change, no Sources touched.
Refs #212
Checklist
Proven to fail
ProvenanceStoreTests.clearUnderConcurrencyProvenanceStore.clearremoves the whole output directory instead of the sidecarprovenance.jsoncould not be opened after the post-clear upsert)FitPrimitivesToolsTests.autoStrategyPicksHigherScorer(new; panel + sphere at eps 0.05, scores 1.0 vs 0.0)chosenlabel flippedscores.chosen == "dihedral")dihedralandransacscores swappedscores.dihedral > scores.ransac)AlignToolsTests.applyWritesTransformInPlaceapplypathmanifestMtime > backdated)AlignToolsTests.preAlignReturnsCoarsePoseEach 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 withgit checkout Sourcesand re-runs green.Notes for the reviewer
autoStrategyReportsScoreskeeps 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.Not proven
SelectionRegistryTests.clearIsAtomicUnderConcurrencycannot detect clear_selections: reported cleared count is not atomic with the actual clear (minor race) #135. I wrote a tool-layer test throughRegistryIntrospectionTools.clearSelectionsand reintroduced thecount()thenclear()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 theclear()primitive and that nothing here covers the caller-level race. A deterministic test would need a seam between the two hops.🤖 Generated with Claude Code