- apps/cli/ is now the canonical CLI (was apps/cli-v2/). - apps/cli/ legacy v0 archived as branch 'legacy-cli-archive' and tag 'cli-v0-legacy-final' before deletion; git history preserves it too. - .github/workflows/release-cli.yml paths updated. - pnpm-lock.yaml regenerated. Broker-side peer-grant enforcement (spec: 2026-04-15-per-peer-capabilities): - 0020_peer-grants.sql adds peer_grants jsonb + GIN index on mesh.member. - handleSend in broker fetches recipient grant maps once per send, drops messages silently when sender lacks the required capability. - POST /cli/mesh/:slug/grants to update from CLI; broker_messages_dropped_by_grant_total metric. - CLI grant/revoke/block now mirror to broker via syncToBroker. Auto-migrate on broker startup: - apps/broker/src/migrate.ts runs drizzle migrate with pg_advisory_lock before the HTTP server binds. Exits non-zero on failure so Coolify healthcheck fails closed. - Dockerfile copies packages/db/migrations into /app/migrations. - postgres 3.4.5 added as direct broker dep. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
import { mkdirSync, rmSync, existsSync, readFileSync, statSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { tmpdir } from "node:os";
|
|
|
|
const TEST_DIR = join(tmpdir(), "claudemesh-test-" + Date.now());
|
|
|
|
describe("config", () => {
|
|
beforeEach(() => {
|
|
mkdirSync(TEST_DIR, { recursive: true });
|
|
process.env.CLAUDEMESH_CONFIG_DIR = TEST_DIR;
|
|
});
|
|
afterEach(() => {
|
|
rmSync(TEST_DIR, { recursive: true, force: true });
|
|
delete process.env.CLAUDEMESH_CONFIG_DIR;
|
|
});
|
|
|
|
it("readConfig returns empty when no file", async () => {
|
|
// Dynamic import to pick up env change
|
|
const { readConfig } = await import("~/services/config/read.js");
|
|
const config = readConfig();
|
|
expect(config.version).toBe(1);
|
|
expect(config.meshes).toEqual([]);
|
|
});
|
|
|
|
it("writeConfig + readConfig round-trip", async () => {
|
|
const { writeConfig } = await import("~/services/config/write.js");
|
|
const { readConfig } = await import("~/services/config/read.js");
|
|
writeConfig({
|
|
version: 1,
|
|
meshes: [{ meshId: "m1", memberId: "mb1", slug: "test", name: "Test", pubkey: "a".repeat(64), secretKey: "b".repeat(128), brokerUrl: "wss://localhost/ws", joinedAt: "2026-01-01" }],
|
|
});
|
|
|
|
const config = readConfig();
|
|
expect(config.meshes).toHaveLength(1);
|
|
expect(config.meshes[0]!.slug).toBe("test");
|
|
});
|
|
|
|
it("config file has 0600 permissions on unix", async () => {
|
|
if (process.platform === "win32") return;
|
|
const { writeConfig } = await import("~/services/config/write.js");
|
|
writeConfig({ version: 1, meshes: [] });
|
|
|
|
const configPath = join(TEST_DIR, "config.json");
|
|
const mode = statSync(configPath).mode & 0o777;
|
|
expect(mode).toBe(0o600);
|
|
});
|
|
});
|