Repository navigation
chore(tests): store captured JSON one record per line - #892
chrisknvidia wants to merge 4 commits into
Conversation
The captured JSON under tests/ was written one scalar per line. It is
now laid out by scripts/layout_json.py: a list or dict that nests at
most two levels and fits in 200 columns, indentation and trailing comma
included, goes on one line. Everything else stays as
json.dumps(indent=2) writes it.
Five glob rules in the script pick the 52 managed files: the 48
tests/fixtures/skillspector-* reports, tests/golden/cli_surface.json,
and the three captures in tests/tier3/fixtures and
tests/reporting/fixtures. Together they go from 32,326 lines to 13,186.
The whole change is 57 files, 3,091 insertions and 22,124 deletions:
19,033 lines fewer.
Not managed: fixtures the product reads as files, and the packaged
src/skillevaluator/tier3/grader_reference suite. Grader validation
hashes that suite's bytes into provenance.suite_sha256, and the current
hash is recorded in examples/grader-qualification-pilot/manifest.json
and in docs/grader-validation.mdx, so a new layout would change a
reported value.
Only whitespace changed. For each of the 52 files the parsed value is
equal, key order included, no object has a duplicate key, and the text
with the whitespace outside strings removed is identical before and
after, so every string and number is spelled as before. Two reports had
no final newline and now have one. 26 lines were longer than 200
columns before and 26 are now; each is a single long string. Running
the writer again changes nothing.
tests/golden/generate_cli_surface.py now writes through the writer and
reproduces the committed snapshot byte for byte.
tests/test_layout_json.py fails when a managed file is not in the
layout and names the command. The two fixture READMEs name the script
and say that only the layout changed.
To re-lay the files after adding or regenerating a capture:
python scripts/layout_json.py
With --check it writes nothing, lists the files that are not in the
layout and exits 1.
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
rng1995
left a comment
There was a problem hiding this comment.
[SkillEvaluator Review]
Thanks @chrisknvidia for this contribution.
Value and readiness: The 52 updated captures preserve their exact token bytes and JSON value order while shrinking from 32,326 to 13,186 lines. The CRLF concern is fixed and head CI exercised tests and packaging. The maintenance command can still follow symlinks out of the checkout. Please address the finding below before final review.
Material findings: 1 P2
- P2 Keep formatter writes inside the checkout (scripts/layout_json.py:87)
PIC tradeoffs: None raised in this draft.
Verification and gaps: Inspected the current diff and related code, tests, and GitHub checks. CI: Green. No local contributor execution.
Reviewed head: 23d00f461f59e9c4e57a0bb5e392d26d94d0356a
| stale += 1 | ||
| print(("not in layout: " if check else "rewrote: ") + path.relative_to(ROOT).as_posix()) | ||
| if not check: | ||
| path.write_text(laid_out, encoding="utf-8", newline="\n") |
There was a problem hiding this comment.
[P2] Keep formatter writes inside the checkout
The managed globs can return a linked JSON file or a JSON file under a linked skillspector-* directory. read_bytes and write_text then follow the link, so the documented local formatter can rewrite a JSON file outside the checkout. Reject these paths before reading or writing and cover both a linked leaf and a linked parent.
rng1995
left a comment
There was a problem hiding this comment.
[SkillEvaluator Review]
Thanks @chrisknvidia for this contribution.
Value and readiness: Delivers what it claims: the 52 reformatted JSON fixtures are lossless. Each equals its merge-base version (same key order and number/string spelling, LF-only, UTF-8, no BOM); the only side effect is a final newline in two passwd-mount reports, and the golden generator reproduces tests/golden/cli_surface.json byte for byte. Not ready yet: one earlier P2 is unfixed.
Prior findings: 2 of 3 earlier threads are fixed or accepted (CRLF handling is fixed; the Devin note about make test and make build is accepted because the PR body is explicit about what was run and CI ran the full suite and the package build). Still open: scripts/layout_json.py:87 (rng1995, P2): a symlinked parent directory still makes the script rewrite files outside the checkout; I reproduced it again on this head.
Material findings: 1 inline: P3 scripts/layout_json.py:82 Name the file when a managed JSON file cannot be parsed.
PIC tradeoffs: Open PRs #897, #792 and #394 also edit tests/golden/cli_surface.json; each will conflict across the whole file once this lands and must regenerate it (the PR body already warns about this). Nothing tests that a new MANAGED glob also gets an eol=lf line in .gitattributes.
Verification and gaps: Compared all 52 files against the merge-base with a script; ran 2,444 tests (the PR's own files, every test file that reads these fixtures, and neighbours) in a scrubbed environment, all passing, ruff clean; the key tests on a tree merging current main pass (236, conflict-free); CI is green, including Gitleaks over full history. Not verified locally: Windows and Python 3.13/3.14 (CI covers them).
Reviewed head: 23d00f461f59e9c4e57a0bb5e392d26d94d0356a
| check = parser.parse_args(argv).check | ||
| stale = 0 | ||
| for path in sorted(path for pattern in MANAGED for path in ROOT.glob(pattern)): | ||
| text = path.read_bytes().decode("utf-8") |
There was a problem hiding this comment.
[P3] Name the file when a managed JSON file cannot be parsed
layout() calls json.loads and main() decodes UTF-8 without saying which file failed. A truncated or mis-encoded managed file (for example a half-written scanner capture) surfaces as a bare json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 10) or UnicodeDecodeError from both python scripts/layout_json.py and tests/test_layout_json.py::test_managed_json_is_in_the_layout. With 52 managed files the reader then has to bisect. Repro: write {"a": [1, to tests/golden/cli_surface.json and run python scripts/layout_json.py --check; the traceback never mentions the path.
Catch ValueError (both JSONDecodeError and UnicodeDecodeError derive from it) around the read and layout, and re-raise with the relative path, for example raise SystemExit(f"{path.relative_to(ROOT).as_posix()}: {error}") from error. This is the same block the open symlink P2 needs to touch, so it can ride along.
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
Summary
The captured JSON under
tests/was stored one scalar per line, so 52 files took 32,326 lines. They are now stored one record per line: a list or dict that nests at most two levels and fits in 200 columns goes on one line, and everything else stays asjson.dumps(indent=2)writes it. Same data in 13,186 lines. The whole change is 19,033 lines smaller.There is no behaviour change. Only whitespace moved: for each of the 52 files the parsed value is equal (key order included), and every string and number is spelled exactly as before. Nothing under
src/changes and no file is removed.What is added:
scripts/layout_json.pywrites the layout. With--checkit writes nothing, lists the files that are not in the layout and exits 1.tests/test_layout_json.pyfails when a managed file drifts, and names the command to run.tests/golden/generate_cli_surface.pynow writes through the same writer, so regenerating reproduces the committed snapshot byte for byte.Left alone on purpose: the packaged grader reference suite under
src/skillevaluator/tier3/grader_reference/. Grader validation hashes those bytes intoprovenance.suite_sha256, so a new layout there would change a reported value.Heads-up for open pull requests: if your branch adds or regenerates a scanner report under
tests/fixtures/skillspector-*, or changestests/golden/cli_surface.json, mergemainand runpython scripts/layout_json.pyonce this is in.Verification
make lintmake testmake buildNothing here is user-visible, so there is no documentation change beyond a line in the two fixture READMEs. Instead of the whole suite on this exact commit, I ran the layout test, the CLI surface test and the tests that read these files (288 passed), plus
ruff checkand a gitleaks scan of the commit. The full suite was run on this change one day earlier onmainand matched unchangedmain.Release Impact
CHANGELOG.md