Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test: keep the workspace-cache fixture independent of the DB run lock (#12371)

[._.]/ Adam Eivye0cacfebda8c
diff --git a/scripts/lib/workspaceCacheFixture.js b/scripts/lib/workspaceCacheFixture.js
index a2c5334eaa..8b082239fe 100644
--- a/scripts/lib/workspaceCacheFixture.js
+++ b/scripts/lib/workspaceCacheFixture.js
@@ -48,6 +48,8 @@ function checkout(host, name, workspace, configName, dependencies) {
put(join(parent, 'package.json'), '{"type":"module"}');
const fixture = createVitestTempFixture(parent, workspace, 'expect(true).toBe(true);', configName);
delete fixture.options.env.PORTOS_CI_BROWSER_OWNER;
+ // Not a `_test` database: the DB run lock stands down, so the fixture neither needs `pg` nor queues behind a real run.
+ fixture.options.env.PGTESTDATABASE = 'workspace_cache_fixture';
const root = fixture.args[fixture.args.indexOf('--root') + 1];
unlinkSync(join(root, 'node_modules'));
link(dependencies, join(root, 'node_modules'));
@@ -61,7 +63,7 @@ function checkout(host, name, workspace, configName, dependencies) {
if (workspace === 'server') {
// Both configs load this environment relative to themselves. Copy its
// Node-only support closure intact so setup and teardown run in this checkout.
- for (const file of ['test/mediaRegistryEnvironment.js', 'test/ownedBrowserDiagnostics.js', 'lib/mockPathsDataRoot.js']) {
+ for (const file of ['test/dbRunExclusivity.js', 'test/mediaRegistryEnvironment.js', 'test/ownedBrowserDiagnostics.js', 'lib/mockPathsDataRoot.js']) {
mkdirSync(dirname(join(root, file)), { recursive: true });
copyFileSync(join(REPO, 'server', file), join(root, file));
}
diff --git a/server/test/dbRunExclusivity.js b/server/test/dbRunExclusivity.js
index 38c03ec6fa..7753065139 100644
--- a/server/test/dbRunExclusivity.js
+++ b/server/test/dbRunExclusivity.js
@@ -11,14 +11,14 @@
* A session-level advisory lock on the test database is held for the whole
* run. It is connection-scoped, so a killed run releases it automatically.
*/
-import pg from 'pg';
-
// Distinct from SCHEMA_DDL_ADVISORY_LOCK_KEY (5977001, lib/db.js) — ensureSchema
// takes that one inside a run and would otherwise deadlock against this holder.
export const DB_RUN_ADVISORY_LOCK_KEY = 5977002;
const WAIT_LOG_INTERVAL_MS = 30_000;
+// `pg` loads lazily: a run that skips the lock (non-test database) never needs it.
+
/** Connection target for the test database, mirroring lib/db.js defaults. */
function testDatabaseConfig(env) {
return {
@@ -37,14 +37,14 @@ function testDatabaseConfig(env) {
*/
export async function acquireDbRunLock({
env = process.env,
- createClient = config => new pg.Client(config),
+ createClient = async config => new (await import('pg')).default.Client(config),
log = console.log,
waitLogIntervalMs = WAIT_LOG_INTERVAL_MS,
} = {}) {
const config = testDatabaseConfig(env);
if (!/_test$/.test(config.database)) return async () => {};
- const client = createClient(config);
+ const client = await createClient(config);
client.on?.('error', () => {});
try {
await client.connect();