Repository navigation
feat: support annotations for secret environment variables in bru and preserve variable value type in yml - #8251
Conversation
…bles Secret env vars support annotations in bru and a type field in yml. Env, collection and folder variables preserve data types in yml via a datatype prop, and external secrets blocks survive read/save.
WalkthroughAdds explicit variable ChangesTyped Environment Variables and External Secrets Support
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/bruno-filestore/src/formats/yml/stringifyEnvironment.ts (1)
13-17:⚠️ Potential issue | 🟠 Major | ⚡ Quick winNon-string typed variables are still dropped on save.
EnvironmentVariable.valuenow allowsnumber,boolean, andobject, but this filter keeps only string-valued entries. Any typed variable constructed in memory will disappear during YAML serialization beforeensureString()runs.Minimal fix
const ocVariables: (Variable | SecretVariable)[] = variables - .filter((v: BrunoEnvironmentVariable) => { - // todo: currently neither bru lang nor bruno app supports non-string values - // update this when bruno app supports non-string values - return typeof v.value === 'string'; - }) + .filter((v: BrunoEnvironmentVariable) => { + return v.secret === true || v.value !== undefined && v.value !== null; + }) .map((v: BrunoEnvironmentVariable): Variable | SecretVariable => {🤖 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 `@packages/bruno-filestore/src/formats/yml/stringifyEnvironment.ts` around lines 13 - 17, The current filter in stringifyEnvironment.ts drops any environment variables whose BrunoEnvironmentVariable.value is not a string; remove or change that predicate so typed values (number, boolean, object) are preserved for serialization and let the existing ensureString() logic handle conversion later. Specifically, update the .filter((v: BrunoEnvironmentVariable) => typeof v.value === 'string') to only exclude truly absent values (e.g., v.value === undefined or v.value === null) so BrunoEnvironmentVariable entries with non-string types are not lost.
🧹 Nitpick comments (2)
packages/bruno-schema-types/src/common/variables.ts (2)
4-4: ⚡ Quick winConsider consolidating duplicate type definitions.
VariableDatatypehas identical literal values toEnvironmentVariableDatatype(defined incollection/environment.ts). Consider extracting this into a shared type to maintain a single source of truth.♻️ Suggested refactor
Move the common type definition to a shared location and import it in both files, or have one file re-export from the other:
-export type VariableDatatype = 'string' | 'number' | 'boolean' | 'object'; +export type { EnvironmentVariableDatatype as VariableDatatype } from '../collection/environment';🤖 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 `@packages/bruno-schema-types/src/common/variables.ts` at line 4, The two identical literal union types VariableDatatype and EnvironmentVariableDatatype should be consolidated into a single shared type; create a common exported type (e.g., CommonVariableDatatype or export VariableDatatype from one central module) and update references so both VariableDatatype usages and EnvironmentVariableDatatype usages import/re-export that single type (replace the duplicate literal definition in packages/bruno-schema-types/src/common/variables.ts and the definition in collection/environment.ts with an import/re-export of the shared symbol).
9-18: Clarify contract:Variable.valueis the stringified form, whiledatatypepreserves the original semantic type.Code in the converters/filestore maps typed values by extracting/stringifying (e.g.,
variable.value.data/ensureString(...)) and then settingvariable.datatype, soVariable.value: string | nullaligns with actual usage and doesn’t imply runtime type mismatches. The main follow-up is to document this intent (e.g., JSDoc onVariable) to prevent future confusion about assigning non-string values.🤖 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 `@packages/bruno-schema-types/src/common/variables.ts` around lines 9 - 18, The Variable interface's contract is unclear: Variable.value is the stringified form while Variable.datatype preserves the original semantic type; update the Variable declaration (interface Variable) with a JSDoc comment clarifying that value is always a string|null (the serialized form used by converters/filestore which call variable.value.data or ensureString(...)) and that datatype contains the original VariableDatatype; keep the Variable.value type as string | null and add the JSDoc to prevent future assignments of non-string runtime values and to point maintainers to converters/filestore behavior.
🤖 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 `@packages/bruno-lang/v2/src/envToJson.js`:
- Around line 272-283: The externalsecrets conversion in externalsecrets
(packages/bruno-lang/v2/src/envToJson.js) currently collapses provider records
to {name, value} via mapPairListToKeyValPairs and loses provider-specific
fields; update externalsecrets to preserve the full original AST/object for each
variable (including fields like path, by_path, etc.) instead of reducing to only
name and value, and ensure the complementary writer in jsonToEnv.js is updated
to emit the full record shape (not just name/value) so provider-specific records
survive the BRU roundtrip.
---
Outside diff comments:
In `@packages/bruno-filestore/src/formats/yml/stringifyEnvironment.ts`:
- Around line 13-17: The current filter in stringifyEnvironment.ts drops any
environment variables whose BrunoEnvironmentVariable.value is not a string;
remove or change that predicate so typed values (number, boolean, object) are
preserved for serialization and let the existing ensureString() logic handle
conversion later. Specifically, update the .filter((v: BrunoEnvironmentVariable)
=> typeof v.value === 'string') to only exclude truly absent values (e.g.,
v.value === undefined or v.value === null) so BrunoEnvironmentVariable entries
with non-string types are not lost.
---
Nitpick comments:
In `@packages/bruno-schema-types/src/common/variables.ts`:
- Line 4: The two identical literal union types VariableDatatype and
EnvironmentVariableDatatype should be consolidated into a single shared type;
create a common exported type (e.g., CommonVariableDatatype or export
VariableDatatype from one central module) and update references so both
VariableDatatype usages and EnvironmentVariableDatatype usages import/re-export
that single type (replace the duplicate literal definition in
packages/bruno-schema-types/src/common/variables.ts and the definition in
collection/environment.ts with an import/re-export of the shared symbol).
- Around line 9-18: The Variable interface's contract is unclear: Variable.value
is the stringified form while Variable.datatype preserves the original semantic
type; update the Variable declaration (interface Variable) with a JSDoc comment
clarifying that value is always a string|null (the serialized form used by
converters/filestore which call variable.value.data or ensureString(...)) and
that datatype contains the original VariableDatatype; keep the Variable.value
type as string | null and add the JSDoc to prevent future assignments of
non-string runtime values and to point maintainers to converters/filestore
behavior.
🪄 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: e6e6b24a-e14a-455a-b579-bcb982599735
📒 Files selected for processing (15)
packages/bruno-app/src/providers/ReduxStore/slices/collections/environment-events.spec.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/index.jspackages/bruno-filestore/src/formats/yml/common/variables.tspackages/bruno-filestore/src/formats/yml/parseEnvironment.tspackages/bruno-filestore/src/formats/yml/stringifyEnvironment.tspackages/bruno-filestore/src/formats/yml/tests/parseEnvironment.spec.jspackages/bruno-filestore/src/formats/yml/tests/variables.spec.jspackages/bruno-lang/v2/src/envToJson.jspackages/bruno-lang/v2/src/jsonToEnv.jspackages/bruno-lang/v2/tests/annotations.spec.jspackages/bruno-schema-types/src/collection/environment.tspackages/bruno-schema-types/src/common/variables.tspackages/bruno-schema/src/collections/environmentSchema.spec.jspackages/bruno-schema/src/collections/index.jspackages/bruno-schema/src/collections/requestSchema.spec.js
annotations and data types support for secret environment variablesbru and preserve variable value type in yml
setRequestVars, setFolderVars and setCollectionVars rebuilt variables with a field whitelist, dropping datatype (yml) and annotations (bru) on save after an edit.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js`:
- Around line 2070-2078: The variable mapping omits the description field
causing descriptions to be dropped; in the mapping callbacks for setRequestVars,
setFolderVars, and setCollectionVars add description = '' to the destructured
parameters and include description in the returned object (alongside uid, name,
value, enabled, datatype, annotations, and conditional local) so
variable.description is preserved when mapping variables.
🪄 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: 77341724-a26b-496c-9d91-ec41283cab44
📒 Files selected for processing (1)
packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
…nd preserve variable value type in `yml` (#8251)
…nd preserve variable value type in `yml` (usebruno#8251)
Description
Secret env vars support annotations in bru and a type field in yml. Env, collection and folder variables preserve data types in yml via a datatype prop, and external secrets blocks survive read/save.
Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit
New Features
Improvements
Tests