Files
ai/object/main_test.go
zeekayandHanzo Dev cec6d69791 test(object): the package ran ZERO tests and hid a live defect behind "ok"
TestMain called os.Exit(0) before m.Run() whenever no seeded database was
present. That bought an honest "these did not run" for the integration tests at
the price of the entire package: `go test ./object/` printed a cheerful "ok" in
0.1s having executed NOTHING — all 182 tests, including the ~150 that touch no
database at all.

That is false assurance, and it was not theoretical. It concealed a real defect
for as long as it existed:

    --- FAIL: TestCrawlStorageEndpoint
        host = "minio.hanzo.svc.cluster.local:9000", want "s3.hanzo.svc:9000"

The crawl-storage default still named a MinIO Service that no longer exists in
the cluster (verified: no minio Service in any namespace; s3 is the replacement).
crawlStorageDefaultEndpoint had already been corrected to s3.hanzo.svc:9000 with
a comment explaining exactly this, but conf/app.conf still SET the key to the
dead host, so the corrected constant could never apply and the test guarding it
could never report. conf/app.conf now leaves it empty and the constant is the
single source of the default. (Production was unaffected — its mounted app.conf
carries no such line — so this bit local dev and any deploy shipping the repo
default.)

Only TWO tests in this package acquire a store, so the gate belongs in THEM, not
over all 182. requireStore(t) skips on an absent database and the panics that
made a missing store abort the whole binary are now t.Skip/t.Fatalf. Both
packages' helpers defer to ONE probe (object.StoreProbeReason, the standard
export_test.go idiom) so there is no second copy to drift.

Measured, before -> after: 0 tests executed -> 153 PASS, 0 FAIL, 26 honest SKIP,
0 panics. Full suite: 22 packages ok, 0 FAIL.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-04 18:23:34 -07:00

89 lines
3.8 KiB
Go

//go:build !skipCi
package object
import (
"fmt"
"os"
"testing"
)
// The tests in this package are INTEGRATION tests: they read and write real
// rows through the configured adapter, and several also call a live model
// endpoint. They were written to be excluded with `-tags skipCi`, but nothing
// in the repo passes that tag, so `go test ./...` ran them against a database
// that is not there. Every one of them then dereferenced the nil entity its
// query did not return, and a panic in a test aborts the whole package binary —
// which is why one failure (TestTranslateArticle) was all anyone ever saw, with
// TestUpdateStoreFolders and TestCrawlStorageEndpoint hidden behind it.
//
// That absence must mean "these did not run", never "these failed". It used to
// be enforced with os.Exit(0) BEFORE m.Run(), which bought that honesty at the
// price of the whole package: every test here was skipped, including the ones
// that touch no database at all, and `go test ./object/` reported a cheerful
// "ok" in 0.1s having executed nothing. That is false assurance, which is worse
// than a red suite — it hid a real defect (the crawl-storage default still
// naming a retired MinIO Service) behind a passing package for as long as it
// existed.
//
// Only TWO tests in this package actually acquire a store, so the gate belongs
// in THEM, not over all 182. They now t.Skip on an absent store — the same
// convention article_test.go and datastore_live_test.go already use — and the
// panics that made a missing database abort the whole binary are t.Skip/t.Fatalf
// instead. So the suite runs, the pure tests report real results, and the
// integration tests still say "did not run" rather than "failed".
//
// The reason is still printed, because a run where the integration tests skipped
// is not the same run as one where they passed. The build tag still works and is
// still the way to exclude them at compile time.
func TestMain(m *testing.M) {
if reason := probeStore(); reason != "" {
fmt.Printf("object: integration tests will skip — %s\n", reason)
}
os.Exit(m.Run())
}
// requireStore skips the calling test when there is no seeded database.
//
// This is the gate that used to live in TestMain over the whole package. Here it
// applies to exactly the tests that need it, so a missing database stops the
// integration tests and nothing else. Call it as the first statement of any test
// that reads or writes real rows: without it such a test reaches a nil store and
// panics, and a panic aborts the entire package binary — which is how one
// missing database used to hide every other result in this package.
func requireStore(t *testing.T) {
t.Helper()
if reason := probeStore(); reason != "" {
t.Skipf("integration test needs a seeded database — %s", reason)
}
}
// StoreProbeReason exposes probeStore to the object_test package, whose files
// share this test binary but cannot see an unexported identifier. It is declared
// in a _test.go file, so it is not part of the object package's API — the
// standard export_test.go idiom. One probe, two thin wrappers, rather than a
// second copy of the logic that can drift from this one.
func StoreProbeReason() string { return probeStore() }
// probeStore returns why the integration environment is unusable, or "" when it
// is ready. InitConfig panics on a missing config file rather than returning an
// error, so the recover is the only way to ask the question.
func probeStore() (reason string) {
defer func() {
if r := recover(); r != nil {
reason = fmt.Sprintf("configuration is not loadable: %v", r)
}
}()
InitConfig()
store, err := getStore("admin", "default")
switch {
case err != nil:
return fmt.Sprintf("the store is not readable: %v", err)
case store == nil:
return "store admin/default is absent; the tests need a seeded database"
}
return ""
}