Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Cleanup (#68648)

Aleksandr Lesnenko049526c61c5e
diff --git a/.claude-env-files.edn b/.claude-env-files.edn
deleted file mode 100644
index 4ada47930bb..00000000000
--- a/.claude-env-files.edn
+++ /dev/null
@@ -1 +0,0 @@
-{"edpaget" ["PROJECT_SUMMARY.md" "LLM_CODE_STYLE.md" "CLAUDE.md" ".claude/agents/clojure-project-executor.md" ".claude/agents/web-assumption-validator.md" ".claude/agents/software-architect-planner.md" ".claude/agents/codebase-behavior-researcher.md" ".claude/commands/orchestrate-clojure.md" ".clojure-mcp/config.edn"]}
\ No newline at end of file
diff --git a/.claude-env-state.edn b/.claude-env-state.edn
deleted file mode 100644
index 2982c31ecfa..00000000000
--- a/.claude-env-state.edn
+++ /dev/null
@@ -1 +0,0 @@
-{:current-environment "edpaget", :last-updated #inst "2025-08-20T16:01:36.621-00:00"}
\ No newline at end of file
diff --git a/DECOUPLING_INTERFACES_BROAD_SURVEY.md b/DECOUPLING_INTERFACES_BROAD_SURVEY.md
deleted file mode 100644
index 9b476ca0696..00000000000
--- a/DECOUPLING_INTERFACES_BROAD_SURVEY.md
+++ /dev/null
@@ -1,451 +0,0 @@
-# Decoupling via Defined Interfaces in Functional Programming
-
-## A Cross-Language Survey of Best Practices
-
-This document surveys interface and decoupling mechanisms across functional programming languages, examining how different languages approach polymorphism, dependency injection, and architectural boundaries.
-
----
-
-## Table of Contents
-
-1. [Overview](#overview)
-2. [Haskell](#haskell)
-3. [ML Family (OCaml, Standard ML) & Scala](#ml-family-and-scala)
-4. [Elixir](#elixir)
-5. [F#](#f)
-6. [Cross-Cutting Patterns](#cross-cutting-patterns)
-7. [Key Papers and Talks](#key-papers-and-talks)
-8. [Summary Comparison](#summary-comparison)
-
----
-
-## Overview
-
-Functional programming languages approach decoupling differently than object-oriented languages. Instead of interface-based inheritance hierarchies, FP languages typically use:
-
-- **Type classes / Protocols** - Ad-hoc polymorphism
-- **Module systems** - Encapsulation and abstraction
-- **Effect systems** - Separating what from how
-- **Higher-order functions** - Functions as first-class dependencies
-
-Each approach has trade-offs in terms of expressiveness, performance, and ease of use.
-
----
-
-## Haskell
-
-Haskell provides the most sophisticated type-level interface mechanisms among mainstream FP languages.
-
-### Type Classes
-
-Type classes are Haskell's primary interface mechanism, providing ad-hoc polymorphism:
-
-```haskell
-class Comparable a where
- compare :: a -> a -> Ordering
-
- -- Default implementation
- lessThan :: a -> a -> Bool
- lessThan x y = compare x y == LT
-
-instance Comparable Temperature where
- compare (Celsius x) (Celsius y) = Prelude.compare x y
-```
-
-**Key advantages over OOP interfaces:**
-- Instances can be defined separately from type definitions
-- Type safety enforced at compile time
-- Laws provide semantic contracts
-
-### Type Class Laws
-
-Laws are semantic contracts that implementations must satisfy:
-
-```haskell
--- Functor Laws
--- 1. Identity: fmap id == id
--- 2. Composition: fmap (f . g) == fmap f . fmap g
-
--- Monad Laws
--- 1. Left identity: return a >>= k == k a
--- 2. Right identity: m >>= return == m
--- 3. Associativity: (m >>= k) >>= h == m >>= (\x -> k x >>= h)
-```
-
-### Module System
-
-Haskell uses explicit export lists for encapsulation:
-
-```haskell
-module Stack
- ( Stack -- Export type only, not constructors
- , empty
- , push
- , pop
- ) where
-
--- Implementation hidden
-data Stack a = Stack [a]
-
-empty :: Stack a
-empty = Stack []
-```
-
-**Smart constructors** enforce invariants:
-
-```haskell
-module Email (Email, mkEmail, emailText) where
-
-newtype Email = Email Text
-
-mkEmail :: Text -> Either String Email
-mkEmail t
- | "@" `T.isInfixOf` t = Right (Email t)
- | otherwise = Left "Invalid email"
-```
-
-### Effect Systems
-
-Haskell has evolved multiple approaches to decoupling effects:
-
-#### MTL (Monad Transformer Library)
-
-```haskell
-processUser :: (MonadReader Config m, MonadState AppState m, MonadError AppError m)
- => UserId -> m User
-```
-
-#### ReaderT Pattern
-
-```haskell
-data Env = Env
- { envConfig :: Config
- , envLogger :: LogLevel -> Text -> IO ()
- , envDatabase :: Connection
- }
-
-newtype AppM a = AppM { unAppM :: ReaderT Env IO a }
-```
-
-#### Modern Effect Systems
-
-| Library | Performance | Ergonomics | Use Case |
-|---------|-------------|------------|----------|
-| effectful | Excellent | Good | Production |
-| fused-effects | Excellent | Medium | Performance-critical |
-| polysemy | Poor | Excellent | Prototyping |
-
-### Key Resources
-
-**Papers:**
-- ["How to Make Ad-Hoc Polymorphism Less Ad Hoc"](https://dl.acm.org/doi/pdf/10.1145/75277.75283) - Wadler & Blott (1989)
-- ["Data Types à la Carte"](https://www.cambridge.org/core/journals/journal-of-functional-programming/article/data-types-a-la-carte/14416CB20C4637164EA9F77097909409) - Swierstra (2008)
-- ["Freer Monads, More Extensible Effects"](https://okmij.org/ftp/Haskell/extensible/more.pdf) - Kiselyov & Ishii (2015)
-
-**Blogs:**
-- [Three Layer Haskell Cake](https://www.parsonsmatt.org/2018/03/22/three_layer_haskell_cake.html) - Matt Parsons
-- [The ReaderT Design Pattern](https://www.fpcomplete.com/blog/readert-design-pattern/) - FP Complete
-
----
-
-## ML Family and Scala
-
-### OCaml/Standard ML Module System
-
-ML languages have the most powerful module systems with signatures and functors:
-
-```ocaml
-(* Signature defines interface *)
-module type STACK = sig
- type 'a t
- val empty : 'a t
- val push : 'a -> 'a t -> 'a t
- val pop : 'a t -> ('a * 'a t) option
-end
-
-(* Module implements signature *)
-module ListStack : STACK = struct
- type 'a t = 'a list
- let empty = []
- let push x s = x :: s
- let pop = function
- | [] -> None
- | x::xs -> Some (x, xs)
-end
-```
-
-**Functors** enable parameterized modules (dependency injection at the module level):
-
-```ocaml
-module MakeCache (S : STORAGE) : CACHE = struct
- let get key = S.read key
- let set key value = S.write key value
-end
-
-module RedisCache = MakeCache(RedisStorage)
-module MemCache = MakeCache(InMemoryStorage)
-```
-
-### Scala Type Classes and Tagless Final
-
-Scala encodes type classes via implicit parameters:
-
-```scala
-trait Serializable[A] {
- def serialize(a: A): String
-}
-
-implicit val stringSerializable: Serializable[String] =
- (s: String) => s
-
-def save[A: Serializable](a: A): Unit =
- println(implicitly[Serializable[A]].serialize(a))
-```
-
-**Tagless Final** provides effect abstraction:
-
-```scala
-trait UserRepository[F[_]] {
- def getUser(id: UserId): F[Option[User]]
- def saveUser(user: User): F[Unit]
-}
-
-// Production interpreter
-class PostgresUserRepo extends UserRepository[IO] { ... }
-
-// Test interpreter
-class InMemoryUserRepo extends UserRepository[Id] { ... }
-```
-
-### Key Resources
-
-**Papers:**
-- ["Applicative Programming with Effects"](https://www.cambridge.org/core/journals/journal-of-functional-programming/article/applicative-programming-with-effects/9A3F61D50B56E6D40E779F9FE91C2021) - McBride & Paterson
-- ["Finally Tagless, Partially Evaluated"](https://okmij.org/ftp/tagless-final/JFP.pdf) - Carette, Kiselyov, Shan
-
-**Talks:**
-- Odersky's talks on Scala type system
-- "Constraints Liberate, Liberties Constrain" - Runar Bjarnason
-
----
-
-## Elixir
-
-Elixir provides two main mechanisms for polymorphism: behaviours and protocols.
-
-### Behaviours
-
-Behaviours define contracts that modules must implement:
-
-```elixir
-defmodule MyApp.Notifier do
- @callback send_notification(user :: term(), message :: String.t()) ::
- {:ok, reference()} | {:error, reason :: term()}
-end
-
-defmodule MyApp.EmailNotifier do
- @behaviour MyApp.Notifier
-
- @impl MyApp.Notifier
- def send_notification(user, message) do
- # Implementation
- {:ok, make_ref()}
- end
-end
-```
-
-**Best practice:** Always use `@impl ModuleName` rather than `@impl true`.
-
-### Protocols
-
-Protocols enable polymorphism based on data type:
-
-```elixir
-defprotocol Size do
- def size(data)
-end
-
-defimpl Size, for: BitString do
- def size(string), do: byte_size(string)
-end
-
-defimpl Size, for: Map do
- def size(map), do: map_size(map)
-end
-```
-
-### OTP Patterns
-
-GenServer separates client API from server implementation:
-
-```elixir
-defmodule MyApp.Cache do
- use GenServer
-
- # Client API
- def get(key), do: GenServer.call(__MODULE__, {:get, key})
- def put(key, value), do: GenServer.cast(__MODULE__, {:put, key, value})
-
- # Server callbacks
- @impl GenServer
- def handle_call({:get, key}, _from, state) do
- {:reply, Map.get(state, key), state}
- end
-end
-```
-
-### Key Resources
-
-**Talks:**
-- Jose Valim's ElixirConf Keynotes
-- "Gang of None? Design Patterns in Elixir" - ElixirConf EU 2024
-
-**Documentation:**
-- [OTP Design Principles](https://www.erlang.org/doc/system/design_principles.html)
-- [Elixir Behaviours](https://hexdocs.pm/elixir/behaviours.html)
-- [Elixir Protocols](https://hexdocs.pm/elixir/protocols.html)
-
----
-
-## F#
-
-F# combines functional programming with .NET's object system.
-
-### Object Expressions
-
-Anonymous interface implementations:
-
-```fsharp
-type ILogger =
- abstract member Log : string -> unit
-
-let createConsoleLogger prefix =
- { new ILogger with
- member _.Log(message) =
- printfn "[%s] %s" prefix message }
-```
-
-### Type Providers
-
-Compile-time type generation from external schemas:
-
-```fsharp
-type MoviesProvider = JsonProvider<"movies.json">
-
-let movies = MoviesProvider.Load("https://api.example.com/movies")
-for movie in movies do
- printfn "%s (%d)" movie.Title movie.Year
-```
-
-### Computation Expressions
-
-Uniform syntax for monadic computations:
-
-```fsharp
-let validateUser name email = result {
- let! validName = validateName name
- let! validEmail = validateEmail email
- return { Name = validName; Email = validEmail }
-}
-```
-
-### Signature Files (.fsi)
-
-Define public interfaces separately:
-
-```fsharp
-// Users.fsi
-module Users =
- type User
- val create : name:string -> email:string -> Result<User, string>
- val findById : id:int -> User option
-```
-
-### Key Resources
-
-**Talks:**
-- ["F# Code I Love"](https://www.microsoft.com/en-us/research/video/f-code-i-love-don-syme/) - Don Syme
-- ["The F# Path to Relaxation"](https://www.microsoft.com/en-us/research/video/the-f-path-to-relaxation-don-syme/) - Don Syme
-
-**Articles:**
-- [F# for Fun and Profit - Dependency Injection](https://fsharpforfunandprofit.com/posts/dependencies/)
-- [Designing with Capabilities](https://fsharpforfunandprofit.com/cap/)
-
----
-
-## Cross-Cutting Patterns
-
-### Dependency Injection in FP
-
-| Pattern | Description | Example |
-|---------|-------------|---------|
-| **Partial Application** | Pre-bind dependencies | `(partial save-user db)` |
-| **Reader Monad** | Environment passing | `ReaderT Env IO a` |
-| **Higher-Order Functions** | Functions as dependencies | `(defn process [get-data] ...)` |
-| **Records of Functions** | Service objects | `{:get-user fn :save-user fn}` |
-
-### Interface Design Principles
-
-1. **Minimal Surface Area** - Small, focused interfaces
-2. **Composition over Inheritance** - Combine small pieces
-3. **Data-Oriented Boundaries** - Pass data, not behavior
-4. **Test at the Seams** - Mock at interface boundaries
-
-### Anti-Patterns to Avoid
-
-- **Over-abstraction** - Don't abstract prematurely
-- **Leaky abstractions** - Implementation details bleeding through
-- **Premature protocol creation** - Start with functions, graduate to protocols
-- **Ignoring data-driven alternatives** - Maps are often better than protocols
-
----
-
-## Key Papers and Talks
-
-### Foundational Papers
-
-| Paper | Authors | Year | Significance |
-|-------|---------|------|--------------|
-| [How to Make Ad-Hoc Polymorphism Less Ad Hoc](https://dl.acm.org/doi/pdf/10.1145/75277.75283) | Wadler & Blott | 1989 | Introduced type classes |
-| [Data Types à la Carte](https://www.cambridge.org/core/journals/journal-of-functional-programming/article/data-types-a-la-carte/14416CB20C4637164EA9F77097909409) | Swierstra | 2008 | Composable data types |
-| [Freer Monads, More Extensible Effects](https://okmij.org/ftp/Haskell/extensible/more.pdf) | Kiselyov & Ishii | 2015 | Efficient effect systems |
-
-### Conference Talks
-
-- **"The Evolution of Effects"** - Haskell Symposium 2023 Keynote
-- **"Components Just Enough Structure"** - Stuart Sierra, Clojure/West 2014
-- **Jose Valim's ElixirConf Keynotes** - Annual Elixir design updates
-
----
-
-## Summary Comparison
-
-| Language | Primary Mechanism | Dispatch | Key Strength |
-|----------|-------------------|----------|--------------|
-| **Haskell** | Type classes | Compile-time | Type safety + laws |
-| **OCaml** | Module signatures | Compile-time | Powerful functors |
-| **Scala** | Implicits/type classes | Compile-time | JVM integration |
-| **Elixir** | Behaviours/Protocols | Runtime | OTP patterns |
-| **F#** | Object expressions | Runtime | .NET integration |
-| **Clojure** | Protocols/Multimethods | Runtime | Maximum flexibility |
-
-### When to Use Each Approach
-
-- **Type classes** - When you need compile-time safety and laws
-- **Module systems** - When you need strong encapsulation
-- **Effect systems** - When you need to mock/swap implementations
-- **Protocols** - When you need open extension
-- **Higher-order functions** - When you need maximum simplicity
-
----
-
-## Next Steps
-
-For Clojure-specific patterns and practices, see:
-- [DECOUPLING_INTERFACES_CLOJURE.md](./DECOUPLING_INTERFACES_CLOJURE.md)
-
-This companion document covers:
-- Protocols and Multimethods in depth
-- Clojure Spec and Malli
-- Component, Integrant, and Mount
-- Testing and mocking patterns
diff --git a/DECOUPLING_INTERFACES_CLOJURE.md b/DECOUPLING_INTERFACES_CLOJURE.md
deleted file mode 100644
index 3e558ce374b..00000000000
--- a/DECOUPLING_INTERFACES_CLOJURE.md
+++ /dev/null
@@ -1,1119 +0,0 @@
-# Decoupling via Defined Interfaces in Clojure
-
-## A Deep Dive into Clojure's Interface Mechanisms
-
-This document provides comprehensive coverage of Clojure's approaches to decoupling and defining interfaces, including protocols, multimethods, spec, Malli, and component systems.
-
----
-
-## Table of Contents
-
-1. [Protocols](#protocols)
-2. [Multimethods](#multimethods)
-3. [Protocols vs Multimethods Decision Matrix](#protocols-vs-multimethods-decision-matrix)
-4. [Clojure Spec](#clojure-spec)
-5. [Malli](#malli)
-6. [Component Systems](#component-systems)
-7. [Dependency Injection Patterns](#dependency-injection-patterns)
-8. [Best Practices](#best-practices)
-9. [Resources and References](#resources-and-references)
-
----
-
-## Protocols
-
-Protocols provide high-performance, type-based polymorphism that solves the expression problem.
-
-### Definition and Basic Usage
-
-```clojure
-(defprotocol Greetable
- "A protocol for things that can greet"
- (greet [this] "Return a greeting")
- (greet-with-name [this name] "Return a personalized greeting"))
-```
-
-### Implementation with defrecord
-
-```clojure
-(defprotocol WereCreature
- (full-moon-behavior [creature]))
-
-(defrecord WereWolf [name title]
- WereCreature
- (full-moon-behavior [this]
- (str name " will howl and murder")))
-
-;; Usage
-(def jacob (->WereWolf "Jacob" "Alpha"))
-(full-moon-behavior jacob) ; => "Jacob will howl and murder"
-```
-
-### Extension Mechanisms
-
-**extend-type** - One type, multiple protocols:
-
-```clojure
-(extend-type java.lang.String
- Greetable
- (greet [this] (str "Hello, I am " this))
- (greet-with-name [this name] (str this " says hello to " name)))
-```
-
-**extend-protocol** - One protocol, multiple types:
-
-```clojure
-(extend-protocol Greetable
- java.lang.String
- (greet [s] (str "String: " s))
-
- clojure.lang.PersistentVector
- (greet [v] (str "Vector with " (count v) " items"))
-
- java.lang.Object
- (greet [o] "Generic greeting"))
-```
-
-**Reification** - Anonymous implementations:
-
-```clojure
-(defn open-resource [path]
- (let [resource (load-resource path)]
- (reify
- Closeable
- (close [this] (cleanup resource))
-
- Object
- (toString [this] (str "Resource: " path)))))
-```
-
-### When to Use Protocols
-
-- Single dispatch on first argument's type
-- Need maximum performance (~5x faster than multimethods)
-- Defining coherent abstractions (group of related functions)
-- Building libraries for others to extend
-
----
-
-## Multimethods
-
-Multimethods provide maximum flexibility with dispatch on any function of any arguments.
-
-### Basic Pattern
-
-```clojure
-(defmulti encounter
- (fn [creature1 creature2]
- [(:species creature1) (:species creature2)]))
-
-(defmethod encounter [:human :dog]
- [h d]
- (str (:name h) " pets " (:name d)))
-
-(defmethod encounter :default
- [c1 c2]
- (str (:name c1) " ignores " (:name c2)))
-```
-
-### Hierarchies
-
-```clojure
-(derive ::square ::rect)
-(derive ::rect ::shape)
-
-(defmulti area :shape-type)
-
-(defmethod area ::rect
- [{:keys [width height]}]
- (* width height))
-
-;; Square inherits rect implementation
-(area {:shape-type ::square :width 5 :height 5}) ; => 25
-```
-
-### When to Use Multimethods
-
-- Dispatch on multiple arguments
-- Dispatch on values (not types)
-- Need custom hierarchies
-- Dispatch logic is complex or arbitrary
-
----
-
-## Protocols vs Multimethods Decision Matrix
-
-| Scenario | Recommendation |
-|----------|----------------|
-| Dispatch on first argument's type only | **Protocols** |
-| Performance critical | **Protocols** (~5x faster) |
-| Dispatch on multiple arguments | **Multimethods** |
-| Dispatch on values/keywords | **Multimethods** |
-| Custom hierarchies | **Multimethods** |
-| Maximum REPL flexibility | **Multimethods** |
-
-### Key References
-
-**Talks:**
-- [Rich Hickey on Protocols (InfoQ 2010)](https://www.infoq.com/interviews/hickey-clojure-protocols/)
-- [Clojure's Solutions to the Expression Problem (Strange Loop)](https://www.infoq.com/presentations/Clojure-Expression-Problem/)
-
-**Documentation:**
-- [Clojure Protocols Reference](https://clojure.org/reference/protocols)
-- [Clojure Multimethods Reference](https://clojure.org/reference/multimethods)
-
-**Books:**
-- ["The Joy of Clojure" Chapter 9](https://www.manning.com/books/the-joy-of-clojure-second-edition)
-- ["Clojure for the Brave and True"](https://www.braveclojure.com/multimethods-records-protocols/)
-
----
-
-## Clojure Spec
-
-Spec provides specifications for data and function contracts with generative testing support.
-
-### Defining Specifications
-
-```clojure
-(require '[clojure.spec.alpha :as s])
-
-;; Simple predicates
-(s/def ::email string?)
-(s/def ::age pos-int?)
-
-;; Map specs
-(s/def ::person
- (s/keys :req [::name ::age]
- :opt [::email]))
-
-;; Using specs
-(s/valid? ::person {::name "Alice" ::age 30}) ; => true
-```
-
-### Function Contracts
-
-```clojure
-(defn ranged-rand [start end]
- (+ start (rand-int (- end start))))
-
-(s/fdef ranged-rand
- :args (s/and (s/cat :start int? :end int?)
- #(< (:start %) (:end %)))
- :ret int?
- :fn (s/and #(>= (:ret %) (-> % :args :start))
- #(< (:ret %) (-> % :args :end))))
-```
-
-### Instrumentation
-
-```clojure
-(require '[clojure.spec.test.alpha :as stest])
-
-;; Enable validation during development
-(stest/instrument)
-
-;; Run generative tests
-(stest/check `ranged-rand)
-```
-
-### Key Resources
-
-**Talks:**
-- [Rich Hickey - "Spec-ulation" (Clojure/conj 2016)](https://www.youtube.com/watch?v=oyLBGkS5ICk)
-- [Rich Hickey - "Maybe Not" (Clojure/conj 2018)](https://www.youtube.com/watch?v=YR5WdGrpoug)
-- [Alex Miller - "clojure.spec" (Strange Loop 2016)](https://www.youtube.com/watch?v=VNTQ-M_uSo8)
-
-**Documentation:**
-- [Clojure Spec Guide](https://clojure.org/guides/spec)
-- [Spec 2 Alpha Repository](https://github.com/clojure/spec-alpha2)
-
----
-
-## Malli
-
-Malli is a high-performance, data-driven schema library from Metosin.
-
-### Schema Definition
-
-```clojure
-(require '[malli.core :as m])
-
-(def Person
- [:map
- [:name :string]
- [:age :int]
- [:email {:optional true} :string]])
-
-(m/validate Person {:name "Alice" :age 30}) ; => true
-
-;; Compiled validator for performance
-(def valid-person? (m/validator Person))
-```
-
-### Function Schemas
-
-```clojure
-(m/=> plus [:=> [:cat :int :int] :int])
-
-(defn plus [x y] (+ x y))
-
-;; Instrumentation
-(require '[malli.instrument :as mi])
-(mi/instrument!)
-```
-
-### Transformations and Coercion
-
-```clojure
-(require '[malli.transform :as mt])
-
-(m/decode :int "42" (mt/string-transformer))
-; => 42
-
-(m/decode
- [:map [:x :boolean] [:y :int]]
- {:x "true" :y "1"}
- (mt/string-transformer))
-; => {:x true, :y 1}
-```
-
-### Error Messages
-
-```clojure
-(require '[malli.error :as me])
-
-(-> Person
- (m/explain {:name 123})
- (me/humanize))
-; => {:name ["should be a string"]}
-```
-
-### Spec vs Malli Comparison
-
-| Feature | Clojure Spec | Malli |
-|---------|--------------|-------|
-| **Syntax** | Macro-based | Data-driven |
-| **Performance** | Good | Excellent (10-100x) |
-| **Transformation** | Not supported | Built-in |
-| **Error Messages** | Basic | Rich with spell-check |
-| **JSON Schema** | Third-party | Built-in |
-| **Global Registry** | Required | Optional |
-
-### When to Choose Malli
-
-- Runtime schema creation
-- Data transformation/coercion
-- Better error messages
-- JSON Schema generation
-- Performance-critical validation
-
-### Key Resources
-
-**Documentation:**
-- [Malli GitHub](https://github.com/metosin/malli)
-- [Function Schemas](https://github.com/metosin/malli/blob/master/docs/function-schemas.md)
-- [Value Transformation](https://github.com/metosin/malli/blob/master/docs/value-transformation.md)
-
----
-
-## Component Systems
-
-Three major libraries for managing application state and dependencies.
-
-### Component (Stuart Sierra)
-
-**Philosophy:** Explicit dependency injection with lifecycle management.
-
-```clojure
-(require '[com.stuartsierra.component :as component])
-
-(defrecord Database [host port connection]
- component/Lifecycle
- (start [this]
- (assoc this :connection (connect host port)))
- (stop [this]
- (.close connection)
- (assoc this :connection nil)))
-
-(defn create-system [config]
- (component/system-map
- :database (new-database (:db-host config) (:db-port config))
- :app (component/using
- (new-application)
- [:database])))
-
-(def system (component/start (create-system config)))
-```
-
-**GitHub:** https://github.com/stuartsierra/component
-
-### Integrant (James Reeves)
-
-**Philosophy:** Data-driven configuration with multimethod lifecycle.
-
-**config.edn:**
-```clojure
-{:adapter/jetty {:port 8080
- :handler #ig/ref :handler/api}
- :handler/api {:database #ig/ref :database/postgres}
- :database/postgres {:host "localhost" :port 5432}}
-```
-
-```clojure
-(require '[integrant.core :as ig])
-
-(defmethod ig/init-key :database/postgres [_ {:keys [host port]}]
- (create-connection host port))
-
-(defmethod ig/halt-key! :database/postgres [_ conn]
- (.close conn))
-
-(def system (ig/init config))
-```
-
-**GitHub:** https://github.com/weavejester/integrant
-
-### Mount (Anatoly Polinsky)
-
-**Philosophy:** Namespace-based states with compiler-driven ordering.
-
-```clojure
-(require '[mount.core :refer [defstate]])
-
-(defstate conn
- :start (create-connection config)
- :stop (close-connection conn))
-
-;; Start all states
-(mount/start)
-
-;; Testing with substitutes
-(mount/start-with {#'myapp.db/conn mock-conn})
-```
-
-**GitHub:** https://github.com/tolitius/mount
-
-### Comparison Table
-
-| Feature | Component | Integrant | Mount |
-|---------|-----------|-----------|-------|
-| **Configuration** | Code | EDN | In defstate |
-| **Dependencies** | Explicit | Refs | Implicit |
-| **Multiple instances** | Native | Composite keys | Limited |
-| **Learning curve** | Moderate | Moderate | Easy |
-| **Boilerplate** | High | Medium | Low |
-
-### When to Use Each
-
-- **Component** - Large apps, explicit dependencies, DI familiar teams
-- **Integrant** - Data-driven config, Duct framework
-- **Mount** - Incremental adoption, minimal ceremony, REPL-first
-
-### Avoiding the "God Object" Problem
-
-A common criticism of Component/Integrant is that they lead to functions requiring large system objects with all dependencies. Here's how to avoid this anti-pattern:
-
-#### 1. Pass Only What's Needed
-
-```clojure
-;; Bad - god object
-(defn create-user [app-component user-data]
- (let [db (:database app-component)
- email (:email-service app-component)]
- ...))
-
-;; Good - explicit minimal dependencies
-(defn create-user [db email-service user-data]
- ...)
-```
-
-#### 2. Functional Core, Imperative Shell
-
-Keep business logic pure - it doesn't need dependencies:
-
-```clojure
-;; Pure core - no dependencies needed
-(defn calculate-order-total [order discounts tax-rate]
- (let [subtotal (reduce + (map :price (:items order)))
- discount (apply-discounts subtotal discounts)]
- (* discount (+ 1 tax-rate))))
-
-;; Thin shell - only this needs dependencies
-(defn process-order! [db email-service order]
- (let [discounts (db/get-discounts db (:user-id order))
- tax-rate (db/get-tax-rate db (:region order))
- total (calculate-order-total order discounts tax-rate)]
- (db/save-order! db (assoc order :total total))
- (email/send-receipt! email-service order)))
-```
-
-#### 3. Partial Application / Closures
-
-Pre-bind dependencies at system startup:
-
-```clojure
-(defn make-user-creator [db email-service]
- (fn [user-data]
- (let [user (db/insert! db :users user-data)]
- (email/send-welcome! email-service user)
- user)))
-
-(defrecord UserService [database email-service create-user]
- component/Lifecycle
- (start [this]
- (assoc this :create-user
- (make-user-creator database email-service)))
- (stop [this]
- (assoc this :create-user nil)))
-
-;; Usage - clean single-purpose function
-((:create-user user-service) {:name "Alice" :email "[email protected]"})
-```
-
-#### 4. Protocol Segregation
-
-Define narrow, focused protocols instead of one big component:
-
-```clojure
-;; Good - segregated protocols
-(defprotocol UserRepository
- (find-user [this id])
- (save-user [this user]))
-
-(defprotocol EmailSender
- (send-email [this to subject body]))
-
-;; Functions declare exactly what they need
-(defn notify-user [email-sender user message]
- (send-email email-sender (:email user) "Notification" message))
-```
-
-#### 5. The "Has" Pattern
-
-Define capability protocols that document requirements:
-
-```clojure
-(defprotocol HasDatabase
- (get-database [this]))
-
-(defprotocol HasEmailService
- (get-email-service [this]))
-
-(defrecord AppComponent [database email-service]
- HasDatabase
- (get-database [this] database)
- HasEmailService
- (get-email-service [this] email-service))
-
-;; Function documents exactly what it needs
-(defn create-user [component user-data]
- {:pre [(satisfies? HasDatabase component)
- (satisfies? HasEmailService component)]}
- (let [db (get-database component)
- email (get-email-service component)]
- ...))
-```
-
-#### 6. Layered Architecture
-
-Organize components so each layer has limited scope:
-
-```clojure
-;; Layer 1: Infrastructure
-:database (new-database config)
-:cache (new-cache config)
-
-;; Layer 2: Repositories (only infrastructure deps)
-:user-repo (component/using (new-user-repo) [:database :cache])
-
-;; Layer 3: Services (repos + services)
-:user-service (component/using (new-user-service)
- [:user-repo :email-client])
-
-;; Layer 4: Handlers (only services they need)
-:user-handler (component/using (new-user-handler) [:user-service])
-```
-
-#### Key Principle
-
-The god object problem comes from conflating "what I depend on" with "what I need for this operation."
-
-| Anti-Pattern | Better Approach |
-|--------------|-----------------|
-| Pass whole system | Pass specific dependencies |
-| One big component | Many small, focused components |
-| All logic in components | Pure functions + thin component shell |
-| Components do everything | Components just wire things together |
-
-### REPL-Friendly Patterns
-
-A common pain point with component systems is needing to start the entire system just to run a quick query. Here's how to maintain REPL productivity:
-
-#### 1. Standalone Resource Constructors
-
-Design components so resources can be created independently:
-
-```clojure
-;; This should work without any system
-(def conn (db/create-connection {:host "localhost" :port 5432}))
-(jdbc/execute! conn ["SELECT * FROM users LIMIT 5"])
-(.close conn)
-
-;; The component just automates lifecycle
-(defrecord Database [config conn]
- component/Lifecycle
- (start [this] (assoc this :conn (db/create-connection config)))
- (stop [this] (.close conn) (assoc this :conn nil)))
-```
-
-#### 2. Dev Namespace with Helpers
-
-```clojure
-(ns user
- (:require [integrant.repl :refer [go halt reset]]
- [integrant.repl.state :refer [system]]))
-
-;; Convenience accessors
-(defn db [] (:database/postgres system))
-(defn cache [] (:cache/redis system))
-
-;; Quick connection without system
-(defn dev-db []
- (db/create-connection (load-dev-config)))
-
-(defmacro with-dev-db [binding & body]
- `(let [~binding (dev-db)]
- (try ~@body (finally (.close ~binding)))))
-
-;; At REPL:
-(with-dev-db [conn]
- (jdbc/execute! conn ["SELECT count(*) FROM users"]))
-```
-
-#### 3. Partial System Startup
-
-Start only what you need:
-
-```clojure
-;; Integrant - start specific keys
-(def db-only (ig/init config [:database/postgres]))
-(jdbc/execute! (:database/postgres db-only) ["SELECT 1"])
-(ig/halt! db-only)
-
-;; Mount - start specific states
-(mount/start #'myapp.db/conn)
-(jdbc/execute! myapp.db/conn ["SELECT 1"])
-```
-
-#### 4. The "Bag of Functions" Pattern
-
-Return pre-bound functions that manage their own resources:
-
-```clojure
-(defn make-user-operations [db-config]
- (let [get-conn #(db/create-connection db-config)]
- {:get-user (fn [id]
- (with-open [conn (get-conn)]
- (jdbc/get-by-id conn :users id)))
- :list-users (fn []
- (with-open [conn (get-conn)]
- (jdbc/execute! conn ["SELECT * FROM users"])))}))
-
-;; At REPL - no system needed
-(def ops (make-user-operations dev-config))
-((:list-users ops))
-```
-
-#### Key Insight
-
-**Separate resource creation from lifecycle management.** Your constructors should work standalone; the component system just manages them.
-
-### Combining Multimethods with Component Systems
-
-Multimethods and component systems solve different problems and work well together:
-
-| Concern | Solution |
-|---------|----------|
-| **Polymorphism** - Different behavior by type/value | Multimethods / Protocols |
-| **Lifecycle & Dependencies** - Managing stateful resources | Component / Integrant / Mount |
-
-#### When Multimethods Are Enough
-
-If your implementations are **stateless** (use global resources like database pools), pure multimethods work great:
-
-```clojure
-;; No components needed - uses global database access
-(defmulti authenticate (fn [provider _request] provider))
-
-(defmethod authenticate :provider/password
- [_provider request]
- ;; t2/select uses global connection pool
- (let [user (t2/select-one :model/User :email (:email request))]
- (when (check-password user (:password request))
- {:success? true :user-id (:id user)})))
-```
-
-#### When to Add Components
-
-Add component management when providers need:
-- **Connection pools** - LDAP, HTTP clients
-- **Caching** - Provider-specific caches
-- **Background processes** - Token refresh
-- **Expensive initialization** - SAML metadata, keys
-
-#### Pattern 1: Pass Dependencies Through Context
-
-Multimethod receives dependencies via context map:
-
-```clojure
-(defmulti authenticate
- (fn [provider _context _request] provider))
-
-;; Simple providers ignore context
-(defmethod authenticate :provider/password
- [_provider _context request]
- (password-authenticate request))
-
-;; Complex providers use context
-(defmethod authenticate :provider/ldap
- [_provider {:keys [ldap-client]} request]
- (ldap-authenticate ldap-client request))
-
-;; Component creates context
-(defrecord AuthService [ldap-client saml-config database]
- component/Lifecycle
- (start [this]
- (assoc this :context {:ldap-client ldap-client
- :saml-config saml-config
- :database database}))
- (stop [this] this))
-
-;; Public API with default context
-(defn authenticate-user
- ([provider request]
- (authenticate provider default-context request))
- ([provider context request]
- (authenticate provider context request)))
-```
-
-#### Pattern 2: Component Registry of Providers
-
-Each provider is a component implementing a protocol:
-
-```clojure
-(defprotocol AuthProvider
- (authenticate [this request]))
-
-(defrecord LdapProvider [ldap-client config]
- component/Lifecycle
- (start [this]
- (assoc this :ldap-client (ldap/connect config)))
- (stop [this]
- (ldap/disconnect ldap-client)
- this)
-
- AuthProvider
- (authenticate [this request]
- (ldap-authenticate ldap-client request)))
-
-;; Registry holds all providers
-(defrecord AuthRegistry [ldap-provider saml-provider]
- component/Lifecycle
- (start [this]
- (assoc this :providers
- {:provider/ldap ldap-provider
- :provider/saml saml-provider}))
- (stop [this] this))
-
-;; Lookup and delegate
-(defn authenticate-user [registry provider-key request]
- (if-let [provider (get-in registry [:providers provider-key])]
- (authenticate provider request)
- (throw (ex-info "Unknown provider" {:provider provider-key}))))
-```
-
-#### Recommended Hybrid Approach
-
-Use multimethods for dispatch with optional context for dependencies:
-
-```clojure
-(defmulti authenticate
- (fn [provider _context _request] provider))
-
-;; Stateless - ignores context
-(defmethod authenticate :provider/password
- [_provider _context request]
- (password-authenticate request))
-
-;; Stateful - uses context
-(defmethod authenticate :provider/ldap
- [_provider {:keys [ldap-pool]} request]
- (ldap-authenticate ldap-pool request))
-
-;; Default context for production
-(def default-auth-context
- {:ldap-pool @ldap-connection-pool
- :http-client @http-client})
-
-;; Testable public API
-(defn authenticate-user
- ([provider request]
- (authenticate-user provider default-auth-context request))
- ([provider context request]
- (authenticate provider context request)))
-```
-
-This gives you:
-- Backward compatibility with stateless providers
-- Dependency injection for providers that need it
-- Testability (pass mock context)
-- No forced component system overhead
-
-### Key Resources
-
-**Talks:**
-- [Stuart Sierra - Components Just Enough Structure](https://www.youtube.com/watch?v=av9Xi6CNqq4) (Clojure/West 2014)
-
-**Books:**
-- [Clojure Applied](https://pragprog.com/titles/vmclojeco/clojure-applied/) - Chapters 6 & 7
-
-**Comparisons:**
-- [Yogthos - Contrasting Component and Mount](https://yogthos.net/posts/2016-01-19-ContrastingComponentAndMount.html)
-- [Mount - Differences from Component](https://github.com/tolitius/mount/blob/master/doc/differences-from-component.md)
-
----
-
-## Dependency Injection Patterns
-
-### Pattern 1: Higher-Order Functions
-
-```clojure
-(defn calculate-total [get-price items]
- (reduce + (map get-price items)))
-
-;; Production
-(calculate-total db/get-price items)
-
-;; Test
-(calculate-total (constantly 10.0) items)
-```
-
-### Pattern 2: Configuration Maps
-
-```clojure
-(defn process-order [{:keys [db-conn email-service]} order]
- (-> order
- (save-to-db db-conn)
- (send-confirmation email-service)))
-```
-
-### Pattern 3: Protocols and Records
-
-```clojure
-(defprotocol EmailService
- (send-email [this to subject body]))
-
-(defrecord SmtpService [config]
- EmailService
- (send-email [this to subject body]
- (smtp/send config to subject body)))
-
-(defrecord MockEmailService [sent-emails]
- EmailService
- (send-email [this to subject body]
- (swap! sent-emails conj {:to to :subject subject})))
-```
-
-### Pattern 4: Functional Core, Imperative Shell
-
-```clojure
-;; Pure core
-(defn calculate-discount [user order]
- (cond
- (:premium user) (* 0.8 (:total order))
- (:member user) (* 0.9 (:total order))
- :else (:total order)))
-
-;; Impure shell
-(defn process-order! [db user-id order-id]
- (let [user (db/get-user db user-id)
- order (db/get-order db order-id)
- discounted (calculate-discount user order)] ; Pure!
- (db/update-order! db order-id {:total discounted})))
-```
-
----
-
-## Toucan Lifecycle Hooks and Model Coupling
-
-Toucan2 lifecycle hooks (`define-before-insert`, `define-after-update`, etc.) are a form of implicit coupling that deserves special consideration.
-
-### The Trade-off
-
-Lifecycle hooks provide **automatic enforcement** - you can't forget to call them - but create **hidden dependencies** that are hard to trace and test.
-
-### When Hooks Work Well
-
-**Use hooks for single-model concerns:**
-
-```clojure
-;; Good - validation and normalization
-(t2/define-before-insert :model/User
- [user]
- (-> user
- (update :email u/lower-case-en)
- (assoc :date_joined (t/offset-date-time))))
-
-;; Good - simple defaults
-(t2/define-before-insert :model/Card
- [card]
- (assoc card :creator_id api/*current-user-id*))
-```
-
-### When Hooks Cause Problems
-
-**Avoid hooks for complex multi-model operations:**
-
-```clojure
-;; Problematic - hidden cross-model coupling
-(t2/define-after-insert :model/User
- [user]
- ;; Caller has no idea this happens
- (t2/insert! :model/AuthIdentity {:user_id (:id user) ...})
- (t2/insert! :model/PermissionsGroupMembership {:user_id (:id user) ...})
- (events/publish-event! :event/user-joined {:user user})
- user)
-```
-
-**Problems with this pattern:**
-- Callers don't know what else happens on insert
-- Hard to create a "bare" user for testing
-- Transaction boundaries are unclear
-- Can cause N+1 queries or circular dependencies
-
-### Better Alternatives
-
-#### 1. Service Functions for Complex Operations
-
-```clojure
-;; Explicit orchestration - caller knows what happens
-(defn create-user!
- "Create a user with all related entities."
- [user-data]
- (t2/with-transaction [_conn]
- (let [user (t2/insert-returning-instance! :model/User user-data)]
- (t2/insert! :model/AuthIdentity {:user_id (:id user) ...})
- (add-to-default-group! user)
- (events/publish-event! :event/user-joined {:user user})
- user)))
-
-;; Keep the hook simple
-(t2/define-before-insert :model/User
- [user]
- (-> user
- (update :email u/lower-case-en)
- (assoc :date_joined (t/offset-date-time))))
-```
-
-#### 2. Events for Async Side Effects
-
-```clojure
-;; Loose coupling via events
-(t2/define-after-insert :model/Card
- [card]
- (events/publish-event! :event/card-create {:object card})
- card)
-
-;; Handlers are separate and testable
-(methodical/defmethod events/publish-event! :event/card-create
- [_topic {:keys [object]}]
- (search/update-index! object)
- (audit/log-create! object))
-```
-
-#### 3. Derived Hooks for Cross-Cutting Concerns
-
-```clojure
-;; Metabase pattern - declare capabilities
-(methodical/defmethod t2/model-hooks :model/Card
- [_model]
- [:hook/timestamped? :hook/entity-id :hook/search-index])
-
-;; Single implementation for all models with this hook
-(t2/define-before-insert :hook/timestamped?
- [instance]
- (assoc instance
- :created_at (t/offset-date-time)
- :updated_at (t/offset-date-time)))
-```
-
-### Coupling Analysis: When to Use What
-
-| Pattern | Use For | Coupling | Testability |
-|---------|---------|----------|-------------|
-| **Lifecycle Hooks** | Validation, defaults, single-model transforms | Tight | Hard |
-| **Service Functions** | Complex multi-model operations | Medium | Good |
-| **Events** | Async side effects (indexing, notifications) | Loose | Good |
-| **Derived Hooks** | Cross-cutting concerns (timestamps, IDs) | Medium | Good |
-
-### Problem Patterns to Avoid
-
-1. **Hidden N+1 queries** - Hook that iterates over related entities
-2. **Circular dependencies** - Model A hook calls Model B which calls Model A
-3. **Transaction ambiguity** - Unclear if hook runs in same transaction
-4. **Requiring-resolve hacks** - Sign of circular dependency
-
-### Recommendations
-
-1. **Keep hooks simple** - Validation and single-model transforms only
-2. **Use service functions** - For anything that touches multiple models
-3. **Use events** - For side effects that don't need to be transactional
-4. **Document what happens** - If a hook does something surprising, document it
-
-```clojure
-;; Good documentation
-(t2/define-after-insert :model/Database
- [database]
- ;; NOTE: This creates DataPermissions entries for ALL groups
- ;; and schedules sync tasks. See `create-database!` for the
- ;; full orchestration.
- (create-default-permissions! database)
- (schedule-sync-tasks! database)
- database)
-```
-
-The goal is **explicit over implicit** - callers should be able to understand what happens when they call `t2/insert!` vs `create-database!`.
-
----
-
-## Best Practices
-
-### Interface Design
-
-1. **Keep interfaces small** - Single-method protocols are easier to extend
-2. **Start with maps** - Graduate to records when needed
-3. **Spec at boundaries** - Not everywhere, just system edges
-4. **Program to abstractions** - Not implementations
-
-### Protocol Usage
-
-```clojure
-;; Good - small, focused
-(defprotocol Nameable (get-name [x]))
-(defprotocol Describable (get-description [x]))
-
-;; Avoid - too broad
-(defprotocol Entity
- (get-name [x])
- (get-description [x])
- (get-id [x])
- (serialize [x]))
-```
-
-### Multimethod Usage
-
-```clojure
-;; Good - simple dispatch
-(defmulti process :type)
-
-;; Avoid - expensive dispatch function
-(defmulti process (fn [x] (expensive-calculation x)))
-
-;; Always provide default
-(defmethod process :default [x]
- (throw (ex-info "Unknown type" {:input x})))
-```
-
-### Spec/Malli Usage
-
-```clojure
-;; Good - at API boundary
-(s/fdef api-handler :args (s/cat :request ::api-request))
-
-;; Avoid - internal implementation
-;; (s/fdef private-helper ...)
-
-;; Don't use spec for coercion (use Malli instead)
-```
-
-### Testing
-
-```clojure
-;; Test with protocol implementations
-(deftest service-test
- (let [mock-db (->MockDatabase (atom {}))]
- (is (valid? (process-data mock-db input)))))
-
-;; Test with spec/malli generators
-(defspec round-trip 100
- (prop/for-all [person (mg/generator Person)]
- (= person (-> person serialize deserialize))))
-```
-
----
-
-## Resources and References
-
-### Official Documentation
-
-- [Clojure Protocols](https://clojure.org/reference/protocols)
-- [Clojure Multimethods](https://clojure.org/reference/multimethods)
-- [Clojure Spec Guide](https://clojure.org/guides/spec)
-
-### Video Talks
-
-| Talk | Speaker | Event | Link |
-|------|---------|-------|------|
-| Protocols and Clojure 1.3 | Rich Hickey | InfoQ 2010 | [Link](https://www.infoq.com/interviews/hickey-clojure-protocols/) |
-| Spec-ulation | Rich Hickey | Clojure/conj 2016 | [Link](https://www.youtube.com/watch?v=oyLBGkS5ICk) |
-| Maybe Not | Rich Hickey | Clojure/conj 2018 | [Link](https://www.youtube.com/watch?v=YR5WdGrpoug) |
-| clojure.spec | Alex Miller | Strange Loop 2016 | [Link](https://www.youtube.com/watch?v=VNTQ-M_uSo8) |
-| Components | Stuart Sierra | Clojure/West 2014 | [Link](https://www.youtube.com/watch?v=av9Xi6CNqq4) |
-
-### Books
-
-- [The Joy of Clojure](https://www.manning.com/books/the-joy-of-clojure-second-edition) - Chapter 9
-- [Clojure for the Brave and True](https://www.braveclojure.com/multimethods-records-protocols/)
-- [Clojure Applied](https://pragprog.com/titles/vmclojeco/clojure-applied/) - Chapters 6 & 7
-
-### Libraries
-
-| Library | Purpose | Link |
-|---------|---------|------|
-| Component | Dependency injection | [GitHub](https://github.com/stuartsierra/component) |
-| Integrant | Data-driven systems | [GitHub](https://github.com/weavejester/integrant) |
-| Mount | Namespace states | [GitHub](https://github.com/tolitius/mount) |
-| Malli | Data schemas | [GitHub](https://github.com/metosin/malli) |
-| Spec-tools | Spec utilities | [GitHub](https://github.com/metosin/spec-tools) |
-| Expound | Better spec errors | [GitHub](https://github.com/bhb/expound) |
-
-### Blog Posts
-
-- [Polymorphic Performance](https://insideclojure.org/2015/04/27/poly-perf/) - Alex Miller
-- [Contrasting Component and Mount](https://yogthos.net/posts/2016-01-19-ContrastingComponentAndMount.html) - Yogthos
-- [Data Validation in Clojure](https://ostash.dev/posts/2021-08-22-data-validation-in-clojure/)
-
----
-
-## Summary
-
-Clojure provides multiple mechanisms for decoupling:
-
-| Mechanism | Use Case | Performance |
-|-----------|----------|-------------|
-| **Protocols** | Type-based dispatch | Excellent |
-| **Multimethods** | Flexible dispatch | Good |
-| **Spec** | Contracts + testing | Good |
-| **Malli** | Schemas + transforms | Excellent |
-| **Component/Integrant/Mount** | System management | N/A |
-
-**Recommendations:**
-
-1. Start with **higher-order functions** for simple DI
-2. Use **protocols** for type-based polymorphism
-3. Use **multimethods** for complex dispatch logic
-4. Use **Malli** for validation with transformation
-5. Use **Spec** for function contracts and generative testing
-6. Choose **Component/Integrant/Mount** based on team preference and app complexity
-
-The key principle: **start simple, add abstraction when needed**. Maps and functions go a long way before you need protocols or multimethods.
diff --git a/OIDC_SECURITY_ANALYSIS.md b/OIDC_SECURITY_ANALYSIS.md
deleted file mode 100644
index 2639aa48277..00000000000
--- a/OIDC_SECURITY_ANALYSIS.md
+++ /dev/null
@@ -1,420 +0,0 @@
-# OIDC Implementation Security Analysis
-
-**Date:** 2026-01-19
-**Scope:** `metabase.sso.oidc.*` and `metabase.sso.providers.oidc`
-
-## Executive Summary
-
-This document provides a security analysis of the OIDC (OpenID Connect) authentication implementation in Metabase. The implementation includes several strong security measures but has areas that require attention, particularly around redirect URL validation and caching mechanisms.
-
----
-
-## High Severity Issues
-
-### 1. Open Redirect Vulnerability - FIXED
-
-**Locations:**
-- `src/metabase/sso/oidc/state.clj:70-111` (validation functions)
-- `src/metabase/sso/oidc/state.clj:136` (validation call in create-oidc-state)
-
-**Description:**
-
-~~The redirect URL stored in the encrypted state cookie is used directly after authentication completes without validation.~~
-
-**FIXED:** The `create-oidc-state` function now validates redirect URLs before storing them. The validation:
-- Accepts relative URLs starting with `/` (but rejects protocol-relative URLs like `//evil.com`)
-- Accepts absolute URLs only if they have the same origin as the configured `site-url`
-- Rejects all other URLs including `javascript:`, `data:`, and external domains
-
-**Implementation:**
-
-```clojure
-;; New validation functions added to state.clj:
-(defn valid-redirect-url?
- "Validates that a redirect URL is safe for use after OIDC authentication."
- ([redirect-url] (valid-redirect-url? redirect-url (system.settings/site-url)))
- ([redirect-url site-url]
- (cond
- (or (nil? redirect-url) (str/blank? redirect-url)) false
- (relative-url? redirect-url) true ; /path is OK, //evil.com is not
- :else (same-origin? redirect-url site-url))))
-
-;; Validation is called in create-oidc-state:
-(validate-redirect-url! redirect) ; throws on invalid URL
-```
-
-**Tests:** See `test/metabase/sso/oidc/state_test.clj`:
-- `valid-redirect-url-test` - comprehensive URL validation tests
-- `create-oidc-state-rejects-invalid-redirects-test` - integration tests for rejection
-- `wrap-oidc-redirect-test` - tests open redirect protection in high-level API
-
----
-
-## Medium Severity Issues
-
-### 2. JWKS Cache Has No Expiration - FIXED
-
-**Location:** `src/metabase/sso/oidc/tokens.clj:11-45`
-
-**Description:**
-
-~~The JWKS (JSON Web Key Set) cache is implemented as a simple atom with no TTL or size limits.~~
-
-**FIXED:** The JWKS cache now includes TTL-based expiration:
-
-- Cache entries expire after 1 hour (3600000 ms)
-- Expired entries trigger automatic re-fetch from the IdP
-- New `invalidate-jwks-cache!` function allows manual cache invalidation for specific URIs
-
-**Implementation:**
-
-```clojure
-(def ^:private jwks-cache
- "Cache of JWKS with TTL. Map of JWKS URI string -> {:jwks map :fetched-at timestamp}."
- (atom {}))
-
-(def ^:private jwks-cache-ttl-ms
- "JWKS cache TTL: 1 hour."
- 3600000)
-
-(defn- cache-expired? [cache-entry]
- (or (nil? cache-entry)
- (nil? (:fetched-at cache-entry))
- (> (- (System/currentTimeMillis) (:fetched-at cache-entry))
- jwks-cache-ttl-ms)))
-
-(defn invalidate-jwks-cache! [jwks-uri]
- "Invalidate cached JWKS for a specific URI."
- (swap! jwks-cache dissoc jwks-uri))
-```
-
-**Tests:** See `test/metabase/sso/oidc/tokens_test.clj`:
-- `jwks-cache-uses-cached-entry-when-fresh-test`
-- `jwks-cache-refetches-when-expired-test`
-- `invalidate-jwks-cache-test`
-
----
-
-### 3. Discovery Document Cache Has No Expiration - FIXED
-
-**Location:** `src/metabase/sso/oidc/discovery.clj:11-14`
-
-**Description:**
-
-~~Similar to the JWKS cache, the discovery document cache has no TTL.~~
-
-**FIXED:** The discovery document cache now includes TTL-based expiration:
-
-- Cache entries expire after 24 hours (86400000 ms)
-- Expired entries trigger automatic re-fetch from the IdP
-- New `invalidate-cache!` function allows manual cache invalidation for specific issuers
-- Cache refresh events are logged for audit purposes
-
-**Implementation:**
-
-```clojure
-(def ^:private discovery-cache
- "Cache of discovery documents with TTL.
- Map of issuer URL string -> {:document discovery-map :fetched-at timestamp}."
- (atom {}))
-
-(def ^:private discovery-cache-ttl-ms
- "Discovery document cache TTL: 24 hours."
- 86400000)
-
-(defn- cache-expired? [cache-entry]
- (or (nil? cache-entry)
- (nil? (:fetched-at cache-entry))
- (> (- (System/currentTimeMillis) (:fetched-at cache-entry))
- discovery-cache-ttl-ms)))
-
-(defn invalidate-cache! [issuer]
- "Invalidate cached discovery document for a specific issuer."
- (let [normalized (normalize-issuer issuer)]
- (swap! discovery-cache dissoc normalized)
- (log/infof "Invalidated discovery cache for issuer %s" normalized)))
-```
-
-**Tests:** See `test/metabase/sso/oidc/discovery_test.clj`:
-- `discovery-cache-uses-cached-entry-when-fresh-test`
-- `discovery-cache-refetches-when-expired-test`
-- `invalidate-discovery-cache-test`
-- `invalidate-discovery-cache-with-trailing-slash-test`
-
----
-
-### 4. Missing SSRF Protection on External URL Fetches
-
-**Locations:**
-- `src/metabase/sso/oidc/discovery.clj:27-46`
-- `src/metabase/sso/oidc/tokens.clj:20-33`
-
-**Description:**
-
-When fetching discovery documents and JWKS, there's no validation preventing requests to internal network addresses:
-
-```clojure
-;; discovery.clj
-(http/get url {:as :json ...})
-
-;; tokens.clj
-(http/get jwks-uri {:as :json ...})
-```
-
-**Security Impact:**
-
-A malicious or compromised issuer configuration could:
-- Make requests to internal services (SSRF)
-- Probe internal network topology
-- Access cloud metadata endpoints (e.g., `169.254.169.254`)
-
-**Recommendation:**
-
-Use the existing `metabase.util.http/valid-host?` function:
-
-```clojure
-(require '[metabase.util.http :as u.http])
-
-(defn- fetch-discovery-document [issuer]
- (let [url (discovery-url issuer)]
- (when-not (u.http/valid-host? :external-only url)
- (throw (ex-info "Invalid issuer URL: internal addresses not allowed" {:url url})))
- ;; ... existing fetch logic
- ))
-```
-
----
-
-### 5. No PKCE Support
-
-**Locations:**
-- `src/metabase/sso/providers/oidc.clj:54-83`
-- `src/metabase/sso/oidc/common.clj:29-49`
-
-**Description:**
-
-PKCE (Proof Key for Code Exchange) is not implemented. The authorization flow uses only the basic authorization code flow without code challenge/verifier.
-
-**Security Impact:**
-
-- Authorization code interception attacks are possible if an attacker can observe the callback URL
-- OAuth 2.1 and current OIDC best practices recommend PKCE for all clients
-- Some IdPs may require PKCE
-
-**Recommendation:**
-
-Add PKCE support:
-
-```clojure
-;; In common.clj
-(defn generate-code-verifier
- "Generate a cryptographically random code verifier for PKCE."
- []
- (-> (nonce/random-bytes 32) codecs/bytes->b64-str
- (str/replace #"\+" "-")
- (str/replace #"/" "_")
- (str/replace #"=" "")))
-
-(defn generate-code-challenge
- "Generate S256 code challenge from verifier."
- [verifier]
- (-> verifier
- codecs/str->bytes
- (buddy.core.hash/sha256)
- codecs/bytes->b64-str
- (str/replace #"\+" "-")
- (str/replace #"/" "_")
- (str/replace #"=" "")))
-
-;; Add to authorization URL params:
-{:code_challenge (generate-code-challenge code-verifier)
- :code_challenge_method "S256"}
-
-;; Store code_verifier in state cookie, include in token exchange
-```
-
----
-
-### 6. Hardcoded RS256 Algorithm
-
-**Location:** `src/metabase/sso/oidc/tokens.clj:74`
-
-**Description:**
-
-The JWT verification algorithm is hardcoded to RS256:
-
-```clojure
-(jwt/unsign token public-key {:alg :rs256})
-```
-
-**Security Impact:**
-
-- Some IdPs use different algorithms (RS384, RS512, ES256)
-- The JWK's `alg` field is not validated against the token's algorithm
-- Could lead to interoperability issues or security misconfigurations
-
-**Recommendation:**
-
-```clojure
-(def ^:private allowed-algorithms
- "Allowlist of acceptable JWT signing algorithms."
- #{:rs256 :rs384 :rs512 :es256 :es384 :es512})
-
-(defn- get-algorithm [key-data]
- (let [alg (-> key-data :alg str/lower-case keyword)]
- (when-not (contains? allowed-algorithms alg)
- (throw (ex-info "Unsupported JWT algorithm" {:algorithm alg})))
- alg))
-
-;; In verify-signature:
-(let [alg (get-algorithm key-data)
- public-key (keys/jwk->public-key key-data)]
- (jwt/unsign token public-key {:alg alg}))
-```
-
----
-
-## Low Severity Issues
-
-### 7. Missing Token Time Validations
-
-**Location:** `src/metabase/sso/oidc/tokens.clj:128-166`
-
-**Description:**
-
-Token validation checks `exp` (expiry) but not:
-- `iat` (issued at) - tokens issued far in the past could indicate replay
-- `nbf` (not before) - respecting intended activation time
-- `auth_time` - for session freshness requirements
-
-**Recommendation:**
-
-```clojure
-(defn validate-issued-at
- "Validate that the token was issued recently (within acceptable window)."
- [claims max-age-seconds]
- (when-let [iat (:iat claims)]
- (let [now (quot (System/currentTimeMillis) 1000)
- age (- now iat)]
- (and (>= age 0) (<= age max-age-seconds)))))
-
-(defn validate-not-before
- "Validate that the token is active (current time >= nbf)."
- [claims]
- (if-let [nbf (:nbf claims)]
- (let [now (quot (System/currentTimeMillis) 1000)]
- (>= now nbf))
- true)) ; nbf is optional
-```
-
----
-
-### 8. Missing `azp` Claim Validation
-
-**Location:** `src/metabase/sso/oidc/tokens.clj:102-115`
-
-**Description:**
-
-When the audience (`aud`) claim is an array with multiple values, the OIDC spec recommends validating the `azp` (authorized party) claim equals the client_id.
-
-**Recommendation:**
-
-```clojure
-(defn validate-authorized-party
- "Validate azp claim when aud is multi-valued."
- [claims expected-client-id]
- (let [aud (:aud claims)
- azp (:azp claims)]
- (if (and (sequential? aud) (> (count aud) 1))
- (= azp expected-client-id)
- true))) ; azp validation only required for multi-valued aud
-```
-
----
-
-### 9. Potential Sensitive Data in Error Logs
-
-**Location:** `src/metabase/sso/providers/oidc.clj:79`
-
-**Description:**
-
-Token exchange error responses are logged in their entirety:
-
-```clojure
-(log/errorf "Token exchange failed: %s" (:body response))
-```
-
-Some IdP implementations may include sensitive information in error responses.
-
-**Recommendation:**
-
-Log only sanitized error information:
-
-```clojure
-(log/errorf "Token exchange failed: error=%s description=%s"
- (get-in response [:body :error])
- (get-in response [:body :error_description]))
-```
-
----
-
-### 10. SameSite=Lax Cookie Consideration
-
-**Location:** `src/metabase/sso/oidc/state.clj:141-146`
-
-**Description:**
-
-The state cookie uses `SameSite=Lax`, which is required for OIDC flows (the cookie must be sent on the redirect back from the IdP). However, this means the cookie will be sent on top-level GET navigations from other sites.
-
-**Impact:**
-
-This is acceptable and necessary for OIDC but should be documented. The 10-minute TTL and cryptographic state validation mitigate most risks.
-
-**Recommendation:**
-
-- Document this trade-off in security documentation
-- Ensure state TTL remains short (current 10 minutes is appropriate)
-- Consider reducing TTL further if possible (e.g., 5 minutes)
-
----
-
-## Positive Security Findings
-
-The implementation includes several strong security measures:
-
-| Feature | Implementation | Assessment |
-|---------|---------------|------------|
-| State Encryption | AES256-CBC-HMAC-SHA512 | Strong |
-| Key Derivation | PBKDF2+SHA512 with 100k iterations | Strong |
-| CSRF Protection | Cryptographically random state parameter | Correct |
-| Nonce Validation | Prevents token replay | Correct |
-| State TTL | 10-minute expiration | Appropriate |
-| Issuer Validation | Exact match required | Correct |
-| Audience Validation | Supports string and array formats | Correct |
-| Cookie Security | HttpOnly, Secure (on HTTPS), path-restricted | Correct |
-| Encryption Requirement | Enforces `MB_ENCRYPTION_SECRET_KEY` | Good |
-
----
-
-## Remediation Priority
-
-| Priority | Issue | Effort | Status |
-|----------|-------|--------|--------|
-| 1 | Open Redirect Vulnerability | Low | **FIXED** |
-| 2 | JWKS Cache Expiration | Medium | **FIXED** |
-| 3 | SSRF Protection | Low | Open |
-| 4 | Discovery Cache Expiration | Medium | **FIXED** |
-| 5 | PKCE Support | Medium | Open |
-| 6 | Algorithm Flexibility | Low | Open |
-| 7 | Token Time Validations | Low | Open |
-| 8 | azp Claim Validation | Low | Open |
-| 9 | Log Sanitization | Low | Open |
-
----
-
-## References
-
-- [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html)
-- [OAuth 2.0 Security Best Current Practice](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics)
-- [PKCE RFC 7636](https://datatracker.ietf.org/doc/html/rfc7636)
-- [OWASP Authentication Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html)
diff --git a/PLAN_frontend_snippet_dirty_state.md b/PLAN_frontend_snippet_dirty_state.md
deleted file mode 100644
index 9a5fe608bc7..00000000000
--- a/PLAN_frontend_snippet_dirty_state.md
+++ /dev/null
@@ -1,109 +0,0 @@
-# Plan: Frontend Snippet Dirty State Refresh
-
-## Overview
-
-Implement declarative support for refreshing dirty status when snippets are created/updated/deleted in the frontend. This ensures snippet dirty state is properly reflected as library dirty state.
-
-## Background
-
-### Current State
-- Backend support for snippet remote sync was added in commit `d7bfe1a05af`
-- Snippets live in collections with `namespace: "snippets"` - NOT within the Library collection hierarchy
-- The Library section in the UI displays snippets, so snippet dirty state should show as Library dirty
-
-### What Was Missing
-1. **Snippets not in `MODEL_MUTATION_CONFIGS`** - Snippet mutations didn't trigger dirty state invalidation
-2. **`useHasLibraryDirtyChanges` didn't check snippets** - It only checked the Library collection tree, not snippets-namespace collections
-
-## Implementation
-
-### Change 1: Add Snippet to Model Mutation Configs
-
-**File**: `enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/model-configs.ts`
-
-Added import for `snippetApi` and snippet config to `MODEL_MUTATION_CONFIGS`:
-
-```typescript
-import { snippetApi } from "metabase/api/snippet";
-
-// In MODEL_MUTATION_CONFIGS array:
-{
- modelType: "snippet",
- createEndpoints: [snippetApi.endpoints.createSnippet.matchFulfilled],
- updateEndpoints: [snippetApi.endpoints.updateSnippet.matchFulfilled],
- invalidation: { type: InvalidationType.Always },
-},
-```
-
-This ensures:
-- When `createSnippet` or `updateSnippet` mutations complete, dirty state tags are invalidated
-- Snippet archiving (deletion) uses `updateSnippet` with `archived: true`, so it's covered
-
-### Change 2: Update Library Dirty Changes Hook
-
-**File**: `enterprise/frontend/src/metabase-enterprise/remote_sync/hooks/use-has-library-dirty-changes.ts`
-
-Updated to also check for dirty snippets and snippets-namespace collections:
-
-1. Added fetch for snippets-namespace collections:
- ```typescript
- const { data: snippetsCollections = [] } = useListCollectionsTreeQuery(
- { namespace: "snippets" },
- { skip: !isGitSyncVisible },
- );
- ```
-
-2. Added check for dirty snippets before checking Library tree:
- ```typescript
- const hasSnippetDirtyChanges = dirty.some((entity) => {
- if (entity.model === "snippet") {
- return true;
- }
- if (
- entity.model === "collection" &&
- numericSnippetCollectionIds.has(entity.id)
- ) {
- return true;
- }
- return false;
- });
-
- if (hasSnippetDirtyChanges) {
- return true;
- }
- ```
-
-## Files Changed
-
-| File | Change |
-|------|--------|
-| `enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/model-configs.ts` | Add snippetApi import and snippet config |
-| `enterprise/frontend/src/metabase-enterprise/remote_sync/hooks/use-has-library-dirty-changes.ts` | Add snippet dirty state detection |
-
-## How It Works
-
-1. User creates/updates/archives a snippet
-2. RTK Query mutation completes (`createSnippet.matchFulfilled` or `updateSnippet.matchFulfilled`)
-3. Listener middleware detects the mutation via `MODEL_MUTATION_CONFIGS`
-4. Middleware invalidates `REMOTE_SYNC_INVALIDATION_TAGS` (including `collection-dirty-entities`)
-5. `useRemoteSyncDirtyState` refetches dirty entities from `/api/ee/remote-sync/dirty`
-6. `useHasLibraryDirtyChanges` checks if any dirty entity is:
- - A snippet (`model === "snippet"`)
- - A collection in the snippets namespace
- - An entity in the Library collection tree
-7. If any match, Library shows as dirty in the UI
-
-## Testing
-
-### Manual Testing Steps
-1. Enable remote sync on Library collection
-2. Create a new snippet in the SQL editor or Data Studio
-3. Verify Library shows dirty indicator
-4. Update an existing snippet
-5. Verify Library shows dirty indicator
-6. Archive a snippet
-7. Verify Library shows dirty indicator
-8. Export changes
-9. Verify dirty indicators clear
-
-## Status: IMPLEMENTED
diff --git a/PLAN_memoize_default_secret_key.md b/PLAN_memoize_default_secret_key.md
deleted file mode 100644
index 001954c505e..00000000000
--- a/PLAN_memoize_default_secret_key.md
+++ /dev/null
@@ -1,108 +0,0 @@
-# Plan: Convert `default-secret-key` to Memoized Function
-
-## Goal
-Convert `default-secret-key` from a `defonce` binding to a memoized function so the value can be recalculated when `env/env` changes (e.g., during testing).
-
-## File to Modify
-- `/Users/edwardpaget/Projects/metabase/src/metabase/util/encryption.clj`
-
-## Implementation Steps
-
-### Step 1: Change `defonce` to a memoized function
-
-Replace:
-```clojure
-(def ^:private ^{:tag 'bytes} default-secret-key
- (validate-and-hash-secret-key (env/env :mb-encryption-secret-key)))
-```
-
-With:
-```clojure
-(def ^:private default-secret-key*
- "Memoized function that hashes the secret key. Takes the raw key as argument
- so memoization correctly detects when the env value changes."
- (memoize
- (fn [secret-key-from-env]
- (validate-and-hash-secret-key secret-key-from-env))))
-
-(defn ^:private default-secret-key
- "Returns the hashed default encryption secret key, memoized for performance.
- Automatically recalculates if the env var value changes."
- ^bytes []
- (default-secret-key* (env/env :mb-encryption-secret-key)))
-```
-
-**Key insight**: By passing `(env/env :mb-encryption-secret-key)` as an argument to the memoized function, the memoization will automatically return the cached value when the env value is the same, but recompute when it changes. No manual cache clearing needed for env changes.
-
-### Step 2: (Optional) Add a function to reset the memoization cache
-
-Since the memoization now keys on the env value itself, the cache will automatically recompute when the env changes. However, we may still want a reset function for testing edge cases (e.g., clearing all cached entries):
-
-```clojure
-(defn reset-default-secret-key!
- "Clears all memoized secret key hashes. Normally not needed since the cache
- automatically handles env changes, but useful for testing."
- []
- (memoize/memo-clear! default-secret-key*))
-```
-
-This requires adding `[clojure.core.memoize :as memoize]` to the requires. **This step is optional** - we can skip it if tests don't require clearing the entire cache.
-
-### Step 3: Update all usages to call it as a function
-
-Replace all occurrences of `default-secret-key` with `(default-secret-key)`:
-
-| Line | Current | Updated |
-|------|---------|---------|
-| 62 | `(boolean default-secret-key)` | `(boolean (default-secret-key))` |
-| 67 | `(if default-secret-key` | `(if (default-secret-key)` |
-| 68-70 | `(if default-secret-key "..." "...")` | `(if (default-secret-key) "..." "...")` |
-| 79 | `(encrypt-bytes default-secret-key b)` | `(encrypt-bytes (default-secret-key) b)` |
-| 93 | `(encrypt default-secret-key s)` | `(encrypt (default-secret-key) s)` |
-| 104 | `(decrypt-bytes default-secret-key b)` | `(decrypt-bytes (default-secret-key) b)` |
-| 117 | `(encrypt-stream default-secret-key input-stream)` | `(encrypt-stream (default-secret-key) input-stream)` |
-| 130 | `(encrypt-for-stream default-secret-key input)` | `(encrypt-for-stream (default-secret-key) input)` |
-| 139 | `(maybe-decrypt-stream default-secret-key input-stream)` | `(maybe-decrypt-stream (default-secret-key) input-stream)` |
-| 164 | `(decrypt default-secret-key s)` | `(decrypt (default-secret-key) s)` |
-| 171 | `(maybe-encrypt default-secret-key s)` | `(maybe-encrypt (default-secret-key) s)` |
-| 183 | `(maybe-encrypt-bytes default-secret-key b)` | `(maybe-encrypt-bytes (default-secret-key) b)` |
-| 193 | `(maybe-encrypt-for-stream default-secret-key s)` | `(maybe-encrypt-for-stream (default-secret-key) s)` |
-| 235 | `(cons default-secret-key args)` | `(cons (default-secret-key) args)` |
-
-### Step 4: (Only if Step 2 is included) Add require for clojure.core.memoize
-
-If adding the `reset-default-secret-key!` function, add to the `:require` block:
-```clojure
-[clojure.core.memoize :as memoize]
-```
-
-Note: `clojure.core/memoize` (used in Step 1) is built-in and requires no import. Only `clojure.core.memoize` (the contrib library) is needed for `memo-clear!`.
-
-## Verification
-
-1. Run the encryption tests:
- ```
- clojure -X:dev:test :only metabase.util.encryption-test
- ```
-
-2. Test that memoization automatically detects env changes:
- ```clojure
- ;; In REPL
- (require '[metabase.util.encryption :as encryption])
- (require '[environ.core :as env])
-
- ;; Check initial state (probably false if no key set)
- (encryption/default-encryption-enabled?)
-
- ;; Set a new key
- (alter-var-root #'env/env assoc :mb-encryption-secret-key "some-test-key-16chars")
-
- ;; Should now return true - memoization detects the env change automatically
- (encryption/default-encryption-enabled?)
-
- ;; Remove the key
- (alter-var-root #'env/env dissoc :mb-encryption-secret-key)
-
- ;; Should return false again
- (encryption/default-encryption-enabled?)
- ```
diff --git a/PLAN_optimize_can_run_adhoc_query.md b/PLAN_optimize_can_run_adhoc_query.md
deleted file mode 100644
index 11d7ecc74e1..00000000000
--- a/PLAN_optimize_can_run_adhoc_query.md
+++ /dev/null
@@ -1,231 +0,0 @@
-# Plan: Optimize `can_run_adhoc_query` Computation
-
-## Summary
-
-Optimize `can_run_adhoc_query` computation for both OSS and EE by avoiding expensive query preprocessing.
-
-**Current cost:** N cards × full query preprocessing (~3-15ms each)
-**Proposed cost:**
-- **OSS:** Extract source card IDs (lightweight) + DB-level permission check
-- **EE:** 1 recursive SQL query against dependency table
-
-## OSS Optimization
-
-On OSS, table-level blocking doesn't exist. The permission model simplifies to:
-
-| Check | What's Required |
-|-------|-----------------|
-| Source cards | Collection read permission |
-| Database | `create-queries` ≠ `:no` (`:query-builder` for MBQL, `:query-builder-and-native` for native) |
-
-**Key insight:** We can use `lib/all-source-card-ids` to extract card references without full `preprocess-query`. This walks the query AST but doesn't expand source cards or resolve tables.
-
-```clojure
-;; Lightweight extraction (no preprocessing)
-(lib/all-source-card-ids query) ;; → #{card-id ...}
-(lib/any-native-stage? query) ;; → boolean
-```
-
-## EE Optimization (with Dependencies Feature)
-
-| Dependency Path | Permission Required |
-|-----------------|---------------------|
-| Card → Table (direct) | view-data + create-queries |
-| Card → Card | collection read |
-| Card → Card → Table (transitive) | view-data only |
-
-The `is_direct` flag in the recursive CTE distinguishes direct vs transitive table dependencies.
-
-## Files to Create
-
-### 1. `enterprise/backend/src/metabase_enterprise/queries/adhoc_query_perms.clj`
-
-EE implementation using recursive CTE against dependency table.
-
-### 2. `enterprise/backend/test/metabase_enterprise/queries/adhoc_query_perms_test.clj`
-
-Test coverage for EE-specific behavior (recursive CTE, staleness fallback).
-
-## Files to Modify
-
-### 1. `src/metabase/queries/models/card.clj`
-
-**Change:** Replace expensive `query-perms/can-run-query?` with lightweight check
-
-```clojure
-;; NEW: Lightweight OSS permission check (no query preprocessing)
-(defn- can-run-adhoc-query-oss?
- "Check if current user can run ad-hoc query for card.
- Lightweight: extracts source cards without full query preprocessing."
- [{:keys [database_id dataset_query]}]
- (let [query (lib/query (lib-be/application-database-metadata-provider database_id)
- dataset_query)
- source-card-ids (lib/all-source-card-ids query)
- native? (lib/any-native-stage? query)
- required-perm (if native? :query-builder-and-native :query-builder)]
- (and
- ;; User has query permission on the database
- (not= :no (perms/full-db-permission-for-user
- api/*current-user-id* :perms/create-queries database_id))
- (or (not native?)
- (= required-perm (perms/full-db-permission-for-user
- api/*current-user-id* :perms/create-queries database_id)))
- ;; User can read all source cards
- (every? mi/can-read?
- (when (seq source-card-ids)
- (t2/select :model/Card :id [:in source-card-ids]))))))
-
-;; defenterprise wrapper for EE override
-(defenterprise compute-can-run-adhoc-query-batch
- "Compute can_run_adhoc_query for a batch of cards."
- metabase-enterprise.queries.adhoc-query-perms
- [cards]
- ;; OSS: use lightweight check
- (into {}
- (map (fn [{card-id :id :as card}]
- [card-id (can-run-adhoc-query-oss? card)]))
- (filter (comp seq :dataset_query) cards)))
-
-;; Simplify with-can-run-adhoc-query - remove expensive prefetching
-(mu/defn with-can-run-adhoc-query
- [cards :- [:maybe [:sequential ::queries.schema/card]]]
- (perms/prime-db-cache (into #{} (map :database_id cards)))
- (mi/instances-with-hydrated-data
- cards :can_run_adhoc_query
- #(compute-can-run-adhoc-query-batch (filter (comp seq :dataset_query) cards))
- :id
- {:default false}))
-```
-
-## Recursive CTE Query
-
-```clojure
-(defn transitive-deps-for-cards-query
- "Build HoneySQL query for transitive dependencies with directness tracking."
- [card-ids]
- {:with-recursive
- [[[:transitive_deps {:columns [:start_card_id :to_entity_type :to_entity_id :is_direct_table]}]
- {:union-all
- [;; Base case: direct dependencies
- {:select [[:from_entity_id :start_card_id]
- :to_entity_type
- :to_entity_id
- [[:case [:= :to_entity_type [:inline "table"]]
- [:inline 1]
- :else [:inline 0]]
- :is_direct_table]]
- :from [:dependency]
- :where [:and
- [:= :from_entity_type [:inline "card"]]
- [:in :from_entity_id card-ids]]}
- ;; Recursive case: follow card->X edges
- {:select [:td.start_card_id
- :d.to_entity_type
- :d.to_entity_id
- [[:inline 0] :is_direct_table]]
- :from [[:dependency :d]]
- :join [[:transitive_deps :td]
- [:and
- [:= :d.from_entity_type :td.to_entity_type]
- [:= :d.from_entity_id :td.to_entity_id]]]
- :where [:= :td.to_entity_type [:inline "card"]]}]}]]
- :select [:start_card_id :to_entity_type :to_entity_id
- [[:max :is_direct_table] :is_direct]]
- :from [:transitive_deps]
- :group-by [:start_card_id :to_entity_type :to_entity_id]})
-```
-
-## Staleness Handling
-
-Check `dependency_analysis_version` and fall back to OSS for stale cards:
-
-```clojure
-(defn- partition-by-staleness
- "Split card IDs into fresh (use deps) and stale (use fallback)."
- [card-ids]
- (let [current-version models.dependency/current-dependency-analysis-version
- stale-ids (t2/select-fn-set :id :model/Card
- :id [:in card-ids]
- :dependency_analysis_version [:< current-version])]
- {:fresh (remove stale-ids card-ids)
- :stale stale-ids}))
-```
-
-## Native Query Handling
-
-Native queries are handled by checking `dataset_query` type:
-
-```clojure
-(defn- native-query? [card]
- (= :native (-> card :dataset_query :type)))
-
-(defn- has-native-perms? [db-id]
- (= :query-builder-and-native
- (perms/full-db-permission-for-user
- api/*current-user-id* :perms/create-queries db-id)))
-```
-
-Native queries require `create-queries: :query-builder-and-native` on the database regardless of table dependencies.
-
-## Integration with Block Permissions
-
-The existing `check-block-permissions` middleware (EE) checks view-data on ALL tables in the preprocessed query. Our optimization handles the same tables via the transitive dependency graph, so block permissions will be respected.
-
-## Feature Gating
-
-```clojure
-(defenterprise compute-can-run-adhoc-query-batch
- "..."
- metabase-enterprise.queries.adhoc-query-perms
- :feature :dependencies ;; Requires dependencies premium feature
- [cards]
- ;; OSS fallback
- ...)
-```
-
-## Implementation Steps
-
-### Phase 1: OSS Optimization
-1. **Add `can-run-adhoc-query-oss?`** - lightweight check using `lib/all-source-card-ids`
-2. **Wrap in `defenterprise`** for EE override
-3. **Simplify `with-can-run-adhoc-query`** - remove expensive prefetching
-4. **Write tests** for OSS permission scenarios
-5. **Benchmark** OSS improvement
-
-### Phase 2: EE Optimization (requires dependencies feature)
-1. **Create EE namespace** with recursive CTE query builder
-2. **Implement EE version** with:
- - Transitive deps fetch via CTE
- - Direct vs transitive table permission checks
- - Staleness detection and fallback
-3. **Write EE tests** covering dependency graph scenarios
-4. **Benchmark** EE improvement vs OSS
-
-## Verification
-
-### OSS Tests
-1. Card with no source cards → check DB permission only
-2. Card with source cards → check collection read + DB permission
-3. Native query → requires `:query-builder-and-native`
-4. User blocked from DB → returns false
-5. User can't read source card → returns false
-
-### EE Tests
-1. Direct table dependency → needs view-data + create-queries
-2. Transitive table dependency → needs view-data only
-3. Stale dependency_analysis_version → falls back to OSS
-4. Recursive CTE handles deep card chains (A → B → C → table)
-
-### Performance
-```clojure
-;; Benchmark with 500 cards
-(time (t2/hydrate cards :can_run_adhoc_query))
-;; Before: ~2-4 seconds
-;; After OSS: ~200-400ms (no preprocessing)
-;; After EE: ~50-100ms (single CTE)
-```
-
-### Manual Testing
-- GET `/api/collection/:id/items?models=card&include_can_run_adhoc_query=true`
-- Verify correct permissions with large collection (500+ cards)
-- Check SQL logs: should see 1 CTE query (EE) or N lightweight queries (OSS), not N preprocessing calls
diff --git a/PLAN_python_library_remote_sync.md b/PLAN_python_library_remote_sync.md
deleted file mode 100644
index 9c7e7535be9..00000000000
--- a/PLAN_python_library_remote_sync.md
+++ /dev/null
@@ -1,285 +0,0 @@
-# Plan: Remote-Sync Support for PythonLibrary
-
-## Overview
-
-This plan implements remote-sync support for the `PythonLibrary` entity, enabling Python libraries (reusable code for Python transforms) to be synchronized with a Git repository.
-
-## Background
-
-### Current PythonLibrary State
-- **Model**: `:model/PythonLibrary` (table: `python_library`)
-- **Identity**: Path-based (unique `path` column, currently only supports `common.py`)
-- **Fields**: `id`, `path`, `source`, `created_at`, `updated_at`
-- **Serialization**: Explicitly excluded in `excluded-models`
-- **Access**: Superuser-only
-- **Feature flag**: `transforms-python` premium feature
-
-### Remote-Sync Pattern Requirements
-Based on similar entities (Transforms, NativeQuerySnippets), PythonLibrary needs:
-1. Backend spec definition in `spec.clj`
-2. Serialization support (currently excluded)
-3. Event handling for create/update/delete
-4. Frontend type and config updates
-
-## Design Decisions
-
-### Identity Strategy: `:path`
-Since PythonLibrary uses `path` as its unique identifier (not `entity_id`), use path-based identity similar to Table/Field models.
-
-### Eligibility: Setting-based (tied to transforms)
-PythonLibrary is tightly coupled with Python transforms. Use the existing `remote-sync-transforms` setting to control eligibility - when transforms are synced, so are their associated libraries.
-
-### Export Path Type: `:python-library-path`
-New path type exporting to `python-libraries/{path}.yaml` structure.
-
-### Export Scope: `:all`
-Global scope - export all PythonLibrary instances (similar to TransformTag/NativeQuerySnippet).
-
----
-
-## Implementation Steps
-
-### Phase 1: Backend - Serialization Support
-
-#### Step 1.1: Add PythonLibrary to serialization models list
-**File**: `enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj`
-
-- Remove `PythonLibrary` from `excluded-models` list
-- Add `:model/PythonLibrary` to the models list (likely in a transforms-related section)
-
-#### Step 1.2: Implement serialization methods for PythonLibrary
-**File**: `enterprise/backend/src/metabase_enterprise/transforms_python/models/python_library.clj`
-
-Add serdes methods:
-```clojure
-(defmethod serdes/hash-fields :model/PythonLibrary [_model] [:path])
-
-(defmethod serdes/make-spec "PythonLibrary" [_model-name _opts]
- {:copy [:path :source]})
-
-(defmethod serdes/entity-id :model/PythonLibrary [{:keys [path]}] path)
-
-(defmethod serdes/generate-path :model/PythonLibrary [_ {:keys [path]}]
- [{:model "PythonLibrary" :id path}])
-```
-
-#### Step 1.3: Implement serdes ingestion methods
-**File**: `enterprise/backend/src/metabase_enterprise/transforms_python/models/python_library.clj`
-
-Add ingestion support:
-```clojure
-(defmethod serdes/load-xform "PythonLibrary" [entity]
- (-> entity
- (dissoc :serdes/meta)
- (assoc :path (-> entity :serdes/meta first :id))))
-
-(defmethod serdes/load-find-local "PythonLibrary" [path]
- (t2/select-one :model/PythonLibrary :path (-> path last :id)))
-
-(defmethod serdes/load-update! "PythonLibrary" [_model-name ingested local]
- (t2/update! :model/PythonLibrary (:id local) ingested))
-
-(defmethod serdes/load-insert! "PythonLibrary" [_model-name ingested]
- (t2/insert-returning-instance! :model/PythonLibrary ingested))
-```
-
----
-
-### Phase 2: Backend - Remote-Sync Spec
-
-#### Step 2.1: Add PythonLibrary spec to remote-sync
-**File**: `enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj`
-
-Add spec definition:
-```clojure
-:model/PythonLibrary
-{:model-type "PythonLibrary"
- :model-key :model/PythonLibrary
- :identity :path
- :events {:prefix :event/python-library
- :types [:create :update :delete]}
- :eligibility {:type :setting
- :setting :remote-sync-transforms}
- :archived-key nil ; PythonLibrary has no archived state
- :tracking {:select-fields [:path]
- :field-mappings {:model_name :path}}
- :removal {:statuses #{"removed"}
- :scope-key nil} ; global scope
- :export-path {:type :python-library-path}
- :export-scope :all
- :enabled? :remote-sync-transforms}
-```
-
-#### Step 2.2: Implement python-library-path export path type
-**File**: `enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj`
-
-Add path generation method:
-```clojure
-(defmethod export-path-segments :python-library-path
- [_type {:keys [path]}]
- ["python-libraries" (str (str/replace path #"\.py$" "") ".yaml")])
-```
-
-#### Step 2.3: Add path identity handler if needed
-**File**: `enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj`
-
-Verify that the `:path` identity type properly handles PythonLibrary's path-based identification:
-```clojure
-(defmethod get-model-identity :path
- [spec instance]
- ;; May need to handle PythonLibrary specifically or ensure generic path handling works
- ...)
-```
-
----
-
-### Phase 3: Backend - Event Handling
-
-#### Step 3.1: Add PythonLibrary events to the events system
-**File**: `enterprise/backend/src/metabase_enterprise/transforms_python/models/python_library.clj`
-
-Add event publication on model changes:
-```clojure
-(t2/define-after-insert :model/PythonLibrary [library]
- (events/publish-event! :event/python-library-create library)
- library)
-
-(t2/define-after-update :model/PythonLibrary [library]
- (events/publish-event! :event/python-library-update library)
- library)
-
-(t2/define-after-delete :model/PythonLibrary [library]
- (events/publish-event! :event/python-library-delete library))
-```
-
-#### Step 3.2: Verify event registration in remote-sync
-The spec-driven event system should automatically register handlers based on the spec's `:events` configuration. Verify that `register-events-for-spec!` properly handles the new PythonLibrary spec.
-
----
-
-### Phase 4: Frontend - Types and Configuration
-
-#### Step 4.1: Update RemoteSyncEntityModel type
-**File**: `frontend/src/metabase-types/api/remote-sync.ts`
-
-Add "pythonlibrary" to the entity model type:
-```typescript
-export type RemoteSyncEntityModel =
- | "card"
- | "dataset"
- | "metric"
- | "dashboard"
- | "collection"
- | "document"
- | "snippet"
- | "table"
- | "field"
- | "segment"
- | "measure"
- | "transform"
- | "transformtag"
- | "pythonlibrary"; // Add this
-```
-
-#### Step 4.2: Add model mutation configs
-**File**: `enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/model-configs.ts`
-
-Add PythonLibrary configuration:
-```typescript
-{
- modelType: "pythonlibrary",
- createEndpoints: [], // Using upsert, no separate create
- updateEndpoints: [pythonTransformLibraryApi.endpoints.updatePythonLibrary.matchFulfilled],
- deleteEndpoints: [], // No delete endpoint currently
- invalidation: { type: InvalidationType.Always },
-}
-```
-
-#### Step 4.3: Update entity display utilities (if needed)
-**File**: `enterprise/frontend/src/metabase-enterprise/remote_sync/utils.ts`
-
-May need to add icon/color mappings for pythonlibrary entity type in the AllChangesView display logic.
-
----
-
-### Phase 5: Testing
-
-#### Step 5.1: Backend unit tests
-**File**: `enterprise/backend/test/metabase_enterprise/remote_sync/python_library_test.clj` (new)
-
-Test cases:
-- Serialization round-trip (export → import)
-- Event publication on create/update/delete
-- RemoteSyncObject tracking when setting enabled
-- No tracking when setting disabled
-- Export path generation
-
-#### Step 5.2: Backend integration tests
-**File**: `enterprise/backend/test/metabase_enterprise/remote_sync/impl_test.clj` (add tests)
-
-Test cases:
-- PythonLibrary included in export when transforms setting enabled
-- PythonLibrary excluded from export when setting disabled
-- Import creates/updates PythonLibrary correctly
-
-#### Step 5.3: Frontend unit tests
-**File**: `enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/model-configs.unit.spec.ts` (if exists, add tests)
-
-Test cases:
-- PythonLibrary mutations trigger dirty state invalidation
-- Correct entity type display in AllChangesView
-
----
-
-## Files to Modify
-
-### Backend (Clojure)
-
-| File | Changes |
-|------|---------|
-| `enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj` | Remove from excluded-models, add to appropriate models list |
-| `enterprise/backend/src/metabase_enterprise/transforms_python/models/python_library.clj` | Add serdes methods, event publication |
-| `enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj` | Add PythonLibrary spec, export-path-segments method |
-| `enterprise/backend/src/metabase_enterprise/remote_sync/events.clj` | Verify event registration (may be automatic) |
-
-### Frontend (TypeScript)
-
-| File | Changes |
-|------|---------|
-| `frontend/src/metabase-types/api/remote-sync.ts` | Add "pythonlibrary" to RemoteSyncEntityModel |
-| `enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/model-configs.ts` | Add PythonLibrary mutation config |
-| `enterprise/frontend/src/metabase-enterprise/remote_sync/utils.ts` | Add icon/display helpers if needed |
-
-### Tests (New)
-
-| File | Purpose |
-|------|---------|
-| `enterprise/backend/test/metabase_enterprise/remote_sync/python_library_test.clj` | New test file for PythonLibrary remote-sync |
-
----
-
-## Dependencies and Considerations
-
-### Prerequisites
-- Current branch already has transforms remote-sync support (based on recent commits)
-- `remote-sync-transforms` setting already exists and controls transform syncing
-
-### Risks and Mitigations
-1. **Path normalization**: PythonLibrary normalizes paths to `.py` extension - ensure serialization handles this consistently
-2. **Single library constraint**: Currently only `common.py` is supported - serialization should handle this gracefully
-3. **No delete endpoint**: PythonLibrary API only has GET/PUT (upsert) - may need to handle deletion tracking differently
-
-### Future Considerations
-- If more library paths are supported in future, the serialization will already handle them via path-based identity
-- Consider whether library deletion should be supported and how it would affect remote-sync
-
----
-
-## Success Criteria
-
-1. ✅ PythonLibrary changes are tracked in RemoteSyncObject when `remote-sync-transforms` is enabled
-2. ✅ PythonLibrary exports to `python-libraries/common.yaml` during git sync export
-3. ✅ PythonLibrary imports from YAML correctly during git sync import
-4. ✅ Frontend shows PythonLibrary in dirty changes view
-5. ✅ All existing tests pass
-6. ✅ New tests for PythonLibrary remote-sync functionality pass
diff --git a/PLAN_query_processor_benchmarks.md b/PLAN_query_processor_benchmarks.md
deleted file mode 100644
index a791247c376..00000000000
--- a/PLAN_query_processor_benchmarks.md
+++ /dev/null
@@ -1,373 +0,0 @@
-# Query Processor CPU and Memory Benchmarks - Implementation Plan
-
-## Existing Benchmarks
-
-### 1. Query Processor Compilation Benchmark
-**File**: `test/metabase/query_processor/perf_test.clj`
-
-Benchmarks query compilation (MBQL → SQL) using Criterium with mock metadata providers:
-- Small: 5 tables × 10 columns
-- Medium: 5 tables × 100 columns
-- Large: 5 tables × 1000 columns
-- Huge: 5 tables × 10,000 columns
-
-**Coverage**: Only `qp.compile/compile` - does NOT cover preprocessing, execution, or HTTP API.
-
-```clojure
-;; REPL usage
-(compile-time mp-medium trivial-query computed-cache-on)
-```
-
-### 2. Search Performance Benchmark
-**File**: `dev/src/dev/search_perf.clj`
-
-Full load testing framework for search functionality:
-- Creates 10k+ tables, users, permission groups
-- Tracks p50/p95 percentiles
-- Warmup iterations
-- Multiple search patterns
-
-```clojure
-;; REPL usage
-(run-full-benchmark! {:num-tables 10000 :num-groups 10 :num-users 100})
-```
-
-### 3. Memory Utilities
-**File**: `dev/src/dev/memory.clj`
-
-Thread allocation measurement utilities:
-- `measure-thread-allocations` - Bytes allocated by a function
-- `with-memory-logging` - Macro for memory logging
-
-### 4. Available Dependencies (in deps.edn :dev alias)
-- `criterium/criterium {:mvn/version "0.4.6"}` - Statistical benchmarking
-- `com.clojure-goes-fast/clj-async-profiler` - Flame graphs
-- `com.clojure-goes-fast/clj-memory-meter` - Deep object sizing
-- `com.clojure-goes-fast/jvm-alloc-rate-meter` - Heap allocation monitoring
-
-### Gap Analysis
-The existing benchmarks do NOT cover:
-- Full query execution (preprocessing + compilation + execution)
-- HTTP API layer performance
-- Concurrent load testing
-- Memory profiling per query type
-- Native queries, nested queries, pivots, exports
-
----
-
-## Overview
-
-Add a comprehensive benchmarking suite for Metabase query processing that covers:
-- **Unit benchmarks**: Isolated QP phase testing (preprocess, compile, execute)
-- **Integration benchmarks**: Full query execution through API
-- **Load testing**: 50-200+ concurrent HTTP requests with percentile tracking
-- **Memory profiling**: Heap allocations and object sizing per query
-
-**Target databases**: H2 (default/CI) + Postgres (realistic testing)
-**Execution modes**: CI smoke tests + local REPL-driven profiling
-
----
-
-## Directory Structure
-
-```
-dev/src/dev/benchmark/
-├── core.clj # Criterium wrappers, config, percentile calculations
-├── memory.clj # Memory profiling (extends dev.memory)
-├── profiler.clj # clj-async-profiler integration (flame graphs)
-├── queries/
-│ └── definitions.clj # Query library: MBQL, native, nested, pivot, exports
-├── qp/
-│ ├── unit.clj # Isolated QP phase benchmarks
-│ └── integration.clj # Full query execution benchmarks
-├── load/
-│ ├── concurrent.clj # HTTP load testing with thread pools
-│ └── data_setup.clj # Large dataset creation for Postgres
-└── report/
- ├── console.clj # Pretty-printed console output
- └── json.clj # JSON reports for CI artifacts
-
-test/metabase/benchmark/
-└── smoke_test.clj # Quick CI verification (no perf thresholds)
-```
-
----
-
-## Implementation Steps
-
-### Step 1: Core Benchmark Infrastructure
-**Files**: `dev/src/dev/benchmark/core.clj`
-
-Create Criterium wrappers with structured result output:
-- `bench` - Run benchmark, return `{:mean-ns :std-dev-ns :percentiles {:p50 :p95 :p99}}`
-- `bench-quick` - Fast mode for smoke tests
-- Configuration via `*benchmark-config*` dynamic var
-
-**Pattern to follow**: `test/metabase/query_processor/perf_test.clj` lines 88-96
-
-```clojure
-(defn bench [thunk & {:keys [quick?]}]
- (let [results (if quick?
- (crit/quick-benchmark (thunk) {})
- (crit/benchmark (thunk) {}))]
- {:mean-ns (first (:mean results))
- :percentiles (calculate-percentiles (:samples results))}))
-```
-
----
-
-### Step 2: Query Definitions Library
-**Files**: `dev/src/dev/benchmark/queries/definitions.clj`
-
-Define representative queries using `metabase.test.data`:
-- `simple-select` - Basic table scan
-- `aggregation-query` - COUNT, SUM with filters
-- `join-query` - Multi-table joins with breakouts
-- `nested-query` - Query with saved question as source
-- `native-query` - Raw SQL execution
-- `pivot-query` - Pivot table generation
-
-Each returns a proper MBQL query map.
-
----
-
-### Step 3: Unit Benchmarks (QP Phases)
-**Files**: `dev/src/dev/benchmark/qp/unit.clj`
-
-Benchmark isolated QP phases:
-
-```clojure
-(defn benchmark-preprocess [query]
- (qp.setup/with-qp-setup [query query]
- (mu/disable-enforcement
- (bench #(qp.preprocess/preprocess query)))))
-
-(defn benchmark-compile [query]
- (qp.setup/with-qp-setup [query query]
- (mu/disable-enforcement
- (let [preprocessed (qp.preprocess/preprocess query)]
- (bench #(qp.compile/compile-preprocessed preprocessed))))))
-```
-
-**Key targets**:
-- `qp.preprocess/preprocess` - 42+ middleware steps
-- `qp.compile/compile-preprocessed` - MBQL → SQL
-- Individual middleware: `resolve-fields`, `add-remaps`, `annotate/expected-cols`
-
----
-
-### Step 4: Integration Benchmarks
-**Files**: `dev/src/dev/benchmark/qp/integration.clj`
-
-Full end-to-end benchmarks:
-
-```clojure
-(defn benchmark-process-query [query]
- (bench #(qp/process-query (qp/userland-query-with-default-constraints query))))
-
-(defn benchmark-api-query [query user]
- (bench #(mt/user-http-request user :post 200 "dataset" query)))
-
-(defn benchmark-export [query format user]
- (bench #(mt/user-http-request user :post 200
- (str "dataset/" (name format)) {:query query})))
-```
-
-Test all query types + export formats (CSV, JSON, XLSX).
-
----
-
-### Step 5: Load Testing (Concurrent HTTP)
-**Files**: `dev/src/dev/benchmark/load/concurrent.clj`
-
-Heavy concurrency testing (50-200+ concurrent):
-
-```clojure
-(defn run-load-test [{:keys [concurrent-requests duration-seconds query user]}]
- (let [pool (cp/threadpool concurrent-requests)
- results (atom [])]
- (cp/pfor pool (range concurrent-requests)
- (while-within-duration
- (swap! results conj (execute-request query user))))
- (calculate-stats @results)))
-```
-
-**Output**:
-- Throughput (requests/second)
-- Latency percentiles (p50, p95, p99)
-- Error rate
-- Total requests
-
-**Dependencies**: Add `org.clj-commons/claypoole` to `:dev` alias if not present.
-
----
-
-### Step 6: Memory Profiling
-**Files**: `dev/src/dev/benchmark/memory.clj`
-
-Extend existing `dev.memory` utilities:
-
-```clojure
-(defn profile-query-memory [query]
- (let [{:keys [allocations]} (memory/measure-thread-allocations
- #(qp/process-query query))
- result-size (mm/measure result)]
- {:thread-allocations-bytes allocations
- :result-size-bytes result-size
- :bytes-per-row (/ result-size row-count)}))
-```
-
-**Uses**:
-- `dev.memory/measure-thread-allocations` (existing)
-- `clj-memory-meter.core/measure` for deep object sizing
-- `jvm-alloc-rate-meter` for allocation rate during load
-
----
-
-### Step 7: Async Profiler (Flame Graphs)
-**Files**: `dev/src/dev/benchmark/profiler.clj`
-
-Generate CPU and allocation flame graphs:
-
-```clojure
-(defn profile-query-cpu [query & {:keys [iterations output-dir]}]
- (prof/profile {:event :cpu :output-dir output-dir}
- (dotimes [_ iterations]
- (qp/process-query query)))
- (prof/generate-flamegraph output-dir))
-```
-
-Output HTML flame graphs to `target/profiler/`.
-
----
-
-### Step 8: Reporting
-**Files**: `dev/src/dev/benchmark/report/{console,json}.clj`
-
-**Console output**: Formatted table with benchmark name, mean, p50, p95, p99
-**JSON output**: Machine-readable for CI artifacts
-
-```clojure
-(defn generate-report [results]
- {:timestamp (java.time.Instant/now)
- :git-sha (git-sha)
- :jvm-version (System/getProperty "java.version")
- :results results})
-```
-
-Support baseline comparison with configurable regression threshold.
-
----
-
-### Step 9: CI Integration
-**Files**: `test/metabase/benchmark/smoke_test.clj`, `deps.edn`
-
-Smoke tests verify benchmarks complete without errors (no perf assertions):
-
-```clojure
-(deftest ^:benchmark preprocess-benchmark-smoke-test
- (testing "Preprocess benchmark completes"
- (let [result (unit/benchmark-preprocess (queries/simple-select))]
- (is (pos? (:mean-ns result)))
- (is (< (:mean-ns result) 1e10))))) ; Sanity: < 10 seconds
-```
-
-**deps.edn alias**:
-```clojure
-:benchmark {:extra-paths ["dev/src"]
- :exec-fn dev.benchmark.runner/run-benchmarks
- :exec-args {:output-path "target/benchmark-results.json"}}
-```
-
----
-
-### Step 10: Database Setup (H2 + Postgres)
-**Files**: `dev/src/dev/benchmark/load/data_setup.clj`
-
-**H2**: Use standard test data (`metabase.test.data/db`)
-**Postgres**: Create larger datasets using `dev.add-load` patterns
-
-```clojure
-(def data-sizes
- {:small {:tables 5 :rows-per-table 100}
- :medium {:tables 10 :rows-per-table 1000}
- :large {:tables 20 :rows-per-table 10000}})
-
-(defn ensure-benchmark-data! [size]
- (case (driver/the-driver)
- :h2 (data/db)
- :postgres (create-postgres-benchmark-data! size)))
-```
-
----
-
-## Key Files to Reference
-
-| Purpose | Existing File |
-|---------|--------------|
-| Criterium patterns | `test/metabase/query_processor/perf_test.clj` |
-| Load testing patterns | `dev/src/dev/search_perf.clj` |
-| Memory utilities | `dev/src/dev/memory.clj` |
-| Bulk data loading | `dev/src/dev/add_load.clj` |
-| Test data setup | `test/metabase/test/data.clj` |
-| HTTP test client | `test/metabase/test/http_client.clj` |
-
----
-
-## REPL Usage Examples
-
-```clojure
-;; Unit benchmarks
-(require '[dev.benchmark.qp.unit :as unit])
-(unit/run-all-unit-benchmarks)
-
-;; Integration benchmarks
-(require '[dev.benchmark.qp.integration :as integration])
-(integration/run-all-integration-benchmarks)
-
-;; Load test with 100 concurrent for 30 seconds
-(require '[dev.benchmark.load.concurrent :as load])
-(load/run-load-test {:concurrent-requests 100
- :duration-seconds 30
- :query (queries/simple-select)})
-
-;; CPU flame graph
-(require '[dev.benchmark.profiler :as profiler])
-(profiler/profile-query-cpu (queries/complex-join))
-;; Open target/profiler/*.html
-```
-
----
-
-## CI Usage
-
-```bash
-# Quick smoke tests
-clojure -X:dev:test :only '["test/metabase/benchmark"]' :include-tags '[:benchmark]'
-
-# Full benchmark with JSON report
-clojure -X:dev:benchmark :output-path target/benchmark-results.json
-```
-
----
-
-## Risk Mitigations
-
-| Risk | Mitigation |
-|------|------------|
-| Flaky CI tests | Smoke tests verify completion only, no performance thresholds |
-| Thread pool exhaustion | Configure Jetty threads (MB_JETTY_MAXTHREADS) for load tests |
-| Memory leaks during load | Monitor heap, limit duration, force GC between tests |
-| Non-reproducible results | Record JVM version, git SHA, use relative comparisons |
-| H2 unrealistic for production | Postgres available for local testing with larger datasets |
-
----
-
-## Dependencies to Add
-
-```clojure
-;; In deps.edn :dev alias (if not already present)
-org.clj-commons/claypoole {:mvn/version "1.2.0"} ; Thread pools for load testing
-```
-
-All other dependencies (criterium, clj-async-profiler, clj-memory-meter) already present in `:dev` alias.
diff --git a/PLAN_remote_sync_has_changes.md b/PLAN_remote_sync_has_changes.md
deleted file mode 100644
index 55d959c6fc4..00000000000
--- a/PLAN_remote_sync_has_changes.md
+++ /dev/null
@@ -1,222 +0,0 @@
-# Plan: Remote Sync "Has Remote Changes" Endpoint
-
-## Goal
-
-Create a new endpoint that checks if there are changes on the remote (Git) repository that can be pulled, with in-memory caching to avoid excessive Git operations.
-
-## Current State
-
-- Remote-sync endpoints are defined in `enterprise/backend/src/metabase_enterprise/remote_sync/api.clj`
-- Version tracking exists via `remote-sync.task/last-version` (returns last successfully synced Git SHA)
-- Remote version can be fetched via `source.p/version` on a snapshot
-- Currently, remote changes are only detected during export (to prevent overwriting)
-- **No endpoint exists to check for remote changes without attempting a sync**
-
-## Design Decisions
-
-- **Never imported before**: Return `has_changes: true` (there is content to pull)
-- **Remote unreachable**: Let error propagate (consistent with other endpoints)
-- **Branch changed**: Reset cache when branch setting changes
-- **Change summary**: Not included - endpoint only returns boolean and versions
-
-## Implementation Steps
-
-### Step 1: Add Cache Atom and TTL Setting
-
-**File:** `enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj`
-
-Add an atom-based cache for storing remote change check results:
-
-```clojure
-(def ^:private remote-changes-cache
- "Cache for remote changes check to avoid frequent git operations.
- Structure: {:last-checked-ms <timestamp>
- :branch <branch-name>
- :remote-version <git-sha>
- :has-changes? <boolean>}"
- (atom nil))
-```
-
-**File:** `enterprise/backend/src/metabase_enterprise/remote_sync/settings.clj`
-
-Add a configurable TTL setting:
-
-```clojure
-(defsetting remote-sync-check-changes-cache-ttl-seconds
- (deferred-tru "Time-to-live in seconds for the remote changes check cache. Default is 60 seconds.")
- :type :integer
- :visibility :admin
- :export? false
- :encryption :no
- :default 60)
-```
-
-### Step 2: Implement Core Logic
-
-**File:** `enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj`
-
-Add function to check for remote changes with caching:
-
-```clojure
-(defn has-remote-changes?
- "Check if remote has new changes compared to last imported version.
- Uses cache to avoid frequent git operations. Returns map with:
- - :has-changes? boolean
- - :remote-version string (git SHA)
- - :local-version string (git SHA of last import, or nil)
- - :cached? boolean (whether result came from cache)
-
- Cache is invalidated if:
- - TTL has expired
- - Branch setting has changed
- - force-refresh? is true"
- ([]
- (has-remote-changes? nil))
- ([{:keys [force-refresh?]}]
- (let [cache-state @remote-changes-cache
- now-ms (System/currentTimeMillis)
- ttl-ms (* 1000 (settings/remote-sync-check-changes-cache-ttl-seconds))
- current-branch (settings/remote-sync-branch)
- cache-valid? (and cache-state
- (not force-refresh?)
- (= current-branch (:branch cache-state))
- (< (- now-ms (:last-checked-ms cache-state)) ttl-ms))]
- (if cache-valid?
- (assoc cache-state :cached? true)
- (let [last-imported (remote-sync.task/last-version)
- source (source/source-from-settings current-branch)
- snapshot (source.p/snapshot source)
- current-remote (source.p/version snapshot)
- ;; has-changes? is true if:
- ;; - never imported (last-imported is nil), OR
- ;; - remote version differs from local version
- has-changes? (or (nil? last-imported)
- (not= last-imported current-remote))
- result {:last-checked-ms now-ms
- :branch current-branch
- :remote-version current-remote
- :local-version last-imported
- :has-changes? has-changes?}]
- (reset! remote-changes-cache result)
- (assoc result :cached? false))))))
-
-(defn invalidate-remote-changes-cache!
- "Invalidate the remote changes cache. Call this after import/export."
- []
- (reset! remote-changes-cache nil))
-```
-
-### Step 3: Invalidate Cache on Import/Export
-
-**File:** `enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj`
-
-Modify `async-import!` and `async-export!` to invalidate cache on success:
-
-```clojure
-;; At the end of successful import in async-import!
-(invalidate-remote-changes-cache!)
-
-;; At the end of successful export in async-export!
-(invalidate-remote-changes-cache!)
-```
-
-### Step 4: Add Response Schema
-
-**File:** `enterprise/backend/src/metabase_enterprise/remote_sync/schema.clj`
-
-```clojure
-(def HasRemoteChangesResponse
- "Response schema for the has-remote-changes endpoint."
- [:map
- [:has_changes :boolean]
- [:remote_version [:maybe :string]]
- [:local_version [:maybe :string]]
- [:cached :boolean]])
-```
-
-### Step 5: Add API Endpoint
-
-**File:** `enterprise/backend/src/metabase_enterprise/remote_sync/api.clj`
-
-```clojure
-(api.macros/defendpoint :get "/has-remote-changes" :- schema/HasRemoteChangesResponse
- "Check if there are new changes on the remote branch that can be pulled.
- Uses in-memory caching (configurable TTL via remote-sync-check-changes-cache-ttl-seconds setting).
-
- Returns:
- - has_changes: true if remote version differs from last imported version, or if never imported
- - remote_version: current Git SHA on remote branch
- - local_version: Git SHA of last successful import (nil if never imported)
- - cached: true if result was served from cache"
- [_route-params
- _query-params
- {:keys [force_refresh] :or {force_refresh false}} :- [:map [:force_refresh {:optional true} :boolean]]]
- (api/check-superuser)
- (api/check-400 (settings/remote-sync-enabled) (tru "Remote sync is not configured."))
- (let [result (impl/has-remote-changes? {:force-refresh? force_refresh})]
- {:has_changes (:has-changes? result)
- :remote_version (:remote-version result)
- :local_version (:local-version result)
- :cached (:cached? result)}))
-```
-
-### Step 6: Add Tests
-
-**File:** `enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj`
-
-Add tests for:
-1. Endpoint returns `has_changes: true` when never imported
-2. Endpoint returns `has_changes: true` when remote version differs
-3. Endpoint returns `has_changes: false` when versions match
-4. Cache is used on subsequent calls within TTL
-5. `force_refresh=true` bypasses cache
-6. Cache is invalidated when branch changes
-7. Cache is invalidated after import
-8. Cache is invalidated after export
-9. Endpoint requires superuser
-10. Endpoint returns 400 if remote-sync not configured
-
-## API Contract
-
-### Request
-
-```
-GET /api/ee/remote-sync/has-remote-changes
-GET /api/ee/remote-sync/has-remote-changes?force_refresh=true
-```
-
-**Headers:** Requires superuser authentication
-
-**Query Parameters:**
-- `force_refresh` (optional, boolean): If true, bypass cache and check remote
-
-### Response
-
-```json
-{
- "has_changes": true,
- "remote_version": "abc123def456...",
- "local_version": "789xyz...",
- "cached": false
-}
-```
-
-**Fields:**
-- `has_changes`: `true` if there are changes to pull (or never imported), `false` if up-to-date
-- `remote_version`: Current Git SHA on the remote branch
-- `local_version`: Git SHA of last successful import (`null` if never imported)
-- `cached`: `true` if this result came from cache, `false` if freshly fetched
-
-**Status Codes:**
-- `200`: Success
-- `400`: Remote sync not configured
-- `401`: Not authenticated
-- `403`: Not superuser
-
-## Files to Modify
-
-1. `enterprise/backend/src/metabase_enterprise/remote_sync/settings.clj` - Add TTL setting
-2. `enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj` - Add cache and logic
-3. `enterprise/backend/src/metabase_enterprise/remote_sync/schema.clj` - Add response schema
-4. `enterprise/backend/src/metabase_enterprise/remote_sync/api.clj` - Add endpoint
-5. `enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj` - Add tests
diff --git a/PLAN_remote_sync_snippets.md b/PLAN_remote_sync_snippets.md
deleted file mode 100644
index eee332b09f3..00000000000
--- a/PLAN_remote_sync_snippets.md
+++ /dev/null
@@ -1,303 +0,0 @@
-# Plan: Support Remote Syncing NativeQuerySnippets Globally
-
-## Overview
-
-Add support for globally syncing ALL NativeQuerySnippets and their collections when the Library collection is remote-synced. No separate setting is needed - snippet syncing is automatically tied to the Library collection's `is_remote_synced` status.
-
-**Trigger**: When `(collection/library-collection)` has `is_remote_synced = true`, all snippets sync globally.
-
-## Current State
-
-### NativeQuerySnippet Remote Sync (existing)
-- **Location**: `enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj` (lines 110-124)
-- **Eligibility**: Collection-based (`:collection :remote-synced`)
-- **Behavior**: Only syncs snippets in remote-synced collections
-- **Export Path**: `:collection-entity` type
-
-### Transform Remote Sync (reference pattern)
-- Uses `remote-sync-transforms` setting
-- When enabled, syncs ALL transforms globally
-- We'll follow similar pattern but check Library collection sync status instead
-
-## Implementation Plan
-
-### 1. Backend: Add Helper Function to Check Library Sync Status
-
-**File**: `enterprise/backend/src/metabase_enterprise/remote_sync/settings.clj`
-
-Add helper function:
-```clojure
-(defn library-is-remote-synced?
- "Returns true if the Library collection exists and is remote-synced.
- When true, all snippets and snippet collections should be synced."
- []
- (when-let [library (collection/library-collection)]
- (collection/remote-synced-collection? library)))
-```
-
-### 2. Backend: Update NativeQuerySnippet Spec
-
-**File**: `enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj`
-
-Change the NativeQuerySnippet spec from collection-based to a new eligibility type that checks Library sync status:
-
-**Current spec** (lines 110-124):
-```clojure
-:model/NativeQuerySnippet
-{:model-type "NativeQuerySnippet"
- :model-key :model/NativeQuerySnippet
- :identity :entity-id
- :events {:prefix :event/snippet
- :types [:create :update :delete]}
- :eligibility {:type :collection
- :collection :remote-synced}
- :archived-key :archived
- :tracking {:select-fields [:name :id]
- :field-mappings {:model_name :name}}
- :removal {:statuses #{"removed"}
- :scope-key :collection_id}
- :export-path {:type :collection-entity}
- :enabled? true}
-```
-
-**New spec**:
-```clojure
-:model/NativeQuerySnippet
-{:model-type "NativeQuerySnippet"
- :model-key :model/NativeQuerySnippet
- :identity :entity-id
- :events {:prefix :event/snippet
- :types [:create :update :delete]}
- :eligibility {:type :library-synced} ; New eligibility type
- :archived-key :archived
- :tracking {:select-fields [:name :id]
- :field-mappings {:model_name :name}}
- :removal {:statuses #{"removed"}} ; Remove scope-key for global deletion
- :export-path {:type :snippet-path} ; New path type for snippets directory
- :export-scope :all ; Export all snippets
- :enabled? :library-synced} ; Controlled by Library sync status
-```
-
-### 3. Backend: Add `:library-synced` Eligibility Type
-
-**File**: `enterprise/backend/src/metabase_enterprise/remote_sync/events.clj`
-
-Add new eligibility check method:
-```clojure
-(defmethod check-eligibility :library-synced
- [_eligibility _entity]
- (settings/library-is-remote-synced?))
-```
-
-### 4. Backend: Add `spec-enabled?` Support for `:library-synced`
-
-**File**: `enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj`
-
-Update `spec-enabled?` to handle the `:library-synced` keyword:
-```clojure
-(defn spec-enabled?
- "Returns true if the spec is enabled."
- [spec]
- (let [enabled (:enabled? spec)]
- (cond
- (boolean? enabled) enabled
- (= enabled :library-synced) (settings/library-is-remote-synced?)
- (keyword? enabled) (boolean ((keyword (name enabled)))))))
-```
-
-### 5. Backend: Add Snippet Path Construction
-
-**File**: `enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj`
-
-Add new export path type `:snippet-path` to `construct-export-path` multimethod:
-
-```clojure
-(defmethod construct-export-path :snippet-path
- [_path-type entity]
- (let [collection (when (:collection_id entity)
- (t2/select-one :model/Collection :id (:collection_id entity)))]
- (if collection
- ;; Snippets in collections: snippets/<collection-hierarchy>/<entity-id>
- (concat ["snippets"]
- (rest (serdes/path-for-collection collection)) ; Remove "collections" prefix
- [(serdes/eid->label entity)])
- ;; Root snippets: snippets/<entity-id>
- ["snippets" (serdes/eid->label entity)])))
-```
-
-### 6. Backend: Update Collection Eligibility for Snippets Namespace
-
-**File**: `enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj` or `events.clj`
-
-Update Collection eligibility to include snippets-namespace collections when Library is remote-synced:
-
-```clojure
-;; In the Collection eligibility check, a collection is eligible if:
-;; 1. It's remote-synced, OR
-;; 2. It's a transforms-namespace collection and remote-sync-transforms is enabled, OR
-;; 3. It's a snippets-namespace collection and Library is remote-synced
-```
-
-Update `should-sync-collection?` function:
-```clojure
-(defn should-sync-collection?
- "Returns true if a collection should be synced."
- [collection]
- (or (collection/remote-synced-collection? collection)
- (and (= (:namespace collection) :transforms)
- (settings/remote-sync-transforms))
- (and (= (:namespace collection) :snippets)
- (settings/library-is-remote-synced?))))
-```
-
-### 7. Backend: Add Import Path Filter
-
-**File**: `enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj`
-
-Update the path filters in the import function to include snippets:
-
-**Current** (around line 140):
-```clojure
-(let [path-filters (cond-> [#"collections/.*" #"databases/.*"]
- (settings/remote-sync-transforms)
- (conj #"transforms/.*"))]
-```
-
-**New**:
-```clojure
-(let [path-filters (cond-> [#"collections/.*" #"databases/.*"]
- (settings/remote-sync-transforms)
- (conj #"transforms/.*")
- (settings/library-is-remote-synced?)
- (conj #"snippets/.*"))]
-```
-
-### 8. Backend: Add Snippet Tracking Sync Function
-
-**File**: `enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj`
-
-Add `sync-snippet-tracking!` function to be called when Library collection's sync status changes:
-
-```clojure
-(defn sync-snippet-tracking!
- "Called when the Library collection's remote sync status changes. When enabled,
- marks all existing snippets and snippet collections for initial sync. When
- disabled, removes all snippet tracking entries."
- [enabled?]
- (if enabled?
- ;; Mark all snippets and snippet collections for sync
- (do
- ;; Mark snippets-namespace collections
- (doseq [collection (t2/select :model/Collection :namespace :snippets)]
- (rso/upsert-status! "Collection" (:entity_id collection) "create"
- {:model_name (:name collection)
- :model_collection_id (:id collection)}))
- ;; Mark all snippets
- (doseq [snippet (t2/select :model/NativeQuerySnippet)]
- (rso/upsert-status! "NativeQuerySnippet" (:entity_id snippet) "create"
- {:model_name (:name snippet)})))
- ;; Remove all snippet tracking
- (do
- (t2/delete! :model/RemoteSyncObject :model_type "NativeQuerySnippet")
- (t2/delete! :model/RemoteSyncObject
- :model_type "Collection"
- :model_collection_id [:in {:select [:id]
- :from [:collection]
- :where [:= :namespace "snippets"]}]))))
-```
-
-### 9. Backend: Call Snippet Tracking on Library Sync Status Change
-
-**File**: `enterprise/backend/src/metabase_enterprise/remote_sync/events.clj` or appropriate event handler
-
-When the Library collection's `is_remote_synced` changes, call `sync-snippet-tracking!`:
-
-```clojure
-;; In the collection update event handler, detect Library collection sync changes
-(when (and (collection/is-library? collection)
- (contains? changes :is_remote_synced))
- (impl/sync-snippet-tracking! (:is_remote_synced changes)))
-```
-
-### 10. Backend: Update Dirty Detection
-
-**File**: `enterprise/backend/src/metabase_enterprise/remote_sync/models/remote_sync_object.clj`
-
-Update `excluded-model-types` to exclude NativeQuerySnippet when Library is not remote-synced:
-
-```clojure
-(defn excluded-model-types
- "Returns set of model types to exclude from dirty detection based on settings."
- []
- (cond-> #{}
- (not (settings/remote-sync-transforms))
- (conj "Transform" "TransformTag")
- (not (settings/library-is-remote-synced?))
- (conj "NativeQuerySnippet")))
-```
-
-### 11. Tests
-
-**File**: `enterprise/backend/test/metabase_enterprise/remote_sync/snippets_test.clj` (new file)
-
-Create comprehensive tests:
-
-1. Test snippet tracking is created when Library becomes remote-synced
-2. Test snippet tracking is removed when Library is no longer remote-synced
-3. Test snippets are exported when Library is remote-synced
-4. Test snippets are not exported when Library is not remote-synced
-5. Test snippet collections (`:snippets` namespace) are synced when Library is remote-synced
-6. Test import includes snippets when Library is remote-synced
-7. Test dirty detection excludes snippets when Library is not remote-synced
-8. Test archived snippets are marked for deletion
-9. Test snippet eligibility check returns correct value based on Library status
-
-## File Changes Summary
-
-| File | Change Type | Description |
-|------|-------------|-------------|
-| `enterprise/backend/src/metabase_enterprise/remote_sync/settings.clj` | Modify | Add `library-is-remote-synced?` helper function |
-| `enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj` | Modify | Update NativeQuerySnippet spec, add `:snippet-path`, add `:library-synced` enabled check |
-| `enterprise/backend/src/metabase_enterprise/remote_sync/events.clj` | Modify | Add `:library-synced` eligibility type, handle Library sync status changes |
-| `enterprise/backend/src/metabase_enterprise/remote_sync/impl.clj` | Modify | Add snippet path filter, add `sync-snippet-tracking!` |
-| `enterprise/backend/src/metabase_enterprise/remote_sync/models/remote_sync_object.clj` | Modify | Update `excluded-model-types` |
-| `enterprise/backend/test/metabase_enterprise/remote_sync/snippets_test.clj` | New | Comprehensive tests |
-
-## Implementation Order
-
-1. **Phase 1: Core Infrastructure**
- - Add `library-is-remote-synced?` helper
- - Add `:library-synced` eligibility type
- - Update `spec-enabled?` for `:library-synced`
-
-2. **Phase 2: Spec Updates**
- - Update NativeQuerySnippet spec
- - Add `:snippet-path` export path type
- - Update Collection eligibility for snippets namespace
-
-3. **Phase 3: Tracking & Import**
- - Add `sync-snippet-tracking!` function
- - Hook into Library collection sync status change events
- - Add import path filter for snippets
- - Update dirty detection exclusions
-
-4. **Phase 4: Testing**
- - Create comprehensive test file
- - Test all edge cases
-
-## Key Differences from Transform Implementation
-
-| Aspect | Transforms | Snippets |
-|--------|------------|----------|
-| Trigger | `remote-sync-transforms` setting | Library collection `is_remote_synced` |
-| Setting required | Yes | No |
-| Eligibility type | `:setting` | `:library-synced` (new) |
-| Collections namespace | `:transforms` | `:snippets` |
-| Export path | `transforms/...` | `snippets/...` |
-
-## Notes
-
-- No frontend changes needed (no new setting to toggle)
-- Snippet sync is implicitly enabled when Library is remote-synced
-- All snippets sync globally (not scoped to specific collections)
-- Snippet collections (`:snippets` namespace) also sync when enabled
diff --git a/PLAN_standardize_table_permissions.md b/PLAN_standardize_table_permissions.md
deleted file mode 100644
index c6475c4a9dc..00000000000
--- a/PLAN_standardize_table_permissions.md
+++ /dev/null
@@ -1,314 +0,0 @@
-# Plan: Standardize Table/Field/Database Permission Checks
-
-## Goal
-
-Consolidate all permission checks for Tables, Fields, and Databases through the standard `metabase.models.interface` methods rather than having ad hoc checks scattered throughout the codebase.
-
-## Key Insight
-
-The current `can-read?` for Table/Field conflates two distinct questions:
-1. "Can I see this table exists and view its metadata?"
-2. "Can I query data from this table?"
-
-Cards handle this correctly: `can-read?` answers "can see metadata" (via collection permissions), while query execution is checked separately.
-
-## Proposed Interface
-
-Add a new multimethod `can-query?` to cleanly separate these concerns:
-
-| Method | Semantics | Table/Field Implementation |
-|--------|-----------|---------------------------|
-| `can-read?` | Can see this exists, view metadata | data perms OR manage-table-metadata OR published-in-accessible-collection |
-| `can-query?` | Can execute queries against data | `:perms/view-data` + `:perms/create-queries` |
-| `can-write?` | Can modify this model | `:perms/manage-table-metadata` (EE) or superuser (OSS) |
-
-## Current State: Ad Hoc Permission Checks
-
-These locations have special-cased permission checks that should use the standard interface:
-
-### Direct Permission Checks (bypass `mi/can-read?`)
-
-| File | Lines | Current Check | Should Use |
-|------|-------|---------------|------------|
-| `src/metabase/search/impl.clj` | 72-80 | Duplicates view-data + create-queries check | `mi/can-read?` |
-| `src/metabase/warehouse_schema_rest/api/table.clj` | 513-518 | Direct `:perms/manage-table-metadata` | `mi/can-write?` |
-| `src/metabase/warehouses_rest/api.clj` | 1241-1251 | Composite schema permission | New `can-read-schema?` helper using `mi/can-read?` |
-| `enterprise/.../sandbox/api/table.clj` | 62-71 | Permission elevation for sandboxed | Should work with updated `can-read?` |
-
-### Filter Functions (should use `mi/can-read?`)
-
-| File | Lines | Function |
-|------|-------|----------|
-| `enterprise/.../advanced_permissions/common.clj` | 91-111 | `filter-tables-by-data-model-perms` |
-| `enterprise/.../advanced_permissions/common.clj` | 113-133 | `filter-schema-by-data-model-perms` |
-| `enterprise/.../advanced_permissions/common.clj` | 135-160 | `filter-databases-by-data-model-perms` |
-
-## Implementation Plan
-
-### Phase 1: Add `can-query?` Multimethod
-
-**File: `src/metabase/models/interface.clj`**
-
-```clojure
-(defmulti can-query?
- "Return whether [[metabase.api.common/*current-user*]] has permission to
- execute queries against this model's data. For Tables/Fields, this checks
- data access permissions. For Cards, this checks if the user can run the
- underlying query. Models without queryable data return false by default."
- {:arglists '([instance] [model pk])}
- dispatch-on-model)
-
-(defmethod can-query? :default
- ([_instance] false)
- ([_model _pk] false))
-```
-
-**File: `src/metabase/warehouse_schema/models/table.clj`**
-
-```clojure
-(defmethod mi/can-query? :model/Table
- ([instance]
- (and (perms/user-has-permission-for-table?
- api/*current-user-id*
- :perms/view-data
- :unrestricted
- (:db_id instance)
- (:id instance))
- (perms/user-has-permission-for-table?
- api/*current-user-id*
- :perms/create-queries
- :query-builder
- (:db_id instance)
- (:id instance))))
- ([_ pk]
- (mi/can-query? (t2/select-one :model/Table pk))))
-```
-
-**File: `src/metabase/warehouse_schema/models/field.clj`**
-
-```clojure
-(defmethod mi/can-query? :model/Field
- ([instance]
- (and (perms/user-has-permission-for-table?
- api/*current-user-id*
- :perms/view-data
- :unrestricted
- (field->db-id instance)
- (:table_id instance))
- (perms/user-has-permission-for-table?
- api/*current-user-id*
- :perms/create-queries
- :query-builder
- (field->db-id instance)
- (:table_id instance))))
- ([model pk]
- (mi/can-query? (t2/select-one model pk))))
-```
-
-**File: `src/metabase/warehouses/models/database.clj`**
-
-```clojure
-(defmethod mi/can-query? :model/Database
- ([instance]
- (mi/can-query? :model/Database (u/the-id instance)))
- ([_model database-id]
- (contains? #{:query-builder :query-builder-and-native}
- (perms/most-permissive-database-permission-for-user
- api/*current-user-id*
- :perms/create-queries
- database-id))))
-```
-
-### Phase 2: Update `can-read?` for Metadata Visibility
-
-Update Table/Field/Database `can-read?` to include all valid access paths:
-
-**File: `src/metabase/warehouse_schema/models/table.clj`**
-
-```clojure
-(defmethod mi/can-read? :model/Table
- ([instance]
- (or
- ;; Path 1: Has data query permissions
- (mi/can-query? instance)
- ;; Path 2: Has manage-table-metadata permission
- (perms/user-has-permission-for-table?
- api/*current-user-id*
- :perms/manage-table-metadata
- :yes
- (:db_id instance)
- (:id instance))
- ;; Path 3: Table is published in accessible collection (EE)
- (published-tables/can-access-via-collection? instance)))
- ([_ pk]
- (mi/can-read? (t2/select-one :model/Table pk))))
-```
-
-**File: `src/metabase/warehouse_schema/models/field.clj`**
-
-```clojure
-(defmethod mi/can-read? :model/Field
- ([instance]
- (or
- ;; Path 1: Has data query permissions
- (mi/can-query? instance)
- ;; Path 2: Has manage-table-metadata permission on parent table
- (perms/user-has-permission-for-table?
- api/*current-user-id*
- :perms/manage-table-metadata
- :yes
- (field->db-id instance)
- (:table_id instance))
- ;; Path 3: Parent table is published in accessible collection
- (when-let [table (or (:table instance)
- (t2/select-one :model/Table :id (:table_id instance)))]
- (published-tables/can-access-via-collection? table))))
- ([model pk]
- (mi/can-read? (t2/select-one model pk))))
-```
-
-**File: `src/metabase/warehouses/models/database.clj`**
-
-Keep existing logic (already includes published table check):
-```clojure
-(defmethod mi/can-read? :model/Database
- ([_model database-id]
- (or (mi/can-query? :model/Database database-id)
- (perms/user-has-published-table-permission-for-database? database-id))))
-```
-
-### Phase 3: Migrate Special-Cased Checks
-
-#### 3.1 Search Permission Check
-
-**File: `src/metabase/search/impl.clj` (lines 72-80)**
-
-Before:
-```clojure
-(defmethod check-permissions-for-model :table
- [search-ctx instance]
- (let [instance-id (:id instance)
- user-id (:current-user-id search-ctx)
- db-id (database/table-id->database-id instance-id)]
- (and
- (perms/user-has-permission-for-table? user-id :perms/view-data :unrestricted db-id instance-id)
- (perms/user-has-permission-for-table? user-id :perms/create-queries :query-builder db-id instance-id))))
-```
-
-After:
-```clojure
-(defmethod check-permissions-for-model :table
- [_search-ctx instance]
- (mi/can-read? :model/Table (:id instance)))
-```
-
-#### 3.2 Sync Schema Endpoint
-
-**File: `src/metabase/warehouse_schema_rest/api/table.clj` (lines 513-518)**
-
-Before:
-```clojure
-(api/check-403
- (perms/user-has-permission-for-table?
- api/*current-user-id*
- :perms/manage-table-metadata
- :yes
- (:id database)
- id))
-```
-
-After:
-```clojure
-(api/write-check :model/Table id)
-```
-
-#### 3.3 Enterprise Filter Functions
-
-**File: `enterprise/.../advanced_permissions/common.clj`**
-
-Update `filter-tables-by-data-model-perms` to use `mi/can-read?`:
-```clojure
-(defn filter-tables-by-data-model-perms
- [tables]
- (filter mi/can-read? tables))
-```
-
-Or if specifically filtering for write access:
-```clojure
-(defn filter-tables-by-data-model-perms
- [tables]
- (filter mi/can-write? tables))
-```
-
-### Phase 4: Add `api/query-check` Helper
-
-**File: `src/metabase/api/common.clj`**
-
-```clojure
-(defn query-check
- "Check whether we can query data from `obj`, or `entity` with `id`.
- If the object doesn't exist, throw a 404; if we don't have permissions, throw 403."
- ([obj]
- (check-404 obj)
- (check-403 (mi/can-query? obj))
- obj)
- ([entity id]
- (query-check (t2/select-one entity :id id)))
- ([entity id & other-conditions]
- (query-check (apply t2/select-one entity :id id other-conditions))))
-```
-
-### Phase 5: Update Query Permission Checks
-
-Places that check "can query this table" should use `mi/can-query?` or `api/query-check`:
-
-| File | Current | After |
-|------|---------|-------|
-| Query processor permission middleware | Direct permission checks | `mi/can-query?` |
-| Card query execution | Mix of checks | `mi/can-query?` for underlying tables |
-
-## Files to Modify
-
-### Core Interface
-- `src/metabase/models/interface.clj` - add `can-query?` multimethod
-
-### Model Implementations
-- `src/metabase/warehouse_schema/models/table.clj` - implement `can-query?`, update `can-read?`
-- `src/metabase/warehouse_schema/models/field.clj` - implement `can-query?`, update `can-read?`
-- `src/metabase/warehouses/models/database.clj` - implement `can-query?`, update `can-read?`
-
-### API Layer
-- `src/metabase/api/common.clj` - add `query-check` helper
-
-### Migration of Special Cases
-- `src/metabase/search/impl.clj` - use `mi/can-read?`
-- `src/metabase/warehouse_schema_rest/api/table.clj` - use standard checks
-- `src/metabase/warehouses_rest/api.clj` - use standard checks
-- `enterprise/.../advanced_permissions/common.clj` - use `mi/can-read?`/`mi/can-write?`
-- `enterprise/.../sandbox/api/table.clj` - verify works with updated `can-read?`
-
-## Testing Strategy
-
-1. **Unit tests for `can-query?`** - verify correct permission checks
-2. **Unit tests for updated `can-read?`** - verify all three access paths work
-3. **Integration tests** - verify API endpoints behave correctly
-4. **Regression tests** - ensure no permission escalation or denial
-
-## Permission Matrix After Implementation
-
-| User Has | `can-read?` | `can-query?` | `can-write?` |
-|----------|-------------|--------------|--------------|
-| Data perms (view-data + create-queries) | ✅ | ✅ | ❌ |
-| Manage-table-metadata only | ✅ | ❌ | ✅ |
-| Published table in accessible collection | ✅ | ❌* | ❌ |
-| None of the above | ❌ | ❌ | ❌ |
-
-*Published tables may grant query access depending on EE configuration
-
-## Benefits
-
-1. **Single source of truth** - all permission logic in model interface methods
-2. **Semantic clarity** - `can-read?` means "see metadata", `can-query?` means "execute queries"
-3. **Consistency** - matches how Cards work (collection perms for visibility, data perms for execution)
-4. **Maintainability** - changes to permission logic only need to happen in one place
-5. **Testability** - easier to test permission logic in isolation
diff --git a/PLAN_table_path_in_changes_view.md b/PLAN_table_path_in_changes_view.md
deleted file mode 100644
index 63a88af9519..00000000000
--- a/PLAN_table_path_in_changes_view.md
+++ /dev/null
@@ -1,205 +0,0 @@
-# Plan: Update Path for Table Children in Git Sync Changes View
-
-## Problem Statement
-
-When displaying changes in the git sync modals, fields and segments are currently grouped only by their collection (inherited from the parent table). The UI doesn't show which table these entities belong to, making it hard for users to understand the context of changes to table children.
-
-**Current behavior:**
-```
-Collection: Root / Sales
- ├── orders_table (Table) [Create]
- ├── customer_id (Field) [Create] ← No indication this belongs to orders_table
- └── active_customers (Segment) [Create] ← No indication this belongs to orders_table
-```
-
-**Desired behavior:**
-```
-Collection: Root / Sales
- └── orders_table (Table) [Create]
- ├── customer_id (Field) [Create]
- └── active_customers (Segment) [Create]
-```
-
-## Implementation Plan
-
-### Step 1: Backend - Add table_id and table_name to dirty state response
-
-**File:** `enterprise/backend/src/metabase_enterprise/remote_sync/models/remote_sync_object.clj`
-
-1. Update `build-select-clause` to include `table_id` for models that have it
-2. Update the query to include `table_name` from the joined `metabase_table` for field and segment models
-3. Add new columns to the select clause:
- - `:table_id` - The ID of the parent table (for fields/segments)
- - `:table_name` - The name of the parent table (for fields/segments)
-
-Changes needed:
-- Add `:has-table-id` configuration option to model configs
-- Update `build-select-clause` to include table_id when the model has it (fields, segments)
-- Add table_name from the joined metabase_table
-
-**File:** `enterprise/backend/src/metabase_enterprise/remote_sync/schema.clj`
-
-1. Add optional `:table_id` and `:table_name` fields to `DirtyItem` schema
-
-### Step 2: Frontend Types - Update RemoteSyncEntity type
-
-**File:** `frontend/src/metabase-types/api/remote-sync.ts`
-
-1. Add `table` and `field` and `segment` to `RemoteSyncEntityModel` union type
-2. Add optional `table_id?: number` field to `RemoteSyncEntity`
-3. Add optional `table_name?: string` field to `RemoteSyncEntity`
-
-### Step 3: Frontend Utils - Create table grouping utilities
-
-**File:** `enterprise/frontend/src/metabase-enterprise/remote_sync/utils.ts`
-
-1. Add helper function to identify table-child models:
- ```typescript
- export const isTableChildModel = (model: string): boolean => {
- return model === "field" || model === "segment";
- };
- ```
-
-2. Add helper to get table info from entity:
- ```typescript
- export const getParentTableInfo = (entity: RemoteSyncEntity) => {
- if (isTableChildModel(entity.model) && entity.table_id) {
- return { id: entity.table_id, name: entity.table_name };
- }
- return null;
- };
- ```
-
-### Step 4: Frontend UI - Update AllChangesView to nest table children
-
-**File:** `enterprise/frontend/src/metabase-enterprise/remote_sync/components/ChangesLists/AllChangesView.tsx`
-
-1. Update `groupedData` useMemo to create a two-level hierarchy:
- - First level: Group by collection (existing)
- - Second level: Within each collection, separate tables and their children from other items
-
-2. For each collection group:
- - Identify table entities
- - Identify field/segment entities that belong to tables (via `table_id`)
- - Group fields/segments under their parent table
- - Render table items with nested children
-
-3. Update the rendering to show:
- ```
- Collection Path
- ├── Table Item
- │ ├── Field Item
- │ └── Segment Item
- └── Other Item (Card, Dashboard, etc.)
- ```
-
-### Step 5: Update EntityLink to handle table children rendering
-
-**File:** `enterprise/frontend/src/metabase-enterprise/remote_sync/components/ChangesLists/EntityLink.tsx`
-
-The EntityLink component may need minor updates to handle the nested indentation visually, or this can be handled in AllChangesView through additional styling.
-
-### Step 6: Test mock utilities
-
-**File:** `frontend/src/metabase-types/api/mocks/remote-sync.ts`
-
-Update `createMockRemoteSyncEntity` to support table_id and table_name.
-
-**File:** `frontend/test/__support__/server-mocks/remote-sync.ts`
-
-Update mock types if needed.
-
-### Step 7: Write tests
-
-Add tests for:
-1. Backend: dirty state query returns correct table_id/table_name for fields and segments
-2. Frontend: grouping logic correctly nests fields/segments under tables
-3. Frontend: UI renders nested structure correctly
-
-## Technical Details
-
-### Backend Query Changes
-
-Current query for field:
-```sql
-SELECT field.id, field.name, ..., metabase_table.collection_id, 'field' as model
-FROM metabase_field field
-INNER JOIN remote_sync_object rs_obj ON ...
-INNER JOIN metabase_table ON field.table_id = metabase_table.id
-```
-
-Updated query:
-```sql
-SELECT field.id, field.name, ...,
- metabase_table.collection_id,
- field.table_id,
- metabase_table.name as table_name,
- 'field' as model
-FROM metabase_field field
-INNER JOIN remote_sync_object rs_obj ON ...
-INNER JOIN metabase_table ON field.table_id = metabase_table.id
-```
-
-### Frontend Grouping Logic
-
-```typescript
-// Pseudocode for the grouping logic
-const groupedData = useMemo(() => {
- const byCollection = _.groupBy(entities, (e) => e.collection_id || 0);
-
- return Object.entries(byCollection).map(([collectionId, items]) => {
- // Separate tables and their children from other items
- const tables = items.filter(i => i.model === "table");
- const tableChildren = items.filter(i => isTableChildModel(i.model));
- const otherItems = items.filter(i => i.model !== "table" && !isTableChildModel(i.model));
-
- // Group table children by their parent table
- const tableChildrenByTable = _.groupBy(tableChildren, (e) => e.table_id);
-
- // Create table items with their nested children
- const tableItems = tables.map(table => ({
- ...table,
- children: tableChildrenByTable[table.id] || []
- }));
-
- // Handle orphan table children (table not in dirty set)
- const orphanTableIds = Object.keys(tableChildrenByTable)
- .filter(id => !tables.some(t => t.id === Number(id)));
-
- const orphanTableGroups = orphanTableIds.map(tableId => ({
- tableId: Number(tableId),
- tableName: tableChildrenByTable[tableId][0]?.table_name,
- children: tableChildrenByTable[tableId]
- }));
-
- return {
- pathSegments: getCollectionPathSegments(...),
- collectionId,
- collectionEntity,
- tableItems, // Tables with their children
- orphanTableGroups, // Children of tables not in dirty set
- items: otherItems // Non-table items (cards, dashboards, etc.)
- };
- });
-}, [entities, collectionMap]);
-```
-
-## Files to Modify
-
-1. `enterprise/backend/src/metabase_enterprise/remote_sync/models/remote_sync_object.clj`
-2. `enterprise/backend/src/metabase_enterprise/remote_sync/schema.clj`
-3. `frontend/src/metabase-types/api/remote-sync.ts`
-4. `enterprise/frontend/src/metabase-enterprise/remote_sync/utils.ts`
-5. `enterprise/frontend/src/metabase-enterprise/remote_sync/components/ChangesLists/AllChangesView.tsx`
-6. `frontend/src/metabase-types/api/mocks/remote-sync.ts` (optional)
-7. `frontend/test/__support__/server-mocks/remote-sync.ts` (optional)
-
-## Considerations
-
-1. **Orphan children**: Fields/segments may be dirty without their parent table being dirty. Need to handle this case by showing a "virtual" table parent grouping using the table_name from the field/segment.
-
-2. **Performance**: The grouping logic adds complexity but operates on already-fetched data, so impact should be minimal.
-
-3. **Backwards compatibility**: Adding optional fields to the API response is backward compatible.
-
-4. **UI clarity**: The nested structure should make it clearer which table fields/segments belong to, improving user understanding of changes.
diff --git a/PLAN_transforms_collection_dirty_state.md b/PLAN_transforms_collection_dirty_state.md
deleted file mode 100644
index a09fce86a2e..00000000000
--- a/PLAN_transforms_collection_dirty_state.md
+++ /dev/null
@@ -1,153 +0,0 @@
-# Plan: Fix Transforms Collections Dirty State Issues
-
-## Problem Summary
-
-Two issues exist with transforms collections in DataStudio:
-
-1. **Creating new transforms collections doesn't trigger dirty state rechecking**
-2. **Transforms collections don't show in the changes view hierarchy**
-
----
-
-## Issue 1: Dirty State Not Invalidated for Transforms Collections
-
-### Root Cause
-
-When a transforms collection is created, the frontend middleware doesn't invalidate the dirty state cache.
-
-**Location**: `enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.ts:239-248`
-
-```typescript
-remoteSyncListenerMiddleware.startListening({
- matcher: collectionApi.endpoints.createCollection.matchFulfilled,
- effect: async (action: PayloadAction<Collection>, { dispatch }) => {
- const collection = action.payload;
-
- if (collection.is_remote_synced) { // ← BUG: Only checks is_remote_synced
- invalidateRemoteSyncTags(dispatch);
- }
- },
-});
-```
-
-The backend tracks transforms-namespace collections differently:
-- Regular collections are tracked when `is_remote_synced = true`
-- Transforms collections are tracked when `namespace = "transforms"` AND `remote-sync-transforms` setting is enabled
-
-See `spec.clj:328-345`:
-```clojure
-(defmethod check-eligibility :collection
- [{:keys [eligibility]} object]
- (case (:collection eligibility)
- :any
- (or (collections/remote-synced-collection? (or collection-id object))
- (and (rs-settings/remote-sync-transforms)
- (transforms-namespace-collection? object)))))
-```
-
-### Fix
-
-Modify the middleware to also invalidate tags when creating a transforms-namespace collection:
-
-```typescript
-// remote-sync-listener-middleware.ts
-
-remoteSyncListenerMiddleware.startListening({
- matcher: collectionApi.endpoints.createCollection.matchFulfilled,
- effect: async (action: PayloadAction<Collection>, { dispatch, getState }) => {
- const collection = action.payload;
-
- // Check if this is a remote-synced collection
- const isRemoteSynced = collection.is_remote_synced;
-
- // Check if this is a transforms-namespace collection with transforms sync enabled
- const state = getState();
- const isTransformsSyncEnabled = getSetting(state, "remote-sync-transforms");
- const isTransformsCollection = collection.namespace === "transforms";
-
- if (isRemoteSynced || (isTransformsCollection && isTransformsSyncEnabled)) {
- invalidateRemoteSyncTags(dispatch);
- }
- },
-});
-```
-
-Similar changes needed for:
-- `collectionApi.endpoints.updateCollection.matchFulfilled` (lines 250-266)
-- `collectionApi.endpoints.deleteCollection.matchFulfilled` (lines 268-286)
-
----
-
-## Issue 2: Transforms Collections Not in Changes View Hierarchy
-
-### Root Cause
-
-The `AllChangesView` component fetches the collection tree without including the "transforms" namespace.
-
-**Location**: `enterprise/frontend/src/metabase-enterprise/remote_sync/components/ChangesLists/AllChangesView.tsx:51-58`
-
-```typescript
-const { data: collectionTree = [] } = useListCollectionsTreeQuery({
- namespaces: [
- "",
- "analytics",
- ...(isUsingTenants ? ["shared-tenant-collection"] : []),
- ],
- "include-library": true,
-});
-```
-
-When transforms entities are dirty, they have a `collection_id` that points to a transforms-namespace collection. Since this collection isn't in the tree, `buildCollectionMap` can't resolve it, and the path segments are wrong/empty.
-
-### Fix
-
-Add "transforms" to the namespaces when `remote-sync-transforms` setting is enabled:
-
-```typescript
-// AllChangesView.tsx
-
-const isTransformsSyncEnabled = useSetting("remote-sync-transforms");
-
-const { data: collectionTree = [] } = useListCollectionsTreeQuery({
- namespaces: [
- "",
- "analytics",
- ...(isUsingTenants ? ["shared-tenant-collection"] : []),
- ...(isTransformsSyncEnabled ? ["transforms"] : []),
- ],
- "include-library": true,
-});
-```
-
----
-
-## Files to Modify
-
-1. **`enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.ts`**
- - Add state access to collection create/update/delete listeners
- - Check for transforms-namespace collections in addition to `is_remote_synced`
-
-2. **`enterprise/frontend/src/metabase-enterprise/remote_sync/components/ChangesLists/AllChangesView.tsx`**
- - Add `useSetting("remote-sync-transforms")` hook
- - Include "transforms" namespace conditionally in the collection tree query
-
----
-
-## Testing
-
-1. **Dirty state invalidation test**:
- - Enable remote-sync-transforms setting
- - Create a new transforms collection
- - Verify the dirty badge appears immediately without focus/refetch
-
-2. **Changes view hierarchy test**:
- - Create transforms and transforms collections
- - Open the changes view
- - Verify transforms collections appear with correct hierarchy/path
-
----
-
-## Implementation Order
-
-1. Fix Issue 2 first (AllChangesView) - simpler change, one file
-2. Fix Issue 1 (middleware) - more involved, needs state access pattern
diff --git a/PLAN_transforms_remote_sync_toggle.md b/PLAN_transforms_remote_sync_toggle.md
deleted file mode 100644
index b71013a6f21..00000000000
--- a/PLAN_transforms_remote_sync_toggle.md
+++ /dev/null
@@ -1,259 +0,0 @@
-# Plan: Add Transforms Remote-Sync Toggle Setting
-
-## Overview
-
-Add a toggle setting to enable/disable syncing transforms via remote-sync. The toggle should appear in:
-1. The admin remote-sync settings page (`/admin/settings/remote-sync`)
-2. The "Set up git sync" modal in the data studio
-
-The backend setting `remote-sync-transforms` already exists in `settings.clj`, but is not exposed through the API or frontend.
-
-## Current State
-
-### Backend
-- **Setting exists**: `remote-sync-transforms` in `enterprise/backend/src/metabase_enterprise/remote_sync/settings.clj:89-95`
- - Type: boolean, default: false, visibility: admin
-- **Not in API**: The PUT `/api/ee/remote-sync/settings` endpoint does NOT accept `remote-sync-transforms` in its schema
-- **Not in settings update function**: `check-and-update-remote-settings!` doesn't process this setting
-- **Backend tests exist**: Extensive tests in `transforms_test.clj` and `spec_test.clj`
-
-### Frontend
-- **No toggle exists**: `RemoteSyncSettingsForm.tsx` has no transforms toggle
-- **No constant**: `constants.ts` doesn't define a key for transforms
-- **No type definition**: `EnterpriseSettings` interface doesn't include `remote-sync-transforms`
-- **No schema validation**: `REMOTE_SYNC_SCHEMA` doesn't include transforms
-
-## Implementation Plan
-
-### Step 1: Backend API Updates
-
-**File: `enterprise/backend/src/metabase_enterprise/remote_sync/api.clj`**
-
-Update the PUT `/api/ee/remote-sync/settings` endpoint schema (lines 111-121) to accept `remote-sync-transforms`:
-
-```clojure
-:- [:map
- [:remote-sync-url {:optional true} [:maybe :string]]
- [:remote-sync-token {:optional true} [:maybe :string]]
- [:remote-sync-type {:optional true} [:maybe [:enum :read-only :read-write]]]
- [:remote-sync-branch {:optional true} [:maybe :string]]
- [:remote-sync-auto-import {:optional true} [:maybe :boolean]]
- [:remote-sync-transforms {:optional true} [:maybe :boolean]] ;; ADD THIS
- [:collections {:optional true} [:maybe [:map-of pos-int? :boolean]]]]
-```
-
-**File: `enterprise/backend/src/metabase_enterprise/remote_sync/settings.clj`**
-
-Update `check-and-update-remote-settings!` function (line 144) to include `:remote-sync-transforms` in the settings keys list:
-
-```clojure
-(doseq [k [:remote-sync-url :remote-sync-token :remote-sync-type
- :remote-sync-branch :remote-sync-auto-import :remote-sync-transforms]]
- ...)
-```
-
-### Step 2: Frontend Type Definitions
-
-**File: `frontend/src/metabase-types/api/settings.ts`**
-
-Add to `EnterpriseSettings` interface (around line 678):
-
-```typescript
-"remote-sync-transforms"?: boolean | null;
-```
-
-**File: `frontend/src/metabase-types/api/remote-sync.ts`**
-
-Update `RemoteSyncConfigurationSettings` type (lines 74-83) to include transforms:
-
-```typescript
-export type RemoteSyncConfigurationSettings = Pick<
- EnterpriseSettings,
- | "remote-sync-enabled"
- | "remote-sync-url"
- | "remote-sync-token"
- | "remote-sync-type"
- | "remote-sync-branch"
- | "remote-sync-transforms" // ADD THIS
-> & {
- collections?: CollectionSyncPreferences;
-};
-```
-
-### Step 3: Frontend Constants and Schema
-
-**File: `enterprise/frontend/src/metabase-enterprise/remote_sync/constants.ts`**
-
-Add new constant and update schema:
-
-```typescript
-export const TRANSFORMS_KEY = "remote-sync-transforms";
-
-export const REMOTE_SYNC_SCHEMA = Yup.object({
- [REMOTE_SYNC_KEY]: Yup.boolean().nullable().default(true),
- [URL_KEY]: Yup.string().nullable().default(null),
- [TOKEN_KEY]: Yup.string().nullable().default(null),
- [AUTO_IMPORT_KEY]: Yup.boolean().nullable().default(false),
- [TRANSFORMS_KEY]: Yup.boolean().nullable().default(false), // ADD THIS
- [TYPE_KEY]: Yup.string()
- .oneOf(["read-only", "read-write"] as const)
- .nullable()
- .default("read-only"),
- [BRANCH_KEY]: Yup.string().nullable().default("main"),
- [COLLECTIONS_KEY]: Yup.object().nullable().default({}),
-});
-```
-
-### Step 4: Frontend Settings Form UI
-
-**File: `enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.tsx`**
-
-1. Import the new constant:
-```typescript
-import {
- AUTO_IMPORT_KEY,
- BRANCH_KEY,
- COLLECTIONS_KEY,
- REMOTE_SYNC_KEY,
- REMOTE_SYNC_SCHEMA,
- TOKEN_KEY,
- TRANSFORMS_KEY, // ADD THIS
- TYPE_KEY,
- URL_KEY,
-} from "../../constants";
-```
-
-2. Add a new section for transforms toggle. The toggle should appear after the "Collections to sync" section (around line 432). Add a new section:
-
-```tsx
-{/* Section 5: Transforms sync (when enabled and read-write mode) */}
-{isRemoteSyncEnabled && (
- <RemoteSyncSettingsSection
- title={t`Transforms`}
- variant={variant}
- >
- <FormSwitch
- label={t`Sync transforms with git`}
- description={t`When enabled, all transforms, transform tags, and transform jobs will be synced.`}
- name={TRANSFORMS_KEY}
- size="sm"
- />
- </RemoteSyncSettingsSection>
-)}
-```
-
-**Design Considerations:**
-- The toggle should only appear when remote-sync is enabled (similar to the Collections section)
-- The toggle should work in both read-only and read-write modes
-- Include a description explaining what transforms syncing includes
-
-### Step 5: Initial Values in Form
-
-Update the `initialValues` useMemo in `RemoteSyncSettingsForm.tsx` to include the transforms setting from server data (the schema cast will handle this automatically since it's already in settingValues).
-
-No code change needed - the `REMOTE_SYNC_SCHEMA.cast(settingValues, { stripUnknown: true })` will automatically include the transforms setting once it's added to the schema.
-
-### Step 6: Tests
-
-#### Backend Tests
-
-**File: `enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj`**
-
-Add test cases for the settings endpoint accepting `remote-sync-transforms`:
-
-```clojure
-(deftest update-settings-transforms-test
- (testing "PUT /api/ee/remote-sync/settings can update remote-sync-transforms"
- (mt/with-temporary-setting-values [remote-sync-url "https://github.com/test/repo.git"
- remote-sync-transforms false]
- (mt/user-http-request :crowberto :put 200 "ee/remote-sync/settings"
- {:remote-sync-transforms true})
- (is (true? (remote-sync.settings/remote-sync-transforms))))))
-```
-
-#### Frontend Unit Tests
-
-**File: `enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.unit.spec.tsx`**
-
-Add test cases:
-
-```typescript
-describe("Transforms sync toggle", () => {
- it("should display transforms toggle when remote sync is enabled", async () => {
- await setup({ isRemoteSyncEnabled: true });
- expect(screen.getByText("Sync transforms with git")).toBeInTheDocument();
- });
-
- it("should not display transforms toggle when remote sync is disabled", async () => {
- await setup({ isRemoteSyncEnabled: false });
- expect(screen.queryByText("Sync transforms with git")).not.toBeInTheDocument();
- });
-
- it("should include transforms setting in form submission", async () => {
- const { onSubmit } = await setup({ isRemoteSyncEnabled: true });
-
- const transformsSwitch = screen.getByRole("switch", { name: /sync transforms/i });
- await userEvent.click(transformsSwitch);
-
- await userEvent.click(screen.getByTestId("remote-sync-submit-button"));
-
- expect(onSubmit).toHaveBeenCalledWith(
- expect.objectContaining({
- "remote-sync-transforms": true,
- })
- );
- });
-});
-```
-
-#### E2E Tests (Optional)
-
-**File: `e2e/test/scenarios/admin/remote-sync.cy.spec.ts`**
-
-Add E2E test for the transforms toggle:
-
-```typescript
-describe("Transforms sync toggle", () => {
- it("should allow enabling/disabling transforms sync", () => {
- cy.visit("/admin/settings/remote-sync");
-
- // Enable remote sync first
- cy.findByLabelText("Repository URL").type("https://github.com/test/repo.git");
- cy.findByLabelText("Access Token").type("test-token");
- cy.findByText("Set up Remote Sync").click();
-
- // Toggle transforms
- cy.findByText("Sync transforms with git").should("be.visible");
- cy.findByRole("switch", { name: /sync transforms/i }).click();
- cy.findByText("Save changes").click();
-
- // Verify saved
- cy.reload();
- cy.findByRole("switch", { name: /sync transforms/i }).should("be.checked");
- });
-});
-```
-
-## File Change Summary
-
-| File | Change Type | Description |
-|------|-------------|-------------|
-| `enterprise/backend/src/metabase_enterprise/remote_sync/api.clj` | Modify | Add `remote-sync-transforms` to API schema |
-| `enterprise/backend/src/metabase_enterprise/remote_sync/settings.clj` | Modify | Add transforms to `check-and-update-remote-settings!` |
-| `frontend/src/metabase-types/api/settings.ts` | Modify | Add `remote-sync-transforms` to EnterpriseSettings |
-| `frontend/src/metabase-types/api/remote-sync.ts` | Modify | Add transforms to RemoteSyncConfigurationSettings |
-| `enterprise/frontend/src/metabase-enterprise/remote_sync/constants.ts` | Modify | Add TRANSFORMS_KEY and update schema |
-| `enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.tsx` | Modify | Add transforms toggle UI |
-| `enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj` | Modify | Add tests for transforms setting |
-| `enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.unit.spec.tsx` | Modify | Add tests for transforms toggle |
-| `e2e/test/scenarios/admin/remote-sync.cy.spec.ts` | Modify (Optional) | Add E2E tests |
-
-## Notes
-
-1. **Git Settings Modal**: Since `GitSettingsModal` uses `RemoteSyncSettingsForm` with `variant="settings-modal"`, the transforms toggle will automatically appear in the modal once added to the form component. No separate changes needed for the modal.
-
-2. **Read-only vs Read-write**: The transforms toggle should be available in both modes since transforms can be synced in either direction.
-
-3. **Existing Backend Logic**: The backend already has comprehensive logic for handling transforms sync based on the `remote-sync-transforms` setting. This plan only needs to expose the setting through the API and UI.
-
-4. **Backwards Compatibility**: Setting defaults to `false`, so existing installations won't have transforms sync enabled automatically.