# Scene, resource, and registry validation

The third pillar statically validates Godot text formats (`.tscn`, `.tres`,
`project.godot`) with a tolerant, dependency-free parser. No Godot binary,
editor, or network is required. Exposed as MCP tools and `gdcorrect` CLI
subcommands. Every command reports a `findings` array with the same finding
shape as lint, and the same exit codes (0 when nothing reaches `--fail-on`,
default `error`; 1 otherwise; 2 on a usage, config, or tool error). The
surrounding JSON differs by command: `validate-scenes` and `validate-project`
return `{ root, findings, count }`, `validate-registries` adds `entries`, and
`report` groups findings into `scenes`, `project`, `registries`, and `lint`
with totals.

## Checks

### validate_scenes (`gdcorrect validate-scenes`)
For every `.tscn` under the project root (directories matched by `exclude` are skipped):

| Rule ID | Severity | Flags |
|---------|----------|-------|
| `scene-ext-resource-missing` | error | An `ext_resource` `path` that does not resolve to an existing file. |
| `scene-missing-ext-resource-id` | error | An `ExtResource("id")` reference whose id is not declared in the scene (in properties, nested arrays/dicts, or node `instance=` attributes). |
| `scene-duplicate-resource-id` | error | Two `ext_resource` declarations sharing an id. |
| `scene-ext-resource-path-stale` | warning | The `path` is missing but the `uid` resolves, so Godot still loads the file by uid. |
| `scene-ext-resource-uid-mismatch` | warning | `uid` and `path` name different existing files; Godot loads the uid's file. |
| `scene-ext-resource-uid-unknown` | warning | A uid-only `ext_resource` whose uid matches nothing in the project. |
| `scene-missing-sub-resource-id` | error | A `SubResource("id")` reference whose id has no `[sub_resource]` declaration in the file. |
| `scene-node-parent-missing` | error | A `[node parent="..."]` path that names no node declared in the scene (paths under instanced sub-scenes are skipped). |
| `scene-connection-method-missing` | error | A `[connection]` whose target node's script has no such method. Checked only when the script directly `extends` a built-in class, so its own `func`s plus the engine class chain (from the symbol DB) are the complete method set. |
| `scene-node-path-missing` | warning | A literal `$A/B`, `$"A/B"`, or `get_node("A/B")` in a script that resolves in none of the scenes the script is attached to. Skipped when any attaching scene is instanced/inherited at that node, when the path crosses an instanced child, and for absolute, `..`, and `%Unique` paths. Suppress runtime-added nodes with `# gdcorrect-ignore[scene-node-path-missing]`. |

`res://` maps to the project root. `uid://` references resolve through a static
index built from what Godot 4.4+ commits next to the files: `<file>.uid`
sidecars, `uid=` in `<asset>.import`, and `uid=` in `.tscn`/`.tres` headers. Godot
loads by uid first and falls back to the path, which is why a stale path with a
valid uid is only a warning. `run/main_scene` and autoloads may also be `uid://`.

### validate_project_config (`gdcorrect validate-project`)
Reads `project.godot`:

| Rule ID | Severity | Flags |
|---------|----------|-------|
| `project-missing` | error | No `project.godot` at the given root. |
| `project-main-scene-missing` | error / warning | `run/main_scene` points at a missing scene (error), or is a `uid://` that matches no scene in the project (warning). |
| `project-autoload-missing` | error / warning | An `[autoload]` entry points at a missing file (error), or is a `uid://` that matches nothing in the project (warning). Leading `*` handled. |
| `project-input-malformed` | warning | An `[input]` action that is not a well-formed dictionary. |
| `project-input-action-undefined` | warning | A string-literal action name passed to `Input.is_action_*`, `get_action_strength`, `get_axis`, or `get_vector` in a `.gd` file that is not defined in `[input]` (built-in `ui_*` actions are allowed; `InputMap.has_action` is ignored). |

### validate_registries (`gdcorrect validate-registries`) — the headline check
For each directory in `registryDirs`, every `.tres` (with no `registryDirs`
configured, there is nothing to validate and the command passes):

| Rule ID | Severity | Flags |
|---------|----------|-------|
| `registry-parse-error` | error | File is not a valid Godot text resource (no `gd_resource` header). |
| `registry-script-missing` | error | The resource's script `ext_resource` resolves to no existing `.gd`. Resolution matches scenes: by `uid` first, then `path`, so a stale path with a valid uid is fine. |
| `registry-dangling-path` | error | A string property that looks like a resource path points at a missing file. |
| `registry-dir-missing` | error | A `registryDirs` entry does not exist or lies outside the project root (reported against `godot-correctness.config.json`). A leading `res://` is accepted. |

When a resource's script resolves and declares `class_name`, that name is
recorded per entry in the result. The dangling-path check is why this pillar
exists: these failures are invisible until a runtime scene load.

A value is treated as a resource path when it is a string that is `res://`-prefixed,
ends in `.tscn`/`.tres`/`.gd`/`.res`/`.scn`, or whose property name matches
`pathPropertyPatterns`.

### project_report (`gdcorrect report`)
Aggregates all of the above plus GDScript lint into one JSON report with
severity counts.

## Configuration

Added to `godot-correctness.config.json` (see [config reference](./lint.md#configuration)):

```json
{
  "registryDirs": ["resources/items", "resources/levels"],
  "pathPropertyPatterns": ["*_path", "*_scene", "*_texture", "*_resource"]
}
```

- `registryDirs`: project-relative directories of data-driven `.tres` registries
  to deep-validate. Empty by default (no registry validation until configured).
- `pathPropertyPatterns`: property-name globs whose string values are treated as
  resource paths. Defaults to `*_path`, `*_scene`, `*_texture`, `*_resource`.
