Skip to content

test(report): pin the document count in the bulk title and bool cards - #563

Open
digalaviz wants to merge 2 commits into
awslabs:devfrom
digalaviz:test/467-pin-report-document-count
Open

digalaviz wants to merge 2 commits into
awslabs:devfrom
digalaviz:test/467-pin-report-document-count

Conversation

@digalaviz

Copy link
Copy Markdown
Contributor

tl;dr for humans

Follow-up to #474, as noted in its review. #474 fixed the bulk report title and the bool guard on the Executive Summary cards, but no test failed if either fix was reverted. This adds three tests that fail under those reverts, and one CHANGELOG clause for the ReportResult.metadata change. No library code changes.


for agents

- reverting _get_document_count to its 1.0.1 body brought back
  "None Documents" in the bulk title with every reporting test green
- the bool guard on the executive summary cards had no test either
- each new test fails under its mutation and passes on dev
- awslabs#474 changes ReportResult.metadata["document_count"] and the bulk
  title the same way as the card; the entry only named the card
@github-actions

Copy link
Copy Markdown

Security Scan Results

ASH Security Scan Report

  • Report generated: 2026-11-11T02:33:39+00:00
  • Time since scan: 3 minutes

Scan Metadata

  • Project: ASH
  • Scan executed: 2026-11-11T02:30:25+00:00
  • ASH version: 3.1.2

Summary

Scanner Results

The table below shows findings by scanner, with status based on severity thresholds and dependencies:

  • Severity levels:
    • Suppressed (S): Findings that have been explicitly suppressed and don't affect scanner status
    • Critical (C): Highest severity findings that require immediate attention
    • High (H): Serious findings that should be addressed soon
    • Medium (M): Moderate risk findings
    • Low (L): Lower risk findings
    • Info (I): Informational findings with minimal risk
  • Duration (Time): Time taken by the scanner to complete its execution
  • Actionable: Number of findings at or above the threshold severity level that require attention
  • Result:
    • PASSED = No findings at or above threshold
    • FAILED = Findings at or above threshold
    • MISSING = Required dependencies not available
    • SKIPPED = Scanner explicitly disabled
    • ERROR = Scanner execution error
  • Threshold: The minimum severity level that will cause a scanner to fail
    • Thresholds: ALL, LOW, MEDIUM, HIGH, CRITICAL
    • Source: Values in parentheses indicate where the threshold is set:
      • global (global_settings section in the ASH_CONFIG used)
      • config (scanner config section in the ASH_CONFIG used)
      • scanner (default configuration in the plugin, if explicitly set)
  • Statistics calculation:
    • All statistics are calculated from the final aggregated SARIF report
    • Suppressed findings are counted separately and do not contribute to actionable findings
    • Scanner status is determined by comparing actionable findings to the threshold
Scanner Suppressed Critical High Medium Low Info Actionable Result Threshold
bandit 0 6 0 0 6677 0 6 FAILED MEDIUM (global)
cdk-nag 0 0 0 0 0 0 0 PASSED MEDIUM (global)
cfn-nag 0 0 0 0 0 0 0 MISSING MEDIUM (global)
checkov 0 0 0 0 0 0 0 PASSED MEDIUM (global)
detect-secrets 0 1 0 0 0 0 1 SKIPPED MEDIUM (global)
grype 0 0 0 0 0 0 0 MISSING MEDIUM (global)
npm-audit 0 0 0 0 0 0 0 PASSED MEDIUM (global)
opengrep 0 0 0 0 0 0 0 MISSING MEDIUM (global)
semgrep 3 0 0 0 0 0 0 PASSED MEDIUM (global)
syft 0 0 0 0 0 0 0 MISSING MEDIUM (global)

Top 4 Hotspots

Files with the highest number of security findings:

Finding Count File Location
2 tests/comparators/test_anls_leaf_semantics.py
2 .ash/ash_output/converted/jupyter/examples__notebooks__Strands_Evals_FCC_Live_Agent__ipynb-converted.py
2 tests/structured_object_evaluator/test_rollup_node_semantics.py
1 tests/test_readme_examples.py

Detailed Findings

Show 7 actionable findings

Finding 1: SECRET-HEX-HIGH-ENTROPY-STRING

  • Severity: HIGH
  • Scanner: detect-secrets
  • Rule ID: SECRET-HEX-HIGH-ENTROPY-STRING
  • Location: tests/comparators/test_anls_leaf_semantics.py:89

Description:
Secret of type 'Hex High Entropy String' detected in file 'tests/comparators/test_anls_leaf_semantics.py' at line 89

Code Snippet:

Secret of type Hex High Entropy String detected

Finding 2: B310

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B310
  • Location: .ash/ash_output/converted/jupyter/examples__notebooks__Strands_Evals_FCC_Live_Agent__ipynb-converted.py:83-85

Description:
Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.

Code Snippet:

)
with urllib.request.urlopen(url, timeout=60) as resp:
    rows = [item["row"] for item in json.load(resp)["rows"]]

Finding 3: B108

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B108
  • Location: tests/comparators/test_anls_leaf_semantics.py:210-212

Description:
Probable insecure usage of temp file/directory.

Code Snippet:

uuid.UUID(int=1),
            pathlib.Path("/tmp/x"),
            b"bytes",

Finding 4: B307

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B307
  • Location: tests/structured_object_evaluator/test_rollup_node_semantics.py:1363-1369

Description:
Use of possibly insecure function - consider using safer ast.literal_eval.

Code Snippet:

def published_label(node: dict, section: str, object_lists: set) -> str:
            counts_objects = eval(  # noqa: S307
                cond.group(1),
                {},
                {"data": node, "section": section, "OBJECT_LISTS": object_lists},
            )
            return eval(unit.group(1), {}, {"counts_objects": counts_objects})  # noqa: S307

Finding 5: B307

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B307
  • Location: tests/structured_object_evaluator/test_rollup_node_semantics.py:1368-1370

Description:
Use of possibly insecure function - consider using safer ast.literal_eval.

Code Snippet:

)
            return eval(unit.group(1), {}, {"counts_objects": counts_objects})  # noqa: S307

Finding 6: B102

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B102
  • Location: tests/test_readme_examples.py:55-57

Description:
Use of exec detected.

Code Snippet:

with contextlib.redirect_stdout(out):
        exec(code, namespace)
    prints = [line for line in code.splitlines() if line.startswith("print(")]

Finding 7: B310

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B310
  • Location: .ash/ash_output/converted/jupyter/examples__notebooks__Strands_Evals_FCC_Live_Agent__ipynb-converted.py:83-85

Description:
Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.

Code Snippet:

)
with urllib.request.urlopen(url, timeout=60) as resp:
    rows = [item["row"] for item in json.load(resp)["rows"]]

Report generated by Automated Security Helper (ASH) at 2026-11-11T02:33:40+00:00

@vawsgit vawsgit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

needs changes

Two medium findings and four low ones, each in an inline comment, plus two optional notes. Measured at head be8d82c, with stickler imported from that checkout's src.

The PR's verification claims hold. Reverting _get_document_count to its 1.0.1 body fails both new reporter tests. Removing and not isinstance(value, bool) fails the bool test. The two test files give 61 passed.

To change:

  1. The test named for ReportResult.metadata never calls generate_report. With the metadata line back on the 1.0.1 lookup, the full suite gives 4119 passed, 13 skipped, 1 xfailed. (medium)
  2. The bool test mocks the gauge, and the gauge still scores cm_f1=True as a green 100%. (medium)
  3. No test pins a zero count, or a dict whose document_count is None. (low)
  4. The #467 CHANGELOG entry still omits that integer scores now show as 1.000 in a threshold colour, which the #474 review raised. (low)
  5. The new CHANGELOG clause does not state the new metadata values. (low)
  6. The dict test's docstring says the title uses a dict's count. It never does. (low)

Optional: an issue reference in the bool test's docstring, and a title assertion that does not pin the 1 Documents plural.

Each suggested test was run against head and against each mutation named in its comment, and ruff check is clean on them.

results = ProcessEvaluation(metrics={})

assert self.reporter._generate_title(results, True) == "Evaluation Report - 1 Documents"
assert self.reporter._get_document_count(results) == 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test is named for ReportResult.metadata, but it never calls generate_report. Neither new reporter test does: both call the private helpers only. So generate_report's metadata line and its page-title call can go back to the 1.0.1 lookup with every test passing.

"document_count": self._get_document_count(evaluation_results),

title=title or self._generate_title(results, is_bulk),

Measured at be8d82c, with stickler imported from that checkout's src:

  • Line 117 as getattr(evaluation_results, "document_count", 1): generate_report(ProcessEvaluation(metrics={}), path).metadata["document_count"] is None, and a dict with document_count: 7 reports 1. The full suite gives 4119 passed, 13 skipped, 1 xfailed.
  • Line 175 building the title inline with the 1.0.1 lookup: the written page's <title> is Evaluation Report - None Documents. tests/reporting gives 171 passed.

The existing metadata asserts cannot tell either change apart. They use a dict without the key (line 63) or a Mock with a set count (line 87, and test_output_validation.py:217).

The test below goes through generate_report. It passes at head. It fails under the _get_document_count revert from the PR body, under the line-117 change, and under the line-175 change.

Suggested change
assert self.reporter._get_document_count(results) == 1
assert self.reporter._get_document_count(results) == 1
def test_generate_report_never_shows_none_document_count(self):
"""generate_report's metadata and page title use the count, not None (#467)."""
for results, expected in (
(ProcessEvaluation(metrics={}), 1),
({'overall': {}, 'document_count': 7}, 7),
):
report = self.reporter.generate_report(results, self.output_path)
with open(self.output_path, encoding='utf-8') as f:
page = f.read()
assert report.success, report.errors
assert report.metadata["document_count"] == expected
assert 'None Documents' not in page


def test_executive_summary_does_not_score_a_bool_metric(self):
"""bool is an int subclass, so True must not render as a coloured 1.000."""
generator = SectionGenerator({'overall': {'cm_f1': True}}, self.mock_viz_engine)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test passes while the same Executive Summary still scores cm_f1=True. The gauge guard has no bool check, so a real report draws a green 100% Overall gauge above the uncoloured True card.

f1_score = metrics.get('cm_f1', metrics.get('f1', 0))
if isinstance(f1_score, (int, float)) and f1_score > 0:
html_string += f'<div class="performance-section">{self.viz_engine.generate_performance_gauge(f1_score, config)}</div>'

The test cannot see the gauge. self.mock_viz_engine is a Mock(spec=VisualizationEngine): it receives generate_performance_gauge(True, config) and writes a Mock repr into the page. '1.000' not in result would pass even with the real engine, because the gauge prints 100%. Measured at be8d82c with a real VisualizationEngine: the gauge is conic-gradient(#28a745 100%, ...) labelled 100%, and both assertions still pass.

The field views break this docstring's rule word for word. A field with cm_f1: True renders as a green 1.000 bar in generate_field_performance_chart and a green 1.000 cell in generate_field_performance_table. The comment at section_generator.py:43-46 says the cards treat scores "consistently with the gauge and field views". For a bool, they do not.

if isinstance(f1_score, (int, float)):

tests/reporting/html/README.md covers this case: "when the question is what the renderer decides about real results, build the results for real."

Fix, one of:

  • Add and not isinstance(f1_score, bool) to section_generator.py:27, and assert self.mock_viz_engine.generate_performance_gauge.assert_not_called() in this test. With that check added, tests/reporting still gives 171 passed.
  • Keep the PR test-only: rename the test and its docstring so they claim the card only, and file the gauge and field views separately.


def test_get_document_count_reads_a_results_dict_key(self):
"""The title and ReportResult.metadata use a dict's document_count (#467)."""
assert self.reporter._get_document_count({'overall': {}, 'document_count': 7}) == 7

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new tests pin the count fallback for two inputs only: a ProcessEvaluation with no count, and a dict with 7. Two plausible rewrites of DataExtractor.get_document_count pass all 171 tests in tests/reporting (measured at be8d82c):

if isinstance(results, ProcessEvaluation):
count = getattr(results, 'document_count', None)
elif isinstance(results, dict):
count = results.get('document_count')
else:
count = None
return 1 if count is None else count

The test below passes at head and fails under each rewrite:

Suggested change
assert self.reporter._get_document_count({'overall': {}, 'document_count': 7}) == 7
assert self.reporter._get_document_count({'overall': {}, 'document_count': 7}) == 7
def test_get_document_count_keeps_zero_and_replaces_a_dict_none(self):
"""A count of 0 stays 0, and a dict's explicit None counts as 1 (#467)."""
assert self.reporter._get_document_count(ProcessEvaluation(document_count=0, metrics={})) == 0
assert self.reporter._get_document_count({'overall': {}, 'document_count': None}) == 1

Comment thread CHANGELOG.md
Comment on lines 29 to 30
the right document count.** A guard on a method that does not exist kept every
card blue regardless of `color_thresholds`, and the Documents card ignored a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This entry still leaves out one visible change from #474, which the #474 review raised. Integer scores changed from an uncoloured 1 to 1.000 in a threshold colour. "Kept every card blue" is also wrong for those cards: 1.0.1 showed an integer score as 1 in #010101.

Input {'overall': {'cm_precision': 0.444, 'cm_recall': 1}}:

  • 1.0.1: Precision 0.444 in #007bff, Recall 1 in #010101.
  • be8d82c: Precision 0.444 in #fd7e14, Recall 1.000 in #28a745.

Anyone who diffs or parses report HTML sees 1 become 1.000, and no entry explains it. RELEASING.md says: "Entries are for changes a user can observe."

Suggested wording for that sentence: "A guard on a method that does not exist kept every float score blue regardless of color_thresholds, and showed an integer score such as 1 uncoloured. Integer scores now show as 1.000 in a threshold colour."

Comment thread CHANGELOG.md
Comment on lines +32 to +33
now read in one place, `DataExtractor.get_document_count`, so the bulk title
and `ReportResult.metadata["document_count"]` change the same way

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This clause does not say what the metadata values become, and "the same way" reads as if a dict's count now reaches the title.

  • ReportResult.metadata["document_count"] for a ProcessEvaluation with no count: None in 1.0.1, 1 now.
  • The same key for a results dict with document_count: 7: 1 in 1.0.1, 7 now.
  • A dict's title is Evaluation Report in both versions, because a dict is never bulk (html_reporter.py:149).

A caller that read None as "count unknown" now gets 1, and this entry does not tell them. The #474 review asked for these two metadata changes to be named.

Suggested change
now read in one place, `DataExtractor.get_document_count`, so the bulk title
and `ReportResult.metadata["document_count"]` change the same way
now read in one place, `DataExtractor.get_document_count`. The bulk title and
`ReportResult.metadata["document_count"]` now show `1` instead of `None` for a
`ProcessEvaluation` without a count, and the metadata reports a results dict's
own `document_count` instead of `1`

assert self.reporter._get_document_count(results) == 1

def test_get_document_count_reads_a_results_dict_key(self):
"""The title and ReportResult.metadata use a dict's document_count (#467)."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The title half of this docstring is false. _generate_html_content sets is_bulk = isinstance(results, ProcessEvaluation) (html_reporter.py:149), so a dict's title is always Evaluation Report and never shows its count. The test also reads neither the title nor the metadata: it calls _get_document_count only.

Suggested change
"""The title and ReportResult.metadata use a dict's document_count (#467)."""
"""_get_document_count reads a results dict's document_count key (#467)."""

assert 'None' not in result

def test_executive_summary_does_not_score_a_bool_metric(self):
"""bool is an int subclass, so True must not render as a coloured 1.000."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Optional: this regression test's docstring has no issue reference. The bool check came from #474, for #467, and the PR's two other new tests end with (#467). docs/docs/Getting-Started/Contributing/testing-guide.md:287 asks for one: "Documentation: Include issue reference in docstring".

Suggested change
"""bool is an int subclass, so True must not render as a coloured 1.000."""
"""bool is an int subclass, so True must not render as a coloured 1.000 (#467)."""

"""A ProcessEvaluation without document_count counts as 1, not None (#467)."""
results = ProcessEvaluation(metrics={})

assert self.reporter._generate_title(results, True) == "Evaluation Report - 1 Documents"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Optional: the exact match also pins the 1 Documents plural, which the PR body leaves out of scope. A later fix to 1 Document would then have to edit this #467 test. This check still fails on None Documents and accepts either plural:

Suggested change
assert self.reporter._generate_title(results, True) == "Evaluation Report - 1 Documents"
assert "- 1 Document" in self.reporter._generate_title(results, True)

@sromoam sromoam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with vawsgit's review. Items 1 and 2 still reproduce on this head (measured against this branch), and those are the ones I'd want fixed before merging. Two small, optional additions:

Smaller

  • When you add the zero and dict-None cases from vawsgit's item 3, consider putting them in test_data_extractors.py next to :243-249, where get_document_count is already pinned for the dict key and the None fallback. Please keep the two new reporter tests, or their generate_report version from item 1: they're the only tests that fail if _get_document_count (html_reporter.py:316-318) goes back to its 1.0.1 body.
  • test_section_generator.py:127 hard-codes the neutral hex, so restyling #010101 at section_generator.py:52 fails the test with no change in behaviour. Taking the colour from ColorUtils, as the sibling test at :98 does, keeps the "not coloured" check without the hex (inline below).

results = ProcessEvaluation(metrics={})

assert self.reporter._generate_title(results, True) == "Evaluation Report - 1 Documents"
assert self.reporter._get_document_count(results) == 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A small one, alongside vawsgit's item 3: the zero and dict-None cases would sit best in test_data_extractors.py next to :243-249, where DataExtractor.get_document_count is already pinned. Nothing pins them today. return count or 1 at data_extractors.py:105, or .get('document_count', 1) in the dict branch, still passes all of tests/reporting (measured against this branch). Please keep this assert, or its generate_report(...).metadata version from item 1: it's one of the only two tests that fail if _get_document_count goes back to its 1.0.1 body.

Comment on lines +123 to +127
generator = SectionGenerator({'overall': {'cm_f1': True}}, self.mock_viz_engine)

result = generator.generate_executive_summary(ReportConfig())

assert 'style="color: #010101;">True' in result

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Optional: line 127 hard-codes #010101, so a restyle at section_generator.py:52 fails this test with no change in behaviour. '>True</div>' on its own would let a green True card pass, so here is a version that keeps the "not coloured" check without the hex, in the style of the sibling test at :98. It passes at head and still fails with the bool guard removed or with the bool coloured by threshold (measured against this branch):

Suggested change
generator = SectionGenerator({'overall': {'cm_f1': True}}, self.mock_viz_engine)
result = generator.generate_executive_summary(ReportConfig())
assert 'style="color: #010101;">True' in result
from stickler.reporting.html.utils import ColorUtils
generator = SectionGenerator({'overall': {'cm_f1': True}}, self.mock_viz_engine)
config = ReportConfig()
result = generator.generate_executive_summary(config)
excellent = ColorUtils.get_performance_color(1, config.color_thresholds)
assert '>True</div>' in result
assert f'color: {excellent};">True' not in result

This branch has not been deployed

No deployments
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.

3 participants