Skip to content

explore and doctor: propose generated subjects, find DbContext classes by base, report missing SDK pins - #418

Open
agorischek wants to merge 2 commits into
mainfrom
agorischek-crispy-dollop
Open

agorischek wants to merge 2 commits into
mainfrom
agorischek-crispy-dollop

Conversation

@agorischek

Copy link
Copy Markdown
Collaborator

What changed

Setup trials found three ways projections explore and projections doctor miss a repository's subjects or needs.

  • Generated subjects were skipped. Explore dropped every file .gitattributes marks linguist-generated before matching detection patterns, so it never proposed rails-schema for an app whose db/schema.rb is marked generated, which the default .gitattributes of a new Rails app does. Detection now skips only vendored files, so a generated schema dump, db/structure.sql, lockfile or migration snapshot still proposes the built-in that reads it. Projections of the whole repository still skip generated files and still get the exclusion globs. Vendored paths and the ignored directories (vendor, node_modules, third_party, tests, fixtures) still propose nothing.
  • efcore-schema matched file names. It was proposed only for *DbContext.cs, so a context in DatabaseContext.cs was never found. It now detects **/*.cs and, like tetragon-policies, keeps only files that declare a class deriving from DbContext, IdentityDbContext<…> (or another …DbContext base, such as ApiAuthorizationDbContext<…>). A cheap text scan handles primary constructors and qualified names, and it ignores generic constraints (where T : DbContext) and DbContextOptions.
  • SDK pins weren't reported as needs. Doctor, and the needs of explore's .NET candidates, now read the nearest global.json above the project (sdk.version, rollForward with its patch default, allowPrerelease, and paths per the SDK resolver's rules). They compare it with dotnet --list-sdks and report a fail or install need naming the pin, the SDKs the policy accepts and what is installed. A missing dotnet (or inputs.dotnet) is also reported. Nothing is run for snapshot inputs or for a repository-relative inputs.dotnet, because doctor never runs repository code. Explore's Rust candidates now also report a rust-toolchain.toml channel that rustup lacks, reusing doctor's existing check.

Evidence

  • npm run tools -- check --fast: passed (includes cargo check --all-targets, cargo fmt, considered complexity budgets).

  • cargo test -p projections-cli --lib -- explore:: doctor::: 50 passed. New unit tests cover roll-forward policies, prerelease ordering, paths, the nearest global.json, context detection and toolchain needs.

  • cargo test -p projections-cli --test authoring -- explore_proposes doctor_and_explore_report a_candidate_is_shown_and_compared: new regression tests explore_proposes_generated_subjects_and_contexts_by_their_base_class and doctor_and_explore_report_an_sdk_global_json_pins_that_isnt_installed (fake dotnet with only SDK 11 against a pin of 10.0.100) passed, along with the other explore tests. a_candidate_is_shown_and_compared_before_it_is_adopted failed locally only because the default comparator Wasm wasn't built (its first compare step); its efcore fixture now derives from DbContext, and I checked that adopt --dry-run path manually with the built CLI.

  • Manual: against a real dotnet with only SDK 11.0.100 installed, explore --list for a repo pinning 10.0.100 (latestFeature) lists the missing SDK as a need.

  • Not run locally (disk): clippy, the full test suites and regenerating reference docs. The one generated line in docs/builtins/extractors/efcore-schema.md was set to exactly what builtins.mjs emits for the new detects.

  • Documentation that this change affects is updated, and generated reference
    pages are regenerated (npm run docs:generate).

  • Fixes include a regression test.

  • A changelog fragment at changelog.d/<this PR's number>.md describes what
    users will notice, or the PR has the no changelog label (see
    changelog.d/README.md).

  • No credentials, private source or machine-specific paths are included.

agorischek and others added 2 commits December 5, 2026 03:53
…report missing SDK pins

- explore matches a built-in's detection patterns against generated files too
  (only vendored files are skipped), so a linguist-generated db/schema.rb or
  db/structure.sql proposes rails-schema. Whole-repository candidates still
  skip generated files.
- efcore-schema is proposed for any C# file declaring a class that derives
  from DbContext or IdentityDbContext, whatever the file is named.
- doctor and explore's needs report a global.json SDK pin (version and
  rollForward) that the installed dotnet --list-sdks can't satisfy, and a
  missing dotnet; explore also reports a rust-toolchain.toml pin rustup lacks.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The dotnet executable check can allow repository-controlled code to run without --trust and with the full process environment, leaving a critical security issue unresolved.

4 open issues
What changed in this PR

Improves Projections’ subject discovery and toolchain diagnostics so setup identifies more usable inputs and missing prerequisites.

Changes:

  • Proposes generated subjects while preserving vendored exclusions.
  • Detects EF Core contexts by base class rather than filename.
  • Reports missing .NET SDK pins and Rust toolchains.
File Description
packages/​extractors/​efcore-schema/​src/​lib.rs Broadens detection to C# files.
packages/​cli/​tests/​authoring.rs Adds discovery and SDK diagnostic regressions.
packages/​cli/​src/​explore/​vendored.rs Separates generated and vendored filtering.
packages/​cli/​src/​explore/​typescript/​tsconfig.rs Exposes JSON-with-comments parsing.
packages/​cli/​src/​explore/​typescript.rs Enables parser reuse.
packages/​cli/​src/​explore/​tetragon.rs Shares bounded file reading.
packages/​cli/​src/​explore/​needs.rs Adds candidate toolchain needs.
packages/​cli/​src/​explore/​efcore.rs Filters C# files for context declarations.
packages/​cli/​src/​explore.rs Integrates discovery filters and needs.
packages/​cli/​src/​doctor/​toolchains.rs Shares Rust toolchain checks.
packages/​cli/​src/​doctor/​dotnet.rs Adds SDK pin and availability checks.
packages/​cli/​src/​doctor.rs Integrates .NET diagnostics.
docs/​builtins/​extractors/​efcore-schema.md Updates the documented detection glob.
changelog.d/​418.md Documents discovery and diagnostic fixes.
changelog.d/​418-behaviour-changes.md Documents new doctor failure conditions.

Review effort: Balanced

.unwrap_or_else(|| project.to_owned());
let pin = Pin::find(&built)?;
let shown = pin.file.strip_prefix(project).unwrap_or(&pin.file).display().to_string();
unmet(&pin, &shown, &dotnet.display().to_string(), || listed(&dotnet))
Comment on lines +267 to +271
let runs_dotnet = match &definition["extractor"] {
Value::String(builtin) => BUILTINS.contains(&builtin.as_str()) && crate::extractors::requires_trust(definition),
extractor => extractor["command"][0]
.as_str()
.is_some_and(|program| ["dotnet", "dotnet.exe"].contains(&program)),
Comment on lines +297 to +301
let built = definition["inputs"]["project"]
.as_str()
.or_else(|| definition["inputs"]["projects"][0].as_str())
.and_then(|file| project.join(file).parent().map(Path::to_owned))
.unwrap_or_else(|| project.to_owned());
}

fn declares_context(class: &regex::Regex, text: &str) -> bool {
text.contains("Context") && class.is_match(text)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants