PY-56

Reload Artifacts and Check Their Evidence

  • Medium–Hard
  • Artifacts and Evidence
  • Python

Task

Write audit_artifacts(base_path, manifest, digest_file, count_records). manifest["artifacts"] is an ordered list of records with path, count, bytes, and digest. Paths are safe, unique, and relative to base_path.

Return a list of every disagreement. If a listed path is not a regular file, append only this record for it:

{"path": relative, "field": "file", "expected": "present", "observed": None}

For an existing file, recompute its byte size, record count, and digest. Check fields in the order bytes, count, then digest. For each unequal field, append:

{"path": relative, "field": field, "expected": expected, "observed": observed}

Use count_records(path) and digest_file(path) as supplied. Keep manifest artifact order. An exact match returns an empty list. This task audits saved evidence; it does not rerun the program that created the artifacts.

Example

If rows.tsv exists with six bytes but its manifest records five, append a bytes disagreement. If its declared count and digest also differ, append those two records after the byte disagreement rather than stopping early.

Your implementation

Edit solution.py and keep this function signature:

You may import Path from pathlib. Do not modify the manifest or files, execute a pipeline, print, or ask for input.