diff --git a/API_REFERENCE.md b/API_REFERENCE.md index 8b803fc..431ec7b 100644 --- a/API_REFERENCE.md +++ b/API_REFERENCE.md @@ -23,7 +23,7 @@ Complete API documentation for the vCon library - a Python implementation of the | --- | --- | | `add_tag()` wrote `party: 0` even with no parties | `add_tag(name, value, party=None)`; `party` defaults to 0. On a vCon with no parties it still writes party 0 but emits a `DeprecationWarning` (it will raise in 1.1); a `party` index out of range raises `ValueError` | | `add_wtf_transcription_attachment()` | deprecated (`DeprecationWarning`); use `add_wtf_transcription_analysis()`, which writes the analysis entry the WTF draft requires | -| `is_valid()` core structure only | also reports a malformed `content_hash` and errors in the body of every `lawful_basis` attachment; `get_validation_warnings()` adds a `url` without `content_hash` (an error from 1.1), JSON-string bodies under `encoding: "json"`, and lawful-basis warnings | +| `is_valid()` core structure only | also reports a malformed `content_hash` and errors in the body of every `lawful_basis` attachment; `get_validation_warnings()` adds JSON-string bodies under `encoding: "json"`, and lawful-basis warnings | | loading rewrote `created_at` (and crashed on an unparseable one) | `created_at` is kept exactly as written; `is_valid()` reports an unparseable value | | `Dialog.add_inline_data(body: str, ...)` | also accepts `bytes` (encoded to base64url); `content_hash` is over the decoded content | | `generate_thumbnail()` defined twice (the image one won) | dispatches to `generate_image_thumbnail()` or `generate_video_thumbnail()`; video helpers need `pip install "vcon[video]"` and the ffmpeg binary | @@ -416,7 +416,7 @@ is_valid, errors = vcon.is_valid() ``` ###### `get_validation_warnings() -> List[str]` -Findings that do not make the vCon invalid, for example a `url` without a `content_hash` on a dialog, attachment or analysis entry (a MUST in core-05, reported as a warning in 1.0.x and an `is_valid()` error from vcon 1.1), an `encoding: "json"` body that is a serialized JSON string, and lawful-basis warnings (an unknown proof type, hash algorithm or canonicalization method is a warning, since the draft's lists are open). +Findings that do not make the vCon invalid, for example an `encoding: "json"` body that is a serialized JSON string, and lawful-basis warnings (an unknown proof type, hash algorithm or canonicalization method is a warning, since the draft's lists are open). A `url` without a `content_hash` is allowed on a dialog, attachment or analysis entry (from 1.0.6; earlier 1.0.x releases warned), because a producer cannot always get stable bytes for it, such as a YouTube page or audio behind a login. `redacted_from` and `amended_from` still need a `content_hash` with a `url`. ```python warnings = vcon.get_validation_warnings() diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b766db..b554e0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [1.0.6] - 2026-11-20 + +### Changed +- A `url` without a `content_hash` is allowed on a Dialog, Attachment or + Analysis. A producer cannot always obtain stable bytes for the URL (a + streaming-service page such as YouTube, audio behind a login), so a hash + cannot be computed. This follows the working group's direction on + draft-ietf-vcon-vcon-core issue #40; core-05 itself still says MUST. 1.0.4 + and 1.0.5 reported it as a warning and said it would become an error in + 1.1; that plan is dropped. An Attachment needs `body`+`encoding` or `url` + (it used to need `url`+`content_hash`). +- Unchanged: a malformed `content_hash` is still an `is_valid()` error, and + `redacted_from` and `amended_from` still need a `content_hash` with a `url`. + ## [1.0.5] - 2026-11-18 ### Fixed diff --git a/GUIDE.md b/GUIDE.md index 688f405..5e7b8b9 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -756,7 +756,7 @@ is_valid, errors = Vcon.validate_file("conversation.json") is_valid, errors = Vcon.validate_json(json_string) ``` -Besides the structure rules, `is_valid()` reports a malformed `content_hash` (it must be `-`: 86 characters for sha512, 43 for sha256), an unparseable `created_at`, and problems in the body of every `lawful_basis` attachment (missing `lawful_basis`, `expiration`, `purpose_grants` and so on). `vcon.get_validation_warnings()` returns findings that do not make the vCon invalid: a `url` without a `content_hash` on a dialog, attachment or analysis entry (a warning in 1.0.x, an `is_valid()` error from vcon 1.1), an `encoding: "json"` body that is a serialized JSON string, and lawful-basis warnings (an unknown proof type, hash algorithm or canonicalization method is a warning, not an error). Loading a vCon keeps `created_at` exactly as written. +Besides the structure rules, `is_valid()` reports a malformed `content_hash` (it must be `-`: 86 characters for sha512, 43 for sha256), an unparseable `created_at`, and problems in the body of every `lawful_basis` attachment (missing `lawful_basis`, `expiration`, `purpose_grants` and so on). `vcon.get_validation_warnings()` returns findings that do not make the vCon invalid: an `encoding: "json"` body that is a serialized JSON string, and lawful-basis warnings (an unknown proof type, hash algorithm or canonicalization method is a warning, not an error). Loading a vCon keeps `created_at` exactly as written. A `url` without a `content_hash` is allowed on a dialog, attachment or analysis entry (from 1.0.6; earlier 1.0.x releases warned), because a producer cannot always get stable bytes for it, such as a YouTube page or audio behind a login. `redacted_from` and `amended_from` still need a `content_hash` with a `url`. ### UUID Generation ```python diff --git a/LLM_GUIDE.md b/LLM_GUIDE.md index a3b429c..10cb660 100644 --- a/LLM_GUIDE.md +++ b/LLM_GUIDE.md @@ -849,7 +849,7 @@ is_valid, errors = Vcon.validate_json(json_string) - an unparseable `created_at` (loading keeps `created_at` exactly as written and no longer reformats or rejects it) - errors in the body of every `lawful_basis` attachment (missing `lawful_basis`, `expiration`, `purpose_grants` and so on) -`get_validation_warnings()` adds a `url` without a `content_hash` on a dialog, attachment or analysis entry (a MUST in core-05: a warning in 1.0.x, an `is_valid()` error from vcon 1.1, so always set `content_hash` with a `url`), an `encoding: "json"` body that is a serialized JSON string (pass the JSON value itself), and lawful-basis warnings; an unknown proof type, hash algorithm or canonicalization method is a warning, not an error. +Set `content_hash` with a `url` whenever you have the bytes (`compute_content_hash()`); it may be left out when you cannot get stable bytes, such as a YouTube page or audio behind a login, but `redacted_from` and `amended_from` always need it. `get_validation_warnings()` adds an `encoding: "json"` body that is a serialized JSON string (pass the JSON value itself), and lawful-basis warnings; an unknown proof type, hash algorithm or canonicalization method is a warning, not an error. ## Common Patterns and Best Practices diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index b2d70b3..a7c3d4d 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -9,7 +9,7 @@ | `add_wtf_transcription_attachment()` | deprecated (`DeprecationWarning`): the WTF draft stores a transcription as analysis. Use `add_wtf_transcription_analysis(transcript, segments, metadata, dialog_index=None, session_index=None, **kwargs)`; read it back with `vcon.find_analysis_by_type("wtf_transcription")` instead of `find_wtf_attachments()` | | `add_tag()` on a vCon with no parties wrote `party: 0` silently | still writes party 0, but emits a `DeprecationWarning` (the vCon fails `is_valid()`); it will raise `ValueError` in 1.1. Add a party before the first tag. New `party=` argument (default 0); an index out of range raises `ValueError` | | `is_valid()` did not check `content_hash` or lawful-basis bodies | errors for a malformed `content_hash` (`-`, 86 characters for sha512, 43 for sha256) and for problems in a `lawful_basis` attachment body. Unknown lawful-basis proof types, hash algorithms and canonicalization methods are warnings | -| no check for `url` without `content_hash` | reported by `get_validation_warnings()`; an `is_valid()` error from 1.1 | +| no check for `url` without `content_hash` | 1.0.4 and 1.0.5 warned; from 1.0.6 it is allowed on Dialog, Attachment and Analysis (still required on `redacted_from` and `amended_from`) | | (no check) | `get_validation_warnings()` reports an `encoding: "json"` body that is a serialized JSON string | | loading rewrote `created_at` into Python's ISO format (and an unparseable value crashed `Vcon()`) | `created_at` is kept exactly as written; `is_valid()` reports an unparseable value | | `Dialog.add_inline_data()` took a str and hashed the base64url text | also takes `bytes` (encoded for you); `content_hash` is over the decoded content | diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 60ea14e..bae3c8d 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -187,8 +187,9 @@ Reading and validating Besides the structure and references, ``is_valid()`` checks that every ``content_hash`` has the form ``-`` and the body of every ``lawful_basis`` attachment. A ``url`` without a -``content_hash`` is reported by ``get_validation_warnings()`` in 1.0.x and -will be an error from 1.1. Loading keeps every value as written, including +``content_hash`` is allowed on a Dialog, Attachment or Analysis, because a +producer cannot always get stable bytes for it (a YouTube page, audio behind a +login); ``redacted_from`` and ``amended_from`` still need one. Loading keeps every value as written, including timestamps, so an invalid ``created_at`` is reported by ``is_valid()`` rather than raised. diff --git a/pyproject.toml b/pyproject.toml index b883c34..462c415 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "vcon" -version = "1.0.5" +version = "1.0.6" description = "The vCon library - vCon 0.5.0 (draft-ietf-vcon-vcon-core-05) specification implementation" authors = ["Thomas McCarthy-Howe "] license = "MIT" diff --git a/setup.py b/setup.py index 899008a..4721929 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="vcon", - version="1.0.5", + version="1.0.6", author="Thomas McCarthy-Howe", author_email="ghostofbasho@gmail.com", description="The vCon library - vCon 0.5.0 (draft-ietf-vcon-vcon-core-05) specification implementation", diff --git a/src/vcon/validation.py b/src/vcon/validation.py index 0f9410e..2269e7d 100644 --- a/src/vcon/validation.py +++ b/src/vcon/validation.py @@ -90,17 +90,16 @@ def content_hash_problems(value: Any) -> List[str]: return problems -def _check_content(obj: Dict[str, Any], label: str, errors: List[str], warnings: List[str], - check_url: bool = True) -> None: +def _check_content(obj: Dict[str, Any], label: str, errors: List[str], warnings: List[str]) -> None: """Integrity and body-form checks shared by Dialog, Attachment, Analysis and the - redacted_from / amended_from references (section 2.4).""" - if check_url and "url" in obj and "content_hash" not in obj: - # A MUST in section 2.4. Reported as a warning in 1.0.x so producers - # that only hold a carrier URL keep validating; an error from 1.1. - warnings.append( - f"{label} has a url but no content_hash (an external reference MUST have both; " - "this will be an error in vcon 1.1)." - ) + redacted_from / amended_from references (section 2.4). + + A ``url`` without a ``content_hash`` is allowed on Dialog, Attachment and + Analysis: a producer cannot always obtain stable bytes for the URL (a + streaming-service page, audio behind a login). This follows the working + group's direction on draft-ietf-vcon-vcon-core issue #40; core-05 still + says MUST. ``redacted_from`` and ``amended_from`` keep the requirement. + """ if "content_hash" in obj: for problem in content_hash_problems(obj["content_hash"]): errors.append(f"{label} has an invalid content_hash: {problem}.") @@ -362,7 +361,7 @@ def validate_vcon_dict( errors.append("redacted_from is missing required field: type") if "url" in rf and "content_hash" not in rf: errors.append("redacted_from with url must include content_hash.") - _check_content(rf, "redacted_from", errors, warnings, check_url=False) + _check_content(rf, "redacted_from", errors, warnings) af = vcon.get("amended_from") if "amended_from" in vcon: if not isinstance(af, dict): @@ -372,7 +371,7 @@ def validate_vcon_dict( errors.append("amended_from must include uuid, or an external reference (url).") if "url" in af and "content_hash" not in af: errors.append("amended_from with url must include content_hash.") - _check_content(af, "amended_from", errors, warnings, check_url=False) + _check_content(af, "amended_from", errors, warnings) # --- extensions / critical ------------------------------------------- ext_listed = vcon.get("extensions", []) @@ -551,11 +550,10 @@ def validate_vcon_dict( if "purpose" not in attachment: errors.append(f"Attachment at index {i} is missing required field: purpose") has_inline = "body" in attachment and "encoding" in attachment - has_external = "url" in attachment and "content_hash" in attachment + has_external = "url" in attachment if not (has_inline or has_external or redacted): - errors.append(f"Attachment at index {i} must include body+encoding or url+content_hash.") - _check_content(attachment, f"Attachment at index {i}", errors, warnings, - check_url=has_inline or redacted) + errors.append(f"Attachment at index {i} must include body+encoding or url.") + _check_content(attachment, f"Attachment at index {i}", errors, warnings) if "encoding" in attachment and attachment["encoding"] not in CORE_ENCODINGS and not ext_listed: errors.append(f"Attachment at index {i} has invalid encoding: {attachment['encoding']}") if "body" in attachment and attachment["body"] != "" and "mediatype" not in attachment: diff --git a/tests/test_fixes_1_0_4.py b/tests/test_fixes_1_0_4.py index 9986d6c..a6e73ab 100644 --- a/tests/test_fixes_1_0_4.py +++ b/tests/test_fixes_1_0_4.py @@ -28,11 +28,21 @@ def _recording(**kw): class TestContentHash: - def test_url_needs_content_hash(self): + def test_url_without_content_hash_is_allowed(self): + # 1.0.6: allowed on Dialog, Attachment and Analysis (WG direction on + # draft-ietf-vcon-vcon-core issue #40, e.g. a YouTube recording link). v = _base() - v.add_dialog(_recording(url="https://example.com/a.wav"), session=0) - assert v.is_valid() == (True, []) # a warning in 1.0.x, an error from 1.1 - assert any("has a url but no content_hash" in w for w in v.get_validation_warnings()) + v.add_dialog(_recording(url="https://www.youtube.com/watch?v=x"), session=0) + v.add_attachment("doc", url="https://example.com/d.pdf", party=0, session=0) + v.add_analysis(type="summary", vendor="v", url="https://example.com/s.json", + sessions=0, body=None) + assert v.is_valid() == (True, []) + assert not any("content_hash" in w for w in v.get_validation_warnings()) + + def test_redacted_and_amended_from_still_need_content_hash(self): + v = _base() + v.vcon_dict["amended_from"] = {"url": "https://example.com/v.json"} + assert "amended_from with url must include content_hash." in v.is_valid()[1] def test_well_formed_hash_passes(self): v = _base() @@ -52,7 +62,7 @@ def test_hash_array_and_unknown_algorithm(self): def test_attachment_and_analysis_are_checked(self): v = _base() - v.add_attachment("doc", url="https://example.com/d.pdf", party=0, session=0) + v.vcon_dict["attachments"].append({"purpose": "doc", "start": T, "party": 0, "session": 0}) v.add_analysis(type="summary", vendor="v", url="https://example.com/s.json", content_hash="sha512-x", sessions=0, body=None) errors = v.is_valid()[1]