@celilo/cli 0.1.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 +1566 -0
- package/bin/celilo +16 -0
- package/drizzle/0000_complex_puma.sql +179 -0
- package/drizzle/0001_dizzy_wolfpack.sql +2 -0
- package/drizzle/0002_web_routes.sql +16 -0
- package/drizzle/0003_backup_storage.sql +32 -0
- package/drizzle/meta/0000_snapshot.json +1151 -0
- package/drizzle/meta/0001_snapshot.json +1167 -0
- package/drizzle/meta/0002_snapshot.json +1257 -0
- package/drizzle/meta/_journal.json +27 -0
- package/package.json +64 -0
- package/schemas/system_config.json +106 -0
- package/src/__integration__/container-services-cli.integration.test.ts +246 -0
- package/src/ansible/dependencies.test.ts +309 -0
- package/src/ansible/dependencies.ts +896 -0
- package/src/ansible/inventory.test.ts +463 -0
- package/src/ansible/inventory.ts +445 -0
- package/src/ansible/secrets.ts +222 -0
- package/src/ansible/validation.test.ts +92 -0
- package/src/ansible/validation.ts +272 -0
- package/src/api-clients/digitalocean.ts +94 -0
- package/src/api-clients/proxmox.ts +655 -0
- package/src/capabilities/logging-wrapper.test.ts +217 -0
- package/src/capabilities/lookup.test.ts +149 -0
- package/src/capabilities/lookup.ts +89 -0
- package/src/capabilities/public-web-helpers.test.ts +198 -0
- package/src/capabilities/public-web-publish.test.ts +458 -0
- package/src/capabilities/registration.test.ts +395 -0
- package/src/capabilities/registration.ts +200 -0
- package/src/capabilities/route-validation.test.ts +121 -0
- package/src/capabilities/route-validation.ts +96 -0
- package/src/capabilities/secret-ref.test.ts +313 -0
- package/src/capabilities/secret-validation.ts +157 -0
- package/src/capabilities/secrets.test.ts +750 -0
- package/src/capabilities/secrets.ts +244 -0
- package/src/capabilities/validation.test.ts +613 -0
- package/src/capabilities/validation.ts +160 -0
- package/src/capabilities/well-known.test.ts +238 -0
- package/src/capabilities/well-known.ts +222 -0
- package/src/cli/cli.test.ts +654 -0
- package/src/cli/command-registry.ts +742 -0
- package/src/cli/command-tree-parser.test.ts +180 -0
- package/src/cli/command-tree-parser.ts +193 -0
- package/src/cli/commands/backup-create.ts +137 -0
- package/src/cli/commands/backup-delete.ts +74 -0
- package/src/cli/commands/backup-import.ts +97 -0
- package/src/cli/commands/backup-list.ts +132 -0
- package/src/cli/commands/backup-name.ts +73 -0
- package/src/cli/commands/backup-prune.ts +98 -0
- package/src/cli/commands/backup-restore.ts +122 -0
- package/src/cli/commands/capability-info.ts +121 -0
- package/src/cli/commands/capability-list.ts +47 -0
- package/src/cli/commands/completion.ts +87 -0
- package/src/cli/commands/hook-run.ts +176 -0
- package/src/cli/commands/ipam.ts +607 -0
- package/src/cli/commands/machine-add.ts +235 -0
- package/src/cli/commands/machine-earmark.ts +82 -0
- package/src/cli/commands/machine-list.ts +77 -0
- package/src/cli/commands/machine-remove.ts +90 -0
- package/src/cli/commands/machine-status.ts +131 -0
- package/src/cli/commands/module-audit.ts +51 -0
- package/src/cli/commands/module-build.ts +60 -0
- package/src/cli/commands/module-config.ts +170 -0
- package/src/cli/commands/module-deploy.ts +71 -0
- package/src/cli/commands/module-generate.ts +236 -0
- package/src/cli/commands/module-health.ts +108 -0
- package/src/cli/commands/module-import.ts +80 -0
- package/src/cli/commands/module-list.ts +43 -0
- package/src/cli/commands/module-logs.ts +73 -0
- package/src/cli/commands/module-remove.ts +162 -0
- package/src/cli/commands/module-show.ts +208 -0
- package/src/cli/commands/module-status.ts +131 -0
- package/src/cli/commands/module-types.ts +189 -0
- package/src/cli/commands/module-upgrade.ts +192 -0
- package/src/cli/commands/package.ts +68 -0
- package/src/cli/commands/secret-list.ts +99 -0
- package/src/cli/commands/secret-set.ts +134 -0
- package/src/cli/commands/service-add-digitalocean.ts +133 -0
- package/src/cli/commands/service-add-proxmox.ts +342 -0
- package/src/cli/commands/service-config-get.ts +83 -0
- package/src/cli/commands/service-config-set.ts +145 -0
- package/src/cli/commands/service-list.ts +74 -0
- package/src/cli/commands/service-reconfigure.ts +230 -0
- package/src/cli/commands/service-remove.ts +103 -0
- package/src/cli/commands/service-verify.ts +240 -0
- package/src/cli/commands/status.ts +216 -0
- package/src/cli/commands/storage-add-local.ts +106 -0
- package/src/cli/commands/storage-add-s3.ts +114 -0
- package/src/cli/commands/storage-list.ts +72 -0
- package/src/cli/commands/storage-remove.ts +54 -0
- package/src/cli/commands/storage-set-default.ts +44 -0
- package/src/cli/commands/storage-verify.ts +54 -0
- package/src/cli/commands/system-config.ts +168 -0
- package/src/cli/commands/system-init.ts +314 -0
- package/src/cli/commands/system-secret-get.ts +98 -0
- package/src/cli/commands/system-secret-set.ts +76 -0
- package/src/cli/commands/system-vault-password.ts +34 -0
- package/src/cli/completion.test.ts +37 -0
- package/src/cli/completion.ts +482 -0
- package/src/cli/fuel-gauge.test.ts +208 -0
- package/src/cli/fuel-gauge.ts +405 -0
- package/src/cli/generate-zsh-completion.test.ts +95 -0
- package/src/cli/generate-zsh-completion.ts +497 -0
- package/src/cli/index.ts +1583 -0
- package/src/cli/interactive-config.test.ts +201 -0
- package/src/cli/interactive-config.ts +62 -0
- package/src/cli/parser.test.ts +227 -0
- package/src/cli/parser.ts +244 -0
- package/src/cli/prompts.test.ts +33 -0
- package/src/cli/prompts.ts +121 -0
- package/src/cli/types.ts +38 -0
- package/src/cli/validators.test.ts +235 -0
- package/src/cli/validators.ts +188 -0
- package/src/config/env.ts +41 -0
- package/src/config/paths.test.ts +172 -0
- package/src/config/paths.ts +108 -0
- package/src/db/client.ts +190 -0
- package/src/db/migrate.ts +30 -0
- package/src/db/schema.test.ts +221 -0
- package/src/db/schema.ts +434 -0
- package/src/hooks/capability-loader-firewall.test.ts +246 -0
- package/src/hooks/capability-loader.test.ts +100 -0
- package/src/hooks/capability-loader.ts +520 -0
- package/src/hooks/define-hook.test.ts +488 -0
- package/src/hooks/executor.test.ts +462 -0
- package/src/hooks/executor.ts +469 -0
- package/src/hooks/logger.test.ts +54 -0
- package/src/hooks/logger.ts +95 -0
- package/src/hooks/test-fixtures/failing-hook.ts +13 -0
- package/src/hooks/test-fixtures/no-default-hook.ts +6 -0
- package/src/hooks/test-fixtures/success-hook.ts +20 -0
- package/src/hooks/test-fixtures/unbranded-hook.ts +11 -0
- package/src/hooks/test-fixtures/void-hook.ts +13 -0
- package/src/hooks/types.ts +89 -0
- package/src/infrastructure/property-extractor.test.ts +194 -0
- package/src/infrastructure/property-extractor.ts +151 -0
- package/src/ipam/allocator.test.ts +442 -0
- package/src/ipam/allocator.ts +369 -0
- package/src/ipam/auto-allocator.test.ts +247 -0
- package/src/ipam/auto-allocator.ts +270 -0
- package/src/ipam/subnet-parser.test.ts +107 -0
- package/src/ipam/subnet-parser.ts +136 -0
- package/src/manifest/contracts/index.ts +61 -0
- package/src/manifest/contracts/v1.ts +118 -0
- package/src/manifest/json-schema-roundtrip.test.ts +99 -0
- package/src/manifest/schema.ts +367 -0
- package/src/manifest/template-validator.test.ts +231 -0
- package/src/manifest/template-validator.ts +322 -0
- package/src/manifest/validate.test.ts +1180 -0
- package/src/manifest/validate.ts +415 -0
- package/src/module/import.test.ts +355 -0
- package/src/module/import.ts +676 -0
- package/src/module/packaging/audit.ts +169 -0
- package/src/module/packaging/build.ts +228 -0
- package/src/module/packaging/checksum.ts +41 -0
- package/src/module/packaging/extract.ts +234 -0
- package/src/module/packaging/signature.ts +47 -0
- package/src/secrets/encryption.test.ts +284 -0
- package/src/secrets/encryption.ts +162 -0
- package/src/secrets/generators.test.ts +112 -0
- package/src/secrets/generators.ts +127 -0
- package/src/secrets/master-key.test.ts +159 -0
- package/src/secrets/master-key.ts +114 -0
- package/src/secrets/storage.test.ts +115 -0
- package/src/secrets/storage.ts +106 -0
- package/src/secrets/vault.test.ts +35 -0
- package/src/secrets/vault.ts +42 -0
- package/src/services/backup-create.ts +532 -0
- package/src/services/backup-metadata.ts +198 -0
- package/src/services/backup-restore.ts +229 -0
- package/src/services/backup-retention.ts +84 -0
- package/src/services/backup-storage.ts +281 -0
- package/src/services/build-stream.test.ts +122 -0
- package/src/services/build-stream.ts +201 -0
- package/src/services/config-interview.ts +694 -0
- package/src/services/container-service.test.ts +298 -0
- package/src/services/container-service.ts +401 -0
- package/src/services/cross-module-data-manager.test.ts +405 -0
- package/src/services/cross-module-data-manager.ts +412 -0
- package/src/services/deploy-ansible.ts +88 -0
- package/src/services/deploy-planner.ts +153 -0
- package/src/services/deploy-preflight.ts +274 -0
- package/src/services/deploy-ssh.ts +131 -0
- package/src/services/deploy-terraform.test.ts +55 -0
- package/src/services/deploy-terraform.ts +445 -0
- package/src/services/deploy-validation.ts +311 -0
- package/src/services/dns-auto-register.ts +211 -0
- package/src/services/health-runner.ts +184 -0
- package/src/services/infrastructure-selector.test.ts +485 -0
- package/src/services/infrastructure-selector.ts +245 -0
- package/src/services/infrastructure-variable-resolver.test.ts +751 -0
- package/src/services/infrastructure-variable-resolver.ts +234 -0
- package/src/services/machine-detector.ts +328 -0
- package/src/services/machine-pool.test.ts +405 -0
- package/src/services/machine-pool.ts +316 -0
- package/src/services/manifest-validation.ts +120 -0
- package/src/services/module-build.test.ts +290 -0
- package/src/services/module-build.ts +431 -0
- package/src/services/module-config.test.ts +237 -0
- package/src/services/module-config.ts +298 -0
- package/src/services/module-deploy.ts +862 -0
- package/src/services/module-types-drift.test.ts +73 -0
- package/src/services/module-types-generator.test.ts +288 -0
- package/src/services/module-types-generator.ts +189 -0
- package/src/services/proxmox-state-recovery.ts +140 -0
- package/src/services/schema-validation.ts +155 -0
- package/src/services/secret-schema-loader.test.ts +311 -0
- package/src/services/secret-schema-loader.ts +239 -0
- package/src/services/ssh-key-manager.test.ts +283 -0
- package/src/services/ssh-key-manager.ts +193 -0
- package/src/services/storage-providers/local.ts +105 -0
- package/src/services/storage-providers/s3.ts +182 -0
- package/src/services/storage-providers/types.ts +24 -0
- package/src/services/system-config-schema-types.ts +25 -0
- package/src/services/system-config-validator.test.ts +160 -0
- package/src/services/system-config-validator.ts +74 -0
- package/src/services/system-init.test.ts +153 -0
- package/src/services/system-init.ts +253 -0
- package/src/services/terraform-safety.ts +174 -0
- package/src/services/zone-detector.test.ts +110 -0
- package/src/services/zone-detector.ts +102 -0
- package/src/services/zone-policy.test.ts +97 -0
- package/src/services/zone-policy.ts +126 -0
- package/src/templates/generator.test.ts +645 -0
- package/src/templates/generator.ts +1119 -0
- package/src/templates/types.ts +62 -0
- package/src/test-utils/INTERACTIVE_PROMPTS.md +167 -0
- package/src/test-utils/cli-context-interactive.test.ts +152 -0
- package/src/test-utils/cli-context-server.test.ts +66 -0
- package/src/test-utils/cli-context.test.ts +273 -0
- package/src/test-utils/cli-context.ts +677 -0
- package/src/test-utils/cli-result.test.ts +282 -0
- package/src/test-utils/cli-result.ts +241 -0
- package/src/test-utils/cli.ts +55 -0
- package/src/test-utils/completion-harness.test.ts +126 -0
- package/src/test-utils/completion-harness.ts +82 -0
- package/src/test-utils/database.test.ts +182 -0
- package/src/test-utils/database.ts +126 -0
- package/src/test-utils/filesystem.test.ts +208 -0
- package/src/test-utils/filesystem.ts +142 -0
- package/src/test-utils/fixtures.test.ts +123 -0
- package/src/test-utils/fixtures.ts +160 -0
- package/src/test-utils/golden-diff.ts +197 -0
- package/src/test-utils/index.ts +77 -0
- package/src/test-utils/integration.ts +81 -0
- package/src/test-utils/module-fixtures.ts +468 -0
- package/src/test-utils/modules.test.ts +144 -0
- package/src/test-utils/modules.ts +183 -0
- package/src/test-utils/setup-test-db.ts +90 -0
- package/src/test-utils/value-extractor.test.ts +231 -0
- package/src/test-utils/value-extractor.ts +228 -0
- package/src/types/infrastructure.ts +157 -0
- package/src/utils/shell.test.ts +365 -0
- package/src/utils/shell.ts +159 -0
- package/src/validation/schemas.ts +166 -0
- package/src/variables/ansible-resolver.test.ts +142 -0
- package/src/variables/ansible-resolver.ts +69 -0
- package/src/variables/capability-self-ref.test.ts +220 -0
- package/src/variables/context.test.ts +1265 -0
- package/src/variables/context.ts +624 -0
- package/src/variables/declarative-derivation.test.ts +743 -0
- package/src/variables/declarative-derivation.ts +200 -0
- package/src/variables/parser.test.ts +231 -0
- package/src/variables/parser.ts +76 -0
- package/src/variables/resolver.test.ts +458 -0
- package/src/variables/resolver.ts +282 -0
- package/src/variables/types.ts +59 -0
|
@@ -0,0 +1,743 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import type { ModuleManifest, VariableDeclare } from '../manifest/schema';
|
|
3
|
+
import {
|
|
4
|
+
applyDeclarativeDerivations,
|
|
5
|
+
resolveDeclarativeDerivation,
|
|
6
|
+
} from './declarative-derivation';
|
|
7
|
+
import type { ResolutionContext } from './types';
|
|
8
|
+
|
|
9
|
+
describe('resolveDeclarativeDerivation', () => {
|
|
10
|
+
describe('system config references', () => {
|
|
11
|
+
test('resolves $system:key pattern', () => {
|
|
12
|
+
const variable: VariableDeclare = {
|
|
13
|
+
name: 'primary_domain',
|
|
14
|
+
type: 'string',
|
|
15
|
+
required: false,
|
|
16
|
+
source: 'user',
|
|
17
|
+
derive_from: '$system:primary_domain',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const context: ResolutionContext = {
|
|
21
|
+
moduleId: 'test-module',
|
|
22
|
+
selfConfig: {},
|
|
23
|
+
systemConfig: { primary_domain: 'example.com' },
|
|
24
|
+
systemSecrets: {},
|
|
25
|
+
secrets: {},
|
|
26
|
+
capabilities: {},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const result = resolveDeclarativeDerivation(variable, context);
|
|
30
|
+
expect(result).toBe('example.com');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('resolves nested system config with dots', () => {
|
|
34
|
+
const variable: VariableDeclare = {
|
|
35
|
+
name: 'dmz_subnet',
|
|
36
|
+
type: 'string',
|
|
37
|
+
required: false,
|
|
38
|
+
source: 'user',
|
|
39
|
+
derive_from: '$system:network.dmz.subnet',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const context: ResolutionContext = {
|
|
43
|
+
moduleId: 'test-module',
|
|
44
|
+
selfConfig: {},
|
|
45
|
+
systemConfig: { 'network.dmz.subnet': '10.0.10.0/24' },
|
|
46
|
+
systemSecrets: {},
|
|
47
|
+
secrets: {},
|
|
48
|
+
capabilities: {},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const result = resolveDeclarativeDerivation(variable, context);
|
|
52
|
+
expect(result).toBe('10.0.10.0/24');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('throws on missing system config', () => {
|
|
56
|
+
const variable: VariableDeclare = {
|
|
57
|
+
name: 'primary_domain',
|
|
58
|
+
type: 'string',
|
|
59
|
+
required: false,
|
|
60
|
+
source: 'user',
|
|
61
|
+
derive_from: '$system:primary_domain',
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const context: ResolutionContext = {
|
|
65
|
+
moduleId: 'test-module',
|
|
66
|
+
selfConfig: {},
|
|
67
|
+
systemConfig: {},
|
|
68
|
+
systemSecrets: {},
|
|
69
|
+
secrets: {},
|
|
70
|
+
capabilities: {},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
expect(() => resolveDeclarativeDerivation(variable, context)).toThrow(
|
|
74
|
+
"Missing system config: primary_domain (required by variable 'primary_domain')",
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('variable interpolation', () => {
|
|
80
|
+
test('resolves {variable} pattern', () => {
|
|
81
|
+
const variable: VariableDeclare = {
|
|
82
|
+
name: 'vps_hostname',
|
|
83
|
+
type: 'string',
|
|
84
|
+
required: false,
|
|
85
|
+
source: 'user',
|
|
86
|
+
derive_from: '{hostname}.example.com',
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const context: ResolutionContext = {
|
|
90
|
+
moduleId: 'test-module',
|
|
91
|
+
selfConfig: { hostname: 'dns-ext' },
|
|
92
|
+
systemConfig: {},
|
|
93
|
+
systemSecrets: {},
|
|
94
|
+
secrets: {},
|
|
95
|
+
capabilities: {},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const result = resolveDeclarativeDerivation(variable, context);
|
|
99
|
+
expect(result).toBe('dns-ext.example.com');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('resolves multiple variable interpolations', () => {
|
|
103
|
+
const variable: VariableDeclare = {
|
|
104
|
+
name: 'vps_hostname',
|
|
105
|
+
type: 'string',
|
|
106
|
+
required: false,
|
|
107
|
+
source: 'user',
|
|
108
|
+
derive_from: '{hostname}.{primary_domain}',
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const context: ResolutionContext = {
|
|
112
|
+
moduleId: 'test-module',
|
|
113
|
+
selfConfig: { hostname: 'dns-ext', primary_domain: 'example.com' },
|
|
114
|
+
systemConfig: {},
|
|
115
|
+
systemSecrets: {},
|
|
116
|
+
secrets: {},
|
|
117
|
+
capabilities: {},
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const result = resolveDeclarativeDerivation(variable, context);
|
|
121
|
+
expect(result).toBe('dns-ext.example.com');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('throws on missing variable', () => {
|
|
125
|
+
const variable: VariableDeclare = {
|
|
126
|
+
name: 'vps_hostname',
|
|
127
|
+
type: 'string',
|
|
128
|
+
required: false,
|
|
129
|
+
source: 'user',
|
|
130
|
+
derive_from: '{hostname}.{primary_domain}',
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const context: ResolutionContext = {
|
|
134
|
+
moduleId: 'test-module',
|
|
135
|
+
selfConfig: { hostname: 'dns-ext' }, // missing primary_domain
|
|
136
|
+
systemConfig: {},
|
|
137
|
+
systemSecrets: {},
|
|
138
|
+
secrets: {},
|
|
139
|
+
capabilities: {},
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
expect(() => resolveDeclarativeDerivation(variable, context)).toThrow(
|
|
143
|
+
"Missing variable: primary_domain (required by variable 'vps_hostname')",
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('capability references', () => {
|
|
149
|
+
test('resolves $capability:name.path pattern', () => {
|
|
150
|
+
const variable: VariableDeclare = {
|
|
151
|
+
name: 'dns_server_ip',
|
|
152
|
+
type: 'string',
|
|
153
|
+
required: false,
|
|
154
|
+
source: 'user',
|
|
155
|
+
derive_from: '$capability:dns_external.server.ip',
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const context: ResolutionContext = {
|
|
159
|
+
moduleId: 'test-module',
|
|
160
|
+
selfConfig: {},
|
|
161
|
+
systemConfig: {},
|
|
162
|
+
systemSecrets: {},
|
|
163
|
+
secrets: {},
|
|
164
|
+
capabilities: {
|
|
165
|
+
dns_external: {
|
|
166
|
+
server: {
|
|
167
|
+
ip: '188.166.157.2',
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const result = resolveDeclarativeDerivation(variable, context);
|
|
174
|
+
expect(result).toBe('188.166.157.2');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('resolves nested capability path', () => {
|
|
178
|
+
const variable: VariableDeclare = {
|
|
179
|
+
name: 'dns_primary',
|
|
180
|
+
type: 'string',
|
|
181
|
+
required: false,
|
|
182
|
+
source: 'user',
|
|
183
|
+
derive_from: '$capability:dns_external.server.ip.primary',
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const context: ResolutionContext = {
|
|
187
|
+
moduleId: 'test-module',
|
|
188
|
+
selfConfig: {},
|
|
189
|
+
systemConfig: {},
|
|
190
|
+
systemSecrets: {},
|
|
191
|
+
secrets: {},
|
|
192
|
+
capabilities: {
|
|
193
|
+
dns_external: {
|
|
194
|
+
server: {
|
|
195
|
+
ip: {
|
|
196
|
+
primary: '188.166.157.2',
|
|
197
|
+
secondary: '188.166.157.3',
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const result = resolveDeclarativeDerivation(variable, context);
|
|
205
|
+
expect(result).toBe('188.166.157.2');
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('throws on missing capability', () => {
|
|
209
|
+
const variable: VariableDeclare = {
|
|
210
|
+
name: 'dns_server_ip',
|
|
211
|
+
type: 'string',
|
|
212
|
+
required: false,
|
|
213
|
+
source: 'user',
|
|
214
|
+
derive_from: '$capability:dns_external.server.ip',
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const context: ResolutionContext = {
|
|
218
|
+
moduleId: 'test-module',
|
|
219
|
+
selfConfig: {},
|
|
220
|
+
systemConfig: {},
|
|
221
|
+
systemSecrets: {},
|
|
222
|
+
secrets: {},
|
|
223
|
+
capabilities: {},
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
expect(() => resolveDeclarativeDerivation(variable, context)).toThrow(
|
|
227
|
+
"Missing capability: dns_external (required by variable 'dns_server_ip')",
|
|
228
|
+
);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test('throws on missing capability field', () => {
|
|
232
|
+
const variable: VariableDeclare = {
|
|
233
|
+
name: 'dns_server_ip',
|
|
234
|
+
type: 'string',
|
|
235
|
+
required: false,
|
|
236
|
+
source: 'user',
|
|
237
|
+
derive_from: '$capability:dns_external.server.ip',
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const context: ResolutionContext = {
|
|
241
|
+
moduleId: 'test-module',
|
|
242
|
+
selfConfig: {},
|
|
243
|
+
systemConfig: {},
|
|
244
|
+
systemSecrets: {},
|
|
245
|
+
secrets: {},
|
|
246
|
+
capabilities: {
|
|
247
|
+
dns_external: {
|
|
248
|
+
server: {}, // missing ip field
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
expect(() => resolveDeclarativeDerivation(variable, context)).toThrow(
|
|
254
|
+
"Missing capability field: dns_external.server.ip (required by variable 'dns_server_ip')",
|
|
255
|
+
);
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
describe('nested variable resolution', () => {
|
|
260
|
+
test('resolves $system: references within capability values', () => {
|
|
261
|
+
const variable: VariableDeclare = {
|
|
262
|
+
name: 'auth_url',
|
|
263
|
+
type: 'string',
|
|
264
|
+
required: false,
|
|
265
|
+
source: 'capability',
|
|
266
|
+
derive_from: '$capability:idp.auth_url',
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const context: ResolutionContext = {
|
|
270
|
+
moduleId: 'test-module',
|
|
271
|
+
selfConfig: {},
|
|
272
|
+
systemConfig: { primary_domain: 'example.com' },
|
|
273
|
+
systemSecrets: {},
|
|
274
|
+
secrets: {},
|
|
275
|
+
capabilities: {
|
|
276
|
+
idp: {
|
|
277
|
+
auth_url: 'https://auth.${system:primary_domain}',
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const result = resolveDeclarativeDerivation(variable, context);
|
|
283
|
+
expect(result).toBe('https://auth.example.com');
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test('resolves $system: references (unbraced) within capability values', () => {
|
|
287
|
+
const variable: VariableDeclare = {
|
|
288
|
+
name: 'api_url',
|
|
289
|
+
type: 'string',
|
|
290
|
+
required: false,
|
|
291
|
+
source: 'capability',
|
|
292
|
+
derive_from: '$capability:idp.api_url',
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const context: ResolutionContext = {
|
|
296
|
+
moduleId: 'test-module',
|
|
297
|
+
selfConfig: {},
|
|
298
|
+
systemConfig: { primary_domain: 'example.com' },
|
|
299
|
+
systemSecrets: {},
|
|
300
|
+
secrets: {},
|
|
301
|
+
capabilities: {
|
|
302
|
+
idp: {
|
|
303
|
+
api_url: 'https://auth.$system:primary_domain/api',
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
const result = resolveDeclarativeDerivation(variable, context);
|
|
309
|
+
expect(result).toBe('https://auth.example.com/api');
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
describe('mixed patterns', () => {
|
|
314
|
+
test('combines system config and variable interpolation', () => {
|
|
315
|
+
const variable: VariableDeclare = {
|
|
316
|
+
name: 'full_url',
|
|
317
|
+
type: 'string',
|
|
318
|
+
required: false,
|
|
319
|
+
source: 'user',
|
|
320
|
+
derive_from: 'https://{hostname}.$system:primary_domain',
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const context: ResolutionContext = {
|
|
324
|
+
moduleId: 'test-module',
|
|
325
|
+
selfConfig: { hostname: 'www' },
|
|
326
|
+
systemConfig: { primary_domain: 'example.com' },
|
|
327
|
+
systemSecrets: {},
|
|
328
|
+
secrets: {},
|
|
329
|
+
capabilities: {},
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
const result = resolveDeclarativeDerivation(variable, context);
|
|
333
|
+
expect(result).toBe('https://www.example.com');
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test('combines all three pattern types', () => {
|
|
337
|
+
const variable: VariableDeclare = {
|
|
338
|
+
name: 'acme_dns',
|
|
339
|
+
type: 'string',
|
|
340
|
+
required: false,
|
|
341
|
+
source: 'user',
|
|
342
|
+
derive_from: '{hostname}.$system:primary_domain@$capability:dns_external.server.ip',
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const context: ResolutionContext = {
|
|
346
|
+
moduleId: 'test-module',
|
|
347
|
+
selfConfig: { hostname: 'caddy' },
|
|
348
|
+
systemConfig: { primary_domain: 'example.com' },
|
|
349
|
+
systemSecrets: {},
|
|
350
|
+
secrets: {},
|
|
351
|
+
capabilities: {
|
|
352
|
+
dns_external: {
|
|
353
|
+
server: { ip: '188.166.157.2' },
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
const result = resolveDeclarativeDerivation(variable, context);
|
|
359
|
+
expect(result).toBe('caddy.example.com@188.166.157.2');
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
describe('no derivation', () => {
|
|
364
|
+
test('returns undefined when derive_from is not set', () => {
|
|
365
|
+
const variable: VariableDeclare = {
|
|
366
|
+
name: 'hostname',
|
|
367
|
+
type: 'string',
|
|
368
|
+
required: false,
|
|
369
|
+
source: 'user',
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
const context: ResolutionContext = {
|
|
373
|
+
moduleId: 'test-module',
|
|
374
|
+
selfConfig: {},
|
|
375
|
+
systemConfig: {},
|
|
376
|
+
systemSecrets: {},
|
|
377
|
+
secrets: {},
|
|
378
|
+
capabilities: {},
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
const result = resolveDeclarativeDerivation(variable, context);
|
|
382
|
+
expect(result).toBeUndefined();
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
describe('applyDeclarativeDerivations', () => {
|
|
388
|
+
describe('basic derivations', () => {
|
|
389
|
+
test('applies single derivation', () => {
|
|
390
|
+
const manifest: ModuleManifest = {
|
|
391
|
+
celilo_contract: '1.0',
|
|
392
|
+
id: 'test-module',
|
|
393
|
+
name: 'Test Module',
|
|
394
|
+
version: '1.0.0',
|
|
395
|
+
requires: { capabilities: [] },
|
|
396
|
+
provides: { capabilities: [] },
|
|
397
|
+
variables: {
|
|
398
|
+
owns: [
|
|
399
|
+
{
|
|
400
|
+
name: 'primary_domain',
|
|
401
|
+
type: 'string',
|
|
402
|
+
required: false,
|
|
403
|
+
source: 'user',
|
|
404
|
+
derive_from: '$system:primary_domain',
|
|
405
|
+
},
|
|
406
|
+
],
|
|
407
|
+
imports: [],
|
|
408
|
+
},
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const context: ResolutionContext = {
|
|
412
|
+
moduleId: 'test-module',
|
|
413
|
+
selfConfig: {},
|
|
414
|
+
systemConfig: { primary_domain: 'example.com' },
|
|
415
|
+
systemSecrets: {},
|
|
416
|
+
secrets: {},
|
|
417
|
+
capabilities: {},
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
applyDeclarativeDerivations(manifest, context);
|
|
421
|
+
|
|
422
|
+
expect(context.selfConfig.primary_domain).toBe('example.com');
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
test('applies multiple derivations in order', () => {
|
|
426
|
+
const manifest: ModuleManifest = {
|
|
427
|
+
celilo_contract: '1.0',
|
|
428
|
+
id: 'test-module',
|
|
429
|
+
name: 'Test Module',
|
|
430
|
+
version: '1.0.0',
|
|
431
|
+
requires: { capabilities: [] },
|
|
432
|
+
provides: { capabilities: [] },
|
|
433
|
+
variables: {
|
|
434
|
+
owns: [
|
|
435
|
+
{
|
|
436
|
+
name: 'primary_domain',
|
|
437
|
+
type: 'string',
|
|
438
|
+
required: false,
|
|
439
|
+
source: 'user',
|
|
440
|
+
derive_from: '$system:primary_domain',
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
name: 'vps_hostname',
|
|
444
|
+
type: 'string',
|
|
445
|
+
required: false,
|
|
446
|
+
source: 'user',
|
|
447
|
+
derive_from: '{hostname}.{primary_domain}',
|
|
448
|
+
},
|
|
449
|
+
],
|
|
450
|
+
imports: [],
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
const context: ResolutionContext = {
|
|
455
|
+
moduleId: 'test-module',
|
|
456
|
+
selfConfig: { hostname: 'dns-ext' },
|
|
457
|
+
systemConfig: { primary_domain: 'example.com' },
|
|
458
|
+
systemSecrets: {},
|
|
459
|
+
secrets: {},
|
|
460
|
+
capabilities: {},
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
applyDeclarativeDerivations(manifest, context);
|
|
464
|
+
|
|
465
|
+
expect(context.selfConfig.primary_domain).toBe('example.com');
|
|
466
|
+
expect(context.selfConfig.vps_hostname).toBe('dns-ext.example.com');
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
describe('user config precedence', () => {
|
|
471
|
+
test('does not overwrite user-provided values', () => {
|
|
472
|
+
const manifest: ModuleManifest = {
|
|
473
|
+
celilo_contract: '1.0',
|
|
474
|
+
id: 'test-module',
|
|
475
|
+
name: 'Test Module',
|
|
476
|
+
version: '1.0.0',
|
|
477
|
+
requires: { capabilities: [] },
|
|
478
|
+
provides: { capabilities: [] },
|
|
479
|
+
variables: {
|
|
480
|
+
owns: [
|
|
481
|
+
{
|
|
482
|
+
name: 'primary_domain',
|
|
483
|
+
type: 'string',
|
|
484
|
+
required: false,
|
|
485
|
+
source: 'user',
|
|
486
|
+
derive_from: '$system:primary_domain',
|
|
487
|
+
},
|
|
488
|
+
],
|
|
489
|
+
imports: [],
|
|
490
|
+
},
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
const context: ResolutionContext = {
|
|
494
|
+
moduleId: 'test-module',
|
|
495
|
+
selfConfig: { primary_domain: 'custom.com' }, // User provided
|
|
496
|
+
systemConfig: { primary_domain: 'example.com' },
|
|
497
|
+
systemSecrets: {},
|
|
498
|
+
secrets: {},
|
|
499
|
+
capabilities: {},
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
applyDeclarativeDerivations(manifest, context);
|
|
503
|
+
|
|
504
|
+
// Should keep user value
|
|
505
|
+
expect(context.selfConfig.primary_domain).toBe('custom.com');
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
describe('dependency resolution', () => {
|
|
510
|
+
test('resolves dependencies in declaration order', () => {
|
|
511
|
+
const manifest: ModuleManifest = {
|
|
512
|
+
celilo_contract: '1.0',
|
|
513
|
+
id: 'test-module',
|
|
514
|
+
name: 'Test Module',
|
|
515
|
+
version: '1.0.0',
|
|
516
|
+
requires: { capabilities: [] },
|
|
517
|
+
provides: { capabilities: [] },
|
|
518
|
+
variables: {
|
|
519
|
+
owns: [
|
|
520
|
+
// First: derive primary_domain from system
|
|
521
|
+
{
|
|
522
|
+
name: 'primary_domain',
|
|
523
|
+
type: 'string',
|
|
524
|
+
required: false,
|
|
525
|
+
source: 'user',
|
|
526
|
+
derive_from: '$system:primary_domain',
|
|
527
|
+
},
|
|
528
|
+
// Second: derive vps_hostname using primary_domain
|
|
529
|
+
{
|
|
530
|
+
name: 'vps_hostname',
|
|
531
|
+
type: 'string',
|
|
532
|
+
required: false,
|
|
533
|
+
source: 'user',
|
|
534
|
+
derive_from: '{hostname}.{primary_domain}',
|
|
535
|
+
},
|
|
536
|
+
// Third: derive full_url using vps_hostname
|
|
537
|
+
{
|
|
538
|
+
name: 'full_url',
|
|
539
|
+
type: 'string',
|
|
540
|
+
required: false,
|
|
541
|
+
source: 'user',
|
|
542
|
+
derive_from: 'https://{vps_hostname}',
|
|
543
|
+
},
|
|
544
|
+
],
|
|
545
|
+
imports: [],
|
|
546
|
+
},
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
const context: ResolutionContext = {
|
|
550
|
+
moduleId: 'test-module',
|
|
551
|
+
selfConfig: { hostname: 'dns-ext' },
|
|
552
|
+
systemConfig: { primary_domain: 'example.com' },
|
|
553
|
+
systemSecrets: {},
|
|
554
|
+
secrets: {},
|
|
555
|
+
capabilities: {},
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
applyDeclarativeDerivations(manifest, context);
|
|
559
|
+
|
|
560
|
+
expect(context.selfConfig.primary_domain).toBe('example.com');
|
|
561
|
+
expect(context.selfConfig.vps_hostname).toBe('dns-ext.example.com');
|
|
562
|
+
expect(context.selfConfig.full_url).toBe('https://dns-ext.example.com');
|
|
563
|
+
});
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
describe('error handling', () => {
|
|
567
|
+
test('throws error for required variable with missing dependency', () => {
|
|
568
|
+
const manifest: ModuleManifest = {
|
|
569
|
+
celilo_contract: '1.0',
|
|
570
|
+
id: 'test-module',
|
|
571
|
+
name: 'Test Module',
|
|
572
|
+
version: '1.0.0',
|
|
573
|
+
requires: { capabilities: [] },
|
|
574
|
+
provides: { capabilities: [] },
|
|
575
|
+
variables: {
|
|
576
|
+
owns: [
|
|
577
|
+
{
|
|
578
|
+
name: 'primary_domain',
|
|
579
|
+
type: 'string',
|
|
580
|
+
required: true, // Required!
|
|
581
|
+
source: 'user',
|
|
582
|
+
derive_from: '$system:primary_domain',
|
|
583
|
+
},
|
|
584
|
+
],
|
|
585
|
+
imports: [],
|
|
586
|
+
},
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
const context: ResolutionContext = {
|
|
590
|
+
moduleId: 'test-module',
|
|
591
|
+
selfConfig: {},
|
|
592
|
+
systemConfig: {}, // Missing primary_domain
|
|
593
|
+
systemSecrets: {},
|
|
594
|
+
secrets: {},
|
|
595
|
+
capabilities: {},
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
expect(() => applyDeclarativeDerivations(manifest, context)).toThrow(
|
|
599
|
+
"Missing system config: primary_domain (required by variable 'primary_domain')",
|
|
600
|
+
);
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
test('silently skips optional variable with missing dependency', () => {
|
|
604
|
+
const manifest: ModuleManifest = {
|
|
605
|
+
celilo_contract: '1.0',
|
|
606
|
+
id: 'test-module',
|
|
607
|
+
name: 'Test Module',
|
|
608
|
+
version: '1.0.0',
|
|
609
|
+
requires: { capabilities: [] },
|
|
610
|
+
provides: { capabilities: [] },
|
|
611
|
+
variables: {
|
|
612
|
+
owns: [
|
|
613
|
+
{
|
|
614
|
+
name: 'primary_domain',
|
|
615
|
+
type: 'string',
|
|
616
|
+
required: false, // Optional
|
|
617
|
+
source: 'user',
|
|
618
|
+
derive_from: '$system:primary_domain',
|
|
619
|
+
},
|
|
620
|
+
],
|
|
621
|
+
imports: [],
|
|
622
|
+
},
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
const context: ResolutionContext = {
|
|
626
|
+
moduleId: 'test-module',
|
|
627
|
+
selfConfig: {},
|
|
628
|
+
systemConfig: {}, // Missing primary_domain
|
|
629
|
+
systemSecrets: {},
|
|
630
|
+
secrets: {},
|
|
631
|
+
capabilities: {},
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
// Should not throw
|
|
635
|
+
applyDeclarativeDerivations(manifest, context);
|
|
636
|
+
|
|
637
|
+
// Variable remains unset
|
|
638
|
+
expect(context.selfConfig.primary_domain).toBeUndefined();
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
test('skips non-string types (handled by config interview instead)', () => {
|
|
642
|
+
const manifest: ModuleManifest = {
|
|
643
|
+
celilo_contract: '1.0',
|
|
644
|
+
id: 'test-module',
|
|
645
|
+
name: 'Test Module',
|
|
646
|
+
version: '1.0.0',
|
|
647
|
+
requires: { capabilities: [] },
|
|
648
|
+
provides: { capabilities: [] },
|
|
649
|
+
variables: {
|
|
650
|
+
owns: [
|
|
651
|
+
{
|
|
652
|
+
name: 'port',
|
|
653
|
+
type: 'number',
|
|
654
|
+
required: false,
|
|
655
|
+
source: 'user',
|
|
656
|
+
derive_from: '$system:port',
|
|
657
|
+
},
|
|
658
|
+
],
|
|
659
|
+
imports: [],
|
|
660
|
+
},
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
const context: ResolutionContext = {
|
|
664
|
+
moduleId: 'test-module',
|
|
665
|
+
selfConfig: {},
|
|
666
|
+
systemConfig: { port: '8080' },
|
|
667
|
+
systemSecrets: {},
|
|
668
|
+
secrets: {},
|
|
669
|
+
capabilities: {},
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
applyDeclarativeDerivations(manifest, context);
|
|
673
|
+
|
|
674
|
+
// Non-string variable is skipped — port remains unset
|
|
675
|
+
expect(context.selfConfig.port).toBeUndefined();
|
|
676
|
+
});
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
describe('skips', () => {
|
|
680
|
+
test('skips variables without derive_from', () => {
|
|
681
|
+
const manifest: ModuleManifest = {
|
|
682
|
+
celilo_contract: '1.0',
|
|
683
|
+
id: 'test-module',
|
|
684
|
+
name: 'Test Module',
|
|
685
|
+
version: '1.0.0',
|
|
686
|
+
requires: { capabilities: [] },
|
|
687
|
+
provides: { capabilities: [] },
|
|
688
|
+
variables: {
|
|
689
|
+
owns: [
|
|
690
|
+
{
|
|
691
|
+
name: 'hostname',
|
|
692
|
+
type: 'string',
|
|
693
|
+
required: true,
|
|
694
|
+
source: 'user',
|
|
695
|
+
// No derive_from
|
|
696
|
+
},
|
|
697
|
+
],
|
|
698
|
+
imports: [],
|
|
699
|
+
},
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
const context: ResolutionContext = {
|
|
703
|
+
moduleId: 'test-module',
|
|
704
|
+
selfConfig: {},
|
|
705
|
+
systemConfig: {},
|
|
706
|
+
systemSecrets: {},
|
|
707
|
+
secrets: {},
|
|
708
|
+
capabilities: {},
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
// Should not throw or modify context
|
|
712
|
+
applyDeclarativeDerivations(manifest, context);
|
|
713
|
+
|
|
714
|
+
expect(context.selfConfig.hostname).toBeUndefined();
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
test('handles manifest with no variables', () => {
|
|
718
|
+
const manifest: ModuleManifest = {
|
|
719
|
+
celilo_contract: '1.0',
|
|
720
|
+
id: 'test-module',
|
|
721
|
+
name: 'Test Module',
|
|
722
|
+
version: '1.0.0',
|
|
723
|
+
requires: { capabilities: [] },
|
|
724
|
+
provides: { capabilities: [] },
|
|
725
|
+
variables: { owns: [], imports: [] },
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
const context: ResolutionContext = {
|
|
729
|
+
moduleId: 'test-module',
|
|
730
|
+
selfConfig: {},
|
|
731
|
+
systemConfig: {},
|
|
732
|
+
systemSecrets: {},
|
|
733
|
+
secrets: {},
|
|
734
|
+
capabilities: {},
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
// Should not throw
|
|
738
|
+
applyDeclarativeDerivations(manifest, context);
|
|
739
|
+
|
|
740
|
+
expect(context.selfConfig).toEqual({});
|
|
741
|
+
});
|
|
742
|
+
});
|
|
743
|
+
});
|