Support fuzz configuration via env variables#952
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR introduces fuzzing mode support to the jam CLI by adding a new fuzz-env module that reads and validates fuzzing environment variables (JAM_FUZZ, JAM_FUZZ_SPEC, JAM_FUZZ_SOCK_PATH, JAM_FUZZ_DATA_PATH, JAM_FUZZ_LOG_LEVEL). It includes comprehensive tests for the module, documentation of the environment variables and their usage, and integration into the CLI entry point. The PR also updates the Docker base image to explicitly specify linux/amd64 platform for multi-arch builds. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
bin/jam/fuzz-env.test.ts (1)
136-154: ⚡ Quick winAdd one regression case for whitespace-padded env inputs.
Given env values often come from shells/templating, a single case like
" TRACE "/" /tmp/s "will guard normalization behavior and prevent regressions.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@bin/jam/fuzz-env.test.ts` around lines 136 - 154, Add a regression case that verifies readFuzzEnv normalizes whitespace-padded env values: in the "parses each documented log level" test (fuzz-env.test.ts) add an input case where JAM_FUZZ_LOG_LEVEL is padded (e.g. " TRACE ") and/or other env strings like JAM_FUZZ_SOCK_PATH/JAM_FUZZ_DATA_PATH include trailing/leading spaces, then call readFuzzEnv with those padded env vars and assert the returned result.logLevel equals the expected Level (use the same Level.TRACE expected symbol); this ensures readFuzzEnv trims whitespace and prevents regressions.bin/jam/index.ts (1)
26-28: ⚡ Quick winUse repo validation helper instead of direct throw for CLI-arg rejection.
This keeps error semantics consistent with the rest of the codebase’s validation style in command entrypoints.
As per coding guidelines: "Use ensure/check to validate values; prefer Result types over exceptions; avoid subclassing Error."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@bin/jam/index.ts` around lines 26 - 28, Replace the direct throw in the CLI arg guard (the process.argv length check that throws new Error("When JAM_FUZZ is set, command-line arguments are not accepted.")) with the repo validation helper used elsewhere (e.g., ensure or check) so error semantics match the codebase; call the helper with a clear message and the same condition (process.argv.length > 2) so the validation path and Result-style handling are used instead of throwing an Error directly.bin/jam/fuzz-env.ts (1)
36-63: 🏗️ Heavy liftPrefer repo-standard validation primitives over throwing generic
Errorin parser paths.The new validation path currently throws directly. Converting this to the repo’s
ensure/check+ Result-style flow would better match existing error-handling conventions and make this utility easier to compose/test upstream.As per coding guidelines: "Use ensure/check to validate values; prefer Result types over exceptions; avoid subclassing Error."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@bin/jam/fuzz-env.ts` around lines 36 - 63, Replace the direct throws in the parser with the repo-standard ensure/check + Result pattern: in the REQUIRED_VARS loop use the ensure/check primitive to assert non-empty values for each env[name] (referencing REQUIRED_VARS, env, JAM_FUZZ), convert the JAM_FUZZ_SPEC parsing (specRaw, KnownChainSpec) to validate via ensure/check and return a Result.err message instead of throwing, and likewise validate rawLogLevel against LOG_LEVELS (rawLogLevel, LOG_LEVELS, JAM_FUZZ_LOG_LEVEL) using ensure/check and return a Result.err when parsing fails; ensure the function returns a Result.ok with the parsed spec/log level (Level) on success so callers can handle errors without exceptions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@bin/jam/fuzz-env.ts`:
- Around line 43-71: The env values are not being trimmed, so leading/trailing
whitespace can make valid inputs fail later; trim JAM_FUZZ_SPEC and
JAM_FUZZ_LOG_LEVEL before comparing to KnownChainSpec and looking up LOG_LEVELS
(use the trimmed string in error messages too), and return trimmed socketPath
and dataPath (trim env[JAM_FUZZ_SOCK_PATH] and env[JAM_FUZZ_DATA_PATH] before
returning) so callers get normalized paths; update references to specRaw and
rawLogLevel in the parsing logic and to the returned socketPath/dataPath to use
the trimmed values.
---
Nitpick comments:
In `@bin/jam/fuzz-env.test.ts`:
- Around line 136-154: Add a regression case that verifies readFuzzEnv
normalizes whitespace-padded env values: in the "parses each documented log
level" test (fuzz-env.test.ts) add an input case where JAM_FUZZ_LOG_LEVEL is
padded (e.g. " TRACE ") and/or other env strings like
JAM_FUZZ_SOCK_PATH/JAM_FUZZ_DATA_PATH include trailing/leading spaces, then call
readFuzzEnv with those padded env vars and assert the returned result.logLevel
equals the expected Level (use the same Level.TRACE expected symbol); this
ensures readFuzzEnv trims whitespace and prevents regressions.
In `@bin/jam/fuzz-env.ts`:
- Around line 36-63: Replace the direct throws in the parser with the
repo-standard ensure/check + Result pattern: in the REQUIRED_VARS loop use the
ensure/check primitive to assert non-empty values for each env[name]
(referencing REQUIRED_VARS, env, JAM_FUZZ), convert the JAM_FUZZ_SPEC parsing
(specRaw, KnownChainSpec) to validate via ensure/check and return a Result.err
message instead of throwing, and likewise validate rawLogLevel against
LOG_LEVELS (rawLogLevel, LOG_LEVELS, JAM_FUZZ_LOG_LEVEL) using ensure/check and
return a Result.err when parsing fails; ensure the function returns a Result.ok
with the parsed spec/log level (Level) on success so callers can handle errors
without exceptions.
In `@bin/jam/index.ts`:
- Around line 26-28: Replace the direct throw in the CLI arg guard (the
process.argv length check that throws new Error("When JAM_FUZZ is set,
command-line arguments are not accepted.")) with the repo validation helper used
elsewhere (e.g., ensure or check) so error semantics match the codebase; call
the helper with a clear message and the same condition (process.argv.length > 2)
so the validation path and Result-style handling are used instead of throwing an
Error directly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f2236eb4-d38d-443a-9393-bc664698f790
📒 Files selected for processing (5)
Dockerfilebin/jam/README.mdbin/jam/fuzz-env.test.tsbin/jam/fuzz-env.tsbin/jam/index.ts
View all
Benchmarks summary: 83/83 OK ✅ |
No description provided.