schema-lint chassis v0: code-tagged diagnostics (MR-694) (#87)

First slice of the schema-lint chassis. Adds stable `OG-XXX-NNN`
codes to schema-migration rejections so operators can suppress, look
up, and filter on identifiers rather than free-text prose. Atlas-style
chassis adapted to omnigraph's typed-IR substrate (no SQL injection
vector, no per-engine locks, native edge/vector/embedding types).

What's in v0:

- New `omnigraph-compiler/src/lint/` module with:
  - `diagnostic.rs` — Family / SafetyTier / Severity enums covering ten
    families (DS, MF, CD, BC, NM, OW, NL, VE, ED, LK). Only DS and MF
    are populated in this PR.
  - `codes.rs` — 8 DiagnosticCode constants (OG-DS-101..105,
    OG-MF-103, OG-MF-104, OG-MF-106). Five of the eight are wired to
    real emission sites; the other three are reserved.
  - Unit tests for catalog invariants: codes unique, prefix matches
    family, suffixes are 3-digit, destructive defaults to error,
    lookup() works, EMITTED_IN_V0 codes exist in ALL_CODES.

- `SchemaMigrationStep::UnsupportedChange` gains an optional
  `code: Option<String>` field. New `unsupported_error_message()`
  helper prefixes the message with `[code]` when present.

- 5 of 17 existing rejection paths now carry codes:
  - `removing node type` → OG-DS-102
  - `removing edge type` → OG-DS-103
  - `removing property` → OG-DS-104
  - `adding required property without backfill` → OG-MF-103
  - `changing property type` → OG-MF-106
  Remaining 12 paths carry `code: None` and are tagged as future work.

- `schema_apply` surfaces the formatted error (with `[code]` prefix);
  CLI `omnigraph schema plan` renders the code on the
  `unsupported change on <entity>` line.

- PR #62 destructive-rejection tests in `tests/schema_apply.rs` now
  assert on the stable code (`msg.contains("OG-DS-104")`) instead of
  the error-message substring. 11/11 tests pass.

- New `docs/schema-lint.md` documents the v0 catalog + the 10 families
  + Atlas prior art. AGENTS.md index updated.

What's explicitly NOT in v0 (subsequent PRs):

- No severity config in `omnigraph.yaml` (MR-694 §2).
- No `@allow(OG-XXX-NNN, "rationale")` suppression directive (§3).
- No `--allow-data-loss` flag or destructive-tier enforcement.
- No new `SchemaMigrationStep` variants (soft/hard drops, default,
  widen/narrow). MR-700, MR-697 land those.
- No pre-migration checks (MR-941).
- No CD / VE / LK / NM family rules (MR-942..945).
- No CI integration (MR-946).

Tests: 235 compiler tests, 11 schema_apply integration tests, 14
lint module tests, 55 CLI tests — all green.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Andrew Altshuler 2026-05-13 17:08:18 +03:00 committed by GitHub
parent f28f644bf2
commit c142dafdf3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 445 additions and 24 deletions

View file

@ -53,15 +53,12 @@ pub(super) async fn apply_schema_with_lock(
let plan = plan_schema_migration(&accepted_ir, &desired_ir)
.map_err(|err| OmniError::manifest(err.to_string()))?;
if !plan.supported {
let reason = plan
let message = plan
.steps
.iter()
.find_map(|step| match step {
SchemaMigrationStep::UnsupportedChange { reason, .. } => Some(reason.as_str()),
_ => None,
})
.unwrap_or("unsupported schema migration plan");
return Err(OmniError::manifest(reason.to_string()));
.find_map(|step| step.unsupported_error_message())
.unwrap_or_else(|| "unsupported schema migration plan".to_string());
return Err(OmniError::manifest(message));
}
if plan.steps.is_empty() {
return Ok(SchemaApplyResult {
@ -141,8 +138,11 @@ pub(super) async fn apply_schema_with_lock(
}
SchemaMigrationStep::UpdateTypeMetadata { .. }
| SchemaMigrationStep::UpdatePropertyMetadata { .. } => {}
SchemaMigrationStep::UnsupportedChange { reason, .. } => {
return Err(OmniError::manifest(reason.clone()));
step @ SchemaMigrationStep::UnsupportedChange { .. } => {
return Err(OmniError::manifest(
step.unsupported_error_message()
.unwrap_or_else(|| "unsupported schema migration step".to_string()),
));
}
}
}

View file

@ -126,9 +126,10 @@ async fn apply_schema_rejects_dropping_a_property_with_data() {
// the column is nullable — it would silently destroy data.
let desired = TEST_SCHEMA.replace(" age: I32?\n", "");
let err = db.apply_schema(&desired).await.unwrap_err();
let msg = err.to_string();
assert!(
err.to_string().contains("removing property"),
"expected 'removing property' in error, got: {err}"
msg.contains("OG-DS-104"),
"expected schema-lint code OG-DS-104 in error, got: {msg}"
);
// Manifest didn't advance and existing rows are untouched.
@ -166,8 +167,8 @@ edge Knows: Person -> Person {
let err = db.apply_schema(desired).await.unwrap_err();
let msg = err.to_string();
assert!(
msg.contains("removing node type") || msg.contains("removing edge type"),
"expected drop-type error, got: {msg}"
msg.contains("OG-DS-102") || msg.contains("OG-DS-103"),
"expected schema-lint code OG-DS-102 or OG-DS-103 in error, got: {msg}"
);
assert_eq!(
db.snapshot_of(ReadTarget::branch("main"))
@ -191,9 +192,10 @@ async fn apply_schema_rejects_dropping_an_edge_type() {
// Drop only the `WorksAt` edge.
let desired = TEST_SCHEMA.replace("\nedge WorksAt: Person -> Company", "");
let err = db.apply_schema(&desired).await.unwrap_err();
let msg = err.to_string();
assert!(
err.to_string().contains("removing edge type"),
"expected 'removing edge type' error, got: {err}"
msg.contains("OG-DS-103"),
"expected schema-lint code OG-DS-103 in error, got: {msg}"
);
assert_eq!(
db.snapshot_of(ReadTarget::branch("main"))
@ -221,9 +223,10 @@ async fn apply_schema_rejects_adding_a_required_property_without_backfill() {
" age: I32?\n email: String\n}",
);
let err = db.apply_schema(&desired).await.unwrap_err();
let msg = err.to_string();
assert!(
err.to_string().contains("adding required property"),
"expected 'adding required property' error, got: {err}"
msg.contains("OG-MF-103"),
"expected schema-lint code OG-MF-103 in error, got: {msg}"
);
assert_eq!(
db.snapshot_of(ReadTarget::branch("main"))
@ -253,8 +256,8 @@ async fn plan_schema_for_property_type_narrowing_is_not_supported() {
assert!(!plan.supported, "narrowing I64 -> I32 must not be supported");
assert!(plan.steps.iter().any(|step| matches!(
step,
SchemaMigrationStep::UnsupportedChange { reason, .. }
if reason.contains("changing property type")
SchemaMigrationStep::UnsupportedChange { code, .. }
if code.as_deref() == Some("OG-MF-106")
)));
}