Skip to content

Add YAML coverage for diff cases (Go tests retained)#21

Merged
winebarrel merged 3 commits into
mainfrom
yamlify-diff-tests
May 2, 2026
Merged

Add YAML coverage for diff cases (Go tests retained)#21
winebarrel merged 3 commits into
mainfrom
yamlify-diff-tests

Conversation

@winebarrel

@winebarrel winebarrel commented May 2, 2026

Copy link
Copy Markdown
Owner

Summary

Expand the YAML fixture set to cover the diff cases that previously only had Go tests under diff/tables_test.go. The Go tests are kept as-is so the per-package coverage stays high; this PR is purely additive.

New YAML fixtures (8)

  • apply/add_check_constraint.yml
  • apply/drop_check_constraint.yml
  • apply/wildcard_allow_drop.yml
  • plan/disallowed_drop_table.yml
  • plan/disallowed_drop_check_constraint.yml
  • plan/disallowed_drop_index.yml
  • plan/disallowed_drop_foreign_key.yml
  • plan/drop_table_cascades_fk.yml

Coverage

Package Before After
myschema (root) 82.5% 82.5%
catalog 77.3% 77.3%
diff 69.5% 69.5% (preserved)
model 95.9% 95.9%
parser 72.5% 72.5%

Cross-package (-coverpkg=./...) from root grows from 67% → 74% thanks to the YAML fixtures exercising more end-to-end paths.

Side effect: surfaced two real MySQL behaviours

  • MySQL auto-creates a same-named index alongside every FK, so suppressed FK drops surface as both DROP INDEX fk and DROP FOREIGN KEY fk. Documented in plan/disallowed_drop_foreign_key.yml.
  • --allow-drop=all emits DROP COLUMN AND DROP INDEX for a column-dependent index, but the column drop already removed the index → MySQL errors. The wildcard fixture sidesteps this; tracked separately as a TODO.

Test plan

  • make test (all suites)
  • make test-scenario
  • golangci-lint
  • All three sample DBs round-trip without drift
  • CI green on this PR

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 2, 2026 07:48
@codecov

codecov Bot commented May 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.79%. Comparing base (b94f766) to head (a45853c).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #21   +/-   ##
=======================================
  Coverage   69.79%   69.79%           
=======================================
  Files          25       25           
  Lines        1652     1652           
=======================================
  Hits         1153     1153           
  Misses        381      381           
  Partials      118      118           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Pull request overview

This PR migrates a set of SQL-input → SQL-output diff tests from Go unit tests into the existing YAML plan/apply fixture harness, keeping only the cases that can’t be expressed (or shouldn’t be) in YAML.

Changes:

  • Replaced most diff/tables_test.go SQL-to-SQL assertions with YAML fixtures under testdata/{plan,apply}.
  • Added new plan/apply YAML fixtures covering check constraints, disallowed drops, wildcard allow-drop, and FK/table drop ordering.
  • Retained two Go tests for internal API/ordering invariants that the YAML harness can’t represent.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
diff/tables_test.go Removes redundant SQL→SQL unit tests; keeps nil-drop-policy and internal FK/table bucket ordering invariants.
testdata/apply/add_check_constraint.yml Adds an apply fixture for emitting ADD CONSTRAINT ... CHECK.
testdata/apply/drop_check_constraint.yml Adds an apply fixture for allowed check-constraint drops.
testdata/apply/wildcard_allow_drop.yml Adds an apply fixture validating allow_drop: [all] across multiple drop kinds.
testdata/plan/disallowed_drop_table.yml Adds a plan fixture asserting DROP TABLE suppression when allow_drop is omitted.
testdata/plan/disallowed_drop_check_constraint.yml Adds a plan fixture asserting DROP CHECK suppression when allow_drop is omitted.
testdata/plan/disallowed_drop_index.yml Adds a plan fixture asserting DROP INDEX suppression when allow_drop is omitted.
testdata/plan/disallowed_drop_foreign_key.yml Adds a plan fixture asserting FK+auto-index drops are both suppressed without allow_drop.
testdata/plan/drop_table_cascades_fk.yml Adds a plan fixture asserting FK drops are emitted before table drops when dropping related tables.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread testdata/plan/drop_table_cascades_fk.yml Outdated
AGENTS.md says: "Add a YAML fixture whenever the test is purely
SQL-input → SQL-output. Reach for a Go test only when the scenario
can't be expressed that way." diff/tables_test.go drifted from that
guidance — most of its 17 tests parsed two SQL strings, called
DiffTables, and asserted on the produced SQL, which is exactly what
the plan/apply YAML harness already does end-to-end against a real
MySQL.

Audit:
- 13 tests deleted: had matching YAML fixtures (TestDiffEmptyToOneTable,
  AddColumn, DropColumnSuppressed/Allowed, ModifyColumnType,
  ModifyColumnDefault, DropTableAllowed, AddIndex, AddForeignKey,
  DiffNoChanges) or were one rename away from one (DropPolicyWildcard).
- 6 new YAML fixtures fill the cases that lacked a YAML equivalent:
  apply/add_check_constraint, apply/drop_check_constraint,
  apply/wildcard_allow_drop, plan/disallowed_drop_table,
  plan/disallowed_drop_check_constraint, plan/disallowed_drop_index,
  plan/disallowed_drop_foreign_key, plan/drop_table_cascades_fk.
- 2 tests kept in Go because YAML can't express them:
    TestDropPolicyNilFallsBackToAllowAll — nil DropChecker is an
      internal API contract; the CLI never produces nil.
    TestDiffDropTableWithFKOrdering — pins the bucket separation
      between FKDropStmts and DropStmts, which the YAML harness
      flattens into one plan body.

Side effect: surfaced two real MySQL behaviours captured in fixture
comments —
  - MySQL auto-creates a same-named index alongside every FK, so
    suppressed FK drops surface as both a `DROP INDEX fk` and a
    `DROP FOREIGN KEY fk` skipped comment. Documented in
    plan/disallowed_drop_foreign_key.yml.
  - --allow-drop=all emits a column drop AND a same-column index drop
    even though the column drop already removes the index, so
    `DROP INDEX` then fails. The wildcard fixture sidesteps this by
    exercising table+constraint+view drops together; a follow-up TODO
    will fix the index-drop suppression for column-dependent indexes.

Coverage: local diff/ coverage drops from 69% to 31% — but
`-coverpkg=./...` from the root package shows 74% of the total
codebase is covered via the YAML harness. The "lost" coverage is
recouped one layer up; net effect is fewer assertions saying the
same thing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@winebarrel winebarrel force-pushed the yamlify-diff-tests branch from 5b5386b to e5b9da7 Compare May 2, 2026 07:54
@winebarrel winebarrel changed the title Move SQL-input/SQL-output diff tests into YAML fixtures Add YAML coverage for diff cases (Go tests retained) May 2, 2026
Copilot pointed out that the comment overstated the case: with this
fixture's `posts` then `users` drop order (alphabetical TABLE_NAME),
MySQL would in fact accept `DROP TABLE users` even without the
explicit FK drop, because the child table is gone first.

The real invariant is the bucket separation in DiffTables —
FKDropStmts run before any DropStmts entry — so the plan is robust
against future drop-ordering changes and against variants where the
parent comes first alphabetically.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread testdata/plan/drop_table_cascades_fk.yml Outdated
Copilot pushed back: the previous "robust under any future DROP-order
change" wording overstated what a strict-string-equality YAML plan
field can verify. If we ever reorder the drops, this fixture fails on
purpose — that's the point.

Reword to: this fixture pins the *current* deterministic ordering
(FKDropStmts then TABLE_NAME-ordered DropStmts), and Go's
TestDiffDropTableWithFKOrdering pins the bucket separation that makes
the plan correct under parent-alphabetically-first variants.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@winebarrel winebarrel merged commit 2a89694 into main May 2, 2026
8 checks passed
@winebarrel winebarrel deleted the yamlify-diff-tests branch May 2, 2026 08:16
winebarrel added a commit that referenced this pull request May 2, 2026
Restructure:
- Group by priority (High correctness / High production gates / Medium /
  Low) instead of by area. Easier to answer "what should I work on next".
- Strip the [x] entries — git log / closed PRs are the real archaeology;
  TODO becomes noise once items duplicate that history.
- Move out-of-scope items (triggers, routines, events, sequences) into
  the header so they stop reappearing in priority discussions.

New entries surfaced during recent test work:

- HIGH (bug): --allow-drop=all emits a redundant `DROP INDEX` after a
  `DROP COLUMN` removed the column (and MySQL auto-removed the
  same-column index). Apply errors with 1091. Found while writing
  the wildcard YAML fixture in PR #21; fixture sidesteps the case.

- HIGH (bug): DROP TABLE ordering when one being-dropped table is
  FK-referenced by another being-dropped table. The bucket separation
  fixes the simple case but parent-alphabetically-first variants still
  fail; needs a topo-sort pass (mirror of view-side fix).

Reword the `applyAlterTable` cleanup item — it now handles
AddIndexDefinition too (vitess maps standalone CREATE INDEX into
*AlterTable + AddIndexDefinition). Remaining gap: silently ignoring
other ALTER subcommands; raise a clear error so users learn the
intended desired-state shape.

Drop the `parseOne` cleanup entry — it was already removed in PR #21.

99 lines, 28 open items (down from 149 / 30 mixed-state).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
winebarrel added a commit that referenced this pull request May 2, 2026
Two remaining inline comments (the other two were already addressed
in earlier commits of this branch):

test/scenario/helper.sh
  - The default `_base_dsn` no longer hardcodes 127.0.0.1:3306; it's
    now built from MYSQL_USER / MYSQL_HOST / MYSQL_PORT, so the
    mysql CLI used by setup_db and the myschema driver target the
    same instance even when only MYSQL_PORT is overridden.
    Reordered the var-init block so MYSQL_HOST / MYSQL_PORT /
    MYSQL_USER are resolved before _base_dsn references them.
    (Copilot #2.)

Makefile
  - test-mysql9 / clean-schema-mysql9 stop hardcoding the full DSN
    and just delegate to the existing `test` / `clean-schema`
    targets with MYSQL_PORT=3307. The MYSCHEMA_TEST_DSN template at
    the top of the Makefile is recursively expanded, so the new port
    flows through to the DSN and any MYSQL_HOST / MYSQL_USER
    customisation carries with it. (Copilot #3.)

Verified locally: `make test-mysql9` and `make test-scenario
MYSQL_PORT=3307` both pass against the running 9.x compose service.

Copilot #1 (Makefile `:=` overriding env) was fixed in 0320bfc.
Copilot #4 (compose.yaml comment about profile) was updated when
the profile itself was removed in 1f51540.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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