Skip to content

test: make real Ghidra imports opt-in and isolate their state - #32

Closed
walsykerem wants to merge 1 commit into
mainfrom
fix/issue-2-ghidra-guard
Closed

walsykerem wants to merge 1 commit into
mainfrom
fix/issue-2-ghidra-guard

Conversation

@walsykerem

Copy link
Copy Markdown
Owner

Real Ghidra import tests now share one guard instead of each setting a 300s timeout individually and writing into the user's Ghidra cache and session.

  • New requireRealGhidra(t) in test/ghidra_real_test.go skips under -short, skips whenever CI is set, and requires LRECON_OPS_GHIDRA=1; it also skips when analyzeHeadless is missing.
  • When it does run, LRECON_GHIDRA_CACHE and LRECON_STATE point at a t.TempDir(), and LRECON_GHIDRA_TIMEOUT=300s is set once, so a local real import no longer mutates the user's project or session state.
  • The five real-import tests call the helper: TestMetaGhidraReal, TestOpNativeGhidraRealImport, TestOpGhidraResultExit0, TestTur7Bucket22ProcedureGraph, TestTur7Bucket26CallPathDisasmHops. No tests were deleted and no workflow or dependency was added.

Verified in the temp clone (tests are copied into lrecon/ the same way CI does, because test/ is not a standalone package):

cp test/*_test.go lrecon/ && go test ./lrecon -count=1 -timeout 5m -run '^(TestMetaGhidraReal|TestOpNativeGhidraRealImport|TestOpGhidraResultExit0|TestTur7Bucket22ProcedureGraph|TestTur7Bucket26CallPathDisasmHops)$' -v

Result: exit 0, all five SKIP, ok lrecon/lrecon 0.654s. With CI=true LRECON_OPS_GHIDRA=1 all five skip with real ghidra import is skipped in CI (exit 0, ok lrecon/lrecon 0.826s). A cold real import was not run here because Ghidra is not installed on this machine.

Fixes #2

Real analyzeHeadless imports cost minutes and write a Ghidra project, so
they must never run in CI. Add one helper that skips under -short, skips
when CI is set, and requires LRECON_OPS_GHIDRA=1, then points
LRECON_GHIDRA_CACHE and LRECON_STATE at a t.TempDir() so a local run leaves
the user's project and session state untouched.

Fixes #2
@sonarqubecloud

Copy link
Copy Markdown

@qodo-code-review

qodo-code-review Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Make real Ghidra import tests opt-in and isolate their state

🧪 Tests 🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

AI Description

• Skip real Ghidra imports in CI, short runs, and runs without explicit opt-in or Ghidra.
• Isolate cache and session state per test, preventing changes to users’ local data.
• Share the guard and 300-second timeout across five real-import tests.
Merge Risk 🟢 Low

Blast radius 🟢 Low 💥 0 capabilities

  • No production behavior changes identified.
Behavioral complexity 🟢 Low 🧩 Assessed behavior

  • No production behavior changes identified.
Potential damage 🟢 Low 🩹 Assessed behavior

  • No production behavior changes identified.
Assessed commit d4dca70
Diagram

graph TD
  Tests["Five import tests"] --> Guard["Shared Ghidra guard"] --> Gate{"Eligible locally?"} -->|yes| Env["Isolated test state"] --> Ghidra["Ghidra imports"]
  Gate -->|no| Skip["Skip test"]
Loading
High-Level Assessment

A shared helper is the right scope: it prevents inconsistent gates and state setup without changing unrelated tests. Per-test checks would retain duplication, while suite-wide setup would affect tests that do not import through Ghidra.

Files changed (6) +36 / -28

Tests (6) +36 / -28
ghidra_real_test.goAdd a shared guard for real Ghidra tests +31/-0

Add a shared guard for real Ghidra tests

• Adds requireRealGhidra to skip short and CI runs, require explicit opt-in, and check for Ghidra. Eligible runs use test-temporary cache and state paths and a 300-second Ghidra timeout.

test/ghidra_real_test.go

op_contract_test.goGuard the Ghidra success-path contract test +1/-6

Guard the Ghidra success-path contract test

• Replaces the local installation check and timeout setup in TestOpGhidraResultExit0 with the shared guard.

test/op_contract_test.go

op_meta_real_test.goGuard the real Ghidra metadata test +1/-9

Guard the real Ghidra metadata test

• Moves TestMetaGhidraReal’s short-run, installation, and timeout handling into the shared guard while retaining its metadata assertions.

test/op_meta_real_test.go

op_native_test.goGuard the native Ghidra import test +1/-9

Guard the native Ghidra import test

• Replaces TestOpNativeGhidraRealImport’s local skip checks and timeout setup with the shared guard.

test/op_native_test.go

op_tur7_bucket22_test.goGate the procedure-graph integration test +1/-3

Gate the procedure-graph integration test

• Calls the shared guard before fixture and Ghidra work and removes the test-local timeout setting.

test/op_tur7_bucket22_test.go

op_tur7_bucket26_test.goGate the call-path integration test +1/-1

Gate the call-path integration test

• Calls the shared guard before building the call-chain fixture and removes the test-local timeout setting.

test/op_tur7_bucket26_test.go

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📎 Requirement gaps (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

Nice, no open findings for this group


Remediation recommended

Nice, no open findings for this group


Informational

1. Session isolation is bypassed when LRECON_SESSION is set 🟡 Low 🐞 Bug ≡ Correctness
Description
requireRealGhidra isolates the session by setting LRECON_STATE, but sessionPath checks
LRECON_SESSION first and returns it unchanged, so a developer who exports LRECON_SESSION still
has the real session file read and rewritten by the opt-in run. The helper's stated guarantee that a
local real import leaves session state untouched therefore holds only when that variable is unset.
Code

test/ghidra_real_test.go[R28-29]

+	t.Setenv("LRECON_GHIDRA_CACHE", filepath.Join(root, "ghidra-cache"))
+	t.Setenv("LRECON_STATE", filepath.Join(root, "state"))
Evidence
sessionPath returns LRECON_SESSION whenever it is non-empty and only consults LRECON_STATE
afterwards, so the helper's isolation of LRECON_STATE does not cover an environment that sets
LRECON_SESSION. The PR description claims the real import no longer mutates session state, which
this path contradicts.

lrecon/op_native_util.go[762-775]
test/ghidra_real_test.go[27-30]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

Issue description
requireRealGhidra in test/ghidra_real_test.go isolates state by setting LRECON_STATE to a temp dir. sessionPath in lrecon/op_native_util.go gives LRECON_SESSION priority over LRECON_STATE, so an exported LRECON_SESSION makes the opt-in real import read and write the developer's real session file.

Fix Focus Areas
- test/ghidra_real_test.go[27-30]
- lrecon/op_native_util.go[762-775]

Recommended Fix
In requireRealGhidra, after the existing t.Setenv calls, add t.Setenv("LRECON_SESSION", "") (or set it to filepath.Join(root, "session.json")) so the session path always resolves inside the temp root. Verify that an empty value falls through to LRECON_STATE in sessionPath, which uses TrimSpace and then checks emptiness.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


2. Opt-in Ghidra runs always pay a cold import 🟡 Low 🐞 Bug ➹ Performance
Description
Pointing LRECON_GHIDRA_CACHE at a fresh t.TempDir() on every call means the content-addressed
Ghidra entry cache is never reused across runs, so each local real import repeats the multi-minute
analysis. The temp directory is also removed at test end, discarding the analysed project each time.
Code

test/ghidra_real_test.go[R27-28]

+	root := t.TempDir()
+	t.Setenv("LRECON_GHIDRA_CACHE", filepath.Join(root, "ghidra-cache"))
Evidence
ghidraCacheRoot returns the environment value as the cache root whenever it is set, and the cache
key is derived from the target bytes, so a fresh temp root guarantees a miss. The helper deletes
that root when the test finishes, so the cache cannot carry over between runs.

lrecon/op_native_cache.go[68-80]
test/ghidra_real_test.go[27-28]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

Issue description
requireRealGhidra in test/ghidra_real_test.go sets LRECON_GHIDRA_CACHE to a per-test t.TempDir(). ghidraCacheRoot in lrecon/op_native_cache.go uses that value as the cache root, so the content-keyed import cache is discarded at the end of every test and every run re-imports from scratch.

Fix Focus Areas
- test/ghidra_real_test.go[27-28]
- lrecon/op_native_cache.go[68-80]

Recommended Fix
Either keep the temp isolation and note in the helper comment and README that each opt-in run is a cold import, or honour an explicit developer-chosen cache, for example by only setting LRECON_GHIDRA_CACHE to the temp root when it is unset and the caller opts in with a separate variable. Choose one and make the comment match the behaviour.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Grey Divider

Context sources
⚠️ Tickets: not configured — No jira, linear integration is connected for the linked tickets
✅ Cross-repo context — repo relationships
Review mode: Auto: 🚀 Fast: Localized test gating and environment isolation avoid high-risk runtime paths.

Grey Divider

Tip of the day
💡 Did you know, you can tweak Display settings with a live preview to see your comment before it ships

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

Qodo Fixer

No findings are within the configured fix scope. To change which findings are fixed, adjust the setting on your Qodo configuration page.

@walsykerem

Copy link
Copy Markdown
Owner Author

Recreated from verified backup (/Users/keremurhan/lrecon-pr-backup-20261126) as part of PR cleanup; replacement PR follows.

@walsykerem walsykerem closed this Nov 26, 2026
@walsykerem
walsykerem deleted the fix/issue-2-ghidra-guard branch November 26, 2026 15:59
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.

Real Ghidra import tests need 300s timeout and mutate project state

1 participant