Skip to content

Commit d1fd926

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 9b2b67d commit d1fd926

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
@@ -181,28 +181,30 @@ export const HETERO_PINNED_ICU_COLLATION = "und-x-icu";
181181
// PG17 worker singleton mirroring getWorkerPostgresContainer. PG17 supports the ICU cluster locale
182182
// provider (PG14 does not - it arrived in PG15), so only this side sets the cluster locale; the real
183183
// cross-version guarantee is the per-column COLLATE in the proof test.
184+
async function bootstrapPg17TemplateContainer(
185+
pushSchema: (databaseUrl: string) => Promise<unknown>
186+
): Promise<StartedPostgreSqlContainer> {
187+
const container = await withCiResourceLimits(new PostgreSqlContainer("docker.io/postgres:17"))
188+
.withCommand(["-c", "listen_addresses=*", "-c", "wal_level=logical"])
189+
.withEnvironment({
190+
POSTGRES_INITDB_ARGS: "--locale-provider=icu --icu-locale=en-US --encoding=UTF8",
191+
})
192+
.start();
193+
const admin = new PrismaClient({
194+
datasources: {
195+
db: { url: postgresUriWithDatabase(container.getConnectionUri(), "postgres") },
196+
},
197+
});
198+
await admin.$executeRawUnsafe(`CREATE DATABASE "${POSTGRES_TEMPLATE_DB}"`);
199+
await admin.$disconnect();
200+
await pushSchema(postgresUriWithDatabase(container.getConnectionUri(), POSTGRES_TEMPLATE_DB));
201+
return container;
202+
}
203+
184204
let workerPostgresContainer17: Promise<StartedPostgreSqlContainer> | undefined;
185205
const getWorkerPostgresContainer17 = () => {
186206
if (!workerPostgresContainer17) {
187-
workerPostgresContainer17 = (async () => {
188-
const container = await withCiResourceLimits(new PostgreSqlContainer("docker.io/postgres:17"))
189-
.withCommand(["-c", "listen_addresses=*", "-c", "wal_level=logical"])
190-
.withEnvironment({
191-
POSTGRES_INITDB_ARGS: "--locale-provider=icu --icu-locale=en-US --encoding=UTF8",
192-
})
193-
.start();
194-
const admin = new PrismaClient({
195-
datasources: {
196-
db: { url: postgresUriWithDatabase(container.getConnectionUri(), "postgres") },
197-
},
198-
});
199-
await admin.$executeRawUnsafe(`CREATE DATABASE "${POSTGRES_TEMPLATE_DB}"`);
200-
await admin.$disconnect();
201-
await pushDatabaseSchema(
202-
postgresUriWithDatabase(container.getConnectionUri(), POSTGRES_TEMPLATE_DB)
203-
);
204-
return container;
205-
})();
207+
workerPostgresContainer17 = bootstrapPg17TemplateContainer(pushDatabaseSchema);
206208
}
207209
return workerPostgresContainer17;
208210
};
@@ -214,25 +216,7 @@ const getWorkerPostgresContainer17 = () => {
214216
let runOpsWorkerPostgresContainer17: Promise<StartedPostgreSqlContainer> | undefined;
215217
const getRunOpsWorkerPostgresContainer17 = () => {
216218
if (!runOpsWorkerPostgresContainer17) {
217-
runOpsWorkerPostgresContainer17 = (async () => {
218-
const container = await withCiResourceLimits(new PostgreSqlContainer("docker.io/postgres:17"))
219-
.withCommand(["-c", "listen_addresses=*", "-c", "wal_level=logical"])
220-
.withEnvironment({
221-
POSTGRES_INITDB_ARGS: "--locale-provider=icu --icu-locale=en-US --encoding=UTF8",
222-
})
223-
.start();
224-
const admin = new PrismaClient({
225-
datasources: {
226-
db: { url: postgresUriWithDatabase(container.getConnectionUri(), "postgres") },
227-
},
228-
});
229-
await admin.$executeRawUnsafe(`CREATE DATABASE "${POSTGRES_TEMPLATE_DB}"`);
230-
await admin.$disconnect();
231-
await pushRunOpsSchema(
232-
postgresUriWithDatabase(container.getConnectionUri(), POSTGRES_TEMPLATE_DB)
233-
);
234-
return container;
235-
})();
219+
runOpsWorkerPostgresContainer17 = bootstrapPg17TemplateContainer(pushRunOpsSchema);
236220
}
237221
return runOpsWorkerPostgresContainer17;
238222
};

0 commit comments

Comments
 (0)