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

Replace ansiconv with ansi2html #15328

Merged
merged 4 commits into from
Aug 22, 2024
Merged

Conversation

jessicamack
Copy link
Member

SUMMARY

The ansiconv package is archived so I'm replacing it with a similar package that's still actively being worked on.

ISSUE TYPE
  • Bug, Docs Fix or other nominal change
COMPONENT NAME
  • Other
AWX VERSION
awx: 24.6.2
ADDITIONAL INFORMATION

The ansiconv package is archived so I'm replacing it with a similar package that's still actively being worked on.
@github-actions github-actions bot added component:api dependencies Pull requests that update a dependency file labels Jul 3, 2024
The version minimum was used to get the latest version while running the upgrader
@AlanCoding
Copy link
Member

The question I'm asking myself is: do we have tests for this view?

@pytest.mark.parametrize("format,content_type", formats)
@pytest.mark.django_db
def test_job_redaction_disabled(get, format, content_type, negative_test_cases, admin):
for test_data in negative_test_cases:
job = test_data['job']
response = get(reverse("api:job_stdout", kwargs={'pk': job.pk}) + "?format=" + format, user=admin, expect=200, format=format)
content = response.data['content'] if format == 'json' else response.data
content = smart_str(content)
assert response.data is not None
assert test_data['uri'].username in content
assert test_data['uri'].password in content

@pytest.mark.django_db
@pytest.mark.parametrize(
'Parent, Child, relation, view',
[
[Job, JobEvent, 'job', 'api:job_stdout'],
[AdHocCommand, AdHocCommandEvent, 'ad_hoc_command', 'api:ad_hoc_command_stdout'],
[_mk_project_update, ProjectUpdateEvent, 'project_update', 'api:project_update_stdout'],
[_mk_inventory_update, InventoryUpdateEvent, 'inventory_update', 'api:inventory_update_stdout'],
],
)
def test_text_stdout(sqlite_copy, Parent, Child, relation, view, get, admin):
job = Parent()
job.save()
for i in range(3):
Child(**{relation: job, 'stdout': 'Testing {}\n'.format(i), 'start_line': i}).save()
url = reverse(view, kwargs={'pk': job.pk}) + '?format=txt'
response = get(url, user=admin, expect=200)
assert smart_str(response.content).splitlines() == ['Testing %d' % i for i in range(3)]

So yes, we are generally hitting that view. And it does seem to hit the format types that would be seen.

But the assertion on the content produced is very light. I would like to see a little bit better of a confirmation. Could we just compare screens of the demo job template manually, like http://localhost:8013/api/v2/jobs/2/stdout/ does it still show the green text in the html format, for example. Does the txt format not have coloring markings at http://localhost:8013/api/v2/jobs/2/stdout/?format=txt?

Screenshot from 2024-07-03 21-45-29

@jessicamack
Copy link
Member Author

@AlanCoding confirming the HTML is displaying the correct colors
html-ouput

@@ -1,5 +1,5 @@
aiohttp>=3.9.4 # CVE-2024-30251
ansiconv==1.0.0 # UPGRADE BLOCKER: from 2013, consider replacing instead of upgrading
ansi2html>=1.9.1 # minimum version for 3.11+ Python
Copy link
Member

Choose a reason for hiding this comment

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

If that's the only reason, it probably doesn't need to be stated here. It's usually good to set a minimum version to the release that introduced a feature being used. The compatibility with the target environment is computed by the dependency resolver when pip install is doing its thing automatically. So tracking the same information manually doesn't typically make sense unless something is really broken and needs to be excluded somehow.

Instead, it might be useful to state what uses this and how.

Copy link
Member

Choose a reason for hiding this comment

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

I checked the source code, and it seems that the released and inspectable versions of the library for the past 12 years had the same API (class+method name) so the lower boundary is indeed not necessary: https://github.com/pycontribs/ansi2html/blob/0.9.3/ansi2html/converter.py#L211. The usage info would still be nice, though.

Copy link

sonarcloud bot commented Aug 21, 2024

@thedoubl3j thedoubl3j merged commit 1b5cdf6 into ansible:devel Aug 22, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked component:api dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants