mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-01 15:35:12 +01:00
Allow owned loopback Postgres databases in recovery qualification
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
16df54ba90
commit
14d60e1e4f
6 files changed
+135
-8
No files matched your search
@@ -6,6 +6,7 @@ const CONTROLLER_DATABASE_OWNER_FILE = ".runner-e2e-controller-owner.json";
|
||||
/** Written only after the supervisor has started this fixture's Postgres. */
|
||||
export async function recordControllerDatabaseOwnership(input: {
|
||||
configPath: string; temporaryRoot: string; dataDirectory: string; connectionString: string;
|
||||
externalDatabaseName?: string;
|
||||
}) {
|
||||
const temporaryRoot = await realpath(input.temporaryRoot);
|
||||
const dataDirectory = await realpath(input.dataDirectory);
|
||||
@@ -13,7 +14,8 @@ export async function recordControllerDatabaseOwnership(input: {
|
||||
throw new Error("Controller database path escaped its fixture-owned root");
|
||||
}
|
||||
await writeFile(path.join(dataDirectory, CONTROLLER_DATABASE_OWNER_FILE), JSON.stringify({
|
||||
version: 1, configPath: await realpath(input.configPath), temporaryRoot,
|
||||
version: input.externalDatabaseName ? 2 : 1, externalDatabaseName: input.externalDatabaseName,
|
||||
configPath: await realpath(input.configPath), temporaryRoot,
|
||||
dataDirectory, connectionString: input.connectionString,
|
||||
}), { mode: 0o600 });
|
||||
}
|
||||
@@ -82,12 +84,16 @@ export async function assertEmbeddedDatabaseIsolation(
|
||||
if (!directory.startsWith(`${root}${path.sep}`)) throw new Error("Database escaped fixture");
|
||||
const owner = JSON.parse(await readFile(path.join(directory, CONTROLLER_DATABASE_OWNER_FILE), "utf8"));
|
||||
const port = config.database.embeddedPostgresPort;
|
||||
const expectedConnection = `postgres://paperclip:paperclip@127.0.0.1:${port}/paperclip`;
|
||||
if (!Number.isInteger(port) || Number(port) < 1 || Number(port) > 65535
|
||||
|| config.database.connectionString !== expectedConnection
|
||||
|| owner.version !== 1 || owner.temporaryRoot !== root || owner.dataDirectory !== directory
|
||||
|| owner.configPath !== await realpath(configPath) || owner.connectionString !== expectedConnection
|
||||
|| !(await stat(path.join(directory, "PG_VERSION"))).isFile()) {
|
||||
const connection = new URL(config.database.connectionString!);
|
||||
const external = owner.version === 2 && /^runner_e2e_[a-f0-9]{32}$/.test(owner.externalDatabaseName)
|
||||
&& ["postgres:", "postgresql:"].includes(connection.protocol)
|
||||
&& ["127.0.0.1", "localhost", "[::1]"].includes(connection.hostname)
|
||||
&& connection.pathname === `/${owner.externalDatabaseName}`;
|
||||
const embedded = owner.version === 1 && Number.isInteger(port) && Number(port) > 0 && Number(port) <= 65535
|
||||
&& config.database.connectionString === `postgres://paperclip:paperclip@127.0.0.1:${port}/paperclip`
|
||||
&& (await stat(path.join(directory, "PG_VERSION"))).isFile();
|
||||
if ((!external && !embedded) || owner.temporaryRoot !== root || owner.dataDirectory !== directory
|
||||
|| owner.configPath !== await realpath(configPath) || owner.connectionString !== config.database.connectionString) {
|
||||
throw new Error("Supervisor database ownership mismatch");
|
||||
}
|
||||
} catch (cause) {
|
||||
|
||||
Reference in new issue
Block a user