[PR #6255] [MERGED] fix(apple): decode NIBArchive booleans with AppKit's polarity #7232

Closed
opened 2026-11-01 21:46:21 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/6255
Author: @kaoru0822-kitauji
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @kaoru0822-kitauji

Base: main ← Head: fix/5541-nib-boolean-values


📝 Commits (1)

  • b0efe92 fix(apple): decode NIBArchive booleans with AppKit's polarity

📊 Changes

5 files changed (+177 additions, -33 deletions)

View changed files

📝 docs/testing.md (+3 -1)
📝 scripts/verify/apple/interface-builder.mjs (+100 -8)
📝 src/artifacts/apple/NibArchive.fixture.ts (+2 -1)
📝 src/artifacts/apple/NibArchive.test.ts (+31 -0)
📝 src/artifacts/apple/NibArchive.ts (+41 -23)

📄 Description

What broke: decode-interface-builder inverted every boolean stored in a compiled NIBArchive: the decoder read type tag 4 as true and tag 5 as false. The test fixture encoder used the same reversed mapping, so round-trip tests could not catch it (#5541).
Fix: the value-type tags are now named once (booleanFalse: 4, booleanTrue: 5) and used by both the read and skip paths. The fixture encoder writes the format's tags, a unit test pins the raw tag bytes, and verify:interface-builder checks both polarities against ibtool --export.
Risk: low. NIB booleans in nibValues now come back with the correct value. No schema change, and no code in src/ interprets these booleans.

Summary

Fixes #5541. On main, NSControlContinuous, NSControlRefusesFirstResponder, NSEnabled, NSWindowIsRestorable and every other boolean in a compiled AppKit NIBArchive decoded to the opposite of its stored value. With this change they match the value AppKit's own nib decoder returns.

Problem and expected behavior

The NIBArchive value table stores booleans as payload-free type tags. readValue in src/artifacts/apple/NibArchive.ts mapped 4 → true, 5 → false. Apple's own decoder reads them the other way round: -[NSCoder decodeBoolForKey:] on the nib decoder returns NO for tag 4 and YES for tag 5, as the evidence below shows. Callers should get the serialized value. The issue's oracle, ibtool --export, reports the same polarity for the source documents.

Change and scope

  • NibArchive.ts: a NibValueType table names all 11 value tags. readValue and skipValue both switch on it instead of on bare numbers, so the boolean polarity is defined in one place. Tag 4 now decodes as false and tag 5 as true. Payload sizes are unchanged.
  • NibArchive.fixture.ts: the encoder writes true as 5 and false as 4. It keeps literal bytes rather than importing the decoder's table, so it does not inherit the decoder's assumption.
  • NibArchive.test.ts: a new test writes raw tags 4 and 5 into a value table and expects false and true. It does not depend on how the fixture encodes booleans.
  • scripts/verify/apple/interface-builder.mjs (the macOS CI apple-artifacts lane, where Xcode is available): after the existing checks, the script makes a copy of Main.xib with continuous and refusesFirstResponder toggled (via ibtool --import) and compiles both sources. It then requires the public CLI's NSButton nibValues to equal ibtool --export for each source: false/false and true/true. This replays the restoration check proposed in the issue.
  • docs/testing.md: describes the added verification.
  • Keyed-archive (bplist/XML) nibs carry plist-native booleans through a different reader and are untouched.

Contribution scope: ordinary fix within existing boundaries; maintainer scope decision not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: NIBArchive value decoding (src/artifacts/apple/NibArchive.ts).

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

  • CLI and MCP/tool-catalog contract: no schema change. Boolean values in nibValues from NIBArchive documents now have the correct polarity.

  • Provider, bridge, target-format, or platform compatibility: NIBArchive only.

  • Evidence, artifact, provenance, or reconstruction contract: observed field values are corrected. Identity, digests and coverage are unchanged.

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

  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

  • 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: raw-tag unit test in NibArchive.test.ts; corrected fixture encoder; ibtool --export comparison of both polarities in verify:interface-builder.

  • Base reproduction (executed, macOS 26 arm64, this host has Command Line Tools but no Xcode ibtool):

    • Independent oracle: a local Objective-C harness (not committed) loads a compiled nib with NSNib and logs every value that AppKit's nib decoder returns from decodeBoolForKey: for keys present in the archive. Each nib is placed alone in an isolated Fixture.app, and the harness compares the per-key true/false counts with the public CLI's nibValues booleans.
    • On base c537c52c9, using real Apple-compiled nibs (TextEdit DocumentWindow.nib, Problem Reporter ProblemReporterMain.nib, Mail ExtensionEnablementConfirmation.nib), all 29 compared keys disagree and every count is exactly swapped. Examples: NSControlContinuous AppKit true/false = (0, 7) vs REA (7, 0); NSWindowIsRestorable (1, 0) vs (0, 1).
    • With this change, the same 3 nibs agree on all 29 keys. A wider sample of 42 real system nibs, spread across 2,669 NIBArchive files in /System/Applications and /System/Library/CoreServices, agrees on 502 of 503 key comparisons. The one difference is NSAnimates in a MainMenu.nib: AppKit returned 1 true while REA reports 1 true and 4 false. AppKit simply did not call decodeBoolForKey: for 4 archived fields, and the polarity agrees.
    • With the decoder change reverted, the new raw-tag test and the existing round-trip test fail (2 failed, 4 passed).
  • User-visible CLI/MCP output (executed, TextEdit DocumentWindow.nib): the CLI's nibValues for its 2 controls now report NSControlContinuous: false and NSControlRefusesFirstResponder: false, the values AppKit decodes (base reported true). The issue's Main.xib / toggled outputs are proposed checks, left to the CI lane.

  • Remaining proof gaps: Xcode ibtool is unavailable on this host, so the new verify:interface-builder steps have not run against real ibtool here. Their ibtool --import/--export invocations copy the issue's executed reproduction. I ran the script end to end with a stand-in ibtool that emits a NIBArchive with raw tags. Against the base build it fails at the false-polarity assertion; with this change it passes. The macOS CI lane will run it against real Xcode. Storyboard/UIKit NIBArchives were not exercised separately; they share the same value decoder.

  • 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 -- src/artifacts/apple/NibArchive.test.ts src/artifacts/apple/AppleAssetCatalogAnalysis.test.ts src/domain/apple/interfaceBuilderGraph.test.ts tests/boundary/filesystem/interfaceBuilderBundle.test.ts tests/boundary/filesystem/nibNativeHierarchy.test.ts tests/acceptance/applications/nibFieldIdentity.test.ts tests/acceptance/applications/assetCatalogResourceKeys.test.ts: 7 files passed, 105 tests passed, 7 skipped (Xcode-gated)
  • npm run test:local -- src/artifacts/apple/NibArchive.test.ts with the decoder reverted: 2 failed, 4 passed
  • AppKit decodeBoolForKey: oracle vs public CLI, 3 real nibs: base 0/29 keys agree; this change 29/29
  • Same oracle on 42 sampled real system nibs with this change: 502/503 key comparisons agree (the remaining one is explained above)
  • node scripts/verify/apple/interface-builder.mjs with a stand-in ibtool: fails on the base build at the false-polarity assertion, passes with this change
  • npm run check:fast: passed
  • npm run format:check: passed
  • npm run docs:check: passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none. NIB booleans were previously inverted; callers now receive the stored values.
  • Real Hopper/Ghidra, browser, or OS coverage: macOS 26 with Command Line Tools and real Apple-compiled system nibs; no provider involved. Xcode ibtool coverage comes from the CI apple-artifacts lane.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the product gets no new reads, processes or side effects. The verify script runs ibtool --import/--export and plutil on temporary fixture files only.

Author readiness

Human owner: @kaoru0822-kitauji

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

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.

🤖 Generated with Claude Code


🔄 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/6255 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Base:** `main` ← **Head:** `fix/5541-nib-boolean-values` --- ### 📝 Commits (1) - [`b0efe92`](https://github.com/morluto/rea/commit/b0efe92ec9fd6b935c5b24f7e819e40ac3586a7a) fix(apple): decode NIBArchive booleans with AppKit's polarity ### 📊 Changes **5 files changed** (+177 additions, -33 deletions) <details> <summary>View changed files</summary> 📝 `docs/testing.md` (+3 -1) 📝 `scripts/verify/apple/interface-builder.mjs` (+100 -8) 📝 `src/artifacts/apple/NibArchive.fixture.ts` (+2 -1) 📝 `src/artifacts/apple/NibArchive.test.ts` (+31 -0) 📝 `src/artifacts/apple/NibArchive.ts` (+41 -23) </details> ### 📄 Description **What broke:** `decode-interface-builder` inverted every boolean stored in a compiled NIBArchive: the decoder read type tag 4 as `true` and tag 5 as `false`. The test fixture encoder used the same reversed mapping, so round-trip tests could not catch it (#5541). **Fix:** the value-type tags are now named once (`booleanFalse: 4`, `booleanTrue: 5`) and used by both the read and skip paths. The fixture encoder writes the format's tags, a unit test pins the raw tag bytes, and `verify:interface-builder` checks both polarities against `ibtool --export`. **Risk:** low. NIB booleans in `nibValues` now come back with the correct value. No schema change, and no code in `src/` interprets these booleans. ## Summary Fixes #5541. On main, `NSControlContinuous`, `NSControlRefusesFirstResponder`, `NSEnabled`, `NSWindowIsRestorable` and every other boolean in a compiled AppKit NIBArchive decoded to the opposite of its stored value. With this change they match the value AppKit's own nib decoder returns. ## Problem and expected behavior The NIBArchive value table stores booleans as payload-free type tags. `readValue` in `src/artifacts/apple/NibArchive.ts` mapped `4 → true`, `5 → false`. Apple's own decoder reads them the other way round: `-[NSCoder decodeBoolForKey:]` on the nib decoder returns NO for tag 4 and YES for tag 5, as the evidence below shows. Callers should get the serialized value. The issue's oracle, `ibtool --export`, reports the same polarity for the source documents. ## Change and scope - `NibArchive.ts`: a `NibValueType` table names all 11 value tags. `readValue` and `skipValue` both switch on it instead of on bare numbers, so the boolean polarity is defined in one place. Tag 4 now decodes as `false` and tag 5 as `true`. Payload sizes are unchanged. - `NibArchive.fixture.ts`: the encoder writes `true` as 5 and `false` as 4. It keeps literal bytes rather than importing the decoder's table, so it does not inherit the decoder's assumption. - `NibArchive.test.ts`: a new test writes raw tags 4 and 5 into a value table and expects `false` and `true`. It does not depend on how the fixture encodes booleans. - `scripts/verify/apple/interface-builder.mjs` (the macOS CI `apple-artifacts` lane, where Xcode is available): after the existing checks, the script makes a copy of `Main.xib` with `continuous` and `refusesFirstResponder` toggled (via `ibtool --import`) and compiles both sources. It then requires the public CLI's `NSButton` `nibValues` to equal `ibtool --export` for each source: false/false and true/true. This replays the restoration check proposed in the issue. - `docs/testing.md`: describes the added verification. - Keyed-archive (bplist/XML) nibs carry plist-native booleans through a different reader and are untouched. Contribution scope: ordinary fix within existing boundaries; maintainer scope decision not applicable. ## Contract and boundary impact - Semantic owner and earliest changed stage: NIBArchive value decoding (`src/artifacts/apple/NibArchive.ts`). - Contribution scope fit and linked maintainer decision: ordinary fix; not applicable. - CLI and MCP/tool-catalog contract: no schema change. Boolean values in `nibValues` from NIBArchive documents now have the correct polarity. - Provider, bridge, target-format, or platform compatibility: NIBArchive only. - Evidence, artifact, provenance, or reconstruction contract: observed field values are corrected. Identity, digests and coverage are unchanged. - Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable. - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact: none. - [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: raw-tag unit test in `NibArchive.test.ts`; corrected fixture encoder; `ibtool --export` comparison of both polarities in `verify:interface-builder`. - Base reproduction (executed, macOS 26 arm64, this host has Command Line Tools but no Xcode `ibtool`): - Independent oracle: a local Objective-C harness (not committed) loads a compiled nib with `NSNib` and logs every value that AppKit's nib decoder returns from `decodeBoolForKey:` for keys present in the archive. Each nib is placed alone in an isolated `Fixture.app`, and the harness compares the per-key true/false counts with the public CLI's `nibValues` booleans. - On base `c537c52c9`, using real Apple-compiled nibs (TextEdit `DocumentWindow.nib`, Problem Reporter `ProblemReporterMain.nib`, Mail `ExtensionEnablementConfirmation.nib`), all 29 compared keys disagree and every count is exactly swapped. Examples: `NSControlContinuous` AppKit true/false = (0, 7) vs REA (7, 0); `NSWindowIsRestorable` (1, 0) vs (0, 1). - With this change, the same 3 nibs agree on all 29 keys. A wider sample of 42 real system nibs, spread across 2,669 NIBArchive files in `/System/Applications` and `/System/Library/CoreServices`, agrees on 502 of 503 key comparisons. The one difference is `NSAnimates` in a `MainMenu.nib`: AppKit returned 1 true while REA reports 1 true and 4 false. AppKit simply did not call `decodeBoolForKey:` for 4 archived fields, and the polarity agrees. - With the decoder change reverted, the new raw-tag test and the existing round-trip test fail (2 failed, 4 passed). - User-visible CLI/MCP output (executed, TextEdit `DocumentWindow.nib`): the CLI's `nibValues` for its 2 controls now report `NSControlContinuous: false` and `NSControlRefusesFirstResponder: false`, the values AppKit decodes (base reported `true`). The issue's `Main.xib` / toggled outputs are proposed checks, left to the CI lane. - Remaining proof gaps: Xcode `ibtool` is unavailable on this host, so the new `verify:interface-builder` steps have not run against real `ibtool` here. Their `ibtool --import/--export` invocations copy the issue's executed reproduction. I ran the script end to end with a stand-in `ibtool` that emits a NIBArchive with raw tags. Against the base build it fails at the false-polarity assertion; with this change it passes. The macOS CI lane will run it against real Xcode. Storyboard/UIKit NIBArchives were not exercised separately; they share the same value decoder. - [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 -- src/artifacts/apple/NibArchive.test.ts src/artifacts/apple/AppleAssetCatalogAnalysis.test.ts src/domain/apple/interfaceBuilderGraph.test.ts tests/boundary/filesystem/interfaceBuilderBundle.test.ts tests/boundary/filesystem/nibNativeHierarchy.test.ts tests/acceptance/applications/nibFieldIdentity.test.ts tests/acceptance/applications/assetCatalogResourceKeys.test.ts`: 7 files passed, 105 tests passed, 7 skipped (Xcode-gated) - `npm run test:local -- src/artifacts/apple/NibArchive.test.ts` with the decoder reverted: 2 failed, 4 passed - AppKit `decodeBoolForKey:` oracle vs public CLI, 3 real nibs: base 0/29 keys agree; this change 29/29 - Same oracle on 42 sampled real system nibs with this change: 502/503 key comparisons agree (the remaining one is explained above) - `node scripts/verify/apple/interface-builder.mjs` with a stand-in `ibtool`: fails on the base build at the false-polarity assertion, passes with this change - `npm run check:fast`: passed - `npm run format:check`: passed - `npm run docs:check`: passed ## Compatibility, safety, and release - Breaking changes or migration steps: none. NIB booleans were previously inverted; callers now receive the stored values. - Real Hopper/Ghidra, browser, or OS coverage: macOS 26 with Command Line Tools and real Apple-compiled system nibs; no provider involved. Xcode `ibtool` coverage comes from the CI `apple-artifacts` lane. - Package or release metadata impact: none. - Security, privacy, process, or containment review: the product gets no new reads, processes or side effects. The verify script runs `ibtool --import/--export` and `plutil` on temporary fixture files only. ## Author readiness Human owner: @kaoru0822-kitauji - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## 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. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:46:21 +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#7232
No description provided.