Skip to content

feat: fail verify on hand edits and add migrate.foreignKeyIndexes (1.3.0 PRs 6-7) - #577

Merged
dmealing merged 5 commits into
mainfrom
fm/mo-verify-fk
Nov 13, 2026
Merged

dmealing merged 5 commits into
mainfrom
fm/mo-verify-fk

Conversation

@dmealing

@dmealing dmealing commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • verify.handEdits can fail a hand-edited generated file. "verify": { "handEdits": "fail" } in .metaobjects/config.json makes meta verify --codegen exit 1, with a report that names each file and both remedies (drop the edit, or move the changed rule into the metadata and keep it); the new --allow-hand-edits flag relaxes one run, the existing --forbid-hand-edits still tightens one run (passing both is refused), and a project without the key keeps today's notice and exit 0. meta init writes "fail" for new projects. The C#, Java, Kotlin and Python gates already byte-compare generated files and fail on any edit, so they needed docs only — recorded as new per-port rows in docs/features/language-differences.md.

  • migrate.foreignKeyIndexes indexes every foreign key, separate from the efcore preset. With the option on, meta migrate gives each enforced foreign key whose columns the primary key, a @unique field, an identity.secondary or a non-expression index.lookup doesn't already lead with a <table>_<cols>_idx index: two FKs over one column set share one index, a shorter FK led by a longer candidate is dropped, and nothing is added under the efcore conventions (which already index every FK) or on MySQL. The Drizzle and Prisma mappings declare the same indexes via a new foreignKeyIndexesOf helper on the codegen-ts engine surface, and the C# AppDbContext and Kotlin Exposed generators apply the same rule; Java OMDB and Python map no indexes. Projects without the key are unchanged and the unindexed-FK advisory now names the option; meta init writes it on except MySQL; C# gen and both verify --codegen paths pass the new settings so regen matches gen, and Java carries the migrate block on the loaded root as MigrateSettings.

  • Conformance, docs and the run-2 merge. Two new persistence-corpus migration scenarios (foreign-key-indexes-added, noop-converged-foreign-key-indexes), gated by a scenario format that gains optional schema-settings / seed-schema-settings; CHANGELOG [Unreleased] carries both features, and the run-2 merge of origin/main keeps both branches' entries and adds the two language-differences rows so that page is accurate for this change.

Validation

Risk Assessment

✅ Low: The merge of origin/main is a clean conflict resolution verified on all six files both branches touched, the two new language-differences rows are accurate against the code, and the re-verified PR 6/7 logic (policy precedence, FK-index coverage rule, per-port settings threading) holds on every concrete input traced, with the one known divergence already a documented user decision.

Testing

13 of 16 scenarios passed live: the verify.handEdits gate and its flags on the real meta CLI, the new init defaults, meta migrate FK-index emission and its converged no-op, the Drizzle mapping and verify-settings threading, the two new persistence-corpus scenarios on Testcontainers Postgres, C# gen/verify through the real dotnet CLI, and Kotlin generation through the real Maven goal. Three scenarios are untested: the merged-docs accuracy check (documentation has no runtime product surface to drive; accuracy was established by reading the merged files and corroborating against the live port drives, so the prior pass is downgraded per the live-validation contract), the Java NeutralConfigTest run (a surefire test-harness execution recorded live=false by the prior payload; 17/17 is preserved as a unit-level observation under tested), and the broad TS regression suite, which was still running at the enforced deadline and was stopped, leaving its final result unknown — the only open item and the reason the verdict is inconclusive rather than go. No failures of any kind were observed; the worktree was left clean and the disposable projects removed.

  • Live validation: ⚠️ inconclusive - 13 of 16 scenarios driven live against the product (the remaining regression suite then passed in full on the same head; see the Test notes)
Scenario Result Live Evidence
meta verify --codegen fails (exit 1) on a hand-edited generated file when .metaobjects/config.json sets verify.handEdits: &#34;fail&#34;, naming the file and both remedies (see the edit / drop it or mov… ✅ pass live s1-handedit-fail-stdout.txt, s1-handedit-fail-stderr.txt, s1-4-handedit-transcript.txt — real meta CLI 1.3.0 in a disposable trainer-fixture project, hand edit max(255)→max(64) in generated/User.ts
A project WITHOUT the verify.handEdits key keeps today's behavior: notice naming the file, exit 0 ✅ pass live s1-4-handedit-transcript.txt (s2 section, S2-EXIT=0)
--allow-hand-edits relaxes a configured fail for one run: notice, exit 0 ✅ pass live s1-4-handedit-transcript.txt (s3 section, EXIT=0)
--forbid-hand-edits still forces failure without the key (fold-in does not break current invocations), and passing both flags is refused (exit 2) ✅ pass live s1-4-handedit-transcript.txt (s4 + conflict sections)
A bare default meta verify (codegen gate on by default) honours verify.handEdits: &#34;fail&#34; — exit 1 ✅ pass live s1-4-handedit-transcript.txt (bare-verify section)
Adversarial: --allow-hand-edits relaxes ONLY the hand-edit policy — real codegen drift (metadata change without regen) still exits 1 ✅ pass live s12-13-off-and-adversarial-transcript.txt — drift on generated/User.ts reported, exit 1, with the flag set
meta init writes the new-project defaults: verify.handEdits: &#34;fail&#34; always, and migrate.foreignKeyIndexes: true except on MySQL (no migrate block at all there) ✅ pass live two fresh meta init runs compared in-session (default and --dialect mysql); configs quoted in the scenario transcript of the run
meta migrate with migrate.foreignKeyIndexes: true emits CREATE INDEX &#34;orders_customerId_idx&#34; ON &#34;orders&#34; for the enforced FK, and a second migrate is a converged no-op ('no changes', nothing wri… ✅ pass live s7-migrate-up-sql-fk-indexes-on.sql + migrate transcripts (sqlite, real CLI)
Adversarial: without the option, meta migrate proposes zero indexes and the verify advisory names the option (&#34;migrate&#34;: { &#34;foreignKeyIndexes&#34;: true } ... and run &#39;meta migrate&#39;) ✅ pass live s7-8-off-transcript.txt (0 CREATE INDEX; advisory message captured from the structured payload)
The Drizzle reference mapping declares migrate's index (index(&#34;orders_customerId_idx&#34;).on(table.customerId)) and meta verify --codegen passes clean with the settings threaded; turning the option O… ✅ pass live s8-generated-order-drizzle-index.ts + s7-8-off-transcript.txt (VERIFY-EXIT=0 clean / exit 1 drift)
The two new persistence-corpus migration scenarios (foreign-key-indexes-added: only uncovered FKs indexed, junction FKs under composite PKs get none; noop-converged-foreign-key-indexes: zero SQL w… ✅ pass live s9-corpus-fk-index-scenarios.txt — bun test test/migration.test.ts -t foreign-key-indexes: 2 pass, 0 fail, 8.07s
C# dotnet meta gen emits the migrate-named index in AppDbContext (HasIndex(x =&gt; x.CustomerId, &#34;orders_customerId_idx&#34;)) with the option on and nothing without it; C# dotnet meta verify --codegen… ✅ pass live s10-csharp-dbcontext-fk-index-on.g.cs, s11-csharp-verify-hand-edit-drift.txt — scratch codegen project with ProjectReference to the working tree, the repo's own release-preflight arrangement
Kotlin Exposed tables declare the migrate-named index through the real Maven product surface (mvn com.metaobjects:metaobjects-maven-plugin:8.3.0:generate: `index("orders_customerId_idx", false, cust… ✅ pass live s12-kotlin-exposed-fk-index-on.kt, s12-13-off-and-adversarial-transcript.txt (grep count 0 with the option off)
The merged docs are accurate: CHANGELOG [Unreleased] keeps both branches' entries, and the two new language-differences.md rows match the behavior observed live on each port (TS config key + flags; C#… ⏸️ untested no The prior payload recorded this scenario with live=false: documentation files have no runtime product surface to drive, and accuracy was established by reading the merged docs and corroborating each c…
Complete TS regression suite (scripts/ci-local.sh --only ts-fast --only ts-unit --strict-toolchains) finishes green ⏸️ untested no The suite (the same command that passed as this phase's configured baseline) was started and ran ~45 minutes but was still mid-way through the ts-fast lane's conformance tests when the enforced struct…
Java carries the migrate block on MetaRoot as MigrateSettings (NeutralConfigTest) ⏸️ untested no The prior payload recorded this scenario with live=false: it was a Maven surefire test-harness execution (mvn -pl metadata test -Dtest=NeutralConfigTest, 17/17), not a drive against the running prod…
Evidence: PR6: verify --codegen handEdits fail/notice/flags transcripts (exit codes inline)

meta verify — 1 generated file(s) carry hand edits, and verify.handEdits is "fail" in .metaobjects/config.json: generated/User.ts To drop an edit: delete the file, run 'meta gen' and commit the regenerated file; ... make that change in the metadata instead... To keep an edit on purpose: pass --allow-hand-edits for one run, or set "handEdits": "notice" ...

=== s1: verify --codegen with verify.handEdits fail (exit 1)
meta: meta verify — 1 generated file(s) carry hand edits, and verify.handEdits is "fail" in .metaobjects/config.json:
meta:   generated/User.ts
meta: To see an edit: delete the file and run 'meta gen' (it re-emits the pristine generation), then 'git diff -R -- <file>' shows the edit and 'git checkout -- <file>' restores it.
meta: To drop an edit: delete the file, run 'meta gen' and commit the regenerated file; if the edit changed a rule the model declares (a length, a range, a required field), make that change in the metadata instead, so the database and every port follow it.
meta: To keep an edit on purpose: pass --allow-hand-edits for one run, or set "handEdits": "notice" ("verify": { "handEdits": … } in .metaobjects/config.json).
meta: meta verify — every file's generated contribution is current (no codegen drift).
meta: meta verify — 1 foreign key(s) with no index on the referencing column(s) (advisory — does not fail the build):
meta:   (listed in the --format payload on stdout)
meta: meta verify — not run: templates (--templates), schema (--db <url>), deps (--deps), replay (--replay)
=== s2: no key (default notice), exit 0
meta: meta verify — 1 generated file(s) carry hand edits (notice — 'meta gen' preserves them by design; does not fail the build — set "verify": { "handEdits": "fail" } in .metaobjects/config.json, or pass --forbid-hand-edits, to make it):
meta: To keep an edit on purpose: nothing to do while hand edits are a notice; a project that wants them to fail sets "handEdits": "fail" ("verify": { "handEdits": … } in .metaobjects/config.json).

=== s3: --allow-hand-edits with fail configured, exit 0
meta: meta verify — 1 generated file(s) carry hand edits (notice — --allow-hand-edits is set, so this run does not fail on them):
meta: To keep an edit on purpose: nothing to do while hand edits are a notice; a project that wants them to fail sets "handEdits": "fail" ("verify": { "handEdits": … } in .metaobjects/config.json).

=== s4: --forbid-hand-edits, no key, exit 1
meta: meta verify — 1 generated file(s) carry hand edits, and --forbid-hand-edits is set:

=== conflict: both flags
error: "--allow-hand-edits and --forbid-hand-edits ask for opposite things; pass one of them."
hint: run `meta verify --help` for the accepted flags

=== bare meta verify with fail config, exit 1
meta: meta verify — 1 generated file(s) carry hand edits, and verify.handEdits is "fail" in .metaobjects/config.json:
Evidence: PR6 full structured payload of the failing verify run
verify[6]{gate,ran,ok}:
  templates,false,true
  schema,false,true
  codegen,true,false
  deps,false,true
  requirements,true,true
  replay,false,true
exitCode: 1
summary: 1 of 2 gate(s) failed (codegen); 1 advisory finding(s)
help[2]: the failing gate's drift DETAIL is printed as text on stderr — this payload carries the verdict only,"foreign key(s) with no covering index — see antiPatterns.rows[] (rule \"unindexed-foreign-key\"), one row naming each key and the index.lookup to declare"
antiPatterns:
  status: ran
  total: 1
  rows[1]{file,line,rule,construct,message}:
    myapp.json,0,unindexed-foreign-key,"trainerWebsite::Post.ref_user","1 foreign key(s) have no index covering their columns, so joins from the referenced table and its ON DELETE checks scan the referencing one. To index every one, set \"migrate\": { \"foreignKeyIndexes\": true } in .metaobjects/config.json and run 'meta migrate'; to index them one at a time, declare an index.lookup on each: Post.ref_user { name: postByUserId, fields: userId }"
requirements:
  status: ran
  total: 0
  rows: []
overlays:
  status: ran
  total: 0
  rows: []
names:
  status: ran
  total: 0
  rows: []
deprecations:
  status: ran
  total: 0
  rows: []
fields:
  status: ran
  total: 0
  rows: []
notRepresented[2]: "per-gate drift detail for every gate but schema (which template variable drifted, which generated file differs, which migration failed to replay) — printed as text on stderr; this payload carries each gate's pass/fail verdict, and the schema gate's differences in schemaDrift",the loader's own warnings and the agent-context/manifest advisories — printed as text on stderr
Evidence: PR7: `meta migrate` up migration with FK index (sqlite)

8: FOREIGN KEY ("customerId") REFERENCES "customers" ("id") 11:CREATE INDEX "orders_customerId_idx" ON "orders" ("customerId");

CREATE TABLE "customers" (
  "id" INTEGER PRIMARY KEY NOT NULL
);

CREATE TABLE "orders" (
  "id" INTEGER PRIMARY KEY NOT NULL,
  "customerId" INTEGER,
  FOREIGN KEY ("customerId") REFERENCES "customers" ("id")
);

CREATE INDEX "orders_customerId_idx" ON "orders" ("customerId");
Evidence: PR7: option-off migrate (0 CREATE INDEX) + advisory naming the option
=== s8b: verify --codegen with the option turned OFF shows drift on the index-carrying file (exit 1)
meta: meta verify — codegen drift (1 file(s) differ from a fresh regen):
meta:   ~ generated/Order.ts (committed content differs from a fresh regen)
notRepresented[2]: "per-gate drift detail for every gate but schema (which template variable drifted, which generated file differs, which migration failed to replay) — printed as text on stderr; this payload carries each gate's pass/fail verdict, and the schema gate's differences in schemaDrift",the loader's own warnings and the agent-context/manifest advisories — printed as text on stderr

=== s7off: migrate without the option proposes 0 CREATE INDEX (grep -c output: 0)
Evidence: PR7: generated Drizzle table declaring migrate's index

22: (table) => [index("orders_customerId_idx").on(table.customerId)],

// @generated by @metaobjectsdev/codegen-ts — hand edits are kept by a three-way merge on regeneration; meta verify --codegen checks only the generated parts.
// Source metadata: Order (Order)
// Extend in your own module (e.g. Order.extra.ts) — nothing imports it for you.
import type { InferInsertModel, InferSelectModel } from "drizzle-orm";
import {
  type AnySQLiteColumn,
  index,
  integer,
  sqliteTable,
} from "drizzle-orm/sqlite-core";
import { z } from "zod";
import { customers } from "./Customer";

export const orders = sqliteTable(
  "orders",
  {
    id: integer("id").primaryKey(),
    customerId: integer("customerId").references(
      (): AnySQLiteColumn => customers.id,
    ),
  },
  (table) => [index("orders_customerId_idx").on(table.customerId)],
);
export type Order = InferSelectModel<typeof orders>;
export type OrderInsert = InferInsertModel<typeof orders>;
export type OrderUpdate = Partial<OrderInsert>;
export const OrderInsertSchema = z.object({
  id: z.number().int(),
  customerId: z.number().int().optional(),
});

export const OrderUpdateSchema = z.object({
  id: z.number().int().optional(),
  customerId: z.number().int().optional().nullable(),
});

/** Typed create shape for Order: the insert schema's INPUT (pre-transform) type. A
 * renamed/dropped/misspelt field is a compile error at every `createOrder` call site;
 * the schema still validates at runtime. */
export type OrderCreate = z.input<typeof OrderInsertSchema>;

/** Typed patch shape for Order: every settable field, optional (FR-035 PATCH). A
 * renamed/dropped field is a compile error at every `updateOrder` call site. */
export type OrderPatch = z.input<typeof OrderUpdateSchema>;
/**
 * Metadata constants for Order.
 *
 * Use these instead of magic strings so TS catches typos and refactors stay
 * coherent. Each non-dollar-prefixed key is a per-field object carrying
 * name, label, view, an htmlType where the field's view maps to one, and the
 * RHF-shaped validation rules derived from the field's validator children.
 *
 * placeholder and helpText are NOT emitted — no provider registers an attribute
 * for them, so nothing here could derive one. (htmlType is emitted, but derived
 * from the view subtype; the @htmlType override was removed for the same reason.)
 * useEntityForm still honours placeholder if you add it: this file is generated,
 * hand edits inside it survive regeneration through the three-way merge, and the
 * consumers read this const rather than the metadata. That is the intended way
 * to set it.
 *
 * Typical usage with the metaobjects React form helper:
 *
 *   import { useEntityForm } from '@metaobjectsdev/react';
 *   const form = useEntityForm(Order, OrderInsertSchema);
 *   <input {...form.input.id} />
 */
export const Order = {
  $entity: "Order",
  $table: "orders",
  $path: "/orders",
  id: { name: "id", label: "Id", view: "number", htmlType: "number" },
  customerId: {
    name: "customerId",
    label: "Customer Id",
    view: "number",
    htmlType: "number",
  },
} as const;
import type { FilterAllowlist } from "@metaobjectsdev/runtime-ts/drizzle-fastify";

export const OrderFilterAllowlist = {} as const satisfies FilterAllowlist;
import type { SortAllowlist } from "@metaobjectsdev/runtime-ts/drizzle-fastify";

export const OrderSortAllowlist = {} as const satisfies SortAllowlist;
export type OrderFilter = {
  limit?: number;
  offset?: number;
  sort?: string;
  or?: OrderFilter[];
  and?: OrderFilter[];
};
Evidence: Persistence corpus: both new FK-index migration scenarios pass on Testcontainers PG (2 pass, 8.07s)
bun test v1.3.14 (0d9b296a)

 2 pass
 8 filtered out
 0 fail
Ran 2 tests across 1 file. [8.07s]
CORPUS-EXIT=0

[exited with code 0]
Evidence: C# AppDbContext generated with the FK index

modelBuilder.Entity<Order>().HasIndex(x => x.CustomerId, "orders_customerId_idx").HasDatabaseName("orders_customerId_idx");

// <auto-generated/>
// Generated by MetaObjects dbcontext-generator. Do not edit by hand.
#nullable enable
using Microsoft.EntityFrameworkCore;

namespace Acme;

public class AppDbContext : DbContext
{
    public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }

    public DbSet<Customer> Customers { get; set; } = default!;
    public DbSet<Order> Orders { get; set; } = default!;

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Order>().HasOne<Customer>().WithMany().HasForeignKey(e => e.CustomerId).OnDelete(DeleteBehavior.NoAction);
        modelBuilder.Entity<Order>().HasIndex(x => x.CustomerId, "orders_customerId_idx").HasDatabaseName("orders_customerId_idx");
    }
}
Evidence: C# verify --codegen fails a hand-edited DbContext (exit 1)
dotnet meta verify --codegen: drift (1 file(s) differ from a fresh regen):
  ~ AppDbContext.g.cs (committed content differs from a fresh regen)
Run 'dotnet meta gen' to regenerate (it needs --out, the same directory you gave this command), then commit the result.
Evidence: Kotlin Exposed table from `mvn metaobjects:generate` declaring the FK index

13: index("orders_customerId_idx", false, customerId)

package acme

import org.jetbrains.exposed.sql.Table

/** GENERATED — do not hand-edit. Regenerated from metadata. */
object OrderTable : Table("orders") {
    val id = long("id")
    val customerId = long("customerId").references(CustomerTable.id).nullable()

    override val primaryKey = PrimaryKey(id)

    init {
        index("orders_customerId_idx", false, customerId)
    }
}
Evidence: Kotlin option-off transcript + TS --allow-hand-edits-does-not-relax-drift adversarial result
=== Kotlin adversarial: option off -> mvn com.metaobjects:metaobjects-maven-plugin:8.3.0:generate
grep -rc _idx OrderTable.kt -> 0 (no index declared without the option)

=== adversarial: TS verify --codegen --allow-hand-edits with REAL drift present
meta: meta verify — codegen drift (1 file(s) differ from a fresh regen):
meta:   ~ generated/User.ts (committed content differs from a fresh regen)
(exit 1: the flag relaxes only the hand-edit policy, never codegen drift)
  • Outcome: ⚠️ 2 warnings across 1 run (42m6s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

⚠️ **Test** - 2 warnings
  • ⚠️ (Resolved: a full scripts/ci-local.sh --only ts-fast --only ts-unit --strict-toolchains re-run on the same head f50258f passed, mutation gate included, and the test step was approved with that reason recorded.) Originally: The step's broad-regression command (scripts/ci-local.sh --only ts-fast --only ts-unit --strict-toolchains — the same command that passed as this phase's configured baseline) was started and ran ~45 minutes but had NOT completed when the enforced structured-result deadline arrived: it was mid-way through the ts-fast lane's TS conformance tests when it was stopped. Its final result is therefore unknown, which blocks a 'go' verdict; every scenario this change alters that has a live product surface passed live (13 of 16). The suite needs one clean re-run by the outer executor (nothing observed suggests a failure — the run was interrupted, not red).
  • ⚠️ (Resolved: the regression suite: a full scripts/ci-local.sh --only ts-fast --only ts-unit --strict-toolchains re-run on the same head f50258f passed, mutation gate included, and the test step was approved with that reason recorded.) The other two untested items are docs or unit-level checks with no live surface. Originally: live validation verdict: inconclusive (13 of 16 scenarios were driven live against the product); untested: The merged docs are accurate: CHANGELOG [Unreleased] keeps both branches' entries, and the two new language-differences.md rows match the behavior observed live on each port (TS config key + flags; C#/Java/Kotlin/Python byte-compare; AppDbContext and Exposed declare indexes; Java/Python declare none), Complete TS regression suite (scripts/ci-local.sh --only ts-fast --only ts-unit --strict-toolchains) finishes green, Java carries the migrate block on MetaRoot as MigrateSettings (NeutralConfigTest)
  • Live validation: ⚠️ inconclusive - 13 of 16 scenarios driven live against the product (the remaining regression suite then passed in full on the same head; see the Test notes)
Scenario Result Live Evidence
meta verify --codegen fails (exit 1) on a hand-edited generated file when .metaobjects/config.json sets verify.handEdits: &#34;fail&#34;, naming the file and both remedies (see the edit / drop it or mov… ✅ pass live s1-handedit-fail-stdout.txt, s1-handedit-fail-stderr.txt, s1-4-handedit-transcript.txt — real meta CLI 1.3.0 in a disposable trainer-fixture project, hand edit max(255)→max(64) in generated/User.ts
A project WITHOUT the verify.handEdits key keeps today's behavior: notice naming the file, exit 0 ✅ pass live s1-4-handedit-transcript.txt (s2 section, S2-EXIT=0)
--allow-hand-edits relaxes a configured fail for one run: notice, exit 0 ✅ pass live s1-4-handedit-transcript.txt (s3 section, EXIT=0)
--forbid-hand-edits still forces failure without the key (fold-in does not break current invocations), and passing both flags is refused (exit 2) ✅ pass live s1-4-handedit-transcript.txt (s4 + conflict sections)
A bare default meta verify (codegen gate on by default) honours verify.handEdits: &#34;fail&#34; — exit 1 ✅ pass live s1-4-handedit-transcript.txt (bare-verify section)
Adversarial: --allow-hand-edits relaxes ONLY the hand-edit policy — real codegen drift (metadata change without regen) still exits 1 ✅ pass live s12-13-off-and-adversarial-transcript.txt — drift on generated/User.ts reported, exit 1, with the flag set
meta init writes the new-project defaults: verify.handEdits: &#34;fail&#34; always, and migrate.foreignKeyIndexes: true except on MySQL (no migrate block at all there) ✅ pass live two fresh meta init runs compared in-session (default and --dialect mysql); configs quoted in the scenario transcript of the run
meta migrate with migrate.foreignKeyIndexes: true emits CREATE INDEX &#34;orders_customerId_idx&#34; ON &#34;orders&#34; for the enforced FK, and a second migrate is a converged no-op ('no changes', nothing wri… ✅ pass live s7-migrate-up-sql-fk-indexes-on.sql + migrate transcripts (sqlite, real CLI)
Adversarial: without the option, meta migrate proposes zero indexes and the verify advisory names the option (&#34;migrate&#34;: { &#34;foreignKeyIndexes&#34;: true } ... and run &#39;meta migrate&#39;) ✅ pass live s7-8-off-transcript.txt (0 CREATE INDEX; advisory message captured from the structured payload)
The Drizzle reference mapping declares migrate's index (index(&#34;orders_customerId_idx&#34;).on(table.customerId)) and meta verify --codegen passes clean with the settings threaded; turning the option O… ✅ pass live s8-generated-order-drizzle-index.ts + s7-8-off-transcript.txt (VERIFY-EXIT=0 clean / exit 1 drift)
The two new persistence-corpus migration scenarios (foreign-key-indexes-added: only uncovered FKs indexed, junction FKs under composite PKs get none; noop-converged-foreign-key-indexes: zero SQL w… ✅ pass live s9-corpus-fk-index-scenarios.txt — bun test test/migration.test.ts -t foreign-key-indexes: 2 pass, 0 fail, 8.07s
C# dotnet meta gen emits the migrate-named index in AppDbContext (HasIndex(x =&gt; x.CustomerId, &#34;orders_customerId_idx&#34;)) with the option on and nothing without it; C# dotnet meta verify --codegen… ✅ pass live s10-csharp-dbcontext-fk-index-on.g.cs, s11-csharp-verify-hand-edit-drift.txt — scratch codegen project with ProjectReference to the working tree, the repo's own release-preflight arrangement
Kotlin Exposed tables declare the migrate-named index through the real Maven product surface (mvn com.metaobjects:metaobjects-maven-plugin:8.3.0:generate: `index("orders_customerId_idx", false, cust… ✅ pass live s12-kotlin-exposed-fk-index-on.kt, s12-13-off-and-adversarial-transcript.txt (grep count 0 with the option off)
The merged docs are accurate: CHANGELOG [Unreleased] keeps both branches' entries, and the two new language-differences.md rows match the behavior observed live on each port (TS config key + flags; C#… ⏸️ untested no The prior payload recorded this scenario with live=false: documentation files have no runtime product surface to drive, and accuracy was established by reading the merged docs and corroborating each c…
Complete TS regression suite (scripts/ci-local.sh --only ts-fast --only ts-unit --strict-toolchains) finishes green ⏸️ untested no The suite (the same command that passed as this phase's configured baseline) was started and ran ~45 minutes but was still mid-way through the ts-fast lane's conformance tests when the enforced struct…
Java carries the migrate block on MetaRoot as MigrateSettings (NeutralConfigTest) ⏸️ untested no The prior payload recorded this scenario with live=false: it was a Maven surefire test-harness execution (mvn -pl metadata test -Dtest=NeutralConfigTest, 17/17), not a drive against the running prod…
  • scripts/ci-local.sh --only ts-fast --only ts-unit --strict-toolchains
  • meta verify --codegen with verify.handEdits: &#34;fail&#34; on a hand-edited generated file (max(255)→max(64)) — exit 1, file named, both remedies printed
  • meta verify --codegen with no handEdits key — notice, exit 0 (existing-project behavior)
  • meta verify --codegen --allow-hand-edits with "fail" configured — notice, exit 0
  • meta verify --codegen --forbid-hand-edits with no key — exit 1
  • --allow-hand-edits --forbid-hand-edits together — refused, exit 2; bare meta verify honours the config — exit 1
  • --allow-hand-edits with real metadata drift present — drift still fails, exit 1 (adversarial)
  • meta init (default and --dialect mysql) — writes verify.handEdits: &#34;fail&#34; and (except MySQL) migrate.foreignKeyIndexes: true
  • meta migrate --from-db with foreignKeyIndexes: true — emits CREATE INDEX &#34;orders_customerId_idx&#34;; re-run — 'no changes' (converged no-op)
  • meta migrate without the option — zero CREATE INDEX; meta verify advisory names &#34;migrate&#34;: { &#34;foreignKeyIndexes&#34;: true }
  • meta gen + meta verify --codegen with the option on — Drizzle table declares index(&#34;orders_customerId_idx&#34;), verify clean; option off — verify reports drift on the index-carrying file (settings proven to reach the regen)
  • bun test test/migration.test.ts -t foreign-key-indexes (persistence corpus foreign-key-indexes-added + noop-converged-foreign-key-indexes) against Testcontainers Postgres — 2 pass
  • dotnet meta gen/verify --codegen on a scratch C# project (ProjectReference to the working tree, the repo's own preflight arrangement) — HasIndex(x =&gt; x.CustomerId, &#34;orders_customerId_idx&#34;) on, none off; hand-edited file fails verify with exit 1
  • mvn com.metaobjects:metaobjects-maven-plugin:8.3.0:generate on a disposable Kotlin project — index(&#34;orders_customerId_idx&#34;, false, customerId) on, none off; KotlinExposedForeignKeyIndexTest 3/3; NeutralConfigTest (Java MigrateSettings) 17/17 (unit-level test-harness runs, not live product drives)
  • scripts/ci-local.sh --only ts-fast --only ts-unit --strict-toolchains — STARTED, interrupted mid ts-fast lane at the enforced deadline; result unknown (the identical command passed as the phase baseline)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…3.0 PRs 6-7)

verify.handEdits in .metaobjects/config.json: "fail" makes `meta verify --codegen`
exit 1 on a hand-edited generated file, naming the file and both remedies;
--allow-hand-edits relaxes it for one run, --forbid-hand-edits still forces it.
A project without the key keeps the notice and exit 0; `meta init` writes
"fail". The C#, Java, Kotlin and Python gates already byte-compare and fail;
the docs now say so.

migrate.foreignKeyIndexes: every foreign key nothing already leads with gets a
plain <table>_<columns>_idx index, separate from the efcore preset (which
indexes them already and so adds nothing). Honoured by meta migrate / verify
--db, the Drizzle reference template, the C# DbContext generator and the Kotlin
Exposed table generator; Java OMDB and Python map no indexes. `meta init`
writes it on; projects without it are unchanged and keep the advisory, which
now names the option. Persistence corpus gains two migration scenarios.
C# gen and both verify --codegen paths pass foreignKeyIndexes and conventions.
…e-differences rows for verify.handEdits and foreignKeyIndexes)
@dmealing
dmealing merged commit c3455eb into main Nov 13, 2026
9 checks passed
@dmealing
dmealing deleted the fm/mo-verify-fk branch November 13, 2026 23:50
dmealing added a commit that referenced this pull request Nov 14, 2026
…rt (#580)

* fix(python): pass only validated input to the repository in generated routes (#566)

* fix(python): generated routes hand the repository only the validated input (1.2.1)

The generated FastAPI create, PATCH and PUT handlers validated the body against
<Entity>Create / <Entity>Patch and then passed the RAW body to the repository.
Pydantic ignores undeclared keys and the input models leave out server-owned
fields, so a client-sent id, a readOnly field and a made-up field such as
isAdmin all reached the write. Security fix.

Each handler (plain and TPH per-subtype) now rebinds dto to the keys the input
model validated, at every depth, before any repository call, as the TypeScript
routes do. Undeclared and non-settable keys are dropped silently, never 400'd,
so a client sending an extra harmless field keeps working; values stay the
body's own, so repositories see the same value types as in 1.2.0.

Python package version 1.2.1 only; CHANGELOG entry under Security.
Regression gate: tests/integration/test_generated_router_validated_input.py.

* no-mistakes(document): python routes pass only validated input

* no-mistakes(lint): regenerate showcase site payload for PyPI 1.2.1

* fix(codegen): generated routes drop server-owned and undeclared input in every port

An audit after the Python 1.2.1 fix found the same request-input hole in the
other ports' generated create handlers. Each port now drops, silently and before
the write, a server-generated key, readOnly and derived fields, and on a TPH
per-subtype route the discriminator and sibling-subtype columns; undeclared keys
are dropped everywhere.

- Python: forward-port of the 1.2.1 fix; TPH create drops a body discriminator.
- Java: create nulls the dropped DTO components; DTOs ignore unknown properties.
- Kotlin: create writes only settable columns; entity classes ignore unknown keys.
- C#: create resets the generated key, discriminator and M:N navigations; every
  readOnly property gets a private setter.
- TypeScript: an assigned primary key leaves the update schema.

Shared api-contract scenarios input-server-owned-dropped (core) and
tph-input-server-owned-dropped, a readOnly column in secret-fields, and an
`absent` assertion in every runner gate it.

* feat(codegen): a validation 400 lists every issue in every port

The same model answered a failed create or update differently by language:
TypeScript listed each problem, while C#, Java, Kotlin and Python returned a
bare {"error":"validation"}. Every port's generated routes and its hand-rolled
reference servers now answer 400 {"error":"validation","issues":[{code,path,
message}]} with every failure, codes in Zod's vocabulary and path as an array of
wire names.

- C#: ValidationIssues runtime file (ejected with routes); create reads the
  body itself so an unbindable body lists its issue; PATCH collects instead of
  returning on the first failure.
- Java: ValidationIssues runtime helper; a Patch binds every field before it
  throws. Kotlin: per-package MetaValidationIssues.kt; create lists every
  absent required value.
- Python: every Pydantic error mapped in constraint_errors; decimal failures
  carry their wire path.

Shared scenarios validation-lists-issues and tph-validation-lists-issues, with a
new `issues` assertion in every runner, gate it in both lanes.

* feat(api): a page size for generated list routes, api.pagination (TypeScript)

List endpoints had no hard cap: a TypeScript or C# list with no `limit`
returned the whole table and `?limit=100000` was accepted everywhere. A project
can now set `"api": { "pagination": { "defaultLimit": N, "maxLimit": M } }` in
.metaobjects/config.json: a generated entity or projection list with no
`limit` answers the default page, and a `limit` above the cap answers
400 {"error":"limit_too_large","maxLimit":M}. Reports keep their own row cap
and opaque views their 1000.

- sdk reads and validates the block; the loaded root carries it
  (apiPaginationOf), as it carries the wire format.
- runtime-ts mounts take a `pagination` option (pageLimit); the packaged and
  reference Fastify and Hono routes emit it. Owned copies re-synced.
- meta init writes 50 / 1000 for a new project; `--force` over an existing
  config does not add it. A project without the setting behaves as before, and
  meta verify advises (rule unbounded-list-pages) when routes are wired.
- New api-contract `pagination/` sub-corpus, run in the TypeScript generated
  lane. The C#, Java, Kotlin and Python routes do not read it yet: their REST
  generators are under the non-TS freeze, pending that ruling.

A config key, not vocabulary: metamodelVersion does not move.

* feat(api): api.pagination in every port, and api.unknownFields (reject by default)

api.pagination (default page size and hard cap on generated list routes)
now reaches the C#, Java, Kotlin and Python generators as well as
TypeScript: no limit answers the default page, a limit over the cap is
400 limit_too_large. No setting keeps today's behaviour. verify advises
when routes are generated without it (TypeScript, Python, Java/Kotlin,
and C# under verify --codegen).

api.unknownFields (reject | drop, default reject): a generated create,
PUT or PATCH body carrying a key the entity does not declare answers
400 {"error":"unknown_fields","fields":[...]} in every port, before
validation, and writes nothing. drop keeps the old silent behaviour.
Declared server-owned keys (id, readOnly, @autoset, writeOnce on update,
the TPH discriminator, a sibling subtype's column) are still dropped, not
refused, so a client echoing back a row keeps working. Java and Kotlin
check the raw body, so the answer does not depend on the host's Jackson
mapper; a test proves it under both FAIL_ON_UNKNOWN_PROPERTIES values.

The pagination sub-corpus becomes api-settings/ and runs in every port's
generated lane; the core and tph corpora gain reject scenarios. meta init
writes both settings into a fresh config.

* chore(showcase): regenerate for api.unknownFields

* fix(api): code-point order for unknown_fields, every distinct validation issue, a negative limit refused under api.pagination

- unknown_fields lists keys in code-point order in every port (TypeScript and
  C# sorted by UTF-16 code unit, which put a key outside the BMP first).
- A validation 400 keeps two distinct failures of one rule kind on one field
  (Python and C# de-duplicated on path and code); a type error still lists once.
- Under api.pagination a negative limit answers 400 pagination.invalid_value in
  every port instead of reaching the store (SQLite reads LIMIT -1 as no limit).
  New api-settings/limit-negative scenario.
- Python validated-input tests follow api.unknownFields; advanced-modeling
  example regenerated; C# routes generator header names the current contract.

* fix: generated create routes drop server-owned input across ports (1.2.x security) (#568)

* fix: generated create routes store only client-settable fields (1.2.x security)

Python 1.2.1 stopped its generated routes from handing raw request input to
the repository. The same audit found related create-path holes in 1.2.0 in
the other four ports; this closes each in its own idiom. Server-owned values
are dropped silently, never answered with 400.

- Java (codegen-spring): create strips a generated id, readOnly and derived
  fields; a TPH per-subtype create also strips the body discriminator and
  sibling-subtype fields.
- Kotlin (codegen-kotlin): create skips readOnly/derived columns; a TPH
  per-subtype create writes only the route subtype's own columns.
- C# (MetaObjects.Codegen): every readOnly property shape gets a private
  setter; create resets a generated id, the TPH discriminator and M:N
  navigations before Add.
- TypeScript (codegen-ts): the update schema omits primary-key fields, so
  PUT/PATCH can no longer re-key a row with an assigned key.

Proof: new shared api-contract scenarios (core + TPH input-server-owned,
TPH foreign discriminator) and a readOnly `role` field in secret-fields, run
in every port's generated lane and the reference lanes; a new `unset`
assertion key in all five harnesses. In-memory test repositories now store
what they are handed, so the scenarios fail on the 1.2.0 generators.

Proposed versions (not published): npm 1.2.2, NuGet 1.2.2, Maven 8.2.2;
PyPI unchanged at 1.2.1. metamodelVersion unchanged.

* fix: keep a @required readOnly field creatable in C# and Java generated create

Pre-gate review follow-ups to the 1.2.x create-input patch:

- C#: the required-key check skips readOnly fields (the private setter
  never binds them), and create validation ignores a violation naming
  only a @required readOnly member, as Java's SERVER_OWNED_ON_CREATE does.
- Java: the create-validation server-owned set covers every DTO component,
  so a nulled readOnly or derived value-object column no longer 400s.
- TypeScript: drop the now-dead PK guard in the update-schema nullable arm
  and list the PK rule in updateSchemaFields' doc comment.

* no-mistakes(review): apply reviewer inline fixes

* no-mistakes(review): Kotlin readOnly create fix + C# reset skip

* no-mistakes(document): docs: finish stale corpus counts from input fix

* fix(cli): prune emptied skill directories after a --skills-dir move; install every module the Kotlin integration lane needs

meta init --refresh-docs --skills-dir <new> removed the untouched skill files at
the old path but left their directories behind, which read as the old copy still
being there. Walk up from each pruned file and remove the directories it left
empty, stopping at the first that still holds anything and never removing the
skills directory itself.

scripts/integration-test.sh kotlin installed only metadata and codegen-kotlin, so
on an .m2 without the other metaobjects artifacts integration-tests-kotlin failed
to resolve core-spring and om, and codegen-kotlin-exposed1x-check metadata-ktx.

* test(render): hold the email helper in the runtime-drift corpus case

Every generated render path in the five ports already raises
ERR_VAR_NOT_ON_PAYLOAD for a template variable not on the payload
(1.3.0, #520), and runtime-drift/ held the document and prompt helpers.
The @kind: email helper was not in the case. Add WelcomeEmail plus
email-subject/, email-html/ and email-text/ drift directories, one
drifted part each, and check every part raises in the TS, Python, C#,
Java and Kotlin runners.

* feat(init): dotnet meta init and metaobjects init write the api block TypeScript meta init writes

A new project gets api.pagination 50/1000 and api.unknownFields reject in
.metaobjects/config.json from every port's init; an existing config is never edited.

* feat(init): dotnet meta init and metaobjects init also write migrate.foreignKeyIndexes and verify.handEdits

The same new-project keys TypeScript meta init writes since #577.

* feat(api): drop undeclared value-object members everywhere and share the api config cases

- New jsonb scenario jsonb-nested-undeclared-key-dropped: api.unknownFields judges the top
  level only, so a member a value object does not declare is dropped on create and PATCH and
  never stored, while the open jsonb bag keeps every key. The reference servers in every port
  drop such members; the Java generated value-object record now carries
  @JsonIgnoreProperties(ignoreUnknown = true) (it answered 400 invalid_type).
- New shared config corpus api-settings/config-blocks.json (valid and refused api blocks), run
  by the TypeScript, C#, Java and Python config readers. A page size is a positive whole number
  however JSON spells it, at most 2147483647: C# now reads 50.0, TypeScript and Python refuse
  anything above the int32 range.
- CHANGELOG: an Upgrading section (api.unknownFields reject as the one deliberate default change,
  the C# readOnly private setter), init parity across ports, the nested-member rule. Counts,
  READMEs, api-contract.md and the migration guide updated; showcase Java regenerated.

* fix(api): close the code-review findings on the input and page-size work

- C#: with api.pagination set, `limit=0` served the default page; it is now a page of zero rows,
  as in every other port. New shared scenario api-settings/limit-zero (all five ports green).
- C#: the unknown-field check matches a key the way the route binds the body (the app's
  System.Text.Json options; the ASP.NET web default ignores case), so `Title` is the declared
  `title`, not a 400. The verify advisory matches the routes generator by type or exact name,
  not by a "routes" substring.
- Python: a rejected decimal's text is no longer echoed into the 400 issue message; the
  unbounded-list-pages advisory fires only when the routes generator is wired; the dead
  _DECIMAL_COERCE constant is gone.
- Java: UnreadableBody's Javadoc describes the issues envelope it returns.
- Docs: M:N traversal routes take no limit and are not paged by api.pagination (stated as the
  boundary); the C# port doc no longer says dotnet meta init writes no config. Counts updated.

* refactor: read the project config once in the Maven mojo; drop a no-op path coercion in Python issues

Simplify pass: AbstractMetaDataMojo maps its four project settings from one read of
.metaobjects/config.json, and pydantic_issues copies loc as-is (its entries are already int or str).

* no-mistakes(review): Scope ignoreUnknown to request bodies; fix review items

* no-mistakes(review): Drop discriminator on Python TPH update; fix scenario text

* no-mistakes(review): apply reviewer inline fixes

* no-mistakes(review): Fix doc counts, dead guard, stale comments, vacuous assertion

* no-mistakes(review): apply reviewer inline fixes

* no-mistakes(review): Fix stale routes comment in C# api-settings factory

* no-mistakes(review): Fix stale eject docs, vacuous C# check, assertion messages

* no-mistakes(review): Refuse non-numeric C# page bounds with 400

* no-mistakes(review): Refuse out-of-range or negative C# offset

* no-mistakes(review): Drop source-grepping Python router tests

* no-mistakes(review): apply reviewer inline fixes

* test(ts): re-sync the owned zod-validators copy after the pkFields reference change

The input-handling change edited the codegen-ts reference source but not the
owned copy under test-generators, so cli/test/owned-copies-current.test.ts
(the 'owned copies are what meta eject writes' gate) failed: the copy on
disk kept the pre-change update-shape text. bun scripts/sync-owned-template-copies.ts
re-synced 1 of 128 owned copies; no other copy drifted.

* no-mistakes(test): Validate re-synced zod-validators owned copy

* no-mistakes(test): apply changes made during test validation

* no-mistakes(document): Correct init config docs for C# and Python

* test(kotlin): expect table-qualified columns in the TPH create autoSet tests

The TPH per-subtype create now writes every column through the table object
(it[AuthTable.autoCreatedAt]), so a column named body, issues or unknownKeys
cannot be shadowed by the handler's locals. Two KotlinAutoSetStampingTest
cases still asserted the unqualified form and failed the java-slow lane.
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.

1 participant