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

Fi 2962 execute outputters #541

Merged
merged 32 commits into from
Nov 15, 2024
Merged

Fi 2962 execute outputters #541

merged 32 commits into from
Nov 15, 2024

Conversation

Shaumik-Ashraf
Copy link
Contributor

@Shaumik-Ashraf Shaumik-Ashraf commented Oct 8, 2024

Summary

To inferno execute add:

  • --outputter option that defaults to console
  • new spinner on console outputter
  • a plain text outputter (no colors or spinner)
  • a quiet outputter (no output)
  • a json outputter, which should copy Inferno's REST API results endpoints.

JSON Output format (for dev_validator suite):

[
  {
    "id": "c2c564ec-1a4d-4c5e-a90f-692133a45e5c",
    "created_at": "2024-10-08T17:08:18.764-04:00",
    "inputs": [
      {
        "name": "url",
        "label": "FHIR Server Base Url",
        "description": null,
        "value": "https://hapi.fhir.org/baseR4",
        "type": "text"
      },
      {
        "name": "access_token",
        "label": "Bearer/Access Token",
        "description": null,
        "value": null,
        "type": "text"
      },
      {
        "name": "patient_id",
        "label": "Patient ID",
        "description": null,
        "value": "1234321",
        "type": "text"
      }
    ],
    "optional": false,
    "outputs": [

    ],
    "requests": [

    ],
    "result": "pass",
    "test_run_id": "92302803-1f13-46ef-a66e-793a92ac5fd1",
    "test_session_id": "cG9laeggvmM",
    "test_suite_id": "dev_validator",
    "updated_at": "2024-10-08T17:08:18.764-04:00"
  },
  {
    "id": "482d9df5-9941-4e46-a302-ae441ea47889",
    "created_at": "2024-10-08T17:08:18.763-04:00",
    "inputs": [

    ],
    "optional": false,
    "outputs": [

    ],
    "requests": [

    ],
    "result": "pass",
    "test_run_id": "92302803-1f13-46ef-a66e-793a92ac5fd1",
    "test_session_id": "cG9laeggvmM",
    "test_suite_id": "dev_validator",
    "updated_at": "2024-10-08T17:08:18.763-04:00"
  },
  {
    "id": "70f3b03b-0d72-4150-9129-d46231d48558",
    "created_at": "2024-10-08T17:08:18.760-04:00",
    "inputs": [
      {
        "name": "url",
        "label": "FHIR Server Base Url",
        "description": null,
        "value": "https://hapi.fhir.org/baseR4",
        "type": "text"
      },
      {
        "name": "access_token",
        "label": "Bearer/Access Token",
        "description": null,
        "value": null,
        "type": "text"
      },
      {
        "name": "patient_id",
        "label": "Patient ID",
        "description": null,
        "value": "1234321",
        "type": "text"
      }
    ],
    "optional": false,
    "outputs": [

    ],
    "requests": [

    ],
    "result": "pass",
    "test_group_id": "dev_validator-patient_group",
    "test_run_id": "92302803-1f13-46ef-a66e-793a92ac5fd1",
    "test_session_id": "cG9laeggvmM",
    "updated_at": "2024-10-08T17:08:18.760-04:00"
  },
  {
    "id": "6c6b4a39-5a1e-4035-92f1-3ee41c7fd18d",
    "created_at": "2024-10-08T17:08:18.757-04:00",
    "inputs": [
      {
        "name": "url",
        "value": "https://hapi.fhir.org/baseR4",
        "type": "text"
      },
      {
        "name": "access_token",
        "value": null,
        "type": "text"
      },
      {
        "name": "patient_id",
        "value": "1234321",
        "type": "text"
      }
    ],
    "optional": false,
    "outputs": [

    ],
    "requests": [
      {
        "id": "baddae85-49d7-490d-b4b3-7b00dfd93d11",
        "direction": "outgoing",
        "index": 279,
        "result_id": "96ff10ed-4fd1-40d8-bb7e-294b866428b3",
        "status": 200,
        "timestamp": "2024-10-08T17:08:18.579-04:00",
        "url": "https://hapi.fhir.org/baseR4/Patient/1234321",
        "verb": "get"
      }
    ],
    "result": "pass",
    "test_id": "dev_validator-patient_group-patient_validate_test",
    "test_run_id": "92302803-1f13-46ef-a66e-793a92ac5fd1",
    "test_session_id": "cG9laeggvmM",
    "updated_at": "2024-10-08T17:08:18.757-04:00"
  },
  {
    "id": "96ff10ed-4fd1-40d8-bb7e-294b866428b3",
    "created_at": "2024-10-08T17:08:18.572-04:00",
    "inputs": [
      {
        "name": "url",
        "value": "https://hapi.fhir.org/baseR4",
        "type": "text"
      },
      {
        "name": "access_token",
        "value": null,
        "type": "text"
      },
      {
        "name": "patient_id",
        "value": "1234321",
        "type": "text"
      }
    ],
    "optional": false,
    "outputs": [

    ],
    "requests": [
      {
        "id": "baddae85-49d7-490d-b4b3-7b00dfd93d11",
        "direction": "outgoing",
        "index": 279,
        "result_id": "96ff10ed-4fd1-40d8-bb7e-294b866428b3",
        "status": 200,
        "timestamp": "2024-10-08T17:08:18.579-04:00",
        "url": "https://hapi.fhir.org/baseR4/Patient/1234321",
        "verb": "get"
      }
    ],
    "result": "pass",
    "test_id": "dev_validator-patient_group-patient_read_test",
    "test_run_id": "92302803-1f13-46ef-a66e-793a92ac5fd1",
    "test_session_id": "cG9laeggvmM",
    "updated_at": "2024-10-08T17:08:18.572-04:00"
  }
]

Testing Guidance

  1. checkout branch
  2. bundle install
  3. bundle exec inferno services start
  4. console outputter w/ spinner:
bundle exec inferno execute -s dev_validator -i "url:https://hapi.fhir.org/baseR4" patient_id:1234321 
  1. plain outputter:
bundle exec inferno execute -s dev_validator -o plain -i "url:https://hapi.fhir.org/baseR4" patient_id:1234321 
  1. quiet outputter:
bundle exec inferno execute -s dev_validator -o quiet -i "url:https://hapi.fhir.org/baseR4" patient_id:1234321 
  1. json outputter:
bundle exec inferno execute -s dev_validator -o json -i "url:https://hapi.fhir.org/baseR4" patient_id:1234321 

Copy link

codecov bot commented Oct 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.06%. Comparing base (17fd170) to head (157b3c3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #541   +/-   ##
=======================================
  Coverage   84.06%   84.06%           
=======================================
  Files         262      262           
  Lines       11410    11410           
  Branches     1254     1254           
=======================================
  Hits         9592     9592           
  Misses       1808     1808           
  Partials       10       10           
Flag Coverage Δ
backend 92.19% <ø> (ø)
frontend 79.33% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Shaumik-Ashraf Shaumik-Ashraf self-assigned this Oct 10, 2024
Gemfile Outdated
end
gem "tty-spinner", "~> 0.9.3"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would have to go in the gemspec.

inflections.acronym 'JSON'
end

OUTPUTTER_WHITELIST = %w[console plain json quiet].freeze
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is all fine, but a Hash mapping the option to the outputter class would be a lot simpler. I don't think being dynamic buys us much here, since we would need to alter code here, as well as documentation when adding new outputters anyway.


module Inferno
module CLI
class Execute
# @private
class ConsoleOutputter
COLOR = Pastel.new
class ConsoleOutputter < JSONOutputter
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unless I'm missing something, I don't think it makes sense for this to inherit from JSONOutputter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It inherits serialize


def print_error(_options, exception)
puts "Error: #{exception.full_message(highlight: false)}"
puts exception.backtrace&.join('\n')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this different from the console outputter version? Also, doesn't full_message already include the stack trace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Plain outputter needs highlight: false or it outputs ANSI code \e[1 (to make it bold).

But the backtrace part was redundant so I'm removing that.

class Execute
# @private
class QuietOutputter
# rubocop:disable Lint/UnusedMethodArgument
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't disable this rule. Prefix the arguments with underscore if they're not used.

@Shaumik-Ashraf Shaumik-Ashraf requested review from Jammjammjamm and removed request for Jammjammjamm November 14, 2024 22:34
@Shaumik-Ashraf Shaumik-Ashraf merged commit af1e650 into main Nov 15, 2024
10 checks passed
@Shaumik-Ashraf Shaumik-Ashraf deleted the fi-2962-execute-outputters branch November 15, 2024 17:18
@Shaumik-Ashraf Shaumik-Ashraf mentioned this pull request Nov 25, 2024
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.

2 participants