The approach by Stripe is very creative https://stripe.dev/blog/selective-test-execution-at-stripe-fast-ci-for-a-50m-line-ruby-monorepo , use LD_PRELOAD to track what a spec/test opens. It does get complicated fast though with stuff like bootsnap and preloading, but catches YAML access among many other things.
