Skip to content

feat: support annotations for secret environment variables in bru and preserve variable value type in yml - #8251

Merged
sid-bruno merged 2 commits into
usebruno:mainfrom
lohit-bruno:secret_environment_variables_annotations_support
Jun 12, 2026
Merged

sid-bruno merged 2 commits into
usebruno:mainfrom
lohit-bruno:secret_environment_variables_annotations_support

Conversation

@lohit-bruno

@lohit-bruno lohit-bruno commented Jun 12, 2026 •

Copy link
Copy Markdown
Collaborator

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:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

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

    • Support for typed environment variables (number, boolean, object) and preserved datatypes
    • External secrets blocks for environments
    • Annotations preserved for secret environment variables
  • Improvements

    • Datatypes and external secrets are retained during edits, imports, and round-trip save/load
  • Tests

    • Expanded test coverage validating typed variables, external secrets, annotations, parsing and serialization

…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.
@coderabbitai

coderabbitai Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds explicit variable datatype support and externalSecrets handling end-to-end: types/schemas, YML parse/stringify, bru grammar and json serialization, validation tests, and Redux state updates with tests.

Changes

Typed Environment Variables and External Secrets Support

Layer / File(s) Summary
Schema types and contracts
packages/bruno-schema-types/src/common/variables.ts, packages/bruno-schema-types/src/collection/environment.ts
Add VariableDatatype/EnvironmentVariableDatatype unions, datatype on Variable/EnvironmentVariable, new ExternalSecretVariables/ExternalSecrets types, and optional Environment.externalSecrets.
YML variable conversion
packages/bruno-filestore/src/formats/yml/common/variables.ts, packages/bruno-filestore/src/formats/yml/tests/variables.spec.js
Add isTypedValue type-guard; toOpenCollectionVariables emits {type,data} for non-string datatypes; toBrunoVariables reads typed values and sets datatype accordingly; tests cover conversions.
Environment parse & stringify
packages/bruno-filestore/src/formats/yml/parseEnvironment.ts, packages/bruno-filestore/src/formats/yml/stringifyEnvironment.ts, packages/bruno-filestore/src/formats/yml/tests/parseEnvironment.spec.js
parseEnvironment/stringifyEnvironment now preserve non-string datatype as {type,data} values and normalize/emit externalSecrets; added round-trip tests including secrets and falsy typed values.
Bru grammar & serialization
packages/bruno-lang/v2/src/envToJson.js, packages/bruno-lang/v2/src/jsonToEnv.js, packages/bruno-lang/v2/tests/annotations.spec.js
Extend bru grammar to parse vars:externalsecrets:<type> blocks and annotated array items; map array entries to {name,annotations}; jsonToEnv emits vars:externalsecrets blocks and updates secret var serialization; tests added.
Schema validation & tests
packages/bruno-schema/src/collections/index.js, packages/bruno-schema/src/collections/environmentSchema.spec.js, packages/bruno-schema/src/collections/requestSchema.spec.js
Add datatype to variable schemas and new externalSecrets schemas; tests validate datatype preservation, provider-specific externalSecrets keys, empty variables array handling, and rejection of unknown externalSecrets keys.
Redux vars mapping
packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
setRequestVars, setFolderVars, and setCollectionVars now include datatype and annotations when present in mapped vars.
Redux env events & tests
packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js, packages/bruno-app/src/providers/ReduxStore/slices/collections/environment-events.spec.js
collectionAddEnvFileEvent now preserves incoming environment.externalSecrets onto existing envs and clears externalSecrets when omitted; tests verify preservation/clearing and datatype retention across add/update flows.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested labels

pr-feature

Suggested reviewers

  • helloanoop
  • naman-bruno
  • sid-bruno
  • bijin-bruno

Poem

Typed vars and secrets in the fray,
From schema down to YAML play,
Grammar, parse, and Redux kept,
Tests ensure no data stepped,
Small types now lead the way.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: annotation support for secret environment variables in bru format and preservation of variable value types in yml format.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Non-string typed variables are still dropped on save.

EnvironmentVariable.value now allows number, boolean, and object, but this filter keeps only string-valued entries. Any typed variable constructed in memory will disappear during YAML serialization before ensureString() 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 win

Consider consolidating duplicate type definitions.

VariableDatatype has identical literal values to EnvironmentVariableDatatype (defined in collection/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.value is the stringified form, while datatype preserves the original semantic type.

Code in the converters/filestore maps typed values by extracting/stringifying (e.g., variable.value.data / ensureString(...)) and then setting variable.datatype, so Variable.value: string | null aligns with actual usage and doesn’t imply runtime type mismatches. The main follow-up is to document this intent (e.g., JSDoc on Variable) 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

📥 Commits

Reviewing files that changed from the base of the PR and between 13363d7 and 9998ec2.

📒 Files selected for processing (15)
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/environment-events.spec.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
  • packages/bruno-filestore/src/formats/yml/common/variables.ts
  • packages/bruno-filestore/src/formats/yml/parseEnvironment.ts
  • packages/bruno-filestore/src/formats/yml/stringifyEnvironment.ts
  • packages/bruno-filestore/src/formats/yml/tests/parseEnvironment.spec.js
  • packages/bruno-filestore/src/formats/yml/tests/variables.spec.js
  • packages/bruno-lang/v2/src/envToJson.js
  • packages/bruno-lang/v2/src/jsonToEnv.js
  • packages/bruno-lang/v2/tests/annotations.spec.js
  • packages/bruno-schema-types/src/collection/environment.ts
  • packages/bruno-schema-types/src/common/variables.ts
  • packages/bruno-schema/src/collections/environmentSchema.spec.js
  • packages/bruno-schema/src/collections/index.js
  • packages/bruno-schema/src/collections/requestSchema.spec.js

Comment thread packages/bruno-lang/v2/src/envToJson.js Resolved
@lohit-bruno lohit-bruno changed the title feat: annotations and data types support for secret environment variables feat: support annotations for secret environment variables in bru and preserve variable value type in yml Jun 12, 2026
setRequestVars, setFolderVars and setCollectionVars rebuilt variables
with a field whitelist, dropping datatype (yml) and annotations (bru)
on save after an edit.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9998ec2 and ae9ea4b.

📒 Files selected for processing (1)
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js

@sid-bruno
sid-bruno merged commit d8d468f into usebruno:main Jun 12, 2026
15 of 19 checks passed
lohit-bruno added a commit that referenced this pull request Jun 15, 2026
abhishekp-bruno pushed a commit to abhishekp-bruno/bruno that referenced this pull request Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants