|
| 1 | +# Tool Contract Deduplication Audit |
| 2 | + |
| 3 | +PR: PR_26152_074-tool-contract-deduplication-audit |
| 4 | +Date: 2026-06-02 |
| 5 | + |
| 6 | +## Scope |
| 7 | + |
| 8 | +- Audited current contract structure after PR_26152_073 split tool contracts by tool. |
| 9 | +- Limited changes to `src/shared/contracts/`, `src/shared/contracts/tools/`, contract tests validation, and reports. |
| 10 | +- No runtime code, UI, CSS, HTML, or non-contract JavaScript changed. |
| 11 | +- Per-tool contract files remain split and were not merged into one file. |
| 12 | + |
| 13 | +## Structure Reviewed |
| 14 | + |
| 15 | +| Area | Result | |
| 16 | +|---|---| |
| 17 | +| `identityPermissionsContract.js` | Identity roles, permissions, scopes, and visibility states remain shared primitives. | |
| 18 | +| `projectContract.js` | Project roles, visibility, access rules, and state validation remain shared primitives. | |
| 19 | +| `toolStateContract.js` | Tool State ownership, visibility, status, versioning, recovery, and exportability remain shared primitives. | |
| 20 | +| `assetContract.js` | Generic asset ownership, status, visibility, metadata, type, and export behavior remain shared primitives. | |
| 21 | +| `paletteContract.js` | Palette-specific swatch validation and portable export behavior remain shared primitives. | |
| 22 | +| `vectorAssetContract.js` | Vector asset validation and portable export behavior remain shared primitives. | |
| 23 | +| `toolContractPrimitives.js` | Owns tool contract defaults, validation, ownership, visibility, access, export/import format validation, and shared asset-type/status declaration helpers. | |
| 24 | +| `contracts/tools/*.js` | Remain per-tool declarations only, with unique tool inputs/outputs/type/assets/import/export data. | |
| 25 | + |
| 26 | +## Duplication Findings |
| 27 | + |
| 28 | +| Category | Before | After | Action | |
| 29 | +|---|---:|---:|---| |
| 30 | +| Per-tool contract files | 34 | 34 | Preserved split per-tool modules. | |
| 31 | +| Matching per-tool tests | 34 | 34 | Preserved tool-by-tool coverage. | |
| 32 | +| `supportedAssetTypes: []` duplicated in tool files | 13 | 0 | Replaced with `TOOL_CONTRACT_SUPPORTED_ASSET_TYPES.NONE`. | |
| 33 | +| `Object.values(ASSET_TYPES)` duplicated in tool files | 5 | 0 | Replaced with `TOOL_CONTRACT_SUPPORTED_ASSET_TYPES.ALL`. | |
| 34 | +| `status: TOOL_CONTRACT_STATUS.DRAFT` duplicated in tool files | 11 | 0 | Replaced with `createDraftToolContract(...)`. | |
| 35 | +| Duplicated ownership rules in tool files | 0 | 0 | Ownership remains in `createToolContract`. | |
| 36 | +| Duplicated visibility rules in tool files | 0 | 0 | Visibility/access remains in `toolContractPrimitives.js`. | |
| 37 | +| Duplicated validation logic in tool files | 0 | 0 | Validation remains in `validateToolContract` and shared test helper. | |
| 38 | +| Duplicated portable export/import validation | 0 | 0 | Portable export/import validation remains in `toolContractPrimitives.js`. | |
| 39 | + |
| 40 | +## Per-Tool Audit |
| 41 | + |
| 42 | +| Tool Contract Group | Unique Tool Data | Deduplicated Data | Validation/Ownership/Visibility | |
| 43 | +|---|---|---|---| |
| 44 | +| Active registered tools | `toolId`, `toolType`, inputs, outputs, asset types, import/export formats | Empty/all supported asset declarations where applicable | Shared through `toolContractPrimitives.js`. | |
| 45 | +| Root Tools Index planning contracts | `toolId`, `toolType`, inputs, outputs, asset types, import/export formats | Draft status, empty/all supported asset declarations where applicable | Shared through `toolContractPrimitives.js`. | |
| 46 | +| Tool contract index | Contract aggregation and root-card coverage mapping | No validation logic added | Lookup and coverage only; per-tool declarations stay split. | |
| 47 | +| Per-tool tests | Expected tool id per module | Repeated assertions remain in `toolContractTestHelpers.mjs` | Matching one test per tool preserved. | |
| 48 | + |
| 49 | +## Shared Primitive Ownership Summary |
| 50 | + |
| 51 | +`src/shared/contracts/toolContractPrimitives.js` now owns: |
| 52 | + |
| 53 | +- default tool contract owner/project identifiers |
| 54 | +- default visibility/status/version behavior |
| 55 | +- `createToolContract` |
| 56 | +- `createDraftToolContract` |
| 57 | +- `TOOL_CONTRACT_SUPPORTED_ASSET_TYPES.ALL` |
| 58 | +- `TOOL_CONTRACT_SUPPORTED_ASSET_TYPES.NONE` |
| 59 | +- tool type/status/visibility/format validators |
| 60 | +- source tool state validation |
| 61 | +- actor visibility/access checks |
| 62 | +- archived edit policy checks |
| 63 | +- portable tool contract export creation and validation |
| 64 | + |
| 65 | +Per-tool contract modules own only the data that distinguishes that tool: |
| 66 | + |
| 67 | +- `toolId` |
| 68 | +- `toolType` |
| 69 | +- `requiredInputs` |
| 70 | +- `producedOutputs` |
| 71 | +- `supportedAssetTypes` |
| 72 | +- `importFormats` |
| 73 | +- `exportFormats` |
| 74 | + |
| 75 | +## Behavior Invariance |
| 76 | + |
| 77 | +- No tool contract was removed. |
| 78 | +- No tool contract id changed. |
| 79 | +- No per-tool coverage test was removed. |
| 80 | +- No validation, ownership, visibility, access, status, import, or export rule changed. |
| 81 | +- All changed contract outputs remain covered by the same targeted contract test suite. |
| 82 | + |
| 83 | +## Validation |
| 84 | + |
| 85 | +```powershell |
| 86 | +$rootContractTests = Get-ChildItem -Path tests/shared -Filter '*Contract.test.mjs' | Sort-Object Name | ForEach-Object { $_.FullName } |
| 87 | +$toolContractTests = Get-ChildItem -Path tests/shared/tools -Filter '*.test.mjs' | Sort-Object Name | ForEach-Object { $_.FullName } |
| 88 | +node ./scripts/run-node-test-files.mjs $rootContractTests $toolContractTests |
| 89 | +``` |
| 90 | + |
| 91 | +Result: PASS, 41/41 targeted node test files passed. |
| 92 | + |
| 93 | +## Lane Report |
| 94 | + |
| 95 | +- Lanes executed: contract lane for shared contracts and tool contract declarations. |
| 96 | +- Lanes skipped: runtime, integration, engine, samples, recovery/UAT because this PR changes only contract declarations/primitives and reports. |
| 97 | +- Samples decision: SKIP because samples are out of scope and no sample JSON or runtime behavior changed. |
| 98 | +- Playwright impacted: No. This PR changes contract primitives/declarations only and does not change browser UI or runtime behavior. |
| 99 | +- Blocker scope: targeted contract lane only. |
| 100 | + |
| 101 | +## Manual Validation |
| 102 | + |
| 103 | +- Confirm `src/shared/contracts/tools/` still contains one contract module per tool/control. |
| 104 | +- Confirm `tests/shared/tools/` still contains one matching test per tool/control plus shared coverage/helper tests. |
| 105 | +- Confirm no runtime, UI, CSS, HTML, samples, games, or non-contract tool files changed. |
0 commit comments