blob: f138c57f724480f48e52034c6eea822b6efadda1 [file] [view] [edit]
# `verify_cl`
Static verification checks for DevTools, executed directly by Node.js without requiring a full Ninja build.
## Usage
```bash
./dt verify-cl [options]
```
Options:
- `--json`: Output a machine-readable JSON report to `stdout`.
- `--root <dir>`: Repository root directory (defaults to the `devtools-frontend` checkout root).
## Output Schema and Exit Codes
Exit codes:
- `0`: No orphan test errors (`ok === true`; non-blocking warnings may still be present).
- `1`: One or more orphan test errors (`ok === false`).
- `2`: Usage or runtime error (details written to `stderr`).
JSON output (`--json`; entries in `warnings` use the same `{code, file, message, reference}` shape as `findings`):
```json
{
"ok": false,
"findings": [
{
"code": "unwired-test-file",
"file": "front_end/panels/demo/Demo.test.ts",
"message": "Not reachable from manifest root \"//front_end:test_inputs\".",
"reference": "scripts/verify_cl/README.md#orphan-test-manifest"
}
],
"warnings": []
}
```
## Modules
- `gn_reader.ts`: Disk-only `GnBuildReader` for parsing `BUILD.gn` target metadata (`resolvedSources`, `allDeps`, `testonly`) and querying test-graph reachability and unresolved dependency labels via `getReachableTargets()`. Strips trailing toolchain suffixes and assumes conditionals in `BUILD.gn` use additive (`+=`) assignments on dependencies rather than branch-overwriting assignments.
- `checks/orphan_test_manifest.ts`: Verifies test files on disk are wired into their GN test manifest roots.
- `cli.ts`: CLI entrypoint for `./dt verify-cl`.
## orphan-test-manifest
Verifies that test files on disk are reachable from their GN test manifest roots through `testonly` `ts_library`-based targets, and that `devtools_foundation_module` test targets reachable from `//front_end:test_inputs` are also reachable from `//front_end:foundation_test_inputs`. Note that `no_emit = true` on `ts_library` targets is not checked statically.
| Directory | Suffix | Manifest root |
| --- | --- | --- |
| `front_end` | `.test.ts` | `//front_end:test_inputs` |
| `front_end` | `.test.api.ts` | `//front_end:api_test_inputs` |
| `inspector_overlay` | `.test.ts` | `//inspector_overlay:test_inputs` |
| `mcp` | `.test.ts` | `//mcp:test_inputs` |
| `test/e2e` | `.test.ts` | `//test/e2e:test_inputs` |
| `test/perf` | `.test.ts` | `//test/perf:test_inputs` |
| `test/harness/e2e` | `.test.ts` | `//test/harness:e2e_test_inputs` |
| `test/harness/unit` | `.test.ts` | `//test/harness:unit_test_inputs` |
| `test/harness/unit` | `.test.ts` | `//test/harness:foundation_test_inputs` |
Each row is enforced independently, so `test/harness/unit` `.test.ts` files must be reachable from both `//test/harness:unit_test_inputs` and `//test/harness:foundation_test_inputs`.
Files under `/fixtures/`, `/node_modules/`, `front_end/third_party/*/package/`, `front_end/legacy_test_runner/`, and `test/e2e/resources/` are excluded.
### Fixing Findings
Blocking errors (reported in `findings`, exit code `1`):
- `missing-manifest-root`: A configured manifest root target could not be found in its `BUILD.gn`. Restore the target or update `MANIFEST_DOMAINS` (or `FRONT_END_FOUNDATION_ROOT` for `//front_end:foundation_test_inputs`) in `scripts/verify_cl/checks/orphan_test_manifest.ts`.
- `unwired-test-file`: Add the test file to `sources` of a `testonly = true` `ts_library`-based target in its owning `BUILD.gn`, and ensure that target is listed in `deps` (directly or via an intermediate group) of the reported manifest root.
- `unreachable-foundation-test-target`: Add the reported `devtools_foundation_module` test target to `deps` of `//front_end:foundation_test_inputs` (typically via `front_end/BUILD.gn`).
Non-blocking warnings (reported in `warnings`, exit code `0` when no blocking errors exist):
- `unresolved-gn-target`: Static traversal from a manifest root encountered a transitive GN dependency label that could not be resolved to a literal target (for example, a typo or a target defined inside a `foreach`/template block). To avoid false-positive `unwired-test-file` and `unreachable-foundation-test-target` findings for files potentially wired behind that target, orphan and foundation checks are skipped under that label's directory — unless the label sits at the domain's top-level directory or an ancestor, in which case all domain checks stay active. Verify the label exists in `BUILD.gn` or update the dependency so `GnBuildReader` can traverse it statically.
## Presubmit Integration
`CheckOrphanTestManifest` in `PRESUBMIT.py` runs `orphan-test-manifest` on upload and commit whenever a CL adds or
modifies `*.test.ts`, `*.test.api.ts`, `BUILD.gn`, `scripts/build/**/*.gni`, or files under `scripts/verify_cl/` or
`scripts/gn_deps_verifier/`. Add a `Skip-Orphan-Test-Manifest-Check: <reason>` footer in the CL description to bypass
only this check if an unrelated issue on `main` blocks upload or submission.
## Development
Type-check and run the unit test suite:
```bash
autoninja -C out/Default scripts/verify_cl
./dt test scripts/verify_cl/tests
```