Imports and agents make one-line titles too
Fable's delta on #179 (nit): CreateImported and the agent's docs_create stored a title as sent, newlines included. Both clean it with cleanTitle, as a rename and a new document already do; an import's title that cleans to nothing is left as given, and the agent's retry digest keeps the title as sent. TestImportsAndAgentsMakeOneLineTitles fails without it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+48
−3
internal/docs/agent_store.go+5 −3internal/docs/import.go+5 −0internal/docs/title_paths_test.go+38 −0
diff --git a/internal/docs/agent_store.go b/internal/docs/agent_store.go| index d3759e9..3860169 100644 |
| --- a/internal/docs/agent_store.go |
| +++ b/internal/docs/agent_store.go |
| @@ -9,7 +9,6 @@ import ( |
| "encoding/json" |
| "errors" |
| "strconv" |
| - "strings" |
| "time" |
| "unicode/utf8" |
| @@ -277,7 +276,10 @@ func (a *documentAgent) checkCreator(ctx context.Context, tx *gorm.DB, p access. |
| } |
| func (a *documentAgent) create(ctx context.Context, p access.Principal, id requestIdentity, input agentCreateInput) (any, error) { |
| u, err := uuid.Parse(input.ClientID) |
| - if err != nil || u == uuid.Nil || u.String() != input.ClientID || !utf8.ValidString(input.Title) || strings.TrimSpace(input.Title) == "" || len(input.Title) > 512 || len(input.Blocks) > 200 { |
| + // The title is made one line (handlers.go's cleanTitle) before it is |
| + // checked or stored; the retry digest below keeps the title as sent. |
| + title := cleanTitle(input.Title) |
| + if err != nil || u == uuid.Nil || u.String() != input.ClientID || !utf8.ValidString(input.Title) || title == "" || len(input.Title) > 512 || len(input.Blocks) > 200 { |
| return nil, access.Fail("invalid", "Invalid title, client UUID or initial content.") |
| } |
| blocks := make([]core.InitialBlock, len(input.Blocks)) |
| @@ -323,7 +325,7 @@ func (a *documentAgent) create(ctx context.Context, p access.Principal, id reque |
| return e |
| } |
| store := a.store.boundTo(tx) |
| - created, e := store.CreateDraft(ctx, id.Actor.PersonID, input.Title, "") |
| + created, e := store.CreateDraft(ctx, id.Actor.PersonID, title, "") |
| if e != nil { |
| return e |
| } |
diff --git a/internal/docs/import.go b/internal/docs/import.go| index 6a45c3f..14fd7a6 100644 |
| --- a/internal/docs/import.go |
| +++ b/internal/docs/import.go |
| @@ -189,6 +189,11 @@ func canonicalBlocks(blocks []core.BuildBlock) []string { |
| // returns that document and writes nothing, so a retried submission |
| // after a lost answer cannot import twice. |
| func (s *Store) CreateImported(ctx context.Context, owner int64, title, token string, imp *imported) (*Document, error) { |
| + // One line, as every title is (handlers.go's cleanTitle); a title that |
| + // cleans to nothing is left as the caller gave it. |
| + if c := cleanTitle(title); c != "" { |
| + title = c |
| + } |
| if s.content == nil { |
| return nil, errImportUnsealed |
| } |
diff --git a/internal/docs/title_paths_test.go b/internal/docs/title_paths_test.go| new file mode 100644 |
| index 0000000..72e37ce |
| --- /dev/null |
| +++ b/internal/docs/title_paths_test.go |
| @@ -0,0 +1,38 @@ |
| +package docs |
| + |
| +import ( |
| + "context" |
| + "testing" |
| +) |
| + |
| +// Every way a document is made keeps its title one line (cleanTitle): an |
| +// import and an agent's create, as a rename and a new document already do |
| +// (Fable's delta on #179). |
| +func TestImportsAndAgentsMakeOneLineTitles(t *testing.T) { |
| + app, _ := sealedApp(t, Config{}) |
| + owner := app.TestPerson(t, "owner@example.com") |
| + ctx := context.Background() |
| + imp, err := convertImport(ctx, app.store.core, nestedDoc(t)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + doc, err := app.store.CreateImported(ctx, owner, "Board\nminutes\t\x07draft", "title-paths", imp) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if doc.Title != "Board minutes draft" { |
| + t.Errorf("an import kept its title as %q", doc.Title) |
| + } |
| + |
| + f := newDocAgentFixture(t) |
| + in := initialAgentInput() |
| + in.Title = "Agent\r\nnotes here" |
| + body := decodeAgentBody(t, f.call(t, "docs_create", in)) |
| + var made Document |
| + if err := f.a.store.db.Where("sqid=?", body.ID).First(&made).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| + if made.Title != "Agent notes here" { |
| + t.Errorf("an agent's create kept its title as %q", made.Title) |
| + } |
| +} |