Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
217e1e2
fix(site): invalidate old page cache keys on rename
qwqcode Nov 14, 2026
f1398dc
fix(page): scope comment moves to the renamed page site
qwqcode Nov 14, 2026
70b217d
fix(transfer): preserve per-site page metadata in exports
qwqcode Nov 14, 2026
8f3f9f1
test(auth): cover password login and profile access
qwqcode Nov 14, 2026
bb54518
test(config): cover public and admin configuration views
qwqcode Nov 14, 2026
92d2419
test(moderation): cover reply notifications after approval
qwqcode Nov 14, 2026
cdd4618
fix(cache): keep persisted data visible when an update fails
qwqcode Nov 14, 2026
b8f79c6
test(stats): verify page views and comment counts stay within each site
qwqcode Nov 14, 2026
2df95d7
test(notify): cover reply delivery and recipient preferences
qwqcode Nov 14, 2026
12b46a0
test(upload): cover image validation and storage
qwqcode Nov 15, 2026
28c5d89
test(cache): verify warm-up and flush against persisted data
qwqcode Nov 15, 2026
d243281
test(config): cover metadata generator output formats
qwqcode Nov 15, 2026
bc60574
test(i18n): cover extracting and updating translation keys
qwqcode Nov 15, 2026
162f13a
test(cli): cover setup, admin password rotation and data transfer
qwqcode Nov 15, 2026
1bf4a6c
fix(config): validate settings before replacing the config file
qwqcode Nov 15, 2026
7a6e224
test(users): cover administrative account lifecycle
qwqcode Nov 15, 2026
dd54e7c
test(auth): exercise social login through a local OAuth provider
qwqcode Nov 15, 2026
cad63be
test(migrations): verify root IDs for existing comment threads
qwqcode Nov 15, 2026
be4fb34
test(transfer): cover upload, import and export through the admin API
qwqcode Nov 15, 2026
a74cdab
test(auth): cover moving account data during profile merge
qwqcode Nov 15, 2026
e6fb701
test(captcha): cover verification provider request and result contracts
qwqcode Nov 15, 2026
1beb67e
test(moderation): cover cloud provider request and result contracts
qwqcode Nov 15, 2026
3f6892d
test(moderation): verify provider decisions reach stored comments
qwqcode Nov 15, 2026
df5c595
test(notify): cover pending comment delivery to admin webhooks
qwqcode Nov 15, 2026
e327f1b
test(auth): verify registration and password reset by email
qwqcode Nov 15, 2026
058b76e
test(comments): verify moderation deletion removes associated data
qwqcode Nov 15, 2026
64c988f
test(votes): verify counters can be rebuilt from stored votes
qwqcode Nov 15, 2026
fea88c3
test(upload): verify external upload results and local file cleanup
qwqcode Nov 15, 2026
eaaadef
test(hooks): cover ordering, removal and propagation
qwqcode Nov 15, 2026
0c7f97e
test(notify): verify Lark and Bark notification payloads
qwqcode Nov 15, 2026
589788b
test(config): verify compatibility with legacy configuration files
qwqcode Nov 15, 2026
b0e7a4b
fix(db): keep root comments consistent in legacy migrations
qwqcode Nov 15, 2026
ca75941
fix(db): preserve page identities and roll back failed deduplication
qwqcode Nov 15, 2026
ffe2e4d
test(email): verify SMTP delivery and notification email state
qwqcode Nov 15, 2026
d915ee5
fix(moderation): send approval notifications after saving comments
qwqcode Nov 15, 2026
5c0429c
fix(email): reject unsuccessful Aliyun delivery responses
qwqcode Nov 15, 2026
d43f429
fix(comments): reject replies to comments from another site
qwqcode Nov 15, 2026
08d67de
fix(email): synchronize queue shutdown with new messages
qwqcode Nov 15, 2026
65f0d77
fix(comments): handle author and page storage errors when editing
qwqcode Nov 15, 2026
94dc18b
fix(auth): report failures when persisting OAuth sessions
qwqcode Nov 15, 2026
48b57de
test(config): cover repeated site and administrator synchronization
qwqcode Nov 15, 2026
3b7ae3f
test(transfer): verify failed imports roll back all related records
qwqcode Nov 15, 2026
89d6cbc
test(cli): cover informational commands and first-run configuration
qwqcode Nov 15, 2026
a1c7aa1
test(db): verify query logging levels and request context
qwqcode Nov 15, 2026
46d813f
test(auth): cover provider registration and SSO failure handling
qwqcode Nov 15, 2026
397cf13
fix(cache): report invalid configuration without exiting the process
qwqcode Nov 15, 2026
a534bdb
fix(email): clean up sendmail processes after delivery failures
qwqcode Nov 15, 2026
f243fce
test(api): cover management validation and configuration helpers
qwqcode Nov 15, 2026
fbf65e1
fix(api): reject null and malformed request parameters consistently
qwqcode Nov 15, 2026
8dc922d
fix(auth): roll back account data merges and refresh cached ownership
qwqcode Nov 15, 2026
5c03ad8
fix(notify): handle root comments without a parent
qwqcode Nov 15, 2026
091e04b
test(pages): verify deletion failures and site isolation
qwqcode Nov 15, 2026
c20094e
test(auth): verify email challenge validation and storage failures
qwqcode Nov 15, 2026
7516cd4
test(captcha): verify rejected image challenges cannot grant access
qwqcode Nov 15, 2026
6052581
test(cli): preserve generated templates and verify release build iden…
qwqcode Nov 15, 2026
29a9c11
fix(cli): handle missing releases during forced upgrades
qwqcode Nov 15, 2026
e80deaf
test(db): run legacy migrations against optional external databases
qwqcode Nov 15, 2026
52694d9
fix(transfer): preserve reply links and dates when rows are skipped
qwqcode Nov 15, 2026
9a8899e
fix(notify): handle single-line Lark cards without panicking
qwqcode Nov 15, 2026
8e51ecf
test(db): cover invalid connection settings and prepared statements
qwqcode Nov 15, 2026
60c74e2
test(captcha): verify configured providers through the shared factory
qwqcode Nov 15, 2026
3067992
fix(notify): report failures when marking notifications read
qwqcode Nov 15, 2026
c7528c9
test(auth): verify social identity rotation and account cleanup
qwqcode Nov 15, 2026
e482746
test(upload): cover unwritable storage and missing files
qwqcode Nov 15, 2026
81ad1d6
test(vote): verify storage failures preserve votes and counters
qwqcode Nov 15, 2026
29abcad
fix(profile): preserve HTTPS when normalizing personal links
qwqcode Nov 15, 2026
6c56eb0
test(auth): cover incomplete social profiles and failed registration
qwqcode Nov 15, 2026
e0dd501
test(users): cover invalid updates and failed account writes
qwqcode Nov 15, 2026
3c2b407
test(config): preserve documentation with invalid generated markers
qwqcode Nov 15, 2026
a25f0f2
test(auth): preserve provider profile fallback behavior
qwqcode Nov 15, 2026
81bb7ae
test(comments): keep comments available without IP region data
qwqcode Nov 15, 2026
b3614a7
test(transfer): report unavailable upload storage
qwqcode Nov 15, 2026
fb131cb
test(vote): refresh cached counters after voting
qwqcode Nov 15, 2026
c738118
test(vote): reject invalid requests and failed voter writes
qwqcode Nov 15, 2026
343ce2b
fix(db): preserve votes and deleted records during page deduplication
qwqcode Nov 15, 2026
0177bf0
fix(api): preserve existing request format handling
qwqcode Nov 15, 2026
012a5b5
test(auth): assert template fallbacks and SSO display names
qwqcode Nov 15, 2026
c81f1df
test(backend): simplify assertions and bound notification fixtures
qwqcode Nov 15, 2026
d9708d9
ci: measure full backend coverage and test legacy migrations
qwqcode Nov 15, 2026
0f2f2ac
test(db): make legacy migration fixtures portable
qwqcode Nov 15, 2026
bc98057
fix(comments): match reply sites using database identity
qwqcode Nov 15, 2026
fbb7a48
fix(comments): preserve legacy authors when editing
qwqcode Nov 15, 2026
4568c4e
fix(api): preserve null parameter compatibility
qwqcode Nov 15, 2026
40af61a
fix(email): unblock queue shutdown during stalled delivery
qwqcode Nov 15, 2026
8dd73c9
fix(import): preserve replies when ancestors are skipped
qwqcode Nov 15, 2026
a5a4201
fix(auth): limit cache invalidation during account merges
qwqcode Nov 15, 2026
0647084
fix(moderation): keep approvals and notifications consistent
qwqcode Nov 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/test-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ jobs:
env:
ARTALK_TEST_DB_TYPE: pgsql
ARTALK_TEST_DB_DSN: host=127.0.0.1 port=5432 user=postgres password=ArtalkTestOnly123 dbname=artalk_test sslmode=disable
run: go test ./server/handler -run '^TestDatabaseCompatibility$' -count=1 -v
run: go test ./internal/dao ./server/handler -run '^(TestDatabaseCompatibility|TestMigrateRootIDsForExistingThreads|TestMergeLegacyPages)$' -count=1 -v
- name: MySQL
if: ${{ !cancelled() }}
env:
ARTALK_TEST_DB_TYPE: mysql
ARTALK_TEST_DB_DSN: root:ArtalkTestOnly123@tcp(127.0.0.1:3306)/artalk_test?charset=utf8mb4&parseTime=True&loc=UTC
run: go test ./server/handler -run '^TestDatabaseCompatibility$' -count=1 -v
run: go test ./internal/dao ./server/handler -run '^(TestDatabaseCompatibility|TestMigrateRootIDsForExistingThreads|TestMergeLegacyPages)$' -count=1 -v
- name: SQL Server
if: ${{ !cancelled() }}
env:
ARTALK_TEST_DB_TYPE: mssql
ARTALK_TEST_DB_DSN: sqlserver://sa:ArtalkTestOnly123@127.0.0.1:1433?database=master&encrypt=disable
run: go test ./server/handler -run '^TestDatabaseCompatibility$' -count=1 -v
run: go test ./internal/dao ./server/handler -run '^(TestDatabaseCompatibility|TestMigrateRootIDsForExistingThreads|TestMergeLegacyPages)$' -count=1 -v

test_app:
name: Test Go (${{ matrix.name }})
Expand Down Expand Up @@ -161,7 +161,7 @@ jobs:
gotestsum \
--junitfile "$REPORT_DIR/unit-tests.xml" \
--jsonfile "$REPORT_DIR/unit-tests.json" \
-- -coverprofile="$REPORT_DIR/coverage.out" ./...
-- -count=1 -coverpkg=./... -coverprofile="$REPORT_DIR/coverage.out" ./...

- name: Upload test results
if: ${{ !cancelled() }}
Expand Down
41 changes: 41 additions & 0 deletions cmd/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/adrg/xdg"
"github.com/artalkjs/artalk/v2/internal/pkged"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -70,3 +71,43 @@ func TestResolveConfigFileWithExplicitPaths(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "custom.yml", cfgFile)
}

func TestLaunchReadOnlyCommands(t *testing.T) {
dir := t.TempDir()
t.Chdir(dir)
previousArgs := os.Args
t.Cleanup(func() { os.Args = previousArgs })
cfg := filepath.Join(dir, "artalk.yml")
require.NoError(t, os.WriteFile(cfg, []byte("site_default: CLI fixture\ntimezone: Local\n"), 0600))
for _, args := range [][]string{nil, {"version"}, {"--version"}, {"config"}, {"unknown-command"}} {
os.Args = append([]string{"artalk", "--workdir", dir, "--config", cfg}, args...)
app := New()
app.RootCmd.SetArgs(os.Args[1:])
require.NoError(t, app.Launch())
require.Nil(t, app.App, "informational commands should not start a database")
}
}

func TestDefaultDataDirectoryAndConfigGeneration(t *testing.T) {
root, err := filepath.Abs("..")
require.NoError(t, err)
oldFS := pkged.FS()
t.Cleanup(func() { pkged.SetFS(oldFS) })
pkged.SetFS(os.DirFS(root))
originalDataHome, originalConfigHome := xdg.DataHome, xdg.ConfigHome
t.Cleanup(func() { xdg.DataHome = originalDataHome; xdg.ConfigHome = originalConfigHome })
xdg.DataHome = t.TempDir()
xdg.ConfigHome = t.TempDir()
t.Chdir(t.TempDir())
workdir, err := initDataDir("")
require.NoError(t, err)
require.Equal(t, filepath.Join(xdg.DataHome, "artalk"), workdir)
conf, err := getConfig("")
require.NoError(t, err)
require.NotEmpty(t, conf.AppKey)
again, err := getConfig("")
require.NoError(t, err)
require.Equal(t, conf.AppKey, again.AppKey, "do not regenerate an existing signing key")
_, err = initDataDir(filepath.Join(t.TempDir(), "missing"))
require.ErrorContains(t, err, "working directory change error")
}
6 changes: 5 additions & 1 deletion cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ func NewUpgradeCommand() *cobra.Command {
if err != nil {
log.Fatal("Error occurred while detecting version: ", err)
}
if !found {
log.Info("No compatible release found")
return
}

ignoreVersionCheck, _ := cmd.Flags().GetBool("force")
if !ignoreVersionCheck {
v := semver.MustParse(strings.TrimPrefix(config.Version, "v"))
if !found || latest.Version.LTE(v) {
if latest.Version.LTE(v) {
log.Info(i18n.T("Current version is the latest") + " (v" + v.String() + ")")
return
}
Expand Down
47 changes: 47 additions & 0 deletions cmd/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cmd

import (
"fmt"
"io"
"net/http"
"runtime"
"strings"
"testing"

"github.com/artalkjs/artalk/v2/internal/config"
"github.com/stretchr/testify/require"
)

type updateTransport func(*http.Request) (*http.Response, error)

func (f updateTransport) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) }

func TestUpgradeWithoutApplicableRelease(t *testing.T) {
previous := http.DefaultTransport
t.Cleanup(func() { http.DefaultTransport = previous })
for _, tc := range []struct {
name, body string
force bool
}{
{"empty release list", "[]", false},
{"force with no compatible release", "[]", true},
{"current release", fmt.Sprintf(`[{"tag_name":%q,"assets":[{"id":1,"name":%q,"browser_download_url":"https://fixture.invalid/never-download"}]}]`, config.Version, "artalk_"+runtime.GOOS+"_"+runtime.GOARCH+".tar.gz"), false},
} {
t.Run(tc.name, func(t *testing.T) {
calls := 0
http.DefaultTransport = updateTransport(func(r *http.Request) (*http.Response, error) {
calls++
require.Equal(t, "https://api.github.com/repos/ArtalkJS/Artalk/releases", r.URL.String())
return &http.Response{StatusCode: 200, Header: make(http.Header), Body: io.NopCloser(strings.NewReader(tc.body)), Request: r}, nil
})
command := NewUpgradeCommand()
if tc.force {
command.SetArgs([]string{"--force"})
} else {
command.SetArgs([]string{})
}
require.NoError(t, command.Execute())
require.Equal(t, 1, calls, "no binary download should occur")
})
}
}
100 changes: 100 additions & 0 deletions cmd/workflow_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package cmd

import (
"encoding/json"
"os"
"path/filepath"
"testing"

"github.com/artalkjs/artalk/v2/internal/config"
"github.com/artalkjs/artalk/v2/internal/entity"
"github.com/artalkjs/artalk/v2/internal/pkged"
"github.com/stretchr/testify/require"
)

func TestCLISetupAndDataTransfer(t *testing.T) {
repo, err := filepath.Abs("..")
require.NoError(t, err)
oldFS := pkged.FS()
t.Cleanup(func() { pkged.SetFS(oldFS) })
pkged.SetFS(os.DirFS(repo))
t.Setenv("ATK_LOCALE", "en")

dir := t.TempDir()
t.Chdir(dir)
configPath := filepath.Join(dir, "artalk.yml")
previousArgs := os.Args
t.Cleanup(func() { os.Args = previousArgs })

run := func(check func(*ArtalkCmd), args ...string) {
t.Helper()
os.Args = append([]string{"artalk", "-w", dir, "-c", configPath}, args...)
app := New()
app.mountCommands()
app.RootCmd.SetArgs(os.Args[1:])
require.NoError(t, app.RootCmd.Execute())
if app.App != nil {
defer func() { require.NoError(t, app.App.ResetBootstrapState()) }()
}
if check != nil {
check(app)
}
}

t.Run("generate configuration", func(t *testing.T) {
run(func(app *ArtalkCmd) {
require.Nil(t, app.App, "config generation can run without a database")
}, "gen", "config", dir)
conf, err := config.NewFromFile(configPath)
require.NoError(t, err)
require.NotEmpty(t, conf.AppKey)
})

// Use a disposable SQLite database for the full-boot commands.
const cfg = "app_key: cli-test\ntimezone: Local\nsite_default: CLI Site\ndb:\n type: sqlite\n file: cli.db\n"
require.NoError(t, os.WriteFile(configPath, []byte(cfg), 0600))

t.Run("create and rotate administrator password", func(t *testing.T) {
var id uint
admin := []string{"admin", "--name", "Operator", "--email", "operator@example.org"}
run(func(app *ArtalkCmd) {
user := app.Dao().FindUser("Operator", "operator@example.org")
require.True(t, user.IsAdmin)
require.True(t, user.CheckPassword("original-password"))
id = user.ID
}, append(admin, "--password", "original-password")...)
run(func(app *ArtalkCmd) {
user := app.Dao().FindUser("Operator", "operator@example.org")
require.Equal(t, id, user.ID)
require.True(t, user.CheckPassword("new-password"))
require.False(t, user.CheckPassword("original-password"))
}, append(admin, "--password", "new-password")...)
})

t.Run("import and export", func(t *testing.T) {
input := filepath.Join(dir, "comments.artrans")
const comments = `[{
"id":"1","rid":"0","content":"Imported reply",
"nick":"Reader","email":"reader@example.org",
"page_key":"/imported","site_name":"CLI Site"
}]`
require.NoError(t, os.WriteFile(input, []byte(comments), 0600))
run(func(app *ArtalkCmd) {
require.NotZero(t, app.Dao().FindPage("/imported", "CLI Site").ID)
}, "import", "-y", input)

output := t.TempDir()
run(nil, "export", output)
files, err := filepath.Glob(filepath.Join(output, "backup-*.artrans"))
require.NoError(t, err)
require.Len(t, files, 1)
body, err := os.ReadFile(files[0])
require.NoError(t, err)
var exported []entity.Artran
require.NoError(t, json.Unmarshal(body, &exported))
require.Len(t, exported, 1)
require.Equal(t, "Imported reply", exported[0].Content)
require.Equal(t, "/imported", exported[0].PageKey)
require.Equal(t, "CLI Site", exported[0].SiteName)
})
}
13 changes: 9 additions & 4 deletions internal/artransfer/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@ func exportArtrans(db *gorm.DB, params *ExportParams) (string, error) {
return string(jsonByte), nil
}

type exportPageKey struct {
site, key string
}

type exportCache struct {
Users map[uint]entity.User
Pages map[string]entity.Page
Pages map[exportPageKey]entity.Page
Sites map[string]entity.Site
}

func newExportCache() *exportCache {
return &exportCache{
Users: map[uint]entity.User{},
Pages: map[string]entity.Page{},
Pages: map[exportPageKey]entity.Page{},
Sites: map[string]entity.Site{},
}
}
Expand All @@ -58,10 +62,11 @@ func commentToArtran(db *gorm.DB, c *entity.Comment, cache *exportCache) entity.
cache.Users[c.UserID] = user
}

page, pageHit := cache.Pages[c.PageKey]
pageKey := exportPageKey{site: c.SiteName, key: c.PageKey}
page, pageHit := cache.Pages[pageKey]
if !pageHit {
db.Where(&entity.Page{SiteName: c.SiteName, Key: c.PageKey}).First(&page)
cache.Pages[c.PageKey] = page
cache.Pages[pageKey] = page
}

site, siteHit := cache.Sites[c.SiteName]
Expand Down
38 changes: 38 additions & 0 deletions internal/artransfer/exporter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package artransfer

import (
"encoding/json"
"testing"

"github.com/artalkjs/artalk/v2/internal/entity"
"github.com/artalkjs/artalk/v2/test"
"github.com/stretchr/testify/require"
)

func TestExportPreservesPageMetadataAcrossSites(t *testing.T) {
app, err := test.NewTestApp()
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, app.Cleanup()) })
const key = "/shared-export-page"

for _, site := range []string{"Site A", "Site B"} {
page := app.Dao().FindCreatePage(key, "", site)
require.NotZero(t, page.ID)
page.Title = "Page on " + site
require.NoError(t, app.Dao().UpdatePage(&page))
comment := entity.Comment{Content: "Comment on " + site, PageKey: key, SiteName: site, UserID: 1001}
require.NoError(t, app.Dao().DB().Create(&comment).Error)
}

exported, err := RunExportArtrans(app.Dao(), &ExportParams{})
require.NoError(t, err)
var comments []entity.Artran
require.NoError(t, json.Unmarshal([]byte(exported), &comments))
titles := make(map[string]string)
for _, comment := range comments {
if comment.PageKey == key {
titles[comment.SiteName] = comment.PageTitle
}
}
require.Equal(t, map[string]string{"Site A": "Page on Site A", "Site B": "Page on Site B"}, titles)
}
Loading
Loading