@launchfile/macos-dev 0.1.3
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/CLAUDE.md +37 -0
- package/dist/__tests__/dry-run.test.d.ts +2 -0
- package/dist/__tests__/dry-run.test.d.ts.map +1 -0
- package/dist/__tests__/dry-run.test.js +129 -0
- package/dist/__tests__/dry-run.test.js.map +1 -0
- package/dist/__tests__/env-writer.test.d.ts +2 -0
- package/dist/__tests__/env-writer.test.d.ts.map +1 -0
- package/dist/__tests__/env-writer.test.js +127 -0
- package/dist/__tests__/env-writer.test.js.map +1 -0
- package/dist/__tests__/lockfile-detect.test.d.ts +2 -0
- package/dist/__tests__/lockfile-detect.test.d.ts.map +1 -0
- package/dist/__tests__/lockfile-detect.test.js +75 -0
- package/dist/__tests__/lockfile-detect.test.js.map +1 -0
- package/dist/__tests__/port-allocator.test.d.ts +2 -0
- package/dist/__tests__/port-allocator.test.d.ts.map +1 -0
- package/dist/__tests__/port-allocator.test.js +53 -0
- package/dist/__tests__/port-allocator.test.js.map +1 -0
- package/dist/__tests__/secret-generator.test.d.ts +2 -0
- package/dist/__tests__/secret-generator.test.d.ts.map +1 -0
- package/dist/__tests__/secret-generator.test.js +26 -0
- package/dist/__tests__/secret-generator.test.js.map +1 -0
- package/dist/__tests__/state.test.d.ts +2 -0
- package/dist/__tests__/state.test.d.ts.map +1 -0
- package/dist/__tests__/state.test.js +30 -0
- package/dist/__tests__/state.test.js.map +1 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +69 -0
- package/dist/cli.js.map +1 -0
- package/dist/env-writer.d.ts +46 -0
- package/dist/env-writer.d.ts.map +1 -0
- package/dist/env-writer.js +175 -0
- package/dist/env-writer.js.map +1 -0
- package/dist/health.d.ts +12 -0
- package/dist/health.d.ts.map +1 -0
- package/dist/health.js +72 -0
- package/dist/health.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/lockfile-detect.d.ts +14 -0
- package/dist/lockfile-detect.d.ts.map +1 -0
- package/dist/lockfile-detect.js +40 -0
- package/dist/lockfile-detect.js.map +1 -0
- package/dist/port-allocator.d.ts +21 -0
- package/dist/port-allocator.d.ts.map +1 -0
- package/dist/port-allocator.js +78 -0
- package/dist/port-allocator.js.map +1 -0
- package/dist/prereqs.d.ts +10 -0
- package/dist/prereqs.d.ts.map +1 -0
- package/dist/prereqs.js +22 -0
- package/dist/prereqs.js.map +1 -0
- package/dist/process-manager.d.ts +43 -0
- package/dist/process-manager.d.ts.map +1 -0
- package/dist/process-manager.js +188 -0
- package/dist/process-manager.js.map +1 -0
- package/dist/provider.d.ts +26 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +342 -0
- package/dist/provider.js.map +1 -0
- package/dist/resources/index.d.ts +10 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +23 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/mysql.d.ts +16 -0
- package/dist/resources/mysql.d.ts.map +1 -0
- package/dist/resources/mysql.js +64 -0
- package/dist/resources/mysql.js.map +1 -0
- package/dist/resources/postgres.d.ts +22 -0
- package/dist/resources/postgres.d.ts.map +1 -0
- package/dist/resources/postgres.js +98 -0
- package/dist/resources/postgres.js.map +1 -0
- package/dist/resources/redis.d.ts +16 -0
- package/dist/resources/redis.d.ts.map +1 -0
- package/dist/resources/redis.js +42 -0
- package/dist/resources/redis.js.map +1 -0
- package/dist/resources/sqlite.d.ts +16 -0
- package/dist/resources/sqlite.d.ts.map +1 -0
- package/dist/resources/sqlite.js +38 -0
- package/dist/resources/sqlite.js.map +1 -0
- package/dist/resources/types.d.ts +40 -0
- package/dist/resources/types.d.ts.map +1 -0
- package/dist/resources/types.js +8 -0
- package/dist/resources/types.js.map +1 -0
- package/dist/runtimes/bun.d.ts +11 -0
- package/dist/runtimes/bun.d.ts.map +1 -0
- package/dist/runtimes/bun.js +20 -0
- package/dist/runtimes/bun.js.map +1 -0
- package/dist/runtimes/index.d.ts +8 -0
- package/dist/runtimes/index.d.ts.map +1 -0
- package/dist/runtimes/index.js +18 -0
- package/dist/runtimes/index.js.map +1 -0
- package/dist/runtimes/node.d.ts +11 -0
- package/dist/runtimes/node.d.ts.map +1 -0
- package/dist/runtimes/node.js +70 -0
- package/dist/runtimes/node.js.map +1 -0
- package/dist/runtimes/python.d.ts +11 -0
- package/dist/runtimes/python.d.ts.map +1 -0
- package/dist/runtimes/python.js +38 -0
- package/dist/runtimes/python.js.map +1 -0
- package/dist/runtimes/ruby.d.ts +11 -0
- package/dist/runtimes/ruby.d.ts.map +1 -0
- package/dist/runtimes/ruby.js +51 -0
- package/dist/runtimes/ruby.js.map +1 -0
- package/dist/runtimes/types.d.ts +13 -0
- package/dist/runtimes/types.d.ts.map +1 -0
- package/dist/runtimes/types.js +5 -0
- package/dist/runtimes/types.js.map +1 -0
- package/dist/secret-generator.d.ts +11 -0
- package/dist/secret-generator.d.ts.map +1 -0
- package/dist/secret-generator.js +26 -0
- package/dist/secret-generator.js.map +1 -0
- package/dist/shell.d.ts +25 -0
- package/dist/shell.d.ts.map +1 -0
- package/dist/shell.js +46 -0
- package/dist/shell.js.map +1 -0
- package/dist/state.d.ts +35 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +62 -0
- package/dist/state.js.map +1 -0
- package/dist/storage.d.ts +16 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +48 -0
- package/dist/storage.js.map +1 -0
- package/package.json +41 -0
- package/src/__tests__/dry-run.test.ts +157 -0
- package/src/__tests__/env-writer.test.ts +156 -0
- package/src/__tests__/lockfile-detect.test.ts +74 -0
- package/src/__tests__/port-allocator.test.ts +59 -0
- package/src/__tests__/secret-generator.test.ts +31 -0
- package/src/__tests__/state.test.ts +33 -0
- package/src/cli.ts +78 -0
- package/src/env-writer.ts +231 -0
- package/src/health.ts +80 -0
- package/src/index.ts +9 -0
- package/src/lockfile-detect.ts +48 -0
- package/src/port-allocator.ts +97 -0
- package/src/prereqs.ts +32 -0
- package/src/process-manager.ts +242 -0
- package/src/provider.ts +415 -0
- package/src/resources/index.ts +29 -0
- package/src/resources/mysql.ts +98 -0
- package/src/resources/postgres.ts +133 -0
- package/src/resources/redis.ts +58 -0
- package/src/resources/sqlite.ts +52 -0
- package/src/resources/types.ts +47 -0
- package/src/runtimes/bun.ts +25 -0
- package/src/runtimes/index.ts +24 -0
- package/src/runtimes/node.ts +71 -0
- package/src/runtimes/python.ts +42 -0
- package/src/runtimes/ruby.ts +55 -0
- package/src/runtimes/types.ts +16 -0
- package/src/secret-generator.ts +32 -0
- package/src/shell.ts +70 -0
- package/src/state.ts +92 -0
- package/src/storage.ts +67 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { readLaunch } from "@launchfile/sdk";
|
|
5
|
+
import {
|
|
6
|
+
buildResolverContext,
|
|
7
|
+
resolveComponentEnv,
|
|
8
|
+
resolveGenerators,
|
|
9
|
+
} from "../env-writer.js";
|
|
10
|
+
import { getProvisioner } from "../resources/index.js";
|
|
11
|
+
import type { ResourceProperties } from "../resources/types.js";
|
|
12
|
+
import { allocatePorts } from "../port-allocator.js";
|
|
13
|
+
|
|
14
|
+
const CATALOG_DIR = join(import.meta.dirname, "../../../../catalog/drafts");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Dry-run test: parse a catalog Launchfile, simulate provisioning,
|
|
18
|
+
* resolve env vars, and verify the output makes sense.
|
|
19
|
+
*/
|
|
20
|
+
describe("dry-run against catalog", () => {
|
|
21
|
+
it("resolves miniflux Launchfile", async () => {
|
|
22
|
+
const yaml = await readFile(join(CATALOG_DIR, "miniflux/Launchfile"), "utf8");
|
|
23
|
+
const launch = readLaunch(yaml);
|
|
24
|
+
|
|
25
|
+
expect(launch.name).toBe("miniflux");
|
|
26
|
+
expect(Object.keys(launch.components)).toEqual(["default"]);
|
|
27
|
+
|
|
28
|
+
const component = launch.components.default!;
|
|
29
|
+
|
|
30
|
+
// Verify requires
|
|
31
|
+
expect(component.requires).toHaveLength(1);
|
|
32
|
+
expect(component.requires![0]!.type).toBe("postgres");
|
|
33
|
+
expect(component.requires![0]!.set_env?.DATABASE_URL).toBe("$url");
|
|
34
|
+
|
|
35
|
+
// Simulate provisioned postgres
|
|
36
|
+
const resourceMap: Record<string, ResourceProperties> = {
|
|
37
|
+
postgres: {
|
|
38
|
+
url: "postgresql://launchfile_miniflux:secret@localhost:5432/launchfile_miniflux",
|
|
39
|
+
host: "localhost",
|
|
40
|
+
port: 5432,
|
|
41
|
+
user: "launchfile_miniflux",
|
|
42
|
+
password: "secret",
|
|
43
|
+
name: "launchfile_miniflux",
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const ports = await allocatePorts(launch.components, "miniflux");
|
|
48
|
+
const context = buildResolverContext(resourceMap, ports, {});
|
|
49
|
+
|
|
50
|
+
const env = resolveComponentEnv(component, context, resourceMap);
|
|
51
|
+
await resolveGenerators(component, env);
|
|
52
|
+
|
|
53
|
+
// DATABASE_URL should be resolved from postgres $url
|
|
54
|
+
expect(env.DATABASE_URL).toBe(
|
|
55
|
+
"postgresql://launchfile_miniflux:secret@localhost:5432/launchfile_miniflux",
|
|
56
|
+
);
|
|
57
|
+
// Default env vars should be resolved
|
|
58
|
+
expect(env.RUN_MIGRATIONS).toBe("1");
|
|
59
|
+
expect(env.CREATE_ADMIN).toBe("1");
|
|
60
|
+
expect(env.ADMIN_USERNAME).toBe("admin");
|
|
61
|
+
// ADMIN_PASSWORD has generator: secret, so it should be generated
|
|
62
|
+
expect(env.ADMIN_PASSWORD).toBeTruthy();
|
|
63
|
+
expect(env.ADMIN_PASSWORD!.length).toBeGreaterThan(10);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("resolves langfuse Launchfile", async () => {
|
|
67
|
+
const yaml = await readFile(join(CATALOG_DIR, "langfuse/Launchfile"), "utf8");
|
|
68
|
+
const launch = readLaunch(yaml);
|
|
69
|
+
|
|
70
|
+
expect(launch.name).toBe("langfuse");
|
|
71
|
+
|
|
72
|
+
for (const [name, component] of Object.entries(launch.components)) {
|
|
73
|
+
// Every required resource should have a known provisioner
|
|
74
|
+
for (const req of component.requires ?? []) {
|
|
75
|
+
const provisioner = getProvisioner(req.type);
|
|
76
|
+
expect(provisioner, `No provisioner for ${req.type} in ${name}`).toBeDefined();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("resolves chatwoot multi-component Launchfile", async () => {
|
|
82
|
+
const yaml = await readFile(join(CATALOG_DIR, "chatwoot/Launchfile"), "utf8");
|
|
83
|
+
const launch = readLaunch(yaml);
|
|
84
|
+
|
|
85
|
+
expect(launch.name).toBe("chatwoot");
|
|
86
|
+
const componentNames = Object.keys(launch.components);
|
|
87
|
+
expect(componentNames.length).toBeGreaterThan(1);
|
|
88
|
+
|
|
89
|
+
// Simulate resources
|
|
90
|
+
const resourceMap: Record<string, ResourceProperties> = {
|
|
91
|
+
postgres: {
|
|
92
|
+
url: "postgresql://user:pass@localhost:5432/chatwoot",
|
|
93
|
+
host: "localhost",
|
|
94
|
+
port: 5432,
|
|
95
|
+
user: "user",
|
|
96
|
+
password: "pass",
|
|
97
|
+
name: "chatwoot",
|
|
98
|
+
},
|
|
99
|
+
redis: {
|
|
100
|
+
url: "redis://localhost:6379/0",
|
|
101
|
+
host: "localhost",
|
|
102
|
+
port: 6379,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const ports = await allocatePorts(launch.components, "chatwoot");
|
|
107
|
+
const secrets: Record<string, string> = {};
|
|
108
|
+
|
|
109
|
+
// Generate secrets from launch.secrets
|
|
110
|
+
if (launch.secrets) {
|
|
111
|
+
for (const [name] of Object.entries(launch.secrets)) {
|
|
112
|
+
secrets[name] = `test-secret-${name}`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const context = buildResolverContext(resourceMap, ports, secrets);
|
|
117
|
+
|
|
118
|
+
// Resolve env for each component — should not throw
|
|
119
|
+
for (const [name, component] of Object.entries(launch.components)) {
|
|
120
|
+
const env = resolveComponentEnv(component, context, resourceMap);
|
|
121
|
+
await resolveGenerators(component, env);
|
|
122
|
+
// Every component should have at least some env vars
|
|
123
|
+
expect(Object.keys(env).length, `${name} should have env vars`).toBeGreaterThan(0);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("identifies unsupported resource types", async () => {
|
|
128
|
+
// Check all catalog Launchfiles for resource types we support
|
|
129
|
+
const { readdir } = await import("node:fs/promises");
|
|
130
|
+
const apps = await readdir(CATALOG_DIR);
|
|
131
|
+
const unsupported = new Set<string>();
|
|
132
|
+
|
|
133
|
+
for (const app of apps) {
|
|
134
|
+
try {
|
|
135
|
+
const yaml = await readFile(join(CATALOG_DIR, app, "Launchfile"), "utf8");
|
|
136
|
+
const launch = readLaunch(yaml);
|
|
137
|
+
|
|
138
|
+
for (const component of Object.values(launch.components)) {
|
|
139
|
+
for (const req of [...(component.requires ?? []), ...(component.supports ?? [])]) {
|
|
140
|
+
if (!getProvisioner(req.type)) {
|
|
141
|
+
unsupported.add(req.type);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} catch {
|
|
146
|
+
// Skip apps that can't be parsed
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Log unsupported types for visibility
|
|
151
|
+
if (unsupported.size > 0) {
|
|
152
|
+
console.log(` Unsupported resource types in catalog: ${[...unsupported].join(", ")}`);
|
|
153
|
+
}
|
|
154
|
+
// This test is informational — it doesn't fail
|
|
155
|
+
expect(true).toBe(true);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
buildResolverContext,
|
|
4
|
+
resolveComponentEnv,
|
|
5
|
+
generateSecrets,
|
|
6
|
+
} from "../env-writer.js";
|
|
7
|
+
import type { NormalizedComponent, Secret } from "@launchfile/sdk";
|
|
8
|
+
import type { ResourceProperties } from "../resources/types.js";
|
|
9
|
+
|
|
10
|
+
describe("buildResolverContext", () => {
|
|
11
|
+
it("builds context from resources, ports, and secrets", () => {
|
|
12
|
+
const resources: Record<string, ResourceProperties> = {
|
|
13
|
+
postgres: {
|
|
14
|
+
url: "postgresql://user:pass@localhost:5432/mydb",
|
|
15
|
+
host: "localhost",
|
|
16
|
+
port: 5432,
|
|
17
|
+
user: "user",
|
|
18
|
+
password: "pass",
|
|
19
|
+
name: "mydb",
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
const ports = { backend: 3000, frontend: 3001 };
|
|
23
|
+
const secrets = { "jwt-secret": "abc123" };
|
|
24
|
+
|
|
25
|
+
const ctx = buildResolverContext(resources, ports, secrets);
|
|
26
|
+
|
|
27
|
+
expect(ctx.components?.backend).toEqual({
|
|
28
|
+
url: "http://localhost:3000",
|
|
29
|
+
host: "localhost",
|
|
30
|
+
port: 3000,
|
|
31
|
+
});
|
|
32
|
+
expect(ctx.resources?.postgres?.url).toBe("postgresql://user:pass@localhost:5432/mydb");
|
|
33
|
+
expect(ctx.secrets?.["jwt-secret"]).toBe("abc123");
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("resolveComponentEnv", () => {
|
|
38
|
+
it("resolves set_env from requires", () => {
|
|
39
|
+
const component: NormalizedComponent = {
|
|
40
|
+
requires: [
|
|
41
|
+
{
|
|
42
|
+
type: "postgres",
|
|
43
|
+
set_env: {
|
|
44
|
+
DATABASE_URL: "$url",
|
|
45
|
+
DB_HOST: "$host",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
const resourceMap: Record<string, ResourceProperties> = {
|
|
51
|
+
postgres: {
|
|
52
|
+
url: "postgresql://user:pass@localhost:5432/mydb",
|
|
53
|
+
host: "localhost",
|
|
54
|
+
port: 5432,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
const context = buildResolverContext(resourceMap, {}, {});
|
|
58
|
+
|
|
59
|
+
const env = resolveComponentEnv(component, context, resourceMap);
|
|
60
|
+
|
|
61
|
+
expect(env.DATABASE_URL).toBe("postgresql://user:pass@localhost:5432/mydb");
|
|
62
|
+
expect(env.DB_HOST).toBe("localhost");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("resolves component-level env defaults", () => {
|
|
66
|
+
const component: NormalizedComponent = {
|
|
67
|
+
env: {
|
|
68
|
+
PORT: { default: "8080" },
|
|
69
|
+
LOG_LEVEL: { default: "info" },
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
const context = buildResolverContext({}, {}, {});
|
|
73
|
+
|
|
74
|
+
const env = resolveComponentEnv(component, context, {});
|
|
75
|
+
|
|
76
|
+
expect(env.PORT).toBe("8080");
|
|
77
|
+
expect(env.LOG_LEVEL).toBe("info");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("resolves cross-component references", () => {
|
|
81
|
+
const component: NormalizedComponent = {
|
|
82
|
+
env: {
|
|
83
|
+
BACKEND_URL: { default: "$components.backend.url" },
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
const context = buildResolverContext({}, { backend: 3000 }, {});
|
|
87
|
+
|
|
88
|
+
const env = resolveComponentEnv(component, context, {});
|
|
89
|
+
|
|
90
|
+
expect(env.BACKEND_URL).toBe("http://localhost:3000");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("resolves secrets references", () => {
|
|
94
|
+
const component: NormalizedComponent = {
|
|
95
|
+
env: {
|
|
96
|
+
SECRET_KEY: { default: "$secrets.my-key" },
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
const context = buildResolverContext({}, {}, { "my-key": "super-secret" });
|
|
100
|
+
|
|
101
|
+
const env = resolveComponentEnv(component, context, {});
|
|
102
|
+
|
|
103
|
+
expect(env.SECRET_KEY).toBe("super-secret");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("set_env takes precedence over component env", () => {
|
|
107
|
+
const component: NormalizedComponent = {
|
|
108
|
+
requires: [
|
|
109
|
+
{
|
|
110
|
+
type: "postgres",
|
|
111
|
+
set_env: { DATABASE_URL: "$url" },
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
env: {
|
|
115
|
+
DATABASE_URL: { default: "fallback" },
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
const resourceMap: Record<string, ResourceProperties> = {
|
|
119
|
+
postgres: {
|
|
120
|
+
url: "postgresql://real-url",
|
|
121
|
+
host: "localhost",
|
|
122
|
+
port: 5432,
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
const context = buildResolverContext(resourceMap, {}, {});
|
|
126
|
+
|
|
127
|
+
const env = resolveComponentEnv(component, context, resourceMap);
|
|
128
|
+
|
|
129
|
+
expect(env.DATABASE_URL).toBe("postgresql://real-url");
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("generateSecrets", () => {
|
|
134
|
+
it("generates new secrets", async () => {
|
|
135
|
+
const defs: Record<string, Secret> = {
|
|
136
|
+
"jwt-secret": { generator: "secret" },
|
|
137
|
+
"app-uuid": { generator: "uuid" },
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const secrets = await generateSecrets(defs, {});
|
|
141
|
+
|
|
142
|
+
expect(secrets["jwt-secret"]).toBeTruthy();
|
|
143
|
+
expect(secrets["app-uuid"]).toMatch(/^[0-9a-f-]+$/);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("reuses existing secrets", async () => {
|
|
147
|
+
const defs: Record<string, Secret> = {
|
|
148
|
+
"jwt-secret": { generator: "secret" },
|
|
149
|
+
};
|
|
150
|
+
const existing = { "jwt-secret": "keep-this" };
|
|
151
|
+
|
|
152
|
+
const secrets = await generateSecrets(defs, existing);
|
|
153
|
+
|
|
154
|
+
expect(secrets["jwt-secret"]).toBe("keep-this");
|
|
155
|
+
});
|
|
156
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { detectPackageManager } from "../lockfile-detect.js";
|
|
3
|
+
import { mkdtemp, writeFile, rm } from "node:fs/promises";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
|
|
7
|
+
describe("detectPackageManager", () => {
|
|
8
|
+
it("returns null for empty directory", async () => {
|
|
9
|
+
const dir = await mkdtemp(join(tmpdir(), "lf-test-"));
|
|
10
|
+
try {
|
|
11
|
+
const pm = await detectPackageManager(dir);
|
|
12
|
+
expect(pm).toBeNull();
|
|
13
|
+
} finally {
|
|
14
|
+
await rm(dir, { recursive: true });
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("detects bun from bun.lockb", async () => {
|
|
19
|
+
const dir = await mkdtemp(join(tmpdir(), "lf-test-"));
|
|
20
|
+
try {
|
|
21
|
+
await writeFile(join(dir, "bun.lockb"), "");
|
|
22
|
+
const pm = await detectPackageManager(dir);
|
|
23
|
+
expect(pm?.name).toBe("bun");
|
|
24
|
+
expect(pm?.installCommand).toBe("bun install");
|
|
25
|
+
} finally {
|
|
26
|
+
await rm(dir, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("detects yarn from yarn.lock", async () => {
|
|
31
|
+
const dir = await mkdtemp(join(tmpdir(), "lf-test-"));
|
|
32
|
+
try {
|
|
33
|
+
await writeFile(join(dir, "yarn.lock"), "");
|
|
34
|
+
const pm = await detectPackageManager(dir);
|
|
35
|
+
expect(pm?.name).toBe("yarn");
|
|
36
|
+
} finally {
|
|
37
|
+
await rm(dir, { recursive: true });
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("detects pnpm from pnpm-lock.yaml", async () => {
|
|
42
|
+
const dir = await mkdtemp(join(tmpdir(), "lf-test-"));
|
|
43
|
+
try {
|
|
44
|
+
await writeFile(join(dir, "pnpm-lock.yaml"), "");
|
|
45
|
+
const pm = await detectPackageManager(dir);
|
|
46
|
+
expect(pm?.name).toBe("pnpm");
|
|
47
|
+
} finally {
|
|
48
|
+
await rm(dir, { recursive: true });
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("detects bundler from Gemfile.lock", async () => {
|
|
53
|
+
const dir = await mkdtemp(join(tmpdir(), "lf-test-"));
|
|
54
|
+
try {
|
|
55
|
+
await writeFile(join(dir, "Gemfile.lock"), "");
|
|
56
|
+
const pm = await detectPackageManager(dir);
|
|
57
|
+
expect(pm?.name).toBe("bundler");
|
|
58
|
+
} finally {
|
|
59
|
+
await rm(dir, { recursive: true });
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("prefers bun over yarn when both present", async () => {
|
|
64
|
+
const dir = await mkdtemp(join(tmpdir(), "lf-test-"));
|
|
65
|
+
try {
|
|
66
|
+
await writeFile(join(dir, "bun.lockb"), "");
|
|
67
|
+
await writeFile(join(dir, "yarn.lock"), "");
|
|
68
|
+
const pm = await detectPackageManager(dir);
|
|
69
|
+
expect(pm?.name).toBe("bun");
|
|
70
|
+
} finally {
|
|
71
|
+
await rm(dir, { recursive: true });
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { allocatePort, allocatePorts } from "../port-allocator.js";
|
|
3
|
+
|
|
4
|
+
describe("allocatePort", () => {
|
|
5
|
+
it("returns a port in the expected range", async () => {
|
|
6
|
+
const port = await allocatePort("test-app", new Set());
|
|
7
|
+
expect(port).toBeGreaterThanOrEqual(10_000);
|
|
8
|
+
expect(port).toBeLessThan(20_000);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("is deterministic for the same key", async () => {
|
|
12
|
+
const port1 = await allocatePort("my-app", new Set());
|
|
13
|
+
const port2 = await allocatePort("my-app", new Set());
|
|
14
|
+
expect(port1).toBe(port2);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("avoids ports already in use", async () => {
|
|
18
|
+
const port1 = await allocatePort("collision-test", new Set());
|
|
19
|
+
const port2 = await allocatePort("collision-test", new Set([port1]));
|
|
20
|
+
expect(port2).not.toBe(port1);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("produces different ports for different keys", async () => {
|
|
24
|
+
const port1 = await allocatePort("app-a", new Set());
|
|
25
|
+
const port2 = await allocatePort("app-b", new Set());
|
|
26
|
+
// Not guaranteed but overwhelmingly likely for different inputs
|
|
27
|
+
expect(port1).not.toBe(port2);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("allocatePorts", () => {
|
|
32
|
+
it("allocates ports for all components", async () => {
|
|
33
|
+
const components = {
|
|
34
|
+
backend: { provides: [{ port: 3000 }] },
|
|
35
|
+
frontend: { provides: [{ port: 3001 }] },
|
|
36
|
+
};
|
|
37
|
+
const ports = await allocatePorts(components, "test-app");
|
|
38
|
+
expect(ports.backend).toBeDefined();
|
|
39
|
+
expect(ports.frontend).toBeDefined();
|
|
40
|
+
expect(ports.backend).not.toBe(ports.frontend);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("prefers the declared port if free", async () => {
|
|
44
|
+
const components = {
|
|
45
|
+
api: { provides: [{ port: 4567 }] },
|
|
46
|
+
};
|
|
47
|
+
const ports = await allocatePorts(components, "test-app");
|
|
48
|
+
expect(ports.api).toBe(4567);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("reuses saved ports when available", async () => {
|
|
52
|
+
const components = {
|
|
53
|
+
api: { provides: [{ port: 3000 }] },
|
|
54
|
+
};
|
|
55
|
+
const saved = { api: 9876 };
|
|
56
|
+
const ports = await allocatePorts(components, "test-app", saved);
|
|
57
|
+
expect(ports.api).toBe(9876);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { generateValue, generatePassword } from "../secret-generator.js";
|
|
3
|
+
|
|
4
|
+
describe("generateValue", () => {
|
|
5
|
+
it("generates a base64url secret", async () => {
|
|
6
|
+
const value = await generateValue("secret");
|
|
7
|
+
expect(value).toMatch(/^[A-Za-z0-9_-]+$/);
|
|
8
|
+
expect(value.length).toBeGreaterThan(20);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("generates a UUID", async () => {
|
|
12
|
+
const value = await generateValue("uuid");
|
|
13
|
+
expect(value).toMatch(
|
|
14
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("generates unique values each time", async () => {
|
|
19
|
+
const a = await generateValue("secret");
|
|
20
|
+
const b = await generateValue("secret");
|
|
21
|
+
expect(a).not.toBe(b);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe("generatePassword", () => {
|
|
26
|
+
it("generates a URL-safe password", () => {
|
|
27
|
+
const pw = generatePassword();
|
|
28
|
+
expect(pw).toMatch(/^[A-Za-z0-9_-]+$/);
|
|
29
|
+
expect(pw.length).toBeGreaterThan(10);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { initState, hashLaunchfile } from "../state.js";
|
|
3
|
+
|
|
4
|
+
describe("initState", () => {
|
|
5
|
+
it("creates a state with correct app name", () => {
|
|
6
|
+
const state = initState("my-app", "name: my-app");
|
|
7
|
+
expect(state.appName).toBe("my-app");
|
|
8
|
+
expect(state.version).toBe(1);
|
|
9
|
+
expect(state.resources).toEqual({});
|
|
10
|
+
expect(state.secrets).toEqual({});
|
|
11
|
+
expect(state.ports).toEqual({});
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("hashes launchfile content", () => {
|
|
15
|
+
const state = initState("app", "some yaml content");
|
|
16
|
+
expect(state.launchfileHash).toBeTruthy();
|
|
17
|
+
expect(state.launchfileHash.length).toBe(16);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("hashLaunchfile", () => {
|
|
22
|
+
it("is deterministic", () => {
|
|
23
|
+
const a = hashLaunchfile("hello");
|
|
24
|
+
const b = hashLaunchfile("hello");
|
|
25
|
+
expect(a).toBe(b);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("differs for different content", () => {
|
|
29
|
+
const a = hashLaunchfile("hello");
|
|
30
|
+
const b = hashLaunchfile("world");
|
|
31
|
+
expect(a).not.toBe(b);
|
|
32
|
+
});
|
|
33
|
+
});
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* CLI entry point for the macOS dev provider.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* launch up [--with-optional] [--no-build] [--dry-run]
|
|
7
|
+
* launch down [--destroy]
|
|
8
|
+
* launch status
|
|
9
|
+
* launch env [component]
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { launchUp, launchDown, launchStatus, launchEnv } from "./provider.js";
|
|
13
|
+
|
|
14
|
+
const args = process.argv.slice(2);
|
|
15
|
+
const command = args[0];
|
|
16
|
+
|
|
17
|
+
function hasFlag(flag: string): boolean {
|
|
18
|
+
return args.includes(`--${flag}`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getArg(index: number): string | undefined {
|
|
22
|
+
return args[index];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function main(): Promise<void> {
|
|
26
|
+
switch (command) {
|
|
27
|
+
case "up":
|
|
28
|
+
await launchUp({
|
|
29
|
+
withOptional: hasFlag("with-optional"),
|
|
30
|
+
noBuild: hasFlag("no-build"),
|
|
31
|
+
dryRun: hasFlag("dry-run"),
|
|
32
|
+
detach: hasFlag("detach"),
|
|
33
|
+
});
|
|
34
|
+
break;
|
|
35
|
+
|
|
36
|
+
case "down":
|
|
37
|
+
await launchDown({
|
|
38
|
+
destroy: hasFlag("destroy"),
|
|
39
|
+
});
|
|
40
|
+
break;
|
|
41
|
+
|
|
42
|
+
case "status":
|
|
43
|
+
await launchStatus();
|
|
44
|
+
break;
|
|
45
|
+
|
|
46
|
+
case "env":
|
|
47
|
+
await launchEnv({
|
|
48
|
+
component: getArg(1),
|
|
49
|
+
});
|
|
50
|
+
break;
|
|
51
|
+
|
|
52
|
+
default:
|
|
53
|
+
console.log(`launch — macOS dev provider for Launchfile
|
|
54
|
+
|
|
55
|
+
Usage:
|
|
56
|
+
launch up [--with-optional] [--no-build] [--dry-run]
|
|
57
|
+
Provision resources, install deps, and start the app.
|
|
58
|
+
|
|
59
|
+
launch down [--destroy]
|
|
60
|
+
Stop processes. --destroy also drops databases and cleans up.
|
|
61
|
+
|
|
62
|
+
launch status
|
|
63
|
+
Show status of components and resources.
|
|
64
|
+
|
|
65
|
+
launch env [component]
|
|
66
|
+
Print resolved environment variables.
|
|
67
|
+
`);
|
|
68
|
+
if (command && command !== "help" && command !== "--help") {
|
|
69
|
+
console.error(`Unknown command: ${command}`);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
main().catch((err) => {
|
|
76
|
+
console.error(err.message ?? err);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
});
|