Commit Graph
10 Commits
Author SHA1 Message Date
james.maesandClaude Opus 4.7 b7255c57a7 test(03-05): end-to-end smoke script scripts/smoke-test-hud.sh
Post-build smoke (invoke after `xcodebuild build`) verifies the built
Jarvis.app has:
  * Contents/Resources/webview/ directory present (blue-folder wiring OK)
  * index.html present (scripts/build-webview.sh rsync OK)
  * assets/ subdirectory with >=1 *.js chunk (Vite build OK)
  * index.html references ./assets/ relative paths (Vite base: './')
  * index.html does NOT reference absolute /assets/ src|href paths
  * bus-harness.html still present (02-04 parity script invariant preserved)

Covers the gap left by the Xcode 26 `xcodebuild test` RunningBoard blocker
(.planning/debug/xctest-launch-runningboard-error-5.md). XCTest-level
assertions are structural (read repo tree); this script asserts the
BUILT .app shape, which is what the user's cold-launch actually sees.

Runs green against the Debug build produced by Task 1.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-24 15:54:53 -05:00
james.maesandClaude Opus 4.7 cabc27299a feat(03-05): AppDelegate wires HudStateCoordinator + bridge; lint activated; W1-W6 + B1-B3 tests
- App/HUD/HudStateBridge.swift (new): @MainActor public func busHudState(
  from: HudState) -> Bus.HudState. RawValue round-trip with assertionFailure
  on drift, .idle fallback in Release. Option (b) from the plan — avoids
  name-collision between App.HudState and Bus.HudState via module-qualified
  Bus.HudState in the helper's scope.
- App/AppDelegate.swift:
    * New stored properties: hudStateCoordinator, dormantAgentContinuation,
      dormantVoiceContinuation, dormantConfirmContinuation (all internal so
      @testable import Jarvis can assert W5 retention), webviewEntryFilename
      (internal test seam for W6).
    * installBus(): constructs HudStateCoordinator with emit closure that
      bridges App.HudState -> Bus.HudState via busHudState() and dispatches
      to bridge.send(.hudState(...)) on the MainActor. Creates three dormant
      AsyncStream producers (Phase 4/5/6 replace them) and retains their
      continuations on self so coordinator.{agent,voice,confirm}Task stay
      live. markReady() fires from onHandshakeArmed so the HUD promotes
      .booting -> .idle as soon as the webview is responsive.
    * Load target: bus-harness.html -> index.html (via
      webviewEntryFilename property so W6 can assert post-install value).
      XCTest-host short-circuit from 02-03 deviation #5 preserved, updated
      to reference the property-driven filename.
- scripts/check-single-writer-hudstate.sh: allowlist extended to
  {HudStateCoordinator.swift, HudStateBridge.swift, AppDelegate.swift} +
  {BusOutbound.swift, Protocol.swift}. Rationale comment updated: Phase 4+
  drives the coordinator via its three input AsyncStreams, not new
  .hudState(...) call sites. Already wired as a preBuildScript by Task 1.
- App/Tests/AppTests/HudStateCoordinatorBusWiringTests.swift (new):
    * W1 test_coordinatorConstructedInInstallBus — delegate.hudStateCoordinator
      non-nil after applicationWillFinishLaunching.
    * W2 test_emitClosureBridgesToBusSend — FakeJSEvaluator observes the
      closure producing a decoded BusOutbound.hudState(.thinking) after
      coordinator.markReady() + agent.yield(.thinking). Proves the exact
      closure shape AppDelegate installs routes rawValues end-to-end.
    * W3 test_markReadyCalledOnHandshakeArmed — coordinator pinned at .booting
      pre-handshake, promotes to .idle after bridge.handleHelloAck.
    * W4 test_appHudStateRawValueMatchesBusHudState — table-driven bidirectional
      rawValue parity over HudState.allCases and Bus.HudState.allCases. Catches
      drift before busHudState()'s assertion fires at runtime.
    * W5 test_dormantStreamsHeldByDelegate — all three continuations non-nil.
    * W6 test_installBusLoadsIndexNotHarness — webviewEntryFilename == "index"
      post-installBus.
- App/Tests/AppTests/WebviewBundleLoadTests.swift (new):
    * B1 test_indexHtmlInRepoWebviewDir — structural (#filePath traversal to
      repo root), catches missing committed index.html.
    * B3 test_indexHtmlReferencesRelativeAssets — content-grep for "./assets/"
      present + "src=\"/assets/" absent. Catches Vite misconfig or absolute-
      path drift.
    * B-extra test_assetsDirectoryGitignored_documentedInSmokeScript — doc-only,
      asserts the split of responsibility between XCTest (committed index.html)
      and scripts/smoke-test-hud.sh (built-app assets/*.js).

Tests are repo-structural / evaluator-observation only; xcodebuild test
launch still blocked on Xcode 26 RunningBoard error 5 per 02-03 precedent.
Verification is xcodebuild build (succeeds) + scripts/smoke-test-hud.sh
(next task). This follows the 02-03 SUMMARY deviation #5 pattern.

xcodebuild build -configuration Debug: BUILD SUCCEEDED.
bash scripts/check-single-writer-hudstate.sh: PASS (allowlist active).
packages/Bus swift test: 47/47 green.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-24 15:53:58 -05:00
james.maesandClaude Opus 4.7 a9a1b86ef9 feat(03-05): build-webview.sh + project.yml pre-build wiring + commit index.html
- scripts/build-webview.sh (exec): pnpm install (content-hash-cached) +
  @jarvis/bus build + @jarvis/hud build + rsync dist/ -> App/Resources/webview/
  with --exclude bus-harness.html (preserved for 02-04 parity script) and
  --exclude .gitignore (preserves the assets/ ignore pattern).
- project.yml: adds two preBuildScripts after check-no-evaluate-javascript:
    * Check single-writer HUD state (HUD-08)
    * Build webview bundle
  Ordering stays: existing parity/protocol/no-eval checks → single-writer
  lint → webview build → (postBuildScripts: pre-codesign verify → codesign
  → post-codesign verify → pbxproj lint).
- App/Resources/webview/.gitignore: ignore assets/ (regenerated every build).
- App/Resources/webview/index.html: committed entry point (R3F bundle).

Assets are NOT committed — they rebuild from webview/packages/hud/ on every
xcodebuild via the new pre-build script.

xcodebuild build -configuration Debug succeeds end-to-end; built app
has Contents/Resources/webview/index.html + assets/index-*.js with
relative (./assets/) paths.

packages/Bus swift test: 47/47 green.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-24 15:47:24 -05:00
james.maes 79092263bb feat(03-01): HudStateCoordinator single-writer + intents + lint
Implements HUD-08 precedence ladder as the sole Swift-side writer of
HudState. Three producer streams (agent, voice, confirmation) feed a
MainActor-isolated resolver; one emit closure is the only path out.

- HudStateIntent.swift: AgentHudIntent/VoiceHudIntent/ConfirmHudIntent
  Sendable enums. SystemHudIntent intentionally omitted — markReady()
  is a one-shot direct call, not a stream.
- HudStateCoordinator.swift: @MainActor final class. Ladder per
  HUD-08 verbatim: awaitingConfirmation > speaking > listening >
  thinking > idle > booting > reconfiguring. Ready-gate tweak on the
  .booting step (RESEARCH Open Q #4 pre-authorized) so boot-time
  silent inputs don't prematurely resolve to .idle.
- Bus-agnostic by design: takes @escaping @MainActor (HudState) -> Void
  emit closure so Plan 03-05 can wire it to WebviewBridge without this
  plan importing Bus or WebKit.
- Weak-self capture + deinit cancel on three for-await loops prevents
  the T-03-03 leak.
- HudStateCoordinatorTests.swift: 19 methods covering every precedence
  pair, booting gate, idempotent emit, cleared-confirm restore,
  weak-self no-leak, interleaved producers.
- scripts/check-single-writer-hudstate.sh: executable; exits 0 on
  current codebase; exits 1 on planted .hudState() construction
  outside the allowlist. Pre-build wiring deferred to Plan 03-05.
2026-04-23 18:55:04 -05:00
james.maes a63d521d38 feat(02-04): add bus parity + HUD-04 lint + harness-parity pre-build scripts
Three build-breaking check scripts + two smoke test harnesses + two fixture dirs:

- scripts/check-bus-protocol-version.sh: greps Swift vs TS BUS_PROTOCOL_VERSION
  constants, diffs the two fixture directories (packages/Bus/Tests/BusTests/
  Fixtures/ vs webview/packages/bus/fixtures/). Fails build on any drift.
- scripts/check-no-evaluate-javascript.sh: scans App/ + packages/ for
  `.evaluateJavaScript(` outside test dirs; HUD-04 architectural lint.
- scripts/check-bus-harness-parity.sh: byte-identical check between
  canonical webview/bus-harness.html and bundle copy (Plan 02-03 provides
  the bundle copy; this script enforces no-drift going forward).
- scripts/test-check-bus-protocol-version.sh + bus-mismatch/ fixture:
  drives the protocol-version checker against a v2.0.0/v1.9.0 mismatch,
  asserts exit 1 + both versions in error text.
- scripts/test-check-no-evaluate-javascript.sh + bus-evaluate-js/ fixture:
  drives HUD-04 lint against bad.swift (evaluateJavaScript) + good.swift
  (callAsyncJavaScript). Asserts bad.swift flagged, good.swift not flagged.
  Fixture is copied to a temp dir to bypass the production */test-fixtures/*
  path-skip rule.

[Rule 3 - Blocking] Normalized Swift-side fixtures to drop trailing newlines.
The 14 JSON files under packages/Bus/Tests/BusTests/Fixtures/ had stray
trailing \n while the TS mirror at webview/packages/bus/fixtures/ did not.
Plan 02-02's SUMMARY documented the no-trailing-newline convention (matches
Swift JSONEncoder default) but Plan 02-01's fixtures were authored via a
text editor that added them. Stripping \n lets check-bus-protocol-version.sh
pass without relaxing the byte-equality invariant. Swift CodableRoundTripTests
remain green (24/24) because JSONSerialization ignores trailing whitespace.
2026-04-23 17:51:56 -05:00
james.maes 0517926f61 fix(01): split entitlements per-config + address AMFI rejection on ad-hoc Debug
The debugger agent diagnosed the JarvisAppTests xctest launch failure
(Runningboard error 5 / Launchd job spawn failed). Root cause: AMFI
rejected the ad-hoc signed Debug bundle because it carried the managed
`com.apple.developer.speech-recognition-assets` entitlement. The kernel
logged `AMFI: Code has restricted entitlements, but the validation of
its code signature failed` → `load code signature error 4` → spawn
failure → Runningboard error 5.

**Changes:**

- Split `App/Jarvis.entitlements` → `Jarvis.Debug.entitlements` (no
  `speech-recognition-assets`; adds `get-task-allow` for XCTest attach)
  + `Jarvis.Release.entitlements` (full managed set, unchanged).
- `project.yml`: per-config `CODE_SIGN_ENTITLEMENTS`; Debug gets
  `ENABLE_HARDENED_RUNTIME=NO` + `OTHER_CODE_SIGN_FLAGS=""` +
  `ONLY_ACTIVE_ARCH=YES`; `DEVELOPMENT_TEAM` moved from base → Release
  only (avoids Team ID leaking into the Xcode 26 debug dylib).
- `scripts/codesign.sh`: resolves entitlements via $CODE_SIGN_ENTITLEMENTS
  env, falls back to config-specific file, then to the legacy path.
  Also signs `Contents/MacOS/*.debug.dylib` now that Xcode 26 emits it.
- `scripts/verify-entitlements.sh`: per-config `MAIN_REQUIRED` +
  `MAIN_FORBIDDEN` lists — Debug forbids `speech-recognition-assets`
  (wrong for ad-hoc) and requires `get-task-allow`; Release enforces
  the shipping posture with all 3 managed keys.

**Residual known issue** (documented in `.planning/debug/xctest-launch-runningboard-error-5.md`
and `01-HUMAN-UAT.md` §4): Xcode 26 still emits `Jarvis.debug.dylib`
with a code signature whose Team ID context diverges from our ad-hoc
outer sign, producing a dyld "different Team IDs" rejection when xctest
tries to load the bundle. Multiple workarounds attempted
(SWIFT_ENABLE_DEBUG_DYLIB=NO, resigning the dylib, stripping it
post-build). `xcodebuild test -scheme Jarvis -only-testing:JarvisAppTests`
fails bootstrap; SPM package tests (56, all passing) and `xcodebuild
build` both succeed. Actual code quality is unaffected — this is a
harness/tooling boundary issue.

Verified: 56 SPM tests pass; `xcodebuild build -configuration Debug`
BUILD SUCCEEDED; `scripts/test-verify-entitlements.sh` self-test
PASS=3 FAIL=0.
2026-04-23 17:06:10 -05:00
james.maes 4446afbc45 fix(01-WR-12): check codesign exit code explicitly in verify-entitlements.sh
Phase 1 REVIEW.md WR-12: both `--post-codesign` greps used
`codesign … 2>&1 || true`, which merged stderr into stdout AND
swallowed the exit code. In the helper check this was the worst
case: a helper whose binary was deleted between signing and verify
would emit error text that doesn't contain "apple-events", and the
grep-for-absence would coincidentally pass — letting an unsigned
helper ship.

scripts/verify-entitlements.sh
- Main app `codesign -d`: split streams (stdout → EXTRACTED, stderr →
  /tmp/codesign-main.err), check exit status explicitly, dump stderr
  and bail if codesign failed.
- Per-helper `codesign -d`: same pattern. /tmp/codesign-helper.err
  is cleaned up on both success and failure.
- Drop `-depth` from the helper find — it's relevant for signing
  (deepest-first) but pointless for verify-only.

Self-test still passes (test-verify-entitlements.sh: 3/3 PASS).
2026-04-23 16:23:18 -05:00
james.maes e9a0bb14d2 feat(01-05): add JarvisEntitlementProbeTests target + EntitlementProbe scheme
- App/Tests/JarvisEntitlementProbeTests/JarvisEntitlementProbeTests.swift:
  one-shot XCTest gated on #if JARVIS_ENTITLEMENT_PROBE. Calls
  SpeechTranscriber(locale:preset:) + AssetInventory.status(forModules:)
  and accepts any of three failure surfaces as confirmation that the
  speech-recognition-assets entitlement is load-bearing:
    (a) NSError SFSpeechErrorDomain code 1 (assetUnavailable)
    (b) NSError SFSpeechErrorDomain code 10 (macOS 26 'unallocated locales')
    (c) AssetInventory.Status description containing 'unavailable' /
        'unsupported'
- App/Tests/JarvisEntitlementProbeTests/Info.plist: standard test bundle.
- project.yml: new JarvisEntitlementProbeTests target (OTHER_SWIFT_FLAGS =
  -DJARVIS_ENTITLEMENT_PROBE) + EntitlementProbe scheme. Default Jarvis
  scheme's test action lists only JarvisAppTests — the probe target is
  opt-in via EntitlementProbe scheme only.
- Jarvis.xcodeproj/xcshareddata/xcschemes/EntitlementProbe.xcscheme: new
  shared scheme referencing JarvisEntitlementProbeTests as its sole
  testable.

Deviations from plan's copy-verbatim XCTest shape:
- Added @available(macOS 26.0, *) to the test class: macOS 26 SpeechModule
  / SpeechTranscriber / AssetInventory are not available pre-Tahoe.
  Deployment target stays at 13.0 for the rest of the project.
- preset: .progressiveLiveTranscription -> .progressiveTranscription
  (actual Apple SDK name on macOS 26.4).
- AssetInventory.status(forModules:) is async non-throwing on macOS 26.4;
  wrapped in a throwing adapter so the historical do/catch shape from
  RESEARCH Q4 (NSError SFSpeechErrorDomain codes 1/10) stays intact.

Also: [Rule 3 - Blocking] extend codesign.sh to handle nested .xctest
plugins under Contents/PlugIns/. When build-for-testing is invoked, the
xctest lives inside Jarvis.app/Contents/PlugIns/ and must be signed
before the main app, or codesign on the parent bundle fails with
'bundle format unrecognized'. Empty xctest shells that materialize
before the test target has been compiled are removed (Xcode recreates
+ populates them in a later iteration).

Task 3 acceptance: xcodebuild -list shows EntitlementProbe scheme +
JarvisEntitlementProbeTests target; EntitlementProbe build-for-testing
succeeds with the full codesign + entitlement verification chain.
2026-04-22 14:42:30 -05:00
james.maes faf00042c4 feat(01-05): wire codesign + verify scripts into Jarvis target build phases
Append four PBXShellScriptBuildPhase entries to the Jarvis target (via
project.yml postBuildScripts, regenerated via xcodegen) in RESEARCH
Open Q #8 order:
  1. (existing) Create Contents/Helpers directory
  2. Verify entitlements (pre-codesign)  -- writes JarvisEntitlementsVerified=YES
  3. Codesign bundle (deepest-first)     -- scripts/codesign.sh
  4. Verify entitlements (post-codesign) -- greps signed entitlements
  5. Verify codesign settings (pbxproj lint)

The pre-codesign phase writes the verified flag to Info.plist BEFORE
codesign so it becomes part of the signed content (writing AFTER codesign
invalidates the signature, per Open Q #8 correction).

The Codesign phase falls back to CODE_SIGN_IDENTITY (then '-') when
CODE_SIGNING_ALLOWED=NO (Xcode does not set EXPANDED_CODE_SIGN_IDENTITY
in that case). Debug's CODE_SIGNING_ALLOWED=NO escape hatch from Plan 01
stays in place — it is what lets our script be the authoritative
codesigner without Xcode's own step fighting the managed
speech-recognition-assets entitlement on a dev machine without a
provisioning profile. See SUMMARY Deferred Items for cleanup path once
a Developer ID cert + provisioning profile land.

Debug build now runs the full four-phase Run Script sequence and emits:
  pre-codesign: JarvisEntitlementsVerified=YES written
  post-codesign: entitlement verification passed
  verify-codesign-settings: pbxproj lint passed

Also: [Rule 1 - Bug] fix verify-entitlements.sh --post-codesign to pass
--xml to codesign -d --entitlements -. macOS 26's default output is a
'[Dict] [Key] ...' rich-text dump which the XML grep below did not match;
--xml forces the legacy XML plist output the verifier is written against.
2026-04-22 14:28:39 -05:00
james.maes 52f2bdee0d feat(01-05): add build-time codesign + entitlement verification scripts
- scripts/codesign.sh: deepest-first walker (find -depth) signing nested
  Contents/Helpers/**/*.app with per-helper .entitlements, then main app
  last. Never uses --deep (TN2206/Pitfall #3 guard).
- scripts/verify-entitlements.sh: two-mode script per RESEARCH Open Q #8.
  --pre-codesign validates source + writes JarvisEntitlementsVerified=YES
  to unsigned Info.plist so the flag becomes part of the signed content.
  --post-codesign greps signed entitlements (via codesign -d --entitlements -)
  for MAIN_REQUIRED/MAIN_FORBIDDEN + per-helper rules; never writes. Strips
  XML comments before grep (self-invalidating-grep defense).
- scripts/verify-codesign-settings.sh: pbxproj linter for CodeSignOnCopy = YES,
  --deep, and missing --options=runtime/--timestamp.
- scripts/test-verify-entitlements.sh: fault-injection self-test harness
  that feeds good/broken/forbidden fixtures to --verify-fixture mode and
  asserts exit codes.
- scripts/test-fixtures/{good,broken,forbidden}-entitlements.plist: fixtures
  exercising the happy path, missing allow-jit, and forbidden apple-events.

Self-test: PASS=3 FAIL=0. Linter passes against current pbxproj.

MCP-06, SEC-02, SEC-03, SEC-08 scaffolded.
2026-04-22 14:21:33 -05:00