@celilo/cli 0.11.0-alpha.0 → 0.12.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/AGENTS.md +7 -4
- package/CELILO_CORE_MODULES.md +7 -6
- package/CELILO_SUBSYSTEMS.md +47 -5
- package/MODULE_PRIMITIVES.md +164 -0
- package/README.md +5 -5
- package/drizzle/0015_port_forwards.sql +12 -0
- package/drizzle/meta/_journal.json +7 -0
- package/package.json +8 -8
- package/schemas/system_config.json +1 -1
- package/src/ansible/inventory.test.ts +1 -1
- package/src/ansible/inventory.ts +3 -3
- package/src/capabilities/public-web-publish.test.ts +209 -0
- package/src/capabilities/validation.test.ts +1 -1
- package/src/capabilities/well-known.test.ts +1 -1
- package/src/capabilities/well-known.ts +2 -2
- package/src/cli/commands/api.ts +1 -1
- package/src/cli/commands/backup-pull.ts +1 -1
- package/src/cli/commands/events.ts +1 -1
- package/src/cli/commands/module-changeset.ts +1 -1
- package/src/cli/commands/module-import.ts +1 -1
- package/src/cli/commands/module-publish.ts +1 -1
- package/src/cli/commands/module-remove.ts +26 -1
- package/src/cli/commands/module-types.ts +1 -1
- package/src/cli/commands/module-upgrade.ts +1 -1
- package/src/cli/commands/module-version.ts +1 -1
- package/src/cli/commands/module-where.test.ts +26 -0
- package/src/cli/commands/module-where.ts +130 -0
- package/src/cli/commands/proxmox-node-list.ts +1 -1
- package/src/cli/commands/publish/alpha.test.ts +1 -1
- package/src/cli/commands/publish/alpha.ts +3 -3
- package/src/cli/commands/publish/changesets.ts +1 -1
- package/src/cli/commands/publish/global-install.ts +6 -2
- package/src/cli/commands/publish/helpers.ts +21 -14
- package/src/cli/commands/publish/index.ts +4 -4
- package/src/cli/commands/publish/plan.ts +3 -3
- package/src/cli/commands/publish/preflight.ts +2 -2
- package/src/cli/commands/publish/types.ts +2 -2
- package/src/cli/commands/publish/workspace.test.ts +1 -1
- package/src/cli/commands/publish/workspace.ts +2 -2
- package/src/cli/commands/registry-owner.test.ts +166 -0
- package/src/cli/commands/registry-owner.ts +124 -0
- package/src/cli/commands/registry-token.test.ts +109 -0
- package/src/cli/commands/registry-token.ts +194 -0
- package/src/cli/commands/restore.ts +1 -1
- package/src/cli/commands/service-add-proxmox.ts +1 -1
- package/src/cli/commands/subscribers-list.ts +1 -1
- package/src/cli/commands/system-apply-config-equivalence.test.ts +1 -1
- package/src/cli/commands/system-apply-config.ts +1 -1
- package/src/cli/commands/system-init-deprecation.test.ts +1 -1
- package/src/cli/commands/system-init.ts +2 -2
- package/src/cli/commands/token.test.ts +26 -0
- package/src/cli/commands/token.ts +160 -0
- package/src/cli/completion.ts +19 -0
- package/src/cli/index.ts +155 -4
- package/src/cli/restore-command.test.ts +1 -1
- package/src/db/client.ts +1 -1
- package/src/db/schema.ts +50 -7
- package/src/hooks/capability-loader-firewall.test.ts +4 -3
- package/src/hooks/capability-loader.ts +100 -10
- package/src/hooks/define-hook.test.ts +24 -0
- package/src/hooks/executor.test.ts +1 -1
- package/src/hooks/executor.ts +2 -2
- package/src/hooks/types.ts +1 -1
- package/src/manifest/contracts/v1.ts +2 -2
- package/src/manifest/schema.ts +13 -13
- package/src/manifest/template-validator.ts +1 -1
- package/src/module/packaging/build.ts +19 -0
- package/src/module/packaging/workspace-deps.test.ts +94 -0
- package/src/module/packaging/workspace-deps.ts +185 -0
- package/src/module/versioning/changeset-version.ts +1 -1
- package/src/policy/no-hand-built-ssh.test.ts +90 -0
- package/src/registry/client.test.ts +86 -0
- package/src/registry/client.ts +67 -1
- package/src/services/api-access.ts +1 -1
- package/src/services/aspect-approvals.ts +1 -1
- package/src/services/aspect-runner.ts +3 -3
- package/src/services/aspect-template-resolver.test.ts +1 -1
- package/src/services/aspect-template-resolver.ts +1 -1
- package/src/services/build-bus/delivery-events.ts +1 -1
- package/src/services/build-bus/fan-out.ts +1 -1
- package/src/services/build-bus/hook-dispatch.ts +1 -1
- package/src/services/build-bus/receiver-server.ts +1 -1
- package/src/services/build-bus/status.test.ts +1 -1
- package/src/services/build-bus/status.ts +1 -1
- package/src/services/build-bus/subscriber-store.ts +1 -1
- package/src/services/bus-interview.ts +1 -1
- package/src/services/celilo-events.ts +1 -1
- package/src/services/celilo-mgmt-hooks.test.ts +1 -1
- package/src/services/cross-module-read.ts +1 -1
- package/src/services/deploy-posture.ts +1 -1
- package/src/services/deployed-systems.test.ts +1 -1
- package/src/services/deployed-systems.ts +4 -4
- package/src/services/dns-provider-backfill.ts +2 -2
- package/src/services/events-daemon.ts +1 -1
- package/src/services/machine-pool.ts +3 -3
- package/src/services/module-deploy.ts +93 -8
- package/src/services/module-subscriptions.ts +1 -1
- package/src/services/module-types-generator.ts +1 -1
- package/src/services/module-validator/git-hygiene.ts +1 -1
- package/src/services/port-forwards.test.ts +92 -0
- package/src/services/port-forwards.ts +86 -0
- package/src/services/proxmox-reconcile.ts +2 -2
- package/src/services/public-web-republish.test.ts +189 -0
- package/src/services/public-web-republish.ts +84 -0
- package/src/services/restore-from-file.ts +1 -1
- package/src/services/restore-preflight.ts +1 -1
- package/src/services/system-identity.ts +1 -1
- package/src/services/system-init.test.ts +2 -2
- package/src/services/system-init.ts +2 -2
- package/src/services/web-route-cleanup.test.ts +250 -0
- package/src/services/web-route-cleanup.ts +144 -0
- package/src/templates/generator.ts +2 -2
- package/src/types/infrastructure.ts +1 -1
- package/src/variables/computed/computed-integration.test.ts +1 -1
- package/src/variables/computed/evaluate.ts +1 -1
- package/src/variables/computed/parse.ts +1 -1
- package/src/variables/context.test.ts +1 -1
- package/src/variables/context.ts +5 -5
- package/src/variables/lxc-nameserver.test.ts +1 -1
- package/src/variables/resolver.ts +2 -2
- package/src/variables/types.ts +1 -1
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
2
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import type { RunResult, Runner } from '@celilo/capabilities';
|
|
6
|
+
import { eq } from 'drizzle-orm';
|
|
7
|
+
import type { DbClient } from '../db/client';
|
|
8
|
+
import { capabilities, moduleConfigs, modules, webRoutes } from '../db/schema';
|
|
9
|
+
import { setupTestDatabase } from '../test-utils/setup-test-db';
|
|
10
|
+
import type { RouteReconcileWaitResult } from './celilo-events';
|
|
11
|
+
import { cleanupWebRoutesForModule } from './web-route-cleanup';
|
|
12
|
+
|
|
13
|
+
const CADDY_IP = '10.0.10.10';
|
|
14
|
+
|
|
15
|
+
const CLEAN_RECONCILE: RouteReconcileWaitResult = {
|
|
16
|
+
events: 1,
|
|
17
|
+
succeeded: 1,
|
|
18
|
+
failed: 0,
|
|
19
|
+
timedOut: false,
|
|
20
|
+
noDispatcher: false,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function createRecordingRunner(result: Partial<RunResult> = {}): Runner & { calls: string[] } {
|
|
24
|
+
const calls: string[] = [];
|
|
25
|
+
const runner = ((cmd: string) => {
|
|
26
|
+
calls.push(cmd);
|
|
27
|
+
return { ok: true, stdout: '', stderr: '', ...result } as RunResult;
|
|
28
|
+
}) as Runner & { calls: string[] };
|
|
29
|
+
runner.calls = calls;
|
|
30
|
+
return runner;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('cleanupWebRoutesForModule', () => {
|
|
34
|
+
let dir: string;
|
|
35
|
+
let db: DbClient;
|
|
36
|
+
|
|
37
|
+
async function seedModule(id: string): Promise<void> {
|
|
38
|
+
db.insert(modules)
|
|
39
|
+
.values({
|
|
40
|
+
id,
|
|
41
|
+
name: id,
|
|
42
|
+
version: '1.0.0',
|
|
43
|
+
manifestData: {},
|
|
44
|
+
sourcePath: `/tmp/${id}`,
|
|
45
|
+
})
|
|
46
|
+
.run();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function seedCaddyProvider(): Promise<void> {
|
|
50
|
+
await seedModule('caddy');
|
|
51
|
+
db.insert(capabilities)
|
|
52
|
+
.values({ moduleId: 'caddy', capabilityName: 'public_web', version: '3.0.0', data: {} })
|
|
53
|
+
.run();
|
|
54
|
+
db.insert(moduleConfigs)
|
|
55
|
+
.values({
|
|
56
|
+
moduleId: 'caddy',
|
|
57
|
+
key: 'target_ip',
|
|
58
|
+
value: `${CADDY_IP}/24`,
|
|
59
|
+
valueJson: JSON.stringify(`${CADDY_IP}/24`),
|
|
60
|
+
})
|
|
61
|
+
.run();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function seedRoute(
|
|
65
|
+
moduleId: string,
|
|
66
|
+
slug: string,
|
|
67
|
+
path: string,
|
|
68
|
+
type: 'static' | 'reverse_proxy',
|
|
69
|
+
) {
|
|
70
|
+
db.insert(webRoutes)
|
|
71
|
+
.values({
|
|
72
|
+
slug,
|
|
73
|
+
moduleId,
|
|
74
|
+
type,
|
|
75
|
+
path,
|
|
76
|
+
hostname: 'iamtheinternet.org',
|
|
77
|
+
targetHost: type === 'reverse_proxy' ? '10.0.20.5' : null,
|
|
78
|
+
targetPort: type === 'reverse_proxy' ? 8080 : null,
|
|
79
|
+
})
|
|
80
|
+
.run();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
beforeEach(async () => {
|
|
84
|
+
dir = mkdtempSync(join(tmpdir(), 'wrc-'));
|
|
85
|
+
const dbPath = join(dir, 'celilo.db');
|
|
86
|
+
process.env.CELILO_DB_PATH = dbPath;
|
|
87
|
+
db = await setupTestDatabase(dbPath);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
afterEach(() => {
|
|
91
|
+
db.$client.close();
|
|
92
|
+
process.env.CELILO_DB_PATH = undefined;
|
|
93
|
+
try {
|
|
94
|
+
rmSync(dir, { recursive: true, force: true });
|
|
95
|
+
} catch {
|
|
96
|
+
/* ignore */
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('deletes routes, reclaims the asset root, and emits the reconcile', async () => {
|
|
101
|
+
await seedCaddyProvider();
|
|
102
|
+
await seedModule('hello-foo');
|
|
103
|
+
seedRoute('hello-foo', 'foo', '/foo', 'static');
|
|
104
|
+
|
|
105
|
+
const run = createRecordingRunner();
|
|
106
|
+
let emittedFor: string | undefined;
|
|
107
|
+
|
|
108
|
+
const result = await cleanupWebRoutesForModule({
|
|
109
|
+
moduleId: 'hello-foo',
|
|
110
|
+
db,
|
|
111
|
+
run,
|
|
112
|
+
emitAndWait: async (triggeredBy) => {
|
|
113
|
+
emittedFor = triggeredBy;
|
|
114
|
+
return CLEAN_RECONCILE;
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
expect(result.routesRemoved).toBe(1);
|
|
119
|
+
expect(result.assetDirsRemoved).toEqual(['/srv/www/foo']);
|
|
120
|
+
expect(result.warnings).toEqual([]);
|
|
121
|
+
expect(emittedFor).toBe('hello-foo');
|
|
122
|
+
|
|
123
|
+
expect(run.calls).toHaveLength(1);
|
|
124
|
+
expect(run.calls[0]).toContain(`root@${CADDY_IP}`);
|
|
125
|
+
expect(run.calls[0]).toContain('rm -rf');
|
|
126
|
+
expect(run.calls[0]).toContain('/srv/www/foo');
|
|
127
|
+
|
|
128
|
+
const remaining = db.select().from(webRoutes).where(eq(webRoutes.moduleId, 'hello-foo')).all();
|
|
129
|
+
expect(remaining).toHaveLength(0);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('leaves other modules routes alone', async () => {
|
|
133
|
+
await seedCaddyProvider();
|
|
134
|
+
await seedModule('hello-foo');
|
|
135
|
+
await seedModule('hello-bar');
|
|
136
|
+
seedRoute('hello-foo', 'foo', '/foo', 'static');
|
|
137
|
+
seedRoute('hello-bar', 'bar', '/bar', 'static');
|
|
138
|
+
|
|
139
|
+
const run = createRecordingRunner();
|
|
140
|
+
await cleanupWebRoutesForModule({
|
|
141
|
+
moduleId: 'hello-foo',
|
|
142
|
+
db,
|
|
143
|
+
run,
|
|
144
|
+
emitAndWait: async () => CLEAN_RECONCILE,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const survivors = db.select().from(webRoutes).all();
|
|
148
|
+
expect(survivors.map((r) => r.moduleId)).toEqual(['hello-bar']);
|
|
149
|
+
// Only /srv/www/foo is touched — the sibling's asset root must survive.
|
|
150
|
+
expect(run.calls.join('\n')).not.toContain('/srv/www/bar');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('no-ops when the module owns no routes (its on_uninstall already ran)', async () => {
|
|
154
|
+
await seedCaddyProvider();
|
|
155
|
+
await seedModule('celilo-website');
|
|
156
|
+
|
|
157
|
+
const run = createRecordingRunner();
|
|
158
|
+
let emitted = false;
|
|
159
|
+
|
|
160
|
+
const result = await cleanupWebRoutesForModule({
|
|
161
|
+
moduleId: 'celilo-website',
|
|
162
|
+
db,
|
|
163
|
+
run,
|
|
164
|
+
emitAndWait: async () => {
|
|
165
|
+
emitted = true;
|
|
166
|
+
return CLEAN_RECONCILE;
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(result).toEqual({ routesRemoved: 0, assetDirsRemoved: [], warnings: [] });
|
|
171
|
+
expect(run.calls).toHaveLength(0);
|
|
172
|
+
// No redundant reconcile on every module removal.
|
|
173
|
+
expect(emitted).toBe(false);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('skips the remote rm for reverse-proxy routes (no assets on the host)', async () => {
|
|
177
|
+
await seedCaddyProvider();
|
|
178
|
+
await seedModule('forgejo');
|
|
179
|
+
seedRoute('forgejo', 'forgejo', '/git', 'reverse_proxy');
|
|
180
|
+
|
|
181
|
+
const run = createRecordingRunner();
|
|
182
|
+
const result = await cleanupWebRoutesForModule({
|
|
183
|
+
moduleId: 'forgejo',
|
|
184
|
+
db,
|
|
185
|
+
run,
|
|
186
|
+
emitAndWait: async () => CLEAN_RECONCILE,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
expect(result.routesRemoved).toBe(1);
|
|
190
|
+
expect(run.calls).toHaveLength(0);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('still deletes routes when the asset rm fails', async () => {
|
|
194
|
+
await seedCaddyProvider();
|
|
195
|
+
await seedModule('hello-foo');
|
|
196
|
+
seedRoute('hello-foo', 'foo', '/foo', 'static');
|
|
197
|
+
|
|
198
|
+
const run = createRecordingRunner({ ok: false, stderr: 'host unreachable' });
|
|
199
|
+
const result = await cleanupWebRoutesForModule({
|
|
200
|
+
moduleId: 'hello-foo',
|
|
201
|
+
db,
|
|
202
|
+
run,
|
|
203
|
+
emitAndWait: async () => CLEAN_RECONCILE,
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
expect(result.routesRemoved).toBe(1);
|
|
207
|
+
expect(result.assetDirsRemoved).toEqual([]);
|
|
208
|
+
expect(result.warnings.join(' ')).toMatch(/Failed to remove \/srv\/www\/foo/);
|
|
209
|
+
expect(db.select().from(webRoutes).all()).toHaveLength(0);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('warns when no provider is deployed to clean assets from', async () => {
|
|
213
|
+
await seedModule('hello-foo');
|
|
214
|
+
seedRoute('hello-foo', 'foo', '/foo', 'static');
|
|
215
|
+
|
|
216
|
+
const run = createRecordingRunner();
|
|
217
|
+
const result = await cleanupWebRoutesForModule({
|
|
218
|
+
moduleId: 'hello-foo',
|
|
219
|
+
db,
|
|
220
|
+
run,
|
|
221
|
+
emitAndWait: async () => CLEAN_RECONCILE,
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
expect(result.routesRemoved).toBe(1);
|
|
225
|
+
expect(run.calls).toHaveLength(0);
|
|
226
|
+
expect(result.warnings.join(' ')).toMatch(/No public_web provider host found/);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test('warns — but does not throw — when the provider never reconciles', async () => {
|
|
230
|
+
await seedCaddyProvider();
|
|
231
|
+
await seedModule('hello-foo');
|
|
232
|
+
seedRoute('hello-foo', 'foo', '/foo', 'static');
|
|
233
|
+
|
|
234
|
+
const result = await cleanupWebRoutesForModule({
|
|
235
|
+
moduleId: 'hello-foo',
|
|
236
|
+
db,
|
|
237
|
+
run: createRecordingRunner(),
|
|
238
|
+
emitAndWait: async () => ({
|
|
239
|
+
events: 1,
|
|
240
|
+
succeeded: 0,
|
|
241
|
+
failed: 0,
|
|
242
|
+
timedOut: false,
|
|
243
|
+
noDispatcher: true,
|
|
244
|
+
}),
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
expect(result.routesRemoved).toBe(1);
|
|
248
|
+
expect(result.warnings.join(' ')).toMatch(/no event dispatcher is running/);
|
|
249
|
+
});
|
|
250
|
+
});
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route cleanup on module removal — the consumer half of ISS-0035.
|
|
3
|
+
*
|
|
4
|
+
* `register_route` / `unregister_routes` emit `public_web.routes_changed`, and
|
|
5
|
+
* the provider's `reconcile_routes` subscription re-renders its config from
|
|
6
|
+
* `web_routes`. But `unregister_routes` is only reachable from a module's own
|
|
7
|
+
* `on_uninstall` teardown script, and most consumers don't define one —
|
|
8
|
+
* celilo-website, celilo-registry, celilo-apt-repo and celilo-mgmt all publish
|
|
9
|
+
* a site and have no teardown. For those, `module remove` deleted the route
|
|
10
|
+
* rows through the FK cascade on `modules.id` and emitted NOTHING, so the
|
|
11
|
+
* provider never learned the route was gone: the rendered Caddyfile kept a site
|
|
12
|
+
* block for a module that no longer exists, and `/srv/www/<slug>` was orphaned.
|
|
13
|
+
*
|
|
14
|
+
* The fix lives here rather than in each module's teardown script for the usual
|
|
15
|
+
* reason: one call site in `performModuleRemove` covers every consumer and
|
|
16
|
+
* can't be forgotten by the next one. Modules that DO define an `on_uninstall`
|
|
17
|
+
* calling `unregister_routes` still win — their hook runs first and this
|
|
18
|
+
* becomes a no-op (zero owned routes).
|
|
19
|
+
*
|
|
20
|
+
* Everything here is best-effort. A failed asset `rm` or an undelivered
|
|
21
|
+
* reconcile is reported as a warning, never a thrown error: a stuck provider is
|
|
22
|
+
* no reason to strand a module in a half-removed state.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { execRunner, runAppCommand, shellEscape } from '@celilo/capabilities';
|
|
26
|
+
import type { Runner } from '@celilo/capabilities';
|
|
27
|
+
import { eq } from 'drizzle-orm';
|
|
28
|
+
import type { DbClient } from '../db/client';
|
|
29
|
+
import { capabilities, webRoutes } from '../db/schema';
|
|
30
|
+
import { loadHookConfigMap } from '../hooks/load-hook-config';
|
|
31
|
+
import { emitWebRoutesChangedAndWait } from './celilo-events';
|
|
32
|
+
|
|
33
|
+
export interface WebRouteCleanupResult {
|
|
34
|
+
routesRemoved: number;
|
|
35
|
+
/** Asset roots actually deleted from the provider host. */
|
|
36
|
+
assetDirsRemoved: string[];
|
|
37
|
+
/** Non-fatal problems, for the caller to log. Never thrown. */
|
|
38
|
+
warnings: string[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface WebRouteCleanupDeps {
|
|
42
|
+
moduleId: string;
|
|
43
|
+
db: DbClient;
|
|
44
|
+
/** Injectable remote runner — tests pass a mock. */
|
|
45
|
+
run?: Runner;
|
|
46
|
+
/** Injectable event emit + wait — tests pass a stub. */
|
|
47
|
+
emitAndWait?: typeof emitWebRoutesChangedAndWait;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The provider host that owns `/srv/www` — the same `config.target_ip` the
|
|
52
|
+
* public_web capability uses for its asset uploads.
|
|
53
|
+
*/
|
|
54
|
+
async function resolvePublicWebHostIp(db: DbClient): Promise<string | undefined> {
|
|
55
|
+
const providers = db
|
|
56
|
+
.select()
|
|
57
|
+
.from(capabilities)
|
|
58
|
+
.where(eq(capabilities.capabilityName, 'public_web'))
|
|
59
|
+
.all();
|
|
60
|
+
const provider = providers[0];
|
|
61
|
+
if (!provider) return undefined;
|
|
62
|
+
|
|
63
|
+
const config = await loadHookConfigMap(provider.moduleId, db);
|
|
64
|
+
// target_ip may carry a CIDR suffix; the capability strips it the same way.
|
|
65
|
+
return String(config.target_ip ?? '').split('/')[0] || undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Delete a module's web routes, reclaim its static asset roots, and tell the
|
|
70
|
+
* provider to reconcile. Returns counts + warnings; never throws.
|
|
71
|
+
*/
|
|
72
|
+
export async function cleanupWebRoutesForModule(
|
|
73
|
+
deps: WebRouteCleanupDeps,
|
|
74
|
+
): Promise<WebRouteCleanupResult> {
|
|
75
|
+
const { moduleId, db, run = execRunner, emitAndWait = emitWebRoutesChangedAndWait } = deps;
|
|
76
|
+
|
|
77
|
+
const owned = db.select().from(webRoutes).where(eq(webRoutes.moduleId, moduleId)).all();
|
|
78
|
+
if (owned.length === 0) {
|
|
79
|
+
// Either the module never registered a route, or its own on_uninstall
|
|
80
|
+
// already called unregister_routes (which emitted and reconciled). Nothing
|
|
81
|
+
// to do — and importantly, no event, so we don't trigger a redundant
|
|
82
|
+
// reconcile on every module removal.
|
|
83
|
+
return { routesRemoved: 0, assetDirsRemoved: [], warnings: [] };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const warnings: string[] = [];
|
|
87
|
+
const assetDirsRemoved: string[] = [];
|
|
88
|
+
|
|
89
|
+
const staticSlugs = owned.filter((r) => r.type === 'static').map((r) => r.slug);
|
|
90
|
+
if (staticSlugs.length > 0) {
|
|
91
|
+
const providerIp = await resolvePublicWebHostIp(db);
|
|
92
|
+
if (!providerIp) {
|
|
93
|
+
warnings.push(
|
|
94
|
+
`No public_web provider host found — left ${staticSlugs.length} asset dir(s) in /srv/www on disk`,
|
|
95
|
+
);
|
|
96
|
+
} else {
|
|
97
|
+
for (const slug of staticSlugs) {
|
|
98
|
+
const dir = `/srv/www/${slug}`;
|
|
99
|
+
// escape-hatch: reclaiming a consumer's static web root on the provider
|
|
100
|
+
// host. No capability owns asset-root teardown, and it is neither
|
|
101
|
+
// desired-state nor a service action.
|
|
102
|
+
const result = runAppCommand(
|
|
103
|
+
{ ipv4_address: providerIp },
|
|
104
|
+
`rm -rf ${shellEscape(dir)}`,
|
|
105
|
+
run,
|
|
106
|
+
{ timeoutMs: 30_000 },
|
|
107
|
+
);
|
|
108
|
+
if (result.ok) {
|
|
109
|
+
assetDirsRemoved.push(dir);
|
|
110
|
+
} else {
|
|
111
|
+
warnings.push(
|
|
112
|
+
`Failed to remove ${dir} on ${providerIp} (continuing): ${result.stderr || result.stdout || 'unknown'}`,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
db.delete(webRoutes).where(eq(webRoutes.moduleId, moduleId)).run();
|
|
120
|
+
|
|
121
|
+
// Same signal a consumer's own unregister_routes emits. Unlike the deploy
|
|
122
|
+
// path (ISS-0081), an undelivered reconcile here is a warning, not a
|
|
123
|
+
// failure — removal must complete regardless.
|
|
124
|
+
const reconcile = await emitAndWait(moduleId);
|
|
125
|
+
if (reconcile.noDispatcher) {
|
|
126
|
+
warnings.push(
|
|
127
|
+
`Routes for ${moduleId} were deleted but no event dispatcher is running, so the public_web provider has not reconciled — it is still serving the removed route(s) until its next reconcile.`,
|
|
128
|
+
);
|
|
129
|
+
} else if (reconcile.timedOut) {
|
|
130
|
+
warnings.push(
|
|
131
|
+
`public_web provider did not confirm the route removal within the deadline (${reconcile.succeeded} ok, ${reconcile.failed} failed of ${reconcile.events} event(s)).`,
|
|
132
|
+
);
|
|
133
|
+
} else if (reconcile.failed > 0) {
|
|
134
|
+
warnings.push(
|
|
135
|
+
`public_web provider failed to apply the route removal (${reconcile.failed} delivery failure(s)) — it may still be serving the removed route(s).`,
|
|
136
|
+
);
|
|
137
|
+
} else if (reconcile.events > 0 && reconcile.succeeded === 0) {
|
|
138
|
+
warnings.push(
|
|
139
|
+
`Routes for ${moduleId} were deleted but NO provider reconciled — the provider has no reconcile_routes subscription, so the removed route(s) may still be served.`,
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return { routesRemoved: owned.length, assetDirsRemoved, warnings };
|
|
144
|
+
}
|
|
@@ -158,7 +158,7 @@ export function getOutputFilename(templateFilename: string): string {
|
|
|
158
158
|
* a no-op and a real change an in-place UPDATE — never the destructive
|
|
159
159
|
* REPLACE the terraform-safety guard (create-only, see terraform-safety.ts)
|
|
160
160
|
* rejects. terraform = birth DNS, the `dns-client-config` aspect = ongoing
|
|
161
|
-
* DNS. The per-type lists are in the callback. See
|
|
161
|
+
* DNS. The per-type lists are in the callback. See openspec/specs/lxc-dns-at-birth/spec.md.
|
|
162
162
|
*
|
|
163
163
|
* Anchored on the resource's opening line — it never brace-matches the nested
|
|
164
164
|
* disk/network/features blocks, so it's robust to attribute order/formatting.
|
|
@@ -736,7 +736,7 @@ export async function generateTemplates(options: GenerateOptions): Promise<Gener
|
|
|
736
736
|
|
|
737
737
|
// Dedicated DNS-ingress IP (ISS-0156). A dns_internal provider now deploys into
|
|
738
738
|
// a PROTECTED zone (dmz) so it can see protected-zone query sources for
|
|
739
|
-
// split-horizon views (
|
|
739
|
+
// split-horizon views (openspec/specs/internal-dns-zone-views/spec.md). `internal` devices have
|
|
740
740
|
// no route into the 10-net, so they reach the resolver through a firewall DNAT
|
|
741
741
|
// on a dedicated `internal`-subnet address. A module opts in by declaring a
|
|
742
742
|
// `dns_ingress_ip` infrastructure variable; we allocate a free IP from the
|
|
@@ -96,7 +96,7 @@ export interface Machine {
|
|
|
96
96
|
/**
|
|
97
97
|
* Appliance / API-only machines (e.g., greenwave) where celilo has
|
|
98
98
|
* no shell access. Base-module aspects skip these — see
|
|
99
|
-
*
|
|
99
|
+
* openspec/specs/base-module-aspects/spec.md D8. Optional on the type because most call
|
|
100
100
|
* sites don't care; the DB column defaults to false so the
|
|
101
101
|
* effective value is well-defined regardless.
|
|
102
102
|
*/
|
|
@@ -159,7 +159,7 @@ describe('computed capability fields — DB integration', () => {
|
|
|
159
159
|
if (!result.success) expect(result.error).toMatch(/could not be resolved|Failed to evaluate/);
|
|
160
160
|
});
|
|
161
161
|
|
|
162
|
-
// Gap B (
|
|
162
|
+
// Gap B (openspec/specs/internal-dns-split-horizon/spec.md step 3): buildResolutionContext
|
|
163
163
|
// must EAGERLY evaluate computed markers into the capabilities map, so the
|
|
164
164
|
// `variables.imports` path (which reads context.capabilities directly, not via
|
|
165
165
|
// resolveVariable) sees the real array.
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* integration (a later step) decide how refs map onto live data.
|
|
9
9
|
*
|
|
10
10
|
* The function allow-list is the v1 set from
|
|
11
|
-
*
|
|
11
|
+
* openspec/specs/internal-dns-split-horizon/spec.md (D1.1):
|
|
12
12
|
* keys, values, map, concat, unique, format
|
|
13
13
|
*
|
|
14
14
|
* Secret-projection rule: `values(secret.*)` is rejected — it would leak
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Parser for the computed-variable DSL.
|
|
3
3
|
*
|
|
4
|
-
* Computed variables (
|
|
4
|
+
* Computed variables (openspec/specs/internal-dns-split-horizon/spec.md, D1) are
|
|
5
5
|
* declared in a manifest with `type: computed` and a `value:` expression
|
|
6
6
|
* derived on access from other values, e.g.:
|
|
7
7
|
*
|
|
@@ -21,7 +21,7 @@ const TEST_DB_PATH = './test-context.db';
|
|
|
21
21
|
/**
|
|
22
22
|
* Select a proxmox container_service for a module + give it a hostname, so the
|
|
23
23
|
* deployed-system recording in buildResolutionContext fires (IPAM allocates and
|
|
24
|
-
* records into module_systems).
|
|
24
|
+
* records into module_systems). openspec/specs/module-systems-addressing/spec.md.
|
|
25
25
|
*/
|
|
26
26
|
function setupProxmoxInfra(db: DbClient, moduleId: string, zone: string): void {
|
|
27
27
|
const serviceId = `svc-${moduleId}`;
|
package/src/variables/context.ts
CHANGED
|
@@ -148,7 +148,7 @@ function autoDeriveInventoryVariables(
|
|
|
148
148
|
* its deployed systems. `$self:` supports the optional `[N]` array-index suffix
|
|
149
149
|
* (e.g. `$self:domains[0]`). `$infra:` references a provider's deployed system
|
|
150
150
|
* by name (the replacement for the old `$self:target_ip` — see
|
|
151
|
-
*
|
|
151
|
+
* openspec/specs/module-systems-addressing/spec.md). Non-string values and strings that don't
|
|
152
152
|
* start with one of those prefixes are returned unchanged.
|
|
153
153
|
*/
|
|
154
154
|
function resolveSelfRefsInObject(
|
|
@@ -323,7 +323,7 @@ export async function buildResolutionContext(
|
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
-
// Deployed-system recording (
|
|
326
|
+
// Deployed-system recording (openspec/specs/module-systems-addressing/spec.md).
|
|
327
327
|
// Record this module's system(s) into module_systems at generate time, so
|
|
328
328
|
// `$infra:<name>.…` resolves in templates. The address comes from:
|
|
329
329
|
// - machine pool → the machine's own IP; no vmid (no container).
|
|
@@ -468,7 +468,7 @@ export async function buildResolutionContext(
|
|
|
468
468
|
providerSystems,
|
|
469
469
|
);
|
|
470
470
|
|
|
471
|
-
// Evaluate computed-field markers (
|
|
471
|
+
// Evaluate computed-field markers (openspec/specs/internal-dns-split-horizon/spec.md
|
|
472
472
|
// D1) in the PROVIDER's context, so consumers — both `$capability:` template
|
|
473
473
|
// refs AND `variables.imports` — see the real value (e.g. domain_list as an
|
|
474
474
|
// array) rather than the raw marker. Only build the provider lookup when a
|
|
@@ -498,7 +498,7 @@ export async function buildResolutionContext(
|
|
|
498
498
|
systemConfigMap[row.key] = row.value;
|
|
499
499
|
}
|
|
500
500
|
|
|
501
|
-
// LXC nameserver list (
|
|
501
|
+
// LXC nameserver list (openspec/specs/lxc-dns-at-birth/spec.md). Proxmox's `nameserver` is a
|
|
502
502
|
// space-separated primary/secondary list. Compose it so every celilo-built
|
|
503
503
|
// LXC boots with a working resolver — before Ansible's apt update, and
|
|
504
504
|
// independent of which Proxmox node it lands on (the nodes' DNS defaults
|
|
@@ -566,7 +566,7 @@ export async function buildResolutionContext(
|
|
|
566
566
|
// Build the `$infra:<name>.<field>` lookup from the systems recorded above
|
|
567
567
|
// (proxmox/machine at generate; DigitalOcean gets refreshed at deploy from
|
|
568
568
|
// terraform outputs). This is what lets `$infra:` resolve in templates.
|
|
569
|
-
//
|
|
569
|
+
// openspec/specs/module-systems-addressing/spec.md.
|
|
570
570
|
let infraSystemsMap: Record<string, import('./types').InfraSystemFields> = {};
|
|
571
571
|
if (module?.manifestData) {
|
|
572
572
|
const { buildInfraSystemsMap } = await import('../services/deployed-systems');
|
|
@@ -9,7 +9,7 @@ const TEST_DB_PATH = './test-lxc-nameserver.db';
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Coverage for the generate-time `lxc_nameserver` composition
|
|
12
|
-
* (
|
|
12
|
+
* (openspec/specs/lxc-dns-at-birth/spec.md): proxmox_lxc templates read `$self:lxc_nameserver`,
|
|
13
13
|
* a space-separated primary/secondary list = internal dns_internal resolver
|
|
14
14
|
* first (CIDR stripped), then the public dns.primary/dns.fallback resolvers;
|
|
15
15
|
* public-only when no dns_internal provider is registered (bootstrap).
|
|
@@ -75,7 +75,7 @@ export async function resolveVariable(
|
|
|
75
75
|
|
|
76
76
|
case 'infra': {
|
|
77
77
|
// Format: $infra:<system-name>.<field> — references a deployed system by
|
|
78
|
-
// its stable handle (requires.systems[].name).
|
|
78
|
+
// its stable handle (requires.systems[].name). openspec/specs/module-systems-addressing/spec.md.
|
|
79
79
|
const dot = variable.path.indexOf('.');
|
|
80
80
|
if (dot === -1) {
|
|
81
81
|
return {
|
|
@@ -208,7 +208,7 @@ export async function resolveVariable(
|
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
-
// Computed field (
|
|
211
|
+
// Computed field (openspec/specs/internal-dns-split-horizon/spec.md D1):
|
|
212
212
|
// evaluate the DSL expression in the PROVIDER's context. Like the
|
|
213
213
|
// lazy $self: block below, we look up the provider module, but here
|
|
214
214
|
// we build a typed lookup over its config/secrets/system data.
|
package/src/variables/types.ts
CHANGED
|
@@ -24,7 +24,7 @@ export interface ResolutionContext {
|
|
|
24
24
|
capabilities: Record<string, Record<string, unknown>>;
|
|
25
25
|
/**
|
|
26
26
|
* The module's deployed systems, keyed by name, for `$infra:<name>.<field>`
|
|
27
|
-
* resolution at generate time (
|
|
27
|
+
* resolution at generate time (openspec/specs/module-systems-addressing/spec.md). Each value
|
|
28
28
|
* exposes the snake_cased fields a template can reference: `ipv4_address`,
|
|
29
29
|
* `hostname`, `zone`, `vmid`, `cidr`. Optional only so the many test-stub
|
|
30
30
|
* `ResolutionContext` literals need no churn — production (buildResolutionContext)
|