diff --git a/docs/runtime-refactor.md b/docs/runtime-refactor.md new file mode 100644 index 00000000..5ee319a6 --- /dev/null +++ b/docs/runtime-refactor.md @@ -0,0 +1,113 @@ +# Runtime foundation: staged refactor + +Baseline: `09c8cbf184e37e2e934e133b74a5db9af67b4f97` (main, 2026-11-04). +The product objective remains LLM statistical-watermark processing. This work +neither adds another Unicode layer nor turns the project into a detector product. + +## Stage 1: stop implicit research imports + +Implemented in this change: + +- `fuckmark`, `fuckmark.product`, and `fuckmark.transforms` resolve public exports + on demand. Importing the package or reading version metadata no longer loads + all research adapters, detectors, corpora, and transform schedulers. +- Public names, their defining import targets, and the order of `__all__` are + preserved. The two transform rules previously accessible outside `__all__` + remain accessible. Real classes/functions are returned, not proxy objects. +- Resolved objects are cached. Import errors propagate rather than becoming + misleading AttributeErrors. Reload clears cached exports; `dir()` lists the + API without importing implementations. +- Cold-process tests check the boundary and all export targets. Full wildcard + imports and explicit research APIs still work and intentionally load the + implementations they request. + +This is runtime isolation, not full core extraction or a smaller wheel. No +algorithm, detector threshold, frozen evidence, research module, CLI behavior, +workflow, release version, or dependency declaration is changed. The existing +Python, CLI I/O, frozen-readiness, and packaging suites remain the regression +checks. No speedup is claimed without a controlled measurement. + +### Baseline compatibility evidence + +The new explicit export tables were generated from the old import declarations, +not guessed from names. The source Git blob identities were verified first: + +| Package entrypoint | Original Git blob | Exports / wildcard exports | +| --- | --- | --- | +| `fuckmark/__init__.py` | `6da7ab00a563a6cdb729aadb63bc80aef7175ece` | 239 / 239 | +| `fuckmark/product/__init__.py` | `4f17ba5f23989263a39498114c72ceb6c879d107` | 74 / 74 | +| `fuckmark/transforms/__init__.py` | `842cce605ea6f78287f30ce647c37278a4af05b9` | 156 / 154 | + +`tests/test_lazy_public_api.py` pins the original ordered wildcard lists and +name-to-module mappings by SHA-256, then separately checks object identity +against the real implementations. Adding an intentional public API requires +updating this baseline with an explicit review; the digest is not a scientific +watermark-effectiveness metric. + +Run the targeted checks with: + +```sh +python -m pytest -q tests/test_lazy_public_api.py +``` + +Then run the unchanged full suite and installed CLI checks before merging. +A namespace-only local test is not a substitute for those full tests. + +## Stage 2: extract the execution path, without changing results + +Next, separately reviewed work: + +1. Record byte-for-byte output and structured statuses for multilingual text, + protected code/links, empty inputs, existing carriers, capped inputs, and + malformed inputs. Include package/wheel entrypoints and legacy APIs. +2. Extract `ProcessResult` and pure transformation orchestration from `cli.py`. + Keep command parsing, terminal messages, file writes, and clipboard access + outside the engine. Preserve compatibility of the existing CLI imports. +3. Map actual imports, dynamic lookups, workflows, scripts, tests, documented + APIs, and frozen source hashes before moving a module. +4. Move runtime dependencies behind a one-way boundary. Research may depend on + core; core must not depend on research runners or detector feedback. +5. Only then separate the default wheel from optional research/replay tooling. + Do not simply exclude `experiments/` while reachable APIs still need it. + +Gate: existing output/status compatibility, reproducible historical records, +clean installed-package tests, and no weakened isolation or fidelity checks. + +## Stage 3: a useful watermark experiment before a new algorithm + +Build one reproducible comparison first, not dozens of new runners. Use known +watermarked and matched unwatermarked sources, a calibrated fixed threshold, +separate development/confirmation data and held-out keys. Report detector TPR +at a specified FPR, text-quality failures, normalizer behavior, cost, and +failures to process. Keep historical mark-only results separate from the live +five-layer algorithm. An exact-source restore count is not a detection rate. + +Start with one pinned open statistical-watermark implementation. Expand to a +second tokenizer/model family and a different watermark mechanism only after +the first harness is valid. Do not spend model budget on a new strategy before +this baseline can detect regressions. + +## Stage 4: constrained reconstruction is a hypothesis, not a release promise + +Evaluate content reconstruction against a plain paraphrasing baseline under the +same budget and fidelity constraints. Lock numbers, entities, quotes, code, +formulas, negation, and factual relationships where they can be checked. Measure +omissions and invented statements separately. Independent fidelity review is +required; one model judging its own rewrite is not proof of equivalence. + +Promote a new strategy only if it improves the predeclared quality/effectiveness +tradeoff on unused evaluation data. If it does not, retain the negative result +and stop that branch rather than adding layers or inventing a success metric. +No universal removal, unknown-detector guarantee, or novelty claim follows from +this architecture. + +## Removal policy + +A module is not dead merely because the current CLI does not call it. A removal +must identify callers (including dynamic imports and external API contracts), +historical replay value, and replacement tests. Archive historically meaningful +code; delete only demonstrably unused code after those checks. A green test +suite alone does not prove an undocumented external caller does not exist. + +Keep this change independent of algorithm experiments and marketing work so it +can be reviewed or reverted without rewriting the scientific record. diff --git a/fuckmark/__init__.py b/fuckmark/__init__.py index 6da7ab00..5ae028d3 100644 --- a/fuckmark/__init__.py +++ b/fuckmark/__init__.py @@ -1,472 +1,266 @@ +from importlib import import_module as _import_module + + +_EXPORTS: dict[str, str | None] = { + "TASK29_FIDELITY_READINESS_ALGORITHM_VERSION": ".transforms", + "FidelityReadinessStatus": ".transforms", + "FidelityReadinessVerificationError": ".transforms", + "FidelityRuleReadiness": ".transforms", + "Task29FidelityReadinessReport": ".transforms", + "build_task29_fidelity_readiness": ".transforms", + "verify_task29_fidelity_readiness": ".transforms", + "FIDELITY_EVIDENCE_ALGORITHM_VERSION": ".transforms", + "BLIND_REVIEW_PACKET_ALGORITHM_VERSION": ".transforms", + "BlindHumanFidelityAudit": ".transforms", + "BlindReviewPacket": ".transforms", + "BlindReviewPacketEntry": ".transforms", + "BlindReviewPacketVerificationError": ".transforms", + "BlindReviewJudgment": ".transforms", + "FidelityAdjudication": ".transforms", + "FidelityEvidenceVerificationError": ".transforms", + "FidelityLabel": ".transforms", + "FidelityReviewSample": ".transforms", + "GrammarFixture": ".transforms", + "GrammarFixtureDisposition": ".transforms", + "LEXICAL_PROMOTION_EVIDENCE_ALGORITHM_VERSION": ".transforms", + "LexicalPromotionEvidence": ".transforms", + "SYNTAX_DEVELOPMENT_EVIDENCE_ALGORITHM_VERSION": ".transforms", + "SyntaxDevelopmentEvidence": ".transforms", + "create_blind_human_fidelity_audit": ".transforms", + "bind_blind_review_judgment": ".transforms", + "bind_blind_review_judgments": ".transforms", + "build_blind_review_packet": ".transforms", + "source_verified_historical_visible_edit_transform_registry": ".transforms", + "source_verified_release_transform_registry": ".transforms", + "verify_fidelity_review_sample": ".transforms", + "verify_blind_review_packet": ".transforms", + "verify_grammar_fixture": ".transforms", + "verify_lexical_promotion_evidence": ".transforms", + "verify_syntax_development_evidence": ".transforms", + "__project_name__": None, + "__version__": None, + "AdapterRegistry": ".adapters", + "AdapterSignals": ".adapters", + "align_tokens": ".alignment", + "AlignmentOp": ".alignment", + "AlignmentResult": ".alignment", + "AlignmentStep": ".alignment", + "apply_calibration": ".detectors", + "BLIND_HUMAN_REVIEW_POLICY_ID": ".transforms", + "build_corpus_manifest": ".corpus", + "CORPUS_MANIFEST_ALGORITHM_VERSION": ".corpus", + "CorpusDomain": ".corpus", + "CorpusIntegrityError": ".corpus", + "CorpusLeakageError": ".corpus", + "CorpusManifest": ".corpus", + "CorpusPairingError": ".corpus", + "CorpusSample": ".corpus", + "CorpusSplit": ".corpus", + "DeduplicationPolicy": ".corpus", + "GenerationParameters": ".corpus", + "GenerationTokenRecord": ".corpus", + "KeySplit": ".corpus", + "ModelTokenizerIdentity": ".corpus", + "PaddingSide": ".corpus", + "PromptBoundaryMode": ".corpus", + "PromptRecord": ".corpus", + "TARGET_LENGTHS": ".corpus", + "TextOnlyTokenRecord": ".corpus", + "TokenTrack": ".corpus", + "WatermarkCondition": ".corpus", + "WatermarkLabel": ".corpus", + "BaselineStatus": ".detectors", + "build_native_observations": ".native_observations", + "build_token_ngrams": ".observations", + "calibrate_detector": ".detectors", + "CalibratedDetectorResult": ".detectors", + "CALIBRATION_ALGORITHM_VERSION": ".detectors", + "CalibrationBundle": ".detectors", + "CalibrationIdentityError": ".detectors", + "CalibrationResolutionError": ".detectors", + "CalibrationScope": ".detectors", + "CalibrationThreshold": ".detectors", + "canonical_json_bytes": ".config", + "canonical_json_text": ".config", + "canonicalize": ".config", + "capture_lexical_retokenization_fixture": ".transforms", + "capture_syntax_retokenization_fixture": ".transforms", + "ComparisonOperator": ".detectors", + "CompatibilityStatus": ".detectors", + "conserved_runs": ".alignment", + "create_deepmind_reference_adapter": ".adapters", + "create_huggingface_synthid_adapter": ".adapters", + "create_lexical_rule_audit": ".transforms", + "create_syntax_rule_audit": ".transforms", + "DEEPMIND_REFERENCE_ADAPTER_ID": ".adapters", + "DEEPMIND_REFERENCE_ALGORITHM_VERSION": ".adapters", + "DEEPMIND_REFERENCE_SOURCE_PIN": ".adapters", + "DeepMindReferenceAdapter": ".adapters", + "DeepMindReferenceConfig": ".adapters", + "default_adapter_registry": ".adapters", + "derive_seed": ".hashing", + "DetectorArtifactVerificationError": ".detectors", + "DetectorCalibrationIdentity": ".detectors", + "DetectorCompatibility": ".detectors", + "DetectorCompatibilityError": ".detectors", + "DetectorFamily": ".detectors", + "development_lexical_rules": ".transforms", + "development_syntax_rules": ".transforms", + "development_transform_registry": ".transforms", + "evaluate_detector_compatibility": ".detectors", + "evaluate_pristine_baseline": ".detectors", + "exact_binomial_interval": ".detectors", + "ExactBinomialInterval": ".detectors", + "HUGGINGFACE_SYNTHID_ADAPTER_ID": ".adapters", + "HUGGINGFACE_SYNTHID_ALGORITHM_VERSION": ".adapters", + "HUGGINGFACE_SYNTHID_SOURCE_PIN": ".adapters", + "HuggingFaceSynthIDAdapter": ".adapters", + "HuggingFaceSynthIDConfig": ".adapters", + "Interval": ".coverage", + "LEXICAL_RETOKENIZATION_FIXTURE_ALGORITHM_VERSION": ".transforms", + "LEXICAL_RULE_AUDIT_ALGORITHM_VERSION": ".transforms", + "LEXICAL_TEMPLATE_RULE_ALGORITHM_VERSION": ".transforms", + "LexicalAuditStatus": ".transforms", + "LexicalConstruction": ".transforms", + "LexicalRetokenizationFixture": ".transforms", + "LexicalRetokenizationVerificationError": ".transforms", + "LexicalRuleAudit": ".transforms", + "LexicalRulePromotionError": ".transforms", + "LexicalTemplateRule": ".transforms", + "load_source_pin": ".source_registry", + "MEAN_ALGORITHM_VERSION": ".detectors", + "mean_evidence": ".detectors", + "mean_score": ".detectors", + "merge_intervals": ".coverage", + "MINIMUM_SYNTAX_EQUIVALENT_OR_MINOR_RATE": ".transforms", + "MINIMUM_SYNTAX_GRAMMAR_FIXTURES_PER_CLASS": ".transforms", + "MINIMUM_SYNTAX_HUMAN_AUDIT_SAMPLES": ".transforms", + "NativeObservationBatch": ".native_observations", + "NativeObservationRecord": ".native_observations", + "NativeObservationVerificationError": ".observation_verification", + "NullQuantile": ".detectors", + "PristineBaselineSummary": ".detectors", + "release_transform_registry": ".transforms", + "require_complete_lexical_audit_summaries": ".transforms", + "require_supported_detector": ".detectors", + "RunIdentity": ".types", + "SCAN_ALGORITHM_VERSION": ".product.scan", + "SCAN_CATEGORIES": ".product.scan", + "SECURITY_SCAN_CATEGORIES": ".product.scan", + "NORMALIZE_ALGORITHM_VERSION": ".product.normalize", + "NormalizeReceipt": ".product.normalize", + "normalize_receipt_dict": ".product.normalize", + "normalize_text": ".product.normalize", + "skeleton_fold": ".product.normalize", + "HiddenFinding": ".product.scan", + "ScanResult": ".product.scan", + "classify_hidden_codepoint": ".product.scan", + "clean_hidden_characters": ".product.scan", + "autofix_trojan_source": ".product.scan", + "extract_tag_payload": ".product.scan", + "scan_dict": ".product.scan", + "scan_hidden_characters": ".product.scan", + "scan_human_report": ".product.scan", + "scan_machine_line": ".product.scan", + "Guard": ".guard", + "GuardReceipt": ".guard", + "HiddenTextRefused": ".guard", + "inspect": ".guard", + "protect": ".guard", + "receipt_dict": ".guard", + "ScoreDirection": ".detectors", + "sha256_bytes": ".hashing", + "sha256_file": ".hashing", + "sha256_json": ".hashing", + "sha256_text": ".hashing", + "SourcePin": ".types", + "SourcePinRegistry": ".source_registry", + "structural_observation_diff": ".observations", + "StructuralObservationDiff": ".observations", + "StructuralObservationState": ".observations", + "StructuralObservationSummary": ".observations", + "substitution_observation_interval": ".coverage", + "summarize_structural_observations": ".observations", + "SYNTAX_RETOKENIZATION_FIXTURE_ALGORITHM_VERSION": ".transforms", + "SYNTAX_RULE_AUDIT_ALGORITHM_VERSION": ".transforms", + "SYNTAX_TEMPLATE_RULE_ALGORITHM_VERSION": ".transforms", + "SyntaxAuditStatus": ".transforms", + "SyntaxConstruction": ".transforms", + "SyntaxRetokenizationFixture": ".transforms", + "SyntaxRetokenizationVerificationError": ".transforms", + "SyntaxRuleAudit": ".transforms", + "SyntaxTemplateRule": ".transforms", + "TokenNgram": ".observations", + "UncalibratedDetectorEvidence": ".detectors", + "union_size": ".coverage", + "validate_alignment": ".alignment", + "verify_calibrated_detector_result": ".detectors", + "verify_calibration_bundle": ".detectors", + "verify_lexical_retokenization_fixture": ".transforms", + "verify_native_observation_batch": ".observation_verification", + "verify_pristine_baseline_summary": ".detectors", + "verify_syntax_retokenization_fixture": ".transforms", + "verify_uncalibrated_detector_evidence": ".detectors", + "WatermarkAdapter": ".adapters", + "WEIGHTED_MEAN_ALGORITHM_VERSION": ".detectors", + "weighted_mean_evidence": ".detectors", + "weighted_mean_score": ".detectors", + "CandidateConflict": ".transforms", + "CandidateEnumeration": ".transforms", + "CandidateRejection": ".transforms", + "CandidateRejectionReason": ".transforms", + "HARD_INVARIANT_ALGORITHM_VERSION": ".transforms", + "HardInvariantReason": ".transforms", + "HardInvariantReport": ".transforms", + "HardInvariantSignature": ".transforms", + "hard_invariant_signature": ".transforms", + "validate_hard_invariants": ".transforms", + "InvariantDifference": ".transforms", + "InvariantStatus": ".transforms", + "LiteralTransformRule": ".transforms", + "PROTECTED_SPAN_ALGORITHM_VERSION": ".transforms", + "ProtectedInvariantReport": ".transforms", + "ProtectedSpan": ".transforms", + "ProtectedSpanExtractor": ".transforms", + "ProtectedSpanKind": ".transforms", + "ProtectedSpanManifest": ".transforms", + "RULE_ALGORITHM_VERSION": ".transforms", + "TRANSFORM_APPLY_ALGORITHM_VERSION": ".transforms", + "TRANSFORM_REGISTRY_ALGORITHM_VERSION": ".transforms", + "TransformCandidate": ".transforms", + "TransformFamily": ".transforms", + "TransformOperation": ".transforms", + "TransformRegistry": ".transforms", + "TransformResult": ".transforms", + "TransformRule": ".transforms", + "TransformTier": ".transforms", + "TransformationTrace": ".transforms", + "UserProtectedRange": ".transforms", + "default_contraction_rules": ".transforms", + "default_transform_registry": ".transforms", + "historical_visible_edit_transform_registry": ".transforms", + "validate_protected_invariants": ".transforms", + "ZeroValidObservationsError": ".detectors", +} + +__all__ = list(_EXPORTS) + +for _export_name in _EXPORTS: + globals().pop(_export_name, None) +del _export_name + __project_name__ = "FuckMark" __version__ = "0.4.1" -from .adapters import ( - DEEPMIND_REFERENCE_ADAPTER_ID, - DEEPMIND_REFERENCE_ALGORITHM_VERSION, - DEEPMIND_REFERENCE_SOURCE_PIN, - AdapterRegistry, - AdapterSignals, - DeepMindReferenceAdapter, - DeepMindReferenceConfig, - HUGGINGFACE_SYNTHID_ADAPTER_ID, - HUGGINGFACE_SYNTHID_ALGORITHM_VERSION, - HUGGINGFACE_SYNTHID_SOURCE_PIN, - HuggingFaceSynthIDAdapter, - HuggingFaceSynthIDConfig, - WatermarkAdapter, - create_deepmind_reference_adapter, - create_huggingface_synthid_adapter, - default_adapter_registry, -) -from .alignment import AlignmentOp, AlignmentResult, AlignmentStep, align_tokens, conserved_runs, validate_alignment -from .config import canonical_json_bytes, canonical_json_text, canonicalize -from .coverage import Interval, merge_intervals, substitution_observation_interval, union_size -from .corpus import ( - CORPUS_MANIFEST_ALGORITHM_VERSION, - TARGET_LENGTHS, - CorpusDomain, - CorpusIntegrityError, - CorpusLeakageError, - CorpusManifest, - CorpusPairingError, - CorpusSample, - CorpusSplit, - DeduplicationPolicy, - GenerationParameters, - GenerationTokenRecord, - KeySplit, - ModelTokenizerIdentity, - PaddingSide, - PromptBoundaryMode, - PromptRecord, - TextOnlyTokenRecord, - TokenTrack, - WatermarkCondition, - WatermarkLabel, - build_corpus_manifest, -) -from .hashing import derive_seed, sha256_bytes, sha256_file, sha256_json, sha256_text -from .detectors import ( - BaselineStatus, - CALIBRATION_ALGORITHM_VERSION, - CalibratedDetectorResult, - CalibrationBundle, - CalibrationIdentityError, - CalibrationResolutionError, - CalibrationScope, - CalibrationThreshold, - ComparisonOperator, - CompatibilityStatus, - DetectorArtifactVerificationError, - DetectorCalibrationIdentity, - DetectorCompatibility, - DetectorCompatibilityError, - DetectorFamily, - ExactBinomialInterval, - MEAN_ALGORITHM_VERSION, - NullQuantile, - PristineBaselineSummary, - ScoreDirection, - UncalibratedDetectorEvidence, - WEIGHTED_MEAN_ALGORITHM_VERSION, - ZeroValidObservationsError, - apply_calibration, - calibrate_detector, - evaluate_detector_compatibility, - evaluate_pristine_baseline, - exact_binomial_interval, - mean_evidence, - mean_score, - require_supported_detector, - verify_calibrated_detector_result, - verify_calibration_bundle, - verify_pristine_baseline_summary, - verify_uncalibrated_detector_evidence, - weighted_mean_evidence, - weighted_mean_score, -) -from .product.scan import ( - SCAN_ALGORITHM_VERSION, - SCAN_CATEGORIES, - SECURITY_SCAN_CATEGORIES, - HiddenFinding, - ScanResult, - classify_hidden_codepoint, - clean_hidden_characters, - extract_tag_payload, - autofix_trojan_source, - scan_dict, - scan_hidden_characters, - scan_human_report, - scan_machine_line, -) -from .product.normalize import ( - NORMALIZE_ALGORITHM_VERSION, - NormalizeReceipt, - normalize_receipt_dict, - normalize_text, - skeleton_fold, -) -from .guard import Guard, GuardReceipt, HiddenTextRefused, inspect, protect, receipt_dict -from .native_observations import NativeObservationBatch, NativeObservationRecord, build_native_observations -from .observation_verification import NativeObservationVerificationError, verify_native_observation_batch -from .observations import ( - StructuralObservationDiff, - StructuralObservationState, - StructuralObservationSummary, - TokenNgram, - build_token_ngrams, - structural_observation_diff, - summarize_structural_observations, -) -from .source_registry import SourcePinRegistry, load_source_pin -from .types import RunIdentity, SourcePin -from .transforms import ( - TASK29_FIDELITY_READINESS_ALGORITHM_VERSION, - FidelityReadinessStatus, - FidelityReadinessVerificationError, - FidelityRuleReadiness, - Task29FidelityReadinessReport, - build_task29_fidelity_readiness, - verify_task29_fidelity_readiness, - FIDELITY_EVIDENCE_ALGORITHM_VERSION, - BLIND_REVIEW_PACKET_ALGORITHM_VERSION, - BlindHumanFidelityAudit, - BlindReviewPacket, - BlindReviewPacketEntry, - BlindReviewPacketVerificationError, - BlindReviewJudgment, - FidelityAdjudication, - FidelityEvidenceVerificationError, - FidelityLabel, - FidelityReviewSample, - GrammarFixture, - GrammarFixtureDisposition, - LEXICAL_PROMOTION_EVIDENCE_ALGORITHM_VERSION, - LexicalPromotionEvidence, - SYNTAX_DEVELOPMENT_EVIDENCE_ALGORITHM_VERSION, - SyntaxDevelopmentEvidence, - create_blind_human_fidelity_audit, - bind_blind_review_judgment, - bind_blind_review_judgments, - build_blind_review_packet, - source_verified_historical_visible_edit_transform_registry, - source_verified_release_transform_registry, - verify_fidelity_review_sample, - verify_blind_review_packet, - verify_grammar_fixture, - verify_lexical_promotion_evidence, - verify_syntax_development_evidence, - BLIND_HUMAN_REVIEW_POLICY_ID, - LEXICAL_RETOKENIZATION_FIXTURE_ALGORITHM_VERSION, - LEXICAL_RULE_AUDIT_ALGORITHM_VERSION, - LEXICAL_TEMPLATE_RULE_ALGORITHM_VERSION, - MINIMUM_SYNTAX_EQUIVALENT_OR_MINOR_RATE, - MINIMUM_SYNTAX_GRAMMAR_FIXTURES_PER_CLASS, - MINIMUM_SYNTAX_HUMAN_AUDIT_SAMPLES, - PROTECTED_SPAN_ALGORITHM_VERSION, - RULE_ALGORITHM_VERSION, - SYNTAX_RETOKENIZATION_FIXTURE_ALGORITHM_VERSION, - SYNTAX_RULE_AUDIT_ALGORITHM_VERSION, - SYNTAX_TEMPLATE_RULE_ALGORITHM_VERSION, - TRANSFORM_APPLY_ALGORITHM_VERSION, - TRANSFORM_REGISTRY_ALGORITHM_VERSION, - CandidateConflict, - CandidateEnumeration, - CandidateRejection, - CandidateRejectionReason, - HARD_INVARIANT_ALGORITHM_VERSION, - HardInvariantReason, - HardInvariantReport, - HardInvariantSignature, - InvariantDifference, - InvariantStatus, - LexicalAuditStatus, - LexicalConstruction, - LexicalRetokenizationFixture, - LexicalRetokenizationVerificationError, - LexicalRuleAudit, - LexicalRulePromotionError, - LexicalTemplateRule, - LiteralTransformRule, - ProtectedInvariantReport, - ProtectedSpan, - ProtectedSpanExtractor, - ProtectedSpanKind, - ProtectedSpanManifest, - SyntaxAuditStatus, - SyntaxConstruction, - SyntaxRetokenizationFixture, - SyntaxRetokenizationVerificationError, - SyntaxRuleAudit, - SyntaxTemplateRule, - TransformCandidate, - TransformFamily, - TransformOperation, - TransformRegistry, - TransformResult, - TransformRule, - TransformTier, - TransformationTrace, - UserProtectedRange, - capture_lexical_retokenization_fixture, - capture_syntax_retokenization_fixture, - create_lexical_rule_audit, - create_syntax_rule_audit, - default_contraction_rules, - default_transform_registry, - development_lexical_rules, - development_syntax_rules, - development_transform_registry, - historical_visible_edit_transform_registry, - hard_invariant_signature, - release_transform_registry, - require_complete_lexical_audit_summaries, - validate_hard_invariants, - validate_protected_invariants, - verify_lexical_retokenization_fixture, - verify_syntax_retokenization_fixture, -) -__all__ = [ - "TASK29_FIDELITY_READINESS_ALGORITHM_VERSION", - "FidelityReadinessStatus", - "FidelityReadinessVerificationError", - "FidelityRuleReadiness", - "Task29FidelityReadinessReport", - "build_task29_fidelity_readiness", - "verify_task29_fidelity_readiness", - "FIDELITY_EVIDENCE_ALGORITHM_VERSION", - "BLIND_REVIEW_PACKET_ALGORITHM_VERSION", - "BlindHumanFidelityAudit", - "BlindReviewPacket", - "BlindReviewPacketEntry", - "BlindReviewPacketVerificationError", - "BlindReviewJudgment", - "FidelityAdjudication", - "FidelityEvidenceVerificationError", - "FidelityLabel", - "FidelityReviewSample", - "GrammarFixture", - "GrammarFixtureDisposition", - "LEXICAL_PROMOTION_EVIDENCE_ALGORITHM_VERSION", - "LexicalPromotionEvidence", - "SYNTAX_DEVELOPMENT_EVIDENCE_ALGORITHM_VERSION", - "SyntaxDevelopmentEvidence", - "create_blind_human_fidelity_audit", - "bind_blind_review_judgment", - "bind_blind_review_judgments", - "build_blind_review_packet", - "source_verified_historical_visible_edit_transform_registry", - "source_verified_release_transform_registry", - "verify_fidelity_review_sample", - "verify_blind_review_packet", - "verify_grammar_fixture", - "verify_lexical_promotion_evidence", - "verify_syntax_development_evidence", - "__project_name__", - "__version__", - "AdapterRegistry", - "AdapterSignals", - "align_tokens", - "AlignmentOp", - "AlignmentResult", - "AlignmentStep", - "apply_calibration", - "BLIND_HUMAN_REVIEW_POLICY_ID", - "build_corpus_manifest", - "CORPUS_MANIFEST_ALGORITHM_VERSION", - "CorpusDomain", - "CorpusIntegrityError", - "CorpusLeakageError", - "CorpusManifest", - "CorpusPairingError", - "CorpusSample", - "CorpusSplit", - "DeduplicationPolicy", - "GenerationParameters", - "GenerationTokenRecord", - "KeySplit", - "ModelTokenizerIdentity", - "PaddingSide", - "PromptBoundaryMode", - "PromptRecord", - "TARGET_LENGTHS", - "TextOnlyTokenRecord", - "TokenTrack", - "WatermarkCondition", - "WatermarkLabel", - "BaselineStatus", - "build_native_observations", - "build_token_ngrams", - "calibrate_detector", - "CalibratedDetectorResult", - "CALIBRATION_ALGORITHM_VERSION", - "CalibrationBundle", - "CalibrationIdentityError", - "CalibrationResolutionError", - "CalibrationScope", - "CalibrationThreshold", - "canonical_json_bytes", - "canonical_json_text", - "canonicalize", - "capture_lexical_retokenization_fixture", - "capture_syntax_retokenization_fixture", - "ComparisonOperator", - "CompatibilityStatus", - "conserved_runs", - "create_deepmind_reference_adapter", - "create_huggingface_synthid_adapter", - "create_lexical_rule_audit", - "create_syntax_rule_audit", - "DEEPMIND_REFERENCE_ADAPTER_ID", - "DEEPMIND_REFERENCE_ALGORITHM_VERSION", - "DEEPMIND_REFERENCE_SOURCE_PIN", - "DeepMindReferenceAdapter", - "DeepMindReferenceConfig", - "default_adapter_registry", - "derive_seed", - "DetectorArtifactVerificationError", - "DetectorCalibrationIdentity", - "DetectorCompatibility", - "DetectorCompatibilityError", - "DetectorFamily", - "development_lexical_rules", - "development_syntax_rules", - "development_transform_registry", - "evaluate_detector_compatibility", - "evaluate_pristine_baseline", - "exact_binomial_interval", - "ExactBinomialInterval", - "HUGGINGFACE_SYNTHID_ADAPTER_ID", - "HUGGINGFACE_SYNTHID_ALGORITHM_VERSION", - "HUGGINGFACE_SYNTHID_SOURCE_PIN", - "HuggingFaceSynthIDAdapter", - "HuggingFaceSynthIDConfig", - "Interval", - "LEXICAL_RETOKENIZATION_FIXTURE_ALGORITHM_VERSION", - "LEXICAL_RULE_AUDIT_ALGORITHM_VERSION", - "LEXICAL_TEMPLATE_RULE_ALGORITHM_VERSION", - "LexicalAuditStatus", - "LexicalConstruction", - "LexicalRetokenizationFixture", - "LexicalRetokenizationVerificationError", - "LexicalRuleAudit", - "LexicalRulePromotionError", - "LexicalTemplateRule", - "load_source_pin", - "MEAN_ALGORITHM_VERSION", - "mean_evidence", - "mean_score", - "merge_intervals", - "MINIMUM_SYNTAX_EQUIVALENT_OR_MINOR_RATE", - "MINIMUM_SYNTAX_GRAMMAR_FIXTURES_PER_CLASS", - "MINIMUM_SYNTAX_HUMAN_AUDIT_SAMPLES", - "NativeObservationBatch", - "NativeObservationRecord", - "NativeObservationVerificationError", - "NullQuantile", - "PristineBaselineSummary", - "release_transform_registry", - "require_complete_lexical_audit_summaries", - "require_supported_detector", - "RunIdentity", - "SCAN_ALGORITHM_VERSION", - "SCAN_CATEGORIES", - "SECURITY_SCAN_CATEGORIES", - "NORMALIZE_ALGORITHM_VERSION", - "NormalizeReceipt", - "normalize_receipt_dict", - "normalize_text", - "skeleton_fold", - "HiddenFinding", - "ScanResult", - "classify_hidden_codepoint", - "clean_hidden_characters", - "autofix_trojan_source", - "extract_tag_payload", - "scan_dict", - "scan_hidden_characters", - "scan_human_report", - "scan_machine_line", - "Guard", - "GuardReceipt", - "HiddenTextRefused", - "inspect", - "protect", - "receipt_dict", - "ScoreDirection", - "sha256_bytes", - "sha256_file", - "sha256_json", - "sha256_text", - "SourcePin", - "SourcePinRegistry", - "structural_observation_diff", - "StructuralObservationDiff", - "StructuralObservationState", - "StructuralObservationSummary", - "substitution_observation_interval", - "summarize_structural_observations", - "SYNTAX_RETOKENIZATION_FIXTURE_ALGORITHM_VERSION", - "SYNTAX_RULE_AUDIT_ALGORITHM_VERSION", - "SYNTAX_TEMPLATE_RULE_ALGORITHM_VERSION", - "SyntaxAuditStatus", - "SyntaxConstruction", - "SyntaxRetokenizationFixture", - "SyntaxRetokenizationVerificationError", - "SyntaxRuleAudit", - "SyntaxTemplateRule", - "TokenNgram", - "UncalibratedDetectorEvidence", - "union_size", - "validate_alignment", - "verify_calibrated_detector_result", - "verify_calibration_bundle", - "verify_lexical_retokenization_fixture", - "verify_native_observation_batch", - "verify_pristine_baseline_summary", - "verify_syntax_retokenization_fixture", - "verify_uncalibrated_detector_evidence", - "WatermarkAdapter", - "WEIGHTED_MEAN_ALGORITHM_VERSION", - "weighted_mean_evidence", - "weighted_mean_score", - "CandidateConflict", - "CandidateEnumeration", - "CandidateRejection", - "CandidateRejectionReason", - "HARD_INVARIANT_ALGORITHM_VERSION", - "HardInvariantReason", - "HardInvariantReport", - "HardInvariantSignature", - "hard_invariant_signature", - "validate_hard_invariants", - "InvariantDifference", - "InvariantStatus", - "LiteralTransformRule", - "PROTECTED_SPAN_ALGORITHM_VERSION", - "ProtectedInvariantReport", - "ProtectedSpan", - "ProtectedSpanExtractor", - "ProtectedSpanKind", - "ProtectedSpanManifest", - "RULE_ALGORITHM_VERSION", - "TRANSFORM_APPLY_ALGORITHM_VERSION", - "TRANSFORM_REGISTRY_ALGORITHM_VERSION", - "TransformCandidate", - "TransformFamily", - "TransformOperation", - "TransformRegistry", - "TransformResult", - "TransformRule", - "TransformTier", - "TransformationTrace", - "UserProtectedRange", - "default_contraction_rules", - "default_transform_registry", - "historical_visible_edit_transform_registry", - "validate_protected_invariants", - "ZeroValidObservationsError", -] +def __getattr__(name: str) -> object: + source = _EXPORTS.get(name) + if source is None: + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + value = getattr(_import_module(source, __name__), name) + globals()[name] = value + return value + + +def __dir__() -> list[str]: + return sorted(set(globals()) | set(_EXPORTS)) diff --git a/fuckmark/product/__init__.py b/fuckmark/product/__init__.py index 4f17ba5f..1be8ecbd 100644 --- a/fuckmark/product/__init__.py +++ b/fuckmark/product/__init__.py @@ -1,164 +1,98 @@ -from .carrier_invariants import ( - PRODUCT_CARRIER_INVARIANT_ALGORITHM_VERSION, - WORD_SIGNATURE_SOURCE_RAW, - WORD_SIGNATURE_SOURCE_VISIBLE, - validate_product_carrier_invariants, -) -from .carriers import ( - InvisibleCarrierAfterAsciiLetterRule, - InvisibleCarrierAfterWordFinalAsciiLetterRule, - codepoint_label, - rule_preserves_visible_projection, - space_carrier_rule, -) -from .contract import ( - FROZEN_PRODUCT_CONTRACT_HASH, - PRODUCT_CONTRACT_PATH, - load_product_contract, - product_contract_hash, - product_contract_payload, -) -from .domain import PRODUCT_DOMAIN_ID, is_supported_product_domain_v1 -from .encodings import ( - PRODUCT_ENCODING_POLICY_VERSION, - PRODUCT_TEXT_ENCODING, - UNSUPPORTED_PRODUCT_ENCODINGS, - canonical_product_encoding_name, - encoding_roundtrip_survives, - is_supported_product_encoding, - require_supported_product_encoding, -) -from .invariants import ( - USER_VISIBLE_INVARIANT_ALGORITHM_VERSION, - UserVisibleInvariantReason, - UserVisibleInvariantReport, - validate_user_visible_invariants, -) -from .registry import PRODUCT_REGISTRY_ALGORITHM_VERSION, ProductTransformRegistry, product_transform_registry -from .normalize import ( - NORMALIZE_ALGORITHM_VERSION, - NormalizeReceipt, - normalize_payload, - normalize_receipt_dict, - normalize_text, - skeleton_fold, -) -from .scan import ( - SCAN_ALGORITHM_VERSION, - SCAN_CATEGORIES, - SECURITY_SCAN_CATEGORIES, - TROJAN_SOURCE_CATEGORIES, - HiddenFinding, - ScanResult, - autofix_trojan_source, - classify_hidden_codepoint, - clean_hidden_characters, - extract_tag_payload, - scan_dict, - scan_hidden_characters, - scan_human_report, - scan_machine_line, -) -from .severity import ( - CONTEXT_COMMENT, - CONTEXT_EMOJI, - CONTEXT_IDENTIFIER, - CONTEXT_PROSE, - CONTEXT_STRING, - SEVERITY_CRITICAL, - SEVERITY_HIGH, - SEVERITY_INFO, - SEVERITY_MEDIUM, - annotate_finding, - classify_context, - language_from_path, - normalize_language, - score_severity, - source_roles, -) -from .search import PRODUCT_SEARCH_ALGORITHM_VERSION, raw_codepoint_contains, visible_contains -from .visible_projection import ( - PRODUCT_CONTRACT_ID, - VISIBLE_PROJECTION_ALGORITHM_VERSION, - is_carrier_insertion_v1, - normalize_approved_carriers, - product_approved_carriers_v1, - project_visible_v1, -) +from importlib import import_module as _import_module -__all__ = [ - "InvisibleCarrierAfterAsciiLetterRule", - "InvisibleCarrierAfterWordFinalAsciiLetterRule", - "FROZEN_PRODUCT_CONTRACT_HASH", - "PRODUCT_CARRIER_INVARIANT_ALGORITHM_VERSION", - "PRODUCT_CONTRACT_ID", - "PRODUCT_CONTRACT_PATH", - "PRODUCT_DOMAIN_ID", - "PRODUCT_ENCODING_POLICY_VERSION", - "PRODUCT_REGISTRY_ALGORITHM_VERSION", - "PRODUCT_SEARCH_ALGORITHM_VERSION", - "PRODUCT_TEXT_ENCODING", - "SCAN_ALGORITHM_VERSION", - "SCAN_CATEGORIES", - "SECURITY_SCAN_CATEGORIES", - "TROJAN_SOURCE_CATEGORIES", - "NORMALIZE_ALGORITHM_VERSION", - "NormalizeReceipt", - "normalize_payload", - "normalize_receipt_dict", - "normalize_text", - "skeleton_fold", - "CONTEXT_COMMENT", - "CONTEXT_EMOJI", - "CONTEXT_IDENTIFIER", - "CONTEXT_PROSE", - "CONTEXT_STRING", - "SEVERITY_CRITICAL", - "SEVERITY_HIGH", - "SEVERITY_INFO", - "SEVERITY_MEDIUM", - "annotate_finding", - "classify_context", - "language_from_path", - "normalize_language", - "score_severity", - "source_roles", - "autofix_trojan_source", - "HiddenFinding", - "ScanResult", - "classify_hidden_codepoint", - "clean_hidden_characters", - "extract_tag_payload", - "scan_dict", - "scan_hidden_characters", - "scan_human_report", - "scan_machine_line", - "ProductTransformRegistry", - "UNSUPPORTED_PRODUCT_ENCODINGS", - "USER_VISIBLE_INVARIANT_ALGORITHM_VERSION", - "UserVisibleInvariantReason", - "UserVisibleInvariantReport", - "VISIBLE_PROJECTION_ALGORITHM_VERSION", - "canonical_product_encoding_name", - "codepoint_label", - "encoding_roundtrip_survives", - "is_carrier_insertion_v1", - "is_supported_product_domain_v1", - "is_supported_product_encoding", - "load_product_contract", - "normalize_approved_carriers", - "product_approved_carriers_v1", - "product_contract_hash", - "product_contract_payload", - "product_transform_registry", - "project_visible_v1", - "raw_codepoint_contains", - "require_supported_product_encoding", - "rule_preserves_visible_projection", - "space_carrier_rule", - "validate_product_carrier_invariants", - "validate_user_visible_invariants", - "visible_contains", - "WORD_SIGNATURE_SOURCE_RAW", - "WORD_SIGNATURE_SOURCE_VISIBLE", -] + +_EXPORTS: dict[str, str | None] = { + "InvisibleCarrierAfterAsciiLetterRule": ".carriers", + "InvisibleCarrierAfterWordFinalAsciiLetterRule": ".carriers", + "FROZEN_PRODUCT_CONTRACT_HASH": ".contract", + "PRODUCT_CARRIER_INVARIANT_ALGORITHM_VERSION": ".carrier_invariants", + "PRODUCT_CONTRACT_ID": ".visible_projection", + "PRODUCT_CONTRACT_PATH": ".contract", + "PRODUCT_DOMAIN_ID": ".domain", + "PRODUCT_ENCODING_POLICY_VERSION": ".encodings", + "PRODUCT_REGISTRY_ALGORITHM_VERSION": ".registry", + "PRODUCT_SEARCH_ALGORITHM_VERSION": ".search", + "PRODUCT_TEXT_ENCODING": ".encodings", + "SCAN_ALGORITHM_VERSION": ".scan", + "SCAN_CATEGORIES": ".scan", + "SECURITY_SCAN_CATEGORIES": ".scan", + "TROJAN_SOURCE_CATEGORIES": ".scan", + "NORMALIZE_ALGORITHM_VERSION": ".normalize", + "NormalizeReceipt": ".normalize", + "normalize_payload": ".normalize", + "normalize_receipt_dict": ".normalize", + "normalize_text": ".normalize", + "skeleton_fold": ".normalize", + "CONTEXT_COMMENT": ".severity", + "CONTEXT_EMOJI": ".severity", + "CONTEXT_IDENTIFIER": ".severity", + "CONTEXT_PROSE": ".severity", + "CONTEXT_STRING": ".severity", + "SEVERITY_CRITICAL": ".severity", + "SEVERITY_HIGH": ".severity", + "SEVERITY_INFO": ".severity", + "SEVERITY_MEDIUM": ".severity", + "annotate_finding": ".severity", + "classify_context": ".severity", + "language_from_path": ".severity", + "normalize_language": ".severity", + "score_severity": ".severity", + "source_roles": ".severity", + "autofix_trojan_source": ".scan", + "HiddenFinding": ".scan", + "ScanResult": ".scan", + "classify_hidden_codepoint": ".scan", + "clean_hidden_characters": ".scan", + "extract_tag_payload": ".scan", + "scan_dict": ".scan", + "scan_hidden_characters": ".scan", + "scan_human_report": ".scan", + "scan_machine_line": ".scan", + "ProductTransformRegistry": ".registry", + "UNSUPPORTED_PRODUCT_ENCODINGS": ".encodings", + "USER_VISIBLE_INVARIANT_ALGORITHM_VERSION": ".invariants", + "UserVisibleInvariantReason": ".invariants", + "UserVisibleInvariantReport": ".invariants", + "VISIBLE_PROJECTION_ALGORITHM_VERSION": ".visible_projection", + "canonical_product_encoding_name": ".encodings", + "codepoint_label": ".carriers", + "encoding_roundtrip_survives": ".encodings", + "is_carrier_insertion_v1": ".visible_projection", + "is_supported_product_domain_v1": ".domain", + "is_supported_product_encoding": ".encodings", + "load_product_contract": ".contract", + "normalize_approved_carriers": ".visible_projection", + "product_approved_carriers_v1": ".visible_projection", + "product_contract_hash": ".contract", + "product_contract_payload": ".contract", + "product_transform_registry": ".registry", + "project_visible_v1": ".visible_projection", + "raw_codepoint_contains": ".search", + "require_supported_product_encoding": ".encodings", + "rule_preserves_visible_projection": ".carriers", + "space_carrier_rule": ".carriers", + "validate_product_carrier_invariants": ".carrier_invariants", + "validate_user_visible_invariants": ".invariants", + "visible_contains": ".search", + "WORD_SIGNATURE_SOURCE_RAW": ".carrier_invariants", + "WORD_SIGNATURE_SOURCE_VISIBLE": ".carrier_invariants", +} + +__all__ = list(_EXPORTS) + +for _export_name in _EXPORTS: + globals().pop(_export_name, None) +del _export_name + + +def __getattr__(name: str) -> object: + source = _EXPORTS.get(name) + if source is None: + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + value = getattr(_import_module(source, __name__), name) + globals()[name] = value + return value + + +def __dir__() -> list[str]: + return sorted(set(globals()) | set(_EXPORTS)) diff --git a/fuckmark/transforms/__init__.py b/fuckmark/transforms/__init__.py index 842cce60..a044d734 100644 --- a/fuckmark/transforms/__init__.py +++ b/fuckmark/transforms/__init__.py @@ -1,335 +1,181 @@ -from .candidate_artifacts import CandidateConflict, CandidateEnumeration, CandidateRejection, TransformCandidate -from .effectiveness_profile import ( - CONTENT_REGION_COMBINED_PROFILE_ID, - CONTENT_REGION_COVERAGE_PROFILE_ID, - CONTENT_REGION_COVERAGE_SEED_BASE, - CONTENT_REGION_GENERAL_ONLY_PROFILE_ID, - EFFECTIVENESS_PROFILE_ALGORITHM_VERSION, - KEY_BLIND_COVERAGE_COMPLETION_PROFILE_ID, - KEY_BLIND_COVERAGE_COMPLETION_SEED_BASE, - KEY_BLIND_FULL_POOL_COVERAGE_PROFILE_ID, - KEY_BLIND_FULL_POOL_COVERAGE_SEED_BASE, - KEY_BLIND_HIGH_COVERAGE_BUDGETS, - KEY_BLIND_HIGH_COVERAGE_PROFILE, - KEY_BLIND_HIGH_COVERAGE_PROFILE_ID, - KEY_BLIND_HIGH_COVERAGE_SEED_BASE, - EffectivenessTransformProfile, - content_region_combined_profile, - content_region_combined_transform_registry, - content_region_coverage_profile, - content_region_coverage_transform_registry, - content_region_destruction_profile, - content_region_destruction_transform_registry, - content_region_general_only_profile, - content_region_general_only_transform_registry, - key_blind_coverage_completion_profile, - key_blind_coverage_completion_transform_registry, - zrd_destruction_profile, - zrd_destruction_transform_registry, - quote_safe_zrd_transform_registry, - key_blind_full_pool_coverage_profile, - key_blind_high_coverage_transform_registry, - resolve_effectiveness_profile, - validate_effectiveness_profile_registry, -) -from .fidelity_readiness import ( - TASK29_FIDELITY_READINESS_ALGORITHM_VERSION, - FidelityReadinessStatus, - FidelityReadinessVerificationError, - FidelityRuleReadiness, - Task29FidelityReadinessReport, - build_task29_fidelity_readiness, - verify_task29_fidelity_readiness, -) -from .fidelity_evidence import ( - FIDELITY_EVIDENCE_ALGORITHM_VERSION, - BlindHumanFidelityAudit, - BlindReviewJudgment, - FidelityAdjudication, - FidelityLabel, - FidelityReviewSample, - GrammarFixture, - GrammarFixtureDisposition, - create_blind_human_fidelity_audit, -) -from .fidelity_review_packets import ( - BLIND_REVIEW_PACKET_ALGORITHM_VERSION, - BlindReviewPacket, - BlindReviewPacketEntry, - BlindReviewPacketVerificationError, - bind_blind_review_judgment, - bind_blind_review_judgments, - build_blind_review_packet, - verify_blind_review_packet, -) -from .fidelity_verification import ( - LEXICAL_PROMOTION_EVIDENCE_ALGORITHM_VERSION, - FidelityEvidenceVerificationError, - LexicalPromotionEvidence, - source_verified_historical_visible_edit_transform_registry, - source_verified_release_transform_registry, - verify_fidelity_review_sample, - verify_grammar_fixture, - verify_lexical_promotion_evidence, -) -from .hard_invariants import HARD_INVARIANT_ALGORITHM_VERSION, HardInvariantReport, HardInvariantSignature, hard_invariant_signature, validate_hard_invariants -from .invariants import validate_protected_invariants -from .lexical_audit import ( - BLIND_HUMAN_REVIEW_POLICY_ID, - LEXICAL_RULE_AUDIT_ALGORITHM_VERSION, - MINIMUM_EQUIVALENT_OR_MINOR_RATE, - MINIMUM_GRAMMAR_FIXTURES_PER_CLASS, - MINIMUM_HUMAN_AUDIT_SAMPLES, - LexicalAuditStatus, - LexicalRuleAudit, - LexicalRulePromotionError, - create_lexical_rule_audit, - require_complete_lexical_audit_summaries, -) -from .lexical_rules import ( - LEXICAL_TEMPLATE_RULE_ALGORITHM_VERSION, - LexicalConstruction, - LexicalTemplateRule, - development_lexical_rules, -) -from .lexical_tokenization import ( - LEXICAL_RETOKENIZATION_FIXTURE_ALGORITHM_VERSION, - LexicalRetokenizationFixture, - LexicalRetokenizationVerificationError, - capture_lexical_retokenization_fixture, - verify_lexical_retokenization_fixture, -) -from .protected import PROTECTED_SPAN_ALGORITHM_VERSION, ProtectedSpanExtractor -from .protected_artifacts import ( - InvariantDifference, - ProtectedInvariantReport, - ProtectedSpan, - ProtectedSpanManifest, - UserProtectedRange, -) -from .registry import ( - TRANSFORM_APPLY_ALGORITHM_VERSION, - TRANSFORM_REGISTRY_ALGORITHM_VERSION, - TransformRegistry, - default_transform_registry, - development_transform_registry, - historical_visible_edit_transform_registry, - release_transform_registry, -) -from .rules import ( - RULE_ALGORITHM_VERSION, - GeneralWordLeadingSpacingRule, - GeneralWordSpacingRule, - LiteralTransformRule, - TransformRule, - default_contraction_rules, -) -from .contractions import ( - zrd_contraction_extension_metadata, - zrd_forward_contraction_extension_rules, - zrd_reverse_contraction_extension_rules, -) -from .scheduler import ( - CANDIDATE_SCHEDULER_ALGORITHM_VERSION, - CandidateScheduler, - CoverageOptimalityDiagnostic, - KeyBlindScheduleInput, - ScheduleGeometryMode, - SchedulePolicy, - ScheduleResult, - SchedulerCandidate, -) -from .schema import CandidateRejectionReason, HardInvariantReason, InvariantStatus, ProtectedSpanKind, TransformFamily, TransformTier -from .syntax_audit import ( - MINIMUM_SYNTAX_EQUIVALENT_OR_MINOR_RATE, - MINIMUM_SYNTAX_GRAMMAR_FIXTURES_PER_CLASS, - MINIMUM_SYNTAX_HUMAN_AUDIT_SAMPLES, - SYNTAX_RULE_AUDIT_ALGORITHM_VERSION, - SyntaxAuditStatus, - SyntaxRuleAudit, - create_syntax_rule_audit, -) -from .syntax_fidelity_verification import ( - SYNTAX_DEVELOPMENT_EVIDENCE_ALGORITHM_VERSION, - SyntaxDevelopmentEvidence, - verify_syntax_development_evidence, -) -from .syntax_rules import ( - SYNTAX_TEMPLATE_RULE_ALGORITHM_VERSION, - SyntaxConstruction, - SyntaxTemplateRule, - development_syntax_rules, -) -from .syntax_tokenization import ( - SYNTAX_RETOKENIZATION_FIXTURE_ALGORITHM_VERSION, - SyntaxRetokenizationFixture, - SyntaxRetokenizationVerificationError, - capture_syntax_retokenization_fixture, - verify_syntax_retokenization_fixture, -) -from .tokenizer_geometry import ( - TOKENIZER_GEOMETRY_ALGORITHM_VERSION, - CandidateTokenizerGeometry, - TokenOffset, - TokenizerGeometryError, - build_candidate_tokenizer_geometry, -) -from .trace import TransformOperation, TransformResult, TransformationTrace +from importlib import import_module as _import_module -__all__ = [ - "TASK29_FIDELITY_READINESS_ALGORITHM_VERSION", - "FidelityReadinessStatus", - "FidelityReadinessVerificationError", - "FidelityRuleReadiness", - "Task29FidelityReadinessReport", - "build_task29_fidelity_readiness", - "verify_task29_fidelity_readiness", - "FIDELITY_EVIDENCE_ALGORITHM_VERSION", - "BLIND_REVIEW_PACKET_ALGORITHM_VERSION", - "BlindHumanFidelityAudit", - "BlindReviewPacket", - "BlindReviewPacketEntry", - "BlindReviewPacketVerificationError", - "BlindReviewJudgment", - "CandidateTokenizerGeometry", - "FidelityAdjudication", - "FidelityEvidenceVerificationError", - "FidelityLabel", - "FidelityReviewSample", - "GrammarFixture", - "GrammarFixtureDisposition", - "LEXICAL_PROMOTION_EVIDENCE_ALGORITHM_VERSION", - "LexicalPromotionEvidence", - "SYNTAX_DEVELOPMENT_EVIDENCE_ALGORITHM_VERSION", - "SyntaxDevelopmentEvidence", - "TOKENIZER_GEOMETRY_ALGORITHM_VERSION", - "TokenOffset", - "TokenizerGeometryError", - "build_candidate_tokenizer_geometry", - "create_blind_human_fidelity_audit", - "bind_blind_review_judgment", - "bind_blind_review_judgments", - "build_blind_review_packet", - "source_verified_historical_visible_edit_transform_registry", - "source_verified_release_transform_registry", - "verify_fidelity_review_sample", - "verify_blind_review_packet", - "verify_grammar_fixture", - "verify_lexical_promotion_evidence", - "verify_syntax_development_evidence", - "BLIND_HUMAN_REVIEW_POLICY_ID", - "CANDIDATE_SCHEDULER_ALGORITHM_VERSION", - "CandidateConflict", - "CandidateEnumeration", - "CandidateRejection", - "CandidateRejectionReason", - "CandidateScheduler", - "CoverageOptimalityDiagnostic", - "EFFECTIVENESS_PROFILE_ALGORITHM_VERSION", - "EffectivenessTransformProfile", - "HARD_INVARIANT_ALGORITHM_VERSION", - "HardInvariantReason", - "HardInvariantReport", - "HardInvariantSignature", - "hard_invariant_signature", - "key_blind_high_coverage_transform_registry", - "key_blind_full_pool_coverage_profile", - "resolve_effectiveness_profile", - "validate_hard_invariants", - "InvariantDifference", - "InvariantStatus", - "KeyBlindScheduleInput", - "KEY_BLIND_HIGH_COVERAGE_BUDGETS", - "KEY_BLIND_HIGH_COVERAGE_PROFILE", - "KEY_BLIND_HIGH_COVERAGE_PROFILE_ID", - "KEY_BLIND_HIGH_COVERAGE_SEED_BASE", - "KEY_BLIND_FULL_POOL_COVERAGE_PROFILE_ID", - "KEY_BLIND_FULL_POOL_COVERAGE_SEED_BASE", - "KEY_BLIND_COVERAGE_COMPLETION_PROFILE_ID", - "KEY_BLIND_COVERAGE_COMPLETION_SEED_BASE", - "CONTENT_REGION_COMBINED_PROFILE_ID", - "CONTENT_REGION_COVERAGE_PROFILE_ID", - "CONTENT_REGION_COVERAGE_SEED_BASE", - "CONTENT_REGION_GENERAL_ONLY_PROFILE_ID", - "content_region_combined_profile", - "content_region_combined_transform_registry", - "content_region_destruction_profile", - "content_region_destruction_transform_registry", - "zrd_contraction_extension_metadata", - "zrd_destruction_profile", - "zrd_destruction_transform_registry", - "quote_safe_zrd_transform_registry", - "zrd_forward_contraction_extension_rules", - "zrd_reverse_contraction_extension_rules", - "content_region_general_only_profile", - "content_region_general_only_transform_registry", - "content_region_coverage_profile", - "content_region_coverage_transform_registry", - "key_blind_coverage_completion_profile", - "key_blind_coverage_completion_transform_registry", - "LEXICAL_RETOKENIZATION_FIXTURE_ALGORITHM_VERSION", - "LEXICAL_RULE_AUDIT_ALGORITHM_VERSION", - "LEXICAL_TEMPLATE_RULE_ALGORITHM_VERSION", - "LexicalAuditStatus", - "LexicalConstruction", - "LexicalRetokenizationFixture", - "LexicalRetokenizationVerificationError", - "LexicalRuleAudit", - "LexicalRulePromotionError", - "LexicalTemplateRule", - "LiteralTransformRule", - "MINIMUM_EQUIVALENT_OR_MINOR_RATE", - "MINIMUM_GRAMMAR_FIXTURES_PER_CLASS", - "MINIMUM_HUMAN_AUDIT_SAMPLES", - "MINIMUM_SYNTAX_EQUIVALENT_OR_MINOR_RATE", - "MINIMUM_SYNTAX_GRAMMAR_FIXTURES_PER_CLASS", - "MINIMUM_SYNTAX_HUMAN_AUDIT_SAMPLES", - "PROTECTED_SPAN_ALGORITHM_VERSION", - "ProtectedInvariantReport", - "ProtectedSpan", - "ProtectedSpanExtractor", - "ProtectedSpanKind", - "ProtectedSpanManifest", - "RULE_ALGORITHM_VERSION", - "ScheduleGeometryMode", - "SchedulePolicy", - "ScheduleResult", - "SchedulerCandidate", - "SYNTAX_RETOKENIZATION_FIXTURE_ALGORITHM_VERSION", - "SYNTAX_RULE_AUDIT_ALGORITHM_VERSION", - "SYNTAX_TEMPLATE_RULE_ALGORITHM_VERSION", - "SyntaxAuditStatus", - "SyntaxConstruction", - "SyntaxRetokenizationFixture", - "SyntaxRetokenizationVerificationError", - "SyntaxRuleAudit", - "SyntaxTemplateRule", - "TRANSFORM_APPLY_ALGORITHM_VERSION", - "TRANSFORM_REGISTRY_ALGORITHM_VERSION", - "TransformCandidate", - "TransformFamily", - "TransformOperation", - "TransformRegistry", - "TransformResult", - "TransformRule", - "TransformTier", - "TransformationTrace", - "UserProtectedRange", - "capture_lexical_retokenization_fixture", - "capture_syntax_retokenization_fixture", - "create_lexical_rule_audit", - "create_syntax_rule_audit", - "default_contraction_rules", - "default_transform_registry", - "development_lexical_rules", - "development_syntax_rules", - "development_transform_registry", - "historical_visible_edit_transform_registry", - "release_transform_registry", - "require_complete_lexical_audit_summaries", - "validate_effectiveness_profile_registry", - "validate_protected_invariants", - "verify_lexical_retokenization_fixture", - "verify_syntax_retokenization_fixture", -] +_EXPORTS: dict[str, str | None] = { + "TASK29_FIDELITY_READINESS_ALGORITHM_VERSION": ".fidelity_readiness", + "FidelityReadinessStatus": ".fidelity_readiness", + "FidelityReadinessVerificationError": ".fidelity_readiness", + "FidelityRuleReadiness": ".fidelity_readiness", + "Task29FidelityReadinessReport": ".fidelity_readiness", + "build_task29_fidelity_readiness": ".fidelity_readiness", + "verify_task29_fidelity_readiness": ".fidelity_readiness", + "FIDELITY_EVIDENCE_ALGORITHM_VERSION": ".fidelity_evidence", + "BLIND_REVIEW_PACKET_ALGORITHM_VERSION": ".fidelity_review_packets", + "BlindHumanFidelityAudit": ".fidelity_evidence", + "BlindReviewPacket": ".fidelity_review_packets", + "BlindReviewPacketEntry": ".fidelity_review_packets", + "BlindReviewPacketVerificationError": ".fidelity_review_packets", + "BlindReviewJudgment": ".fidelity_evidence", + "CandidateTokenizerGeometry": ".tokenizer_geometry", + "FidelityAdjudication": ".fidelity_evidence", + "FidelityEvidenceVerificationError": ".fidelity_verification", + "FidelityLabel": ".fidelity_evidence", + "FidelityReviewSample": ".fidelity_evidence", + "GrammarFixture": ".fidelity_evidence", + "GrammarFixtureDisposition": ".fidelity_evidence", + "LEXICAL_PROMOTION_EVIDENCE_ALGORITHM_VERSION": ".fidelity_verification", + "LexicalPromotionEvidence": ".fidelity_verification", + "SYNTAX_DEVELOPMENT_EVIDENCE_ALGORITHM_VERSION": ".syntax_fidelity_verification", + "SyntaxDevelopmentEvidence": ".syntax_fidelity_verification", + "TOKENIZER_GEOMETRY_ALGORITHM_VERSION": ".tokenizer_geometry", + "TokenOffset": ".tokenizer_geometry", + "TokenizerGeometryError": ".tokenizer_geometry", + "build_candidate_tokenizer_geometry": ".tokenizer_geometry", + "create_blind_human_fidelity_audit": ".fidelity_evidence", + "bind_blind_review_judgment": ".fidelity_review_packets", + "bind_blind_review_judgments": ".fidelity_review_packets", + "build_blind_review_packet": ".fidelity_review_packets", + "source_verified_historical_visible_edit_transform_registry": ".fidelity_verification", + "source_verified_release_transform_registry": ".fidelity_verification", + "verify_fidelity_review_sample": ".fidelity_verification", + "verify_blind_review_packet": ".fidelity_review_packets", + "verify_grammar_fixture": ".fidelity_verification", + "verify_lexical_promotion_evidence": ".fidelity_verification", + "verify_syntax_development_evidence": ".syntax_fidelity_verification", + "BLIND_HUMAN_REVIEW_POLICY_ID": ".lexical_audit", + "CANDIDATE_SCHEDULER_ALGORITHM_VERSION": ".scheduler", + "CandidateConflict": ".candidate_artifacts", + "CandidateEnumeration": ".candidate_artifacts", + "CandidateRejection": ".candidate_artifacts", + "CandidateRejectionReason": ".schema", + "CandidateScheduler": ".scheduler", + "CoverageOptimalityDiagnostic": ".scheduler", + "EFFECTIVENESS_PROFILE_ALGORITHM_VERSION": ".effectiveness_profile", + "EffectivenessTransformProfile": ".effectiveness_profile", + "HARD_INVARIANT_ALGORITHM_VERSION": ".hard_invariants", + "HardInvariantReason": ".schema", + "HardInvariantReport": ".hard_invariants", + "HardInvariantSignature": ".hard_invariants", + "hard_invariant_signature": ".hard_invariants", + "key_blind_high_coverage_transform_registry": ".effectiveness_profile", + "key_blind_full_pool_coverage_profile": ".effectiveness_profile", + "resolve_effectiveness_profile": ".effectiveness_profile", + "validate_hard_invariants": ".hard_invariants", + "InvariantDifference": ".protected_artifacts", + "InvariantStatus": ".schema", + "KeyBlindScheduleInput": ".scheduler", + "KEY_BLIND_HIGH_COVERAGE_BUDGETS": ".effectiveness_profile", + "KEY_BLIND_HIGH_COVERAGE_PROFILE": ".effectiveness_profile", + "KEY_BLIND_HIGH_COVERAGE_PROFILE_ID": ".effectiveness_profile", + "KEY_BLIND_HIGH_COVERAGE_SEED_BASE": ".effectiveness_profile", + "KEY_BLIND_FULL_POOL_COVERAGE_PROFILE_ID": ".effectiveness_profile", + "KEY_BLIND_FULL_POOL_COVERAGE_SEED_BASE": ".effectiveness_profile", + "KEY_BLIND_COVERAGE_COMPLETION_PROFILE_ID": ".effectiveness_profile", + "KEY_BLIND_COVERAGE_COMPLETION_SEED_BASE": ".effectiveness_profile", + "CONTENT_REGION_COMBINED_PROFILE_ID": ".effectiveness_profile", + "CONTENT_REGION_COVERAGE_PROFILE_ID": ".effectiveness_profile", + "CONTENT_REGION_COVERAGE_SEED_BASE": ".effectiveness_profile", + "CONTENT_REGION_GENERAL_ONLY_PROFILE_ID": ".effectiveness_profile", + "content_region_combined_profile": ".effectiveness_profile", + "content_region_combined_transform_registry": ".effectiveness_profile", + "content_region_destruction_profile": ".effectiveness_profile", + "content_region_destruction_transform_registry": ".effectiveness_profile", + "zrd_contraction_extension_metadata": ".contractions", + "zrd_destruction_profile": ".effectiveness_profile", + "zrd_destruction_transform_registry": ".effectiveness_profile", + "quote_safe_zrd_transform_registry": ".effectiveness_profile", + "zrd_forward_contraction_extension_rules": ".contractions", + "zrd_reverse_contraction_extension_rules": ".contractions", + "content_region_general_only_profile": ".effectiveness_profile", + "content_region_general_only_transform_registry": ".effectiveness_profile", + "content_region_coverage_profile": ".effectiveness_profile", + "content_region_coverage_transform_registry": ".effectiveness_profile", + "key_blind_coverage_completion_profile": ".effectiveness_profile", + "key_blind_coverage_completion_transform_registry": ".effectiveness_profile", + "LEXICAL_RETOKENIZATION_FIXTURE_ALGORITHM_VERSION": ".lexical_tokenization", + "LEXICAL_RULE_AUDIT_ALGORITHM_VERSION": ".lexical_audit", + "LEXICAL_TEMPLATE_RULE_ALGORITHM_VERSION": ".lexical_rules", + "LexicalAuditStatus": ".lexical_audit", + "LexicalConstruction": ".lexical_rules", + "LexicalRetokenizationFixture": ".lexical_tokenization", + "LexicalRetokenizationVerificationError": ".lexical_tokenization", + "LexicalRuleAudit": ".lexical_audit", + "LexicalRulePromotionError": ".lexical_audit", + "LexicalTemplateRule": ".lexical_rules", + "LiteralTransformRule": ".rules", + "MINIMUM_EQUIVALENT_OR_MINOR_RATE": ".lexical_audit", + "MINIMUM_GRAMMAR_FIXTURES_PER_CLASS": ".lexical_audit", + "MINIMUM_HUMAN_AUDIT_SAMPLES": ".lexical_audit", + "MINIMUM_SYNTAX_EQUIVALENT_OR_MINOR_RATE": ".syntax_audit", + "MINIMUM_SYNTAX_GRAMMAR_FIXTURES_PER_CLASS": ".syntax_audit", + "MINIMUM_SYNTAX_HUMAN_AUDIT_SAMPLES": ".syntax_audit", + "PROTECTED_SPAN_ALGORITHM_VERSION": ".protected", + "ProtectedInvariantReport": ".protected_artifacts", + "ProtectedSpan": ".protected_artifacts", + "ProtectedSpanExtractor": ".protected", + "ProtectedSpanKind": ".schema", + "ProtectedSpanManifest": ".protected_artifacts", + "RULE_ALGORITHM_VERSION": ".rules", + "ScheduleGeometryMode": ".scheduler", + "SchedulePolicy": ".scheduler", + "ScheduleResult": ".scheduler", + "SchedulerCandidate": ".scheduler", + "SYNTAX_RETOKENIZATION_FIXTURE_ALGORITHM_VERSION": ".syntax_tokenization", + "SYNTAX_RULE_AUDIT_ALGORITHM_VERSION": ".syntax_audit", + "SYNTAX_TEMPLATE_RULE_ALGORITHM_VERSION": ".syntax_rules", + "SyntaxAuditStatus": ".syntax_audit", + "SyntaxConstruction": ".syntax_rules", + "SyntaxRetokenizationFixture": ".syntax_tokenization", + "SyntaxRetokenizationVerificationError": ".syntax_tokenization", + "SyntaxRuleAudit": ".syntax_audit", + "SyntaxTemplateRule": ".syntax_rules", + "TRANSFORM_APPLY_ALGORITHM_VERSION": ".registry", + "TRANSFORM_REGISTRY_ALGORITHM_VERSION": ".registry", + "TransformCandidate": ".candidate_artifacts", + "TransformFamily": ".schema", + "TransformOperation": ".trace", + "TransformRegistry": ".registry", + "TransformResult": ".trace", + "TransformRule": ".rules", + "TransformTier": ".schema", + "TransformationTrace": ".trace", + "UserProtectedRange": ".protected_artifacts", + "capture_lexical_retokenization_fixture": ".lexical_tokenization", + "capture_syntax_retokenization_fixture": ".syntax_tokenization", + "create_lexical_rule_audit": ".lexical_audit", + "create_syntax_rule_audit": ".syntax_audit", + "default_contraction_rules": ".rules", + "default_transform_registry": ".registry", + "development_lexical_rules": ".lexical_rules", + "development_syntax_rules": ".syntax_rules", + "development_transform_registry": ".registry", + "historical_visible_edit_transform_registry": ".registry", + "release_transform_registry": ".registry", + "require_complete_lexical_audit_summaries": ".lexical_audit", + "validate_effectiveness_profile_registry": ".effectiveness_profile", + "validate_protected_invariants": ".invariants", + "verify_lexical_retokenization_fixture": ".lexical_tokenization", + "verify_syntax_retokenization_fixture": ".syntax_tokenization", + "GeneralWordLeadingSpacingRule": ".rules", + "GeneralWordSpacingRule": ".rules", +} + +_NON_STAR_EXPORTS = frozenset(['GeneralWordLeadingSpacingRule', 'GeneralWordSpacingRule']) +__all__ = [name for name in _EXPORTS if name not in _NON_STAR_EXPORTS] + +for _export_name in _EXPORTS: + globals().pop(_export_name, None) +del _export_name + + +def __getattr__(name: str) -> object: + source = _EXPORTS.get(name) + if source is None: + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + value = getattr(_import_module(source, __name__), name) + globals()[name] = value + return value + + +def __dir__() -> list[str]: + return sorted(set(globals()) | set(_EXPORTS)) diff --git a/tests/test_lazy_public_api.py b/tests/test_lazy_public_api.py new file mode 100644 index 00000000..c31db534 --- /dev/null +++ b/tests/test_lazy_public_api.py @@ -0,0 +1,199 @@ +from __future__ import annotations + +import json +from pathlib import Path +import subprocess +import sys +import textwrap + +import pytest + + +ROOT = Path(__file__).resolve().parents[1] +CONTRACTS = { + "fuckmark": ( + "dd095eb14d8a0c73be8674f941739cc765271ae7ee0042fe4ce1faea5e0890ac", + "fc656f5b8d63a9fd381369eb826510cdba3bb6b1a765f102f0b11c2fa2849287", + ), + "fuckmark.product": ( + "21433495e5266e2b6f72053c2eaf8f13d7eed3728e656be0d6272b1133e6302a", + "83fe65314eeb827ee894350ea6cc2c0630a3631fca13b3643cd2a8a27509701b", + ), + "fuckmark.transforms": ( + "605ad75cee8e396a2665c0373c176246baabca27b44e5008a4a31aab6dcd896e", + "17c92d95d25c384c39a33a655dfa520511a68f98605e43cd98efc1bcd7392174", + ), +} + + +def run_cold(code: str) -> object: + result = subprocess.run( + [sys.executable, "-c", textwrap.dedent(code)], + cwd=ROOT, + capture_output=True, + text=True, + timeout=60, + check=False, + ) + assert result.returncode == 0, result.stdout + result.stderr + return json.loads(result.stdout) + + +@pytest.mark.parametrize("package", CONTRACTS) +def test_export_targets_and_wildcard_order_preserve_baseline(package: str) -> None: + result = run_cold(f""" + import hashlib, importlib, json + p = importlib.import_module({package!r}) + def digest(value): + data = json.dumps(value, sort_keys=True, separators=(',', ':')) + return hashlib.sha256(data.encode()).hexdigest() + print(json.dumps([digest(p._EXPORTS), digest(p.__all__)])) + """) + assert result == list(CONTRACTS[package]) + + +@pytest.mark.parametrize("package", CONTRACTS) +def test_namespace_import_does_not_load_implementations(package: str) -> None: + result = run_cold(f""" + import importlib, json, sys + importlib.import_module({package!r}) + print(json.dumps(sorted(n for n in sys.modules + if n == 'fuckmark' or n.startswith('fuckmark.')))) + """) + expected = ["fuckmark"] if package == "fuckmark" else ["fuckmark", package] + assert result == expected + + +@pytest.mark.parametrize("package", CONTRACTS) +def test_dir_exposes_api_without_loading_it(package: str) -> None: + assert run_cold(f""" + import importlib, json, sys + p = importlib.import_module({package!r}) + before = set(sys.modules) + names = dir(p) + assert set(p.__all__) <= set(names) + assert set(p._EXPORTS) <= set(names) + print(json.dumps(before == set(sys.modules))) + """) is True + + +@pytest.mark.parametrize("package", CONTRACTS) +def test_unknown_attribute_has_no_import_side_effect(package: str) -> None: + assert run_cold(f""" + import importlib, json, sys + p = importlib.import_module({package!r}) + before = set(sys.modules) + try: + getattr(p, 'this_symbol_does_not_exist') + except AttributeError as error: + assert p.__name__ in str(error) + else: + raise AssertionError('missing AttributeError') + assert not hasattr(p, 'this_symbol_does_not_exist') + print(json.dumps(before == set(sys.modules))) + """) is True + + +@pytest.mark.parametrize("package", CONTRACTS) +def test_successful_resolution_is_cached(package: str) -> None: + assert run_cold(f""" + import importlib, json, types + p = importlib.import_module({package!r}) + name = next(n for n, source in p._EXPORTS.items() if source is not None) + sentinel = object() + calls = [] + def load(source, parent): + calls.append((source, parent)) + return types.SimpleNamespace(**{{name: sentinel}}) + p._import_module = load + assert getattr(p, name) is sentinel + assert getattr(p, name) is sentinel + assert p.__dict__[name] is sentinel + print(json.dumps(calls == [(p._EXPORTS[name], p.__name__)])) + """) is True + + +@pytest.mark.parametrize("package", CONTRACTS) +def test_failed_import_is_not_hidden_or_cached(package: str) -> None: + assert run_cold(f""" + import importlib, json + p = importlib.import_module({package!r}) + name = next(n for n, source in p._EXPORTS.items() if source is not None) + def fail(source, parent): + raise ImportError('deliberate test failure') + p._import_module = fail + for _ in range(2): + try: + getattr(p, name) + except ImportError as error: + assert str(error) == 'deliberate test failure' + else: + raise AssertionError('import failure was swallowed') + print(json.dumps(name not in p.__dict__)) + """) is True + + +@pytest.mark.parametrize("package", CONTRACTS) +def test_reload_clears_previously_cached_exports(package: str) -> None: + assert run_cold(f""" + import importlib, json + p = importlib.import_module({package!r}) + name = next(n for n, source in p._EXPORTS.items() if source is not None) + p.__dict__[name] = object() + public = list(p.__all__) + importlib.reload(p) + assert p.__all__ == public + assert name not in p.__dict__ + if p.__name__ == 'fuckmark': + assert p.__version__ == '0.4.1' + assert p.__project_name__ == 'FuckMark' + print('true') + """) is True + + +@pytest.mark.parametrize("leaf", ["fuckmark.product.domain", "fuckmark.transforms.schema"]) +def test_leaf_import_does_not_pull_research_packages(leaf: str) -> None: + result = run_cold(f""" + import importlib, json, sys + importlib.import_module({leaf!r}) + forbidden = ('fuckmark.adapters', 'fuckmark.corpus', 'fuckmark.detectors', + 'fuckmark.experiments', 'fuckmark.transforms.scheduler', + 'fuckmark.transforms.effectiveness_profile', + 'fuckmark.transforms.fidelity_readiness') + loaded = sorted(n for n in sys.modules + if any(n == prefix or n.startswith(prefix + '.') + for prefix in forbidden)) + print(json.dumps(loaded)) + """) + assert result == [] + + +@pytest.mark.parametrize("package", CONTRACTS) +def test_real_exports_resolve_to_original_objects(package: str) -> None: + assert run_cold(f""" + import importlib, json + p = importlib.import_module({package!r}) + for name, source in p._EXPORTS.items(): + if source is None: + assert name in p.__dict__ + continue + actual = getattr(p, name) + original = getattr(importlib.import_module(source, p.__name__), name) + assert actual is original, name + assert getattr(p, name) is actual, name + print('true') + """) is True + + +@pytest.mark.parametrize("package", CONTRACTS) +def test_star_import_preserves_public_objects(package: str) -> None: + assert run_cold(f""" + import importlib, json + p = importlib.import_module({package!r}) + namespace = {{}} + exec('from ' + p.__name__ + ' import *', namespace) + assert set(namespace) - {{'__builtins__'}} == set(p.__all__) + for name in p.__all__: + assert namespace[name] is getattr(p, name), name + print('true') + """) is True