backplane-tracecheck 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- backplane_tracecheck-0.2.0.dist-info/METADATA +167 -0
- backplane_tracecheck-0.2.0.dist-info/RECORD +15 -0
- backplane_tracecheck-0.2.0.dist-info/WHEEL +4 -0
- backplane_tracecheck-0.2.0.dist-info/entry_points.txt +2 -0
- backplane_tracecheck-0.2.0.dist-info/licenses/LICENSE +202 -0
- backplane_tracecheck-0.2.0.dist-info/licenses/NOTICE +5 -0
- tracecheck/__init__.py +1 -0
- tracecheck/__main__.py +131 -0
- tracecheck/contract.py +92 -0
- tracecheck/engine.py +310 -0
- tracecheck/reader.py +735 -0
- tracecheck/report.py +14 -0
- tracecheck/samples.py +103 -0
- tracecheck/server.py +158 -0
- tracecheck/ui.html +21 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: backplane-tracecheck
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Check robot recordings (MCAP) against an explicit, versioned recording contract.
|
|
5
|
+
Project-URL: Homepage, https://backplanerobotics.com
|
|
6
|
+
Project-URL: Source, https://github.com/backplane-robotics/backplane-tracecheck
|
|
7
|
+
Project-URL: Issues, https://github.com/backplane-robotics/backplane-tracecheck/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/backplane-robotics/backplane-tracecheck/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Backplane Robotics LLC
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Keywords: data-quality,mcap,recording,robotics,ros2,rosbag
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering
|
|
21
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: lz4>=4.3
|
|
24
|
+
Requires-Dist: mcap<2,>=1.5
|
|
25
|
+
Requires-Dist: zstandard>=0.22
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
29
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# Backplane Tracecheck
|
|
33
|
+
|
|
34
|
+
**Check robot recordings against an explicit recording contract.**
|
|
35
|
+
|
|
36
|
+
Tracecheck reads an [MCAP](https://mcap.dev) recording (the default ROS 2 bag format) and checks it against a small JSON *recording contract*: which topics must be present, their schemas and encodings, message counts, rates, timestamp gaps, regressions, sequence continuity and time coverage. It produces a JSON report and a readable HTML report. Each finding points to an exact byte offset in the file.
|
|
37
|
+
|
|
38
|
+
- Free and open source (Apache-2.0).
|
|
39
|
+
- Read-only. Message payloads are never decoded or executed.
|
|
40
|
+
- No robot, ROS install, account or cloud service needed.
|
|
41
|
+
- Streams files of any size. Handles zstd and lz4 chunks safely.
|
|
42
|
+
- Runs as a Python CLI or entirely in your browser at **[backplanerobotics.com/tracecheck](https://backplanerobotics.com/tracecheck/)**, where files never leave your device.
|
|
43
|
+
|
|
44
|
+
Built by [Backplane Robotics](https://backplanerobotics.com).
|
|
45
|
+
|
|
46
|
+
## Install
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install backplane-tracecheck
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Requires Python 3.11+.
|
|
53
|
+
|
|
54
|
+
## Quick start
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Write the synthetic demo recordings and contract to ./examples
|
|
58
|
+
tracecheck samples
|
|
59
|
+
|
|
60
|
+
tracecheck validate-contract examples/demo-contract.json
|
|
61
|
+
tracecheck check examples/clean.mcap --contract examples/demo-contract.json --out reports/clean
|
|
62
|
+
tracecheck check examples/faults.mcap --contract examples/demo-contract.json --out reports/faults
|
|
63
|
+
|
|
64
|
+
# Optional local browser UI (binds to 127.0.0.1 only)
|
|
65
|
+
tracecheck serve --open
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`--out` must be a new directory. Existing reports are never overwritten.
|
|
69
|
+
|
|
70
|
+
**Useful options**
|
|
71
|
+
|
|
72
|
+
| Option | Effect |
|
|
73
|
+
|---|---|
|
|
74
|
+
| `--fast` | Read only the summary section: inventory, counts, schemas and metadata in milliseconds. Timing checks (C06–C10) skip. Falls back to a full scan if the file has no usable summary. |
|
|
75
|
+
| `--ignore-missing-crc` | Don't warn when the writer stored no CRCs (same as `"missing_crc": "ignore"` in the contract). Corrupt CRCs still fail. |
|
|
76
|
+
| `--fail-on fail` | Exit 0 on warnings, exit 1 only on failures (the default `warn` also exits 1 on warnings). |
|
|
77
|
+
| `--timeout SECONDS` | Stop a scan that takes too long. |
|
|
78
|
+
| `--max-chunk-mib`, `--max-record-mib`, `--max-tracked-messages` | Raise or lower the memory safety limits (defaults: 256, 256, 20,000,000). |
|
|
79
|
+
|
|
80
|
+
**Exit codes**
|
|
81
|
+
- `0`: overall pass.
|
|
82
|
+
- `1`: contract failures, warnings or an incomplete scan (all recorded in the report).
|
|
83
|
+
- `2`: configuration, input or operational error. No report is written.
|
|
84
|
+
|
|
85
|
+
## In the browser
|
|
86
|
+
|
|
87
|
+
[backplanerobotics.com/tracecheck](https://backplanerobotics.com/tracecheck/) runs the same checks in a Web Worker, using a JavaScript port of the engine in [`web/src/engine/`](https://github.com/backplane-robotics/backplane-tracecheck/tree/main/web/src/engine).
|
|
88
|
+
- The file is read locally in slices and never uploaded.
|
|
89
|
+
- The site's Content-Security-Policy blocks connections to any other origin.
|
|
90
|
+
- For the same inputs, the browser and CLI produce identical JSON reports, apart from timestamps and tool fields. The web test suite checks this.
|
|
91
|
+
|
|
92
|
+
## A minimal contract
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"version": 1,
|
|
97
|
+
"name": "My recording requirements",
|
|
98
|
+
"topics": {
|
|
99
|
+
"/my/topic": { "required": true, "min_count": 1 }
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Start minimal, then read the report's channel inventory to see the actual schema names, encodings and fingerprints. Add only the requirements you can justify. See [docs/CONTRACT_REFERENCE.md](https://github.com/backplane-robotics/backplane-tracecheck/blob/main/docs/CONTRACT_REFERENCE.md) for every key.
|
|
105
|
+
|
|
106
|
+
## The ten checks
|
|
107
|
+
|
|
108
|
+
| ID | Check |
|
|
109
|
+
|---|---|
|
|
110
|
+
| C01 | Readable bounded MCAP scan (with CRC verification where present) |
|
|
111
|
+
| C02 | Required topics contain messages |
|
|
112
|
+
| C03 | Profile, schema and encoding |
|
|
113
|
+
| C04 | Required file metadata |
|
|
114
|
+
| C05 | Message counts |
|
|
115
|
+
| C06 | Average recorded rate |
|
|
116
|
+
| C07 | Sorted timestamp gaps |
|
|
117
|
+
| C08 | Record-order timestamp regressions |
|
|
118
|
+
| C09 | Sequence continuity |
|
|
119
|
+
| C10 | Expected interval coverage |
|
|
120
|
+
|
|
121
|
+
**Statuses**
|
|
122
|
+
- **PASS:** the configured requirement was met.
|
|
123
|
+
- **WARN:** a scoped limitation, for example message data with no CRC coverage. Default ROS 2 files with chunk CRCs pass.
|
|
124
|
+
- **FAIL:** an unmet requirement or a failed scan. It does not mean the robot is unsafe.
|
|
125
|
+
- **SKIPPED:** no conclusion was reached.
|
|
126
|
+
|
|
127
|
+
Tracecheck does not certify safety, establish regulatory compliance, determine causality or measure transport latency.
|
|
128
|
+
|
|
129
|
+
## Development
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
python -m venv .venv
|
|
133
|
+
.venv/Scripts/activate # Windows; use `source .venv/bin/activate` elsewhere
|
|
134
|
+
pip install -e ".[dev]"
|
|
135
|
+
python -m pytest
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
After an intentional behaviour change, regenerate the golden results shared by both test suites and review the diff:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
tracecheck samples && python tools/make_golden.py
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**Website** (Node 20+):
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
cd web
|
|
148
|
+
npm install
|
|
149
|
+
npm test # engine parity tests against examples/ and the Python engine
|
|
150
|
+
npm run dev # local dev server
|
|
151
|
+
npm run build # static site in web/dist (deploy to Cloudflare Pages)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Repository layout
|
|
155
|
+
|
|
156
|
+
| Path | Contents |
|
|
157
|
+
|---|---|
|
|
158
|
+
| `src/tracecheck/` | Python package and CLI |
|
|
159
|
+
| `tests/` | Engine, streaming, contract, CLI and local-server tests |
|
|
160
|
+
| `examples/` | Synthetic MCAP recordings, contracts and golden results (invented data) |
|
|
161
|
+
| `docs/` | Contract reference and third-party notices |
|
|
162
|
+
| `tools/` | Maintenance scripts (golden-result generator) |
|
|
163
|
+
| `web/` | Browser-only website and Tracecheck web app for backplanerobotics.com |
|
|
164
|
+
|
|
165
|
+
## License
|
|
166
|
+
|
|
167
|
+
Apache-2.0. See [LICENSE](https://github.com/backplane-robotics/backplane-tracecheck/blob/main/LICENSE) and [NOTICE](https://github.com/backplane-robotics/backplane-tracecheck/blob/main/NOTICE). Copyright 2026 Backplane Robotics LLC.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
tracecheck/__init__.py,sha256=Zn1KFblwuFHiDRdRAiRnDBRkbPttWh44jKa5zG2ov0E,22
|
|
2
|
+
tracecheck/__main__.py,sha256=oF5AmHU1gi3nc-3-n0fwaweRsOsUSFRORJnqg9p2sBk,6360
|
|
3
|
+
tracecheck/contract.py,sha256=V6i7osDbsp7_DUKyAUxFQ_Hv3xiUTgTEreI7pbUpc4g,4690
|
|
4
|
+
tracecheck/engine.py,sha256=eVzwDS0eXCAEYXGKuJfdSaMhRakR0-uJaBfDs4qVSv8,15618
|
|
5
|
+
tracecheck/reader.py,sha256=Kwu7z0UDXj6_68ihBBwiUlxPedg2LdluWefTxMs1wFU,28238
|
|
6
|
+
tracecheck/report.py,sha256=VD3i7xaEUKptw4BjFYX8MubPadkSJq95P0LKoVbd_78,2973
|
|
7
|
+
tracecheck/samples.py,sha256=5qAuVX5awr3BK3-CtMo0bC38DIovm7Zger8-eJacoZU,6396
|
|
8
|
+
tracecheck/server.py,sha256=fjgKDkpWqkXB_pR1ZhffY8UBgOKfOs1hozMgYHd-u1c,7818
|
|
9
|
+
tracecheck/ui.html,sha256=fOMSVp6Mg-qQ6akBMrv3UTEV_xy2u4z7P5N6NKucF2Q,8245
|
|
10
|
+
backplane_tracecheck-0.2.0.dist-info/METADATA,sha256=QWcSnR4x22KDwexhUt6pnORCfSRgLrWspY4b7NvMDCY,7013
|
|
11
|
+
backplane_tracecheck-0.2.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
12
|
+
backplane_tracecheck-0.2.0.dist-info/entry_points.txt,sha256=OvzkPGcRDOZeou1k8_Djnq-YW_AFmxeJT4du76g_Lg8,56
|
|
13
|
+
backplane_tracecheck-0.2.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
14
|
+
backplane_tracecheck-0.2.0.dist-info/licenses/NOTICE,sha256=YibcaDSbp5tPQ_95mwOhwNDpiozMHzUgEllBaqr0V14,223
|
|
15
|
+
backplane_tracecheck-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
tracecheck/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.0"
|
tracecheck/__main__.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Command-line interface: ``tracecheck check | validate-contract | samples | serve``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from . import __version__
|
|
11
|
+
from .contract import ContractError, loads
|
|
12
|
+
from .engine import analyze_file
|
|
13
|
+
from .reader import MiB, Limits
|
|
14
|
+
from .report import render
|
|
15
|
+
|
|
16
|
+
EXIT_PASS, EXIT_FINDINGS, EXIT_ERROR = 0, 1, 2
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _load_contract(path: Path) -> dict:
|
|
20
|
+
if path.stat().st_size > 65536:
|
|
21
|
+
raise ContractError("contract exceeds 64 KiB")
|
|
22
|
+
return loads(path.read_text(encoding="utf-8-sig"))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _parser() -> argparse.ArgumentParser:
|
|
26
|
+
p = argparse.ArgumentParser(
|
|
27
|
+
prog="tracecheck",
|
|
28
|
+
description="Backplane Tracecheck: check MCAP robot recordings against a recording contract. "
|
|
29
|
+
"Exit 0 pass, 1 findings/warnings, 2 input/config/operational error.",
|
|
30
|
+
)
|
|
31
|
+
p.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
32
|
+
sub = p.add_subparsers(dest="command", required=True)
|
|
33
|
+
|
|
34
|
+
check = sub.add_parser("check", help="check a recording and write JSON + HTML reports")
|
|
35
|
+
check.add_argument("recording", type=Path)
|
|
36
|
+
check.add_argument("--contract", type=Path, required=True)
|
|
37
|
+
check.add_argument("--out", type=Path, required=True, help="new output directory; existing files are never overwritten")
|
|
38
|
+
check.add_argument("--fast", action="store_true",
|
|
39
|
+
help="read only the summary section (inventory, counts, schemas, metadata); timing checks skip")
|
|
40
|
+
check.add_argument("--ignore-missing-crc", action="store_true",
|
|
41
|
+
help="do not warn when CRCs are absent (same as contract \"missing_crc\": \"ignore\")")
|
|
42
|
+
check.add_argument("--fail-on", choices=["warn", "fail"], default="warn",
|
|
43
|
+
help="lowest overall status that gives exit code 1 (default: warn)")
|
|
44
|
+
check.add_argument("--timeout", type=float, default=None, metavar="SECONDS", help="stop the scan after SECONDS")
|
|
45
|
+
check.add_argument("--max-chunk-mib", type=int, default=Limits.max_chunk_uncompressed_bytes // MiB,
|
|
46
|
+
help="largest allowed uncompressed chunk (default: %(default)s)")
|
|
47
|
+
check.add_argument("--max-record-mib", type=int, default=Limits.max_record_bytes // MiB,
|
|
48
|
+
help="largest allowed record that must be read into memory (default: %(default)s)")
|
|
49
|
+
check.add_argument("--max-tracked-messages", type=int, default=Limits.max_tracked_messages,
|
|
50
|
+
help="timestamps kept in memory for sorted-gap checks (default: %(default)s)")
|
|
51
|
+
check.add_argument("--quiet", action="store_true", help="no progress output")
|
|
52
|
+
|
|
53
|
+
v = sub.add_parser("validate-contract", help="validate a contract file")
|
|
54
|
+
v.add_argument("contract", type=Path)
|
|
55
|
+
|
|
56
|
+
s = sub.add_parser("serve", help="local browser UI on 127.0.0.1 (files up to 64 MiB)")
|
|
57
|
+
s.add_argument("--port", type=int, default=8765)
|
|
58
|
+
s.add_argument("--open", action="store_true")
|
|
59
|
+
|
|
60
|
+
sm = sub.add_parser("samples", help="write synthetic example recordings and the demo contract")
|
|
61
|
+
sm.add_argument("--dest", type=Path, default=Path("examples"))
|
|
62
|
+
|
|
63
|
+
w = sub.add_parser("_worker") # internal: used by the local server
|
|
64
|
+
w.add_argument("recording", type=Path)
|
|
65
|
+
w.add_argument("contract", type=Path)
|
|
66
|
+
w.add_argument("--name")
|
|
67
|
+
return p
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def main(argv: list[str] | None = None) -> int:
|
|
71
|
+
args = _parser().parse_args(argv)
|
|
72
|
+
try:
|
|
73
|
+
if args.command == "serve":
|
|
74
|
+
from .server import serve
|
|
75
|
+
|
|
76
|
+
serve(args.port, args.open)
|
|
77
|
+
return EXIT_PASS
|
|
78
|
+
if args.command == "samples":
|
|
79
|
+
from .samples import generate
|
|
80
|
+
|
|
81
|
+
generate(args.dest)
|
|
82
|
+
print(f"Synthetic examples ready in {args.dest}/")
|
|
83
|
+
return EXIT_PASS
|
|
84
|
+
contract = _load_contract(args.contract)
|
|
85
|
+
if args.command == "validate-contract":
|
|
86
|
+
print("Contract valid:", contract["name"])
|
|
87
|
+
return EXIT_PASS
|
|
88
|
+
if not args.recording.is_file():
|
|
89
|
+
raise ValueError("recording must be a regular file")
|
|
90
|
+
if args.command == "_worker":
|
|
91
|
+
from .server import UPLOAD_LIMIT
|
|
92
|
+
|
|
93
|
+
r = analyze_file(args.recording, contract, args.name or args.recording.name,
|
|
94
|
+
limits=Limits(max_seconds=30, max_record_bytes=8 * MiB,
|
|
95
|
+
max_chunk_uncompressed_bytes=UPLOAD_LIMIT)) # fmt: skip
|
|
96
|
+
print(json.dumps(r, ensure_ascii=True))
|
|
97
|
+
return EXIT_PASS
|
|
98
|
+
|
|
99
|
+
if args.out.exists():
|
|
100
|
+
raise ValueError("output directory already exists; choose a new --out path")
|
|
101
|
+
if args.ignore_missing_crc:
|
|
102
|
+
contract = dict(contract, missing_crc="ignore")
|
|
103
|
+
limits = Limits(
|
|
104
|
+
max_seconds=args.timeout,
|
|
105
|
+
max_chunk_uncompressed_bytes=args.max_chunk_mib * MiB,
|
|
106
|
+
max_record_bytes=args.max_record_mib * MiB,
|
|
107
|
+
max_tracked_messages=args.max_tracked_messages,
|
|
108
|
+
)
|
|
109
|
+
progress = None
|
|
110
|
+
if not args.quiet and sys.stderr.isatty() and not args.fast:
|
|
111
|
+
def progress(done: int, total: int) -> None:
|
|
112
|
+
print(f"\r scanned {done / MiB:,.0f} / {total / MiB:,.0f} MiB ({100 * done / max(total, 1):.0f}%)",
|
|
113
|
+
end="", file=sys.stderr, flush=True) # fmt: skip
|
|
114
|
+
r = analyze_file(args.recording, contract, fast=args.fast, limits=limits, progress=progress)
|
|
115
|
+
if progress is not None:
|
|
116
|
+
print(file=sys.stderr)
|
|
117
|
+
args.out.mkdir(parents=True, exist_ok=False)
|
|
118
|
+
(args.out / "report.json").write_text(json.dumps(r, indent=2, ensure_ascii=False), encoding="utf-8")
|
|
119
|
+
(args.out / "report.html").write_text(render(r), encoding="utf-8")
|
|
120
|
+
note = f" | fast mode fell back to full scan: {r['fast_mode_fallback']}" if "fast_mode_fallback" in r else ""
|
|
121
|
+
print(f"{r['overall'].upper()} | mode={r['scan_mode']} | scan_complete={r['scan_complete']} | "
|
|
122
|
+
f"{r['status_counts']} | reports: {args.out}{note}") # fmt: skip
|
|
123
|
+
failing = {"warn": ("skipped", "warn", "fail"), "fail": ("fail",)}[args.fail_on]
|
|
124
|
+
return EXIT_FINDINGS if r["overall"] in failing else EXIT_PASS
|
|
125
|
+
except (OSError, ValueError) as e:
|
|
126
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
127
|
+
return EXIT_ERROR
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
if __name__ == "__main__":
|
|
131
|
+
sys.exit(main())
|
tracecheck/contract.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""Small strict contract language; unknown keys and ambiguous numbers are errors."""
|
|
2
|
+
import json
|
|
3
|
+
import math
|
|
4
|
+
import re
|
|
5
|
+
|
|
6
|
+
MAX_CONTRACT = 64 * 1024
|
|
7
|
+
MISSING_CRC = ('warn', 'ignore')
|
|
8
|
+
|
|
9
|
+
class ContractError(ValueError):
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
def require(ok, message):
|
|
13
|
+
if not ok:
|
|
14
|
+
raise ContractError(message)
|
|
15
|
+
|
|
16
|
+
def keys(obj, allowed, where):
|
|
17
|
+
require(isinstance(obj, dict), f"{where}: expected an object")
|
|
18
|
+
require(not (set(obj) - set(allowed)), f"{where}: unknown keys {sorted(set(obj)-set(allowed))}")
|
|
19
|
+
|
|
20
|
+
def string(value, where):
|
|
21
|
+
require(isinstance(value, str) and 0 < len(value) <= 256, f"{where}: expected 1–256 characters")
|
|
22
|
+
|
|
23
|
+
def number(value, where, integer=False):
|
|
24
|
+
require(type(value) in ((int,) if integer else (int, float)) and 0 <= value <= 2**64-1 and math.isfinite(value),
|
|
25
|
+
f"{where}: expected a finite nonnegative {'integer' if integer else 'number'}")
|
|
26
|
+
|
|
27
|
+
def unique(pairs):
|
|
28
|
+
result = {}
|
|
29
|
+
for k, v in pairs:
|
|
30
|
+
require(k not in result, f"duplicate key: {k}")
|
|
31
|
+
result[k] = v
|
|
32
|
+
return result
|
|
33
|
+
|
|
34
|
+
def loads(text):
|
|
35
|
+
require(len(text.encode('utf-8')) <= MAX_CONTRACT, "contract exceeds 64 KiB")
|
|
36
|
+
try:
|
|
37
|
+
value = json.loads(text, object_pairs_hook=unique, parse_constant=lambda v: (_ for _ in ()).throw(ContractError(f"invalid number: {v}")))
|
|
38
|
+
except (ValueError, RecursionError) as e:
|
|
39
|
+
raise ContractError(str(e)) from e
|
|
40
|
+
return validate(value)
|
|
41
|
+
|
|
42
|
+
def validate(c):
|
|
43
|
+
keys(c, ['version', 'name', 'profile', 'missing_crc', 'metadata', 'topics'], 'contract')
|
|
44
|
+
require(type(c.get('version')) is int and c['version'] == 1, 'version must be 1')
|
|
45
|
+
string(c.get('name'), 'name')
|
|
46
|
+
if 'profile' in c:
|
|
47
|
+
require(isinstance(c['profile'], str) and len(c['profile']) <= 256, 'profile must be a string')
|
|
48
|
+
require(c.get('missing_crc', 'warn') in MISSING_CRC, f'missing_crc must be one of {list(MISSING_CRC)}')
|
|
49
|
+
keys(c.get('metadata', {}), c.get('metadata', {}).keys() if isinstance(c.get('metadata', {}), dict) else [], 'metadata')
|
|
50
|
+
for name, fields in c.get('metadata', {}).items():
|
|
51
|
+
string(name, 'metadata name')
|
|
52
|
+
require(isinstance(fields, dict) and len(fields) <= 30, 'metadata fields must be an object, <=30 keys')
|
|
53
|
+
for key, expected in fields.items():
|
|
54
|
+
string(key, 'metadata key')
|
|
55
|
+
if expected is not None:
|
|
56
|
+
string(expected, 'metadata expected value')
|
|
57
|
+
topics = c.get('topics')
|
|
58
|
+
require(isinstance(topics, dict) and 0 < len(topics) <= 50, 'topics must contain 1–50 entries')
|
|
59
|
+
for topic, t in topics.items():
|
|
60
|
+
string(topic, 'topic')
|
|
61
|
+
keys(t, ['required', 'message_encoding', 'schema_name', 'schema_encoding', 'schema_sha256', 'min_count', 'max_count',
|
|
62
|
+
'time_basis', 'clock_confirmed', 'min_rate_hz', 'max_rate_hz', 'max_gap_ns',
|
|
63
|
+
'check_regression', 'sequence', 'interval_ns', 'boundary_tolerance_ns'], topic)
|
|
64
|
+
for k in ['required', 'clock_confirmed', 'check_regression']:
|
|
65
|
+
if k in t:
|
|
66
|
+
require(type(t[k]) is bool, f'{topic}.{k}: expected boolean')
|
|
67
|
+
for k in ['message_encoding', 'schema_name', 'schema_encoding']:
|
|
68
|
+
if k in t:
|
|
69
|
+
string(t[k], f'{topic}.{k}')
|
|
70
|
+
if 'schema_sha256' in t:
|
|
71
|
+
require(isinstance(t['schema_sha256'], str) and re.fullmatch('[0-9a-f]{64}', t['schema_sha256']) is not None,
|
|
72
|
+
f'{topic}.schema_sha256: expected 64 lowercase hex characters')
|
|
73
|
+
for k in ['min_count', 'max_count', 'max_gap_ns', 'boundary_tolerance_ns']:
|
|
74
|
+
if k in t:
|
|
75
|
+
number(t[k], f'{topic}.{k}', True)
|
|
76
|
+
for k in ['min_rate_hz', 'max_rate_hz']:
|
|
77
|
+
if k in t:
|
|
78
|
+
number(t[k], f'{topic}.{k}')
|
|
79
|
+
for lo, hi in [('min_count', 'max_count'), ('min_rate_hz', 'max_rate_hz')]:
|
|
80
|
+
if lo in t and hi in t:
|
|
81
|
+
require(t[lo] <= t[hi], f'{topic}: {lo} exceeds {hi}')
|
|
82
|
+
require(t.get('time_basis', 'log_time') in ['log_time', 'publish_time'], f'{topic}: unsupported time_basis')
|
|
83
|
+
require(t.get('sequence', 'disabled') in ['disabled', 'increment_mod32'], f'{topic}: unsupported sequence policy')
|
|
84
|
+
if 'interval_ns' in t:
|
|
85
|
+
v = t['interval_ns']
|
|
86
|
+
require(isinstance(v, list) and len(v) == 2, f'{topic}: interval_ns needs [start,end]')
|
|
87
|
+
for x in v:
|
|
88
|
+
number(x, f'{topic}.interval_ns', True)
|
|
89
|
+
require(v[0] < v[1], f'{topic}: interval start must precede end')
|
|
90
|
+
require(t.get('boundary_tolerance_ns', 0) * 2 <= v[1]-v[0], f'{topic}: boundary tolerance too large')
|
|
91
|
+
require(len(json.dumps(c).encode()) <= MAX_CONTRACT, 'contract exceeds 64 KiB')
|
|
92
|
+
return c
|