@codapult/cli 0.17.2 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -7
- package/dist/commands/config-show.js +6 -9
- package/dist/commands/db.js +10 -36
- package/dist/commands/deploy.js +8 -19
- package/dist/commands/doctor.js +2 -7
- package/dist/commands/env.js +3 -11
- package/dist/commands/generate.js +5 -21
- package/dist/commands/guard.d.ts +5 -0
- package/dist/commands/guard.js +5 -0
- package/dist/commands/mcp.js +5 -16
- package/dist/commands/plugins.js +5 -21
- package/dist/commands/setup.js +2 -6
- package/dist/commands/update.js +2 -6
- package/dist/index.js +111 -5
- package/dist/mcp/resources.js +15 -15
- package/dist/mcp/server.js +6 -0
- package/dist/mcp/tools/db.js +11 -16
- package/dist/mcp/tools/deploy.js +2 -8
- package/dist/mcp/tools/env.js +6 -12
- package/dist/mcp/tools/generate.js +10 -15
- package/dist/mcp/tools/plugins.js +5 -11
- package/dist/mcp/tools/project.js +9 -30
- package/dist/utils/command.d.ts +3 -0
- package/dist/utils/command.js +35 -4
- package/dist/utils/config.d.ts +5 -0
- package/dist/utils/config.js +5 -0
- package/dist/utils/project-checks.d.ts +2 -0
- package/dist/utils/project-checks.js +2 -0
- package/dist/utils/project.d.ts +1 -0
- package/dist/utils/project.js +16 -0
- package/package.json +16 -5
- package/dist/commands/generate.test.d.ts +0 -1
- package/dist/commands/generate.test.js +0 -125
- package/dist/mcp/tools/db.test.d.ts +0 -1
- package/dist/mcp/tools/db.test.js +0 -221
- package/dist/mcp/tools/env.test.d.ts +0 -1
- package/dist/mcp/tools/env.test.js +0 -156
- package/dist/mcp/tools/project.test.d.ts +0 -1
- package/dist/mcp/tools/project.test.js +0 -188
- package/dist/utils/config-report.test.d.ts +0 -1
- package/dist/utils/config-report.test.js +0 -18
- package/dist/utils/env-compatibility.test.d.ts +0 -1
- package/dist/utils/env-compatibility.test.js +0 -23
- package/dist/utils/env-schema-parser.test.d.ts +0 -1
- package/dist/utils/env-schema-parser.test.js +0 -11
- package/dist/utils/git.test.d.ts +0 -1
- package/dist/utils/git.test.js +0 -77
- package/dist/utils/health-render.test.d.ts +0 -1
- package/dist/utils/health-render.test.js +0 -18
- package/dist/utils/live-db-diff.test.d.ts +0 -1
- package/dist/utils/live-db-diff.test.js +0 -29
- package/dist/utils/manifest.test.d.ts +0 -1
- package/dist/utils/manifest.test.js +0 -107
- package/dist/utils/patchers.test.d.ts +0 -1
- package/dist/utils/patchers.test.js +0 -647
- package/dist/utils/project-env.test.d.ts +0 -1
- package/dist/utils/project-env.test.js +0 -47
- package/dist/utils/project.test.d.ts +0 -1
- package/dist/utils/project.test.js +0 -123
- package/dist/utils/schema-parity.test.d.ts +0 -1
- package/dist/utils/schema-parity.test.js +0 -27
- package/dist/utils/schema-parser.test.d.ts +0 -1
- package/dist/utils/schema-parser.test.js +0 -59
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { ENV_EXAMPLE_FILE_NAME, ENV_FILE_NAME } from '../../utils/project-env.js';
|
|
3
|
-
vi.mock('node:fs');
|
|
4
|
-
vi.mock('../../utils/project.js', () => ({
|
|
5
|
-
findProjectRoot: vi.fn(),
|
|
6
|
-
readProjectFile: vi.fn(),
|
|
7
|
-
}));
|
|
8
|
-
const { existsSync, readFileSync, writeFileSync } = await import('node:fs');
|
|
9
|
-
const { findProjectRoot, readProjectFile } = await import('../../utils/project.js');
|
|
10
|
-
const { registerEnvTools } = await import('./env.js');
|
|
11
|
-
const mockedFindRoot = vi.mocked(findProjectRoot);
|
|
12
|
-
const mockedReadProject = vi.mocked(readProjectFile);
|
|
13
|
-
const mockedExists = vi.mocked(existsSync);
|
|
14
|
-
const mockedRead = vi.mocked(readFileSync);
|
|
15
|
-
const mockedWrite = vi.mocked(writeFileSync);
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
vi.resetAllMocks();
|
|
18
|
-
mockedFindRoot.mockReturnValue('/project');
|
|
19
|
-
});
|
|
20
|
-
function createMockServer() {
|
|
21
|
-
const tools = [];
|
|
22
|
-
const registerTool = vi.fn((name, _opts, handler) => {
|
|
23
|
-
tools.push({ name, handler });
|
|
24
|
-
});
|
|
25
|
-
return { registerTool, tools };
|
|
26
|
-
}
|
|
27
|
-
describe('registerEnvTools', () => {
|
|
28
|
-
it('registers environment inspection and mutation tools', () => {
|
|
29
|
-
const server = createMockServer();
|
|
30
|
-
registerEnvTools(server);
|
|
31
|
-
expect(server.tools).toHaveLength(5);
|
|
32
|
-
expect(server.tools.map((t) => t.name)).toEqual([
|
|
33
|
-
'codapult_env_check',
|
|
34
|
-
'codapult_env_sync',
|
|
35
|
-
'codapult_env_schema',
|
|
36
|
-
'codapult_env_read',
|
|
37
|
-
'codapult_env_update',
|
|
38
|
-
]);
|
|
39
|
-
});
|
|
40
|
-
describe('codapult_env_schema', () => {
|
|
41
|
-
it(`parses ${ENV_EXAMPLE_FILE_NAME} entries with comments`, () => {
|
|
42
|
-
const server = createMockServer();
|
|
43
|
-
registerEnvTools(server);
|
|
44
|
-
const envExample = `# Auth provider
|
|
45
|
-
AUTH_PROVIDER=better-auth
|
|
46
|
-
# Stripe secret key
|
|
47
|
-
STRIPE_SECRET_KEY=sk_test_xxx
|
|
48
|
-
# === Section header ===
|
|
49
|
-
# Optional database URL
|
|
50
|
-
DATABASE_URL=sqlite://local.db
|
|
51
|
-
`;
|
|
52
|
-
mockedReadProject.mockReturnValue(envExample);
|
|
53
|
-
const handler = server.tools.find((t) => t.name === 'codapult_env_schema').handler;
|
|
54
|
-
const result = handler({});
|
|
55
|
-
const parsed = JSON.parse(result.content[0].text);
|
|
56
|
-
expect(parsed).toHaveLength(3);
|
|
57
|
-
const authEntry = parsed.find((e) => e.key === 'AUTH_PROVIDER');
|
|
58
|
-
expect(authEntry.value).toBe('better-auth');
|
|
59
|
-
expect(authEntry.comment).toBe('Auth provider');
|
|
60
|
-
expect(authEntry.required).toBe(true);
|
|
61
|
-
const dbEntry = parsed.find((e) => e.key === 'DATABASE_URL');
|
|
62
|
-
expect(dbEntry.value).toBe('sqlite://local.db');
|
|
63
|
-
expect(dbEntry.comment).toBe('Optional database URL');
|
|
64
|
-
});
|
|
65
|
-
it(`returns error when ${ENV_EXAMPLE_FILE_NAME} not found`, () => {
|
|
66
|
-
const server = createMockServer();
|
|
67
|
-
registerEnvTools(server);
|
|
68
|
-
mockedReadProject.mockReturnValue(undefined);
|
|
69
|
-
const handler = server.tools.find((t) => t.name === 'codapult_env_schema').handler;
|
|
70
|
-
const result = handler({});
|
|
71
|
-
expect(result.isError).toBe(true);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
describe('codapult_env_read', () => {
|
|
75
|
-
it('reports missing and unconfigured variables', () => {
|
|
76
|
-
const server = createMockServer();
|
|
77
|
-
registerEnvTools(server);
|
|
78
|
-
const envLocal = `AUTH_PROVIDER=better-auth\nSTRIPE_SECRET_KEY=your-key-here\n`;
|
|
79
|
-
const envExample = `AUTH_PROVIDER=better-auth\nSTRIPE_SECRET_KEY=\nDATABASE_URL=\n`;
|
|
80
|
-
mockedExists.mockReturnValue(true);
|
|
81
|
-
mockedRead.mockReturnValue(envLocal);
|
|
82
|
-
mockedReadProject.mockImplementation((_root, path) => {
|
|
83
|
-
if (path === ENV_EXAMPLE_FILE_NAME)
|
|
84
|
-
return envExample;
|
|
85
|
-
return undefined;
|
|
86
|
-
});
|
|
87
|
-
const handler = server.tools.find((t) => t.name === 'codapult_env_read').handler;
|
|
88
|
-
const result = handler({});
|
|
89
|
-
const parsed = JSON.parse(result.content[0].text);
|
|
90
|
-
expect(parsed.missing).toContain('DATABASE_URL');
|
|
91
|
-
expect(parsed.unconfigured).toContain('STRIPE_SECRET_KEY');
|
|
92
|
-
});
|
|
93
|
-
it('can read from process env', () => {
|
|
94
|
-
const server = createMockServer();
|
|
95
|
-
registerEnvTools(server);
|
|
96
|
-
vi.stubEnv('AUTH_PROVIDER', 'better-auth');
|
|
97
|
-
vi.stubEnv('STRIPE_SECRET_KEY', 'sk_live_123');
|
|
98
|
-
mockedReadProject.mockImplementation((_root, path) => {
|
|
99
|
-
if (path === ENV_EXAMPLE_FILE_NAME)
|
|
100
|
-
return `AUTH_PROVIDER=better-auth\nSTRIPE_SECRET_KEY=\nDATABASE_URL=\n`;
|
|
101
|
-
return undefined;
|
|
102
|
-
});
|
|
103
|
-
const handler = server.tools.find((t) => t.name === 'codapult_env_read').handler;
|
|
104
|
-
const result = handler({ env_source: 'process' });
|
|
105
|
-
const parsed = JSON.parse(result.content[0].text);
|
|
106
|
-
expect(parsed.variables.some((v) => v.key === 'AUTH_PROVIDER')).toBe(true);
|
|
107
|
-
});
|
|
108
|
-
it(`returns error when ${ENV_FILE_NAME} not found`, () => {
|
|
109
|
-
const server = createMockServer();
|
|
110
|
-
registerEnvTools(server);
|
|
111
|
-
mockedReadProject.mockReturnValue(undefined);
|
|
112
|
-
const handler = server.tools.find((t) => t.name === 'codapult_env_read').handler;
|
|
113
|
-
const result = handler({});
|
|
114
|
-
expect(result.isError).toBe(true);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
describe('codapult_env_update', () => {
|
|
118
|
-
it(`updates existing variable in ${ENV_FILE_NAME}`, () => {
|
|
119
|
-
const server = createMockServer();
|
|
120
|
-
registerEnvTools(server);
|
|
121
|
-
mockedExists.mockReturnValue(true);
|
|
122
|
-
mockedRead.mockReturnValue('AUTH_PROVIDER=better-auth\nSTRIPE_KEY=old\n');
|
|
123
|
-
const handler = server.tools.find((t) => t.name === 'codapult_env_update').handler;
|
|
124
|
-
const result = handler({ key: 'STRIPE_KEY', value: 'sk_new_123' });
|
|
125
|
-
expect(result.isError).toBeUndefined();
|
|
126
|
-
const written = mockedWrite.mock.calls[0][1];
|
|
127
|
-
expect(written).toContain('STRIPE_KEY="sk_new_123"');
|
|
128
|
-
expect(written).toContain('AUTH_PROVIDER=better-auth');
|
|
129
|
-
});
|
|
130
|
-
it('appends new variable when not present', () => {
|
|
131
|
-
const server = createMockServer();
|
|
132
|
-
registerEnvTools(server);
|
|
133
|
-
mockedExists.mockReturnValue(true);
|
|
134
|
-
mockedRead.mockReturnValue('AUTH_PROVIDER=better-auth\n');
|
|
135
|
-
const handler = server.tools.find((t) => t.name === 'codapult_env_update').handler;
|
|
136
|
-
handler({ key: 'NEW_VAR', value: 'new_value' });
|
|
137
|
-
const written = mockedWrite.mock.calls[0][1];
|
|
138
|
-
expect(written).toContain('NEW_VAR="new_value"');
|
|
139
|
-
});
|
|
140
|
-
it(`returns error when ${ENV_FILE_NAME} not found`, () => {
|
|
141
|
-
const server = createMockServer();
|
|
142
|
-
registerEnvTools(server);
|
|
143
|
-
mockedExists.mockReturnValue(false);
|
|
144
|
-
const handler = server.tools.find((t) => t.name === 'codapult_env_update').handler;
|
|
145
|
-
const result = handler({ key: 'X', value: 'Y' });
|
|
146
|
-
expect(result.isError).toBe(true);
|
|
147
|
-
});
|
|
148
|
-
it('returns error for process env updates', () => {
|
|
149
|
-
const server = createMockServer();
|
|
150
|
-
registerEnvTools(server);
|
|
151
|
-
const handler = server.tools.find((t) => t.name === 'codapult_env_update').handler;
|
|
152
|
-
const result = handler({ key: 'X', value: 'Y', env_source: 'process' });
|
|
153
|
-
expect(result.isError).toBe(true);
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { ENV_FILE_NAME } from '../../utils/project-env.js';
|
|
3
|
-
vi.mock('node:fs');
|
|
4
|
-
vi.mock('node:child_process');
|
|
5
|
-
vi.mock('../../utils/project.js', () => ({
|
|
6
|
-
findProjectRoot: vi.fn(),
|
|
7
|
-
readProjectFile: vi.fn(),
|
|
8
|
-
readJsonFile: vi.fn(),
|
|
9
|
-
}));
|
|
10
|
-
vi.mock('../../utils/project-env.js', () => ({
|
|
11
|
-
ENV_FILE_NAME: '.env.local',
|
|
12
|
-
getProjectEnvOptions: vi.fn((envSource) => ({ envFile: envSource !== 'process' })),
|
|
13
|
-
getProjectEnvSource: vi.fn((options) => options?.envFile === false ? 'process' : 'file'),
|
|
14
|
-
loadProjectEnv: vi.fn(),
|
|
15
|
-
}));
|
|
16
|
-
const { existsSync, readFileSync, readdirSync } = await import('node:fs');
|
|
17
|
-
const { execSync } = await import('node:child_process');
|
|
18
|
-
const { findProjectRoot, readProjectFile, readJsonFile } = await import('../../utils/project.js');
|
|
19
|
-
const { loadProjectEnv } = await import('../../utils/project-env.js');
|
|
20
|
-
const { registerProjectTools } = await import('./project.js');
|
|
21
|
-
const mockedFindRoot = vi.mocked(findProjectRoot);
|
|
22
|
-
const mockedReadProject = vi.mocked(readProjectFile);
|
|
23
|
-
const mockedLoadProjectEnv = vi.mocked(loadProjectEnv);
|
|
24
|
-
const mockedExists = vi.mocked(existsSync);
|
|
25
|
-
const mockedRead = vi.mocked(readFileSync);
|
|
26
|
-
const mockedReaddir = vi.mocked(readdirSync);
|
|
27
|
-
const mockedReadJson = vi.mocked(readJsonFile);
|
|
28
|
-
const mockedExec = vi.mocked(execSync);
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
vi.resetAllMocks();
|
|
31
|
-
mockedFindRoot.mockReturnValue('/project');
|
|
32
|
-
mockedLoadProjectEnv.mockReturnValue({
|
|
33
|
-
source: 'file',
|
|
34
|
-
filePath: `/project/${ENV_FILE_NAME}`,
|
|
35
|
-
fileExists: false,
|
|
36
|
-
content: '',
|
|
37
|
-
});
|
|
38
|
-
mockedReaddir.mockReturnValue([]);
|
|
39
|
-
mockedReadJson.mockReturnValue({ name: 'codapult', version: '1.0.0' });
|
|
40
|
-
});
|
|
41
|
-
function createMockServer() {
|
|
42
|
-
const tools = [];
|
|
43
|
-
const registerTool = vi.fn((name, _opts, handler) => {
|
|
44
|
-
tools.push({ name, handler });
|
|
45
|
-
});
|
|
46
|
-
return { registerTool, tools };
|
|
47
|
-
}
|
|
48
|
-
describe('registerProjectTools', () => {
|
|
49
|
-
it('registers project inspection and execution tools', () => {
|
|
50
|
-
const server = createMockServer();
|
|
51
|
-
registerProjectTools(server);
|
|
52
|
-
expect(server.tools).toHaveLength(6);
|
|
53
|
-
const names = server.tools.map((t) => t.name);
|
|
54
|
-
expect(names).toContain('codapult_project_status');
|
|
55
|
-
expect(names).toContain('codapult_project_config');
|
|
56
|
-
expect(names).toContain('codapult_run_checks');
|
|
57
|
-
expect(names).toContain('codapult_doctor');
|
|
58
|
-
expect(names).toContain('codapult_project_context');
|
|
59
|
-
expect(names).toContain('codapult_build');
|
|
60
|
-
});
|
|
61
|
-
describe('codapult_project_status', () => {
|
|
62
|
-
it('returns project info with adapters and plugins', () => {
|
|
63
|
-
const server = createMockServer();
|
|
64
|
-
registerProjectTools(server);
|
|
65
|
-
mockedRead.mockReturnValue(JSON.stringify({ name: 'codapult', version: '1.0.0' }));
|
|
66
|
-
mockedLoadProjectEnv.mockReturnValue({
|
|
67
|
-
source: 'file',
|
|
68
|
-
filePath: `/project/${ENV_FILE_NAME}`,
|
|
69
|
-
fileExists: true,
|
|
70
|
-
content: [
|
|
71
|
-
'AUTH_PROVIDER=kinde',
|
|
72
|
-
'PAYMENT_PROVIDER=lemonsqueezy',
|
|
73
|
-
'STORAGE_PROVIDER=s3',
|
|
74
|
-
'ENABLE_TEAMS=false',
|
|
75
|
-
'GOOGLE_CLIENT_ID=abc',
|
|
76
|
-
'GOOGLE_CLIENT_SECRET=def',
|
|
77
|
-
].join('\n'),
|
|
78
|
-
});
|
|
79
|
-
mockedExists.mockReturnValue(true);
|
|
80
|
-
mockedReaddir.mockReturnValue(['analytics.ts', 'crm.ts', 'index.ts']);
|
|
81
|
-
mockedExec.mockImplementation((cmd) => {
|
|
82
|
-
if (cmd.includes('branch'))
|
|
83
|
-
return Buffer.from('main');
|
|
84
|
-
if (cmd.includes('porcelain'))
|
|
85
|
-
return Buffer.from('');
|
|
86
|
-
return Buffer.from('');
|
|
87
|
-
});
|
|
88
|
-
const handler = server.tools.find((t) => t.name === 'codapult_project_status').handler;
|
|
89
|
-
const result = handler({});
|
|
90
|
-
const parsed = JSON.parse(result.content[0].text);
|
|
91
|
-
expect(parsed.name).toBe('codapult');
|
|
92
|
-
expect(parsed.adapters.auth).toBe('kinde');
|
|
93
|
-
expect(parsed.adapters.payments).toBe('lemonsqueezy');
|
|
94
|
-
expect(parsed.adapters.storage).toBe('s3');
|
|
95
|
-
expect(parsed.adapters.database).toBe('turso');
|
|
96
|
-
expect(parsed.adapters.embedding).toBe('openai');
|
|
97
|
-
expect(parsed.adapters.vectorStore).toBe('sqlite');
|
|
98
|
-
expect(parsed.oauthProviders).toEqual(['google']);
|
|
99
|
-
expect(parsed.plugins).toEqual(['analytics', 'crm']);
|
|
100
|
-
expect(parsed.features.enabled).toContain('aiChat');
|
|
101
|
-
expect(parsed.features.enabled).toContain('blog');
|
|
102
|
-
expect(parsed.features.disabled).toContain('teams');
|
|
103
|
-
expect(parsed.git.branch).toBe('main');
|
|
104
|
-
expect(parsed.git.dirty).toBe(false);
|
|
105
|
-
});
|
|
106
|
-
it('uses process env when requested', () => {
|
|
107
|
-
const server = createMockServer();
|
|
108
|
-
registerProjectTools(server);
|
|
109
|
-
mockedRead.mockReturnValue(JSON.stringify({ name: 'codapult', version: '1.0.0' }));
|
|
110
|
-
mockedLoadProjectEnv.mockReturnValue({
|
|
111
|
-
source: 'process',
|
|
112
|
-
filePath: `/project/${ENV_FILE_NAME}`,
|
|
113
|
-
fileExists: false,
|
|
114
|
-
content: 'AUTH_PROVIDER=none\nENABLE_BLOG=false',
|
|
115
|
-
});
|
|
116
|
-
mockedExists.mockReturnValue(true);
|
|
117
|
-
mockedReaddir.mockReturnValue([]);
|
|
118
|
-
const handler = server.tools.find((t) => t.name === 'codapult_project_status').handler;
|
|
119
|
-
const result = handler({ env_source: 'process' });
|
|
120
|
-
const parsed = JSON.parse(result.content[0].text);
|
|
121
|
-
expect(parsed.adapters.auth).toBe('none');
|
|
122
|
-
expect(mockedLoadProjectEnv).toHaveBeenCalledWith('/project', { envFile: false });
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
describe('codapult_project_config', () => {
|
|
126
|
-
it('returns app.ts content', () => {
|
|
127
|
-
const server = createMockServer();
|
|
128
|
-
registerProjectTools(server);
|
|
129
|
-
mockedReadProject.mockReturnValue('export const appConfig = { brand: "test" };');
|
|
130
|
-
const handler = server.tools.find((t) => t.name === 'codapult_project_config').handler;
|
|
131
|
-
const result = handler({});
|
|
132
|
-
expect(result.content[0].text).toContain('appConfig');
|
|
133
|
-
});
|
|
134
|
-
it('returns fallback message when config not found', () => {
|
|
135
|
-
const server = createMockServer();
|
|
136
|
-
registerProjectTools(server);
|
|
137
|
-
mockedReadProject.mockReturnValue(undefined);
|
|
138
|
-
const handler = server.tools.find((t) => t.name === 'codapult_project_config').handler;
|
|
139
|
-
const result = handler({});
|
|
140
|
-
expect(result.content[0].text).toContain('not found');
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
describe('codapult_doctor', () => {
|
|
144
|
-
it('checks required files and TypeScript compilation', () => {
|
|
145
|
-
const server = createMockServer();
|
|
146
|
-
registerProjectTools(server);
|
|
147
|
-
mockedExists.mockReturnValue(true);
|
|
148
|
-
mockedExec.mockReturnValue(Buffer.from(''));
|
|
149
|
-
const handler = server.tools.find((t) => t.name === 'codapult_doctor').handler;
|
|
150
|
-
const result = handler({});
|
|
151
|
-
const parsed = JSON.parse(result.content[0].text);
|
|
152
|
-
const pkgCheck = parsed.checks.find((c) => c.id === 'package');
|
|
153
|
-
expect(pkgCheck?.status).toBe('ok');
|
|
154
|
-
const tsCheck = parsed.checks.find((c) => c.id === 'typecheck');
|
|
155
|
-
expect(tsCheck?.status).toBe('ok');
|
|
156
|
-
});
|
|
157
|
-
it('reports missing files', () => {
|
|
158
|
-
const server = createMockServer();
|
|
159
|
-
registerProjectTools(server);
|
|
160
|
-
mockedExists.mockReturnValue(false);
|
|
161
|
-
mockedExec.mockImplementation(() => {
|
|
162
|
-
throw new Error('compile error');
|
|
163
|
-
});
|
|
164
|
-
const handler = server.tools.find((t) => t.name === 'codapult_doctor').handler;
|
|
165
|
-
const result = handler({});
|
|
166
|
-
const parsed = JSON.parse(result.content[0].text);
|
|
167
|
-
const failedChecks = parsed.checks.filter((c) => c.status === 'fail');
|
|
168
|
-
expect(failedChecks.length).toBeGreaterThan(0);
|
|
169
|
-
});
|
|
170
|
-
it('reports process env source when requested', () => {
|
|
171
|
-
const server = createMockServer();
|
|
172
|
-
registerProjectTools(server);
|
|
173
|
-
mockedExists.mockReturnValue(true);
|
|
174
|
-
mockedExec.mockReturnValue(Buffer.from(''));
|
|
175
|
-
mockedLoadProjectEnv.mockReturnValue({
|
|
176
|
-
source: 'process',
|
|
177
|
-
filePath: `/project/${ENV_FILE_NAME}`,
|
|
178
|
-
fileExists: false,
|
|
179
|
-
content: '',
|
|
180
|
-
});
|
|
181
|
-
const handler = server.tools.find((t) => t.name === 'codapult_doctor').handler;
|
|
182
|
-
const result = handler({ env_source: 'process' });
|
|
183
|
-
const parsed = JSON.parse(result.content[0].text);
|
|
184
|
-
const envCheck = parsed.checks.find((c) => c.id === 'env-file');
|
|
185
|
-
expect(envCheck?.message).toBe('Using process.env');
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
vi.mock('./project.js', () => ({ readProjectFile: vi.fn() }));
|
|
3
|
-
const { readProjectFile } = await import('./project.js');
|
|
4
|
-
const { collectAppConfigSummary } = await import('./config-report.js');
|
|
5
|
-
describe('collectAppConfigSummary', () => {
|
|
6
|
-
it('returns the shared displayable app config subset', () => {
|
|
7
|
-
vi.mocked(readProjectFile).mockReturnValue(`
|
|
8
|
-
export const appConfig = {
|
|
9
|
-
brand: { name: 'Codapult', description: 'Starter', logo: '/logo.svg' },
|
|
10
|
-
company: { contactEmail: 'hello@example.com', githubUrl: 'https://github.com/codapult' },
|
|
11
|
-
};
|
|
12
|
-
`);
|
|
13
|
-
expect(collectAppConfigSummary('/project')).toEqual({
|
|
14
|
-
brand: { name: 'Codapult', description: 'Starter', logo: '/logo.svg' },
|
|
15
|
-
company: { contactEmail: 'hello@example.com', githubUrl: 'https://github.com/codapult' },
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { checkEnvSchemaCompatibility } from './env-compatibility.js';
|
|
3
|
-
vi.mock('node:fs', () => ({ existsSync: vi.fn(() => true) }));
|
|
4
|
-
vi.mock('./project.js', () => ({ readProjectFile: vi.fn() }));
|
|
5
|
-
const { readProjectFile } = await import('./project.js');
|
|
6
|
-
const mockedRead = vi.mocked(readProjectFile);
|
|
7
|
-
describe('checkEnvSchemaCompatibility', () => {
|
|
8
|
-
it('reports a compatible host schema', async () => {
|
|
9
|
-
const { ENV_SCHEMA_KEYS } = await import('./env-config.js');
|
|
10
|
-
mockedRead.mockReturnValue(`export const envSchema = z.object({ ${ENV_SCHEMA_KEYS.map((key) => `${key}: z.string()`).join(', ')} });`);
|
|
11
|
-
const result = checkEnvSchemaCompatibility('/project');
|
|
12
|
-
expect(result.status).toBe('ok');
|
|
13
|
-
expect(result.schemaOnly).toEqual([]);
|
|
14
|
-
expect(result.mirrorOnly).toEqual([]);
|
|
15
|
-
});
|
|
16
|
-
it('reports variables added to or removed from the host schema', () => {
|
|
17
|
-
mockedRead.mockReturnValue('export const envSchema = z.object({ APP_MODE: z.string(), NEW_KEY: z.string() });');
|
|
18
|
-
const result = checkEnvSchemaCompatibility('/project');
|
|
19
|
-
expect(result.status).toBe('warn');
|
|
20
|
-
expect(result.schemaOnly).toEqual(['NEW_KEY']);
|
|
21
|
-
expect(result.mirrorOnly.length).toBeGreaterThan(0);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { extractEnvSchemaKeys } from './env-schema-parser.js';
|
|
3
|
-
describe('extractEnvSchemaKeys', () => {
|
|
4
|
-
it('finds z.object keys through chained calls and comments', () => {
|
|
5
|
-
expect(extractEnvSchemaKeys(`
|
|
6
|
-
export const envSchema = z
|
|
7
|
-
.object({ APP_MODE: z.string(), 'CUSTOM_KEY': z.string(), })
|
|
8
|
-
.superRefine(() => {});
|
|
9
|
-
`)).toEqual(['APP_MODE', 'CUSTOM_KEY']);
|
|
10
|
-
});
|
|
11
|
-
});
|
package/dist/utils/git.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/utils/git.test.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { dirNameFromGitUrl, clonePlugin } from './git.js';
|
|
3
|
-
vi.mock('node:child_process');
|
|
4
|
-
vi.mock('node:fs');
|
|
5
|
-
const { execSync, spawnSync } = await import('node:child_process');
|
|
6
|
-
const { existsSync, mkdirSync } = await import('node:fs');
|
|
7
|
-
const mockedExec = vi.mocked(execSync);
|
|
8
|
-
const mockedSpawn = vi.mocked(spawnSync);
|
|
9
|
-
const mockedExists = vi.mocked(existsSync);
|
|
10
|
-
const mockedMkdir = vi.mocked(mkdirSync);
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
vi.resetAllMocks();
|
|
13
|
-
});
|
|
14
|
-
// ---------------------------------------------------------------------------
|
|
15
|
-
// dirNameFromGitUrl
|
|
16
|
-
// ---------------------------------------------------------------------------
|
|
17
|
-
describe('dirNameFromGitUrl', () => {
|
|
18
|
-
it('extracts name from SSH URL with .git suffix', () => {
|
|
19
|
-
expect(dirNameFromGitUrl('git@github.com:org/codapult-plugin-onboarding.git')).toBe('codapult-plugin-onboarding');
|
|
20
|
-
});
|
|
21
|
-
it('extracts name from HTTPS URL without .git suffix', () => {
|
|
22
|
-
expect(dirNameFromGitUrl('https://github.com/org/codapult-plugin-crm')).toBe('codapult-plugin-crm');
|
|
23
|
-
});
|
|
24
|
-
it('handles URL with trailing slash', () => {
|
|
25
|
-
expect(dirNameFromGitUrl('https://github.com/org/my-plugin.git')).toBe('my-plugin');
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
// ---------------------------------------------------------------------------
|
|
29
|
-
// clonePlugin
|
|
30
|
-
// ---------------------------------------------------------------------------
|
|
31
|
-
describe('clonePlugin', () => {
|
|
32
|
-
it('clones into .codapult/plugins/ when directory does not exist', () => {
|
|
33
|
-
mockedExists.mockReturnValue(false);
|
|
34
|
-
mockedSpawn.mockReturnValue({
|
|
35
|
-
status: 0,
|
|
36
|
-
stderr: Buffer.from(''),
|
|
37
|
-
stdout: Buffer.from(''),
|
|
38
|
-
pid: 0,
|
|
39
|
-
signal: null,
|
|
40
|
-
output: [],
|
|
41
|
-
});
|
|
42
|
-
const result = clonePlugin('/project', 'git@github.com:org/codapult-plugin-test.git');
|
|
43
|
-
expect(result.pluginDir).toBe('/project/.codapult/plugins/codapult-plugin-test');
|
|
44
|
-
expect(mockedMkdir).toHaveBeenCalledWith('/project/.codapult/plugins', { recursive: true });
|
|
45
|
-
expect(mockedSpawn).toHaveBeenCalledWith('git', [
|
|
46
|
-
'clone',
|
|
47
|
-
'--depth',
|
|
48
|
-
'1',
|
|
49
|
-
'git@github.com:org/codapult-plugin-test.git',
|
|
50
|
-
'/project/.codapult/plugins/codapult-plugin-test',
|
|
51
|
-
], expect.objectContaining({ stdio: 'pipe' }));
|
|
52
|
-
});
|
|
53
|
-
it('runs git pull when .git directory already exists', () => {
|
|
54
|
-
mockedExists.mockReturnValue(true);
|
|
55
|
-
const result = clonePlugin('/project', 'git@github.com:org/codapult-plugin-test.git');
|
|
56
|
-
expect(result.pluginDir).toBe('/project/.codapult/plugins/codapult-plugin-test');
|
|
57
|
-
expect(mockedExec).toHaveBeenCalledWith('git pull --ff-only', expect.objectContaining({
|
|
58
|
-
cwd: '/project/.codapult/plugins/codapult-plugin-test',
|
|
59
|
-
}));
|
|
60
|
-
});
|
|
61
|
-
it('throws when git clone fails', () => {
|
|
62
|
-
mockedExists.mockReturnValue(false);
|
|
63
|
-
mockedSpawn.mockReturnValue({
|
|
64
|
-
status: 128,
|
|
65
|
-
stderr: Buffer.from('Permission denied (publickey)'),
|
|
66
|
-
stdout: Buffer.from(''),
|
|
67
|
-
pid: 0,
|
|
68
|
-
signal: null,
|
|
69
|
-
output: [],
|
|
70
|
-
});
|
|
71
|
-
expect(() => clonePlugin('/project', 'git@github.com:org/private-plugin.git')).toThrow('Permission denied');
|
|
72
|
-
});
|
|
73
|
-
it('rejects URLs that are not https:// or git@', () => {
|
|
74
|
-
expect(() => clonePlugin('/project', 'file:///etc/passwd')).toThrow('Invalid git URL');
|
|
75
|
-
expect(() => clonePlugin('/project', '/some/local/path')).toThrow('Invalid git URL');
|
|
76
|
-
});
|
|
77
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { healthExitCode } from './health-render.js';
|
|
3
|
-
describe('healthExitCode', () => {
|
|
4
|
-
it('fails CI only when the health report contains failures', () => {
|
|
5
|
-
expect(healthExitCode({
|
|
6
|
-
root: '/',
|
|
7
|
-
status: 'warn',
|
|
8
|
-
checks: [],
|
|
9
|
-
summary: { ok: 0, warnings: 1, failures: 0 },
|
|
10
|
-
})).toBe(0);
|
|
11
|
-
expect(healthExitCode({
|
|
12
|
-
root: '/',
|
|
13
|
-
status: 'fail',
|
|
14
|
-
checks: [],
|
|
15
|
-
summary: { ok: 0, warnings: 0, failures: 1 },
|
|
16
|
-
})).toBe(1);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { diffSchemaWithLiveDatabase } from './live-db-diff.js';
|
|
3
|
-
describe('diffSchemaWithLiveDatabase', () => {
|
|
4
|
-
it('compares physical column names and normalizes SQL types', () => {
|
|
5
|
-
const differences = diffSchemaWithLiveDatabase([
|
|
6
|
-
{
|
|
7
|
-
name: 'users',
|
|
8
|
-
columns: [
|
|
9
|
-
{ name: 'displayName', databaseName: 'display_name', type: 'text', constraints: [] },
|
|
10
|
-
{ name: 'id', databaseName: 'id', type: 'uuid', constraints: ['PRIMARY KEY'] },
|
|
11
|
-
],
|
|
12
|
-
},
|
|
13
|
-
], [
|
|
14
|
-
{
|
|
15
|
-
name: 'users',
|
|
16
|
-
columns: [
|
|
17
|
-
{ name: 'display_name', type: 'text', constraints: [] },
|
|
18
|
-
{ name: 'legacy', type: 'text', constraints: [] },
|
|
19
|
-
],
|
|
20
|
-
},
|
|
21
|
-
{ name: 'orphan', columns: [] },
|
|
22
|
-
]);
|
|
23
|
-
expect(differences).toEqual([
|
|
24
|
-
{ table: 'users', issue: 'column_missing_in_database', details: 'id' },
|
|
25
|
-
{ table: 'users', issue: 'column_missing_in_schema', details: 'legacy' },
|
|
26
|
-
{ table: 'orphan', issue: 'missing_in_schema' },
|
|
27
|
-
]);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { resolveManifest } from './manifest.js';
|
|
3
|
-
vi.mock('node:fs');
|
|
4
|
-
const { existsSync, readFileSync } = await import('node:fs');
|
|
5
|
-
const mockedExists = vi.mocked(existsSync);
|
|
6
|
-
const mockedRead = vi.mocked(readFileSync);
|
|
7
|
-
const ROOT = '/project';
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
vi.resetAllMocks();
|
|
10
|
-
});
|
|
11
|
-
const validManifest = JSON.stringify({
|
|
12
|
-
name: 'test-plugin',
|
|
13
|
-
package: '@codapult/plugin-test',
|
|
14
|
-
version: '0.1.0',
|
|
15
|
-
description: 'A test plugin',
|
|
16
|
-
install: {},
|
|
17
|
-
});
|
|
18
|
-
describe('resolveManifest', () => {
|
|
19
|
-
it('resolves manifest from direct path', () => {
|
|
20
|
-
mockedExists.mockImplementation((p) => {
|
|
21
|
-
const path = p;
|
|
22
|
-
return path === '/absolute/path/codapult-plugin.json';
|
|
23
|
-
});
|
|
24
|
-
mockedRead.mockReturnValue(validManifest);
|
|
25
|
-
const result = resolveManifest(ROOT, '/absolute/path');
|
|
26
|
-
expect(result).not.toBeNull();
|
|
27
|
-
expect(result.manifest.name).toBe('test-plugin');
|
|
28
|
-
expect(result.pluginDir).toBe('/absolute/path');
|
|
29
|
-
});
|
|
30
|
-
it('resolves manifest from sibling dir with codapult-plugin- prefix', () => {
|
|
31
|
-
mockedExists.mockImplementation((p) => {
|
|
32
|
-
const path = p;
|
|
33
|
-
return path === '/codapult-plugin-crm/codapult-plugin.json';
|
|
34
|
-
});
|
|
35
|
-
mockedRead.mockReturnValue(validManifest);
|
|
36
|
-
const result = resolveManifest(ROOT, 'crm');
|
|
37
|
-
expect(result).not.toBeNull();
|
|
38
|
-
expect(result.pluginDir).toContain('codapult-plugin-crm');
|
|
39
|
-
});
|
|
40
|
-
it('resolves manifest from sibling dir with codapult- prefix', () => {
|
|
41
|
-
mockedExists.mockImplementation((p) => {
|
|
42
|
-
const path = p;
|
|
43
|
-
// Direct path check fails, codapult-plugin- prefix fails, codapult- prefix succeeds
|
|
44
|
-
if (path.includes('codapult-plugin-foo'))
|
|
45
|
-
return false;
|
|
46
|
-
return path === '/codapult-foo/codapult-plugin.json';
|
|
47
|
-
});
|
|
48
|
-
mockedRead.mockReturnValue(validManifest);
|
|
49
|
-
const result = resolveManifest(ROOT, 'foo');
|
|
50
|
-
expect(result).not.toBeNull();
|
|
51
|
-
});
|
|
52
|
-
it('resolves manifest from sibling dir with exact name', () => {
|
|
53
|
-
mockedExists.mockImplementation((p) => {
|
|
54
|
-
const path = p;
|
|
55
|
-
if (path.includes('codapult-plugin-bar') || path.includes('codapult-bar'))
|
|
56
|
-
return false;
|
|
57
|
-
return path === '/bar/codapult-plugin.json';
|
|
58
|
-
});
|
|
59
|
-
mockedRead.mockReturnValue(validManifest);
|
|
60
|
-
const result = resolveManifest(ROOT, 'bar');
|
|
61
|
-
expect(result).not.toBeNullable();
|
|
62
|
-
});
|
|
63
|
-
it('returns null when no manifest found', () => {
|
|
64
|
-
mockedExists.mockReturnValue(false);
|
|
65
|
-
const result = resolveManifest(ROOT, 'nonexistent');
|
|
66
|
-
expect(result).toBeNullable();
|
|
67
|
-
});
|
|
68
|
-
it('resolves manifest from .codapult/plugins/ cache directory', () => {
|
|
69
|
-
mockedExists.mockImplementation((p) => {
|
|
70
|
-
const path = p;
|
|
71
|
-
return path === '/project/.codapult/plugins/codapult-plugin-cached/codapult-plugin.json';
|
|
72
|
-
});
|
|
73
|
-
mockedRead.mockReturnValue(validManifest);
|
|
74
|
-
const result = resolveManifest(ROOT, 'cached');
|
|
75
|
-
expect(result).not.toBeNull();
|
|
76
|
-
expect(result.pluginDir).toContain('.codapult/plugins/codapult-plugin-cached');
|
|
77
|
-
});
|
|
78
|
-
it('prefers .codapult/plugins/ cache over sibling directory', () => {
|
|
79
|
-
mockedExists.mockImplementation((p) => {
|
|
80
|
-
const path = p;
|
|
81
|
-
return (path === '/codapult-plugin-both/codapult-plugin.json' ||
|
|
82
|
-
path === '/project/.codapult/plugins/codapult-plugin-both/codapult-plugin.json');
|
|
83
|
-
});
|
|
84
|
-
mockedRead.mockReturnValue(validManifest);
|
|
85
|
-
const result = resolveManifest(ROOT, 'both');
|
|
86
|
-
expect(result).not.toBeNull();
|
|
87
|
-
expect(result.pluginDir).toBe('/project/.codapult/plugins/codapult-plugin-both');
|
|
88
|
-
});
|
|
89
|
-
it('returns null for invalid JSON manifest', () => {
|
|
90
|
-
mockedExists.mockReturnValue(true);
|
|
91
|
-
mockedRead.mockReturnValue('not valid json {{{');
|
|
92
|
-
const result = resolveManifest(ROOT, 'broken');
|
|
93
|
-
expect(result).toBeNullable();
|
|
94
|
-
});
|
|
95
|
-
it('prioritizes direct path over sibling directories', () => {
|
|
96
|
-
mockedExists.mockImplementation((p) => {
|
|
97
|
-
const path = p;
|
|
98
|
-
// Both direct path and sibling codapult-plugin- path have manifests
|
|
99
|
-
return (path === '/direct/codapult-plugin.json' ||
|
|
100
|
-
path === '/codapult-plugin-direct/codapult-plugin.json');
|
|
101
|
-
});
|
|
102
|
-
mockedRead.mockReturnValue(validManifest);
|
|
103
|
-
const result = resolveManifest(ROOT, '/direct');
|
|
104
|
-
expect(result).not.toBeNull();
|
|
105
|
-
expect(result.pluginDir).toBe('/direct');
|
|
106
|
-
});
|
|
107
|
-
});
|