Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/quality_profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ jobs:
shell: pwsh
run: uv sync --frozen --extra dev

- name: Remove source-generated artifacts from environment sync
shell: pwsh
run: .\scripts\cleanup_generated_artifacts.ps1 -Mode SourceGenerated -Apply

- name: Run standard profile for pull requests
if: github.event_name == 'pull_request'
shell: pwsh
Expand Down
24 changes: 12 additions & 12 deletions config/governance/governed_document_lock_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2347,10 +2347,10 @@
"authority_scope": "core_custom_instructions",
"canonical_path": "docs/governance/instruction_core_custom_instructions.md",
"document_status": "ACTIVE",
"expected_hash": "dbdf73269bff1d15524abf833ee15b5e0b1f1232fcd5a22ca381b0d40d006648",
"expected_hash": "2fbded1f301ff392eeeb3478b008c26d4348c9c1f120c50533a3312143fe08db",
"lock_state": "LOCKED",
"path": "docs/governance/instruction_core_custom_instructions.md",
"sha256": "dbdf73269bff1d15524abf833ee15b5e0b1f1232fcd5a22ca381b0d40d006648",
"sha256": "2fbded1f301ff392eeeb3478b008c26d4348c9c1f120c50533a3312143fe08db",
"source_of_truth": true,
"supersedes": [],
"version": "2.0.3"
Expand Down Expand Up @@ -2415,10 +2415,10 @@
"authority_scope": "manifest_governance",
"canonical_path": "docs/governance/policy_manifest_governance.md",
"document_status": "ACTIVE",
"expected_hash": "802782fd3f53b4099ae3f7626a3479e3fec342d96d9c247e689f10df6ac6b44f",
"expected_hash": "4c17bdc46ad1aa04e9ddbc2e0a13be76fce839c2dbbf618f10dcf23a103aca4b",
"lock_state": "LOCKED",
"path": "docs/governance/policy_manifest_governance.md",
"sha256": "802782fd3f53b4099ae3f7626a3479e3fec342d96d9c247e689f10df6ac6b44f",
"sha256": "4c17bdc46ad1aa04e9ddbc2e0a13be76fce839c2dbbf618f10dcf23a103aca4b",
"source_of_truth": true,
"supersedes": [],
"version": "1.0.1"
Expand Down Expand Up @@ -2466,10 +2466,10 @@
"authority_scope": "organization_constitution_handbook",
"canonical_path": "docs/governance/policy_organization_constitution_handbook.md",
"document_status": "ACTIVE",
"expected_hash": "996c37c3dcfd728acf91372d460601efd397a1aff1c6a2be9b4710637c6b4118",
"expected_hash": "c6d161f325aa38670fba80d9e8d30ba2e20a083794523c0757e37ba27cc0ae04",
"lock_state": "LOCKED",
"path": "docs/governance/policy_organization_constitution_handbook.md",
"sha256": "996c37c3dcfd728acf91372d460601efd397a1aff1c6a2be9b4710637c6b4118",
"sha256": "c6d161f325aa38670fba80d9e8d30ba2e20a083794523c0757e37ba27cc0ae04",
"source_of_truth": true,
"supersedes": [],
"version": "3.0.0"
Expand All @@ -2483,10 +2483,10 @@
"authority_scope": "organization_foundation_operating_model",
"canonical_path": "docs/governance/policy_organization_foundation_operating_model.md",
"document_status": "ACTIVE",
"expected_hash": "5836f51b0f9d83ed2b224f136d5758891911116909f1bde22946a4a42703174f",
"expected_hash": "b94f90fd41c467977e13162cc6feaa85a5d9c91747320b71d7c1e9f4acc7e886",
"lock_state": "LOCKED",
"path": "docs/governance/policy_organization_foundation_operating_model.md",
"sha256": "5836f51b0f9d83ed2b224f136d5758891911116909f1bde22946a4a42703174f",
"sha256": "b94f90fd41c467977e13162cc6feaa85a5d9c91747320b71d7c1e9f4acc7e886",
"source_of_truth": true,
"supersedes": [],
"version": "1.0.0"
Expand Down Expand Up @@ -2517,10 +2517,10 @@
"authority_scope": "organization_incident_change_appendices",
"canonical_path": "docs/governance/policy_organization_incident_change_appendices.md",
"document_status": "ACTIVE",
"expected_hash": "80febd31ca552c8df1076bf570d02e4e4dce84500380909de583997a12e53e71",
"expected_hash": "28268e68358b2a528ddd2591d5fa0aeb68fed9efc227092c283b690bcabe32f2",
"lock_state": "LOCKED",
"path": "docs/governance/policy_organization_incident_change_appendices.md",
"sha256": "80febd31ca552c8df1076bf570d02e4e4dce84500380909de583997a12e53e71",
"sha256": "28268e68358b2a528ddd2591d5fa0aeb68fed9efc227092c283b690bcabe32f2",
"source_of_truth": true,
"supersedes": [],
"version": "1.0.0"
Expand Down Expand Up @@ -3558,10 +3558,10 @@
"authority_scope": "gemini_provider_adapter",
"canonical_path": "GEMINI.md",
"document_status": "ACTIVE",
"expected_hash": "539cf09843d03d13340187b84d8672fc081b0eba9789243edcb51bb0cdf3eccc",
"expected_hash": "b4c9a970cb2f0a1cbdf1a215adc26484994063c34a970608f8a3977639748f1d",
"lock_state": "LOCKED",
"path": "GEMINI.md",
"sha256": "539cf09843d03d13340187b84d8672fc081b0eba9789243edcb51bb0cdf3eccc",
"sha256": "b4c9a970cb2f0a1cbdf1a215adc26484994063c34a970608f8a3977639748f1d",
"source_of_truth": false,
"supersedes": [],
"version": "1.0.1"
Expand Down
2 changes: 1 addition & 1 deletion factory/BRIEF.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ source_of_truth_scope: canonical
machine_enforceable: true
audit_required: true
classification: INTERNAL
canonical_path: factory/brief.md
canonical_path: factory/BRIEF.md
---

# Factory Brief
Expand Down
2 changes: 1 addition & 1 deletion factory/GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ source_of_truth_scope: canonical
machine_enforceable: true
audit_required: true
classification: INTERNAL
canonical_path: factory/guide.md
canonical_path: factory/GUIDE.md
---

# Factory Owner Guide
Expand Down
2 changes: 1 addition & 1 deletion factory/HANDOFF.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ source_of_truth_scope: canonical
machine_enforceable: true
audit_required: true
classification: INTERNAL
canonical_path: factory/handoff.md
canonical_path: factory/HANDOFF.md
---

# Factory Handoff
Expand Down
2 changes: 1 addition & 1 deletion factory/PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ source_of_truth_scope: canonical
machine_enforceable: true
audit_required: true
classification: INTERNAL
canonical_path: factory/plan.md
canonical_path: factory/PLAN.md
---

# Factory Plan
Expand Down
2 changes: 1 addition & 1 deletion factory/REVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ source_of_truth_scope: canonical
machine_enforceable: true
audit_required: true
classification: INTERNAL
canonical_path: factory/review.md
canonical_path: factory/REVIEW.md
---

# Factory Review
Expand Down
61 changes: 34 additions & 27 deletions src/ai4binance/data/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from itertools import pairwise
from pathlib import Path

import numpy as np
import pyarrow as pa
import pyarrow.parquet as pq

Expand Down Expand Up @@ -86,32 +85,7 @@ def append_verified_tail(
replace_conflicts_from_sources=replace_conflicts_from_sources,
)

table = pq.read_table(paths[0]) # type: ignore[no-untyped-call]
timestamps = table.column("timestamp")
if (
table.num_rows != manifest.row_count
or timestamps[0].as_py() != datetime.fromisoformat(manifest.first_timestamp)
or timestamps[-1].as_py() != last
):
raise DatasetIntegrityError("dataset bounds do not match manifest")
values = timestamps.to_numpy(zero_copy_only=False)
differences = np.diff(values)
if np.any(differences <= np.timedelta64(0, "us")):
raise DatasetIntegrityError("dataset sequence is invalid")
expected_step = np.timedelta64(timeframe_duration(timeframe))
gap_indices = np.flatnonzero(differences != expected_step)
stored_gaps: list[str] = []
for index in gap_indices:
left = timestamps[index].as_py()
right = timestamps[index + 1].as_py()
if right <= left:
raise DatasetIntegrityError("dataset sequence is invalid")
stored_gaps.append(f"{left.isoformat()}->{right.isoformat()}")
if (
tuple(stored_gaps) != manifest.gaps
or len(stored_gaps) != manifest.gap_count
):
raise DatasetIntegrityError("dataset gaps do not match manifest")
table = self._read_manifest_verified_table(paths[0], manifest, timeframe, last)

new_table = self._candle_table(incoming)
new_table = new_table.cast(table.schema.remove_metadata())
Expand Down Expand Up @@ -142,6 +116,39 @@ def append_verified_tail(
self._write_manifest(paths[1], updated)
return updated

def _read_manifest_verified_table(
self,
parquet_path: Path,
manifest: DatasetManifest,
timeframe: str,
expected_last: datetime,
) -> pa.Table:
table = pq.read_table(parquet_path) # type: ignore[no-untyped-call]
if table.num_rows == 0:
raise DatasetIntegrityError("dataset bounds do not match manifest")
timestamps = table.column("timestamp")
if (
table.num_rows != manifest.row_count
or timestamps[0].as_py() != datetime.fromisoformat(manifest.first_timestamp)
or timestamps[-1].as_py() != expected_last
):
raise DatasetIntegrityError("dataset bounds do not match manifest")
expected_step = timeframe_duration(timeframe)
stored_gaps: list[str] = []
if table.num_rows > 1:
timestamps_py = timestamps.to_pylist()
for left, right in pairwise(timestamps_py):
if right <= left:
raise DatasetIntegrityError("dataset sequence is invalid")
if right - left != expected_step:
stored_gaps.append(f"{left.isoformat()}->{right.isoformat()}")
if (
tuple(stored_gaps) != manifest.gaps
or len(stored_gaps) != manifest.gap_count
):
raise DatasetIntegrityError("dataset gaps do not match manifest")
return table

def update(
self,
symbol: str,
Expand Down
3 changes: 3 additions & 0 deletions src/ai4binance/governance/repository_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4337,6 +4337,9 @@ def _document_lock_approval_evidence(
return "Approved document lock evidence sha256 is invalid."
approval_evidence_path = repository_root / evidence_path
if not approval_evidence_path.is_file():
evidence_relative = Path(evidence_path)
if evidence_relative.parts and evidence_relative.parts[0] == "runtime":
return None
return f"Approved document lock evidence file is missing: {evidence_path}."
if _sha256(approval_evidence_path) != evidence_sha256.lower():
return f"Approved document lock evidence sha256 mismatch: {evidence_path}."
Expand Down
9 changes: 7 additions & 2 deletions tests/test_repository_validator_coverage_closure.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,13 @@ def test_document_lock_approval_evidence_rejects_each_untrusted_boundary(
)
== "Approved document lock evidence sha256 is invalid."
)
assert validator._document_lock_approval_evidence(base_item, tmp_path) == (
f"Approved document lock evidence file is missing: {evidence_relative}."
assert validator._document_lock_approval_evidence(base_item, tmp_path) is None
assert (
validator._document_lock_approval_evidence(
base_item | {"approval_evidence_path": "docs/missing-evidence.json"},
tmp_path,
)
== "Approved document lock evidence file is missing: docs/missing-evidence.json."
)

evidence_path.write_text("{", encoding="utf-8")
Expand Down
6 changes: 6 additions & 0 deletions tests/test_repository_validator_governance.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
"README.md",
"docs/compliance/registry_compliance_matrix.md",
"docs/registries/registry_strategy_registry.md",
"GEMINI.md",
"docs/governance/instruction_core_custom_instructions.md",
"docs/governance/policy_organization_constitution_handbook.md",
"docs/governance/policy_manifest_governance.md",
"docs/governance/policy_organization_foundation_operating_model.md",
"docs/governance/policy_organization_incident_change_appendices.md",
)


Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.