Spaces:
Sleeping
Sleeping
Download src/tests/runtime/test_pdf_contract.py from dellweb3/VibeCoding: direct link, hf CLI and curl.
- Browser
- Download file 2.77 kB
-
https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/src/tests/runtime/test_pdf_contract.py
- Command line
-
hf download hf://spaces/dellweb3/VibeCoding/src/tests/runtime/test_pdf_contract.py
-
curl -L -o test_pdf_contract.py https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/src/tests/runtime/test_pdf_contract.py
2.77 kB
| import unittest | |
| from unittest.mock import patch | |
| from pydantic import ValidationError | |
| from src.modules.execution.pdf_dependency import FRAMEWORK, PROFILE, SHA512, overlay | |
| from src.modules.execution.scenarios.pdf import scenario, framework_candidate, sample_pdf, MAX_PDF_BYTES | |
| from src.modules.harness.policy import Harness | |
| from src.modules.skill.domain.models import SkillError | |
| from src.adapters.sandbox.preview import PreviewSession | |
| class PDFContractTests(unittest.TestCase): | |
| def config(self): return scenario('zkcoding-qemu@sha256:'+'a'*64) | |
| def test_only_exact_pdf_profile_allows_pinned_dependency(self): | |
| framework=framework_candidate().model_copy(update={'state':'approved'}).model_dump() | |
| Harness(enabled=True).framework(framework) | |
| for updates in ({'profile_id':'java17-standard-web'}, {'version':'0.2.0'}, {'dependencies':{}}, | |
| {'dependencies':{'org.apache.pdfbox:pdfbox-app':'3.0.7'}}): | |
| with self.assertRaises(SkillError): Harness(enabled=True).framework({**framework,**updates}) | |
| def test_profile_and_hash_are_bound_and_overlay_is_read_only(self): | |
| config=self.config() | |
| with patch('src.modules.execution.pdf_dependency.dependency_bytes',return_value=b'fixture'): | |
| entries=overlay(config) | |
| self.assertEqual(entries[-1][0],'approved/pdfbox-app-3.0.8.jar') | |
| self.assertEqual(entries[-1][2]&0o777,0o444) | |
| for updates in ({'dependency_sha512':'0'*128}, {'dependency_profile':'jdk'}): | |
| with self.assertRaises(ValidationError): type(config)(**{**config.model_dump(),**updates}) | |
| def test_suite_covers_text_scan_encryption_malformed_limits(self): | |
| config=self.config() | |
| codes={c.expected_json.get('error') for c in config.tests} | |
| self.assertTrue({'ENCRYPTED_PDF','INVALID_PDF','INVALID_INPUT','PAGE_LIMIT','TEXT_LIMIT','PDF_TOO_LARGE'}<=codes) | |
| self.assertIn('NO_TEXT',{c.expected_json.get('status') for c in config.tests}) | |
| self.assertLess(len(sample_pdf()),MAX_PDF_BYTES) | |
| def test_body_is_rejected_before_transport_outside_pdf_endpoint(self): | |
| from types import SimpleNamespace | |
| config=self.config() | |
| preview=PreviewSession(SimpleNamespace(config=config),{'files':{},'source_digest':'a'*64}) | |
| for method,path in [('GET','/api/pdf/analyze'),('POST','/other')]: | |
| with self.assertRaises(SkillError) as raised: preview.request(method,path,'',{'base64':'AA=='}) | |
| self.assertEqual(raised.exception.code,'PREVIEW_BODY_NOT_ALLOWED') | |
| with self.assertRaises(SkillError) as raised: preview.request('POST','/api/pdf/analyze','',{'base64':'A'*180000}) | |
| self.assertEqual(raised.exception.status,413) | |
| if __name__=='__main__': unittest.main() | |