visual-access-contract 0.2.1__tar.gz

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.
Files changed (31) hide show
  1. visual_access_contract-0.2.1/LICENSE +202 -0
  2. visual_access_contract-0.2.1/PKG-INFO +146 -0
  3. visual_access_contract-0.2.1/README.md +131 -0
  4. visual_access_contract-0.2.1/checks/__init__.py +0 -0
  5. visual_access_contract-0.2.1/checks/structured_check.py +175 -0
  6. visual_access_contract-0.2.1/checks/visual_check.py +163 -0
  7. visual_access_contract-0.2.1/evidence/__init__.py +0 -0
  8. visual_access_contract-0.2.1/evidence/reporter.py +148 -0
  9. visual_access_contract-0.2.1/pyproject.toml +25 -0
  10. visual_access_contract-0.2.1/setup.cfg +4 -0
  11. visual_access_contract-0.2.1/tests/test_cli_adoption.py +117 -0
  12. visual_access_contract-0.2.1/tests/test_contract_cli.py +81 -0
  13. visual_access_contract-0.2.1/tests/test_demo_report.py +63 -0
  14. visual_access_contract-0.2.1/tests/test_integration_app.py +93 -0
  15. visual_access_contract-0.2.1/vac/__init__.py +0 -0
  16. visual_access_contract-0.2.1/vac/__main__.py +40 -0
  17. visual_access_contract-0.2.1/vac/cli.py +98 -0
  18. visual_access_contract-0.2.1/vac/contract.py +256 -0
  19. visual_access_contract-0.2.1/vac/demo-contract.yaml +46 -0
  20. visual_access_contract-0.2.1/vac/demo.py +53 -0
  21. visual_access_contract-0.2.1/vac/demo_fixture.py +86 -0
  22. visual_access_contract-0.2.1/vac/html_report.py +92 -0
  23. visual_access_contract-0.2.1/vac/output.py +71 -0
  24. visual_access_contract-0.2.1/vac/runner.py +151 -0
  25. visual_access_contract-0.2.1/vac/session.py +63 -0
  26. visual_access_contract-0.2.1/visual_access_contract.egg-info/PKG-INFO +146 -0
  27. visual_access_contract-0.2.1/visual_access_contract.egg-info/SOURCES.txt +29 -0
  28. visual_access_contract-0.2.1/visual_access_contract.egg-info/dependency_links.txt +1 -0
  29. visual_access_contract-0.2.1/visual_access_contract.egg-info/entry_points.txt +2 -0
  30. visual_access_contract-0.2.1/visual_access_contract.egg-info/requires.txt +6 -0
  31. visual_access_contract-0.2.1/visual_access_contract.egg-info/top_level.txt +3 -0
@@ -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.
@@ -0,0 +1,146 @@
1
+ Metadata-Version: 2.4
2
+ Name: visual-access-contract
3
+ Version: 0.2.1
4
+ Summary: CI checks for role-specific visibility of synthetic data
5
+ License-Expression: Apache-2.0
6
+ Requires-Python: >=3.12
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: playwright==1.62.0
10
+ Requires-Dist: PyYAML==6.0.3
11
+ Provides-Extra: integration
12
+ Requires-Dist: fastapi==0.115.12; extra == "integration"
13
+ Requires-Dist: uvicorn==0.34.2; extra == "integration"
14
+ Dynamic: license-file
15
+
16
+ # Visual Access Contract
17
+
18
+ [![CI](https://github.com/Anne07-Ai/visual-access-contract/actions/workflows/contract-validation.yml/badge.svg)](https://github.com/Anne07-Ai/visual-access-contract/actions/workflows/contract-validation.yml)
19
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue)](LICENSE)
20
+ [![Python 3.12 or later](https://img.shields.io/badge/python-3.12%2B-blue)](pyproject.toml)
21
+
22
+ Visual Access Contract checks a versioned, role-specific masking rule against selected API responses, visible DOM text, and rendered pixels in CI. In our four-case synthetic experiment, OCR caught a canvas disclosure that the selected API and DOM checks missed, while API inspection caught a disclosure that never appeared on screen.
23
+
24
+ **Status** · Private engineering prototype for AppSec and QA teams. The current baseline covers one role, one field, and four synthetic scenarios. It uses a local fixture server and runs in reporting mode. The fixture results establish coverage for these scenarios. Coverage on customer applications and OCR accuracy across layouts still need validation.
25
+
26
+ ## Install from PyPI
27
+
28
+ After the first PyPI publication, install VAC with Python 3.12 or newer in a virtual environment. Install Tesseract with your system package manager.
29
+
30
+ ```bash
31
+ pip install visual-access-contract
32
+ python -m playwright install chromium
33
+ vac check --contract contract.yaml
34
+ ```
35
+
36
+ Use a schema 1.0 contract for `vac check`. See [Getting started](docs/getting-started.md) for an example.
37
+
38
+ ## Try it in 60 seconds
39
+
40
+ After installing Python 3.12 or later, run these three lines on Ubuntu from a terminal with access to the repository:
41
+
42
+ ```bash
43
+ git clone https://github.com/Anne07-Ai/visual-access-contract.git && cd visual-access-contract
44
+ python -m venv .venv && source .venv/bin/activate && sudo apt-get install -y tesseract-ocr && python -m pip install -e . && python -m playwright install --with-deps chromium
45
+ python -m vac demo
46
+ ```
47
+
48
+ The demo starts and stops its own loopback fixture. It prints the selected check results and writes `vac-demo-report.html`, `vac-demo-report.sarif`, and `vac-demo-report.json` in the current directory. The synthetic demo has an expected API finding for support and an expected OCR finding for the viewer. Open the HTML file locally to view the role and field matrix alongside the redacted OCR match.
49
+
50
+ ## How it works
51
+
52
+ 1. **Policy** · A versioned contract specifies the field and the visibility allowed for a role.
53
+ 2. **Structured checks** · The runner inspects one fixture API response and visible text in the fixture's display cards.
54
+ 3. **Visual check** · Tesseract reads the fixture canvas or viewport image. The runner sends screenshots to OCR in memory and writes redacted text evidence for visual failures.
55
+ 4. **Reporting** · Console and JSON output show individual check results, distinct flagged cases, and cases flagged by one group while the other group passed.
56
+
57
+ ## Fixture coverage
58
+
59
+ | Case | API response | Visible DOM | OCR | Expected finding |
60
+ |---|---|---|---|---|
61
+ | A | Masked | Masked | Masked | All checks pass |
62
+ | B | Full value | Masked | Masked | API check flags the full value |
63
+ | C | Masked | Masked | Full value on canvas | OCR flags the value |
64
+ | D | Full value | Full value | Full value | API, DOM, and OCR checks flag the value |
65
+
66
+ In Case C, the HTML includes the synthetic chart label as character codes. The browser reconstructs the label and paints it on the canvas. The selected JSON response and visible DOM contain only the masked value. The full value is absent as literal text in the HTML and remains recoverable from the page script. The fixture measures what VAC's selected checks observe. Case D uses ordinary DOM text, which OCR reads from the viewport image.
67
+
68
+ ## Run the baseline
69
+
70
+ Use Python 3.12, Tesseract OCR, and Playwright Chromium. On Ubuntu, install Tesseract with `sudo apt-get install tesseract-ocr`.
71
+
72
+ ```bash
73
+ python -m venv .venv
74
+ source .venv/bin/activate
75
+ python -m pip install -e .
76
+ python -m playwright install chromium
77
+ ```
78
+
79
+ Start the fixture server in one terminal with `python -I fixtures/fixture_server.py`. In a second terminal with the same environment activated, run:
80
+
81
+ ```bash
82
+ python -I run_experiment.py --verify-fixtures
83
+ ```
84
+
85
+ The JSON report is written to `evidence/experiment_report.json`. The flag returns a failure if an expected fixture result differs or OCR is inconclusive. GitHub Actions uses this flag to verify the prototype. Running without it produces a reporting-only result.
86
+
87
+ ### Output and exit codes
88
+
89
+ ```bash
90
+ python -m vac check --contract examples/contract.yaml --json-stdout --quiet | jq .
91
+ ```
92
+
93
+ JSON is written to `vac-results.json` by default. `--json-stdout` sends the same report to stdout without writing a JSON file. SARIF and optional HTML output still go to files. `--quiet` prints one summary with the exit code to stderr, keeping stdout available for JSON.
94
+
95
+ | Code | Meaning |
96
+ | --- | --- |
97
+ | `0` | Checks passed with `--enforce`. In reporting mode, the run completed and outcomes are in the report. |
98
+ | `1` | With `--enforce`, at least one selected check found a violation or was inconclusive. |
99
+ | `2` | Contract, session, or run setup error. |
100
+
101
+ ## Adoption guides
102
+
103
+ - [Getting started](docs/getting-started.md)
104
+ - [Writing contracts](docs/writing-contracts.md)
105
+ - [CI integration](docs/ci-integration.md)
106
+ - [Launch post](docs/blog/launch.md)
107
+
108
+ ## Design-partner evaluation
109
+
110
+ The next milestone is a comparison with existing browser assertions on a broader synthetic evaluation set. Measure unique detections, false alerts, the fraction of regions OCR can verify, and time to locate the issue from the report. An approved staging pilot should follow once those results and evidence handling have been reviewed.
111
+
112
+ ## Run a multi-field, multi-role contract
113
+
114
+ The version 1 CLI takes an explicit YAML contract. See [the synthetic example](examples/contract.yaml) for two fields and three roles. For each configured role and scenario, VAC opens an isolated browser session, verifies the role on a caller-supplied identity endpoint, and reports the three checks independently per field.
115
+
116
+ ```bash
117
+ python -I vac_cli.py --contract examples/contract.yaml --report vac-results.json --sarif vac-results.sarif --html
118
+ ```
119
+
120
+ Use `--html` for the default `vac-results.html` file, or `--html path/to/report.html` for a custom path. Configure the origin, scenario paths, test role credentials, and field locators for your test application. The example targets the optional local mock app in `tests/session_app.py`. The implemented policy allows a full value or checks that a known synthetic numeric identifier is absent from the selected field where masking is required. A masked rule permits omission of the full value and does not validate exact mask formatting. An unavailable selected check is inconclusive. Use `--enforce` to fail CI on either a violation or an inconclusive check.
121
+
122
+ Authentication supports environment-backed bearer tokens and session cookies. The loopback-only SSO stub accepts a pre-issued synthetic session cookie. The identity endpoint must return `{"role": "<expected role>"}` for the current test session. Requests are limited to GET and HEAD on one configured origin, with cross-origin calls and redirects blocked. Keep credentials in CI secrets and use only synthetic records. Screenshots and inspected bodies stay in memory. Reports contain check metadata only.
123
+
124
+ ### GitHub Action
125
+
126
+ On an Ubuntu runner, check out the application repository and start its synthetic test environment in earlier steps. Run VAC from that checkout using the following step. For private cross-repository use, the VAC repository must be available to the caller via GitHub Actions access settings.
127
+
128
+ ```yaml
129
+ - name: Verify selected visibility checks
130
+ id: vac
131
+ uses: Anne07-Ai/visual-access-contract@v1
132
+ with:
133
+ contract: path/to/contract.yaml
134
+ enforce: "true"
135
+ env:
136
+ VAC_ADMIN_TOKEN: ${{ secrets.VAC_ADMIN_TOKEN }}
137
+ VAC_SUPPORT_COOKIE: ${{ secrets.VAC_SUPPORT_COOKIE }}
138
+
139
+ - name: Upload SARIF to GitHub code scanning
140
+ if: ${{ !cancelled() && hashFiles(steps.vac.outputs.sarif) != '' }}
141
+ uses: github/codeql-action/upload-sarif@v4
142
+ with:
143
+ sarif_file: ${{ steps.vac.outputs.sarif }}
144
+ ```
145
+
146
+ The optional upload step requires GitHub code scanning and `security-events: write` in the caller job. SARIF includes confirmed findings with their role, scenario and check type. The JSON report also records passes and inconclusive checks.
@@ -0,0 +1,131 @@
1
+ # Visual Access Contract
2
+
3
+ [![CI](https://github.com/Anne07-Ai/visual-access-contract/actions/workflows/contract-validation.yml/badge.svg)](https://github.com/Anne07-Ai/visual-access-contract/actions/workflows/contract-validation.yml)
4
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue)](LICENSE)
5
+ [![Python 3.12 or later](https://img.shields.io/badge/python-3.12%2B-blue)](pyproject.toml)
6
+
7
+ Visual Access Contract checks a versioned, role-specific masking rule against selected API responses, visible DOM text, and rendered pixels in CI. In our four-case synthetic experiment, OCR caught a canvas disclosure that the selected API and DOM checks missed, while API inspection caught a disclosure that never appeared on screen.
8
+
9
+ **Status** · Private engineering prototype for AppSec and QA teams. The current baseline covers one role, one field, and four synthetic scenarios. It uses a local fixture server and runs in reporting mode. The fixture results establish coverage for these scenarios. Coverage on customer applications and OCR accuracy across layouts still need validation.
10
+
11
+ ## Install from PyPI
12
+
13
+ After the first PyPI publication, install VAC with Python 3.12 or newer in a virtual environment. Install Tesseract with your system package manager.
14
+
15
+ ```bash
16
+ pip install visual-access-contract
17
+ python -m playwright install chromium
18
+ vac check --contract contract.yaml
19
+ ```
20
+
21
+ Use a schema 1.0 contract for `vac check`. See [Getting started](docs/getting-started.md) for an example.
22
+
23
+ ## Try it in 60 seconds
24
+
25
+ After installing Python 3.12 or later, run these three lines on Ubuntu from a terminal with access to the repository:
26
+
27
+ ```bash
28
+ git clone https://github.com/Anne07-Ai/visual-access-contract.git && cd visual-access-contract
29
+ python -m venv .venv && source .venv/bin/activate && sudo apt-get install -y tesseract-ocr && python -m pip install -e . && python -m playwright install --with-deps chromium
30
+ python -m vac demo
31
+ ```
32
+
33
+ The demo starts and stops its own loopback fixture. It prints the selected check results and writes `vac-demo-report.html`, `vac-demo-report.sarif`, and `vac-demo-report.json` in the current directory. The synthetic demo has an expected API finding for support and an expected OCR finding for the viewer. Open the HTML file locally to view the role and field matrix alongside the redacted OCR match.
34
+
35
+ ## How it works
36
+
37
+ 1. **Policy** · A versioned contract specifies the field and the visibility allowed for a role.
38
+ 2. **Structured checks** · The runner inspects one fixture API response and visible text in the fixture's display cards.
39
+ 3. **Visual check** · Tesseract reads the fixture canvas or viewport image. The runner sends screenshots to OCR in memory and writes redacted text evidence for visual failures.
40
+ 4. **Reporting** · Console and JSON output show individual check results, distinct flagged cases, and cases flagged by one group while the other group passed.
41
+
42
+ ## Fixture coverage
43
+
44
+ | Case | API response | Visible DOM | OCR | Expected finding |
45
+ |---|---|---|---|---|
46
+ | A | Masked | Masked | Masked | All checks pass |
47
+ | B | Full value | Masked | Masked | API check flags the full value |
48
+ | C | Masked | Masked | Full value on canvas | OCR flags the value |
49
+ | D | Full value | Full value | Full value | API, DOM, and OCR checks flag the value |
50
+
51
+ In Case C, the HTML includes the synthetic chart label as character codes. The browser reconstructs the label and paints it on the canvas. The selected JSON response and visible DOM contain only the masked value. The full value is absent as literal text in the HTML and remains recoverable from the page script. The fixture measures what VAC's selected checks observe. Case D uses ordinary DOM text, which OCR reads from the viewport image.
52
+
53
+ ## Run the baseline
54
+
55
+ Use Python 3.12, Tesseract OCR, and Playwright Chromium. On Ubuntu, install Tesseract with `sudo apt-get install tesseract-ocr`.
56
+
57
+ ```bash
58
+ python -m venv .venv
59
+ source .venv/bin/activate
60
+ python -m pip install -e .
61
+ python -m playwright install chromium
62
+ ```
63
+
64
+ Start the fixture server in one terminal with `python -I fixtures/fixture_server.py`. In a second terminal with the same environment activated, run:
65
+
66
+ ```bash
67
+ python -I run_experiment.py --verify-fixtures
68
+ ```
69
+
70
+ The JSON report is written to `evidence/experiment_report.json`. The flag returns a failure if an expected fixture result differs or OCR is inconclusive. GitHub Actions uses this flag to verify the prototype. Running without it produces a reporting-only result.
71
+
72
+ ### Output and exit codes
73
+
74
+ ```bash
75
+ python -m vac check --contract examples/contract.yaml --json-stdout --quiet | jq .
76
+ ```
77
+
78
+ JSON is written to `vac-results.json` by default. `--json-stdout` sends the same report to stdout without writing a JSON file. SARIF and optional HTML output still go to files. `--quiet` prints one summary with the exit code to stderr, keeping stdout available for JSON.
79
+
80
+ | Code | Meaning |
81
+ | --- | --- |
82
+ | `0` | Checks passed with `--enforce`. In reporting mode, the run completed and outcomes are in the report. |
83
+ | `1` | With `--enforce`, at least one selected check found a violation or was inconclusive. |
84
+ | `2` | Contract, session, or run setup error. |
85
+
86
+ ## Adoption guides
87
+
88
+ - [Getting started](docs/getting-started.md)
89
+ - [Writing contracts](docs/writing-contracts.md)
90
+ - [CI integration](docs/ci-integration.md)
91
+ - [Launch post](docs/blog/launch.md)
92
+
93
+ ## Design-partner evaluation
94
+
95
+ The next milestone is a comparison with existing browser assertions on a broader synthetic evaluation set. Measure unique detections, false alerts, the fraction of regions OCR can verify, and time to locate the issue from the report. An approved staging pilot should follow once those results and evidence handling have been reviewed.
96
+
97
+ ## Run a multi-field, multi-role contract
98
+
99
+ The version 1 CLI takes an explicit YAML contract. See [the synthetic example](examples/contract.yaml) for two fields and three roles. For each configured role and scenario, VAC opens an isolated browser session, verifies the role on a caller-supplied identity endpoint, and reports the three checks independently per field.
100
+
101
+ ```bash
102
+ python -I vac_cli.py --contract examples/contract.yaml --report vac-results.json --sarif vac-results.sarif --html
103
+ ```
104
+
105
+ Use `--html` for the default `vac-results.html` file, or `--html path/to/report.html` for a custom path. Configure the origin, scenario paths, test role credentials, and field locators for your test application. The example targets the optional local mock app in `tests/session_app.py`. The implemented policy allows a full value or checks that a known synthetic numeric identifier is absent from the selected field where masking is required. A masked rule permits omission of the full value and does not validate exact mask formatting. An unavailable selected check is inconclusive. Use `--enforce` to fail CI on either a violation or an inconclusive check.
106
+
107
+ Authentication supports environment-backed bearer tokens and session cookies. The loopback-only SSO stub accepts a pre-issued synthetic session cookie. The identity endpoint must return `{"role": "<expected role>"}` for the current test session. Requests are limited to GET and HEAD on one configured origin, with cross-origin calls and redirects blocked. Keep credentials in CI secrets and use only synthetic records. Screenshots and inspected bodies stay in memory. Reports contain check metadata only.
108
+
109
+ ### GitHub Action
110
+
111
+ On an Ubuntu runner, check out the application repository and start its synthetic test environment in earlier steps. Run VAC from that checkout using the following step. For private cross-repository use, the VAC repository must be available to the caller via GitHub Actions access settings.
112
+
113
+ ```yaml
114
+ - name: Verify selected visibility checks
115
+ id: vac
116
+ uses: Anne07-Ai/visual-access-contract@v1
117
+ with:
118
+ contract: path/to/contract.yaml
119
+ enforce: "true"
120
+ env:
121
+ VAC_ADMIN_TOKEN: ${{ secrets.VAC_ADMIN_TOKEN }}
122
+ VAC_SUPPORT_COOKIE: ${{ secrets.VAC_SUPPORT_COOKIE }}
123
+
124
+ - name: Upload SARIF to GitHub code scanning
125
+ if: ${{ !cancelled() && hashFiles(steps.vac.outputs.sarif) != '' }}
126
+ uses: github/codeql-action/upload-sarif@v4
127
+ with:
128
+ sarif_file: ${{ steps.vac.outputs.sarif }}
129
+ ```
130
+
131
+ The optional upload step requires GitHub code scanning and `security-events: write` in the caller job. SARIF includes confirmed findings with their role, scenario and check type. The JSON report also records passes and inconclusive checks.
File without changes
@@ -0,0 +1,175 @@
1
+ """
2
+ Structured Data Check (Check 1)
3
+ Inspects the API response and page DOM for field values that violate
4
+ the access contract. No vision — pure text/data matching.
5
+
6
+ Returns a CheckResult with pass/fail and what was found.
7
+ """
8
+
9
+ import re
10
+ from dataclasses import dataclass, field
11
+ from typing import Optional
12
+
13
+
14
+ @dataclass
15
+ class CheckResult:
16
+ check_type: str
17
+ case: str
18
+ role: str
19
+ rule_id: str
20
+ status: str # "pass", "fail", "inconclusive"
21
+ detail: str
22
+ found_values: list = field(default_factory=list)
23
+ inspected_sources: list = field(default_factory=list)
24
+
25
+
26
+ def build_patterns(contract_rule: dict) -> list:
27
+ """Build regex patterns from the synthetic values in the contract.
28
+
29
+ For a masked rule, we look for the FULL value — if it's present,
30
+ the check fails. We also verify the masked/last-4 value is present
31
+ where expected.
32
+ """
33
+ full_value = contract_rule["synthetic_values"]["full"]
34
+ # Escape for regex and allow flexible separators (dash, space, none)
35
+ digits = re.sub(r"[^0-9]", "", full_value)
36
+ # Match the full number with any separator style
37
+ flexible = r"[\s\-\.]*".join(digits)
38
+ return [re.compile(flexible)]
39
+
40
+
41
+ def check_api_response(
42
+ response_body: str,
43
+ contract_rule: dict,
44
+ role: str,
45
+ case: str,
46
+ ) -> CheckResult:
47
+ """Check whether the API response contains a value that violates
48
+ the contract for the given role."""
49
+
50
+ rule_id = contract_rule["id"]
51
+ role_config = contract_rule["roles"].get(role)
52
+
53
+ if not role_config:
54
+ return CheckResult(
55
+ check_type="structured",
56
+ case=case,
57
+ role=role,
58
+ rule_id=rule_id,
59
+ status="inconclusive",
60
+ detail=f"Role '{role}' not defined in contract rule {rule_id}",
61
+ inspected_sources=["api_response"],
62
+ )
63
+
64
+ if role_config["visibility"] == "full":
65
+ # This role is allowed to see everything — always passes
66
+ return CheckResult(
67
+ check_type="structured",
68
+ case=case,
69
+ role=role,
70
+ rule_id=rule_id,
71
+ status="pass",
72
+ detail="Role has full visibility — no restriction to enforce",
73
+ inspected_sources=["api_response"],
74
+ )
75
+
76
+ # Role should see masked only — check if full value is present
77
+ patterns = build_patterns(contract_rule)
78
+ full_value = contract_rule["synthetic_values"]["full"]
79
+ found = []
80
+
81
+ for pattern in patterns:
82
+ matches = pattern.findall(response_body)
83
+ for match in matches:
84
+ found.append(match)
85
+
86
+ if found:
87
+ return CheckResult(
88
+ check_type="structured",
89
+ case=case,
90
+ role=role,
91
+ rule_id=rule_id,
92
+ status="fail",
93
+ detail=(
94
+ f"Full value found in API response for role '{role}' "
95
+ f"which should only see {role_config['visibility']} "
96
+ f"({role_config.get('mask_format', 'masked')})"
97
+ ),
98
+ found_values=[_redact(v) for v in found],
99
+ inspected_sources=["api_response"],
100
+ )
101
+
102
+ return CheckResult(
103
+ check_type="structured",
104
+ case=case,
105
+ role=role,
106
+ rule_id=rule_id,
107
+ status="pass",
108
+ detail=f"Full value not found in API response — masking intact",
109
+ inspected_sources=["api_response"],
110
+ )
111
+
112
+
113
+ def check_dom_text(
114
+ page_text: str,
115
+ contract_rule: dict,
116
+ role: str,
117
+ case: str,
118
+ ) -> CheckResult:
119
+ """Check whether visible DOM text contains a value that violates
120
+ the contract for the given role."""
121
+
122
+ rule_id = contract_rule["id"]
123
+ role_config = contract_rule["roles"].get(role)
124
+
125
+ if not role_config or role_config["visibility"] == "full":
126
+ return CheckResult(
127
+ check_type="structured_dom",
128
+ case=case,
129
+ role=role,
130
+ rule_id=rule_id,
131
+ status="pass",
132
+ detail="Role has full visibility or is undefined",
133
+ inspected_sources=["dom_text"],
134
+ )
135
+
136
+ patterns = build_patterns(contract_rule)
137
+ found = []
138
+
139
+ for pattern in patterns:
140
+ matches = pattern.findall(page_text)
141
+ for match in matches:
142
+ found.append(match)
143
+
144
+ if found:
145
+ return CheckResult(
146
+ check_type="structured_dom",
147
+ case=case,
148
+ role=role,
149
+ rule_id=rule_id,
150
+ status="fail",
151
+ detail=(
152
+ f"Full value found in DOM text for role '{role}' "
153
+ f"which should only see {role_config['visibility']}"
154
+ ),
155
+ found_values=[_redact(v) for v in found],
156
+ inspected_sources=["dom_text"],
157
+ )
158
+
159
+ return CheckResult(
160
+ check_type="structured_dom",
161
+ case=case,
162
+ role=role,
163
+ rule_id=rule_id,
164
+ status="pass",
165
+ detail="Full value not found in visible DOM text",
166
+ inspected_sources=["dom_text"],
167
+ )
168
+
169
+
170
+ def _redact(value: str) -> str:
171
+ """Redact a found value for the evidence report.
172
+ Keep only the last 4 characters visible."""
173
+ if len(value) <= 4:
174
+ return value
175
+ return "*" * (len(value) - 4) + value[-4:]