@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 03:37 UTC

next
ts 152 lines 5.24 KB
Raw
1 import { describe, expect, test } from 'bun:test';
2 import { readFileSync } from 'node:fs';
3 import { resolve } from 'node:path';
4 import { z } from 'zod';
5
6 const workflowPath = resolve(process.cwd(), '..', '.github', 'workflows', 'docs-update-data.yml');
7
8 const workflowStepSchema = z
9 .object({
10 name: z.string().optional(),
11 id: z.string().optional(),
12 uses: z.string().optional(),
13 if: z.string().optional(),
14 'continue-on-error': z.boolean().optional(),
15 'working-directory': z.string().optional(),
16 env: z.record(z.string(), z.unknown()).optional(),
17 with: z.record(z.string(), z.unknown()).optional(),
18 run: z.string().optional(),
19 })
20 .passthrough();
21
22 const workflowSchema = z
23 .object({
24 on: z
25 .object({
26 repository_dispatch: z
27 .object({
28 types: z.array(z.string()),
29 })
30 .optional(),
31 })
32 .passthrough()
33 .optional(),
34 jobs: z
35 .record(
36 z.string(),
37 z
38 .object({
39 steps: z.array(workflowStepSchema).optional(),
40 })
41 .passthrough()
42 )
43 .optional(),
44 })
45 .passthrough();
46
47 type WorkflowStep = z.infer<typeof workflowStepSchema>;
48
49 function stepNamed(steps: WorkflowStep[], name: string): WorkflowStep {
50 const step = steps.find(candidate => candidate.name === name);
51 expect(step, `Expected workflow step "${name}"`).toBeDefined();
52 return step ?? {};
53 }
54
55 describe('docs data update workflow', () => {
56 const workflow = workflowSchema.parse(Bun.YAML.parse(readFileSync(workflowPath, 'utf8')));
57 const steps = workflow.jobs?.['update-data']?.steps ?? [];
58
59 test('refreshes data after Apollo and Mercury production changes', () => {
60 expect(workflow.on?.repository_dispatch?.types).toEqual([
61 'apollo-production-deploy',
62 'mercury-production-deploy',
63 ]);
64
65 const logTrigger = stepNamed(steps, 'Log trigger source');
66 expect(logTrigger.env?.APOLLO_COMMIT).toContain('client_payload.hermes_commit');
67 expect(logTrigger.env?.MERCURY_COMMIT).toBe(
68 '${{ github.event.client_payload.mercury_commit }}'
69 );
70 expect(logTrigger.run).toContain('Triggered by Mercury production registry sync');
71 });
72
73 test('keeps the release-bot token scoped to data sync and PR creation', () => {
74 const appToken = stepNamed(steps, 'Generate GitHub App token');
75
76 expect(appToken.with?.['permission-contents']).toBe('write');
77 expect(appToken.with?.['permission-pull-requests']).toBe('write');
78 expect(appToken.with).not.toHaveProperty('permission-issues');
79 });
80
81 test('uses the job token for all same-repository issue tracking', () => {
82 const issueSteps = [
83 'Open tracking issue on failure',
84 'Close tracking issue on recovery',
85 'Track KB freshness verifier health',
86 'Track KB freshness findings',
87 ];
88
89 for (const name of issueSteps) {
90 expect(stepNamed(steps, name).env?.GH_TOKEN).toBe('${{ secrets.GITHUB_TOKEN }}');
91 }
92
93 for (const step of steps.filter(candidate => candidate.run?.includes('gh issue'))) {
94 expect(step.env?.GH_TOKEN).not.toBe('${{ steps.app-token.outputs.token }}');
95 }
96 });
97
98 test('keeps the optional KB freshness check out of every required data-sync step', () => {
99 expect(stepNamed(steps, 'Verify KB freshness against refreshed data')['continue-on-error']).toBe(true);
100
101 const requiredStepNames = [
102 'Generate GitHub App token',
103 'Checkout repository',
104 'Generate toolkits data',
105 'Fetch OpenAPI spec',
106 'Generate API index pages',
107 'Generate meta tools reference',
108 'Create Pull Request',
109 ];
110
111 for (const name of requiredStepNames) {
112 const step = stepNamed(steps, name);
113 const dependencies = JSON.stringify({ if: step.if, env: step.env, with: step.with });
114 expect(dependencies).not.toContain('steps.verify-kb');
115 }
116 });
117
118 test('keeps the generated-data pull request scope and target stable', () => {
119 const createPullRequest = stepNamed(steps, 'Create Pull Request');
120 const addPaths = String(createPullRequest.with?.['add-paths']);
121
122 expect(createPullRequest.with?.branch).toBe('docs/auto-update-data');
123 expect(createPullRequest.with?.base).toBe('next');
124 for (const path of [
125 'docs/public/data/',
126 'docs/public/openapi.json',
127 'docs/public/openapi-v3.json',
128 'docs/public/openapi-webhooks.json',
129 'docs/content/reference/api-reference/',
130 'docs/content/reference/v3/api-reference/',
131 'docs/content/toolkits/meta-tools/',
132 ]) {
133 expect(addPaths).toContain(path);
134 }
135 });
136
137 test('opens failures before checkout and closes the issue after recovery', () => {
138 const failure = stepNamed(steps, 'Open tracking issue on failure');
139 const recovery = stepNamed(steps, 'Close tracking issue on recovery');
140
141 expect(failure.if).toBe('failure()');
142 expect(failure['working-directory']).toBe('${{ github.workspace }}');
143 expect(failure.env?.GH_TOKEN).toBe('${{ secrets.GITHUB_TOKEN }}');
144 expect(failure.env?.LABEL).toBe('docs-data-sync-failure');
145
146 expect(recovery.if).toBe('success()');
147 expect(recovery.env?.LABEL).toBe('docs-data-sync-failure');
148 expect(recovery.run).toContain('gh issue list');
149 expect(recovery.run).toContain('gh issue close');
150 expect(recovery.run).toContain('${{ github.run_id }}');
151 });
152 });