mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
fix(codegen): preserve equivalent suffixed type references (#48024)
This commit is contained in:
committed by
GitHub
Unverified
parent
a322d7f98f
commit
11aee1b49f
@@ -143,6 +143,52 @@ describe("HttpApiCodegen.generate", () => {
|
||||
expect(source).not.toContain("@example/api")
|
||||
})
|
||||
|
||||
test("preserves named Effect references across optional schema occurrences", () => {
|
||||
const State = Schema.Record(Schema.String, Schema.Unknown).annotate({ identifier: "Message.State" })
|
||||
const output = emitEffectShape(
|
||||
compileContract(
|
||||
api(
|
||||
HttpApiEndpoint.get("get", "/session", {
|
||||
success: Schema.Struct({
|
||||
encoded: Schema.toEncoded(Schema.Struct({ state: Schema.optionalKey(State) })),
|
||||
optional: Schema.optional(State),
|
||||
}),
|
||||
}),
|
||||
),
|
||||
),
|
||||
{
|
||||
typeReferences: [
|
||||
{ schema: State, name: "Message.State", import: 'import type { Message } from "@example/schema/message"' },
|
||||
],
|
||||
},
|
||||
)
|
||||
const source = output.files[0]?.content
|
||||
expect(source).toContain('readonly "state"?: Message.State')
|
||||
expect(source).toContain('readonly "optional"?: Message.State | undefined')
|
||||
})
|
||||
|
||||
test("does not reuse named Effect references for different suffixed shapes", () => {
|
||||
const State = Schema.Record(Schema.String, Schema.Unknown).annotate({ identifier: "Message.State" })
|
||||
const Different = Schema.Record(Schema.String, Schema.Number).annotate({ identifier: "Message.State" })
|
||||
const output = emitEffectShape(
|
||||
compileContract(
|
||||
api(
|
||||
HttpApiEndpoint.get("get", "/session", {
|
||||
success: Schema.Struct({ original: State, different: Different }),
|
||||
}),
|
||||
),
|
||||
),
|
||||
{
|
||||
typeReferences: [
|
||||
{ schema: State, name: "Message.State", import: 'import type { Message } from "@example/schema/message"' },
|
||||
],
|
||||
},
|
||||
)
|
||||
const source = output.files[0]?.content
|
||||
expect(source).toContain('readonly "original": Message.State')
|
||||
expect(source).toContain('readonly "different": ({ readonly [x: string]: number })')
|
||||
})
|
||||
|
||||
test("allows composed Effect outputs to use an authoritative named type", () => {
|
||||
const output = emitEffectShape(
|
||||
compileContract(api(HttpApiEndpoint.get("events", "/event", { success: Schema.Unknown }))),
|
||||
|
||||
Reference in New Issue
Block a user