# Native Oficina ID server verification

Implementer: Codex GPT-6-Astra.

Initial red: `GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run TestNativeExchangeGates -count=1` failed all cases with HTTP 404 before the route existed. The first device unit test failed to compile before RegisterNative, NativeSession and SessionHash existed.

Each mutation below was applied alone, tested, and restored in a finally block. A caught mutation must produce a test assertion failure, not a compile failure.

## native nonce

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeExchangeGates$/(verifier|web-nonce)$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeExchangeGates (0.07s)
--- FAIL: TestNativeExchangeGates/verifier (0.03s)
native_test.go:142: status 200 want 401
--- FAIL: TestNativeExchangeGates/web-nonce (0.04s)
native_test.go:142: status 200 want 401
```

## pinned signature issuer audience and expiry

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeExchangeGates$/(audience|issuer|key|expired)$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeExchangeGates (0.11s)
--- FAIL: TestNativeExchangeGates/audience (0.03s)
native_test.go:142: status 200 want 401
--- FAIL: TestNativeExchangeGates/issuer (0.03s)
native_test.go:142: status 403 want 401
--- FAIL: TestNativeExchangeGates/key (0.03s)
native_test.go:142: status 200 want 401
```

## Origin including empty

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeExchangeGates$/(origin|empty-origin)$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeExchangeGates (0.11s)
--- FAIL: TestNativeExchangeGates/origin (0.05s)
native_test.go:142: status 200 want 400
--- FAIL: TestNativeExchangeGates/empty-origin (0.06s)
native_test.go:142: status 200 want 400
```

## fetch provenance

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeExchangeGates$/fetch$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeExchangeGates (0.03s)
--- FAIL: TestNativeExchangeGates/fetch (0.03s)
native_test.go:142: status 200 want 400
```

## JSON media

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeExchangeGates$/json$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeExchangeGates (0.03s)
--- FAIL: TestNativeExchangeGates/json (0.03s)
native_test.go:142: status 200 want 400
```

## unknown input fields

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeExchangeGates$/unknown-field$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeExchangeGates (0.03s)
--- FAIL: TestNativeExchangeGates/unknown-field (0.03s)
native_test.go:142: status 200 want 400
```

## duplicate input fields

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeExchangeGates$/duplicate-field$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeExchangeGates (0.04s)
--- FAIL: TestNativeExchangeGates/duplicate-field (0.04s)
native_test.go:142: status 200 want 400
```

## replay reservation

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeExchangeGates$/replay$|^TestNativeConcurrentExchange$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeExchangeGates (0.03s)
--- FAIL: TestNativeExchangeGates/replay (0.03s)
native_test.go:142: status 200 want 401
--- FAIL: TestNativeConcurrentExchange (0.04s)
native_test.go:207: concurrent mints 8
```

## identical unknown including choice new

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeUnknownIsIdentical$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeUnknownIsIdentical (0.01s)
native_test.go:169: unknown status: 409
```

## roster before replay reservation

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeUnknownIsIdentical$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeUnknownIsIdentical (0.02s)
native_test.go:178: unknown allocated oficina_handoff_replay 1 <nil>
```

## roster unavailable

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeExchangeGates$/unavailable$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeExchangeGates (0.02s)
--- FAIL: TestNativeExchangeGates/unavailable (0.02s)
native_test.go:142: status 403 want 503
```

## session epoch at mint

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeExchangeGates$/epoch$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeExchangeGates (0.02s)
--- FAIL: TestNativeExchangeGates/epoch (0.02s)
native_test.go:142: status 200 want 403
```

## reserve releases writer before mint

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeConcurrentExchange$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeConcurrentExchange (2.02s)
native_test.go:200: concurrent status 503
```

## absolute seven days

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeSessionAbsoluteLifetime$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeSessionAbsoluteLifetime (0.02s)
native_test.go:263: absolute native lifetime slid
```

## home derived method resolution

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeSessionAbsoluteLifetime$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeSessionAbsoluteLifetime (0.03s)
native_test.go:260: native resolution {pr_aaaaaaaaaaaaaaaaaaaaaaaaaa home-assertion-native 2026-11-20 14:23:01 +0000 UTC 2026-11-20 14:23:01 +0000 UTC} oficina identity refused
```

## source session method

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeSessionOnRejectsLocal$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeSessionOnRejectsLocal (0.01s)
native_test.go:285: local session authorized native device
```

## native unlink deletion

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/oficinaid -run ^TestNativeUnlinkDeletesSession$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestNativeUnlinkDeletesSession (0.02s)
native_test.go:294: native sessions retained 1 <nil>
```

## device actor and source person

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPINativeDeviceTransactionGuards$/(actor|session-person)$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestPersonAPINativeDeviceTransactionGuards (0.46s)
--- FAIL: TestPersonAPINativeDeviceTransactionGuards/actor (0.45s)
person_api_native_id_test.go:251: native device guard accepted actor
--- FAIL: TestPersonAPINativeDeviceTransactionGuards/session-person (0.01s)
person_api_native_id_test.go:251: native device guard accepted session-person
```

## device source method

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPINativeDeviceTransactionGuards$/session-method$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestPersonAPINativeDeviceTransactionGuards (0.45s)
--- FAIL: TestPersonAPINativeDeviceTransactionGuards/session-method (0.45s)
person_api_native_id_test.go:251: native device guard accepted session-method
```

## device source expiry

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPINativeDeviceTransactionGuards$/session-expiry$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestPersonAPINativeDeviceTransactionGuards (0.45s)
--- FAIL: TestPersonAPINativeDeviceTransactionGuards/session-expiry (0.45s)
person_api_native_id_test.go:251: native device guard accepted session-expiry
```

## device transactional roster

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPINativeDeviceTransactionGuards$/roster$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestPersonAPINativeDeviceTransactionGuards (0.45s)
--- FAIL: TestPersonAPINativeDeviceTransactionGuards/roster (0.45s)
person_api_native_id_test.go:251: native device guard accepted roster
```

## device expiry follows original session

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPINativeDevice$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestPersonAPINativeDevice (0.47s)
person_api_native_id_test.go:111: wrong owner, source, or expiry
```

## audit credential exclusion

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPINativeDevice$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestPersonAPINativeDevice (0.46s)
person_api_native_id_test.go:120: credential or label in audit
```

## audit failure rollback

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPINativeDeviceTransactionGuards$/audit$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestPersonAPINativeDeviceTransactionGuards (0.46s)
--- FAIL: TestPersonAPINativeDeviceTransactionGuards/audit (0.46s)
person_api_native_id_test.go:251: native device guard accepted audit
```

## device key length

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPINativeDeviceGates$/key$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestPersonAPINativeDeviceGates (0.47s)
--- FAIL: TestPersonAPINativeDeviceGates/key (0.00s)
person_api_native_id_test.go:196: native HTTP 200, want 422
```

## device revocation cascade

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPINativeSessionRevocation$/session$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestPersonAPINativeSessionRevocation (0.46s)
--- FAIL: TestPersonAPINativeSessionRevocation/session (0.46s)
person_api_native_id_test.go:281: native device remained live session
```

## push cleanup cascade

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPINativeSessionRevocation$/session$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestPersonAPINativeSessionRevocation (0.46s)
--- FAIL: TestPersonAPINativeSessionRevocation/session (0.46s)
person_api_native_id_test.go:285: push secret survived push_registrations
```

## device same origin

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPINativeDeviceGates$/no-origin$ -count=1 -timeout=15s`

Caught:

```text
--- FAIL: TestPersonAPINativeDeviceGates (0.47s)
--- FAIL: TestPersonAPINativeDeviceGates/no-origin (0.00s)
person_api_native_id_test.go:196: native HTTP 200, want 403
```

## Scope and contracts

Paul's clarification on 2026-11-20 limits this branch to existing explicit
Oficina ID links. Every unlinked subject, even with `choice:"new"`, receives
403 unknown. There is no allocation or 409 choice path. The approved spec's
Order section records Home roster integration as follow-up work.

`POST /native/oficina-id` accepts JSON `{assertion, verifier, choice?}`.
`verifier` is canonical unpadded base64url of 32 random bytes (43 ASCII
characters). Challenge hashes those ASCII characters; the nonce hashes the
native context and decoded challenge, taking the first 16 bytes as Home's
handoff protocol specifies. Only absent choice or `"new"` is accepted; it
never allocates. Origin and Sec-Fetch-Site headers are refused, including an
empty Origin. There are no cookies set. All answers are JSON and no-store:

- 200: `{name, value, expires_at}`, with expiry in Unix seconds.
- 400: `{"state":"invalid"}`.
- 401: `{"state":"failed"}`.
- 403: `{"state":"unknown"}`, byte-identical for every unknown subject.
- 503: `{"state":"unavailable"}` for unavailable roster/storage.

`POST /api/v1/auth/devices/native` accepts JSON `{public_key, label}` and the
exchange session as a Cookie. Send `Origin: <instance origin>`. A device bearer,
a web Oficina ID session, a local session, and mixed credentials cannot
register a device. public_key is canonical unpadded base64url of the existing
pairing protocol's 32-byte Curve25519 signing public key. label is 1–128 UTF-8
bytes without NUL, CR or LF. No person or actor field is accepted.
Idempotency-Key is not required: each success registers a new device.

The 200 response is pairing's existing PersonCredential:
`{id, token, audience, instance_id, expires_at}`. audience is
`equipo.person.v1`; expires_at is an RFC3339 UTC timestamp, seven days after
the source session's At, including when registration occurs days later.
Errors use the existing `{code, copy_key, request_id, current_revision?}`
envelope: 401 unauthenticated, 403 forbidden, 422 invalid_input and 503
unavailable. Paired devices retain their existing 30-day expiry.

The audit action `person_device.native` records the verified actor and device
ID only. It has no token, session hash, public key or label. This adds no
rendered interface text. Source session deletion revokes its native devices,
clears pending credential responses and removes their push tokens and pending
pushes. Unlink and roster deletion/address changes reach the same cascade.
Home grant revocation alone has the native spec's disclosed offline residual:
without instance session deletion, an already issued session and device may
last to their absolute seven-day expiry.

## Transaction and live evidence

The handoff module is advanced to e03a01a1881c to reuse its verified native
nonce and durable Reserve implementation; Rastrillo remains v0.30.3.
Reserve commits its own short transaction before mintNative is invoked.
The latter opens its own transaction and uses that handle for link resolution,
current roster/epoch checks, the session insert and audit. No external hook
or framework session writer is called with that writer held. With unlinked
allocation deferred, there are no Admit, Unlinked or HomeOnly hooks here.

TestNativeVerifierDoesNotWaitOnWriter holds the only connection in a write
transaction and verifies a bad assertion returns without waiting on it.
TestNativeConcurrentExchange performs successful exchanges with the pool
limited to one connection; the mutation that holds a writer across the mint
fails with 503 instead of wedging. It also proves only one of eight concurrent
redemptions succeeds and replay survives a new Store. TestNativeConcurrentUnlink
covers exchange racing unlink and replay after relink.

TestPersonAPINativeLiveExchange runs a fake Home signing server and Equipo's
production router on loopback HTTP/TLS listeners. It obtains an assertion,
exchanges it, registers a device, and successfully reads the engine snapshot
using only the resulting device bearer. Its source-session and credential
expiries agree. Test cleanup closes both listeners and their databases.

## Home follow-up, inspected read-only

Inspected Home origin/main at 17cdcaff33452b49eb7bd38c999219a5bc49dcc4.
No Home files were changed.

- `internal/home/native_assert.go`: nativeAssert already accepts any exact
  origin in consumers(), except the operator consumer, and calls shared
  mintPolicy. Equipo requires no app-specific assert bypass or new audience
  predicate. Its exact origin must be an active consumer.
- `internal/home/consumer_registry.go`: consumers() is HOME_CONSUMERS plus
  active consumer-table records. Registration must use the existing operator
  flow; duplicate ID/origin entries in the environment and table fail closed.
  Source inspection cannot attest to a deployed registry entry: the operator
  must verify each Equipo consumer and its exact origin before rollout.
- Add Equipo to `nativeTeamApps` in `internal/home/directory_native.go`, so
  GET /api/native/teams can return it as the sixth native app.
- Add the integrated app in `directoryApps()` in
  `internal/home/directory_runtime.go`; this also supplies the allowed apps
  for directorydata.Store and the directory roster source. Merely adding the
  native filter entry is insufficient: AgentChoices also filters allowed apps.
- Add Equipo to `directorydata.CanonicalOrigin` for the existing `oficina`
  team and its `equipo` consumer at `https://equipo.oficina.works`.
  Other teams use their registered `https://<label>.equipo.oficina.works`
  route. The canonical rule also gates operator adoption planning.
- Add the display catalog entry and any desired preview configuration in
  `directory_catalog.go`; cover Equipo in chooser/catalog tests.
- Extend TestNativeAssert for a registered Equipo audience and near-misses,
  and TestNativeDirectoryTeams for a current member's live Equipo instance,
  including pending/disabled and non-member exclusion. Keep unavailable
  directory reads as errors, never empty team counts.
- Paul still performs Alta adoption and Home confirmations to create the
  membership and live team_instances records. This branch does not provision
  or assert their existence, or create an unlinked person locally.

## Restored verification

All 28 mutations above failed their intended assertions and were restored.
With `GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0`:

- `go test ./internal/equipo ./internal/equipo/oficinaid ./internal/equipo/personapi ./internal/wire/wireschema -count=1`: passed.
- `go test ./internal/plan3test -run TestPersonAPI -count=1`: passed, including both contract tests and all native route tests.
- The app and integration size allowances are updated to the measured 21508
  source lines and 11852 test lines, respectively, for the added wiring and
  security/integration tests.
- `make runner-dead-references lanes-check fmt-check budget migration-check`:
  passed, with the Go 1.26.11 toolchain directory first on PATH.
- `go vet ./internal/equipo ./internal/equipo/oficinaid ./internal/equipo/personapi ./internal/wire/wireschema ./internal/plan3test`: passed.
- `make copy-release-check`: passed; no new rendered copy was introduced.
- Reference scan after staging all new files: 2487 text files, 2846 matches,
  zero failures.

## Review fixes (Astra review 1, by Claude)

**P1. A native session could approve a paired device.** Pairing approval
mints a 30-day credential, so a 7-day Oficina ID session could outlive
itself through it. `DeviceStore.Approve` now refuses any principal with a
`SessionHash` (`ErrForbidden`), and `DeviceBrowser.ApproveForm` refuses a
native cookie before reaching approval. The person's web session still
approves.

- `personapi.TestNativeSessionNeverApprovesAPairedDevice` and
  `TestNativeSessionNeverApprovesFromTheBrowserForm` failed first ("native
  session reached the approval write", "native session reached approval").
- `plan3test.TestPersonAPINativeSessionNeverApprovesPairing` drives both
  routes with the minted native cookie (403 each, device stays unapproved),
  then approves with the person's web session (200).
- Mutations: store guard to `if false` failed the store test and the
  end-to-end test (`native HTTP 200, want 403`); browser guard removed failed
  the browser-form test. Both restored.

**P2. The native inputs lost `required`.** The generator writes input
schemas with nothing required, which replaced the hand-written
`BeginDeviceInput` (`public_key`, `label`). `wireschema.InputRequired` now
names the fields the handlers refuse to go without, for `BeginDeviceInput`
and `NativeRequest` (`assertion`, `verifier`), and panics on a name the
type lacks. The document carries both lists.

- `wireschema.TestNativeInputsRequireWhatTheirHandlersRequire` validates
  incomplete bodies (refused) and complete ones (accepted); it failed first
  on four bodies.
- Mutation: dropping the required list failed that test and
  `TestPersonAPIDeviceContract`. Restored.

`TestRequestBodies` (inputs require nothing) now exempts exactly the
`InputRequired` names.

Gates on macOS, with `GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0`: `fmt-check`,
`gitleaks`, `budget` (plan3test raised to the measured 11887 test lines),
`migration-check`, `copy-release-check`, `lanes-check` and
`runner-dead-references` pass; `personapi`, `oficinaid`, `wireschema` and
the `TestPersonAPI` contracts pass. `make test` here fails only where macOS
cannot run it: the Linux runner packages, the browser tests (no Chromium),
and `TestCoordinatorAcceptance3B` and `TestPublishCoreAuthorizationContract`,
which fail the same way on main. `vet` and `staticcheck` stop at
`internal/toolproxy` (`unix.O_PATH`, Linux only). CI on Linux is the gate.
