Add revision-checked delegated semantic deck editing
Expose concrete schemas for thirteen native semantic operations, preserve exact input numbers, and apply through the canonical engine within the guarded writer transaction. Persist sealed immutable retry acknowledgements and generated IDs. Independent specification/source review: GPT-6 Astra. Full canonical pinned gate, focused race, and eight effective adversarial mutants passed.
15 files changed,
+1,160
−15
docs/agent-access.md+18 −1docs/superpowers/specs/2026-11-01-agent-deck-editing.md+231 −0internal/slides/agent_access.go+7 −1internal/slides/agent_authority.go+1 −6internal/slides/agent_create.go+3 −0internal/slides/agent_edit.go+229 −0internal/slides/agent_edit_boundary_test.go+214 −0internal/slides/agent_edit_contract.go+70 −0internal/slides/agent_edit_test.go+339 −0internal/slides/agent_integration_test.go+18 −0internal/slides/agent_migrations/migrations/0002_edits.sql+7 −0internal/slides/agent_operations.go+1 −0internal/slides/decks.go+8 −3internal/slides/snapshot.go+13 −4internal/slides/team_guard_test.go+1 −0
CI passed — run details
diff --git a/docs/agent-access.md b/docs/agent-access.md| index daa3b17..11df9a6 100644 |
| --- a/docs/agent-access.md |
| +++ b/docs/agent-access.md |
| @@ -9,6 +9,7 @@ The operation descriptors are exported with `go run ./cmd/slides-contract`. Use |
| | slides_list_decks | slides:read | team, optional limit (1–100), cursor | |
| | slides_get_deck | slides:read | team, sqid | |
| | slides_create_deck | slides:write | team, client_id UUID, title, optional theme, slides | |
| +| slides_update_deck | slides:write | team, sqid, expected_revision, client_id UUID, ops | |
| Each initial slide contains `heading`, `body_markdown`, and `notes_markdown`. Supply 1–50 slides and at most 128 KiB of combined text. Titles are at most 512 UTF-8 bytes. New decks start private and use the existing collaborative block tree, so browser editing and presentation work normally. Reads include speaker notes for the same current permissions as the existing drive API. Results and input are bounded at 1 MiB. Creation returns only sqid, URL and decimal-string revision. |
| @@ -16,10 +17,26 @@ Reuse the same nonzero canonical UUID and identical normalized payload after an |
| The CLI uses `oficina call slides_create_deck --input <JSON-file>` according to the installed CLI's help. Paseo can use the CLI's local MCP bridge and credential store. ChatGPT and Claude use the public remote connection service and their separately registered OAuth callbacks. App-adapter tests are not certification of those live hosts. No production deployment is claimed by this branch. |
| -The original `/api/v1/decks` drive API remains available for its existing tokens. Delegated semantic editing, asset uploads, exports, presentation control and sharing are follow-on operation contracts; these three tools do not claim to expose them yet. |
| +The original `/api/v1/decks` drive API remains available for its existing tokens. Asset uploads, exports, presentation control and sharing remain follow-on delegated operation contracts. |
| In roster team mode, creating decks requires current Home membership; the local |
| allowlist grants no team standing. The agent team must match the provisioned |
| roster team. Full lists return a retryable failure if roster authority cannot |
| be verified; exact independently shared decks remain readable. This initial |
| API requires an existing Home-linked local account. |
| + |
| +`slides_update_deck` applies 1–100 semantic operations atomically. Its exported |
| +schema describes each operation's fields and types: metadata, slides, blocks, |
| +text, notes, layout and ordering use the native editor engine. Read |
| +`slides_get_deck`, copy its decimal-string `revision` into `expected_revision`, |
| +and choose a new canonical nonzero UUID for the edit. The update returns |
| +`sqid`, `url`, `revision` and `ids` (server-minted IDs keyed by operation index). |
| +A stale revision returns `conflict` without changing the deck. |
| + |
| +Keep the same UUID, expected revision and ordered payload after an uncertain |
| +response. A matching retry returns the original **applied** revision and IDs, |
| +even after somebody edits the deck later; read again for current content. |
| +Current access is required on every attempt and before response delivery. |
| +Existing independent deck grants permit document editing under the app's |
| +native policy; creation continues to require current membership. New edits |
| +never automatically rebase and never accept raw Yjs or whole-deck replacement. |
diff --git a/docs/superpowers/specs/2026-11-01-agent-deck-editing.md b/docs/superpowers/specs/2026-11-01-agent-deck-editing.md| new file mode 100644 |
| index 0000000..7dac0c0 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-01-agent-deck-editing.md |
| @@ -0,0 +1,231 @@ |
| +# Delegated semantic deck editing |
| + |
| +Status: specification and final source independently approved by a separate |
| +GPT-6 Astra agent, 2026-11-01, with the machine contract clarification below. |
| +Validation is recorded below. |
| +Author: GPT-6 Astra, 2026-11-01. Paul authorized everyday editing APIs through |
| +the suite's existing API, CLI and MCP connection. This extends the approved |
| +2026-10-25 agent-access design. Its identity, namespace, privacy, roster and |
| +response-emission rules remain binding, and existing v1 contracts are unchanged. |
| + |
| +## Contract |
| + |
| +Add `slides_update_deck`, scope `slides:write`, readOnly false, idempotent true. |
| +HTTP, CLI and MCP use the same team-independent descriptor. All five fields |
| +below are required; unknown top-level fields are refused. |
| + |
| +```json |
| +{ |
| + "team": "team-id", |
| + "sqid": "k7m2xq9dwb", |
| + "expected_revision": "12", |
| + "client_id": "1dc98332-7165-43c5-8f98-9546f10146a8", |
| + "ops": [ |
| + {"op":"set_notes","id":"abcdefghijkl","markdown":"Discuss the revised estimate."}, |
| + {"op":"add_slide","layout":"flow","template":"title-body"} |
| + ] |
| +} |
| +``` |
| + |
| +Sqid retains the exact existing ten-character alphabet and revision retains |
| +the canonical nonnegative decimal string of `Deck.Seq`, at most MaxInt64. |
| +Signs, leading zeros, fractions and overflow are invalid. A new edit must |
| +leave room for one sequence increment. The UUID is nonzero canonical |
| +lowercase hyphenated form. Team is 1–128 characters and must equal the |
| +configured instance team. Accept 1–100 ordered semantic operations, at most |
| +1 MiB for the whole request. Reject malformed Unicode and duplicate JSON |
| +object keys before decoding op fragments; retain raw numbers and the semantic |
| +distinction between absent keys and null. |
| + |
| +Allowed operation names are `set_meta`, `add_slide`, `remove_slide`, |
| +`move_slide`, `duplicate_slide`, `set_slide`, `set_notes`, `add_block`, |
| +`remove_block`, `move_block`, `set_block`, `set_text` and `set_phone`. |
| +Their fields, references, markdown, rich text, fractional coordinates and |
| +ordering are the existing canonical operation vocabulary in `docs/api.md` |
| +and `core/src/ops.rs`, with no second Go operation interpreter. The exported |
| +descriptor exposes concrete argument fields and types for every supported op, |
| +using per-operation `oneOf` or an equivalent machine schema, so API, CLI and |
| +MCP callers can discover the contract without external documentation. The core |
| +validates operation-specific types, fields and cross-operation references. |
| +The envelope limit and op count are enforced before calling the engine. |
| +Asset registration/removal, upload, export, presentation, sharing and deck |
| +deletion are outside this slice. Existing registered images can still be |
| +referenced by ordinary block operations under their current validation. |
| + |
| +Missing slide/block IDs are minted through existing `mintOpIDs`, including |
| +duplicate-slide block identities. Caller-supplied IDs retain native semantics. |
| +The caller can provide its own IDs when later operations in the same batch |
| +need to refer to newly added objects. No raw Yjs updates or whole-deck JSON |
| +replacement are accepted. |
| + |
| +Success is a small acknowledgement: |
| + |
| +```json |
| +{"sqid":"k7m2xq9dwb","revision":"13","url":"https://slides.example/d/k7m2xq9dwb","ids":{"1":"mnopqrstuvwx"}} |
| +``` |
| + |
| +All four fields are required. `ids` is the existing native operation-index |
| +map for server-minted slide/block IDs; duplicate-slide child block identities |
| +are discoverable by reading the resulting deck, as on the existing drive API. |
| +`revision` is the immutable sequence committed by this mutation. A completed |
| +retry returns the same revision and IDs even after later browser edits. It |
| +does not return a stale deck body; `slides_get_deck` gives current content and |
| +revision. Existing create responses keep their current-revision semantics. |
| +Bound the encoded result before commit to the existing 1 MiB result maximum. |
| + |
| +`conflict` means stale expected revision for a new mutation or a reused client |
| +UUID with a different target, expected revision or ordered operation payload. |
| +Current access is checked before disclosing conflict. A stale request never |
| +automatically rebases against a newer deck. The caller reads again and chooses |
| +a fresh UUID for its revised intent. Core refusal is `invalid`; storage, |
| +deadline or engine execution failures are unavailable, not partial success. |
| +Missing/inaccessible decks and other authority failures use existing codes. |
| + |
| +## Native authority and response boundary |
| + |
| +Only creation requires creator membership; do not treat every slides:write |
| +operation as create. Document editing follows the app's existing deck write |
| +authority: a person who can reach a deck through the native owner/team/grant |
| +seam may edit its document, as `apiOps` does. No new viewer/editor distinction |
| +is invented. Existing independent deck grants survive NotMember or Unknown; |
| +owner/team-rung reach requires Member from the single captured Access. |
| + |
| +At writer reservation and before commit, including completed retries, |
| +reverify the original delegation verifier and unchanged principal fields, |
| +resolve the keyed Home link on the transaction through `ResolveOn`, compare |
| +stable local person ID and address, and recheck live deck reach on that same |
| +transaction. The team write guard wraps the entire mutation/receipt decision. |
| +No outer-pool lookup, HomeOnly fallback, automatic provisioning or roster |
| +network request runs under the writer. A missing or expired required lease |
| +fails closed; an independent current grant is checked on the transaction. |
| + |
| +Remember the exact deck for existing before-header and per-chunk identity, |
| +delegation, live deck and roster checks. Preserve the standing-lease socket |
| +deadline clamp. Loss of authority during emission aborts it; a committed but |
| +unacknowledged edit is recovered through its stable retry UUID. |
| + |
| +## One canonical edit transaction |
| + |
| +Use the existing semantic engine, op ID minting, `metaRowUpdates`, |
| +`applyOpsOn`, core shape check and canonical projection parser. Do not call |
| +the legacy `applyAgentOps` retry loop: it intentionally retries a busy deck |
| +at its new sequence, which violates this operation's explicit precondition. |
| + |
| +Reserve the SQLite writer using the existing immutable namespace marker. |
| +Recheck local authority, read any existing receipt, then read the current |
| +deck row and compare its sequence to expected_revision. Open a fresh owned |
| +core handle whose snapshot and ordered log reads use the caller's transaction |
| +at that exact sequence; factor a transaction-aware `openDeck` seam if needed. |
| +Never call the outer-pool reader while holding the writer. All handles are |
| +closed/discarded after either commit or rollback. |
| + |
| +For a new request, mint missing IDs on a copy of its op fragments, preserving |
| +the original request for fingerprinting. Apply the batch once through the |
| +canonical engine; require both `Handle.Check` of shared-type structure and |
| +`deck.Parse` of `Handle.JSON` before commit. The app's transaction encloses |
| +the update-log insert, optimistic sequence bump, any deck-row metadata, |
| +actor attribution, receipt and final authority check. If the existing helper |
| +performs inserts before shape checking, these stay inside the uncommitted |
| +transaction and any failed check rolls all of them back. The resulting deck |
| +must also fit the existing 1 MiB canonical get result bound, so this editing |
| +surface cannot successfully create a deck its read operation cannot return. |
| + |
| +Preserve fractional z/box values by retaining raw op JSON and the canonical |
| +JSON projection; never round-trip through the simplified typed Deck struct |
| +as the source of persisted content. All order changes go through the engine's |
| +identity-preserving order keys. Both required checks remain independent gates. |
| +Only after commit publish the new sequence and attempt a native snapshot. |
| +Replays publish nothing and create no extra log entry or actor attribution. |
| + |
| +## Durable retry and attribution |
| + |
| +Add a separate additive edit-receipt table. Its unique HMAC coordinate binds |
| +operation name, both authority issuers, team, subject, delegated client and |
| +client UUID. The payload HMAC binds sqid, expected revision and ordered |
| +operation content before server-generated IDs. Object key order and harmless |
| +JSON whitespace do not change the fingerprint: canonicalize recursively with |
| +exact JSON numbers, without float64 conversion; number spelling may remain |
| +significant and is documented as requiring an exact semantic retry payload. |
| +Absent and null remain different. No plaintext markdown or op payload is |
| +persisted in the receipt or logged. |
| + |
| +Persist the target deck ID, applied sequence and a sealed acknowledgement |
| +containing the stable returned ID map under a receipt-specific purpose. Use |
| +the existing sealed connection attribution and connection actor on the update |
| +row. The immutable namespace marker's no-adoption checks include new edit |
| +receipts as well as creation receipts and attribution. Marker, receipt, |
| +attribution and content share one transaction and key/issuer/team continuity. |
| + |
| +A matching completed receipt is returned only after current resource and |
| +writer authority checks, before checking expected_revision against the now |
| +current deck. This is why a retry after later changes is safe. Changed payload |
| +conflicts. Concurrent identical submissions commit one batch and return one |
| +stable acknowledgement. A failed write leaves no receipt or generated IDs |
| +claiming a committed result. Recreated app and reopened database must replay |
| +the same applied revision and IDs without rerunning the semantic engine. |
| + |
| +## Review and validation gates |
| + |
| +Independent highest-capability spec approval precedes implementation and |
| +independent source/evidence review follows. Required gates: |
| + |
| +- Real Home grant/gateway/MCP create-read-edit-read, including text, notes, |
| + slide/block reorder, add/duplicate/remove, metadata and fractional canvas |
| + coordinates. Compare native `openDeck`, the canonical JSON read operation |
| + and browser-rendered HTML from the same state. |
| +- Two concurrent edits from one sequence: one commit, one conflict; exact |
| + duplicate retry after a later native edit and after app restart preserves |
| + that later edit and returns original generated IDs and applied sequence. |
| +- Invalid later op, malformed rich text, missing reference and columns-cycle |
| + rejection leave no partial updates. Independently exercise shape and |
| + projection gates, not merely core input parsing. |
| +- SQL failures at update insert, metadata update, attribution and receipt |
| + persistence roll back sequence, log, metadata and acknowledgement. A |
| + fresh open reads the old deck; no seq publication or snapshot precedes |
| + commit. Completed retries do not apply another op batch. |
| +- Initial/final revocation, unlink, binding corruption, live deck/grant loss |
| + and roster lease expiry, including direct-domain completed-retry tests |
| + independent of emission. Independent granted access under Unknown and |
| + NotMember remains supported; create still requires current membership. |
| +- Exact JSON numbers, null/absence, strict Unicode/duplicate keys, revision |
| + limits, unknown operation names and 100-op/1 MiB bounds. Verify sealed |
| + acknowledgement/attribution and no plaintext content in receipt storage. |
| +- Add the delegated path to the enumerated team-write lapse test. Effective |
| + runtime-failing mutants separately skip revision comparison, completed |
| + receipt payload checking, final writer guard, live transactional reach, |
| + one canonical shape gate and receipt atomicity. |
| +- Restore all mutants; run focused race tests and the full pinned |
| + `.amadan/ci.d/10-gate` (canonical wasm rebuild/cmp, Rust/JS, Go and migrations) |
| + on the final tree. A fast `make ci` alone does not replace this gate. |
| + |
| +This additive operation carries no canary, main-merge or deployment approval. |
| + |
| +## Independent review record |
| + |
| +On 2026-11-01 a separate GPT-6 Astra agent approved this specification before |
| +implementation, then independently reviewed the final source and selected |
| +adversarial mutations. Final source approval covers this bounded editing |
| +operation and its native transaction/authority integration. It does not approve |
| +main merge, canary behavior or deployment. |
| + |
| +Eight selected mutants failed at runtime: missing revision check, ignored |
| +completed receipt, missing final writer check, new IDs returned on replay, |
| +omitted shared-type shape check, omitted projection parsing, float64 receipt |
| +fingerprints, and ignored receipt persistence failure. Every original was |
| +restored. The exported operation contract contains concrete schemas for all |
| +thirteen allowed semantic operations; the canonical engine remains authoritative. |
| + |
| +Final restored-tree canonical gate passed on 2026-11-01: |
| +`TMPDIR=/tmp GOTOOLCHAIN=go1.26.5 ./.amadan/ci.d/10-gate`. This includes |
| +Rust formatting/clippy/tests, canonical WASM rebuild and byte comparison, |
| +JavaScript tests/vectors/bundle checks, and Go vet/formatting/tests/migrations |
| +and credits. The short temporary directory avoids the macOS Unix-socket path |
| +limit in the existing shutdown test; no application behavior or test was |
| +changed for that environment constraint. |
| + |
| +The final focused race check also passed (313.173s): |
| +`GOMAXPROCS=2 TMPDIR=/tmp GOTOOLCHAIN=go1.26.5 go test -race |
| +./internal/slides -run |
| +'TestAgentDeckEdit|TestAgentGatewayToRealSlides|TestAgentTeamSlidesMembership' |
| +-count=1 -timeout 1200s`. It covers the editing boundary, native semantic |
| +parity, real HTTPS CLI/MCP edit/read/retry, and retained roster behavior. |
diff --git a/internal/slides/agent_access.go b/internal/slides/agent_access.go| index a9954b9..bed30b9 100644 |
| --- a/internal/slides/agent_access.go |
| +++ b/internal/slides/agent_access.go |
| @@ -107,12 +107,15 @@ func (a *slideAgent) httpHandler(verifier access.Verifier) (http.Handler, error) |
| return |
| } |
| name := strings.TrimPrefix(r.URL.Path, "/api/v1/operations/") |
| - write := name == "slides_create_deck" |
| + write := name == "slides_create_deck" || name == "slides_update_deck" |
| discovery := r.Method == "GET" && r.URL.Path == "/api/v1/operations" |
| if discovery && !p.Allows(a.team, "slides:read") { |
| write = true |
| } |
| member, e := a.member(r.Context(), p, write) |
| + if e == nil && name == "slides_create_deck" { |
| + e = a.creator(member) |
| + } |
| if e != nil { |
| slideAgentWriteFailure(w, e) |
| return |
| @@ -195,6 +198,9 @@ func (a *slideAgent) httpHandler(verifier access.Verifier) (http.Handler, error) |
| return e |
| } |
| fresh, e := a.member(checkCtx, p, write) |
| + if e == nil && name == "slides_create_deck" { |
| + e = a.creator(fresh) |
| + } |
| if e != nil { |
| return e |
| } |
diff --git a/internal/slides/agent_authority.go b/internal/slides/agent_authority.go| index ab436b3..1971637 100644 |
| --- a/internal/slides/agent_authority.go |
| +++ b/internal/slides/agent_authority.go |
| @@ -64,7 +64,7 @@ func (a *slideAgent) digest(domain string, value any) string { |
| } |
| func (a *slideAgent) bind(tx *gorm.DB) error { |
| want := a.digest("keycheck", []string{"immutable-authority", a.identityIssuer, a.issuer, a.team}) |
| - if e := tx.Exec("INSERT INTO slides_agent_state(id,keycheck) SELECT 1,? WHERE NOT EXISTS(SELECT 1 FROM slides_agent_receipts) AND NOT EXISTS(SELECT 1 FROM slides_connections) ON CONFLICT(id) DO NOTHING", want).Error; e != nil { |
| + if e := tx.Exec("INSERT INTO slides_agent_state(id,keycheck) SELECT 1,? WHERE NOT EXISTS(SELECT 1 FROM slides_agent_receipts) AND NOT EXISTS(SELECT 1 FROM slides_connections) AND NOT EXISTS(SELECT 1 FROM slides_agent_edits) ON CONFLICT(id) DO NOTHING", want).Error; e != nil { |
| return e |
| } |
| var got string |
| @@ -107,11 +107,6 @@ func (a *slideAgent) member(ctx context.Context, p access.Principal, write bool) |
| } else { |
| u.team = &teamAccess{Access: a.app.team.Access(ctx, p.Subject)} |
| } |
| - if write { |
| - if err := a.creator(u); err != nil { |
| - return User{}, err |
| - } |
| - } |
| } |
| return u, nil |
| } |
diff --git a/internal/slides/agent_create.go b/internal/slides/agent_create.go| index fc31068..536cbec 100644 |
| --- a/internal/slides/agent_create.go |
| +++ b/internal/slides/agent_create.go |
| @@ -28,6 +28,9 @@ type slideAgentCreate struct { |
| } |
| func (a *slideAgent) create(ctx context.Context, p access.Principal, u User, in slideAgentCreate) (any, error) { |
| + if err := a.creator(u); err != nil { |
| + return nil, slideAgentFailure(err) |
| + } |
| id, e := uuid.Parse(in.ClientID) |
| if e != nil || id == uuid.Nil || id.String() != in.ClientID { |
| return nil, access.Fail("invalid", "Supply a canonical nonzero UUID client_id.") |
diff --git a/internal/slides/agent_edit.go b/internal/slides/agent_edit.go| new file mode 100644 |
| index 0000000..ce2e497 |
| --- /dev/null |
| +++ b/internal/slides/agent_edit.go |
| @@ -0,0 +1,229 @@ |
| +package slides |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "encoding/json" |
| + "errors" |
| + "math" |
| + "strconv" |
| + |
| + access "amadan.net/oficina/agent-access.git" |
| + "amadan.net/oficina/home/connect/linkstore" |
| + "amadan.net/oficina/home/handoff/seal" |
| + "amadan.net/oficina/slides/internal/slides/core" |
| + "amadan.net/oficina/slides/internal/slides/deck" |
| + "github.com/google/uuid" |
| + "gorm.io/gorm" |
| +) |
| + |
| +type slideAgentEdit struct { |
| + Coordinate string `gorm:"primaryKey"` |
| + Content string |
| + DeckID int64 |
| + Revision int64 |
| + ResultSealed []byte |
| +} |
| + |
| +func (slideAgentEdit) TableName() string { return "slides_agent_edits" } |
| + |
| +type slideAgentUpdate struct { |
| + Team string `json:"team"` |
| + Sqid string `json:"sqid"` |
| + ExpectedRevision string `json:"expected_revision"` |
| + ClientID string `json:"client_id"` |
| + Ops []map[string]json.RawMessage `json:"ops"` |
| +} |
| +type slideAgentUpdated struct { |
| + Sqid string `json:"sqid"` |
| + Revision string `json:"revision"` |
| + URL string `json:"url"` |
| + IDs map[string]string `json:"ids"` |
| +} |
| + |
| +func (a *slideAgent) editorInTx(ctx context.Context, tx *gorm.DB, p access.Principal, u User, sqid string, d *Deck) error { |
| + state, ok := ctx.Value(slideAgentKey{}).(*slideAgentContext) |
| + if !ok || state == nil || state.verify == nil { |
| + return linkstore.ErrRefused |
| + } |
| + if err := state.verify(ctx); err != nil { |
| + return err |
| + } |
| + person, err := a.app.home.ResolveOn(ctx, tx.Statement.ConnPool, p.Subject) |
| + if err != nil { |
| + return err |
| + } |
| + if person.ID != u.ID || person.Label != u.Email { |
| + return linkstore.ErrRefused |
| + } |
| + var current User |
| + if err = tx.First(¤t, person.ID).Error; err != nil { |
| + return err |
| + } |
| + if current.Email != u.Email || a.app.team == nil && !a.app.allowed.allows(current.Email) { |
| + return linkstore.ErrRefused |
| + } |
| + current.team = u.team |
| + return a.visible(ctx, tx, current, "sqid=?", sqid, d) |
| +} |
| + |
| +func (a *slideAgent) update(ctx context.Context, p access.Principal, u User, in slideAgentUpdate) (any, error) { |
| + expected, err := strconv.ParseInt(in.ExpectedRevision, 10, 64) |
| + if err != nil || expected < 0 || strconv.FormatInt(expected, 10) != in.ExpectedRevision { |
| + return nil, access.Fail("invalid", "Use a canonical nonnegative decimal revision.") |
| + } |
| + id, err := uuid.Parse(in.ClientID) |
| + if err != nil || id == uuid.Nil || id.String() != in.ClientID { |
| + return nil, access.Fail("invalid", "Use a canonical nonzero client UUID.") |
| + } |
| + if len(in.Ops) < 1 || len(in.Ops) > 100 { |
| + return nil, access.Fail("invalid", "Supply one to one hundred semantic operations.") |
| + } |
| + for _, op := range in.Ops { |
| + if !slideAgentEditableOp(rawString(op, "op")) { |
| + return nil, access.Fail("invalid", "Unsupported deck operation.") |
| + } |
| + } |
| + // Decode numbers as Number, not float64. Marshal sorts object keys recursively |
| + // and keeps ordered arrays, exact number spelling and absent versus null. |
| + original, err := json.Marshal(in) |
| + if err != nil { |
| + return nil, slideAgentFailure(err) |
| + } |
| + var canonical any |
| + decoder := json.NewDecoder(bytes.NewReader(original)) |
| + decoder.UseNumber() |
| + if err = decoder.Decode(&canonical); err != nil { |
| + return nil, slideAgentFailure(err) |
| + } |
| + coordinate := a.digest("edit-coordinate", []string{"slides_update_deck", a.identityIssuer, a.issuer, a.team, p.Subject, p.Client, in.ClientID}) |
| + content := a.digest("edit-content", canonical) |
| + var initial Deck |
| + if err = a.visible(ctx, a.app.db.G, u, "sqid=?", in.Sqid, &initial); err != nil { |
| + return nil, slideAgentFailure(err) |
| + } |
| + sealer, err := seal.New(a.key, "oficina/slides/agent/v1") |
| + if err != nil { |
| + return nil, slideAgentFailure(err) |
| + } |
| + var result slideAgentUpdated |
| + var d Deck |
| + var h *core.Handle |
| + fresh := false |
| + defer func() { |
| + if h != nil { |
| + h.Close(context.WithoutCancel(ctx)) |
| + } |
| + }() |
| + guard := a.app.deckGuard(ctx, u, initial) |
| + err = a.app.db.G.WithContext(ctx).Transaction(func(tx *gorm.DB) error { |
| + if e := a.bind(tx); e != nil { |
| + return e |
| + } |
| + return guard.run(func() error { |
| + if e := a.editorInTx(ctx, tx, p, u, in.Sqid, &d); e != nil { |
| + return e |
| + } |
| + var receipt slideAgentEdit |
| + e := tx.Where("coordinate=?", coordinate).Take(&receipt).Error |
| + if e == nil { |
| + if receipt.Content != content || receipt.DeckID != d.ID { |
| + return access.Fail("conflict", "This client UUID already names a different edit.") |
| + } |
| + plain, e := sealer.Open("edit-result/"+coordinate, receipt.ResultSealed) |
| + if e != nil { |
| + return e |
| + } |
| + if e = json.Unmarshal(plain, &result); e != nil { |
| + return e |
| + } |
| + if result.Sqid != in.Sqid || result.Revision != strconv.FormatInt(receipt.Revision, 10) || result.IDs == nil { |
| + return access.Fail("unavailable", "The edit receipt is unavailable.") |
| + } |
| + return a.editorInTx(ctx, tx, p, u, in.Sqid, &d) |
| + } |
| + if !errors.Is(e, gorm.ErrRecordNotFound) { |
| + return e |
| + } |
| + if d.Seq != expected { |
| + return access.Fail("conflict", "This deck changed. Read it again before editing.") |
| + } |
| + if d.Seq == math.MaxInt64 { |
| + return access.Fail("unavailable", "This deck's revision cannot advance.") |
| + } |
| + var view *deck.Deck |
| + h, view, e = a.app.openDeckOn(ctx, tx, d) |
| + if e != nil { |
| + return e |
| + } |
| + var copied slideAgentUpdate |
| + if e = json.Unmarshal(original, &copied); e != nil { |
| + return e |
| + } |
| + ids, e := mintOpIDs(copied.Ops, view) |
| + if e != nil { |
| + return e |
| + } |
| + encoded, e := json.Marshal(copied.Ops) |
| + if e != nil { |
| + return e |
| + } |
| + actor, e := a.actor(tx, p, u) |
| + if e != nil { |
| + return e |
| + } |
| + if e = applyOpsOn(ctx, tx, h, &d, actor, encoded, metaRowUpdates(copied.Ops)); e != nil { |
| + return e |
| + } |
| + if e = h.Check(ctx); e != nil { |
| + return e |
| + } |
| + raw, e := h.JSON(ctx) |
| + if e != nil { |
| + return e |
| + } |
| + if _, e = deck.Parse(raw); e != nil { |
| + return e |
| + } |
| + if _, e = slideAgentBounded(map[string]any{"sqid": d.Sqid, "revision": strconv.FormatInt(d.Seq+1, 10), "deck": json.RawMessage(raw)}); e != nil { |
| + return e |
| + } |
| + result = slideAgentUpdated{Sqid: d.Sqid, Revision: strconv.FormatInt(d.Seq+1, 10), URL: a.app.cfg.Origin + "/d/" + d.Sqid, IDs: ids} |
| + if _, e = slideAgentBounded(result); e != nil { |
| + return e |
| + } |
| + encoded, e = json.Marshal(result) |
| + if e != nil { |
| + return e |
| + } |
| + ciphertext, e := sealer.Seal("edit-result/"+coordinate, encoded) |
| + if e != nil { |
| + return e |
| + } |
| + if e = tx.Create(&slideAgentEdit{Coordinate: coordinate, Content: content, DeckID: d.ID, Revision: d.Seq + 1, ResultSealed: ciphertext}).Error; e != nil { |
| + return e |
| + } |
| + if e = a.editorInTx(ctx, tx, p, u, in.Sqid, &d); e != nil { |
| + return e |
| + } |
| + fresh = true |
| + return nil |
| + }) |
| + }) |
| + if err != nil { |
| + var rejected *core.RejectedError |
| + if errors.As(err, &rejected) { |
| + return nil, access.Fail("invalid", "The semantic operation batch was refused.") |
| + } |
| + if errors.Is(err, errDeckBusy) { |
| + return nil, access.Fail("conflict", "This deck changed. Read it again before editing.") |
| + } |
| + return nil, slideAgentFailure(err) |
| + } |
| + if fresh { |
| + a.app.live.PublishSeq(d.Sqid, d.Seq) |
| + a.app.maybeSnapshot(ctx, d, h, d.Seq) |
| + } |
| + a.remember(ctx, d.ID) |
| + return slideAgentBounded(result) |
| +} |
diff --git a/internal/slides/agent_edit_boundary_test.go b/internal/slides/agent_edit_boundary_test.go| new file mode 100644 |
| index 0000000..de75eb5 |
| --- /dev/null |
| +++ b/internal/slides/agent_edit_boundary_test.go |
| @@ -0,0 +1,214 @@ |
| +package slides |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "encoding/json" |
| + "os" |
| + "reflect" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/home/roster" |
| + "amadan.net/oficina/home/teammode" |
| + "amadan.net/rastrillo/rastrillo/db" |
| +) |
| + |
| +func TestAgentDeckEditRestart(t *testing.T) { |
| + f := newSlideAgentFixture(t) |
| + sqid := slideCreated(t, f.call(t, "slides_create_deck", initialSlideAgentInput())) |
| + in := updateDeckInput(t, f, sqid, []op{{"op": "add_slide", "layout": "flow"}}) |
| + ack := updatedDeck(t, f.call(t, "slides_update_deck", in)) |
| + var path string |
| + if e := f.a.app.db.Writer().QueryRow("SELECT file FROM pragma_database_list WHERE name='main'").Scan(&path); e != nil { |
| + t.Fatal(e) |
| + } |
| + f.a.app.Close() |
| + f.a.app.db.Close() |
| + d, e := db.Open(path, quietLogger()) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + defer d.Close() |
| + _, app, e := New(d, f.a.app.cfg) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + defer app.Close() |
| + f.a.app = app |
| + f.install(t) |
| + if got := updatedDeck(t, f.call(t, "slides_update_deck", in)); !reflect.DeepEqual(got, ack) { |
| + t.Fatal("reopened edit receipt", got, ack) |
| + } |
| +} |
| +func TestAgentDeckEditLimitsAndSchema(t *testing.T) { |
| + f := newSlideAgentFixture(t) |
| + sqid := slideCreated(t, f.call(t, "slides_create_deck", initialSlideAgentInput())) |
| + in := updateDeckInput(t, f, sqid, []op{{"op": "add_slide", "layout": "flow"}}) |
| + for _, rev := range []string{"01", "-1", "1.0", "9223372036854775808"} { |
| + bad := in |
| + bad.ExpectedRevision = rev |
| + if r := f.call(t, "slides_update_deck", bad); r.Code != 422 { |
| + t.Fatal(rev, r.Code) |
| + } |
| + } |
| + for _, ops := range [][]op{nil, {{"op": "register_asset", "id": "image"}}, {{"op": "add_slide", "layout": "nonsense"}}, {{"op": "set_notes", "id": "x", "markdown": 3}}, {{"op": "set_phone", "slide": "s", "id": "b", "phone": map[string]any{"unknown": true}}}} { |
| + bad := updateDeckInput(t, f, sqid, ops) |
| + if r := f.call(t, "slides_update_deck", bad); r.Code != 422 { |
| + t.Fatal("schema", r.Code, r.Body.String()) |
| + } |
| + } |
| + many := in |
| + many.Ops = nil |
| + for range 101 { |
| + many.Ops = append(many.Ops, in.Ops[0]) |
| + } |
| + if r := f.call(t, "slides_update_deck", many); r.Code != 422 { |
| + t.Fatal("op cap", r.Code) |
| + } |
| + raw, _ := json.Marshal(in) |
| + raw = bytes.Replace(raw, []byte(`"flow"`), []byte(`"\ud800"`), 1) |
| + if r := f.raw(t, "slides_update_deck", raw); r.Code != 422 { |
| + t.Fatal("invalid Unicode", r.Code) |
| + } |
| + raw, _ = json.Marshal(in) |
| + raw = bytes.Replace(raw, []byte(`"layout":"flow"`), []byte(`"layout":"flow","layout":"canvas"`), 1) |
| + if r := f.raw(t, "slides_update_deck", raw); r.Code != 422 { |
| + t.Fatal("duplicate keys", r.Code) |
| + } |
| + enormous := updateDeckInput(t, f, sqid, []op{{"op": "set_meta", "title": strings.Repeat("a", slideAgentLimit)}}) |
| + if r := f.call(t, "slides_update_deck", enormous); r.Code != 413 { |
| + t.Fatal("request cap", r.Code) |
| + } |
| + var n int64 |
| + f.a.app.db.G.Model(&slideAgentEdit{}).Count(&n) |
| + if n != 0 { |
| + t.Fatal("invalid request left receipt") |
| + } |
| +} |
| +func TestAgentDeckEditResultRemainsReadable(t *testing.T) { |
| + f := newSlideAgentFixture(t) |
| + initial := initialSlideAgentInput() |
| + initial.Slides[0].Body = strings.Repeat("x", 120<<10) |
| + sqid := slideCreated(t, f.call(t, "slides_create_deck", initial)) |
| + _, v, _ := readEditedDeck(t, f, sqid) |
| + var ops []op |
| + for range 10 { |
| + ops = append(ops, op{"op": "duplicate_slide", "id": v.Slides[0].ID}) |
| + } |
| + in := updateDeckInput(t, f, sqid, ops) |
| + before := editDeckCounts(t, f) |
| + if r := f.call(t, "slides_update_deck", in); r.Code != 413 { |
| + t.Fatal("unreadable result committed", r.Code, r.Body.String()) |
| + } |
| + if !reflect.DeepEqual(before, editDeckCounts(t, f)) { |
| + t.Fatal("oversized result effects") |
| + } |
| +} |
| +func TestAgentDeckEditChecksWholeSharedTypeShape(t *testing.T) { |
| + f := newSlideAgentFixture(t) |
| + sqid := slideCreated(t, f.call(t, "slides_create_deck", initialSlideAgentInput())) |
| + var d Deck |
| + if e := f.a.app.db.G.Where("sqid=?", sqid).Take(&d).Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + // Simulate an old, invalid stored document whose tolerant JSON view still |
| + // parses. A harmless edit must not append on top of an unknown shared mark. |
| + poison, e := os.ReadFile("../slidestest/testdata/poison/unknownmark.yjs") |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + if e = f.a.app.db.G.Create(&DeckUpdate{DeckID: d.ID, Seq: d.Seq + 1, Actor: "legacy", Bytes: poison}).Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + if e = f.a.app.db.G.Model(&Deck{}).Where("id=?", d.ID).Update("seq", d.Seq+1).Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + in := updateDeckInput(t, f, sqid, []op{{"op": "set_meta", "title": "Must not commit"}}) |
| + before := editDeckCounts(t, f) |
| + r := f.call(t, "slides_update_deck", in) |
| + if r.Code != 422 { |
| + t.Fatal("shared-type shape gate", r.Code, r.Body.String()) |
| + } |
| + if !reflect.DeepEqual(before, editDeckCounts(t, f)) { |
| + t.Fatal("shape-invalid edit committed") |
| + } |
| +} |
| +func testAgentDeckEditGuardLapse(t *testing.T) { |
| + f, af := newTeamSlideAgent(t) |
| + sqid := slideCreated(t, af.call(t, "slides_create_deck", teamSlideInput(af))) |
| + in := updateDeckInput(t, af, sqid, []op{{"op": "add_slide", "layout": "flow"}}) |
| + counts := editDeckCounts(t, af) |
| + old := teamGuard |
| + t.Cleanup(func() { teamGuard = old }) |
| + teamGuard = func(ctx context.Context, authorize func(roster.State) error, write func() error) error { |
| + return teammode.Guard(ctx, authorize, func() error { |
| + if e := write(); e != nil { |
| + return e |
| + } |
| + f.expired() |
| + return nil |
| + }) |
| + } |
| + if r := af.call(t, "slides_update_deck", in); r.Code != 503 || !reflect.DeepEqual(counts, editDeckCounts(t, af)) { |
| + t.Fatal("last team guard omitted", r.Code, r.Body.String()) |
| + } |
| +} |
| + |
| +func TestAgentDeckEditExactNumberRetryFingerprint(t *testing.T) { |
| + f := newSlideAgentFixture(t) |
| + sqid := slideCreated(t, f.call(t, "slides_create_deck", initialSlideAgentInput())) |
| + _, v, _ := readEditedDeck(t, f, sqid) |
| + s := v.Slides[0] |
| + in := updateDeckInput(t, f, sqid, []op{{"op": "set_block", "slide": s.ID, "id": s.Blocks[0].ID, "props": map[string]any{"custom_number": json.Number("9007199254740993")}}}) |
| + ack := updatedDeck(t, f.call(t, "slides_update_deck", in)) |
| + same, _ := json.Marshal(in) |
| + // Object whitespace is irrelevant, but adjacent integers above 2^53 must |
| + // not collapse to the same retry fingerprint through float64 decoding. |
| + if got := updatedDeck(t, f.raw(t, "slides_update_deck", append([]byte(" \n"), same...))); !reflect.DeepEqual(got, ack) { |
| + t.Fatal("whitespace changed retry") |
| + } |
| + changed := bytes.Replace(same, []byte("9007199254740993"), []byte("9007199254740992"), 1) |
| + if r := f.raw(t, "slides_update_deck", changed); r.Code != 409 { |
| + t.Fatal("rounded retry identity", r.Code, r.Body.String()) |
| + } |
| +} |
| +func TestAgentDeckEditRejectsInvalidNativeProjection(t *testing.T) { |
| + f := newSlideAgentFixture(t) |
| + sqid := slideCreated(t, f.call(t, "slides_create_deck", initialSlideAgentInput())) |
| + before, v, raw := readEditedDeck(t, f, sqid) |
| + s := v.Slides[0] |
| + // The native op accepts int64, but Yjs stores a Number: MaxInt64 rounds |
| + // past the host's integer field. Shared rich-text shape remains valid. |
| + in := updateDeckInput(t, f, sqid, []op{{"op": "set_phone", "slide": s.ID, "id": s.Blocks[0].ID, "phone": map[string]any{"order": json.Number("9223372036854775807")}}}) |
| + counts := editDeckCounts(t, f) |
| + r := f.call(t, "slides_update_deck", in) |
| + if r.Code != 503 { |
| + t.Fatal("invalid projection accepted", r.Code, r.Body.String()) |
| + } |
| + after, _, got := readEditedDeck(t, f, sqid) |
| + if after.Seq != before.Seq || !bytes.Equal(raw, got) || !reflect.DeepEqual(counts, editDeckCounts(t, f)) { |
| + t.Fatal("invalid projection persisted") |
| + } |
| +} |
| + |
| +func TestAgentDeckEditWriteScopeAndUnboundReceipt(t *testing.T) { |
| + f := newSlideAgentFixture(t) |
| + sqid := slideCreated(t, f.call(t, "slides_create_deck", initialSlideAgentInput())) |
| + in := updateDeckInput(t, f, sqid, []op{{"op": "add_slide", "layout": "flow"}}) |
| + f.p.Scopes = []string{"slides:write"} |
| + updatedDeck(t, f.call(t, "slides_update_deck", in)) |
| + f.p.Scopes = []string{"slides:read"} |
| + if r := f.call(t, "slides_update_deck", in); r.Code != 403 { |
| + t.Fatal("read scope edited", r.Code) |
| + } |
| + f.p.Scopes = []string{"slides:write"} |
| + for _, table := range []string{"slides_agent_receipts", "slides_connections", "slides_agent_state"} { |
| + if e := f.a.app.db.G.Exec("DELETE FROM " + table).Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + if r := f.call(t, "slides_update_deck", in); r.Code != 503 { |
| + t.Fatal("unbound edit receipt adopted", r.Code) |
| + } |
| +} |
diff --git a/internal/slides/agent_edit_contract.go b/internal/slides/agent_edit_contract.go| new file mode 100644 |
| index 0000000..201d48d |
| --- /dev/null |
| +++ b/internal/slides/agent_edit_contract.go |
| @@ -0,0 +1,70 @@ |
| +package slides |
| + |
| +import ( |
| + access "amadan.net/oficina/agent-access.git" |
| + "context" |
| + "encoding/json" |
| + strictjson "github.com/go-json-experiment/json" |
| +) |
| + |
| +// These are discoverable argument schemas, not a second operation interpreter. |
| +// core/src/ops.rs owns validation and execution. Contract tests exercise every |
| +// advertised variant against that engine to keep the public vocabulary honest. |
| +func slideAgentEditVariants() []any { |
| + str := func() any { return map[string]any{"type": "string"} } |
| + nullable := func(v any) any { return map[string]any{"anyOf": []any{v, map[string]any{"type": "null"}}} } |
| + object := func(p map[string]any, required ...string) any { |
| + if required == nil { |
| + required = []string{} |
| + } |
| + return slideAgentObject(p, required...) |
| + } |
| + enumeration := func(values ...string) any { return map[string]any{"enum": values} } |
| + num := map[string]any{"type": "number"} |
| + box := object(map[string]any{"x": num, "y": num, "w": num, "h": num}, "x", "y", "w", "h") |
| + fonts := object(map[string]any{"heading": str(), "body": str()}, "heading", "body") |
| + background := object(map[string]any{"kind": enumeration("theme", "color", "image"), "value": str()}, "kind") |
| + phone := object(map[string]any{"hidden": map[string]any{"type": "boolean"}, "order": map[string]any{"type": "integer"}, "size": enumeration("s", "m", "l"), "box": box}) |
| + props := map[string]any{"type": "object", "description": "Canonical properties for the block type, as exposed in slides_get_deck. Passed unchanged to the semantic engine."} |
| + layout := enumeration("flow", "canvas") |
| + template := enumeration("title", "title-body", "two-column", "section", "image-full", "quote", "blank") |
| + region := enumeration("heading", "body", "aside", "media") |
| + variant := func(name string, p map[string]any, required ...string) any { |
| + p["op"] = map[string]any{"const": name} |
| + return object(p, append([]string{"op"}, required...)...) |
| + } |
| + return []any{ |
| + variant("set_meta", map[string]any{"title": str(), "theme": str(), "accent": nullable(str()), "fonts": nullable(fonts)}), |
| + variant("add_slide", map[string]any{"id": str(), "after": nullable(str()), "layout": layout, "template": template}, "layout"), |
| + variant("remove_slide", map[string]any{"id": str()}, "id"), |
| + variant("move_slide", map[string]any{"id": str(), "after": nullable(str())}, "id"), |
| + variant("duplicate_slide", map[string]any{"id": str(), "new_id": str(), "new_block_ids": map[string]any{"type": "array", "items": str()}}, "id"), |
| + variant("set_slide", map[string]any{"id": str(), "layout": layout, "template": template, "background": background, "phone": enumeration("inherit", "reflow"), "transition": enumeration("none", "fade")}, "id"), |
| + variant("set_notes", map[string]any{"id": str(), "markdown": str()}, "id", "markdown"), |
| + variant("add_block", map[string]any{"slide": str(), "id": str(), "type": enumeration("heading", "text", "list", "quote", "image", "columns", "code", "shape", "table", "divider", "spacer"), "props": props, "region": region, "box": box, "z": num, "after": nullable(str()), "markdown": str()}, "slide", "type"), |
| + variant("remove_block", map[string]any{"slide": str(), "id": str()}, "slide", "id"), |
| + variant("move_block", map[string]any{"slide": str(), "id": str(), "after": nullable(str())}, "slide", "id"), |
| + variant("set_block", map[string]any{"slide": str(), "id": str(), "props": props, "region": nullable(region), "box": nullable(box), "z": num}, "slide", "id"), |
| + variant("set_text", map[string]any{"slide": str(), "id": str(), "markdown": str()}, "slide", "id", "markdown"), |
| + variant("set_phone", map[string]any{"slide": str(), "id": str(), "phone": phone}, "slide", "id", "phone"), |
| + } |
| +} |
| +func slideAgentEditableOp(name string) bool { |
| + switch name { |
| + case "set_meta", "add_slide", "remove_slide", "move_slide", "duplicate_slide", "set_slide", "set_notes", "add_block", "remove_block", "move_block", "set_block", "set_text", "set_phone": |
| + return true |
| + } |
| + return false |
| +} |
| +func (a *slideAgent) updateOperation(input func(map[string]any, ...string) json.RawMessage, sqid, revision map[string]any) access.Operation { |
| + return access.Operation{Name: "slides_update_deck", Description: "Atomically apply one to one hundred canonical semantic operations at expected_revision. Keep the same client UUID and payload on retry. The returned revision and generated IDs name the original commit; read again for current content.", Scope: "slides:write", Idempotent: true, |
| + Input: input(map[string]any{"sqid": sqid, "expected_revision": revision, "client_id": slideAgentString(36), "ops": map[string]any{"type": "array", "minItems": 1, "maxItems": 100, "items": map[string]any{"oneOf": slideAgentEditVariants()}}}, "sqid", "expected_revision", "client_id", "ops"), |
| + Output: slideAgentObject(map[string]any{"sqid": sqid, "revision": revision, "url": slideAgentString(4096), "ids": map[string]any{"type": "object", "additionalProperties": map[string]any{"type": "string"}}}, "sqid", "revision", "url", "ids"), |
| + Invoke: func(ctx context.Context, p access.Principal, raw json.RawMessage) (any, error) { |
| + var in slideAgentUpdate |
| + if err := strictjson.Unmarshal(raw, &in); err != nil { |
| + return nil, access.Fail("invalid", "Invalid semantic deck edit arguments.") |
| + } |
| + return a.update(ctx, p, slideAgentMember(ctx), in) |
| + }} |
| +} |
diff --git a/internal/slides/agent_edit_test.go b/internal/slides/agent_edit_test.go| new file mode 100644 |
| index 0000000..915b647 |
| --- /dev/null |
| +++ b/internal/slides/agent_edit_test.go |
| @@ -0,0 +1,339 @@ |
| +package slides |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "encoding/json" |
| + "fmt" |
| + "net/http/httptest" |
| + "reflect" |
| + "strconv" |
| + "strings" |
| + "sync" |
| + "testing" |
| + |
| + access "amadan.net/oficina/agent-access.git" |
| + "amadan.net/oficina/home/teammode" |
| + "amadan.net/oficina/slides/internal/slides/deck" |
| + deckrender "amadan.net/oficina/slides/internal/slides/render" |
| + "github.com/google/uuid" |
| +) |
| + |
| +func updateDeckInput(t *testing.T, f *slideAgentFixture, sqid string, ops []op) slideAgentUpdate { |
| + t.Helper() |
| + var d Deck |
| + if e := f.a.app.db.G.Where("sqid=?", sqid).Take(&d).Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + b, e := json.Marshal(ops) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + var raw []map[string]json.RawMessage |
| + if e = json.Unmarshal(b, &raw); e != nil { |
| + t.Fatal(e) |
| + } |
| + return slideAgentUpdate{Team: f.a.team, Sqid: sqid, ExpectedRevision: strconv.FormatInt(d.Seq, 10), ClientID: uuid.NewString(), Ops: raw} |
| +} |
| +func updatedDeck(t *testing.T, r *httptest.ResponseRecorder) slideAgentUpdated { |
| + t.Helper() |
| + var result slideAgentUpdated |
| + if r.Code != 200 { |
| + t.Fatal(r.Code, r.Body.String()) |
| + } |
| + if e := json.Unmarshal(r.Body.Bytes(), &result); e != nil { |
| + t.Fatal(e) |
| + } |
| + return result |
| +} |
| +func editDeckCounts(t *testing.T, f *slideAgentFixture) []int64 { |
| + t.Helper() |
| + var counts []int64 |
| + for _, name := range []string{"decks", "deck_updates", "deck_snapshots", "slides_agent_edits", "slides_connections"} { |
| + var n int64 |
| + if e := f.a.app.db.G.Table(name).Count(&n).Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + counts = append(counts, n) |
| + } |
| + return counts |
| +} |
| +func readEditedDeck(t *testing.T, f *slideAgentFixture, sqid string) (Deck, *deck.Deck, []byte) { |
| + t.Helper() |
| + var d Deck |
| + if e := f.a.app.db.G.Where("sqid=?", sqid).Take(&d).Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + h, v, e := f.a.app.openDeck(t.Context(), d) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + defer h.Close(t.Context()) |
| + raw, e := h.JSON(t.Context()) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + return d, v, raw |
| +} |
| +func TestAgentDeckEditCanonicalParityAndLaterRetry(t *testing.T) { |
| + f := newSlideAgentFixture(t) |
| + sqid := slideCreated(t, f.call(t, "slides_create_deck", initialSlideAgentInput())) |
| + _, before, _ := readEditedDeck(t, f, sqid) |
| + s := before.Slides[0] |
| + heading, body := s.Blocks[0].ID, s.Blocks[1].ID |
| + in := updateDeckInput(t, f, sqid, []op{ |
| + {"op": "set_meta", "title": "Edited title", "theme": "ink"}, |
| + {"op": "set_slide", "id": s.ID, "layout": "canvas"}, |
| + {"op": "set_notes", "id": s.ID, "markdown": "EDITED_NOTES"}, |
| + {"op": "set_text", "slide": s.ID, "id": heading, "markdown": "EDITED_HEADING"}, |
| + {"op": "set_block", "slide": s.ID, "id": heading, "z": 0.25, "box": map[string]any{"x": 0.1, "y": 0.2, "w": 0.5, "h": 0.4}}, |
| + {"op": "set_phone", "slide": s.ID, "id": heading, "phone": map[string]any{"size": "l", "hidden": false}}, |
| + {"op": "move_block", "slide": s.ID, "id": body, "after": nil}, |
| + {"op": "add_slide", "id": "newslideabcd", "layout": "flow", "template": "blank"}, |
| + {"op": "add_block", "slide": "newslideabcd", "id": "newblockabcd", "type": "text", "region": "body", "markdown": "Temporary"}, |
| + {"op": "move_slide", "id": "newslideabcd", "after": nil}, |
| + {"op": "duplicate_slide", "id": s.ID}, |
| + {"op": "remove_block", "slide": "newslideabcd", "id": "newblockabcd"}, |
| + {"op": "remove_slide", "id": "newslideabcd"}, |
| + }) |
| + events, cancel := f.a.app.live.Subscribe(sqid) |
| + defer cancel() |
| + ack := updatedDeck(t, f.call(t, "slides_update_deck", in)) |
| + if ack.IDs["10"] == "" { |
| + t.Fatal("missing duplicate ID", ack) |
| + } |
| + select { |
| + case <-events: |
| + default: |
| + t.Fatal("committed edit not published") |
| + } |
| + d, view, raw := readEditedDeck(t, f, sqid) |
| + if d.Title != "Edited title" || d.Theme != "ink" || d.Seq != 2 || len(view.Slides) != 2 || !bytes.Contains(raw, []byte(`"z":0.25`)) || !bytes.Contains(raw, []byte("EDITED_NOTES")) { |
| + t.Fatal("canonical mismatch", d, string(raw)) |
| + } |
| + html, e := deckrender.Slide(view, 0, deckrender.Desktop) |
| + if e != nil || !strings.Contains(string(html), "EDITED_HEADING") { |
| + t.Fatal("native render mismatch", e, string(html)) |
| + } |
| + get := f.call(t, "slides_get_deck", map[string]any{"team": f.a.team, "sqid": sqid}) |
| + if get.Code != 200 || !bytes.Contains(get.Body.Bytes(), []byte(`"z":0.25`)) { |
| + t.Fatal("API rounded native content", get.Body.String()) |
| + } |
| + ops, _ := opsJSON([]op{{"op": "set_notes", "id": s.ID, "markdown": "LATER_NATIVE_EDIT"}}) |
| + if e = f.a.app.editDeck(t.Context(), &d, actorFor(f.u), ops, nil, nil); e != nil { |
| + t.Fatal(e) |
| + } |
| + // Discard the native seq notification; replay itself must publish nothing. |
| + select { |
| + case <-events: |
| + default: |
| + } |
| + counts := editDeckCounts(t, f) |
| + if replay := updatedDeck(t, f.call(t, "slides_update_deck", in)); !reflect.DeepEqual(replay, ack) { |
| + t.Fatal("unstable retry", replay, ack) |
| + } |
| + if !reflect.DeepEqual(counts, editDeckCounts(t, f)) { |
| + t.Fatal("retry wrote log/receipt") |
| + } |
| + select { |
| + case <-events: |
| + t.Fatal("retry published another edit") |
| + default: |
| + } |
| + _, _, raw = readEditedDeck(t, f, sqid) |
| + if !bytes.Contains(raw, []byte("LATER_NATIVE_EDIT")) { |
| + t.Fatal("retry overwrote later edit") |
| + } |
| + stale := in |
| + stale.ClientID = uuid.NewString() |
| + if r := f.call(t, "slides_update_deck", stale); r.Code != 409 { |
| + t.Fatal("stale edit", r.Code) |
| + } |
| + mismatch := in |
| + mismatch.ExpectedRevision = "3" |
| + if r := f.call(t, "slides_update_deck", mismatch); r.Code != 409 { |
| + t.Fatal("changed retry", r.Code) |
| + } |
| +} |
| +func TestAgentDeckEditAtomicRefusals(t *testing.T) { |
| + for _, sql := range []string{ |
| + `CREATE TRIGGER edit_fail BEFORE INSERT ON slides_agent_edits BEGIN SELECT RAISE(ABORT,'receipt failure'); END`, |
| + `CREATE TRIGGER edit_fail AFTER INSERT ON slides_agent_edits BEGIN DELETE FROM home_identity_links; END`, |
| + `CREATE TRIGGER edit_fail AFTER INSERT ON slides_agent_edits BEGIN UPDATE home_identity_links SET person_binding=zeroblob(32); END`, |
| + `CREATE TRIGGER edit_fail BEFORE UPDATE OF title ON decks BEGIN SELECT RAISE(ABORT,'metadata failure'); END`, |
| + } { |
| + t.Run(sql, func(t *testing.T) { |
| + f := newSlideAgentFixture(t) |
| + sqid := slideCreated(t, f.call(t, "slides_create_deck", initialSlideAgentInput())) |
| + before, _, raw := readEditedDeck(t, f, sqid) |
| + counts := editDeckCounts(t, f) |
| + in := updateDeckInput(t, f, sqid, []op{{"op": "set_meta", "title": "Should roll back"}, {"op": "add_slide", "layout": "flow"}}) |
| + events, cancel := f.a.app.live.Subscribe(sqid) |
| + defer cancel() |
| + if e := f.a.app.db.G.Exec(sql).Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + if r := f.call(t, "slides_update_deck", in); r.Code == 200 { |
| + t.Fatal("failed write acknowledged") |
| + } |
| + after, _, got := readEditedDeck(t, f, sqid) |
| + if before.Seq != after.Seq || before.Title != after.Title || !bytes.Equal(raw, got) || !reflect.DeepEqual(counts, editDeckCounts(t, f)) { |
| + t.Fatal("atomic rollback failed") |
| + } |
| + select { |
| + case <-events: |
| + t.Fatal("rolled-back seq published") |
| + default: |
| + } |
| + if e := f.a.app.db.G.Exec("DROP TRIGGER edit_fail").Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + updatedDeck(t, f.call(t, "slides_update_deck", in)) |
| + }) |
| + } |
| +} |
| +func TestAgentDeckEditInvalidLaterOperation(t *testing.T) { |
| + f := newSlideAgentFixture(t) |
| + sqid := slideCreated(t, f.call(t, "slides_create_deck", initialSlideAgentInput())) |
| + before, _, raw := readEditedDeck(t, f, sqid) |
| + counts := editDeckCounts(t, f) |
| + in := updateDeckInput(t, f, sqid, []op{{"op": "set_meta", "title": "Partial title"}, {"op": "remove_slide", "id": "nonexistent"}}) |
| + r := f.call(t, "slides_update_deck", in) |
| + if r.Code != 422 { |
| + t.Fatal("invalid semantic batch", r.Code, r.Body.String()) |
| + } |
| + after, _, got := readEditedDeck(t, f, sqid) |
| + if before.Seq != after.Seq || !bytes.Equal(raw, got) || !reflect.DeepEqual(counts, editDeckCounts(t, f)) { |
| + t.Fatal("partial semantic batch") |
| + } |
| +} |
| +func TestAgentDeckEditConcurrency(t *testing.T) { |
| + for _, same := range []bool{true, false} { |
| + t.Run(strconv.FormatBool(same), func(t *testing.T) { |
| + f := newSlideAgentFixture(t) |
| + sqid := slideCreated(t, f.call(t, "slides_create_deck", initialSlideAgentInput())) |
| + in := updateDeckInput(t, f, sqid, []op{{"op": "add_slide", "layout": "flow"}}) |
| + var wg sync.WaitGroup |
| + codes := make(chan int, 4) |
| + for range 4 { |
| + wg.Add(1) |
| + go func() { |
| + defer wg.Done() |
| + v := in |
| + if !same { |
| + v.ClientID = uuid.NewString() |
| + } |
| + codes <- f.call(t, "slides_update_deck", v).Code |
| + }() |
| + } |
| + wg.Wait() |
| + close(codes) |
| + ok, conflict := 0, 0 |
| + for n := range codes { |
| + switch n { |
| + case 200: |
| + ok++ |
| + case 409: |
| + conflict++ |
| + default: |
| + t.Fatal(n) |
| + } |
| + } |
| + if same && ok != 4 || !same && (ok != 1 || conflict != 3) { |
| + t.Fatal(ok, conflict) |
| + } |
| + d, _, _ := readEditedDeck(t, f, sqid) |
| + if d.Seq != 2 { |
| + t.Fatal("more than one edit", d.Seq) |
| + } |
| + }) |
| + } |
| +} |
| +func TestAgentDeckEditWriterGuardsWithoutEmission(t *testing.T) { |
| + for _, retry := range []bool{false, true} { |
| + for _, phase := range []int{1, 2} { |
| + t.Run(fmt.Sprintf("retry=%v/phase=%d", retry, phase), func(t *testing.T) { |
| + f := newSlideAgentFixture(t) |
| + sqid := slideCreated(t, f.call(t, "slides_create_deck", initialSlideAgentInput())) |
| + in := updateDeckInput(t, f, sqid, []op{{"op": "add_slide", "layout": "flow"}}) |
| + if retry { |
| + updatedDeck(t, f.call(t, "slides_update_deck", in)) |
| + } |
| + if !retry && phase == 1 { |
| + if e := f.a.app.db.G.Exec(`CREATE TRIGGER trap BEFORE INSERT ON deck_updates BEGIN SELECT RAISE(ABORT,'early guard omitted'); END`).Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + u, e := f.a.member(t.Context(), f.p, true) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + n := 0 |
| + state := &slideAgentContext{member: u, slides: map[int64]bool{}, verify: func(context.Context) error { |
| + n++ |
| + if n == phase { |
| + return access.Fail("unauthenticated", "Revoked") |
| + } |
| + return nil |
| + }} |
| + counts := editDeckCounts(t, f) |
| + ctx := context.WithValue(t.Context(), slideAgentKey{}, state) |
| + _, e = f.a.update(ctx, f.p, u, in) |
| + if access.SafeFailure(e).Code != "unauthenticated" || n != phase { |
| + t.Fatal("writer guard", e, n) |
| + } |
| + if !reflect.DeepEqual(counts, editDeckCounts(t, f)) { |
| + t.Fatal("revoked edit committed") |
| + } |
| + }) |
| + } |
| + } |
| +} |
| +func TestAgentDeckEditTeamSharesAndLapse(t *testing.T) { |
| + f, af := newTeamSlideAgent(t) |
| + sqid := slideCreated(t, af.call(t, "slides_create_deck", teamSlideInput(af))) |
| + var d Deck |
| + if e := f.d.G.Where("sqid=?", sqid).Take(&d).Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + other := f.localUser("other@example.com") |
| + f.grant(d, af.u, other) |
| + in := updateDeckInput(t, af, sqid, []op{{"op": "add_slide", "layout": "flow"}}) |
| + f.dir.Set(af.p.Subject, "") |
| + f.refreshed() |
| + ack := updatedDeck(t, af.call(t, "slides_update_deck", in)) |
| + in.ClientID = uuid.NewString() |
| + in.ExpectedRevision = ack.Revision |
| + f.expired() |
| + updatedDeck(t, af.call(t, "slides_update_deck", in)) |
| + for _, retry := range []bool{false, true} { |
| + t.Run(strconv.FormatBool(retry), func(t *testing.T) { |
| + f, af := newTeamSlideAgent(t) |
| + sqid := slideCreated(t, af.call(t, "slides_create_deck", teamSlideInput(af))) |
| + in := updateDeckInput(t, af, sqid, []op{{"op": "add_slide", "layout": "flow"}}) |
| + if retry { |
| + updatedDeck(t, af.call(t, "slides_update_deck", in)) |
| + } |
| + u, e := af.a.member(t.Context(), af.p, true) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + n := 0 |
| + state := &slideAgentContext{member: u, slides: map[int64]bool{}, verify: func(context.Context) error { |
| + n++ |
| + if n == 2 { |
| + f.expired() |
| + } |
| + return nil |
| + }} |
| + ctx := teammode.WithAccess(context.WithValue(t.Context(), slideAgentKey{}, state), u.team.Access) |
| + counts := editDeckCounts(t, af) |
| + if _, e = af.a.update(ctx, af.p, u, in); e == nil { |
| + t.Fatal("expired writer accepted") |
| + } |
| + if !reflect.DeepEqual(counts, editDeckCounts(t, af)) { |
| + t.Fatal("expired edit effects") |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/slides/agent_integration_test.go b/internal/slides/agent_integration_test.go| index b577be4..c99600f 100644 |
| --- a/internal/slides/agent_integration_test.go |
| +++ b/internal/slides/agent_integration_test.go |
| @@ -138,6 +138,24 @@ func TestAgentGatewayToRealSlides(t *testing.T) { |
| if !strings.Contains(string(text), "REAL_DECK_CANARY") { |
| t.Fatal("MCP could not read created deck") |
| } |
| + |
| + edit := updateDeckInput(t, f, deck.Sqid, []op{{"op": "set_meta", "title": "CLI_EDITED_DECK"}}) |
| + rawEdit, _ := json.Marshal(edit) |
| + if _, err = cli.Call(ctx, "slides_update_deck", json.RawMessage(rawEdit)); err != nil { |
| + t.Fatal("CLI edit", err) |
| + } |
| + replayEdit, err := session.CallTool(ctx, &mcp.CallToolParams{Name: "slides_update_deck", Arguments: json.RawMessage(rawEdit)}) |
| + if err != nil || replayEdit.IsError { |
| + t.Fatal("MCP edit retry", replayEdit, err) |
| + } |
| + afterEdit, err := session.CallTool(ctx, &mcp.CallToolParams{Name: "slides_get_deck", Arguments: map[string]any{"team": "blue", "sqid": deck.Sqid}}) |
| + if err != nil || afterEdit.IsError { |
| + t.Fatal("MCP edited read", afterEdit, err) |
| + } |
| + editedText, _ := json.Marshal(afterEdit.Content) |
| + if !strings.Contains(string(editedText), "CLI_EDITED_DECK") { |
| + t.Fatal("semantic edit did not reach MCP read", string(editedText)) |
| + } |
| var count int |
| if err = f.a.app.db.G.Raw("SELECT COUNT(*) FROM decks").Scan(&count).Error; err != nil || count != 1 { |
| t.Fatal("transport retry duplicated deck", count, err) |
diff --git a/internal/slides/agent_migrations/migrations/0002_edits.sql b/internal/slides/agent_migrations/migrations/0002_edits.sql| new file mode 100644 |
| index 0000000..74e3410 |
| --- /dev/null |
| +++ b/internal/slides/agent_migrations/migrations/0002_edits.sql |
| @@ -0,0 +1,7 @@ |
| +CREATE TABLE slides_agent_edits ( |
| + coordinate TEXT PRIMARY KEY NOT NULL, |
| + content TEXT NOT NULL, |
| + deck_id INTEGER NOT NULL, |
| + revision INTEGER NOT NULL, |
| + result_sealed BLOB NOT NULL |
| +); |
diff --git a/internal/slides/agent_operations.go b/internal/slides/agent_operations.go| index c8aeb15..ff45d72 100644 |
| --- a/internal/slides/agent_operations.go |
| +++ b/internal/slides/agent_operations.go |
| @@ -52,6 +52,7 @@ func (a *slideAgent) registry() (*access.Registry, error) { |
| return a.create(ctx, p, slideAgentMember(ctx), in) |
| }}, |
| } |
| + ops = append(ops, a.updateOperation(input, sqid, revision)) |
| for i := range ops { |
| scope, invoke := ops[i].Scope, ops[i].Invoke |
| ops[i].Available = func(p access.Principal) bool { return p.Allows(a.team, scope) } |
diff --git a/internal/slides/decks.go b/internal/slides/decks.go| index 277f981..68c6cec 100644 |
| --- a/internal/slides/decks.go |
| +++ b/internal/slides/decks.go |
| @@ -200,12 +200,17 @@ func (a *app) visibleDecksOn(db *gorm.DB, viewer User) *gorm.DB { |
| // deck with none, or one whose snapshot row could not be read, opens |
| // from the plain log and is exactly the same deck, only slower. |
| func (a *app) openDeck(ctx context.Context, d Deck) (*core.Handle, *deck.Deck, error) { |
| + return a.openDeckOn(ctx, a.db.G, d) |
| +} |
| + |
| +// openDeckOn reads every snapshot and log page on the caller's connection. |
| +func (a *app) openDeckOn(ctx context.Context, db *gorm.DB, d Deck) (*core.Handle, *deck.Deck, error) { |
| h, err := a.core.NewDoc(ctx, d.Sqid, serverClientID) |
| if err != nil { |
| return nil, nil, fmt.Errorf("slides: open deck %s: %w", d.Sqid, err) |
| } |
| - snap, updates, err := a.replayPlan(ctx, d) |
| + snap, updates, err := a.replayPlanOn(ctx, db, d) |
| if err != nil { |
| h.Close(ctx) |
| return nil, nil, err |
| @@ -225,7 +230,7 @@ func (a *app) openDeck(ctx context.Context, d Deck) (*core.Handle, *deck.Deck, e |
| } |
| since = 0 |
| retained = 0 |
| - updates, err = a.replayLog(ctx, d, 0) |
| + updates, err = replayLogOn(ctx, db, d, 0) |
| if err != nil { |
| h.Close(ctx) |
| return nil, nil, err |
| @@ -262,7 +267,7 @@ func (a *app) openDeck(ctx context.Context, d Deck) (*core.Handle, *deck.Deck, e |
| since = u.Seq |
| retained++ |
| } |
| - updates, err = a.replayLog(ctx, d, since) |
| + updates, err = replayLogOn(ctx, db, d, since) |
| if err != nil { |
| h.Close(ctx) |
| return nil, nil, err |
diff --git a/internal/slides/snapshot.go b/internal/slides/snapshot.go| index 04cd3df..1b71165 100644 |
| --- a/internal/slides/snapshot.go |
| +++ b/internal/slides/snapshot.go |
| @@ -44,8 +44,11 @@ const replayCheckpointCadence = core.MaxRetainedUpdates / 2 |
| // the tie resolves to the last row written rather than being treated as |
| // an error worth reporting. |
| func (a *app) latestSnapshot(ctx context.Context, deckID int64) (*DeckSnapshot, error) { |
| + return latestSnapshotOn(ctx, a.db.G, deckID) |
| +} |
| +func latestSnapshotOn(ctx context.Context, db *gorm.DB, deckID int64) (*DeckSnapshot, error) { |
| var row DeckSnapshot |
| - err := a.db.G.WithContext(ctx). |
| + err := db.WithContext(ctx). |
| Where("deck_id = ?", deckID). |
| Order("seq DESC, id DESC"). |
| Take(&row).Error |
| @@ -71,7 +74,10 @@ func (a *app) latestSnapshot(ctx context.Context, deckID int64) (*DeckSnapshot, |
| // as "no snapshot" plus a log line, and the deck opens slowly rather |
| // than not at all. |
| func (a *app) replayPlan(ctx context.Context, d Deck) (*DeckSnapshot, []DeckUpdate, error) { |
| - snap, err := a.latestSnapshot(ctx, d.ID) |
| + return a.replayPlanOn(ctx, a.db.G, d) |
| +} |
| +func (a *app) replayPlanOn(ctx context.Context, db *gorm.DB, d Deck) (*DeckSnapshot, []DeckUpdate, error) { |
| + snap, err := latestSnapshotOn(ctx, db, d.ID) |
| if err != nil { |
| a.logger.Error("slides: read a deck's newest snapshot, replaying the plain log instead", |
| "deck", d.Sqid, "err", err) |
| @@ -85,13 +91,16 @@ func (a *app) replayPlan(ctx context.Context, d Deck) (*DeckSnapshot, []DeckUpda |
| if snap != nil { |
| since = snap.Seq |
| } |
| - updates, err := a.replayLog(ctx, d, since) |
| + updates, err := replayLogOn(ctx, db, d, since) |
| return snap, updates, err |
| } |
| func (a *app) replayLog(ctx context.Context, d Deck, since int64) ([]DeckUpdate, error) { |
| + return replayLogOn(ctx, a.db.G, d, since) |
| +} |
| +func replayLogOn(ctx context.Context, db *gorm.DB, d Deck, since int64) ([]DeckUpdate, error) { |
| var updates []DeckUpdate |
| - if err := a.db.G.WithContext(ctx). |
| + if err := db.WithContext(ctx). |
| Where("deck_id = ? AND seq > ? AND seq <= ?", d.ID, since, d.Seq). |
| Order("seq").Limit(replayBatchSize).Find(&updates).Error; err != nil { |
| return nil, fmt.Errorf("slides: read deck %s log: %w", d.Sqid, err) |
diff --git a/internal/slides/team_guard_test.go b/internal/slides/team_guard_test.go| index 834bdd2..7912d1f 100644 |
| --- a/internal/slides/team_guard_test.go |
| +++ b/internal/slides/team_guard_test.go |
| @@ -132,6 +132,7 @@ func (f *teamFixture) snapshot(d Deck) teamSnapshot { |
| // survived (Fable's #53 required test 2, for Slides: the database is |
| // read back, not just the status). |
| func TestTeamEveryWriteRouteRefusesALapseBeforeCommit(t *testing.T) { |
| + t.Run("delegated deck edit", testAgentDeckEditGuardLapse) |
| f := newTeamFixture(t) |
| store, err := blobs.Dir(t.TempDir()) |
| if err != nil { |