Files
davidandClaude Opus 5.5 13bf18facc Phase 1, part 1: fetch, write and publish posts from the web app
Brings back posting, which Phase 0 removed with the terminal interface.

- Content page: per inventory entry, fetch its X account, X hashtag
  search, YouTube channel and RSS/Atom feeds (new), then select, dismiss
  or restore the fetched items, which are kept in the database.
- Writing: one AI call returns a draft per channel (X and LinkedIn),
  prompted from the company profile, the entry's relationship, talking
  points and mention policy, and each channel's rules. Fetched text is
  quoted as untrusted. An over-long X draft gets one request to shorten.
- Drafts page: edit with a live length counter that counts like X, then
  publish each draft on its own. A draft is claimed before posting so it
  can't go out twice; failures are kept on the draft for a retry; X
  tokens are refreshed and saved.
- Migration 2 adds content_items and drafts, and turns queued posts into
  drafts for the platforms they hadn't reached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 12:58:24 -07:00

69 lines
1.9 KiB
Go

package db
import (
"database/sql"
"path/filepath"
"testing"
)
// A database from Phase 0 (schema 1) keeps its queued posts as drafts for
// the platforms they hadn't reached.
func TestMigratePostsToDrafts(t *testing.T) {
path := filepath.Join(t.TempDir(), "app.db")
old, err := sql.Open("sqlite", "file:"+path)
if err != nil {
t.Fatal(err)
}
for _, q := range []string{
migrations[0],
`PRAGMA user_version = 1`,
`INSERT INTO inventory (name, relationship, data) VALUES ('Jitsi', 'competitor', '{}')`,
`INSERT INTO posts (id, inventory_name, content, source_url, generated_at, posted_to) VALUES
('a', 'Jitsi', 'Posted to X only', 'https://x.com/1', '2026-11-01T10:00:00Z', '["x"]'),
('b', 'Nextcloud', 'Not posted', '', '2026-11-02T10:00:00Z', '[]'),
('c', 'Nextcloud', 'Posted everywhere', '', '2026-11-03T10:00:00Z', '["x","linkedin"]')`,
} {
if _, err := old.Exec(q); err != nil {
t.Fatal(err)
}
}
old.Close()
d, err := Open(path)
if err != nil {
t.Fatal(err)
}
defer d.Close()
rows, err := d.Query(`SELECT batch, inventory_name, kind, channel, content, status FROM drafts ORDER BY batch, channel`)
if err != nil {
t.Fatal(err)
}
defer rows.Close()
var got []string
for rows.Next() {
var batch, name, kind, channel, content, status string
if err := rows.Scan(&batch, &name, &kind, &channel, &content, &status); err != nil {
t.Fatal(err)
}
got = append(got, batch+" "+name+" "+kind+" "+channel+" "+status)
}
want := []string{
"a Jitsi competitor linkedin draft",
"b Nextcloud partner linkedin draft",
"b Nextcloud partner x draft",
}
if len(got) != len(want) {
t.Fatalf("drafts = %q, want %q", got, want)
}
for i := range want {
if got[i] != want[i] {
t.Errorf("draft %d = %q, want %q", i, got[i], want[i])
}
}
var n int
if err := d.QueryRow(`SELECT count(*) FROM sqlite_master WHERE name = 'posts'`).Scan(&n); err != nil || n != 0 {
t.Errorf("posts table still there (%d, %v)", n, err)
}
}