✨ feat: add schema-per-scenario isolation with BDD_SCHEMA_ISOLATION env var
- Add BDD_SCHEMA_ISOLATION env var to enable PostgreSQL schema-per-scenario isolation
- Generate unique schema names: test_{sha256(feature:scenario)[:8]}
- Implement SetupScenarioSchema() and TeardownScenarioSchema() with search_path handling
- Add CASCADE drop to clean up all scenario-created DB objects
- Add isSchemaIsolationEnabled() helpers to both suite.go and server.go
- Skip table clearing when schema isolation is active (schema drop replaces it)
- Update validate-test-suite.sh to set FIXED_TEST_PORT and BDD_SCHEMA_ISOLATION
- Add isCleanupLoggingEnabled() for optional CLEANUP: prefixed logs
- Add ADR 0025 documenting all isolation strategies and decision rationale
Activation:
BDD_SCHEMA_ISOLATION=true - Enable schema-per-scenario isolation
BDD_ENABLE_CLEANUP_LOGS=true - Enable verbose cleanup/isolation logging
Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -42,11 +42,10 @@ func InitializeTestSuite(ctx *godog.TestSuiteContext) {
|
||||
|
||||
sc := ctx.ScenarioContext()
|
||||
sc.BeforeScenario(func(s *godog.Scenario) {
|
||||
// Get feature name from context or environment
|
||||
// Get feature name from environment - falls back to "bdd" for multi-feature tests
|
||||
feature := os.Getenv("FEATURE")
|
||||
if feature == "" {
|
||||
// Try to extract feature from scenario tags or path
|
||||
feature = "unknown"
|
||||
feature = "bdd"
|
||||
}
|
||||
|
||||
if isCleanupLoggingEnabled() {
|
||||
@@ -55,9 +54,14 @@ func InitializeTestSuite(ctx *godog.TestSuiteContext) {
|
||||
|
||||
// Setup schema isolation if enabled
|
||||
if sharedServer != nil {
|
||||
if err := sharedServer.SetupScenarioSchema(feature, s.Name); err != nil {
|
||||
// Include scenario Uri for disambiguation when multiple features run
|
||||
scenarioKey := s.Name
|
||||
if s.Uri != "" {
|
||||
scenarioKey = fmt.Sprintf("%s:%s", s.Uri, s.Name)
|
||||
}
|
||||
if err := sharedServer.SetupScenarioSchema(feature, scenarioKey); err != nil {
|
||||
if isCleanupLoggingEnabled() {
|
||||
log.Warn().Err(err).Msg("ISOLATION: Failed to setup scenario schema")
|
||||
log.Warn().Err(err).Str("feature", feature).Str("scenario", scenarioKey).Msg("ISOLATION: Failed to setup scenario schema")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user