Skip to content

fix(validate): read the spec doc at runtime in the error-code test (fixes Nix channel) - #1659

Merged
robcohen merged 1 commit into
mainfrom
fix/spec-include-runtime
Jul 1, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/spec-include-runtime

Conversation

@robcohen

@robcohen robcohen commented Jul 1, 2026

Copy link
Copy Markdown
Member

Fixes the Test Nix release-channel failure (surfaced verifying the v0.17.2 channel run).

Root cause

rustledger-validate's error_codes_documented_in_spec test did:

let spec = include_str!("../../../spec/core/validation.md");

That reaches the workspace-root spec/ dir, outside the crate, so it isn't packaged to crates.io. When the Nix channel builds and tests the published crate, the test module fails to compile:

error: couldn't read `crates/rustledger-validate/src/../../../spec/core/validation.md`: No such file or directory

It's a #[cfg(test)] test, so it never affected the library/binary/component or normal cargo install consumers — only test builds of the published crate (Nix, cargo test from crates.io). It's been red on Nix across the 0.17.x releases.

Fix

Read the spec at runtime relative to CARGO_MANIFEST_DIR, and skip gracefully when it's absent (the published-crate case), instead of include_str! at compile time. The drift guard still runs in the workspace (spec present) — verified passing here.

Test-only change; no shipped artifact changes. Verified: the test passes in-workspace, clippy -D warnings + fmt clean.

🤖 Generated with Claude Code

error_codes_documented_in_spec used include_str! on spec/core/validation.md — a
workspace-root file OUTSIDE the crate, so it is not packaged to crates.io.
Building the PUBLISHED crate's tests (as the Nix release channel does) failed to
compile: 'couldn't read ../../../spec/core/validation.md: No such file or
directory'. This broke the Test Nix release channel across the 0.17.x releases.

Read the spec at runtime relative to CARGO_MANIFEST_DIR and skip gracefully when
it is absent (the published-crate case), instead of include_str! at compile time.
The drift guard still runs in the workspace (where the spec is present); it is a
test-only change — no shipped artifact (library, binary, or component) is
affected.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner July 1, 2026 00:44
Copilot AI review requested due to automatic review settings July 1, 2026 00:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the rustledger-validate error-code drift-guard test so it no longer depends on include_str!() for a workspace-root spec file that isn’t present in published-crate builds (fixing Nix channel failures when running tests from crates.io sources).

Changes:

  • Switches the spec lookup from compile-time include_str!() to runtime file IO relative to CARGO_MANIFEST_DIR.
  • Gracefully skips the drift-guard test when the spec file is absent (published crate / Nix channel scenario).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/rustledger-validate/src/error.rs Resolved
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-validate/src/error.rs 50.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 32.8ms ± 0.9ms 23.3 MB
beancount 905.3ms ± 8.3ms 50.5 MB
Comparison 27.6x faster 2.2x less

vs main branch (2026-06-30)

Metric main this PR Change
Time 42ms 32.8ms -21.9% 🟢
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 792
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@robcohen
robcohen merged commit 414dfba into main Jul 1, 2026
44 checks passed
@robcohen
robcohen deleted the fix/spec-include-runtime branch July 1, 2026 01:07
@robcohen robcohen mentioned this pull request Jul 1, 2026
robcohen added a commit that referenced this pull request Jul 1, 2026
Patch release: fix the Nix release-channel build by reading the validation spec
at runtime instead of include_str! on a non-packaged workspace-root file (#1659).
Test-only fix; no library/binary/component behavior change. Workspace 0.17.2 ->
0.17.3 (cargo set-version); packages/mcp-server bumped to match.

Co-authored-by: Claude Opus 4.8 <[email protected]>
robcohen added a commit that referenced this pull request Jul 2, 2026
…1685)

* test(core): behavior-replay conformance against the TLA+ model (MBT)

The specs bounds are tiny (Conservation: 207 states / 678 transitions), so TLC
can enumerate the COMPLETE state graph. New model-based-testing layer:

- scripts/tla-behaviors.py: TLC -dump dot,actionlabels state graph ->
  edge-coverage behavior corpus (one behavior per transition = shortest
  canonical path to the source state + the transition). Output is canonical
  (content-derived ordering, no node ids), so regeneration is byte-stable
  regardless of TLC dump order. --self-test included.
- spec/tla/behaviors/Conservation.json: the committed corpus (678 behaviors
  covering all 678 transitions).
- tests/tla_behavior_replay.rs: replays EVERY behavior against the real
  Inventory, asserting after each step (a) the abstraction — units ==
  spec inventory, harness accumulators == totalAdded/totalReduced — and
  (b) enabledness: a model-enabled Reduce may not Err. Hermetic (no
  Java/TLC in cargo test); graceful skip when spec/ is not packaged
  (published-crate / crane builds, the #1659 lesson).
- tla.yml: lockstep guard — regenerates the corpus from the spec and fails
  on drift, so the replay test can never silently certify against a stale
  model.
- RUST_MAPPING.md: documents the layer and how to extend it to more specs.

Exhaustive conformance up to the model bound: strictly stronger than the
sampled tla_proptest properties, one notch below a refinement proof.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(tla-behaviors): derive actions from state deltas — TLC-version-agnostic edge parsing

The PR's own lockstep guard caught the exact failure mode it exists for: CI's
tla2tools (1.8.0) emits dot edges the 1.7.4-tuned label regex didn't match, so
CI regenerated a corpus with 207 states but ZERO transitions and the byte-diff
failed. Fixes:

- Edge regex matches any 'id -> id' line; the action label is optional
  decoration. Semantics are DERIVED from the state delta (totalAdded grew ->
  Add, totalReduced grew -> Reduce), so committed corpus and CI regeneration
  agree regardless of TLC's dot dialect.
- The generator now REFUSES to emit a vacuous corpus (states without
  transitions = parse failure, hard error instead of a garbage diff).
- Stutter self-loops (emitted by some TLC versions) are skipped, and
  coverage.transitions counts only semantic edges, keeping the byte-diff
  stable across versions.
- Self-test extended: stripping all action labels must produce the identical
  corpus.

Committed corpus regenerated with the new derivation: byte-identical
(678 behaviors / 678 transitions), confirming the change is purely parsing.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
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.

2 participants