sscpac / statick

Making code quality easier.
https://sscpac.github.io/statick/
Creative Commons Zero v1.0 Universal
74 stars 14 forks source link

Fix groovylint unit test. #493

Closed tdenewiler closed 9 months ago

tdenewiler commented 10 months ago

We are getting a unit test failure. The failure is in an integration test. I have not looked to see if anything changed with the upstream tool. The error is

=================================== FAILURES ===================================
  ____________________ test_groovylint_tool_plugin_scan_valid ____________________

      def test_groovylint_tool_plugin_scan_valid():
          """Integration test: Make sure the groovylint output hasn't changed."""
          plugin = setup_groovylint_tool_plugin()
          if not plugin.command_exists("npm-groovy-lint"):
              pytest.skip("Missing groovylint executable.")
          package = Package(
              "valid_package", os.path.join(os.path.dirname(__file__), "valid_package")
          )
          package["groovy_src"] = [
              os.path.join(os.path.dirname(__file__), "valid_package", "Jenkinsfile"),
              os.path.join(os.path.dirname(__file__), "valid_package", "test.gradle"),
              os.path.join(os.path.dirname(__file__), "valid_package", "test.groovy"),
          ]
          issues = plugin.scan(package, "level")
  >       assert not issues
  E       assert not [Issue(filename='/home/runner/work/statick/statick/tests/plugins/tool/groovylint_tool_plugin/valid_package/test_errors...essage="The String 'Hello World!' can be wrapped in single quotes instead of double quotes", cert_reference=None), ...]

  ../tests/plugins/tool/groovylint_tool_plugin/test_groovylint_tool_plugin.py:83: AssertionError
  ------------------------------ Captured log call -------------------------------
  WARNING  root:groovylint_tool_plugin.py:120 ValueError: Expecting value: line 1 column 1 (char 0)
  WARNING  root:groovylint_tool_plugin.py:120 ValueError: Expecting value: line 1 column 1 (char 0)
  WARNING  root:groovylint_tool_plugin.py:120 ValueError: Expecting value: line 1 column 1 (char 0)
  WARNING  root:groovylint_tool_plugin.py:120 ValueError: Expecting value: line 1 column 1 (char 0)
  WARNING  root:groovylint_tool_plugin.py:120 ValueError: Expecting value: line 1 column 1 (char 0)
  WARNING  root:groovylint_tool_plugin.py:120 ValueError: Expecting value: line 1 column 1 (char 0)

An example job with the failure is at https://github.com/sscpac/statick/actions/runs/7732454334/job/21082413604. From there we are getting groovylint from NPM at version 14.2.0.

tdenewiler commented 10 months ago

Unfortunately, all of the logs of passing unit tests in workflows are no longer available (there was no activity on this repo for >3 months and the workflow was disabled). I do not know what version of groovylint was installed on passing jobs.

Locally, I have 9.0.0 and the tests pass.

$ npm-groovy-lint --version
GroovyLint: Successfully processed CodeNarc: 
CodeNarc version 2.2.0

npm-groovy-lint version 9.0.0

Embeds:
CodeNarc version 2.2.0
- Groovy version 3.0.9 (superlite)

In the failing workflow I see version 14.2.0 installed: https://github.com/sscpac/statick/actions/runs/7732454334/job/21082413604

npm WARN EBADENGINE   package: 'npm-groovy-lint@14.2.0',

I will try updating my local version to 14.2.0, get the same errors as CI gets, and fix them.

tdenewiler commented 10 months ago

I have 14.2.0 installed locally and when I run

$ /usr/local/bin/npm-groovy-lint --serverhost http://127.0.0.1 --serverport 7484 --output json valid_package/Jenkinsfile

I get a whole mess of output that starts with

CodeNarcServer unexpected error:
{
  "message": "Request failed with status code 500",
  "name": "AxiosError",
  "stack": "AxiosError: Request failed with status code 500\n    at settle (/usr/local/lib/node_modules/npm-groovy-lint/node_modules/axios/dist/node/axios.cjs:1967:12)\n    at IncomingMessage.handleStreamEnd (/usr/local/lib/node_modules/npm-groovy-lint/node_modules/axios/dist/node/axios.cjs:3066:11)\n    at IncomingMessage.emit (node:events:525:35)\n    at endReadableNT (node:internal/streams/readable:1359:12)\n    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)\n    at Axios.request (/usr/local/lib/node_modules/npm-groovy-lint/node_modules/axios/dist/node/axios.cjs:3877:41)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async CodeNarcCaller.callCodeNarcServer (/usr/local/lib/node_modules/npm-groovy-lint/lib/codenarc-caller.js:80:24)\n    at async NpmGroovyLint.callCodeNarc (/usr/local/lib/node_modules/npm-groovy-lint/lib/groovy-lint.js:271:32)\n    at async NpmGroovyLint.run (/usr/local/lib/node_modules/npm-groovy-lint/lib/groovy-lint.js:68:13)\n    at async /usr/local/lib/node_modules/npm-groovy-lint/lib/index.js:12:9",
  "config": {
    "transitional": {
      "silentJSONParsing": true,
      "forcedJSONParsing": true,
      "clarifyTimeoutError": false
    },
    "adapter": [
      "xhr",
      "http"
    ],
    "transformRequest": [
      null
    ],
    "transformResponse": [
      null
    ],
    "timeout": 600000,
    "xsrfCookieName": "XSRF-TOKEN",
    "xsrfHeaderName": "X-XSRF-TOKEN",
    "maxContentLength": -1,
    "maxBodyLength": -1,
    "env": {},
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Content-Type": "application/json",
      "User-Agent": "axios/1.6.7",
      "Content-Length": "16446",
      "Accept-Encoding": "gzip, compress, deflate, br"
    },
...

I made changes to go through the output until we find a dictionary that matches the expected output. I was able to get the unit tests passing without making changes to the unit tests.

That type of output shows up when running from the command line manually, or when I run the tool as part of Statick. A quick google search did not show others with similar issues. It is possible I/we can install npm-groovy-lint in a way that fixes the errors, but the code changes should work on regular output the same as they do on the current output.