[PR #2463] [CLOSED] fix(mcp): accept HarmonyOS package formats in session target output #5246

Closed
opened 2026-10-31 01:05:08 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/2463
Author: @zktufo
Created: 10/13/2026
Status: ❌ Closed

Base: main ← Head: fix/harmony-session-output-formats


📝 Commits (1)

  • e275fd4 fix(mcp): accept HarmonyOS package formats in session target output

📊 Changes

2 files changed (+76 additions, -0 deletions)

View changed files

📝 src/contracts/toolOutputSchemaPrimitives.ts (+3 -0)
➕ tests/boundary/mcp/harmonySessionFormatsMcp.test.ts (+73 -0)

📄 Description

Summary

Fixes finding D09 of #2454. A HarmonyOS root (.hap, .hsp, or the .app App Pack) opens successfully in a session, but the MCP session tools then reject their own result: the shared target-format enum behind the session output contract omitted all three formats, so open_binary returned Output validation error: Invalid structured content for tool open_binary: result.format: Invalid discriminator value. while the target was already active and inspect_artifact worked.

This PR adds the three formats to the owning shared enum. It does not close #2454: the remaining findings of that audit are untouched and can follow as separate changes.

Problem and expected behavior

Smallest trigger: write any ZIP archive ending in .hap and open it through the session opener.

Output validation error: Invalid structured content for tool open_binary:
result.format: Invalid discriminator value. Expected 'hopper' | 'analysis-database' |
'mach-o' | 'mach-o-universal' | 'elf' | 'pe' | 'dos-mz' | 'dos-com' | 'zip' | 'ipa' |
'apk' | 'msix' | 'appx' | 'asar' | 'dmg' | 'pkg' | 'plist' | 'javascript' |
'source-map' | 'raw-binary'

Violated invariant: every target format the classifier can produce must be representable in the shared session output contract that validates it. Detection and admission succeeded; only the result projection rejected the observation.

Change and scope

Add hap, hsp and app-pack to targetFormatSchema in src/contracts/toolOutputSchemaPrimitives.ts, inserted after appx to mirror the domain enumeration's order. That enum is the owner behind detectedLifecycleTargetSchema, which both sessionOutputSchemas.open_binary and sessionOutputSchemas.binary_session consume.

Why this fits: every other format enumeration in the repository already carries the three — the domain formatSchema (src/domain/analysisSnapshot.ts), src/domain/artifactGraph.ts, src/domain/evidence.ts, src/domain/binaryTargetTypes.ts, src/domain/zipPackageFormat.ts and HARMONY_ROOT_FORMATS in src/domain/harmony/harmonyApplication.ts. Only the contracts enum was behind, so this restores the contract to the classification it validates rather than widening admission.

Intentionally not included: detection changes, inventory/projection changes, CLI changes, and the other eleven findings of #2454.

Contribution scope: not applicable (an ordinary fix within existing boundaries).

Contract and boundary impact

  • Semantic owner and earliest changed stage: targetFormatSchema (shared session output contract) — result projection and validation, after detection and admission already succeeded. BinaryTargetResolver, zipPackageFormatForPath and the .app root rule are unchanged.

  • Contribution scope fit and linked maintainer decision: not applicable.

  • CLI and MCP/tool-catalog contract: MCP open_binary and binary_session structured output now validate for the three formats. No tool input, catalog or CLI contract change; npm run mcp-catalog:check passes unchanged.

  • Provider, bridge, target-format, or platform compatibility: only additional format families are accepted; every existing format is unchanged. No provider, bridge or platform surface is touched.

  • Evidence, artifact, provenance, or reconstruction contract: none — the field enumerates a format string the pipeline already produced.

  • Target selection, authority, upstream behavior, and cleanup details: not applicable.

  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none; npm run docs:check and npm run mcp-catalog:check both pass, and no ignored output was committed.

  • Read existing files or captured data.

  • Launch or attach to a process.

  • Inject instrumentation or run scripts/code.

  • Change process memory, registers, files, or configuration.

  • Contact network services.

  • Recover protected code or work around protections.

  • Documentation or usability only; no target interaction.

  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/mcp/harmonySessionFormatsMcp.test.ts (new). Three cases, one per root format, each opening a synthetic ZIP-backed root through the real in-memory MCP session server and asserting that both open_binary and binary_session succeed and report the detected format.
  • Base reproduction or other evidence: with the source fix stashed and the test kept, all three cases fail on the unfixed base with the quoted output-validation error. With the fix, 3/3 pass.
  • User-visible CLI/MCP output (if applicable): the error text above is the observed result on the unfixed base; after the change the tools return their normal result envelope with format set to hap, hsp or app-pack.
  • Remaining proof gaps: the real-pipeline Harmony lane (npm run verify:harmony) requires the pinned HAP fixture (REA_HARMONY_TEST_HAP, fetched by npm run fixtures:harmony), which is not available in this environment, so that lane was not run. The synthetic ZIP root exercises the same suffix-plus-ZIP-magic classification and the same output validation that failed. No licensed-provider or Windows lane is involved in this change.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:focused -- tests/boundary/mcp/harmonySessionFormatsMcp.test.ts — 3 passed (3 failed with the source fix stashed)
  • npm run test:focused -- tests/boundary/filesystem/harmony/application.test.ts — 16 passed
  • npm run test:focused -- tests/boundary/mcp/artifactMcp.test.ts — 8 passed
  • npm run check:fast — 2/2 tasks successful (typecheck, lint)
  • npm run format:check — 2955 files formatted
  • npm run verify:test-discovery — 1009 test files discovered exactly once
  • npm run mcp-catalog:check — 4/4 tasks successful
  • npm run docs:check — 6/6 tasks successful

Compatibility, safety, and release

  • Breaking changes or migration steps: none. The enum only gains members.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; no provider, engine or host interaction is involved.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none. The change does not alter admission, detection, authority or target selection; it lets the session tools report a format the opener already accepted.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/2463 **Author:** [@zktufo](https://github.com/zktufo) **Created:** 10/13/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/harmony-session-output-formats` --- ### 📝 Commits (1) - [`e275fd4`](https://github.com/morluto/rea/commit/e275fd4e3079b622dbb6c0857839e4305ac7d6c6) fix(mcp): accept HarmonyOS package formats in session target output ### 📊 Changes **2 files changed** (+76 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/contracts/toolOutputSchemaPrimitives.ts` (+3 -0) ➕ `tests/boundary/mcp/harmonySessionFormatsMcp.test.ts` (+73 -0) </details> ### 📄 Description ## Summary Fixes finding **D09** of #2454. A HarmonyOS root (`.hap`, `.hsp`, or the `.app` App Pack) opens successfully in a session, but the MCP session tools then reject their own result: the shared target-format enum behind the session output contract omitted all three formats, so `open_binary` returned `Output validation error: Invalid structured content for tool open_binary: result.format: Invalid discriminator value.` while the target was already active and `inspect_artifact` worked. This PR adds the three formats to the owning shared enum. It does **not** close #2454: the remaining findings of that audit are untouched and can follow as separate changes. ## Problem and expected behavior Smallest trigger: write any ZIP archive ending in `.hap` and open it through the session opener. ``` Output validation error: Invalid structured content for tool open_binary: result.format: Invalid discriminator value. Expected 'hopper' | 'analysis-database' | 'mach-o' | 'mach-o-universal' | 'elf' | 'pe' | 'dos-mz' | 'dos-com' | 'zip' | 'ipa' | 'apk' | 'msix' | 'appx' | 'asar' | 'dmg' | 'pkg' | 'plist' | 'javascript' | 'source-map' | 'raw-binary' ``` Violated invariant: every target format the classifier can produce must be representable in the shared session output contract that validates it. Detection and admission succeeded; only the result projection rejected the observation. ## Change and scope Add `hap`, `hsp` and `app-pack` to `targetFormatSchema` in `src/contracts/toolOutputSchemaPrimitives.ts`, inserted after `appx` to mirror the domain enumeration's order. That enum is the owner behind `detectedLifecycleTargetSchema`, which both `sessionOutputSchemas.open_binary` and `sessionOutputSchemas.binary_session` consume. Why this fits: every other format enumeration in the repository already carries the three — the domain `formatSchema` (`src/domain/analysisSnapshot.ts`), `src/domain/artifactGraph.ts`, `src/domain/evidence.ts`, `src/domain/binaryTargetTypes.ts`, `src/domain/zipPackageFormat.ts` and `HARMONY_ROOT_FORMATS` in `src/domain/harmony/harmonyApplication.ts`. Only the contracts enum was behind, so this restores the contract to the classification it validates rather than widening admission. Intentionally not included: detection changes, inventory/projection changes, CLI changes, and the other eleven findings of #2454. Contribution scope: not applicable (an ordinary fix within existing boundaries). ## Contract and boundary impact - Semantic owner and earliest changed stage: `targetFormatSchema` (shared session output contract) — result projection and validation, after detection and admission already succeeded. `BinaryTargetResolver`, `zipPackageFormatForPath` and the `.app` root rule are unchanged. - Contribution scope fit and linked maintainer decision: not applicable. - CLI and MCP/tool-catalog contract: MCP `open_binary` and `binary_session` structured output now validate for the three formats. No tool input, catalog or CLI contract change; `npm run mcp-catalog:check` passes unchanged. - Provider, bridge, target-format, or platform compatibility: only additional format families are accepted; every existing format is unchanged. No provider, bridge or platform surface is touched. - Evidence, artifact, provenance, or reconstruction contract: none — the field enumerates a format string the pipeline already produced. - Target selection, authority, upstream behavior, and cleanup details: not applicable. - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact: none; `npm run docs:check` and `npm run mcp-catalog:check` both pass, and no ignored output was committed. - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: `tests/boundary/mcp/harmonySessionFormatsMcp.test.ts` (new). Three cases, one per root format, each opening a synthetic ZIP-backed root through the real in-memory MCP session server and asserting that both `open_binary` and `binary_session` succeed and report the detected format. - Base reproduction or other evidence: with the source fix stashed and the test kept, all three cases fail on the unfixed base with the quoted output-validation error. With the fix, 3/3 pass. - User-visible CLI/MCP output (if applicable): the error text above is the observed result on the unfixed base; after the change the tools return their normal result envelope with `format` set to `hap`, `hsp` or `app-pack`. - Remaining proof gaps: the real-pipeline Harmony lane (`npm run verify:harmony`) requires the pinned HAP fixture (`REA_HARMONY_TEST_HAP`, fetched by `npm run fixtures:harmony`), which is not available in this environment, so that lane was not run. The synthetic ZIP root exercises the same suffix-plus-ZIP-magic classification and the same output validation that failed. No licensed-provider or Windows lane is involved in this change. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run test:focused -- tests/boundary/mcp/harmonySessionFormatsMcp.test.ts` — 3 passed (3 failed with the source fix stashed) - `npm run test:focused -- tests/boundary/filesystem/harmony/application.test.ts` — 16 passed - `npm run test:focused -- tests/boundary/mcp/artifactMcp.test.ts` — 8 passed - `npm run check:fast` — 2/2 tasks successful (typecheck, lint) - `npm run format:check` — 2955 files formatted - `npm run verify:test-discovery` — 1009 test files discovered exactly once - `npm run mcp-catalog:check` — 4/4 tasks successful - `npm run docs:check` — 6/6 tasks successful ## Compatibility, safety, and release - Breaking changes or migration steps: none. The enum only gains members. - Real Hopper/Ghidra, browser, or OS coverage: not applicable; no provider, engine or host interaction is involved. - Package or release metadata impact: none. - Security, privacy, process, or containment review: none. The change does not alter admission, detection, authority or target selection; it lets the session tools report a format the opener already accepted. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:05:08 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5246
No description provided.