feat: refactor and WIP add e2e tests

pull/715/head
Travis Fischer 2025-06-01 22:51:00 +07:00
rodzic d809560257
commit 832862367d
19 zmienionych plików z 165 dodań i 25 usunięć

Wyświetl plik

@ -0,0 +1,8 @@
# ------------------------------------------------------------------------------
# This is an example .env file.
#
# All of these environment vars must be defined either in your environment or in
# a local .env file in order to run this project.
# ------------------------------------------------------------------------------
# TODO

Wyświetl plik

@ -0,0 +1,25 @@
{
"name": "@agentic/platform-e2e-tests",
"private": true,
"version": "0.1.0",
"description": "Internal Agentic platform E2E tests.",
"author": "Travis Fischer <travis@transitivebullsh.it>",
"license": "UNLICENSED",
"repository": {
"type": "git",
"url": "git+https://github.com/transitive-bullshit/agentic-platform.git",
"directory": "apps/e2e"
},
"type": "module",
"scripts": {
"test": "run-s test:*",
"test:lint": "eslint .",
"test:typecheck": "tsc --noEmit",
"test:e2e": "vitest run"
},
"devDependencies": {
"@agentic/platform": "workspace:*",
"@agentic/platform-api-client": "workspace:*",
"@agentic/platform-fixtures": "workspace:*"
}
}

Wyświetl plik

@ -0,0 +1,63 @@
import 'dotenv/config'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { loadAgenticConfig } from '@agentic/platform'
import { AgenticApiClient } from '@agentic/platform-api-client'
import { describe, expect, test } from 'vitest'
const fixtures = [
'basic-raw-free-ts',
'basic-raw-free-json',
'pricing-freemium',
'pricing-pay-as-you-go',
'pricing-3-plans',
'pricing-monthly-annual',
'pricing-custom-0'
]
const fixturesDir = path.join(
fileURLToPath(import.meta.url),
'..',
'..',
'..',
'..',
'packages',
'fixtures'
)
const validFixturesDir = path.join(fixturesDir, 'valid')
console.log(validFixturesDir)
describe('loadAgenticConfig', () => {
for (const fixture of fixtures) {
test(
`${fixture}`,
{
timeout: 60_000
},
async () => {
const fixtureDir = path.join(validFixturesDir, fixture)
const config = await loadAgenticConfig({ cwd: fixtureDir })
expect(config).toMatchSnapshot()
}
)
}
for (const fixture of invalidFixtures) {
test(
`invalid: ${fixture}`,
{
timeout: 60_000
},
async () => {
const fixtureDir = path.join(invalidFixturesDir, fixture)
await expect(
loadAgenticConfig({ cwd: fixtureDir })
).rejects.toThrowErrorMatchingSnapshot()
}
)
}
})

Wyświetl plik

@ -0,0 +1,5 @@
{
"extends": "@fisch0920/config/tsconfig-node",
"include": ["src", "*.config.ts"],
"exclude": ["node_modules", "dist"]
}

Wyświetl plik

@ -0,0 +1,16 @@
import { defineConfig } from 'tsup'
export default defineConfig([
{
entry: ['src/server.ts'],
outDir: 'dist',
target: 'node18',
platform: 'node',
format: ['esm'],
splitting: false,
sourcemap: true,
minify: false,
shims: true,
dts: true
}
])

Wyświetl plik

@ -0,0 +1,12 @@
import tsconfigPaths from 'vite-tsconfig-paths'
import { defineConfig } from 'vitest/config'
export default defineConfig({
plugins: [tsconfigPaths()],
test: {
environment: 'node',
globals: true,
watch: false,
restoreMocks: true
}
})

Wyświetl plik

@ -38,10 +38,10 @@ export async function getRequestCacheKey(
// TODO: gracefully handle content-encoding compression // TODO: gracefully handle content-encoding compression
// TODO: more robust content-type detection // TODO: more robust content-type detection
if (type?.includes('json')) { if (type.includes('json')) {
const bodyJson: any = await request.clone().json() const bodyJson: any = await request.clone().json()
hash = hashObject(bodyJson) hash = hashObject(bodyJson)
} else if (type?.includes('text/')) { } else if (type.includes('text/')) {
const bodyString = await request.clone().text() const bodyString = await request.clone().text()
hash = await sha256(bodyString) hash = await sha256(bodyString)
} else { } else {

Wyświetl plik

@ -20,8 +20,7 @@
"scripts": { "scripts": {
"test": "run-s test:*", "test": "run-s test:*",
"test:lint": "eslint .", "test:lint": "eslint .",
"test:typecheck": "tsc --noEmit", "test:typecheck": "tsc --noEmit"
"test:unit": "vitest run"
}, },
"dependencies": { "dependencies": {
"@agentic/platform": "workspace:*", "@agentic/platform": "workspace:*",
@ -39,11 +38,9 @@
"open": "catalog:", "open": "catalog:",
"ora": "catalog:", "ora": "catalog:",
"restore-cursor": "catalog:", "restore-cursor": "catalog:",
"semver": "catalog:", "semver": "catalog:"
"unconfig": "catalog:"
}, },
"devDependencies": { "devDependencies": {
"@agentic/platform-fixtures": "workspace:*",
"@commander-js/extra-typings": "catalog:", "@commander-js/extra-typings": "catalog:",
"@types/semver": "catalog:" "@types/semver": "catalog:"
}, },

Wyświetl plik

@ -1,9 +1,9 @@
import { loadAgenticConfig } from '@agentic/platform'
import { Command } from 'commander' import { Command } from 'commander'
import { oraPromise } from 'ora' import { oraPromise } from 'ora'
import type { Context } from '../types' import type { Context } from '../types'
import { AuthStore } from '../lib/auth-store' import { AuthStore } from '../lib/auth-store'
import { loadAgenticConfig } from '../lib/load-agentic-config'
export function registerDebugCommand({ program, logger }: Context) { export function registerDebugCommand({ program, logger }: Context) {
const command = new Command('debug') const command = new Command('debug')

Wyświetl plik

@ -1,9 +1,9 @@
import { loadAgenticConfig } from '@agentic/platform'
import { Command } from 'commander' import { Command } from 'commander'
import { oraPromise } from 'ora' import { oraPromise } from 'ora'
import type { Context } from '../types' import type { Context } from '../types'
import { AuthStore } from '../lib/auth-store' import { AuthStore } from '../lib/auth-store'
import { loadAgenticConfig } from '../lib/load-agentic-config'
export function registerDeployCommand({ client, program, logger }: Context) { export function registerDeployCommand({ client, program, logger }: Context) {
const command = new Command('deploy') const command = new Command('deploy')

Wyświetl plik

@ -1,8 +1,8 @@
import type { AgenticApiClient } from '@agentic/platform-api-client' import type { AgenticApiClient } from '@agentic/platform-api-client'
import type { Deployment } from '@agentic/platform-types' import type { Deployment } from '@agentic/platform-types'
import { loadAgenticConfig } from '@agentic/platform'
import { AuthStore } from './auth-store' import { AuthStore } from './auth-store'
import { loadAgenticConfig } from './load-agentic-config'
export async function resolveDeployment({ export async function resolveDeployment({
client, client,

Wyświetl plik

@ -19,7 +19,8 @@
"scripts": { "scripts": {
"test": "run-s test:*", "test": "run-s test:*",
"test:lint": "eslint .", "test:lint": "eslint .",
"test:typecheck": "tsc --noEmit" "test:typecheck": "tsc --noEmit",
"test:unit": "vitest run"
}, },
"dependencies": { "dependencies": {
"@agentic/platform-core": "workspace:*", "@agentic/platform-core": "workspace:*",
@ -29,6 +30,7 @@
"@hono/zod-openapi": "catalog:", "@hono/zod-openapi": "catalog:",
"@modelcontextprotocol/sdk": "catalog:", "@modelcontextprotocol/sdk": "catalog:",
"semver": "catalog:", "semver": "catalog:",
"unconfig": "catalog:",
"zod": "catalog:" "zod": "catalog:"
}, },
"devDependencies": { "devDependencies": {

Wyświetl plik

@ -1,4 +1,5 @@
export * from './define-config' export * from './define-config'
export * from './load-agentic-config'
export * from './resolve-agentic-project-config' export * from './resolve-agentic-project-config'
export * from './validate-agentic-project-config' export * from './validate-agentic-project-config'
export { defaultFreePricingPlan } from '@agentic/platform-types' export { defaultFreePricingPlan } from '@agentic/platform-types'

Wyświetl plik

@ -39,7 +39,6 @@ const fixturesDir = path.join(
'..', '..',
'..', '..',
'..', '..',
'..',
'fixtures' 'fixtures'
) )

Wyświetl plik

@ -1,7 +1,8 @@
import type { AgenticProjectConfig } from '@agentic/platform-types' import type { AgenticProjectConfig } from '@agentic/platform-types'
import { validateAgenticProjectConfig } from '@agentic/platform'
import { loadConfig } from 'unconfig' import { loadConfig } from 'unconfig'
import { validateAgenticProjectConfig } from './validate-agentic-project-config'
export async function loadAgenticConfig({ export async function loadAgenticConfig({
cwd cwd
}: { }: {

Wyświetl plik

@ -7,10 +7,10 @@ import {
resolvedAgenticProjectConfigSchema resolvedAgenticProjectConfigSchema
} from '@agentic/platform-types' } from '@agentic/platform-types'
// NOTE: The extra typing and cast here are necessary because we're // NOTE: The extra typing and casts here are necessary because we're overriding
// overriding the default zod types for some fields (e.g. `pricingPlans`) in // the default zod types for some fields (e.g. `pricingPlans`) in order to get
// order to get stricter TypeScript types than what zod v3 allows (nested // stricter TypeScript types than what zod v3 allows (nested discrimianted
// discrimianted unions). This should be removed once we upgrade to zod v4. // unions). We should consider removing these once we upgrade to zod v4.
/** /**
* @internal * @internal
@ -20,7 +20,7 @@ export function parseAgenticProjectConfig(
{ strip = false, strict = false }: { strip?: boolean; strict?: boolean } = {} { strip = false, strict = false }: { strip?: boolean; strict?: boolean } = {}
): AgenticProjectConfig { ): AgenticProjectConfig {
return parseZodSchema< return parseZodSchema<
z.infer<typeof agenticProjectConfigSchema>, z.output<typeof agenticProjectConfigSchema>,
ZodTypeDef, ZodTypeDef,
z.input<typeof agenticProjectConfigSchema> z.input<typeof agenticProjectConfigSchema>
>( >(
@ -41,7 +41,7 @@ export function parseResolvedAgenticProjectConfig(
{ strip = false, strict = false }: { strip?: boolean; strict?: boolean } = {} { strip = false, strict = false }: { strip?: boolean; strict?: boolean } = {}
): ResolvedAgenticProjectConfig { ): ResolvedAgenticProjectConfig {
return parseZodSchema< return parseZodSchema<
z.infer<typeof resolvedAgenticProjectConfigSchema>, z.output<typeof resolvedAgenticProjectConfigSchema>,
ZodTypeDef, ZodTypeDef,
z.input<typeof resolvedAgenticProjectConfigSchema> z.input<typeof resolvedAgenticProjectConfigSchema>
>( >(

Wyświetl plik

@ -343,6 +343,18 @@ importers:
specifier: 'catalog:' specifier: 'catalog:'
version: 0.43.1(@opentelemetry/api@1.9.0)(@types/pg@8.6.1)(kysely@0.28.2)(postgres@3.4.7) version: 0.43.1(@opentelemetry/api@1.9.0)(@types/pg@8.6.1)(kysely@0.28.2)(postgres@3.4.7)
apps/e2e:
devDependencies:
'@agentic/platform':
specifier: workspace:*
version: link:../../packages/platform
'@agentic/platform-api-client':
specifier: workspace:*
version: link:../../packages/api-client
'@agentic/platform-fixtures':
specifier: workspace:*
version: link:../../packages/fixtures
apps/gateway: apps/gateway:
dependencies: dependencies:
'@agentic/platform': '@agentic/platform':
@ -451,13 +463,7 @@ importers:
semver: semver:
specifier: 'catalog:' specifier: 'catalog:'
version: 7.7.2 version: 7.7.2
unconfig:
specifier: 'catalog:'
version: 7.3.2
devDependencies: devDependencies:
'@agentic/platform-fixtures':
specifier: workspace:*
version: link:../fixtures
'@commander-js/extra-typings': '@commander-js/extra-typings':
specifier: 'catalog:' specifier: 'catalog:'
version: 14.0.0(commander@14.0.0) version: 14.0.0(commander@14.0.0)
@ -538,6 +544,9 @@ importers:
semver: semver:
specifier: 'catalog:' specifier: 'catalog:'
version: 7.7.2 version: 7.7.2
unconfig:
specifier: 'catalog:'
version: 7.3.2
zod: zod:
specifier: 'catalog:' specifier: 'catalog:'
version: 3.25.36 version: 3.25.36

Wyświetl plik

@ -51,6 +51,8 @@
- add support for caching - add support for caching
- add support for custom headers on responses - add support for custom headers on responses
- signed requests - signed requests
- revisit deployment identifiers so possibly be URL-friendly?
- rename parseFaasIdentifier and move validators package into platform-types
## License ## License