Stop committing credentials; fix posting length, partial posts, and data safety
- Untrack config.yaml (now gitignored) and add config.example.yaml with blank credentials; install.sh copies the example and sets mode 600 - Reserve room for the appended source link when asking Claude for a post, count length the way X does, and refuse over-length tweets before posting - Return https://x.com/i/status/<id> for posted tweets - Track which platforms each queued post reached so a partial failure can be retried without double-posting - Write config, state, posts and dismissed files atomically with 0600 - Keep refreshed Twitter tokens in memory if saving them fails, and log the failure instead of writing to the hidden stderr - Exit with a clear message on corrupt data files instead of panicking - Surface save errors in the UI; show status/error messages on home - Add tests for X length counting, the post store, and token updates Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"coremarketing/internal/fileutil"
|
||||
"coremarketing/internal/models"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
@@ -148,7 +149,7 @@ func UpdateOAuth2Tokens(path, accessToken, refreshToken string) error {
|
||||
updated = oauth2RefreshTokenRe.ReplaceAllLiteralString(updated, `oauth2_refresh_token: "`+refreshToken+`"`)
|
||||
}
|
||||
|
||||
return os.WriteFile(path, []byte(updated), 0600)
|
||||
return fileutil.WriteFileAtomic(path, []byte(updated), 0600)
|
||||
}
|
||||
|
||||
// UpdateLinkedInCredentials rewrites the access_token and author_urn values
|
||||
@@ -188,5 +189,5 @@ func UpdateLinkedInCredentials(path, accessToken, authorURN string) error {
|
||||
if !tokenDone || !urnDone {
|
||||
return fmt.Errorf("linkedin credentials fields not found in %s", path)
|
||||
}
|
||||
return os.WriteFile(path, []byte(strings.Join(result, "\n")), 0600)
|
||||
return fileutil.WriteFileAtomic(path, []byte(strings.Join(result, "\n")), 0600)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const sample = `credentials:
|
||||
twitter:
|
||||
oauth2_access_token: "old-access"
|
||||
oauth2_refresh_token: "old-refresh"
|
||||
linkedin:
|
||||
access_token: ""
|
||||
author_urn: ""
|
||||
`
|
||||
|
||||
func TestUpdateTokensDoesNotTouchOtherSections(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "config.yaml")
|
||||
if err := os.WriteFile(path, []byte(sample), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := UpdateOAuth2Tokens(path, "new-access", "new-refresh"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := UpdateLinkedInCredentials(path, "li-token", "urn:li:person:1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, _ := os.ReadFile(path)
|
||||
got := string(data)
|
||||
for _, want := range []string{
|
||||
`oauth2_access_token: "new-access"`,
|
||||
`oauth2_refresh_token: "new-refresh"`,
|
||||
` access_token: "li-token"`,
|
||||
`author_urn: "urn:li:person:1"`,
|
||||
} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Errorf("missing %q in:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user