Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
E2E harness: address review on the fast lane
Petr Bauch6cc9f8465fcf
diff --git a/console/tooling-e2e/README.md b/console/tooling-e2e/README.mdindex 069675ac5..6f36ec74e 100644--- a/console/tooling-e2e/README.md+++ b/console/tooling-e2e/README.md@@ -44,11 +44,14 @@ what `pnpm -r test` and PR CI see. The unit tests (configuration, the read-onlyguard, naming, scenario headers) run either way.Housekeeping after an interrupted run deletes every `e2e-*` agent and room on-the Switch server and archives every `e2e-*` Mattermost channel, and nothing-else. It is also what a scheduled wipe of a deployed environment runs:+the Switch server and archives every `e2e-*` Mattermost channel older than the+age you give, and nothing else. The age floor is what lets a scheduled wipe of a+deployed environment run while a suite is in progress; make it longer than the+longest run. `0` takes everything, which is only right when nothing else is+running against the server:```bash-SWITCH_E2E_LANE=fast pnpm cleanup+SWITCH_E2E_LANE=fast pnpm cleanup --older-than 120```Typecheck: `pnpm typecheck`.diff --git a/console/tooling-e2e/scripts/ephemeral-stack.sh b/console/tooling-e2e/scripts/ephemeral-stack.shindex 384d1e75a..b75681c2c 100755--- a/console/tooling-e2e/scripts/ephemeral-stack.sh+++ b/console/tooling-e2e/scripts/ephemeral-stack.sh@@ -30,7 +30,7 @@ while [ $# -gt 0 ]; doshiftdone-for tool in docker uv openssl curl jq; do+for tool in docker uv openssl curl jq lsof; docommand -v "$tool" >/dev/null || { echo "$tool is required but not on PATH." >&2; exit 1; }donefor port in 5432 8000 8065 8081; do@@ -43,12 +43,7 @@ donerm -rf "$OUT"; mkdir -p "$OUT"ENV_FILE="$OUT/stack.env"cp "$REPO/.env.example" "$ENV_FILE"-for key in DB_PASSWORD DB_OWNER_PASSWORD AGENT_REGISTRATION_TOKEN GATEWAY_ADMIN_PASSWORD \- MATTERMOST_ADMIN_PASSWORD MATTERMOST_USER_PASSWORD; do- sed -i.bak "s|^${key}=.*|${key}=$(openssl rand -hex 24)|" "$ENV_FILE"-done-sed -i.bak "s|^SECRET_KEYS=.*|SECRET_KEYS=e2e:$(openssl rand -hex 32)|" "$ENV_FILE"-rm -f "$ENV_FILE.bak"+"$REPO/deploy/local/generate-env-secrets.sh" "$ENV_FILE" e2echmod 600 "$ENV_FILE"set -a; source "$ENV_FILE"; set +adiff --git a/console/tooling-e2e/src/cleanup.ts b/console/tooling-e2e/src/cleanup.tsindex 0948d054b..baf7446c8 100644--- a/console/tooling-e2e/src/cleanup.ts+++ b/console/tooling-e2e/src/cleanup.ts@@ -1,60 +1,102 @@/**- * Remove artefacts a crashed or interrupted run left behind: Switch agents,- * Switch rooms and Mattermost channels whose names start with `e2e-`.+ * Remove artefacts that interrupted runs left behind: Switch agents, Switch+ * rooms and Mattermost channels whose names start with `e2e-` and that are+ * older than `--older-than <minutes>`.** Scoped strictly to that prefix — an operator's real agents and their rooms are- * never in scope, and the script prints everything it touches. It is also what- * a scheduled wipe of a deployed environment runs.+ * never in scope, and the script prints everything it touches. The age floor is+ * what lets a scheduled wipe of a deployed environment run while a suite is in+ * progress: a run's own artefacts are younger than the floor, so it is left+ * alone. Pick a floor longer than the longest run; `0` takes everything, which+ * is only right when nothing else is running against the server.*- * SWITCH_E2E_LANE=fast node --experimental-strip-types src/cleanup.ts+ * SWITCH_E2E_LANE=fast node --experimental-strip-types src/cleanup.ts --older-than 120*/import { ARTIFACT_PREFIX } from './core/run.ts';import { message, resolveLane } from './core/suite.ts';-export async function cleanup(log: (message: string) => void = console.log): Promise<void> {+export async function cleanup(+ olderThanMinutes: number,+ log: (message: string) => void = console.log+): Promise<void> {const lane = await resolveLane('fast');if (!lane.target) throw new Error(`Cannot clean up: ${lane.skip}`);const { env, switchClient, mattermost } = lane.target;+ const cutoff = Date.now() - olderThanMinutes * 60_000;+ const stale = (name: string, createdMs: number): boolean =>+ name.startsWith(ARTIFACT_PREFIX) && createdMs <= cutoff;+ let failures = 0;for (const room of await switchClient.listRooms()) {- if (!room.name.startsWith(ARTIFACT_PREFIX)) continue;+ if (!stale(room.name, timestampMs(room.createdAt))) continue;try {await switchClient.deleteRoom(room.id);log(`deleted room ${room.name} (${room.id})`);} catch (error) {+ failures += 1;log(`could not delete room ${room.name}: ${message(error)}`);}}for (const agent of await switchClient.listAgents()) {- if (!agent.name.startsWith(ARTIFACT_PREFIX)) continue;+ if (!stale(agent.name, timestampMs(agent.createdAt))) continue;try {await switchClient.deleteAgentByName(agent.name);log(`deleted agent ${agent.name} (${agent.id})`);} catch (error) {+ failures += 1;log(`could not delete agent ${agent.name}: ${message(error)}`);}}if (!mattermost || !env.mattermost) {- log('no Mattermost configured — skipping channels');- return;- }- const team = await mattermost.findTeam(env.mattermost.team);- for (const channel of await mattermost.listTeamChannels(team.id)) {- if (!channel.name.startsWith(ARTIFACT_PREFIX)) continue;- try {- await mattermost.archiveChannel(channel.id);- log(`archived channel ${channel.name} (${channel.id})`);- } catch (error) {- log(`could not archive channel ${channel.name}: ${message(error)}`);+ log('no Mattermost configured — channels not checked');+ } else {+ const team = await mattermost.findTeam(env.mattermost.team);+ for (const channel of await mattermost.listTeamChannels(team.id)) {+ if (!stale(channel.name, channel.create_at)) continue;+ try {+ await mattermost.archiveChannel(channel.id);+ log(`archived channel ${channel.name} (${channel.id})`);+ } catch (error) {+ failures += 1;+ log(`could not archive channel ${channel.name}: ${message(error)}`);+ }}}++ if (failures > 0) throw new Error(`${failures} artefact(s) could not be removed; see above.`);+}++/**+ * A server timestamp in epoch milliseconds. One without a UTC offset is+ * refused: JavaScript would read it as local time, and an age floor computed+ * from that is off by the machine's timezone.+ */+export function timestampMs(raw: string): number {+ if (!/(Z|[+-]\d{2}:?\d{2})$/.test(raw.trim())) {+ throw new Error(`Timestamp '${raw}' carries no UTC offset; cannot tell its age.`);+ }+ const ms = Date.parse(raw.trim().replace(' ', 'T'));+ if (Number.isNaN(ms)) throw new Error(`Cannot parse timestamp '${raw}'.`);+ return ms;+}++export function olderThanFrom(argv: readonly string[]): number {+ const index = argv.indexOf('--older-than');+ const raw = index === -1 ? undefined : argv[index + 1];+ const minutes = raw === undefined ? Number.NaN : Number(raw);+ if (!Number.isFinite(minutes) || minutes < 0) {+ throw new Error('Pass --older-than <minutes>: only artefacts older than that are removed.');+ }+ return minutes;}if (import.meta.url === `file://${process.argv[1]}`) {- cleanup().catch((error: unknown) => {- console.error(message(error));- process.exitCode = 1;- });+ Promise.resolve()+ .then(() => cleanup(olderThanFrom(process.argv.slice(2))))+ .catch((error: unknown) => {+ console.error(message(error));+ process.exitCode = 1;+ });}diff --git a/console/tooling-e2e/src/clients/mattermost-client.ts b/console/tooling-e2e/src/clients/mattermost-client.tsindex a2c31f788..cfe067e6d 100644--- a/console/tooling-e2e/src/clients/mattermost-client.ts+++ b/console/tooling-e2e/src/clients/mattermost-client.ts@@ -28,6 +28,10 @@ export interface MattermostChannel {name: string;display_name: string;team_id: string;+ /** Epoch milliseconds. */+ create_at: number;+ /** Non-zero once the channel is archived. */+ delete_at?: number;}export interface MattermostUser {diff --git a/console/tooling-e2e/src/clients/switch-client.ts b/console/tooling-e2e/src/clients/switch-client.tsindex 1b56c7709..391b5bc9d 100644--- a/console/tooling-e2e/src/clients/switch-client.ts+++ b/console/tooling-e2e/src/clients/switch-client.ts@@ -26,6 +26,7 @@ export interface RegisteredAgent {export interface RoomSummary {id: string;name: string;+ createdAt: string;bridgeId: string | null;bridgeType: string | null;archived: boolean;@@ -40,6 +41,7 @@ export interface RoomDetail extends RoomSummary {export interface AgentSummary {id: string;name: string;+ createdAt: string;}/**@@ -102,10 +104,9 @@ function truncate(text: string, max: number): string {return text.length > max ? `${text.slice(0, max)}…` : text;}-interface RequestInit {+interface SwitchRequest {token?: string;cookie?: string;- headers?: Record<string, string>;body?: unknown;timeoutMs?: number;}@@ -128,20 +129,19 @@ export class SwitchClient {// ── plumbing ──────────────────────────────────────────────────────────────- private async request<T>(method: string, path: string, init: RequestInit = {}): Promise<T> {+ private async request<T>(method: string, path: string, init: SwitchRequest = {}): Promise<T> {return (await this.rawRequest(method, path, init)).parsed as T;}private async rawRequest(method: string,path: string,- init: RequestInit+ init: SwitchRequest): Promise<{ parsed: unknown; response: Response }> {assertAllowed(this.environment, method, path);const headers: Record<string, string> = { Accept: 'application/json' };if (init.token) headers.Authorization = `Bearer ${init.token}`;if (init.cookie) headers.Cookie = init.cookie;- Object.assign(headers, init.headers ?? {});if (init.body !== undefined) headers['Content-Type'] = 'application/json';const response = await fetch(`${this.apiUrl}${path}`, {@@ -290,8 +290,11 @@ export class SwitchClient {}async listAgents(): Promise<AgentSummary[]> {- const rows = await this.gateway<{ id: string; name: string }[]>('GET', '/agents');- return rows.map((row) => ({ id: row.id, name: row.name }));+ const rows = await this.gateway<{ id: string; name: string; created_at: string }[]>(+ 'GET',+ '/agents'+ );+ return rows.map((row) => ({ id: row.id, name: row.name, createdAt: row.created_at }));}/** The bridge id of the default collaboration bridge of `type`. */@@ -530,6 +533,7 @@ export class SwitchClient {interface RawRoom {id: string;name: string;+ created_at: string;bridge_id?: string | null;bridge_type?: string | null;archived?: boolean;@@ -552,6 +556,7 @@ function toRoomSummary(row: RawRoom): RoomSummary {return {id: row.id,name: row.name,+ createdAt: row.created_at,bridgeId: row.bridge_id ?? null,bridgeType: row.bridge_type ?? null,archived: row.archived ?? false,diff --git a/console/tooling-e2e/src/core/core.test.ts b/console/tooling-e2e/src/core/core.test.tsindex 8d2561b45..757bd3544 100644--- a/console/tooling-e2e/src/core/core.test.ts+++ b/console/tooling-e2e/src/core/core.test.ts@@ -1,7 +1,8 @@import { describe, expect, it } from 'vitest';+import { olderThanFrom, timestampMs } from '../cleanup.ts';import { FAST_SCENARIOS } from '../fast/index.ts';import { SCENARIOS as PROVIDER_SCENARIOS } from '../provider/scenarios.ts';-import { laneFrom, loadEnv, MissingConfigError, type HarnessEnv } from './env.ts';+import { laneFrom, loadEnv, MissingConfigError, strictFrom, type HarnessEnv } from './env.ts';import { assertAllowed, ReadOnlyEnvironmentError } from './guard.ts';import { isValidMattermostUsername, RunContext } from './run.ts';import {@@ -45,8 +46,15 @@ describe('configuration', () => {it('refuses an unknown environment or lane', () => {expect(() => loadEnv('fast', { ...BASE, SWITCH_E2E_ENVIRONMENT: 'qa' }, {})).toThrow(/qa/);- expect(() => laneFrom({ SWITCH_E2E_LANE: 'slow' })).toThrow(/slow/);- expect(laneFrom({})).toBeNull();+ expect(() => laneFrom({ SWITCH_E2E_LANE: 'slow' }, {})).toThrow(/slow/);+ expect(laneFrom({}, {})).toBeNull();+ });++ it('reads the lane and strict mode from .env as well as the environment', () => {+ expect(laneFrom({}, { SWITCH_E2E_LANE: 'fast' })).toBe('fast');+ expect(strictFrom({}, { SWITCH_E2E_STRICT: '1' })).toBe(true);+ expect(loadEnv('fast', BASE, { SWITCH_E2E_STRICT: '1' }).strict).toBe(true);+ expect(laneFrom({ SWITCH_E2E_LANE: 'provider' }, { SWITCH_E2E_LANE: 'fast' })).toBe('provider');});});@@ -159,3 +167,20 @@ describe('admission', () => {});});});++describe('cleanup age floor', () => {+ it('reads server timestamps with an offset, and refuses ones without', () => {+ expect(timestampMs('2026-10-16 17:08:52.123456+00:00')).toBe(+ Date.UTC(2026, 9, 16, 17, 8, 52, 123)+ );+ expect(timestampMs('2026-10-16T17:08:52Z')).toBe(Date.UTC(2026, 9, 16, 17, 8, 52));+ expect(() => timestampMs('2026-10-16 17:08:52')).toThrow(/UTC offset/);+ });++ it('requires --older-than', () => {+ expect(olderThanFrom(['--older-than', '120'])).toBe(120);+ expect(olderThanFrom(['--older-than', '0'])).toBe(0);+ expect(() => olderThanFrom([])).toThrow(/--older-than/);+ expect(() => olderThanFrom(['--older-than', '-1'])).toThrow(/--older-than/);+ });+});diff --git a/console/tooling-e2e/src/core/env.ts b/console/tooling-e2e/src/core/env.tsindex b6346ffa1..1a280d130 100644--- a/console/tooling-e2e/src/core/env.ts+++ b/console/tooling-e2e/src/core/env.ts@@ -160,13 +160,28 @@ function reader(source: Source, file: Record<string, string>): (key: string) =>* case every end-to-end suite skips, which is what keeps `pnpm -r test` on a* developer machine from reaching for a server.*/-export function laneFrom(source: Source = process.env): Lane | null {- const raw = reader(source, {})('SWITCH_E2E_LANE');+export function laneFrom(+ source: Source = process.env,+ file: Record<string, string> = readDotEnvFile()+): Lane | null {+ const raw = reader(source, file)('SWITCH_E2E_LANE');if (raw === undefined) return null;if (raw === 'fast' || raw === 'provider') return raw;throw new Error(`SWITCH_E2E_LANE must be 'fast' or 'provider' — got '${raw}'.`);}+/**+ * Whether a run that cannot go ahead fails rather than skips. Read from the+ * same sources as everything else, so `.env` and the environment never+ * disagree about it.+ */+export function strictFrom(+ source: Source = process.env,+ file: Record<string, string> = readDotEnvFile()+): boolean {+ return reader(source, file)('SWITCH_E2E_STRICT') === '1';+}+/*** Resolve the harness configuration from `process.env` layered over `.env`.* Throws {@link MissingConfigError} naming every absent variable at once rather@@ -207,7 +222,7 @@ export function loadEnv(return {lane,environment: environmentFrom(required.SWITCH_E2E_ENVIRONMENT as string),- strict: get('SWITCH_E2E_STRICT') === '1',+ strict: strictFrom(source, file),keepArtifacts: get('SWITCH_E2E_KEEP') === '1',switch: {apiUrl: stripTrailingSlash(required.SWITCH_API_URL as string),diff --git a/console/tooling-e2e/src/core/run.ts b/console/tooling-e2e/src/core/run.tsindex cc796de85..e76676412 100644--- a/console/tooling-e2e/src/core/run.ts+++ b/console/tooling-e2e/src/core/run.ts@@ -59,12 +59,14 @@ export class RunContext {}export class NameScope {+ readonly runId: string;+ private readonly letter: string;private readonly used = new Set<string>();- constructor(- readonly runId: string,- private readonly letter: string- ) {}+ constructor(runId: string, letter: string) {+ this.runId = runId;+ this.letter = letter;+ }/*** The name for an agent, room or channel.diff --git a/console/tooling-e2e/src/core/suite.ts b/console/tooling-e2e/src/core/suite.tsindex 18c6ddf99..1fc95b682 100644--- a/console/tooling-e2e/src/core/suite.ts+++ b/console/tooling-e2e/src/core/suite.ts@@ -1,6 +1,13 @@import { MattermostClient } from '../clients/mattermost-client.ts';import { SwitchClient } from '../clients/switch-client.ts';-import { laneFrom, loadEnv, type HarnessEnv, type Lane } from './env.ts';+import {+ laneFrom,+ loadEnv,+ readDotEnvFile,+ strictFrom,+ type HarnessEnv,+ type Lane,+} from './env.ts';/*** Whether this process runs a lane's suite at all, and the clients it runs with.@@ -23,14 +30,15 @@ export type LaneResolution = { target: LaneTarget; skip: null } | { target: null* suite that never ran.*/export async function resolveLane(lane: Lane): Promise<LaneResolution> {- const asked = laneFrom();+ const file = readDotEnvFile();+ const asked = laneFrom(process.env, file);if (asked !== lane) {return {target: null,skip: asked === null ? 'SWITCH_E2E_LANE is not set' : `SWITCH_E2E_LANE is '${asked}'`,};}- const strict = process.env.SWITCH_E2E_STRICT === '1';+ const strict = strictFrom(process.env, file);const unable = (reason: string): LaneResolution => {if (strict) throw new Error(`The ${lane} lane cannot run (SWITCH_E2E_STRICT=1): ${reason}`);return { target: null, skip: reason };@@ -38,7 +46,7 @@ export async function resolveLane(lane: Lane): Promise<LaneResolution> {let env: HarnessEnv;try {- env = loadEnv(lane);+ env = loadEnv(lane, process.env, file);} catch (error) {return unable(message(error));}diff --git a/console/tooling-e2e/src/fast/fast.e2e.test.ts b/console/tooling-e2e/src/fast/fast.e2e.test.tsindex 1440f8827..ca7224875 100644--- a/console/tooling-e2e/src/fast/fast.e2e.test.ts+++ b/console/tooling-e2e/src/fast/fast.e2e.test.ts@@ -44,13 +44,18 @@ describe('fast lane', () => {const names = run.scope();const fixtures = new Fixtures(env, names, switchClient, mattermost);const log = (message: string): void => console.log(`[${scenario.header.id}] ${message}`);+ let failure: unknown = null;try {await scenario.run({ env, names, switchClient, mattermost, fixtures, log });- } finally {- const leftovers = await fixtures.teardown();- for (const line of leftovers) log(`teardown: ${line}`);- if (!env.keepArtifacts) expect(leftovers, 'teardown left artefacts behind').toEqual([]);+ } catch (error) {+ failure = error;}+ const leftovers = await fixtures.teardown();+ for (const line of leftovers) log(`teardown: ${line}`);+ // The scenario's own failure is the root cause and is reported as is; a+ // leak is only the verdict when nothing else went wrong.+ if (failure !== null) throw failure;+ if (!env.keepArtifacts) expect(leftovers, 'teardown left artefacts behind').toEqual([]);});}});diff --git a/console/tooling-e2e/src/fixtures/fixtures.ts b/console/tooling-e2e/src/fixtures/fixtures.tsindex 51da21e7b..691886517 100644--- a/console/tooling-e2e/src/fixtures/fixtures.ts+++ b/console/tooling-e2e/src/fixtures/fixtures.ts@@ -22,14 +22,23 @@ import type { NameScope } from '../core/run.ts';* room should not hide another.*/export class Fixtures {+ readonly env: HarnessEnv;+ readonly names: NameScope;+ readonly switchClient: SwitchClient;+ readonly mattermost: MattermostClient | null;private readonly cleanups: { label: string; run: () => Promise<void> }[] = [];constructor(- readonly env: HarnessEnv,- readonly names: NameScope,- readonly switchClient: SwitchClient,- readonly mattermost: MattermostClient | null- ) {}+ env: HarnessEnv,+ names: NameScope,+ switchClient: SwitchClient,+ mattermost: MattermostClient | null+ ) {+ this.env = env;+ this.names = names;+ this.switchClient = switchClient;+ this.mattermost = mattermost;+ }/*** Register an agent named for `role` in this scope.@@ -106,19 +115,21 @@ export class Fixtures {agentNames: agents.map((agent) => agent.name),userNames: [human.username],});- this.defer(`room ${name} (${room.id})`, () => this.switchClient.deleteRoom(room.id));- if (!room.externalChannelId) {+ const channelId = room.externalChannelId;+ // One step, in order: the room first, then its channel only if deleting the+ // room did not already archive it.+ this.defer(`room ${name} (${room.id}) and channel ${channelId ?? 'none'}`, async () => {+ await this.switchClient.deleteRoom(room.id);+ if (channelId === null) return;+ const left = await mattermost.getChannel(channelId);+ if (!left.delete_at) await mattermost.archiveChannel(channelId);+ });+ if (channelId === null) {throw new Error(`Switch room ${room.id} was created without a Mattermost channel — ` +`the collaboration bridge did not provision one.`);}- const channelId = room.externalChannelId;- // Deleting the room usually takes the channel with it, so archiving is- // normally a no-op; it is the safety net when it does not.- this.defer(`channel ${channelId}`, async () => {- await mattermost.archiveChannel(channelId).catch(() => undefined);- });const channel = await mattermost.getChannel(channelId);const bridged: BridgedRoom = { room, channel, human, bots };diff --git a/console/tooling-e2e/tsconfig.json b/console/tooling-e2e/tsconfig.jsonindex 875681286..641ae596e 100644--- a/console/tooling-e2e/tsconfig.json+++ b/console/tooling-e2e/tsconfig.json@@ -3,8 +3,12 @@"target": "ES2023","module": "ESNext","moduleResolution": "bundler",- "lib": ["ES2023"],- "types": ["node"],+ "lib": [+ "ES2023"+ ],+ "types": [+ "node"+ ],"strict": true,"noUncheckedIndexedAccess": true,"noEmit": true,@@ -12,7 +16,11 @@"skipLibCheck": true,"esModuleInterop": true,"resolveJsonModule": true,- "verbatimModuleSyntax": true+ "verbatimModuleSyntax": true,+ "erasableSyntaxOnly": true},- "include": ["src/**/*.ts", "vitest.config.ts"]+ "include": [+ "src/**/*.ts",+ "vitest.config.ts"+ ]}diff --git a/deploy/local/docker-compose.yml b/deploy/local/docker-compose.ymlindex 6b5b6cdee..2fe8cbb2d 100644--- a/deploy/local/docker-compose.yml+++ b/deploy/local/docker-compose.yml@@ -53,6 +53,9 @@ services:mattermost:image: mattermost/mattermost-team-edition:latestplatform: linux/amd64+ # It calls back to switch-core on the host for button presses; see `setup`.+ extra_hosts:+ - "host.docker.internal:host-gateway"ports:- "${SWITCH_BIND_ADDR:-127.0.0.1}:8065:8065"volumes:@@ -99,6 +102,10 @@ services:context: .dockerfile: deploy/shared_resources/images/Dockerfile.setuprestart: on-failure+ # Docker Desktop and OrbStack define host.docker.internal; Linux Docker+ # (a CI runner) only does when asked.+ extra_hosts:+ - "host.docker.internal:host-gateway"environment:SWITCH_URL: http://host.docker.internal:8000MATTERMOST_URL: http://mattermost:8065diff --git a/deploy/local/generate-env-secrets.sh b/deploy/local/generate-env-secrets.shnew file mode 100755index 000000000..810a67deb--- /dev/null+++ b/deploy/local/generate-env-secrets.sh@@ -0,0 +1,21 @@+#!/usr/bin/env bash+# Fill a copy of .env.example with fresh random secrets, in place.+#+# deploy/local/generate-env-secrets.sh <env-file> <secret-keys-label>+#+# The one place that knows which keys are secrets: `just init-env` uses it for a+# developer's .env, and the end-to-end harness for each throwaway stack's env+# file. A secret added to .env.example goes in this list.+set -euo pipefail+file="$1"+label="$2"+command -v openssl >/dev/null 2>&1 || { echo "openssl is required to generate secrets." >&2; exit 1; }+for key in DB_PASSWORD DB_OWNER_PASSWORD \+ AGENT_REGISTRATION_TOKEN GATEWAY_ADMIN_PASSWORD \+ MATTERMOST_ADMIN_PASSWORD MATTERMOST_USER_PASSWORD; do+ grep -q "^${key}=" "$file" || { echo "$file has no ${key}= line to fill." >&2; exit 1; }+ sed -i.bak "s|^${key}=.*|${key}=$(openssl rand -hex 24)|" "$file"+done+grep -q "^SECRET_KEYS=" "$file" || { echo "$file has no SECRET_KEYS= line to fill." >&2; exit 1; }+sed -i.bak "s|^SECRET_KEYS=.*|SECRET_KEYS=${label}:$(openssl rand -hex 32)|" "$file"+rm -f "$file.bak"diff --git a/justfile b/justfileindex 6fcbd3ccf..725d9b6e6 100644--- a/justfile+++ b/justfile@@ -21,19 +21,8 @@ init-env:echo " Delete it first if you really want to regenerate every secret." >&2exit 1fi- if ! command -v openssl >/dev/null 2>&1; then- echo "openssl is required to generate secrets but was not found on PATH." >&2- exit 1- ficp .env.example .env- for key in DB_PASSWORD DB_OWNER_PASSWORD \- AGENT_REGISTRATION_TOKEN GATEWAY_ADMIN_PASSWORD \- MATTERMOST_ADMIN_PASSWORD MATTERMOST_USER_PASSWORD; do- secret="$(openssl rand -hex 24)"- sed -i.bak "s|^${key}=.*|${key}=${secret}|" .env- done- sed -i.bak "s|^SECRET_KEYS=.*|SECRET_KEYS=local:$(openssl rand -hex 32)|" .env- rm -f .env.bak+ deploy/local/generate-env-secrets.sh .env localecho "✅ Wrote .env with freshly generated secrets."echo " Gateway admin login: $(grep '^GATEWAY_ADMIN_EMAIL=' .env | cut -d= -f2-) / $(grep '^GATEWAY_ADMIN_PASSWORD=' .env | cut -d= -f2-)"echo " The stack binds to 127.0.0.1 only (set SWITCH_BIND_ADDR to expose it)."