oficina / equipo Public

fix: verify Amadan descriptions through production readback

codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev 97126e1ef0aacf2787541c83bfa99404d51a02f2 parent a624bec
8 files changed, +2,155 −53
  • docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md +1,590 −0
  • internal/equipotest/publish_test.go +16 −0
  • internal/runner/forge/description.go +33 −14
  • internal/runner/forge/description_test.go +271 −12
  • internal/runner/forge/description_transport.go +79 −0
  • internal/runner/forge/publisher.go +30 −12
  • internal/runner/forge/publisher_test.go +135 −2
  • internal/runner/runtime_workflow.go +1 −13

CI failed — run details

diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md
index 061669c8..5be0877a 100644
--- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md
+++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md
@@ -21130,3 +21130,1593 @@ and this controller report were added. No copy-review server, provider prompt,
subagent, credentials, server, scratch file, push or deployment was used.
Go caches stayed at their defaults. Task 11a must lower or remove the test
exemption after removing the named legacy coverage. No other concerns.
+
+
+---
+
+# Task 10: Amadan description publication readback
+
+Status: DONE. Branch: `plan-2b`. Workspace: `/home/paulca/amadan.net/oficina/equipo-plan-2b`.
+Commit subject: `fix: verify Amadan descriptions through production readback`.
+
+## Built
+
+The runtime now constructs the production description transport with the installed
+Amadan command writer. The only runtime wiring change replaces the unavailable
+description placeholder; Task 9's launchers, namespaces, direct launch, checks,
+workspace, supervisor and workflow wiring remain intact.
+
+`DescriptionChannels` and `DescriptionContentHash` implement the four-channel
+contract: description, human, summary and notes, each prefixed by its unsigned
+8-byte big-endian UTF-8 byte length. The tests pin both required literal hashes:
+
+- Empty channels: `sha256:66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925`.
+- `["Equipo café\n", "Paul", "Fixed\nchecked", "✓"]`, with actual newlines:
+ `sha256:ac030712c32422e57053ff69f80ec87d1efdff87a000e9a08dd3e711d0995a88`.
+
+The GET reader accepts an unqualified review ref and escapes the entire name as
+one path segment. It validates the disclosed agent in `by`, the complete channel
+hash and structured optional `agent` metadata. It retains the channels, content
+hash, `at` and agent metadata in the returned Description. Its body digest is
+separate from the API channel hash. Text is preserved verbatim. Empty descriptions,
+malformed JSON, invalid UTF-8, oversized responses and unsuccessful HTTP responses
+cannot confirm publication. GET has a 15-second deadline, a 1 MiB response limit,
+no redirects and no inherited cookie credentials.
+
+The transport always reports `BeforePush() == false`. The publisher keeps the
+pending expected description in its journal before push. After checking the exact
+remote head it reads, journals the description attempt before Set, then reads again
+even if Set loses its reply. Reconciliation after restart reads without repeating
+Set or push. A visible ref remains incomplete until the exact expected repository,
+ref, agent, body and body digest match the validated readback. Existing candidate,
+head, default-ref, agent, isolation and evidence checks remain in place.
+
+The command writer uses `amadan branch describe <ns>/<repo> <name> -hub
+https://amadan.net -body -`. Body text goes through stdin. The child receives only
+its fixed HOME/PATH and a disposable AMADAN_HOME containing one supplied hub token
+in a 0600 credentials file under a 0700 directory. The command has a 15-second
+bound, process-group cancellation, discarded stdout/stderr and sanitized errors.
+Command state is removed on return. No credentials enter argv or application logs.
+
+Tests cover the carried `approved beyond profile` label in both GET readback and
+publication recovery, with whitespace and Unicode preserved. Production ordering
+is tested against a bare local Git repository and a loopback GET server. A fake
+Python describe command checks argv, stdin, environment, credential file modes,
+cleanup, errors and cancellation. The real installed CLI was never used to write.
+
+## Files
+
+- `internal/runner/forge/description.go`: channel hash and validated GET readback.
+- `internal/runner/forge/description_transport.go`: transport and scoped command writer.
+- `internal/runner/forge/publisher.go`: explicit expected-description comparison and durable write-attempt recovery.
+- `internal/runner/runtime_workflow.go`: replace only the description placeholder.
+- `internal/runner/forge/description_test.go`: hash, HTTP and fake-command tests.
+- `internal/runner/forge/publisher_test.go`: production-transport recovery and independent expected-field checks.
+- `internal/equipotest/publish_test.go`: production wiring assertion, including retained Task 9 fields.
+- `docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md`: appended this Task 10 report.
+- `.superpowers/sdd/2026-11-03-equipo-plan-2b-direct/task-10-report.md`: this report, saved in the repository's ignored controller workspace.
+
+## Installed CLI evidence
+
+Read-only `amadan branch describe -h` reported `-body string`, with `"-" reads
+stdin`, and `-hub string`. `amadan branch -h` reported:
+
+```text
+amadan branch describe [<ns>/<repo>] <name> -body D|-
+```
+
+Both help commands exit 1 with their usage output. There is no `branch show` in
+the installed contract. `amadan -h` also confirmed explicit hub/repository selection.
+No login, enrollment, provider prompt or live publication was run.
+
+To avoid inventing a token environment variable, read-only inspection of
+`/home/paulca/.local/bin/amadan` used `go tool nm`, `go tool objdump` and binary
+string extraction. `helper.Home` reads AMADAN_HOME; `helper.CredentialsPath` appends
+`credentials`; `helper.LoadCredentials` unmarshals the `tokens` map; and
+`cli.CredentialFor` indexes it by normalized hub. `main.readBodyArg` uses
+`io.ReadAll` and byte-to-string conversion without trimming. No other worktree or
+credential store was read or changed. The fake command pins this installed layout.
+
+## Interpretations
+
+1. New interface names initially did not exist. Tests were written first and the
+ required command failed to compile, while the production-wiring assertion also
+ failed. Minimal declarations then exposed the old JSON hashing and qualified-ref
+ behavior, allowing the same command to produce behavioral RED before the fix.
+2. The old lost-reply test required the first Execute call to fail even when the
+ description had been stored. The brief requires GET after a lost Set reply, so
+ the updated test accepts immediate success only after confirmed GET. When GET
+ remains empty, the result stays uncertain and later reconciliation only reads.
+3. A durable Set intent is treated as possibly dispatched even if a crash happened
+ before the command began. This follows the security intent of avoiding a second
+ send after a lost reply. The publisher does not guess that such a write failed.
+4. The ban on credential homes is applied to account provisioning, provider homes
+ and real login state. The installed CLI's credential-scoped writer necessarily
+ needs disposable command state. Tests create only temporary files containing
+ `fake-only`, run a fake command and remove that state. No real credential home
+ was created, copied or changed.
+5. These are controller evidence reports and code changes. The explicit instruction
+ to avoid copy-review takes precedence over generic writing workflows. README
+ and copy.go are unchanged. No handoff file or subagent was created.
+6. The task report directory is ignored by the repository. The report is saved at
+ the requested path; the same complete evidence is appended to the tracked
+ controller report and included in the commit.
+
+## RED evidence
+
+All test commands ran from the workspace above with CGO_ENABLED=0 and default Go
+caches. Tests were added before behavior changes. First run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge ./internal/runner ./internal/equipotest -run 'TestAmadanDescription|TestPublishDescription|TestPublishTransport' -count=1
+```
+
+Exit 1 from Go. Initial output:
+
+```text
+# amadan.net/oficina/equipo/internal/runner/forge [amadan.net/oficina/equipo/internal/runner/forge.test]
+internal/runner/forge/description_test.go:47:7: undefined: DescriptionChannels
+internal/runner/forge/description_test.go:48:240: undefined: DescriptionContentHash
+internal/runner/forge/description_test.go:52:46: undefined: DescriptionChannels
+internal/runner/forge/description_test.go:53:13: undefined: DescriptionChannels
+internal/runner/forge/description_test.go:54:12: undefined: DescriptionChannels
+internal/runner/forge/description_test.go:55:51: undefined: DescriptionContentHash
+internal/runner/forge/description_test.go:56:5: undefined: DescriptionContentHash
+internal/runner/forge/description_test.go:56:28: undefined: DescriptionChannels
+internal/runner/forge/description_test.go:56:81: undefined: DescriptionContentHash
+internal/runner/forge/description_test.go:56:104: undefined: DescriptionChannels
+internal/runner/forge/description_test.go:56:104: too many errors
+FAIL amadan.net/oficina/equipo/internal/runner/forge [build failed]
+ok amadan.net/oficina/equipo/internal/runner 0.006s [no tests to run]
+--- FAIL: TestPublishTransportIsProduction (0.00s)
+ publish_test.go:102: runtime publication still uses unavailable description transport
+FAIL
+rastrillo-budget/v1 ran 6ms
+FAIL amadan.net/oficina/equipo/internal/equipotest 0.071s
+FAIL
+
+```
+
+After adding only interface/data declarations, the old JSON hash helper, forwarding
+transport scaffold and an unavailable writer stub, repeat the same command:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge ./internal/runner ./internal/equipotest -run 'TestAmadanDescription|TestPublishDescription|TestPublishTransport' -count=1
+```
+
+Exit 1 from Go. Behavioral RED output:
+
+```text
+--- FAIL: TestAmadanDescriptionLengthHash (0.00s)
+ --- FAIL: TestAmadanDescriptionLengthHash/empty (0.00s)
+ description_test.go:58: hash = sha256:8c6e780bd03fbe1f0699ae90e38ca9d7af0f5ac91747c2a9b66ae942294f2cd9, want sha256:66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925
+ --- FAIL: TestAmadanDescriptionLengthHash/utf8 (0.00s)
+ description_test.go:58: hash = sha256:5a0cb8c4ae8f2bfba1ae730c81064829eeaa704deae924e9d8a464e1c2c0fdb5, want sha256:ac030712c32422e57053ff69f80ec87d1efdff87a000e9a08dd3e711d0995a88
+--- FAIL: TestAmadanDescriptionReadback (0.08s)
+ --- FAIL: TestAmadanDescriptionReadback/valid (0.00s)
+ description_test.go:99: team: invalid
+ --- FAIL: TestAmadanDescriptionReadback/optional_agent (0.00s)
+ description_test.go:99: team: invalid
+ --- FAIL: TestAmadanDescriptionReadback/reordered (0.00s)
+ description_test.go:99: team: invalid
+--- FAIL: TestAmadanDescriptionCommand (0.00s)
+ description_test.go:135: team: uncertain
+--- FAIL: TestPublishDescriptionIdentity (0.39s)
+ --- FAIL: TestPublishDescriptionIdentity/lost_description_reply (0.23s)
+ publisher_test.go:402: GET failed to confirm lost description reply team: uncertain
+--- FAIL: TestPublishDescriptionRecovery (1.10s)
+ --- FAIL: TestPublishDescriptionRecovery/lost_reply (0.20s)
+ publisher_test.go:591: description intent not durable before write
+ --- FAIL: TestPublishDescriptionRecovery/delayed_readback (0.16s)
+ publisher_test.go:591: description intent not durable before write
+ --- FAIL: TestPublishDescriptionRecovery/empty (0.16s)
+ publisher_test.go:591: description intent not durable before write
+ --- FAIL: TestPublishDescriptionRecovery/trimmed (0.16s)
+ publisher_test.go:591: description intent not durable before write
+ --- FAIL: TestPublishDescriptionRecovery/wrong_digest (0.17s)
+ publisher_test.go:591: description intent not durable before write
+ --- FAIL: TestPublishDescriptionRecovery/wrong_ref (0.25s)
+ publisher_test.go:591: description intent not durable before write
+FAIL
+rastrillo-budget/v1 ran 1.694s
+FAIL amadan.net/oficina/equipo/internal/runner/forge 1.697s
+ok amadan.net/oficina/equipo/internal/runner 0.005s [no tests to run]
+--- FAIL: TestPublishTransportIsProduction (0.00s)
+ publish_test.go:102: runtime publication still uses unavailable description transport
+FAIL
+rastrillo-budget/v1 ran 3ms
+FAIL amadan.net/oficina/equipo/internal/equipotest 0.063s
+FAIL
+
+```
+
+## GREEN evidence
+
+The first implemented run passed, followed by the extended cases and mutation
+checks. Final restored command and output:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge ./internal/runner ./internal/equipotest -run 'TestAmadanDescription|TestPublishDescription|TestPublishTransport' -count=1
+```
+
+Exit 0:
+
+```text
+ok amadan.net/oficina/equipo/internal/runner/forge 1.703s
+ok amadan.net/oficina/equipo/internal/runner 0.005s [no tests to run]
+ok amadan.net/oficina/equipo/internal/equipotest 0.055s
+
+```
+
+Targeted existing publication regressions, including the carried approval label:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge ./internal/runner ./internal/equipotest -run 'TestAmadanDescription|TestPublish|TestApprovedBeyondProfilePublisher' -count=1
+```
+
+Exit 0:
+
+```text
+ok amadan.net/oficina/equipo/internal/runner/forge 7.216s
+ok amadan.net/oficina/equipo/internal/runner 0.006s [no tests to run]
+ok amadan.net/oficina/equipo/internal/equipotest 0.664s
+
+```
+
+The runner package compiles in both commands; these name filters select no runner
+package tests. The runtime wiring assertion runs in equipotest. No whole suite,
+make ci, provider command or live Amadan gate was run. `git diff --check` passed.
+
+## Mutation evidence
+
+47 independent mutations compiled and failed their named tests. Each edit below
+was applied alone, the exact test command was run, and the original source bytes
+were restored in a finally block before the next mutation. No compilation failure
+is counted. The final GREEN runs above used restored code. Replacement strings
+below use Python literal notation; they identify the exact source edit.
+
+### M01: json_hash
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'return "sha256:" + hex.EncodeToString(hash.Sum(nil))'
+```
+
+with:
+
+```python
+'_ = hex.EncodeToString(hash.Sum(nil))\n raw, _ := json.Marshal(c)\n return "sha256:" + team.ContentDigest(raw)'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionLengthHash' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionLengthHash (0.00s)
+ --- FAIL: TestAmadanDescriptionLengthHash/empty (0.00s)
+ description_test.go:71: hash = sha256:8c6e780bd03fbe1f0699ae90e38ca9d7af0f5ac91747c2a9b66ae942294f2cd9, want sha256:66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925
+ --- FAIL: TestAmadanDescriptionLengthHash/utf8 (0.00s)
+ description_test.go:71: hash = sha256:5a0cb8c4ae8f2bfba1ae730c81064829eeaa704deae924e9d8a464e1c2c0fdb5, want sha256:ac030712c32422e57053ff69f80ec87d1efdff87a000e9a08dd3e711d0995a88
+```
+
+### M02: trim_text
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'metadata := bytes.TrimSpace(result.Agent)'
+```
+
+with:
+
+```python
+'result.Description = strings.TrimSpace(result.Description)\n metadata := bytes.TrimSpace(result.Agent)'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback/valid' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.00s)
+ --- FAIL: TestAmadanDescriptionReadback/valid (0.00s)
+ description_test.go:159: lost verbatim content or metadata: {Repository:amadan.net/oficina/equipo Ref:review/trial Agent:equipo~owner@example.com Body:Equipo café
+```
+
+### M03: ignore_by
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+' || result.By != cred.Agent'
+```
+
+with:
+
+```python
+''
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback/wrong_agent' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.00s)
+ --- FAIL: TestAmadanDescriptionReadback/wrong_agent (0.00s)
+ description_test.go:153: accepted wrong_agent
+```
+
+### M04: ignore_hash
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'if result.ContentHash != DescriptionContentHash(result.DescriptionChannels) {'
+```
+
+with:
+
+```python
+'if false {'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback/(wrong_hash|tamper)' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.00s)
+ --- FAIL: TestAmadanDescriptionReadback/tamper (0.00s)
+ description_test.go:153: accepted tamper
+ --- FAIL: TestAmadanDescriptionReadback/wrong_hash (0.00s)
+ description_test.go:153: accepted wrong_hash
+```
+
+### M05: accept_empty
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+' || result.Empty'
+```
+
+with:
+
+```python
+''
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback/empty' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.00s)
+ --- FAIL: TestAmadanDescriptionReadback/empty (0.00s)
+ description_test.go:153: accepted empty
+```
+
+### M06: lose_at
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'At: result.At'
+```
+
+with:
+
+```python
+'At: 0'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback/valid' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.00s)
+ --- FAIL: TestAmadanDescriptionReadback/valid (0.00s)
+ description_test.go:159: lost verbatim content or metadata: {Repository:amadan.net/oficina/equipo Ref:review/trial Agent:equipo~owner@example.com Body: Equipo café
+```
+
+### M07: lose_metadata
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'AgentMetadata: result.Agent'
+```
+
+with:
+
+```python
+'AgentMetadata: nil'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback/valid' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.00s)
+ --- FAIL: TestAmadanDescriptionReadback/valid (0.00s)
+ description_test.go:162: lost structured agent metadata
+```
+
+### M08: accept_unstructured_metadata
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'len(metadata) > 0 && string(metadata) != "null" && metadata[0] != \'{\''
+```
+
+with:
+
+```python
+'false && len(metadata) > 0'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback/bad_metadata' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.00s)
+ --- FAIL: TestAmadanDescriptionReadback/bad_metadata (0.00s)
+ description_test.go:153: accepted bad_metadata
+```
+
+### M09: accept_invalid_utf8
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'!utf8.Valid(data) || '
+```
+
+with:
+
+```python
+'!utf8.Valid(data) && false || '
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback/invalid_utf8' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.00s)
+ --- FAIL: TestAmadanDescriptionReadback/invalid_utf8 (0.00s)
+ description_test.go:153: accepted invalid_utf8
+```
+
+### M10: ignore_decode_error
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'json.Unmarshal(data, &result) != nil'
+```
+
+with:
+
+```python
+'json.Unmarshal(data, &result) != nil && false'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback/malformed_at' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.00s)
+ --- FAIL: TestAmadanDescriptionReadback/malformed_at (0.00s)
+ description_test.go:153: accepted malformed_at
+```
+
+### M11: allow_oversized
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'1<<20'
+```
+
+with:
+
+```python
+'2<<20'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback/oversized' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.01s)
+ --- FAIL: TestAmadanDescriptionReadback/oversized (0.01s)
+ description_test.go:153: accepted oversized
+```
+
+### M12: follow_redirect
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'local.CheckRedirect = func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }'
+```
+
+with:
+
+```python
+'local.CheckRedirect = nil'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback/redirect' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.00s)
+ --- FAIL: TestAmadanDescriptionReadback/redirect (0.00s)
+ description_test.go:89: followed redirect with credentials
+```
+
+### M13: no_get_deadline
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'context.WithTimeout(ctx, 15*time.Second)'
+```
+
+with:
+
+```python
+'context.WithCancel(ctx)\n _ = time.Second'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback/valid' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.00s)
+ --- FAIL: TestAmadanDescriptionReadback/valid (0.00s)
+ description_test.go:42: missing bounded GET deadline
+ --- FAIL: TestAmadanDescriptionReadback/invalid_utf8 (0.00s)
+ description_test.go:42: missing bounded GET deadline
+```
+
+### M14: unescaped_slash
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'url.PathEscape(branch)'
+```
+
+with:
+
+```python
+'branch'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback/valid' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.00s)
+ --- FAIL: TestAmadanDescriptionReadback/valid (0.00s)
+ description_test.go:94: wrong request: GET /api/v1/repos/oficina/equipo/branches/review/trial/description
+ --- FAIL: TestAmadanDescriptionReadback/invalid_utf8 (0.00s)
+ description_test.go:94: wrong request: GET /api/v1/repos/oficina/equipo/branches/review/trial/description
+```
+
+### M15: require_qualified_ref
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'validRef(ref)'
+```
+
+with:
+
+```python
+'strings.HasPrefix(ref, "refs/heads/")'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback/valid' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.00s)
+ --- FAIL: TestAmadanDescriptionReadback/valid (0.00s)
+ description_test.go:157: team: invalid
+ description_test.go:170: invalid target reached HTTP
+```
+
+### M16: ignore_invalid_ref
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'validRef(ref)'
+```
+
+with:
+
+```python
+'true'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.04s)
+ description_test.go:170: invalid target reached HTTP
+ description_test.go:170: invalid target reached HTTP
+ description_test.go:170: invalid target reached HTTP
+ description_test.go:170: invalid target reached HTTP
+```
+
+### M17: description_before_push
+
+File: `internal/runner/forge/description_transport.go`. Replace:
+
+```python
+'BeforePush() bool { return false }'
+```
+
+with:
+
+```python
+'BeforePush() bool { return true }'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestPublishDescriptionRecovery/lost_reply' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestPublishDescriptionRecovery (0.02s)
+ --- FAIL: TestPublishDescriptionRecovery/lost_reply (0.02s)
+ publisher_test.go:625: production transport describes before push
+```
+
+### M18: duplicate_set
+
+File: `internal/runner/forge/publisher.go`. Replace:
+
+```python
+'r.DescriptionAttempted || (e != nil'
+```
+
+with:
+
+```python
+'false || (e != nil'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestPublishDescriptionRecovery/empty' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestPublishDescriptionRecovery (0.19s)
+ --- FAIL: TestPublishDescriptionRecovery/empty (0.19s)
+ publisher_test.go:658: duplicate write/push or skipped GET 3 1 6
+```
+
+### M19: skip_readback
+
+File: `internal/runner/forge/publisher.go`. Replace:
+
+```python
+'if e != nil || !descriptionMatches(got, desc) {'
+```
+
+with:
+
+```python
+'if false {'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestPublishDescriptionRecovery/empty' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestPublishDescriptionRecovery (0.15s)
+ --- FAIL: TestPublishDescriptionRecovery/empty (0.15s)
+ publisher_test.go:638: unconfirmed description delivered success
+```
+
+### M20: lose_write_journal
+
+File: `internal/runner/forge/publisher.go`. Replace:
+
+```python
+'if e = runnerproto.JournalCredentials(p.path(r.Authorization.Ticket.Dispatch), *r); e != nil {'
+```
+
+with:
+
+```python
+'if false {'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestPublishDescriptionRecovery/lost_reply' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestPublishDescriptionRecovery (0.13s)
+ --- FAIL: TestPublishDescriptionRecovery/lost_reply (0.13s)
+ publisher_test.go:616: description intent not durable before write
+```
+
+### M21: no_lost_reply_get
+
+File: `internal/runner/forge/publisher.go`. Replace:
+
+```python
+'_ = p.cfg.Description.Set(ctx, cred, desc)'
+```
+
+with:
+
+```python
+'if e = p.cfg.Description.Set(ctx, cred, desc); e != nil { return team.ErrUncertain }'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestPublishDescriptionRecovery/lost_reply' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestPublishDescriptionRecovery (0.12s)
+ --- FAIL: TestPublishDescriptionRecovery/lost_reply (0.12s)
+ publisher_test.go:633: team: uncertain
+```
+
+### M22: write_after_read_error
+
+File: `internal/runner/forge/publisher.go`. Replace:
+
+```python
+'(e != nil && !errors.Is(e, team.ErrEvidence))'
+```
+
+with:
+
+```python
+'(false && !errors.Is(e, team.ErrEvidence))'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestPublishDescriptionReadFailureDoesNotWrite' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestPublishDescriptionReadFailureDoesNotWrite (0.17s)
+ publisher_test.go:693: read failure caused a write or success team: uncertain 1
+```
+
+### M23: ignore_expected_repository
+
+File: `internal/runner/forge/publisher.go`. Replace:
+
+```python
+'got.Repository == want.Repository'
+```
+
+with:
+
+```python
+'true'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestPublishDescriptionRecovery/wrong_repo' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestPublishDescriptionRecovery (0.15s)
+ --- FAIL: TestPublishDescriptionRecovery/wrong_repo (0.15s)
+ publisher_test.go:638: unconfirmed description delivered success
+```
+
+### M24: ignore_expected_ref
+
+File: `internal/runner/forge/publisher.go`. Replace:
+
+```python
+'got.Ref == want.Ref'
+```
+
+with:
+
+```python
+'true'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestPublishDescriptionRecovery/wrong_ref' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestPublishDescriptionRecovery (0.15s)
+ --- FAIL: TestPublishDescriptionRecovery/wrong_ref (0.15s)
+ publisher_test.go:638: unconfirmed description delivered success
+```
+
+### M25: ignore_expected_agent
+
+File: `internal/runner/forge/publisher.go`. Replace:
+
+```python
+'got.Agent == want.Agent'
+```
+
+with:
+
+```python
+'true'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestPublishDescriptionRecovery/wrong_agent' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestPublishDescriptionRecovery (0.11s)
+ --- FAIL: TestPublishDescriptionRecovery/wrong_agent (0.11s)
+ publisher_test.go:638: unconfirmed description delivered success
+```
+
+### M26: ignore_expected_body
+
+File: `internal/runner/forge/publisher.go`. Replace:
+
+```python
+'got.Body == want.Body'
+```
+
+with:
+
+```python
+'true'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestPublishDescriptionRecovery/wrong_body' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestPublishDescriptionRecovery (0.12s)
+ --- FAIL: TestPublishDescriptionRecovery/wrong_body (0.12s)
+ publisher_test.go:638: unconfirmed description delivered success
+```
+
+### M27: ignore_expected_digest
+
+File: `internal/runner/forge/publisher.go`. Replace:
+
+```python
+'got.Digest == want.Digest'
+```
+
+with:
+
+```python
+'true'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestPublishDescriptionRecovery/wrong_digest' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestPublishDescriptionRecovery (0.15s)
+ --- FAIL: TestPublishDescriptionRecovery/wrong_digest (0.15s)
+ publisher_test.go:638: unconfirmed description delivered success
+```
+
+### M28: inherit_person_environment
+
+File: `internal/runner/forge/description_transport.go`. Replace:
+
+```python
+'cmd.Env = []string{"HOME=/nonexistent", "PATH=/usr/bin:/bin", "AMADAN_HOME=" + dir}'
+```
+
+with:
+
+```python
+'cmd.Env = append(os.Environ(), "HOME=/nonexistent", "PATH=/usr/bin:/bin", "AMADAN_HOME=" + dir)'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.02s)
+ description_test.go:205: team: uncertain
+```
+
+### M29: token_in_argv
+
+File: `internal/runner/forge/description_transport.go`. Replace:
+
+```python
+'"-body", "-")'
+```
+
+with:
+
+```python
+'"-body", "-", c.Bearer)'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.02s)
+ description_test.go:205: team: uncertain
+```
+
+### M30: trim_stdin
+
+File: `internal/runner/forge/description_transport.go`. Replace:
+
+```python
+'strings.NewReader(d.Body)'
+```
+
+with:
+
+```python
+'strings.NewReader(strings.TrimSpace(d.Body))'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.02s)
+ description_test.go:205: team: uncertain
+```
+
+### M31: public_token_file
+
+File: `internal/runner/forge/description_transport.go`. Replace:
+
+```python
+'credentials, 0600'
+```
+
+with:
+
+```python
+'credentials, 0644'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.02s)
+ description_test.go:205: team: uncertain
+```
+
+### M32: retain_token_scratch
+
+File: `internal/runner/forge/description_transport.go`. Replace:
+
+```python
+'defer os.RemoveAll(dir)'
+```
+
+with:
+
+```python
+'// mutation: keep scratch'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.02s)
+ description_test.go:215: credential scratch was retained
+```
+
+### M33: expose_command_output
+
+File: `internal/runner/forge/description_transport.go`. Replace:
+
+```python
+'cmd.Stdout, cmd.Stderr = io.Discard, io.Discard'
+```
+
+with:
+
+```python
+'_ = io.Discard\n cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.02s)
+ description_test.go:261: command output escaped error boundary
+```
+
+### M34: writer_agent
+
+File: `internal/runner/forge/description_transport.go`. Replace:
+
+```python
+'d.Agent != c.Agent || '
+```
+
+with:
+
+```python
+''
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand/agent' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.10s)
+ --- FAIL: TestAmadanDescriptionCommand/agent (0.03s)
+ description_test.go:245: invalid write reached command <nil>
+```
+
+### M35: writer_body_digest
+
+File: `internal/runner/forge/description_transport.go`. Replace:
+
+```python
+'d.Digest != Digest([]byte(d.Body)) || '
+```
+
+with:
+
+```python
+''
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand/digest' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.08s)
+ --- FAIL: TestAmadanDescriptionCommand/digest (0.02s)
+ description_test.go:245: invalid write reached command <nil>
+```
+
+### M36: writer_empty_body
+
+File: `internal/runner/forge/description_transport.go`. Replace:
+
+```python
+'d.Body == "" || '
+```
+
+with:
+
+```python
+''
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand/empty' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.09s)
+ --- FAIL: TestAmadanDescriptionCommand/empty (0.02s)
+ description_test.go:245: invalid write reached command team: uncertain
+```
+
+### M37: writer_utf8
+
+File: `internal/runner/forge/description_transport.go`. Replace:
+
+```python
+'!utf8.ValidString(d.Body) || '
+```
+
+with:
+
+```python
+'(!utf8.ValidString(d.Body) && false) || '
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand/invalid_utf8' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.10s)
+ --- FAIL: TestAmadanDescriptionCommand/invalid_utf8 (0.03s)
+ description_test.go:245: invalid write reached command team: uncertain
+```
+
+### M38: writer_size
+
+File: `internal/runner/forge/description_transport.go`. Replace:
+
+```python
+'len(d.Body) > 1<<20 || '
+```
+
+with:
+
+```python
+''
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand/oversized' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.08s)
+ --- FAIL: TestAmadanDescriptionCommand/oversized (0.02s)
+ description_test.go:245: invalid write reached command team: uncertain
+```
+
+### M39: writer_scratch
+
+File: `internal/runner/forge/description_transport.go`. Replace:
+
+```python
+' || !filepath.IsAbs(w.scratch)'
+```
+
+with:
+
+```python
+''
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.01s)
+ description_test.go:207: relative scratch accepted team: uncertain
+```
+
+### M40: target_remote
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'cred.Remote == "https://"+repo && '
+```
+
+with:
+
+```python
+''
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.07s)
+ --- FAIL: TestAmadanDescriptionCommand/foreign_remote (0.01s)
+ description_test.go:245: invalid write reached command <nil>
+```
+
+### M41: target_agent
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'team.ValidPublicationAgent(cred.Agent) && '
+```
+
+with:
+
+```python
+''
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.07s)
+ --- FAIL: TestAmadanDescriptionCommand/person (0.01s)
+ description_test.go:245: invalid write reached command <nil>
+```
+
+### M42: target_header
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+' && !strings.ContainsAny(cred.Bearer, "\\r\\n\\x00")'
+```
+
+with:
+
+```python
+''
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.07s)
+ --- FAIL: TestAmadanDescriptionCommand/header (0.02s)
+ description_test.go:245: invalid write reached command team: uncertain
+```
+
+### M43: ignore_command_timeout
+
+File: `internal/runner/forge/description_transport.go`. Replace:
+
+```python
+'exec.CommandContext(ctx, w.path'
+```
+
+with:
+
+```python
+'exec.CommandContext(context.Background(), w.path'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (2.06s)
+ description_test.go:268: command did not respect timeout <nil>
+```
+
+### M44: forward_cookies
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'local.Jar = nil'
+```
+
+with:
+
+```python
+'// mutation: keep unrelated cookies'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionReadback/valid' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionReadback (0.00s)
+ --- FAIL: TestAmadanDescriptionReadback/valid (0.00s)
+ description_test.go:95: forwarded unrelated client credentials
+ --- FAIL: TestAmadanDescriptionReadback/invalid_utf8 (0.00s)
+ description_test.go:95: forwarded unrelated client credentials
+```
+
+### M45: missing_token
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'cred.Bearer != "" && '
+```
+
+with:
+
+```python
+''
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand/missing_token' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.07s)
+ --- FAIL: TestAmadanDescriptionCommand/missing_token (0.02s)
+ description_test.go:259: invalid write reached command team: uncertain
+```
+
+### M46: invalid_repository
+
+File: `internal/runner/forge/description.go`. Replace:
+
+```python
+'validRepository(repo) && '
+```
+
+with:
+
+```python
+''
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand/repository' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.07s)
+ --- FAIL: TestAmadanDescriptionCommand/repository (0.02s)
+ description_test.go:259: invalid write reached command team: uncertain
+```
+
+### M47: missing_writer
+
+File: `internal/runner/forge/description_transport.go`. Replace:
+
+```python
+'if t.writer == nil {'
+```
+
+with:
+
+```python
+'if false {'
+```
+
+Run:
+
+```sh
+CGO_ENABLED=0 go test ./internal/runner/forge -run 'TestAmadanDescriptionCommand' -count=1
+```
+
+Exit 1; compiled test failure:
+
+```text
+--- FAIL: TestAmadanDescriptionCommand (0.01s)
+panic: runtime error: invalid memory address or nil pointer dereference [recovered, repanicked]
+ /home/paulca/.local/go-dist/src/testing/testing.go:1974 +0x232
+ /home/paulca/.local/go-dist/src/testing/testing.go:1977 +0x349
+ /home/paulca/.local/go-dist/src/runtime/panic.go:860 +0x13a
+```
+
+## User-facing strings
+
+No new application strings or copy.go entries. No copy review is pending for this
+task. Existing `team.ErrInvalid`, `team.ErrEvidence`, `team.ErrUncertain` and
+publication labels are reused. `approved beyond profile` is carried unchanged.
+New text consists of internal code comments, test diagnostics and this controller
+report. No README prose, UI copy or published branch description was written.
+
+## Concerns and limits
+
+No known failing task requirement. Live publication and installed-CLI network
+behavior were not exercised, as required by the brief. The runtime wiring test is
+a source assertion, supplemented by production transport and publisher behavior
+tests using local Git, loopback HTTP and a fake command.
+
+If the process dies after journaling a write attempt but before actually starting
+the command, GET may stay empty. That attempt remains incomplete; it needs an
+explicit recovery decision rather than an automatic duplicate Set. This is an
+intentional conservative outcome, not delivery success.
+
+All test servers close through cleanup. All fake commands exit or are killed on
+cancellation. Task scratch under `/home/paulca/t/e2b/task10` is removed after its
+evidence is copied here. Go caches are unchanged. No push, merge or deployment.
diff --git a/internal/equipotest/publish_test.go b/internal/equipotest/publish_test.go
index d0d9dc90..11da1001 100644
--- a/internal/equipotest/publish_test.go
+++ b/internal/equipotest/publish_test.go
@@ -3,6 +3,8 @@ package equipotest
import (
"amadan.net/oficina/equipo/internal/equipo"
"context"
+ "os"
+ "strings"
"testing"
"time"
@@ -92,3 +94,17 @@ func TestPublishInstanceAdapter(t *testing.T) {
t.Fatal("verified durable observation lost")
}
}
+
+func TestPublishTransportIsProduction(t *testing.T) {
+ raw, err := os.ReadFile("../runner/runtime_workflow.go")
+ executionMust(t, err)
+ source := string(raw)
+ if strings.Contains(source, "unavailableDescription") || !strings.Contains(source, "Description: forge.NewDescriptionTransport(") || !strings.Contains(source, "forge.NewCommandDescriptionWriter(") {
+ t.Fatal("runtime publication still uses unavailable description transport")
+ }
+ for _, wiring := range []string{"Launchers: r.launchers", "Namespaces: r.namespaces", "Launch: r.directLaunch"} {
+ if !strings.Contains(source, wiring) {
+ t.Fatal("Task 9 direct wiring lost", wiring)
+ }
+ }
+}
diff --git a/internal/runner/forge/description.go b/internal/runner/forge/description.go
index a5ca2c13..6ee605d2 100644
--- a/internal/runner/forge/description.go
+++ b/internal/runner/forge/description.go
@@ -1,35 +1,35 @@
package forge
import (
+ "bytes"
"context"
+ "crypto/sha256"
+ "encoding/binary"
+ "encoding/hex"
"encoding/json"
"io"
"net/http"
"net/url"
"strings"
"time"
+ "unicode/utf8"
"amadan.net/oficina/equipo/internal/equipo/team"
)
-type descriptionText struct {
+type DescriptionChannels struct {
Description string `json:"description"`
Human string `json:"human"`
Summary string `json:"summary"`
Notes string `json:"notes"`
}
-// ReadBranchDescription implements the announced Amadan GET contract, also used
-// by `amadan branch show <ns>/<repo> <name> -json`. Production publication stays
-// disabled until the deployed contract and pre-push ordering are verified.
+// ReadBranchDescription reads the four verbatim channels from Amadan.
func ReadBranchDescription(ctx context.Context, client *http.Client, cred Credential, repo, ref string) (Description, error) {
- if !repoName.MatchString(repo) || cred.Remote != "https://"+repo || !team.ValidPublicationAgent(cred.Agent) || cred.Bearer == "" || !strings.HasPrefix(ref, "refs/heads/") {
- return Description{}, team.ErrInvalid
- }
- branch := strings.TrimPrefix(ref, "refs/heads/")
- if branch == "" || strings.ContainsAny(branch, "\x00\r\n") {
+ if !validDescriptionTarget(cred, repo, ref) {
return Description{}, team.ErrInvalid
}
+ branch := ref
parts := strings.Split(repo, "/")
endpoint := "https://amadan.net/api/v1/repos/" + url.PathEscape(parts[1]) + "/" + url.PathEscape(parts[2]) + "/branches/" + url.PathEscape(branch) + "/description"
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
@@ -44,6 +44,7 @@ func ReadBranchDescription(ctx context.Context, client *http.Client, cred Creden
client = http.DefaultClient
}
local := *client
+ local.Jar = nil
local.CheckRedirect = func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }
response, err := local.Do(req)
if err != nil {
@@ -58,19 +59,37 @@ func ReadBranchDescription(ctx context.Context, client *http.Client, cred Creden
return Description{}, team.ErrUncertain
}
var result struct {
- descriptionText
+ DescriptionChannels
By string `json:"by"`
At int64 `json:"at"`
Agent json.RawMessage `json:"agent"`
Empty bool `json:"empty"`
ContentHash string `json:"content_hash"`
}
- if json.Unmarshal(data, &result) != nil || result.Empty || result.By != cred.Agent || result.Description == "" {
+ if !utf8.Valid(data) || json.Unmarshal(data, &result) != nil || result.Empty || result.By != cred.Agent || result.Description == "" {
return Description{}, team.ErrEvidence
}
- content, _ := json.Marshal(result.descriptionText)
- if result.ContentHash != "sha256:"+team.ContentDigest(content) {
+ if result.ContentHash != DescriptionContentHash(result.DescriptionChannels) {
return Description{}, team.ErrEvidence
}
- return Description{Repository: repo, Ref: ref, Agent: result.By, Body: result.Description, Digest: team.ContentDigest([]byte(result.Description))}, nil
+ metadata := bytes.TrimSpace(result.Agent)
+ if len(metadata) > 0 && string(metadata) != "null" && metadata[0] != '{' {
+ return Description{}, team.ErrEvidence
+ }
+ return Description{Repository: repo, Ref: ref, Agent: result.By, Body: result.Description, Digest: team.ContentDigest([]byte(result.Description)), At: result.At, AgentMetadata: result.Agent, Channels: result.DescriptionChannels, ContentHash: result.ContentHash}, nil
+}
+
+func DescriptionContentHash(c DescriptionChannels) string {
+ hash := sha256.New()
+ var size [8]byte
+ for _, channel := range []string{c.Description, c.Human, c.Summary, c.Notes} {
+ binary.BigEndian.PutUint64(size[:], uint64(len(channel)))
+ _, _ = hash.Write(size[:])
+ _, _ = hash.Write([]byte(channel))
+ }
+ return "sha256:" + hex.EncodeToString(hash.Sum(nil))
+}
+
+func validDescriptionTarget(cred Credential, repo, ref string) bool {
+ return validRepository(repo) && validRef(ref) && cred.Remote == "https://"+repo && team.ValidPublicationAgent(cred.Agent) && cred.Bearer != "" && !strings.ContainsAny(cred.Bearer, "\r\n\x00")
}
diff --git a/internal/runner/forge/description_test.go b/internal/runner/forge/description_test.go
index 6a295f2a..8c011b77 100644
--- a/internal/runner/forge/description_test.go
+++ b/internal/runner/forge/description_test.go
@@ -1,30 +1,289 @@
package forge
import (
- "amadan.net/oficina/equipo/internal/equipo/team"
+ "bytes"
"context"
"encoding/json"
+ "errors"
"io"
+ "net"
"net/http"
+ "net/http/cookiejar"
+ "net/http/httptest"
+ "net/url"
+ "os"
+ "path/filepath"
"strings"
"testing"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/equipo/team"
)
type descriptionRoundTrip func(*http.Request) (*http.Response, error)
func (f descriptionRoundTrip) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) }
-func TestPlannedAmadanDescriptionReadback(t *testing.T) {
- client := &http.Client{Transport: descriptionRoundTrip(func(r *http.Request) (*http.Response, error) {
- if r.Method != "GET" || r.URL.EscapedPath() != "/api/v1/repos/oficina/equipo/branches/review%2Ftrial/description" || r.Header.Get("Authorization") != "Bearer test-token" {
- t.Fatal("wrong request", r.Method, r.URL.EscapedPath())
+
+func descriptionServer(t *testing.T, h http.HandlerFunc) *http.Client {
+ t.Helper()
+ s := httptest.NewUnstartedServer(h)
+ listener, err := net.Listen("tcp", "127.0.0.1:0")
+ must(t, err)
+ must(t, s.Listener.Close())
+ s.Listener = listener
+ s.Start()
+ t.Cleanup(s.Close)
+ target, err := url.Parse(s.URL)
+ must(t, err)
+ transport := &http.Transport{Proxy: nil}
+ t.Cleanup(transport.CloseIdleConnections)
+ return &http.Client{Transport: descriptionRoundTrip(func(r *http.Request) (*http.Response, error) {
+ deadline, ok := r.Context().Deadline()
+ if !ok || time.Until(deadline) > 15*time.Second {
+ t.Error("missing bounded GET deadline")
+ }
+ if r.URL.Scheme != "https" || r.URL.Host != "amadan.net" {
+ t.Error("wrong production origin")
}
- fields := descriptionText{Description: "supervised trial; unconfined"}
- content, _ := json.Marshal(fields)
- body, _ := json.Marshal(map[string]any{"description": fields.Description, "human": "", "summary": "", "notes": "", "by": "codex~owner@example.com", "at": 123, "agent": nil, "empty": false, "content_hash": "sha256:" + team.ContentDigest(content)})
- return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(string(body)))}, nil
+ local := r.Clone(r.Context())
+ u := *r.URL
+ u.Scheme, u.Host = target.Scheme, target.Host
+ local.URL = &u
+ return transport.RoundTrip(local)
})}
- got, err := ReadBranchDescription(context.Background(), client, Credential{Remote: "https://amadan.net/oficina/equipo", Bearer: "test-token", Agent: "codex~owner@example.com"}, "amadan.net/oficina/equipo", "refs/heads/review/trial")
- if err != nil || got.Body != "supervised trial; unconfined" || got.Digest != team.ContentDigest([]byte(got.Body)) {
- t.Fatalf("%+v %v", got, err)
+}
+
+func descriptionResponse(body, agent string) map[string]any {
+ c := DescriptionChannels{Description: body, Human: "Paul", Summary: "Fixed\nchecked", Notes: "✓"}
+ return map[string]any{"description": c.Description, "human": c.Human, "summary": c.Summary, "notes": c.Notes, "by": agent, "at": 123, "agent": map[string]any{"name": "equipo", "operator": "owner@example.com"}, "empty": false, "content_hash": DescriptionContentHash(c)}
+}
+
+func TestAmadanDescriptionLengthHash(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ c DescriptionChannels
+ want string
+ }{
+ {"empty", DescriptionChannels{}, "sha256:66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925"},
+ {"utf8", DescriptionChannels{"Equipo café\n", "Paul", "Fixed\nchecked", "✓"}, "sha256:ac030712c32422e57053ff69f80ec87d1efdff87a000e9a08dd3e711d0995a88"},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ if got := DescriptionContentHash(tc.c); got != tc.want {
+ t.Fatalf("hash = %s, want %s", got, tc.want)
+ }
+ })
+ }
+ if DescriptionContentHash(DescriptionChannels{Description: "ab", Human: "c"}) == DescriptionContentHash(DescriptionChannels{Description: "a", Human: "bc"}) {
+ t.Fatal("channel boundaries lost")
+ }
+}
+
+func TestAmadanDescriptionReadback(t *testing.T) {
+ cred := Credential{Remote: "https://amadan.net/oficina/equipo", Agent: "equipo~owner@example.com", Bearer: "fake-only"}
+ body := " Equipo café\n unconfined; approved beyond profile\n"
+ for _, name := range []string{"valid", "optional_agent", "reordered", "tamper", "wrong_hash", "wrong_agent", "bad_metadata", "empty", "invalid_utf8", "malformed", "malformed_at", "trailing", "oversized", "redirect", "auth", "timeout"} {
+ t.Run(name, func(t *testing.T) {
+ requests := 0
+ client := descriptionServer(t, func(w http.ResponseWriter, r *http.Request) {
+ requests++
+ if r.URL.Path == "/redirected" {
+ t.Error("followed redirect with credentials")
+ w.WriteHeader(500)
+ return
+ }
+ if r.Header.Get("Cookie") != "" {
+ t.Error("forwarded unrelated client credentials")
+ }
+ if r.Method != "GET" || r.URL.EscapedPath() != "/api/v1/repos/oficina/equipo/branches/review%2Ftrial/description" || r.Header.Get("Authorization") != "Bearer fake-only" {
+ t.Errorf("wrong request: %s %s", r.Method, r.URL.EscapedPath())
+ }
+ response := descriptionResponse(body, cred.Agent)
+ switch name {
+ case "optional_agent":
+ delete(response, "agent")
+ case "tamper":
+ response["description"] = body + "changed"
+ case "wrong_hash":
+ response["content_hash"] = "sha256:" + strings.Repeat("0", 64)
+ case "wrong_agent":
+ response["by"] = "other~owner@example.com"
+ case "bad_metadata":
+ response["agent"] = "not structured"
+ case "empty":
+ response["empty"] = true
+ case "invalid_utf8":
+ response["description"] = "�"
+ response["content_hash"] = DescriptionContentHash(DescriptionChannels{"�", "Paul", "Fixed\nchecked", "✓"})
+ raw, _ := json.Marshal(response)
+ _, _ = w.Write(bytes.Replace(raw, []byte("�"), []byte{0xff}, 1))
+ return
+ case "malformed_at":
+ response["at"] = "invalid"
+ case "malformed":
+ _, _ = io.WriteString(w, "{")
+ return
+ case "trailing":
+ _, _ = io.WriteString(w, "{}{}")
+ return
+ case "oversized":
+ response["padding"] = strings.Repeat("x", 1<<20)
+ case "redirect":
+ http.Redirect(w, r, "/redirected", 302)
+ return
+ case "auth":
+ w.WriteHeader(401)
+ return
+ case "timeout":
+ <-r.Context().Done()
+ return
+ }
+ if name == "reordered" {
+ raw, _ := json.Marshal(response)
+ // Whitespace and field order are not part of the content hash.
+ _, _ = io.WriteString(w, "{\"extra\":true, "+string(raw[1:]))
+ return
+ }
+ _ = json.NewEncoder(w).Encode(response)
+ })
+ jar, err := cookiejar.New(nil)
+ must(t, err)
+ origin, _ := url.Parse("https://amadan.net")
+ jar.SetCookies(origin, []*http.Cookie{{Name: "person", Value: "fake-cookie"}})
+ client.Jar = jar
+ callCtx := context.Background()
+ if name == "timeout" {
+ var cancel context.CancelFunc
+ callCtx, cancel = context.WithTimeout(callCtx, 30*time.Millisecond)
+ defer cancel()
+ }
+ got, err := ReadBranchDescription(callCtx, client, cred, "amadan.net/oficina/equipo", "review/trial")
+ if name != "valid" && name != "optional_agent" && name != "reordered" {
+ if err == nil {
+ t.Fatalf("accepted %s", name)
+ }
+ return
+ }
+ must(t, err)
+ if got.Body != body || got.Digest != team.ContentDigest([]byte(body)) || got.Agent != cred.Agent || got.Ref != "review/trial" || got.At != 123 || got.Channels.Notes != "✓" || got.ContentHash != DescriptionContentHash(got.Channels) {
+ t.Fatalf("lost verbatim content or metadata: %+v", got)
+ }
+ if name != "optional_agent" && !strings.Contains(string(got.AgentMetadata), "operator") {
+ t.Fatal("lost structured agent metadata")
+ }
+ if requests != 1 {
+ t.Fatal("unexpected request count", requests)
+ }
+ })
+ }
+ invalidClient := descriptionServer(t, func(w http.ResponseWriter, r *http.Request) {
+ t.Error("invalid target reached HTTP")
+ w.WriteHeader(http.StatusBadRequest)
+ })
+ for _, ref := range []string{"refs/heads/review/trial", "refs/tags/x", "../x", "review//trial", "-flag"} {
+ if _, err := ReadBranchDescription(context.Background(), invalidClient, cred, "amadan.net/oficina/equipo", ref); err == nil {
+ t.Fatal("accepted invalid ref", ref)
+ }
+ }
+}
+
+func TestAmadanDescriptionCommand(t *testing.T) {
+ t.Setenv("PERSON_SECRET", "person-canary")
+ t.Setenv("AMADAN_HOME", "/must-not-use-person-login")
+ root := t.TempDir()
+ command := filepath.Join(root, "describe")
+ script := `#!/usr/bin/python3
+import json,os,sys,stat
+assert sys.argv[1:] == ['branch','describe','oficina/equipo','review/trial','-hub','https://amadan.net','-body','-']
+assert 'PERSON_SECRET' not in os.environ
+assert os.environ['HOME'] == '/nonexistent'
+home = os.environ['AMADAN_HOME']
+assert home != '/must-not-use-person-login'
+assert stat.S_IMODE(os.stat(home).st_mode) == 0o700
+path = home+'/credentials'
+assert stat.S_IMODE(os.stat(path).st_mode) == 0o600
+assert json.load(open(path)) == {'tokens': {'https://amadan.net':'fake-only'}}
+assert sys.stdin.read() == ' Equipo café\n unconfined; approved beyond profile\n'
+`
+ must(t, os.WriteFile(command, []byte(script), 0700))
+ cred := Credential{Remote: "https://amadan.net/oficina/equipo", Agent: "equipo~owner@example.com", Bearer: "fake-only"}
+ desc := Description{Repository: "amadan.net/oficina/equipo", Ref: "review/trial", Agent: cred.Agent, Body: " Equipo café\n unconfined; approved beyond profile\n"}
+ desc.Digest = Digest([]byte(desc.Body))
+ scratch := filepath.Join(root, "scratch")
+ must(t, os.Mkdir(scratch, 0700))
+ writer := NewCommandDescriptionWriter(command, scratch)
+ must(t, writer.Set(context.Background(), cred, desc))
+ if err := NewCommandDescriptionWriter(command, "relative").Set(context.Background(), cred, desc); err != team.ErrInvalid {
+ t.Fatal("relative scratch accepted", err)
+ }
+ if err := NewDescriptionTransport(nil, nil).Set(context.Background(), cred, desc); err != team.ErrUncertain {
+ t.Fatal("missing writer accepted", err)
+ }
+ entries, err := os.ReadDir(scratch)
+ must(t, err)
+ if len(entries) != 0 {
+ t.Fatal("credential scratch was retained")
+ }
+ for _, name := range []string{"person", "foreign_remote", "missing_token", "repository", "header", "ref", "digest", "agent", "empty", "invalid_utf8", "oversized"} {
+ t.Run(name, func(t *testing.T) {
+ c, d := cred, desc
+ switch name {
+ case "person":
+ c.Agent = "owner@example.com"
+ d.Agent = c.Agent
+ case "foreign_remote":
+ c.Remote = "https://evil.example/oficina/equipo"
+ case "missing_token":
+ c.Bearer = ""
+ case "repository":
+ d.Repository = "amadan.net/../equipo"
+ c.Remote = "https://" + d.Repository
+ case "header":
+ c.Bearer = "fake\r\nInjected: x"
+ case "ref":
+ d.Ref = "refs/heads/review/trial"
+ case "digest":
+ d.Digest = strings.Repeat("0", 64)
+ case "agent":
+ d.Agent = "other~owner@example.com"
+ case "invalid_utf8":
+ d.Body = string([]byte{0xff})
+ d.Digest = Digest([]byte(d.Body))
+ case "oversized":
+ d.Body = strings.Repeat("x", (1<<20)+1)
+ d.Digest = Digest([]byte(d.Body))
+ case "empty":
+ d.Body = ""
+ d.Digest = Digest(nil)
+ }
+ if err := writer.Set(context.Background(), c, d); !errors.Is(err, team.ErrInvalid) {
+ t.Fatal("invalid write reached command", err)
+ }
+ })
+ }
+ must(t, os.WriteFile(command, []byte("#!/usr/bin/python3\nimport sys\nprint('fake-only',file=sys.stderr)\nprint('fake-only')\nsys.exit(1)\n"), 0700))
+ readLog, writeLog, err := os.Pipe()
+ must(t, err)
+ previousOut, previousErr := os.Stdout, os.Stderr
+ os.Stdout, os.Stderr = writeLog, writeLog
+ commandErr := writer.Set(context.Background(), cred, desc)
+ os.Stdout, os.Stderr = previousOut, previousErr
+ must(t, writeLog.Close())
+ captured, err := io.ReadAll(readLog)
+ must(t, readLog.Close())
+ must(t, err)
+ if commandErr != team.ErrUncertain || len(captured) != 0 {
+ t.Fatal("command output escaped error boundary")
+ }
+ must(t, os.WriteFile(command, []byte("#!/usr/bin/python3\nimport time\ntime.sleep(2)\n"), 0700))
+ bounded, cancel := context.WithTimeout(context.Background(), 30*time.Millisecond)
+ defer cancel()
+ started := time.Now()
+ if err := writer.Set(bounded, cred, desc); err != team.ErrUncertain || time.Since(started) > time.Second {
+ t.Fatal("command did not respect timeout", err)
+ }
+ entries, err = os.ReadDir(scratch)
+ must(t, err)
+ if len(entries) != 0 {
+ t.Fatal("failed command retained credentials")
}
}
diff --git a/internal/runner/forge/description_transport.go b/internal/runner/forge/description_transport.go
new file mode 100644
index 00000000..a69f1b12
--- /dev/null
+++ b/internal/runner/forge/description_transport.go
@@ -0,0 +1,79 @@
+package forge
+
+import (
+ "context"
+ "encoding/json"
+ "io"
+ "net/http"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strings"
+ "syscall"
+ "time"
+ "unicode/utf8"
+
+ "amadan.net/oficina/equipo/internal/equipo/team"
+)
+
+type DescriptionWriter interface {
+ Set(context.Context, Credential, Description) error
+}
+
+type descriptionTransport struct {
+ client *http.Client
+ writer DescriptionWriter
+}
+
+func NewDescriptionTransport(client *http.Client, writer DescriptionWriter) DescriptionTransport {
+ return &descriptionTransport{client: client, writer: writer}
+}
+func (*descriptionTransport) BeforePush() bool { return false }
+func (t *descriptionTransport) Set(ctx context.Context, c Credential, d Description) error {
+ if t.writer == nil {
+ return team.ErrUncertain
+ }
+ return t.writer.Set(ctx, c, d)
+}
+func (t *descriptionTransport) Read(ctx context.Context, c Credential, repo, ref string) (Description, error) {
+ return ReadBranchDescription(ctx, t.client, c, repo, ref)
+}
+
+type commandDescriptionWriter struct{ path, scratch string }
+
+// NewCommandDescriptionWriter scopes the installed CLI to one supplied token.
+// The temporary command state contains no personal login or provider home.
+func NewCommandDescriptionWriter(path, scratch string) DescriptionWriter {
+ return commandDescriptionWriter{path: path, scratch: scratch}
+}
+func (w commandDescriptionWriter) Set(ctx context.Context, c Credential, d Description) error {
+ if !validDescriptionTarget(c, d.Repository, d.Ref) || d.Agent != c.Agent || d.Body == "" || !utf8.ValidString(d.Body) || len(d.Body) > 1<<20 || d.Digest != Digest([]byte(d.Body)) || !filepath.IsAbs(w.scratch) {
+ return team.ErrInvalid
+ }
+ ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
+ defer cancel()
+ dir, err := os.MkdirTemp(w.scratch, "describe-")
+ if err != nil {
+ return team.ErrUncertain
+ }
+ defer os.RemoveAll(dir)
+ credentials, err := json.Marshal(map[string]any{"tokens": map[string]string{"https://amadan.net": c.Bearer}})
+ if err != nil {
+ return team.ErrUncertain
+ }
+ if err = os.WriteFile(filepath.Join(dir, "credentials"), credentials, 0600); err != nil {
+ return team.ErrUncertain
+ }
+ cmd := exec.CommandContext(ctx, w.path, "branch", "describe", strings.TrimPrefix(d.Repository, "amadan.net/"), d.Ref, "-hub", "https://amadan.net", "-body", "-")
+ cmd.Dir = dir
+ cmd.Env = []string{"HOME=/nonexistent", "PATH=/usr/bin:/bin", "AMADAN_HOME=" + dir}
+ cmd.Stdin = strings.NewReader(d.Body)
+ cmd.Stdout, cmd.Stderr = io.Discard, io.Discard
+ cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
+ cmd.Cancel = func() error { return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) }
+ cmd.WaitDelay = time.Second
+ if err = cmd.Run(); err != nil {
+ return team.ErrUncertain
+ }
+ return nil
+}
diff --git a/internal/runner/forge/publisher.go b/internal/runner/forge/publisher.go
index d51c02ff..5f6227f1 100644
--- a/internal/runner/forge/publisher.go
+++ b/internal/runner/forge/publisher.go
@@ -22,11 +22,15 @@ import (
type Authorization = runnerproto.PublicationAuthorization
type Credential struct{ Remote, Agent, Bearer string }
-type Description struct{ Repository, Ref, Agent, Body, Digest string }
+type Description struct {
+ Repository, Ref, Agent, Body, Digest string
+ At int64
+ AgentMetadata json.RawMessage
+ Channels DescriptionChannels
+ ContentHash string
+}
// DescriptionTransport must confirm the stored body and its attributed agent.
-// The installed CLI help does not supply a readback contract. No production
-// implementation is enabled until the owning product supplies that contract.
type DescriptionTransport interface {
BeforePush() bool
Set(context.Context, Credential, Description) error
@@ -148,9 +152,10 @@ func (p *Publisher) credential(ctx context.Context, repository string) (Credenti
}
type record struct {
- Authorization Authorization
- Description Description
- Remote string
+ Authorization Authorization
+ Description Description
+ Remote string
+ DescriptionAttempted bool
// An empty phase is a legacy journal and cannot prove no dispatch.
Phase string
}
@@ -270,7 +275,7 @@ func (p *Publisher) Execute(ctx context.Context, d team.Dispatch) (receipt team.
return team.Receipt{}, e
}
mayPublish = true
- if e = p.confirmDescription(ctx, cred, desc); e != nil {
+ if e = p.confirmDescription(ctx, cred, &r); e != nil {
return team.Receipt{}, team.ErrUncertain
}
}
@@ -297,16 +302,29 @@ func (p *Publisher) remote(remote string) string {
}
return remote
}
-func (p *Publisher) confirmDescription(ctx context.Context, cred Credential, desc Description) error {
+func descriptionMatches(got, want Description) bool {
+ return got.Repository == want.Repository && got.Ref == want.Ref && got.Agent == want.Agent && got.Body == want.Body && got.Digest == want.Digest
+}
+
+func (p *Publisher) confirmDescription(ctx context.Context, cred Credential, r *record) error {
+ desc := r.Description
got, e := p.cfg.Description.Read(ctx, cred, desc.Repository, desc.Ref)
- if e == nil && got == desc {
+ if e == nil && descriptionMatches(got, desc) {
return nil
}
- if e = p.cfg.Description.Set(ctx, cred, desc); e != nil {
+ // Once a write may have run, reconciliation only reads. A transport failure
+ // also cannot prove that the existing description needs changing.
+ if r.DescriptionAttempted || (e != nil && !errors.Is(e, team.ErrEvidence)) {
+ return team.ErrUncertain
+ }
+ r.DescriptionAttempted = true
+ if e = runnerproto.JournalCredentials(p.path(r.Authorization.Ticket.Dispatch), *r); e != nil {
return team.ErrUncertain
}
+ // A failed command may have stored the description before losing its reply.
+ _ = p.cfg.Description.Set(ctx, cred, desc)
got, e = p.cfg.Description.Read(ctx, cred, desc.Repository, desc.Ref)
- if e != nil || got != desc {
+ if e != nil || !descriptionMatches(got, desc) {
return team.ErrUncertain
}
return nil
@@ -334,7 +352,7 @@ func (p *Publisher) reconcile(ctx context.Context, r record) (team.Receipt, erro
if head != v.Head {
return team.Receipt{}, team.ErrConflict
}
- if e = p.confirmDescription(ctx, cred, r.Description); e != nil {
+ if e = p.confirmDescription(ctx, cred, &r); e != nil {
return team.Receipt{}, e
}
label := v.Isolation.Status
diff --git a/internal/runner/forge/publisher_test.go b/internal/runner/forge/publisher_test.go
index 8deb7729..aa80e45b 100644
--- a/internal/runner/forge/publisher_test.go
+++ b/internal/runner/forge/publisher_test.go
@@ -5,10 +5,12 @@ import (
"encoding/json"
"errors"
"fmt"
+ "net/http"
"os"
"os/exec"
"path/filepath"
"strings"
+ "sync"
"testing"
"time"
@@ -397,8 +399,8 @@ func TestPublishDescriptionIdentity(t *testing.T) {
f := newFixture(t)
f.desc.requiresRef = true
f.desc.lostSet = true
- if _, e := f.p.Execute(ctx, f.auth.Ticket.Dispatch); e == nil {
- t.Fatal("lost description reply delivered success")
+ if _, e := f.p.Execute(ctx, f.auth.Ticket.Dispatch); e != nil {
+ t.Fatal("GET failed to confirm lost description reply", e)
}
r, e := f.p.Reconcile(ctx, f.auth.Ticket.Dispatch)
must(t, e)
@@ -560,3 +562,134 @@ func TestTrialPublisherRequiresBothLabels(t *testing.T) {
}
}
}
+
+// The fake writer only writes the in-memory response served by loopback GET.
+type descriptionWriterFunc func(context.Context, Credential, Description) error
+
+func (f descriptionWriterFunc) Set(ctx context.Context, c Credential, d Description) error {
+ return f(ctx, c, d)
+}
+
+func TestPublishDescriptionRecovery(t *testing.T) {
+ for _, mode := range []string{"lost_reply", "delayed_readback", "empty", "trimmed", "wrong_digest", "wrong_ref", "wrong_repo", "wrong_body", "wrong_agent"} {
+ t.Run(mode, func(t *testing.T) {
+ f := newFixture(t)
+ f.auth.Publication.Description = " unconfined; approved beyond profile\n"
+ f.auth.Publication.DescriptionHash = Digest([]byte(f.auth.Publication.Description))
+ raw, _ := json.Marshal(f.auth.Publication)
+ f.auth.Ticket.Dispatch.Payload, f.auth.Ticket.Dispatch.Hash, _ = Canonical(raw)
+ var mu sync.Mutex
+ body := ""
+ writes, reads := 0, 0
+ f.p.beforePush = func() {
+ saved, err := f.p.load(f.auth.Ticket.Dispatch)
+ must(t, err)
+ if saved.Description.Body != f.auth.Publication.Description || saved.DescriptionAttempted {
+ t.Fatal("missing pending description before push")
+ }
+ f.pushes++
+ }
+ visible := mode != "delayed_readback"
+ client := descriptionServer(t, func(w http.ResponseWriter, r *http.Request) {
+ mu.Lock()
+ defer mu.Unlock()
+ reads++
+ if r.URL.EscapedPath() != "/api/v1/repos/example/repo/branches/heads%2Fmain/description" {
+ t.Error("ref qualified twice or not escaped")
+ }
+ if body == "" || !visible || mode == "empty" {
+ _ = json.NewEncoder(w).Encode(map[string]any{"empty": true})
+ return
+ }
+ _ = json.NewEncoder(w).Encode(descriptionResponse(body, "equipo~operator@example.test"))
+ })
+ transport := NewDescriptionTransport(client, descriptionWriterFunc(func(_ context.Context, c Credential, d Description) error {
+ mu.Lock()
+ defer mu.Unlock()
+ writes++
+ if f.pushes != 1 || gitTest(t, f.root, "--git-dir="+f.remote, "rev-parse", "refs/heads/heads/main") != f.auth.Candidate.Commit {
+ t.Fatal("describe before exact ref exists")
+ }
+ saved, err := f.p.load(f.auth.Ticket.Dispatch)
+ must(t, err)
+ if saved.Description.Body != d.Body || !saved.DescriptionAttempted {
+ t.Fatal("description intent not durable before write")
+ }
+ body = d.Body
+ if mode == "trimmed" {
+ body = strings.TrimSpace(body)
+ }
+ return team.ErrUncertain // Server stored it, command reply was lost.
+ }))
+ if transport.BeforePush() {
+ t.Fatal("production transport describes before push")
+ }
+ f.p.cfg.Description = transport
+ if strings.HasPrefix(mode, "wrong_") {
+ f.p.cfg.Description = changedDescription{DescriptionTransport: transport, field: mode}
+ }
+ receipt, err := f.p.Execute(ctx, f.auth.Ticket.Dispatch)
+ if mode == "lost_reply" {
+ must(t, err)
+ if receipt.Outcome != team.OutcomeSuccess {
+ t.Fatal("readback did not confirm lost reply")
+ }
+ } else if err == nil {
+ t.Fatal("unconfirmed description delivered success")
+ }
+ mu.Lock()
+ visible = true
+ mu.Unlock()
+ // Reconstruct the publisher to exercise the durable journal after a restart.
+ restarted, err := newPublisher(f.p.cfg, f.p.localRemote)
+ must(t, err)
+ restarted.beforePush = f.p.beforePush
+ result, err := restarted.Reconcile(ctx, f.auth.Ticket.Dispatch)
+ if mode == "lost_reply" || mode == "delayed_readback" {
+ must(t, err)
+ if result.Receipt == nil || result.Receipt.Fields["description_hash"] != f.auth.Publication.DescriptionHash {
+ t.Fatal("lost body digest")
+ }
+ } else if err == nil || result.Receipt != nil {
+ t.Fatal("unconfirmed description reconciled success")
+ }
+ _, _ = restarted.Execute(ctx, f.auth.Ticket.Dispatch)
+ if writes != 1 || f.pushes != 1 || reads < 3 {
+ t.Fatal("duplicate write/push or skipped GET", writes, f.pushes, reads)
+ }
+ })
+ }
+}
+
+type changedDescription struct {
+ DescriptionTransport
+ field string
+}
+
+func (c changedDescription) Read(ctx context.Context, cred Credential, repo, ref string) (Description, error) {
+ d, err := c.DescriptionTransport.Read(ctx, cred, repo, ref)
+ switch c.field {
+ case "wrong_digest":
+ d.Digest = strings.Repeat("0", 64)
+ case "wrong_ref":
+ d.Ref = "another/ref"
+ case "wrong_repo":
+ d.Repository = "amadan.net/other/repo"
+ case "wrong_body":
+ d.Body = strings.TrimSpace(d.Body)
+ case "wrong_agent":
+ d.Agent = "another~operator@example.test"
+ }
+ return d, err
+}
+
+func TestPublishDescriptionReadFailureDoesNotWrite(t *testing.T) {
+ f := newFixture(t)
+ writes := 0
+ client := descriptionServer(t, func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusUnauthorized) })
+ f.p.cfg.Description = NewDescriptionTransport(client, descriptionWriterFunc(func(context.Context, Credential, Description) error { writes++; return team.ErrUncertain }))
+ _, err := f.p.Execute(ctx, f.auth.Ticket.Dispatch)
+ if err == nil || f.pushes != 1 || writes != 0 {
+ t.Fatal("read failure caused a write or success", err, writes)
+ }
+}
diff --git a/internal/runner/runtime_workflow.go b/internal/runner/runtime_workflow.go
index 32667124..c1137a92 100644
--- a/internal/runner/runtime_workflow.go
+++ b/internal/runner/runtime_workflow.go
@@ -37,18 +37,6 @@ func (f forgeCredentials) Resolve(ctx context.Context, repo string) (workspace.R
return workspace.Remote{URL: c.Remote, Bearer: c.Bearer}, err
}
-// Keep publication unavailable until the deployed Amadan readback and ordering
-// are verified. forge.ReadBranchDescription implements the announced GET shape.
-type unavailableDescription struct{}
-
-func (unavailableDescription) BeforePush() bool { return true }
-func (unavailableDescription) Set(context.Context, forge.Credential, forge.Description) error {
- return paseo.ErrCapability
-}
-func (unavailableDescription) Read(context.Context, forge.Credential, string, string) (forge.Description, error) {
- return forge.Description{}, paseo.ErrCapability
-}
-
func (r *Runtime) active() (RunClaim, error) {
r.mu.Lock()
defer r.mu.Unlock()
@@ -175,7 +163,7 @@ func (r *Runtime) wire(ctx context.Context) error {
return paseo.ErrIdentity
}
return r.api.Call(ctx, "validate", claimRequest(c, "publish-validate"), nil)
- }, Export: manager.ExportCandidate, Credential: credentials.credential, Description: unavailableDescription{}})
+ }, Export: manager.ExportCandidate, Credential: credentials.credential, Description: forge.NewDescriptionTransport(nil, forge.NewCommandDescriptionWriter("amadan", r.cfg.ScratchRoot))})
}
workflow, err := NewBugWorkflow(BugWorkflowConfig{Workspaces: manager, Launchers: r.launchers, Namespaces: r.namespaces, Launch: r.directLaunch, Witness: w, Policy: r.policy, Executor: executor, PublisherFor: publisherFor, StateDir: r.cfg.StateDir, Executable: r.cfg.Executable, InstanceID: r.cfg.InstanceID, Copy: r.cfg.Copy})
if err != nil {