Avoid unnecessary reads when validating Scriptorium outputs

This commit is contained in:
2026-11-26 13:51:06 +00:00
parent 72eb597a72
commit 0a43b67847
3 changed files with 70 additions and 10 deletions

View File

@@ -11,7 +11,7 @@ are retained as scope decisions.
## Finding 1: Avoid full-file allocation for post-capture size checks
Status: Pending consideration.
Status: Complete.
Priority: P3 — bounded memory and redundant I/O optimization; no demonstrated
incorrect result or release-blocking defect.
@@ -69,6 +69,21 @@ Retain focused tests for empty, oversized, nonregular, and failed outputs, and
valid/invalid preview JSON. Review the implementation's buffering directly;
timing thresholds, allocator-count contracts, and benchmark gates are unnecessary.
### Resolution and verification
Generation validates the closed captured file with `os.Stat`, checking regular
file type, nonempty size, and the existing maximum without reading its payload.
Its post-capture validation uses O(1) extra memory. Preview performs one bounded
read and checks both nonempty content and JSON validity on that buffer.
Streaming limits, write/close error propagation, and stage-owned payload checks
and promotion remain unchanged.
Sparse-file tests cover empty, nonempty, exact-limit, and oversized outputs;
missing/nonregular output checks and an empty-preview case complement the
existing successful, invalid, and failed subprocess cases. Verification passed:
`go test ./...`, race-enabled Scriptorium/subprocess tests, Scriptorium package
vet, and `git diff --check` using Go 1.27.4.
## Stage-by-stage disposition
| Stage | Algorithmic assessment |
@@ -87,5 +102,5 @@ timing thresholds, allocator-count contracts, and benchmark gates are unnecessar
| 12 — Documentation | No algorithm implemented. Documentation introduces no additional algorithmic requirement relevant to this audit. |
No newly implemented quadratic-time algorithm or additional correctness defect
was identified within this scope. Finding 1 warrants consideration as a small,
behavior-preserving follow-up.
was identified within this scope. Finding 1 has been addressed by the
behavior-preserving follow-up described above.