Skip to content

fix: SqlHandler.AppendLiteral expects a constant (#109) - #163

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
claude/109-append-literal-fcfe85
Nov 16, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
claude/109-append-literal-fcfe85

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #109

Problem

SqlHandler is public, as an interpolated-string handler has to be: the compiler builds it in the contributor's assembly. So a contributor could build one by hand, call AppendLiteral with a string built at run time, and pass it to sql.Statement(ref handler). The string reached the DDL as it was, past the typed holes. Reproduced before the fix: probe E11 (below) compiled clean against the kernel, with the SDK's .NET analyzers on.

Change

  • AppendLiteral's parameter is [ConstantExpected]. A value that is not a constant is CA1857: a warning in a contributor's build by default, an error in this repository's. The compiler only ever passes constants, so sql.Statement($"…") is unchanged.
  • No call can be blocked outright: anything the compiler can call, a contributor can call too. A runtime check (comparing against the interned literal) was ruled out: string.Intern gets around it, and it depends on how the runtime interns strings. The remarks, CLAUDE.md and design/schemakit-api.md now say the guarantee comes from the holes, not the handler.
  • SchemaSqlTests' helper drives the handler by hand on purpose, so it now suppresses CA1857 with a reason.

Tests

  • KernelProbeTests now runs the SDK's .NET analyzers. The project file copies them next to the tests, so each snippet is compiled the way a contributor's build compiles it. New probe E11.literal-from-a-runtime-string: a hand-built handler fed "DROP INDEX " + name must fail with CA1857, and its allowed twin, the interpolated form, must compile clean. Without the attribute the forbidden form compiled clean (1 failed, 54 passed). With it, all 127 probe tests pass, and the existing allowed forms stay clean with the analyzers on.
  • PublicSurfaceTests.The_handler_takes_a_constant_for_a_literal checks that the attribute is there. It fails with the attribute removed.
  • Run locally without servers: kernel 724, PostgreSQL 176, second provider 85, all green. The second provider is a contributor written against the public contract alone, and it never calls the handler directly.

🤖 Generated with Claude Code

… build checks it

The handler is public because the compiler builds it in the contributor's
assembly, so AppendLiteral could be called by hand with any string, which then
reached the DDL as it was. Nothing can stop that call; its parameter is now
[ConstantExpected], so a string built at run time is CA1857, a warning in a
contributor's build by default and an error here.

The kernel probes run the SDK's .NET analyzers, so E11 compiles a hand-built
handler fed a runtime string and asserts CA1857 beside the interpolated form.
PublicSurfaceTests holds the attribute. CLAUDE.md and the API design say the
guarantee is the holes', not the handler's.

Closes #109

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 16, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) severity/low Cosmetic, message or documentation-level difference area/migrations The differ and generator decorators, snapshot format, EnsureCreated and the UseSchemaKit wiring labels Nov 16, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit a528b59 into main Nov 16, 2026
11 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the claude/109-append-literal-fcfe85 branch November 16, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/migrations The differ and generator decorators, snapshot format, EnsureCreated and the UseSchemaKit wiring bug Something isn't working package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SqlHandler.AppendLiteral takes any string when it is called directly, past the typed holes

1 participant