fix(ci): repair the mobile showcase screenshots workflow (#5057)

This commit is contained in:
Julius Marminge authored and GitHub committed 2026-07-31 10:11:12 +02:00
1 parent e259dd23c7
commit 50a3d6b872
3 files changed
+72 -18

No files matched your search

@@ -52,6 +52,7 @@ jobs:
args:
- --filter=@t3tools/mobile...
- --filter=@t3tools/scripts...
- --filter=t3...
- name: Expose pnpm
run: |
@@ -100,6 +101,7 @@ jobs:
args:
- --filter=@t3tools/mobile...
- --filter=@t3tools/scripts...
- --filter=t3...
- name: Expose pnpm
run: |
+47 -12
View File
@@ -1,4 +1,4 @@
// @effect-diagnostics nodeBuiltinImport:off globalDate:off - This host-side fixture creates an isolated local T3 environment.
// @effect-diagnostics nodeBuiltinImport:off globalTimers:off globalDate:off - This host-side fixture creates an isolated local T3 environment.
import * as NodeChildProcess from "node:child_process";
import * as NodeFSP from "node:fs/promises";
import * as NodePath from "node:path";
@@ -387,6 +387,48 @@ function insertThread(
.run(input.id, isWorking ? "running" : "ready", isWorking ? turnId : null, updatedAt);
}
const SEEDED_PROJECTION_TABLES = [
"projection_pending_approvals",
"projection_thread_proposed_plans",
"projection_thread_activities",
"projection_thread_messages",
"projection_thread_sessions",
"projection_turns",
"projection_threads",
"projection_projects",
"projection_state",
] as const;
function hasSeedableSchema(dbPath: string): boolean {
let database: NodeSqlite.DatabaseSync;
try {
database = new NodeSqlite.DatabaseSync(dbPath, { readOnly: true });
} catch {
return false;
}
try {
const row = database
.prepare(
`SELECT COUNT(*) AS count FROM sqlite_master WHERE type = 'table' AND name IN (${SEEDED_PROJECTION_TABLES.map(() => "?").join(", ")})`,
)
.get(...SEEDED_PROJECTION_TABLES) as { count: number };
return row.count === SEEDED_PROJECTION_TABLES.length;
} catch {
return false;
} finally {
database.close();
}
}
async function waitForSeedableSchema(dbPath: string, timeoutMs = 60_000): Promise<void> {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
if (hasSeedableSchema(dbPath)) return;
await new Promise((resolve) => setTimeout(resolve, 250));
}
throw new Error(`The environment server did not migrate ${dbPath} within ${timeoutMs}ms.`);
}
function seedDatabase(
dbPath: string,
workspaceRoots: ReadonlyMap<string, string>,
@@ -401,17 +443,7 @@ function seedDatabase(
const database = new NodeSqlite.DatabaseSync(dbPath, { timeout: 30_000 });
try {
database.exec("BEGIN IMMEDIATE");
for (const table of [
"projection_pending_approvals",
"projection_thread_proposed_plans",
"projection_thread_activities",
"projection_thread_messages",
"projection_thread_sessions",
"projection_turns",
"projection_threads",
"projection_projects",
"projection_state",
]) {
for (const table of SEEDED_PROJECTION_TABLES) {
database.exec(`DELETE FROM ${table}`);
}
const insertProject = database.prepare(
@@ -594,6 +626,9 @@ export async function seedShowcaseEnvironment(input: {
});
}),
);
// The environment server begins listening before it finishes migrating the
// database, so wait for the schema before deleting from and reseeding it.
await waitForSeedableSchema(dbPath);
seedDatabase(dbPath, workspaceRoots, projects, threads, now);
const terminalDirectory = NodePath.join(input.baseDir, "userdata", "logs", "terminals");
+23 -6
View File
@@ -500,6 +500,23 @@ async function waitForPort(port: number, label = "Process", timeoutMs = 60_000):
throw new Error(`${label} did not begin listening on port ${port} within ${timeoutMs}ms.`);
}
async function waitForFileContent(
filePath: string,
label: string,
timeoutMs = 60_000,
): Promise<string> {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
const content = await NodeFSP.readFile(filePath, "utf8").then(
(value) => value.trim(),
() => "",
);
if (content) return content;
await delay(250);
}
throw new Error(`${label} was not written to ${filePath} within ${timeoutMs}ms.`);
}
async function reserveAvailablePort(): Promise<number> {
return await new Promise<number>((resolve, reject) => {
const server = NodeNet.createServer();
@@ -1225,12 +1242,12 @@ async function main(): Promise<void> {
showcaseServers.push(server);
await waitForPort(port, `${environment.label} server`);
await seedShowcaseEnvironment({ baseDir, projectIds: environment.projectIds });
const environmentId = (
await NodeFSP.readFile(NodePath.join(baseDir, "userdata", "environment-id"), "utf8")
).trim();
if (!environmentId) {
throw new Error(`${environment.label} did not persist an environment id.`);
}
// The server begins listening before the ServerEnvironment layer
// persists the environment id, so poll rather than read once.
const environmentId = await waitForFileContent(
NodePath.join(baseDir, "userdata", "environment-id"),
`${environment.label} environment id`,
);
showcaseEnvironments.push({ baseDir, environmentId, label: environment.label, port });
}