Skip to content

Commit bb1bd8f

Browse files
d-csclaude
andcommitted
test(run-ops): strip schema comments before parity regexes; dedupe PG17 fixture bootstrap
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 213bb9a commit bb1bd8f

2 files changed

Lines changed: 32 additions & 41 deletions

File tree

internal-packages/run-ops-database/prisma/schema.parity.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ function readSchema(rel: string) {
2323
return readFileSync(resolve(__dirname, rel), "utf8");
2424
}
2525

26+
// Prisma comments (`///` docs and `//` lines) may legitimately mention
27+
// control-plane model names in prose, which would false-match the drift
28+
// regexes below. Strip them so parity assertions only see real schema syntax.
29+
function stripComments(schema: string) {
30+
return schema.replace(/\/\/.*$/gm, "");
31+
}
32+
2633
describe("dedicated run-ops schema parity", () => {
2734
it("references no control-plane model as a relation target", () => {
28-
const dedicated = readSchema("./schema.prisma");
35+
const dedicated = stripComments(readSchema("./schema.prisma"));
2936
for (const model of CONTROL_PLANE_MODELS) {
3037
// A relation target appears as ` fieldName Model @relation(...)`. A bare
3138
// scalar column like `projectId String` is fine; the model TYPE must be absent.
@@ -60,7 +67,7 @@ describe("dedicated run-ops schema parity", () => {
6067
});
6168

6269
it("keeps the group-(A) waitpoint-block references FK-FREE (scalar columns / explicit FK-free join models)", () => {
63-
const dedicated = readSchema("./schema.prisma");
70+
const dedicated = stripComments(readSchema("./schema.prisma"));
6471
// TaskRunWaitpoint must NOT carry a `@relation` to Waitpoint/TaskRun/BatchTaskRun.
6572
const trw = dedicated.match(/model TaskRunWaitpoint \{[\s\S]*?\n\}/)![0];
6673
expect(trw).not.toMatch(/@relation/);
@@ -77,7 +84,7 @@ describe("dedicated run-ops schema parity", () => {
7784
});
7885

7986
it("keeps the group-(B) co-resident references as real FKs (e.g. TaskRunAttempt.taskRun)", () => {
80-
const dedicated = readSchema("./schema.prisma");
87+
const dedicated = stripComments(readSchema("./schema.prisma"));
8188
const attempt = dedicated.match(/model TaskRunAttempt \{[\s\S]*?\n\}/)![0];
8289
// The attempt->run relation stays a real FK (always co-resident).
8390
expect(attempt).toMatch(/taskRun\s+TaskRun\s+@relation/);

internal-packages/testcontainers/src/index.ts

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -176,28 +176,30 @@ export const HETERO_PINNED_ICU_COLLATION = "und-x-icu";
176176
// PG17 worker singleton mirroring getWorkerPostgresContainer. PG17 supports the ICU cluster locale
177177
// provider (PG14 does not - it arrived in PG15), so only this side sets the cluster locale; the real
178178
// cross-version guarantee is the per-column COLLATE in the proof test.
179+
async function bootstrapPg17TemplateContainer(
180+
pushSchema: (databaseUrl: string) => Promise<unknown>
181+
): Promise<StartedPostgreSqlContainer> {
182+
const container = await withCiResourceLimits(new PostgreSqlContainer("docker.io/postgres:17"))
183+
.withCommand(["-c", "listen_addresses=*", "-c", "wal_level=logical"])
184+
.withEnvironment({
185+
POSTGRES_INITDB_ARGS: "--locale-provider=icu --icu-locale=en-US --encoding=UTF8",
186+
})
187+
.start();
188+
const admin = new PrismaClient({
189+
datasources: {
190+
db: { url: postgresUriWithDatabase(container.getConnectionUri(), "postgres") },
191+
},
192+
});
193+
await admin.$executeRawUnsafe(`CREATE DATABASE "${POSTGRES_TEMPLATE_DB}"`);
194+
await admin.$disconnect();
195+
await pushSchema(postgresUriWithDatabase(container.getConnectionUri(), POSTGRES_TEMPLATE_DB));
196+
return container;
197+
}
198+
179199
let workerPostgresContainer17: Promise<StartedPostgreSqlContainer> | undefined;
180200
const getWorkerPostgresContainer17 = () => {
181201
if (!workerPostgresContainer17) {
182-
workerPostgresContainer17 = (async () => {
183-
const container = await withCiResourceLimits(new PostgreSqlContainer("docker.io/postgres:17"))
184-
.withCommand(["-c", "listen_addresses=*", "-c", "wal_level=logical"])
185-
.withEnvironment({
186-
POSTGRES_INITDB_ARGS: "--locale-provider=icu --icu-locale=en-US --encoding=UTF8",
187-
})
188-
.start();
189-
const admin = new PrismaClient({
190-
datasources: {
191-
db: { url: postgresUriWithDatabase(container.getConnectionUri(), "postgres") },
192-
},
193-
});
194-
await admin.$executeRawUnsafe(`CREATE DATABASE "${POSTGRES_TEMPLATE_DB}"`);
195-
await admin.$disconnect();
196-
await pushDatabaseSchema(
197-
postgresUriWithDatabase(container.getConnectionUri(), POSTGRES_TEMPLATE_DB)
198-
);
199-
return container;
200-
})();
202+
workerPostgresContainer17 = bootstrapPg17TemplateContainer(pushDatabaseSchema);
201203
}
202204
return workerPostgresContainer17;
203205
};
@@ -209,25 +211,7 @@ const getWorkerPostgresContainer17 = () => {
209211
let runOpsWorkerPostgresContainer17: Promise<StartedPostgreSqlContainer> | undefined;
210212
const getRunOpsWorkerPostgresContainer17 = () => {
211213
if (!runOpsWorkerPostgresContainer17) {
212-
runOpsWorkerPostgresContainer17 = (async () => {
213-
const container = await withCiResourceLimits(new PostgreSqlContainer("docker.io/postgres:17"))
214-
.withCommand(["-c", "listen_addresses=*", "-c", "wal_level=logical"])
215-
.withEnvironment({
216-
POSTGRES_INITDB_ARGS: "--locale-provider=icu --icu-locale=en-US --encoding=UTF8",
217-
})
218-
.start();
219-
const admin = new PrismaClient({
220-
datasources: {
221-
db: { url: postgresUriWithDatabase(container.getConnectionUri(), "postgres") },
222-
},
223-
});
224-
await admin.$executeRawUnsafe(`CREATE DATABASE "${POSTGRES_TEMPLATE_DB}"`);
225-
await admin.$disconnect();
226-
await pushRunOpsSchema(
227-
postgresUriWithDatabase(container.getConnectionUri(), POSTGRES_TEMPLATE_DB)
228-
);
229-
return container;
230-
})();
214+
runOpsWorkerPostgresContainer17 = bootstrapPg17TemplateContainer(pushRunOpsSchema);
231215
}
232216
return runOpsWorkerPostgresContainer17;
233217
};

0 commit comments

Comments
 (0)