Skip to content

fix: add main.rs driver to rust dynamic tracer fixture#1877

Open
carlos-alm wants to merge 1 commit into
fix/issue-1757-token-benchmark-dedupe-persistfrom
fix/issue-1759-rust-tracer-fixture-mainrs
Open

fix: add main.rs driver to rust dynamic tracer fixture#1877
carlos-alm wants to merge 1 commit into
fix/issue-1757-token-benchmark-dedupe-persistfrom
fix/issue-1759-rust-tracer-fixture-mainrs

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

  • tests/benchmarks/resolution/fixtures/rust/ had no main.rs, so native-tracer.sh's trace_rust() failed immediately on the injection step, before ever reaching compile/run — silently skipped as "toolchain not available" by the consuming test, masking the fact this tracer path had never actually been exercised.
  • Added main.rs exercising the full models/repository/service/validator chain. Getting it to actually run end-to-end (the issue's real impact concern) surfaced 3 more latent bugs in the same never-exercised path, all fixed as necessary prerequisites: a GNU-only sed form in native-tracer.sh that BSD sed (macOS) rejects, an impl-block context regex that captured the trait name instead of the concrete type for impl Trait for Type, and the fixture itself never compiling as a real crate (missing Clone derive, missing trait import).

Closes #1759

Test plan

  • npm test — full suite green (3519 passed, 0 failed)
  • npm run lint — clean (.rs/.sh outside Biome's scope, no other format gate applies)
  • native-tracer.sh now compiles and runs end-to-end, producing 23/24 expected edges (the one miss is legitimately unreachable at runtime — a repo stub's save() never persists into its HashMap, pre-existing fixture behavior)
  • tracer-validation.test.ts's rust case now actually runs (not skipped) at 100% same-file recall against the 0.5 threshold
  • resolution-benchmark.test.ts's rust suite: 100% precision, 58.3% recall, both above thresholds

Filed #1876 for a genuinely separate finding surfaced by this work: both engines miss receiver-typed calls on locally-typed variables and trait-dispatch through local variables — confirmed as a real resolution gap, not an engine-parity divergence.

Stacked on #1875 (base branch fix/issue-1757-token-benchmark-dedupe-persist) — only the rust fixture/tracer diff is this issue's change.

The rust fixture had no main.rs, so trace_rust() failed immediately
trying to inject `mod trace_support;` into a nonexistent file. This
silently skipped the rust same-file recall assertion in
tracer-validation.test.ts as "toolchain not available" even when cargo
was installed, masking the fact that the rust dynamic tracer had never
actually been exercised.

Adds main.rs exercising the full models/repository/service/validator
call chain through build_service()/add_user()/get_user()/remove_user()
plus a direct_repo_access() helper, and documents the edges it
introduces in expected-edges.json (mirroring how the swift/dart/zig
fixtures already catalog every call sourced from their own main
driver) — precision stays at 100%, recall is 58.3% against a larger,
more complete manifest (24 edges vs. 14).

Getting the tracer to actually run past the missing file surfaced
three more bugs in the same trace_rust() code path that had never
been reached before, since compilation was never previously attempted:

- The dump_trace() injection used a GNU-only inline `i\text` sed form
  that BSD sed (macOS) rejects; switched to the portable `i\` +
  newline form.
- The impl-block context regex captured the trait name instead of the
  concrete type for `impl Trait for Type` blocks, mislabeling e.g.
  EmailValidator.validate as Validator.validate in the trace output.
- trace_support.rs's trace_call() held an immutable borrow from
  t.stack.last() across mutations of t.seen/t.edges, which doesn't
  compile under the borrow checker; clones the needed fields out
  first instead.

The fixture itself also never compiled as a real crate: User didn't
derive Clone (needed by find_by_id's .cloned()), and service.rs called
Repository trait methods on self.repo without importing the trait.
Both fixed.

Verified end-to-end: native-tracer.sh now compiles and runs, producing
23/24 expected edges (the only miss, User.display_name, is legitimately
unreachable since the repo stub's save() never persists into its
HashMap). tracer-validation.test.ts's rust case now actually runs
(rather than skipping) at 100% same-file recall (7/7) against the 50%
threshold. Filed #1876 for the pre-existing static-resolution gap this
also confirmed (receiver-typed/trait-dispatch calls through
locally-typed variables aren't resolved by either engine).

Fixes #1759

Impact: 1 functions changed, 1 affected

Impact: 3 functions changed, 2 affected
@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR unblocks the Rust dynamic tracer path by adding the missing main.rs fixture driver and fixing three latent bugs that prevented the Rust fixture from ever compiling or running end-to-end.

  • New main.rs: exercises the full models → repository → service → validator call chain, providing 10 new expected edges in expected-edges.json for both same-file and cross-module resolution modes.
  • Fixture compilation fixes: #[derive(Clone)] added to User (required by cloned() in the repository), Repository trait import added to service.rs (required to call trait methods via UserRepository).
  • native-tracer.sh fixes: borrow-checker-safe trace_call (clones caller fields before mutating Tracer), corrected impl-block regex so impl Trait for Type captures the concrete type in group 2, and BSD-portable i\\<newline>text sed syntax replacing the GNU-only inline form.

Confidence Score: 4/5

Safe to merge; all changes are scoped to test fixtures and the tracer shell script, with the full suite confirmed green.

The Rust tracer path is now correctly exercised. The one remaining concern is that the Swift, Dart, Zig, and C# tracer sections still carry the GNU-only i ext inline sed form that was just patched for Rust — on macOS, this silently breaks dump injection for Dart/Zig and would abort the Swift tracer outright (no 2>/dev/null || true guard). This is a pre-existing gap made more visible by the fix landing here.

tests/benchmarks/resolution/tracer/native-tracer.sh — the Swift, Dart, Zig, and C# dump-injection sedi calls should receive the same BSD-portable i\ treatment applied to Rust in this PR.

Important Files Changed

Filename Overview
tests/benchmarks/resolution/tracer/native-tracer.sh Three targeted fixes for the Rust tracer: borrow-checker-safe trace_call, corrected impl-block context regex (group 2 for concrete type on impl Trait for Type), and BSD-portable sed insert syntax. The same GNU-only i\text pattern persists in Swift, Dart, Zig, and C# sections.
tests/benchmarks/resolution/fixtures/rust/main.rs New driver exercising the full models/repository/service/validator chain; imports Repository trait so save() is callable; correct Rust crate entry point.
tests/benchmarks/resolution/fixtures/rust/models.rs Added #[derive(Clone)] to User, required by repository.rs's self.store.get(&id).cloned() call.
tests/benchmarks/resolution/fixtures/rust/service.rs Added Repository to the use import so trait methods (save, find_by_id, delete) are callable via UserRepository.
tests/benchmarks/resolution/fixtures/rust/expected-edges.json 10 new expected edges added for main.rs calls; modes (module-function, receiver-typed, constructor, same-file) are correct. The User.display_name edge is a known runtime miss (acknowledged in PR) since the stub repository never persists via save().

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant main
    participant build_service as build_service (service.rs)
    participant UserService as UserService (service.rs)
    participant UserRepository as UserRepository (repository.rs)
    participant create_user as create_user (models.rs)
    participant validate_all as validate_all (validator.rs)
    participant User as User (models.rs)
    participant direct_repo_access as direct_repo_access (main.rs)

    main->>build_service: build_service()
    build_service-->>main: UserService

    main->>UserService: add_user(1, "Alice", ...)
    UserService->>create_user: create_user(...)
    UserService->>validate_all: "validate_all(&user)"
    UserService->>UserRepository: "save(&user)"
    UserService-->>main: Ok(())

    main->>UserService: get_user(1)
    UserService->>UserRepository: find_by_id(1)
    UserService-->>main: None (stub never persisted)

    Note over main,User: display_name() unreachable at runtime

    main->>UserService: remove_user(1)
    UserService->>UserRepository: delete(1)
    UserService-->>main: bool

    main->>direct_repo_access: direct_repo_access()
    direct_repo_access->>UserRepository: new()
    direct_repo_access->>create_user: create_user(2, "Bob", ...)
    direct_repo_access->>validate_all: "validate_all(&user)"
    direct_repo_access->>UserRepository: "save(&user)"
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant main
    participant build_service as build_service (service.rs)
    participant UserService as UserService (service.rs)
    participant UserRepository as UserRepository (repository.rs)
    participant create_user as create_user (models.rs)
    participant validate_all as validate_all (validator.rs)
    participant User as User (models.rs)
    participant direct_repo_access as direct_repo_access (main.rs)

    main->>build_service: build_service()
    build_service-->>main: UserService

    main->>UserService: add_user(1, "Alice", ...)
    UserService->>create_user: create_user(...)
    UserService->>validate_all: "validate_all(&user)"
    UserService->>UserRepository: "save(&user)"
    UserService-->>main: Ok(())

    main->>UserService: get_user(1)
    UserService->>UserRepository: find_by_id(1)
    UserService-->>main: None (stub never persisted)

    Note over main,User: display_name() unreachable at runtime

    main->>UserService: remove_user(1)
    UserService->>UserRepository: delete(1)
    UserService-->>main: bool

    main->>direct_repo_access: direct_repo_access()
    direct_repo_access->>UserRepository: new()
    direct_repo_access->>create_user: create_user(2, "Bob", ...)
    direct_repo_access->>validate_all: "validate_all(&user)"
    direct_repo_access->>UserRepository: "save(&user)"
Loading

Comments Outside Diff (1)

  1. tests/benchmarks/resolution/tracer/native-tracer.sh, line 711-717 (link)

    P2 BSD-incompatible i\text form still present in Swift, Zig, Dart, and C# tracer sections

    The same GNU-only i\text inline syntax that was just fixed for the Rust section is still used in the Swift tracer (line ~713), Zig tracer (line ~922), Dart tracer (line ~810), and C# tracer (line ~609, ~613). On macOS, BSD sed rejects i\<text> without a following newline and, in the Swift case specifically (no 2>/dev/null || true guard), a failure in sedi would propagate through set -euo pipefail and abort the tracer entirely rather than falling back to empty_result.

    Fix in Claude Code

Fix All in Claude Code

Reviews (1): Last reviewed commit: "fix: add main.rs driver to rust dynamic ..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Codegraph Impact Analysis

3 functions changed2 callers affected across 2 files

  • main in tests/benchmarks/resolution/fixtures/rust/main.rs:11 (0 transitive callers)
  • direct_repo_access in tests/benchmarks/resolution/fixtures/rust/main.rs:29 (1 transitive callers)
  • trace_rust in tests/benchmarks/resolution/tracer/native-tracer.sh:323 (1 transitive callers)

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