openpetswithchatandmcp/apps/desktop/contracts/codemap.md
OpenPets Dev 6ab3bb64d8 feat(rebrand): rename OpenPets to FamiliarOS and pets to familiars
- Rename all user-facing and technical identifiers from OpenPets/Pet to FamiliarOS/Familiar.
- Rename packages from @open-pets/* to @familiaros/*; rename install-pet/pet-format packages.
- Rename plugin IDs and directories from openpets.* to familiaros.*.
- Rename IPC namespace from openpets:* to familiaros:* and state filenames from openpets-* to familiaros-* with legacy migration.
- Rename source files (pet-window, built-in-pet, default-pet-controller, etc.) to familiar equivalents.
- Update locales (en, es-419, ja, ko, pt-BR, zh-Hans, zh-Hant) and tray/pet context menu strings.
- Add Familiar naming feature: preference, settings input, tray menu display.
- Update assets and packaging config; all desktop tests pass.
2026-06-17 01:42:08 +00:00

2.9 KiB

apps/desktop/contracts/

Responsibility

Public API boundary contract tests for the FamiliarOS desktop application. These contracts validate that critical external-facing interfaces (catalog data, IPC protocol) conform to expected schemas and behavior. Contract tests are compiled to .test-dist/contracts/ and executed during pnpm test.

Design Patterns

  • Schema Validation Contracts: Test catalog and plugin manifest validation logic against valid fixtures plus targeted invalid cases
  • Protocol Contracts: Verify IPC request/response parsing, token validation, and message constraints
  • Fixture-Based Testing: Uses real fixture data (catalog.v2.fixture.json) to ensure validation matches production data
  • Negative Testing: Includes invalid cases to ensure proper rejection of malformed data
  • Standalone Execution: Each contract file is executable Node.js code that runs independently

Data & Control Flow

Catalog Fixture Contract (catalog-fixture.contract.ts):

Load catalog.v2.fixture.json → validateCatalogV2() → Assert valid
→ Test invalid cases (bad IDs, duplicates, HTTP URLs, wrong hosts, reserved IDs)
→ Assert each invalid case is properly rejected

Local IPC Protocol Contract (local-ipc-protocol.contract.ts):

Test parseIpcRequest() with valid/invalid tokens, versions, methods
→ Test validateReaction() with valid/invalid reaction types
→ Test validateSayMessage() with valid/invalid messages (length, newlines, code blocks, URLs, paths, secrets)
→ Test maxIpcMessageBytes boundary
→ Test errorResponse() structure

Plugin Manifest Contract (plugin-manifest.contract.ts):

Assert familiaros.plugin.json filename constant
→ Validate a declarative timer manifest with permissions, config schema, and familiar actions
→ Test config references, unknown fields, runtime/permission constraints, deferred config types/features, defaults, options, timer intervals, and required permissions
→ Assert each invalid manifest reports the expected error code

Integration Points

  • Source modules: Imports from ../src/catalog-validation.js, ../src/local-ipc-protocol.js, ../src/plugin-manifest.js
  • Fixture data: catalog.v2.fixture.json in parent directory
  • Test runner: Executed by scripts/run-tests.mjs in the contract tests phase
  • Build output: Compiled to .test-dist/contracts/*.contract.js via tsconfig.tests.json

Key Contracts

  • catalog-fixture.contract.ts: Validates catalog V2 schema against fixture and invalid cases (duplicate IDs, bad URL schemes, wrong hosts, reserved "builtin" ID)
  • local-ipc-protocol.contract.ts: Validates IPC protocol parsing, token auth, reaction types, message constraints, and error response formatting
  • plugin-manifest.contract.ts: Validates plugin manifest filename, declarative timer manifest schema, permission requirements, config references, action constraints, and expected validation error codes