Skip to content

Commit 4072ab1

Browse files
committed
test: increase timeout for imageTag priority tests to 60s
Add 30s subprocess timeout to Bun.spawnSync calls to prevent hanging on Docker daemon check in CI environments without Docker.
1 parent aa5c141 commit 4072ab1

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cli/test/init.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ describe("CLI commands", () => {
792792
describe("imageTag priority behavior", () => {
793793
// Tests for the imageTag priority: --tag flag > PGAI_TAG env var > pkg.version
794794
// This verifies the fix that prevents stale .env PGAI_TAG from being used
795+
// These tests spawn subprocesses so need longer timeout
795796

796797
let tempDir: string;
797798

@@ -814,11 +815,13 @@ describe("imageTag priority behavior", () => {
814815
fs.writeFileSync(resolve(testDir, "docker-compose.yml"), "version: '3'\nservices: {}\n");
815816

816817
// Run from the test directory (so resolvePaths finds docker-compose.yml)
818+
// Note: Command may hang on Docker check in CI without Docker, so we use a timeout
817819
const cliPath = resolve(import.meta.dir, "..", "bin", "postgres-ai.ts");
818820
const bunBin = typeof process.execPath === "string" && process.execPath.length > 0 ? process.execPath : "bun";
819821
const result = Bun.spawnSync([bunBin, cliPath, "mon", "local-install", "--db-url", "postgresql://u:p@h:5432/d", "--yes"], {
820822
env: { ...process.env, PGAI_TAG: undefined },
821823
cwd: testDir,
824+
timeout: 30000, // Kill subprocess after 30s if it hangs on Docker
822825
});
823826

824827
// Read the .env that was written
@@ -828,7 +831,7 @@ describe("imageTag priority behavior", () => {
828831
expect(envContent).not.toMatch(/PGAI_TAG=beta/);
829832
// It should contain the CLI version (0.0.0-dev.0 in dev)
830833
expect(envContent).toMatch(/PGAI_TAG=\d+\.\d+\.\d+|PGAI_TAG=0\.0\.0-dev/);
831-
});
834+
}, 60000);
832835

833836
test("--tag flag takes priority over pkg.version", () => {
834837
const testDir = resolve(tempDir, "tag-flag-test");
@@ -840,6 +843,7 @@ describe("imageTag priority behavior", () => {
840843
const result = Bun.spawnSync([bunBin, cliPath, "mon", "local-install", "--tag", "v1.2.3-custom", "--db-url", "postgresql://u:p@h:5432/d", "--yes"], {
841844
env: { ...process.env, PGAI_TAG: undefined },
842845
cwd: testDir,
846+
timeout: 30000,
843847
});
844848

845849
const envContent = fs.readFileSync(resolve(testDir, ".env"), "utf8");
@@ -848,7 +852,7 @@ describe("imageTag priority behavior", () => {
848852
// Verify stdout confirms the tag being used
849853
const stdout = new TextDecoder().decode(result.stdout);
850854
expect(stdout).toMatch(/Using image tag: v1\.2\.3-custom/);
851-
});
855+
}, 60000);
852856

853857
test("PGAI_TAG env var is intentionally ignored (Bun auto-loads .env)", () => {
854858
// Note: We do NOT use process.env.PGAI_TAG because Bun auto-loads .env files,
@@ -863,13 +867,14 @@ describe("imageTag priority behavior", () => {
863867
const result = Bun.spawnSync([bunBin, cliPath, "mon", "local-install", "--db-url", "postgresql://u:p@h:5432/d", "--yes"], {
864868
env: { ...process.env, PGAI_TAG: "v2.0.0-from-env" },
865869
cwd: testDir,
870+
timeout: 30000,
866871
});
867872

868873
const envContent = fs.readFileSync(resolve(testDir, ".env"), "utf8");
869874
// PGAI_TAG env var should be IGNORED - uses pkg.version instead
870875
expect(envContent).not.toMatch(/PGAI_TAG=v2\.0\.0-from-env/);
871876
expect(envContent).toMatch(/PGAI_TAG=\d+\.\d+\.\d+|PGAI_TAG=0\.0\.0-dev/);
872-
});
877+
}, 60000);
873878

874879
test("existing registry and password are preserved while tag is updated", () => {
875880
const testDir = resolve(tempDir, "preserve-test");
@@ -884,6 +889,7 @@ describe("imageTag priority behavior", () => {
884889
const result = Bun.spawnSync([bunBin, cliPath, "mon", "local-install", "--db-url", "postgresql://u:p@h:5432/d", "--yes"], {
885890
env: { ...process.env, PGAI_TAG: undefined },
886891
cwd: testDir,
892+
timeout: 30000,
887893
});
888894

889895
const envContent = fs.readFileSync(resolve(testDir, ".env"), "utf8");
@@ -894,5 +900,5 @@ describe("imageTag priority behavior", () => {
894900
// But registry and password should be preserved
895901
expect(envContent).toMatch(/PGAI_REGISTRY=my\.registry\.com/);
896902
expect(envContent).toMatch(/GF_SECURITY_ADMIN_PASSWORD=secret123/);
897-
});
903+
}, 60000);
898904
});

0 commit comments

Comments
 (0)