Skip to content

chore: Refactor 'metaData.js'#382

Merged
zongqichen merged 4 commits intomainfrom
chore/refactor-metaData
Mar 16, 2026
Merged

chore: Refactor 'metaData.js'#382
zongqichen merged 4 commits intomainfrom
chore/refactor-metaData

Conversation

@mlakov
Copy link
Contributor

@mlakov mlakov commented Mar 10, 2026

♻️ Refactor metaData.js with Frozen Compiler Map and Modernized Tests

Refactor

Replaced the large switch statement in metaData.js with a frozen compilers map for cleaner, more maintainable metadata compilation logic. Also modernized test assertions to use idiomatic async Jest patterns throughout the test suite.

Changes

  • lib/metaData.js:

    • Added path module import and reordered assert/cdsc declarations for better organization.
    • Extracted extractServiceName(url) and extractCompilerType(url) as standalone helper functions, replacing inline URL parsing logic.
    • Removed the _getServersFromAnnotation helper and the switch-based compiler dispatch; replaced with a frozen compilers object (Object.freeze) mapping each COMPILER_TYPES key to its own async handler.
    • Each compiler entry now directly declares its own contentType, eliminating the manual content type derivation logic previously inferred from the compiler name.
    • Consolidated error handling into a single .catch() with a unified log message: Compilation failed for service ${serviceName} (compiler: ${compilerType}) - ${error.message}.
  • __tests__/unit/metaData.test.js:

    • Replaced all try/catch assertion patterns with await expect(...).rejects.toThrow(...) for idiomatic async Jest error testing.
    • Replaced const result = await ...; expect(result)... patterns with await expect(...).resolves.toEqual(...) for cleaner async success assertions.
    • Removed the "getMetadata should handle invalid URL format" test case (the explicit "Invalid URL format" error no longer exists).
    • Renamed "getMetadata should raise error when get edmx failed" to "getMetadata should raise error when get OpenAPI failed" to align with the updated test URL and error.
  • 🔄 Regenerate and Update Summary

📬 Subscribe to the Hyperspace PR Bot DL to get the latest announcements and pilot features!

PR Bot Information

Version: 1.18.5 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • Event Trigger: pull_request.edited
  • LLM: anthropic--claude-4.6-sonnet
  • Output Template: Default Template
  • Summary Prompt: Default Prompt
  • Correlation ID: 26e52080-1e60-11f1-9318-c014ee0ee278

@mlakov mlakov requested a review from zongqichen March 10, 2026 06:41
@mlakov mlakov added the run-e2e Trigger e2e test pipeline label Mar 10, 2026
Copy link
Contributor

@hyperspace-insights hyperspace-insights bot left a comment

Choose a reason for hiding this comment

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

The refactor is generally clean and well-structured. Two issues were raised: (1) the assert for unsupported format types fires synchronously before the .catch() error-logging handler, causing unsupported-format errors to be silently swallowed without logging; and (2) extractServiceName and extractCompilerType redundantly parse the same URL twice, which is also fragile for non-.json extensions — these should share a single parse.

PR Bot Information

Version: 1.17.99 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • Correlation ID: 1a62a280-1c4c-11f1-9007-7e27141b47b4
  • Event Trigger: pull_request.opened
  • Agent Instructions:
  • LLM: anthropic--claude-4.6-sonnet

@mlakov mlakov added the retry-e2e When the e2e pipeline failed, add retry-e2e label Mar 10, 2026
@ord-e2e-bot ord-e2e-bot bot removed the retry-e2e When the e2e pipeline failed, add retry-e2e label Mar 10, 2026
@mlakov mlakov added the retry-e2e When the e2e pipeline failed, add retry-e2e label Mar 10, 2026
@ord-e2e-bot ord-e2e-bot bot removed the retry-e2e When the e2e pipeline failed, add retry-e2e label Mar 10, 2026
@mlakov mlakov added retry-e2e When the e2e pipeline failed, add retry-e2e ready for review labels Mar 10, 2026
@mlakov mlakov marked this pull request as ready for review March 10, 2026 10:24
@ord-e2e-bot ord-e2e-bot bot removed the retry-e2e When the e2e pipeline failed, add retry-e2e label Mar 10, 2026
@mlakov mlakov requested a review from MariusPerleSAP March 10, 2026 16:26
@mlakov mlakov force-pushed the chore/refactor-metaData branch from 457344a to 467d034 Compare March 11, 2026 08:34
@mlakov mlakov added the retry-e2e When the e2e pipeline failed, add retry-e2e label Mar 11, 2026
@ord-e2e-bot ord-e2e-bot bot removed the retry-e2e When the e2e pipeline failed, add retry-e2e label Mar 11, 2026
@zongqichen zongqichen added the retry-e2e When the e2e pipeline failed, add retry-e2e label Mar 11, 2026
@ord-e2e-bot ord-e2e-bot bot removed the retry-e2e When the e2e pipeline failed, add retry-e2e label Mar 11, 2026
@mlakov mlakov requested a review from MariusPerleSAP March 12, 2026 09:04
Copy link
Contributor

@zongqichen zongqichen left a comment

Choose a reason for hiding this comment

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

Solid refactor and clean some legacy bugs or codes, appreciate it. Some comments we can discuss.

@mlakov mlakov force-pushed the chore/refactor-metaData branch 2 times, most recently from 509ba3c to f23d7ac Compare March 13, 2026 15:11
@mlakov mlakov force-pushed the chore/refactor-metaData branch from f23d7ac to 943d938 Compare March 13, 2026 19:05
@mlakov mlakov requested a review from zongqichen March 14, 2026 06:20
Copy link
Contributor

@zongqichen zongqichen left a comment

Choose a reason for hiding this comment

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

LGTM

@zongqichen zongqichen merged commit 2b8340f into main Mar 16, 2026
5 checks passed
@zongqichen zongqichen deleted the chore/refactor-metaData branch March 16, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review run-e2e Trigger e2e test pipeline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants