Metadata-Version: 2.4
Name: iot-fixturekit
Version: 0.1.0a9
Summary: Local-first, schema-driven IoT diagnostic fixture tooling
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/FlyzDev/fixturekit
Project-URL: Issues, https://github.com/FlyzDev/fixturekit/issues
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: pytest
Requires-Dist: pytest>=7; extra == "pytest"
Dynamic: license-file

# IoT FixtureKit

**Experimental local-first tooling for converting IoT diagnostics into
reproducible test fixtures.** The core runs offline, with no telemetry or automatic uploads. Optional lab setup can fetch public dependencies and source checkouts.

Home Assistant integration authors frequently need real device behavior to
write regression tests. Different projects maintain their own diagnostic-to-fixture
workflows. This experiment tests whether an explicit projection engine can reduce
that maintenance without replacing their existing protocol libraries or tests.

**Published alpha preview (0.1.0a8); source candidate (0.1.0a9, unreleased).** Independent security review is pending.
No privacy certification or upstream endorsement is claimed.

## Install the published alpha

In a virtual environment (Python 3.9+):

    python -m pip install iot-fixturekit==0.1.0a8

For optional pytest integration:

    python -m pip install "iot-fixturekit[pytest]==0.1.0a8"

[PyPI](https://pypi.org/project/iot-fixturekit/0.1.0a8/) ·
[GitHub release files and SHA256 checksums](https://github.com/FlyzDev/fixturekit/releases/tag/v0.1.0a8).
Both distribution hashes match the published GitHub release.

## Start here

See the [current quickstart](https://github.com/FlyzDev/fixturekit/blob/main/QUICKSTART.md) for a first audit without Git or uv, then the bundled consumer demo; see [CONTRIBUTING.md](CONTRIBUTING.md) for pilot feedback.
Inspect the [recorded Studio demo](https://flyzdev.github.io/fixturekit/studio-demo/) before installing anything. It contains four synthetic reports from a completed first-party CI run, not live results. The separate [extended demo](https://flyzdev.github.io/fixturekit/studio-extended-demo/) records 47 checks from a first-party Linux CI execution with hash-checked HA candidates, including optional network pilots.

See the [public roadmap](ROADMAP.md) and [beta readiness gates](BETA_READINESS.md) for current priorities and release criteria. The [compatibility contract](COMPATIBILITY.md) describes current formats and migration discipline; the [threat model](THREAT_MODEL.md) explains trust and resource boundaries.
Try the optional [offline HTTP replay example](examples/replay/README.md) with VCR.py.
See also the optional [DeepDiff comparison example](examples/diff/README.md)
and [disposable Home Assistant virtual-device lab](examples/ha-lab/README.md).
The [shared climate scenarios](examples/scenario/README.md) combines
these engines in two experimental workflows: unavailable/recovery and frozen sensor/recovery.
Run the bundled lab with [one command](examples/scenario/README.md#run-the-lab-in-one-command) and get a structured JSON report.
Run the four supported synthetic observations and generate a combined dashboard with the [Studio unified runner](examples/studio/README.md#run-the-complete-studio-catalog). Optional Studio setup fetches pinned public sources and dependencies; the core remains offline.
For real loopback TCP faults, see the optional [Toxiproxy network chaos pilot](examples/network-chaos/README.md).
Try the [offline switch consumer replay](examples/tplink-replay/README.md) to use recorded synthetic observations with the pytest hook without installing Home Assistant.
For an actual bundled Home Assistant integration using a synthetic loopback plug, see the separate [TP-Link switch lifecycle research pilot](examples/tplink-lifecycle/README.md). It is restricted to Linux/macOS and a pinned pre-release Home Assistant environment; it is not part of the published Core or accepted Studio catalog.

## Run the synthetic demo

Python 3.9+; no runtime dependencies.

    PYTHONPATH=src python3 -m iot_fixturekit.cli examples/synthetic-diagnostics.json --policy examples/synthetic-policy.json --profile demo

    PYTHONPATH=src python3 -m unittest discover -s tests -v

Unknown object fields are excluded. Selected strings must match declared enum
values. Numbers require explicit bounds. Invalid input is rejected.
The complete projection policy is validated before use, even for empty arrays.
Policies are limited to 64 nested levels and 10,000 rules.
The projection engine additionally limits a projection to 200,000 emitted JSON
values across all containers, including repeated input references. This is
a node-count limit, not a byte-size or execution-time guarantee.
The CLI also limits serialized ASCII JSON to 8 MiB, including
the logical final newline. It rejects oversized output before writing. These
defensive limits are not a complete memory or time isolation guarantee.
The output is versioned and deterministic.

## Important security boundary

This is NOT a complete anonymizer, secret scanner, or privacy guarantee.
A poorly designed policy can retain sensitive values, keys or measurements.
Review policy semantics and output locally before sharing. Do not commit raw
diagnostics, credentials, real device identifiers or customer data. No live
device adapters are implemented yet. All examples are synthetic.

## Pilot validation

Start with maintainer-approved, narrowly scoped adapters for existing fixture
workflows. Do not request upstream adoption until compatibility and maintenance
benefit have been demonstrated. Research notes are maintained separately in the repository.

## Fixture audit (experimental)

Run on an already-reviewed candidate fixture, not as a replacement for redaction:

    PYTHONPATH=src python3 -m iot_fixturekit.audit --profile tuya examples/synthetic-tuya-fixture.json

Generic mode checks JSON/HAR structures and plain-text patterns (including XML).
Tuya mode additionally checks selected requirements documented by Tuya Device
Handlers. Reports contain file ordinals, rule IDs and line numbers (0 for JSON
structural checks), not paths or matched values. Exit 0 means no findings, 1
means findings, 2 means an input error. A clean result does NOT certify privacy.
Unknown secrets, encoded strings, device identifiers and context-specific
sensitive measurements may remain. Generic mode does not parse XML or JSONL
structurally. No upstream adoption is claimed.

## Tuya diagnostics adapter (experimental)

Create a **local review candidate**, not a publication-ready fixture:

    mkdir -p raw/review
    PYTHONPATH=src python3 -m iot_fixturekit.tuya examples/synthetic-tuya-diagnostics.json --output-dir raw/review

The adapter follows the documented Tuya Device Handlers extraction convention:
it selects the diagnostics data object, drops account-specific root keys,
blanks device_info, preserves functional datapoints and preserves the case of
the product ID. Filename components are restricted to safe alphanumeric forms.
The candidate is audited before writing, created with exclusive access (no
overwrite) and restrictive POSIX permissions. Review every field manually
before sharing; unknown datapoints, device names, timestamps and encoded values
may still contain personal data. The CLI never prints candidate values.
Exit 1 indicates audit findings; exit 2 indicates invalid input or write failure.
The ignored raw/ folder is recommended for private local work.

## GitHub Actions consumer template

Copy the [hash-pinned CI starter](examples/ci/fixture-audit.yml) into your
project and adapt its reviewed fixture directory. See [setup notes](examples/ci/README.md).

## Pytest integration

Install the package with its optional pytest extra. The pytest entry point
automatically registers the callable fixture:

```python
def test_device_fixture(iot_fixture_check):
    iot_fixture_check("tests/fixtures/device.json", profile="tuya")
```

Use the default generic profile for other devices. Explicitly parametrize the
files you want checked; there is no automatic repository-wide scanning.
The plugin uses the same file audit as the CLI and reports only rule IDs.
Avoid pytest options or custom plugins that dump sensitive local variables.

## Pre-commit integration

For a local checkout of the package, use a local hook after installing it in
the environment running pre-commit:

```yaml
repos:
  - repo: local
    hooks:
      - id: iot-fixture-audit
        name: Audit IoT test fixtures
        entry: iot-fixture-audit
        language: system
        types: [text]
        files: '(^|/)(fixtures|golden)/.*\.(json|har|xml|jsonl|log|txt)$'
```

Consumers can also use the public hook pinned to the alpha release:

```yaml
repos:
  - repo: https://github.com/FlyzDev/fixturekit
    rev: v0.1.0a8
    hooks:
      - id: iot-fixture-audit
```

See the [pre-commit quickstart](QUICKSTART.md#check-fixtures-before-committing)
for installation, targeted execution and expected results. Restrict the file
pattern to reviewed fixture directories; use separate hooks with
`args: [--profile, tuya]` where appropriate. No findings is not a privacy
guarantee, and a hook is not a substitute for human review.

## Project-specific placeholder policies (experimental)

Some libraries intentionally preserve synthetic MAC addresses in test fixtures.
Use an explicitly reviewed JSON policy, such as
`examples/synthetic-placeholder-policy.json`, with the audit CLI:

    iot-fixture-audit --policy examples/synthetic-placeholder-policy.json tests/fixtures/device.json

Pytest accepts the same file through `policy_path`; pre-commit can pass
`args: [--policy, path/to/policy.json]` on a JSON-only hook.
For Python callers, pass the parsed policy via the keyword-only `policy`
argument to `audit_json` or `audit_file`.

Version 1 supports exact typed JSON paths and exact full colon-delimited MAC
placeholder values only. Integer path segments select array indexes; strings
select object keys. No wildcard or regex exemptions, no credential-rule
exemptions, and no exemption of object keys or Tuya structural checks.
Policies are opt-in; the Tuya conversion CLI retains its original strict audit.
Text formats do not accept policies. Keep policy files human-reviewed and use
only known synthetic values, never actual device addresses. A policy is not
evidence that a fixture is safe to publish.

Audit inputs are limited to 8 MiB per file, 64 nested path segments and
200,000 visited JSON nodes (including object keys). The JSON audit rejects
non-finite numbers, unsupported Python values and unpaired Unicode surrogates.
These are defensive limits, not a complete resource-isolation guarantee.

Text audit additionally limits input to 8,388,608 characters and output to
4,096 distinct line/rule findings per audit_text call. Exceeding a limit
is an input error, never a clean scan. Email and JWT matching starts at
token boundaries to avoid repeatedly scanning long runs of punctuation
or token characters. These heuristics can miss unusual or embedded values.

## License

Apache License 2.0. See LICENSE.

## Tuya loader compatibility pilot

A generated synthetic fixture was successfully loaded by the pinned upstream
Tuya Device Handlers test helper using the published alpha. See
[the reproducible pilot](examples/pilot/TUYA.md) for the exact scope and checks.

## Overkiz profile (experimental)

The opt-in JSON profile checks selected exact state names for unmasked
values, including serial numbers, network identifiers and HomeKit setup
states. It recognizes limited mask-only strings and explicit redaction
placeholders; it does not validate all Overkiz fields or prove privacy.
Use the upstream obfuscator first. Generic mode is unchanged.

    iot-fixture-audit --profile overkiz tests/fixtures/setup/device.json

Pytest accepts profile="overkiz", and JSON pre-commit hooks can pass
args: [--profile, overkiz]. MAC placeholder exceptions do not suppress
semantic state findings. This profile was introduced in alpha 2.

## Overkiz post-obfuscation pilot

The published alpha was tested as an additional non-mutating check after
the pinned pyoverkiz obfuscator. See [the pilot and its known gap](examples/pilot/OVERKIZ.md).

## Synthetic consumer pilot

The examples/pilot directory illustrates a fixture convention used by a
device library: a fixed synthetic Wi-Fi MAC placeholder at status.wifi.mac.
The example is independently constructed, incomplete and not an upstream
fixture or a compatibility guarantee.

After installing the package in a separate project, a JSON-only pre-commit
hook can pass the checked-in policy path as an argument:

```yaml
repos:
  - repo: local
    hooks:
      - id: fixturekit
        name: FixtureKit audit
        entry: iot-fixture-audit
        language: system
        args: [--policy, examples/pilot/shelly-style-policy.json]
        files: '^tests/fixtures/.*\.json$'
```

Use the matching policy in pytest via policy_path. Keep policies under human
review and do not apply the exception globally. This supplements, rather
than replaces, device-library redactors. See the four pilot integration tests.

### Kasa/Tapo pairing-field pilot

The opt-in `kasa` profile checks selected pairing-related fields after upstream
masking. See the [synthetic pilot and compatibility evidence](examples/pilot/KASA.md).
No comprehensive device schema or privacy
guarantee is claimed.

### PyISYox response pilot

The opt-in `pyisyox` profile checks whether the upstream-sensitive
`ssl` JSON field has been masked. See the [synthetic pilot](examples/pilot/PYISYOX.md).
Generic checks and manual review
remain necessary.

### Plugwise XML pilot

The opt-in `plugwise` profile checks documented XML placeholder values
using bounded XML parsing. See the [synthetic pilot](examples/pilot/PLUGWISE.md).
Keep upstream checks and manual review.

## Optional projection fields (alpha 5)

Object rules retain required keys listed in `fields` and may additionally
declare `optional_fields`. Missing optional values are omitted; present
values must satisfy the declared rule, including null or malformed inputs.
Unknown keys are excluded. Required and optional names must not overlap.
No implicit conversion or default is applied.

    iot-fixturekit examples/pilot/mixed-events.json --policy examples/pilot/mixed-events-policy.json --profile events

See [mixed-event example](examples/pilot/MIXED_EVENTS.md). This extension is available in alpha 5.

### Embedded URI credentials (alpha 6)

A narrow additional rule detects nonempty username/password authorities in
HTTP(S), RTSP(S), MQTT(S), Tapo, FTP(S) and SFTP URLs. Findings report only
the rule identifier and location; no matched URI or credential is printed.
This is a bounded heuristic, not a URL parser or complete secret scanner.
It does not cover arbitrary schemes, query-string credentials, username-only
authorities or every unusual encoding. Available in released alpha 6.

## Documentation index

[Plain-text documentation index](llms.txt) with links to released features, examples and limitations.
