Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛Fix: prompt-module/@commitlint #336

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

matscube
Copy link
Contributor

@matscube matscube commented May 10, 2024

Current Issue

  • The OCO_PROMPT_MODULE=@commitlint functionality is currently not working as expected. The following steps reproduce the issue:
    • Run npm i @commitlint/cli
    • Create commitlint.config.js
    • Set OCO_PROMPT_MODULE=@commitlint
    • run oco commitlint force
    • => An error occurs

Identified Problems

  • There's a bug in src/modules/commitlint/utils.ts#getJSONBlock
    • consistency is not defined (a misspelling of input).
  • The method src/modules/commitlint/pwd-commitlint.ts#getCommitLintPWDConfig only supports the CJS version of the @commitlint/load package.
    • This method calls the @commitlint/load package using require. However, commitlint v19 and onwards only support pure ESM.

Proposed Changes

  • Fix the OCO_PROMPT_MODULE=@commitlint functionality
    • by correcting the bug in src/modules/commitlint/utils.ts#getJSONBlock.
  • Add support for the ESM version of @commitlint.
    • This change will ensure compatibility with both CJS and ESM versions of @commitlint.
    • Currently, the minimum supported version is v9 (as CJS) and the maximum supported version is v19 (as ESM, latest).
  • Add end-to-end tests related to commitlint to ensure the functionality works as expected.

Checklist

  • Manual Setup
    • git init
    • npm init
    • Setup commitlint
      • for v19
        • install commitlint( npm install --save-dev @commitlint/{cli,config-conventional}@19.x )
        • create commitlint config (as esm)
          • echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
        • set type: module in package.json
      • for v18
        • install commitlint ( npm install --save-dev @commitlint/{cli,config-conventional}@18.x )
        • create commitlint config (as cjs)
          • echo "module.exports = { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
    • Run oco config set OCO_PROMPT_MODULE=@commitlint
    • Run oco commitlint force
    • Run oco
    • Edit .opencommit-commitlint config
    • Run oco again

…nfig loading to support both CJS and ESM modules

💡 (pwd-commitlint.ts): Add detailed comments and error handling for better clarity and robustness in commitlint module loading process
…ies for commitlint configurations

🔧 (setup.sh): Add shell script to set up commitlint configurations for e2e tests
…o define test mock type for testing purposes

📝 (config.ts): Update documentation for OCO_TEST_MOCK_TYPE configuration key in configValidators and getConfig functions
📝 (testAi.ts): Add TEST_MOCK_TYPES constant array to define supported test mock types
📝 (testAi.ts): Update generateCommitMessage function to use OCO_TEST_MOCK_TYPE from config for different test mock types
📝 (commitlint.test.ts): Add e2e test for running "oco commitlint force" with different @commitlint versions using CJS and ESM
📝 (utils.ts): Add wait function to introduce delay in milliseconds for testing purposes
… version parameter for better code organization and readability

📝 (commitlint.test.ts): add test case for commitlint@9 using CJS to ensure proper functionality and compatibility
📝 (commitlint.test.ts): add test case for commitlint@18 using CJS to ensure proper functionality and compatibility
📝 (commitlint.test.ts): add test case for commitlint@19 using ESM to ensure proper functionality and compatibility
@di-sukharev
Copy link
Owner

hi man, please calm down! haha <3

let me know when i can review and merge it

…port configure

style(test/e2e/prompt-module/commitlint.test.ts): add missing semicolon for consistency
test(test/e2e/prompt-module/commitlint.test.ts): add e2e tests for @commitlint prompt-module integration
…n accuracy

♻️ (commitlint config): refactor commitlint.config.js to use ES module syntax
✨ (package.json): specify "type": "module" to support ES module syntax
@@ -1,11 +1,31 @@
import { ChatCompletionRequestMessage } from 'openai';
import { AiEngine } from './Engine';
import { getConfig } from '../commands/config';

export const TEST_MOCK_TYPES = [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the testing of OCO_PROMPT_MODULE=@commitlint, a TestAi that returns JSON data, not just a string, was needed. Therefore, I added a setting to select the output type of TestAi for testing purposes.

@@ -0,0 +1,11 @@
#!/bin/sh
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In order to conduct E2E tests for OCO_PROMPT_MODULE=@commitlint, it was necessary to prepare an environment where the commitlint package is installed.

  • Before running the E2E tests, we create node_modules according to the prepared package-lock.json (by setup.sh),
  • We copy the node_modules with commitlint installed into the test environment within the E2E test suite,
  • We are testing the commitlint command for each version of node_modules.

@matscube matscube marked this pull request as ready for review May 18, 2024 13:18
@matscube
Copy link
Contributor Author

@di-sukharev
Hello, The PR is ready and I wanted to let you know. Please review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants