Skip to content

Commit

Permalink
fix: deps & commands
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Nov 15, 2024
1 parent 9bb7b6b commit db7a960
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 72 deletions.
19 changes: 19 additions & 0 deletions .github/helm/affine/charts/graphql/templates/copilot-test.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{ if .Values.app.copilot.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
Expand Down Expand Up @@ -27,9 +28,27 @@ spec:
secretKeyRef:
name: pg-postgresql
key: postgres-password
- name: DATABASE_URL
value: postgres://{{ .Values.global.database.user }}:$(DATABASE_PASSWORD)@{{ .Values.global.database.url }}:{{ .Values.global.database.port }}/{{ .Values.global.database.name }}
- name: COPILOT_OPENAI_API_KEY
valueFrom:
secretKeyRef:
name: "{{ .Values.app.copilot.secretName }}"
key: openaiSecret
- name: COPILOT_FAL_API_KEY
valueFrom:
secretKeyRef:
name: "{{ .Values.app.copilot.secretName }}"
key: falSecret
- name: COPILOT_UNSPLASH_API_KEY
valueFrom:
secretKeyRef:
name: "{{ .Values.app.copilot.secretName }}"
key: unsplashSecret
resources:
requests:
cpu: '100m'
memory: '200Mi'
restartPolicy: Never
backoffLimit: 1
{{ end }}
9 changes: 5 additions & 4 deletions packages/backend/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
"start": "node --loader ts-node/esm/transpile-only.mjs ./src/index.ts",
"dev": "nodemon ./src/index.ts",
"test": "ava --concurrency 1 --serial",
"test:copilot:e2e": "ava \"e2e/copilot.e2e.ts\"",
"test:copilot:e2e": "ava \"tests/**/copilot-*.e2e.ts\"",
"test:copilot:spec": "ava \"tests/**/copilot-*.spec.ts\"",
"test:coverage": "c8 ava --concurrency 1 --serial",
"test:copilot:e2e:coverage": "c8 ava --timeout=5m \"e2e/copilot.e2e.ts\"",
"test:copilot:e2e:coverage": "c8 ava --timeout=5m \"tests/**/copilot-*.e2e.ts\"",
"test:copilot:spec:coverage": "c8 ava --timeout=5m \"tests/**/copilot-*.spec.ts\"",
"test:copilot:e2e:cron": "ava --config \"tests/ava.docker.config.js\" \"tests/**/copilot-*.e2e.ts\"",
"postinstall": "prisma generate",
"data-migration": "node --loader ts-node/esm/transpile-only.mjs ./src/data/index.ts",
"predeploy": "yarn prisma migrate deploy && node --import ./scripts/register.js ./dist/data/index.js run",
Expand Down Expand Up @@ -89,6 +90,7 @@
"ses": "^1.4.1",
"socket.io": "^4.7.5",
"stripe": "^17.0.0",
"supertest": "^7.0.0",
"ts-node": "^10.9.2",
"typescript": "^5.6.3",
"yjs": "patch:yjs@npm%3A13.6.18#~/.yarn/patches/yjs-npm-13.6.18-ad0d5f7c43.patch",
Expand All @@ -112,8 +114,7 @@
"@types/supertest": "^6.0.2",
"c8": "^10.0.0",
"nodemon": "^3.1.0",
"sinon": "^19.0.0",
"supertest": "^7.0.0"
"sinon": "^19.0.0"
},
"ava": {
"timeout": "1m",
Expand Down
9 changes: 9 additions & 0 deletions packages/backend/server/tests/ava.docker.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import packageJson from '../package.json' with { type: 'json' };

export default {
...packageJson.ava,
environmentVariables: {
...packageJson.ava.environmentVariables,
TS_NODE_PROJECT: './tests/tsconfig.docker.json',
},
};
2 changes: 1 addition & 1 deletion packages/backend/server/tests/copilot-provider.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { ExecutionContext, TestFn } from 'ava';
import ava from 'ava';
import { z } from 'zod';

import { createWorkspace } from './utils';
import {
chatWithImages,
chatWithText,
Expand All @@ -16,6 +15,7 @@ import {
ProviderWorkflowTestCase,
sse2array,
} from './utils/copilot';
import { createWorkspace } from './utils/workspace';

type Tester = {
app: any;
Expand Down
20 changes: 20 additions & 0 deletions packages/backend/server/tests/tsconfig.docker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ES2022",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"rootDir": ".",
"outDir": "../lib/tests",
"verbatimModuleSyntax": false,
"tsBuildInfoFile": "../lib/tests/.tsbuildinfo"
},
"include": [".", "utils"],
"exclude": [],
"ts-node": {
"esm": true,
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Node"
}
}
}
12 changes: 6 additions & 6 deletions packages/backend/server/tests/utils/blobs.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { INestApplication } from '@nestjs/common';
import request from 'supertest';

import { gql } from './common';
import { gqlEndpoint } from './common';

export async function listBlobs(
app: INestApplication,
token: string,
workspaceId: string
): Promise<string[]> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -29,7 +29,7 @@ export async function getWorkspaceBlobsSize(
workspaceId: string
): Promise<number> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.send({
query: `
Expand All @@ -49,7 +49,7 @@ export async function collectAllBlobSizes(
token: string
): Promise<number> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.send({
query: `
Expand All @@ -71,7 +71,7 @@ export async function checkBlobSize(
size: number
): Promise<number> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.send({
query: `query checkBlobSize($workspaceId: String!, $size: SafeInt!) {
Expand All @@ -92,7 +92,7 @@ export async function setBlob(
buffer: Buffer
): Promise<string> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.field(
Expand Down
38 changes: 37 additions & 1 deletion packages/backend/server/tests/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
export const gql = '/graphql';
import { INestApplication } from '@nestjs/common';
import type { Response } from 'supertest';
import supertest from 'supertest';

export function handleGraphQLError(resp: Response) {
const { errors } = resp.body;
if (errors) {
const cause = errors[0];
const stacktrace = cause.extensions?.stacktrace;
throw new Error(
stacktrace
? Array.isArray(stacktrace)
? stacktrace.join('\n')
: String(stacktrace)
: cause.message,
cause
);
}
}

export function gql(app: INestApplication, query?: string) {
const req = supertest(app.getHttpServer())
.post('/graphql')
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' });

if (query) {
return req.send({ query });
}

return req;
}

export const gqlEndpoint = '/graphql';

export async function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
11 changes: 5 additions & 6 deletions packages/backend/server/tests/utils/copilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import {
WorkflowNodeType,
WorkflowParams,
} from '../../src/plugins/copilot/workflow/types';
import { gql } from './common';
import { handleGraphQLError, sleep } from './utils';
import { gqlEndpoint, handleGraphQLError, sleep } from './common';

// @ts-expect-error no error
export class MockCopilotTestProvider
Expand Down Expand Up @@ -167,7 +166,7 @@ export async function createCopilotSession(
promptName: string
): Promise<string> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -194,7 +193,7 @@ export async function forkCopilotSession(
latestMessageId: string
): Promise<string> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand Down Expand Up @@ -224,7 +223,7 @@ export async function createCopilotMessage(
params?: Record<string, string>
): Promise<string> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand Down Expand Up @@ -366,7 +365,7 @@ export async function getHistories(
}
): Promise<History[]> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand Down
12 changes: 6 additions & 6 deletions packages/backend/server/tests/utils/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { INestApplication } from '@nestjs/common';
import request from 'supertest';

import type { InvitationType } from '../../src/core/workspaces';
import { gql } from './common';
import { gqlEndpoint } from './common';

export async function inviteUser(
app: INestApplication,
Expand All @@ -13,7 +13,7 @@ export async function inviteUser(
sendInviteMail = false
): Promise<string> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -34,7 +34,7 @@ export async function acceptInviteById(
sendAcceptMail = false
): Promise<boolean> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
query: `
Expand All @@ -54,7 +54,7 @@ export async function leaveWorkspace(
sendLeaveMail = false
): Promise<boolean> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -75,7 +75,7 @@ export async function revokeUser(
userId: string
): Promise<boolean> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -95,7 +95,7 @@ export async function getInviteInfo(
inviteId: string
): Promise<InvitationType> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand Down
14 changes: 7 additions & 7 deletions packages/backend/server/tests/utils/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '../../src/core/auth';
import { sessionUser } from '../../src/core/auth/service';
import { UserService, type UserType } from '../../src/core/user';
import { gql } from './common';
import { gqlEndpoint } from './common';

export async function internalSignIn(app: INestApplication, userId: string) {
const auth = app.get(AuthService);
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function signUp(

export async function currentUser(app: INestApplication, token: string) {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(token, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -90,7 +90,7 @@ export async function sendChangeEmail(
callbackUrl: string
): Promise<boolean> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -112,7 +112,7 @@ export async function sendSetPasswordEmail(
callbackUrl: string
): Promise<boolean> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -134,7 +134,7 @@ export async function changePassword(
password: string
): Promise<string> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
query: `
Expand All @@ -156,7 +156,7 @@ export async function sendVerifyChangeEmail(
callbackUrl: string
): Promise<boolean> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand All @@ -178,7 +178,7 @@ export async function changeEmail(
email: string
): Promise<UserType & { token: ClientTokenType }> {
const res = await request(app.getHttpServer())
.post(gql)
.post(gqlEndpoint)
.auth(userToken, { type: 'bearer' })
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
.send({
Expand Down
Loading

0 comments on commit db7a960

Please sign in to comment.