@antelopejs/dms-assistant 0.2.7-next.443.g999eec7 → 0.2.7-next.445.g6db36a8
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/package.json +6 -2
- package/frontend-vue/builder/tests/database-build.test.ts +0 -232
- package/frontend-vue/builder/tests/database-connect.test.ts +0 -348
- package/frontend-vue/builder/tests/database-display.test.ts +0 -112
- package/frontend-vue/builder/tests/database.test.ts +0 -138
- package/frontend-vue/builder/tests/enabled.test.ts +0 -17
- package/frontend-vue/builder/tests/owner-ui.test.ts +0 -29
- package/frontend-vue/builder/tests/stubs/frontend-module.ts +0 -63
- package/frontend-vue/builder/vitest.config.ts +0 -21
- package/frontend-vue/tests/assistant-actions.test.ts +0 -109
- package/frontend-vue/tests/assistant-activity.test.ts +0 -281
- package/frontend-vue/tests/backend-boundary.test.ts +0 -130
- package/frontend-vue/tests/backoff.test.ts +0 -40
- package/frontend-vue/tests/block-health.test.ts +0 -142
- package/frontend-vue/tests/channel-client.test.ts +0 -246
- package/frontend-vue/tests/chat/block-preview.test.ts +0 -367
- package/frontend-vue/tests/chat/block-target.test.ts +0 -133
- package/frontend-vue/tests/chat/build-view.test.ts +0 -171
- package/frontend-vue/tests/chat/chat-scroll.test.ts +0 -251
- package/frontend-vue/tests/chat/conversation-events.test.ts +0 -622
- package/frontend-vue/tests/chat/diff-and-keys.test.ts +0 -178
- package/frontend-vue/tests/chat/held-card.test.ts +0 -133
- package/frontend-vue/tests/chat/markdown-content.test.ts +0 -86
- package/frontend-vue/tests/chat/markdown.test.ts +0 -352
- package/frontend-vue/tests/chat/provider-notice.test.ts +0 -33
- package/frontend-vue/tests/chat/tool-lexicon.test.ts +0 -212
- package/frontend-vue/tests/chat/useChatChannel.test.ts +0 -124
- package/frontend-vue/tests/chat/useConversation.test.ts +0 -288
- package/frontend-vue/tests/chat-panel.test.ts +0 -300
- package/frontend-vue/tests/chat-transport.test.ts +0 -94
- package/frontend-vue/tests/embedding.test.ts +0 -10
- package/frontend-vue/tests/formal/connection-analysis-scenarios.ts +0 -130
- package/frontend-vue/tests/formal/connection-analysis-world.ts +0 -497
- package/frontend-vue/tests/formal/connection-analysis.test.ts +0 -36
- package/frontend-vue/tests/host-commands.test.ts +0 -182
- package/frontend-vue/tests/launcher-icon.test.ts +0 -62
- package/frontend-vue/tests/launcher-label.test.ts +0 -40
- package/frontend-vue/tests/launcher-state.test.ts +0 -215
- package/frontend-vue/tests/mockup-fold.test.ts +0 -95
- package/frontend-vue/tests/navigation.test.ts +0 -142
- package/frontend-vue/tests/onboarding-api.test.ts +0 -29
- package/frontend-vue/tests/onboarding-claude.test.ts +0 -144
- package/frontend-vue/tests/onboarding-connect-memory.test.ts +0 -126
- package/frontend-vue/tests/onboarding-controller-restart.test.ts +0 -134
- package/frontend-vue/tests/onboarding-controller.test.ts +0 -307
- package/frontend-vue/tests/onboarding-database-driver-install.test.ts +0 -112
- package/frontend-vue/tests/onboarding-database-engines.test.ts +0 -142
- package/frontend-vue/tests/onboarding-database-new-url.test.ts +0 -174
- package/frontend-vue/tests/onboarding-database-reload.test.ts +0 -229
- package/frontend-vue/tests/onboarding-database-tabs.test.ts +0 -184
- package/frontend-vue/tests/onboarding-database.test.ts +0 -540
- package/frontend-vue/tests/onboarding-deep-link.test.ts +0 -51
- package/frontend-vue/tests/onboarding-flow.test.ts +0 -204
- package/frontend-vue/tests/onboarding-install.test.ts +0 -62
- package/frontend-vue/tests/onboarding-mockups.test.ts +0 -86
- package/frontend-vue/tests/onboarding-scratch.test.ts +0 -70
- package/frontend-vue/tests/onboarding-widget.test.ts +0 -97
- package/frontend-vue/tests/palette-assistant.test.ts +0 -241
- package/frontend-vue/tests/panel-approvals.test.ts +0 -226
- package/frontend-vue/tests/panel-closed-conversation.test.ts +0 -53
- package/frontend-vue/tests/panel-mockup-prompt.test.ts +0 -238
- package/frontend-vue/tests/panel-modes.test.ts +0 -131
- package/frontend-vue/tests/panel-questions.test.ts +0 -151
- package/frontend-vue/tests/panel-states.test.ts +0 -252
- package/frontend-vue/tests/panel-tools.test.ts +0 -219
- package/frontend-vue/tests/session-gate.test.ts +0 -66
- package/frontend-vue/tests/sidecar-guest.test.ts +0 -81
- package/frontend-vue/tests/sidecar-status.test.ts +0 -117
- package/frontend-vue/tests/support/api-error-presenter.ts +0 -30
- package/frontend-vue/tests/support/database-connect.ts +0 -129
- package/frontend-vue/tests/support/dms-frontend-module.ts +0 -9
- package/frontend-vue/tests/support/dms-state.ts +0 -12
- package/frontend-vue/tests/support/fake-layout.ts +0 -119
- package/frontend-vue/tests/support/i18n.ts +0 -49
- package/frontend-vue/tests/support/onboarding-host.ts +0 -104
- package/frontend-vue/tests/support/onboarding.ts +0 -176
- package/frontend-vue/tests/support/panel-fixtures.ts +0 -155
- package/frontend-vue/tests/support/panel-harness.ts +0 -211
- package/frontend-vue/tests/support/setup-layout.ts +0 -3
- package/frontend-vue/tests/support/stand-ins/DmsBlockPreview.ts +0 -18
- package/frontend-vue/tests/support/stand-ins/DmsEmptyState.ts +0 -17
- package/frontend-vue/tests/support/stand-ins/DmsSegmentedControl.ts +0 -35
- package/frontend-vue/tests/support/stand-ins/DmsStatusPill.ts +0 -7
- package/frontend-vue/tests/support/stand-ins/OnboardingModal.ts +0 -13
- package/frontend-vue/tests/support/stand-ins/UBadge.ts +0 -7
- package/frontend-vue/tests/support/stand-ins/UButton.ts +0 -27
- package/frontend-vue/tests/support/stand-ins/UCheckbox.ts +0 -25
- package/frontend-vue/tests/support/stand-ins/UDropdownMenu.ts +0 -34
- package/frontend-vue/tests/support/stand-ins/UFormField.ts +0 -9
- package/frontend-vue/tests/support/stand-ins/UInput.ts +0 -16
- package/frontend-vue/tests/support/stand-ins/UKbd.ts +0 -7
- package/frontend-vue/tests/support/stand-ins/UModal.ts +0 -20
- package/frontend-vue/tests/support/stand-ins/UPopover.ts +0 -9
- package/frontend-vue/tests/support/stand-ins/UTabs.ts +0 -31
- package/frontend-vue/tests/support/stand-ins/UTextarea.ts +0 -19
- package/frontend-vue/tests/support/stubs.ts +0 -28
- package/frontend-vue/tests/views/api-data-reads.test.ts +0 -451
- package/frontend-vue/tests/views/api-error-presentation.test.ts +0 -89
- package/frontend-vue/tests/views/diff-view.test.ts +0 -167
- package/frontend-vue/tests/views/use-assistant.test.ts +0 -53
- package/frontend-vue/tests/views/view-format.test.ts +0 -59
- package/frontend-vue/vitest.config.ts +0 -33
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/dms-assistant",
|
|
3
|
-
"version": "0.2.7-next.
|
|
3
|
+
"version": "0.2.7-next.445.g6db36a8",
|
|
4
4
|
"description": "Development assistant for the AntelopeJS DMS: a chat panel and coding agent that edit the project in reviewable, undoable change sets, and an onboarding that starts a project from scratch or from a database you already run.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -25,6 +25,10 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"dist",
|
|
27
27
|
"frontend-vue",
|
|
28
|
+
"!frontend-vue/tests",
|
|
29
|
+
"!frontend-vue/builder/tests",
|
|
30
|
+
"!frontend-vue/vitest.config.ts",
|
|
31
|
+
"!frontend-vue/builder/vitest.config.ts",
|
|
28
32
|
"skills",
|
|
29
33
|
"sidecar/dist",
|
|
30
34
|
"sidecar/package.json"
|
|
@@ -95,7 +99,7 @@
|
|
|
95
99
|
}
|
|
96
100
|
},
|
|
97
101
|
"dmsFrontend": "dist/frontend-module.js",
|
|
98
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "6db36a8594a4de4b4ec410b05aa8993736121321",
|
|
99
103
|
"scripts": {
|
|
100
104
|
"build": "rimraf dist && tsc",
|
|
101
105
|
"build:sidecar": "pnpm --dir sidecar run build",
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { buildState, preferredSchemas } from '../app/runtime/database-build'
|
|
3
|
-
import type {
|
|
4
|
-
AnalysisState,
|
|
5
|
-
DatabaseConnection,
|
|
6
|
-
MappingProposal,
|
|
7
|
-
OpenItem,
|
|
8
|
-
ProposedResource,
|
|
9
|
-
} from '../app/runtime/database-types'
|
|
10
|
-
|
|
11
|
-
type BuildAnswers = Parameters<typeof buildState>[0]
|
|
12
|
-
|
|
13
|
-
const THREE_MINUTES_MS = 3 * 60 * 1000
|
|
14
|
-
const TWENTY_SECONDS_MS = 20 * 1000
|
|
15
|
-
|
|
16
|
-
function proposed<T>(value: T) {
|
|
17
|
-
return { value, rule: 'R1', kind: 'default' as const }
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function resource(relation: string, tableView: boolean): ProposedResource {
|
|
21
|
-
return {
|
|
22
|
-
relation,
|
|
23
|
-
tableView: proposed(tableView),
|
|
24
|
-
writable: proposed(false),
|
|
25
|
-
label: proposed(null),
|
|
26
|
-
title: proposed(relation),
|
|
27
|
-
fields: [],
|
|
28
|
-
leftOut: [],
|
|
29
|
-
writes: { insert: false, update: false, delete: false },
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function item(id: string, kind: OpenItem['kind'], extra: Partial<OpenItem> = {}): OpenItem {
|
|
34
|
-
return { id, kind, question: id, options: [], proposed: null, ...extra }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** The seed database's proposal: 5 pages, 2 for statistics, 2 labels and a purpose. */
|
|
38
|
-
const SEED: MappingProposal = {
|
|
39
|
-
connection: 'orb',
|
|
40
|
-
module: 'builder-db-orb-tables',
|
|
41
|
-
database: { engine: 'postgresql', role: 'reader', writes: 'none' },
|
|
42
|
-
resources: [
|
|
43
|
-
...['customers', 'employees', 'invoices', 'orders', 'products'].map((name) => resource(`public.${name}`, true)),
|
|
44
|
-
resource('public.categories', false),
|
|
45
|
-
resource('public.suppliers', false),
|
|
46
|
-
],
|
|
47
|
-
excluded: [],
|
|
48
|
-
open: [
|
|
49
|
-
item('label:customers', 'label', { relation: 'public.customers' }),
|
|
50
|
-
item('label:orders', 'label', { relation: 'public.orders' }),
|
|
51
|
-
item('purpose:order_items', 'purpose', {
|
|
52
|
-
relation: 'public.order_items',
|
|
53
|
-
resource: resource('public.order_items', false),
|
|
54
|
-
}),
|
|
55
|
-
],
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const LISTED: DatabaseConnection = {
|
|
59
|
-
id: 'orb',
|
|
60
|
-
engine: 'postgresql',
|
|
61
|
-
version: '16.15',
|
|
62
|
-
database: 'orb',
|
|
63
|
-
role: 'reader',
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function job(status: AnalysisState['status'], proposal?: MappingProposal): AnalysisState {
|
|
67
|
-
return {
|
|
68
|
-
id: 'job-1',
|
|
69
|
-
connection: 'orb',
|
|
70
|
-
status,
|
|
71
|
-
progress: { relations: 8, described: 8, toProfile: 8, profiled: 3, timeouts: 0 },
|
|
72
|
-
proposal,
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function statuses(answers: BuildAnswers, reloadingFor = 0): string[] {
|
|
77
|
-
return buildState(answers, reloadingFor).steps.map((step) => step.status)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
describe('the build steps, derived from the three answers', () => {
|
|
81
|
-
it('reads a failed request as the project reloading', () => {
|
|
82
|
-
const answers: BuildAnswers = { declared: 'unreachable', listed: 'unreachable', analysis: 'unreachable' }
|
|
83
|
-
expect(statuses(answers)).toEqual(['done', 'running', 'pending', 'pending'])
|
|
84
|
-
expect(buildState(answers).reload).toBe('down')
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('waits on the reload while the connection is declared and not listed yet', () => {
|
|
88
|
-
const answers: BuildAnswers = { declared: true, variable: 'BUILDER_DB_ORB_URL', listed: null, analysis: null }
|
|
89
|
-
const view = buildState(answers)
|
|
90
|
-
expect(statuses(answers)).toEqual(['done', 'running', 'pending', 'pending'])
|
|
91
|
-
expect(view.steps[0]?.detail).toContain('BUILDER_DB_ORB_URL')
|
|
92
|
-
expect(view.needsAnalysis).toBe(false)
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
it('fails step 3 with the error the connection reports', () => {
|
|
96
|
-
const answers: BuildAnswers = {
|
|
97
|
-
declared: true,
|
|
98
|
-
listed: { id: 'orb', error: 'PostgreSQL adapter is not connected: wrong user or password (28P01)' },
|
|
99
|
-
analysis: null,
|
|
100
|
-
}
|
|
101
|
-
const view = buildState(answers)
|
|
102
|
-
expect(statuses(answers)).toEqual(['done', 'done', 'failed', 'pending'])
|
|
103
|
-
expect(view.connectionError).toContain('wrong user or password')
|
|
104
|
-
expect(view.needsAnalysis).toBe(false)
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
it('asks for the analysis once connected and none exists', () => {
|
|
108
|
-
const answers: BuildAnswers = { declared: true, listed: LISTED, analysis: null }
|
|
109
|
-
expect(statuses(answers)).toEqual(['done', 'done', 'done', 'running'])
|
|
110
|
-
expect(buildState(answers).needsAnalysis).toBe(true)
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
it('shows the analysis progress while it runs', () => {
|
|
114
|
-
const answers: BuildAnswers = { declared: true, listed: LISTED, analysis: job('running') }
|
|
115
|
-
const view = buildState(answers)
|
|
116
|
-
expect(view.steps[3]).toMatchObject({ status: 'running', detail: '8 of 8 tables described, 3 of 8 profiled.' })
|
|
117
|
-
expect(view.needsAnalysis).toBe(false)
|
|
118
|
-
expect(view.fork).toBeUndefined()
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it('fails step 4 with the analysis error', () => {
|
|
122
|
-
const answers: BuildAnswers = { declared: true, listed: LISTED, analysis: { ...job('failed'), error: 'timeout' } }
|
|
123
|
-
const view = buildState(answers)
|
|
124
|
-
expect(view.steps[3]).toMatchObject({ status: 'failed', detail: 'The analysis failed: timeout' })
|
|
125
|
-
expect(view.analysisFailed).toBe(true)
|
|
126
|
-
expect(view.needsAnalysis).toBe(false)
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
it('asks the schemas question instead of forking', () => {
|
|
130
|
-
const schemas = item('schemas:orb', 'schemas', { options: [{ value: 'sales', title: 'sales (150)' }] })
|
|
131
|
-
const answers: BuildAnswers = {
|
|
132
|
-
declared: true,
|
|
133
|
-
listed: LISTED,
|
|
134
|
-
analysis: job('done', { ...SEED, resources: [], open: [schemas] }),
|
|
135
|
-
}
|
|
136
|
-
const view = buildState(answers)
|
|
137
|
-
expect(view.schemas?.id).toBe('schemas:orb')
|
|
138
|
-
expect(view.steps[3]?.status).toBe('running')
|
|
139
|
-
expect(view.fork).toBeUndefined()
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
it('forks on a finished analysis, on its job', () => {
|
|
143
|
-
const answers: BuildAnswers = { declared: true, listed: LISTED, analysis: job('done', SEED) }
|
|
144
|
-
const view = buildState(answers)
|
|
145
|
-
expect(statuses(answers)).toEqual(['done', 'done', 'done', 'done'])
|
|
146
|
-
expect(view.fork).toEqual({ tables: 8, pages: 5, stats: 2, questions: 3 })
|
|
147
|
-
expect(view.job).toBe('job-1')
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
it('ends without a fork when there is nothing the role can read', () => {
|
|
151
|
-
const answers: BuildAnswers = {
|
|
152
|
-
declared: true,
|
|
153
|
-
listed: LISTED,
|
|
154
|
-
analysis: job('done', { ...SEED, resources: [], open: [] }),
|
|
155
|
-
}
|
|
156
|
-
const view = buildState(answers)
|
|
157
|
-
expect(view.empty).toBe(true)
|
|
158
|
-
expect(view.fork).toBeUndefined()
|
|
159
|
-
expect(view.steps[3]?.detail).toBe('No tables user reader can read.')
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
it('fails the reload after 3 minutes with how to restart by hand, and not before', () => {
|
|
163
|
-
const answers: BuildAnswers = { declared: 'unreachable', listed: 'unreachable', analysis: 'unreachable' }
|
|
164
|
-
expect(buildState(answers, THREE_MINUTES_MS - 1).steps[1]?.status).toBe('running')
|
|
165
|
-
const late = buildState(answers, THREE_MINUTES_MS)
|
|
166
|
-
expect(late.gaveUp).toBe(true)
|
|
167
|
-
expect(late.steps[1]).toMatchObject({ status: 'failed' })
|
|
168
|
-
expect(late.steps[1]?.detail).toContain('Restart it by hand')
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
it('asks for a restart once the project has answered for 20 seconds without the connection, and keeps waiting', () => {
|
|
172
|
-
const answers: BuildAnswers = { declared: true, listed: null, analysis: null }
|
|
173
|
-
expect(buildState(answers, TWENTY_SECONDS_MS - 1).restartNeeded).toBe(false)
|
|
174
|
-
expect(buildState(answers, TWENTY_SECONDS_MS).restartNeeded).toBe(true)
|
|
175
|
-
const late = buildState(answers, THREE_MINUTES_MS)
|
|
176
|
-
expect(late.restartNeeded).toBe(true)
|
|
177
|
-
expect(late.gaveUp).toBe(false)
|
|
178
|
-
expect(late.steps[1]).toMatchObject({ status: 'running' })
|
|
179
|
-
expect(late.steps[1]?.detail).toContain('ajs project dev -w')
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
it('asks for no restart while the project does not answer', () => {
|
|
183
|
-
const answers: BuildAnswers = { declared: 'unreachable', listed: 'unreachable', analysis: 'unreachable' }
|
|
184
|
-
expect(buildState(answers, TWENTY_SECONDS_MS).restartNeeded).toBe(false)
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
it('fails step 1 when the configuration no longer declares the connection', () => {
|
|
188
|
-
expect(statuses({ declared: false, listed: null, analysis: null })[0]).toBe('failed')
|
|
189
|
-
})
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
describe('the fork summary', () => {
|
|
193
|
-
const fork = (proposal: MappingProposal) =>
|
|
194
|
-
buildState({ declared: true, listed: LISTED, analysis: job('done', proposal) }).fork
|
|
195
|
-
|
|
196
|
-
it('counts a purpose item as a table, and its own questions with the open items', () => {
|
|
197
|
-
const withQuestions: MappingProposal = {
|
|
198
|
-
...SEED,
|
|
199
|
-
open: SEED.open.map((entry) =>
|
|
200
|
-
entry.kind === 'purpose' ? { ...entry, open: [item('label:order_items', 'label')] } : entry,
|
|
201
|
-
),
|
|
202
|
-
}
|
|
203
|
-
expect(fork(withQuestions)).toEqual({ tables: 8, pages: 5, stats: 2, questions: 4 })
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
it('counts field-type items as questions', () => {
|
|
207
|
-
const typed = { ...SEED, open: [...SEED.open, item('field-type:orders.total', 'field-type')] }
|
|
208
|
-
expect(fork(typed)?.questions).toBe(4)
|
|
209
|
-
})
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
describe('the schemas the question pre-checks', () => {
|
|
213
|
-
it('checks public when the database has it', () => {
|
|
214
|
-
const schemas = item('s', 'schemas', {
|
|
215
|
-
options: [
|
|
216
|
-
{ value: 'sales', title: 'sales (300)' },
|
|
217
|
-
{ value: 'public', title: 'public (12)' },
|
|
218
|
-
],
|
|
219
|
-
})
|
|
220
|
-
expect(preferredSchemas(schemas)).toEqual(['public'])
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
it('checks the largest schema otherwise', () => {
|
|
224
|
-
const schemas = item('s', 'schemas', {
|
|
225
|
-
options: [
|
|
226
|
-
{ value: 'hr', title: 'hr (40)' },
|
|
227
|
-
{ value: 'sales', title: 'sales (300)' },
|
|
228
|
-
],
|
|
229
|
-
})
|
|
230
|
-
expect(preferredSchemas(schemas)).toEqual(['sales'])
|
|
231
|
-
})
|
|
232
|
-
})
|
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
type ConnectForm,
|
|
4
|
-
connectSteps,
|
|
5
|
-
connectVariables,
|
|
6
|
-
connectionUrl,
|
|
7
|
-
connectionId,
|
|
8
|
-
engineOfScheme,
|
|
9
|
-
fieldProblem,
|
|
10
|
-
managedNames,
|
|
11
|
-
missingField,
|
|
12
|
-
parseConnectionUrl,
|
|
13
|
-
} from '../app/runtime/database-connect'
|
|
14
|
-
import type { DriverPackage, ProjectModules } from '../app/runtime/database-types'
|
|
15
|
-
|
|
16
|
-
const FIELDS = parseConnectionUrl('postgres', 'postgres://reader:s3cret@db.example:5432/erp')
|
|
17
|
-
|
|
18
|
-
const POSTGRES_DRIVER: DriverPackage = { package: '@antelopejs/postgres', version: '>=0.2.6 <0.3.0' }
|
|
19
|
-
|
|
20
|
-
function form(overrides: Partial<ConnectForm> = {}): ConnectForm {
|
|
21
|
-
return {
|
|
22
|
-
name: 'ERP',
|
|
23
|
-
engine: 'postgres',
|
|
24
|
-
fields: FIELDS,
|
|
25
|
-
overrides: {},
|
|
26
|
-
...overrides,
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function project(overrides: Partial<ProjectModules> = {}): ProjectModules {
|
|
31
|
-
return { modules: [], self: 'dms', databasePins: [], drivers: {}, ...overrides }
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
describe('the names the builder manages for a connection', () => {
|
|
35
|
-
it('follows the name under a prefix no ordinary module uses', () => {
|
|
36
|
-
expect(managedNames(form({ name: 'Client ERP' }))).toEqual({
|
|
37
|
-
driverModule: 'builder-db-client-erp',
|
|
38
|
-
tablesModule: 'builder-db-client-erp-tables',
|
|
39
|
-
variable: 'BUILDER_DB_CLIENT_ERP_URL',
|
|
40
|
-
databaseVariable: 'BUILDER_DB_CLIENT_ERP_DATABASE',
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('folds accents rather than splitting the word', () => {
|
|
45
|
-
expect(connectionId('Données Comptabilité')).toBe('donnees-comptabilite')
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('keeps a name the integrator changed, and derives the others', () => {
|
|
49
|
-
const steps = connectSteps(form({ overrides: { tablesModule: 'erp-tables' } }), project(), POSTGRES_DRIVER)
|
|
50
|
-
expect(steps.map((step) => `${step.op}:${step.id}`)).toEqual([
|
|
51
|
-
'AddModule:builder-db-erp',
|
|
52
|
-
'CreateLocalModule:erp-tables',
|
|
53
|
-
'ConfigureModule:dms',
|
|
54
|
-
])
|
|
55
|
-
})
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
describe('the wiring of a database', () => {
|
|
59
|
-
it('adds the driver at the range the project gives, below every other database provider, and touches no other module than the DMS', () => {
|
|
60
|
-
const [driver, tables, dms] = connectSteps(form(), project({ modules: ['mongodb', 'dms'] }), POSTGRES_DRIVER)
|
|
61
|
-
expect(driver).toMatchObject({
|
|
62
|
-
op: 'AddModule',
|
|
63
|
-
entry: {
|
|
64
|
-
source: { type: 'package', package: '@antelopejs/postgres', version: '>=0.2.6 <0.3.0' },
|
|
65
|
-
env: { url: 'BUILDER_DB_ERP_URL' },
|
|
66
|
-
exportPriority: { '@antelopejs/interface-database': -1 },
|
|
67
|
-
},
|
|
68
|
-
})
|
|
69
|
-
expect(tables).toMatchObject({
|
|
70
|
-
path: 'modules/builder-db-erp-tables',
|
|
71
|
-
entry: { importOverrides: [{ interface: '@antelopejs/interface-database', source: 'builder-db-erp' }] },
|
|
72
|
-
})
|
|
73
|
-
expect(dms).toMatchObject({ id: 'dms' })
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
it('declares the connection on the id the project gives @antelopejs/dms', () => {
|
|
77
|
-
const steps = connectSteps(
|
|
78
|
-
form(),
|
|
79
|
-
project({ modules: ['@antelopejs/dms'], self: '@antelopejs/dms' }),
|
|
80
|
-
POSTGRES_DRIVER,
|
|
81
|
-
)
|
|
82
|
-
expect(steps.filter((step) => step.op === 'ConfigureModule').map((step) => step.id)).toEqual(['@antelopejs/dms'])
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
it('gives the builder and the assistant one connection, on the DMS', () => {
|
|
86
|
-
const steps = connectSteps(form(), project({ modules: ['dms'] }), POSTGRES_DRIVER)
|
|
87
|
-
expect(steps.filter((step) => step.op === 'ConfigureModule')).toEqual([
|
|
88
|
-
{
|
|
89
|
-
op: 'ConfigureModule',
|
|
90
|
-
id: 'dms',
|
|
91
|
-
entry: {
|
|
92
|
-
importOverrides: [
|
|
93
|
-
{ interface: '@antelopejs/interface-database-catalog', source: 'builder-db-erp', id: 'erp' },
|
|
94
|
-
],
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
])
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
it('pins each module the builder says needs the project\'s own database, one step each', () => {
|
|
101
|
-
const steps = connectSteps(
|
|
102
|
-
form(),
|
|
103
|
-
project({
|
|
104
|
-
modules: ['dms', 'app', 'mongodb'],
|
|
105
|
-
ownDatabase: 'mongodb',
|
|
106
|
-
databasePins: [
|
|
107
|
-
{ module: 'dms', provider: 'mongodb' },
|
|
108
|
-
{ module: 'app', provider: 'mongodb' },
|
|
109
|
-
],
|
|
110
|
-
}),
|
|
111
|
-
POSTGRES_DRIVER,
|
|
112
|
-
)
|
|
113
|
-
expect(steps.slice(3)).toEqual([
|
|
114
|
-
{
|
|
115
|
-
op: 'ConfigureModule',
|
|
116
|
-
id: 'dms',
|
|
117
|
-
entry: { importOverrides: [{ interface: '@antelopejs/interface-database', source: 'mongodb' }] },
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
op: 'ConfigureModule',
|
|
121
|
-
id: 'app',
|
|
122
|
-
entry: { importOverrides: [{ interface: '@antelopejs/interface-database', source: 'mongodb' }] },
|
|
123
|
-
},
|
|
124
|
-
])
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
describe('and its registration with dms-database', () => {
|
|
128
|
-
const registered = project({
|
|
129
|
-
modules: ['dms', 'dms-database', 'mongodb'],
|
|
130
|
-
ownDatabase: 'mongodb',
|
|
131
|
-
dmsDatabase: 'dms-database',
|
|
132
|
-
})
|
|
133
|
-
const dmsDatabaseStep = (form: ConnectForm, modules = registered) =>
|
|
134
|
-
connectSteps(form, modules, POSTGRES_DRIVER).find((step) => step.id === 'dms-database')
|
|
135
|
-
|
|
136
|
-
it('writes the own database first, then the connection on both interfaces, and reads it only by default', () => {
|
|
137
|
-
expect(dmsDatabaseStep(form())).toEqual({
|
|
138
|
-
op: 'ConfigureModule',
|
|
139
|
-
id: 'dms-database',
|
|
140
|
-
entry: {
|
|
141
|
-
importOverrides: [
|
|
142
|
-
{ interface: '@antelopejs/interface-database', source: 'mongodb' },
|
|
143
|
-
{ interface: '@antelopejs/interface-database', source: 'builder-db-erp', id: 'erp' },
|
|
144
|
-
{ interface: '@antelopejs/interface-database-catalog', source: 'builder-db-erp', id: 'erp' },
|
|
145
|
-
],
|
|
146
|
-
config: { externalConnections: { erp: { access: 'read' } } },
|
|
147
|
-
},
|
|
148
|
-
})
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
it('writes read-write access when the integrator chose it', () => {
|
|
152
|
-
expect(dmsDatabaseStep(form({ access: 'read-write' }))).toMatchObject({
|
|
153
|
-
entry: { config: { externalConnections: { erp: { access: 'read-write' } } } },
|
|
154
|
-
})
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
it('comes after the catalog connection and before the pins', () => {
|
|
158
|
-
const steps = connectSteps(
|
|
159
|
-
form(),
|
|
160
|
-
{ ...registered, databasePins: [{ module: 'app', provider: 'mongodb' }] },
|
|
161
|
-
POSTGRES_DRIVER,
|
|
162
|
-
)
|
|
163
|
-
expect(steps.map((step) => step.id)).toEqual([
|
|
164
|
-
'builder-db-erp',
|
|
165
|
-
'builder-db-erp-tables',
|
|
166
|
-
'dms',
|
|
167
|
-
'dms-database',
|
|
168
|
-
'app',
|
|
169
|
-
])
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
it('is written when the project has dms-database and an own database to pin it to, and not otherwise', () => {
|
|
173
|
-
expect(dmsDatabaseStep(form())).toBeDefined()
|
|
174
|
-
expect(dmsDatabaseStep(form(), project({ modules: registered.modules, ownDatabase: 'mongodb' }))).toBeUndefined()
|
|
175
|
-
expect(dmsDatabaseStep(form(), project({ modules: registered.modules, dmsDatabase: 'dms-database' }))).toBeUndefined()
|
|
176
|
-
})
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
it('never carries the connection details into the configuration', () => {
|
|
180
|
-
expect(JSON.stringify(connectSteps(form(), project({ modules: ['dms-assistant'] }), POSTGRES_DRIVER))).not.toMatch(
|
|
181
|
-
/s3cret|db\.example|postgres:\/\//,
|
|
182
|
-
)
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
it('waits for a name, a host, a database and a user', () => {
|
|
186
|
-
expect(missingField(form())).toBeUndefined()
|
|
187
|
-
expect(missingField(form({ name: ' - ' }))).toBe('a name')
|
|
188
|
-
expect(missingField(form({ fields: { ...form().fields, user: '' } }))).toBe('a user')
|
|
189
|
-
})
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
describe('the wiring of a document database', () => {
|
|
193
|
-
const mongodb = (overrides: Partial<ConnectForm> = {}) =>
|
|
194
|
-
form({
|
|
195
|
-
engine: 'mongodb',
|
|
196
|
-
fields: { ...FIELDS, port: '27017' },
|
|
197
|
-
...overrides,
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
it('wires postgres with its URL only, and disables no export', () => {
|
|
201
|
-
const [driver] = connectSteps(form(), project(), POSTGRES_DRIVER)
|
|
202
|
-
expect(driver.entry).not.toHaveProperty('disabledExports')
|
|
203
|
-
expect(connectVariables(form()).map((variable) => variable.name)).toEqual(['BUILDER_DB_ERP_URL'])
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
it('wires mongodb with its URL and database variables, and never offers its raw client', () => {
|
|
207
|
-
const [driver] = connectSteps(mongodb(), project(), { package: '@antelopejs/mongodb', version: '>=1.6.3 <1.7.0' })
|
|
208
|
-
expect(driver.entry).toMatchObject({
|
|
209
|
-
source: { package: '@antelopejs/mongodb', version: '>=1.6.3 <1.7.0' },
|
|
210
|
-
config: { mode: 'external' },
|
|
211
|
-
env: { url: 'BUILDER_DB_ERP_URL', database: 'BUILDER_DB_ERP_DATABASE' },
|
|
212
|
-
disabledExports: ['@antelopejs/interface-mongodb'],
|
|
213
|
-
})
|
|
214
|
-
expect(connectVariables(mongodb())).toEqual([
|
|
215
|
-
{ name: 'BUILDER_DB_ERP_URL', value: 'mongodb://reader:s3cret@db.example:27017/erp' },
|
|
216
|
-
{ name: 'BUILDER_DB_ERP_DATABASE', value: 'erp' },
|
|
217
|
-
])
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
it('waits for a database variable only where the driver reads one', () => {
|
|
221
|
-
expect(missingField(mongodb({ overrides: { databaseVariable: ' ' } }))).toBe('a database variable')
|
|
222
|
-
expect(missingField(form({ overrides: { databaseVariable: ' ' } }))).toBeUndefined()
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
it('wires rethinkdb with the database in its URL, and never offers its raw client', () => {
|
|
226
|
-
const rethinkdb = form({
|
|
227
|
-
engine: 'rethinkdb',
|
|
228
|
-
fields: { ...FIELDS, port: '28015' },
|
|
229
|
-
})
|
|
230
|
-
const [driver] = connectSteps(rethinkdb, project(), { package: '@antelopejs/rethinkdb', version: '>=1.7.1 <1.9.0' })
|
|
231
|
-
expect(driver.entry).toMatchObject({
|
|
232
|
-
source: { package: '@antelopejs/rethinkdb', version: '>=1.7.1 <1.9.0' },
|
|
233
|
-
env: { url: 'BUILDER_DB_ERP_URL' },
|
|
234
|
-
disabledExports: ['@antelopejs/interface-rethinkdb'],
|
|
235
|
-
})
|
|
236
|
-
expect(connectVariables(rethinkdb)).toEqual([
|
|
237
|
-
{ name: 'BUILDER_DB_ERP_URL', value: 'rethinkdb://reader:s3cret@db.example:28015/erp' },
|
|
238
|
-
])
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
it('wires mysql with the database in its URL, and disables no export', () => {
|
|
242
|
-
const { host, database, user, password } = FIELDS
|
|
243
|
-
const mysql = form({ engine: 'mysql', fields: { ...FIELDS, port: '3306' } })
|
|
244
|
-
const [driver] = connectSteps(mysql, project(), { package: '@antelopejs/mysql', version: '>=0.1.0 <0.2.0' })
|
|
245
|
-
expect(driver.entry).toMatchObject({
|
|
246
|
-
source: { package: '@antelopejs/mysql', version: '>=0.1.0 <0.2.0' },
|
|
247
|
-
env: { url: 'BUILDER_DB_ERP_URL' },
|
|
248
|
-
})
|
|
249
|
-
expect(driver.entry).not.toHaveProperty('disabledExports')
|
|
250
|
-
expect(connectVariables(mysql)).toEqual([
|
|
251
|
-
{ name: 'BUILDER_DB_ERP_URL', value: `mysql://${user}:${password}@${host}:3306/${database}` },
|
|
252
|
-
])
|
|
253
|
-
})
|
|
254
|
-
|
|
255
|
-
it('reads a URL of each engine, and knows the engine by its scheme', () => {
|
|
256
|
-
expect(parseConnectionUrl('mongodb', 'mongodb://reader:pw@db.example/erp?authSource=admin')).toMatchObject({
|
|
257
|
-
port: '27017',
|
|
258
|
-
database: 'erp',
|
|
259
|
-
options: { authSource: 'admin' },
|
|
260
|
-
})
|
|
261
|
-
expect(() => parseConnectionUrl('mongodb', 'postgres://db.example/erp')).toThrow(/not a MongoDB URL/)
|
|
262
|
-
expect(engineOfScheme('rethinkdb')).toBe('rethinkdb')
|
|
263
|
-
expect(engineOfScheme('postgresql:')).toBe('postgres')
|
|
264
|
-
expect(engineOfScheme('mysql')).toBe('mysql')
|
|
265
|
-
expect(engineOfScheme('mariadb')).toBeUndefined()
|
|
266
|
-
})
|
|
267
|
-
})
|
|
268
|
-
|
|
269
|
-
describe('the tables module of a new connection', () => {
|
|
270
|
-
it('is created under its own folder, its record naming the connection', () => {
|
|
271
|
-
const steps = connectSteps(form(), project(), POSTGRES_DRIVER)
|
|
272
|
-
expect(steps[1]).toEqual({
|
|
273
|
-
op: 'CreateLocalModule',
|
|
274
|
-
id: 'builder-db-erp-tables',
|
|
275
|
-
path: 'modules/builder-db-erp-tables',
|
|
276
|
-
entry: { importOverrides: [{ interface: '@antelopejs/interface-database', source: 'builder-db-erp' }] },
|
|
277
|
-
connection: 'erp',
|
|
278
|
-
})
|
|
279
|
-
})
|
|
280
|
-
})
|
|
281
|
-
|
|
282
|
-
describe('a connection URL', () => {
|
|
283
|
-
it('fills the fields from a pasted URL, decoding its credentials', () => {
|
|
284
|
-
expect(
|
|
285
|
-
parseConnectionUrl('postgres', 'postgresql://re%40der:p%40ss%2Fw@db.example:6432/erp?sslmode=require&application_name=dms'),
|
|
286
|
-
).toEqual({
|
|
287
|
-
host: 'db.example',
|
|
288
|
-
port: '6432',
|
|
289
|
-
database: 'erp',
|
|
290
|
-
user: 're@der',
|
|
291
|
-
password: 'p@ss/w',
|
|
292
|
-
ssl: true,
|
|
293
|
-
options: { application_name: 'dms' },
|
|
294
|
-
})
|
|
295
|
-
})
|
|
296
|
-
|
|
297
|
-
it('takes the default port when the URL has none, and SSL off without sslmode', () => {
|
|
298
|
-
expect(parseConnectionUrl('postgres', 'postgres://u@h/db')).toMatchObject({ port: '5432', ssl: false, password: '' })
|
|
299
|
-
})
|
|
300
|
-
|
|
301
|
-
it('keeps a strict SSL mode as it was pasted', () => {
|
|
302
|
-
const fields = parseConnectionUrl('postgres', 'postgres://u:p@h/db?sslmode=verify-full')
|
|
303
|
-
expect(fields.ssl).toBe(true)
|
|
304
|
-
expect(connectionUrl('postgres', fields)).toBe('postgres://u:p@h:5432/db?sslmode=verify-full')
|
|
305
|
-
})
|
|
306
|
-
|
|
307
|
-
it('refuses a URL of another engine, or no URL at all', () => {
|
|
308
|
-
expect(() => parseConnectionUrl('postgres', 'mysql://u@h/db')).toThrow(/PostgreSQL/)
|
|
309
|
-
expect(() => parseConnectionUrl('postgres', 'db.example')).toThrow()
|
|
310
|
-
})
|
|
311
|
-
|
|
312
|
-
it('writes back what it read, credentials encoded and options kept', () => {
|
|
313
|
-
const pasted = 'postgres://re%40der:p%40ss@db.example:6432/erp?application_name=dms&sslmode=require'
|
|
314
|
-
expect(connectionUrl('postgres', parseConnectionUrl('postgres', pasted))).toBe(pasted)
|
|
315
|
-
})
|
|
316
|
-
|
|
317
|
-
it('keeps an sslmode the SSL switch does not stand for, until the switch is turned on', () => {
|
|
318
|
-
const fields = parseConnectionUrl('postgres', 'postgres://u:p@h/db?sslmode=no-verify')
|
|
319
|
-
expect(fields.ssl).toBe(false)
|
|
320
|
-
expect(connectionUrl('postgres', fields)).toBe('postgres://u:p@h:5432/db?sslmode=no-verify')
|
|
321
|
-
expect(connectionUrl('postgres', { ...fields, ssl: true })).toBe('postgres://u:p@h:5432/db?sslmode=require')
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
it('builds one from the fields, with sslmode when SSL is on', () => {
|
|
325
|
-
expect(connectionUrl('postgres', { ...form().fields, ssl: true })).toBe(
|
|
326
|
-
'postgres://reader:s3cret@db.example:5432/erp?sslmode=require',
|
|
327
|
-
)
|
|
328
|
-
})
|
|
329
|
-
|
|
330
|
-
it('writes the database name as the driver decodes it, and refuses one it cannot', () => {
|
|
331
|
-
const fields = { ...form().fields, database: 'sales$2024' }
|
|
332
|
-
expect(connectionUrl('postgres', fields)).toBe('postgres://reader:s3cret@db.example:5432/sales$2024')
|
|
333
|
-
expect(connectionUrl('postgres', { ...fields, database: 'erp main' })).toBe(
|
|
334
|
-
'postgres://reader:s3cret@db.example:5432/erp%20main',
|
|
335
|
-
)
|
|
336
|
-
expect(parseConnectionUrl('postgres', 'postgres://u@h/sales%242024').database).toBe('sales%242024')
|
|
337
|
-
expect(fieldProblem({ ...fields, database: 'a?b' })).toMatch(/\?/)
|
|
338
|
-
})
|
|
339
|
-
|
|
340
|
-
it('writes a socket directory as one host, and an IPv6 address in brackets', () => {
|
|
341
|
-
expect(connectionUrl('postgres', { ...form().fields, host: '/var/run/postgresql', port: '' })).toBe(
|
|
342
|
-
'postgres://reader:s3cret@%2Fvar%2Frun%2Fpostgresql/erp',
|
|
343
|
-
)
|
|
344
|
-
expect(connectionUrl('postgres', { ...form().fields, host: '::1' })).toBe('postgres://reader:s3cret@[::1]:5432/erp')
|
|
345
|
-
expect(fieldProblem({ ...form().fields, host: 'db.example ' })).toBeUndefined()
|
|
346
|
-
expect(fieldProblem({ ...form().fields, host: 'db.example:5433' })).toMatch(/port/)
|
|
347
|
-
})
|
|
348
|
-
})
|