# Project card hardening

Branch: projects/card-tests, based on origin/main f6189100. The landed
projects/card-names worktree was clean and has been removed.

## Plan

1. Choose both existing repositories in the placement identity regression.
   Mutate the identity condition so every option matches the first repository;
   the second-choice test must fail, then pass after restoration.
2. Send exactly "Don't use choice03" through the device API with a visible typed
   card and a real trusted name choice03. Mutate anchored matching to substring
   matching; the card must incorrectly close and the regression must fail.
3. Send a matching project name with a runner below ProtocolPlacement. Observe
   the current 409, then preflight the capability and pass through as an ordinary
   message. Remove the preflight deliberately and observe the same failure.
4. Run the pinned gates, suites and fixture checks. Commit, scan references,
   push only this branch through the helper, and wait for Linux CI.

No runtime copy, wire shape, migrations, main push or deployment changes.

## Findings and evidence

1. Identity mapping: the regression now chooses both old and new, checking the
   learned name against the selected project's ID. Disabling the identity
   condition chooses p_old for the second option and fails.
2. Phrase anchoring: the device API regression sends exactly "Don't use choice03"
   with choice03 registered as a trusted team name. Matching use anywhere
   incorrectly answers the card, so the state assertion fails.
3. Old runner: the new device case first reproduced HTTP 409 idempotency_conflict
   at ProtocolPlacement - 1. Composer interception now checks placement support
   before answering; an old runner uses ordinary send behavior instead. The card
   stays open, words and retry identity are preserved, and the message dispatches.

Test-first command: `GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/chat ./internal/thintest -run 'TestCardNamesPlacementIdentity|TestCardNamesComposerDevice' -count=1`.
Before the fix, the old-runner case failed with 409. After the fix both packages
passed (0.490s and 2.698s). Each mutation below ran alone and was restored in a
finally block. All three failed on the intended assertion.

### every option matches first repository

File: `internal/equipo/chat/project_resolution.go`.

Changed `if choice != ProjectName(repo) && repo != p.ChosenRepo {` to `if false && choice != ProjectName(repo) && repo != p.ChosenRepo {`.

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/equipo/chat -run TestCardNamesPlacementIdentity/suggestion=portal/new -count=1`

```text
--- FAIL: TestCardNamesPlacementIdentity (0.06s)
    --- FAIL: TestCardNamesPlacementIdentity/suggestion=portal/new (0.06s)
        project_card_names_test.go:262: name learned for the wrong repository [{p_old owner@example.com portal 2026-11-12 12:00:00 +0000 UTC}] want new
FAIL
rastrillo-budget/v1 ran 58ms
FAIL	amadan.net/oficina/equipo/internal/equipo/chat	0.438s
FAIL
```

### unanchored use phrase

File: `internal/equipo/chat/project_composer.go`.

Changed `if name, ok := strings.CutPrefix(phrase, prefix); ok {` to `if _, name, ok := strings.Cut(phrase, prefix); ok {`.

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/thintest -run TestCardNamesComposerDevice/negated -count=1`

```text
--- FAIL: TestCardNamesComposerDevice (0.61s)
    --- FAIL: TestCardNamesComposerDevice/negated (0.61s)
        project_card_names_test.go:91: card state answered want open
FAIL
rastrillo-budget/v1 ran 615ms
FAIL	amadan.net/oficina/equipo/internal/thintest	1.156s
FAIL
```

### missing old-runner pass-through

File: `internal/equipo/chat/project_composer.go`.

Changed `if err := t.placementRunner(person); errors.Is(err, ErrConflict) {` to `if err := t.placementRunner(person); false && errors.Is(err, ErrConflict) {`.

`GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0 go test ./internal/thintest -run TestCardNamesComposerDevice/old-runner -count=1`

```text
--- FAIL: TestCardNamesComposerDevice (0.61s)
    --- FAIL: TestCardNamesComposerDevice/old-runner (0.61s)
        project_card_names_test.go:71: composer refused by open card HTTP 409: {"code":"idempotency_conflict","copy_key":"api.idempotency_conflict","request_id":"SIMM24KXQIDDT5NUJ2WDGNKH4O"}
FAIL
rastrillo-budget/v1 ran 611ms
FAIL	amadan.net/oficina/equipo/internal/thintest	1.135s
FAIL
```

## Final local verification

All commands used GOTOOLCHAIN=go1.26.11, CGO_ENABLED=0 and pinned gofmt on PATH.
fmt-check, gitleaks, budget, migration-check, copy-release-check, lanes-check and
spacing passed. Full suites passed: equipo 18.121s, chat 3.634s, thintest 154.219s,
wire 0.224s, wireschema 0.618s and testci 12.915s. PersonAPI/Plan3Release passed
in 11.433s; all seven native fixtures match the schema.

Measured budgets: chat 33340 source / 8282 test lines, thintest 33989 test lines.
The increases are five source, two chat-test and twelve device-test lines.
Explanations remain below 200 bytes; TestBudgetRecordsAreShort passed.

Fresh origin/main is f6189100454e8e914f9e87ac9c9c31d6f0e08bd0, the branch base.
No integration merge is needed. Postcommit reference scan and Linux CI verdict
will be reported with the pushed SHA. No copy changes or outstanding decisions.
