用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/briandenicola/Aurearia --skill go-sqlite-test-isolation命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
Handle mixed legacy/new set-type contracts without writing deprecated values.
Deep quality-control audit to run after major features, migrations, or integrations land — covers engineering best practices, security, docs, architecture, test coverage, supply chain, UX, and operational readiness
Reuse the shared museum tray renderer across authenticated and public coin presentations.
| name | go-sqlite-test-isolation |
| description | Ensuring SQLite in-memory databases are truly isolated per Go test when using glebarez/sqlite |
| domain | testing |
| confidence | high |
| source | earned |
In Go test files using gorm.Open(sqlite.Open(":memory:"), &gorm.Config{}), multiple test functions that run in the same go test process share the same underlying in-memory SQLite database. Data inserted in one test leaks into subsequent tests that use a bare :memory: DSN.
This causes subtle failures where:
Use a uniquely-named in-memory database per test by encoding a test-specific name in the DSN:
var testCounter uint64 // package-level
func setupTestDB(t *testing.T) *gorm.DB {
t.Helper()
dbName := fmt.Sprintf("file:my_svc_%d_%d?mode=memory&cache=shared",
time.Now().UnixNano(), atomic.AddUint64(&testCounter, 1))
db, err := gorm.Open(sqlite.Open(dbName), &gorm.Config{})
// ...
}
The file:NAME?mode=memory&cache=shared DSN creates a named in-memory database. Each unique name is a separate SQLite database. The cache=shared flag is required to allow GORM's connection pool (multiple Go connections) to see the same in-memory DB — without it, each pooled connection would see a different (empty) database.
// BAD: all tests in the same process share one anonymous in-memory database
func setupTestDB(t *testing.T) *gorm.DB {
db, _ := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
// ...
}
Tests that used :memory: but happened to not overlap on (coinID, userID) pairs or to not read back stale rows appeared to pass. When scoring weights changed such that more items were written to the shared DB (and those items matched the target coin in a later test), the failure surfaced. This is a data-dependent flake, not a stable test.
If a test that creates a fresh user with userID=1 returns more results than expected, and those extra results have data characteristics consistent with a different test's setup, suspect :memory: sharing.
:memory: Is Safe:memory: without a unique name is safe only when:
*sql.DB (not pooled)In practice, neither condition holds in multi-test packages with GORM. Use named in-memory DBs everywhere.