Skip to content

fuzzy1337.functional_metrics

fuzzy1337.functional_metrics

Score finite functional oracles and derive explainable capability reports.

RunStatus

Bases: StrEnum

Terminal assessment states that preserve crash and timeout truth.

Source code in fuzzy1337/functional_metrics.py
20
21
22
23
24
25
class RunStatus(StrEnum):
    """Terminal assessment states that preserve crash and timeout truth."""

    COMPLETED = "completed"
    CRASHED = "crashed"
    TIMED_OUT = "timed-out"

OracleCheck dataclass

Declare one finite check; unknown expectations require an incomplete oracle.

Attributes:

Name Type Description
identifier str

Exact finding/check key matched against normalized detections.

capability str

Matrix row key; several checks may exercise the same capability.

expected bool | None

Positive, negative, or unknown expected detection.

applicable bool

Whether this check applies to the declared scenario.

Source code in fuzzy1337/functional_metrics.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@dataclass(frozen=True, slots=True)
class OracleCheck:
    """Declare one finite check; unknown expectations require an incomplete oracle.

    Attributes:
        identifier: Exact finding/check key matched against normalized detections.
        capability: Matrix row key; several checks may exercise the same capability.
        expected: Positive, negative, or unknown expected detection.
        applicable: Whether this check applies to the declared scenario.
    """

    identifier: str
    capability: str
    expected: bool | None
    applicable: bool = True

    def __post_init__(self) -> None:
        """Reject ambiguous check identity, applicability, or expectation."""

        RequireIdentifier(self.identifier, "check identifier")
        RequireIdentifier(self.capability, "capability")

        if type(self.applicable) is not bool or (
            self.expected is not None and type(self.expected) is not bool
        ):
            raise ValueError("check applicability and expectation must be boolean or null")

        if not self.applicable and self.expected is not None:
            raise ValueError("non-applicable checks cannot declare an expectation")

__post_init__() -> None

Reject ambiguous check identity, applicability, or expectation.

Source code in fuzzy1337/functional_metrics.py
44
45
46
47
48
49
50
51
52
53
54
55
56
def __post_init__(self) -> None:
    """Reject ambiguous check identity, applicability, or expectation."""

    RequireIdentifier(self.identifier, "check identifier")
    RequireIdentifier(self.capability, "capability")

    if type(self.applicable) is not bool or (
        self.expected is not None and type(self.expected) is not bool
    ):
        raise ValueError("check applicability and expectation must be boolean or null")

    if not self.applicable and self.expected is not None:
        raise ValueError("non-applicable checks cannot declare an expectation")

ScenarioOracle dataclass

Versioned target metadata and finite expectations for one assessment.

Attributes:

Name Type Description
identifier str

Stable scenario identity.

target_pack str

Stable first-party or pinned external target pack identity.

target_version str

Exact target version or digest.

provenance str

Origin of the target and oracle, retained in JSON.

checks tuple[OracleCheck, ...]

Finite declared positive, negative, and applicability metadata.

complete bool

Whether this oracle exhaustively describes applicable expected checks.

required_evidence tuple[str, ...]

Roles required for evidence completeness measurement.

Source code in fuzzy1337/functional_metrics.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
@dataclass(frozen=True, slots=True)
class ScenarioOracle:
    """Versioned target metadata and finite expectations for one assessment.

    Attributes:
        identifier: Stable scenario identity.
        target_pack: Stable first-party or pinned external target pack identity.
        target_version: Exact target version or digest.
        provenance: Origin of the target and oracle, retained in JSON.
        checks: Finite declared positive, negative, and applicability metadata.
        complete: Whether this oracle exhaustively describes applicable expected checks.
        required_evidence: Roles required for evidence completeness measurement.
    """

    identifier: str
    target_pack: str
    target_version: str
    provenance: str
    checks: tuple[OracleCheck, ...]
    complete: bool
    required_evidence: tuple[str, ...] = ("stdout", "stderr", "invocation")

    def __post_init__(self) -> None:
        """Freeze metadata and prevent incomplete truth from claiming accuracy."""

        RequireIdentifier(self.identifier, "scenario identifier")
        RequireIdentifier(self.target_pack, "target pack")
        RequireText(self.target_version, "target version")
        RequireText(self.provenance, "provenance")
        checks = tuple(self.checks)
        UniqueIdentifiers(tuple(check.identifier for check in checks), "check identifiers")
        evidence = UniqueIdentifiers(self.required_evidence, "required evidence")

        if type(self.complete) is not bool:
            raise ValueError("oracle completeness must be boolean")

        if self.complete and any(check.applicable and check.expected is None for check in checks):
            raise ValueError("complete oracles require every applicable expectation")

        object.__setattr__(self, "checks", checks)
        object.__setattr__(self, "required_evidence", evidence)

__post_init__() -> None

Freeze metadata and prevent incomplete truth from claiming accuracy.

Source code in fuzzy1337/functional_metrics.py
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def __post_init__(self) -> None:
    """Freeze metadata and prevent incomplete truth from claiming accuracy."""

    RequireIdentifier(self.identifier, "scenario identifier")
    RequireIdentifier(self.target_pack, "target pack")
    RequireText(self.target_version, "target version")
    RequireText(self.provenance, "provenance")
    checks = tuple(self.checks)
    UniqueIdentifiers(tuple(check.identifier for check in checks), "check identifiers")
    evidence = UniqueIdentifiers(self.required_evidence, "required evidence")

    if type(self.complete) is not bool:
        raise ValueError("oracle completeness must be boolean")

    if self.complete and any(check.applicable and check.expected is None for check in checks):
        raise ValueError("complete oracles require every applicable expectation")

    object.__setattr__(self, "checks", checks)
    object.__setattr__(self, "required_evidence", evidence)

RawEvidence dataclass

Preserve exact textual assessment output under a declared evidence role.

Attributes:

Name Type Description
role str

Unique role such as stdout, stderr, or invocation.

media_type str

MIME type describing the preserved content.

content str

Exact text, including empty stderr or partial failed output.

Source code in fuzzy1337/functional_metrics.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
@dataclass(frozen=True, slots=True)
class RawEvidence:
    """Preserve exact textual assessment output under a declared evidence role.

    Attributes:
        role: Unique role such as stdout, stderr, or invocation.
        media_type: MIME type describing the preserved content.
        content: Exact text, including empty stderr or partial failed output.
    """

    role: str
    media_type: str
    content: str

    def __post_init__(self) -> None:
        """Validate role and media type without modifying raw output."""

        RequireIdentifier(self.role, "evidence role")
        RequireText(self.media_type, "media type")

        if not isinstance(self.content, str):
            raise ValueError("raw evidence content must be text")

__post_init__() -> None

Validate role and media type without modifying raw output.

Source code in fuzzy1337/functional_metrics.py
116
117
118
119
120
121
122
123
def __post_init__(self) -> None:
    """Validate role and media type without modifying raw output."""

    RequireIdentifier(self.role, "evidence role")
    RequireText(self.media_type, "media type")

    if not isinstance(self.content, str):
        raise ValueError("raw evidence content must be text")

FunctionalRun dataclass

Keep scanner/release identity, normalized detections, and raw evidence distinct.

Attributes:

Name Type Description
scenario_id str

ScenarioOracle identifier assessed by this run.

scanner_id str

Assessment producer; independent of target oracle identity.

release_id str

Scanner/product release or explicitly identified contract-probe version.

status RunStatus

Completed, crashed, or timed-out assessment state.

duration_seconds float

Measured finite nonnegative elapsed assessment duration.

detected_checks tuple[str, ...]

Normalized check identifiers; raw duplicates remain preserved.

discovered_objects tuple[str, ...]

Normalized object identifiers, counted by unique identity.

evidence tuple[RawEvidence, ...]

Exact textual assessment outputs and invocation metadata.

Source code in fuzzy1337/functional_metrics.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
@dataclass(frozen=True, slots=True)
class FunctionalRun:
    """Keep scanner/release identity, normalized detections, and raw evidence distinct.

    Attributes:
        scenario_id: ScenarioOracle identifier assessed by this run.
        scanner_id: Assessment producer; independent of target oracle identity.
        release_id: Scanner/product release or explicitly identified contract-probe version.
        status: Completed, crashed, or timed-out assessment state.
        duration_seconds: Measured finite nonnegative elapsed assessment duration.
        detected_checks: Normalized check identifiers; raw duplicates remain preserved.
        discovered_objects: Normalized object identifiers, counted by unique identity.
        evidence: Exact textual assessment outputs and invocation metadata.
    """

    scenario_id: str
    scanner_id: str
    release_id: str
    status: RunStatus
    duration_seconds: float
    detected_checks: tuple[str, ...] = ()
    discovered_objects: tuple[str, ...] = ()
    evidence: tuple[RawEvidence, ...] = ()

    def __post_init__(self) -> None:
        """Reject invalid terminal state or duration and freeze supplied sequences."""

        RequireIdentifier(self.scenario_id, "scenario identifier")
        RequireIdentifier(self.scanner_id, "scanner identifier")
        RequireText(self.release_id, "release identifier")

        if not isinstance(self.status, RunStatus):
            raise ValueError("run status must be a terminal RunStatus")

        if (
            isinstance(self.duration_seconds, bool)
            or not isinstance(self.duration_seconds, (int, float))
            or not math.isfinite(self.duration_seconds)
            or self.duration_seconds < 0
        ):
            raise ValueError("duration must be finite and nonnegative")

        for field_name in ("detected_checks", "discovered_objects"):
            values = tuple(getattr(self, field_name))

            for value in values:
                RequireIdentifier(value, field_name)

            object.__setattr__(self, field_name, values)

        evidence = tuple(self.evidence)
        UniqueIdentifiers(tuple(record.role for record in evidence), "evidence roles")
        object.__setattr__(self, "evidence", evidence)

__post_init__() -> None

Reject invalid terminal state or duration and freeze supplied sequences.

Source code in fuzzy1337/functional_metrics.py
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
def __post_init__(self) -> None:
    """Reject invalid terminal state or duration and freeze supplied sequences."""

    RequireIdentifier(self.scenario_id, "scenario identifier")
    RequireIdentifier(self.scanner_id, "scanner identifier")
    RequireText(self.release_id, "release identifier")

    if not isinstance(self.status, RunStatus):
        raise ValueError("run status must be a terminal RunStatus")

    if (
        isinstance(self.duration_seconds, bool)
        or not isinstance(self.duration_seconds, (int, float))
        or not math.isfinite(self.duration_seconds)
        or self.duration_seconds < 0
    ):
        raise ValueError("duration must be finite and nonnegative")

    for field_name in ("detected_checks", "discovered_objects"):
        values = tuple(getattr(self, field_name))

        for value in values:
            RequireIdentifier(value, field_name)

        object.__setattr__(self, field_name, values)

    evidence = tuple(self.evidence)
    UniqueIdentifiers(tuple(record.role for record in evidence), "evidence roles")
    object.__setattr__(self, "evidence", evidence)

Ratio(numerator: int, denominator: int) -> float | None

Return a defined ratio or null when its finite denominator is zero.

Parameters:

Name Type Description Default
numerator int

Nonnegative count above the fraction line.

required
denominator int

Nonnegative count below the fraction line.

required

Returns:

Type Description
float | None

Floating-point ratio or None for an undefined denominator.

Raises:

Type Description
ValueError

Either count is not a nonnegative integer.

Source code in fuzzy1337/functional_metrics.py
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
def Ratio(numerator: int, denominator: int) -> float | None:
    """Return a defined ratio or null when its finite denominator is zero.

    Args:
        numerator: Nonnegative count above the fraction line.
        denominator: Nonnegative count below the fraction line.

    Returns:
        Floating-point ratio or None for an undefined denominator.

    Raises:
        ValueError: Either count is not a nonnegative integer.
    """

    if any(type(value) is not int or value < 0 for value in (numerator, denominator)):
        raise ValueError("ratio counts must be nonnegative integers")

    return numerator / denominator if denominator else None

ScoreRun(oracle: ScenarioOracle, run: FunctionalRun) -> dict[str, object]

Score exact known answers while preserving failed/qualitative run truth.

Parameters:

Name Type Description Default
oracle ScenarioOracle

Finite scenario truth and required evidence roles.

required
run FunctionalRun

Assessment observations, terminal state, and raw evidence.

required

Returns:

Type Description
dict[str, object]

Counts, nullable accuracy ratios, runtime state, and evidence completeness.

Raises:

Type Description
ValueError

The run belongs to a different scenario.

Source code in fuzzy1337/functional_metrics.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
def ScoreRun(oracle: ScenarioOracle, run: FunctionalRun) -> dict[str, object]:
    """Score exact known answers while preserving failed/qualitative run truth.

    Args:
        oracle: Finite scenario truth and required evidence roles.
        run: Assessment observations, terminal state, and raw evidence.

    Returns:
        Counts, nullable accuracy ratios, runtime state, and evidence completeness.

    Raises:
        ValueError: The run belongs to a different scenario.
    """

    if oracle.identifier != run.scenario_id:
        raise ValueError("run scenario does not match the oracle")

    detected = set(run.detected_checks)
    positives = {check.identifier for check in oracle.checks if check.applicable and check.expected}
    negatives = {
        check.identifier for check in oracle.checks if check.applicable and check.expected is False
    }
    declared = {check.identifier for check in oracle.checks if check.applicable}
    unexpected = detected - declared
    missing_evidence = sorted(set(oracle.required_evidence) - {item.role for item in run.evidence})
    eligible = oracle.complete and run.status is RunStatus.COMPLETED and bool(declared)
    tp = len(positives & detected)
    fp = len(negatives & detected)
    fn = len(positives - detected)
    tn = len(negatives - detected)

    return {
        "accuracy_available": eligible,
        "accuracy_reason": (
            "complete-oracle" if eligible
            else "incomplete-run" if run.status is not RunStatus.COMPLETED
            else "incomplete-oracle" if not oracle.complete else "empty-oracle"
        ),
        "tp": tp if eligible else None,
        "fp": fp if eligible else None,
        "fn": fn if eligible else None,
        "tn": tn if eligible else None,
        "recall_tpr": Ratio(tp, tp + fn) if eligible else None,
        "false_positive_rate": Ratio(fp, fp + tn) if eligible else None,
        "precision": Ratio(tp, tp + fp) if eligible else None,
        "accuracy": Ratio(tp + tn, tp + fp + fn + tn) if eligible else None,
        "unexpected_detections": sorted(unexpected),
        "unexpected_detection_count": len(unexpected),
        "detected_check_count": len(detected),
        "discovered_object_count": len(set(run.discovered_objects)),
        "duration_seconds": run.duration_seconds,
        "crashes": int(run.status is RunStatus.CRASHED),
        "timeouts": int(run.status is RunStatus.TIMED_OUT),
        "evidence_expected": len(oracle.required_evidence),
        "evidence_present": len(oracle.required_evidence) - len(missing_evidence),
        "evidence_completeness": Ratio(
            len(oracle.required_evidence) - len(missing_evidence), len(oracle.required_evidence)
        ),
        "missing_evidence": missing_evidence,
    }

BuildReport(scenarios: Sequence[ScenarioOracle], runs: Sequence[FunctionalRun]) -> dict[str, object]

Build versioned run evidence and capability matrix from one oracle source.

Parameters:

Name Type Description Default
scenarios Sequence[ScenarioOracle]

Unique scenario metadata, including target pack/version.

required
runs Sequence[FunctionalRun]

At most one run per scenario, scanner, and release.

required

Returns:

Type Description
dict[str, object]

Deterministic JSON-compatible report with raw runs and matrix projections.

Raises:

Type Description
ValueError

A scenario is duplicated, a run is duplicated, or a run is undeclared.

Source code in fuzzy1337/functional_metrics.py
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
def BuildReport(
    scenarios: Sequence[ScenarioOracle], runs: Sequence[FunctionalRun]
) -> dict[str, object]:
    """Build versioned run evidence and capability matrix from one oracle source.

    Args:
        scenarios: Unique scenario metadata, including target pack/version.
        runs: At most one run per scenario, scanner, and release.

    Returns:
        Deterministic JSON-compatible report with raw runs and matrix projections.

    Raises:
        ValueError: A scenario is duplicated, a run is duplicated, or a run is undeclared.
    """

    UniqueIdentifiers(tuple(item.identifier for item in scenarios), "scenario identifiers")
    oracles = {item.identifier: item for item in scenarios}
    grouped: dict[str, list[FunctionalRun]] = {key: [] for key in oracles}
    seen: set[tuple[str, str, str]] = set()

    for assessment in runs:
        identity = (assessment.scenario_id, assessment.scanner_id, assessment.release_id)

        if identity in seen:
            raise ValueError("scenario/scanner/release runs must be unique")

        if assessment.scenario_id not in oracles:
            raise ValueError("run scenario must be declared")

        seen.add(identity)
        grouped[assessment.scenario_id].append(assessment)

    capabilities = sorted({check.capability for item in scenarios for check in item.checks})
    columns: list[dict[str, object]] = []
    cells_by_capability: dict[str, list[dict[str, object]]] = {key: [] for key in capabilities}
    scored_runs: list[dict[str, object]] = []

    for scenario_id, oracle in sorted(oracles.items()):
        scenario_runs = sorted(
            grouped[scenario_id], key=lambda item: (item.scanner_id, item.release_id)
        )
        column_runs: Sequence[FunctionalRun | None] = scenario_runs or (None,)

        for run in column_runs:
            columns.append({
                "scenario_id": scenario_id,
                "target_pack": oracle.target_pack,
                "target_version": oracle.target_version,
                "scanner_id": run.scanner_id if run else None,
                "release_id": run.release_id if run else None,
            })

            if run is not None:
                scored_runs.append({"run": asdict(run), "metrics": ScoreRun(oracle, run)})

            for capability in capabilities:
                checks = [item for item in oracle.checks if item.capability == capability]
                detected = set(run.detected_checks) if run else set()
                applicable = any(item.applicable for item in checks)
                state = "not-run" if applicable else "not-applicable"

                if run is not None and applicable:
                    state = run.status.value if run.status is not RunStatus.COMPLETED else (
                        "detected" if any(item.identifier in detected for item in checks)
                        else "not-detected"
                    )

                if run is not None and not applicable and any(
                    item.identifier in detected for item in checks
                ):
                    state = "unexpected-detection"

                cells_by_capability[capability].append({
                    "applicable": applicable,
                    "state": state,
                    "checks": [
                        {
                            "identifier": item.identifier,
                            "expected": item.expected,
                            "detected": item.identifier in detected if run else None,
                            "applicable": item.applicable,
                        }
                        for item in sorted(checks, key=lambda item: item.identifier)
                    ],
                })

    return {
        "schema_version": FUNCTIONAL_REPORT_VERSION,
        "scenarios": [asdict(item) for _, item in sorted(oracles.items())],
        "runs": scored_runs,
        "matrix": {
            "columns": columns,
            "rows": [
                {"capability": key, "cells": cells_by_capability[key]} for key in capabilities
            ],
        },
    }

SerializeReport(report: dict[str, object]) -> str

Serialize report data with stable keys and standards-compliant numbers.

Parameters:

Name Type Description Default
report dict[str, object]

Data produced by BuildReport.

required

Returns:

Type Description
str

Indented JSON with a trailing newline.

Raises:

Type Description
ValueError

Report data contains non-finite numbers.

Source code in fuzzy1337/functional_metrics.py
363
364
365
366
367
368
369
370
371
372
373
374
375
376
def SerializeReport(report: dict[str, object]) -> str:
    """Serialize report data with stable keys and standards-compliant numbers.

    Args:
        report: Data produced by BuildReport.

    Returns:
        Indented JSON with a trailing newline.

    Raises:
        ValueError: Report data contains non-finite numbers.
    """

    return json.dumps(report, indent=2, sort_keys=True, allow_nan=False) + "\n"

MatrixRows(report: dict[str, object]) -> list[list[str]]

Project generated report cells into a shared human-readable table.

Parameters:

Name Type Description Default
report dict[str, object]

Data produced by BuildReport.

required

Returns:

Type Description
list[list[str]]

Table header and rows preserving individual expected/detected check states.

Source code in fuzzy1337/functional_metrics.py
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
def MatrixRows(report: dict[str, object]) -> list[list[str]]:
    """Project generated report cells into a shared human-readable table.

    Args:
        report: Data produced by BuildReport.

    Returns:
        Table header and rows preserving individual expected/detected check states.
    """

    matrix = report["matrix"]
    assert isinstance(matrix, dict), "matrix must be produced by BuildReport"
    headers = ["Capability"]

    for column in matrix["columns"]:
        scanner = column["scanner_id"] or "not-run"
        release = column["release_id"] or "none"
        headers.append(
            f"{column['target_pack']}@{column['target_version']} / "
            f"{column['scenario_id']} / {scanner}@{release}"
        )

    rows = [headers]

    for row in matrix["rows"]:
        values = [row["capability"]]

        for cell in row["cells"]:
            checks = [item for item in cell["checks"] if item["applicable"]]
            expected = ", ".join(
                f"{item['identifier']}: expected="
                f"{'unknown' if item['expected'] is None else item['expected']}, "
                f"detected={'not-run' if item['detected'] is None else item['detected']}"
                for item in checks
            ) or "none"
            values.append(f"{cell['state']}; {expected}")

        rows.append(values)

    return rows

RenderMarkdown(report: dict[str, object]) -> str

Render a source-aligned Markdown matrix without interpreting supplied HTML.

Parameters:

Name Type Description Default
report dict[str, object]

Data produced by BuildReport.

required

Returns:

Type Description
str

Capability table with escaped text and aligned source columns.

Source code in fuzzy1337/functional_metrics.py
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
def RenderMarkdown(report: dict[str, object]) -> str:
    """Render a source-aligned Markdown matrix without interpreting supplied HTML.

    Args:
        report: Data produced by BuildReport.

    Returns:
        Capability table with escaped text and aligned source columns.
    """

    rows = []

    for row in MatrixRows(report):
        escaped = []

        for value in row:
            value = html.escape(value).replace("|", "&#124;").replace("\\", "\\\\")

            for character in "`*_[]()!~":
                value = value.replace(character, "\\" + character)

            escaped.append(value)

        rows.append(escaped)

    widths = [max(3, *(len(row[index]) for row in rows)) for index in range(len(rows[0]))]
    rows.insert(1, ["-" * width for width in widths])

    return "\n".join(
        "| " + " | ".join(
            value.ljust(width) for value, width in zip(row, widths, strict=True)
        ) + " |"
        for row in rows
    ) + "\n"

RenderHtml(report: dict[str, object]) -> str

Render an escaped HTML matrix that never embeds executable raw evidence.

Parameters:

Name Type Description Default
report dict[str, object]

Data produced by BuildReport.

required

Returns:

Type Description
str

Standalone UTF-8 HTML document containing the capability table.

Source code in fuzzy1337/functional_metrics.py
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
def RenderHtml(report: dict[str, object]) -> str:
    """Render an escaped HTML matrix that never embeds executable raw evidence.

    Args:
        report: Data produced by BuildReport.

    Returns:
        Standalone UTF-8 HTML document containing the capability table.
    """

    rows = MatrixRows(report)
    header = "".join(f"<th scope=\"col\">{html.escape(value)}</th>" for value in rows[0])
    body = "".join(
        "<tr>" + "".join(f"<td>{html.escape(value)}</td>" for value in row) + "</tr>"
        for row in rows[1:]
    )

    return (
        "<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\">"
        "<title>Functional capability matrix</title></head><body>"
        f"<table><caption>Functional capability matrix</caption><thead><tr>{header}</tr>"
        f"</thead><tbody>{body}</tbody></table></body></html>\n"
    )