fix(leanix-bridge): validate mapping partials and export parseLeanixMappingInput#2829
Conversation
…appingInput - parseLeanixMappingInput for untrusted mapping before merge - Specs: root keys, string records on factSheetTypes/relationTypes/metadataToFields - Export parseLeanixMappingInput from package entrypoint Made-with: Cursor
🦋 Changeset detectedLatest commit: b6764d4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 20 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughA new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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.
🧹 Nitpick comments (2)
packages/leanix-bridge/src/mapping.ts (1)
45-47: Consider usingTypeErrorfor type validation errors.Per JavaScript conventions and the static analysis hint, type check errors should throw
TypeErrorrather thanErrorfor better semantic clarity.♻️ Proposed fix
if (typeof input !== 'object' || Array.isArray(input)) { - throw new Error('LeanIX mapping must be a plain object (not an array or primitive)') + throw new TypeError('LeanIX mapping must be a plain object (not an array or primitive)') }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/leanix-bridge/src/mapping.ts` around lines 45 - 47, The type-check that currently throws new Error('LeanIX mapping must be a plain object (not an array or primitive)') should throw a TypeError instead; update the throw in the input validation branch (the if block checking typeof input !== 'object' || Array.isArray(input')) to throw new TypeError with the same message so type validation errors use the correct Error subclass (locate this in the mapping.ts validation logic where input is checked).packages/leanix-bridge/src/mapping.spec.ts (1)
11-47: Good test coverage for the new validation function.The tests appropriately cover null/undefined passthrough, empty object acceptance, root type validation, unknown key rejection, and non-string value validation for all three record fields.
Consider adding a positive test case for a fully valid config to complement the rejection tests:
💡 Optional: Add valid full config test
it('accepts empty object', () => { expect(parseLeanixMappingInput({})).toEqual({}) }) + + it('accepts valid full config', () => { + const validConfig = { + factSheetTypes: { system: 'Application' }, + relationTypes: { default: 'depends on' }, + metadataToFields: { title: 'name' }, + } + expect(parseLeanixMappingInput(validConfig)).toEqual(validConfig) + })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/leanix-bridge/src/mapping.spec.ts` around lines 11 - 47, Add a positive unit test that asserts parseLeanixMappingInput returns the expected normalized object for a fully valid config: create a test in the describe('parseLeanixMappingInput') block that calls parseLeanixMappingInput with an object containing valid string-valued factSheetTypes, relationTypes, and metadataToFields entries and expects the parsed result to equal the same (or normalized) object; reference the parseLeanixMappingInput symbol and place the test alongside the existing "accepts empty object" and rejection tests to ensure a successful round-trip for valid input.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/leanix-bridge/src/mapping.spec.ts`:
- Around line 11-47: Add a positive unit test that asserts
parseLeanixMappingInput returns the expected normalized object for a fully valid
config: create a test in the describe('parseLeanixMappingInput') block that
calls parseLeanixMappingInput with an object containing valid string-valued
factSheetTypes, relationTypes, and metadataToFields entries and expects the
parsed result to equal the same (or normalized) object; reference the
parseLeanixMappingInput symbol and place the test alongside the existing
"accepts empty object" and rejection tests to ensure a successful round-trip for
valid input.
In `@packages/leanix-bridge/src/mapping.ts`:
- Around line 45-47: The type-check that currently throws new Error('LeanIX
mapping must be a plain object (not an array or primitive)') should throw a
TypeError instead; update the throw in the input validation branch (the if block
checking typeof input !== 'object' || Array.isArray(input')) to throw new
TypeError with the same message so type validation errors use the correct Error
subclass (locate this in the mapping.ts validation logic where input is
checked).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 59a33607-a970-4016-a89a-c6799b87107c
📒 Files selected for processing (4)
.changeset/leanix-bridge-mapping-validation.mdpackages/leanix-bridge/src/index.tspackages/leanix-bridge/src/mapping.spec.tspackages/leanix-bridge/src/mapping.ts
Summary
This PR contains
@likec4/leanix-bridgecode and tests only, scoped for a focused review:parseLeanixMappingInput: validate untrusted partial LeanIX mapping (e.g. from YAML/JSON) before merge — plain object, allowed top-level keys only, string records forfactSheetTypes,relationTypes, andmetadataToFields.mergeWithDefault: usesparseLeanixMappingInputso invalid partials fail fast.parseLeanixMappingInputre-exported from the package entrypoint.Includes changeset:
.changeset/leanix-bridge-mapping-validation.md.Companion (docs / skills / MCP copy): #2828 — no file overlap; either can merge first.
Motivation
Keeps LeanIX bridge validation and tests in a small, reviewable PR. Documentation and agent skills live in the companion PR above.
Verification
Per CONTRIBUTING, run tests with
pnpm testafter a clean tree.Stale compiled
*.jsfiles underpackages/*/src/are gitignored (see.gitignore— “Compiled artifacts (do not commit)”). If they are left on disk from a previous local build, Vite/Vitest may resolve those before the.tssources and produce misleading failures (wrong module graph, snapshot drift).pnpm clean(and removing any remaining ignoredpackages/*/src/**/*.jsif needed) restores the layout the maintainers expect before runningpnpm test.After a clean, run
pnpm generateifpackages/language-serverfails with missinggenerated/*(see AGENTS.md).Suggested local sequence:
pnpm clean→pnpm install(if needed) →pnpm generate(if needed) →pnpm test.This PR does not change the diagram app or docs site UI; Playwright E2E viewports (
pnpm test:e2e) are optional for reviewers here and are not required to validate these package-only changes.Checklist
mainbefore creating this PR.pnpm test:e2eonly if you want full Playwright coverage unrelated to this diff.)(Lines 11–12 are intentionally unchecked: this PR does not edit user-facing documentation files. Documentation and skills ship in #2828; this PR only adds the
@likec4/leanix-bridgechangeset.)