Add trusted TQQQ snapshot package boundary - #216
Conversation
Co-Authored-By: Codex <noreply@openai.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2457f9f2e1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| payload = _parse_canonical_json(package.canonical_bytes) | ||
| _validate_payload(payload, package.external_bindings) | ||
| return package |
There was a problem hiding this comment.
Recheck the content digest at the consumer boundary
When a factory-created instance's slots are changed through object.__setattr__ (which bypasses frozen=True), this path validates the replacement JSON but never compares sha256(canonical_bytes) with external_bindings.content_sha256. A different, structurally valid fixture therefore retains a stale external digest and is returned as trusted; recompute and verify the content digest before returning the package.
Useful? React with 👍 / 👎.
| try: | ||
| return json.dumps(value, ensure_ascii=False, separators=(",", ":"), sort_keys=True).encode("utf-8") | ||
| except (TypeError, ValueError) as exc: |
There was a problem hiding this comment.
Reject non-finite values during canonical serialization
When a caller passes a non-finite float such as NaN or Infinity, json.dumps defaults to allow_nan=True, so this function returns non-JSON tokens instead of raising SnapshotValidationError; _parse_canonical_json then explicitly rejects those same bytes. Set allow_nan=False so the public canonicalizer cannot generate artifacts that the package reader considers invalid.
Useful? React with 👍 / 👎.
| CANONICAL_DECIMAL_PATTERN = r"(?:[1-9][0-9]*|[1-9][0-9]*\.[0-9]*[1-9])" | ||
| _DECIMAL_RE = re.compile(rf"^{CANONICAL_DECIMAL_PATTERN}$") |
There was a problem hiding this comment.
Allow canonical fractional adjusted closes below one
For any clean-cutover fixture containing a positive split-adjusted price below 1, such as "0.5", this pattern rejects the row even though it is a canonical positive decimal. This conflicts with the existing TQQQ snapshot contract, which accepts every positive finite adjusted close and covers leveraged-ETF history from 2010; add a 0.<nonzero fraction> alternative while continuing to reject zero and the noncanonical .5 form.
Useful? React with 👍 / 👎.
| if any(not _is_canonical_session(session) for session in value): | ||
| _invalid("expected_sessions contains an invalid session") | ||
| if tuple(sorted(value)) != value or len(set(value)) != len(value): | ||
| _invalid("expected_sessions must be sorted and unique") |
There was a problem hiding this comment.
Reject weekend dates from the session binding
When both expected_sessions and the payload contain a canonical weekend date such as 2024-01-06, these checks accept it and the factory returns a trusted QQQ/TQQQ package. The existing TQQQ snapshot validator rejects dayofweek >= 5, and a U.S. equity calendar cannot contain Saturday or Sunday sessions, so validate the weekday here before treating the external coverage as trustworthy.
Useful? React with 👍 / 👎.
Co-Authored-By: Codex <noreply@openai.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f6e8e91d1f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if type(bindings) is not ExternalBindings: | ||
| _invalid("bindings must be an ExternalBindings value") | ||
| raw = _read_trusted_file(trusted_root=trusted_root, relative_path=relative_path) |
There was a problem hiding this comment.
Revalidate bindings before creating the trusted package
When a valid ExternalBindings instance is altered through object.__setattr__ before being passed here, this type check does not rerun its field validation. For example, changing source_sha256 to "invalid" still lets the factory return a TrustedSnapshotPackage, even though the consumer validator subsequently rejects that same package; code relying on the documented guarantee that factory output is already trusted can therefore receive malformed external bindings. Call _validate_external_bindings(bindings) at the factory boundary before reading or constructing the package.
Useful? React with 👍 / 👎.
Co-Authored-By: Codex <noreply@openai.com>
Bounded P2 TQQQ trusted snapshot package
6def35cef7433af57371f668afb75e6123e225c2(tree1dd563d90b497ed185db97954ad623a4263cfe03).PYTHONPATH=src python3 -m pytest -q tests/test_soxl_tqqq_clean_cutover_snapshot.pyfailed during collection becausesoxl_tqqq_clean_cutover_snapshotdid not exist.TrustedSnapshotPackage, typed external digest/session bindings, descriptor-safe strict readback, canonical JSON validation, and runtime-generated checked-in schema parity.29 passed; fullPYTHONPATH=src python3 -m pytest -q598 passed, 3 skipped; focused and full Ruff passed;git diff --checkandcompileallpassed.offline_fixture=true), no provider/data/plugin/replay/broker/cloud/live behavior, andsize=0.