mirror of
https://gitee.com/zhangsken/opencode.git
synced 2026-10-16 10:30:01 +08:00
test(codegen): prune redundant generator coverage
This commit is contained in:
@@ -1533,16 +1533,6 @@ function isSafeOutputPath(path: string) {
|
||||
return path !== manifestName && !isAbsolute(path) && path !== "." && path !== ".." && !/[\\/]/.test(path)
|
||||
}
|
||||
|
||||
export function generate<Id extends string, Groups extends HttpApiGroup.Constraint>(
|
||||
api: HttpApi.HttpApi<Id, Groups>,
|
||||
options: { readonly directory: string },
|
||||
): Effect.Effect<void, GenerationError | PlatformError.PlatformError, FileSystem.FileSystem> {
|
||||
return Effect.try({
|
||||
try: () => emitEffect(compile(api)),
|
||||
catch: (error) => (error instanceof GenerationError ? error : new GenerationError({ reason: String(error) })),
|
||||
}).pipe(Effect.flatMap((output) => write(output, options.directory)))
|
||||
}
|
||||
|
||||
function isFlattenableStruct(schema: Schema.Top) {
|
||||
const ast = Schema.toType(schema).ast
|
||||
return SchemaAST.isObjects(ast) && ast.indexSignatures.length === 0
|
||||
|
||||
@@ -3,7 +3,7 @@ import { mkdtemp, rm } from "node:fs/promises"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
import { Effect, FileSystem, Schema, SchemaAST, SchemaGetter } from "effect"
|
||||
import { Effect, Schema, SchemaAST, SchemaGetter } from "effect"
|
||||
import {
|
||||
HttpApi,
|
||||
HttpApiEndpoint,
|
||||
@@ -19,8 +19,6 @@ import {
|
||||
emitEffectImported,
|
||||
emitEffectShape,
|
||||
emitPromise,
|
||||
generate,
|
||||
GenerationError,
|
||||
type Output,
|
||||
} from "../src"
|
||||
import { it } from "./effect"
|
||||
@@ -49,7 +47,7 @@ async function emittedModule(output: Output) {
|
||||
}
|
||||
}
|
||||
|
||||
describe("HttpApiCodegen.generate", () => {
|
||||
describe("HttpApiCodegen.compile and emit", () => {
|
||||
test("compiles one contract for Promise and Effect emitters", () => {
|
||||
const contract = compileContract(
|
||||
api(
|
||||
@@ -1100,16 +1098,6 @@ describe("HttpApiCodegen.generate", () => {
|
||||
expect(url).toBe("https://example.com/event?after=2")
|
||||
})
|
||||
|
||||
test("preserves public group and endpoint identifiers exactly", () => {
|
||||
const output = compile(
|
||||
HttpApi.make("test").add(
|
||||
HttpApiGroup.make("session").add(HttpApiEndpoint.get("get", "/session/:sessionID", { success: Schema.String })),
|
||||
),
|
||||
)
|
||||
|
||||
expect(output.operations[0]).toMatchObject({ group: "session", name: "get" })
|
||||
})
|
||||
|
||||
test("emits one client module per HttpApi group", () => {
|
||||
const source = HttpApi.make("test")
|
||||
.add(HttpApiGroup.make("session").add(HttpApiEndpoint.get("get", "/session", { success: Schema.String })))
|
||||
@@ -1617,24 +1605,6 @@ describe("HttpApiCodegen.generate", () => {
|
||||
expect(output.files[0]?.content).toContain("type RawGroup = HttpApiClient.Client<typeof GroupHealth")
|
||||
})
|
||||
|
||||
it.effect("reports compiler failures in the generate Effect", () =>
|
||||
Effect.gen(function* () {
|
||||
const error = yield* generate(
|
||||
api(
|
||||
HttpApiEndpoint.get("get", "/url", {
|
||||
success: Schema.declare((input): input is URL => input instanceof URL),
|
||||
}),
|
||||
),
|
||||
{
|
||||
directory: "/generated",
|
||||
},
|
||||
).pipe(Effect.flip)
|
||||
|
||||
expect(error).toBeInstanceOf(GenerationError)
|
||||
if (error instanceof GenerationError) expect(error.reason).toBe("Unportable schema: session.get.success")
|
||||
}).pipe(Effect.provideService(FileSystem.FileSystem, FileSystem.makeNoop({}))),
|
||||
)
|
||||
|
||||
test("rejects required client middleware without an adapter", () => {
|
||||
class SignedRequest extends HttpApiMiddleware.Service<SignedRequest>()("SignedRequest", {
|
||||
requiredForClient: true,
|
||||
|
||||
@@ -60,22 +60,19 @@ describe("HttpApiCodegen.write", () => {
|
||||
)
|
||||
})
|
||||
|
||||
it.effect("rejects unsafe and duplicate output paths before writing", () => {
|
||||
it.effect("rejects unsafe output paths before writing", () => {
|
||||
const writes: Array<string> = []
|
||||
return Effect.gen(function* () {
|
||||
const error = yield* write(
|
||||
{
|
||||
operations: [],
|
||||
files: [
|
||||
{ path: "../outside.ts", content: "" },
|
||||
{ path: "client.ts", content: "" },
|
||||
{ path: "CLIENT.ts", content: "" },
|
||||
],
|
||||
files: [{ path: "../outside.ts", content: "" }],
|
||||
},
|
||||
"/generated",
|
||||
).pipe(Effect.flip)
|
||||
|
||||
expect(error._tag).toBe("GenerationError")
|
||||
expect(error.reason).toBe("Unsafe output path: ../outside.ts")
|
||||
expect(writes).toEqual([])
|
||||
}).pipe(
|
||||
Effect.provideService(
|
||||
|
||||
Reference in New Issue
Block a user