BOHICA-LABS / BOHICA-LABS/prism

prism-dtu-common has no relocatable fixture loader, so include_str! is hand-rolled per call site

Open Beginner friendly
#286 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1
Forks
0
Avg merge
4h 46m
Merged PRs (30d)
37

Description

`prism-dtu-common` exposes one way to load a fixture, and it is the one that cannot be relocated. A crate that wants its fixtures in the binary has to leave the shared module and hand-roll the work, which is what `prism-dtu-crowdstrike` does today. That gap is a plausible reason the runtime-read pattern spread to four other crates: it is the path the library offers.

## Expected

A crate author reaching for `prism_dtu_common::` finds an affordance for the documented contract, "fixture files are bundled at build time", and uses it.

## Actual

`fixture.rs` exports `load_fixture` and `load_fixture_as`, both of which take a `crate_dir` and read from disk at call time. There is nothing for the embedded case. So `prism-dtu-crowdstrike/src/routes/detections.rs:49-55` writes its own:

```rust
let raw = include_str!("../../fixtures/detections-ids.json");
#[allow(clippy::expect_used)]
serde_json::from_str::>(raw)
.expect("detections-ids.json must be a JSON array of strings")
```

That is correct, and it is repeated per call site with its own message and its own `#[allow]`. Nothing signals that this is the intended shape rather than a local workaround, and the doc comment on `load_fixture` still says `crate_dir` "should be `env!("CARGO_MANIFEST_DIR")` at the call site", which points every new caller at the non-relocatable path.

## Why it is worth a small addition rather than leaving it

The fix for the relocatability defect is mechanical across 17 call sites. Doing it with a shared helper makes the intent explicit at each site, keeps the panic message consistent, and puts the reasoning in one doc comment where the next person reads it, instead of spreading `#[allow(clippy::expect_used)]` further.

`load_fixture` stays as it is. It is the right tool for the `fixture-gen` and test paths that genuinely want to read a file that may change without a rebuild, and nothing proposed here removes that.

Relevant paths: `crates/prism-dtu-common/src/fixture.rs:15-27`, `crates/prism-dtu-crowdstrike/src/routes/detections.rs:49-55`.

## Ask

Would a `prism_dtu_common::embedded_fixture(raw: &str, name: &str) -> serde_json::Value` be welcome, taking the `include_str!` result and doing the parse-and-panic once, with the relocatability reasoning documented on it? Happy to include it in the PR for the defect.

Context for the defect this enables a fix for: #285, clones failing outside their build tree.

Contributor guide

No contributing guide indexed for this repository

Research direction

Look at crates/prism-dtu-common/src/fixture.rs to understand the existing load_fixture functions. Examine the example in crates/prism-dtu-crowdstrike/src/routes/detections.rs lines 49-55. The task is to add a new function, likely named embedded_fixture, that takes an include_str! result and a fixture name, parses it to serde_json::Value, and panics with a consistent message. Check issue #285 for context on the relocatability defect. Done means the new function is exported and documented, and the existing call sites can be updated to use it.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.