Skip to content

Commit d1e36c8

Browse files
authored
fix(ci): enforce effect-ts analyzer on tests (#23)
* fix(lint): include tests in effect-ts analyzer * chore(ci): retrigger checks after runner stall --------- Co-authored-by: skulidropek <skulidropek@users.noreply.github.com>
1 parent 3fe9d83 commit d1e36c8

File tree

4 files changed

+54
-31
lines changed

4 files changed

+54
-31
lines changed

packages/app/eslint.effect-ts-check.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const restrictedSyntaxBaseNoServiceFactory = [
136136
export default tseslint.config(
137137
{
138138
name: "effect-ts-compliance-check",
139-
files: ["src/**/*.ts", "scripts/**/*.ts"],
139+
files: ["src/**/*.ts", "scripts/**/*.ts", "tests/**/*.ts"],
140140
languageOptions: {
141141
parser: tseslint.parser,
142142
globals: { ...globals.node }

packages/app/tests/app/main.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ const withArgv = (nextArgv: ReadonlyArray<string>) =>
2626
})
2727
)
2828

29-
const usageCases = [
30-
{ argv: ["node", "main"], needle: "pnpm docker-git" as const },
31-
{ argv: ["node", "main", "Alice"], needle: "Usage:" as const }
32-
] as const
29+
type UsageCase = {
30+
readonly argv: ReadonlyArray<string>
31+
readonly needle: string
32+
}
33+
34+
const usageCases: ReadonlyArray<UsageCase> = [
35+
{ argv: ["node", "main"], needle: "pnpm docker-git" },
36+
{ argv: ["node", "main", "Alice"], needle: "Usage:" }
37+
]
3338

3439
const runUsageCase = ({
3540
argv,
3641
needle
37-
}: (typeof usageCases)[number]) =>
42+
}: UsageCase) =>
3843
Effect.scoped(
3944
Effect.gen(function*(_) {
4045
const logSpy = yield* _(withLogSpy)

packages/lib/eslint.effect-ts-check.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const restrictedSyntaxBaseNoServiceFactory = [
136136
export default tseslint.config(
137137
{
138138
name: "effect-ts-compliance-check",
139-
files: ["src/**/*.ts", "scripts/**/*.ts"],
139+
files: ["src/**/*.ts", "scripts/**/*.ts", "tests/**/*.ts"],
140140
languageOptions: {
141141
parser: tseslint.parser,
142142
globals: { ...globals.node }

packages/lib/tests/usecases/prepare-files.test.ts

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import * as fs from "node:fs"
2-
import * as os from "node:os"
3-
import * as path from "node:path"
4-
1+
import * as FileSystem from "@effect/platform/FileSystem"
2+
import * as Path from "@effect/platform/Path"
53
import { NodeContext } from "@effect/platform-node"
64
import { describe, expect, it } from "@effect/vitest"
75
import { Effect } from "effect"
86

97
import type { TemplateConfig } from "../../src/core/domain.js"
108
import { prepareProjectFiles } from "../../src/usecases/actions/prepare-files.js"
119

12-
const withTempDir = <A, E, R>(use: (tempDir: string) => Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
10+
const withTempDir = <A, E, R>(
11+
use: (tempDir: string) => Effect.Effect<A, E, R>
12+
): Effect.Effect<A, E, R | FileSystem.FileSystem> =>
1313
Effect.scoped(
1414
Effect.gen(function*(_) {
15+
const fs = yield* _(FileSystem.FileSystem)
1516
const tempDir = yield* _(
16-
Effect.acquireRelease(
17-
Effect.sync(() => fs.mkdtempSync(path.join(os.tmpdir(), "docker-git-force-env-"))),
18-
(dir) => Effect.sync(() => fs.rmSync(dir, { recursive: true, force: true }))
19-
)
17+
fs.makeTempDirectoryScoped({
18+
prefix: "docker-git-force-env-"
19+
})
2020
)
2121
return yield* _(use(tempDir))
2222
})
2323
)
2424

25-
const makeGlobalConfig = (root: string): TemplateConfig => ({
25+
const makeGlobalConfig = (root: string, path: Path.Path): TemplateConfig => ({
2626
containerName: "dg-test",
2727
serviceName: "dg-test",
2828
sshUser: "dev",
@@ -41,7 +41,11 @@ const makeGlobalConfig = (root: string): TemplateConfig => ({
4141
pnpmVersion: "10.27.0"
4242
})
4343

44-
const makeProjectConfig = (outDir: string, enableMcpPlaywright: boolean): TemplateConfig => ({
44+
const makeProjectConfig = (
45+
outDir: string,
46+
enableMcpPlaywright: boolean,
47+
path: Path.Path
48+
): TemplateConfig => ({
4549
containerName: "dg-test",
4650
serviceName: "dg-test",
4751
sshUser: "dev",
@@ -60,14 +64,33 @@ const makeProjectConfig = (outDir: string, enableMcpPlaywright: boolean): Templa
6064
pnpmVersion: "10.27.0"
6165
})
6266

67+
const isRecord = (value: unknown): value is Record<string, unknown> =>
68+
typeof value === "object" && value !== null
69+
70+
const readEnableMcpPlaywrightFlag = (value: unknown): boolean | undefined => {
71+
if (!isRecord(value)) {
72+
return undefined
73+
}
74+
75+
const template = value.template
76+
if (!isRecord(template)) {
77+
return undefined
78+
}
79+
80+
const flag = template.enableMcpPlaywright
81+
return typeof flag === "boolean" ? flag : undefined
82+
}
83+
6384
describe("prepareProjectFiles", () => {
6485
it.effect("force-env refresh rewrites managed templates", () =>
6586
withTempDir((root) =>
6687
Effect.gen(function*(_) {
88+
const fs = yield* _(FileSystem.FileSystem)
89+
const path = yield* _(Path.Path)
6790
const outDir = path.join(root, "project")
68-
const globalConfig = makeGlobalConfig(root)
69-
const withoutMcp = makeProjectConfig(outDir, false)
70-
const withMcp = makeProjectConfig(outDir, true)
91+
const globalConfig = makeGlobalConfig(root, path)
92+
const withoutMcp = makeProjectConfig(outDir, false, path)
93+
const withMcp = makeProjectConfig(outDir, true, path)
7194

7295
yield* _(
7396
prepareProjectFiles(outDir, root, globalConfig, withoutMcp, {
@@ -76,9 +99,7 @@ describe("prepareProjectFiles", () => {
7699
})
77100
)
78101

79-
const composeBefore = yield* _(
80-
Effect.sync(() => fs.readFileSync(path.join(outDir, "docker-compose.yml"), "utf8"))
81-
)
102+
const composeBefore = yield* _(fs.readFileString(path.join(outDir, "docker-compose.yml")))
82103
expect(composeBefore).not.toContain("dg-test-browser")
83104

84105
yield* _(
@@ -88,16 +109,13 @@ describe("prepareProjectFiles", () => {
88109
})
89110
)
90111

91-
const composeAfter = yield* _(
92-
Effect.sync(() => fs.readFileSync(path.join(outDir, "docker-compose.yml"), "utf8"))
93-
)
94-
const configAfter = yield* _(
95-
Effect.sync(() => JSON.parse(fs.readFileSync(path.join(outDir, "docker-git.json"), "utf8")))
96-
)
112+
const composeAfter = yield* _(fs.readFileString(path.join(outDir, "docker-compose.yml")))
113+
const configAfterText = yield* _(fs.readFileString(path.join(outDir, "docker-git.json")))
114+
const configAfter = yield* _(Effect.sync((): unknown => JSON.parse(configAfterText)))
97115

98116
expect(composeAfter).toContain("dg-test-browser")
99117
expect(composeAfter).toContain('MCP_PLAYWRIGHT_ENABLE: "1"')
100-
expect(configAfter.template.enableMcpPlaywright).toBe(true)
118+
expect(readEnableMcpPlaywrightFlag(configAfter)).toBe(true)
101119
})
102120
).pipe(Effect.provide(NodeContext.layer)))
103121
})

0 commit comments

Comments
 (0)