fix(teardown,sdk): MSSQL CHECK-constraint teardown + clean db.reset()#37
Merged
Merged
Conversation
Mirrors example-todo-db: bootstrap state.enc via noorm ci, build schema, apply changes, run SDK suite against SQL Server 2022. Uses noorm run build (not db reset) because schema-bound validator UDFs lock referenced tables, and config 'test' with isTest=true to match the test-context bootstrap.
Wire .claude/project/signals.md @-ref into CLAUDE.md, add generated signals files, .signalsignore, followups, and docs/design + docs/spec scaffolding. Gitignore scratchpad and prev-deterministic snapshot.
Two related MSSQL teardown fixes plus cross-dialect verification. 1) teardown drops MSSQL CHECK constraints before functions (#36) A scalar UDF referenced by a CHECK constraint can't be dropped while its table exists (MSSQL error 3729). Functions are dropped before tables to satisfy schema-bound dependents, so the CHECK dependency is severed first via a new MSSQL-only dropCheckConstraints() op that drops all user-schema CHECK constraints (excluding the noorm schema) ahead of the function drops. PostgreSQL is unaffected (dropFunction uses CASCADE); MySQL forbids UDFs in CHECK constraints; SQLite has no stored functions. A PG integration test locks in the CASCADE behavior so a refactor can't reintroduce the break. 2) db.reset() ignores preserveTables for a clean rebuild db.reset() (teardown + build) honored settings.teardown.preserveTables, so preserved reference tables survived teardown and collided with the build's CREATE TABLE, aborting the rebuild. reset() now runs a full teardown that ignores preserveTables; the setting still applies to teardown() and truncate(). Verified end to end: db.reset() now fully and idempotently rebuilds the 38-table llm-memory-db-mssql example schema. Changesets added for both @noormdev/sdk and @noormdev/cli (noorm db teardown and noorm db reset route through the same core). Closes #36
Master CI has been red since the alpha.36 work began; the failures were cross-file test contamination plus stale assertions, not product bugs. Each failing test passes in isolation. Contamination (state leaking across files in a serial in-process run): - tests/core/identity/env.test.ts reassigned the whole process.env object in afterEach, detaching the reference the config module bound at import — poisoned every later env-config test (config: env / resolver). Restore env keys in place instead. - tests/core/sql-terminal/executor.test.ts spied on kysely's shared sql.raw export without restoring it, so sql.raw stayed mocked process-wide and the sdk impersonate suite executed no SQL. Add vi.restoreAllMocks() in afterEach. Stale assertions (identifier quoting added in 66e6fb8 / df24197; execution tests already pass with the quoted form, only the SQL-string asserts lagged): - tests/sdk/context.test.ts: EXEC checkout_trx -> EXEC [checkout_trx] - tests/integration/sdk/tvf.test.ts: quote pg and mssql TVF call identifiers Verified: all four CI groups green locally (group1 2040, group2 116, group3 337, group4 587), typecheck + lint clean.
The two useOnEvent tests used fixed 10ms setTimeout waits for observer to React state propagation, which is too tight on a loaded CI runner (the subscribe test failed all three retries). Add a polling waitFor helper: the single-event test re-emits each poll until received (tolerates a not- yet-registered subscription); the counter test waits generously for the subscription, emits exactly three times, then polls for the final count. Verified stable across repeated local runs.
await import('tarn') / import('tedious') expose their exports under .default
once bundled by tsup, so spreading the namespace left tarn.Pool undefined and
kysely threw 'Pool is not a constructor' on every MSSQL connection — breaking
noorm db create/run/change in the published CLI and any bundled SDK consumer.
Normalize with 'module.default ?? module', mirroring the postgres dialect's
existing pg.default?.Pool guard.
Surfaced by the new example-llm-memory-db-mssql CI job. Verified: the bundled
CLI now connects to MSSQL and queries sys.databases instead of crashing.
The MCP discovery test hard-coded connect config 'dev', but the example
suite (createContext({config:'test'})) and the CI job (noorm ci init --name
test) only provision the 'test' config, so the MCP connect returned an error
under CI. Use 'test' to match the rest of the suite.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two related MSSQL teardown fixes plus cross-dialect verification.
1. teardown drops MSSQL CHECK constraints before functions (#36)
A scalar UDF referenced by a CHECK constraint can't be dropped while its table exists (MSSQL error 3729). Functions are dropped before tables to satisfy schema-bound dependents, so the CHECK dependency is now severed first via a new MSSQL-only
dropCheckConstraints()op (excludes thenoormschema). PostgreSQL is unaffected (dropFunctionuses CASCADE); MySQL forbids UDFs in CHECK constraints; SQLite has no stored functions. A PG integration test locks in the CASCADE behavior.2. db.reset() ignores preserveTables for a clean rebuild
db.reset()(teardown + build) honoredsettings.teardown.preserveTables, so preserved reference tables survived teardown and collided with the build'sCREATE TABLE, aborting the rebuild.reset()now runs a full teardown that ignorespreserveTables; the setting still applies toteardown()andtruncate(). Verified end to end:db.reset()now fully and idempotently rebuilds the 38-table llm-memory-db-mssql example schema.Tests
tests/integration/sdk/db-reset.test.ts, plus CASCADE guard intests/integration/teardown/postgres.test.ts)Changesets
@noormdev/sdkand@noormdev/clipatch entries for both fixes (noorm db teardown/noorm db resetroute through the same core).Closes #36