Implement TREV-WP-0002 Stage 0 foundation: schemas, pure fold, golden Phase
Delivers the offline runnable specification foundation for the Trust Layer
(TSD §3-§6), not a hosted Trust Service:
- JSON Schemas for Phase Manifest, Ledger Entry, Extension Contract, and
Conversion Attestation, encoding the Stage 0 working defaults (Q3 future
license enum, Q6 single-currency Phases, Q8 required longstop_at).
- src/target_revenue: pure Outstanding Target fold, SHA-256 hash-chain
verification, Ed25519 signing helpers, extension conformance checks
(including a core-term-redefinition heuristic), and conversion detection
that never requires an attestation document to determine conversion status.
- examples/phase-001: golden Phase package matching the concept doc's
worked example, generated via scripts/generate_golden_phase.py so the
hash chain is computed by the library itself, not hand-typed.
- 32 passing pytest tests covering manifest/ledger/extension conformance,
tamper/reorder detection, and the full lifecycle fold to conversion.
- docs/adr/ADR-0001: proposed (not accepted) Stage 0 stack choice, per the
WP-0002-T01 human-accept gate — implementation proceeded against the
proposal as the workplan note permits, but the task stays open.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-28 18:47:29 +02:00
|
|
|
import copy
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
from conftest import golden_extension, load_json, FIXTURES_DIR
|
|
|
|
|
|
|
|
|
|
from target_revenue import validation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"name",
|
|
|
|
|
[
|
|
|
|
|
"development-license",
|
|
|
|
|
"cost-plus-operations",
|
|
|
|
|
"phase-sponsorship",
|
|
|
|
|
"service-with-development-allocation",
|
Advance WP-0007: degeneration research, profile catalog, canonicalization checklist
T01: specs/TargetDegenerationPolicyResearch.md. Survey finds no
precedent (BSL/FSL/Elastic) implements progress-sensitive degeneration
- TRSL's model is original design. Proposes a candidate v1 formula
(90-day rolling "quiet period" pause on Remission Credit accrual
during active Development Credit periods), resolves the
contributor-diversity input as explicitly not-adopted (no
gaming-resistant signal exists yet), and resolves the
longstop/progress-sensitivity relationship as a hard, unconditional
backstop. Does not recommend v0 vs v1 for T02 - that's the human gate.
T02: recommendation added (confirm v0 for the first pilot cohort, name
v1 as the next iteration) - left todo per the human-accept policy.
T03: specs/CanonicalMonetizationProfiles.md with worked narratives for
all six catalog profiles, plus two new fixtures (product-ideation,
general-consulting), both schema-validated and added to the
parametrized conformance test.
T04: specs/CanonicalizationReviewChecklist.md, an 8-item checklist
layered on the already-implemented promote_extension_canonical()
mechanism (WP-0006-T03) - defines what a reviewer must verify, not a
new promotion mechanism.
2026-07-29 22:31:19 +02:00
|
|
|
"product-ideation",
|
|
|
|
|
"general-consulting",
|
Implement TREV-WP-0002 Stage 0 foundation: schemas, pure fold, golden Phase
Delivers the offline runnable specification foundation for the Trust Layer
(TSD §3-§6), not a hosted Trust Service:
- JSON Schemas for Phase Manifest, Ledger Entry, Extension Contract, and
Conversion Attestation, encoding the Stage 0 working defaults (Q3 future
license enum, Q6 single-currency Phases, Q8 required longstop_at).
- src/target_revenue: pure Outstanding Target fold, SHA-256 hash-chain
verification, Ed25519 signing helpers, extension conformance checks
(including a core-term-redefinition heuristic), and conversion detection
that never requires an attestation document to determine conversion status.
- examples/phase-001: golden Phase package matching the concept doc's
worked example, generated via scripts/generate_golden_phase.py so the
hash chain is computed by the library itself, not hand-typed.
- 32 passing pytest tests covering manifest/ledger/extension conformance,
tamper/reorder detection, and the full lifecycle fold to conversion.
- docs/adr/ADR-0001: proposed (not accepted) Stage 0 stack choice, per the
WP-0002-T01 human-accept gate — implementation proceeded against the
proposal as the workplan note permits, but the task stays open.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-28 18:47:29 +02:00
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
def test_canonical_stage0_extensions_are_conformant(name):
|
|
|
|
|
validation.validate_extension_contract(golden_extension(name))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_non_conforming_extension_is_rejected():
|
|
|
|
|
extension = load_json(FIXTURES_DIR / "non_conforming_extension.json")
|
|
|
|
|
with pytest.raises(validation.ConformanceError) as excinfo:
|
|
|
|
|
validation.validate_extension_contract(extension)
|
|
|
|
|
assert "Outstanding Target" in str(excinfo.value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_extension_missing_required_field_is_rejected():
|
|
|
|
|
extension = copy.deepcopy(golden_extension("development-license"))
|
|
|
|
|
del extension["evidence"]
|
|
|
|
|
with pytest.raises(validation.ConformanceError):
|
|
|
|
|
validation.validate_extension_contract(extension)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_extension_bad_status_is_rejected():
|
|
|
|
|
extension = copy.deepcopy(golden_extension("development-license"))
|
|
|
|
|
extension["status"] = "endorsed" # not in {registered, canonical, deprecated}
|
|
|
|
|
with pytest.raises(validation.ConformanceError):
|
|
|
|
|
validation.validate_extension_contract(extension)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_core_term_redefinition_heuristic_is_case_insensitive():
|
|
|
|
|
extension = copy.deepcopy(golden_extension("development-license"))
|
|
|
|
|
extension["allocation"]["rule"] = "Development Credit means whatever the licensor prefers."
|
|
|
|
|
errors = validation.check_extension_core_term_redefinition(extension)
|
|
|
|
|
assert errors
|
|
|
|
|
assert "Development Credit" in errors[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_legitimate_rule_referencing_core_term_without_redefining_is_allowed():
|
|
|
|
|
extension = golden_extension("development-license")
|
|
|
|
|
# References "Development Credit" as a target, not a redefinition.
|
|
|
|
|
errors = validation.check_extension_core_term_redefinition(extension)
|
|
|
|
|
assert errors == []
|