Repository navigation
feat: variable data types support - #8046
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds comprehensive typed-variable support: new datatype utilities, DatatypeSelector UI, table/editor adjustments, Redux persistence updates, filestore/OpenCollection converters, BRU/YML language tooling, Electron runtime parsing, and extensive unit and E2E tests/fixtures. ChangesTyped variables end-to-end
Estimated code review effort: Possibly related PRs:
Suggested reviewers:
✨ 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 |
data types support
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (11)
packages/bruno-common/src/utils/datatype.ts (1)
9-37: 💤 Low valueOuter
try/catchis redundant.None of the operations inside the outer block throw (the only throwing call,
JSON.parse, has its own innertry/catch). The wrapper can go, but it's harmless — leave it if you prefer the belt-and-braces.🤖 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-common/src/utils/datatype.ts` around lines 9 - 37, Remove the redundant outer try/catch wrapper in the parseValueByDatatype function: the only potentially-throwing operation (JSON.parse) is already protected by its own inner try/catch, so eliminate the top-level try { ... } catch { ... } surrounding the datatype branches in parseValueByDatatype to simplify control flow and avoid swallowing unexpected errors unnecessarily.packages/bruno-filestore/src/formats/yml/common/datatype.ts (1)
2-8: ⚡ Quick winUse
import type/export typeforBrunoVariableDatatype
BrunoVariableDatatypeis defined as a type inpackages/bruno-common/src/utils/datatype.ts.packages/bruno-filestore/tsconfig(.build).jsondoesn’t enableisolatedModules, so the TS1205-specific risk is unlikely here, but re-exporting it via a value export is still brittle—export it as a type instead.♻️ Proposed fix
import type { VariableTypedValue } from '`@opencollection/types/common/variables`'; import { parseValueByDatatype, - BrunoVariableDatatype, isBrunoVariableDatatype } from '`@usebruno/common/utils`'; +import type { BrunoVariableDatatype } from '`@usebruno/common/utils`'; -export { BrunoVariableDatatype, isBrunoVariableDatatype }; +export type { BrunoVariableDatatype }; +export { isBrunoVariableDatatype };🤖 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/common/datatype.ts` around lines 2 - 8, BrunoVariableDatatype is a type and should be imported/exported as a type-only symbol: change the import to use "import type" for BrunoVariableDatatype (keep parseValueByDatatype and isBrunoVariableDatatype as regular imports) and change the re-export to "export type { BrunoVariableDatatype }" while leaving "export { isBrunoVariableDatatype }" as a value export so only the type is re-exported.packages/bruno-filestore/src/formats/yml/stringifyFolder.spec.ts (1)
36-36: ⚡ Quick winAdd defensive checks before non-null assertions.
If
parseFolderreturns an unexpected structure or the parsing fails, the non-null assertions will cause the test to crash rather than fail with a clear message.🛡️ Proposed defensive checks
const reparsed = parseFolder(yml); +expect(reparsed.request).toBeDefined(); +expect(reparsed.request!.vars).toBeDefined(); +expect(reparsed.request!.vars!.req).toBeDefined(); const reqVars = reparsed.request!.vars!.req!;🤖 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/stringifyFolder.spec.ts` at line 36, The test currently uses non-null assertions on reparsed.request!.vars!.req! which will crash the test on unexpected parseFolder output; update stringifyFolder.spec.ts to defensively check the structure returned by parseFolder: verify reparsed is defined, then that reparsed.request, reparsed.request.vars and reparsed.request.vars.req are defined (use expect(...).toBeDefined() or conditional guards) and emit clear failure messages before accessing req; reference the symbols reparsed, request, vars, req and the parseFolder call to locate where to add these assertions/guards.packages/bruno-filestore/src/formats/yml/stringifyItem.spec.ts (1)
42-42: ⚡ Quick winAdd defensive checks before non-null assertions.
Similar to the folder test, add explicit assertions to verify the structure before accessing nested properties.
🛡️ Proposed defensive checks
const reparsed = parseItem(yml); +expect(reparsed.request).toBeDefined(); +expect(reparsed.request!.vars).toBeDefined(); +expect(reparsed.request!.vars.req).toBeDefined(); const reqVars = reparsed.request!.vars.req;🤖 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/stringifyItem.spec.ts` at line 42, Add explicit defensive assertions before using the non-null assertion on reparsed.request so the test fails with a clear message instead of throwing; before the line referencing reqVars (reparsed.request!.vars.req) add checks such as asserting reparsed.request is defined and has vars (e.g., expect(reparsed.request).toBeDefined() and expect(reparsed.request!.vars).toBeDefined()) and/or assert that vars.req exists, then assign const reqVars = reparsed.request!.vars.req safely; this targets the usage of reparsed.request!.vars.req in stringifyItem.spec.ts.packages/bruno-js/tests/setEnvVar.spec.js (1)
64-89: ⚖️ Poor tradeoffDocument the silent data loss risk in production code.
The tests correctly document that functions, symbols, and circular objects serialize to
""and are "silently lost on save round-trip." Consider adding runtime warnings in the actualsetEnvVarimplementation or documentation to alert users that these types won't persist correctly.🤖 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-js/tests/setEnvVar.spec.js` around lines 64 - 89, The tests show functions, symbols, and circular objects stored via setEnvVar end up serialized to "" by valueToString and are silently lost on persist; update the setEnvVar implementation to detect non-serializable values (e.g., call valueToString(value) and/or attempt JSON.stringify/valueToString and treat a returned empty string as non-serializable) and emit a runtime warning when the caller passes { persist: true } for such values; reference setEnvVar, valueToString, mergeAndPersistEnvironment, and persistentEnvVariables—log a clear warning (including the env var name and type) to the module logger or console and skip persisting or coerce behavior so users are informed of the data-loss risk.packages/bruno-lang/v2/src/jsonToCollectionBru.js (1)
379-381: ⚡ Quick winExtract duplicated
serializeVarhelper and move it up in the file.The same
serializeVarfunction is defined twice (once for reqvars at line 379 and again for resvars at line 409). As noted in past review comments, this helper should be moved up in the file and defined once to avoid duplication.♻️ Proposed refactor
const stripLastLine = (text) => { if (!text || !text.length) return text; return text.replace(/(\r?\n)$/, ''); }; +const serializeVar = (item, prefix = '') => { + return `${serializeAnnotations(buildAnnotationsFromVariable(item))}${prefix}${item.name}: ${getValueString(item.value)}`; +}; + const jsonToCollectionBru = (json) => { const { meta, query, headers, auth, script, tests, vars, docs } = json; // ... rest of function let reqvars = _.get(vars, 'req'); let resvars = _.get(vars, 'res'); if (reqvars && reqvars.length) { const varsEnabled = _.filter(reqvars, (v) => v.enabled && !v.local); const varsDisabled = _.filter(reqvars, (v) => !v.enabled && !v.local); const varsLocalEnabled = _.filter(reqvars, (v) => v.enabled && v.local); const varsLocalDisabled = _.filter(reqvars, (v) => !v.enabled && v.local); - const serializeVar = (item, prefix = '') => { - return `${serializeAnnotations(buildAnnotationsFromVariable(item))}${prefix}${item.name}: ${getValueString(item.value)}`; - }; - bru += `vars:pre-request {`; // ... rest of reqvars block } if (resvars && resvars.length) { const varsEnabled = _.filter(resvars, (v) => v.enabled && !v.local); const varsDisabled = _.filter(resvars, (v) => !v.enabled && !v.local); const varsLocalEnabled = _.filter(resvars, (v) => v.enabled && v.local); const varsLocalDisabled = _.filter(resvars, (v) => !v.enabled && v.local); - const serializeVar = (item, prefix = '') => { - return `${serializeAnnotations(buildAnnotationsFromVariable(item))}${prefix}${item.name}: ${getValueString(item.value)}`; - }; - bru += `vars:post-response {`; // ... rest of resvars block }Also applies to: 409-411
🤖 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-lang/v2/src/jsonToCollectionBru.js` around lines 379 - 381, There are two identical helpers named serializeVar (used for reqvars and resvars); extract a single serializeVar function to a higher scope (above where reqvars and resvars are built) and remove the duplicate definition, making sure the shared serializeVar uses buildAnnotationsFromVariable and getValueString and is referenced by both the request and response variable serialization code (so both places call serializeVar(item, prefix) instead of redefining it).packages/bruno-lang/v2/src/jsonToBru.js (1)
666-668: ⚡ Quick winExtract duplicated
serializeVarhelper to reduce code duplication.The same
serializeVarfunction is defined twice (once for reqvars at line 666 and again for resvars at line 694). Consider defining it once before the reqvars block and reusing it for both.♻️ Proposed refactor
let reqvars = _.get(vars, 'req'); let resvars = _.get(vars, 'res'); + const serializeVar = (item, prefix = '') => { + return `${serializeAnnotations(buildAnnotationsFromVariable(item))}${prefix}${item.name}: ${getValueString(item.value)}`; + }; + if (reqvars && reqvars.length) { const varsEnabled = _.filter(reqvars, (v) => v.enabled && !v.local); const varsDisabled = _.filter(reqvars, (v) => !v.enabled && !v.local); const varsLocalEnabled = _.filter(reqvars, (v) => v.enabled && v.local); const varsLocalDisabled = _.filter(reqvars, (v) => !v.enabled && v.local); bru += `vars:pre-request {`; - const serializeVar = (item, prefix = '') => { - return `${serializeAnnotations(buildAnnotationsFromVariable(item))}${prefix}${item.name}: ${getValueString(item.value)}`; - }; - if (varsEnabled.length) { bru += `\n${indentString(varsEnabled.map((item) => serializeVar(item)).join('\n'))}`; } // ... rest of reqvars block } if (resvars && resvars.length) { const varsEnabled = _.filter(resvars, (v) => v.enabled && !v.local); const varsDisabled = _.filter(resvars, (v) => !v.enabled && !v.local); const varsLocalEnabled = _.filter(resvars, (v) => v.enabled && v.local); const varsLocalDisabled = _.filter(resvars, (v) => !v.enabled && v.local); - const serializeVar = (item, prefix = '') => { - return `${serializeAnnotations(buildAnnotationsFromVariable(item))}${prefix}${item.name}: ${getValueString(item.value)}`; - }; - bru += `vars:post-response {`; // ... rest of resvars block }Also applies to: 694-696
🤖 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-lang/v2/src/jsonToBru.js` around lines 666 - 668, The helper serializeVar is duplicated for reqvars and resvars; extract a single function and reuse it: create one serializeVar(item, prefix = '') that returns `${serializeAnnotations(buildAnnotationsFromVariable(item))}${prefix}${item.name}: ${getValueString(item.value)}` placed before the reqvars block, remove the second definition, and update both reqvars and resvars code paths to call this single serializeVar; keep the same parameter names and ensure references to serializeAnnotations, buildAnnotationsFromVariable, and getValueString remain unchanged.tests/variable-datatypes/create-via-ui.spec.ts (1)
73-73: ⚡ Quick winReplace fixed sleeps with event-driven waits for stability.
These
page.waitForTimeout(...)calls make the test slower and can still be flaky. Prefer waiting on concrete UI/state signals (existing row/type-label assertions, save completion indicators, or post-save persisted-state checks) instead of wall-clock delays.Suggested direction
- await page.waitForTimeout(200); + // rely on explicit assertion that confirms the mutation/render completed - await page.waitForTimeout(500); + // wait for a deterministic save-complete signal (UI/state), then continue - await page.waitForTimeout(200); + // rely on type-label/value assertion for synchronization - await page.waitForTimeout(500); + // wait for env save completion signal before post-save assertionsAs per coding guidelines: “Try to reduce usage of
page.waitForTimeout();in code unless absolutely necessary and the locator cannot be found using existingexpect()playwright calls”.Also applies to: 85-85, 207-207, 212-212
🤖 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 `@tests/variable-datatypes/create-via-ui.spec.ts` at line 73, The test uses fixed sleeps (await page.waitForTimeout(200)) which are slow and flaky; replace them with event-driven waits tied to UI/state changes: for example, after creating/saving a variable use await page.waitForResponse(...) to wait for the save API response or await page.waitForSelector(...) / await expect(someRowOrTypeLabelLocator).toBeVisible() to wait for the new row or type-label to appear, and after edits use await page.waitForFunction(...) or await expect(persistedStateLocator).toHaveText(...) to assert persistence; update every occurrence of page.waitForTimeout (including the ones at the same block and noted around lines 85, 207, 212) to use these locator/response-based waits (refer to page, save button / save API, and the row/type-label locators used elsewhere in create-via-ui.spec.ts).tests/variable-datatypes/fixtures/workspace/collections/bru/folder/request.bru (1)
8-19: ⚡ Quick winAvoid duplicating query params in both URL and
params:queryblock.Line 8 and Lines 13-19 define the same params twice. Keep only
params:query(or only inline URL params) to prevent drift and flaky args assertions.Suggested cleanup
post { - url: https://httpbin.org/anything?q=hi&p_str={{req_str}}&p_num={{req_num}}&p_bool={{req_bool}}&p_obj={{req_obj}} + url: https://httpbin.org/anything body: json auth: none }🤖 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 `@tests/variable-datatypes/fixtures/workspace/collections/bru/folder/request.bru` around lines 8 - 19, The request currently duplicates query parameters by placing them in the URL string and again in the params:query block; remove the inline query string from the url value (leave url as the base endpoint, e.g. https://httpbin.org/anything) and keep the params:query block as the single source of truth so p_str, p_num, p_bool, p_obj and q are only defined in params:query; update any tests or consumers that expect inline params to use params:query instead.tests/variable-datatypes/parsed-from-fixture.spec.ts (2)
226-235: 🏗️ Heavy liftNetwork reliance on httpbin.org makes these tests non-hermetic — the Linux run already hit a
502 Bad Gateway.
sendAndAssertAllTestsPass(and the multipart/form-urlencoded tests) post to a live external service, so a transient upstream outage fails the suite regardless of correctness. This also conflicts with the parallel-safe/no-external-state expectation for E2E tests. Consider routing these against a local/mocked HTTP endpoint so the wire-format assertions stay deterministic.As per coding guidelines: "E2E tests must be parallel-safe. No shared user data directories, ports, files, DBs, caches, clipboard assumptions, or global app state."
🤖 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 `@tests/variable-datatypes/parsed-from-fixture.spec.ts` around lines 226 - 235, The tests call external httpbin.org which makes them non-hermetic; change sendAndAssertAllTestsPass (and the multipart/form-urlencoded test helpers) to target a local/mock HTTP endpoint instead of the live service: implement a Playwright route or an in-process test HTTP server that returns the same responses and wire-format for the requests, ensure the mock is started/stubbed per-test (using unique ports or request interception) so tests are parallel-safe, and update assertions to use the mock’s responses rather than relying on httpbin.org.
126-137: ⚡ Quick winReplace the fixed
waitForTimeout(300)with an event-driven wait.Line 134 already confirms the label flipped; the draft/
has-changes-iconstate is the actual signal callers depend on before saving. Wait on that instead of a magic sleep.As per coding guidelines: "Replace magic timeouts with event-driven waits in E2E tests." The same applies to `waitForTimeout(50)` (line 209) and `waitForTimeout(150)` (line 281).♻️ Proposed change
await expect(trigger).toHaveText(newType); - // Let the dispatched Redux mutation propagate before the caller saves. - await page.waitForTimeout(300); + // Wait for the dispatched mutation to mark the tab dirty before the caller saves. + await expect(page.locator('.request-tab.active .has-changes-icon')).toBeVisible();🤖 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 `@tests/variable-datatypes/parsed-from-fixture.spec.ts` around lines 126 - 137, The test uses a fixed sleep in changeRowDatatype (function changeRowDatatype) after asserting the .type-label text; replace the magic waitForTimeout(300) with an event-driven wait that waits for the row's "has-changes-icon"/draft state to appear (or update) so callers know the Redux mutation propagated before saving; locate the row Locator passed into changeRowDatatype and wait on a selector like row.locator('.has-changes-icon') (e.g., toBeVisible or toHaveCount(1)) or wait for the draft attribute/state change on that row, and apply the same pattern to the other two fixed waits in the spec (the waitForTimeout(50) and waitForTimeout(150)) so all three become event-driven waits tied to the UI state.
🤖 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/components/EnvironmentVariablesTable/index.js`:
- Line 599: The value prop currently sets value={typeof variable.value ===
'string' ? variable.value : JSON.stringify(variable.value, null, 2)} which
causes null/undefined to render as "null"/"undefined"; update the logic in the
EnvironmentVariablesTable component where variable.value is used (the value prop
for the editor/input) to check for variable.value === null || variable.value ===
undefined and use an empty string (or placeholder) in that case, otherwise keep
the existing behavior (string as-is, non-string JSON.stringify). Ensure you
update any helper/inline expression referencing variable.value to handle
null/undefined consistently.
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js`:
- Around line 2299-2309: The secret branch currently drops the datatype when
persisting (the block using v.secret and valueToString(found.value)), causing
typed secrets to become plain strings; update that branch to preserve or
propagate the datatype (use found.datatype or fall back to v.datatype) and
include it in the returned object alongside valueToString(found.value) so
secrets keep their datatype metadata. Locate the branch that checks v.secret
(references: v, found, valueToString) and return { ...rest, value:
valueToString(found.value), ...(datatype ? { datatype } : {}) } where datatype
is taken from found.datatype || v.datatype.
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js`:
- Around line 420-425: The code currently unconditionally overwrites
variable.datatype during ephemeral updates, causing deletes to restore
persistedValue but not the original datatype; modify the logic so you do not
clobber an existing datatype: only infer and assign variable.datatype when it is
currently undefined (e.g., if (!variable.datatype) variable.datatype = inferred
=== 'string' ? undefined : inferred), or alternatively capture the previous
datatype into the rollback/persisted state (persistedValue.previousDatatype) and
restore that on bru.deleteEnvVar() rollback; reference variable.datatype,
getDatatypeFromValue, persistedValue (rollback state), and the
bru.setEnvVar()/bru.deleteEnvVar() flow when implementing the fix.
In `@tests/environments/api-setEnvVar/api-setEnvVar-with-persist-typed.spec.ts`:
- Around line 61-62: The test uses newApp.firstWindow() immediately after
restartApp(), which can race on slow first-window startup; replace that with
waitForReadyPage(newApp) so the test waits for the app to reach
[data-app-state="loaded"] before interacting—call waitForReadyPage(newApp) and
use its returned page instead of newApp.firstWindow(); keep restartApp() as-is
and only swap the window-acquisition to waitForReadyPage to ensure reliable
startup handling.
In `@tests/variable-datatypes/parsed-from-fixture.spec.ts`:
- Around line 586-591: After opening the global environment settings with
openEnvironmentSettings(page, 'global'), the global env table is not scrolled so
trailing virtualized rows like strict_glob_num_str never mount; call
scrollEnvTableToBottom(page) after openEnvironmentSettings and before the
expectEnvVarTypeLabel assertions (e.g., before checking 'strict_glob_num_str')
so the virtualizer renders those rows; update the test sequence around
openEnvironmentSettings and expectEnvVarTypeLabel to include
scrollEnvTableToBottom(page) for the global table.
- Around line 297-318: The hover helper is racing against delayed hide timers:
after calling each popup._hidePopup({ immediate: true }) in hoverVarInBody,
ensure the DOM is actually free of any .CodeMirror-brunoVarInfo before
proceeding by waiting for the selector to disappear (e.g., await
page.waitForFunction(() => !document.querySelector('.CodeMirror-brunoVarInfo'))
or equivalent). This guarantees that any scheduled hide paths won’t remove the
next tooltip mid-assert; reference hoverVarInBody, the _hidePopup({ immediate:
true }) call, and the '.CodeMirror-brunoVarInfo' selector when making the
change.
---
Nitpick comments:
In `@packages/bruno-common/src/utils/datatype.ts`:
- Around line 9-37: Remove the redundant outer try/catch wrapper in the
parseValueByDatatype function: the only potentially-throwing operation
(JSON.parse) is already protected by its own inner try/catch, so eliminate the
top-level try { ... } catch { ... } surrounding the datatype branches in
parseValueByDatatype to simplify control flow and avoid swallowing unexpected
errors unnecessarily.
In `@packages/bruno-filestore/src/formats/yml/common/datatype.ts`:
- Around line 2-8: BrunoVariableDatatype is a type and should be
imported/exported as a type-only symbol: change the import to use "import type"
for BrunoVariableDatatype (keep parseValueByDatatype and isBrunoVariableDatatype
as regular imports) and change the re-export to "export type {
BrunoVariableDatatype }" while leaving "export { isBrunoVariableDatatype }" as a
value export so only the type is re-exported.
In `@packages/bruno-filestore/src/formats/yml/stringifyFolder.spec.ts`:
- Line 36: The test currently uses non-null assertions on
reparsed.request!.vars!.req! which will crash the test on unexpected parseFolder
output; update stringifyFolder.spec.ts to defensively check the structure
returned by parseFolder: verify reparsed is defined, then that reparsed.request,
reparsed.request.vars and reparsed.request.vars.req are defined (use
expect(...).toBeDefined() or conditional guards) and emit clear failure messages
before accessing req; reference the symbols reparsed, request, vars, req and the
parseFolder call to locate where to add these assertions/guards.
In `@packages/bruno-filestore/src/formats/yml/stringifyItem.spec.ts`:
- Line 42: Add explicit defensive assertions before using the non-null assertion
on reparsed.request so the test fails with a clear message instead of throwing;
before the line referencing reqVars (reparsed.request!.vars.req) add checks such
as asserting reparsed.request is defined and has vars (e.g.,
expect(reparsed.request).toBeDefined() and
expect(reparsed.request!.vars).toBeDefined()) and/or assert that vars.req
exists, then assign const reqVars = reparsed.request!.vars.req safely; this
targets the usage of reparsed.request!.vars.req in stringifyItem.spec.ts.
In `@packages/bruno-js/tests/setEnvVar.spec.js`:
- Around line 64-89: The tests show functions, symbols, and circular objects
stored via setEnvVar end up serialized to "" by valueToString and are silently
lost on persist; update the setEnvVar implementation to detect non-serializable
values (e.g., call valueToString(value) and/or attempt
JSON.stringify/valueToString and treat a returned empty string as
non-serializable) and emit a runtime warning when the caller passes { persist:
true } for such values; reference setEnvVar, valueToString,
mergeAndPersistEnvironment, and persistentEnvVariables—log a clear warning
(including the env var name and type) to the module logger or console and skip
persisting or coerce behavior so users are informed of the data-loss risk.
In `@packages/bruno-lang/v2/src/jsonToBru.js`:
- Around line 666-668: The helper serializeVar is duplicated for reqvars and
resvars; extract a single function and reuse it: create one serializeVar(item,
prefix = '') that returns
`${serializeAnnotations(buildAnnotationsFromVariable(item))}${prefix}${item.name}:
${getValueString(item.value)}` placed before the reqvars block, remove the
second definition, and update both reqvars and resvars code paths to call this
single serializeVar; keep the same parameter names and ensure references to
serializeAnnotations, buildAnnotationsFromVariable, and getValueString remain
unchanged.
In `@packages/bruno-lang/v2/src/jsonToCollectionBru.js`:
- Around line 379-381: There are two identical helpers named serializeVar (used
for reqvars and resvars); extract a single serializeVar function to a higher
scope (above where reqvars and resvars are built) and remove the duplicate
definition, making sure the shared serializeVar uses
buildAnnotationsFromVariable and getValueString and is referenced by both the
request and response variable serialization code (so both places call
serializeVar(item, prefix) instead of redefining it).
In `@tests/variable-datatypes/create-via-ui.spec.ts`:
- Line 73: The test uses fixed sleeps (await page.waitForTimeout(200)) which are
slow and flaky; replace them with event-driven waits tied to UI/state changes:
for example, after creating/saving a variable use await
page.waitForResponse(...) to wait for the save API response or await
page.waitForSelector(...) / await
expect(someRowOrTypeLabelLocator).toBeVisible() to wait for the new row or
type-label to appear, and after edits use await page.waitForFunction(...) or
await expect(persistedStateLocator).toHaveText(...) to assert persistence;
update every occurrence of page.waitForTimeout (including the ones at the same
block and noted around lines 85, 207, 212) to use these locator/response-based
waits (refer to page, save button / save API, and the row/type-label locators
used elsewhere in create-via-ui.spec.ts).
In
`@tests/variable-datatypes/fixtures/workspace/collections/bru/folder/request.bru`:
- Around line 8-19: The request currently duplicates query parameters by placing
them in the URL string and again in the params:query block; remove the inline
query string from the url value (leave url as the base endpoint, e.g.
https://httpbin.org/anything) and keep the params:query block as the single
source of truth so p_str, p_num, p_bool, p_obj and q are only defined in
params:query; update any tests or consumers that expect inline params to use
params:query instead.
In `@tests/variable-datatypes/parsed-from-fixture.spec.ts`:
- Around line 226-235: The tests call external httpbin.org which makes them
non-hermetic; change sendAndAssertAllTestsPass (and the
multipart/form-urlencoded test helpers) to target a local/mock HTTP endpoint
instead of the live service: implement a Playwright route or an in-process test
HTTP server that returns the same responses and wire-format for the requests,
ensure the mock is started/stubbed per-test (using unique ports or request
interception) so tests are parallel-safe, and update assertions to use the
mock’s responses rather than relying on httpbin.org.
- Around line 126-137: The test uses a fixed sleep in changeRowDatatype
(function changeRowDatatype) after asserting the .type-label text; replace the
magic waitForTimeout(300) with an event-driven wait that waits for the row's
"has-changes-icon"/draft state to appear (or update) so callers know the Redux
mutation propagated before saving; locate the row Locator passed into
changeRowDatatype and wait on a selector like row.locator('.has-changes-icon')
(e.g., toBeVisible or toHaveCount(1)) or wait for the draft attribute/state
change on that row, and apply the same pattern to the other two fixed waits in
the spec (the waitForTimeout(50) and waitForTimeout(150)) so all three become
event-driven waits tied to the UI state.
🪄 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: bed82917-eebd-4976-bb9f-b203ac7a23e9
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (131)
package.jsonpackages/bruno-app/src/components/CollectionSettings/Vars/VarsTable/StyledWrapper.jspackages/bruno-app/src/components/CollectionSettings/Vars/VarsTable/index.jspackages/bruno-app/src/components/DatatypeSelector/StyledWrapper.jspackages/bruno-app/src/components/DatatypeSelector/index.jspackages/bruno-app/src/components/EditableTable/index.jspackages/bruno-app/src/components/EnvironmentVariablesTable/index.jspackages/bruno-app/src/components/FolderSettings/Vars/VarsTable/StyledWrapper.jspackages/bruno-app/src/components/FolderSettings/Vars/VarsTable/index.jspackages/bruno-app/src/components/RequestPane/Vars/VarsTable/StyledWrapper.jspackages/bruno-app/src/components/RequestPane/Vars/VarsTable/index.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/index.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/index.spec.jspackages/bruno-app/src/providers/ReduxStore/slices/global-environments.jspackages/bruno-app/src/utils/codemirror/brunoVarInfo.jspackages/bruno-app/src/utils/collections/export.jspackages/bruno-app/src/utils/collections/index.jspackages/bruno-app/src/utils/collections/index.spec.jspackages/bruno-app/src/utils/environments.jspackages/bruno-app/src/utils/environments.spec.jspackages/bruno-app/src/utils/tests/collections/datatype-export-import.spec.jspackages/bruno-common/src/utils/datatype.spec.tspackages/bruno-common/src/utils/datatype.tspackages/bruno-common/src/utils/index.tspackages/bruno-converters/babel.config.jspackages/bruno-converters/jest.config.jspackages/bruno-converters/package.jsonpackages/bruno-converters/rollup.config.jspackages/bruno-converters/src/opencollection/common/datatype.tspackages/bruno-converters/src/opencollection/common/variables.tspackages/bruno-converters/src/opencollection/environment.tspackages/bruno-converters/tests/opencollection/environment.spec.jspackages/bruno-converters/tests/opencollection/variables.spec.jspackages/bruno-converters/tsconfig.jsonpackages/bruno-electron/src/store/global-environments.jspackages/bruno-electron/src/utils/collection.jspackages/bruno-electron/tests/store/global-environments.test.jspackages/bruno-filestore/package.jsonpackages/bruno-filestore/rollup.config.jspackages/bruno-filestore/src/formats/yml/common/actions.tspackages/bruno-filestore/src/formats/yml/common/datatype.spec.tspackages/bruno-filestore/src/formats/yml/common/datatype.tspackages/bruno-filestore/src/formats/yml/common/variables.spec.tspackages/bruno-filestore/src/formats/yml/common/variables.tspackages/bruno-filestore/src/formats/yml/parseCollection.spec.tspackages/bruno-filestore/src/formats/yml/parseEnvironment.spec.tspackages/bruno-filestore/src/formats/yml/parseEnvironment.tspackages/bruno-filestore/src/formats/yml/parseFolder.spec.tspackages/bruno-filestore/src/formats/yml/parseItem.spec.tspackages/bruno-filestore/src/formats/yml/stringifyCollection.spec.tspackages/bruno-filestore/src/formats/yml/stringifyEnvironment.spec.tspackages/bruno-filestore/src/formats/yml/stringifyEnvironment.tspackages/bruno-filestore/src/formats/yml/stringifyFolder.spec.tspackages/bruno-filestore/src/formats/yml/stringifyItem.spec.tspackages/bruno-filestore/tsconfig.build.jsonpackages/bruno-filestore/tsconfig.jsonpackages/bruno-js/src/bru.jspackages/bruno-js/tests/runtime.spec.jspackages/bruno-js/tests/setEnvVar.spec.jspackages/bruno-lang/package.jsonpackages/bruno-lang/v2/src/bruToJson.jspackages/bruno-lang/v2/src/collectionBruToJson.jspackages/bruno-lang/v2/src/envToJson.jspackages/bruno-lang/v2/src/jsonToBru.jspackages/bruno-lang/v2/src/jsonToCollectionBru.jspackages/bruno-lang/v2/src/jsonToEnv.jspackages/bruno-lang/v2/src/utils.jspackages/bruno-lang/v2/tests/bruToJson.spec.jspackages/bruno-lang/v2/tests/envToJson.spec.jspackages/bruno-lang/v2/tests/jsonToBru.spec.jspackages/bruno-lang/v2/tests/jsonToEnv.spec.jspackages/bruno-lang/v2/tests/utils.spec.jspackages/bruno-schema-types/src/collection/environment.tspackages/bruno-schema-types/src/common/variables.tspackages/bruno-schema/package.jsonpackages/bruno-schema/src/collections/index.jspackages/bruno-tests/collection/collection.brupackages/bruno-tests/collection/environments/Local.brupackages/bruno-tests/collection/environments/Prod.brupackages/bruno-tests/collection/variable-datatypes/folder.brupackages/bruno-tests/collection/variable-datatypes/form-urlencoded.brupackages/bruno-tests/collection/variable-datatypes/multipart.brupackages/bruno-tests/collection/variable-datatypes/typed vars.brupackages/bruno-tests/yml-collection/environments/Local.ymlpackages/bruno-tests/yml-collection/environments/Prod.ymlpackages/bruno-tests/yml-collection/opencollection.ymlpackages/bruno-tests/yml-collection/variable-datatypes/folder.ymlpackages/bruno-tests/yml-collection/variable-datatypes/form-urlencoded.ymlpackages/bruno-tests/yml-collection/variable-datatypes/multipart.ymlpackages/bruno-tests/yml-collection/variable-datatypes/typed-vars.ymlplaywright/index.tstests/environments/api-setEnvVar/api-setEnvVar-ephemeral-save.spec.tstests/environments/api-setEnvVar/api-setEnvVar-with-persist-typed.spec.tstests/environments/api-setEnvVar/api-setEnvVar-with-persist.spec.tstests/environments/api-setEnvVar/api-setEnvVar-without-persist.spec.tstests/environments/api-setEnvVar/fixtures/collection/api-setEnvVar-ephemeral-save.brutests/environments/api-setEnvVar/fixtures/collection/api-setEnvVar-with-persist-typed.brutests/environments/api-setEnvVar/fixtures/collection/environments/EphemeralSave.brutests/environments/api-setEnvVar/fixtures/collection/environments/Typed.brutests/environments/datatype-preservation/datatype-preservation.spec.tstests/environments/datatype-preservation/fixtures/bru/bruno.jsontests/environments/datatype-preservation/fixtures/bru/environments/typed_env.brutests/environments/datatype-preservation/fixtures/bru/test.brutests/environments/datatype-preservation/fixtures/yml/environments/typed_env.ymltests/environments/datatype-preservation/fixtures/yml/opencollection.ymltests/environments/datatype-preservation/fixtures/yml/test.ymltests/environments/datatype-preservation/init-user-data/collection-security.jsontests/environments/datatype-preservation/init-user-data/preferences.jsontests/global-environments/collection/set-global-nonstring.brutests/global-environments/non-string-values.spec.tstests/variable-datatypes/create-via-ui.spec.tstests/variable-datatypes/fixtures/import/datatypes-collection.ymltests/variable-datatypes/fixtures/workspace/collections/bru/bruno.jsontests/variable-datatypes/fixtures/workspace/collections/bru/collection.brutests/variable-datatypes/fixtures/workspace/collections/bru/environments/test_env.brutests/variable-datatypes/fixtures/workspace/collections/bru/folder/folder.brutests/variable-datatypes/fixtures/workspace/collections/bru/folder/form_urlencoded.brutests/variable-datatypes/fixtures/workspace/collections/bru/folder/multipart.brutests/variable-datatypes/fixtures/workspace/collections/bru/folder/request.brutests/variable-datatypes/fixtures/workspace/collections/yml/environments/test_env.ymltests/variable-datatypes/fixtures/workspace/collections/yml/folder/folder.ymltests/variable-datatypes/fixtures/workspace/collections/yml/folder/form_urlencoded.ymltests/variable-datatypes/fixtures/workspace/collections/yml/folder/multipart.ymltests/variable-datatypes/fixtures/workspace/collections/yml/folder/request.ymltests/variable-datatypes/fixtures/workspace/collections/yml/opencollection.ymltests/variable-datatypes/fixtures/workspace/environments/typed_global.ymltests/variable-datatypes/fixtures/workspace/workspace.ymltests/variable-datatypes/import.spec.tstests/variable-datatypes/init-user-data/preferences.jsontests/variable-datatypes/parsed-from-fixture.spec.ts
💤 Files with no reviewable changes (3)
- tests/global-environments/collection/set-global-nonstring.bru
- packages/bruno-js/src/bru.js
- tests/global-environments/non-string-values.spec.ts
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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-tests/src/index.js`:
- Around line 90-101: The error handler mounted via app.use that returns an echo
for '/api/echo/everything' should only do so for body-parser parse failures;
update the conditional in that middleware to check the error is a malformed-body
error (e.g., err.type === 'entity.parse.failed' or err.status === 400) before
returning the JSON with method, url, query, headers, body (req.rawBody);
otherwise call next(err) to avoid masking other failures.
In `@tests/variable-datatypes/create-via-ui.spec.ts`:
- Around line 211-213: Replace the fixed sleep after calling
locators.environment.saveButton().click() with an explicit wait for the actual
post-save UI change: after invoking locators.environment.saveButton().click(),
wait for a specific locator to update (for example the saved environment row or
its type label) using an assertion or a locator wait (e.g., waitForSelector /
waitForFunction / expect(locator).toHaveText) instead of
page.waitForTimeout(500); target the environment row/label locator used
elsewhere in this spec (e.g., the saved row locator or type label locator) so
the test proceeds only once the UI reflects the save.
🪄 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: 9486d455-ec1c-47d6-83f1-b06bd114ac22
📒 Files selected for processing (36)
packages/bruno-app/src/components/DatatypeSelector/index.jspackages/bruno-app/src/utils/collections/export.jspackages/bruno-app/src/utils/environments.spec.jspackages/bruno-app/src/utils/tests/collections/datatype-export-import.spec.jspackages/bruno-converters/jest.config.jspackages/bruno-converters/src/opencollection/common/datatype.tspackages/bruno-converters/src/opencollection/common/variables.tspackages/bruno-converters/src/opencollection/environment.tspackages/bruno-converters/tests/opencollection/environment.spec.jspackages/bruno-converters/tests/opencollection/variables.spec.jspackages/bruno-filestore/src/formats/yml/common/datatype.tspackages/bruno-filestore/src/formats/yml/common/variables.spec.tspackages/bruno-filestore/src/formats/yml/common/variables.tspackages/bruno-filestore/src/formats/yml/stringifyEnvironment.spec.tspackages/bruno-filestore/src/formats/yml/stringifyEnvironment.tspackages/bruno-js/tests/runtime.spec.jspackages/bruno-js/tests/setEnvVar.spec.jspackages/bruno-lang/v2/src/jsonToBru.jspackages/bruno-lang/v2/src/jsonToCollectionBru.jspackages/bruno-lang/v2/src/utils.jspackages/bruno-tests/collection/variable-datatypes/typed vars.brupackages/bruno-tests/src/index.jspackages/bruno-tests/yml-collection/variable-datatypes/typed-vars.ymltests/environments/api-setEnvVar/api-setEnvVar-ephemeral-save.spec.tstests/utils/page/locators.tstests/variable-datatypes/create-via-ui.spec.tstests/variable-datatypes/fixtures/import/datatypes-collection.ymltests/variable-datatypes/fixtures/workspace/collections/bru/collection.brutests/variable-datatypes/fixtures/workspace/collections/bru/folder/form_urlencoded.brutests/variable-datatypes/fixtures/workspace/collections/bru/folder/multipart.brutests/variable-datatypes/fixtures/workspace/collections/bru/folder/request.brutests/variable-datatypes/fixtures/workspace/collections/yml/folder/form_urlencoded.ymltests/variable-datatypes/fixtures/workspace/collections/yml/folder/multipart.ymltests/variable-datatypes/fixtures/workspace/collections/yml/folder/request.ymltests/variable-datatypes/fixtures/workspace/collections/yml/opencollection.ymltests/variable-datatypes/parsed-from-fixture.spec.ts
💤 Files with no reviewable changes (1)
- packages/bruno-js/tests/setEnvVar.spec.js
✅ Files skipped from review due to trivial changes (4)
- tests/variable-datatypes/fixtures/workspace/collections/bru/folder/form_urlencoded.bru
- packages/bruno-converters/jest.config.js
- tests/variable-datatypes/fixtures/workspace/collections/yml/opencollection.yml
- packages/bruno-converters/tests/opencollection/variables.spec.js
🚧 Files skipped from review as they are similar to previous changes (17)
- tests/variable-datatypes/fixtures/workspace/collections/bru/collection.bru
- tests/variable-datatypes/fixtures/import/datatypes-collection.yml
- packages/bruno-filestore/src/formats/yml/stringifyEnvironment.spec.ts
- packages/bruno-converters/tests/opencollection/environment.spec.js
- packages/bruno-lang/v2/src/jsonToBru.js
- packages/bruno-filestore/src/formats/yml/common/variables.spec.ts
- packages/bruno-converters/src/opencollection/common/variables.ts
- packages/bruno-js/tests/runtime.spec.js
- packages/bruno-app/src/utils/collections/export.js
- packages/bruno-filestore/src/formats/yml/common/datatype.ts
- packages/bruno-converters/src/opencollection/environment.ts
- packages/bruno-converters/src/opencollection/common/datatype.ts
- packages/bruno-app/src/components/DatatypeSelector/index.js
- packages/bruno-tests/yml-collection/variable-datatypes/typed-vars.yml
- tests/variable-datatypes/fixtures/workspace/collections/yml/folder/request.yml
- tests/environments/api-setEnvVar/api-setEnvVar-ephemeral-save.spec.ts
- packages/bruno-lang/v2/src/utils.js
73247c9 to
6f304e8
Compare
5717735 to
819cbec
Compare
Typed environment, collection, folder, and request variables (string / number / boolean / object) with read-time parsing across BRU, OpenCollection YML, and the legacy global env store.
Popup display and env/global/runtime scope lookups now keep 0, false, and ''. Editor seeds objects via JSON.stringify so a blur can't dispatch '[object Object]'. Adds hover-popup tests and broader fixture coverage; drops the global-environments non-string spec, now subsumed by the variable-datatypes suite.
Pretty-print object variable values so .bru and .yml serialize consistently, centralize the v2 serializeVar helper, and stabilize the variable-datatypes Playwright suite under CI worker contention.
Temporary: isolates the variable-datatypes suite into a dedicated Playwright project with full traces + failure screenshots, and points the CI e2e step at it, to capture inspectable artifacts for the mac/windows failures. Revert after diagnosis.
Resolve the hovered variable from the pointer position instead of the token bounding-box center, whose midpoint falls between rows when a {{var}} reference wraps and resolved coordsChar to the wrong character.
Vars/env tables use react-virtuoso, so rows outside the scroll viewport aren't in the DOM and toHaveText can't mount them. Scroll the target row into view first; replaces the env-only scrollEnvTableToBottom helper, which targeted the wrong (non-scrolling) element.
Restores the e2e action, package script, and Playwright config to upstream/main now that the variable-datatypes failures are fixed and confirmed green in CI.
Secret environment variables now carry a dataType (number/boolean/object) across collection and global environments in both bru and yml collections. The value is stringified before encryption and parsed back on decrypt, so a typed secret round-trips as its native JS type. Renames the variable `datatype` prop and `Datatype` identifiers to `dataType`/`DataType`.
WORD_PATTERN's `$-/` was parsed as a character range (matching `( ) % & ' * + ,`), so the word-extractor walked back across the `(` in `console.log(bru.get` and captured the whole expression as one token, resolving to the wrong context. Make `-` a literal so the token boundary stops at those characters.
EditableTable shared one react-virtuoso customScrollParent across the stacked request var tables, so the layout jumped on scroll; each table now uses its own content-sized scroller (mirroring the environment table). Also removes a spurious scrollbar caused by the 1px-bordered scroller under border-box, and renders object/array variable values pretty-printed via a new optional `indent` on valueToString.
The per-table content-sized scroller mis-positioned rows in the stacked pre/post variable tables — rows rendered far off-screen. Revert to the shared scroll-parent model with fixed-height rows so the whole vars tab scrolls as one unit (matching main). Typed object values render single-line in the value cell.
Add a render-after-scroll test for the request/collection/folder variable tables. Re-scroll the headers windowing assertions inside a retry: under parallel load the one-shot scroll fired before the virtualised list finished sizing, so it stopped short of the target row.
A secret set via bru.setEnvVar infers its dataType like any var (expect @Number, not none). Add fixtures + assertions for variables declared without a dataType (numeric/boolean/object-looking values stay strings), and run the BRU and YML datatype suites from one parameterized factory so they can't drift.
The component directory was committed as DatatypeSelector while every import and the component itself use DataTypeSelector. macOS resolved it; Linux did not, crashing the renderer before it signalled app-loaded and failing all Playwright suites.
…ling Add untyped variables (values that look typed but carry no annotation) to the datatype-preservation fixtures and assert they round-trip as plain strings. Share a scrollVirtuosoRowIntoView helper that targets the table-container scroller and retries the scroll-to-top to beat virtuoso restoring a persisted scroll position; use it from the datatype-preservation and parsed-from-fixture specs in place of their duplicated local helpers.
db3ffe3 to
88c8c35
Compare
Description
Typed environment, collection, folder, and request variables (string / number / boolean / object) with read-time parsing across BRU, OpenCollection YML.
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
Bug Fixes
Tests