From b47f272873d4502fd25afc1550dfb903c05fcfc0 Mon Sep 17 00:00:00 2001 From: Gavin Ying Date: Mon, 16 Nov 2026 10:00:58 +0800 Subject: [PATCH 1/3] test(modpoll-wot): publish rejection vectors for other implementations (WOT-06) --- packages/modpoll-wot/.coverage | Bin 53248 -> 53248 bytes packages/modpoll-wot/profile.md | 10 ++ .../fixtures/conformance.rejections.json | 65 +++++++++++ packages/modpoll-wot/tests/test_rejections.py | 110 ++++++++++++++++++ 4 files changed, 185 insertions(+) create mode 100644 packages/modpoll-wot/tests/fixtures/conformance.rejections.json create mode 100644 packages/modpoll-wot/tests/test_rejections.py diff --git a/packages/modpoll-wot/.coverage b/packages/modpoll-wot/.coverage index e42c6b5657df9702697e0aa24ecd9fd7fe65998d..d4b8d769a2e5948d9b06baa009def17d23d5fe6d 100644 GIT binary patch delta 711 zcmZozz}&EadBb0QM)S@8^f?41+!***@dxt#;akGz&-;^iF|Q}jN1i!6Zkq)KG^ zylfF1Kp|7OP?j%0TL?R{!IMw|zDV!0ggt3u6It5jNcQ z<7EqGMpB_P+1j6rEu0A`WDK`-nm->~2qRDk?wiS9{RJi58TeQ8xbp|`F5&&f_m?k# zXD-htzNNfgK<{hvu!OPzl~0UQ0eM~k$@APHEI{`_CHN73=L%;5It(g4nJ1QyC6Wc` zahO0>tN@CUlTXE>*@5I~HiR8pFQ_1KhJpVp|5g6o{A>8<@ptfB@JsMB@V)0d1N7}WK4nF27Di4Nj$fs_8!FHF z|9@ZqlJnVe&NIq06#n~tc>n+Z@B56CKlIr!zMrhyFKzu__UYaA-^=U2TkpMi```Zk zEMLC;|1W>w`@ZXc>*Rk_e|=ZI_y7NY>%ZOp`@inrp7`ze>)-!-y8ZX&*Z=z`H}`8W z{+_(1U(sa$=ISHY=Kue{LXHV&xgGZ}rg~}Yi;FY!^YjWTV>p5GwrKK`ZG3sz z;y8dZj%YHXWvNA(X_?81B@pdV?3k7+O@8MKbPgL98Nt-Nl!E-syb_?zk*q)k=q{T) z%a4mKh6N~t;imU~ylj!oSo8?wvZ5Fh&I)rZIXfQ7k}rBa8Vc z@gqW%E0zW5cvR`hHnDsx@hrgLL=&G9D}ZT*4=@B{d9aBKAcY?r7H3SJ701nj&Hnds zd{~{02s-9C7GTJsId4upKP%80OHR}vRoVPKo?k)YG6Vlt{%ibu_}B8!=kMgV-0-o z|C4<>cYS#|*G22S7p4F0-_P>p+yDRa4j=bj|C=ZOqx$Qs;=TX>SFQhc`|tm{e|zG$ z->-lF@9Fm6n_vGwKe?%2gYov{)%}XbdnZ>Pxi|m{UCi3)i9v4ge^wEm!~m diff --git a/packages/modpoll-wot/profile.md b/packages/modpoll-wot/profile.md index b1f81b0..60bf65a 100644 --- a/packages/modpoll-wot/profile.md +++ b/packages/modpoll-wot/profile.md @@ -215,6 +215,16 @@ requires a new prefix. `conformance.tm.json`, which covers every byte and word order and each Form extension; with `conformance.data.json` it is also what the workspace integration tests serve with modsim and read with modpoll. +### Rejection vectors + +An implementation that accepts or stores Thing Models without this package, such as a web service, must refuse what +this loader refuses. [tests/fixtures/conformance.rejections.json](https://github.com/top-maker/modpoll/blob/v2/packages/modpoll-wot/tests/fixtures/conformance.rejections.json) +lists documents that must be refused: each vector is a JSON Patch (RFC 6902, `add`, `replace` and `remove` only) +applied to `conformance.tm.json`, with the name of the rule that refuses the result. The unchanged model must be +accepted. The rule names group the vectors for readers and are not an error code contract; `schema` marks a vector +that one of the bundled JSON Schemas already refuses. Two differences cannot be expressed as vectors, because they +disappear when JSON is parsed outside Python: duplicate object keys, and an integer written as a float such as `1.0`. + ## Verification reports A verification report records one reading of a Thing Model on a physical device. Its schema is diff --git a/packages/modpoll-wot/tests/fixtures/conformance.rejections.json b/packages/modpoll-wot/tests/fixtures/conformance.rejections.json new file mode 100644 index 0000000..b56b0a6 --- /dev/null +++ b/packages/modpoll-wot/tests/fixtures/conformance.rejections.json @@ -0,0 +1,65 @@ +{ + "model": "conformance.tm.json", + "vectors": [ + {"rule": "profile-version", "patch": [{"op": "replace", "path": "/modpoll:version", "value": "0.1"}]}, + {"rule": "document-kind", "patch": [{"op": "remove", "path": "/@type"}]}, + {"rule": "placeholder-unbound", "patch": [{"op": "replace", "path": "/description", "value": "Site {{SITE}}"}]}, + {"rule": "placeholder-malformed", "patch": [{"op": "replace", "path": "/description", "value": "Site {{SITE"}]}, + {"rule": "title-blank", "patch": [{"op": "replace", "path": "/title", "value": " "}]}, + {"rule": "security-scheme", "patch": [{"op": "add", "path": "/securityDefinitions", "value": {"basic_sc": {"scheme": "basic", "in": "header"}}}, {"op": "add", "path": "/security", "value": "basic_sc"}]}, + {"rule": "root-feature", "patch": [{"op": "add", "path": "/actions", "value": {"reset": {}}}]}, + {"rule": "root-feature", "patch": [{"op": "add", "path": "/events", "value": {"alarm": {}}}]}, + {"rule": "root-feature", "patch": [{"op": "add", "path": "/links", "value": [{"href": "https://example.com/manual", "rel": "related"}]}]}, + {"rule": "root-feature", "patch": [{"op": "add", "path": "/base", "value": "modbus+tcp://device.example/"}]}, + {"rule": "root-modbus-field", "patch": [{"op": "add", "path": "/modv:unitID", "value": 1}]}, + {"rule": "root-project-extension", "patch": [{"op": "add", "path": "/modpoll:audit", "value": {}}]}, + {"rule": "vocabulary-alias", "patch": [{"op": "replace", "path": "/@context/1/modv", "value": "https://example.com/modbus"}]}, + {"rule": "property-protocol-metadata", "patch": [{"op": "add", "path": "/properties/u32_be/modv:address", "value": 0}]}, + {"rule": "schema", "patch": [{"op": "add", "path": "/properties/u32_be/forms/0/modpoll:scale", "value": 1}]}, + {"rule": "href-invalid", "patch": [{"op": "add", "path": "/properties/u32_be/forms/0/href", "value": "http://device.example/1/0?quantity=2"}]}, + {"rule": "href-disagrees", "patch": [{"op": "add", "path": "/properties/u32_be/forms/0/href", "value": "modbus+tcp://device.example:502/1/5?quantity=2"}]}, + {"rule": "unit-id-inconsistent", "patch": [{"op": "add", "path": "/properties/u32_be/forms/0/modv:unitID", "value": 1}, {"op": "add", "path": "/properties/u32_word_swap/forms/0/modv:unitID", "value": 2}]}, + {"rule": "span", "patch": [{"op": "replace", "path": "/properties/u32_be/forms/0/modv:address", "value": 65535}]}, + {"rule": "span", "patch": [{"op": "replace", "path": "/properties/label/forms/0/modv:quantity", "value": 126}, {"op": "replace", "path": "/properties/label/forms/0/modpoll:byteLength", "value": 252}]}, + {"rule": "codec", "patch": [{"op": "replace", "path": "/properties/half/forms/0/modv:type", "value": "xsd:unsignedShort"}]}, + {"rule": "schema", "patch": [{"op": "replace", "path": "/properties/half/forms/0/modpoll:codec", "value": "uint16"}]}, + {"rule": "bit-raw-type", "patch": [{"op": "replace", "path": "/properties/flag_bit3/forms/0/modv:type", "value": "xsd:short"}]}, + {"rule": "boolean-property", "patch": [{"op": "replace", "path": "/properties/flag_bit3/forms/0/modv:type", "value": "xsd:boolean"}, {"op": "remove", "path": "/properties/flag_bit3/forms/0/modpoll:bit"}, {"op": "replace", "path": "/properties/flag_bit3/type", "value": "integer"}]}, + {"rule": "boolean-scalar-quantity", "patch": [{"op": "replace", "path": "/properties/packed_coils/type", "value": "boolean"}, {"op": "replace", "path": "/properties/packed_coils/forms/0/modv:type", "value": "xsd:boolean"}, {"op": "remove", "path": "/properties/packed_coils/forms/0/modpoll:bitPacking"}]}, + {"rule": "boolean-multiplier", "patch": [{"op": "replace", "path": "/properties/packed_coils/type", "value": "array"}, {"op": "add", "path": "/properties/packed_coils/items", "value": {"type": "boolean"}}, {"op": "replace", "path": "/properties/packed_coils/forms/0/modv:type", "value": "xsd:boolean"}, {"op": "remove", "path": "/properties/packed_coils/forms/0/modpoll:bitPacking"}, {"op": "add", "path": "/properties/packed_coils/forms/0/modpoll:multiplier", "value": 2}]}, + {"rule": "raw-type-missing", "patch": [{"op": "replace", "path": "/properties/half/forms/0/modv:type", "value": "xsd:hexBinary"}, {"op": "remove", "path": "/properties/half/forms/0/modpoll:codec"}]}, + {"rule": "schema", "patch": [{"op": "replace", "path": "/properties/label/forms/0/modpoll:byteLength", "value": 0}]}, + {"rule": "byte-length-not-string", "patch": [{"op": "add", "path": "/properties/u32_be/forms/0/modpoll:byteLength", "value": 4}]}, + {"rule": "bit-packing-missing", "patch": [{"op": "remove", "path": "/properties/packed_coils/forms/0/modpoll:bitPacking"}]}, + {"rule": "bit-packing-misplaced", "patch": [{"op": "add", "path": "/properties/u32_be/forms/0/modpoll:bitPacking", "value": "legacy-msb"}]}, + {"rule": "quantity-width", "patch": [{"op": "replace", "path": "/properties/u32_be/forms/0/modv:quantity", "value": 1}]}, + {"rule": "quantity-width", "patch": [{"op": "replace", "path": "/properties/label/forms/0/modpoll:byteLength", "value": 8}]}, + {"rule": "media-type", "patch": [{"op": "replace", "path": "/properties/u32_be/forms/0/contentType", "value": "application/octet-stream;length=2"}]}, + {"rule": "media-type", "patch": [{"op": "replace", "path": "/properties/u32_word_swap/forms/0/contentType", "value": "application/octet-stream;byteSeq=BIG_ENDIAN"}]}, + {"rule": "media-type", "patch": [{"op": "replace", "path": "/properties/i16_scaled/forms/0/contentType", "value": "application/octet-stream;length=2"}]}, + {"rule": "operation", "patch": [{"op": "replace", "path": "/properties/u32_be/forms/0/op", "value": ["writeproperty"]}]}, + {"rule": "operation", "patch": [{"op": "add", "path": "/properties/u32_be/writeOnly", "value": true}]}, + {"rule": "operation", "patch": [{"op": "add", "path": "/properties/u32_be/forms/1", "value": {"op": ["readproperty"], "contentType": "application/octet-stream", "modv:entity": "HoldingRegister", "modv:address": 0, "modv:quantity": 2, "modv:type": "xsd:unsignedInt"}}]}, + {"rule": "forms-disagree", "patch": [{"op": "remove", "path": "/properties/u32_be/readOnly"}, {"op": "add", "path": "/properties/u32_be/forms/1", "value": {"op": ["writeproperty"], "contentType": "application/octet-stream", "modv:entity": "HoldingRegister", "modv:address": 2, "modv:quantity": 2, "modv:type": "xsd:unsignedInt"}}]}, + {"rule": "forms-cover-access", "patch": [{"op": "remove", "path": "/properties/u32_be/readOnly"}]}, + {"rule": "read-only-table", "patch": [{"op": "replace", "path": "/properties/packed_coils/forms/0/modv:entity", "value": "DiscreteInput"}, {"op": "remove", "path": "/properties/packed_coils/readOnly"}, {"op": "replace", "path": "/properties/packed_coils/forms/0/op", "value": ["readproperty", "writeproperty"]}]}, + {"rule": "schema", "patch": [{"op": "replace", "path": "/properties/i16_scaled/forms/0/modpoll:multiplier", "value": "NaN"}]}, + {"rule": "multiplier", "patch": [{"op": "replace", "path": "/properties/i16_scaled/forms/0/modpoll:multiplier", "value": "1e9999"}]}, + {"rule": "schema", "patch": [{"op": "replace", "path": "/properties/i16_scaled/forms/0/modpoll:multiplier", "value": true}]}, + {"rule": "multiplier", "patch": [{"op": "add", "path": "/properties/label/forms/0/modpoll:multiplier", "value": "2"}]}, + {"rule": "multiplier", "patch": [{"op": "add", "path": "/properties/flag_bit3/forms/0/modpoll:multiplier", "value": "2"}]}, + {"rule": "property-type", "patch": [{"op": "replace", "path": "/properties/i16_scaled/type", "value": "integer"}]}, + {"rule": "property-type", "patch": [{"op": "replace", "path": "/properties/label/type", "value": "integer"}]}, + {"rule": "property-type", "patch": [{"op": "replace", "path": "/properties/flag_bit3/type", "value": "integer"}]}, + {"rule": "property-type", "patch": [{"op": "replace", "path": "/properties/half/type", "value": "integer"}]}, + {"rule": "property-type", "patch": [{"op": "replace", "path": "/properties/u32_be/type", "value": "string"}]}, + {"rule": "group-span", "patch": [{"op": "replace", "path": "/modpoll:acquisition/0/modv:quantity", "value": 126}]}, + {"rule": "group-span", "patch": [{"op": "replace", "path": "/modpoll:acquisition/0/modv:address", "value": 65530}]}, + {"rule": "group-member", "patch": [{"op": "replace", "path": "/modpoll:acquisition/0/modpoll:members/0", "value": "missing"}]}, + {"rule": "group-member", "patch": [{"op": "add", "path": "/modpoll:acquisition/1/modpoll:members/1", "value": "u32_be"}]}, + {"rule": "group-member-span", "patch": [{"op": "replace", "path": "/modpoll:acquisition/0/modv:address", "value": 1}]}, + {"rule": "group-member-span", "patch": [{"op": "replace", "path": "/modpoll:acquisition/0/modv:quantity", "value": 15}]}, + {"rule": "group-member-span", "patch": [{"op": "replace", "path": "/modpoll:acquisition/1/modv:entity", "value": "DiscreteInput"}]}, + {"rule": "property-ungrouped", "patch": [{"op": "remove", "path": "/modpoll:acquisition/0/modpoll:members/0"}]} + ] +} diff --git a/packages/modpoll-wot/tests/test_rejections.py b/packages/modpoll-wot/tests/test_rejections.py new file mode 100644 index 0000000..d176c8b --- /dev/null +++ b/packages/modpoll-wot/tests/test_rejections.py @@ -0,0 +1,110 @@ +"""Rejection vectors: documents another implementation must refuse as well.""" + +from copy import deepcopy +import json +from pathlib import Path + +import pytest + +from modpoll_wot import AcquisitionError +from modpoll_wot.profile import instantiate +from modpoll_wot.validation import ModelValidationError + +FIXTURES = Path(__file__).parent / "fixtures" +VECTORS = json.loads((FIXTURES / "conformance.rejections.json").read_bytes()) +MODEL = json.loads((FIXTURES / VECTORS["model"]).read_bytes()) +# What the loader answers for each rule. A vector that is refused for another reason than its +# own rule would stop testing that rule, so the answer is part of the check. +ANSWERS = { + "profile-version": "unsupported executable profile", + "document-kind": "'href' is a required property", + "placeholder-unbound": "unbound TM placeholder", + "placeholder-malformed": "malformed TM placeholder", + "title-blank": "title cannot be empty", + "security-scheme": "supports only nosec", + "root-feature": "unsupported executable profile feature", + "root-modbus-field": "root Modbus fields are unsupported", + "root-project-extension": "unsupported root project extension", + "vocabulary-alias": "unsupported fixed vocabulary aliases", + "property-protocol-metadata": "protocol metadata belongs in Forms", + "href-invalid": "invalid concrete Modbus TCP href", + "href-disagrees": "href disagrees with", + "unit-id-inconsistent": "inconsistent Unit IDs", + "span": "invalid Modbus span", + "codec": "unsupported or redundant codec", + "bit-raw-type": "bit extraction requires a register unsignedShort", + "boolean-property": "invalid boolean property", + "boolean-scalar-quantity": "scalar boolean requires quantity 1", + "boolean-multiplier": "booleans cannot be multiplied", + "raw-type-missing": "unsupported or missing raw type", + "byte-length-not-string": "byteLength only applies to strings", + "bit-packing-missing": "requires explicit legacy-msb packing", + "bit-packing-misplaced": "bitPacking is only for", + "quantity-width": "quantity disagrees with raw codec width", + "media-type": "binary media parameter", + "operation": "ambiguous or invalid operation", + "forms-disagree": "read/write Forms disagree", + "forms-cover-access": "Forms must cover property access", + "read-only-table": "read-only table requires readOnly", + "multiplier": "multiplier", + "property-type": "property type disagrees", + "group-span": "invalid group span", + "group-member": "unknown or duplicate member", + "group-member-span": "member outside group or wrong entity", + "property-ungrouped": "exactly one acquisition group", +} + + +def patched(document, patch): + """Apply the add, replace and remove operations of a JSON Patch (RFC 6902).""" + document = deepcopy(document) + for operation in patch: + *parents, last = [ + token.replace("~1", "/").replace("~0", "~") + for token in operation["path"].split("/")[1:] + ] + node = document + for token in parents: + node = node[int(token)] if isinstance(node, list) else node[token] + if isinstance(node, list): + index = int(last) + if operation["op"] == "add": + node.insert(index, operation["value"]) + elif operation["op"] == "replace": + node[index] = operation["value"] + else: + del node[index] + elif operation["op"] == "remove": + del node[last] + else: + assert (last in node) == (operation["op"] == "replace"), operation + node[last] = operation["value"] + return document + + +def test_the_unchanged_model_is_accepted(): + instantiate(deepcopy(MODEL)) + instantiate(deepcopy(MODEL), host="device.example") + + +# A TCP host binds more placeholders but must never turn a refusal into an acceptance. +@pytest.mark.parametrize( + "instance", [{}, {"host": "device.example"}], ids=["unbound", "tcp"] +) +@pytest.mark.parametrize( + "vector", + VECTORS["vectors"], + ids=[f"{i}-{vector['rule']}" for i, vector in enumerate(VECTORS["vectors"])], +) +def test_each_vector_is_rejected_by_its_rule(vector, instance): + document = patched(MODEL, vector["patch"]) + with pytest.raises(AcquisitionError) as refusal: + instantiate(document, **instance) + if vector["rule"] == "schema": + assert isinstance(refusal.value, ModelValidationError) + else: + assert ANSWERS[vector["rule"]] in str(refusal.value) + + +def test_every_rule_has_a_vector(): + assert {vector["rule"] for vector in VECTORS["vectors"]} == {*ANSWERS, "schema"} From 1e7fcb5f8789e652078dda1e101d11ce7c5a79f5 Mon Sep 17 00:00:00 2001 From: Gavin Ying Date: Mon, 16 Nov 2026 10:01:26 +0800 Subject: [PATCH 2/3] chore(modpoll-wot): restore the coverage data file changed by a local test run --- packages/modpoll-wot/.coverage | Bin 53248 -> 53248 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/packages/modpoll-wot/.coverage b/packages/modpoll-wot/.coverage index d4b8d769a2e5948d9b06baa009def17d23d5fe6d..e42c6b5657df9702697e0aa24ecd9fd7fe65998d 100644 GIT binary patch delta 867 zcmZozz}&EadBb0QMzhWT^f?41SQz-1@VoN8;_Klv~}Yi;FY!^YjWTV>p5GwrKK`ZG3sz z;y8dZj%YHXWvNA(X_?81B@pdV?3k7+O@8MKbPgL98Nt-Nl!E-syb_?zk*q)k=q{T) z%a4mKh6N~t;imU~ylj!oSo8?wvZ5Fh&I)rZIXfQ7k}rBa8Vc z@gqW%E0zW5cvR`hHnDsx@hrgLL=&G9D}ZT*4=@B{d9aBKAcY?r7H3SJ701nj&Hnds zd{~{02s-9C7GTJsId4upKP%80OHR}vRoVPKo?k)YG6Vlt{%ibu_}B8!=kMgV-0-o z|C4<>cYS#|*G22S7p4F0-_P>p+yDRa4j=bj|C=ZOqx$Qs;=TX>SFQhc`|tm{e|zG$ z->-lF@9Fm6n_vGwKe?%2gYov{)%}XbdnZ>Pxi|m{UCi3)i9v4ge^wEm!~m delta 711 zcmZozz}&EadBb0QM)S@8^f?41+!***@dxt#;akGz&-;^iF|Q}jN1i!6Zkq)KG^ zylfF1Kp|7OP?j%0TL?R{!IMw|zDV!0ggt3u6It5jNcQ z<7EqGMpB_P+1j6rEu0A`WDK`-nm->~2qRDk?wiS9{RJi58TeQ8xbp|`F5&&f_m?k# zXD-htzNNfgK<{hvu!OPzl~0UQ0eM~k$@APHEI{`_CHN73=L%;5It(g4nJ1QyC6Wc` zahO0>tN@CUlTXE>*@5I~HiR8pFQ_1KhJpVp|5g6o{A>8<@ptfB@JsMB@V)0d1N7}WK4nF27Di4Nj$fs_8!FHF z|9@ZqlJnVe&NIq06#n~tc>n+Z@B56CKlIr!zMrhyFKzu__UYaA-^=U2TkpMi```Zk zEMLC;|1W>w`@ZXc>*Rk_e|=ZI_y7NY>%ZOp`@inrp7`ze>)-!-y8ZX&*Z=z`H}`8W z{+_(1U(sa$=ISHY=Kue{LXHV&xgGZ}rg Date: Mon, 16 Nov 2026 10:05:18 +0800 Subject: [PATCH 3/3] docs(modpoll-wot): name the vector file by path until it exists on v2 --- packages/modpoll-wot/profile.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/modpoll-wot/profile.md b/packages/modpoll-wot/profile.md index 60bf65a..73d636f 100644 --- a/packages/modpoll-wot/profile.md +++ b/packages/modpoll-wot/profile.md @@ -218,7 +218,7 @@ requires a new prefix. ### Rejection vectors An implementation that accepts or stores Thing Models without this package, such as a web service, must refuse what -this loader refuses. [tests/fixtures/conformance.rejections.json](https://github.com/top-maker/modpoll/blob/v2/packages/modpoll-wot/tests/fixtures/conformance.rejections.json) +this loader refuses. `tests/fixtures/conformance.rejections.json`, next to the fingerprint vectors, lists documents that must be refused: each vector is a JSON Patch (RFC 6902, `add`, `replace` and `remove` only) applied to `conformance.tm.json`, with the name of the rule that refuses the result. The unchanged model must be accepted. The rule names group the vectors for readers and are not an error code contract; `schema` marks a vector